neural-loom 0.2.49 → 0.2.51
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/BUILD_ID +1 -1
- package/.next/build-manifest.json +3 -3
- package/.next/cache/.previewinfo +1 -1
- package/.next/cache/.rscinfo +1 -1
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/diagnostics/route-bundle-stats.json +2 -2
- package/.next/fallback-build-manifest.json +3 -3
- package/.next/prerender-manifest.json +3 -3
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/context/aider/route.js.nft.json +1 -1
- package/.next/server/app/api/context/claude/route.js.nft.json +1 -1
- package/.next/server/app/api/context/route.js.nft.json +1 -1
- package/.next/server/app/api/context/ssh/route.js.nft.json +1 -1
- package/.next/server/app/api/recents/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/inject/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/input/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/launch/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/scope/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/start/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/stats/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/stop/route.js.nft.json +1 -1
- package/.next/server/app/api/sql/connections/route.js.nft.json +1 -1
- package/.next/server/app/api/sql/mcp/route.js.nft.json +1 -1
- package/.next/server/app/api/sql/query/route.js.nft.json +1 -1
- package/.next/server/app/api/sql/schema/route.js.nft.json +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/page/react-loadable-manifest.json +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0.ptwor._.js +49 -9
- package/.next/server/chunks/[root-of-the-server]__0.ptwor._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__00l5btc._.js +49 -9
- package/.next/server/chunks/[root-of-the-server]__00l5btc._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__06men8g._.js +41 -1
- package/.next/server/chunks/[root-of-the-server]__06men8g._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__0_o7_jj._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0_o7_jj._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__0co.g5k._.js +41 -1
- package/.next/server/chunks/[root-of-the-server]__0co.g5k._.js.map +1 -1
- package/.next/server/chunks/ssr/_0t7oqy6._.js +6 -1
- package/.next/server/chunks/ssr/_0t7oqy6._.js.map +1 -1
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/0bb9anc7wd3_e.js +6 -0
- package/.next/static/chunks/0p28yw2f2duy-.js +1 -0
- package/.next/trace +1 -1
- package/.next/trace-build +1 -1
- package/package.json +1 -1
- package/src/app/components/DbExplorer.tsx +28 -13
- package/src/app/page.tsx +9 -0
- package/src/lib/sql/ConnectionManager.ts +4 -1
- package/src/lib/sql/adapters/MssqlAdapter.ts +151 -0
- package/.next/static/chunks/03f4bqk_d65hs.js +0 -6
- package/.next/static/chunks/0~6gm~u8rgtpd.js +0 -1
- /package/.next/static/{BoncS4SNz6CDpSdR8oY-K → iopRcvtUwbEGa5VOyZAQh}/_buildManifest.js +0 -0
- /package/.next/static/{BoncS4SNz6CDpSdR8oY-K → iopRcvtUwbEGa5VOyZAQh}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{BoncS4SNz6CDpSdR8oY-K → iopRcvtUwbEGa5VOyZAQh}/_ssgManifest.js +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module.exports=[93695,(e,t,a)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},18622,(e,t,a)=>{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"))},56704,(e,t,a)=>{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"))},32319,(e,t,a)=>{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"))},24725,(e,t,a)=>{t.exports=e.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},70406,(e,t,a)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},14747,(e,t,a)=>{t.exports=e.x("path",()=>require("path"))},46786,(e,t,a)=>{t.exports=e.x("os",()=>require("os"))},98003,e=>{"use strict";var t=e.i(22734),a=e.i(14747),n=e.i(46786);let r=null;function s(e){try{t.default.existsSync(e)||t.default.mkdirSync(e,{recursive:!0});let n=a.default.join(e,".write-test-"+Math.random().toString(36).substring(7));return t.default.writeFileSync(n,"test"),t.default.unlinkSync(n),!0}catch{return!1}}e.s(["getConfigDir",0,function(){if(r)return r;let e=a.default.join(process.env.ORIGINAL_CWD||process.cwd(),".ai","neural-loom");try{t.default.existsSync(e)||t.default.mkdirSync(e,{recursive:!0});let n=a.default.join(e,".write-test-"+Math.random().toString(36).substring(7));return t.default.writeFileSync(n,"test"),t.default.unlinkSync(n),r=e,e}catch(
|
|
1
|
+
module.exports=[93695,(e,t,a)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},18622,(e,t,a)=>{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"))},56704,(e,t,a)=>{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"))},32319,(e,t,a)=>{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"))},24725,(e,t,a)=>{t.exports=e.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},70406,(e,t,a)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},14747,(e,t,a)=>{t.exports=e.x("path",()=>require("path"))},46786,(e,t,a)=>{t.exports=e.x("os",()=>require("os"))},98003,e=>{"use strict";var t=e.i(22734),a=e.i(14747),n=e.i(46786);let r=null;function s(e){try{t.default.existsSync(e)||t.default.mkdirSync(e,{recursive:!0});let n=a.default.join(e,".write-test-"+Math.random().toString(36).substring(7));return t.default.writeFileSync(n,"test"),t.default.unlinkSync(n),!0}catch{return!1}}e.s(["getConfigDir",0,function(){if(r)return r;let e=a.default.join(process.env.ORIGINAL_CWD||process.cwd(),".ai","neural-loom");try{t.default.existsSync(e)||t.default.mkdirSync(e,{recursive:!0});let n=a.default.join(e,".write-test-"+Math.random().toString(36).substring(7));return t.default.writeFileSync(n,"test"),t.default.unlinkSync(n),r=e,e}catch(o){console.warn(`[Config] Primary config dir is not writable (${e}). Falling back to home directory.`);let s=a.default.join(n.default.homedir(),".ai","neural-loom");try{return t.default.existsSync(s)||t.default.mkdirSync(s,{recursive:!0}),r=s,s}catch(t){return console.error("[Config] Fallback config dir is also not writable!",t),r=e,e}}},"getDefaultWorkspaceRoot",0,function(){let e,r=process.env.ORIGINAL_CWD||process.cwd();if(s(r)&&!((e=r.toLowerCase().replace(/\\/g,"/")).includes("/program files")||e.includes("/windows/system32")||e.includes("/winnt")||e.startsWith("/usr/")||e.startsWith("/bin/")||e.startsWith("/sbin/")||e.startsWith("/etc/")||e.startsWith("/var/")))return r.replace(/\\/g,"/");let o=n.default.homedir();for(let e of[a.default.join(o,"OneDrive","Projects"),a.default.join(o,"Projects"),a.default.join(o,"source","repos"),a.default.join(o,"Documents"),o])try{if(t.default.existsSync(e)&&s(e))return e.replace(/\\/g,"/")}catch{}return o.replace(/\\/g,"/")},"isDirWritable",0,s])},41230,e=>{"use strict";var t=e.i(22734),a=e.i(14747),n=e.i(98003);class r{config;constructor(e){this.config=e}async getSchemaSummary(){try{let e=await this.listTables(),t=`### Database Schema Summary
|
|
2
2
|
|
|
3
3
|
`;if(0===e.length)return t+"*No tables found in this database.*";for(let a of e){t+=`#### Table: \`${a.name}\` (${a.type})
|
|
4
4
|
`;let e=await this.describeTable(a.name);for(let a of(t+=`| Column | Type | Nullable | Key | References |
|
|
5
5
|
|---|---|---|---|---|
|
|
6
6
|
`,e)){let e=a.isPrimaryKey?"PK":a.isForeignKey?"FK":"",n=a.isForeignKey?`\`${a.referencedTable}.${a.referencedColumn}\``:"";t+=`| \`${a.name}\` | \`${a.type}\` | ${a.nullable?"Yes":"No"} | ${e} | ${n} |
|
|
7
7
|
`}t+=`
|
|
8
|
-
`}return t}catch(e){return`Failed to reflect schema summary: ${e instanceof Error?e.message:String(e)}`}}}class s extends r{db=null;resolvedPath="";constructor(e,t){super(e);const n=e.filepath||"dev.db";if(a.default.isAbsolute(n))this.resolvedPath=n.replace(/\\/g,"/");else{const e=t||process.cwd();this.resolvedPath=a.default.resolve(e,n).replace(/\\/g,"/")}}async connect(){if(this.db)return;let e=a.default.dirname(this.resolvedPath);t.default.existsSync(e)||t.default.mkdirSync(e,{recursive:!0});try{let e;try{e=(()=>{let e=Error("Cannot find module 'better-sqlite3'");throw e.code="MODULE_NOT_FOUND",e})()}catch(e){throw Error("SQLite driver 'better-sqlite3' is not installed. Please run `npm install better-sqlite3` in the neural-loom environment.")}this.db=new e(this.resolvedPath)}catch(e){throw console.error("[SqliteAdapter] Connect failed:",e),e}}async query(e,t=[]){await this.connect();try{if(e.trim().toLowerCase().startsWith("select")||e.trim().toLowerCase().startsWith("pragma")||e.trim().toLowerCase().startsWith("explain")){let a=this.db.prepare(e).all(t),n=a.length>0?Object.keys(a[0]):[];return{rows:a,fields:n}}{let a=this.db.prepare(e).run(t);return{rows:[],affectedRows:a.changes}}}catch(e){throw console.error("[SqliteAdapter] Query execution failed:",e),e}}async listTables(){return(await this.query("SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%'")).rows.map(e=>({name:e.name,type:"table"===e.type?"table":"view"}))}async describeTable(e){await this.connect();let t=this.db.prepare(`PRAGMA table_info(\`${e}\`)`).all(),a=this.db.prepare(`PRAGMA foreign_key_list(\`${e}\`)`).all();return t.map(e=>{let t=a.find(t=>t.from===e.name);return{name:e.name,type:e.type||"TEXT",nullable:0===e.notnull,defaultValue:e.dflt_value,isPrimaryKey:e.pk>0,isForeignKey:!!t,referencedTable:t?t.table:null,referencedColumn:t?t.to:null}})}async disconnect(){this.db&&(this.db.close(),this.db=null)}}class
|
|
8
|
+
`}return t}catch(e){return`Failed to reflect schema summary: ${e instanceof Error?e.message:String(e)}`}}}class s extends r{db=null;resolvedPath="";constructor(e,t){super(e);const n=e.filepath||"dev.db";if(a.default.isAbsolute(n))this.resolvedPath=n.replace(/\\/g,"/");else{const e=t||process.cwd();this.resolvedPath=a.default.resolve(e,n).replace(/\\/g,"/")}}async connect(){if(this.db)return;let e=a.default.dirname(this.resolvedPath);t.default.existsSync(e)||t.default.mkdirSync(e,{recursive:!0});try{let e;try{e=(()=>{let e=Error("Cannot find module 'better-sqlite3'");throw e.code="MODULE_NOT_FOUND",e})()}catch(e){throw Error("SQLite driver 'better-sqlite3' is not installed. Please run `npm install better-sqlite3` in the neural-loom environment.")}this.db=new e(this.resolvedPath)}catch(e){throw console.error("[SqliteAdapter] Connect failed:",e),e}}async query(e,t=[]){await this.connect();try{if(e.trim().toLowerCase().startsWith("select")||e.trim().toLowerCase().startsWith("pragma")||e.trim().toLowerCase().startsWith("explain")){let a=this.db.prepare(e).all(t),n=a.length>0?Object.keys(a[0]):[];return{rows:a,fields:n}}{let a=this.db.prepare(e).run(t);return{rows:[],affectedRows:a.changes}}}catch(e){throw console.error("[SqliteAdapter] Query execution failed:",e),e}}async listTables(){return(await this.query("SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%'")).rows.map(e=>({name:e.name,type:"table"===e.type?"table":"view"}))}async describeTable(e){await this.connect();let t=this.db.prepare(`PRAGMA table_info(\`${e}\`)`).all(),a=this.db.prepare(`PRAGMA foreign_key_list(\`${e}\`)`).all();return t.map(e=>{let t=a.find(t=>t.from===e.name);return{name:e.name,type:e.type||"TEXT",nullable:0===e.notnull,defaultValue:e.dflt_value,isPrimaryKey:e.pk>0,isForeignKey:!!t,referencedTable:t?t.table:null,referencedColumn:t?t.to:null}})}async disconnect(){this.db&&(this.db.close(),this.db=null)}}class o extends r{client=null;schema="public";constructor(e){super(e),this.schema=e.schema||"public"}async connect(){if(!this.client)try{let e;try{e=(()=>{let e=Error("Cannot find module 'pg'");throw e.code="MODULE_NOT_FOUND",e})().Client}catch(e){throw Error("PostgreSQL driver 'pg' is not installed. Please run `npm install pg` in the neural-loom environment.")}this.client=new e({host:this.config.host||"localhost",port:this.config.port||5432,database:this.config.database||"postgres",user:this.config.username||"postgres",password:this.config.password||"",ssl:this.config.ssl?this.config.ssl:void 0}),await this.client.connect()}catch(e){throw console.error("[PostgresAdapter] Connect failed:",e),this.client=null,e}}async query(e,t=[]){await this.connect();try{let a=await this.client.query(e,t),n=a.rows||[],r=a.fields?a.fields.map(e=>e.name):[];return{rows:n,fields:r,affectedRows:null!==a.rowCount?a.rowCount:void 0}}catch(e){throw console.error("[PostgresAdapter] Query failed:",e),e}}async listTables(){let e=`
|
|
9
9
|
SELECT table_name as name, table_type as type
|
|
10
10
|
FROM information_schema.tables
|
|
11
11
|
WHERE table_schema = $1 AND table_type IN ('BASE TABLE', 'VIEW')
|
|
@@ -45,7 +45,7 @@ module.exports=[93695,(e,t,a)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-
|
|
|
45
45
|
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
46
46
|
AND tc.table_schema = $1
|
|
47
47
|
AND tc.table_name = $2
|
|
48
|
-
`,n=await this.query(t,[this.schema,e]),r=await this.query(a,[this.schema,e]);return n.rows.map(e=>{let t=r.rows.find(t=>t.local_column===e.name);return{name:e.name,type:e.type,nullable:"YES"===e.nullable,defaultValue:e.default_value,isPrimaryKey:e.is_pk,isForeignKey:!!t,referencedTable:t?t.foreign_table:null,referencedColumn:t?t.foreign_column:null}})}async disconnect(){this.client&&(await this.client.end(),this.client=null)}}class
|
|
48
|
+
`,n=await this.query(t,[this.schema,e]),r=await this.query(a,[this.schema,e]);return n.rows.map(e=>{let t=r.rows.find(t=>t.local_column===e.name);return{name:e.name,type:e.type,nullable:"YES"===e.nullable,defaultValue:e.default_value,isPrimaryKey:e.is_pk,isForeignKey:!!t,referencedTable:t?t.foreign_table:null,referencedColumn:t?t.foreign_column:null}})}async disconnect(){this.client&&(await this.client.end(),this.client=null)}}class i extends r{connection=null;dbName="";constructor(e){super(e),this.dbName=e.database||""}async connect(){if(!this.connection)try{let e;try{e=(()=>{let e=Error("Cannot find module 'mysql2/promise'");throw e.code="MODULE_NOT_FOUND",e})()}catch(e){throw Error("MySQL driver 'mysql2' is not installed. Please run `npm install mysql2` in the neural-loom environment.")}this.connection=await e.createConnection({host:this.config.host||"localhost",port:this.config.port||3306,database:this.dbName,user:this.config.username||"root",password:this.config.password||"",ssl:this.config.ssl?this.config.ssl:void 0})}catch(e){throw console.error("[MysqlAdapter] Connect failed:",e),this.connection=null,e}}async query(e,t=[]){await this.connect();try{let[a,n]=await this.connection.execute(e,t),r=Array.isArray(a);return{rows:r?a:[],fields:n?n.map(e=>e.name):[],affectedRows:r||void 0===a.affectedRows?void 0:a.affectedRows}}catch(e){throw console.error("[MysqlAdapter] Query failed:",e),e}}async listTables(){let e=`
|
|
49
49
|
SELECT table_name as name, table_type as type
|
|
50
50
|
FROM information_schema.tables
|
|
51
51
|
WHERE table_schema = ? AND table_type IN ('BASE TABLE', 'VIEW')
|
|
@@ -69,18 +69,58 @@ module.exports=[93695,(e,t,a)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-
|
|
|
69
69
|
WHERE table_schema = ?
|
|
70
70
|
AND table_name = ?
|
|
71
71
|
AND referenced_table_name IS NOT NULL
|
|
72
|
-
`,n=await this.query(t,[this.dbName,e]),r=await this.query(a,[this.dbName,e]);return n.rows.map(e=>{let t=r.rows.find(t=>t.local_column===e.name);return{name:e.name,type:e.type||"VARCHAR",nullable:"YES"===e.nullable,defaultValue:e.default_value,isPrimaryKey:"PRI"===e.col_key,isForeignKey:!!t,referencedTable:t?t.foreign_table:null,referencedColumn:t?t.foreign_column:null}})}async disconnect(){this.connection&&(await this.connection.end(),this.connection=null)}}class l
|
|
72
|
+
`,n=await this.query(t,[this.dbName,e]),r=await this.query(a,[this.dbName,e]);return n.rows.map(e=>{let t=r.rows.find(t=>t.local_column===e.name);return{name:e.name,type:e.type||"VARCHAR",nullable:"YES"===e.nullable,defaultValue:e.default_value,isPrimaryKey:"PRI"===e.col_key,isForeignKey:!!t,referencedTable:t?t.foreign_table:null,referencedColumn:t?t.foreign_column:null}})}async disconnect(){this.connection&&(await this.connection.end(),this.connection=null)}}class l extends r{pool=null;schema="dbo";constructor(e){super(e),this.schema=e.schema||"dbo"}async connect(){if(!this.pool)try{let e;try{e=(()=>{let e=Error("Cannot find module 'mssql'");throw e.code="MODULE_NOT_FOUND",e})()}catch(e){throw Error("Microsoft SQL Server driver 'mssql' is not installed. Please run `npm install mssql` in the neural-loom environment.")}this.pool=await e.connect({server:this.config.host||"localhost",port:this.config.port||1433,database:this.config.database,user:this.config.username,password:this.config.password,options:{encrypt:this.config.ssl||!1,trustServerCertificate:!0}})}catch(e){throw console.error("[MssqlAdapter] Connect failed:",e),this.pool=null,e}}async query(e,t=[]){await this.connect();try{let a=this.pool.request();t.length>0&&(a.input("schema",t[0]),t.length>1&&a.input("table",t[1]));let n=await a.query(e),r=n.recordset||[],s=n.recordset&&n.recordset.columns?Object.keys(n.recordset.columns):r.length>0?Object.keys(r[0]):[];return{rows:r,fields:s,affectedRows:n.rowsAffected?n.rowsAffected[0]:void 0}}catch(e){throw console.error("[MssqlAdapter] Query failed:",e),e}}async listTables(){let e=`
|
|
73
|
+
SELECT table_name as name, table_type as type
|
|
74
|
+
FROM information_schema.tables
|
|
75
|
+
WHERE table_schema = @schema AND table_type IN ('BASE TABLE', 'VIEW')
|
|
76
|
+
ORDER BY table_name
|
|
77
|
+
`;return(await this.query(e,[this.schema])).rows.map(e=>({name:e.name,type:"BASE TABLE"===e.type?"table":"view"}))}async describeTable(e){let t=`
|
|
78
|
+
SELECT
|
|
79
|
+
c.column_name as name,
|
|
80
|
+
c.data_type as type,
|
|
81
|
+
c.is_nullable as nullable,
|
|
82
|
+
c.column_default as default_value,
|
|
83
|
+
(
|
|
84
|
+
SELECT COUNT(*)
|
|
85
|
+
FROM information_schema.table_constraints tc
|
|
86
|
+
JOIN information_schema.key_column_usage kcu
|
|
87
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
88
|
+
AND tc.table_schema = kcu.table_schema
|
|
89
|
+
WHERE tc.constraint_type = 'PRIMARY KEY'
|
|
90
|
+
AND tc.table_name = c.table_name
|
|
91
|
+
AND kcu.column_name = c.column_name
|
|
92
|
+
AND tc.table_schema = c.table_schema
|
|
93
|
+
) > 0 as is_pk
|
|
94
|
+
FROM information_schema.columns c
|
|
95
|
+
WHERE c.table_schema = @schema AND c.table_name = @table
|
|
96
|
+
ORDER BY c.ordinal_position
|
|
97
|
+
`,a=`
|
|
98
|
+
SELECT
|
|
99
|
+
kcu.column_name AS local_column,
|
|
100
|
+
ccu.table_name AS foreign_table,
|
|
101
|
+
ccu.column_name AS foreign_column
|
|
102
|
+
FROM information_schema.table_constraints AS tc
|
|
103
|
+
JOIN information_schema.key_column_usage AS kcu
|
|
104
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
105
|
+
AND tc.table_schema = kcu.table_schema
|
|
106
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
|
107
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
108
|
+
AND ccu.table_schema = tc.table_schema
|
|
109
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
110
|
+
AND tc.table_schema = @schema
|
|
111
|
+
AND tc.table_name = @table
|
|
112
|
+
`,n=await this.query(t,[this.schema,e]),r=await this.query(a,[this.schema,e]);return n.rows.map(e=>{let t=r.rows.find(t=>t.local_column===e.name);return{name:e.name,type:e.type,nullable:"YES"===e.nullable,defaultValue:e.default_value,isPrimaryKey:e.is_pk,isForeignKey:!!t,referencedTable:t?t.foreign_table:null,referencedColumn:t?t.foreign_column:null}})}async disconnect(){this.pool&&(await this.pool.close(),this.pool=null)}}class c{static activeInstances=new Map;static getGlobalConfigPath(){return a.default.join((0,n.getConfigDir)(),"global-sql.json")}static getWorkspaceConfigPath(e){return e?a.default.join(e,".ai","neural-loom","sql-config.json"):null}static loadConfig(e){try{if(t.default.existsSync(e)){let a=t.default.readFileSync(e,"utf8");return JSON.parse(a)}}catch(t){console.error(`[ConnectionManager] Failed to load config from ${e}:`,t)}return{connections:{},activeConnection:null}}static saveConfig(e,n){try{let r=a.default.dirname(e);t.default.existsSync(r)||t.default.mkdirSync(r,{recursive:!0}),t.default.writeFileSync(e,JSON.stringify(n,null,2),"utf8")}catch(t){console.error(`[ConnectionManager] Failed to save config to ${e}:`,t)}}static async getProfiles(e){let t=this.loadConfig(this.getGlobalConfigPath()),a=Object.values(t.connections),n=[],r=t.activeConnection,s=!0;if(e){let t=this.getWorkspaceConfigPath(e);if(t){let e=this.loadConfig(t);n=Object.values(e.connections),e.activeConnection&&(r=e.activeConnection,s=!1)}}return{global:a,workspace:n,activeId:r,isActiveGlobal:s}}static async saveProfile(e,t,a){let n=t?this.getGlobalConfigPath():this.getWorkspaceConfigPath(a);if(!n)throw Error("Invalid workspace root path for saving connection profile.");let r=this.loadConfig(n);r.connections[e.id]=e,this.saveConfig(n,r)}static async deleteProfile(e,t,a){let n=t?this.getGlobalConfigPath():this.getWorkspaceConfigPath(a);if(!n)throw Error("Invalid workspace root path for deleting connection profile.");let r=this.loadConfig(n);r.connections[e]&&(delete r.connections[e],r.activeConnection===e&&(r.activeConnection=null),this.saveConfig(n,r));let s=`${t?"global":"ws"}:${e}`,o=this.activeInstances.get(s);o&&(await o.disconnect().catch(console.error),this.activeInstances.delete(s))}static async setActiveProfile(e,t,a){let n=t?this.getGlobalConfigPath():this.getWorkspaceConfigPath(a);if(!n)throw Error("Invalid workspace root path for setting active profile.");let r=this.loadConfig(n);r.activeConnection=e,this.saveConfig(n,r)}static createAdapter(e,t){switch(e.type){case"sqlite":return new s(e,t);case"postgres":return new o(e);case"mysql":return new i(e);case"mssql":return new l(e);default:throw Error(`Unsupported database type: ${e.type}`)}}static async getActiveAdapter(e){let{global:t,workspace:a,activeId:n,isActiveGlobal:r}=await this.getProfiles(e);if(!n)return null;let s=`${r?"global":"ws"}:${n}`,o=this.activeInstances.get(s);if(o){let e=(r?t:a).find(e=>e.id===n);if(e)return{adapter:o,profile:e}}let i=(r?t:a).find(e=>e.id===n);if(!i)return null;let l=this.createAdapter(i,e);return this.activeInstances.set(s,l),{adapter:l,profile:i}}static async closeAll(){for(let[,e]of this.activeInstances.entries())await e.disconnect().catch(console.error);this.activeInstances.clear()}}e.s(["ConnectionManager",0,c],41230)},19668,(e,t,a)=>{t.exports=e.x("readline",()=>require("readline"))},53869,e=>{"use strict";var t=e.i(47909),a=e.i(74017),n=e.i(96250),r=e.i(59756),s=e.i(61916),o=e.i(74677),i=e.i(69741),l=e.i(16795),c=e.i(87718),u=e.i(95169),d=e.i(47587),h=e.i(66012),p=e.i(70101),m=e.i(26937),f=e.i(10372),y=e.i(93695);e.i(52474);var b=e.i(220),g=e.i(89171),_=e.i(19668),w=e.i(41230);class v{workspaceRoot;constructor(e){this.workspaceRoot=e,console.log=(...e)=>{console.error("[LOG]",...e)}}start(){_.default.createInterface({input:process.stdin,output:process.stdout,terminal:!1}).on("line",async e=>{if(e.trim())try{let t=JSON.parse(e);if(t.method){let e=await this.handleMessage(t);e&&process.stdout.write(JSON.stringify(e)+"\n")}}catch(e){this.sendError(null,-32700,"Parse error: "+(e instanceof Error?e.message:String(e)))}}),console.error("[McpServer] SQL Model Context Protocol Server listening on stdio..."),this.workspaceRoot&&console.error(`[McpServer] Workspace Root Context resolved to: ${this.workspaceRoot}`)}async handleMessage(e){let{id:t,method:a,params:n}=e;switch(a){case"initialize":return{jsonrpc:"2.0",id:t,result:{protocolVersion:"2024-11-05",capabilities:{tools:{}},serverInfo:{name:"neural-loom-sql-mcp",version:"1.0.0"}}};case"notifications/initialized":return null;case"tools/list":return{jsonrpc:"2.0",id:t,result:{tools:[{name:"sql_list_connections",description:"Lists all configured global and workspace database connection profiles, and identifies which one is active.",inputSchema:{type:"object",properties:{}}},{name:"sql_list_tables",description:"Lists all tables and views in the currently active database.",inputSchema:{type:"object",properties:{}}},{name:"sql_describe_table",description:"Provides column names, types, primary keys, foreign keys, and nullability information for a specific table.",inputSchema:{type:"object",properties:{table:{type:"string",description:"The name of the table to describe."}},required:["table"]}},{name:"sql_get_schema_summary",description:"Returns a complete Markdown representation of the database schema, detailing all tables, columns, constraints, and relationships.",inputSchema:{type:"object",properties:{}}},{name:"sql_query",description:"Executes a SQL query on the active database connection. Select queries return matching rows; modifying queries return affected row count. If readOnly is set on the connection, modifying statements will fail.",inputSchema:{type:"object",properties:{sql:{type:"string",description:"The SQL statement to execute."}},required:["sql"]}}]}};case"tools/call":return await this.handleToolCall(t,n);default:return{jsonrpc:"2.0",id:t,error:{code:-32601,message:`Method not found: ${a}`}}}}async handleRequest(e){let t=await this.handleMessage(e);t&&process.stdout.write(JSON.stringify(t)+"\n")}async handleToolCall(e,t){let a=t.name,n=t.arguments||{};try{if("sql_list_connections"===a){let t=await w.ConnectionManager.getProfiles(this.workspaceRoot),a=t.isActiveGlobal?t.global.find(e=>e.id===t.activeId):t.workspace.find(e=>e.id===t.activeId),n=`Active Connection Profile: ${a?`${a.name} (${a.type})`:"None"}
|
|
73
113
|
|
|
74
114
|
Global Profiles:
|
|
75
115
|
`+(t.global.length>0?t.global.map(e=>`- [${e.id}] ${e.name} (${e.type}) ${t.activeId===e.id&&t.isActiveGlobal?"(Active)":""}`).join("\n"):"None")+"\n\n"+`Workspace Profiles:
|
|
76
|
-
`+(t.workspace.length>0?t.workspace.map(e=>`- [${e.id}] ${e.name} (${e.type}) ${t.activeId===e.id&&!t.isActiveGlobal?"(Active)":""}`).join("\n"):"None");this.sendToolResult(e,n);return}let t=await
|
|
116
|
+
`+(t.workspace.length>0?t.workspace.map(e=>`- [${e.id}] ${e.name} (${e.type}) ${t.activeId===e.id&&!t.isActiveGlobal?"(Active)":""}`).join("\n"):"None");this.sendToolResult(e,n);return}let t=await w.ConnectionManager.getActiveAdapter(this.workspaceRoot);if(!t)return void this.sendToolResult(e,"Error: No active database connection is selected. Please configure and activate a database connection in the NeuralLoom workspace dashboard UI.",!0);let{adapter:r,profile:s}=t;switch(a){case"sql_list_tables":{let t=await r.listTables(),a=t.length>0?t.map(e=>`- \`${e.name}\` (${e.type})`).join("\n"):"*No tables found in the active database.*";this.sendToolResult(e,`Active Database: ${s.name} (${s.type})
|
|
77
117
|
|
|
78
118
|
### Tables:
|
|
79
|
-
${a}`);break}case"sql_describe_table":{let t=n.table;if(!t)return void this.sendToolResult(e,"Error: Missing required argument 'table'.",!0);let a=await r.describeTable(t),
|
|
119
|
+
${a}`);break}case"sql_describe_table":{let t=n.table;if(!t)return void this.sendToolResult(e,"Error: Missing required argument 'table'.",!0);let a=await r.describeTable(t),o=`### Table Structure: \`${t}\` (Active Connection: ${s.name})
|
|
80
120
|
|
|
81
|
-
`;for(let e of(
|
|
121
|
+
`;for(let e of(o+=`| Column | Type | Nullable | Key | References |
|
|
82
122
|
|---|---|---|---|---|
|
|
83
|
-
`,a)){let t=e.isPrimaryKey?"PK":e.isForeignKey?"FK":"",a=e.isForeignKey?`\`${e.referencedTable}.${e.referencedColumn}\``:"";
|
|
84
|
-
`}this.sendToolResult(e,
|
|
123
|
+
`,a)){let t=e.isPrimaryKey?"PK":e.isForeignKey?"FK":"",a=e.isForeignKey?`\`${e.referencedTable}.${e.referencedColumn}\``:"";o+=`| \`${e.name}\` | \`${e.type}\` | ${e.nullable?"Yes":"No"} | ${t} | ${a} |
|
|
124
|
+
`}this.sendToolResult(e,o);break}case"sql_get_schema_summary":{let t=await r.getSchemaSummary();this.sendToolResult(e,t);break}case"sql_query":{let t=n.sql;if(!t||!t.trim())return void this.sendToolResult(e,"Error: Missing required argument 'sql'.",!0);let a=t.trim().toLowerCase(),o=a.startsWith("insert")||a.startsWith("update")||a.startsWith("delete")||a.startsWith("drop")||a.startsWith("alter")||a.startsWith("create")||a.startsWith("truncate")||a.startsWith("replace");if(s.readOnly&&o)return void this.sendToolResult(e,"Error: Access Denied. This database connection is configured as Read-Only.",!0);let i=await r.query(t);void 0!==i.affectedRows?this.sendToolResult(e,`Query completed successfully. Affected rows: ${i.affectedRows}`):this.sendToolResult(e,JSON.stringify(i.rows,null,2));break}default:this.sendError(e,-32601,`Tool not implemented: ${a}`)}}catch(t){this.sendToolResult(e,`Exception executing tool: ${t.message||String(t)}`,!0)}}sendResponse(e,t){process.stdout.write(JSON.stringify({jsonrpc:"2.0",id:e,result:t})+"\n")}sendToolResult(e,t,a=!1){process.stdout.write(JSON.stringify({jsonrpc:"2.0",id:e,result:{content:[{type:"text",text:t}],isError:a}})+"\n")}sendError(e,t,a){process.stdout.write(JSON.stringify({jsonrpc:"2.0",id:e,error:{code:t,message:a}})+"\n")}}async function E(e){try{let t=e.headers.get("x-workspace-root")||void 0,a=await e.json(),n=new v(t),r=await n.handleMessage(a);if(null===r)return new Response("",{status:204});return g.NextResponse.json(r)}catch(e){return g.NextResponse.json({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error: "+(e.message||String(e))}},{status:500})}}e.s(["POST",0,E],37730);var R=e.i(37730);let A=new t.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/sql/mcp/route",pathname:"/api/sql/mcp",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/sql/mcp/route.ts",nextConfigOutput:"",userland:R,...{}}),{workAsyncStorage:C,workUnitAsyncStorage:S,serverHooks:N}=A;async function q(e,t,n){n.requestMeta&&(0,r.setRequestMeta)(e,n.requestMeta),A.isDev&&(0,r.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let g="/api/sql/mcp/route";g=g.replace(/\/index$/,"")||"/";let _=await A.prepare(e,t,{srcPage:g,multiZoneDraftMode:!1});if(!_)return t.statusCode=400,t.end("Bad Request"),null==n.waitUntil||n.waitUntil.call(n,Promise.resolve()),null;let{buildId:w,deploymentId:v,params:E,nextConfig:R,parsedUrl:C,isDraftMode:S,prerenderManifest:N,routerServerContext:q,isOnDemandRevalidate:k,revalidateOnlyGenerated:x,resolvedPathname:T,clientReferenceManifest:O,serverActionsManifest:P}=_,$=(0,i.normalizeAppPath)(g),D=!!(N.dynamicRoutes[$]||N.routes[T]),M=async()=>((null==q?void 0:q.render404)?await q.render404(e,t,C,!1):t.end("This page could not be found"),null);if(D&&!S){let e=!!N.routes[T],t=N.dynamicRoutes[$];if(t&&!1===t.fallback&&!e){if(R.adapterPath)return await M();throw new y.NoFallbackError}}let I=null;!D||A.isDev||S||(I="/index"===(I=T)?"/":I);let j=!0===A.isDev||!D,L=D&&!j;P&&O&&(0,o.setManifestsSingleton)({page:g,clientReferenceManifest:O,serverActionsManifest:P});let F=e.method||"GET",W=(0,s.getTracer)(),K=W.getActiveScopeSpan(),H=!!(null==q?void 0:q.isWrappedByNextServer),U=!!(0,r.getRequestMeta)(e,"minimalMode"),B=(0,r.getRequestMeta)(e,"incrementalCache")||await A.getIncrementalCache(e,R,N,U);null==B||B.resetRequestCache(),globalThis.__incrementalCache=B;let G={params:E,previewProps:N.preview,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:j,incrementalCache:B,cacheLifeProfiles:R.cacheLife,waitUntil:n.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,a,n,r)=>A.onRequestError(e,t,n,r,q)},sharedContext:{buildId:w,deploymentId:v}},Y=new l.NodeNextRequest(e),J=new l.NodeNextResponse(t),Q=c.NextRequestAdapter.fromNodeNextRequest(Y,(0,c.signalFromNodeResponse)(t));try{let r,o=async e=>A.handle(Q,G).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let a=W.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let n=a.get("next.route");if(n){let t=`${F} ${n}`;e.setAttributes({"next.route":n,"http.route":n,"next.span_name":t}),e.updateName(t),r&&r!==e&&(r.setAttribute("http.route",n),r.updateName(t))}else e.updateName(`${F} ${g}`)}),i=async r=>{var s,i;let l=async({previousCacheEntry:a})=>{try{if(!U&&k&&x&&!a)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let s=await o(r);e.fetchMetrics=G.renderOpts.fetchMetrics;let i=G.renderOpts.pendingWaitUntil;i&&n.waitUntil&&(n.waitUntil(i),i=void 0);let l=G.renderOpts.collectedTags;if(!D)return await (0,h.sendResponse)(Y,J,s,G.renderOpts.pendingWaitUntil),null;{let e=await s.blob(),t=(0,p.toNodeOutgoingHttpHeaders)(s.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let a=void 0!==G.renderOpts.collectedRevalidate&&!(G.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&G.renderOpts.collectedRevalidate,n=void 0===G.renderOpts.collectedExpire||G.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:G.renderOpts.collectedExpire;return{value:{kind:b.CachedRouteKind.APP_ROUTE,status:s.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:a,expire:n}}}}catch(t){throw(null==a?void 0:a.isStale)&&await A.onRequestError(e,t,{routerKind:"App Router",routePath:g,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:L,isOnDemandRevalidate:k})},!1,q),t}},c=await A.handleResponse({req:e,nextConfig:R,cacheKey:I,routeKind:a.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:N,isRoutePPREnabled:!1,isOnDemandRevalidate:k,revalidateOnlyGenerated:x,responseGenerator:l,waitUntil:n.waitUntil,isMinimalMode:U});if(!D)return null;if((null==c||null==(s=c.value)?void 0:s.kind)!==b.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==c||null==(i=c.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});U||t.setHeader("x-nextjs-cache",k?"REVALIDATED":c.isMiss?"MISS":c.isStale?"STALE":"HIT"),S&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let u=(0,p.fromNodeOutgoingHttpHeaders)(c.value.headers);return U&&D||u.delete(f.NEXT_CACHE_TAGS_HEADER),!c.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,m.getCacheControlHeader)(c.cacheControl)),await (0,h.sendResponse)(Y,J,new Response(c.value.body,{headers:u,status:c.value.status||200})),null};H&&K?await i(K):(r=W.getActiveScopeSpan(),await W.withPropagatedContext(e.headers,()=>W.trace(u.BaseServerSpan.handleRequest,{spanName:`${F} ${g}`,kind:s.SpanKind.SERVER,attributes:{"http.method":F,"http.target":e.url}},i),void 0,!H))}catch(t){if(t instanceof y.NoFallbackError||await A.onRequestError(e,t,{routerKind:"App Router",routePath:$,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:L,isOnDemandRevalidate:k})},!1,q),D)throw t;return await (0,h.sendResponse)(Y,J,new Response(null,{status:500})),null}}e.s(["handler",0,q,"patchFetch",0,function(){return(0,n.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:S})},"routeModule",0,A,"serverHooks",0,N,"workAsyncStorage",0,C,"workUnitAsyncStorage",0,S],53869)}];
|
|
85
125
|
|
|
86
126
|
//# sourceMappingURL=%5Broot-of-the-server%5D__0.ptwor._.js.map
|