drizzle-cube 0.4.13 → 0.4.15

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.
Files changed (116) hide show
  1. package/README.md +1 -0
  2. package/dist/adapters/express/index.cjs +6 -6
  3. package/dist/adapters/express/index.js +73 -72
  4. package/dist/adapters/fastify/index.cjs +5 -5
  5. package/dist/adapters/fastify/index.js +110 -109
  6. package/dist/adapters/{handler-CQkIwtxp.js → handler-DZnCbydH.js} +719 -272
  7. package/dist/adapters/handler-ZDYlokiM.cjs +25 -0
  8. package/dist/adapters/hono/index.cjs +6 -6
  9. package/dist/adapters/hono/index.js +121 -120
  10. package/dist/adapters/nextjs/index.cjs +5 -5
  11. package/dist/adapters/nextjs/index.js +92 -91
  12. package/dist/client/charts.js +67 -59
  13. package/dist/client/charts.js.map +1 -1
  14. package/dist/client/chunks/{RetentionCombinedChart-CEI8KQ3t.js → RetentionCombinedChart-CLq89aOJ.js} +2 -2
  15. package/dist/client/chunks/{RetentionCombinedChart-CEI8KQ3t.js.map → RetentionCombinedChart-CLq89aOJ.js.map} +1 -1
  16. package/dist/client/chunks/{analysis-builder-BMmWeFPr.js → analysis-builder-C5e52Z3p.js} +419 -411
  17. package/dist/client/chunks/analysis-builder-C5e52Z3p.js.map +1 -0
  18. package/dist/client/chunks/{analysis-builder-shared-D56zYeV0.js → analysis-builder-shared-EnM-8plh.js} +2 -2
  19. package/dist/client/chunks/{analysis-builder-shared-D56zYeV0.js.map → analysis-builder-shared-EnM-8plh.js.map} +1 -1
  20. package/dist/client/chunks/{chart-activity-grid-CE7xGFQo.js → chart-activity-grid-CPGcTSuh.js} +2 -2
  21. package/dist/client/chunks/{chart-activity-grid-CE7xGFQo.js.map → chart-activity-grid-CPGcTSuh.js.map} +1 -1
  22. package/dist/client/chunks/{chart-area-BJAgusst.js → chart-area-ByJQ7NZd.js} +3 -3
  23. package/dist/client/chunks/{chart-area-BJAgusst.js.map → chart-area-ByJQ7NZd.js.map} +1 -1
  24. package/dist/client/chunks/{chart-bar-Blypx8O4.js → chart-bar-dj14frMt.js} +2 -2
  25. package/dist/client/chunks/{chart-bar-Blypx8O4.js.map → chart-bar-dj14frMt.js.map} +1 -1
  26. package/dist/client/chunks/chart-box-plot-ZatBpatq.js +322 -0
  27. package/dist/client/chunks/chart-box-plot-ZatBpatq.js.map +1 -0
  28. package/dist/client/chunks/{chart-bubble-Bf42A1-B.js → chart-bubble-CemotLx-.js} +2 -2
  29. package/dist/client/chunks/{chart-bubble-Bf42A1-B.js.map → chart-bubble-CemotLx-.js.map} +1 -1
  30. package/dist/client/chunks/chart-candlestick-BIR4uGGt.js +269 -0
  31. package/dist/client/chunks/chart-candlestick-BIR4uGGt.js.map +1 -0
  32. package/dist/client/chunks/chart-config-box-plot-D_E_SSc2.js +38 -0
  33. package/dist/client/chunks/chart-config-box-plot-D_E_SSc2.js.map +1 -0
  34. package/dist/client/chunks/chart-config-candlestick-CRCpD43-.js +70 -0
  35. package/dist/client/chunks/chart-config-candlestick-CRCpD43-.js.map +1 -0
  36. package/dist/client/chunks/chart-config-gauge-CQx9w3d4.js +64 -0
  37. package/dist/client/chunks/chart-config-gauge-CQx9w3d4.js.map +1 -0
  38. package/dist/client/chunks/chart-config-measure-profile-ZYaMrtws.js +70 -0
  39. package/dist/client/chunks/chart-config-measure-profile-ZYaMrtws.js.map +1 -0
  40. package/dist/client/chunks/chart-config-waterfall-DTyXV_fo.js +60 -0
  41. package/dist/client/chunks/chart-config-waterfall-DTyXV_fo.js.map +1 -0
  42. package/dist/client/chunks/{chart-data-table-Ba_6tuJw.js → chart-data-table-D5G8nMnb.js} +2 -2
  43. package/dist/client/chunks/{chart-data-table-Ba_6tuJw.js.map → chart-data-table-D5G8nMnb.js.map} +1 -1
  44. package/dist/client/chunks/{chart-funnel-C9kenCpp.js → chart-funnel-dofnhD24.js} +2 -2
  45. package/dist/client/chunks/{chart-funnel-C9kenCpp.js.map → chart-funnel-dofnhD24.js.map} +1 -1
  46. package/dist/client/chunks/chart-gauge-CKJJ8m3b.js +374 -0
  47. package/dist/client/chunks/chart-gauge-CKJJ8m3b.js.map +1 -0
  48. package/dist/client/chunks/{chart-heat-map-CYGemyPB.js → chart-heat-map-BVuPUKHT.js} +2 -2
  49. package/dist/client/chunks/{chart-heat-map-CYGemyPB.js.map → chart-heat-map-BVuPUKHT.js.map} +1 -1
  50. package/dist/client/chunks/{chart-kpi-delta-D9XJoKuA.js → chart-kpi-delta-Dgg2eYRl.js} +3 -3
  51. package/dist/client/chunks/{chart-kpi-delta-D9XJoKuA.js.map → chart-kpi-delta-Dgg2eYRl.js.map} +1 -1
  52. package/dist/client/chunks/{chart-kpi-number-C29Vj2g8.js → chart-kpi-number-DkoO99c1.js} +2 -2
  53. package/dist/client/chunks/{chart-kpi-number-C29Vj2g8.js.map → chart-kpi-number-DkoO99c1.js.map} +1 -1
  54. package/dist/client/chunks/{chart-kpi-text-CgjjrurK.js → chart-kpi-text-1O6_lmz7.js} +3 -3
  55. package/dist/client/chunks/{chart-kpi-text-CgjjrurK.js.map → chart-kpi-text-1O6_lmz7.js.map} +1 -1
  56. package/dist/client/chunks/{chart-line-zi6olZet.js → chart-line-DzyZkugh.js} +3 -3
  57. package/dist/client/chunks/{chart-line-zi6olZet.js.map → chart-line-DzyZkugh.js.map} +1 -1
  58. package/dist/client/chunks/chart-measure-profile-C2IkBG3V.js +114 -0
  59. package/dist/client/chunks/chart-measure-profile-C2IkBG3V.js.map +1 -0
  60. package/dist/client/chunks/{chart-pie-C4SuxKSN.js → chart-pie-akbfRfb9.js} +2 -2
  61. package/dist/client/chunks/{chart-pie-C4SuxKSN.js.map → chart-pie-akbfRfb9.js.map} +1 -1
  62. package/dist/client/chunks/{chart-radar-BW3Z_-Ly.js → chart-radar-BaN-Kjww.js} +2 -2
  63. package/dist/client/chunks/{chart-radar-BW3Z_-Ly.js.map → chart-radar-BaN-Kjww.js.map} +1 -1
  64. package/dist/client/chunks/{chart-radial-bar-0Fa3aeP5.js → chart-radial-bar-DpptEL3s.js} +2 -2
  65. package/dist/client/chunks/{chart-radial-bar-0Fa3aeP5.js.map → chart-radial-bar-DpptEL3s.js.map} +1 -1
  66. package/dist/client/chunks/{chart-sankey-DBghfbg1.js → chart-sankey-CG-3hHmX.js} +2 -2
  67. package/dist/client/chunks/{chart-sankey-DBghfbg1.js.map → chart-sankey-CG-3hHmX.js.map} +1 -1
  68. package/dist/client/chunks/{chart-scatter-DOVu1TNq.js → chart-scatter-l_yTVxF3.js} +2 -2
  69. package/dist/client/chunks/{chart-scatter-DOVu1TNq.js.map → chart-scatter-l_yTVxF3.js.map} +1 -1
  70. package/dist/client/chunks/{chart-sunburst-LfNthFlZ.js → chart-sunburst-KhDcKhmZ.js} +2 -2
  71. package/dist/client/chunks/{chart-sunburst-LfNthFlZ.js.map → chart-sunburst-KhDcKhmZ.js.map} +1 -1
  72. package/dist/client/chunks/{chart-tree-map-DZtQPyWX.js → chart-tree-map-CBbiaBXV.js} +2 -2
  73. package/dist/client/chunks/{chart-tree-map-DZtQPyWX.js.map → chart-tree-map-CBbiaBXV.js.map} +1 -1
  74. package/dist/client/chunks/chart-waterfall-CX3vx_lI.js +191 -0
  75. package/dist/client/chunks/chart-waterfall-CX3vx_lI.js.map +1 -0
  76. package/dist/client/chunks/{charts-core-DmGfleFz.js → charts-core-CU9u_HtL.js} +2 -1
  77. package/dist/client/chunks/charts-core-CU9u_HtL.js.map +1 -0
  78. package/dist/client/chunks/{charts-loader-CH0_S06T.js → charts-loader-AW3T1nv5.js} +58 -42
  79. package/dist/client/chunks/charts-loader-AW3T1nv5.js.map +1 -0
  80. package/dist/client/chunks/{components-ClQziOcT.js → components-BkeSy9xv.js} +4 -4
  81. package/dist/client/chunks/components-BkeSy9xv.js.map +1 -0
  82. package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +10 -0
  83. package/dist/client/components/AgenticNotebook/ChatMessage.d.ts +2 -0
  84. package/dist/client/components/AgenticNotebook/index.d.ts +11 -1
  85. package/dist/client/components/LoadingIndicator.d.ts +2 -2
  86. package/dist/client/components/charts/BoxPlotChart.config.d.ts +1 -7
  87. package/dist/client/components/charts/CandlestickChart.config.d.ts +5 -0
  88. package/dist/client/components/charts/CandlestickChart.d.ts +4 -0
  89. package/dist/client/components/charts/GaugeChart.config.d.ts +5 -0
  90. package/dist/client/components/charts/GaugeChart.d.ts +4 -0
  91. package/dist/client/components/charts/MeasureProfileChart.config.d.ts +5 -0
  92. package/dist/client/components/charts/MeasureProfileChart.d.ts +4 -0
  93. package/dist/client/components/charts/WaterfallChart.config.d.ts +5 -0
  94. package/dist/client/components/charts/WaterfallChart.d.ts +4 -0
  95. package/dist/client/components/charts/index.d.ts +4 -0
  96. package/dist/client/components.js +1 -1
  97. package/dist/client/hooks/useAgentChat.d.ts +20 -2
  98. package/dist/client/index.js +585 -522
  99. package/dist/client/index.js.map +1 -1
  100. package/dist/client/styles.css +1 -1
  101. package/dist/client/types.d.ts +19 -1
  102. package/dist/client/utils.js +4 -4
  103. package/dist/client-bundle-stats.html +1 -1
  104. package/dist/server/index.cjs +47 -45
  105. package/dist/server/index.d.ts +37 -0
  106. package/dist/server/index.js +1745 -1298
  107. package/package.json +4 -1
  108. package/dist/adapters/handler-dnkqpznh.cjs +0 -23
  109. package/dist/client/chunks/analysis-builder-BMmWeFPr.js.map +0 -1
  110. package/dist/client/chunks/chart-box-plot-Dja4LS3O.js +0 -313
  111. package/dist/client/chunks/chart-box-plot-Dja4LS3O.js.map +0 -1
  112. package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js +0 -85
  113. package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js.map +0 -1
  114. package/dist/client/chunks/charts-core-DmGfleFz.js.map +0 -1
  115. package/dist/client/chunks/charts-loader-CH0_S06T.js.map +0 -1
  116. package/dist/client/chunks/components-ClQziOcT.js.map +0 -1
