sqlbot 0.0.1 → 0.0.11
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/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/(chat)/ai-providers/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/(chat)/chat/[threadId]/page.js +2 -2
- package/.next/standalone/.next/server/app/(chat)/chat/[threadId]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/(chat)/chat/[threadId]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/(chat)/connections/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/(chat)/knowledge-base/page.js +1 -1
- package/.next/standalone/.next/server/app/(chat)/knowledge-base/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/(chat)/knowledge-base/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/(chat)/page.js +1 -1
- package/.next/standalone/.next/server/app/(chat)/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/(chat)/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +2 -2
- package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +2 -2
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/ai-providers.html +1 -1
- package/.next/standalone/.next/server/app/ai-providers.rsc +3 -3
- package/.next/standalone/.next/server/app/ai-providers.segments/!KGNoYXQp/ai-providers/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/ai-providers.segments/!KGNoYXQp/ai-providers.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/ai-providers.segments/!KGNoYXQp.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/ai-providers.segments/_full.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/ai-providers.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/ai-providers.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/api/chat/route.js +1 -1
- package/.next/standalone/.next/server/app/api/chat/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/health/route.js +1 -1
- package/.next/standalone/.next/server/app/api/health/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/knowledge/auto-generate/route.js +1 -1
- package/.next/standalone/.next/server/app/api/knowledge/auto-generate/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/knowledge/generate/route.js +1 -1
- package/.next/standalone/.next/server/app/api/knowledge/generate/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/trpc/[trpc]/route.js +3 -3
- package/.next/standalone/.next/server/app/api/trpc/[trpc]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/connections.html +1 -1
- package/.next/standalone/.next/server/app/connections.rsc +3 -3
- package/.next/standalone/.next/server/app/connections.segments/!KGNoYXQp/connections/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/connections.segments/!KGNoYXQp/connections.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/connections.segments/!KGNoYXQp.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/connections.segments/_full.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/connections.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/connections.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1f49434f._.js +3 -0
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__51b79d66._.js → [root-of-the-server]__3a1fb665._.js} +6 -6
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__73947e32._.js +3 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__747722f0._.js +85 -0
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__ca89cb1f._.js +85 -0
- package/.next/standalone/.next/server/chunks/_26ec1867._.js +13 -13
- package/.next/standalone/.next/server/chunks/_430c5305._.js +13 -13
- package/.next/standalone/.next/server/chunks/_44fa1f03._.js +1 -1
- package/.next/standalone/.next/server/chunks/_75b542e9._.js +1 -1
- package/.next/standalone/.next/server/chunks/_82e2d86b._.js +11 -11
- package/.next/standalone/.next/server/chunks/_c49f2a1f._.js +13 -13
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__d8a3f2e3._.js → [root-of-the-server]__1ad22765._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__2534236b._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__77c3448a._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__85abb029._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__d2e81be0._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_119ae296._.js +12 -12
- package/.next/standalone/.next/server/chunks/ssr/_37f7f89d._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_components_connections_connections-page_tsx_a8fa3df0._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_components_knowledge-base_knowledge-base-page_tsx_10bf7f9a._.js +1 -1
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +2 -2
- package/.next/{static/chunks/b90a78e2d36034ff.js → standalone/.next/static/chunks/00f68930e8af39f1.js} +1 -1
- package/.next/standalone/.next/static/chunks/3bd88f74116ecf0b.js +1 -0
- package/.next/standalone/.next/static/chunks/89e492a83a4b53e3.js +1 -0
- package/.next/standalone/.next/static/chunks/{842e82429bd01d96.js → a3a8f6ede99c1c63.js} +1 -1
- package/.next/standalone/README.md +1 -1
- package/.next/standalone/package.json +1 -1
- package/.next/{standalone/.next/static/chunks/b90a78e2d36034ff.js → static/chunks/00f68930e8af39f1.js} +1 -1
- package/.next/static/chunks/3bd88f74116ecf0b.js +1 -0
- package/.next/static/chunks/89e492a83a4b53e3.js +1 -0
- package/.next/static/chunks/{842e82429bd01d96.js → a3a8f6ede99c1c63.js} +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__26852352._.js +0 -85
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__5dc46bc4._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__8992d6da._.js +0 -3
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__e474c328._.js +0 -85
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0e727499._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__4451526a._.js +0 -3
- package/.next/standalone/.next/static/chunks/000ce5d236847e14.js +0 -1
- package/.next/standalone/.next/static/chunks/7c8dab1a077d98e9.js +0 -1
- package/.next/static/chunks/000ce5d236847e14.js +0 -1
- package/.next/static/chunks/7c8dab1a077d98e9.js +0 -1
- /package/.next/standalone/.next/static/{H1e0tcZUy-dcOaNBJh3iW → MtWdFBWYBrNNpdc-evjbH}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{H1e0tcZUy-dcOaNBJh3iW → MtWdFBWYBrNNpdc-evjbH}/_clientMiddlewareManifest.json +0 -0
- /package/.next/standalone/.next/static/{H1e0tcZUy-dcOaNBJh3iW → MtWdFBWYBrNNpdc-evjbH}/_ssgManifest.js +0 -0
- /package/.next/static/{H1e0tcZUy-dcOaNBJh3iW → MtWdFBWYBrNNpdc-evjbH}/_buildManifest.js +0 -0
- /package/.next/static/{H1e0tcZUy-dcOaNBJh3iW → MtWdFBWYBrNNpdc-evjbH}/_clientMiddlewareManifest.json +0 -0
- /package/.next/static/{H1e0tcZUy-dcOaNBJh3iW → MtWdFBWYBrNNpdc-evjbH}/_ssgManifest.js +0 -0
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ To use AI for SQL generation and chat, you need to configure an AI provider:
|
|
|
49
49
|
6. **Restart** `sqlbot` for the changes to take effect.
|
|
50
50
|
|
|
51
51
|
> [!NOTE]
|
|
52
|
-
> Your API keys are stored securely in `~/.
|
|
52
|
+
> Your API keys are stored securely in `~/.sqlbot/ai-providers.json`.
|
|
53
53
|
|
|
54
54
|
### 2. Database Connections
|
|
55
55
|
Connect your databases to start querying in natural language:
|
package/package.json
CHANGED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
module.exports=[484199,(e,t,n)=>{"use strict";var a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,c={},i={VercelOidcTokenError:()=>u};for(var l in i)a(c,l,{get:i[l],enumerable:!0});t.exports=((e,t,n,c)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of s(t))r.call(e,n)||void 0===n||a(e,n,{get:()=>t[n],enumerable:!(c=o(t,n))||c.enumerable});return e})(a({},"__esModule",{value:!0}),c);class u extends Error{constructor(e,t){super(e),this.name="VercelOidcTokenError",this.cause=t}toString(){return this.cause?`${this.name}: ${this.message}: ${this.cause}`:`${this.name}: ${this.message}`}}},814747,(e,t,n)=>{t.exports=e.x("path",()=>require("path"))},522734,(e,t,n)=>{t.exports=e.x("fs",()=>require("fs"))},446786,(e,t,n)=>{t.exports=e.x("os",()=>require("os"))},666680,(e,t,n)=>{t.exports=e.x("node:crypto",()=>require("node:crypto"))},875398,e=>{"use strict";var t=e.i(666680);let n=new Uint8Array(256),a=n.length;function o(){return a>n.length-16&&((0,t.randomFillSync)(n),a=0),n.slice(a,a+=16)}let s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));let r={};function c(e,t,n,a,o=0){if(e.length<16)throw Error("Random bytes length must be >= 16");if(a){if(o<0||o+16>a.length)throw RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`)}else a=new Uint8Array(16),o=0;return t??=Date.now(),n??=127*e[6]<<24|e[7]<<16|e[8]<<8|e[9],a[o++]=t/0x10000000000&255,a[o++]=t/0x100000000&255,a[o++]=t/0x1000000&255,a[o++]=t/65536&255,a[o++]=t/256&255,a[o++]=255&t,a[o++]=112|n>>>28&15,a[o++]=n>>>20&255,a[o++]=128|n>>>14&63,a[o++]=n>>>6&255,a[o++]=n<<2&255|3&e[10],a[o++]=e[11],a[o++]=e[12],a[o++]=e[13],a[o++]=e[14],a[o++]=e[15],a}e.s(["v7",0,function(e,t,n){let a;if(e)a=c(e.random??e.rng?.()??o(),e.msecs,e.seq,t,n);else{var i,l,u;let e=Date.now(),s=o();i=r,l=e,u=s,i.msecs??=-1/0,i.seq??=0,l>i.msecs?(i.seq=u[6]<<23|u[7]<<16|u[8]<<8|u[9],i.msecs=l):(i.seq=i.seq+1|0,0===i.seq&&i.msecs++),a=c(s,r.msecs,r.seq,t,n)}return t??function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(a)}],875398)},230056,e=>e.a(async(t,n)=>{try{let t=await e.y("pg");e.n(t),n()}catch(e){n(e)}},!0),600177,e=>{"use strict";var t=e.i(522734),n=e.i(814747),a=e.i(446786),o=e.i(875398);let s=(0,n.join)((0,a.homedir)(),".config","clay"),r=(0,n.join)(s,"config.json");function c(){(0,t.mkdirSync)(s,{recursive:!0})}function i(){if(c(),!(0,t.existsSync)(r)){let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(r,JSON.stringify(e,null,2)),e}try{let e=(0,t.readFileSync)(r,"utf-8");return JSON.parse(e)}catch{let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(r,JSON.stringify(e,null,2)),e}}function l(e){c(),(0,t.writeFileSync)(r,JSON.stringify(e,null,2))}function u(){return i().connections}function m(e){return i().connections.find(t=>t.id===e)}function h(){let e=i();return e.activeConnectionId?e.connections.find(t=>t.id===e.activeConnectionId)??null:null}function d(){return i().activeConnectionId}function f(e){let t=i(),n=new Date().toISOString(),a={...e,id:(0,o.v7)(),createdAt:n,updatedAt:n};return t.connections.push(a),1===t.connections.length&&(t.activeConnectionId=a.id),l(t),a}function p(e,t){let n=i(),a=n.connections.findIndex(t=>t.id===e);return -1===a?null:(n.connections[a]={...n.connections[a],...t,updatedAt:new Date().toISOString()},l(n),n.connections[a])}function g(e){let t=i(),n=t.connections.findIndex(t=>t.id===e);return -1!==n&&(t.connections.splice(n,1),t.activeConnectionId===e&&(t.activeConnectionId=t.connections.length>0?t.connections[0].id:null),l(t),!0)}function b(e){let t=i();return!!t.connections.find(t=>t.id===e)&&(t.activeConnectionId=e,l(t),!0)}function y(e){return(0,n.join)(s,"csv-dbs",`${e}.db`)}function w(e,t){let n=i(),a=n.connections.findIndex(t=>t.id===e);return -1===a?null:(n.connections[a]={...n.connections[a],csvFiles:t,updatedAt:new Date().toISOString()},l(n),n.connections[a])}e.s(["addConnection",()=>f,"deleteConnection",()=>g,"getActiveConnection",()=>h,"getActiveConnectionId",()=>d,"getConnection",()=>m,"getConnections",()=>u,"getCsvDbPath",()=>y,"setActiveConnection",()=>b,"updateConnection",()=>p,"updateCsvFiles",()=>w])},393207,(e,t,n)=>{t.exports=e.x("@libsql/client",()=>require("@libsql/client"))},381165,e=>e.a(async(t,n)=>{try{var a=e.i(230056),o=e.i(600177),s=e.i(522734),r=t([a]);[a]=r.then?(await r)():r;let f=new Map;async function c(t){let n=(await e.A(959021)).createPool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectionLimit:5,waitForConnections:!0});return{warehouse:{async execute(e){let[t,a]=await n.execute(e);return{rows:t,fields:(a||[]).map(e=>({name:e.name,dataTypeID:e.columnType}))}}},cleanup:async()=>{await n.end()}}}async function i(t){let n,s;if(!(n=t?(0,o.getConnection)(t):(0,o.getActiveConnection)()))throw Error("No database connection configured. Please add a connection in the Connections page.");let r="sqlite"===n.type||"csv"===n.type?`${n.type}:${n.filePath||n.database||n.id}`:`${n.type}:${n.host}:${n.port}:${n.user}:${n.database}:${n.ssl}:${n.password}`,i=f.get(n.id);if(i&&i.connectionHash===r)return i.lastUsed=Date.now(),{db:i.warehouse,connection:n};if(i){try{await i.cleanup()}catch{}f.delete(n.id)}if("mysql"===n.type)s=await c(n);else if("sqlite"===n.type||"csv"===n.type)s=function(t){let n="csv"===t.type?(0,o.getCsvDbPath)(t.id):t.filePath||t.database;if(!n)throw Error("No database file path specified for SQLite connection.");let a=null;return{warehouse:{async execute(t){let o=(()=>{if(!a){let{createClient:t}=e.r(393207);a=t({url:`file:${n}`})}return a})(),s=await o.execute(t);return{rows:s.rows.map(e=>{let t={};for(let n of s.columns)t[n]=e[n];return t}),fields:s.columns.map(e=>({name:e}))}}},cleanup:async()=>{a&&(a.close?.(),a=null)}}}(n);else{let e;e=new a.Pool({host:n.host,port:n.port,user:n.user,password:n.password,database:n.database,ssl:n.ssl?{rejectUnauthorized:!1}:void 0,max:5,idleTimeoutMillis:3e5}),s={warehouse:{async execute(t){let n=await e.query(t);return{rows:n.rows,fields:n.fields.map(e=>({name:e.name,dataTypeID:e.dataTypeID}))}}},cleanup:async()=>{await e.end()}}}return f.set(n.id,{warehouse:s.warehouse,cleanup:s.cleanup,connectionHash:r,lastUsed:Date.now()}),{db:s.warehouse,connection:n}}async function l(t){let n=Date.now();try{if("sqlite"===t.type){let n=t.filePath||t.database;if(!n)throw Error("No file path specified");if(!(0,s.existsSync)(n))throw Error(`File not found: ${n}`);let{createClient:a}=e.r(393207),o=a({url:`file:${n}`});await o.execute("SELECT 1"),o.close()}else if("csv"===t.type){let n=t.id?(0,o.getCsvDbPath)(t.id):null;if(n&&(0,s.existsSync)(n)){let{createClient:t}=e.r(393207),a=t({url:`file:${n}`});await a.execute("SELECT 1"),a.close()}}else if("mysql"===t.type){let n=await e.A(959021),a=await n.createConnection({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectTimeout:1e4});await a.execute("SELECT 1"),await a.end()}else{let e=new a.Pool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,max:1,connectionTimeoutMillis:1e4}),n=await e.connect();await n.query("SELECT 1"),n.release(),await e.end()}return{success:!0,latencyMs:Date.now()-n}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e),latencyMs:Date.now()-n}}}function u(e){switch(e){case"redshift":return"Amazon Redshift SQL";case"postgresql":return"PostgreSQL";case"mysql":return"MySQL";case"sqlite":case"csv":return"SQLite"}}async function m(t,n,a){let s=(0,o.getCsvDbPath)(t),{mkdirSync:r}=e.r(522734),{dirname:c}=e.r(814747);r(c(s),{recursive:!0});let{createClient:i}=e.r(393207),l=i({url:`file:${s}`});try{let e=function(e){let t=[],n=[],a="",o=!1,s=0;for(;s<e.length;){let r=e[s];o?'"'===r?s+1<e.length&&'"'===e[s+1]?(a+='"',s+=2):(o=!1,s++):(a+=r,s++):'"'===r?(o=!0,s++):","===r?(n.push(a.trim()),a="",s++):"\r"===r||"\n"===r?(n.push(a.trim()),a="",n.some(e=>""!==e)&&t.push(n),n=[],"\r"===r&&s+1<e.length&&"\n"===e[s+1]?s+=2:s++):(a+=r,s++)}return(a||n.length>0)&&(n.push(a.trim()),n.some(e=>""!==e)&&t.push(n)),t}(n);if(e.length<2)throw Error("CSV must have a header row and at least one data row");let t=e[0],o=e.slice(1),s=d(a),r=t.map(d);await l.execute(`DROP TABLE IF EXISTS "${s}"`);let c=r.map((e,t)=>{var n;let a=(n=o.slice(0,20).map(e=>e[t]).filter(Boolean),0===n.length?"TEXT":n.every(e=>/^-?\d+$/.test(e))?"INTEGER":n.every(e=>/^-?\d+(\.\d+)?$/.test(e))?"REAL":"TEXT");return`"${e}" ${a}`});await l.execute(`CREATE TABLE "${s}" (${c.join(", ")})`);let i=0;for(let e=0;e<o.length;e+=500){let t=o.slice(e,e+500),n=t.map(()=>`(${r.map(()=>"?").join(", ")})`).join(", "),a=t.flatMap(e=>r.map((t,n)=>{let a=e[n];return null==a||""===a?null:a}));await l.execute({sql:`INSERT INTO "${s}" (${r.map(e=>`"${e}"`).join(", ")}) VALUES ${n}`,args:a}),i+=t.length}return l.close(),{rowCount:i,columns:r}}catch(e){throw l.close(),e}}async function h(t,n){let a=(0,o.getCsvDbPath)(t);if(!(0,s.existsSync)(a))return;let{createClient:r}=e.r(393207),c=r({url:`file:${a}`});await c.execute(`DROP TABLE IF EXISTS "${d(n)}"`),c.close()}function d(e){return e.replace(/[^\w\s]/g,"").replace(/\s+/g,"_").replace(/^(\d)/,"_$1").toLowerCase().slice(0,64)||"column"}e.s(["getDbDialect",()=>u,"getWarehouseDB",()=>i,"importCsvToSqlite",()=>m,"removeCsvTable",()=>h,"testConnection",()=>l]),n()}catch(e){n(e)}},!1),452886,e=>e.a(async(t,n)=>{try{var a=e.i(712075),o=e.i(469719),s=e.i(608056),r=e.i(381165),c=t([r]);async function i(e,t,n){let c=n||(()=>{}),{db:i,connection:u}=await (0,r.getWarehouseDB)(e),m=u.type,h=(0,r.getDbDialect)(m);c({type:"connecting",connectionName:u.name});let d=(await i.execute(function(e){switch(e){case"postgresql":case"redshift":return`
|
|
2
|
-
SELECT table_schema, table_name
|
|
3
|
-
FROM information_schema.tables
|
|
4
|
-
WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
5
|
-
AND table_type = 'BASE TABLE'
|
|
6
|
-
ORDER BY table_schema, table_name
|
|
7
|
-
LIMIT 50
|
|
8
|
-
`;case"mysql":return`
|
|
9
|
-
SELECT table_schema, table_name
|
|
10
|
-
FROM information_schema.tables
|
|
11
|
-
WHERE table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
|
|
12
|
-
AND table_type = 'BASE TABLE'
|
|
13
|
-
ORDER BY table_schema, table_name
|
|
14
|
-
LIMIT 50
|
|
15
|
-
`;case"sqlite":case"csv":return`
|
|
16
|
-
SELECT name AS table_name
|
|
17
|
-
FROM sqlite_master
|
|
18
|
-
WHERE type = 'table'
|
|
19
|
-
AND name NOT LIKE 'sqlite_%'
|
|
20
|
-
ORDER BY name
|
|
21
|
-
LIMIT 50
|
|
22
|
-
`;default:return"SELECT 1"}}(m))).rows.map(e=>({name:e.table_name||e.name,schema:e.table_schema}));if(0===d.length)return c({type:"no_tables"}),{entries:[],tablesExplored:0,connectionName:u.name};c({type:"tables_found",totalTables:d.length});let f=[];for(let e=0;e<d.length;e++){let t=d[e],n=t.schema?`${t.schema}.${t.name}`:t.name;c({type:"exploring_table",table:n,current:e+1,total:d.length});try{let a=await i.execute(function(e,t,n){switch(e){case"postgresql":case"redshift":return`
|
|
23
|
-
SELECT column_name, data_type, is_nullable, column_default,
|
|
24
|
-
character_maximum_length, numeric_precision
|
|
25
|
-
FROM information_schema.columns
|
|
26
|
-
WHERE table_name = '${t}'
|
|
27
|
-
${n?`AND table_schema = '${n}'`:""}
|
|
28
|
-
ORDER BY ordinal_position
|
|
29
|
-
`;case"mysql":return`
|
|
30
|
-
SELECT column_name, data_type, is_nullable, column_default,
|
|
31
|
-
character_maximum_length, numeric_precision, column_key, extra
|
|
32
|
-
FROM information_schema.columns
|
|
33
|
-
WHERE table_name = '${t}'
|
|
34
|
-
${n?`AND table_schema = '${n}'`:""}
|
|
35
|
-
ORDER BY ordinal_position
|
|
36
|
-
`;case"sqlite":case"csv":return`PRAGMA table_info("${t}")`;default:return"SELECT 1"}}(m,t.name,t.schema)),o=[],s=function(e,t,n){switch(e){case"postgresql":case"redshift":return`
|
|
37
|
-
SELECT
|
|
38
|
-
kcu.column_name,
|
|
39
|
-
ccu.table_schema AS foreign_table_schema,
|
|
40
|
-
ccu.table_name AS foreign_table_name,
|
|
41
|
-
ccu.column_name AS foreign_column_name
|
|
42
|
-
FROM information_schema.table_constraints tc
|
|
43
|
-
JOIN information_schema.key_column_usage kcu
|
|
44
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
45
|
-
JOIN information_schema.constraint_column_usage ccu
|
|
46
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
47
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
48
|
-
AND tc.table_name = '${t}'
|
|
49
|
-
${n?`AND tc.table_schema = '${n}'`:""}
|
|
50
|
-
`;case"mysql":return`
|
|
51
|
-
SELECT
|
|
52
|
-
column_name,
|
|
53
|
-
referenced_table_schema AS foreign_table_schema,
|
|
54
|
-
referenced_table_name AS foreign_table_name,
|
|
55
|
-
referenced_column_name AS foreign_column_name
|
|
56
|
-
FROM information_schema.key_column_usage
|
|
57
|
-
WHERE table_name = '${t}'
|
|
58
|
-
AND referenced_table_name IS NOT NULL
|
|
59
|
-
${n?`AND table_schema = '${n}'`:""}
|
|
60
|
-
`;case"sqlite":case"csv":return`PRAGMA foreign_key_list("${t}")`;default:return null}}(m,t.name,t.schema);if(s)try{o=(await i.execute(s)).rows}catch{}let r=[];try{r=(await i.execute(function(e,t,n){let a=n&&"sqlite"!==e&&"csv"!==e?`"${n}"."${t}"`:`"${t}"`;return`SELECT * FROM ${a} LIMIT 3`}(m,t.name,t.schema))).rows.slice(0,3)}catch{}let l=0;try{let e=await i.execute(function(e,t,n){let a=n&&"sqlite"!==e&&"csv"!==e?`"${n}"."${t}"`:`"${t}"`;return`SELECT COUNT(*) AS row_count FROM ${a}`}(m,t.name,t.schema));l=Number(e.rows[0]?.row_count||0)}catch{}f.push({name:t.name,schema:t.schema,fullName:n,columns:a.rows,foreignKeys:o,sampleRows:r,rowCount:l}),c({type:"table_done",table:n,current:e+1,total:d.length,columnCount:a.rows.length,rowCount:l})}catch(t){console.error(`Failed to explore table ${n}:`,t),c({type:"table_error",table:n,current:e+1,total:d.length})}}if(0===f.length)return{entries:[],tablesExplored:0,connectionName:u.name};let p=f.map(e=>{let t=e.columns.map(e=>{let t=e.column_name||e.name||"unknown",n=e.data_type||e.type||"unknown",a="YES"===e.is_nullable||0===e.notnull?"nullable":"not null",o=1===e.pk?" PRIMARY KEY":"",s=e.column_key?` (${e.column_key})`:"";return` ${t} ${n} ${a}${o}${s}`}).join("\n"),n=e.foreignKeys.length>0?` Foreign Keys:
|
|
61
|
-
${e.foreignKeys.map(e=>` ${e.column_name||e.from} → ${e.foreign_table_name||e.table}.${e.foreign_column_name||e.to}`).join("\n")}`:"",a=e.sampleRows.length>0?` Sample Data (${e.rowCount} total rows):
|
|
62
|
-
${JSON.stringify(e.sampleRows,null,2).split("\n").map(e=>` ${e}`).join("\n")}`:` (${e.rowCount} rows, no sample available)`;return`TABLE: ${e.fullName}
|
|
63
|
-
Columns:
|
|
64
|
-
${t}
|
|
65
|
-
${n}
|
|
66
|
-
${a}`}).join("\n\n---\n\n");c({type:"generating",tablesExplored:f.length});let g=(0,s.getModel)(t||"google-gemini-2.0-flash-001"),b=o.z.object({entries:o.z.array(o.z.object({title:o.z.string().describe("A concise title"),content:o.z.string().describe("Detailed knowledge for AI SQL queries")}))}),y=[];if(p.length<=15e3)c({type:"generating_batch",batch:1,totalBatches:1}),y=(await (0,a.generateObject)({model:g,schema:b,prompt:l(h,u.name,p)})).object.entries,c({type:"batch_done",batch:1,totalBatches:1,entriesFound:y.length});else{let e=[],t="";for(let n of f){let a=p.split("---").find(e=>e.includes(`TABLE: ${n.fullName}`))?.trim()||"";t.length+a.length>15e3?(t&&e.push(t),t=a):t+=(t?"\n\n---\n\n":"")+a}t&&e.push(t);for(let t=0;t<e.length;t++){c({type:"generating_batch",batch:t+1,totalBatches:e.length});let n=await (0,a.generateObject)({model:g,schema:b,prompt:l(h,u.name,e[t])});y.push(...n.object.entries),c({type:"batch_done",batch:t+1,totalBatches:e.length,entriesFound:n.object.entries.length,totalEntries:y.length})}}return{entries:y,tablesExplored:f.length,connectionName:u.name}}function l(e,t,n){return`You are a database knowledge extraction agent. Analyze the following ${e} database schema for connection "${t}" and generate comprehensive knowledge base entries.
|
|
67
|
-
|
|
68
|
-
Your goal: create knowledge entries that would help an AI assistant write better SQL queries against this database.
|
|
69
|
-
|
|
70
|
-
For each entry, focus on:
|
|
71
|
-
1. **Table purposes** — What each table is for, what entity it represents
|
|
72
|
-
2. **Column meanings** — Non-obvious column names, what values mean
|
|
73
|
-
3. **Relationships** — How tables relate to each other (foreign keys, join patterns)
|
|
74
|
-
4. **Data patterns** — Enum values observed in sample data, status codes, date formats
|
|
75
|
-
5. **Business rules** — Any business logic implied by the schema (e.g. soft deletes, computed fields)
|
|
76
|
-
6. **Naming conventions** — Schema-wide patterns in naming
|
|
77
|
-
7. **Important notes** — Anything an AI should know to avoid common mistakes
|
|
78
|
-
|
|
79
|
-
Create at least one entry per table and additional entries for cross-cutting concerns.
|
|
80
|
-
Each entry should be self-contained and useful on its own.
|
|
81
|
-
|
|
82
|
-
Database Schema:
|
|
83
|
-
${n}`}[r]=c.then?(await c)():c,e.s(["exploreDatabase",()=>i]),n()}catch(e){n(e)}},!1)];
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__26852352._.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
module.exports=[918622,(e,t,n)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},556704,(e,t,n)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},832319,(e,t,n)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},193695,(e,t,n)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},814747,(e,t,n)=>{t.exports=e.x("path",()=>require("path"))},522734,(e,t,n)=>{t.exports=e.x("fs",()=>require("fs"))},446786,(e,t,n)=>{t.exports=e.x("os",()=>require("os"))},666680,(e,t,n)=>{t.exports=e.x("node:crypto",()=>require("node:crypto"))},581988,e=>e.a(async(t,n)=>{try{let t=await e.y("@libsql/client");e.n(t),n()}catch(e){n(e)}},!0),484199,(e,t,n)=>{"use strict";var r=Object.defineProperty,s=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,a={},c={VercelOidcTokenError:()=>u};for(var l in c)r(a,l,{get:c[l],enumerable:!0});t.exports=((e,t,n,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of o(t))i.call(e,n)||void 0===n||r(e,n,{get:()=>t[n],enumerable:!(a=s(t,n))||a.enumerable});return e})(r({},"__esModule",{value:!0}),a);class u extends Error{constructor(e,t){super(e),this.name="VercelOidcTokenError",this.cause=t}toString(){return this.cause?`${this.name}: ${this.message}: ${this.cause}`:`${this.name}: ${this.message}`}}},875398,e=>{"use strict";var t=e.i(666680);let n=new Uint8Array(256),r=n.length;function s(){return r>n.length-16&&((0,t.randomFillSync)(n),r=0),n.slice(r,r+=16)}let o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let i={};function a(e,t,n,r,s=0){if(e.length<16)throw Error("Random bytes length must be >= 16");if(r){if(s<0||s+16>r.length)throw RangeError(`UUID byte range ${s}:${s+15} is out of buffer bounds`)}else r=new Uint8Array(16),s=0;return t??=Date.now(),n??=127*e[6]<<24|e[7]<<16|e[8]<<8|e[9],r[s++]=t/0x10000000000&255,r[s++]=t/0x100000000&255,r[s++]=t/0x1000000&255,r[s++]=t/65536&255,r[s++]=t/256&255,r[s++]=255&t,r[s++]=112|n>>>28&15,r[s++]=n>>>20&255,r[s++]=128|n>>>14&63,r[s++]=n>>>6&255,r[s++]=n<<2&255|3&e[10],r[s++]=e[11],r[s++]=e[12],r[s++]=e[13],r[s++]=e[14],r[s++]=e[15],r}e.s(["v7",0,function(e,t,n){let r;if(e)r=a(e.random??e.rng?.()??s(),e.msecs,e.seq,t,n);else{var c,l,u;let e=Date.now(),o=s();c=i,l=e,u=o,c.msecs??=-1/0,c.seq??=0,l>c.msecs?(c.seq=u[6]<<23|u[7]<<16|u[8]<<8|u[9],c.msecs=l):(c.seq=c.seq+1|0,0===c.seq&&c.msecs++),r=a(o,i.msecs,i.seq,t,n)}return t??function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(r)}],875398)},230056,e=>e.a(async(t,n)=>{try{let t=await e.y("pg");e.n(t),n()}catch(e){n(e)}},!0),600177,e=>{"use strict";var t=e.i(522734),n=e.i(814747),r=e.i(446786),s=e.i(875398);let o=(0,n.join)((0,r.homedir)(),".config","clay"),i=(0,n.join)(o,"config.json");function a(){(0,t.mkdirSync)(o,{recursive:!0})}function c(){if(a(),!(0,t.existsSync)(i)){let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(i,JSON.stringify(e,null,2)),e}try{let e=(0,t.readFileSync)(i,"utf-8");return JSON.parse(e)}catch{let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(i,JSON.stringify(e,null,2)),e}}function l(e){a(),(0,t.writeFileSync)(i,JSON.stringify(e,null,2))}function u(){return c().connections}function d(e){return c().connections.find(t=>t.id===e)}function p(){let e=c();return e.activeConnectionId?e.connections.find(t=>t.id===e.activeConnectionId)??null:null}function f(){return c().activeConnectionId}function h(e){let t=c(),n=new Date().toISOString(),r={...e,id:(0,s.v7)(),createdAt:n,updatedAt:n};return t.connections.push(r),1===t.connections.length&&(t.activeConnectionId=r.id),l(t),r}function w(e,t){let n=c(),r=n.connections.findIndex(t=>t.id===e);return -1===r?null:(n.connections[r]={...n.connections[r],...t,updatedAt:new Date().toISOString()},l(n),n.connections[r])}function y(e){let t=c(),n=t.connections.findIndex(t=>t.id===e);return -1!==n&&(t.connections.splice(n,1),t.activeConnectionId===e&&(t.activeConnectionId=t.connections.length>0?t.connections[0].id:null),l(t),!0)}function m(e){let t=c();return!!t.connections.find(t=>t.id===e)&&(t.activeConnectionId=e,l(t),!0)}function v(e){return(0,n.join)(o,"csv-dbs",`${e}.db`)}function g(e,t){let n=c(),r=n.connections.findIndex(t=>t.id===e);return -1===r?null:(n.connections[r]={...n.connections[r],csvFiles:t,updatedAt:new Date().toISOString()},l(n),n.connections[r])}e.s(["addConnection",()=>h,"deleteConnection",()=>y,"getActiveConnection",()=>p,"getActiveConnectionId",()=>f,"getConnection",()=>d,"getConnections",()=>u,"getCsvDbPath",()=>v,"setActiveConnection",()=>m,"updateConnection",()=>w,"updateCsvFiles",()=>g])},393207,(e,t,n)=>{t.exports=e.x("@libsql/client",()=>require("@libsql/client"))},381165,e=>e.a(async(t,n)=>{try{var r=e.i(230056),s=e.i(600177),o=e.i(522734),i=t([r]);[r]=i.then?(await i)():i;let h=new Map;async function a(t){let n=(await e.A(959021)).createPool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectionLimit:5,waitForConnections:!0});return{warehouse:{async execute(e){let[t,r]=await n.execute(e);return{rows:t,fields:(r||[]).map(e=>({name:e.name,dataTypeID:e.columnType}))}}},cleanup:async()=>{await n.end()}}}async function c(t){let n,o;if(!(n=t?(0,s.getConnection)(t):(0,s.getActiveConnection)()))throw Error("No database connection configured. Please add a connection in the Connections page.");let i="sqlite"===n.type||"csv"===n.type?`${n.type}:${n.filePath||n.database||n.id}`:`${n.type}:${n.host}:${n.port}:${n.user}:${n.database}:${n.ssl}:${n.password}`,c=h.get(n.id);if(c&&c.connectionHash===i)return c.lastUsed=Date.now(),{db:c.warehouse,connection:n};if(c){try{await c.cleanup()}catch{}h.delete(n.id)}if("mysql"===n.type)o=await a(n);else if("sqlite"===n.type||"csv"===n.type)o=function(t){let n="csv"===t.type?(0,s.getCsvDbPath)(t.id):t.filePath||t.database;if(!n)throw Error("No database file path specified for SQLite connection.");let r=null;return{warehouse:{async execute(t){let s=(()=>{if(!r){let{createClient:t}=e.r(393207);r=t({url:`file:${n}`})}return r})(),o=await s.execute(t);return{rows:o.rows.map(e=>{let t={};for(let n of o.columns)t[n]=e[n];return t}),fields:o.columns.map(e=>({name:e}))}}},cleanup:async()=>{r&&(r.close?.(),r=null)}}}(n);else{let e;e=new r.Pool({host:n.host,port:n.port,user:n.user,password:n.password,database:n.database,ssl:n.ssl?{rejectUnauthorized:!1}:void 0,max:5,idleTimeoutMillis:3e5}),o={warehouse:{async execute(t){let n=await e.query(t);return{rows:n.rows,fields:n.fields.map(e=>({name:e.name,dataTypeID:e.dataTypeID}))}}},cleanup:async()=>{await e.end()}}}return h.set(n.id,{warehouse:o.warehouse,cleanup:o.cleanup,connectionHash:i,lastUsed:Date.now()}),{db:o.warehouse,connection:n}}async function l(t){let n=Date.now();try{if("sqlite"===t.type){let n=t.filePath||t.database;if(!n)throw Error("No file path specified");if(!(0,o.existsSync)(n))throw Error(`File not found: ${n}`);let{createClient:r}=e.r(393207),s=r({url:`file:${n}`});await s.execute("SELECT 1"),s.close()}else if("csv"===t.type){let n=t.id?(0,s.getCsvDbPath)(t.id):null;if(n&&(0,o.existsSync)(n)){let{createClient:t}=e.r(393207),r=t({url:`file:${n}`});await r.execute("SELECT 1"),r.close()}}else if("mysql"===t.type){let n=await e.A(959021),r=await n.createConnection({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectTimeout:1e4});await r.execute("SELECT 1"),await r.end()}else{let e=new r.Pool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,max:1,connectionTimeoutMillis:1e4}),n=await e.connect();await n.query("SELECT 1"),n.release(),await e.end()}return{success:!0,latencyMs:Date.now()-n}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e),latencyMs:Date.now()-n}}}function u(e){switch(e){case"redshift":return"Amazon Redshift SQL";case"postgresql":return"PostgreSQL";case"mysql":return"MySQL";case"sqlite":case"csv":return"SQLite"}}async function d(t,n,r){let o=(0,s.getCsvDbPath)(t),{mkdirSync:i}=e.r(522734),{dirname:a}=e.r(814747);i(a(o),{recursive:!0});let{createClient:c}=e.r(393207),l=c({url:`file:${o}`});try{let e=function(e){let t=[],n=[],r="",s=!1,o=0;for(;o<e.length;){let i=e[o];s?'"'===i?o+1<e.length&&'"'===e[o+1]?(r+='"',o+=2):(s=!1,o++):(r+=i,o++):'"'===i?(s=!0,o++):","===i?(n.push(r.trim()),r="",o++):"\r"===i||"\n"===i?(n.push(r.trim()),r="",n.some(e=>""!==e)&&t.push(n),n=[],"\r"===i&&o+1<e.length&&"\n"===e[o+1]?o+=2:o++):(r+=i,o++)}return(r||n.length>0)&&(n.push(r.trim()),n.some(e=>""!==e)&&t.push(n)),t}(n);if(e.length<2)throw Error("CSV must have a header row and at least one data row");let t=e[0],s=e.slice(1),o=f(r),i=t.map(f);await l.execute(`DROP TABLE IF EXISTS "${o}"`);let a=i.map((e,t)=>{var n;let r=(n=s.slice(0,20).map(e=>e[t]).filter(Boolean),0===n.length?"TEXT":n.every(e=>/^-?\d+$/.test(e))?"INTEGER":n.every(e=>/^-?\d+(\.\d+)?$/.test(e))?"REAL":"TEXT");return`"${e}" ${r}`});await l.execute(`CREATE TABLE "${o}" (${a.join(", ")})`);let c=0;for(let e=0;e<s.length;e+=500){let t=s.slice(e,e+500),n=t.map(()=>`(${i.map(()=>"?").join(", ")})`).join(", "),r=t.flatMap(e=>i.map((t,n)=>{let r=e[n];return null==r||""===r?null:r}));await l.execute({sql:`INSERT INTO "${o}" (${i.map(e=>`"${e}"`).join(", ")}) VALUES ${n}`,args:r}),c+=t.length}return l.close(),{rowCount:c,columns:i}}catch(e){throw l.close(),e}}async function p(t,n){let r=(0,s.getCsvDbPath)(t);if(!(0,o.existsSync)(r))return;let{createClient:i}=e.r(393207),a=i({url:`file:${r}`});await a.execute(`DROP TABLE IF EXISTS "${f(n)}"`),a.close()}function f(e){return e.replace(/[^\w\s]/g,"").replace(/\s+/g,"_").replace(/^(\d)/,"_$1").toLowerCase().slice(0,64)||"column"}e.s(["getDbDialect",()=>u,"getWarehouseDB",()=>c,"importCsvToSqlite",()=>d,"removeCsvTable",()=>p,"testConnection",()=>l]),n()}catch(e){n(e)}},!1),967030,e=>{e.v(t=>Promise.all(["server/chunks/node_modules_@vercel_oidc_dist_7c2bef69._.js"].map(t=>e.l(t))).then(()=>t(783697)))},683671,e=>{e.v(t=>Promise.all(["server/chunks/node_modules_@vercel_oidc_dist_7fd3d757._.js"].map(t=>e.l(t))).then(()=>t(390391)))},959021,e=>{e.v(t=>Promise.all(["server/chunks/[root-of-the-server]__d85d916d._.js","server/chunks/[root-of-the-server]__e0f10449._.js"].map(t=>e.l(t))).then(()=>t(822244)))}];
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__5dc46bc4._.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
module.exports=[918622,(e,t,n)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},556704,(e,t,n)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},832319,(e,t,n)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},193695,(e,t,n)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},814747,(e,t,n)=>{t.exports=e.x("path",()=>require("path"))},522734,(e,t,n)=>{t.exports=e.x("fs",()=>require("fs"))},446786,(e,t,n)=>{t.exports=e.x("os",()=>require("os"))},666680,(e,t,n)=>{t.exports=e.x("node:crypto",()=>require("node:crypto"))},581988,e=>e.a(async(t,n)=>{try{let t=await e.y("@libsql/client");e.n(t),n()}catch(e){n(e)}},!0),875398,e=>{"use strict";var t=e.i(666680);let n=new Uint8Array(256),r=n.length;function a(){return r>n.length-16&&((0,t.randomFillSync)(n),r=0),n.slice(r,r+=16)}let o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let s={};function i(e,t,n,r,a=0){if(e.length<16)throw Error("Random bytes length must be >= 16");if(r){if(a<0||a+16>r.length)throw RangeError(`UUID byte range ${a}:${a+15} is out of buffer bounds`)}else r=new Uint8Array(16),a=0;return t??=Date.now(),n??=127*e[6]<<24|e[7]<<16|e[8]<<8|e[9],r[a++]=t/0x10000000000&255,r[a++]=t/0x100000000&255,r[a++]=t/0x1000000&255,r[a++]=t/65536&255,r[a++]=t/256&255,r[a++]=255&t,r[a++]=112|n>>>28&15,r[a++]=n>>>20&255,r[a++]=128|n>>>14&63,r[a++]=n>>>6&255,r[a++]=n<<2&255|3&e[10],r[a++]=e[11],r[a++]=e[12],r[a++]=e[13],r[a++]=e[14],r[a++]=e[15],r}e.s(["v7",0,function(e,t,n){let r;if(e)r=i(e.random??e.rng?.()??a(),e.msecs,e.seq,t,n);else{var l,c,u;let e=Date.now(),o=a();l=s,c=e,u=o,l.msecs??=-1/0,l.seq??=0,c>l.msecs?(l.seq=u[6]<<23|u[7]<<16|u[8]<<8|u[9],l.msecs=c):(l.seq=l.seq+1|0,0===l.seq&&l.msecs++),r=i(o,s.msecs,s.seq,t,n)}return t??function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(r)}],875398)},230056,e=>e.a(async(t,n)=>{try{let t=await e.y("pg");e.n(t),n()}catch(e){n(e)}},!0),600177,e=>{"use strict";var t=e.i(522734),n=e.i(814747),r=e.i(446786),a=e.i(875398);let o=(0,n.join)((0,r.homedir)(),".config","clay"),s=(0,n.join)(o,"config.json");function i(){(0,t.mkdirSync)(o,{recursive:!0})}function l(){if(i(),!(0,t.existsSync)(s)){let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(s,JSON.stringify(e,null,2)),e}try{let e=(0,t.readFileSync)(s,"utf-8");return JSON.parse(e)}catch{let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(s,JSON.stringify(e,null,2)),e}}function c(e){i(),(0,t.writeFileSync)(s,JSON.stringify(e,null,2))}function u(){return l().connections}function d(e){return l().connections.find(t=>t.id===e)}function p(){let e=l();return e.activeConnectionId?e.connections.find(t=>t.id===e.activeConnectionId)??null:null}function h(){return l().activeConnectionId}function f(e){let t=l(),n=new Date().toISOString(),r={...e,id:(0,a.v7)(),createdAt:n,updatedAt:n};return t.connections.push(r),1===t.connections.length&&(t.activeConnectionId=r.id),c(t),r}function w(e,t){let n=l(),r=n.connections.findIndex(t=>t.id===e);return -1===r?null:(n.connections[r]={...n.connections[r],...t,updatedAt:new Date().toISOString()},c(n),n.connections[r])}function y(e){let t=l(),n=t.connections.findIndex(t=>t.id===e);return -1!==n&&(t.connections.splice(n,1),t.activeConnectionId===e&&(t.activeConnectionId=t.connections.length>0?t.connections[0].id:null),c(t),!0)}function v(e){let t=l();return!!t.connections.find(t=>t.id===e)&&(t.activeConnectionId=e,c(t),!0)}function g(e){return(0,n.join)(o,"csv-dbs",`${e}.db`)}function m(e,t){let n=l(),r=n.connections.findIndex(t=>t.id===e);return -1===r?null:(n.connections[r]={...n.connections[r],csvFiles:t,updatedAt:new Date().toISOString()},c(n),n.connections[r])}e.s(["addConnection",()=>f,"deleteConnection",()=>y,"getActiveConnection",()=>p,"getActiveConnectionId",()=>h,"getConnection",()=>d,"getConnections",()=>u,"getCsvDbPath",()=>g,"setActiveConnection",()=>v,"updateConnection",()=>w,"updateCsvFiles",()=>m])},393207,(e,t,n)=>{t.exports=e.x("@libsql/client",()=>require("@libsql/client"))},381165,e=>e.a(async(t,n)=>{try{var r=e.i(230056),a=e.i(600177),o=e.i(522734),s=t([r]);[r]=s.then?(await s)():s;let f=new Map;async function i(t){let n=(await e.A(959021)).createPool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectionLimit:5,waitForConnections:!0});return{warehouse:{async execute(e){let[t,r]=await n.execute(e);return{rows:t,fields:(r||[]).map(e=>({name:e.name,dataTypeID:e.columnType}))}}},cleanup:async()=>{await n.end()}}}async function l(t){let n,o;if(!(n=t?(0,a.getConnection)(t):(0,a.getActiveConnection)()))throw Error("No database connection configured. Please add a connection in the Connections page.");let s="sqlite"===n.type||"csv"===n.type?`${n.type}:${n.filePath||n.database||n.id}`:`${n.type}:${n.host}:${n.port}:${n.user}:${n.database}:${n.ssl}:${n.password}`,l=f.get(n.id);if(l&&l.connectionHash===s)return l.lastUsed=Date.now(),{db:l.warehouse,connection:n};if(l){try{await l.cleanup()}catch{}f.delete(n.id)}if("mysql"===n.type)o=await i(n);else if("sqlite"===n.type||"csv"===n.type)o=function(t){let n="csv"===t.type?(0,a.getCsvDbPath)(t.id):t.filePath||t.database;if(!n)throw Error("No database file path specified for SQLite connection.");let r=null;return{warehouse:{async execute(t){let a=(()=>{if(!r){let{createClient:t}=e.r(393207);r=t({url:`file:${n}`})}return r})(),o=await a.execute(t);return{rows:o.rows.map(e=>{let t={};for(let n of o.columns)t[n]=e[n];return t}),fields:o.columns.map(e=>({name:e}))}}},cleanup:async()=>{r&&(r.close?.(),r=null)}}}(n);else{let e;e=new r.Pool({host:n.host,port:n.port,user:n.user,password:n.password,database:n.database,ssl:n.ssl?{rejectUnauthorized:!1}:void 0,max:5,idleTimeoutMillis:3e5}),o={warehouse:{async execute(t){let n=await e.query(t);return{rows:n.rows,fields:n.fields.map(e=>({name:e.name,dataTypeID:e.dataTypeID}))}}},cleanup:async()=>{await e.end()}}}return f.set(n.id,{warehouse:o.warehouse,cleanup:o.cleanup,connectionHash:s,lastUsed:Date.now()}),{db:o.warehouse,connection:n}}async function c(t){let n=Date.now();try{if("sqlite"===t.type){let n=t.filePath||t.database;if(!n)throw Error("No file path specified");if(!(0,o.existsSync)(n))throw Error(`File not found: ${n}`);let{createClient:r}=e.r(393207),a=r({url:`file:${n}`});await a.execute("SELECT 1"),a.close()}else if("csv"===t.type){let n=t.id?(0,a.getCsvDbPath)(t.id):null;if(n&&(0,o.existsSync)(n)){let{createClient:t}=e.r(393207),r=t({url:`file:${n}`});await r.execute("SELECT 1"),r.close()}}else if("mysql"===t.type){let n=await e.A(959021),r=await n.createConnection({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectTimeout:1e4});await r.execute("SELECT 1"),await r.end()}else{let e=new r.Pool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,max:1,connectionTimeoutMillis:1e4}),n=await e.connect();await n.query("SELECT 1"),n.release(),await e.end()}return{success:!0,latencyMs:Date.now()-n}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e),latencyMs:Date.now()-n}}}function u(e){switch(e){case"redshift":return"Amazon Redshift SQL";case"postgresql":return"PostgreSQL";case"mysql":return"MySQL";case"sqlite":case"csv":return"SQLite"}}async function d(t,n,r){let o=(0,a.getCsvDbPath)(t),{mkdirSync:s}=e.r(522734),{dirname:i}=e.r(814747);s(i(o),{recursive:!0});let{createClient:l}=e.r(393207),c=l({url:`file:${o}`});try{let e=function(e){let t=[],n=[],r="",a=!1,o=0;for(;o<e.length;){let s=e[o];a?'"'===s?o+1<e.length&&'"'===e[o+1]?(r+='"',o+=2):(a=!1,o++):(r+=s,o++):'"'===s?(a=!0,o++):","===s?(n.push(r.trim()),r="",o++):"\r"===s||"\n"===s?(n.push(r.trim()),r="",n.some(e=>""!==e)&&t.push(n),n=[],"\r"===s&&o+1<e.length&&"\n"===e[o+1]?o+=2:o++):(r+=s,o++)}return(r||n.length>0)&&(n.push(r.trim()),n.some(e=>""!==e)&&t.push(n)),t}(n);if(e.length<2)throw Error("CSV must have a header row and at least one data row");let t=e[0],a=e.slice(1),o=h(r),s=t.map(h);await c.execute(`DROP TABLE IF EXISTS "${o}"`);let i=s.map((e,t)=>{var n;let r=(n=a.slice(0,20).map(e=>e[t]).filter(Boolean),0===n.length?"TEXT":n.every(e=>/^-?\d+$/.test(e))?"INTEGER":n.every(e=>/^-?\d+(\.\d+)?$/.test(e))?"REAL":"TEXT");return`"${e}" ${r}`});await c.execute(`CREATE TABLE "${o}" (${i.join(", ")})`);let l=0;for(let e=0;e<a.length;e+=500){let t=a.slice(e,e+500),n=t.map(()=>`(${s.map(()=>"?").join(", ")})`).join(", "),r=t.flatMap(e=>s.map((t,n)=>{let r=e[n];return null==r||""===r?null:r}));await c.execute({sql:`INSERT INTO "${o}" (${s.map(e=>`"${e}"`).join(", ")}) VALUES ${n}`,args:r}),l+=t.length}return c.close(),{rowCount:l,columns:s}}catch(e){throw c.close(),e}}async function p(t,n){let r=(0,a.getCsvDbPath)(t);if(!(0,o.existsSync)(r))return;let{createClient:s}=e.r(393207),i=s({url:`file:${r}`});await i.execute(`DROP TABLE IF EXISTS "${h(n)}"`),i.close()}function h(e){return e.replace(/[^\w\s]/g,"").replace(/\s+/g,"_").replace(/^(\d)/,"_$1").toLowerCase().slice(0,64)||"column"}e.s(["getDbDialect",()=>u,"getWarehouseDB",()=>l,"importCsvToSqlite",()=>d,"removeCsvTable",()=>p,"testConnection",()=>c]),n()}catch(e){n(e)}},!1),531233,e=>e.a(async(t,n)=>{try{var r=e.i(679371),a=e.i(381165),o=t([r,a]);async function s(){let e=new Date().toISOString(),t=process.uptime(),n="ok",o="ok";try{await r.rawClient.execute("SELECT 1")}catch(e){console.error("Database health check failed:",e),n="error"}try{let{db:e}=await (0,a.getWarehouseDB)();await e.execute("SELECT 1")}catch(e){console.error("Warehouse health check failed:",e),o="error"}let s="ok"===n&&"ok"===o?"ok":"error";return new Response(JSON.stringify({status:s,timestamp:e,uptime:`${Math.floor(t)}s`,checks:{database:n,warehouse:o}}),{status:"ok"===s?200:503,headers:{"Content-Type":"application/json"}})}[r,a]=o.then?(await o)():o,e.s(["GET",()=>s]),n()}catch(e){n(e)}},!1),243007,e=>e.a(async(t,n)=>{try{var r=e.i(747909),a=e.i(174017),o=e.i(996250),s=e.i(759756),i=e.i(561916),l=e.i(114444),c=e.i(837092),u=e.i(869741),d=e.i(316795),p=e.i(487718),h=e.i(995169),f=e.i(47587),w=e.i(666012),y=e.i(570101),v=e.i(626937),g=e.i(10372),m=e.i(193695);e.i(52474);var x=e.i(600220),C=e.i(531233),E=t([C]);[C]=E.then?(await E)():E;let b=new r.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/health/route",pathname:"/api/health",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/health/route.ts",nextConfigOutput:"standalone",userland:C}),{workAsyncStorage:T,workUnitAsyncStorage:A,serverHooks:q}=b;function R(){return(0,o.patchFetch)({workAsyncStorage:T,workUnitAsyncStorage:A})}async function S(e,t,n){b.isDev&&(0,s.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let r="/api/health/route";r=r.replace(/\/index$/,"")||"/";let o=await b.prepare(e,t,{srcPage:r,multiZoneDraftMode:!1});if(!o)return t.statusCode=400,t.end("Bad Request"),null==n.waitUntil||n.waitUntil.call(n,Promise.resolve()),null;let{buildId:C,params:E,nextConfig:R,parsedUrl:S,isDraftMode:T,prerenderManifest:A,routerServerContext:q,isOnDemandRevalidate:I,revalidateOnlyGenerated:$,resolvedPathname:D,clientReferenceManifest:P,serverActionsManifest:N}=o,O=(0,u.normalizeAppPath)(r),k=!!(A.dynamicRoutes[O]||A.routes[D]),j=async()=>((null==q?void 0:q.render404)?await q.render404(e,t,S,!1):t.end("This page could not be found"),null);if(k&&!T){let e=!!A.routes[D],t=A.dynamicRoutes[O];if(t&&!1===t.fallback&&!e){if(R.experimental.adapterPath)return await j();throw new m.NoFallbackError}}let _=null;!k||b.isDev||T||(_=D,_="/index"===_?"/":_);let U=!0===b.isDev||!k,L=k&&!U;N&&P&&(0,l.setReferenceManifestsSingleton)({page:r,clientReferenceManifest:P,serverActionsManifest:N,serverModuleMap:(0,c.createServerModuleMap)({serverActionsManifest:N})});let M=e.method||"GET",H=(0,i.getTracer)(),F=H.getActiveScopeSpan(),B={params:E,prerenderManifest:A,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:U,incrementalCache:(0,s.getRequestMeta)(e,"incrementalCache"),cacheLifeProfiles:R.cacheLife,waitUntil:n.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,n,r)=>b.onRequestError(e,t,r,q)},sharedContext:{buildId:C}},K=new d.NodeNextRequest(e),X=new d.NodeNextResponse(t),z=p.NextRequestAdapter.fromNodeNextRequest(K,(0,p.signalFromNodeResponse)(t));try{let o=async e=>b.handle(z,B).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let n=H.getRootSpanAttributes();if(!n)return;if(n.get("next.span_type")!==h.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${n.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=n.get("next.route");if(a){let t=`${M} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t)}else e.updateName(`${M} ${r}`)}),l=!!(0,s.getRequestMeta)(e,"minimalMode"),c=async s=>{var i,c;let u=async({previousCacheEntry:a})=>{try{if(!l&&I&&$&&!a)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let r=await o(s);e.fetchMetrics=B.renderOpts.fetchMetrics;let i=B.renderOpts.pendingWaitUntil;i&&n.waitUntil&&(n.waitUntil(i),i=void 0);let c=B.renderOpts.collectedTags;if(!k)return await (0,w.sendResponse)(K,X,r,B.renderOpts.pendingWaitUntil),null;{let e=await r.blob(),t=(0,y.toNodeOutgoingHttpHeaders)(r.headers);c&&(t[g.NEXT_CACHE_TAGS_HEADER]=c),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let n=void 0!==B.renderOpts.collectedRevalidate&&!(B.renderOpts.collectedRevalidate>=g.INFINITE_CACHE)&&B.renderOpts.collectedRevalidate,a=void 0===B.renderOpts.collectedExpire||B.renderOpts.collectedExpire>=g.INFINITE_CACHE?void 0:B.renderOpts.collectedExpire;return{value:{kind:x.CachedRouteKind.APP_ROUTE,status:r.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:n,expire:a}}}}catch(t){throw(null==a?void 0:a.isStale)&&await b.onRequestError(e,t,{routerKind:"App Router",routePath:r,routeType:"route",revalidateReason:(0,f.getRevalidateReason)({isStaticGeneration:L,isOnDemandRevalidate:I})},q),t}},d=await b.handleResponse({req:e,nextConfig:R,cacheKey:_,routeKind:a.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:A,isRoutePPREnabled:!1,isOnDemandRevalidate:I,revalidateOnlyGenerated:$,responseGenerator:u,waitUntil:n.waitUntil,isMinimalMode:l});if(!k)return null;if((null==d||null==(i=d.value)?void 0:i.kind)!==x.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==d||null==(c=d.value)?void 0:c.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});l||t.setHeader("x-nextjs-cache",I?"REVALIDATED":d.isMiss?"MISS":d.isStale?"STALE":"HIT"),T&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let p=(0,y.fromNodeOutgoingHttpHeaders)(d.value.headers);return l&&k||p.delete(g.NEXT_CACHE_TAGS_HEADER),!d.cacheControl||t.getHeader("Cache-Control")||p.get("Cache-Control")||p.set("Cache-Control",(0,v.getCacheControlHeader)(d.cacheControl)),await (0,w.sendResponse)(K,X,new Response(d.value.body,{headers:p,status:d.value.status||200})),null};F?await c(F):await H.withPropagatedContext(e.headers,()=>H.trace(h.BaseServerSpan.handleRequest,{spanName:`${M} ${r}`,kind:i.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},c))}catch(t){if(t instanceof m.NoFallbackError||await b.onRequestError(e,t,{routerKind:"App Router",routePath:O,routeType:"route",revalidateReason:(0,f.getRevalidateReason)({isStaticGeneration:L,isOnDemandRevalidate:I})}),k)throw t;return await (0,w.sendResponse)(K,X,new Response(null,{status:500})),null}}e.s(["handler",()=>S,"patchFetch",()=>R,"routeModule",()=>b,"serverHooks",()=>q,"workAsyncStorage",()=>T,"workUnitAsyncStorage",()=>A]),n()}catch(e){n(e)}},!1),959021,e=>{e.v(t=>Promise.all(["server/chunks/[root-of-the-server]__d85d916d._.js","server/chunks/[root-of-the-server]__e0f10449._.js"].map(t=>e.l(t))).then(()=>t(822244)))}];
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__8992d6da._.js.map
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
module.exports=[484199,(e,t,n)=>{"use strict";var a=Object.defineProperty,s=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,c={},i={VercelOidcTokenError:()=>u};for(var l in i)a(c,l,{get:i[l],enumerable:!0});t.exports=((e,t,n,c)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of o(t))r.call(e,n)||void 0===n||a(e,n,{get:()=>t[n],enumerable:!(c=s(t,n))||c.enumerable});return e})(a({},"__esModule",{value:!0}),c);class u extends Error{constructor(e,t){super(e),this.name="VercelOidcTokenError",this.cause=t}toString(){return this.cause?`${this.name}: ${this.message}: ${this.cause}`:`${this.name}: ${this.message}`}}},875398,e=>{"use strict";var t=e.i(666680);let n=new Uint8Array(256),a=n.length;function s(){return a>n.length-16&&((0,t.randomFillSync)(n),a=0),n.slice(a,a+=16)}let o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));let r={};function c(e,t,n,a,s=0){if(e.length<16)throw Error("Random bytes length must be >= 16");if(a){if(s<0||s+16>a.length)throw RangeError(`UUID byte range ${s}:${s+15} is out of buffer bounds`)}else a=new Uint8Array(16),s=0;return t??=Date.now(),n??=127*e[6]<<24|e[7]<<16|e[8]<<8|e[9],a[s++]=t/0x10000000000&255,a[s++]=t/0x100000000&255,a[s++]=t/0x1000000&255,a[s++]=t/65536&255,a[s++]=t/256&255,a[s++]=255&t,a[s++]=112|n>>>28&15,a[s++]=n>>>20&255,a[s++]=128|n>>>14&63,a[s++]=n>>>6&255,a[s++]=n<<2&255|3&e[10],a[s++]=e[11],a[s++]=e[12],a[s++]=e[13],a[s++]=e[14],a[s++]=e[15],a}e.s(["v7",0,function(e,t,n){let a;if(e)a=c(e.random??e.rng?.()??s(),e.msecs,e.seq,t,n);else{var i,l,u;let e=Date.now(),o=s();i=r,l=e,u=o,i.msecs??=-1/0,i.seq??=0,l>i.msecs?(i.seq=u[6]<<23|u[7]<<16|u[8]<<8|u[9],i.msecs=l):(i.seq=i.seq+1|0,0===i.seq&&i.msecs++),a=c(o,r.msecs,r.seq,t,n)}return t??function(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}(a)}],875398)},230056,e=>e.a(async(t,n)=>{try{let t=await e.y("pg");e.n(t),n()}catch(e){n(e)}},!0),600177,e=>{"use strict";var t=e.i(522734),n=e.i(814747),a=e.i(446786),s=e.i(875398);let o=(0,n.join)((0,a.homedir)(),".config","clay"),r=(0,n.join)(o,"config.json");function c(){(0,t.mkdirSync)(o,{recursive:!0})}function i(){if(c(),!(0,t.existsSync)(r)){let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(r,JSON.stringify(e,null,2)),e}try{let e=(0,t.readFileSync)(r,"utf-8");return JSON.parse(e)}catch{let e={connections:[],activeConnectionId:null};return(0,t.writeFileSync)(r,JSON.stringify(e,null,2)),e}}function l(e){c(),(0,t.writeFileSync)(r,JSON.stringify(e,null,2))}function u(){return i().connections}function m(e){return i().connections.find(t=>t.id===e)}function h(){let e=i();return e.activeConnectionId?e.connections.find(t=>t.id===e.activeConnectionId)??null:null}function d(){return i().activeConnectionId}function f(e){let t=i(),n=new Date().toISOString(),a={...e,id:(0,s.v7)(),createdAt:n,updatedAt:n};return t.connections.push(a),1===t.connections.length&&(t.activeConnectionId=a.id),l(t),a}function p(e,t){let n=i(),a=n.connections.findIndex(t=>t.id===e);return -1===a?null:(n.connections[a]={...n.connections[a],...t,updatedAt:new Date().toISOString()},l(n),n.connections[a])}function g(e){let t=i(),n=t.connections.findIndex(t=>t.id===e);return -1!==n&&(t.connections.splice(n,1),t.activeConnectionId===e&&(t.activeConnectionId=t.connections.length>0?t.connections[0].id:null),l(t),!0)}function b(e){let t=i();return!!t.connections.find(t=>t.id===e)&&(t.activeConnectionId=e,l(t),!0)}function w(e){return(0,n.join)(o,"csv-dbs",`${e}.db`)}function y(e,t){let n=i(),a=n.connections.findIndex(t=>t.id===e);return -1===a?null:(n.connections[a]={...n.connections[a],csvFiles:t,updatedAt:new Date().toISOString()},l(n),n.connections[a])}e.s(["addConnection",()=>f,"deleteConnection",()=>g,"getActiveConnection",()=>h,"getActiveConnectionId",()=>d,"getConnection",()=>m,"getConnections",()=>u,"getCsvDbPath",()=>w,"setActiveConnection",()=>b,"updateConnection",()=>p,"updateCsvFiles",()=>y])},393207,(e,t,n)=>{t.exports=e.x("@libsql/client",()=>require("@libsql/client"))},381165,e=>e.a(async(t,n)=>{try{var a=e.i(230056),s=e.i(600177),o=e.i(522734),r=t([a]);[a]=r.then?(await r)():r;let f=new Map;async function c(t){let n=(await e.A(959021)).createPool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectionLimit:5,waitForConnections:!0});return{warehouse:{async execute(e){let[t,a]=await n.execute(e);return{rows:t,fields:(a||[]).map(e=>({name:e.name,dataTypeID:e.columnType}))}}},cleanup:async()=>{await n.end()}}}async function i(t){let n,o;if(!(n=t?(0,s.getConnection)(t):(0,s.getActiveConnection)()))throw Error("No database connection configured. Please add a connection in the Connections page.");let r="sqlite"===n.type||"csv"===n.type?`${n.type}:${n.filePath||n.database||n.id}`:`${n.type}:${n.host}:${n.port}:${n.user}:${n.database}:${n.ssl}:${n.password}`,i=f.get(n.id);if(i&&i.connectionHash===r)return i.lastUsed=Date.now(),{db:i.warehouse,connection:n};if(i){try{await i.cleanup()}catch{}f.delete(n.id)}if("mysql"===n.type)o=await c(n);else if("sqlite"===n.type||"csv"===n.type)o=function(t){let n="csv"===t.type?(0,s.getCsvDbPath)(t.id):t.filePath||t.database;if(!n)throw Error("No database file path specified for SQLite connection.");let a=null;return{warehouse:{async execute(t){let s=(()=>{if(!a){let{createClient:t}=e.r(393207);a=t({url:`file:${n}`})}return a})(),o=await s.execute(t);return{rows:o.rows.map(e=>{let t={};for(let n of o.columns)t[n]=e[n];return t}),fields:o.columns.map(e=>({name:e}))}}},cleanup:async()=>{a&&(a.close?.(),a=null)}}}(n);else{let e;e=new a.Pool({host:n.host,port:n.port,user:n.user,password:n.password,database:n.database,ssl:n.ssl?{rejectUnauthorized:!1}:void 0,max:5,idleTimeoutMillis:3e5}),o={warehouse:{async execute(t){let n=await e.query(t);return{rows:n.rows,fields:n.fields.map(e=>({name:e.name,dataTypeID:e.dataTypeID}))}}},cleanup:async()=>{await e.end()}}}return f.set(n.id,{warehouse:o.warehouse,cleanup:o.cleanup,connectionHash:r,lastUsed:Date.now()}),{db:o.warehouse,connection:n}}async function l(t){let n=Date.now();try{if("sqlite"===t.type){let n=t.filePath||t.database;if(!n)throw Error("No file path specified");if(!(0,o.existsSync)(n))throw Error(`File not found: ${n}`);let{createClient:a}=e.r(393207),s=a({url:`file:${n}`});await s.execute("SELECT 1"),s.close()}else if("csv"===t.type){let n=t.id?(0,s.getCsvDbPath)(t.id):null;if(n&&(0,o.existsSync)(n)){let{createClient:t}=e.r(393207),a=t({url:`file:${n}`});await a.execute("SELECT 1"),a.close()}}else if("mysql"===t.type){let n=await e.A(959021),a=await n.createConnection({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,connectTimeout:1e4});await a.execute("SELECT 1"),await a.end()}else{let e=new a.Pool({host:t.host,port:t.port,user:t.user,password:t.password,database:t.database,ssl:t.ssl?{rejectUnauthorized:!1}:void 0,max:1,connectionTimeoutMillis:1e4}),n=await e.connect();await n.query("SELECT 1"),n.release(),await e.end()}return{success:!0,latencyMs:Date.now()-n}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e),latencyMs:Date.now()-n}}}function u(e){switch(e){case"redshift":return"Amazon Redshift SQL";case"postgresql":return"PostgreSQL";case"mysql":return"MySQL";case"sqlite":case"csv":return"SQLite"}}async function m(t,n,a){let o=(0,s.getCsvDbPath)(t),{mkdirSync:r}=e.r(522734),{dirname:c}=e.r(814747);r(c(o),{recursive:!0});let{createClient:i}=e.r(393207),l=i({url:`file:${o}`});try{let e=function(e){let t=[],n=[],a="",s=!1,o=0;for(;o<e.length;){let r=e[o];s?'"'===r?o+1<e.length&&'"'===e[o+1]?(a+='"',o+=2):(s=!1,o++):(a+=r,o++):'"'===r?(s=!0,o++):","===r?(n.push(a.trim()),a="",o++):"\r"===r||"\n"===r?(n.push(a.trim()),a="",n.some(e=>""!==e)&&t.push(n),n=[],"\r"===r&&o+1<e.length&&"\n"===e[o+1]?o+=2:o++):(a+=r,o++)}return(a||n.length>0)&&(n.push(a.trim()),n.some(e=>""!==e)&&t.push(n)),t}(n);if(e.length<2)throw Error("CSV must have a header row and at least one data row");let t=e[0],s=e.slice(1),o=d(a),r=t.map(d);await l.execute(`DROP TABLE IF EXISTS "${o}"`);let c=r.map((e,t)=>{var n;let a=(n=s.slice(0,20).map(e=>e[t]).filter(Boolean),0===n.length?"TEXT":n.every(e=>/^-?\d+$/.test(e))?"INTEGER":n.every(e=>/^-?\d+(\.\d+)?$/.test(e))?"REAL":"TEXT");return`"${e}" ${a}`});await l.execute(`CREATE TABLE "${o}" (${c.join(", ")})`);let i=0;for(let e=0;e<s.length;e+=500){let t=s.slice(e,e+500),n=t.map(()=>`(${r.map(()=>"?").join(", ")})`).join(", "),a=t.flatMap(e=>r.map((t,n)=>{let a=e[n];return null==a||""===a?null:a}));await l.execute({sql:`INSERT INTO "${o}" (${r.map(e=>`"${e}"`).join(", ")}) VALUES ${n}`,args:a}),i+=t.length}return l.close(),{rowCount:i,columns:r}}catch(e){throw l.close(),e}}async function h(t,n){let a=(0,s.getCsvDbPath)(t);if(!(0,o.existsSync)(a))return;let{createClient:r}=e.r(393207),c=r({url:`file:${a}`});await c.execute(`DROP TABLE IF EXISTS "${d(n)}"`),c.close()}function d(e){return e.replace(/[^\w\s]/g,"").replace(/\s+/g,"_").replace(/^(\d)/,"_$1").toLowerCase().slice(0,64)||"column"}e.s(["getDbDialect",()=>u,"getWarehouseDB",()=>i,"importCsvToSqlite",()=>m,"removeCsvTable",()=>h,"testConnection",()=>l]),n()}catch(e){n(e)}},!1),452886,e=>e.a(async(t,n)=>{try{var a=e.i(712075),s=e.i(469719),o=e.i(608056),r=e.i(381165),c=t([r]);async function i(e,t,n){let c=n||(()=>{}),{db:i,connection:u}=await (0,r.getWarehouseDB)(e),m=u.type,h=(0,r.getDbDialect)(m);c({type:"connecting",connectionName:u.name});let d=(await i.execute(function(e){switch(e){case"postgresql":case"redshift":return`
|
|
2
|
-
SELECT table_schema, table_name
|
|
3
|
-
FROM information_schema.tables
|
|
4
|
-
WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
5
|
-
AND table_type = 'BASE TABLE'
|
|
6
|
-
ORDER BY table_schema, table_name
|
|
7
|
-
LIMIT 50
|
|
8
|
-
`;case"mysql":return`
|
|
9
|
-
SELECT table_schema, table_name
|
|
10
|
-
FROM information_schema.tables
|
|
11
|
-
WHERE table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
|
|
12
|
-
AND table_type = 'BASE TABLE'
|
|
13
|
-
ORDER BY table_schema, table_name
|
|
14
|
-
LIMIT 50
|
|
15
|
-
`;case"sqlite":case"csv":return`
|
|
16
|
-
SELECT name AS table_name
|
|
17
|
-
FROM sqlite_master
|
|
18
|
-
WHERE type = 'table'
|
|
19
|
-
AND name NOT LIKE 'sqlite_%'
|
|
20
|
-
ORDER BY name
|
|
21
|
-
LIMIT 50
|
|
22
|
-
`;default:return"SELECT 1"}}(m))).rows.map(e=>({name:e.table_name||e.name,schema:e.table_schema}));if(0===d.length)return c({type:"no_tables"}),{entries:[],tablesExplored:0,connectionName:u.name};c({type:"tables_found",totalTables:d.length});let f=[];for(let e=0;e<d.length;e++){let t=d[e],n=t.schema?`${t.schema}.${t.name}`:t.name;c({type:"exploring_table",table:n,current:e+1,total:d.length});try{let a=await i.execute(function(e,t,n){switch(e){case"postgresql":case"redshift":return`
|
|
23
|
-
SELECT column_name, data_type, is_nullable, column_default,
|
|
24
|
-
character_maximum_length, numeric_precision
|
|
25
|
-
FROM information_schema.columns
|
|
26
|
-
WHERE table_name = '${t}'
|
|
27
|
-
${n?`AND table_schema = '${n}'`:""}
|
|
28
|
-
ORDER BY ordinal_position
|
|
29
|
-
`;case"mysql":return`
|
|
30
|
-
SELECT column_name, data_type, is_nullable, column_default,
|
|
31
|
-
character_maximum_length, numeric_precision, column_key, extra
|
|
32
|
-
FROM information_schema.columns
|
|
33
|
-
WHERE table_name = '${t}'
|
|
34
|
-
${n?`AND table_schema = '${n}'`:""}
|
|
35
|
-
ORDER BY ordinal_position
|
|
36
|
-
`;case"sqlite":case"csv":return`PRAGMA table_info("${t}")`;default:return"SELECT 1"}}(m,t.name,t.schema)),s=[],o=function(e,t,n){switch(e){case"postgresql":case"redshift":return`
|
|
37
|
-
SELECT
|
|
38
|
-
kcu.column_name,
|
|
39
|
-
ccu.table_schema AS foreign_table_schema,
|
|
40
|
-
ccu.table_name AS foreign_table_name,
|
|
41
|
-
ccu.column_name AS foreign_column_name
|
|
42
|
-
FROM information_schema.table_constraints tc
|
|
43
|
-
JOIN information_schema.key_column_usage kcu
|
|
44
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
45
|
-
JOIN information_schema.constraint_column_usage ccu
|
|
46
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
47
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
48
|
-
AND tc.table_name = '${t}'
|
|
49
|
-
${n?`AND tc.table_schema = '${n}'`:""}
|
|
50
|
-
`;case"mysql":return`
|
|
51
|
-
SELECT
|
|
52
|
-
column_name,
|
|
53
|
-
referenced_table_schema AS foreign_table_schema,
|
|
54
|
-
referenced_table_name AS foreign_table_name,
|
|
55
|
-
referenced_column_name AS foreign_column_name
|
|
56
|
-
FROM information_schema.key_column_usage
|
|
57
|
-
WHERE table_name = '${t}'
|
|
58
|
-
AND referenced_table_name IS NOT NULL
|
|
59
|
-
${n?`AND table_schema = '${n}'`:""}
|
|
60
|
-
`;case"sqlite":case"csv":return`PRAGMA foreign_key_list("${t}")`;default:return null}}(m,t.name,t.schema);if(o)try{s=(await i.execute(o)).rows}catch{}let r=[];try{r=(await i.execute(function(e,t,n){let a=n&&"sqlite"!==e&&"csv"!==e?`"${n}"."${t}"`:`"${t}"`;return`SELECT * FROM ${a} LIMIT 3`}(m,t.name,t.schema))).rows.slice(0,3)}catch{}let l=0;try{let e=await i.execute(function(e,t,n){let a=n&&"sqlite"!==e&&"csv"!==e?`"${n}"."${t}"`:`"${t}"`;return`SELECT COUNT(*) AS row_count FROM ${a}`}(m,t.name,t.schema));l=Number(e.rows[0]?.row_count||0)}catch{}f.push({name:t.name,schema:t.schema,fullName:n,columns:a.rows,foreignKeys:s,sampleRows:r,rowCount:l}),c({type:"table_done",table:n,current:e+1,total:d.length,columnCount:a.rows.length,rowCount:l})}catch(t){console.error(`Failed to explore table ${n}:`,t),c({type:"table_error",table:n,current:e+1,total:d.length})}}if(0===f.length)return{entries:[],tablesExplored:0,connectionName:u.name};let p=f.map(e=>{let t=e.columns.map(e=>{let t=e.column_name||e.name||"unknown",n=e.data_type||e.type||"unknown",a="YES"===e.is_nullable||0===e.notnull?"nullable":"not null",s=1===e.pk?" PRIMARY KEY":"",o=e.column_key?` (${e.column_key})`:"";return` ${t} ${n} ${a}${s}${o}`}).join("\n"),n=e.foreignKeys.length>0?` Foreign Keys:
|
|
61
|
-
${e.foreignKeys.map(e=>` ${e.column_name||e.from} → ${e.foreign_table_name||e.table}.${e.foreign_column_name||e.to}`).join("\n")}`:"",a=e.sampleRows.length>0?` Sample Data (${e.rowCount} total rows):
|
|
62
|
-
${JSON.stringify(e.sampleRows,null,2).split("\n").map(e=>` ${e}`).join("\n")}`:` (${e.rowCount} rows, no sample available)`;return`TABLE: ${e.fullName}
|
|
63
|
-
Columns:
|
|
64
|
-
${t}
|
|
65
|
-
${n}
|
|
66
|
-
${a}`}).join("\n\n---\n\n");c({type:"generating",tablesExplored:f.length});let g=(0,o.getModel)(t||"google-gemini-2.0-flash-001"),b=s.z.object({entries:s.z.array(s.z.object({title:s.z.string().describe("A concise title"),content:s.z.string().describe("Detailed knowledge for AI SQL queries")}))}),w=[];if(p.length<=15e3)c({type:"generating_batch",batch:1,totalBatches:1}),w=(await (0,a.generateObject)({model:g,schema:b,prompt:l(h,u.name,p)})).object.entries,c({type:"batch_done",batch:1,totalBatches:1,entriesFound:w.length});else{let e=[],t="";for(let n of f){let a=p.split("---").find(e=>e.includes(`TABLE: ${n.fullName}`))?.trim()||"";t.length+a.length>15e3?(t&&e.push(t),t=a):t+=(t?"\n\n---\n\n":"")+a}t&&e.push(t);for(let t=0;t<e.length;t++){c({type:"generating_batch",batch:t+1,totalBatches:e.length});let n=await (0,a.generateObject)({model:g,schema:b,prompt:l(h,u.name,e[t])});w.push(...n.object.entries),c({type:"batch_done",batch:t+1,totalBatches:e.length,entriesFound:n.object.entries.length,totalEntries:w.length})}}return{entries:w,tablesExplored:f.length,connectionName:u.name}}function l(e,t,n){return`You are a database knowledge extraction agent. Analyze the following ${e} database schema for connection "${t}" and generate comprehensive knowledge base entries.
|
|
67
|
-
|
|
68
|
-
Your goal: create knowledge entries that would help an AI assistant write better SQL queries against this database.
|
|
69
|
-
|
|
70
|
-
For each entry, focus on:
|
|
71
|
-
1. **Table purposes** — What each table is for, what entity it represents
|
|
72
|
-
2. **Column meanings** — Non-obvious column names, what values mean
|
|
73
|
-
3. **Relationships** — How tables relate to each other (foreign keys, join patterns)
|
|
74
|
-
4. **Data patterns** — Enum values observed in sample data, status codes, date formats
|
|
75
|
-
5. **Business rules** — Any business logic implied by the schema (e.g. soft deletes, computed fields)
|
|
76
|
-
6. **Naming conventions** — Schema-wide patterns in naming
|
|
77
|
-
7. **Important notes** — Anything an AI should know to avoid common mistakes
|
|
78
|
-
|
|
79
|
-
Create at least one entry per table and additional entries for cross-cutting concerns.
|
|
80
|
-
Each entry should be self-contained and useful on its own.
|
|
81
|
-
|
|
82
|
-
Database Schema:
|
|
83
|
-
${n}`}[r]=c.then?(await c)():c,e.s(["exploreDatabase",()=>i]),n()}catch(e){n(e)}},!1)];
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__e474c328._.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
module.exports=[193695,(a,b,c)=>{b.exports=a.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},650645,a=>{a.n(a.i(827572))},43619,a=>{a.n(a.i(379962))},13718,a=>{a.n(a.i(685523))},118198,a=>{a.n(a.i(545518))},262212,a=>{a.n(a.i(866114))},522734,(a,b,c)=>{b.exports=a.x("fs",()=>require("fs"))},446786,(a,b,c)=>{b.exports=a.x("os",()=>require("os"))},666680,(a,b,c)=>{b.exports=a.x("node:crypto",()=>require("node:crypto"))},581988,a=>a.a(async(b,c)=>{try{let b=await a.y("@libsql/client");a.n(b),c()}catch(a){c(a)}},!0),580949,(a,b,c)=>{"use strict";var d=Object.defineProperty,e=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,g=Object.prototype.hasOwnProperty,h={},i={VercelOidcTokenError:()=>k};for(var j in i)d(h,j,{get:i[j],enumerable:!0});b.exports=((a,b,c,h)=>{if(b&&"object"==typeof b||"function"==typeof b)for(let c of f(b))g.call(a,c)||void 0===c||d(a,c,{get:()=>b[c],enumerable:!(h=e(b,c))||h.enumerable});return a})(d({},"__esModule",{value:!0}),h);class k extends Error{constructor(a,b){super(a),this.name="VercelOidcTokenError",this.cause=b}toString(){return this.cause?`${this.name}: ${this.message}: ${this.cause}`:`${this.name}: ${this.message}`}}},328158,a=>{"use strict";var b=a.i(666680);let c=new Uint8Array(256),d=c.length;function e(){return d>c.length-16&&((0,b.randomFillSync)(c),d=0),c.slice(d,d+=16)}let f=[];for(let a=0;a<256;++a)f.push((a+256).toString(16).slice(1));let g={};function h(a,b,c,d,e=0){if(a.length<16)throw Error("Random bytes length must be >= 16");if(d){if(e<0||e+16>d.length)throw RangeError(`UUID byte range ${e}:${e+15} is out of buffer bounds`)}else d=new Uint8Array(16),e=0;return b??=Date.now(),c??=127*a[6]<<24|a[7]<<16|a[8]<<8|a[9],d[e++]=b/0x10000000000&255,d[e++]=b/0x100000000&255,d[e++]=b/0x1000000&255,d[e++]=b/65536&255,d[e++]=b/256&255,d[e++]=255&b,d[e++]=112|c>>>28&15,d[e++]=c>>>20&255,d[e++]=128|c>>>14&63,d[e++]=c>>>6&255,d[e++]=c<<2&255|3&a[10],d[e++]=a[11],d[e++]=a[12],d[e++]=a[13],d[e++]=a[14],d[e++]=a[15],d}a.s(["v7",0,function(a,b,c){let d;if(a)d=h(a.random??a.rng?.()??e(),a.msecs,a.seq,b,c);else{var i,j,k;let a=Date.now(),f=e();i=g,j=a,k=f,i.msecs??=-1/0,i.seq??=0,j>i.msecs?(i.seq=k[6]<<23|k[7]<<16|k[8]<<8|k[9],i.msecs=j):(i.seq=i.seq+1|0,0===i.seq&&i.msecs++),d=h(f,g.msecs,g.seq,b,c)}return b??function(a,b=0){return(f[a[b+0]]+f[a[b+1]]+f[a[b+2]]+f[a[b+3]]+"-"+f[a[b+4]]+f[a[b+5]]+"-"+f[a[b+6]]+f[a[b+7]]+"-"+f[a[b+8]]+f[a[b+9]]+"-"+f[a[b+10]]+f[a[b+11]]+f[a[b+12]]+f[a[b+13]]+f[a[b+14]]+f[a[b+15]]).toLowerCase()}(d)}],328158)},688505,a=>{"use strict";var b=a.i(522734),c=a.i(814747),d=a.i(446786);a.i(328158);let e=(0,c.join)((0,d.homedir)(),".config","clay"),f=(0,c.join)(e,"config.json");function g(){if((0,b.mkdirSync)(e,{recursive:!0}),!(0,b.existsSync)(f)){let a={connections:[],activeConnectionId:null};return(0,b.writeFileSync)(f,JSON.stringify(a,null,2)),a}try{let a=(0,b.readFileSync)(f,"utf-8");return JSON.parse(a)}catch{let a={connections:[],activeConnectionId:null};return(0,b.writeFileSync)(f,JSON.stringify(a,null,2)),a}}function h(){return g().connections}function i(){return g().activeConnectionId}a.s(["getActiveConnectionId",()=>i,"getConnections",()=>h])},774651,a=>{"use strict";let b=(0,a.i(211857).registerClientReference)(function(){throw Error("Attempted to call ChatComponent() from the server but ChatComponent is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"[project]/src/components/chat-page.tsx <module evaluation>","ChatComponent");a.s(["ChatComponent",0,b])},539552,a=>{"use strict";let b=(0,a.i(211857).registerClientReference)(function(){throw Error("Attempted to call ChatComponent() from the server but ChatComponent is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"[project]/src/components/chat-page.tsx","ChatComponent");a.s(["ChatComponent",0,b])},311274,a=>{"use strict";a.i(774651);var b=a.i(539552);a.n(b)},915077,a=>a.a(async(b,c)=>{try{var d=a.i(594758),e=a.i(837137);a.i(975523);var f=a.i(93321),g=a.i(530385);a.i(451748);var h=b([d]);async function i(a){let b=await d.db.select().from(e.chats).where((0,f.eq)(e.chats.pubId,a));return 0===b.length?null:b[0]}async function j(a){return await d.db.select({id:e.messages.pubId,parts:e.messages.parts,createdAt:e.messages.createdAt,updatedAt:e.messages.updatedAt,role:e.messages.role,metadata:e.messages.metadata,chatId:e.messages.chatId}).from(e.messages).where((0,f.and)((0,f.eq)(e.messages.chatId,a),(0,f.eq)(e.messages.status,"active"))).orderBy((0,g.asc)(e.messages.createdAt))}[d]=h.then?(await h)():h,a.s(["getChat",()=>i,"getMessages",()=>j]),c()}catch(a){c(a)}},!1),89113,a=>a.a(async(b,c)=>{try{var d=a.i(907997),e=a.i(665050),f=a.i(311274),g=a.i(688505),h=a.i(915077),i=b([h]);async function j(a){try{let b=await (0,h.getChat)(a);if(!b)return{chat:null,messages:null,connectionId:null};let c=await (0,h.getMessages)(b.id);return{chat:b,messages:c,connectionId:b.connectionId}}catch(a){return console.log("Error in fetchChat",a),{chat:null,messages:null,connectionId:null}}}async function k({params:a}){let b=await (0,e.getSidebarStateDesktop)(),c=await (0,e.getSidebarStateMobile)(),{threadId:h}=await a,i=await j(h),k=i.connectionId||(0,g.getActiveConnectionId)();return(0,d.jsx)(f.ChatComponent,{initialSidebarCollapsedDesktop:b,initialSidebarCollapsedMobile:c,threadId:h,initialMessages:i.messages,connectionId:k})}[h]=i.then?(await i)():i,a.s(["default",()=>k]),c()}catch(a){c(a)}},!1),682672,a=>{a.v(b=>Promise.all(["server/chunks/ssr/node_modules_@vercel_oidc_dist_4aeec363._.js"].map(b=>a.l(b))).then(()=>b(72918)))},966249,a=>{a.v(b=>Promise.all(["server/chunks/ssr/node_modules_@vercel_oidc_dist_aa62ad66._.js"].map(b=>a.l(b))).then(()=>b(860544)))}];
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__0e727499._.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
module.exports=[522734,(a,b,c)=>{b.exports=a.x("fs",()=>require("fs"))},446786,(a,b,c)=>{b.exports=a.x("os",()=>require("os"))},666680,(a,b,c)=>{b.exports=a.x("node:crypto",()=>require("node:crypto"))},193695,(a,b,c)=>{b.exports=a.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},650645,a=>{a.n(a.i(827572))},43619,a=>{a.n(a.i(379962))},13718,a=>{a.n(a.i(685523))},118198,a=>{a.n(a.i(545518))},262212,a=>{a.n(a.i(866114))},328158,a=>{"use strict";var b=a.i(666680);let c=new Uint8Array(256),d=c.length;function e(){return d>c.length-16&&((0,b.randomFillSync)(c),d=0),c.slice(d,d+=16)}let f=[];for(let a=0;a<256;++a)f.push((a+256).toString(16).slice(1));let g={};function h(a,b,c,d,e=0){if(a.length<16)throw Error("Random bytes length must be >= 16");if(d){if(e<0||e+16>d.length)throw RangeError(`UUID byte range ${e}:${e+15} is out of buffer bounds`)}else d=new Uint8Array(16),e=0;return b??=Date.now(),c??=127*a[6]<<24|a[7]<<16|a[8]<<8|a[9],d[e++]=b/0x10000000000&255,d[e++]=b/0x100000000&255,d[e++]=b/0x1000000&255,d[e++]=b/65536&255,d[e++]=b/256&255,d[e++]=255&b,d[e++]=112|c>>>28&15,d[e++]=c>>>20&255,d[e++]=128|c>>>14&63,d[e++]=c>>>6&255,d[e++]=c<<2&255|3&a[10],d[e++]=a[11],d[e++]=a[12],d[e++]=a[13],d[e++]=a[14],d[e++]=a[15],d}a.s(["v7",0,function(a,b,c){let d;if(a)d=h(a.random??a.rng?.()??e(),a.msecs,a.seq,b,c);else{var i,j,k;let a=Date.now(),f=e();i=g,j=a,k=f,i.msecs??=-1/0,i.seq??=0,j>i.msecs?(i.seq=k[6]<<23|k[7]<<16|k[8]<<8|k[9],i.msecs=j):(i.seq=i.seq+1|0,0===i.seq&&i.msecs++),d=h(f,g.msecs,g.seq,b,c)}return b??function(a,b=0){return(f[a[b+0]]+f[a[b+1]]+f[a[b+2]]+f[a[b+3]]+"-"+f[a[b+4]]+f[a[b+5]]+"-"+f[a[b+6]]+f[a[b+7]]+"-"+f[a[b+8]]+f[a[b+9]]+"-"+f[a[b+10]]+f[a[b+11]]+f[a[b+12]]+f[a[b+13]]+f[a[b+14]]+f[a[b+15]]).toLowerCase()}(d)}],328158)},688505,a=>{"use strict";var b=a.i(522734),c=a.i(814747),d=a.i(446786);a.i(328158);let e=(0,c.join)((0,d.homedir)(),".config","clay"),f=(0,c.join)(e,"config.json");function g(){if((0,b.mkdirSync)(e,{recursive:!0}),!(0,b.existsSync)(f)){let a={connections:[],activeConnectionId:null};return(0,b.writeFileSync)(f,JSON.stringify(a,null,2)),a}try{let a=(0,b.readFileSync)(f,"utf-8");return JSON.parse(a)}catch{let a={connections:[],activeConnectionId:null};return(0,b.writeFileSync)(f,JSON.stringify(a,null,2)),a}}function h(){return g().connections}function i(){return g().activeConnectionId}a.s(["getActiveConnectionId",()=>i,"getConnections",()=>h])},774651,a=>{"use strict";let b=(0,a.i(211857).registerClientReference)(function(){throw Error("Attempted to call ChatComponent() from the server but ChatComponent is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"[project]/src/components/chat-page.tsx <module evaluation>","ChatComponent");a.s(["ChatComponent",0,b])},539552,a=>{"use strict";let b=(0,a.i(211857).registerClientReference)(function(){throw Error("Attempted to call ChatComponent() from the server but ChatComponent is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"[project]/src/components/chat-page.tsx","ChatComponent");a.s(["ChatComponent",0,b])},311274,a=>{"use strict";a.i(774651);var b=a.i(539552);a.n(b)},625044,a=>{"use strict";var b=a.i(907997),c=a.i(311274),d=a.i(665050),e=a.i(688505),f=a.i(328158);async function g(){let a=await (0,d.getSidebarStateDesktop)(),g=await (0,d.getSidebarStateMobile)(),h=(0,e.getActiveConnectionId)();return(0,b.jsx)(c.ChatComponent,{initialSidebarCollapsedDesktop:a,initialSidebarCollapsedMobile:g,threadId:(0,f.v7)(),connectionId:h})}a.s(["default",()=>g])}];
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=%5Broot-of-the-server%5D__4451526a._.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,893213,e=>{"use strict";var t=e.i(843476),s=e.i(271645),a=e.i(618566),n=e.i(672464);e.i(265172);var l=e.i(639372);let r=new WeakMap;var i=e.i(60345),o=e.i(846696),c=e.i(519455),d=e.i(515288),m=e.i(658041),h=e.i(107233);let x=(0,l.atom)({connections:[],activeConnectionId:null});var u=e.i(500932),p=e.i(522016),g=e.i(110204),f=e.i(967489),b=e.i(871689),j=e.i(810980),N=e.i(16715),w=e.i(531278),y=e.i(475254);let k=(0,y.default)("wand-sparkles",[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]]),v=(0,y.default)("bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);var C=e.i(283086);let S=(0,y.default)("cable",[["path",{d:"M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z",key:"trhst0"}],["path",{d:"M17 21v-2",key:"ds4u3f"}],["path",{d:"M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10",key:"1mo9zo"}],["path",{d:"M21 21v-2",key:"eo0ou"}],["path",{d:"M3 5V3",key:"1k5hjh"}],["path",{d:"M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z",key:"1dd30t"}],["path",{d:"M7 5V3",key:"1t1388"}]]);function B(e){let s,l,r,i,o,d,m,y,B,T,E,_,I=(0,u.c)(30),{selectedConnectionId:z,entryCount:D,isRegenerating:F,onConnectionChange:M,onAddEntry:$,onGenerateFromText:P,onAutoGenerate:O,onRegenerateEmbeddings:L}=e,R=(0,a.useRouter)(),{connections:V}=(0,n.useAtomValue)(x);return I[0]!==R?(s=()=>R.push("/"),I[0]=R,I[1]=s):s=I[1],I[2]===Symbol.for("react.memo_cache_sentinel")?(l=(0,t.jsx)(b.ArrowLeft,{className:"h-4 w-4"}),r=(0,t.jsx)("span",{className:"hidden sm:inline",children:"Back to Chat"}),I[2]=l,I[3]=r):(l=I[2],r=I[3]),I[4]!==s?(i=(0,t.jsxs)(c.Button,{variant:"ghost",size:"sm",onClick:s,className:"gap-1.5",children:[l,r]}),I[4]=s,I[5]=i):i=I[5],I[6]===Symbol.for("react.memo_cache_sentinel")?(o=(0,t.jsx)("div",{className:"flex-1"}),d=(0,t.jsx)("h1",{className:"text-sm font-semibold",children:"CLAY"}),I[6]=o,I[7]=d):(o=I[6],d=I[7]),I[8]!==i?(m=(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[i,o,d]}),I[8]=i,I[9]=m):m=I[9],I[10]===Symbol.for("react.memo_cache_sentinel")?(y=(0,t.jsxs)("div",{children:[(0,t.jsxs)("h2",{className:"text-xl sm:text-2xl font-bold tracking-tight flex items-center gap-2",children:[(0,t.jsx)(j.BookOpen,{className:"h-5 w-5 sm:h-6 sm:w-6"}),"Knowledge Base"]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Add context about your database to help AI write better queries."})]}),I[10]=y):y=I[10],I[11]!==V.length||I[12]!==D||I[13]!==F||I[14]!==$||I[15]!==O||I[16]!==P||I[17]!==L||I[18]!==z?(B=V.length>0&&(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap shrink-0",children:[(0,t.jsx)(c.Button,{asChild:!0,variant:"outline",size:"sm",className:"gap-1.5 text-xs",children:(0,t.jsxs)(p.default,{href:"/connections",children:[(0,t.jsx)(S,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"Connections"})]})}),(0,t.jsx)(c.Button,{asChild:!0,variant:"outline",size:"sm",className:"gap-1.5 text-xs",children:(0,t.jsxs)(p.default,{href:"/ai-providers",children:[(0,t.jsx)(C.Sparkles,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"AI Providers"})]})}),(0,t.jsxs)(c.Button,{variant:"outline",size:"sm",onClick:O,disabled:!z,className:"gap-1.5 text-xs",children:[(0,t.jsx)(v,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"Auto"})," Generate"]}),(0,t.jsxs)(c.Button,{variant:"outline",size:"sm",onClick:P,disabled:!z,className:"gap-1.5 text-xs",children:[(0,t.jsx)(k,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"From"})," Text"]}),D>0&&(0,t.jsxs)(c.Button,{variant:"outline",size:"sm",onClick:L,disabled:!z||F,className:"gap-1.5 text-xs",title:"Regenerate vector embeddings for semantic search",children:[F?(0,t.jsx)(w.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(N.RefreshCw,{className:"h-3.5 w-3.5"}),"Rebuild"]}),(0,t.jsxs)(c.Button,{size:"sm",onClick:$,disabled:!z,className:"gap-1.5",children:[(0,t.jsx)(h.Plus,{className:"h-4 w-4"}),"Add"]})]}),I[11]=V.length,I[12]=D,I[13]=F,I[14]=$,I[15]=O,I[16]=P,I[17]=L,I[18]=z,I[19]=B):B=I[19],I[20]!==B?(T=(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[y,B]}),I[20]=B,I[21]=T):T=I[21],I[22]!==V||I[23]!==M||I[24]!==z?(E=V.length>0&&(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(g.Label,{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Connection:"}),(0,t.jsxs)(f.Select,{value:z,onValueChange:M,children:[(0,t.jsx)(f.SelectTrigger,{className:"w-full sm:w-[280px]",children:(0,t.jsx)(f.SelectValue,{placeholder:"Select a connection"})}),(0,t.jsx)(f.SelectContent,{children:V.map(A)})]})]}),I[22]=V,I[23]=M,I[24]=z,I[25]=E):E=I[25],I[26]!==T||I[27]!==E||I[28]!==m?(_=(0,t.jsx)("header",{className:"border-b border-border/40 bg-background/80 backdrop-blur sticky top-0 z-10",children:(0,t.jsxs)("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-4 space-y-4",children:[m,T,E]})}),I[26]=T,I[27]=E,I[28]=m,I[29]=_):_=I[29],_}function A(e){return(0,t.jsx)(f.SelectItem,{value:e.id,children:(0,t.jsxs)("span",{className:"flex items-center gap-2",children:[(0,t.jsx)(m.Database,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.name,(0,t.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.type,")"]})]})},e.id)}var T=e.i(793479),E=e.i(487486),_=e.i(677572),I=e.i(555436),z=e.i(284614),D=e.i(727612);function F(e){let s,a,n,l,r,i,o,d,m,h,x,p,g,f,b=(0,u.c)(34),{searchQuery:j,onSearchChange:N,activeTab:w,onTabChange:y,totalCount:k,humanCount:v,aiCount:S,onClear:B,isClearing:A}=e,F="human"===w?v:"ai"===w?S:k,M="human"===w?"Clear Human":"ai"===w?"Clear AI":"Clear All";return b[0]===Symbol.for("react.memo_cache_sentinel")?(s=(0,t.jsx)(I.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),b[0]=s):s=b[0],b[1]!==N?(a=e=>N(e.target.value),b[1]=N,b[2]=a):a=b[2],b[3]!==j||b[4]!==a?(n=(0,t.jsxs)("div",{className:"relative",children:[s,(0,t.jsx)(T.Input,{placeholder:"Search knowledge base...",value:j,onChange:a,className:"pl-9"})]}),b[3]=j,b[4]=a,b[5]=n):n=b[5],b[6]!==k?(l=(0,t.jsxs)(_.TabsTrigger,{value:"all",className:"gap-1 sm:gap-1.5 flex-1 sm:flex-initial text-xs sm:text-sm",children:["All",(0,t.jsx)(E.Badge,{variant:"secondary",className:"text-[10px] px-1.5 h-4",children:k})]}),b[6]=k,b[7]=l):l=b[7],b[8]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)(z.User,{className:"h-3.5 w-3.5"}),i=(0,t.jsx)("span",{className:"hidden xs:inline",children:"Human"}),b[8]=r,b[9]=i):(r=b[8],i=b[9]),b[10]!==v?(o=(0,t.jsxs)(_.TabsTrigger,{value:"human",className:"gap-1 sm:gap-1.5 flex-1 sm:flex-initial text-xs sm:text-sm",children:[r,i,(0,t.jsx)(E.Badge,{variant:"secondary",className:"text-[10px] px-1.5 h-4",children:v})]}),b[10]=v,b[11]=o):o=b[11],b[12]===Symbol.for("react.memo_cache_sentinel")?(d=(0,t.jsx)(C.Sparkles,{className:"h-3.5 w-3.5"}),b[12]=d):d=b[12],b[13]!==S?(m=(0,t.jsxs)(_.TabsTrigger,{value:"ai",className:"gap-1 sm:gap-1.5 flex-1 sm:flex-initial text-xs sm:text-sm",children:[d,"AI",(0,t.jsx)(E.Badge,{variant:"secondary",className:"text-[10px] px-1.5 h-4",children:S})]}),b[13]=S,b[14]=m):m=b[14],b[15]!==l||b[16]!==o||b[17]!==m?(h=(0,t.jsxs)(_.TabsList,{className:"w-full sm:w-auto",children:[l,o,m]}),b[15]=l,b[16]=o,b[17]=m,b[18]=h):h=b[18],b[19]!==w||b[20]!==y||b[21]!==h?(x=(0,t.jsx)(_.Tabs,{value:w,onValueChange:y,children:h}),b[19]=w,b[20]=y,b[21]=h,b[22]=x):x=b[22],b[23]!==F||b[24]!==M||b[25]!==A||b[26]!==B?(p=F>0&&(0,t.jsxs)(c.Button,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive hover:bg-destructive/10 gap-1.5 h-8 text-xs self-end sm:self-auto",onClick:B,disabled:A,children:[(0,t.jsx)(D.Trash2,{className:"h-3.5 w-3.5"}),M]}),b[23]=F,b[24]=M,b[25]=A,b[26]=B,b[27]=p):p=b[27],b[28]!==x||b[29]!==p?(g=(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[x,p]}),b[28]=x,b[29]=p,b[30]=g):g=b[30],b[31]!==g||b[32]!==n?(f=(0,t.jsxs)("div",{className:"space-y-3",children:[n,g]}),b[31]=g,b[32]=n,b[33]=f):f=b[33],f}let M=(0,y.default)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);var $=e.i(246349),$=$,P=e.i(788699),O=e.i(975157);function L(e){let s,a,n,l,r,i,o,m,h,x,p,g,f,b,j,N,w,y,k=(0,u.c)(44),{entry:v,onEdit:S,onDelete:B}=e,A="ai_generated"===v.source;k[0]!==v.source?(s=(0,O.cn)("text-[10px] gap-1 shrink-0","ai_generated"===v.source?"text-purple-400 bg-purple-400/10 border-purple-400/20":"text-zinc-400 bg-zinc-400/10 border-zinc-400/20"),k[0]=v.source,k[1]=s):s=k[1],k[2]!==A?(a=A?(0,t.jsx)(C.Sparkles,{className:"h-3 w-3"}):(0,t.jsx)(z.User,{className:"h-3 w-3"}),k[2]=A,k[3]=a):a=k[3];let T=A?"AI":"Human";return k[4]!==s||k[5]!==a||k[6]!==T?(n=(0,t.jsx)("div",{className:"flex items-center gap-2 mb-1",children:(0,t.jsxs)(E.Badge,{variant:"outline",className:s,children:[a,T]})}),k[4]=s,k[5]=a,k[6]=T,k[7]=n):n=k[7],k[8]!==v.title?(l=(0,t.jsx)(d.CardTitle,{className:"text-sm font-medium wrap-break-word",children:v.title}),k[8]=v.title,k[9]=l):l=k[9],k[10]!==n||k[11]!==l?(r=(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[n,l]}),k[10]=n,k[11]=l,k[12]=r):r=k[12],k[13]!==v||k[14]!==S?(i=()=>S(v),k[13]=v,k[14]=S,k[15]=i):i=k[15],k[16]===Symbol.for("react.memo_cache_sentinel")?(o=(0,t.jsx)(P.Pencil,{className:"h-3 w-3"}),k[16]=o):o=k[16],k[17]!==i?(m=(0,t.jsx)(c.Button,{variant:"ghost",size:"sm",onClick:i,className:"h-7 w-7 p-0",children:o}),k[17]=i,k[18]=m):m=k[18],k[19]!==v.pubId||k[20]!==v.title||k[21]!==B?(h=()=>B(v.pubId,v.title),k[19]=v.pubId,k[20]=v.title,k[21]=B,k[22]=h):h=k[22],k[23]===Symbol.for("react.memo_cache_sentinel")?(x=(0,t.jsx)(D.Trash2,{className:"h-3 w-3"}),k[23]=x):x=k[23],k[24]!==h?(p=(0,t.jsx)(c.Button,{variant:"ghost",size:"sm",onClick:h,className:"h-7 w-7 p-0 text-destructive hover:text-destructive",children:x}),k[24]=h,k[25]=p):p=k[25],k[26]!==p||k[27]!==m?(g=(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[m,p]}),k[26]=p,k[27]=m,k[28]=g):g=k[28],k[29]!==g||k[30]!==r?(f=(0,t.jsx)(d.CardHeader,{className:"p-4 sm:p-6 pb-2 sm:pb-2",children:(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2 sm:gap-3",children:[r,g]})}),k[29]=g,k[30]=r,k[31]=f):f=k[31],k[32]!==v.content?(b=(0,t.jsx)("p",{className:"text-xs sm:text-sm text-muted-foreground whitespace-pre-wrap line-clamp-3 sm:line-clamp-4",children:v.content}),k[32]=v.content,k[33]=b):b=k[33],k[34]!==v.createdAt?(j=new Date(v.createdAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}),k[34]=v.createdAt,k[35]=j):j=k[35],k[36]!==j?(N=(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/60 mt-2",children:j}),k[36]=j,k[37]=N):N=k[37],k[38]!==b||k[39]!==N?(w=(0,t.jsxs)(d.CardContent,{className:"p-4 sm:p-6 pt-0 sm:pt-0",children:[b,N]}),k[38]=b,k[39]=N,k[40]=w):w=k[40],k[41]!==f||k[42]!==w?(y=(0,t.jsxs)(d.Card,{className:"transition-all hover:border-border/80 group",children:[f,w]}),k[41]=f,k[42]=w,k[43]=y):y=k[43],y}function R(e){let a,n,l,r,i,o,m,x,p,g=(0,u.c)(40),{entries:f,isLoading:b,searchQuery:N,onEdit:y,onDelete:k,onAddFirst:v}=e,[C,S]=(0,s.useState)(1),B=Math.max(1,Math.ceil(f.length/10));g[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{S(1)},g[0]=a):a=g[0],g[1]!==f.length||g[2]!==N?(n=[f.length,N],g[1]=f.length,g[2]=N,g[3]=n):n=g[3],(0,s.useEffect)(a,n),g[4]!==C||g[5]!==B?(l=()=>{C>B&&S(B)},r=[C,B],g[4]=C,g[5]=B,g[6]=l,g[7]=r):(l=g[6],r=g[7]),(0,s.useEffect)(l,r);let A=(C-1)*10;g[8]!==f||g[9]!==A?(i=f.slice(A,A+10),g[8]=f,g[9]=A,g[10]=i):i=g[10];let T=i;if(b){let e;return g[11]===Symbol.for("react.memo_cache_sentinel")?(e=(0,t.jsx)("div",{className:"flex items-center justify-center py-20",children:(0,t.jsx)(w.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),g[11]=e):e=g[11],e}if(0===f.length){let e,s,a,n,l;g[12]===Symbol.for("react.memo_cache_sentinel")?(e=(0,t.jsx)("div",{className:"rounded-full bg-muted p-4 mb-4",children:(0,t.jsx)(j.BookOpen,{className:"h-8 w-8 text-muted-foreground"})}),g[12]=e):e=g[12];let r=N?"No results found":"No knowledge entries yet";g[13]!==r?(s=(0,t.jsx)("h3",{className:"text-lg font-semibold mb-1",children:r}),g[13]=r,g[14]=s):s=g[14];let i=N?"Try a different search query.":"Add knowledge about your database to help AI understand your schema, business logic, and conventions.";return g[15]!==i?(a=(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-6 text-center max-w-sm",children:i}),g[15]=i,g[16]=a):a=g[16],g[17]!==v||g[18]!==N?(n=!N&&(0,t.jsxs)(c.Button,{onClick:v,className:"gap-1.5",children:[(0,t.jsx)(h.Plus,{className:"h-4 w-4"}),"Add First Entry"]}),g[17]=v,g[18]=N,g[19]=n):n=g[19],g[20]!==a||g[21]!==n||g[22]!==s?(l=(0,t.jsx)(d.Card,{className:"border-dashed",children:(0,t.jsxs)(d.CardContent,{className:"flex flex-col items-center justify-center py-16",children:[e,s,a,n]})}),g[20]=a,g[21]=n,g[22]=s,g[23]=l):l=g[23],l}if(g[24]!==k||g[25]!==y||g[26]!==T){let e;g[28]!==k||g[29]!==y?(e=e=>(0,t.jsx)(L,{entry:e,onEdit:y,onDelete:k},e.pubId),g[28]=k,g[29]=y,g[30]=e):e=g[30],o=T.map(e),g[24]=k,g[25]=y,g[26]=T,g[27]=o}else o=g[27];return g[31]!==o?(m=(0,t.jsx)("div",{className:"space-y-3",children:o}),g[31]=o,g[32]=m):m=g[32],g[33]!==C||g[34]!==f.length||g[35]!==B?(x=B>1&&(0,t.jsx)(V,{currentPage:C,totalPages:B,totalEntries:f.length,onPageChange:S}),g[33]=C,g[34]=f.length,g[35]=B,g[36]=x):x=g[36],g[37]!==m||g[38]!==x?(p=(0,t.jsxs)("div",{className:"space-y-4",children:[m,x]}),g[37]=m,g[38]=x,g[39]=p):p=g[39],p}function V(e){let s,a,n,l,r,i,o,d,m,h,x,p=(0,u.c)(35),{currentPage:g,totalPages:f,totalEntries:b,onPageChange:j}=e;p[0]!==g||p[1]!==f?(s=function(e,t){if(t<=7)return Array.from({length:t},(e,t)=>t+1);let s=[],a=Math.max(2,e-1),n=Math.min(t-1,e+1);s.push(1),a>2&&s.push("...");for(let e=a;e<=n;e++)s.push(e);return n<t-1&&s.push("..."),s.push(t),s}(g,f),p[0]=g,p[1]=f,p[2]=s):s=p[2];let N=s,w=(g-1)*10+1,y=Math.min(10*g,b);p[3]!==y||p[4]!==w||p[5]!==b?(a=(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[w,"–",y," of ",b]}),p[3]=y,p[4]=w,p[5]=b,p[6]=a):a=p[6];let k=1===g;if(p[7]!==g||p[8]!==j?(n=()=>j(g-1),p[7]=g,p[8]=j,p[9]=n):n=p[9],p[10]===Symbol.for("react.memo_cache_sentinel")?(l=(0,t.jsx)(M,{className:"h-4 w-4"}),p[10]=l):l=p[10],p[11]!==k||p[12]!==n?(r=(0,t.jsx)(c.Button,{variant:"outline",size:"sm",className:"h-8 w-8 p-0",disabled:k,onClick:n,children:l}),p[11]=k,p[12]=n,p[13]=r):r=p[13],p[14]!==g||p[15]!==j||p[16]!==N){let e;p[18]!==g||p[19]!==j?(e=(e,s)=>"..."===e?(0,t.jsx)("span",{className:"px-1 text-xs text-muted-foreground select-none",children:"..."},`ellipsis-${s}`):(0,t.jsx)(c.Button,{variant:e===g?"default":"outline",size:"sm",className:(0,O.cn)("h-8 w-8 p-0 text-xs",e===g&&"pointer-events-none"),onClick:()=>j(e),children:e},e),p[18]=g,p[19]=j,p[20]=e):e=p[20],i=N.map(e),p[14]=g,p[15]=j,p[16]=N,p[17]=i}else i=p[17];let v=g===f;return p[21]!==g||p[22]!==j?(o=()=>j(g+1),p[21]=g,p[22]=j,p[23]=o):o=p[23],p[24]===Symbol.for("react.memo_cache_sentinel")?(d=(0,t.jsx)($.default,{className:"h-4 w-4"}),p[24]=d):d=p[24],p[25]!==v||p[26]!==o?(m=(0,t.jsx)(c.Button,{variant:"outline",size:"sm",className:"h-8 w-8 p-0",disabled:v,onClick:o,children:d}),p[25]=v,p[26]=o,p[27]=m):m=p[27],p[28]!==m||p[29]!==r||p[30]!==i?(h=(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[r,i,m]}),p[28]=m,p[29]=r,p[30]=i,p[31]=h):h=p[31],p[32]!==h||p[33]!==a?(x=(0,t.jsxs)("div",{className:"flex items-center justify-between pt-2",children:[a,h]}),p[32]=h,p[33]=a,p[34]=x):x=p[34],x}var H=e.i(624687),G=e.i(776639);function K(e){let s,a,n,l,r,i,o,d,m,h,x,p,f,b,j,N,y=(0,u.c)(42),{open:k,onOpenChange:v,editingPubId:C,form:S,onFormChange:B,isFormValid:A,isSaving:E,onSave:_}=e,I=C?"Edit Knowledge Entry":"Add Knowledge Entry";y[0]!==I?(s=(0,t.jsx)(G.DialogTitle,{children:I}),y[0]=I,y[1]=s):s=y[1];let z=C?"Update this knowledge entry.":"Add context about your database to improve AI query accuracy.";y[2]!==z?(a=(0,t.jsx)(G.DialogDescription,{children:z}),y[2]=z,y[3]=a):a=y[3],y[4]!==s||y[5]!==a?(n=(0,t.jsxs)(G.DialogHeader,{className:"shrink-0",children:[s,a]}),y[4]=s,y[5]=a,y[6]=n):n=y[6],y[7]===Symbol.for("react.memo_cache_sentinel")?(l=(0,t.jsx)(g.Label,{htmlFor:"kb-title",children:"Title"}),y[7]=l):l=y[7],y[8]!==B?(r=e=>B(t=>({...t,title:e.target.value})),y[8]=B,y[9]=r):r=y[9],y[10]!==S.title||y[11]!==r?(i=(0,t.jsxs)("div",{className:"space-y-2",children:[l,(0,t.jsx)(T.Input,{id:"kb-title",placeholder:"e.g. User status enum values, Revenue calculation logic",value:S.title,onChange:r})]}),y[10]=S.title,y[11]=r,y[12]=i):i=y[12],y[13]===Symbol.for("react.memo_cache_sentinel")?(o=(0,t.jsx)(g.Label,{htmlFor:"kb-content",children:"Content"}),y[13]=o):o=y[13],y[14]!==B?(d=e=>B(t=>({...t,content:e.target.value})),y[14]=B,y[15]=d):d=y[15],y[16]!==S.content||y[17]!==d?(m=(0,t.jsxs)("div",{className:"space-y-2",children:[o,(0,t.jsx)(H.Textarea,{id:"kb-content",placeholder:"Describe the knowledge here. For example:\n\n- Column descriptions and their meanings\n- Business logic and rules\n- Enum values and their meanings\n- Relationships between tables\n- Important data patterns or conventions",value:S.content,onChange:d,rows:6,className:"resize-y min-h-[120px] max-h-[40vh]"})]}),y[16]=S.content,y[17]=d,y[18]=m):m=y[18],y[19]!==m||y[20]!==i?(h=(0,t.jsxs)("div",{className:"space-y-4 py-2 overflow-y-auto flex-1 min-h-0",children:[i,m]}),y[19]=m,y[20]=i,y[21]=h):h=y[21],y[22]!==v?(x=(0,t.jsx)(c.Button,{variant:"outline",onClick:()=>v(!1),children:"Cancel"}),y[22]=v,y[23]=x):x=y[23];let D=!A||E;y[24]!==E?(p=E&&(0,t.jsx)(w.Loader2,{className:"h-4 w-4 animate-spin"}),y[24]=E,y[25]=p):p=y[25];let F=C?"Update":"Add Entry";return y[26]!==_||y[27]!==D||y[28]!==p||y[29]!==F?(f=(0,t.jsxs)(c.Button,{onClick:_,disabled:D,className:"gap-1.5",children:[p,F]}),y[26]=_,y[27]=D,y[28]=p,y[29]=F,y[30]=f):f=y[30],y[31]!==x||y[32]!==f?(b=(0,t.jsxs)(G.DialogFooter,{className:"shrink-0",children:[x,f]}),y[31]=x,y[32]=f,y[33]=b):b=y[33],y[34]!==h||y[35]!==b||y[36]!==n?(j=(0,t.jsxs)(G.DialogContent,{className:"sm:max-w-lg max-h-[85vh] flex! flex-col! p-4 sm:p-6",children:[n,h,b]}),y[34]=h,y[35]=b,y[36]=n,y[37]=j):j=y[37],y[38]!==v||y[39]!==k||y[40]!==j?(N=(0,t.jsx)(G.Dialog,{open:k,onOpenChange:v,children:j}),y[38]=v,y[39]=k,y[40]=j,y[41]=N):N=y[41],N}var U=e.i(168148),J=e.i(595468),W=e.i(178583);let q={phase:"idle",currentChunk:0,totalChunks:0,entriesFound:0,message:""};function Q({open:e,onOpenChange:a,connectionId:n,onImported:l}){let[r,m]=(0,s.useState)(""),[h,x]=(0,s.useState)([]),[u,p]=(0,s.useState)(new Set),[g,f]=(0,s.useState)(null),[b,j]=(0,s.useState)(!1),[N,y]=(0,s.useState)(q),v=(0,s.useRef)(null),S=i.api.knowledgeBase.create.useMutation(),B=r.length>5e3?Math.ceil(r.length/4400):1,A=(0,s.useCallback)(async()=>{if(!r.trim())return;v.current?.abort();let e=new AbortController;v.current=e,j(!0),y({phase:"analyzing",currentChunk:0,totalChunks:B,entriesFound:0,message:"Starting analysis..."});try{let s=await fetch("/api/knowledge/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:r}),signal:e.signal});if(!s.ok)throw Error(`Server error: ${s.status}`);let a=s.body?.getReader();if(!a)throw Error("No response stream");let n=new TextDecoder,l="";for(;;){let{done:e,value:s}=await a.read();if(e)break;let r=(l+=n.decode(s,{stream:!0})).split("\n");for(let e of(l=r.pop()||"",r))if(e.startsWith("data: "))try{let s=JSON.parse(e.slice(6));t(s)}catch{}}if(l.startsWith("data: "))try{t(JSON.parse(l.slice(6)))}catch{}}catch(e){"AbortError"!==e.name&&o.toast.error(e.message||"Failed to generate knowledge")}finally{j(!1)}function t(e){switch(e.type){case"start":y(t=>({...t,totalChunks:e.totalChunks,message:e.totalChunks>1?`Splitting into ${e.totalChunks} chunks...`:"Analyzing text..."}));break;case"chunk_start":y(t=>({...t,currentChunk:e.chunk,message:`Analyzing chunk ${e.chunk} of ${e.totalChunks}...`}));break;case"chunk_done":y(t=>({...t,currentChunk:e.chunk,entriesFound:e.totalEntries,message:`Chunk ${e.chunk} done — ${e.entriesFound} entries found`}));break;case"done":x(e.entries||[]),p(new Set),f(e.totalChunks>1?{totalChunks:e.totalChunks,totalRawEntries:e.totalRawEntries}:null),y(e=>({...e,phase:"done"}));break;case"error":o.toast.error(e.message||"Generation failed")}}},[r,B]),T=(0,s.useCallback)(async(e,t)=>{if(n)try{await S.mutateAsync({connectionId:n,title:e.title,content:e.content,source:"ai_generated"}),p(e=>{let s=new Set(e);return s.add(t),s}),t>=0&&o.toast.success("Entry imported"),l()}catch(e){throw t>=0&&o.toast.error(e.message||"Failed to import entry"),e}},[n,S,l]),E=(0,s.useCallback)(async()=>{if(!n||0===h.length)return;let e=h.map((e,t)=>({entry:e,index:t})).filter(({index:e})=>!u.has(e));if(0===e.length)return void o.toast.info("All entries already imported");let t=Promise.allSettled(e.map(({entry:e,index:t})=>T(e,-1).then(()=>t)));o.toast.promise(t,{loading:`Importing ${e.length} entries...`,success:e=>{let t=e.filter(e=>"fulfilled"===e.status).map(e=>e.value);p(e=>{let s=new Set(e);return t.forEach(e=>s.add(e)),s});let s=e.length-t.length;return`Imported ${t.length} entries${s>0?` (${s} failed)`:""}`},error:"Failed to import entries"})},[n,h,u,T]),_=(0,s.useCallback)(()=>{v.current?.abort(),m(""),x([]),f(null),p(new Set),y(q),j(!1)},[]),I=N.totalChunks>0?Math.round(N.currentChunk/N.totalChunks*100):0;return(0,t.jsx)(G.Dialog,{open:e,onOpenChange:e=>{e||_(),a(e)},children:(0,t.jsxs)(G.DialogContent,{className:"sm:max-w-2xl flex! flex-col! max-h-[85vh] overflow-hidden p-0",children:[(0,t.jsxs)(G.DialogHeader,{className:"shrink-0 px-4 sm:px-6 pt-6 pb-0",children:[(0,t.jsxs)(G.DialogTitle,{className:"flex items-center gap-2",children:[(0,t.jsx)(C.Sparkles,{className:"h-5 w-5 text-indigo-500"}),"Generate Knowledge from Text"]}),(0,t.jsx)(G.DialogDescription,{children:"Paste documentation or notes below. AI will extract structured knowledge entries."})]}),0===h.length?(0,t.jsxs)("div",{className:"flex flex-col gap-4 flex-1 min-h-0 px-4 sm:px-6 pb-4 sm:pb-6 pt-2",children:[(0,t.jsx)(H.Textarea,{placeholder:"Paste table schemas, business rules, API docs, or any text describing your database...",value:r,onChange:e=>m(e.target.value),className:"flex-1 min-h-[150px] max-h-[50vh] resize-none font-mono text-sm",disabled:b}),b&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsx)(w.Loader2,{className:"h-4 w-4 animate-spin text-indigo-500"}),(0,t.jsx)("span",{children:N.message})]}),N.entriesFound>0&&(0,t.jsxs)("span",{className:"text-xs text-muted-foreground",children:[N.entriesFound," entries so far"]})]}),(0,t.jsx)(U.Progress,{value:I,className:"h-1.5"}),N.totalChunks>1&&(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/60 text-right",children:["Chunk ",N.currentChunk," of"," ",N.totalChunks]})]}),(0,t.jsxs)("div",{className:"flex flex-col-reverse sm:flex-row items-start sm:items-center justify-between gap-2 shrink-0",children:[(0,t.jsx)("div",{className:"text-[11px] text-muted-foreground",children:r.length>0&&!b&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(W.FileText,{className:"h-3 w-3 inline mr-1"}),r.length.toLocaleString()," chars",r.length>5e3&&(0,t.jsxs)("span",{className:"ml-1.5 text-indigo-500",children:["— will be split into ~",B," chunks"]})]})}),(0,t.jsx)(c.Button,{onClick:A,disabled:!r.trim()||b,className:"gap-2",children:b?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Loader2,{className:"h-4 w-4 animate-spin"}),"Analyzing..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(k,{className:"h-4 w-4"}),"Generate Entries"]})})]})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 shrink-0 px-4 sm:px-6 pt-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("h3",{className:"text-sm font-medium text-muted-foreground",children:["Found ",h.length," entries (",u.size," imported)"]}),g&&(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/70 mt-0.5",children:["Processed ",g.totalChunks," ","chunks —"," ",g.totalRawEntries-h.length," ","duplicates removed"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,t.jsx)(c.Button,{variant:"outline",size:"sm",onClick:_,children:"Back to Text"}),(0,t.jsx)(c.Button,{size:"sm",onClick:E,disabled:h.length===u.size,children:"Import All"})]})]}),(0,t.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 pb-4 sm:pb-6",children:(0,t.jsx)("div",{className:"space-y-3",children:h.map((e,s)=>{let a=u.has(s);return(0,t.jsxs)(d.Card,{className:(0,O.cn)("relative transition-all",a&&"bg-muted/50 border-green-500/30"),children:[(0,t.jsx)(d.CardHeader,{className:"p-3 sm:p-4 pb-2",children:(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2 sm:gap-3",children:[(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("h4",{className:"font-medium text-sm wrap-break-word",children:e.title})}),a?(0,t.jsx)(c.Button,{size:"sm",variant:"ghost",disabled:!0,className:"h-8 w-8 p-0 text-green-600 shrink-0",children:(0,t.jsx)(J.CheckCircle2,{className:"h-5 w-5"})}):(0,t.jsx)(c.Button,{size:"sm",onClick:()=>T(e,s),disabled:S.isPending,className:"h-8 px-3 text-xs shrink-0",children:"Import"})]})}),(0,t.jsx)(d.CardContent,{className:"p-3 sm:p-4 pt-0",children:(0,t.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-3",children:e.content})})]},s)})})})]})]})})}var Y=e.i(431343),X=e.i(330325);function Z(e){let s,a,n,l,r,i,o,h=(0,u.c)(39),{open:x,onOpenChange:p,entries:g,importedIndices:f,tablesExplored:b,isExploring:j,progress:N,onStartExploration:y,onImportEntry:k,onImportAll:S}=e,B=g.length>0;h[0]!==N.generatingBatch||h[1]!==N.phase||h[2]!==N.tablesExplored||h[3]!==N.totalBatches||h[4]!==N.totalTables?(s="exploring"===N.phase&&N.totalTables>0?Math.round(N.tablesExplored/N.totalTables*70):"generating"===N.phase?70+(N.totalBatches&&N.generatingBatch?Math.round((N.generatingBatch-1)/N.totalBatches*30):15):100*("done"===N.phase),h[0]=N.generatingBatch,h[1]=N.phase,h[2]=N.tablesExplored,h[3]=N.totalBatches,h[4]=N.totalTables,h[5]=s):s=h[5];let A=s;return h[6]===Symbol.for("react.memo_cache_sentinel")?(a=(0,t.jsxs)(G.DialogHeader,{className:"shrink-0 px-4 sm:px-6 pt-6 pb-0",children:[(0,t.jsxs)(G.DialogTitle,{className:"flex items-center gap-2",children:[(0,t.jsx)(v,{className:"h-5 w-5 text-blue-500"}),"Auto-Generate Knowledge"]}),(0,t.jsx)(G.DialogDescription,{children:"An AI agent will explore your database schema, sample data, and relationships to automatically generate knowledge entries."})]}),h[6]=a):a=h[6],h[7]!==B||h[8]!==j||h[9]!==y||h[10]!==N.phase?(n=!B&&!j&&"idle"===N.phase&&(0,t.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-6 py-12 px-4 sm:px-6",children:[(0,t.jsx)("div",{className:"rounded-full bg-blue-500/10 p-6",children:(0,t.jsx)(m.Database,{className:"h-10 w-10 text-blue-500"})}),(0,t.jsxs)("div",{className:"text-center max-w-sm space-y-2",children:[(0,t.jsx)("h3",{className:"text-base font-semibold",children:"Ready to explore"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"The agent will discover all tables, analyze columns, sample data, and generate knowledge about your database structure and patterns."})]}),(0,t.jsxs)(c.Button,{onClick:y,className:"gap-2",size:"lg",children:[(0,t.jsx)(Y.Play,{className:"h-4 w-4"}),"Start Exploration"]})]}),h[7]=B,h[8]=j,h[9]=y,h[10]=N.phase,h[11]=n):n=h[11],h[12]!==j||h[13]!==N.currentTable||h[14]!==N.generatingBatch||h[15]!==N.message||h[16]!==N.phase||h[17]!==N.tablesExplored||h[18]!==N.totalBatches||h[19]!==N.totalTables||h[20]!==A?(l=j&&(0,t.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-5 py-10 px-4 sm:px-6",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"rounded-full bg-blue-500/10 p-5",children:(0,t.jsx)(v,{className:"h-8 w-8 text-blue-500"})}),(0,t.jsx)("div",{className:"absolute -bottom-1 -right-1 rounded-full bg-background p-1",children:(0,t.jsx)(w.Loader2,{className:"h-5 w-5 animate-spin text-blue-500"})})]}),(0,t.jsxs)("h3",{className:"text-base font-semibold",children:["connecting"===N.phase&&"Connecting to database...","exploring"===N.phase&&"Exploring tables...","generating"===N.phase&&"Generating knowledge..."]}),(0,t.jsxs)("div",{className:"w-full max-w-sm space-y-2",children:[(0,t.jsx)(U.Progress,{value:A,className:"h-2"}),(0,t.jsxs)("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[(0,t.jsx)("span",{children:N.message}),(0,t.jsxs)("span",{children:[A,"%"]})]})]}),"exploring"===N.phase&&N.currentTable&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground bg-muted/50 px-3 py-1.5 rounded-md",children:[(0,t.jsx)(X.Table2,{className:"h-3.5 w-3.5 text-blue-400"}),(0,t.jsx)("span",{className:"font-mono text-xs",children:N.currentTable}),(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/60",children:["(",N.tablesExplored,"/",N.totalTables,")"]})]}),"generating"===N.phase&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground bg-muted/50 px-3 py-1.5 rounded-md",children:[(0,t.jsx)(C.Sparkles,{className:"h-3.5 w-3.5 text-purple-400"}),(0,t.jsx)("span",{className:"text-xs",children:N.totalBatches&&N.totalBatches>1?`AI batch ${N.generatingBatch} of ${N.totalBatches}`:"AI is analyzing the schema..."})]})]}),h[12]=j,h[13]=N.currentTable,h[14]=N.generatingBatch,h[15]=N.message,h[16]=N.phase,h[17]=N.tablesExplored,h[18]=N.totalBatches,h[19]=N.totalTables,h[20]=A,h[21]=l):l=h[21],h[22]!==g||h[23]!==B||h[24]!==f||h[25]!==j||h[26]!==S||h[27]!==k||h[28]!==p||h[29]!==b?(r=B&&!j&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 shrink-0 px-4 sm:px-6 pt-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2",children:[(0,t.jsx)(J.CheckCircle2,{className:"h-4 w-4 text-green-500"}),"Generated ",g.length," entries"]}),(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/70 mt-0.5",children:["Explored ",b," tables —"," ",f.size," imported"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,t.jsx)(c.Button,{variant:"outline",size:"sm",onClick:()=>p(!1),children:"Close"}),(0,t.jsx)(c.Button,{size:"sm",onClick:S,disabled:g.length===f.size,children:"Import All"})]})]}),(0,t.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 pb-4 sm:pb-6",children:(0,t.jsx)("div",{className:"space-y-3",children:g.map((e,s)=>{let a=f.has(s);return(0,t.jsxs)(d.Card,{className:(0,O.cn)("relative transition-all",a&&"bg-muted/50 border-green-500/30"),children:[(0,t.jsx)(d.CardHeader,{className:"p-3 sm:p-4 pb-2",children:(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2 sm:gap-3",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("div",{className:"flex items-center gap-2 mb-1",children:(0,t.jsxs)(E.Badge,{variant:"outline",className:"text-[10px] gap-1 text-purple-400 bg-purple-400/10 border-purple-400/20",children:[(0,t.jsx)(C.Sparkles,{className:"h-3 w-3"}),"AI"]})}),(0,t.jsx)("h4",{className:"font-medium text-sm wrap-break-word",children:e.title})]}),a?(0,t.jsx)(c.Button,{size:"sm",variant:"ghost",disabled:!0,className:"h-8 w-8 p-0 text-green-600 shrink-0",children:(0,t.jsx)(J.CheckCircle2,{className:"h-5 w-5"})}):(0,t.jsx)(c.Button,{size:"sm",onClick:()=>k(e,s),className:"h-8 px-3 text-xs shrink-0",children:"Import"})]})}),(0,t.jsx)(d.CardContent,{className:"p-3 sm:p-4 pt-0",children:(0,t.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-3 sm:line-clamp-4 whitespace-pre-wrap",children:e.content})})]},s)})})})]}),h[22]=g,h[23]=B,h[24]=f,h[25]=j,h[26]=S,h[27]=k,h[28]=p,h[29]=b,h[30]=r):r=h[30],h[31]!==n||h[32]!==l||h[33]!==r?(i=(0,t.jsxs)(G.DialogContent,{className:"sm:max-w-2xl flex! flex-col! max-h-[85vh] overflow-hidden p-0",children:[a,n,l,r]}),h[31]=n,h[32]=l,h[33]=r,h[34]=i):i=h[34],h[35]!==p||h[36]!==x||h[37]!==i?(o=(0,t.jsx)(G.Dialog,{open:x,onOpenChange:p,children:i}),h[35]=p,h[36]=x,h[37]=i,h[38]=o):o=h[38],o}let ee={title:"",content:""},et={phase:"idle",tablesExplored:0,totalTables:0};function es({initialConnections:e,initialEntries:l,initialConnectionId:p}){let g=(0,a.useRouter)(),f=(0,a.useSearchParams)().get("connectionId");!function(e,t){var s;let a,l=(0,n.useStore)(void 0),i=(s=l,(a=r.get(s))||(a=new WeakSet,r.set(s,a)),a);for(let[t,...s]of e)i.has(t)&&1||(i.add(t),l.set(t,...s))}([[x,e]]);let b=(0,n.useAtomValue)(x),[j,N]=(0,s.useState)("all"),[w,y]=(0,s.useState)(""),[k,v]=(0,s.useState)(!1),C=b.connections,S=f||C[0]?.id||"",{data:A,isLoading:T,refetch:E}=i.api.knowledgeBase.list.useQuery({connectionId:S},{enabled:!!S,initialData:S===p?{entries:l}:void 0}),_=A?.entries||[],I=i.api.knowledgeBase.delete.useMutation(),z=i.api.knowledgeBase.bulkDelete.useMutation(),D=i.api.knowledgeBase.regenerateEmbeddings.useMutation(),M=function(e){let t,a,n,l,r,c=(0,u.c)(20),{connectionId:d,onSaved:m}=e,[h,x]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),[f,b]=(0,s.useState)(ee),j=i.api.knowledgeBase.create.useMutation(),N=i.api.knowledgeBase.update.useMutation();c[0]!==f.content||c[1]!==f.title?(t=f.title.trim().length>0&&f.content.trim().length>0,c[0]=f.content,c[1]=f.title,c[2]=t):t=c[2];let w=t,y=j.isPending||N.isPending;c[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{g(null),b(ee),x(!0)},c[3]=a):a=c[3];let k=a;c[4]===Symbol.for("react.memo_cache_sentinel")?(n=e=>{g(e.pubId),b({title:e.title,content:e.content}),x(!0)},c[4]=n):n=c[4];let v=n;c[5]!==d||c[6]!==j||c[7]!==p||c[8]!==f.content||c[9]!==f.title||c[10]!==m||c[11]!==N?(l=async()=>{if(!d)return void o.toast.error("No connection selected");try{p?(await N.mutateAsync({pubId:p,title:f.title,content:f.content}),o.toast.success("Knowledge entry updated")):(await j.mutateAsync({connectionId:d,title:f.title,content:f.content}),o.toast.success("Knowledge entry added")),x(!1),m()}catch(e){o.toast.error(e.message||"Failed to save knowledge entry")}},c[5]=d,c[6]=j,c[7]=p,c[8]=f.content,c[9]=f.title,c[10]=m,c[11]=N,c[12]=l):l=c[12];let C=l;return c[13]!==h||c[14]!==p||c[15]!==f||c[16]!==C||c[17]!==w||c[18]!==y?(r={dialogOpen:h,setDialogOpen:x,editingPubId:p,form:f,setForm:b,isFormValid:w,isSaving:y,openAddDialog:k,openEditDialog:v,handleSave:C},c[13]=h,c[14]=p,c[15]=f,c[16]=C,c[17]=w,c[18]=y,c[19]=r):r=c[19],r}({connectionId:S,onSaved:()=>E()}),$=function({connectionId:e,onImported:t}){let[a,n]=(0,s.useState)(!1),[l,r]=(0,s.useState)([]),[c,d]=(0,s.useState)(new Set),[m,h]=(0,s.useState)(et),[x,u]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=i.api.knowledgeBase.create.useMutation(),f=m.tablesExplored,b=(0,s.useCallback)(()=>{r([]),d(new Set),h(et),u(!1),n(!0)},[]),j=(0,s.useCallback)(async()=>{if(!e)return;p.current?.abort();let t=new AbortController;p.current=t,u(!0),r([]),h({phase:"connecting",tablesExplored:0,totalTables:0});try{let a=await fetch("/api/knowledge/auto-generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connectionId:e}),signal:t.signal});if(!a.ok)throw Error(`Server error: ${a.status}`);let n=a.body?.getReader();if(!n)throw Error("No response stream");let l=new TextDecoder,r="";for(;;){let{done:e,value:t}=await n.read();if(e)break;let a=(r+=l.decode(t,{stream:!0})).split("\n");for(let e of(r=a.pop()||"",a))if(e.startsWith("data: "))try{let t=JSON.parse(e.slice(6));s(t)}catch{}}if(r.startsWith("data: "))try{let e=JSON.parse(r.slice(6));s(e)}catch{}}catch(e){"AbortError"!==e.name&&(o.toast.error(e.message||"Failed to explore database"),h(t=>({...t,phase:"error",message:e.message})))}finally{u(!1)}function s(e){switch(e.type){case"connecting":h(t=>({...t,phase:"connecting",message:`Connecting to ${e.connectionName}...`}));break;case"tables_found":h(t=>({...t,phase:"exploring",totalTables:e.totalTables,message:`Found ${e.totalTables} tables`}));break;case"exploring_table":h(t=>({...t,phase:"exploring",currentTable:e.table,tablesExplored:e.current-1,totalTables:e.total}));break;case"table_done":h(t=>({...t,tablesExplored:e.current,currentTable:e.table,message:`${e.table} — ${e.columnCount} cols, ${e.rowCount} rows`}));break;case"generating":h(t=>({...t,phase:"generating",tablesExplored:e.tablesExplored,message:"AI is analyzing the schema..."}));break;case"generating_batch":h(t=>({...t,phase:"generating",generatingBatch:e.batch,totalBatches:e.totalBatches,message:e.totalBatches>1?`Generating batch ${e.batch} of ${e.totalBatches}...`:"Generating knowledge entries..."}));break;case"batch_done":h(t=>({...t,message:`Batch ${e.batch} done — ${e.entriesFound} entries`}));break;case"done":r(e.entries||[]),h(t=>({...t,phase:"done",tablesExplored:e.tablesExplored})),e.entries?.length||o.toast.info("No knowledge entries could be generated");break;case"error":o.toast.error(e.message||"Exploration failed"),h(t=>({...t,phase:"error",message:e.message}))}}},[e]),N=(0,s.useCallback)(async(s,a)=>{if(e)try{await g.mutateAsync({connectionId:e,title:s.title,content:s.content,source:"ai_generated"}),d(e=>{let t=new Set(e);return t.add(a),t}),a>=0&&o.toast.success("Entry imported"),t()}catch(e){throw a>=0&&o.toast.error(e.message||"Failed to import entry"),e}},[e,g,t]),w=(0,s.useCallback)(async()=>{if(!e||0===l.length)return;let t=l.map((e,t)=>({entry:e,index:t})).filter(({index:e})=>!c.has(e));if(0===t.length)return void o.toast.info("All entries already imported");let s=Promise.allSettled(t.map(({entry:e,index:t})=>N(e,-1).then(()=>t)));o.toast.promise(s,{loading:`Importing ${t.length} entries...`,success:e=>{let t=e.filter(e=>"fulfilled"===e.status).map(e=>e.value);d(e=>{let s=new Set(e);return t.forEach(e=>s.add(e)),s});let s=e.length-t.length;return`Imported ${t.length} entries${s>0?` (${s} failed)`:""}`},error:"Failed to import entries"})},[e,l,c,N]);return{dialogOpen:a,setDialogOpen:n,entries:l,importedIndices:c,tablesExplored:f,isExploring:x,progress:m,openDialog:b,startExploration:j,importEntry:N,importAll:w}}({connectionId:S,onImported:()=>E()}),P=_.filter(e=>"manual"===e.source).length,O=_.filter(e=>"ai_generated"===e.source).length,L=(0,s.useMemo)(()=>{let e=_;if("human"===j?e=e.filter(e=>"manual"===e.source):"ai"===j&&(e=e.filter(e=>"ai_generated"===e.source)),w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.title.toLowerCase().includes(t)||e.content.toLowerCase().includes(t))}return e},[_,j,w]),V=(0,s.useCallback)(e=>{g.push(`/knowledge-base?connectionId=${e}`)},[g]),H=(0,s.useCallback)(async(e,t)=>{if(confirm(`Delete knowledge entry "${t}"? This cannot be undone.`))try{await I.mutateAsync({pubId:e}),o.toast.success("Knowledge entry deleted"),E()}catch(e){o.toast.error(e.message||"Failed to delete knowledge entry")}},[I,E]),G=(0,s.useCallback)(async()=>{if(!S)return;let e="human"===j?"human":"ai"===j?"AI":"all";if(confirm(`Delete ${e} knowledge entries for this connection? This cannot be undone.`))try{let e="human"===j?"manual":"ai"===j?"ai_generated":void 0,t=await z.mutateAsync({connectionId:S,source:e});o.toast.success(`Deleted ${t.count} knowledge entries`),E()}catch(e){o.toast.error(e.message||"Failed to delete knowledge entries")}},[S,j,z,E]),U=(0,s.useCallback)(async()=>{if(S)try{let e=await D.mutateAsync({connectionId:S});o.toast.success(`Regenerated embeddings for ${e.count} entries`)}catch(e){o.toast.error(e.message||"Failed to regenerate embeddings")}},[S,D]);return(0,t.jsxs)("div",{className:"min-h-screen bg-background",children:[(0,t.jsx)(B,{selectedConnectionId:S,entryCount:_.length,isRegenerating:D.isPending,onConnectionChange:V,onAddEntry:M.openAddDialog,onGenerateFromText:()=>v(!0),onAutoGenerate:$.openDialog,onRegenerateEmbeddings:U}),(0,t.jsxs)("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-6 sm:py-8",children:[0===C.length&&(0,t.jsx)(d.Card,{className:"border-dashed",children:(0,t.jsxs)(d.CardContent,{className:"flex flex-col items-center justify-center py-16",children:[(0,t.jsx)("div",{className:"rounded-full bg-muted p-4 mb-4",children:(0,t.jsx)(m.Database,{className:"h-8 w-8 text-muted-foreground"})}),(0,t.jsx)("h3",{className:"text-lg font-semibold mb-1",children:"No connections found"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-6 text-center max-w-sm",children:"Add a database connection first, then come back to add knowledge base entries."}),(0,t.jsxs)(c.Button,{onClick:()=>g.push("/connections"),className:"gap-1.5",children:[(0,t.jsx)(h.Plus,{className:"h-4 w-4"}),"Add Connection"]})]})}),S&&(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(F,{searchQuery:w,onSearchChange:y,activeTab:j,onTabChange:N,totalCount:_.length,humanCount:P,aiCount:O,onClear:G,isClearing:z.isPending}),(0,t.jsx)(R,{entries:L,isLoading:T,searchQuery:w,onEdit:M.openEditDialog,onDelete:H,onAddFirst:M.openAddDialog})]})]}),(0,t.jsx)(K,{open:M.dialogOpen,onOpenChange:M.setDialogOpen,editingPubId:M.editingPubId,form:M.form,onFormChange:M.setForm,isFormValid:M.isFormValid,isSaving:M.isSaving,onSave:M.handleSave}),(0,t.jsx)(Q,{open:k,onOpenChange:v,connectionId:S,onImported:()=>E()}),(0,t.jsx)(Z,{open:$.dialogOpen,onOpenChange:$.setDialogOpen,entries:$.entries,importedIndices:$.importedIndices,tablesExplored:$.tablesExplored,isExploring:$.isExploring,progress:$.progress,onStartExploration:$.startExploration,onImportEntry:$.importEntry,onImportAll:$.importAll})]})}e.s(["KnowledgeBasePage",()=>es],893213)}]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,775258,e=>{"use strict";var s=e.i(843476),t=e.i(500932),a=e.i(60345),n=e.i(846696),l=e.i(522016),i=e.i(618566),r=e.i(519455),c=e.i(871689),o=e.i(107233),d=e.i(283086),m=e.i(810980);function h(e){let a,n,h,x,u,p,g,f,j,b,v,N,y,w,C,S=(0,t.c)(21),{onAddConnection:k}=e,_=(0,i.useRouter)();return S[0]!==_?(a=()=>_.push("/"),S[0]=_,S[1]=a):a=S[1],S[2]===Symbol.for("react.memo_cache_sentinel")?(n=(0,s.jsx)(c.ArrowLeft,{className:"h-4 w-4"}),h=(0,s.jsx)("span",{className:"hidden sm:inline",children:"Back to Chat"}),S[2]=n,S[3]=h):(n=S[2],h=S[3]),S[4]!==a?(x=(0,s.jsxs)(r.Button,{variant:"ghost",size:"sm",onClick:a,className:"gap-1.5",children:[n,h]}),S[4]=a,S[5]=x):x=S[5],S[6]===Symbol.for("react.memo_cache_sentinel")?(u=(0,s.jsx)("div",{className:"flex-1"}),p=(0,s.jsx)("h1",{className:"text-sm font-semibold",children:"CLAY"}),S[6]=u,S[7]=p):(u=S[6],p=S[7]),S[8]!==x?(g=(0,s.jsx)("header",{className:"border-b border-border/40 bg-background/80 backdrop-blur sticky top-0 z-10",children:(0,s.jsxs)("div",{className:"max-w-5xl mx-auto flex items-center gap-4 px-4 sm:px-6 py-4",children:[x,u,p]})}),S[8]=x,S[9]=g):g=S[9],S[10]===Symbol.for("react.memo_cache_sentinel")?(f=(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("h2",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"Connections"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground mt-1 hidden sm:block",children:"Manage your database connections. Supports PostgreSQL, Redshift, MySQL, SQLite, and CSV imports."})]}),S[10]=f):f=S[10],S[11]===Symbol.for("react.memo_cache_sentinel")?(j=(0,s.jsx)(r.Button,{asChild:!0,variant:"outline",size:"sm",className:"gap-1.5 shrink-0",children:(0,s.jsxs)(l.default,{href:"/ai-providers",children:[(0,s.jsx)(d.Sparkles,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"AI Providers"})]})}),S[11]=j):j=S[11],S[12]===Symbol.for("react.memo_cache_sentinel")?(b=(0,s.jsx)(r.Button,{asChild:!0,variant:"outline",size:"sm",className:"gap-1.5 shrink-0",children:(0,s.jsxs)(l.default,{href:"/knowledge-base",children:[(0,s.jsx)(m.BookOpen,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"Knowledge Base"})]})}),S[12]=b):b=S[12],S[13]===Symbol.for("react.memo_cache_sentinel")?(v=(0,s.jsx)(o.Plus,{className:"h-4 w-4"}),N=(0,s.jsx)("span",{className:"sm:hidden",children:"Add"}),y=(0,s.jsx)("span",{className:"hidden sm:inline",children:"Add Connection"}),S[13]=v,S[14]=N,S[15]=y):(v=S[13],N=S[14],y=S[15]),S[16]!==k?(w=(0,s.jsx)("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-5 sm:py-8",children:(0,s.jsxs)("div",{className:"space-y-3 sm:space-y-0 sm:flex sm:items-start sm:justify-between sm:gap-4 mb-6 sm:mb-8",children:[f,(0,s.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[j,b,(0,s.jsxs)(r.Button,{onClick:k,size:"sm",className:"gap-1.5 shrink-0",children:[v,N,y]})]})]})}),S[16]=k,S[17]=w):w=S[17],S[18]!==w||S[19]!==g?(C=(0,s.jsxs)(s.Fragment,{children:[g,w]}),S[18]=w,S[19]=g,S[20]=C):C=S[20],C}var x=e.i(515288),u=e.i(658041),p=e.i(531278),g=e.i(487486),f=e.i(595468),j=e.i(390152),b=e.i(475254);let v=(0,b.default)("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),N=(0,b.default)("shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]),y=(0,b.default)("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);var w=e.i(330325),C=e.i(788699),S=e.i(727612),k=e.i(975157),_=e.i(294918),F=e.i(352786);let D={redshift:5439,postgresql:5432,mysql:3306,sqlite:0,csv:0},A={name:"",type:"postgresql",host:"",port:"5432",user:"",password:"",database:"",ssl:!0,filePath:""},L={redshift:{color:"text-orange-400 bg-orange-400/10 border-orange-400/20",label:"Amazon Redshift",icon:u.Database},postgresql:{color:"text-blue-400 bg-blue-400/10 border-blue-400/20",label:"PostgreSQL",icon:u.Database},mysql:{color:"text-cyan-400 bg-cyan-400/10 border-cyan-400/20",label:"MySQL",icon:u.Database},sqlite:{color:"text-violet-400 bg-violet-400/10 border-violet-400/20",label:"SQLite",icon:F.HardDrive},csv:{color:"text-green-400 bg-green-400/10 border-green-400/20",label:"CSV (SQLite)",icon:_.FileSpreadsheet}},I={color:"text-muted-foreground",label:"",icon:u.Database};function P(e){var a,n,l;let i,c,o,d,m,h,u,p,j,b,v,N,y,w,_,F,D,A,P,B,z,M,R,$=(0,t.c)(61),{connection:V,isActive:Q,isTestPending:E,onSetActive:U,onTestExisting:O,onEdit:H,onDelete:K,onImportCsv:X}=e;$[0]!==V.type?(a=V.type,i=L[a]?.icon??I.icon,$[0]=V.type,$[1]=i):i=$[1];let Y=i,G=Q&&"ring-1 ring-primary/50 border-primary/30";return($[2]!==G?(c=(0,k.cn)("transition-all relative overflow-hidden min-w-0",G),$[2]=G,$[3]=c):c=$[3],$[4]!==V.type)?(o=(0,k.cn)("rounded-lg p-1.5 sm:p-2 border shrink-0",(n=V.type,L[n]?.color??I.color)),$[4]=V.type,$[5]=o):o=$[5],($[6]!==Y?(d=(0,s.jsx)(Y,{className:"h-4 w-4"}),$[6]=Y,$[7]=d):d=$[7],$[8]!==o||$[9]!==d?(m=(0,s.jsx)("div",{className:o,children:d}),$[8]=o,$[9]=d,$[10]=m):m=$[10],$[11]!==V.name?(h=(0,s.jsx)(x.CardTitle,{className:"text-sm sm:text-base truncate",children:V.name}),$[11]=V.name,$[12]=h):h=$[12],$[13]!==Q?(u=Q&&(0,s.jsxs)(g.Badge,{variant:"default",className:"text-[10px] gap-1 shrink-0",children:[(0,s.jsx)(f.CheckCircle2,{className:"h-3 w-3"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"Active"})]}),$[13]=Q,$[14]=u):u=$[14],$[15]!==h||$[16]!==u?(p=(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[h,u]}),$[15]=h,$[16]=u,$[17]=p):p=$[17],$[18]!==V.type)?(l=V.type,j=L[l]?.label??l,$[18]=V.type,$[19]=j):j=$[19],$[20]!==j?(b=(0,s.jsx)(x.CardDescription,{className:"text-xs mt-0.5",children:j}),$[20]=j,$[21]=b):b=$[21],$[22]!==b||$[23]!==p?(v=(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[p,b]}),$[22]=b,$[23]=p,$[24]=v):v=$[24],$[25]!==V.id||$[26]!==H?(N=()=>H(V.id),$[25]=V.id,$[26]=H,$[27]=N):N=$[27],$[28]===Symbol.for("react.memo_cache_sentinel")?(y=(0,s.jsx)(C.Pencil,{className:"h-3.5 w-3.5"}),$[28]=y):y=$[28],$[29]!==N?(w=(0,s.jsx)(r.Button,{variant:"ghost",size:"sm",onClick:N,className:"h-7 w-7 p-0",children:y}),$[29]=N,$[30]=w):w=$[30],$[31]!==V.id||$[32]!==V.name||$[33]!==K?(_=()=>K(V.id,V.name),$[31]=V.id,$[32]=V.name,$[33]=K,$[34]=_):_=$[34],$[35]===Symbol.for("react.memo_cache_sentinel")?(F=(0,s.jsx)(S.Trash2,{className:"h-3.5 w-3.5"}),$[35]=F):F=$[35],$[36]!==_?(D=(0,s.jsx)(r.Button,{variant:"ghost",size:"sm",onClick:_,className:"h-7 w-7 p-0 text-destructive hover:text-destructive",children:F}),$[36]=_,$[37]=D):D=$[37],$[38]!==w||$[39]!==D?(A=(0,s.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[w,D]}),$[38]=w,$[39]=D,$[40]=A):A=$[40],$[41]!==v||$[42]!==A||$[43]!==m?(P=(0,s.jsx)(x.CardHeader,{className:"p-4 sm:p-6 pb-2 sm:pb-3",children:(0,s.jsxs)("div",{className:"flex items-center gap-2.5 sm:gap-3",children:[m,v,A]})}),$[41]=v,$[42]=A,$[43]=m,$[44]=P):P=$[44],$[45]!==V?(B=(0,s.jsx)(T,{connection:V}),$[45]=V,$[46]=B):B=$[46],$[47]!==V||$[48]!==Q||$[49]!==E||$[50]!==X||$[51]!==U||$[52]!==O?(z=(0,s.jsx)(q,{connection:V,isActive:Q,isTestPending:E,onSetActive:U,onTestExisting:O,onImportCsv:X}),$[47]=V,$[48]=Q,$[49]=E,$[50]=X,$[51]=U,$[52]=O,$[53]=z):z=$[53],$[54]!==B||$[55]!==z?(M=(0,s.jsxs)(x.CardContent,{className:"p-4 sm:p-6 pt-0 sm:pt-0 min-w-0 overflow-hidden",children:[B,z]}),$[54]=B,$[55]=z,$[56]=M):M=$[56],$[57]!==P||$[58]!==M||$[59]!==c?(R=(0,s.jsxs)(x.Card,{className:c,children:[P,M]}),$[57]=P,$[58]=M,$[59]=c,$[60]=R):R=$[60],R}function T(e){let a,n=(0,t.c)(2),{connection:l}=e;return n[0]!==l?(a=(0,s.jsx)("div",{className:"space-y-1 text-xs text-muted-foreground mb-3 sm:mb-4 min-w-0 overflow-hidden",children:"sqlite"===l.type?(0,s.jsx)(B,{label:"File",value:l.filePath||l.database||"—"}):"csv"===l.type?(0,s.jsx)(z,{csvFiles:l.csvFiles}):(0,s.jsx)(R,{connection:l})}),n[0]=l,n[1]=a):a=n[1],a}function B(e){let a,n,l,i=(0,t.c)(7),{label:r,value:c}=e;return i[0]!==r?(a=(0,s.jsx)("span",{className:"text-muted-foreground/60 w-12 sm:w-14 shrink-0",children:r}),i[0]=r,i[1]=a):a=i[1],i[2]!==c?(n=(0,s.jsx)("span",{className:"font-mono truncate min-w-0 flex-1",children:c}),i[2]=c,i[3]=n):n=i[3],i[4]!==a||i[5]!==n?(l=(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[a,n]}),i[4]=a,i[5]=n,i[6]=l):l=i[6],l}function z(e){let a,n,l=(0,t.c)(5),{csvFiles:i}=e;if(!i?.length){let e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,s.jsx)("div",{className:"text-muted-foreground/50 italic",children:"No CSV files imported yet"}),l[0]=e):e=l[0],e}return l[1]!==i?(a=i.map(M),l[1]=i,l[2]=a):a=l[2],l[3]!==a?(n=(0,s.jsx)(s.Fragment,{children:a}),l[3]=a,l[4]=n):n=l[4],n}function M(e){return(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsx)(w.Table2,{className:"h-3 w-3 shrink-0 text-green-400/60"}),(0,s.jsx)("span",{className:"font-mono truncate min-w-0",title:e.tableName,children:e.tableName}),(0,s.jsx)("span",{className:"text-muted-foreground/40 shrink-0 text-[10px]",children:null!=e.rowCount&&`${e.rowCount} rows`})]},e.tableName)}function R(e){let a,n,l,i,r,c=(0,t.c)(13),{connection:o}=e,d=`${o.host}:${o.port}`;return c[0]!==d?(a=(0,s.jsx)(B,{label:"Host",value:d}),c[0]=d,c[1]=a):a=c[1],c[2]!==o.database?(n=(0,s.jsx)(B,{label:"DB",value:o.database}),c[2]=o.database,c[3]=n):n=c[3],c[4]!==o.user?(l=(0,s.jsx)(B,{label:"User",value:o.user}),c[4]=o.user,c[5]=l):l=c[5],c[6]!==o.ssl?(i=o.ssl&&(0,s.jsxs)("div",{className:"flex items-center gap-1 text-green-500/70 mt-1",children:[(0,s.jsx)(N,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:"SSL enabled"})]}),c[6]=o.ssl,c[7]=i):i=c[7],c[8]!==a||c[9]!==n||c[10]!==l||c[11]!==i?(r=(0,s.jsxs)(s.Fragment,{children:[a,n,l,i]}),c[8]=a,c[9]=n,c[10]=l,c[11]=i,c[12]=r):r=c[12],r}function q(e){let a,n,i,c,o,d,h,x,u=(0,t.c)(25),{connection:g,isActive:f,isTestPending:b,onSetActive:N,onTestExisting:w,onImportCsv:C}=e;u[0]!==g.id||u[1]!==f||u[2]!==N?(a=!f&&(0,s.jsxs)(r.Button,{variant:"outline",size:"sm",onClick:()=>N(g.id),className:"text-xs gap-1 h-7 px-2",children:[(0,s.jsx)(j.Plug,{className:"h-3 w-3"}),"Active"]}),u[0]=g.id,u[1]=f,u[2]=N,u[3]=a):a=u[3],u[4]!==g.id||u[5]!==w?(n=()=>w(g.id),u[4]=g.id,u[5]=w,u[6]=n):n=u[6],u[7]!==b?(i=b?(0,s.jsx)(p.Loader2,{className:"h-3 w-3 animate-spin"}):(0,s.jsx)(v,{className:"h-3 w-3"}),u[7]=b,u[8]=i):i=u[8],u[9]!==b||u[10]!==n||u[11]!==i?(c=(0,s.jsxs)(r.Button,{variant:"outline",size:"sm",onClick:n,disabled:b,className:"text-xs gap-1 h-7 px-2",children:[i,"Test"]}),u[9]=b,u[10]=n,u[11]=i,u[12]=c):c=u[12],u[13]!==g.id||u[14]!==g.type||u[15]!==C?(o="csv"===g.type&&(0,s.jsxs)(r.Button,{variant:"outline",size:"sm",onClick:()=>C(g.id),className:"text-xs gap-1 h-7 px-2 text-green-400 border-green-400/30 hover:bg-green-400/10",children:[(0,s.jsx)(y,{className:"h-3 w-3"}),"CSV"]}),u[13]=g.id,u[14]=g.type,u[15]=C,u[16]=o):o=u[16];let S=`/knowledge-base?connectionId=${g.id}`;return u[17]===Symbol.for("react.memo_cache_sentinel")?(d=(0,s.jsx)(m.BookOpen,{className:"h-3 w-3"}),u[17]=d):d=u[17],u[18]!==S?(h=(0,s.jsx)(r.Button,{asChild:!0,variant:"outline",size:"sm",className:"text-xs gap-1 h-7 px-2",children:(0,s.jsxs)(l.default,{href:S,children:[d,"KB"]})}),u[18]=S,u[19]=h):h=u[19],u[20]!==a||u[21]!==c||u[22]!==o||u[23]!==h?(x=(0,s.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a,c,o,h]}),u[20]=a,u[21]=c,u[22]=o,u[23]=h,u[24]=x):x=u[24],x}function $(e){let a,n,l=(0,t.c)(22),{connections:i,activeConnectionId:r,isLoading:c,isTestPending:o,onAdd:d,onSetActive:m,onTestExisting:h,onEdit:x,onDelete:u,onImportCsv:g}=e;if(c){let e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,s.jsx)("div",{className:"flex items-center justify-center py-20",children:(0,s.jsx)(p.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),l[0]=e):e=l[0],e}if(0===i.length){let e;return l[1]!==d?(e=(0,s.jsx)(V,{onAdd:d}),l[1]=d,l[2]=e):e=l[2],e}if(l[3]!==r||l[4]!==i||l[5]!==o||l[6]!==u||l[7]!==x||l[8]!==g||l[9]!==m||l[10]!==h){let e;l[12]!==r||l[13]!==o||l[14]!==u||l[15]!==x||l[16]!==g||l[17]!==m||l[18]!==h?(e=e=>(0,s.jsx)(P,{connection:e,isActive:e.id===r,isTestPending:o,onSetActive:m,onTestExisting:h,onEdit:x,onDelete:u,onImportCsv:g},e.id),l[12]=r,l[13]=o,l[14]=u,l[15]=x,l[16]=g,l[17]=m,l[18]=h,l[19]=e):e=l[19],a=i.map(e),l[3]=r,l[4]=i,l[5]=o,l[6]=u,l[7]=x,l[8]=g,l[9]=m,l[10]=h,l[11]=a}else a=l[11];return l[20]!==a?(n=(0,s.jsx)("div",{className:"grid gap-3 sm:gap-4 md:grid-cols-2 min-w-0",children:a}),l[20]=a,l[21]=n):n=l[21],n}function V(e){let a,n,l,i,c,d=(0,t.c)(6),{onAdd:m}=e;return d[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsx)("div",{className:"rounded-full bg-muted p-4 mb-4",children:(0,s.jsx)(u.Database,{className:"h-8 w-8 text-muted-foreground"})}),n=(0,s.jsx)("h3",{className:"text-base sm:text-lg font-semibold mb-1",children:"No connections yet"}),l=(0,s.jsx)("p",{className:"text-sm text-muted-foreground mb-6 text-center max-w-sm",children:"Add a database connection to start querying your data with AI."}),d[0]=a,d[1]=n,d[2]=l):(a=d[0],n=d[1],l=d[2]),d[3]===Symbol.for("react.memo_cache_sentinel")?(i=(0,s.jsx)(o.Plus,{className:"h-4 w-4"}),d[3]=i):i=d[3],d[4]!==m?(c=(0,s.jsx)(x.Card,{className:"border-dashed",children:(0,s.jsxs)(x.CardContent,{className:"flex flex-col items-center justify-center py-10 sm:py-16 px-4",children:[a,n,l,(0,s.jsxs)(r.Button,{onClick:m,className:"gap-1.5",children:[i,"Add Your First Connection"]})]})}),d[4]=m,d[5]=c):c=d[5],c}var Q=e.i(793479),E=e.i(110204),U=e.i(776639),O=e.i(967489),H=e.i(373884),K=e.i(178583),X=e.i(37727);function Y(e,s=6){let t=[],a=[],n="",l=!1,i=0;for(;i<e.length&&t.length<s;){let s=e[i];l?'"'===s?i+1<e.length&&'"'===e[i+1]?(n+='"',i+=2):(l=!1,i++):(n+=s,i++):'"'===s?(l=!0,i++):","===s?(a.push(n.trim()),n="",i++):"\r"===s||"\n"===s?(a.push(n.trim()),n="",a.some(e=>""!==e)&&t.push(a),a=[],"\r"===s&&i+1<e.length&&"\n"===e[i+1]?i+=2:i++):(n+=s,i++)}return(n||a.length>0)&&(a.push(n.trim()),a.some(e=>""!==e)&&t.push(a)),t}function G(e){return e>1048576?`${(e/1048576).toFixed(1)} MB`:`${(e/1024).toFixed(1)} KB`}function J(e){return e.replace(/\.csv$/i,"").replace(/[^\w\s]/g,"").replace(/\s+/g,"_").toLowerCase().slice(0,64)||"imported_data"}function W(e){let a,n,l,i,c,o,d,m,h,x,u,g,f,j,b,N,y,w,C=(0,t.c)(72),{formHook:S,connections:_,onOpenCsvImport:F,onRemoveCsvTable:D}=e,{dialogOpen:A,setDialogOpen:L,editingId:I,form:P,setForm:T,isLocalType:B,testingConnection:z,testResult:M,pendingCsvFiles:R,pendingCsvFileRef:q,isFormValid:$,isSaving:V,handleTypeChange:Q,handleTestConnection:E,handleSave:O,handlePendingCsvFileSelect:H,removePendingCsvFile:K,updatePendingTableName:X}=S,Y="csv"===P.type&&"sm:max-w-xl";C[0]!==Y?(a=(0,k.cn)("sm:max-w-lg max-h-[85vh] flex! flex-col! p-4 sm:p-6",Y),C[0]=Y,C[1]=a):a=C[1];let G=I?"Edit Connection":"Add Connection";C[2]!==G?(n=(0,s.jsx)(U.DialogTitle,{children:G}),C[2]=G,C[3]=n):n=C[3];let J=I?"Update your database connection details.":"Configure a new database connection.";C[4]!==J?(l=(0,s.jsx)(U.DialogDescription,{children:J}),C[4]=J,C[5]=l):l=C[5],C[6]!==n||C[7]!==l?(i=(0,s.jsxs)(U.DialogHeader,{className:"shrink-0",children:[n,l]}),C[6]=n,C[7]=l,C[8]=i):i=C[8],C[9]!==P||C[10]!==T?(c=(0,s.jsx)(Z,{form:P,setForm:T}),C[9]=P,C[10]=T,C[11]=c):c=C[11],C[12]!==I||C[13]!==P||C[14]!==Q?(o=(0,s.jsx)(ee,{form:P,editingId:I,onTypeChange:Q}),C[12]=I,C[13]=P,C[14]=Q,C[15]=o):o=C[15],C[16]!==P||C[17]!==T?(d="sqlite"===P.type&&(0,s.jsx)(es,{form:P,setForm:T}),C[16]=P,C[17]=T,C[18]=d):d=C[18],C[19]!==I||C[20]!==P.type||C[21]!==H||C[22]!==q||C[23]!==R||C[24]!==K||C[25]!==X?(m="csv"===P.type&&!I&&(0,s.jsx)(ea,{pendingCsvFiles:R,pendingCsvFileRef:q,onFileSelect:H,onRemove:K,onUpdateTableName:X}),C[19]=I,C[20]=P.type,C[21]=H,C[22]=q,C[23]=R,C[24]=K,C[25]=X,C[26]=m):m=C[26],C[27]!==_||C[28]!==I||C[29]!==P.type||C[30]!==F||C[31]!==D||C[32]!==L?(h="csv"===P.type&&I&&(0,s.jsx)(en,{editingId:I,connections:_,onOpenCsvImport:F,onRemoveCsvTable:D,onCloseDialog:()=>L(!1)}),C[27]=_,C[28]=I,C[29]=P.type,C[30]=F,C[31]=D,C[32]=L,C[33]=h):h=C[33],C[34]!==P||C[35]!==B||C[36]!==T?(x=!B&&(0,s.jsx)(et,{form:P,setForm:T}),C[34]=P,C[35]=B,C[36]=T,C[37]=x):x=C[37],C[38]!==M?(u=M&&(0,s.jsx)(el,{testResult:M}),C[38]=M,C[39]=u):u=C[39],C[40]!==d||C[41]!==m||C[42]!==h||C[43]!==x||C[44]!==u||C[45]!==c||C[46]!==o?(g=(0,s.jsxs)("div",{className:"space-y-4 py-2 overflow-y-auto flex-1 min-h-0 -mx-4 sm:-mx-6 px-4 sm:px-6",children:[c,o,d,m,h,x,u]}),C[40]=d,C[41]=m,C[42]=h,C[43]=x,C[44]=u,C[45]=c,C[46]=o,C[47]=g):g=C[47],C[48]!==P.type||C[49]!==E||C[50]!==$||C[51]!==z?(f="csv"!==P.type&&(0,s.jsxs)(r.Button,{variant:"outline",onClick:E,disabled:!$||z,className:"gap-1.5",children:[z?(0,s.jsx)(p.Loader2,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(v,{className:"h-4 w-4"}),"Test Connection"]}),C[48]=P.type,C[49]=E,C[50]=$,C[51]=z,C[52]=f):f=C[52];let W=!$||V;C[53]!==V?(j=V&&(0,s.jsx)(p.Loader2,{className:"h-4 w-4 animate-spin"}),C[53]=V,C[54]=j):j=C[54];let ei=I?"Update":"csv"===P.type&&R.length>0?`Save & Import ${R.length} File${R.length>1?"s":""}`:"Save";return C[55]!==O||C[56]!==W||C[57]!==j||C[58]!==ei?(b=(0,s.jsxs)(r.Button,{onClick:O,disabled:W,className:"gap-1.5",children:[j,ei]}),C[55]=O,C[56]=W,C[57]=j,C[58]=ei,C[59]=b):b=C[59],C[60]!==f||C[61]!==b?(N=(0,s.jsxs)(U.DialogFooter,{className:"gap-2 sm:gap-0 shrink-0",children:[f,b]}),C[60]=f,C[61]=b,C[62]=N):N=C[62],C[63]!==g||C[64]!==a||C[65]!==N||C[66]!==i?(y=(0,s.jsxs)(U.DialogContent,{className:a,children:[i,g,N]}),C[63]=g,C[64]=a,C[65]=N,C[66]=i,C[67]=y):y=C[67],C[68]!==A||C[69]!==L||C[70]!==y?(w=(0,s.jsx)(U.Dialog,{open:A,onOpenChange:L,children:y}),C[68]=A,C[69]=L,C[70]=y,C[71]=w):w=C[71],w}function Z(e){let a,n,l,i=(0,t.c)(7),{form:r,setForm:c}=e,o="csv"===r.type?"e.g. Sales Data CSVs":"sqlite"===r.type?"e.g. Local SQLite DB":"e.g. Production Redshift";return i[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsx)(E.Label,{htmlFor:"conn-name",children:"Connection Name"}),i[0]=a):a=i[0],i[1]!==c?(n=e=>c(s=>({...s,name:e.target.value})),i[1]=c,i[2]=n):n=i[2],i[3]!==r.name||i[4]!==o||i[5]!==n?(l=(0,s.jsxs)("div",{className:"space-y-2",children:[a,(0,s.jsx)(Q.Input,{id:"conn-name",placeholder:o,value:r.name,onChange:n})]}),i[3]=r.name,i[4]=o,i[5]=n,i[6]=l):l=i[6],l}function ee(e){let a,n,l,i,r,c=(0,t.c)(9),{form:o,editingId:d,onTypeChange:m}=e;c[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsx)(E.Label,{children:"Database Type"}),c[0]=a):a=c[0],c[1]!==m?(n=e=>m(e),c[1]=m,c[2]=n):n=c[2];let h=!!d;return c[3]===Symbol.for("react.memo_cache_sentinel")?(l=(0,s.jsx)(O.SelectTrigger,{children:(0,s.jsx)(O.SelectValue,{})}),c[3]=l):l=c[3],c[4]===Symbol.for("react.memo_cache_sentinel")?(i=(0,s.jsxs)(O.SelectContent,{children:[(0,s.jsx)(O.SelectItem,{value:"postgresql",children:"PostgreSQL"}),(0,s.jsx)(O.SelectItem,{value:"redshift",children:"Amazon Redshift"}),(0,s.jsx)(O.SelectItem,{value:"mysql",children:"MySQL"}),(0,s.jsx)(O.SelectItem,{value:"sqlite",children:"SQLite"}),(0,s.jsx)(O.SelectItem,{value:"csv",children:"CSV Import"})]}),c[4]=i):i=c[4],c[5]!==o.type||c[6]!==n||c[7]!==h?(r=(0,s.jsxs)("div",{className:"space-y-2",children:[a,(0,s.jsxs)(O.Select,{value:o.type,onValueChange:n,disabled:h,children:[l,i]})]}),c[5]=o.type,c[6]=n,c[7]=h,c[8]=r):r=c[8],r}function es(e){let a,n,l,i,r,c=(0,t.c)(9),{form:o,setForm:d}=e;return c[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsx)(E.Label,{htmlFor:"conn-filepath",children:"Database File Path"}),c[0]=a):a=c[0],c[1]!==d?(n=e=>d(s=>({...s,filePath:e.target.value})),c[1]=d,c[2]=n):n=c[2],c[3]!==o.filePath||c[4]!==n?(l=(0,s.jsx)(Q.Input,{id:"conn-filepath",placeholder:"/path/to/your/database.db",value:o.filePath,onChange:n}),c[3]=o.filePath,c[4]=n,c[5]=l):l=c[5],c[6]===Symbol.for("react.memo_cache_sentinel")?(i=(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Full path to the SQLite database file on your local machine"}),c[6]=i):i=c[6],c[7]!==l?(r=(0,s.jsxs)("div",{className:"space-y-2",children:[a,l,i]}),c[7]=l,c[8]=r):r=c[8],r}function et(e){let a,n,l,i,r,c,o,d,m,h,x,u,p,g,f,j,b,v,N,y,w=(0,t.c)(46),{form:C,setForm:S}=e;w[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsx)(E.Label,{htmlFor:"conn-host",children:"Host"}),w[0]=a):a=w[0],w[1]!==S?(n=e=>S(s=>({...s,host:e.target.value})),w[1]=S,w[2]=n):n=w[2],w[3]!==C.host||w[4]!==n?(l=(0,s.jsxs)("div",{className:"space-y-2",children:[a,(0,s.jsx)(Q.Input,{id:"conn-host",placeholder:"localhost",value:C.host,onChange:n})]}),w[3]=C.host,w[4]=n,w[5]=l):l=w[5],w[6]===Symbol.for("react.memo_cache_sentinel")?(i=(0,s.jsx)(E.Label,{htmlFor:"conn-port",children:"Port"}),w[6]=i):i=w[6];let k=String(D[C.type]);return w[7]!==S?(r=e=>S(s=>({...s,port:e.target.value})),w[7]=S,w[8]=r):r=w[8],w[9]!==C.port||w[10]!==k||w[11]!==r?(c=(0,s.jsxs)("div",{className:"space-y-2",children:[i,(0,s.jsx)(Q.Input,{id:"conn-port",placeholder:k,value:C.port,onChange:r})]}),w[9]=C.port,w[10]=k,w[11]=r,w[12]=c):c=w[12],w[13]===Symbol.for("react.memo_cache_sentinel")?(o=(0,s.jsx)(E.Label,{htmlFor:"conn-database",children:"Database"}),w[13]=o):o=w[13],w[14]!==S?(d=e=>S(s=>({...s,database:e.target.value})),w[14]=S,w[15]=d):d=w[15],w[16]!==C.database||w[17]!==d?(m=(0,s.jsxs)("div",{className:"space-y-2",children:[o,(0,s.jsx)(Q.Input,{id:"conn-database",placeholder:"my_database",value:C.database,onChange:d})]}),w[16]=C.database,w[17]=d,w[18]=m):m=w[18],w[19]===Symbol.for("react.memo_cache_sentinel")?(h=(0,s.jsx)(E.Label,{htmlFor:"conn-user",children:"Username"}),w[19]=h):h=w[19],w[20]!==S?(x=e=>S(s=>({...s,user:e.target.value})),w[20]=S,w[21]=x):x=w[21],w[22]!==C.user||w[23]!==x?(u=(0,s.jsxs)("div",{className:"space-y-2",children:[h,(0,s.jsx)(Q.Input,{id:"conn-user",placeholder:"postgres",value:C.user,onChange:x})]}),w[22]=C.user,w[23]=x,w[24]=u):u=w[24],w[25]===Symbol.for("react.memo_cache_sentinel")?(p=(0,s.jsx)(E.Label,{htmlFor:"conn-password",children:"Password"}),w[25]=p):p=w[25],w[26]!==S?(g=e=>S(s=>({...s,password:e.target.value})),w[26]=S,w[27]=g):g=w[27],w[28]!==C.password||w[29]!==g?(f=(0,s.jsxs)("div",{className:"space-y-2",children:[p,(0,s.jsx)(Q.Input,{id:"conn-password",type:"password",placeholder:"••••••••",value:C.password,onChange:g})]}),w[28]=C.password,w[29]=g,w[30]=f):f=w[30],w[31]!==S?(j=e=>S(s=>({...s,ssl:e.target.checked})),w[31]=S,w[32]=j):j=w[32],w[33]!==C.ssl||w[34]!==j?(b=(0,s.jsx)("input",{type:"checkbox",id:"conn-ssl",checked:C.ssl,onChange:j,className:"rounded border-border"}),w[33]=C.ssl,w[34]=j,w[35]=b):b=w[35],w[36]===Symbol.for("react.memo_cache_sentinel")?(v=(0,s.jsx)(E.Label,{htmlFor:"conn-ssl",className:"text-sm font-normal cursor-pointer",children:"Use SSL"}),w[36]=v):v=w[36],w[37]!==b?(N=(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[b,v]}),w[37]=b,w[38]=N):N=w[38],w[39]!==m||w[40]!==u||w[41]!==f||w[42]!==N||w[43]!==l||w[44]!==c?(y=(0,s.jsxs)(s.Fragment,{children:[l,c,m,u,f,N]}),w[39]=m,w[40]=u,w[41]=f,w[42]=N,w[43]=l,w[44]=c,w[45]=y):y=w[45],y}function ea(e){let a,n,l,i,c,d,m,h,x=(0,t.c)(20),{pendingCsvFiles:u,pendingCsvFileRef:p,onFileSelect:g,onRemove:f,onUpdateTableName:j}=e;return x[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsx)(E.Label,{className:"text-xs",children:"CSV Files"}),x[0]=a):a=x[0],x[1]!==p?(n=()=>p.current?.click(),x[1]=p,x[2]=n):n=x[2],x[3]===Symbol.for("react.memo_cache_sentinel")?(l=(0,s.jsx)(o.Plus,{className:"h-3 w-3"}),x[3]=l):l=x[3],x[4]!==n?(i=(0,s.jsxs)(r.Button,{variant:"outline",size:"sm",onClick:n,className:"text-xs gap-1 h-7 text-green-400 border-green-400/30 hover:bg-green-400/10",children:[l,"Add CSV"]}),x[4]=n,x[5]=i):i=x[5],x[6]!==g||x[7]!==p?(c=(0,s.jsx)("input",{ref:p,type:"file",accept:".csv",onChange:g,className:"hidden"}),x[6]=g,x[7]=p,x[8]=c):c=x[8],x[9]!==i||x[10]!==c?(d=(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[a,i,c]}),x[9]=i,x[10]=c,x[11]=d):d=x[11],x[12]!==f||x[13]!==j||x[14]!==p||x[15]!==u?(m=0===u.length?(0,s.jsxs)("div",{onClick:()=>p.current?.click(),className:"rounded-lg border-2 border-dashed p-6 text-center cursor-pointer transition-colors hover:border-green-400/40 hover:bg-green-400/5",children:[(0,s.jsx)(y,{className:"h-6 w-6 text-muted-foreground/40 mx-auto mb-2"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Click to add CSV files — each file becomes a queryable table"})]}):(0,s.jsx)("div",{className:"rounded-lg border divide-y",children:u.map((e,t)=>(0,s.jsxs)("div",{className:"px-3 py-2.5 space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(K.FileText,{className:"h-4 w-4 shrink-0 text-green-400/70"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:e.fileName}),(0,s.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:[G(e.fileSize),e.previewRows.length>0&&(0,s.jsxs)(s.Fragment,{children:[" · ",e.previewRows[0]?.length||0," columns"]})]})]}),(0,s.jsx)(r.Button,{variant:"ghost",size:"sm",onClick:()=>f(t),className:"h-7 w-7 p-0 text-destructive hover:text-destructive shrink-0",children:(0,s.jsx)(X.X,{className:"h-3 w-3"})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(E.Label,{className:"text-[11px] text-muted-foreground shrink-0 w-16",children:"Table name"}),(0,s.jsx)(Q.Input,{value:e.tableName,onChange:e=>j(t,e.target.value),className:"h-7 text-xs font-mono"})]})]},t))}),x[12]=f,x[13]=j,x[14]=p,x[15]=u,x[16]=m):m=x[16],x[17]!==d||x[18]!==m?(h=(0,s.jsxs)("div",{className:"space-y-3",children:[d,m]}),x[17]=d,x[18]=m,x[19]=h):h=x[19],h}function en(e){let a,n=(0,t.c)(16),{editingId:l,connections:i,onOpenCsvImport:c,onRemoveCsvTable:o,onCloseDialog:d}=e;if(n[0]!==i||n[1]!==l||n[2]!==d||n[3]!==c||n[4]!==o){let e,t,m,h,x;n[6]!==l?(e=e=>e.id===l,n[6]=l,n[7]=e):e=n[7];let u=i.find(e),p=u?.csvFiles||[];n[8]===Symbol.for("react.memo_cache_sentinel")?(t=(0,s.jsx)(E.Label,{className:"text-xs",children:"Imported CSV Files"}),n[8]=t):t=n[8],n[9]!==l||n[10]!==d||n[11]!==c?(m=()=>{d(),c(l)},n[9]=l,n[10]=d,n[11]=c,n[12]=m):m=n[12],n[13]===Symbol.for("react.memo_cache_sentinel")?(h=(0,s.jsx)(y,{className:"h-3 w-3"}),n[13]=h):h=n[13],n[14]!==m?(x=(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[t,(0,s.jsxs)(r.Button,{variant:"outline",size:"sm",onClick:m,className:"text-xs gap-1 h-7 text-green-400 border-green-400/30 hover:bg-green-400/10",children:[h,"Import CSV"]})]}),n[14]=m,n[15]=x):x=n[15],a=(0,s.jsxs)("div",{className:"space-y-3",children:[x,0===p.length?(0,s.jsxs)("div",{className:"rounded-lg border border-dashed p-4 text-center",children:[(0,s.jsx)(_.FileSpreadsheet,{className:"h-6 w-6 text-muted-foreground/40 mx-auto mb-2"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"No CSV files imported yet"})]}):(0,s.jsx)("div",{className:"rounded-lg border divide-y max-h-64 overflow-y-auto",children:p.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[(0,s.jsx)(w.Table2,{className:"h-4 w-4 shrink-0 text-green-400/70"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,s.jsx)("p",{className:"text-xs font-medium font-mono truncate",title:e.tableName,children:e.tableName}),(0,s.jsxs)("p",{className:"text-[11px] text-muted-foreground truncate",title:e.fileName,children:[e.fileName,null!=e.rowCount&&` \xb7 ${e.rowCount} rows`]})]}),(0,s.jsx)(r.Button,{variant:"ghost",size:"sm",onClick:()=>o(l,e.tableName),className:"h-7 w-7 p-0 shrink-0 text-destructive hover:text-destructive",children:(0,s.jsx)(S.Trash2,{className:"h-3.5 w-3.5"})})]},e.tableName))})]}),n[0]=i,n[1]=l,n[2]=d,n[3]=c,n[4]=o,n[5]=a}else a=n[5];return a}function el(e){let a,n,l,i=(0,t.c)(9),{testResult:r}=e,c=r.success?"bg-green-500/10 text-green-500 border border-green-500/20":"bg-destructive/10 text-destructive border border-destructive/20";return i[0]!==c?(a=(0,k.cn)("rounded-lg p-3 text-sm flex items-center gap-2",c),i[0]=c,i[1]=a):a=i[1],i[2]!==r.error||i[3]!==r.latencyMs||i[4]!==r.success?(n=r.success?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(f.CheckCircle2,{className:"h-4 w-4 shrink-0"}),(0,s.jsxs)("span",{children:["Connected successfully (",r.latencyMs,"ms)"]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(H.XCircle,{className:"h-4 w-4 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:r.error})]}),i[2]=r.error,i[3]=r.latencyMs,i[4]=r.success,i[5]=n):n=i[5],i[6]!==a||i[7]!==n?(l=(0,s.jsx)("div",{className:a,children:n}),i[6]=a,i[7]=n,i[8]=l):l=i[8],l}function ei(e){let a,n,l,i,r,c,o,d,m,h,x=(0,t.c)(29),{previewRows:u,totalLineCount:p}=e;if(u.length<=1)return null;let g=u[0];if(x[0]!==g||x[1]!==u){let e,t,c=u.slice(1,6);r="rounded-lg border overflow-hidden",i="overflow-auto max-h-48",n="text-xs",x[7]!==g?(e=g.map(er),x[7]=g,x[8]=e):e=x[8],x[9]!==e?(l=(0,s.jsx)("thead",{className:"sticky top-0",children:(0,s.jsx)("tr",{className:"bg-muted/80 border-b",children:e})}),x[9]=e,x[10]=l):l=x[10],x[11]!==g?(t=(e,t)=>(0,s.jsx)("tr",{className:"border-b last:border-0 hover:bg-muted/30",children:g.map((t,a)=>(0,s.jsx)("td",{className:"px-2.5 py-1 text-muted-foreground font-mono text-[11px] whitespace-nowrap max-w-[180px] truncate",children:(e[a]??"").length>30?(e[a]??"").slice(0,28)+"…":e[a]??""},a))},t),x[11]=g,x[12]=t):t=x[12],a=c.map(t),x[0]=g,x[1]=u,x[2]=a,x[3]=n,x[4]=l,x[5]=i,x[6]=r}else a=x[2],n=x[3],l=x[4],i=x[5],r=x[6];return x[13]!==a?(c=(0,s.jsx)("tbody",{children:a}),x[13]=a,x[14]=c):c=x[14],x[15]!==n||x[16]!==l||x[17]!==c?(o=(0,s.jsxs)("table",{className:n,children:[l,c]}),x[15]=n,x[16]=l,x[17]=c,x[18]=o):o=x[18],x[19]!==i||x[20]!==o?(d=(0,s.jsx)("div",{className:i,children:o}),x[19]=i,x[20]=o,x[21]=d):d=x[21],x[22]!==u.length||x[23]!==p?(m=p&&p>6&&(0,s.jsxs)("div",{className:"px-3 py-1 text-[10px] text-muted-foreground/60 bg-muted/30 border-t text-center",children:["Showing first ",Math.min(u.length-1,5)," rows · full file will be imported"]}),x[22]=u.length,x[23]=p,x[24]=m):m=x[24],x[25]!==r||x[26]!==d||x[27]!==m?(h=(0,s.jsxs)("div",{className:r,children:[d,m]}),x[25]=r,x[26]=d,x[27]=m,x[28]=h):h=x[28],h}function er(e,t){return(0,s.jsx)("th",{className:"px-2.5 py-1.5 text-left font-semibold text-foreground whitespace-nowrap text-[11px]",children:e.length>24?e.slice(0,22)+"…":e||`col_${t+1}`},t)}function ec(e){let a,n,l,i,c,o,d,m,h,x,u,g=(0,t.c)(37),{csvImport:f}=e,{dialogOpen:j,setDialogOpen:b,tableName:v,setTableName:N,fileName:w,fileSize:C,content:S,previewRows:k,importing:F,fileRef:D,isImportValid:A,handleFileSelect:L,handleImport:I}=f;g[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,s.jsxs)(U.DialogHeader,{className:"shrink-0",children:[(0,s.jsxs)(U.DialogTitle,{className:"flex items-center gap-2",children:[(0,s.jsx)(_.FileSpreadsheet,{className:"h-5 w-5 text-green-400"}),"Import CSV File"]}),(0,s.jsx)(U.DialogDescription,{children:"Each imported CSV becomes a queryable SQL table."})]}),g[0]=a):a=g[0],g[1]!==w||g[2]!==D||g[3]!==C||g[4]!==L||g[5]!==k?(n=(0,s.jsx)(eo,{fileRef:D,fileName:w,fileSize:C,previewRows:k,onFileSelect:L}),g[1]=w,g[2]=D,g[3]=C,g[4]=L,g[5]=k,g[6]=n):n=g[6],g[7]!==w||g[8]!==N||g[9]!==v?(l=w&&(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(E.Label,{htmlFor:"csv-table",className:"text-xs",children:"Table Name"}),(0,s.jsx)(Q.Input,{id:"csv-table",placeholder:"e.g. sales_data",value:v,onChange:e=>N(e.target.value),className:"h-9"}),(0,s.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:["SQL table name — you'll query it as"," ",(0,s.jsxs)("code",{className:"bg-muted px-1 rounded",children:["SELECT * FROM ",v||"table_name"]})]})]}),g[7]=w,g[8]=N,g[9]=v,g[10]=l):l=g[10],g[11]!==S||g[12]!==k?(i=k.length>1&&(0,s.jsxs)("div",{className:"space-y-1.5 min-w-0",children:[(0,s.jsx)(E.Label,{className:"text-xs",children:"Preview"}),(0,s.jsx)(ei,{previewRows:k,totalLineCount:S.split("\n").length})]}),g[11]=S,g[12]=k,g[13]=i):i=g[13],g[14]!==n||g[15]!==l||g[16]!==i?(c=(0,s.jsxs)("div",{className:"space-y-4 py-2 overflow-y-auto flex-1 min-h-0",children:[n,l,i]}),g[14]=n,g[15]=l,g[16]=i,g[17]=c):c=g[17],g[18]!==b?(o=(0,s.jsx)(r.Button,{variant:"outline",onClick:()=>b(!1),children:"Cancel"}),g[18]=b,g[19]=o):o=g[19];let P=!A||F;g[20]!==F?(d=F?(0,s.jsx)(p.Loader2,{className:"h-4 w-4 animate-spin"}):(0,s.jsx)(y,{className:"h-4 w-4"}),g[20]=F,g[21]=d):d=g[21];let T=F?"Importing...":"Import";return g[22]!==I||g[23]!==P||g[24]!==d||g[25]!==T?(m=(0,s.jsxs)(r.Button,{onClick:I,disabled:P,className:"gap-1.5",children:[d,T]}),g[22]=I,g[23]=P,g[24]=d,g[25]=T,g[26]=m):m=g[26],g[27]!==m||g[28]!==o?(h=(0,s.jsxs)(U.DialogFooter,{className:"shrink-0",children:[o,m]}),g[27]=m,g[28]=o,g[29]=h):h=g[29],g[30]!==h||g[31]!==c?(x=(0,s.jsxs)(U.DialogContent,{className:"sm:max-w-xl max-h-[85vh] flex! flex-col! overflow-hidden p-4 sm:p-6",children:[a,c,h]}),g[30]=h,g[31]=c,g[32]=x):x=g[32],g[33]!==j||g[34]!==b||g[35]!==x?(u=(0,s.jsx)(U.Dialog,{open:j,onOpenChange:b,children:x}),g[33]=j,g[34]=b,g[35]=x,g[36]=u):u=g[36],u}function eo(e){let a,n,l,i,r,c=(0,t.c)(16),{fileRef:o,fileName:d,fileSize:m,previewRows:h,onFileSelect:x}=e;c[0]!==o?(a=()=>o.current?.click(),c[0]=o,c[1]=a):a=c[1];let u=d?"border-green-400/30 bg-green-400/5":"border-border";return c[2]!==u?(n=(0,k.cn)("border-2 border-dashed rounded-lg px-4 py-3 cursor-pointer transition-colors","hover:border-primary/50 hover:bg-primary/5",u),c[2]=u,c[3]=n):n=c[3],c[4]!==o||c[5]!==x?(l=(0,s.jsx)("input",{ref:o,type:"file",accept:".csv",onChange:x,className:"hidden"}),c[4]=o,c[5]=x,c[6]=l):l=c[6],c[7]!==d||c[8]!==m||c[9]!==h?(i=d?(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(K.FileText,{className:"h-5 w-5 text-green-400 shrink-0"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium truncate",children:d}),(0,s.jsxs)("p",{className:"text-xs text-muted-foreground",children:[m>0&&G(m),h.length>1&&(0,s.jsxs)(s.Fragment,{children:[" · ",h[0]?.length||0," columns detected"]})]})]}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground shrink-0",children:"Change file"})]}):(0,s.jsxs)("div",{className:"flex items-center gap-3 justify-center py-2",children:[(0,s.jsx)(y,{className:"h-5 w-5 text-muted-foreground"}),(0,s.jsx)("span",{className:"text-sm text-muted-foreground",children:"Click to select a CSV file"})]}),c[7]=d,c[8]=m,c[9]=h,c[10]=i):i=c[10],c[11]!==a||c[12]!==n||c[13]!==l||c[14]!==i?(r=(0,s.jsxs)("div",{onClick:a,className:n,children:[l,i]}),c[11]=a,c[12]=n,c[13]=l,c[14]=i,c[15]=r):r=c[15],r}var ed=e.i(271645);function em(){let e,l,i,r,c,o,d,m,x,u,p,g,f,j=(0,t.c)(44),{data:b,isLoading:v}=a.api.connection.list.useQuery(),N=a.api.connection.delete.useMutation(),y=a.api.connection.setActive.useMutation(),w=a.api.connection.testExisting.useMutation(),C=a.api.connection.removeCsvTable.useMutation(),S=a.api.useUtils();j[0]!==b?.connections?(e=b?.connections||[],j[0]=b?.connections,j[1]=e):e=j[1];let k=e,_=b?.activeConnectionId;j[2]!==S.connection.list?(l=()=>{S.connection.list.invalidate()},j[2]=S.connection.list,j[3]=l):l=j[3];let F=l;j[4]!==F?(i={onSaved:F},j[4]=F,j[5]=i):i=j[5];let L=function({onSaved:e}){let[s,t]=(0,ed.useState)(!1),[l,i]=(0,ed.useState)(null),[r,c]=(0,ed.useState)(A),[o,d]=(0,ed.useState)(!1),[m,h]=(0,ed.useState)(null),[x,u]=(0,ed.useState)([]),p=(0,ed.useRef)(null),g=a.api.connection.add.useMutation(),f=a.api.connection.update.useMutation(),j=a.api.connection.test.useMutation(),b=a.api.connection.importCsv.useMutation(),v=a.api.useUtils(),N="sqlite"===r.type||"csv"===r.type,y=(0,ed.useCallback)(()=>{i(null),c(A),h(null),u([]),t(!0)},[]),w=(0,ed.useCallback)(async e=>{i(e),h(null);let s=await v.connection.get.fetch({id:e});if(s.connection){let e=s.connection;c({name:e.name,type:e.type,host:e.host||"",port:String(e.port||0),user:e.user||"",password:e.password||"",database:e.database||"",ssl:e.ssl||!1,filePath:e.filePath||""})}t(!0)},[v]),C=(0,ed.useCallback)(e=>{c(s=>({...s,type:e,..."sqlite"===e||"csv"===e?{host:"",port:"0",user:"",password:"",database:"",ssl:!1}:{port:String(D[e]),filePath:""}})),"csv"!==e&&u([])},[]),S=(0,ed.useCallback)(async()=>{d(!0),h(null);try{let e=await j.mutateAsync({name:r.name||"Test",type:r.type,host:r.host||"",port:parseInt(r.port)||D[r.type],user:r.user||"",password:r.password||"",database:r.database||"",ssl:r.ssl,filePath:r.filePath||void 0});h(e)}catch(e){h({success:!1,error:e.message||"Connection test failed"})}finally{d(!1)}},[r,j]),k=(0,ed.useCallback)(async()=>{try{let s={name:r.name,type:r.type,host:r.host||"",port:parseInt(r.port)||D[r.type],user:r.user||"",password:r.password||"",database:r.database||"",ssl:r.ssl,filePath:r.filePath||void 0};if(l)await f.mutateAsync({id:l,data:s}),n.toast.success("Connection updated");else{let e=await g.mutateAsync(s);if("csv"===r.type&&x.length>0&&e.connection){let s=e.connection.id,t=0;for(let e of x)try{await b.mutateAsync({connectionId:s,csvContent:e.content,tableName:e.tableName,fileName:e.fileName}),t++}catch(s){n.toast.error(`Failed to import ${e.fileName}: ${s.message}`)}n.toast.success(t>0?`Connection created with ${t} CSV file(s) imported`:"Connection added")}else n.toast.success("Connection added");u([])}t(!1),e()}catch(e){n.toast.error(e.message||"Failed to save connection")}},[r,l,g,f,b,x,e]),_=(0,ed.useCallback)(e=>{let s=e.target.files?.[0];if(!s)return;let t=J(s.name),a=new FileReader;a.onload=e=>{let a=e.target?.result||"",n=Y(a,4);u(e=>[...e,{fileName:s.name,tableName:t,content:a,fileSize:s.size,previewRows:n}])},a.readAsText(s),p.current&&(p.current.value="")},[]),F=(0,ed.useCallback)(e=>{u(s=>s.filter((s,t)=>t!==e))},[]),L=(0,ed.useCallback)((e,s)=>{u(t=>t.map((t,a)=>a===e?{...t,tableName:s}:t))},[]),I=!!r.name.trim()&&("sqlite"===r.type?!!r.filePath?.trim():"csv"===r.type?!!l||x.length>0:!!(r.host.trim()&&r.port.trim()&&r.user.trim()&&r.password.trim()&&r.database.trim()));return{dialogOpen:s,setDialogOpen:t,editingId:l,form:r,setForm:c,isLocalType:N,testingConnection:o,testResult:m,pendingCsvFiles:x,pendingCsvFileRef:p,isFormValid:I,isSaving:g.isPending||f.isPending,openAddDialog:y,openEditDialog:w,handleTypeChange:C,handleTestConnection:S,handleSave:k,handlePendingCsvFileSelect:_,removePendingCsvFile:F,updatePendingTableName:L}}(i);j[6]!==F?(r={onImported:F},j[6]=F,j[7]=r):r=j[7];let I=function({onImported:e}){let[s,t]=(0,ed.useState)(!1),[l,i]=(0,ed.useState)(null),[r,c]=(0,ed.useState)(""),[o,d]=(0,ed.useState)(""),[m,h]=(0,ed.useState)(""),[x,u]=(0,ed.useState)(0),[p,g]=(0,ed.useState)([]),[f,j]=(0,ed.useState)(!1),b=(0,ed.useRef)(null),v=a.api.connection.importCsv.useMutation(),N=(0,ed.useCallback)(e=>{i(e),c(""),d(""),h(""),u(0),g([]),t(!0),b.current&&(b.current.value="")},[]),y=(0,ed.useCallback)(e=>{let s=e.target.files?.[0];if(!s)return;d(s.name),u(s.size),c(J(s.name));let t=new FileReader;t.onload=e=>{let s=e.target?.result||"";h(s),g(Y(s,6))},t.readAsText(s)},[]),w=(0,ed.useCallback)(async()=>{if(l&&m&&r){j(!0);try{let s=await v.mutateAsync({connectionId:l,csvContent:m,tableName:r,fileName:o});n.toast.success(`Imported ${s.rowCount} rows into table "${s.tableName}"`),t(!1),e()}catch(e){n.toast.error(e.message||"Failed to import CSV")}finally{j(!1)}}},[l,m,r,o,v,e]),C=!!(m&&r.trim());return{dialogOpen:s,setDialogOpen:t,tableName:r,setTableName:c,fileName:o,fileSize:x,content:m,previewRows:p,importing:f,fileRef:b,isImportValid:C,openDialog:N,handleFileSelect:y,handleImport:w}}(r);j[8]!==N||j[9]!==F?(c=async(e,s)=>{if(confirm(`Delete connection "${s}"? This cannot be undone.`))try{await N.mutateAsync({id:e}),n.toast.success("Connection deleted"),F()}catch(e){n.toast.error(e.message||"Failed to delete connection")}},j[8]=N,j[9]=F,j[10]=c):c=j[10];let P=c;j[11]!==F||j[12]!==y?(o=async e=>{try{await y.mutateAsync({id:e}),F(),n.toast.success("Active connection updated")}catch(e){n.toast.error(e.message||"Failed to set active connection")}},j[11]=F,j[12]=y,j[13]=o):o=j[13];let T=o;j[14]!==w?(d=async e=>{try{let s=await w.mutateAsync({id:e});s.success?n.toast.success(`Connection successful (${s.latencyMs}ms)`):n.toast.error(`Connection failed: ${s.error}`)}catch(e){n.toast.error(e.message||"Test failed")}},j[14]=w,j[15]=d):d=j[15];let B=d;j[16]!==F||j[17]!==C?(m=async(e,s)=>{if(confirm(`Remove table "${s}"? This will delete the imported data.`))try{await C.mutateAsync({connectionId:e,tableName:s}),n.toast.success(`Table "${s}" removed`),F()}catch(e){n.toast.error(e.message||"Failed to remove table")}},j[16]=F,j[17]=C,j[18]=m):m=j[18];let z=m;return j[19]!==L.openAddDialog?(x=(0,s.jsx)(h,{onAddConnection:L.openAddDialog}),j[19]=L.openAddDialog,j[20]=x):x=j[20],j[21]!==_||j[22]!==k||j[23]!==I.openDialog||j[24]!==L.openAddDialog||j[25]!==L.openEditDialog||j[26]!==P||j[27]!==T||j[28]!==B||j[29]!==v||j[30]!==w.isPending?(u=(0,s.jsx)("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 -mt-4 sm:-mt-8 pb-8 sm:pb-12",children:(0,s.jsx)($,{connections:k,activeConnectionId:_,isLoading:v,isTestPending:w.isPending,onAdd:L.openAddDialog,onSetActive:T,onTestExisting:B,onEdit:L.openEditDialog,onDelete:P,onImportCsv:I.openDialog})}),j[21]=_,j[22]=k,j[23]=I.openDialog,j[24]=L.openAddDialog,j[25]=L.openEditDialog,j[26]=P,j[27]=T,j[28]=B,j[29]=v,j[30]=w.isPending,j[31]=u):u=j[31],j[32]!==k||j[33]!==I.openDialog||j[34]!==L||j[35]!==z?(p=(0,s.jsx)(W,{formHook:L,connections:k,onOpenCsvImport:I.openDialog,onRemoveCsvTable:z}),j[32]=k,j[33]=I.openDialog,j[34]=L,j[35]=z,j[36]=p):p=j[36],j[37]!==I?(g=(0,s.jsx)(ec,{csvImport:I}),j[37]=I,j[38]=g):g=j[38],j[39]!==p||j[40]!==g||j[41]!==x||j[42]!==u?(f=(0,s.jsxs)("div",{className:"min-h-screen bg-background overflow-x-hidden",children:[x,u,p,g]}),j[39]=p,j[40]=g,j[41]=x,j[42]=u,j[43]=f):f=j[43],f}e.s(["ConnectionsPage",()=>em],775258)}]);
|