drizzle-cube 0.4.5 → 0.4.8

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 (140) hide show
  1. package/dist/adapters/express/index.cjs +8 -4
  2. package/dist/adapters/express/index.d.ts +7 -0
  3. package/dist/adapters/express/index.js +189 -139
  4. package/dist/adapters/fastify/index.cjs +8 -4
  5. package/dist/adapters/fastify/index.d.ts +7 -0
  6. package/dist/adapters/fastify/index.js +209 -150
  7. package/dist/adapters/handler-BLcxTuwi.cjs +23 -0
  8. package/dist/adapters/handler-odjn7MIB.js +1880 -0
  9. package/dist/adapters/hono/index.cjs +8 -4
  10. package/dist/adapters/hono/index.d.ts +7 -0
  11. package/dist/adapters/hono/index.js +202 -144
  12. package/dist/adapters/{mcp-transport-YHDZWKOi.js → mcp-transport-CU5g9bxj.js} +7 -3
  13. package/dist/adapters/{mcp-transport-BqLo4hKi.cjs → mcp-transport-KX92EgkF.cjs} +21 -21
  14. package/dist/adapters/nextjs/index.cjs +7 -3
  15. package/dist/adapters/nextjs/index.d.ts +14 -0
  16. package/dist/adapters/nextjs/index.js +220 -144
  17. package/dist/client/charts/chartConfigs.d.ts +2 -9
  18. package/dist/client/charts.js +72 -70
  19. package/dist/client/charts.js.map +1 -1
  20. package/dist/client/chunks/{RetentionCombinedChart.config-C-ILIaEb.js → RetentionCombinedChart.config-Bbp2ghim.js} +2 -1
  21. package/dist/client/chunks/RetentionCombinedChart.config-Bbp2ghim.js.map +1 -0
  22. package/dist/client/chunks/{RetentionHeatmap.config-CIvhc-GT.js → RetentionHeatmap.config-BWf_-vdj.js} +2 -1
  23. package/dist/client/chunks/RetentionHeatmap.config-BWf_-vdj.js.map +1 -0
  24. package/dist/client/chunks/{analysis-builder-CG5VIMYB.js → analysis-builder-Bov_gLsf.js} +1408 -1393
  25. package/dist/client/chunks/analysis-builder-Bov_gLsf.js.map +1 -0
  26. package/dist/client/chunks/{analysis-builder-shared-CjlKJgyA.js → analysis-builder-shared-NBk6y0md.js} +3 -3
  27. package/dist/client/chunks/{analysis-builder-shared-CjlKJgyA.js.map → analysis-builder-shared-NBk6y0md.js.map} +1 -1
  28. package/dist/client/chunks/{chart-activity-grid-DStNr34n.js → chart-activity-grid-CE7xGFQo.js} +2 -2
  29. package/dist/client/chunks/{chart-activity-grid-DStNr34n.js.map → chart-activity-grid-CE7xGFQo.js.map} +1 -1
  30. package/dist/client/chunks/chart-box-plot-Dja4LS3O.js +313 -0
  31. package/dist/client/chunks/chart-box-plot-Dja4LS3O.js.map +1 -0
  32. package/dist/client/chunks/{chart-config-activity-grid-CAlo1cHA.js → chart-config-activity-grid-CmOqDuOT.js} +4 -5
  33. package/dist/client/chunks/chart-config-activity-grid-CmOqDuOT.js.map +1 -0
  34. package/dist/client/chunks/{chart-config-area-CyyJOO2T.js → chart-config-area-CK_GVApT.js} +4 -5
  35. package/dist/client/chunks/chart-config-area-CK_GVApT.js.map +1 -0
  36. package/dist/client/chunks/{chart-config-bar-soxw6m2o.js → chart-config-bar-C8uzktxl.js} +4 -5
  37. package/dist/client/chunks/chart-config-bar-C8uzktxl.js.map +1 -0
  38. package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js +85 -0
  39. package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js.map +1 -0
  40. package/dist/client/chunks/{chart-config-bubble-CuSsCHZ4.js → chart-config-bubble-q3DoQX5F.js} +4 -5
  41. package/dist/client/chunks/chart-config-bubble-q3DoQX5F.js.map +1 -0
  42. package/dist/client/chunks/{chart-config-data-table-BhgqwoqT.js → chart-config-data-table-B20Y5JCm.js} +4 -5
  43. package/dist/client/chunks/chart-config-data-table-B20Y5JCm.js.map +1 -0
  44. package/dist/client/chunks/{chart-config-funnel-BlSQYng0.js → chart-config-funnel-3eYnGg8M.js} +4 -5
  45. package/dist/client/chunks/chart-config-funnel-3eYnGg8M.js.map +1 -0
  46. package/dist/client/chunks/{chart-config-heat-map-DHQGFZhX.js → chart-config-heat-map-_wEnTnRA.js} +4 -5
  47. package/dist/client/chunks/chart-config-heat-map-_wEnTnRA.js.map +1 -0
  48. package/dist/client/chunks/{chart-config-kpi-delta-yTA5ug_l.js → chart-config-kpi-delta-DLGZ2A3X.js} +4 -5
  49. package/dist/client/chunks/chart-config-kpi-delta-DLGZ2A3X.js.map +1 -0
  50. package/dist/client/chunks/{chart-config-kpi-number-nVAwDXzq.js → chart-config-kpi-number-K-wzviXF.js} +4 -5
  51. package/dist/client/chunks/chart-config-kpi-number-K-wzviXF.js.map +1 -0
  52. package/dist/client/chunks/{chart-config-kpi-text-DZjqsx-b.js → chart-config-kpi-text-BjYqwqaJ.js} +4 -5
  53. package/dist/client/chunks/chart-config-kpi-text-BjYqwqaJ.js.map +1 -0
  54. package/dist/client/chunks/{chart-config-line-D5ME6w0v.js → chart-config-line-JNagi9tf.js} +4 -5
  55. package/dist/client/chunks/chart-config-line-JNagi9tf.js.map +1 -0
  56. package/dist/client/chunks/{chart-config-markdown-BXKL5TbQ.js → chart-config-markdown-BWQSjJpy.js} +4 -5
  57. package/dist/client/chunks/chart-config-markdown-BWQSjJpy.js.map +1 -0
  58. package/dist/client/chunks/{chart-config-pie-DlHa2jTy.js → chart-config-pie-CNLXb-fr.js} +4 -5
  59. package/dist/client/chunks/chart-config-pie-CNLXb-fr.js.map +1 -0
  60. package/dist/client/chunks/{chart-config-radar-BBAVIF0S.js → chart-config-radar-oxHfRAa3.js} +4 -5
  61. package/dist/client/chunks/chart-config-radar-oxHfRAa3.js.map +1 -0
  62. package/dist/client/chunks/{chart-config-radial-bar-CTwjDRnB.js → chart-config-radial-bar-_Aw3jAEm.js} +4 -5
  63. package/dist/client/chunks/chart-config-radial-bar-_Aw3jAEm.js.map +1 -0
  64. package/dist/client/chunks/{chart-config-sankey-CNAgsMQ4.js → chart-config-sankey-C8FX9hGF.js} +4 -5
  65. package/dist/client/chunks/chart-config-sankey-C8FX9hGF.js.map +1 -0
  66. package/dist/client/chunks/{chart-config-scatter-CWvN2E-X.js → chart-config-scatter-DFKM80eO.js} +4 -5
  67. package/dist/client/chunks/chart-config-scatter-DFKM80eO.js.map +1 -0
  68. package/dist/client/chunks/{chart-config-sunburst-W_SKwaj0.js → chart-config-sunburst-BmC0NLTU.js} +4 -5
  69. package/dist/client/chunks/chart-config-sunburst-BmC0NLTU.js.map +1 -0
  70. package/dist/client/chunks/{chart-config-tree-map-IRAYf9YM.js → chart-config-tree-map-DGMbNTaa.js} +4 -5
  71. package/dist/client/chunks/chart-config-tree-map-DGMbNTaa.js.map +1 -0
  72. package/dist/client/chunks/{chart-data-table-Ch_1c1Zo.js → chart-data-table-Ba_6tuJw.js} +2 -2
  73. package/dist/client/chunks/{chart-data-table-Ch_1c1Zo.js.map → chart-data-table-Ba_6tuJw.js.map} +1 -1
  74. package/dist/client/chunks/{chart-kpi-delta-CWCmi8vL.js → chart-kpi-delta-D9XJoKuA.js} +3 -3
  75. package/dist/client/chunks/{chart-kpi-delta-CWCmi8vL.js.map → chart-kpi-delta-D9XJoKuA.js.map} +1 -1
  76. package/dist/client/chunks/{chart-kpi-number-C-5m3qt5.js → chart-kpi-number-C29Vj2g8.js} +2 -2
  77. package/dist/client/chunks/{chart-kpi-number-C-5m3qt5.js.map → chart-kpi-number-C29Vj2g8.js.map} +1 -1
  78. package/dist/client/chunks/{chart-kpi-text--t4ibPmx.js → chart-kpi-text-CgjjrurK.js} +2 -2
  79. package/dist/client/chunks/{chart-kpi-text--t4ibPmx.js.map → chart-kpi-text-CgjjrurK.js.map} +1 -1
  80. package/dist/client/chunks/chart-markdown-Du4Z2iqK.js +2695 -0
  81. package/dist/client/chunks/chart-markdown-Du4Z2iqK.js.map +1 -0
  82. package/dist/client/chunks/{charts-loader-m5Ussksz.js → charts-loader-HYQFVOo4.js} +14 -13
  83. package/dist/client/chunks/charts-loader-HYQFVOo4.js.map +1 -0
  84. package/dist/client/chunks/{components-D-5p1LVQ.js → components-O0hh7ooo.js} +6 -6
  85. package/dist/client/chunks/components-O0hh7ooo.js.map +1 -0
  86. package/dist/client/chunks/{icons-DRreo6m8.js → icons-DAeqv1iX.js} +7 -7
  87. package/dist/client/chunks/{icons-DRreo6m8.js.map → icons-DAeqv1iX.js.map} +1 -1
  88. package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +8 -0
  89. package/dist/client/components/AgenticNotebook/ChatInput.d.ts +14 -0
  90. package/dist/client/components/AgenticNotebook/ChatMessage.d.ts +7 -0
  91. package/dist/client/components/AgenticNotebook/NotebookCanvas.d.ts +3 -0
  92. package/dist/client/components/AgenticNotebook/NotebookMarkdownBlock.d.ts +12 -0
  93. package/dist/client/components/AgenticNotebook/NotebookPortletBlock.d.ts +12 -0
  94. package/dist/client/components/AgenticNotebook/index.d.ts +34 -0
  95. package/dist/client/components/charts/BoxPlotChart.config.d.ts +11 -0
  96. package/dist/client/components/charts/BoxPlotChart.d.ts +4 -0
  97. package/dist/client/components/charts/index.d.ts +1 -0
  98. package/dist/client/components.js +1 -1
  99. package/dist/client/hooks/useAgentChat.d.ts +36 -0
  100. package/dist/client/icons.js +1 -1
  101. package/dist/client/index.d.ts +6 -0
  102. package/dist/client/index.js +923 -187
  103. package/dist/client/index.js.map +1 -1
  104. package/dist/client/stores/notebookStore.d.ts +152 -0
  105. package/dist/client/styles.css +1 -1
  106. package/dist/client/types.d.ts +1 -1
  107. package/dist/client/utils.js +3 -3
  108. package/dist/client-bundle-stats.html +4 -4
  109. package/dist/server/index.cjs +116 -90
  110. package/dist/server/index.d.ts +155 -0
  111. package/dist/server/index.js +7088 -4852
  112. package/package.json +12 -6
  113. package/dist/client/chunks/RetentionCombinedChart.config-C-ILIaEb.js.map +0 -1
  114. package/dist/client/chunks/RetentionHeatmap.config-CIvhc-GT.js.map +0 -1
  115. package/dist/client/chunks/analysis-builder-CG5VIMYB.js.map +0 -1
  116. package/dist/client/chunks/chart-config-activity-grid-CAlo1cHA.js.map +0 -1
  117. package/dist/client/chunks/chart-config-area-CyyJOO2T.js.map +0 -1
  118. package/dist/client/chunks/chart-config-bar-soxw6m2o.js.map +0 -1
  119. package/dist/client/chunks/chart-config-bubble-CuSsCHZ4.js.map +0 -1
  120. package/dist/client/chunks/chart-config-data-table-BhgqwoqT.js.map +0 -1
  121. package/dist/client/chunks/chart-config-funnel-BlSQYng0.js.map +0 -1
  122. package/dist/client/chunks/chart-config-heat-map-DHQGFZhX.js.map +0 -1
  123. package/dist/client/chunks/chart-config-kpi-delta-yTA5ug_l.js.map +0 -1
  124. package/dist/client/chunks/chart-config-kpi-number-nVAwDXzq.js.map +0 -1
  125. package/dist/client/chunks/chart-config-kpi-text-DZjqsx-b.js.map +0 -1
  126. package/dist/client/chunks/chart-config-line-D5ME6w0v.js.map +0 -1
  127. package/dist/client/chunks/chart-config-markdown-BXKL5TbQ.js.map +0 -1
  128. package/dist/client/chunks/chart-config-pie-DlHa2jTy.js.map +0 -1
  129. package/dist/client/chunks/chart-config-radar-BBAVIF0S.js.map +0 -1
  130. package/dist/client/chunks/chart-config-radial-bar-CTwjDRnB.js.map +0 -1
  131. package/dist/client/chunks/chart-config-sankey-CNAgsMQ4.js.map +0 -1
  132. package/dist/client/chunks/chart-config-scatter-CWvN2E-X.js.map +0 -1
  133. package/dist/client/chunks/chart-config-sunburst-W_SKwaj0.js.map +0 -1
  134. package/dist/client/chunks/chart-config-tree-map-IRAYf9YM.js.map +0 -1
  135. package/dist/client/chunks/chart-markdown-Rq6ORisB.js +0 -276
  136. package/dist/client/chunks/chart-markdown-Rq6ORisB.js.map +0 -1
  137. package/dist/client/chunks/chartConfigRegistry-C5dZm-ZK.js +0 -44
  138. package/dist/client/chunks/chartConfigRegistry-C5dZm-ZK.js.map +0 -1
  139. package/dist/client/chunks/charts-loader-m5Ussksz.js.map +0 -1
  140. package/dist/client/chunks/components-D-5p1LVQ.js.map +0 -1
