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.
- package/dist/adapters/express/index.cjs +8 -4
- package/dist/adapters/express/index.d.ts +7 -0
- package/dist/adapters/express/index.js +189 -139
- package/dist/adapters/fastify/index.cjs +8 -4
- package/dist/adapters/fastify/index.d.ts +7 -0
- package/dist/adapters/fastify/index.js +209 -150
- package/dist/adapters/handler-BLcxTuwi.cjs +23 -0
- package/dist/adapters/handler-odjn7MIB.js +1880 -0
- package/dist/adapters/hono/index.cjs +8 -4
- package/dist/adapters/hono/index.d.ts +7 -0
- package/dist/adapters/hono/index.js +202 -144
- package/dist/adapters/{mcp-transport-YHDZWKOi.js → mcp-transport-CU5g9bxj.js} +7 -3
- package/dist/adapters/{mcp-transport-BqLo4hKi.cjs → mcp-transport-KX92EgkF.cjs} +21 -21
- package/dist/adapters/nextjs/index.cjs +7 -3
- package/dist/adapters/nextjs/index.d.ts +14 -0
- package/dist/adapters/nextjs/index.js +220 -144
- package/dist/client/charts/chartConfigs.d.ts +2 -9
- package/dist/client/charts.js +72 -70
- package/dist/client/charts.js.map +1 -1
- package/dist/client/chunks/{RetentionCombinedChart.config-C-ILIaEb.js → RetentionCombinedChart.config-Bbp2ghim.js} +2 -1
- package/dist/client/chunks/RetentionCombinedChart.config-Bbp2ghim.js.map +1 -0
- package/dist/client/chunks/{RetentionHeatmap.config-CIvhc-GT.js → RetentionHeatmap.config-BWf_-vdj.js} +2 -1
- package/dist/client/chunks/RetentionHeatmap.config-BWf_-vdj.js.map +1 -0
- package/dist/client/chunks/{analysis-builder-CG5VIMYB.js → analysis-builder-Bov_gLsf.js} +1408 -1393
- package/dist/client/chunks/analysis-builder-Bov_gLsf.js.map +1 -0
- package/dist/client/chunks/{analysis-builder-shared-CjlKJgyA.js → analysis-builder-shared-NBk6y0md.js} +3 -3
- package/dist/client/chunks/{analysis-builder-shared-CjlKJgyA.js.map → analysis-builder-shared-NBk6y0md.js.map} +1 -1
- package/dist/client/chunks/{chart-activity-grid-DStNr34n.js → chart-activity-grid-CE7xGFQo.js} +2 -2
- package/dist/client/chunks/{chart-activity-grid-DStNr34n.js.map → chart-activity-grid-CE7xGFQo.js.map} +1 -1
- package/dist/client/chunks/chart-box-plot-Dja4LS3O.js +313 -0
- package/dist/client/chunks/chart-box-plot-Dja4LS3O.js.map +1 -0
- package/dist/client/chunks/{chart-config-activity-grid-CAlo1cHA.js → chart-config-activity-grid-CmOqDuOT.js} +4 -5
- package/dist/client/chunks/chart-config-activity-grid-CmOqDuOT.js.map +1 -0
- package/dist/client/chunks/{chart-config-area-CyyJOO2T.js → chart-config-area-CK_GVApT.js} +4 -5
- package/dist/client/chunks/chart-config-area-CK_GVApT.js.map +1 -0
- package/dist/client/chunks/{chart-config-bar-soxw6m2o.js → chart-config-bar-C8uzktxl.js} +4 -5
- package/dist/client/chunks/chart-config-bar-C8uzktxl.js.map +1 -0
- package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js +85 -0
- package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js.map +1 -0
- package/dist/client/chunks/{chart-config-bubble-CuSsCHZ4.js → chart-config-bubble-q3DoQX5F.js} +4 -5
- package/dist/client/chunks/chart-config-bubble-q3DoQX5F.js.map +1 -0
- package/dist/client/chunks/{chart-config-data-table-BhgqwoqT.js → chart-config-data-table-B20Y5JCm.js} +4 -5
- package/dist/client/chunks/chart-config-data-table-B20Y5JCm.js.map +1 -0
- package/dist/client/chunks/{chart-config-funnel-BlSQYng0.js → chart-config-funnel-3eYnGg8M.js} +4 -5
- package/dist/client/chunks/chart-config-funnel-3eYnGg8M.js.map +1 -0
- package/dist/client/chunks/{chart-config-heat-map-DHQGFZhX.js → chart-config-heat-map-_wEnTnRA.js} +4 -5
- package/dist/client/chunks/chart-config-heat-map-_wEnTnRA.js.map +1 -0
- package/dist/client/chunks/{chart-config-kpi-delta-yTA5ug_l.js → chart-config-kpi-delta-DLGZ2A3X.js} +4 -5
- package/dist/client/chunks/chart-config-kpi-delta-DLGZ2A3X.js.map +1 -0
- package/dist/client/chunks/{chart-config-kpi-number-nVAwDXzq.js → chart-config-kpi-number-K-wzviXF.js} +4 -5
- package/dist/client/chunks/chart-config-kpi-number-K-wzviXF.js.map +1 -0
- package/dist/client/chunks/{chart-config-kpi-text-DZjqsx-b.js → chart-config-kpi-text-BjYqwqaJ.js} +4 -5
- package/dist/client/chunks/chart-config-kpi-text-BjYqwqaJ.js.map +1 -0
- package/dist/client/chunks/{chart-config-line-D5ME6w0v.js → chart-config-line-JNagi9tf.js} +4 -5
- package/dist/client/chunks/chart-config-line-JNagi9tf.js.map +1 -0
- package/dist/client/chunks/{chart-config-markdown-BXKL5TbQ.js → chart-config-markdown-BWQSjJpy.js} +4 -5
- package/dist/client/chunks/chart-config-markdown-BWQSjJpy.js.map +1 -0
- package/dist/client/chunks/{chart-config-pie-DlHa2jTy.js → chart-config-pie-CNLXb-fr.js} +4 -5
- package/dist/client/chunks/chart-config-pie-CNLXb-fr.js.map +1 -0
- package/dist/client/chunks/{chart-config-radar-BBAVIF0S.js → chart-config-radar-oxHfRAa3.js} +4 -5
- package/dist/client/chunks/chart-config-radar-oxHfRAa3.js.map +1 -0
- package/dist/client/chunks/{chart-config-radial-bar-CTwjDRnB.js → chart-config-radial-bar-_Aw3jAEm.js} +4 -5
- package/dist/client/chunks/chart-config-radial-bar-_Aw3jAEm.js.map +1 -0
- package/dist/client/chunks/{chart-config-sankey-CNAgsMQ4.js → chart-config-sankey-C8FX9hGF.js} +4 -5
- package/dist/client/chunks/chart-config-sankey-C8FX9hGF.js.map +1 -0
- package/dist/client/chunks/{chart-config-scatter-CWvN2E-X.js → chart-config-scatter-DFKM80eO.js} +4 -5
- package/dist/client/chunks/chart-config-scatter-DFKM80eO.js.map +1 -0
- package/dist/client/chunks/{chart-config-sunburst-W_SKwaj0.js → chart-config-sunburst-BmC0NLTU.js} +4 -5
- package/dist/client/chunks/chart-config-sunburst-BmC0NLTU.js.map +1 -0
- package/dist/client/chunks/{chart-config-tree-map-IRAYf9YM.js → chart-config-tree-map-DGMbNTaa.js} +4 -5
- package/dist/client/chunks/chart-config-tree-map-DGMbNTaa.js.map +1 -0
- package/dist/client/chunks/{chart-data-table-Ch_1c1Zo.js → chart-data-table-Ba_6tuJw.js} +2 -2
- package/dist/client/chunks/{chart-data-table-Ch_1c1Zo.js.map → chart-data-table-Ba_6tuJw.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-delta-CWCmi8vL.js → chart-kpi-delta-D9XJoKuA.js} +3 -3
- package/dist/client/chunks/{chart-kpi-delta-CWCmi8vL.js.map → chart-kpi-delta-D9XJoKuA.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-number-C-5m3qt5.js → chart-kpi-number-C29Vj2g8.js} +2 -2
- package/dist/client/chunks/{chart-kpi-number-C-5m3qt5.js.map → chart-kpi-number-C29Vj2g8.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-text--t4ibPmx.js → chart-kpi-text-CgjjrurK.js} +2 -2
- package/dist/client/chunks/{chart-kpi-text--t4ibPmx.js.map → chart-kpi-text-CgjjrurK.js.map} +1 -1
- package/dist/client/chunks/chart-markdown-Du4Z2iqK.js +2695 -0
- package/dist/client/chunks/chart-markdown-Du4Z2iqK.js.map +1 -0
- package/dist/client/chunks/{charts-loader-m5Ussksz.js → charts-loader-HYQFVOo4.js} +14 -13
- package/dist/client/chunks/charts-loader-HYQFVOo4.js.map +1 -0
- package/dist/client/chunks/{components-D-5p1LVQ.js → components-O0hh7ooo.js} +6 -6
- package/dist/client/chunks/components-O0hh7ooo.js.map +1 -0
- package/dist/client/chunks/{icons-DRreo6m8.js → icons-DAeqv1iX.js} +7 -7
- package/dist/client/chunks/{icons-DRreo6m8.js.map → icons-DAeqv1iX.js.map} +1 -1
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +8 -0
- package/dist/client/components/AgenticNotebook/ChatInput.d.ts +14 -0
- package/dist/client/components/AgenticNotebook/ChatMessage.d.ts +7 -0
- package/dist/client/components/AgenticNotebook/NotebookCanvas.d.ts +3 -0
- package/dist/client/components/AgenticNotebook/NotebookMarkdownBlock.d.ts +12 -0
- package/dist/client/components/AgenticNotebook/NotebookPortletBlock.d.ts +12 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +34 -0
- package/dist/client/components/charts/BoxPlotChart.config.d.ts +11 -0
- package/dist/client/components/charts/BoxPlotChart.d.ts +4 -0
- package/dist/client/components/charts/index.d.ts +1 -0
- package/dist/client/components.js +1 -1
- package/dist/client/hooks/useAgentChat.d.ts +36 -0
- package/dist/client/icons.js +1 -1
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +923 -187
- package/dist/client/index.js.map +1 -1
- package/dist/client/stores/notebookStore.d.ts +152 -0
- package/dist/client/styles.css +1 -1
- package/dist/client/types.d.ts +1 -1
- package/dist/client/utils.js +3 -3
- package/dist/client-bundle-stats.html +4 -4
- package/dist/server/index.cjs +116 -90
- package/dist/server/index.d.ts +155 -0
- package/dist/server/index.js +7088 -4852
- package/package.json +12 -6
- package/dist/client/chunks/RetentionCombinedChart.config-C-ILIaEb.js.map +0 -1
- package/dist/client/chunks/RetentionHeatmap.config-CIvhc-GT.js.map +0 -1
- package/dist/client/chunks/analysis-builder-CG5VIMYB.js.map +0 -1
- package/dist/client/chunks/chart-config-activity-grid-CAlo1cHA.js.map +0 -1
- package/dist/client/chunks/chart-config-area-CyyJOO2T.js.map +0 -1
- package/dist/client/chunks/chart-config-bar-soxw6m2o.js.map +0 -1
- package/dist/client/chunks/chart-config-bubble-CuSsCHZ4.js.map +0 -1
- package/dist/client/chunks/chart-config-data-table-BhgqwoqT.js.map +0 -1
- package/dist/client/chunks/chart-config-funnel-BlSQYng0.js.map +0 -1
- package/dist/client/chunks/chart-config-heat-map-DHQGFZhX.js.map +0 -1
- package/dist/client/chunks/chart-config-kpi-delta-yTA5ug_l.js.map +0 -1
- package/dist/client/chunks/chart-config-kpi-number-nVAwDXzq.js.map +0 -1
- package/dist/client/chunks/chart-config-kpi-text-DZjqsx-b.js.map +0 -1
- package/dist/client/chunks/chart-config-line-D5ME6w0v.js.map +0 -1
- package/dist/client/chunks/chart-config-markdown-BXKL5TbQ.js.map +0 -1
- package/dist/client/chunks/chart-config-pie-DlHa2jTy.js.map +0 -1
- package/dist/client/chunks/chart-config-radar-BBAVIF0S.js.map +0 -1
- package/dist/client/chunks/chart-config-radial-bar-CTwjDRnB.js.map +0 -1
- package/dist/client/chunks/chart-config-sankey-CNAgsMQ4.js.map +0 -1
- package/dist/client/chunks/chart-config-scatter-CWvN2E-X.js.map +0 -1
- package/dist/client/chunks/chart-config-sunburst-W_SKwaj0.js.map +0 -1
- package/dist/client/chunks/chart-config-tree-map-IRAYf9YM.js.map +0 -1
- package/dist/client/chunks/chart-markdown-Rq6ORisB.js +0 -276
- package/dist/client/chunks/chart-markdown-Rq6ORisB.js.map +0 -1
- package/dist/client/chunks/chartConfigRegistry-C5dZm-ZK.js +0 -44
- package/dist/client/chunks/chartConfigRegistry-C5dZm-ZK.js.map +0 -1
- package/dist/client/chunks/charts-loader-m5Ussksz.js.map +0 -1
- package/dist/client/chunks/components-D-5p1LVQ.js.map +0 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("next/server"),l=require("../mcp-transport-BqLo4hKi.cjs"),c=require("../utils.cjs");function R(n){const{cubes:o,drizzle:s,schema:i,engineType:d,cache:a}=n;if(!o||o.length===0)throw new Error("At least one cube must be provided in the cubes array");const t=new l.SemanticLayerCompiler({drizzle:s,schema:i,engineType:d,cache:a});return o.forEach(e=>{t.registerCube(e)}),t}function h(n,o){const s=n.headers.get("origin"),i={};return o.origin&&(typeof o.origin=="string"?i["Access-Control-Allow-Origin"]=o.origin:Array.isArray(o.origin)?s&&o.origin.includes(s)&&(i["Access-Control-Allow-Origin"]=s):typeof o.origin=="function"&&s&&o.origin(s)&&(i["Access-Control-Allow-Origin"]=s)),o.methods&&(i["Access-Control-Allow-Methods"]=o.methods.join(", ")),o.allowedHeaders&&(i["Access-Control-Allow-Headers"]=o.allowedHeaders.join(", ")),o.credentials&&(i["Access-Control-Allow-Credentials"]="true"),i}function I(n){return async function(s){const i=h(s,n);return new Response(null,{status:200,headers:i})}}function M(n){const{extractSecurityContext:o,cors:s}=n,i=R(n);return async function(a,t){try{let e;if(a.method==="POST"){const N=await a.json();e=N.query||N}else if(a.method==="GET"){const N=a.nextUrl.searchParams.get("query");if(!N)return r.NextResponse.json(c.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(N)}catch{return r.NextResponse.json(c.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(c.formatErrorResponse("Method not allowed",405),{status:405});const u=await o(a,t),m=i.validateQuery(e);if(!m.isValid)return r.NextResponse.json(c.formatErrorResponse(`Query validation failed: ${m.errors.join(", ")}`,400),{status:400});const p=a.headers.get("x-cache-control")==="no-cache",f=await i.executeMultiCubeQuery(e,u,{skipCache:p}),j=c.formatCubeResponse(e,f,i);return r.NextResponse.json(j,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js load handler error:",e),r.NextResponse.json(c.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function T(n){const{cors:o}=n,s=R(n);return async function(d,a){try{const t=s.getMetadata(),e=c.formatMetaResponse(t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js meta handler error:",t),r.NextResponse.json(c.formatErrorResponse(t instanceof Error?t.message:"Failed to fetch metadata",500),{status:500})}}}function L(n){const{extractSecurityContext:o,cors:s}=n,i=R(n);return async function(a,t){try{let e;if(a.method==="POST"){const w=await a.json();e=w.query||w}else if(a.method==="GET"){const w=a.nextUrl.searchParams.get("query");if(!w)return r.NextResponse.json(c.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(w)}catch{return r.NextResponse.json(c.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(c.formatErrorResponse("Method not allowed",405),{status:405});const u=await o(a,t),m=i.validateQuery(e);if(!m.isValid)return r.NextResponse.json(c.formatErrorResponse(`Query validation failed: ${m.errors.join(", ")}`,400),{status:400});const p=e.measures?.[0]||e.dimensions?.[0];if(!p)return r.NextResponse.json(c.formatErrorResponse("No measures or dimensions specified",400),{status:400});const f=p.split(".")[0],j=await i.generateSQL(f,e,u),N=c.formatSqlResponse(e,j);return r.NextResponse.json(N,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js SQL handler error:",e),r.NextResponse.json(c.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500),{status:500})}}}function D(n){const{extractSecurityContext:o,cors:s}=n,i=R(n);return async function(a,t){try{let e;if(a.method==="POST"){const p=await a.json();e=p.query||p}else if(a.method==="GET"){const p=a.nextUrl.searchParams.get("query");if(!p)return r.NextResponse.json({error:"Query parameter is required",valid:!1},{status:400});try{e=JSON.parse(p)}catch{return r.NextResponse.json({error:"Invalid JSON in query parameter",valid:!1},{status:400})}}else return r.NextResponse.json({error:"Method not allowed",valid:!1},{status:405});const u=await o(a,t),m=await c.handleDryRun(e,u,i);return r.NextResponse.json(m,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js dry-run handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},{status:400})}}}function A(n){const{extractSecurityContext:o,cors:s}=n,i=R(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(c.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json(),{queries:u}=e;if(!u||!Array.isArray(u))return r.NextResponse.json(c.formatErrorResponse('Request body must contain a "queries" array',400),{status:400});if(u.length===0)return r.NextResponse.json(c.formatErrorResponse("Queries array cannot be empty",400),{status:400});const m=await o(a,t),p=a.headers.get("x-cache-control")==="no-cache",f=await c.handleBatchRequest(u,m,i,{skipCache:p});return r.NextResponse.json(f,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js batch handler error:",e),r.NextResponse.json(c.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500),{status:500})}}}function Q(n){const{extractSecurityContext:o,cors:s}=n,i=R(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json({error:"Method not allowed"},{status:405});const e=await a.json(),u=e.query||e,m=e.options||{},p=await o(a,t),f=i.validateQuery(u);if(!f.isValid)return r.NextResponse.json({error:`Query validation failed: ${f.errors.join(", ")}`},{status:400});const j=await i.explainQuery(u,p,m);return r.NextResponse.json(j,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js explain handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Explain query failed"},{status:500})}}}function J(n){const{cors:o}=n,s=R(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(c.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json(),e=await c.handleDiscover(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js discover handler error:",t),r.NextResponse.json(c.formatErrorResponse(t instanceof Error?t.message:"Discovery failed",500),{status:500})}}}function q(n){const{cors:o}=n,s=R(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(c.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.naturalLanguage)return r.NextResponse.json(c.formatErrorResponse("naturalLanguage field is required",400),{status:400});const e=await c.handleSuggest(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js suggest handler error:",t),r.NextResponse.json(c.formatErrorResponse(t instanceof Error?t.message:"Query suggestion failed",500),{status:500})}}}function z(n){const{cors:o}=n,s=R(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(c.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.query)return r.NextResponse.json(c.formatErrorResponse("query field is required",400),{status:400});const e=await c.handleValidate(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js validate handler error:",t),r.NextResponse.json(c.formatErrorResponse(t instanceof Error?t.message:"Query validation failed",500),{status:500})}}}function k(n){const{extractSecurityContext:o,cors:s}=n,i=R(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(c.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json();if(!e.query)return r.NextResponse.json(c.formatErrorResponse("query field is required",400),{status:400});const u=await o(a,t),m=await c.handleLoad(i,u,e);return r.NextResponse.json(m,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP load handler error:",e),r.NextResponse.json(c.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function V(n){const{extractSecurityContext:o,cors:s,mcp:i={enabled:!0}}=n,d=R(n);return async function(t){if(t.method==="DELETE")return r.NextResponse.json({error:"Session termination not supported"},{status:405});if(t.method==="GET"){const y=new TextEncoder,g=l.primeEventId(),E=new ReadableStream({start(x){x.enqueue(y.encode(l.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},g,15e3)))}}),S=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const x=h(t,s);Object.entries(x).forEach(([H,b])=>S.set(H,b))}return new r.NextResponse(E,{status:200,headers:S})}if(t.method!=="POST")return r.NextResponse.json(c.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=l.validateOriginHeader(t.headers.get("origin"),i.allowedOrigins?{allowedOrigins:i.allowedOrigins}:{});if(!e.valid)return r.NextResponse.json(l.buildJsonRpcError(null,-32600,e.reason),{status:403});const u=t.headers.get("accept");if(!l.validateAcceptHeader(u))return r.NextResponse.json(l.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),{status:400});const m=l.negotiateProtocol(Object.fromEntries(t.headers.entries()));if(!m.ok)return r.NextResponse.json({error:"Unsupported MCP protocol version",supported:m.supported},{status:426});let p=null;try{p=await t.json()}catch{p=null}const f=l.parseJsonRpc(p);if(!f)return r.NextResponse.json(l.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),{status:400});const j=l.wantsEventStream(u),N=f.method==="initialize",w=(y,g=200,E={})=>r.NextResponse.json(y,{status:g,headers:{...s?h(t,s):{},...E}});try{const y=await l.dispatchMcpMethod(f.method,f.params,{semanticLayer:d,extractSecurityContext:x=>o(x),rawRequest:t,rawResponse:null});if(l.isNotification(f))return new r.NextResponse(null,{status:202});const g=N&&y&&typeof y=="object"&&"sessionId"in y?y.sessionId:void 0,E={};g&&(E[l.MCP_SESSION_ID_HEADER]=g);const S=l.buildJsonRpcResult(f.id??null,y);if(j){const x=new TextEncoder,H=l.primeEventId(),b=new ReadableStream({start(v){v.enqueue(x.encode(`id: ${H}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("next/server"),f=require("../mcp-transport-KX92EgkF.cjs"),i=require("../utils.cjs");function g(n){const{cubes:o,drizzle:s,schema:c,engineType:d,cache:a}=n;if(!o||o.length===0)throw new Error("At least one cube must be provided in the cubes array");const t=new f.SemanticLayerCompiler({drizzle:s,schema:c,engineType:d,cache:a});return o.forEach(e=>{t.registerCube(e)}),t}function R(n,o){const s=n.headers.get("origin"),c={};return o.origin&&(typeof o.origin=="string"?c["Access-Control-Allow-Origin"]=o.origin:Array.isArray(o.origin)?s&&o.origin.includes(s)&&(c["Access-Control-Allow-Origin"]=s):typeof o.origin=="function"&&s&&o.origin(s)&&(c["Access-Control-Allow-Origin"]=s)),o.methods&&(c["Access-Control-Allow-Methods"]=o.methods.join(", ")),o.allowedHeaders&&(c["Access-Control-Allow-Headers"]=o.allowedHeaders.join(", ")),o.credentials&&(c["Access-Control-Allow-Credentials"]="true"),c}function J(n){return async function(s){const c=R(s,n);return new Response(null,{status:200,headers:c})}}function T(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{let e;if(a.method==="POST"){const j=await a.json();e=j.query||j}else if(a.method==="GET"){const j=a.nextUrl.searchParams.get("query");if(!j)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(j)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=a.headers.get("x-cache-control")==="no-cache",p=await c.executeMultiCubeQuery(e,l,{skipCache:u}),E=i.formatCubeResponse(e,p,c);return r.NextResponse.json(E,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function M(n){const{cors:o}=n,s=g(n);return async function(d,a){try{const t=s.getMetadata(),e=i.formatMetaResponse(t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js meta handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Failed to fetch metadata",500),{status:500})}}}function A(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{let e;if(a.method==="POST"){const w=await a.json();e=w.query||w}else if(a.method==="GET"){const w=a.nextUrl.searchParams.get("query");if(!w)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(w)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=e.measures?.[0]||e.dimensions?.[0];if(!u)return r.NextResponse.json(i.formatErrorResponse("No measures or dimensions specified",400),{status:400});const p=u.split(".")[0],E=await c.generateSQL(p,e,l),j=i.formatSqlResponse(e,E);return r.NextResponse.json(j,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js SQL handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500),{status:500})}}}function L(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{let e;if(a.method==="POST"){const u=await a.json();e=u.query||u}else if(a.method==="GET"){const u=a.nextUrl.searchParams.get("query");if(!u)return r.NextResponse.json({error:"Query parameter is required",valid:!1},{status:400});try{e=JSON.parse(u)}catch{return r.NextResponse.json({error:"Invalid JSON in query parameter",valid:!1},{status:400})}}else return r.NextResponse.json({error:"Method not allowed",valid:!1},{status:405});const l=await o(a,t),y=await i.handleDryRun(e,l,c);return r.NextResponse.json(y,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js dry-run handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},{status:400})}}}function D(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json(),{queries:l}=e;if(!l||!Array.isArray(l))return r.NextResponse.json(i.formatErrorResponse('Request body must contain a "queries" array',400),{status:400});if(l.length===0)return r.NextResponse.json(i.formatErrorResponse("Queries array cannot be empty",400),{status:400});const y=await o(a,t),u=a.headers.get("x-cache-control")==="no-cache",p=await i.handleBatchRequest(l,y,c,{skipCache:u});return r.NextResponse.json(p,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js batch handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500),{status:500})}}}function V(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json({error:"Method not allowed"},{status:405});const e=await a.json(),l=e.query||e,y=e.options||{},u=await o(a,t),p=c.validateQuery(l);if(!p.isValid)return r.NextResponse.json({error:`Query validation failed: ${p.errors.join(", ")}`},{status:400});const E=await c.explainQuery(l,u,y);return r.NextResponse.json(E,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js explain handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Explain query failed"},{status:500})}}}function k(n){const{cors:o}=n,s=g(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json(),e=await i.handleDiscover(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js discover handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Discovery failed",500),{status:500})}}}function q(n){const{cors:o}=n,s=g(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.naturalLanguage)return r.NextResponse.json(i.formatErrorResponse("naturalLanguage field is required",400),{status:400});const e=await i.handleSuggest(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js suggest handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query suggestion failed",500),{status:500})}}}function z(n){const{cors:o}=n,s=g(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const e=await i.handleValidate(s,t);return r.NextResponse.json(e,{headers:o?R(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js validate handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query validation failed",500),{status:500})}}}function $(n){const{extractSecurityContext:o,cors:s}=n,c=g(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json();if(!e.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const l=await o(a,t),y=await i.handleLoad(c,l,e);return r.NextResponse.json(y,{headers:s?R(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function _(n){const{extractSecurityContext:o,cors:s,mcp:c={enabled:!0}}=n,d=g(n);return async function(t){if(t.method==="DELETE")return r.NextResponse.json({error:"Session termination not supported"},{status:405});if(t.method==="GET"){const h=new TextEncoder,v=f.primeEventId(),m=new ReadableStream({start(x){x.enqueue(h.encode(f.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},v,15e3)))}}),N=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const x=R(t,s);Object.entries(x).forEach(([C,b])=>N.set(C,b))}return new r.NextResponse(m,{status:200,headers:N})}if(t.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=f.validateOriginHeader(t.headers.get("origin"),c.allowedOrigins?{allowedOrigins:c.allowedOrigins}:{});if(!e.valid)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,e.reason),{status:403});const l=t.headers.get("accept");if(!f.validateAcceptHeader(l))return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),{status:400});const y=f.negotiateProtocol(Object.fromEntries(t.headers.entries()));if(!y.ok)return r.NextResponse.json({error:"Unsupported MCP protocol version",supported:y.supported},{status:426});let u;try{u=await t.json()}catch{u=null}const p=f.parseJsonRpc(u);if(!p)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),{status:400});const E=f.wantsEventStream(l),j=p.method==="initialize",w=(h,v=200,m={})=>r.NextResponse.json(h,{status:v,headers:{...s?R(t,s):{},...m}});try{const h=await f.dispatchMcpMethod(p.method,p.params,{semanticLayer:d,extractSecurityContext:x=>o(x),rawRequest:t,rawResponse:null});if(f.isNotification(p))return new r.NextResponse(null,{status:202});const v=j&&h&&typeof h=="object"&&"sessionId"in h?h.sessionId:void 0,m={};v&&(m[f.MCP_SESSION_ID_HEADER]=v);const N=f.buildJsonRpcResult(p.id??null,h);if(E){const x=new TextEncoder,C=f.primeEventId(),b=new ReadableStream({start(S){S.enqueue(x.encode(`id: ${C}
|
|
2
2
|
|
|
3
|
-
`)),
|
|
3
|
+
`)),S.enqueue(x.encode(f.serializeSseEvent(N,C))),S.close()}}),O=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...m});if(s){const S=R(t,s);Object.entries(S).forEach(([H,P])=>O.set(H,P))}return new r.NextResponse(b,{status:200,headers:O})}return w(N,200,m)}catch(h){if(f.isNotification(p))return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP notification processing error:",h),new r.NextResponse(null,{status:202});process.env.NODE_ENV!=="test"&&console.error("Next.js MCP RPC handler error:",h);const v=h?.code??-32603,m=h?.data,N=h.message||"MCP request failed",x=f.buildJsonRpcError(p.id??null,v,N,m);if(E){const C=new TextEncoder,b=f.primeEventId(),O=new ReadableStream({start(H){H.enqueue(C.encode(`id: ${b}
|
|
4
4
|
|
|
5
|
-
`)),
|
|
5
|
+
`)),H.enqueue(C.encode(f.serializeSseEvent(x,b))),H.close()}}),S=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const H=R(t,s);Object.entries(H).forEach(([P,I])=>S.set(P,I))}return new r.NextResponse(O,{status:200,headers:S})}return w(x,200)}}}function Q(n){const{extractSecurityContext:o,cors:s,agent:c}=n;if(!c)throw new Error("agent config is required for createAgentChatHandler");const d=g(n);return async function(t,e){try{if(t.method!=="POST")return r.NextResponse.json({error:"Method not allowed - use POST"},{status:405});const{handleAgentChat:l}=await Promise.resolve().then(()=>require("../handler-BLcxTuwi.cjs")),y=await t.json(),{message:u,sessionId:p}=y;if(!u||typeof u!="string")return r.NextResponse.json({error:"message is required and must be a string"},{status:400});let E=(c.apiKey||"").trim();if(c.allowClientApiKey){const m=t.headers.get("x-agent-api-key");m&&(E=m.trim())}if(!E)return r.NextResponse.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},{status:401});const j=await o(t,e),w=new TextEncoder,h=new ReadableStream({async start(m){try{const N=l({message:u,sessionId:p,semanticLayer:d,securityContext:j,agentConfig:c,apiKey:E});for await(const x of N){const C=`data: ${JSON.stringify(x)}
|
|
6
|
+
|
|
7
|
+
`;m.enqueue(w.encode(C))}}catch(N){const x={type:"error",data:{message:N instanceof Error?N.message:"Stream failed"}};m.enqueue(w.encode(`data: ${JSON.stringify(x)}
|
|
8
|
+
|
|
9
|
+
`))}finally{m.close()}}}),v=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const m=R(t,s);Object.entries(m).forEach(([N,x])=>v.set(N,x))}return new Response(h,{status:200,headers:v})}catch(l){return process.env.NODE_ENV!=="test"&&console.error("Next.js agent chat handler error:",l),r.NextResponse.json({error:l instanceof Error?l.message:"Agent chat failed"},{status:500})}}}function K(n){const{mcp:o={enabled:!0}}=n,s={load:T(n),meta:M(n),sql:A(n),dryRun:L(n),batch:D(n),explain:V(n)};return o.enabled!==!1&&(s.mcpRpc=_(n)),n.agent&&(s.agentChat=Q(n)),s}exports.createAgentChatHandler=Q;exports.createBatchHandler=D;exports.createCubeHandlers=K;exports.createDiscoverHandler=k;exports.createDryRunHandler=L;exports.createExplainHandler=V;exports.createLoadHandler=T;exports.createMcpLoadHandler=$;exports.createMcpRpcHandler=_;exports.createMetaHandler=M;exports.createOptionsHandler=J;exports.createSqlHandler=A;exports.createSuggestHandler=q;exports.createValidateHandler=z;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
import { SemanticQuery, SecurityContext, DatabaseExecutor, DrizzleDatabase, Cube, CacheConfig } from '../../server';
|
|
3
|
+
import { AgentConfig } from '../../server/agent/types';
|
|
3
4
|
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
4
5
|
import { MySql2Database } from 'drizzle-orm/mysql2';
|
|
5
6
|
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
@@ -87,6 +88,12 @@ export interface NextAdapterOptions {
|
|
|
87
88
|
* @default { enabled: true }
|
|
88
89
|
*/
|
|
89
90
|
mcp?: MCPOptions;
|
|
91
|
+
/**
|
|
92
|
+
* Agent configuration for the agentic AI notebook feature.
|
|
93
|
+
* When provided, enables the POST /agent/chat SSE endpoint.
|
|
94
|
+
* Requires `@anthropic-ai/sdk` as a peer dependency.
|
|
95
|
+
*/
|
|
96
|
+
agent?: AgentConfig;
|
|
90
97
|
}
|
|
91
98
|
export interface RouteContext {
|
|
92
99
|
params?: Record<string, string | string[]>;
|
|
@@ -100,6 +107,7 @@ export interface CubeHandlers {
|
|
|
100
107
|
batch: RouteHandler;
|
|
101
108
|
explain: RouteHandler;
|
|
102
109
|
mcpRpc?: RouteHandler;
|
|
110
|
+
agentChat?: RouteHandler;
|
|
103
111
|
}
|
|
104
112
|
/**
|
|
105
113
|
* Create OPTIONS handler for CORS preflight requests
|
|
@@ -153,6 +161,12 @@ export declare function createMcpLoadHandler(options: NextAdapterOptions): Route
|
|
|
153
161
|
* Implements MCP 2025-11-25 spec
|
|
154
162
|
*/
|
|
155
163
|
export declare function createMcpRpcHandler(options: NextAdapterOptions): RouteHandler;
|
|
164
|
+
/**
|
|
165
|
+
* Create agent chat handler - Agentic AI notebook chat
|
|
166
|
+
* Streams SSE events as the agent discovers data, executes queries,
|
|
167
|
+
* and creates visualizations.
|
|
168
|
+
*/
|
|
169
|
+
export declare function createAgentChatHandler(options: NextAdapterOptions): RouteHandler;
|
|
156
170
|
/**
|
|
157
171
|
* Convenience function to create all route handlers
|
|
158
172
|
*
|