drizzle-cube 0.5.3 → 0.5.4
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 +2 -2
- package/dist/adapters/express/index.js +105 -104
- package/dist/adapters/fastify/index.cjs +2 -2
- package/dist/adapters/fastify/index.js +107 -106
- package/dist/adapters/{google-CBfBGU4F.js → google-CT4kgmBf.js} +1 -1
- package/dist/adapters/{google-BOAwi9Ib.cjs → google-Dgo9-Kb5.cjs} +1 -1
- package/dist/adapters/{handler-Cqf-CqAS.cjs → handler-CNn3q29F.cjs} +13 -13
- package/dist/adapters/{handler-BC3nFNxV.js → handler-_TKfigrZ.js} +33 -34
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +99 -98
- package/dist/adapters/{locale-D9VQkLXt.js → locale-BQQrZYhz.js} +1 -1
- package/dist/adapters/{locale-BoiA6WiV.cjs → locale-Dl_3R6hP.cjs} +7 -7
- package/dist/adapters/mcp-tools.cjs +1 -1
- package/dist/adapters/mcp-tools.js +2 -2
- package/dist/adapters/mcp-transport-CkyawtUT.cjs +40 -0
- package/dist/adapters/mcp-transport-DSbd6M_u.js +586 -0
- package/dist/adapters/mcp-transport.d.ts +22 -0
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +136 -135
- package/dist/adapters/{openai-B4N3KfTG.cjs → openai-BjLV_Wjx.cjs} +1 -1
- package/dist/adapters/{openai-BWdm0JvG.js → openai-DQawCWQb.js} +1 -1
- package/dist/adapters/{utils-CTYvfZ3I.js → utils-DG8ti3FT.js} +1097 -661
- package/dist/adapters/utils-DrWvXf0G.cjs +128 -0
- package/dist/adapters/utils.cjs +1 -1
- package/dist/adapters/utils.d.ts +46 -4
- package/dist/adapters/utils.js +1 -1
- package/dist/client/charts.js +12 -12
- package/dist/client/chunks/{DashboardEditModal-IU_0dgfC.js → DashboardEditModal-BBcB0E2g.js} +10 -10
- package/dist/client/chunks/{DashboardEditModal-IU_0dgfC.js.map → DashboardEditModal-BBcB0E2g.js.map} +1 -1
- package/dist/client/chunks/{FieldSearchModal-BCWanpPX.js → FieldSearchModal-CisOov-_.js} +4 -4
- package/dist/client/chunks/{FieldSearchModal-BCWanpPX.js.map → FieldSearchModal-CisOov-_.js.map} +1 -1
- package/dist/client/chunks/KpiDelta-D09hA_UJ.js +2 -0
- package/dist/client/chunks/KpiNumber-B7F9F9fC.js +2 -0
- package/dist/client/chunks/KpiText-C3ZXOF8b.js +2 -0
- package/dist/client/chunks/{RetentionCombinedChart-CQMBODsK.js → RetentionCombinedChart-DiyZwiPv.js} +3 -3
- package/dist/client/chunks/{RetentionCombinedChart-CQMBODsK.js.map → RetentionCombinedChart-DiyZwiPv.js.map} +1 -1
- package/dist/client/chunks/{RetentionHeatmap-B_5sewwi.js → RetentionHeatmap-usGF7BCo.js} +2 -2
- package/dist/client/chunks/{RetentionHeatmap-B_5sewwi.js.map → RetentionHeatmap-usGF7BCo.js.map} +1 -1
- package/dist/client/chunks/SchemaVisualization-DP4k1fPp.js +2 -0
- package/dist/client/chunks/SchemaVisualizationLazy-Brqv_PY9.js +2 -0
- package/dist/client/chunks/{analysis-builder-Dm6eD_AX.js → analysis-builder-0o1W-k3K.js} +8 -8
- package/dist/client/chunks/{analysis-builder-Dm6eD_AX.js.map → analysis-builder-0o1W-k3K.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-shared-DT5bXwCA.js → analysis-builder-shared-Cz4KAlIC.js} +9 -9
- package/dist/client/chunks/{analysis-builder-shared-DT5bXwCA.js.map → analysis-builder-shared-Cz4KAlIC.js.map} +1 -1
- package/dist/client/chunks/{chart-activity-grid-CWT0gLv4.js → chart-activity-grid-VFFm85hC.js} +18 -3
- package/dist/client/chunks/{chart-activity-grid-CWT0gLv4.js.map → chart-activity-grid-VFFm85hC.js.map} +1 -1
- package/dist/client/chunks/{chart-area-DDti9Qtp.js → chart-area-CwwIHTmK.js} +2 -2
- package/dist/client/chunks/{chart-area-DDti9Qtp.js.map → chart-area-CwwIHTmK.js.map} +1 -1
- package/dist/client/chunks/{chart-bar-B3s9qDlh.js → chart-bar-Bmny922L.js} +3 -3
- package/dist/client/chunks/{chart-bar-B3s9qDlh.js.map → chart-bar-Bmny922L.js.map} +1 -1
- package/dist/client/chunks/{chart-box-plot-o-h9MRX5.js → chart-box-plot-DM7GwtCV.js} +2 -2
- package/dist/client/chunks/{chart-box-plot-o-h9MRX5.js.map → chart-box-plot-DM7GwtCV.js.map} +1 -1
- package/dist/client/chunks/{chart-bubble-CMDp4Pfm.js → chart-bubble-DJOq4IpT.js} +2 -2
- package/dist/client/chunks/{chart-bubble-CMDp4Pfm.js.map → chart-bubble-DJOq4IpT.js.map} +1 -1
- package/dist/client/chunks/{chart-candlestick-WyANJ0Ky.js → chart-candlestick-C2nzVCv1.js} +2 -2
- package/dist/client/chunks/{chart-candlestick-WyANJ0Ky.js.map → chart-candlestick-C2nzVCv1.js.map} +1 -1
- package/dist/client/chunks/{chart-data-table-Qrt6EAno.js → chart-data-table-zZtwLf55.js} +30 -30
- package/dist/client/chunks/chart-data-table-zZtwLf55.js.map +1 -0
- package/dist/client/chunks/{chart-funnel-C7pgktN5.js → chart-funnel-COTJy8BP.js} +2 -2
- package/dist/client/chunks/{chart-funnel-C7pgktN5.js.map → chart-funnel-COTJy8BP.js.map} +1 -1
- package/dist/client/chunks/{chart-gauge-D2r2B_AR.js → chart-gauge-C8lIneI0.js} +2 -2
- package/dist/client/chunks/{chart-gauge-D2r2B_AR.js.map → chart-gauge-C8lIneI0.js.map} +1 -1
- package/dist/client/chunks/{chart-heat-map-Dw2yjwfO.js → chart-heat-map-BJXt3RMt.js} +2 -2
- package/dist/client/chunks/{chart-heat-map-Dw2yjwfO.js.map → chart-heat-map-BJXt3RMt.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-delta-CgldZ7zO.js → chart-kpi-delta-DHkNqufb.js} +3 -3
- package/dist/client/chunks/{chart-kpi-delta-CgldZ7zO.js.map → chart-kpi-delta-DHkNqufb.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-number-ByfuX1ki.js → chart-kpi-number-BrXw7m-S.js} +5 -5
- package/dist/client/chunks/{chart-kpi-number-ByfuX1ki.js.map → chart-kpi-number-BrXw7m-S.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-text-DeNuDraJ.js → chart-kpi-text-D0plngLV.js} +3 -3
- package/dist/client/chunks/{chart-kpi-text-DeNuDraJ.js.map → chart-kpi-text-D0plngLV.js.map} +1 -1
- package/dist/client/chunks/{chart-line-RdZwtk27.js → chart-line-DKvW32U-.js} +3 -3
- package/dist/client/chunks/{chart-line-RdZwtk27.js.map → chart-line-DKvW32U-.js.map} +1 -1
- package/dist/client/chunks/{chart-markdown-CiGRZdJj.js → chart-markdown-CJU2hUq3.js} +2 -2
- package/dist/client/chunks/{chart-markdown-CiGRZdJj.js.map → chart-markdown-CJU2hUq3.js.map} +1 -1
- package/dist/client/chunks/{chart-measure-profile-Ckjw9bX6.js → chart-measure-profile-DNT_tbh4.js} +3 -3
- package/dist/client/chunks/{chart-measure-profile-Ckjw9bX6.js.map → chart-measure-profile-DNT_tbh4.js.map} +1 -1
- package/dist/client/chunks/{chart-pie-BvY4FY__.js → chart-pie-CzYnncO-.js} +3 -3
- package/dist/client/chunks/{chart-pie-BvY4FY__.js.map → chart-pie-CzYnncO-.js.map} +1 -1
- package/dist/client/chunks/{chart-radar-DjiiEAmc.js → chart-radar-8iAt3QZl.js} +3 -3
- package/dist/client/chunks/{chart-radar-DjiiEAmc.js.map → chart-radar-8iAt3QZl.js.map} +1 -1
- package/dist/client/chunks/{chart-radial-bar-lla_JEYu.js → chart-radial-bar-CJbG7RIe.js} +3 -3
- package/dist/client/chunks/{chart-radial-bar-lla_JEYu.js.map → chart-radial-bar-CJbG7RIe.js.map} +1 -1
- package/dist/client/chunks/{chart-sankey-WwkZAhLy.js → chart-sankey-C-wLBUmb.js} +2 -2
- package/dist/client/chunks/{chart-sankey-WwkZAhLy.js.map → chart-sankey-C-wLBUmb.js.map} +1 -1
- package/dist/client/chunks/{chart-scatter-DwXnI0rr.js → chart-scatter-NMjD1lbW.js} +3 -3
- package/dist/client/chunks/{chart-scatter-DwXnI0rr.js.map → chart-scatter-NMjD1lbW.js.map} +1 -1
- package/dist/client/chunks/{chart-sunburst-CIDB_pTl.js → chart-sunburst-HtJ-LJ7n.js} +3 -3
- package/dist/client/chunks/{chart-sunburst-CIDB_pTl.js.map → chart-sunburst-HtJ-LJ7n.js.map} +1 -1
- package/dist/client/chunks/{chart-tree-map-DJHoA26f.js → chart-tree-map-CetaLMt8.js} +3 -3
- package/dist/client/chunks/{chart-tree-map-DJHoA26f.js.map → chart-tree-map-CetaLMt8.js.map} +1 -1
- package/dist/client/chunks/{chart-waterfall-Y7c8csO5.js → chart-waterfall-ontNp1Sd.js} +3 -3
- package/dist/client/chunks/{chart-waterfall-Y7c8csO5.js.map → chart-waterfall-ontNp1Sd.js.map} +1 -1
- package/dist/client/chunks/{charts-core-BXOqaYFn.js → charts-core-B5UXUg6_.js} +2 -2
- package/dist/client/chunks/{charts-core-BXOqaYFn.js.map → charts-core-B5UXUg6_.js.map} +1 -1
- package/dist/client/chunks/{nl-NL-vCifBijs.js → nl-NL-DDf0OdfW.js} +17 -2
- package/dist/client/chunks/{nl-NL-vCifBijs.js.map → nl-NL-DDf0OdfW.js.map} +1 -1
- package/dist/client/chunks/{schema-visualization-DWwJukK7.js → schema-visualization-cnB2xZxn.js} +4 -4
- package/dist/client/chunks/{schema-visualization-DWwJukK7.js.map → schema-visualization-cnB2xZxn.js.map} +1 -1
- package/dist/client/chunks/{useDebounce-DyJVREop.js → useDebounce-BOBSvhHy.js} +4 -4
- package/dist/client/chunks/{useDebounce-DyJVREop.js.map → useDebounce-BOBSvhHy.js.map} +1 -1
- package/dist/client/chunks/{useExplainAI-CxSkjocM.js → useExplainAI-B_Pi4eXW.js} +4 -4
- package/dist/client/chunks/{useExplainAI-CxSkjocM.js.map → useExplainAI-B_Pi4eXW.js.map} +1 -1
- package/dist/client/chunks/{utils-BHZdKxua.js → utils-BIuqPQuJ.js} +2 -2
- package/dist/client/chunks/{utils-BHZdKxua.js.map → utils-BIuqPQuJ.js.map} +1 -1
- package/dist/client/chunks/{vendor-CBD_Olr0.js → vendor-BxLCTfvm.js} +2 -2
- package/dist/client/chunks/{vendor-CBD_Olr0.js.map → vendor-BxLCTfvm.js.map} +1 -1
- package/dist/client/components.js +3 -3
- package/dist/client/hooks.js +3 -3
- package/dist/client/icons.js +1 -1
- package/dist/client/index.js +14 -14
- package/dist/client/providers.js +1 -1
- package/dist/client/schema.js +1 -1
- package/dist/client/utils.js +5 -5
- package/dist/client-bundle-stats.html +1 -1
- package/dist/mcp-app/mcp-app.html +23 -23
- package/dist/server/index.cjs +134 -133
- package/dist/server/index.js +1000 -946
- package/package.json +1 -1
- package/dist/adapters/mcp-prompts-BUFyQLHQ.js +0 -377
- package/dist/adapters/mcp-prompts-B_NvEJT_.cjs +0 -111
- package/dist/adapters/mcp-transport-B0mgxRnJ.js +0 -579
- package/dist/adapters/mcp-transport-irsahKmD.cjs +0 -39
- package/dist/adapters/utils-XPOzzMdY.cjs +0 -17
- package/dist/client/chunks/KpiDelta-_igN6cJa.js +0 -2
- package/dist/client/chunks/KpiNumber-t5n8PtRU.js +0 -2
- package/dist/client/chunks/KpiText-BCZJJ6a0.js +0 -2
- package/dist/client/chunks/SchemaVisualization-BUUhlOvG.js +0 -2
- package/dist/client/chunks/SchemaVisualizationLazy-CwaPCUL0.js +0 -2
- package/dist/client/chunks/chart-data-table-Qrt6EAno.js.map +0 -1
- /package/dist/adapters/{anthropic-Cto4Jxqt.cjs → anthropic-BIva8k1r.cjs} +0 -0
- /package/dist/adapters/{anthropic-DpEbCVvF.js → anthropic-B_rg0BhK.js} +0 -0
- /package/dist/adapters/{dist-BnyV9wfA.cjs → dist-Boc63-1q.cjs} +0 -0
- /package/dist/adapters/{dist-DjVh2RFz.js → dist-De5fzUEM.js} +0 -0
- /package/dist/adapters/{openai-CoqT_FM5.cjs → openai-Bgri5TJc.cjs} +0 -0
- /package/dist/adapters/{openai-D0Nsvc9L.js → openai-CuUGrKaK.js} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-DrWvXf0G.cjs`),t=require(`../locale-Dl_3R6hP.cjs`),n=require(`../mcp-transport-CkyawtUT.cjs`);let r=require(`express`);r=e.w(r,1);let i=require(`cors`);i=e.w(i,1);function a(a){let{cubes:o,drizzle:s,schema:c,extractSecurityContext:l,engineType:u,cors:d,basePath:f=`/cubejs-api/v1`,jsonLimit:p=`10mb`,cache:m,mcp:h={enabled:!0},agent:g}=a;if(!o||o.length===0)throw Error(`At least one cube must be provided in the cubes array`);let _=(0,r.Router)(),v=async(e,n)=>t.r(await l(e,n),t.n(t=>e.get(t)));if(d){let e={...d,allowedHeaders:t.t(d.allowedHeaders)};_.use((0,i.default)(e))}_.use(r.default.json({limit:p})),_.use(r.default.urlencoded({extended:!0,limit:p}));let y=new t.i({drizzle:s,schema:c,engineType:u,cache:m,rlsSetup:a.rlsSetup});if(o.forEach(e=>{y.registerCube(e)}),_.post(`${f}/load`,async(t,n)=>{try{let r=t.body.query||t.body,i=await v(t,n),a=y.validateQuery(r);if(!a.isValid)return n.status(400).json(e.i(`Query validation failed: ${a.errors.join(`, `)}`,400));let o=t.headers[`x-cache-control`]===`no-cache`,s=await y.executeMultiCubeQuery(r,i,{skipCache:o});n.json(e.r(r,s,y))}catch(t){console.error(`Query execution error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Query execution failed`,500))}}),_.get(`${f}/load`,async(t,n)=>{try{let r=t.query.query;if(!r)return n.status(400).json(e.i(`Query parameter is required`,400));let i;try{i=JSON.parse(r)}catch{return n.status(400).json(e.i(`Invalid JSON in query parameter`,400))}let a=await v(t,n),o=y.validateQuery(i);if(!o.isValid)return n.status(400).json(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=t.headers[`x-cache-control`]===`no-cache`,c=await y.executeMultiCubeQuery(i,a,{skipCache:s});n.json(e.r(i,c,y))}catch(t){console.error(`Query execution error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Query execution failed`,500))}}),_.post(`${f}/batch`,async(t,n)=>{try{let{queries:r}=t.body;if(!r||!Array.isArray(r))return n.status(400).json(e.i(`Request body must contain a "queries" array`,400));if(r.length===0)return n.status(400).json(e.i(`Queries array cannot be empty`,400));let i=await e.u(r,await v(t,n),y,{skipCache:t.headers[`x-cache-control`]===`no-cache`});n.json(i)}catch(t){console.error(`Batch execution error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Batch execution failed`,500))}}),_.get(`${f}/meta`,(t,n)=>{try{let t=y.getMetadata();n.json(e.a(t))}catch(t){console.error(`Metadata error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Failed to fetch metadata`,500))}}),_.post(`${f}/sql`,async(t,n)=>{try{let r=t.body,i=await v(t,n),a=y.validateQuery(r);if(!a.isValid)return n.status(400).json(e.i(`Query validation failed: ${a.errors.join(`, `)}`,400));let o=r.measures?.[0]||r.dimensions?.[0];if(!o)return n.status(400).json(e.i(`No measures or dimensions specified`,400));let s=o.split(`.`)[0],c=await y.generateSQL(s,r,i);n.json(e.o(r,c))}catch(t){console.error(`SQL generation error:`,String(t).replace(/\n|\r/g,``)),n.status(500).json(e.i(t instanceof Error?t.message:`SQL generation failed`,500))}}),_.get(`${f}/sql`,async(t,n)=>{try{let r=t.query.query;if(!r)return n.status(400).json(e.i(`Query parameter is required`,400));let i=JSON.parse(r),a=await v(t,n),o=y.validateQuery(i);if(!o.isValid)return n.status(400).json(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=i.measures?.[0]||i.dimensions?.[0];if(!s)return n.status(400).json(e.i(`No measures or dimensions specified`,400));let c=s.split(`.`)[0],l=await y.generateSQL(c,i,a);n.json(e.o(i,l))}catch(t){console.error(`SQL generation error:`,String(t).replace(/\n|\r/g,``)),n.status(500).json(e.i(t instanceof Error?t.message:`SQL generation failed`,500))}}),_.post(`${f}/dry-run`,async(t,n)=>{try{let r=await e.f(t.body.query||t.body,await v(t,n),y);n.json(r)}catch(e){console.error(`Dry-run error:`,e),n.status(400).json({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),_.get(`${f}/dry-run`,async(t,n)=>{try{let r=t.query.query;if(!r)return n.status(400).json({error:`Query parameter is required`,valid:!1});let i=await e.f(JSON.parse(r),await v(t,n),y);n.json(i)}catch(e){console.error(`Dry-run error:`,e),n.status(400).json({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),_.post(`${f}/explain`,async(e,t)=>{try{let n=e.body.query||e.body,r=e.body.options||{},i=await v(e,t),a=y.validateQuery(n);if(!a.isValid)return t.status(400).json({error:`Query validation failed: ${a.errors.join(`, `)}`});let o=await y.explainQuery(n,i,r);t.json(o)}catch(e){console.error(`Explain error:`,e),t.status(500).json({error:e instanceof Error?e.message:`Explain query failed`})}}),g&&_.post(`${f}/agent/chat`,async(e,t)=>{try{let{handleAgentChat:n}=await Promise.resolve().then(()=>require(`../handler-CNn3q29F.cjs`)),{message:r,sessionId:i,history:a}=e.body;if(!r||typeof r!=`string`)return t.status(400).json({error:`message is required and must be a string`});let o=(g.apiKey||``).trim();if(g.allowClientApiKey){let t=e.headers[`x-agent-api-key`];t&&(o=t.trim())}if(!o)return t.status(401).json({error:`No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header.`});let s=g.allowClientApiKey?e.headers[`x-agent-provider`]:void 0,c=g.allowClientApiKey?e.headers[`x-agent-model`]:void 0,l=g.allowClientApiKey?e.headers[`x-agent-provider-endpoint`]:void 0,u=await v(e,t),d=g.buildSystemContext?.(u);t.writeHead(200,{"Content-Type":`text/event-stream`,"Cache-Control":`no-cache`,Connection:`keep-alive`});try{let e=n({message:r,sessionId:i,history:a,semanticLayer:y,securityContext:u,agentConfig:g,apiKey:o,systemContext:d,providerOverride:s,modelOverride:c,baseURLOverride:l});for await(let n of e)t.write(`data: ${JSON.stringify(n)}\n\n`)}catch(e){let n={type:`error`,data:{message:e instanceof Error?e.message:`Stream failed`}};t.write(`data: ${JSON.stringify(n)}\n\n`)}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`})}}),h.enabled!==!1){let e=n.o(y,h.resources),t=n.y(h.prompts),r=n.v(h.instructions),i=h.basePath??`/mcp`;_.post(`${i}`,async(i,a)=>{if(h.resourceMetadataUrl&&!n.u(i.headers.authorization))return a.setHeader(`WWW-Authenticate`,n.c(h.resourceMetadataUrl)),a.status(401).json({error:`Bearer token required`});let o=n.S(i.headers.origin,h.allowedOrigins?{allowedOrigins:h.allowedOrigins}:{});if(!o.valid)return a.status(403).json(n.i(null,-32600,o.reason));let s=i.headers.accept;if(!n.x(s))return a.status(400).json(n.i(null,-32600,`Accept header must include both application/json and text/event-stream`));let c=n.h(i.headers);if(!c.ok)return a.status(426).json({error:`Unsupported MCP protocol version`,supported:c.supported});let l=n.g(i.body);if(!l)return a.status(400).json(n.i(null,-32600,`Invalid JSON-RPC 2.0 request`));let u=n.C(s),d=l.method===`initialize`;try{let o=await n.l(l.method,l.params,{semanticLayer:y,extractSecurityContext:(e,t)=>v(e,t),rawRequest:i,rawResponse:a,negotiatedProtocol:c.negotiated,resources:e,prompts:t,instructions:r,appEnabled:!!h.app,appConfig:typeof h.app==`object`?h.app:void 0,serverName:h.serverName});if(n.m(l))return a.status(202).end();let s=d&&o&&typeof o==`object`&&`sessionId`in o?o.sessionId:void 0;s&&a.setHeader(n.r,s);let f=n.a(l.id??null,o);if(u){let e=n._();return a.status(200),a.setHeader(`Content-Type`,`text/event-stream`),a.setHeader(`Cache-Control`,`no-cache`),a.setHeader(`Connection`,`keep-alive`),a.write(`id: ${e}\n\n`),a.write(n.b(f,e)),a.end()}return a.json(f)}catch(e){if(n.m(l))return console.error(`MCP notification processing error:`,String(e).replace(/\n|\r/g,``)),a.status(202).end();console.error(`MCP RPC error:`,String(e).replace(/\n|\r/g,``));let t=e?.code??-32603,r=e?.data,i=e.message||`MCP request failed`,o=n.i(l.id??null,t,i,r);if(u){let e=n._();return a.status(200),a.setHeader(`Content-Type`,`text/event-stream`),a.setHeader(`Cache-Control`,`no-cache`),a.setHeader(`Connection`,`keep-alive`),a.write(`id: ${e}\n\n`),a.write(n.b(o,e)),a.end()}return a.status(200).json(o)}}),_.get(`${i}`,async(e,t)=>{if(h.resourceMetadataUrl&&!n.u(e.headers.authorization))return t.setHeader(`WWW-Authenticate`,n.c(h.resourceMetadataUrl)),t.status(401).json({error:`Bearer token required`});let r=n._();t.status(200),t.setHeader(`Content-Type`,`text/event-stream`),t.setHeader(`Cache-Control`,`no-cache`),t.setHeader(`Connection`,`keep-alive`),t.write(n.b({jsonrpc:`2.0`,method:`mcp/ready`,params:{protocol:`streamable-http`}},r,15e3));let i=setInterval(()=>{t.write(`: keep-alive
|
|
2
2
|
|
|
3
|
-
`)},15e3);e.on(`close`,()=>{clearInterval(i)})}),_.delete(`${
|
|
3
|
+
`)},15e3);e.on(`close`,()=>{clearInterval(i)})}),_.delete(`${i}`,(e,t)=>h.resourceMetadataUrl&&!n.u(e.headers.authorization)?(t.setHeader(`WWW-Authenticate`,n.c(h.resourceMetadataUrl)),t.status(401).json({error:`Bearer token required`})):t.status(405).json({error:`Session termination not supported`}))}return _.use((t,n,r,i)=>{console.error(`Express adapter error:`,t),r.headersSent||r.status(500).json(e.i(t,500))}),_}function o(e,t){let n=a(t);return e.use(`/`,n),e}function s(e){return o((0,r.default)(),e)}exports.createCubeApp=s,exports.createCubeRouter=a,exports.mountCubeRoutes=o;
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { a as e, f as t, i as n, o as r, r as i, u as a } from "../utils-
|
|
2
|
-
import { i as o, n as s, r as c, t as l } from "../locale-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { a as e, f as t, i as n, o as r, r as i, u as a } from "../utils-DG8ti3FT.js";
|
|
2
|
+
import { i as o, n as s, r as c, t as l } from "../locale-BQQrZYhz.js";
|
|
3
|
+
import { C as u, S as d, _ as f, a as p, b as m, c as h, g, h as _, i as v, l as y, m as b, o as x, r as S, u as C, v as w, x as T, y as E } from "../mcp-transport-DSbd6M_u.js";
|
|
4
|
+
import D, { Router as O } from "express";
|
|
5
|
+
import k from "cors";
|
|
6
6
|
//#region src/adapters/express/index.ts
|
|
7
|
-
function
|
|
8
|
-
let { cubes:
|
|
9
|
-
if (!
|
|
10
|
-
let
|
|
11
|
-
if (
|
|
7
|
+
function A(A) {
|
|
8
|
+
let { cubes: j, drizzle: M, schema: N, extractSecurityContext: P, engineType: F, cors: I, basePath: L = "/cubejs-api/v1", jsonLimit: R = "10mb", cache: z, mcp: B = { enabled: !0 }, agent: V } = A;
|
|
9
|
+
if (!j || j.length === 0) throw Error("At least one cube must be provided in the cubes array");
|
|
10
|
+
let H = O(), U = async (e, t) => c(await P(e, t), s((t) => e.get(t)));
|
|
11
|
+
if (I) {
|
|
12
12
|
let e = {
|
|
13
|
-
...
|
|
14
|
-
allowedHeaders: l(
|
|
13
|
+
...I,
|
|
14
|
+
allowedHeaders: l(I.allowedHeaders)
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
H.use(k(e));
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
H.use(D.json({ limit: R })), H.use(D.urlencoded({
|
|
19
19
|
extended: !0,
|
|
20
|
-
limit:
|
|
20
|
+
limit: R
|
|
21
21
|
}));
|
|
22
|
-
let
|
|
23
|
-
drizzle:
|
|
24
|
-
schema:
|
|
25
|
-
engineType:
|
|
26
|
-
cache:
|
|
27
|
-
rlsSetup:
|
|
22
|
+
let W = new o({
|
|
23
|
+
drizzle: M,
|
|
24
|
+
schema: N,
|
|
25
|
+
engineType: F,
|
|
26
|
+
cache: z,
|
|
27
|
+
rlsSetup: A.rlsSetup
|
|
28
28
|
});
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
}),
|
|
29
|
+
if (j.forEach((e) => {
|
|
30
|
+
W.registerCube(e);
|
|
31
|
+
}), H.post(`${L}/load`, async (e, t) => {
|
|
32
32
|
try {
|
|
33
|
-
let r = e.body.query || e.body, a = await
|
|
33
|
+
let r = e.body.query || e.body, a = await U(e, t), o = W.validateQuery(r);
|
|
34
34
|
if (!o.isValid) return t.status(400).json(n(`Query validation failed: ${o.errors.join(", ")}`, 400));
|
|
35
|
-
let s = e.headers["x-cache-control"] === "no-cache", c = await
|
|
36
|
-
t.json(i(r, c,
|
|
35
|
+
let s = e.headers["x-cache-control"] === "no-cache", c = await W.executeMultiCubeQuery(r, a, { skipCache: s });
|
|
36
|
+
t.json(i(r, c, W));
|
|
37
37
|
} catch (e) {
|
|
38
38
|
console.error("Query execution error:", e), t.status(500).json(n(e instanceof Error ? e.message : "Query execution failed", 500));
|
|
39
39
|
}
|
|
40
|
-
}),
|
|
40
|
+
}), H.get(`${L}/load`, async (e, t) => {
|
|
41
41
|
try {
|
|
42
42
|
let r = e.query.query;
|
|
43
43
|
if (!r) return t.status(400).json(n("Query parameter is required", 400));
|
|
@@ -47,57 +47,57 @@ function k(k) {
|
|
|
47
47
|
} catch {
|
|
48
48
|
return t.status(400).json(n("Invalid JSON in query parameter", 400));
|
|
49
49
|
}
|
|
50
|
-
let o = await
|
|
50
|
+
let o = await U(e, t), s = W.validateQuery(a);
|
|
51
51
|
if (!s.isValid) return t.status(400).json(n(`Query validation failed: ${s.errors.join(", ")}`, 400));
|
|
52
|
-
let c = e.headers["x-cache-control"] === "no-cache", l = await
|
|
53
|
-
t.json(i(a, l,
|
|
52
|
+
let c = e.headers["x-cache-control"] === "no-cache", l = await W.executeMultiCubeQuery(a, o, { skipCache: c });
|
|
53
|
+
t.json(i(a, l, W));
|
|
54
54
|
} catch (e) {
|
|
55
55
|
console.error("Query execution error:", e), t.status(500).json(n(e instanceof Error ? e.message : "Query execution failed", 500));
|
|
56
56
|
}
|
|
57
|
-
}),
|
|
57
|
+
}), H.post(`${L}/batch`, async (e, t) => {
|
|
58
58
|
try {
|
|
59
59
|
let { queries: r } = e.body;
|
|
60
60
|
if (!r || !Array.isArray(r)) return t.status(400).json(n("Request body must contain a \"queries\" array", 400));
|
|
61
61
|
if (r.length === 0) return t.status(400).json(n("Queries array cannot be empty", 400));
|
|
62
|
-
let i = await a(r, await
|
|
62
|
+
let i = await a(r, await U(e, t), W, { skipCache: e.headers["x-cache-control"] === "no-cache" });
|
|
63
63
|
t.json(i);
|
|
64
64
|
} catch (e) {
|
|
65
65
|
console.error("Batch execution error:", e), t.status(500).json(n(e instanceof Error ? e.message : "Batch execution failed", 500));
|
|
66
66
|
}
|
|
67
|
-
}),
|
|
67
|
+
}), H.get(`${L}/meta`, (t, r) => {
|
|
68
68
|
try {
|
|
69
|
-
let t =
|
|
69
|
+
let t = W.getMetadata();
|
|
70
70
|
r.json(e(t));
|
|
71
71
|
} catch (e) {
|
|
72
72
|
console.error("Metadata error:", e), r.status(500).json(n(e instanceof Error ? e.message : "Failed to fetch metadata", 500));
|
|
73
73
|
}
|
|
74
|
-
}),
|
|
74
|
+
}), H.post(`${L}/sql`, async (e, t) => {
|
|
75
75
|
try {
|
|
76
|
-
let i = e.body, a = await
|
|
76
|
+
let i = e.body, a = await U(e, t), o = W.validateQuery(i);
|
|
77
77
|
if (!o.isValid) return t.status(400).json(n(`Query validation failed: ${o.errors.join(", ")}`, 400));
|
|
78
78
|
let s = i.measures?.[0] || i.dimensions?.[0];
|
|
79
79
|
if (!s) return t.status(400).json(n("No measures or dimensions specified", 400));
|
|
80
|
-
let c = s.split(".")[0], l = await
|
|
80
|
+
let c = s.split(".")[0], l = await W.generateSQL(c, i, a);
|
|
81
81
|
t.json(r(i, l));
|
|
82
82
|
} catch (e) {
|
|
83
83
|
console.error("SQL generation error:", String(e).replace(/\n|\r/g, "")), t.status(500).json(n(e instanceof Error ? e.message : "SQL generation failed", 500));
|
|
84
84
|
}
|
|
85
|
-
}),
|
|
85
|
+
}), H.get(`${L}/sql`, async (e, t) => {
|
|
86
86
|
try {
|
|
87
87
|
let i = e.query.query;
|
|
88
88
|
if (!i) return t.status(400).json(n("Query parameter is required", 400));
|
|
89
|
-
let a = JSON.parse(i), o = await
|
|
89
|
+
let a = JSON.parse(i), o = await U(e, t), s = W.validateQuery(a);
|
|
90
90
|
if (!s.isValid) return t.status(400).json(n(`Query validation failed: ${s.errors.join(", ")}`, 400));
|
|
91
91
|
let c = a.measures?.[0] || a.dimensions?.[0];
|
|
92
92
|
if (!c) return t.status(400).json(n("No measures or dimensions specified", 400));
|
|
93
|
-
let l = c.split(".")[0], u = await
|
|
93
|
+
let l = c.split(".")[0], u = await W.generateSQL(l, a, o);
|
|
94
94
|
t.json(r(a, u));
|
|
95
95
|
} catch (e) {
|
|
96
96
|
console.error("SQL generation error:", String(e).replace(/\n|\r/g, "")), t.status(500).json(n(e instanceof Error ? e.message : "SQL generation failed", 500));
|
|
97
97
|
}
|
|
98
|
-
}),
|
|
98
|
+
}), H.post(`${L}/dry-run`, async (e, n) => {
|
|
99
99
|
try {
|
|
100
|
-
let r = await t(e.body.query || e.body, await
|
|
100
|
+
let r = await t(e.body.query || e.body, await U(e, n), W);
|
|
101
101
|
n.json(r);
|
|
102
102
|
} catch (e) {
|
|
103
103
|
console.error("Dry-run error:", e), n.status(400).json({
|
|
@@ -105,14 +105,14 @@ function k(k) {
|
|
|
105
105
|
valid: !1
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
-
}),
|
|
108
|
+
}), H.get(`${L}/dry-run`, async (e, n) => {
|
|
109
109
|
try {
|
|
110
110
|
let r = e.query.query;
|
|
111
111
|
if (!r) return n.status(400).json({
|
|
112
112
|
error: "Query parameter is required",
|
|
113
113
|
valid: !1
|
|
114
114
|
});
|
|
115
|
-
let i = await t(JSON.parse(r), await
|
|
115
|
+
let i = await t(JSON.parse(r), await U(e, n), W);
|
|
116
116
|
n.json(i);
|
|
117
117
|
} catch (e) {
|
|
118
118
|
console.error("Dry-run error:", e), n.status(400).json({
|
|
@@ -120,26 +120,26 @@ function k(k) {
|
|
|
120
120
|
valid: !1
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
}),
|
|
123
|
+
}), H.post(`${L}/explain`, async (e, t) => {
|
|
124
124
|
try {
|
|
125
|
-
let n = e.body.query || e.body, r = e.body.options || {}, i = await
|
|
125
|
+
let n = e.body.query || e.body, r = e.body.options || {}, i = await U(e, t), a = W.validateQuery(n);
|
|
126
126
|
if (!a.isValid) return t.status(400).json({ error: `Query validation failed: ${a.errors.join(", ")}` });
|
|
127
|
-
let o = await
|
|
127
|
+
let o = await W.explainQuery(n, i, r);
|
|
128
128
|
t.json(o);
|
|
129
129
|
} catch (e) {
|
|
130
130
|
console.error("Explain error:", e), t.status(500).json({ error: e instanceof Error ? e.message : "Explain query failed" });
|
|
131
131
|
}
|
|
132
|
-
}),
|
|
132
|
+
}), V && H.post(`${L}/agent/chat`, async (e, t) => {
|
|
133
133
|
try {
|
|
134
|
-
let { handleAgentChat: n } = await import("../handler-
|
|
134
|
+
let { handleAgentChat: n } = await import("../handler-_TKfigrZ.js"), { message: r, sessionId: i, history: a } = e.body;
|
|
135
135
|
if (!r || typeof r != "string") return t.status(400).json({ error: "message is required and must be a string" });
|
|
136
|
-
let o = (
|
|
137
|
-
if (
|
|
136
|
+
let o = (V.apiKey || "").trim();
|
|
137
|
+
if (V.allowClientApiKey) {
|
|
138
138
|
let t = e.headers["x-agent-api-key"];
|
|
139
139
|
t && (o = t.trim());
|
|
140
140
|
}
|
|
141
141
|
if (!o) return t.status(401).json({ error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header." });
|
|
142
|
-
let s =
|
|
142
|
+
let s = V.allowClientApiKey ? e.headers["x-agent-provider"] : void 0, c = V.allowClientApiKey ? e.headers["x-agent-model"] : void 0, l = V.allowClientApiKey ? e.headers["x-agent-provider-endpoint"] : void 0, u = await U(e, t), d = V.buildSystemContext?.(u);
|
|
143
143
|
t.writeHead(200, {
|
|
144
144
|
"Content-Type": "text/event-stream",
|
|
145
145
|
"Cache-Control": "no-cache",
|
|
@@ -150,9 +150,9 @@ function k(k) {
|
|
|
150
150
|
message: r,
|
|
151
151
|
sessionId: i,
|
|
152
152
|
history: a,
|
|
153
|
-
semanticLayer:
|
|
153
|
+
semanticLayer: W,
|
|
154
154
|
securityContext: u,
|
|
155
|
-
agentConfig:
|
|
155
|
+
agentConfig: V,
|
|
156
156
|
apiKey: o,
|
|
157
157
|
systemContext: d,
|
|
158
158
|
providerOverride: s,
|
|
@@ -172,58 +172,59 @@ function k(k) {
|
|
|
172
172
|
} catch (e) {
|
|
173
173
|
console.error("Agent chat error:", e), t.headersSent || t.status(500).json({ error: e instanceof Error ? e.message : "Agent chat failed" });
|
|
174
174
|
}
|
|
175
|
-
}),
|
|
176
|
-
let e =
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
let
|
|
180
|
-
if (!
|
|
181
|
-
let
|
|
182
|
-
if (!
|
|
183
|
-
let
|
|
184
|
-
if (!
|
|
175
|
+
}), B.enabled !== !1) {
|
|
176
|
+
let e = x(W, B.resources), t = E(B.prompts), n = w(B.instructions), r = B.basePath ?? "/mcp";
|
|
177
|
+
H.post(`${r}`, async (r, i) => {
|
|
178
|
+
if (B.resourceMetadataUrl && !C(r.headers.authorization)) return i.setHeader("WWW-Authenticate", h(B.resourceMetadataUrl)), i.status(401).json({ error: "Bearer token required" });
|
|
179
|
+
let a = d(r.headers.origin, B.allowedOrigins ? { allowedOrigins: B.allowedOrigins } : {});
|
|
180
|
+
if (!a.valid) return i.status(403).json(v(null, -32600, a.reason));
|
|
181
|
+
let o = r.headers.accept;
|
|
182
|
+
if (!T(o)) return i.status(400).json(v(null, -32600, "Accept header must include both application/json and text/event-stream"));
|
|
183
|
+
let s = _(r.headers);
|
|
184
|
+
if (!s.ok) return i.status(426).json({
|
|
185
185
|
error: "Unsupported MCP protocol version",
|
|
186
|
-
supported:
|
|
186
|
+
supported: s.supported
|
|
187
187
|
});
|
|
188
|
-
let
|
|
189
|
-
if (!
|
|
190
|
-
let
|
|
188
|
+
let c = g(r.body);
|
|
189
|
+
if (!c) return i.status(400).json(v(null, -32600, "Invalid JSON-RPC 2.0 request"));
|
|
190
|
+
let l = u(o), x = c.method === "initialize";
|
|
191
191
|
try {
|
|
192
|
-
let
|
|
193
|
-
semanticLayer:
|
|
194
|
-
extractSecurityContext: (e, t) =>
|
|
195
|
-
rawRequest:
|
|
196
|
-
rawResponse:
|
|
197
|
-
negotiatedProtocol:
|
|
192
|
+
let a = await y(c.method, c.params, {
|
|
193
|
+
semanticLayer: W,
|
|
194
|
+
extractSecurityContext: (e, t) => U(e, t),
|
|
195
|
+
rawRequest: r,
|
|
196
|
+
rawResponse: i,
|
|
197
|
+
negotiatedProtocol: s.negotiated,
|
|
198
198
|
resources: e,
|
|
199
199
|
prompts: t,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
instructions: n,
|
|
201
|
+
appEnabled: !!B.app,
|
|
202
|
+
appConfig: typeof B.app == "object" ? B.app : void 0,
|
|
203
|
+
serverName: B.serverName
|
|
203
204
|
});
|
|
204
|
-
if (
|
|
205
|
-
let
|
|
206
|
-
|
|
207
|
-
let u =
|
|
208
|
-
if (
|
|
209
|
-
let e =
|
|
210
|
-
return
|
|
205
|
+
if (b(c)) return i.status(202).end();
|
|
206
|
+
let o = x && a && typeof a == "object" && "sessionId" in a ? a.sessionId : void 0;
|
|
207
|
+
o && i.setHeader(S, o);
|
|
208
|
+
let u = p(c.id ?? null, a);
|
|
209
|
+
if (l) {
|
|
210
|
+
let e = f();
|
|
211
|
+
return i.status(200), i.setHeader("Content-Type", "text/event-stream"), i.setHeader("Cache-Control", "no-cache"), i.setHeader("Connection", "keep-alive"), i.write(`id: ${e}\n\n`), i.write(m(u, e)), i.end();
|
|
211
212
|
}
|
|
212
|
-
return
|
|
213
|
+
return i.json(u);
|
|
213
214
|
} catch (e) {
|
|
214
|
-
if (
|
|
215
|
+
if (b(c)) return console.error("MCP notification processing error:", String(e).replace(/\n|\r/g, "")), i.status(202).end();
|
|
215
216
|
console.error("MCP RPC error:", String(e).replace(/\n|\r/g, ""));
|
|
216
|
-
let t = e?.code ?? -32603, n = e?.data,
|
|
217
|
-
if (
|
|
218
|
-
let e =
|
|
219
|
-
return
|
|
217
|
+
let t = e?.code ?? -32603, n = e?.data, r = e.message || "MCP request failed", a = v(c.id ?? null, t, r, n);
|
|
218
|
+
if (l) {
|
|
219
|
+
let e = f();
|
|
220
|
+
return i.status(200), i.setHeader("Content-Type", "text/event-stream"), i.setHeader("Cache-Control", "no-cache"), i.setHeader("Connection", "keep-alive"), i.write(`id: ${e}\n\n`), i.write(m(a, e)), i.end();
|
|
220
221
|
}
|
|
221
|
-
return
|
|
222
|
+
return i.status(200).json(a);
|
|
222
223
|
}
|
|
223
|
-
}),
|
|
224
|
-
if (
|
|
225
|
-
let n =
|
|
226
|
-
t.status(200), t.setHeader("Content-Type", "text/event-stream"), t.setHeader("Cache-Control", "no-cache"), t.setHeader("Connection", "keep-alive"), t.write(
|
|
224
|
+
}), H.get(`${r}`, async (e, t) => {
|
|
225
|
+
if (B.resourceMetadataUrl && !C(e.headers.authorization)) return t.setHeader("WWW-Authenticate", h(B.resourceMetadataUrl)), t.status(401).json({ error: "Bearer token required" });
|
|
226
|
+
let n = f();
|
|
227
|
+
t.status(200), t.setHeader("Content-Type", "text/event-stream"), t.setHeader("Cache-Control", "no-cache"), t.setHeader("Connection", "keep-alive"), t.write(m({
|
|
227
228
|
jsonrpc: "2.0",
|
|
228
229
|
method: "mcp/ready",
|
|
229
230
|
params: { protocol: "streamable-http" }
|
|
@@ -234,18 +235,18 @@ function k(k) {
|
|
|
234
235
|
e.on("close", () => {
|
|
235
236
|
clearInterval(r);
|
|
236
237
|
});
|
|
237
|
-
}),
|
|
238
|
+
}), H.delete(`${r}`, (e, t) => B.resourceMetadataUrl && !C(e.headers.authorization) ? (t.setHeader("WWW-Authenticate", h(B.resourceMetadataUrl)), t.status(401).json({ error: "Bearer token required" })) : t.status(405).json({ error: "Session termination not supported" }));
|
|
238
239
|
}
|
|
239
|
-
return
|
|
240
|
+
return H.use((e, t, r, i) => {
|
|
240
241
|
console.error("Express adapter error:", e), r.headersSent || r.status(500).json(n(e, 500));
|
|
241
|
-
}),
|
|
242
|
+
}), H;
|
|
242
243
|
}
|
|
243
|
-
function
|
|
244
|
-
let n =
|
|
244
|
+
function j(e, t) {
|
|
245
|
+
let n = A(t);
|
|
245
246
|
return e.use("/", n), e;
|
|
246
247
|
}
|
|
247
|
-
function
|
|
248
|
-
return
|
|
248
|
+
function M(e) {
|
|
249
|
+
return j(D(), e);
|
|
249
250
|
}
|
|
250
251
|
//#endregion
|
|
251
|
-
export {
|
|
252
|
+
export { M as createCubeApp, A as createCubeRouter, j as mountCubeRoutes };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-DrWvXf0G.cjs`),t=require(`../locale-Dl_3R6hP.cjs`),n=require(`../mcp-transport-CkyawtUT.cjs`);var r=function(r,i,a){let{cubes:o,drizzle:s,schema:c,extractSecurityContext:l,engineType:u,cors:d,basePath:f=`/cubejs-api/v1`,bodyLimit:p=10485760,cache:m,mcp:h={enabled:!0},agent:g}=i;if(!o||o.length===0)return a(Error(`At least one cube must be provided in the cubes array`));let _=async e=>t.r(await l(e),t.n(t=>e.headers[t.toLowerCase()]));if(d){let e={...d,allowedHeaders:t.t(d.allowedHeaders)};r.register(import(`@fastify/cors`),e)}r.addHook(`onRequest`,async(e,t)=>{e.method===`POST`&&(e.body=void 0)});let v=new t.i({drizzle:s,schema:c,engineType:u,cache:m,rlsSetup:i.rlsSetup});if(o.forEach(e=>{v.registerCube(e)}),r.post(`${f}/load`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(t,n)=>{try{let r=t.body,i=r.query||r,a=await _(t),o=v.validateQuery(i);if(!o.isValid)return n.status(400).send(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=t.headers[`x-cache-control`]===`no-cache`;return e.r(i,await v.executeMultiCubeQuery(i,a,{skipCache:s}),v)}catch(r){return t.log.error(r,`Query execution error`),n.status(500).send(e.i(r instanceof Error?r.message:`Query execution failed`,500))}}),r.get(`${f}/load`,{schema:{querystring:{type:`object`,properties:{query:{type:`string`}},required:[`query`]}}},async(t,n)=>{try{let{query:r}=t.query,i;try{i=JSON.parse(r)}catch{return n.status(400).send(e.i(`Invalid JSON in query parameter`,400))}let a=await _(t),o=v.validateQuery(i);if(!o.isValid)return n.status(400).send(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=t.headers[`x-cache-control`]===`no-cache`,c=await v.executeMultiCubeQuery(i,a,{skipCache:s});return e.r(i,c,v)}catch(r){return t.log.error(r,`Query execution error`),n.status(500).send(e.i(r instanceof Error?r.message:`Query execution failed`,500))}}),r.post(`${f}/batch`,{bodyLimit:p,schema:{body:{type:`object`,required:[`queries`],properties:{queries:{type:`array`,items:{type:`object`}}}}}},async(t,n)=>{try{let{queries:r}=t.body;return!r||!Array.isArray(r)?n.status(400).send(e.i(`Request body must contain a "queries" array`,400)):r.length===0?n.status(400).send(e.i(`Queries array cannot be empty`,400)):await e.u(r,await _(t),v,{skipCache:t.headers[`x-cache-control`]===`no-cache`})}catch(r){return t.log.error(r,`Batch execution error`),n.status(500).send(e.i(r instanceof Error?r.message:`Batch execution failed`,500))}}),r.get(`${f}/meta`,async(t,n)=>{try{return e.a(v.getMetadata())}catch(r){return t.log.error(r,`Metadata error`),n.status(500).send(e.i(r instanceof Error?r.message:`Failed to fetch metadata`,500))}}),r.post(`${f}/sql`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(t,n)=>{try{let r=t.body,i=await _(t),a=v.validateQuery(r);if(!a.isValid)return n.status(400).send(e.i(`Query validation failed: ${a.errors.join(`, `)}`,400));let o=r.measures?.[0]||r.dimensions?.[0];if(!o)return n.status(400).send(e.i(`No measures or dimensions specified`,400));let s=o.split(`.`)[0];return e.o(r,await v.generateSQL(s,r,i))}catch(r){return t.log.error({err:String(r).replace(/\n|\r/g,``)},`SQL generation error`),n.status(500).send(e.i(r instanceof Error?r.message:`SQL generation failed`,500))}}),r.get(`${f}/sql`,{schema:{querystring:{type:`object`,properties:{query:{type:`string`}},required:[`query`]}}},async(t,n)=>{try{let{query:r}=t.query,i=JSON.parse(r),a=await _(t),o=v.validateQuery(i);if(!o.isValid)return n.status(400).send(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=i.measures?.[0]||i.dimensions?.[0];if(!s)return n.status(400).send(e.i(`No measures or dimensions specified`,400));let c=s.split(`.`)[0];return e.o(i,await v.generateSQL(c,i,a))}catch(r){return t.log.error({err:String(r).replace(/\n|\r/g,``)},`SQL generation error`),n.status(500).send(e.i(r instanceof Error?r.message:`SQL generation failed`,500))}}),r.post(`${f}/dry-run`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(t,n)=>{try{let n=t.body;return await e.f(n.query||n,await _(t),v)}catch(e){return t.log.error(e,`Dry-run error`),n.status(400).send({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),r.get(`${f}/dry-run`,{schema:{querystring:{type:`object`,properties:{query:{type:`string`}},required:[`query`]}}},async(t,n)=>{try{let{query:n}=t.query;return await e.f(JSON.parse(n),await _(t),v)}catch(e){return t.log.error(e,`Dry-run error`),n.status(400).send({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),r.post(`${f}/explain`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(e,t)=>{try{let n=e.body,r=n.query||n,i=n.options||{},a=await _(e),o=v.validateQuery(r);return o.isValid?await v.explainQuery(r,a,i):t.status(400).send({error:`Query validation failed: ${o.errors.join(`, `)}`})}catch(n){return e.log.error(n,`Explain error`),t.status(500).send({error:n instanceof Error?n.message:`Explain query failed`})}}),g&&r.post(`${f}/agent/chat`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(e,t)=>{try{let{handleAgentChat:n}=await Promise.resolve().then(()=>require(`../handler-CNn3q29F.cjs`)),{message:r,sessionId:i,history:a}=e.body;if(!r||typeof r!=`string`)return t.status(400).send({error:`message is required and must be a string`});let o=(g.apiKey||``).trim();if(g.allowClientApiKey){let t=e.headers[`x-agent-api-key`];t&&(o=t.trim())}if(!o)return t.status(401).send({error:`No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header.`});let s=g.allowClientApiKey?e.headers[`x-agent-provider`]:void 0,c=g.allowClientApiKey?e.headers[`x-agent-model`]:void 0,l=g.allowClientApiKey?e.headers[`x-agent-provider-endpoint`]:void 0,u=await _(e),d=g.buildSystemContext?.(u);t.raw.writeHead(200,{"Content-Type":`text/event-stream`,"Cache-Control":`no-cache`,Connection:`keep-alive`});try{let e=n({message:r,sessionId:i,history:a,semanticLayer:v,securityContext:u,agentConfig:g,apiKey:o,systemContext:d,providerOverride:s,modelOverride:c,baseURLOverride:l});for await(let n of e)t.raw.write(`data: ${JSON.stringify(n)}\n\n`)}catch(e){let n={type:`error`,data:{message:e instanceof Error?e.message:`Stream failed`}};t.raw.write(`data: ${JSON.stringify(n)}\n\n`)}finally{t.raw.end()}}catch(n){if(e.log.error(n,`Agent chat error`),!t.raw.headersSent)return t.status(500).send({error:n instanceof Error?n.message:`Agent chat failed`})}}),h.enabled!==!1){let e=n.o(v,h.resources),t=n.y(h.prompts),i=n.v(h.instructions),a=h.basePath??`/mcp`;r.post(`${a}`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(r,a)=>{if(h.resourceMetadataUrl&&!n.u(r.headers.authorization))return a.header(`WWW-Authenticate`,n.c(h.resourceMetadataUrl)),a.status(401).send({error:`Bearer token required`});let o=n.S(r.headers.origin,h.allowedOrigins?{allowedOrigins:h.allowedOrigins}:{});if(!o.valid)return a.status(403).send(n.i(null,-32600,o.reason));let s=r.headers.accept;if(!n.x(s))return a.status(400).send(n.i(null,-32600,`Accept header must include both application/json and text/event-stream`));let c=n.h(r.headers);if(!c.ok)return a.status(426).send({error:`Unsupported MCP protocol version`,supported:c.supported});let l=n.g(r.body);if(!l)return a.status(400).send(n.i(null,-32600,`Invalid JSON-RPC 2.0 request`));let u=n.C(s),d=l.method===`initialize`;try{let o=await n.l(l.method,l.params,{semanticLayer:v,extractSecurityContext:(e,t)=>_(e),rawRequest:r,rawResponse:a,negotiatedProtocol:c.negotiated,resources:e,prompts:t,instructions:i,appEnabled:!!h.app,appConfig:typeof h.app==`object`?h.app:void 0,serverName:h.serverName});if(n.m(l))return a.status(202).send();let s=d&&o&&typeof o==`object`&&`sessionId`in o?o.sessionId:void 0;s&&a.header(n.r,s);let f=n.a(l.id??null,o);if(u){let e=n._();a.header(`Content-Type`,`text/event-stream`).header(`Cache-Control`,`no-cache`).header(`Connection`,`keep-alive`).send(`id: ${e}\n\n${n.b(f,e)}`);return}return a.send(f)}catch(e){if(n.m(l))return r.log.error({err:String(e).replace(/\n|\r/g,``)},`MCP notification processing error`),a.status(202).send();r.log.error({err:String(e).replace(/\n|\r/g,``)},`MCP RPC error`);let t=e?.code??-32603,i=e?.data,o=e.message||`MCP request failed`,s=n.i(l.id??null,t,o,i);if(u){let e=n._();a.header(`Content-Type`,`text/event-stream`).header(`Cache-Control`,`no-cache`).header(`Connection`,`keep-alive`).send(`id: ${e}\n\n${n.b(s,e)}`);return}return a.send(s)}}),r.get(`${a}`,async(e,t)=>{if(h.resourceMetadataUrl&&!n.u(e.headers.authorization))return t.header(`WWW-Authenticate`,n.c(h.resourceMetadataUrl)),t.status(401).send({error:`Bearer token required`});let r=n._();t.raw.writeHead(200,{"Content-Type":`text/event-stream`,"Cache-Control":`no-cache`,Connection:`keep-alive`}),t.raw.write(n.b({jsonrpc:`2.0`,method:`mcp/ready`,params:{protocol:`streamable-http`}},r,15e3));let i=setInterval(()=>{t.raw.write(`: keep-alive
|
|
2
2
|
|
|
3
|
-
`)},15e3);e.raw.on(`close`,()=>{clearInterval(i)})}),r.delete(`${
|
|
3
|
+
`)},15e3);e.raw.on(`close`,()=>{clearInterval(i)})}),r.delete(`${a}`,async(e,t)=>h.resourceMetadataUrl&&!n.u(e.headers.authorization)?(t.header(`WWW-Authenticate`,n.c(h.resourceMetadataUrl)),t.status(401).send({error:`Bearer token required`})):t.status(405).send({error:`Session termination not supported`}))}r.setErrorHandler(async(t,n,r)=>(n.log.error(t,`Fastify cube adapter error`),r.statusCode<400&&r.status(500),e.i(t instanceof Error?t:String(t),r.statusCode))),a()};async function i(e,t){await e.register(r,t)}function a(e){let t=require(`fastify`)({logger:!0});return t.register(r,e),t}exports.createCubeApp=a,exports.cubePlugin=r,exports.registerCubeRoutes=i;
|