@@ -1,7 +1,11 @@
1
- "use strict";var O=Object.create;var $=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var D=(l,s,b,v)=>{if(s&&typeof s=="object"||typeof s=="function")for(let m of k(s))!L.call(l,m)&&m!==b&&$(l,m,{get:()=>s[m],enumerable:!(v=J(s,m))||v.enumerable});return l};var z=(l,s,b)=>(b=l!=null?O(A(l)):{},D(s||!l||!l.__esModule?$(b,"default",{value:l,enumerable:!0}):b,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../mcp-transport-BqLo4hKi.cjs"),n=require("../utils.cjs"),q=function(s,b,v){const{cubes:m,drizzle:j,schema:I,extractSecurityContext:h,engineType:M,cors:S,basePath:g="/cubejs-api/v1",bodyLimit:f=10485760,cache:N,mcp:R={enabled:!0}}=b;if(!m||m.length===0)return v(new Error("At least one cube must be provided in the cubes array"));S&&s.register(import("@fastify/cors"),S),s.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const d=new i.SemanticLayerCompiler({drizzle:j,schema:I,engineType:M,cache:N});if(m.forEach(r=>{d.registerCube(r)}),s.post(`${g}/load`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,a=await h(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const u=r.headers["x-cache-control"]==="no-cache",p=await d.executeMultiCubeQuery(o,a,{skipCache:u});return n.formatCubeResponse(o,p,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),s.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(n.formatErrorResponse("Invalid JSON in query parameter",400))}const a=await h(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const u=r.headers["x-cache-control"]==="no-cache",p=await d.executeMultiCubeQuery(o,a,{skipCache:u});return n.formatCubeResponse(o,p,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),s.post(`${g}/batch`,{bodyLimit:f,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(n.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).send(n.formatErrorResponse("Queries array cannot be empty",400));const o=await h(r),a=r.headers["x-cache-control"]==="no-cache";return await n.handleBatchRequest(e,o,d,{skipCache:a})}catch(e){return r.log.error(e,"Batch execution error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),s.get(`${g}/meta`,async(r,t)=>{try{const e=d.getMetadata();return n.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),s.post(`${g}/sql`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await h(r),a=d.validateQuery(e);if(!a.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const c=e.measures?.[0]||e.dimensions?.[0];if(!c)return t.status(400).send(n.formatErrorResponse("No measures or dimensions specified",400));const u=c.split(".")[0],p=await d.generateSQL(u,e,o);return n.formatSqlResponse(e,p)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),s.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),a=await h(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const u=o.measures?.[0]||o.dimensions?.[0];if(!u)return t.status(400).send(n.formatErrorResponse("No measures or dimensions specified",400));const p=u.split(".")[0],x=await d.generateSQL(p,o,a);return n.formatSqlResponse(o,x)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),s.post(`${g}/dry-run`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,a=await h(r);return await n.handleDryRun(o,a,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})}}),s.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),a=await h(r);return await n.handleDryRun(o,a,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})}}),s.post(`${g}/explain`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,a=e.options||{},c=await h(r),u=d.validateQuery(o);return u.isValid?await d.explainQuery(o,c,a):t.status(400).send({error:`Query validation failed: ${u.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.enabled!==!1){const r=R.basePath??"/mcp";s.post(`${r}`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(t,e)=>{const o=i.validateOriginHeader(t.headers.origin,R.allowedOrigins?{allowedOrigins:R.allowedOrigins}:{});if(!o.valid)return e.status(403).send(i.buildJsonRpcError(null,-32600,o.reason));const a=t.headers.accept;if(!i.validateAcceptHeader(a))return e.status(400).send(i.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const c=i.negotiateProtocol(t.headers);if(!c.ok)return e.status(426).send({error:"Unsupported MCP protocol version",supported:c.supported});const u=i.parseJsonRpc(t.body);if(!u)return e.status(400).send(i.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const p=i.wantsEventStream(a),x=u.method==="initialize";try{const y=await i.dispatchMcpMethod(u.method,u.params,{semanticLayer:d,extractSecurityContext:h,rawRequest:t,rawResponse:e,negotiatedProtocol:c.negotiated});if(i.isNotification(u))return e.status(202).send();const E=x&&y&&typeof y=="object"&&"sessionId"in y?y.sessionId:void 0;E&&e.header(i.MCP_SESSION_ID_HEADER,E);const C=i.buildJsonRpcResult(u.id??null,y);if(p){const w=i.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${w}
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-KX92EgkF.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-BLcxTuwi.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)}
2
2
 
3
- ${i.serializeSseEvent(C,w)}`);return}return e.send(C)}catch(y){if(i.isNotification(u))return t.log.error(y,"MCP notification processing error"),e.status(202).send();t.log.error(y,"MCP RPC error");const E=y?.code??-32603,C=y?.data,w=y.message||"MCP request failed",P=i.buildJsonRpcError(u.id??null,E,w,C);if(p){const Q=i.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${Q}
3
+ `)}catch(m){const p={type:"error",data:{message:m instanceof Error?m.message:"Stream failed"}};t.raw.write(`data: ${JSON.stringify(p)}
4
4
 
5
- ${i.serializeSseEvent(P,Q)}`);return}return e.send(P)}}),s.get(`${r}`,async(t,e)=>{const o=i.primeEventId();e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),e.raw.write(i.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const a=setInterval(()=>{e.raw.write(`: keep-alive
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}
6
6
 
7
- `)},15e3);t.raw.on("close",()=>{clearInterval(a)})}),s.delete(`${r}`,async(t,e)=>e.status(405).send({error:"Session termination not supported"}))}s.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 n.formatErrorResponse(o,e.statusCode)}),v()};async function H(l,s){await l.register(q,s)}function T(l){const s=require("fastify")({logger:!0});return s.register(q,l),s}exports.createCubeApp=T;exports.cubePlugin=q;exports.registerCubeRoutes=H;
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: ${$}
8
+
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
+
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;
@@ -1,6 +1,7 @@
1
1
  import { FastifyPluginCallback, FastifyRequest, FastifyInstance } from 'fastify';
2
2
  import { FastifyCorsOptions } from '@fastify/cors';
3
3
  import { SemanticQuery, SecurityContext, DatabaseExecutor, DrizzleDatabase, Cube, CacheConfig } from '../../server';
4
+ import { AgentConfig } from '../../server/agent/types';
4
5
  import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
5
6
  import { MySql2Database } from 'drizzle-orm/mysql2';
6
7
  import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
@@ -72,6 +73,12 @@ export interface FastifyAdapterOptions {
72
73
  * @default { enabled: true }
73
74
  */
74
75
  mcp?: MCPOptions;
76
+ /**
77
+ * Agent configuration for the agentic AI notebook feature.
78
+ * When provided, enables the POST /agent/chat SSE endpoint.
79
+ * Requires `@anthropic-ai/sdk` as a peer dependency.
80
+ */
81
+ agent?: AgentConfig;
75
82
  }
76
83
  /**
77
84
  * Fastify plugin for Cube.js-compatible API