drizzle-cube 0.4.11 → 0.4.14
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/README.md +1 -0
- package/dist/adapters/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +73 -72
- package/dist/adapters/fastify/index.cjs +5 -5
- package/dist/adapters/fastify/index.js +110 -109
- package/dist/adapters/{handler-CQkIwtxp.js → handler-DZnCbydH.js} +719 -272
- package/dist/adapters/handler-ZDYlokiM.cjs +25 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +121 -120
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +92 -91
- package/dist/client/charts.js +67 -59
- package/dist/client/charts.js.map +1 -1
- package/dist/client/chunks/{RetentionCombinedChart-CEI8KQ3t.js → RetentionCombinedChart-CLq89aOJ.js} +2 -2
- package/dist/client/chunks/{RetentionCombinedChart-CEI8KQ3t.js.map → RetentionCombinedChart-CLq89aOJ.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-BMmWeFPr.js → analysis-builder-C5e52Z3p.js} +419 -411
- package/dist/client/chunks/analysis-builder-C5e52Z3p.js.map +1 -0
- package/dist/client/chunks/{analysis-builder-shared-D56zYeV0.js → analysis-builder-shared-EnM-8plh.js} +2 -2
- package/dist/client/chunks/{analysis-builder-shared-D56zYeV0.js.map → analysis-builder-shared-EnM-8plh.js.map} +1 -1
- package/dist/client/chunks/{chart-activity-grid-CE7xGFQo.js → chart-activity-grid-CPGcTSuh.js} +2 -2
- package/dist/client/chunks/{chart-activity-grid-CE7xGFQo.js.map → chart-activity-grid-CPGcTSuh.js.map} +1 -1
- package/dist/client/chunks/{chart-area-BJAgusst.js → chart-area-ByJQ7NZd.js} +3 -3
- package/dist/client/chunks/{chart-area-BJAgusst.js.map → chart-area-ByJQ7NZd.js.map} +1 -1
- package/dist/client/chunks/{chart-bar-Blypx8O4.js → chart-bar-dj14frMt.js} +2 -2
- package/dist/client/chunks/{chart-bar-Blypx8O4.js.map → chart-bar-dj14frMt.js.map} +1 -1
- package/dist/client/chunks/chart-box-plot-ZatBpatq.js +322 -0
- package/dist/client/chunks/chart-box-plot-ZatBpatq.js.map +1 -0
- package/dist/client/chunks/{chart-bubble-Bf42A1-B.js → chart-bubble-CemotLx-.js} +2 -2
- package/dist/client/chunks/{chart-bubble-Bf42A1-B.js.map → chart-bubble-CemotLx-.js.map} +1 -1
- package/dist/client/chunks/chart-candlestick-BIR4uGGt.js +269 -0
- package/dist/client/chunks/chart-candlestick-BIR4uGGt.js.map +1 -0
- package/dist/client/chunks/chart-config-box-plot-D_E_SSc2.js +38 -0
- package/dist/client/chunks/chart-config-box-plot-D_E_SSc2.js.map +1 -0
- package/dist/client/chunks/chart-config-candlestick-CRCpD43-.js +70 -0
- package/dist/client/chunks/chart-config-candlestick-CRCpD43-.js.map +1 -0
- package/dist/client/chunks/chart-config-gauge-CQx9w3d4.js +64 -0
- package/dist/client/chunks/chart-config-gauge-CQx9w3d4.js.map +1 -0
- package/dist/client/chunks/chart-config-measure-profile-ZYaMrtws.js +70 -0
- package/dist/client/chunks/chart-config-measure-profile-ZYaMrtws.js.map +1 -0
- package/dist/client/chunks/chart-config-waterfall-DTyXV_fo.js +60 -0
- package/dist/client/chunks/chart-config-waterfall-DTyXV_fo.js.map +1 -0
- package/dist/client/chunks/{chart-data-table-Ba_6tuJw.js → chart-data-table-D5G8nMnb.js} +2 -2
- package/dist/client/chunks/{chart-data-table-Ba_6tuJw.js.map → chart-data-table-D5G8nMnb.js.map} +1 -1
- package/dist/client/chunks/{chart-funnel-C9kenCpp.js → chart-funnel-dofnhD24.js} +2 -2
- package/dist/client/chunks/{chart-funnel-C9kenCpp.js.map → chart-funnel-dofnhD24.js.map} +1 -1
- package/dist/client/chunks/chart-gauge-CKJJ8m3b.js +374 -0
- package/dist/client/chunks/chart-gauge-CKJJ8m3b.js.map +1 -0
- package/dist/client/chunks/{chart-heat-map-CYGemyPB.js → chart-heat-map-BVuPUKHT.js} +2 -2
- package/dist/client/chunks/{chart-heat-map-CYGemyPB.js.map → chart-heat-map-BVuPUKHT.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-delta-D9XJoKuA.js → chart-kpi-delta-Dgg2eYRl.js} +3 -3
- package/dist/client/chunks/{chart-kpi-delta-D9XJoKuA.js.map → chart-kpi-delta-Dgg2eYRl.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-number-C29Vj2g8.js → chart-kpi-number-DkoO99c1.js} +2 -2
- package/dist/client/chunks/{chart-kpi-number-C29Vj2g8.js.map → chart-kpi-number-DkoO99c1.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-text-CgjjrurK.js → chart-kpi-text-1O6_lmz7.js} +3 -3
- package/dist/client/chunks/{chart-kpi-text-CgjjrurK.js.map → chart-kpi-text-1O6_lmz7.js.map} +1 -1
- package/dist/client/chunks/{chart-line-zi6olZet.js → chart-line-DzyZkugh.js} +3 -3
- package/dist/client/chunks/{chart-line-zi6olZet.js.map → chart-line-DzyZkugh.js.map} +1 -1
- package/dist/client/chunks/chart-measure-profile-C2IkBG3V.js +114 -0
- package/dist/client/chunks/chart-measure-profile-C2IkBG3V.js.map +1 -0
- package/dist/client/chunks/{chart-pie-C4SuxKSN.js → chart-pie-akbfRfb9.js} +2 -2
- package/dist/client/chunks/{chart-pie-C4SuxKSN.js.map → chart-pie-akbfRfb9.js.map} +1 -1
- package/dist/client/chunks/{chart-radar-BW3Z_-Ly.js → chart-radar-BaN-Kjww.js} +2 -2
- package/dist/client/chunks/{chart-radar-BW3Z_-Ly.js.map → chart-radar-BaN-Kjww.js.map} +1 -1
- package/dist/client/chunks/{chart-radial-bar-0Fa3aeP5.js → chart-radial-bar-DpptEL3s.js} +2 -2
- package/dist/client/chunks/{chart-radial-bar-0Fa3aeP5.js.map → chart-radial-bar-DpptEL3s.js.map} +1 -1
- package/dist/client/chunks/{chart-sankey-DBghfbg1.js → chart-sankey-CG-3hHmX.js} +2 -2
- package/dist/client/chunks/{chart-sankey-DBghfbg1.js.map → chart-sankey-CG-3hHmX.js.map} +1 -1
- package/dist/client/chunks/{chart-scatter-DOVu1TNq.js → chart-scatter-l_yTVxF3.js} +2 -2
- package/dist/client/chunks/{chart-scatter-DOVu1TNq.js.map → chart-scatter-l_yTVxF3.js.map} +1 -1
- package/dist/client/chunks/{chart-sunburst-LfNthFlZ.js → chart-sunburst-KhDcKhmZ.js} +2 -2
- package/dist/client/chunks/{chart-sunburst-LfNthFlZ.js.map → chart-sunburst-KhDcKhmZ.js.map} +1 -1
- package/dist/client/chunks/{chart-tree-map-DZtQPyWX.js → chart-tree-map-CBbiaBXV.js} +2 -2
- package/dist/client/chunks/{chart-tree-map-DZtQPyWX.js.map → chart-tree-map-CBbiaBXV.js.map} +1 -1
- package/dist/client/chunks/chart-waterfall-CX3vx_lI.js +191 -0
- package/dist/client/chunks/chart-waterfall-CX3vx_lI.js.map +1 -0
- package/dist/client/chunks/{charts-core-DmGfleFz.js → charts-core-CU9u_HtL.js} +2 -1
- package/dist/client/chunks/charts-core-CU9u_HtL.js.map +1 -0
- package/dist/client/chunks/{charts-loader-CH0_S06T.js → charts-loader-AW3T1nv5.js} +58 -42
- package/dist/client/chunks/charts-loader-AW3T1nv5.js.map +1 -0
- package/dist/client/chunks/{components-ClQziOcT.js → components-BkeSy9xv.js} +4 -4
- package/dist/client/chunks/components-BkeSy9xv.js.map +1 -0
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +10 -0
- package/dist/client/components/AgenticNotebook/ChatMessage.d.ts +2 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +11 -1
- package/dist/client/components/LoadingIndicator.d.ts +2 -2
- package/dist/client/components/charts/BoxPlotChart.config.d.ts +1 -7
- package/dist/client/components/charts/CandlestickChart.config.d.ts +5 -0
- package/dist/client/components/charts/CandlestickChart.d.ts +4 -0
- package/dist/client/components/charts/GaugeChart.config.d.ts +5 -0
- package/dist/client/components/charts/GaugeChart.d.ts +4 -0
- package/dist/client/components/charts/MeasureProfileChart.config.d.ts +5 -0
- package/dist/client/components/charts/MeasureProfileChart.d.ts +4 -0
- package/dist/client/components/charts/WaterfallChart.config.d.ts +5 -0
- package/dist/client/components/charts/WaterfallChart.d.ts +4 -0
- package/dist/client/components/charts/index.d.ts +4 -0
- package/dist/client/components.js +1 -1
- package/dist/client/hooks/useAgentChat.d.ts +20 -2
- package/dist/client/index.js +685 -612
- package/dist/client/index.js.map +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client/types.d.ts +19 -1
- package/dist/client/utils.js +4 -4
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/index.cjs +47 -45
- package/dist/server/index.d.ts +37 -0
- package/dist/server/index.js +1745 -1298
- package/package.json +4 -1
- package/dist/adapters/handler-dnkqpznh.cjs +0 -23
- package/dist/client/chunks/analysis-builder-BMmWeFPr.js.map +0 -1
- package/dist/client/chunks/chart-box-plot-Dja4LS3O.js +0 -313
- package/dist/client/chunks/chart-box-plot-Dja4LS3O.js.map +0 -1
- package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js +0 -85
- package/dist/client/chunks/chart-config-box-plot-D3DA7_pr.js.map +0 -1
- package/dist/client/chunks/charts-core-DmGfleFz.js.map +0 -1
- package/dist/client/chunks/charts-loader-CH0_S06T.js.map +0 -1
- 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
|
[](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:
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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:
|
|
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 (!
|
|
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 (
|
|
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),
|
|
34
|
-
if (!
|
|
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: ${
|
|
36
|
+
`Query validation failed: ${a.errors.join(", ")}`,
|
|
37
37
|
400
|
|
38
38
|
));
|
|
39
|
-
const
|
|
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
|
|
65
|
-
if (!
|
|
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: ${
|
|
67
|
+
`Query validation failed: ${n.errors.join(", ")}`,
|
|
68
68
|
400
|
|
69
69
|
));
|
|
70
|
-
const s = r.headers["x-cache-control"] === "no-cache",
|
|
71
|
-
t.json(A(o,
|
|
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),
|
|
92
|
-
t.json(
|
|
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),
|
|
112
|
-
if (!
|
|
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: ${
|
|
114
|
+
`Query validation failed: ${a.errors.join(", ")}`,
|
|
115
115
|
400
|
|
116
116
|
));
|
|
117
|
-
const
|
|
118
|
-
if (!
|
|
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 =
|
|
124
|
-
t.json(H(e,
|
|
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),
|
|
140
|
-
if (!
|
|
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: ${
|
|
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
|
|
152
|
-
t.json(H(o,
|
|
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),
|
|
162
|
-
t.json(
|
|
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),
|
|
178
|
-
t.json(
|
|
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 || {},
|
|
188
|
-
if (!
|
|
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: ${
|
|
190
|
+
error: `Query validation failed: ${n.errors.join(", ")}`
|
|
191
191
|
});
|
|
192
|
-
const s = await i.explainQuery(e,
|
|
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-
|
|
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
|
|
204
|
+
let s = (j.apiKey || "").trim();
|
|
205
205
|
if (j.allowClientApiKey) {
|
|
206
|
-
const
|
|
207
|
-
|
|
206
|
+
const l = r.headers["x-agent-api-key"];
|
|
207
|
+
l && (s = l.trim());
|
|
208
208
|
}
|
|
209
|
-
if (!
|
|
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
|
|
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
|
|
220
|
+
const l = e({
|
|
221
221
|
message: o,
|
|
222
|
-
sessionId:
|
|
222
|
+
sessionId: a,
|
|
223
|
+
history: n,
|
|
223
224
|
semanticLayer: i,
|
|
224
|
-
securityContext:
|
|
225
|
+
securityContext: f,
|
|
225
226
|
agentConfig: j,
|
|
226
|
-
apiKey:
|
|
227
|
+
apiKey: s
|
|
227
228
|
});
|
|
228
|
-
for await (const
|
|
229
|
-
t.write(`data: ${JSON.stringify(
|
|
229
|
+
for await (const d of l)
|
|
230
|
+
t.write(`data: ${JSON.stringify(d)}
|
|
230
231
|
|
|
231
232
|
`);
|
|
232
|
-
} catch (
|
|
233
|
-
const
|
|
233
|
+
} catch (l) {
|
|
234
|
+
const d = {
|
|
234
235
|
type: "error",
|
|
235
|
-
data: { message:
|
|
236
|
+
data: { message: l instanceof Error ? l.message : "Stream failed" }
|
|
236
237
|
};
|
|
237
|
-
t.write(`data: ${JSON.stringify(
|
|
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
|
|
258
|
-
if (!K(
|
|
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
|
|
261
|
-
if (!
|
|
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:
|
|
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
|
|
270
|
+
const f = T(a), l = s.method === "initialize";
|
|
270
271
|
try {
|
|
271
|
-
const
|
|
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:
|
|
280
|
+
negotiatedProtocol: n.negotiated
|
|
280
281
|
}
|
|
281
282
|
);
|
|
282
283
|
if (P(s))
|
|
283
284
|
return e.status(202).end();
|
|
284
|
-
const v =
|
|
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,
|
|
287
|
-
if (
|
|
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 (
|
|
295
|
+
} catch (d) {
|
|
295
296
|
if (P(s))
|
|
296
|
-
return console.error("MCP notification processing error:",
|
|
297
|
-
console.error("MCP RPC error:",
|
|
298
|
-
const v =
|
|
299
|
-
if (
|
|
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
|
|
315
|
+
const a = setInterval(() => {
|
|
315
316
|
e.write(`: keep-alive
|
|
316
317
|
|
|
317
318
|
`);
|
|
318
319
|
}, 15e3);
|
|
319
320
|
t.on("close", () => {
|
|
320
|
-
clearInterval(
|
|
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,
|
|
329
|
-
const x = W(
|
|
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
|
|
334
|
-
return Y(
|
|
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=(
|
|
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(
|
|
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"})}}),
|
|
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(
|
|
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
|
|
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;
|