package/README.md CHANGED
@@ -8,6 +8,7 @@ Build a semantic layer on top of your Drizzle schema. Define cubes with measures
8
8
 
9
9
  - **[Documentation](https://www.drizzle-cube.dev/)**
10
10
  - **[Try the Sandbox](https://try.drizzle-cube.dev/)**
11
+ - **[Ask for help in Discord](https://discord.gg/kFvT97hZsv)**
11
12
  - **[Contribute to the Roadmap](https://github.com/users/cliftonc/projects/2)**
12
13
 
13
14
  [![NPM Version](https://img.shields.io/npm/v/drizzle-cube)](https://www.npmjs.com/package/drizzle-cube)
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("express"),M=require("cors"),c=require("../mcp-transport-8u9G5oNa.cjs"),n=require("../utils.cjs");function $(g){const{cubes:m,drizzle:w,schema:P,extractSecurityContext:y,engineType:A,cors:x,basePath:f="/cubejs-api/v1",jsonLimit:S="10mb",cache:H,mcp:v={enabled:!0},agent:j}=g;if(!m||m.length===0)throw new Error("At least one cube must be provided in the cubes array");const d=R.Router();x&&d.use(M(x)),d.use(R.json({limit:S})),d.use(R.urlencoded({extended:!0,limit:S}));const u=new c.SemanticLayerCompiler({drizzle:w,schema:P,engineType:A,cache:H});if(m.forEach(r=>{u.registerCube(r)}),d.post(`${f}/load`,async(r,t)=>{try{const e=r.body.query||r.body,o=await y(r,t),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const s=r.headers["x-cache-control"]==="no-cache",i=await u.executeMultiCubeQuery(e,o,{skipCache:s});t.json(n.formatCubeResponse(e,i,u))}catch(e){console.error("Query execution error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),d.get(`${f}/load`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json(n.formatErrorResponse("Query parameter is required",400));let o;try{o=JSON.parse(e)}catch{return t.status(400).json(n.formatErrorResponse("Invalid JSON in query parameter",400))}const a=await y(r,t),s=u.validateQuery(o);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const i=r.headers["x-cache-control"]==="no-cache",l=await u.executeMultiCubeQuery(o,a,{skipCache:i});t.json(n.formatCubeResponse(o,l,u))}catch(e){console.error("Query execution error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),d.post(`${f}/batch`,async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).json(n.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).json(n.formatErrorResponse("Queries array cannot be empty",400));const o=await y(r,t),a=r.headers["x-cache-control"]==="no-cache",s=await n.handleBatchRequest(e,o,u,{skipCache:a});t.json(s)}catch(e){console.error("Batch execution error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),d.get(`${f}/meta`,(r,t)=>{try{const e=u.getMetadata();t.json(n.formatMetaResponse(e))}catch(e){console.error("Metadata error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),d.post(`${f}/sql`,async(r,t)=>{try{const e=r.body,o=await y(r,t),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const s=e.measures?.[0]||e.dimensions?.[0];if(!s)return t.status(400).json(n.formatErrorResponse("No measures or dimensions specified",400));const i=s.split(".")[0],l=await u.generateSQL(i,e,o);t.json(n.formatSqlResponse(e,l))}catch(e){console.error("SQL generation error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),d.get(`${f}/sql`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json(n.formatErrorResponse("Query parameter is required",400));const o=JSON.parse(e),a=await y(r,t),s=u.validateQuery(o);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const i=o.measures?.[0]||o.dimensions?.[0];if(!i)return t.status(400).json(n.formatErrorResponse("No measures or dimensions specified",400));const l=i.split(".")[0],h=await u.generateSQL(l,o,a);t.json(n.formatSqlResponse(o,h))}catch(e){console.error("SQL generation error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),d.post(`${f}/dry-run`,async(r,t)=>{try{const e=r.body.query||r.body,o=await y(r,t),a=await n.handleDryRun(e,o,u);t.json(a)}catch(e){console.error("Dry-run error:",e),t.status(400).json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),d.get(`${f}/dry-run`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json({error:"Query parameter is required",valid:!1});const o=JSON.parse(e),a=await y(r,t),s=await n.handleDryRun(o,a,u);t.json(s)}catch(e){console.error("Dry-run error:",e),t.status(400).json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),d.post(`${f}/explain`,async(r,t)=>{try{const e=r.body.query||r.body,o=r.body.options||{},a=await y(r,t),s=u.validateQuery(e);if(!s.isValid)return t.status(400).json({error:`Query validation failed: ${s.errors.join(", ")}`});const i=await u.explainQuery(e,a,o);t.json(i)}catch(e){console.error("Explain error:",e),t.status(500).json({error:e instanceof Error?e.message:"Explain query failed"})}}),j&&d.post(`${f}/agent/chat`,async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-dnkqpznh.cjs")),{message:o,sessionId:a}=r.body;if(!o||typeof o!="string")return t.status(400).json({error:"message is required and must be a string"});let s=(j.apiKey||"").trim();if(j.allowClientApiKey){const l=r.headers["x-agent-api-key"];l&&(s=l.trim())}if(!s)return t.status(401).json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const i=await y(r,t);t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const l=e({message:o,sessionId:a,semanticLayer:u,securityContext:i,agentConfig:j,apiKey:s});for await(const h of l)t.write(`data: ${JSON.stringify(h)}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("express"),M=require("cors"),c=require("../mcp-transport-8u9G5oNa.cjs"),n=require("../utils.cjs");function $(g){const{cubes:h,drizzle:w,schema:P,extractSecurityContext:y,engineType:A,cors:x,basePath:f="/cubejs-api/v1",jsonLimit:S="10mb",cache:H,mcp:v={enabled:!0},agent:j}=g;if(!h||h.length===0)throw new Error("At least one cube must be provided in the cubes array");const d=R.Router();x&&d.use(M(x)),d.use(R.json({limit:S})),d.use(R.urlencoded({extended:!0,limit:S}));const u=new c.SemanticLayerCompiler({drizzle:w,schema:P,engineType:A,cache:H});if(h.forEach(r=>{u.registerCube(r)}),d.post(`${f}/load`,async(r,t)=>{try{const e=r.body.query||r.body,o=await y(r,t),s=u.validateQuery(e);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",i=await u.executeMultiCubeQuery(e,o,{skipCache:a});t.json(n.formatCubeResponse(e,i,u))}catch(e){console.error("Query execution error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),d.get(`${f}/load`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json(n.formatErrorResponse("Query parameter is required",400));let o;try{o=JSON.parse(e)}catch{return t.status(400).json(n.formatErrorResponse("Invalid JSON in query parameter",400))}const s=await y(r,t),a=u.validateQuery(o);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const i=r.headers["x-cache-control"]==="no-cache",m=await u.executeMultiCubeQuery(o,s,{skipCache:i});t.json(n.formatCubeResponse(o,m,u))}catch(e){console.error("Query execution error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),d.post(`${f}/batch`,async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).json(n.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).json(n.formatErrorResponse("Queries array cannot be empty",400));const o=await y(r,t),s=r.headers["x-cache-control"]==="no-cache",a=await n.handleBatchRequest(e,o,u,{skipCache:s});t.json(a)}catch(e){console.error("Batch execution error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),d.get(`${f}/meta`,(r,t)=>{try{const e=u.getMetadata();t.json(n.formatMetaResponse(e))}catch(e){console.error("Metadata error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),d.post(`${f}/sql`,async(r,t)=>{try{const e=r.body,o=await y(r,t),s=u.validateQuery(e);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const a=e.measures?.[0]||e.dimensions?.[0];if(!a)return t.status(400).json(n.formatErrorResponse("No measures or dimensions specified",400));const i=a.split(".")[0],m=await u.generateSQL(i,e,o);t.json(n.formatSqlResponse(e,m))}catch(e){console.error("SQL generation error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),d.get(`${f}/sql`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json(n.formatErrorResponse("Query parameter is required",400));const o=JSON.parse(e),s=await y(r,t),a=u.validateQuery(o);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const i=o.measures?.[0]||o.dimensions?.[0];if(!i)return t.status(400).json(n.formatErrorResponse("No measures or dimensions specified",400));const m=i.split(".")[0],p=await u.generateSQL(m,o,s);t.json(n.formatSqlResponse(o,p))}catch(e){console.error("SQL generation error:",e),t.status(500).json(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),d.post(`${f}/dry-run`,async(r,t)=>{try{const e=r.body.query||r.body,o=await y(r,t),s=await n.handleDryRun(e,o,u);t.json(s)}catch(e){console.error("Dry-run error:",e),t.status(400).json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),d.get(`${f}/dry-run`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json({error:"Query parameter is required",valid:!1});const o=JSON.parse(e),s=await y(r,t),a=await n.handleDryRun(o,s,u);t.json(a)}catch(e){console.error("Dry-run error:",e),t.status(400).json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),d.post(`${f}/explain`,async(r,t)=>{try{const e=r.body.query||r.body,o=r.body.options||{},s=await y(r,t),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json({error:`Query validation failed: ${a.errors.join(", ")}`});const i=await u.explainQuery(e,s,o);t.json(i)}catch(e){console.error("Explain error:",e),t.status(500).json({error:e instanceof Error?e.message:"Explain query failed"})}}),j&&d.post(`${f}/agent/chat`,async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-ZDYlokiM.cjs")),{message:o,sessionId:s,history:a}=r.body;if(!o||typeof o!="string")return t.status(400).json({error:"message is required and must be a string"});let i=(j.apiKey||"").trim();if(j.allowClientApiKey){const p=r.headers["x-agent-api-key"];p&&(i=p.trim())}if(!i)return t.status(401).json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const m=await y(r,t);t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const p=e({message:o,sessionId:s,history:a,semanticLayer:u,securityContext:m,agentConfig:j,apiKey:i});for await(const l of p)t.write(`data: ${JSON.stringify(l)}
2
2
 
3
- `)}catch(l){const h={type:"error",data:{message:l instanceof Error?l.message:"Stream failed"}};t.write(`data: ${JSON.stringify(h)}
3
+ `)}catch(p){const l={type:"error",data:{message:p instanceof Error?p.message:"Stream failed"}};t.write(`data: ${JSON.stringify(l)}
4
4
 
5
- `)}finally{t.end()}}catch(e){console.error("Agent chat error:",e),t.headersSent||t.status(500).json({error:e instanceof Error?e.message:"Agent chat failed"})}}),v.enabled!==!1){const r=v.basePath??"/mcp";d.post(`${r}`,async(t,e)=>{const o=c.validateOriginHeader(t.headers.origin,v.allowedOrigins?{allowedOrigins:v.allowedOrigins}:{});if(!o.valid)return e.status(403).json(c.buildJsonRpcError(null,-32600,o.reason));const a=t.headers.accept;if(!c.validateAcceptHeader(a))return e.status(400).json(c.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const s=c.negotiateProtocol(t.headers);if(!s.ok)return e.status(426).json({error:"Unsupported MCP protocol version",supported:s.supported});const i=c.parseJsonRpc(t.body);if(!i)return e.status(400).json(c.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const l=c.wantsEventStream(a),h=i.method==="initialize";try{const p=await c.dispatchMcpMethod(i.method,i.params,{semanticLayer:u,extractSecurityContext:y,rawRequest:t,rawResponse:e,negotiatedProtocol:s.negotiated});if(c.isNotification(i))return e.status(202).end();const b=h&&p&&typeof p=="object"&&"sessionId"in p?p.sessionId:void 0;b&&e.setHeader(c.MCP_SESSION_ID_HEADER,b);const C=c.buildJsonRpcResult(i.id??null,p);if(l){const E=c.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${E}
5
+ `)}finally{t.end()}}catch(e){console.error("Agent chat error:",e),t.headersSent||t.status(500).json({error:e instanceof Error?e.message:"Agent chat failed"})}}),v.enabled!==!1){const r=v.basePath??"/mcp";d.post(`${r}`,async(t,e)=>{const o=c.validateOriginHeader(t.headers.origin,v.allowedOrigins?{allowedOrigins:v.allowedOrigins}:{});if(!o.valid)return e.status(403).json(c.buildJsonRpcError(null,-32600,o.reason));const s=t.headers.accept;if(!c.validateAcceptHeader(s))return e.status(400).json(c.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const a=c.negotiateProtocol(t.headers);if(!a.ok)return e.status(426).json({error:"Unsupported MCP protocol version",supported:a.supported});const i=c.parseJsonRpc(t.body);if(!i)return e.status(400).json(c.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const m=c.wantsEventStream(s),p=i.method==="initialize";try{const l=await c.dispatchMcpMethod(i.method,i.params,{semanticLayer:u,extractSecurityContext:y,rawRequest:t,rawResponse:e,negotiatedProtocol:a.negotiated});if(c.isNotification(i))return e.status(202).end();const b=p&&l&&typeof l=="object"&&"sessionId"in l?l.sessionId:void 0;b&&e.setHeader(c.MCP_SESSION_ID_HEADER,b);const C=c.buildJsonRpcResult(i.id??null,l);if(m){const E=c.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${E}
6
6
 
7
- `),e.write(c.serializeSseEvent(C,E)),e.end()}return e.json(C)}catch(p){if(c.isNotification(i))return console.error("MCP notification processing error:",p),e.status(202).end();console.error("MCP RPC error:",p);const b=p?.code??-32603,C=p?.data,E=p.message||"MCP request failed",Q=c.buildJsonRpcError(i.id??null,b,E,C);if(l){const q=c.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${q}
7
+ `),e.write(c.serializeSseEvent(C,E)),e.end()}return e.json(C)}catch(l){if(c.isNotification(i))return console.error("MCP notification processing error:",l),e.status(202).end();console.error("MCP RPC error:",l);const b=l?.code??-32603,C=l?.data,E=l.message||"MCP request failed",Q=c.buildJsonRpcError(i.id??null,b,E,C);if(m){const q=c.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${q}
8
8
 
9
- `),e.write(c.serializeSseEvent(Q,q)),e.end()}return e.status(200).json(Q)}}),d.get(`${r}`,async(t,e)=>{const o=c.primeEventId();e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(c.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const a=setInterval(()=>{e.write(`: keep-alive
9
+ `),e.write(c.serializeSseEvent(Q,q)),e.end()}return e.status(200).json(Q)}}),d.get(`${r}`,async(t,e)=>{const o=c.primeEventId();e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(c.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const s=setInterval(()=>{e.write(`: keep-alive
10
10
 
11
- `)},15e3);t.on("close",()=>{clearInterval(a)})}),d.delete(`${r}`,(t,e)=>e.status(405).json({error:"Session termination not supported"}))}return d.use((r,t,e,o)=>{console.error("Express adapter error:",r),e.headersSent||e.status(500).json(n.formatErrorResponse(r,500))}),d}function I(g,m){const w=$(m);return g.use("/",w),g}function N(g){const m=R();return I(m,g)}exports.createCubeApp=N;exports.createCubeRouter=$;exports.mountCubeRoutes=I;
11
+ `)},15e3);t.on("close",()=>{clearInterval(s)})}),d.delete(`${r}`,(t,e)=>e.status(405).json({error:"Session termination not supported"}))}return d.use((r,t,e,o)=>{console.error("Express adapter error:",r),e.headersSent||e.status(500).json(n.formatErrorResponse(r,500))}),d}function I(g,h){const w=$(h);return g.use("/",w),g}function N(g){const h=R();return I(h,g)}exports.createCubeApp=N;exports.createCubeRouter=$;exports.mountCubeRoutes=I;
@@ -4,7 +4,7 @@ import { S as D, v as _, b as w, a as K, n as V, p as z, w as T, d as B, i as P,
4
4
  import { formatErrorResponse as u, formatCubeResponse as A, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as H, handleDryRun as M } from "../utils.js";
5
5
  function W(h) {
6
6
  const {
7
- cubes: f,
7
+ cubes: m,
8
8
  drizzle: x,
9
9
  schema: N,
10
10
  extractSecurityContext: y,
@@ -16,7 +16,7 @@ function W(h) {
16
16
  mcp: g = { enabled: !0 },
17
17
  agent: j
18
18
  } = h;
19
- if (!f || f.length === 0)
19
+ if (!m || m.length === 0)
20
20
  throw new Error("At least one cube must be provided in the cubes array");
21
21
  const c = J();
22
22
  R && c.use(L(R)), c.use(E.json({ limit: $ })), c.use(E.urlencoded({ extended: !0, limit: $ }));
@@ -26,17 +26,17 @@ function W(h) {
26
26
  engineType: k,
27
27
  cache: O
28
28
  });
29
- if (f.forEach((r) => {
29
+ if (m.forEach((r) => {
30
30
  i.registerCube(r);
31
31
  }), c.post(`${p}/load`, async (r, t) => {
32
32
  try {
33
- const e = r.body.query || r.body, o = await y(r, t), n = i.validateQuery(e);
34
- if (!n.isValid)
33
+ const e = r.body.query || r.body, o = await y(r, t), a = i.validateQuery(e);
34
+ if (!a.isValid)
35
35
  return t.status(400).json(u(
36
- `Query validation failed: ${n.errors.join(", ")}`,
36
+ `Query validation failed: ${a.errors.join(", ")}`,
37
37
  400
38
38
  ));
39
- const a = r.headers["x-cache-control"] === "no-cache", s = await i.executeMultiCubeQuery(e, o, { skipCache: a });
39
+ const n = r.headers["x-cache-control"] === "no-cache", s = await i.executeMultiCubeQuery(e, o, { skipCache: n });
40
40
  t.json(A(e, s, i));
41
41
  } catch (e) {
42
42
  console.error("Query execution error:", e), t.status(500).json(u(
@@ -61,14 +61,14 @@ function W(h) {
61
61
  400
62
62
  ));
63
63
  }
64
- const n = await y(r, t), a = i.validateQuery(o);
65
- if (!a.isValid)
64
+ const a = await y(r, t), n = i.validateQuery(o);
65
+ if (!n.isValid)
66
66
  return t.status(400).json(u(
67
- `Query validation failed: ${a.errors.join(", ")}`,
67
+ `Query validation failed: ${n.errors.join(", ")}`,
68
68
  400
69
69
  ));
70
- const s = r.headers["x-cache-control"] === "no-cache", d = await i.executeMultiCubeQuery(o, n, { skipCache: s });
71
- t.json(A(o, d, i));
70
+ const s = r.headers["x-cache-control"] === "no-cache", f = await i.executeMultiCubeQuery(o, a, { skipCache: s });
71
+ t.json(A(o, f, i));
72
72
  } catch (e) {
73
73
  console.error("Query execution error:", e), t.status(500).json(u(
74
74
  e instanceof Error ? e.message : "Query execution failed",
@@ -88,8 +88,8 @@ function W(h) {
88
88
  "Queries array cannot be empty",
89
89
  400
90
90
  ));
91
- const o = await y(r, t), n = r.headers["x-cache-control"] === "no-cache", a = await X(e, o, i, { skipCache: n });
92
- t.json(a);
91
+ const o = await y(r, t), a = r.headers["x-cache-control"] === "no-cache", n = await X(e, o, i, { skipCache: a });
92
+ t.json(n);
93
93
  } catch (e) {
94
94
  console.error("Batch execution error:", e), t.status(500).json(u(
95
95
  e instanceof Error ? e.message : "Batch execution failed",
@@ -108,20 +108,20 @@ function W(h) {
108
108
  }
109
109
  }), c.post(`${p}/sql`, async (r, t) => {
110
110
  try {
111
- const e = r.body, o = await y(r, t), n = i.validateQuery(e);
112
- if (!n.isValid)
111
+ const e = r.body, o = await y(r, t), a = i.validateQuery(e);
112
+ if (!a.isValid)
113
113
  return t.status(400).json(u(
114
- `Query validation failed: ${n.errors.join(", ")}`,
114
+ `Query validation failed: ${a.errors.join(", ")}`,
115
115
  400
116
116
  ));
117
- const a = e.measures?.[0] || e.dimensions?.[0];
118
- if (!a)
117
+ const n = e.measures?.[0] || e.dimensions?.[0];
118
+ if (!n)
119
119
  return t.status(400).json(u(
120
120
  "No measures or dimensions specified",
121
121
  400
122
122
  ));
123
- const s = a.split(".")[0], d = await i.generateSQL(s, e, o);
124
- t.json(H(e, d));
123
+ const s = n.split(".")[0], f = await i.generateSQL(s, e, o);
124
+ t.json(H(e, f));
125
125
  } catch (e) {
126
126
  console.error("SQL generation error:", e), t.status(500).json(u(
127
127
  e instanceof Error ? e.message : "SQL generation failed",
@@ -136,10 +136,10 @@ function W(h) {
136
136
  "Query parameter is required",
137
137
  400
138
138
  ));
139
- const o = JSON.parse(e), n = await y(r, t), a = i.validateQuery(o);
140
- if (!a.isValid)
139
+ const o = JSON.parse(e), a = await y(r, t), n = i.validateQuery(o);
140
+ if (!n.isValid)
141
141
  return t.status(400).json(u(
142
- `Query validation failed: ${a.errors.join(", ")}`,
142
+ `Query validation failed: ${n.errors.join(", ")}`,
143
143
  400
144
144
  ));
145
145
  const s = o.measures?.[0] || o.dimensions?.[0];
@@ -148,8 +148,8 @@ function W(h) {
148
148
  "No measures or dimensions specified",
149
149
  400
150
150
  ));
151
- const d = s.split(".")[0], m = await i.generateSQL(d, o, n);
152
- t.json(H(o, m));
151
+ const f = s.split(".")[0], l = await i.generateSQL(f, o, a);
152
+ t.json(H(o, l));
153
153
  } catch (e) {
154
154
  console.error("SQL generation error:", e), t.status(500).json(u(
155
155
  e instanceof Error ? e.message : "SQL generation failed",
@@ -158,8 +158,8 @@ function W(h) {
158
158
  }
159
159
  }), c.post(`${p}/dry-run`, async (r, t) => {
160
160
  try {
161
- const e = r.body.query || r.body, o = await y(r, t), n = await M(e, o, i);
162
- t.json(n);
161
+ const e = r.body.query || r.body, o = await y(r, t), a = await M(e, o, i);
162
+ t.json(a);
163
163
  } catch (e) {
164
164
  console.error("Dry-run error:", e), t.status(400).json({
165
165
  error: e instanceof Error ? e.message : "Dry-run validation failed",
@@ -174,8 +174,8 @@ function W(h) {
174
174
  error: "Query parameter is required",
175
175
  valid: !1
176
176
  });
177
- const o = JSON.parse(e), n = await y(r, t), a = await M(o, n, i);
178
- t.json(a);
177
+ const o = JSON.parse(e), a = await y(r, t), n = await M(o, a, i);
178
+ t.json(n);
179
179
  } catch (e) {
180
180
  console.error("Dry-run error:", e), t.status(400).json({
181
181
  error: e instanceof Error ? e.message : "Dry-run validation failed",
@@ -184,12 +184,12 @@ function W(h) {
184
184
  }
185
185
  }), c.post(`${p}/explain`, async (r, t) => {
186
186
  try {
187
- const e = r.body.query || r.body, o = r.body.options || {}, n = await y(r, t), a = i.validateQuery(e);
188
- if (!a.isValid)
187
+ const e = r.body.query || r.body, o = r.body.options || {}, a = await y(r, t), n = i.validateQuery(e);
188
+ if (!n.isValid)
189
189
  return t.status(400).json({
190
- error: `Query validation failed: ${a.errors.join(", ")}`
190
+ error: `Query validation failed: ${n.errors.join(", ")}`
191
191
  });
192
- const s = await i.explainQuery(e, n, o);
192
+ const s = await i.explainQuery(e, a, o);
193
193
  t.json(s);
194
194
  } catch (e) {
195
195
  console.error("Explain error:", e), t.status(500).json({
@@ -198,43 +198,44 @@ function W(h) {
198
198
  }
199
199
  }), j && c.post(`${p}/agent/chat`, async (r, t) => {
200
200
  try {
201
- const { handleAgentChat: e } = await import("../handler-CQkIwtxp.js"), { message: o, sessionId: n } = r.body;
201
+ const { handleAgentChat: e } = await import("../handler-DZnCbydH.js"), { message: o, sessionId: a, history: n } = r.body;
202
202
  if (!o || typeof o != "string")
203
203
  return t.status(400).json({ error: "message is required and must be a string" });
204
- let a = (j.apiKey || "").trim();
204
+ let s = (j.apiKey || "").trim();
205
205
  if (j.allowClientApiKey) {
206
- const d = r.headers["x-agent-api-key"];
207
- d && (a = d.trim());
206
+ const l = r.headers["x-agent-api-key"];
207
+ l && (s = l.trim());
208
208
  }
209
- if (!a)
209
+ if (!s)
210
210
  return t.status(401).json({
211
211
  error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
212
212
  });
213
- const s = await y(r, t);
213
+ const f = await y(r, t);
214
214
  t.writeHead(200, {
215
215
  "Content-Type": "text/event-stream",
216
216
  "Cache-Control": "no-cache",
217
217
  Connection: "keep-alive"
218
218
  });
219
219
  try {
220
- const d = e({
220
+ const l = e({
221
221
  message: o,
222
- sessionId: n,
222
+ sessionId: a,
223
+ history: n,
223
224
  semanticLayer: i,
224
- securityContext: s,
225
+ securityContext: f,
225
226
  agentConfig: j,
226
- apiKey: a
227
+ apiKey: s
227
228
  });
228
- for await (const m of d)
229
- t.write(`data: ${JSON.stringify(m)}
229
+ for await (const d of l)
230
+ t.write(`data: ${JSON.stringify(d)}
230
231
 
231
232
  `);
232
- } catch (d) {
233
- const m = {
233
+ } catch (l) {
234
+ const d = {
234
235
  type: "error",
235
- data: { message: d instanceof Error ? d.message : "Stream failed" }
236
+ data: { message: l instanceof Error ? l.message : "Stream failed" }
236
237
  };
237
- t.write(`data: ${JSON.stringify(m)}
238
+ t.write(`data: ${JSON.stringify(d)}
238
239
 
239
240
  `);
240
241
  } finally {
@@ -254,21 +255,21 @@ function W(h) {
254
255
  );
255
256
  if (!o.valid)
256
257
  return e.status(403).json(w(null, -32600, o.reason));
257
- const n = t.headers.accept;
258
- if (!K(n))
258
+ const a = t.headers.accept;
259
+ if (!K(a))
259
260
  return e.status(400).json(w(null, -32600, "Accept header must include both application/json and text/event-stream"));
260
- const a = V(t.headers);
261
- if (!a.ok)
261
+ const n = V(t.headers);
262
+ if (!n.ok)
262
263
  return e.status(426).json({
263
264
  error: "Unsupported MCP protocol version",
264
- supported: a.supported
265
+ supported: n.supported
265
266
  });
266
267
  const s = z(t.body);
267
268
  if (!s)
268
269
  return e.status(400).json(w(null, -32600, "Invalid JSON-RPC 2.0 request"));
269
- const d = T(n), m = s.method === "initialize";
270
+ const f = T(a), l = s.method === "initialize";
270
271
  try {
271
- const l = await B(
272
+ const d = await B(
272
273
  s.method,
273
274
  s.params,
274
275
  {
@@ -276,27 +277,27 @@ function W(h) {
276
277
  extractSecurityContext: y,
277
278
  rawRequest: t,
278
279
  rawResponse: e,
279
- negotiatedProtocol: a.negotiated
280
+ negotiatedProtocol: n.negotiated
280
281
  }
281
282
  );
282
283
  if (P(s))
283
284
  return e.status(202).end();
284
- const v = m && l && typeof l == "object" && "sessionId" in l ? l.sessionId : void 0;
285
+ const v = l && d && typeof d == "object" && "sessionId" in d ? d.sessionId : void 0;
285
286
  v && e.setHeader(F, v);
286
- const C = U(s.id ?? null, l);
287
- if (d) {
287
+ const C = U(s.id ?? null, d);
288
+ if (f) {
288
289
  const b = S();
289
290
  return e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(`id: ${b}
290
291
 
291
292
  `), e.write(Q(C, b)), e.end();
292
293
  }
293
294
  return e.json(C);
294
- } catch (l) {
295
+ } catch (d) {
295
296
  if (P(s))
296
- return console.error("MCP notification processing error:", l), e.status(202).end();
297
- console.error("MCP RPC error:", l);
298
- const v = l?.code ?? -32603, C = l?.data, b = l.message || "MCP request failed", q = w(s.id ?? null, v, b, C);
299
- if (d) {
297
+ return console.error("MCP notification processing error:", d), e.status(202).end();
298
+ console.error("MCP RPC error:", d);
299
+ const v = d?.code ?? -32603, C = d?.data, b = d.message || "MCP request failed", q = w(s.id ?? null, v, b, C);
300
+ if (f) {
300
301
  const I = S();
301
302
  return e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(`id: ${I}
302
303
 
@@ -311,13 +312,13 @@ function W(h) {
311
312
  method: "mcp/ready",
312
313
  params: { protocol: "streamable-http" }
313
314
  }, o, 15e3));
314
- const n = setInterval(() => {
315
+ const a = setInterval(() => {
315
316
  e.write(`: keep-alive
316
317
 
317
318
  `);
318
319
  }, 15e3);
319
320
  t.on("close", () => {
320
- clearInterval(n);
321
+ clearInterval(a);
321
322
  });
322
323
  }), c.delete(`${r}`, (t, e) => e.status(405).json({ error: "Session termination not supported" }));
323
324
  }
@@ -325,13 +326,13 @@ function W(h) {
325
326
  console.error("Express adapter error:", r), e.headersSent || e.status(500).json(u(r, 500));
326
327
  }), c;
327
328
  }
328
- function Y(h, f) {
329
- const x = W(f);
329
+ function Y(h, m) {
330
+ const x = W(m);
330
331
  return h.use("/", x), h;
331
332
  }
332
333
  function oe(h) {
333
- const f = E();
334
- return Y(f, h);
334
+ const m = E();
335
+ return Y(m, h);
335
336
  }
336
337
  export {
337
338
  oe as createCubeApp,
@@ -1,11 +1,11 @@
1
- "use strict";var O=Object.create;var j=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var H=(l,n,b,C)=>{if(n&&typeof n=="object"||typeof n=="function")for(let f of J(n))!D.call(l,f)&&f!==b&&j(l,f,{get:()=>n[f],enumerable:!(C=k(n,f))||C.enumerable});return l};var T=(l,n,b)=>(b=l!=null?O(L(l)):{},H(n||!l||!l.__esModule?j(b,"default",{value:l,enumerable:!0}):b,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../mcp-transport-8u9G5oNa.cjs"),i=require("../utils.cjs"),q=function(n,b,C){const{cubes:f,drizzle:I,schema:A,extractSecurityContext:g,engineType:M,cors:P,basePath:h="/cubejs-api/v1",bodyLimit:v=10485760,cache:N,mcp:E={enabled:!0},agent:R}=b;if(!f||f.length===0)return C(new Error("At least one cube must be provided in the cubes array"));P&&n.register(import("@fastify/cors"),P),n.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const d=new u.SemanticLayerCompiler({drizzle:I,schema:A,engineType:M,cache:N});if(f.forEach(r=>{d.registerCube(r)}),n.post(`${h}/load`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:a});return i.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.get(`${h}/load`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query;let o;try{o=JSON.parse(e)}catch{return t.status(400).send(i.formatErrorResponse("Invalid JSON in query parameter",400))}const s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:a});return i.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.post(`${h}/batch`,{bodyLimit:v,schema:{body:{type:"object",required:["queries"],properties:{queries:{type:"array",items:{type:"object"}}}}}},async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).send(i.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).send(i.formatErrorResponse("Queries array cannot be empty",400));const o=await g(r),s=r.headers["x-cache-control"]==="no-cache";return await i.handleBatchRequest(e,o,d,{skipCache:s})}catch(e){return r.log.error(e,"Batch execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),n.get(`${h}/meta`,async(r,t)=>{try{const e=d.getMetadata();return i.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),n.post(`${h}/sql`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await g(r),s=d.validateQuery(e);if(!s.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const c=e.measures?.[0]||e.dimensions?.[0];if(!c)return t.status(400).send(i.formatErrorResponse("No measures or dimensions specified",400));const a=c.split(".")[0],y=await d.generateSQL(a,e,o);return i.formatSqlResponse(e,y)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.get(`${h}/sql`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query,o=JSON.parse(e),s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=o.measures?.[0]||o.dimensions?.[0];if(!a)return t.status(400).send(i.formatErrorResponse("No measures or dimensions specified",400));const y=a.split(".")[0],m=await d.generateSQL(y,o,s);return i.formatSqlResponse(o,m)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.post(`${h}/dry-run`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await g(r);return await i.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.get(`${h}/dry-run`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query,o=JSON.parse(e),s=await g(r);return await i.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.post(`${h}/explain`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=e.options||{},c=await g(r),a=d.validateQuery(o);return a.isValid?await d.explainQuery(o,c,s):t.status(400).send({error:`Query validation failed: ${a.errors.join(", ")}`})}catch(e){return r.log.error(e,"Explain error"),t.status(500).send({error:e instanceof Error?e.message:"Explain query failed"})}}),R&&n.post(`${h}/agent/chat`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-dnkqpznh.cjs")),o=r.body,{message:s,sessionId:c}=o;if(!s||typeof s!="string")return t.status(400).send({error:"message is required and must be a string"});let a=(R.apiKey||"").trim();if(R.allowClientApiKey){const m=r.headers["x-agent-api-key"];m&&(a=m.trim())}if(!a)return t.status(401).send({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const y=await g(r);t.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const m=e({message:s,sessionId:c,semanticLayer:d,securityContext:y,agentConfig:R,apiKey:a});for await(const p of m)t.raw.write(`data: ${JSON.stringify(p)}
1
+ "use strict";var O=Object.create;var j=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var H=(p,n,b,C)=>{if(n&&typeof n=="object"||typeof n=="function")for(let h of J(n))!D.call(p,h)&&h!==b&&j(p,h,{get:()=>n[h],enumerable:!(C=k(n,h))||C.enumerable});return p};var T=(p,n,b)=>(b=p!=null?O(L(p)):{},H(n||!p||!p.__esModule?j(b,"default",{value:p,enumerable:!0}):b,p));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../mcp-transport-8u9G5oNa.cjs"),a=require("../utils.cjs"),q=function(n,b,C){const{cubes:h,drizzle:I,schema:A,extractSecurityContext:m,engineType:M,cors:P,basePath:g="/cubejs-api/v1",bodyLimit:v=10485760,cache:N,mcp:R={enabled:!0},agent:w}=b;if(!h||h.length===0)return C(new Error("At least one cube must be provided in the cubes array"));P&&n.register(import("@fastify/cors"),P),n.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const d=new u.SemanticLayerCompiler({drizzle:I,schema:A,engineType:M,cache:N});if(h.forEach(r=>{d.registerCube(r)}),n.post(`${g}/load`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await m(r),i=d.validateQuery(o);if(!i.isValid)return t.status(400).send(a.formatErrorResponse(`Query validation failed: ${i.errors.join(", ")}`,400));const c=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:c});return a.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(a.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.get(`${g}/load`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query;let o;try{o=JSON.parse(e)}catch{return t.status(400).send(a.formatErrorResponse("Invalid JSON in query parameter",400))}const s=await m(r),i=d.validateQuery(o);if(!i.isValid)return t.status(400).send(a.formatErrorResponse(`Query validation failed: ${i.errors.join(", ")}`,400));const c=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:c});return a.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(a.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.post(`${g}/batch`,{bodyLimit:v,schema:{body:{type:"object",required:["queries"],properties:{queries:{type:"array",items:{type:"object"}}}}}},async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).send(a.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).send(a.formatErrorResponse("Queries array cannot be empty",400));const o=await m(r),s=r.headers["x-cache-control"]==="no-cache";return await a.handleBatchRequest(e,o,d,{skipCache:s})}catch(e){return r.log.error(e,"Batch execution error"),t.status(500).send(a.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),n.get(`${g}/meta`,async(r,t)=>{try{const e=d.getMetadata();return a.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),t.status(500).send(a.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),n.post(`${g}/sql`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await m(r),s=d.validateQuery(e);if(!s.isValid)return t.status(400).send(a.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const i=e.measures?.[0]||e.dimensions?.[0];if(!i)return t.status(400).send(a.formatErrorResponse("No measures or dimensions specified",400));const c=i.split(".")[0],y=await d.generateSQL(c,e,o);return a.formatSqlResponse(e,y)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(a.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.get(`${g}/sql`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query,o=JSON.parse(e),s=await m(r),i=d.validateQuery(o);if(!i.isValid)return t.status(400).send(a.formatErrorResponse(`Query validation failed: ${i.errors.join(", ")}`,400));const c=o.measures?.[0]||o.dimensions?.[0];if(!c)return t.status(400).send(a.formatErrorResponse("No measures or dimensions specified",400));const y=c.split(".")[0],E=await d.generateSQL(y,o,s);return a.formatSqlResponse(o,E)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(a.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.post(`${g}/dry-run`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await m(r);return await a.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.get(`${g}/dry-run`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query,o=JSON.parse(e),s=await m(r);return await a.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.post(`${g}/explain`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=e.options||{},i=await m(r),c=d.validateQuery(o);return c.isValid?await d.explainQuery(o,i,s):t.status(400).send({error:`Query validation failed: ${c.errors.join(", ")}`})}catch(e){return r.log.error(e,"Explain error"),t.status(500).send({error:e instanceof Error?e.message:"Explain query failed"})}}),w&&n.post(`${g}/agent/chat`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-ZDYlokiM.cjs")),o=r.body,{message:s,sessionId:i,history:c}=o;if(!s||typeof s!="string")return t.status(400).send({error:"message is required and must be a string"});let y=(w.apiKey||"").trim();if(w.allowClientApiKey){const l=r.headers["x-agent-api-key"];l&&(y=l.trim())}if(!y)return t.status(401).send({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const E=await m(r);t.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const l=e({message:s,sessionId:i,history:c,semanticLayer:d,securityContext:E,agentConfig:w,apiKey:y});for await(const f of l)t.raw.write(`data: ${JSON.stringify(f)}
2
2
 
3
- `)}catch(m){const p={type:"error",data:{message:m instanceof Error?m.message:"Stream failed"}};t.raw.write(`data: ${JSON.stringify(p)}
3
+ `)}catch(l){const f={type:"error",data:{message:l instanceof Error?l.message:"Stream failed"}};t.raw.write(`data: ${JSON.stringify(f)}
4
4
 
5
- `)}finally{t.raw.end()}}catch(e){if(r.log.error(e,"Agent chat error"),!t.raw.headersSent)return t.status(500).send({error:e instanceof Error?e.message:"Agent chat failed"})}}),E.enabled!==!1){const r=E.basePath??"/mcp";n.post(`${r}`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(t,e)=>{const o=u.validateOriginHeader(t.headers.origin,E.allowedOrigins?{allowedOrigins:E.allowedOrigins}:{});if(!o.valid)return e.status(403).send(u.buildJsonRpcError(null,-32600,o.reason));const s=t.headers.accept;if(!u.validateAcceptHeader(s))return e.status(400).send(u.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const c=u.negotiateProtocol(t.headers);if(!c.ok)return e.status(426).send({error:"Unsupported MCP protocol version",supported:c.supported});const a=u.parseJsonRpc(t.body);if(!a)return e.status(400).send(u.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const y=u.wantsEventStream(s),m=a.method==="initialize";try{const p=await u.dispatchMcpMethod(a.method,a.params,{semanticLayer:d,extractSecurityContext:g,rawRequest:t,rawResponse:e,negotiatedProtocol:c.negotiated});if(u.isNotification(a))return e.status(202).send();const w=m&&p&&typeof p=="object"&&"sessionId"in p?p.sessionId:void 0;w&&e.header(u.MCP_SESSION_ID_HEADER,w);const x=u.buildJsonRpcResult(a.id??null,p);if(y){const S=u.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${S}
5
+ `)}finally{t.raw.end()}}catch(e){if(r.log.error(e,"Agent chat error"),!t.raw.headersSent)return t.status(500).send({error:e instanceof Error?e.message:"Agent chat failed"})}}),R.enabled!==!1){const r=R.basePath??"/mcp";n.post(`${r}`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(t,e)=>{const o=u.validateOriginHeader(t.headers.origin,R.allowedOrigins?{allowedOrigins:R.allowedOrigins}:{});if(!o.valid)return e.status(403).send(u.buildJsonRpcError(null,-32600,o.reason));const s=t.headers.accept;if(!u.validateAcceptHeader(s))return e.status(400).send(u.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const i=u.negotiateProtocol(t.headers);if(!i.ok)return e.status(426).send({error:"Unsupported MCP protocol version",supported:i.supported});const c=u.parseJsonRpc(t.body);if(!c)return e.status(400).send(u.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const y=u.wantsEventStream(s),E=c.method==="initialize";try{const l=await u.dispatchMcpMethod(c.method,c.params,{semanticLayer:d,extractSecurityContext:m,rawRequest:t,rawResponse:e,negotiatedProtocol:i.negotiated});if(u.isNotification(c))return e.status(202).send();const f=E&&l&&typeof l=="object"&&"sessionId"in l?l.sessionId:void 0;f&&e.header(u.MCP_SESSION_ID_HEADER,f);const x=u.buildJsonRpcResult(c.id??null,l);if(y){const S=u.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${S}
6
6
 
7
- ${u.serializeSseEvent(x,S)}`);return}return e.send(x)}catch(p){if(u.isNotification(a))return t.log.error(p,"MCP notification processing error"),e.status(202).send();t.log.error(p,"MCP RPC error");const w=p?.code??-32603,x=p?.data,S=p.message||"MCP request failed",Q=u.buildJsonRpcError(a.id??null,w,S,x);if(y){const $=u.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${$}
7
+ ${u.serializeSseEvent(x,S)}`);return}return e.send(x)}catch(l){if(u.isNotification(c))return t.log.error(l,"MCP notification processing error"),e.status(202).send();t.log.error(l,"MCP RPC error");const f=l?.code??-32603,x=l?.data,S=l.message||"MCP request failed",Q=u.buildJsonRpcError(c.id??null,f,S,x);if(y){const $=u.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${$}
8
8
 
9
9
  ${u.serializeSseEvent(Q,$)}`);return}return e.send(Q)}}),n.get(`${r}`,async(t,e)=>{const o=u.primeEventId();e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),e.raw.write(u.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const s=setInterval(()=>{e.raw.write(`: keep-alive
10
10
 
11
- `)},15e3);t.raw.on("close",()=>{clearInterval(s)})}),n.delete(`${r}`,async(t,e)=>e.status(405).send({error:"Session termination not supported"}))}n.setErrorHandler(async(r,t,e)=>{t.log.error(r,"Fastify cube adapter error"),e.statusCode<400&&e.status(500);const o=r instanceof Error?r:String(r);return i.formatErrorResponse(o,e.statusCode)}),C()};async function z(l,n){await l.register(q,n)}function K(l){const n=require("fastify")({logger:!0});return n.register(q,l),n}exports.createCubeApp=K;exports.cubePlugin=q;exports.registerCubeRoutes=z;
11
+ `)},15e3);t.raw.on("close",()=>{clearInterval(s)})}),n.delete(`${r}`,async(t,e)=>e.status(405).send({error:"Session termination not supported"}))}n.setErrorHandler(async(r,t,e)=>{t.log.error(r,"Fastify cube adapter error"),e.statusCode<400&&e.status(500);const o=r instanceof Error?r:String(r);return a.formatErrorResponse(o,e.statusCode)}),C()};async function z(p,n){await p.register(q,n)}function K(p){const n=require("fastify")({logger:!0});return n.register(q,p),n}exports.createCubeApp=K;exports.cubePlugin=q;exports.registerCubeRoutes=z;