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,7 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("hono"),i=require("../mcp-transport-KX92EgkF.cjs"),v=require("../utils.cjs");var D=w=>{const p={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...w},I=(y=>typeof y=="string"?y==="*"?()=>y:u=>y===u?u:null:typeof y=="function"?y:u=>y.includes(u)?u:null)(p.origin),m=(y=>typeof y=="function"?y:Array.isArray(y)?()=>y:()=>[])(p.allowMethods);return async function(u,h){function g(C,c){u.res.headers.set(C,c)}const b=await I(u.req.header("origin")||"",u);if(b&&g("Access-Control-Allow-Origin",b),p.credentials&&g("Access-Control-Allow-Credentials","true"),p.exposeHeaders?.length&&g("Access-Control-Expose-Headers",p.exposeHeaders.join(",")),u.req.method==="OPTIONS"){p.origin!=="*"&&g("Vary","Origin"),p.maxAge!=null&&g("Access-Control-Max-Age",p.maxAge.toString());const C=await m(u.req.header("origin")||"",u);C.length&&g("Access-Control-Allow-Methods",C.join(","));let c=p.allowHeaders;if(!c?.length){const s=u.req.header("Access-Control-Request-Headers");s&&(c=s.split(/\s*,\s*/))}return c?.length&&(g("Access-Control-Allow-Headers",c.join(",")),u.res.headers.append("Vary","Access-Control-Request-Headers")),u.res.headers.delete("Content-Length"),u.res.headers.delete("Content-Type"),new Response(null,{headers:u.res.headers,status:204,statusText:"No Content"})}await h(),p.origin!=="*"&&u.header("Vary","Origin",{append:!0})}};function O(w){const{cubes:j,drizzle:p,schema:I,extractSecurityContext:m,engineType:y,cors:u,basePath:h="/cubejs-api/v1",cache:g,mcp:b={enabled:!0},agent:C}=w;if(!j||j.length===0)throw new Error("At least one cube must be provided in the cubes array");const c=new N.Hono;u&&c.use("/*",D(u));const s=new i.SemanticLayerCompiler({drizzle:p,schema:I,engineType:y,cache:g});if(j.forEach(r=>{s.registerCube(r)}),c.post(`${h}/load`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const a=r.req.header("x-cache-control")==="no-cache",d=await s.executeMultiCubeQuery(n,o,{skipCache:a});return r.json(v.formatCubeResponse(n,d,s))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),c.get(`${h}/load`,async r=>{try{const e=r.req.query("query");if(!e)return r.json({error:"Query parameter is required"},400);let n;try{n=JSON.parse(e)}catch{return r.json({error:"Invalid JSON in query parameter"},400)}const o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const a=r.req.header("x-cache-control")==="no-cache",d=await s.executeMultiCubeQuery(n,o,{skipCache:a});return r.json(v.formatCubeResponse(n,d,s))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),c.post(`${h}/batch`,async r=>{try{const e=await r.req.json(),{queries:n}=e;if(!n||!Array.isArray(n))return r.json({error:'Request body must contain a "queries" array'},400);if(n.length===0)return r.json({error:"Queries array cannot be empty"},400);const o=await m(r),t=r.req.header("x-cache-control")==="no-cache",a=await v.handleBatchRequest(n,o,s,{skipCache:t});return r.json(a)}catch(e){return console.error("Batch execution error:",e),r.json({error:e instanceof Error?e.message:"Batch execution failed"},500)}}),c.get(`${h}/meta`,r=>{try{const e=s.getMetadata();return r.json(v.formatMetaResponse(e))}catch(e){return console.error("Metadata error:",e),r.json({error:e instanceof Error?e.message:"Failed to fetch metadata"},500)}}),c.post(`${h}/sql`,async r=>{try{const e=await r.req.json(),n=await m(r),o=s.validateQuery(e);if(!o.isValid)return r.json({error:`Query validation failed: ${o.errors.join(", ")}`},400);const t=e.measures?.[0]||e.dimensions?.[0];if(!t)return r.json({error:"No measures or dimensions specified"},400);const a=t.split(".")[0],d=await s.generateSQL(a,e,n);return r.json(v.formatSqlResponse(e,d))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),c.get(`${h}/sql`,async r=>{try{const e=r.req.query("query");if(!e)return r.json({error:"Query parameter is required"},400);const n=JSON.parse(e),o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const a=n.measures?.[0]||n.dimensions?.[0];if(!a)return r.json({error:"No measures or dimensions specified"},400);const d=a.split(".")[0],q=await s.generateSQL(d,n,o);return r.json(v.formatSqlResponse(n,q))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),c.post(`${h}/dry-run`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=await m(r),t=await v.handleDryRun(n,o,s);return r.json(t)}catch(e){return console.error("Dry-run error:",e),r.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},400)}}),c.get(`${h}/dry-run`,async r=>{try{const e=r.req.query("query");if(!e)return r.json({error:"Query parameter is required",valid:!1},400);const n=JSON.parse(e),o=await m(r),t=await v.handleDryRun(n,o,s);return r.json(t)}catch(e){return console.error("Dry-run error:",e),r.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},400)}}),c.post(`${h}/explain`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=e.options||{},t=await m(r),a=s.validateQuery(n);if(!a.isValid)return r.json({error:`Query validation failed: ${a.errors.join(", ")}`},400);const d=await s.explainQuery(n,t,o);return r.json(d)}catch(e){return console.error("Explain error:",e),r.json({error:e instanceof Error?e.message:"Explain query failed"},500)}}),C&&c.post(`${h}/agent/chat`,async r=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-BLcxTuwi.cjs")),n=await r.req.json(),{message:o,sessionId:t}=n;if(!o||typeof o!="string")return r.json({error:"message is required and must be a string"},400);let a=(C.apiKey||"").trim();if(C.allowClientApiKey){const l=r.req.header("x-agent-api-key");l&&(a=l.trim())}if(!a)return r.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},401);const d=await m(r),q=new TextEncoder,R=new ReadableStream({async start(l){try{const x=e({message:o,sessionId:t,semanticLayer:s,securityContext:d,agentConfig:C,apiKey:a});for await(const E of x){const f=`data: ${JSON.stringify(E)}
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`;l.enqueue(q.encode(f))}}catch(x){const E={type:"error",data:{message:x instanceof Error?x.message:"Stream failed"}};l.enqueue(q.encode(`data: ${JSON.stringify(E)}
|
|
4
4
|
|
|
5
|
-
`))
|
|
5
|
+
`))}finally{l.close()}}});return new Response(R,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}catch(e){return console.error("Agent chat error:",e),r.json({error:e instanceof Error?e.message:"Agent chat failed"},500)}}),b.enabled!==!1){const r={uri:"drizzle-cube://schema",name:"Cube Schema",description:"Current cube metadata as JSON",mimeType:"application/json",text:JSON.stringify(s.getMetadata(),null,2)},e=[...i.getDefaultResources(),r],n=i.getDefaultPrompts(),o=b.basePath??"/mcp";c.post(`${o}`,async t=>{const a=i.validateOriginHeader(t.req.header("origin"),b.allowedOrigins?{allowedOrigins:b.allowedOrigins}:{});if(!a.valid)return t.json(i.buildJsonRpcError(null,-32600,a.reason),403);const d=t.req.header("accept");if(!i.validateAcceptHeader(d))return t.json(i.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),400);const q=i.negotiateProtocol(t.req.header());if(!q.ok)return t.json({error:"Unsupported MCP protocol version",supported:q.supported},426);const R=await t.req.json().catch(()=>null),l=i.parseJsonRpc(R);if(!l)return t.json(i.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),400);const x=i.wantsEventStream(d),E=l.method==="initialize";try{const f=await i.dispatchMcpMethod(l.method,l.params,{semanticLayer:s,extractSecurityContext:m,rawRequest:t,rawResponse:null,negotiatedProtocol:q.negotiated,resources:e,prompts:n});if(i.isNotification(l))return t.body(null,202);const $=i.buildJsonRpcResult(l.id??null,f),T=E&&f&&typeof f=="object"&&"sessionId"in f?f.sessionId:void 0,S={};if(T&&(S[i.MCP_SESSION_ID_HEADER]=T),x){const A=new TextEncoder,Q=i.primeEventId(),H=new ReadableStream({start(P){P.enqueue(A.encode(`id: ${Q}
|
|
6
6
|
|
|
7
|
-
`))
|
|
7
|
+
`)),P.enqueue(A.encode(i.serializeSseEvent($,Q))),P.close()}});return new Response(H,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...S}})}return t.json($,200,S)}catch(f){if(i.isNotification(l))return console.error("MCP notification processing error:",f),t.body(null,202);console.error("MCP RPC error:",f);const $=f?.code??-32603,T=f?.data,S=f.message||"MCP request failed",A=i.buildJsonRpcError(l.id??null,$,S,T);if(x){const Q=new TextEncoder,H=i.primeEventId(),P=new ReadableStream({start(M){M.enqueue(Q.encode(`id: ${H}
|
|
8
|
+
|
|
9
|
+
`)),M.enqueue(Q.encode(i.serializeSseEvent(A,H))),M.close()}});return new Response(P,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}return t.json(A,200)}}),c.delete(`${o}`,t=>t.json({error:"Session termination not supported"},405)),c.get(`${o}`,t=>{const a=new TextEncoder,d=i.primeEventId();let q;const R=new ReadableStream({start(l){l.enqueue(a.encode(i.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},d,15e3))),q=setInterval(()=>{l.enqueue(a.encode(`: keep-alive
|
|
10
|
+
|
|
11
|
+
`))},15e3)},cancel(){clearInterval(q)}});return new Response(R,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})})}return c}function J(w,j){const p=O(j);return w.route("/",p),w}function k(w){const j=new N.Hono;return J(j,w)}exports.createCubeApp=k;exports.createCubeRoutes=O;exports.mountCubeRoutes=J;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
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';
|
|
@@ -72,6 +73,12 @@ export interface HonoAdapterOptions {
|
|
|
72
73
|
* @default { enabled: true }
|
|
73
74
|
*/
|
|
74
75
|
mcp?: MCPOptions;
|
|
76
|
+
/**
|
|
77
|
+
* Agent configuration for the agentic AI notebook feature.
|
|
78
|
+
* When provided, enables the POST /agent/chat SSE endpoint.
|
|
79
|
+
* Requires `@anthropic-ai/sdk` as a peer dependency.
|
|
80
|
+
*/
|
|
81
|
+
agent?: AgentConfig;
|
|
75
82
|
}
|
|
76
83
|
/**
|
|
77
84
|
* Create Hono routes for Cube.js-compatible API
|
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
import { Hono as
|
|
2
|
-
import { S as
|
|
3
|
-
import { formatCubeResponse as
|
|
4
|
-
var
|
|
5
|
-
const
|
|
1
|
+
import { Hono as L } from "hono";
|
|
2
|
+
import { S as V, v as B, b as M, a as z, n as K, p as _, w as U, d as F, g as G, f as X, i as O, c as W, M as Y, e as T, s as I } from "../mcp-transport-CU5g9bxj.js";
|
|
3
|
+
import { formatCubeResponse as k, handleBatchRequest as Z, formatMetaResponse as ee, formatSqlResponse as D, handleDryRun as J } from "../utils.js";
|
|
4
|
+
var re = (w) => {
|
|
5
|
+
const y = {
|
|
6
6
|
...{
|
|
7
7
|
origin: "*",
|
|
8
8
|
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
9
9
|
allowHeaders: [],
|
|
10
10
|
exposeHeaders: []
|
|
11
11
|
},
|
|
12
|
-
...
|
|
13
|
-
},
|
|
14
|
-
return async function(
|
|
15
|
-
function
|
|
16
|
-
|
|
12
|
+
...w
|
|
13
|
+
}, H = /* @__PURE__ */ ((d) => typeof d == "string" ? d === "*" ? () => d : (c) => d === c ? c : null : typeof d == "function" ? d : (c) => d.includes(c) ? c : null)(y.origin), f = ((d) => typeof d == "function" ? d : Array.isArray(d) ? () => d : () => [])(y.allowMethods);
|
|
14
|
+
return async function(c, m) {
|
|
15
|
+
function g(q, i) {
|
|
16
|
+
c.res.headers.set(q, i);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
if (!
|
|
25
|
-
const
|
|
26
|
-
|
|
18
|
+
const j = await H(c.req.header("origin") || "", c);
|
|
19
|
+
if (j && g("Access-Control-Allow-Origin", j), y.credentials && g("Access-Control-Allow-Credentials", "true"), y.exposeHeaders?.length && g("Access-Control-Expose-Headers", y.exposeHeaders.join(",")), c.req.method === "OPTIONS") {
|
|
20
|
+
y.origin !== "*" && g("Vary", "Origin"), y.maxAge != null && g("Access-Control-Max-Age", y.maxAge.toString());
|
|
21
|
+
const q = await f(c.req.header("origin") || "", c);
|
|
22
|
+
q.length && g("Access-Control-Allow-Methods", q.join(","));
|
|
23
|
+
let i = y.allowHeaders;
|
|
24
|
+
if (!i?.length) {
|
|
25
|
+
const s = c.req.header("Access-Control-Request-Headers");
|
|
26
|
+
s && (i = s.split(/\s*,\s*/));
|
|
27
27
|
}
|
|
28
|
-
return
|
|
29
|
-
headers:
|
|
28
|
+
return i?.length && (g("Access-Control-Allow-Headers", i.join(",")), c.res.headers.append("Vary", "Access-Control-Request-Headers")), c.res.headers.delete("Content-Length"), c.res.headers.delete("Content-Type"), new Response(null, {
|
|
29
|
+
headers: c.res.headers,
|
|
30
30
|
status: 204,
|
|
31
31
|
statusText: "No Content"
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
await
|
|
34
|
+
await m(), y.origin !== "*" && c.header("Vary", "Origin", { append: !0 });
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
function
|
|
37
|
+
function te(w) {
|
|
38
38
|
const {
|
|
39
|
-
cubes:
|
|
40
|
-
drizzle:
|
|
41
|
-
schema:
|
|
42
|
-
extractSecurityContext:
|
|
43
|
-
engineType:
|
|
44
|
-
cors:
|
|
45
|
-
basePath:
|
|
46
|
-
cache:
|
|
47
|
-
mcp:
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
cubes: C,
|
|
40
|
+
drizzle: y,
|
|
41
|
+
schema: H,
|
|
42
|
+
extractSecurityContext: f,
|
|
43
|
+
engineType: d,
|
|
44
|
+
cors: c,
|
|
45
|
+
basePath: m = "/cubejs-api/v1",
|
|
46
|
+
cache: g,
|
|
47
|
+
mcp: j = { enabled: !0 },
|
|
48
|
+
agent: q
|
|
49
|
+
} = w;
|
|
50
|
+
if (!C || C.length === 0)
|
|
50
51
|
throw new Error("At least one cube must be provided in the cubes array");
|
|
51
|
-
const i = new
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
drizzle:
|
|
55
|
-
schema:
|
|
56
|
-
engineType:
|
|
57
|
-
cache:
|
|
52
|
+
const i = new L();
|
|
53
|
+
c && i.use("/*", re(c));
|
|
54
|
+
const s = new V({
|
|
55
|
+
drizzle: y,
|
|
56
|
+
schema: H,
|
|
57
|
+
engineType: d,
|
|
58
|
+
cache: g
|
|
58
59
|
});
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
}), i.post(`${
|
|
60
|
+
if (C.forEach((r) => {
|
|
61
|
+
s.registerCube(r);
|
|
62
|
+
}), i.post(`${m}/load`, async (r) => {
|
|
62
63
|
try {
|
|
63
|
-
const e = await r.req.json(), n = e.query || e,
|
|
64
|
+
const e = await r.req.json(), n = e.query || e, o = await f(r), t = s.validateQuery(n);
|
|
64
65
|
if (!t.isValid)
|
|
65
66
|
return r.json({
|
|
66
67
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
67
68
|
}, 400);
|
|
68
|
-
const
|
|
69
|
-
return r.json(
|
|
69
|
+
const a = r.req.header("x-cache-control") === "no-cache", l = await s.executeMultiCubeQuery(n, o, { skipCache: a });
|
|
70
|
+
return r.json(k(n, l, s));
|
|
70
71
|
} catch (e) {
|
|
71
72
|
return console.error("Query execution error:", e), r.json({
|
|
72
73
|
error: e instanceof Error ? e.message : "Query execution failed"
|
|
73
74
|
}, 500);
|
|
74
75
|
}
|
|
75
|
-
}), i.get(`${
|
|
76
|
+
}), i.get(`${m}/load`, async (r) => {
|
|
76
77
|
try {
|
|
77
78
|
const e = r.req.query("query");
|
|
78
79
|
if (!e)
|
|
@@ -87,19 +88,19 @@ function re(q) {
|
|
|
87
88
|
error: "Invalid JSON in query parameter"
|
|
88
89
|
}, 400);
|
|
89
90
|
}
|
|
90
|
-
const
|
|
91
|
+
const o = await f(r), t = s.validateQuery(n);
|
|
91
92
|
if (!t.isValid)
|
|
92
93
|
return r.json({
|
|
93
94
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
94
95
|
}, 400);
|
|
95
|
-
const
|
|
96
|
-
return r.json(
|
|
96
|
+
const a = r.req.header("x-cache-control") === "no-cache", l = await s.executeMultiCubeQuery(n, o, { skipCache: a });
|
|
97
|
+
return r.json(k(n, l, s));
|
|
97
98
|
} catch (e) {
|
|
98
99
|
return console.error("Query execution error:", e), r.json({
|
|
99
100
|
error: e instanceof Error ? e.message : "Query execution failed"
|
|
100
101
|
}, 500);
|
|
101
102
|
}
|
|
102
|
-
}), i.post(`${
|
|
103
|
+
}), i.post(`${m}/batch`, async (r) => {
|
|
103
104
|
try {
|
|
104
105
|
const e = await r.req.json(), { queries: n } = e;
|
|
105
106
|
if (!n || !Array.isArray(n))
|
|
@@ -110,68 +111,68 @@ function re(q) {
|
|
|
110
111
|
return r.json({
|
|
111
112
|
error: "Queries array cannot be empty"
|
|
112
113
|
}, 400);
|
|
113
|
-
const
|
|
114
|
-
return r.json(
|
|
114
|
+
const o = await f(r), t = r.req.header("x-cache-control") === "no-cache", a = await Z(n, o, s, { skipCache: t });
|
|
115
|
+
return r.json(a);
|
|
115
116
|
} catch (e) {
|
|
116
117
|
return console.error("Batch execution error:", e), r.json({
|
|
117
118
|
error: e instanceof Error ? e.message : "Batch execution failed"
|
|
118
119
|
}, 500);
|
|
119
120
|
}
|
|
120
|
-
}), i.get(`${
|
|
121
|
+
}), i.get(`${m}/meta`, (r) => {
|
|
121
122
|
try {
|
|
122
|
-
const e =
|
|
123
|
-
return r.json(
|
|
123
|
+
const e = s.getMetadata();
|
|
124
|
+
return r.json(ee(e));
|
|
124
125
|
} catch (e) {
|
|
125
126
|
return console.error("Metadata error:", e), r.json({
|
|
126
127
|
error: e instanceof Error ? e.message : "Failed to fetch metadata"
|
|
127
128
|
}, 500);
|
|
128
129
|
}
|
|
129
|
-
}), i.post(`${
|
|
130
|
+
}), i.post(`${m}/sql`, async (r) => {
|
|
130
131
|
try {
|
|
131
|
-
const e = await r.req.json(), n = await
|
|
132
|
-
if (!
|
|
132
|
+
const e = await r.req.json(), n = await f(r), o = s.validateQuery(e);
|
|
133
|
+
if (!o.isValid)
|
|
133
134
|
return r.json({
|
|
134
|
-
error: `Query validation failed: ${
|
|
135
|
+
error: `Query validation failed: ${o.errors.join(", ")}`
|
|
135
136
|
}, 400);
|
|
136
137
|
const t = e.measures?.[0] || e.dimensions?.[0];
|
|
137
138
|
if (!t)
|
|
138
139
|
return r.json({
|
|
139
140
|
error: "No measures or dimensions specified"
|
|
140
141
|
}, 400);
|
|
141
|
-
const
|
|
142
|
-
return r.json(
|
|
142
|
+
const a = t.split(".")[0], l = await s.generateSQL(a, e, n);
|
|
143
|
+
return r.json(D(e, l));
|
|
143
144
|
} catch (e) {
|
|
144
145
|
return console.error("SQL generation error:", e), r.json({
|
|
145
146
|
error: e instanceof Error ? e.message : "SQL generation failed"
|
|
146
147
|
}, 500);
|
|
147
148
|
}
|
|
148
|
-
}), i.get(`${
|
|
149
|
+
}), i.get(`${m}/sql`, async (r) => {
|
|
149
150
|
try {
|
|
150
151
|
const e = r.req.query("query");
|
|
151
152
|
if (!e)
|
|
152
153
|
return r.json({
|
|
153
154
|
error: "Query parameter is required"
|
|
154
155
|
}, 400);
|
|
155
|
-
const n = JSON.parse(e),
|
|
156
|
+
const n = JSON.parse(e), o = await f(r), t = s.validateQuery(n);
|
|
156
157
|
if (!t.isValid)
|
|
157
158
|
return r.json({
|
|
158
159
|
error: `Query validation failed: ${t.errors.join(", ")}`
|
|
159
160
|
}, 400);
|
|
160
|
-
const
|
|
161
|
-
if (!
|
|
161
|
+
const a = n.measures?.[0] || n.dimensions?.[0];
|
|
162
|
+
if (!a)
|
|
162
163
|
return r.json({
|
|
163
164
|
error: "No measures or dimensions specified"
|
|
164
165
|
}, 400);
|
|
165
|
-
const
|
|
166
|
-
return r.json(
|
|
166
|
+
const l = a.split(".")[0], h = await s.generateSQL(l, n, o);
|
|
167
|
+
return r.json(D(n, h));
|
|
167
168
|
} catch (e) {
|
|
168
169
|
return console.error("SQL generation error:", e), r.json({
|
|
169
170
|
error: e instanceof Error ? e.message : "SQL generation failed"
|
|
170
171
|
}, 500);
|
|
171
172
|
}
|
|
172
|
-
}), i.post(`${
|
|
173
|
+
}), i.post(`${m}/dry-run`, async (r) => {
|
|
173
174
|
try {
|
|
174
|
-
const e = await r.req.json(), n = e.query || e,
|
|
175
|
+
const e = await r.req.json(), n = e.query || e, o = await f(r), t = await J(n, o, s);
|
|
175
176
|
return r.json(t);
|
|
176
177
|
} catch (e) {
|
|
177
178
|
return console.error("Dry-run error:", e), r.json({
|
|
@@ -179,7 +180,7 @@ function re(q) {
|
|
|
179
180
|
valid: !1
|
|
180
181
|
}, 400);
|
|
181
182
|
}
|
|
182
|
-
}), i.get(`${
|
|
183
|
+
}), i.get(`${m}/dry-run`, async (r) => {
|
|
183
184
|
try {
|
|
184
185
|
const e = r.req.query("query");
|
|
185
186
|
if (!e)
|
|
@@ -187,7 +188,7 @@ function re(q) {
|
|
|
187
188
|
error: "Query parameter is required",
|
|
188
189
|
valid: !1
|
|
189
190
|
}, 400);
|
|
190
|
-
const n = JSON.parse(e),
|
|
191
|
+
const n = JSON.parse(e), o = await f(r), t = await J(n, o, s);
|
|
191
192
|
return r.json(t);
|
|
192
193
|
} catch (e) {
|
|
193
194
|
return console.error("Dry-run error:", e), r.json({
|
|
@@ -195,98 +196,155 @@ function re(q) {
|
|
|
195
196
|
valid: !1
|
|
196
197
|
}, 400);
|
|
197
198
|
}
|
|
198
|
-
}), i.post(`${
|
|
199
|
+
}), i.post(`${m}/explain`, async (r) => {
|
|
199
200
|
try {
|
|
200
|
-
const e = await r.req.json(), n = e.query || e,
|
|
201
|
-
if (!
|
|
201
|
+
const e = await r.req.json(), n = e.query || e, o = e.options || {}, t = await f(r), a = s.validateQuery(n);
|
|
202
|
+
if (!a.isValid)
|
|
202
203
|
return r.json({
|
|
203
|
-
error: `Query validation failed: ${
|
|
204
|
+
error: `Query validation failed: ${a.errors.join(", ")}`
|
|
204
205
|
}, 400);
|
|
205
|
-
const
|
|
206
|
-
return r.json(
|
|
206
|
+
const l = await s.explainQuery(n, t, o);
|
|
207
|
+
return r.json(l);
|
|
207
208
|
} catch (e) {
|
|
208
209
|
return console.error("Explain error:", e), r.json({
|
|
209
210
|
error: e instanceof Error ? e.message : "Explain query failed"
|
|
210
211
|
}, 500);
|
|
211
212
|
}
|
|
212
|
-
}),
|
|
213
|
+
}), q && i.post(`${m}/agent/chat`, async (r) => {
|
|
214
|
+
try {
|
|
215
|
+
const { handleAgentChat: e } = await import("../handler-odjn7MIB.js"), n = await r.req.json(), { message: o, sessionId: t } = n;
|
|
216
|
+
if (!o || typeof o != "string")
|
|
217
|
+
return r.json({ error: "message is required and must be a string" }, 400);
|
|
218
|
+
let a = (q.apiKey || "").trim();
|
|
219
|
+
if (q.allowClientApiKey) {
|
|
220
|
+
const u = r.req.header("x-agent-api-key");
|
|
221
|
+
u && (a = u.trim());
|
|
222
|
+
}
|
|
223
|
+
if (!a)
|
|
224
|
+
return r.json({
|
|
225
|
+
error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
|
|
226
|
+
}, 401);
|
|
227
|
+
const l = await f(r), h = new TextEncoder(), x = new ReadableStream({
|
|
228
|
+
async start(u) {
|
|
229
|
+
try {
|
|
230
|
+
const v = e({
|
|
231
|
+
message: o,
|
|
232
|
+
sessionId: t,
|
|
233
|
+
semanticLayer: s,
|
|
234
|
+
securityContext: l,
|
|
235
|
+
agentConfig: q,
|
|
236
|
+
apiKey: a
|
|
237
|
+
});
|
|
238
|
+
for await (const b of v) {
|
|
239
|
+
const p = `data: ${JSON.stringify(b)}
|
|
240
|
+
|
|
241
|
+
`;
|
|
242
|
+
u.enqueue(h.encode(p));
|
|
243
|
+
}
|
|
244
|
+
} catch (v) {
|
|
245
|
+
const b = {
|
|
246
|
+
type: "error",
|
|
247
|
+
data: { message: v instanceof Error ? v.message : "Stream failed" }
|
|
248
|
+
};
|
|
249
|
+
u.enqueue(h.encode(`data: ${JSON.stringify(b)}
|
|
250
|
+
|
|
251
|
+
`));
|
|
252
|
+
} finally {
|
|
253
|
+
u.close();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return new Response(x, {
|
|
258
|
+
status: 200,
|
|
259
|
+
headers: {
|
|
260
|
+
"Content-Type": "text/event-stream",
|
|
261
|
+
"Cache-Control": "no-cache",
|
|
262
|
+
Connection: "keep-alive"
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
} catch (e) {
|
|
266
|
+
return console.error("Agent chat error:", e), r.json({
|
|
267
|
+
error: e instanceof Error ? e.message : "Agent chat failed"
|
|
268
|
+
}, 500);
|
|
269
|
+
}
|
|
270
|
+
}), j.enabled !== !1) {
|
|
213
271
|
const r = {
|
|
214
272
|
uri: "drizzle-cube://schema",
|
|
215
273
|
name: "Cube Schema",
|
|
216
274
|
description: "Current cube metadata as JSON",
|
|
217
275
|
mimeType: "application/json",
|
|
218
|
-
text: JSON.stringify(
|
|
219
|
-
}, e = [...
|
|
220
|
-
i.post(`${
|
|
221
|
-
const
|
|
276
|
+
text: JSON.stringify(s.getMetadata(), null, 2)
|
|
277
|
+
}, e = [...X(), r], n = G(), o = j.basePath ?? "/mcp";
|
|
278
|
+
i.post(`${o}`, async (t) => {
|
|
279
|
+
const a = B(
|
|
222
280
|
t.req.header("origin"),
|
|
223
|
-
|
|
281
|
+
j.allowedOrigins ? { allowedOrigins: j.allowedOrigins } : {}
|
|
224
282
|
);
|
|
225
|
-
if (!
|
|
226
|
-
return t.json(
|
|
227
|
-
const
|
|
228
|
-
if (!
|
|
229
|
-
return t.json(
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
283
|
+
if (!a.valid)
|
|
284
|
+
return t.json(M(null, -32600, a.reason), 403);
|
|
285
|
+
const l = t.req.header("accept");
|
|
286
|
+
if (!z(l))
|
|
287
|
+
return t.json(M(null, -32600, "Accept header must include both application/json and text/event-stream"), 400);
|
|
288
|
+
const h = K(t.req.header());
|
|
289
|
+
if (!h.ok)
|
|
232
290
|
return t.json({
|
|
233
291
|
error: "Unsupported MCP protocol version",
|
|
234
|
-
supported:
|
|
292
|
+
supported: h.supported
|
|
235
293
|
}, 426);
|
|
236
|
-
const
|
|
237
|
-
if (!
|
|
238
|
-
return t.json(
|
|
239
|
-
const
|
|
294
|
+
const x = await t.req.json().catch(() => null), u = _(x);
|
|
295
|
+
if (!u)
|
|
296
|
+
return t.json(M(null, -32600, "Invalid JSON-RPC 2.0 request"), 400);
|
|
297
|
+
const v = U(l), b = u.method === "initialize";
|
|
240
298
|
try {
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
299
|
+
const p = await F(
|
|
300
|
+
u.method,
|
|
301
|
+
u.params,
|
|
244
302
|
{
|
|
245
|
-
semanticLayer:
|
|
246
|
-
extractSecurityContext:
|
|
303
|
+
semanticLayer: s,
|
|
304
|
+
extractSecurityContext: f,
|
|
247
305
|
rawRequest: t,
|
|
248
306
|
rawResponse: null,
|
|
249
|
-
negotiatedProtocol:
|
|
307
|
+
negotiatedProtocol: h.negotiated,
|
|
250
308
|
resources: e,
|
|
251
309
|
prompts: n
|
|
252
310
|
}
|
|
253
311
|
);
|
|
254
|
-
if (
|
|
312
|
+
if (O(u))
|
|
255
313
|
return t.body(null, 202);
|
|
256
|
-
const
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
259
|
-
start(
|
|
260
|
-
|
|
314
|
+
const Q = W(u.id ?? null, p), P = b && p && typeof p == "object" && "sessionId" in p ? p.sessionId : void 0, R = {};
|
|
315
|
+
if (P && (R[Y] = P), v) {
|
|
316
|
+
const S = new TextEncoder(), E = T(), $ = new ReadableStream({
|
|
317
|
+
start(A) {
|
|
318
|
+
A.enqueue(S.encode(`id: ${E}
|
|
261
319
|
|
|
262
|
-
`)),
|
|
320
|
+
`)), A.enqueue(S.encode(I(Q, E))), A.close();
|
|
263
321
|
}
|
|
264
322
|
});
|
|
265
|
-
return new Response(
|
|
323
|
+
return new Response($, {
|
|
266
324
|
status: 200,
|
|
267
325
|
headers: {
|
|
268
326
|
"Content-Type": "text/event-stream",
|
|
269
327
|
"Cache-Control": "no-cache",
|
|
270
328
|
Connection: "keep-alive",
|
|
271
|
-
...
|
|
329
|
+
...R
|
|
272
330
|
}
|
|
273
331
|
});
|
|
274
332
|
}
|
|
275
|
-
return t.json(
|
|
276
|
-
} catch (
|
|
277
|
-
if (
|
|
278
|
-
return console.error("MCP notification processing error:",
|
|
279
|
-
console.error("MCP RPC error:",
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
282
|
-
const
|
|
283
|
-
start(
|
|
284
|
-
|
|
333
|
+
return t.json(Q, 200, R);
|
|
334
|
+
} catch (p) {
|
|
335
|
+
if (O(u))
|
|
336
|
+
return console.error("MCP notification processing error:", p), t.body(null, 202);
|
|
337
|
+
console.error("MCP RPC error:", p);
|
|
338
|
+
const Q = p?.code ?? -32603, P = p?.data, R = p.message || "MCP request failed", S = M(u.id ?? null, Q, R, P);
|
|
339
|
+
if (v) {
|
|
340
|
+
const E = new TextEncoder(), $ = T(), A = new ReadableStream({
|
|
341
|
+
start(N) {
|
|
342
|
+
N.enqueue(E.encode(`id: ${$}
|
|
285
343
|
|
|
286
|
-
`)),
|
|
344
|
+
`)), N.enqueue(E.encode(I(S, $))), N.close();
|
|
287
345
|
}
|
|
288
346
|
});
|
|
289
|
-
return new Response(
|
|
347
|
+
return new Response(A, {
|
|
290
348
|
status: 200,
|
|
291
349
|
headers: {
|
|
292
350
|
"Content-Type": "text/event-stream",
|
|
@@ -295,28 +353,28 @@ function re(q) {
|
|
|
295
353
|
}
|
|
296
354
|
});
|
|
297
355
|
}
|
|
298
|
-
return t.json(
|
|
356
|
+
return t.json(S, 200);
|
|
299
357
|
}
|
|
300
|
-
}), i.delete(`${
|
|
301
|
-
const
|
|
302
|
-
let
|
|
303
|
-
const
|
|
304
|
-
start(
|
|
305
|
-
|
|
358
|
+
}), i.delete(`${o}`, (t) => t.json({ error: "Session termination not supported" }, 405)), i.get(`${o}`, (t) => {
|
|
359
|
+
const a = new TextEncoder(), l = T();
|
|
360
|
+
let h;
|
|
361
|
+
const x = new ReadableStream({
|
|
362
|
+
start(u) {
|
|
363
|
+
u.enqueue(a.encode(I({
|
|
306
364
|
jsonrpc: "2.0",
|
|
307
365
|
method: "mcp/ready",
|
|
308
366
|
params: { protocol: "streamable-http" }
|
|
309
|
-
},
|
|
310
|
-
|
|
367
|
+
}, l, 15e3))), h = setInterval(() => {
|
|
368
|
+
u.enqueue(a.encode(`: keep-alive
|
|
311
369
|
|
|
312
370
|
`));
|
|
313
371
|
}, 15e3);
|
|
314
372
|
},
|
|
315
373
|
cancel() {
|
|
316
|
-
clearInterval(
|
|
374
|
+
clearInterval(h);
|
|
317
375
|
}
|
|
318
376
|
});
|
|
319
|
-
return new Response(
|
|
377
|
+
return new Response(x, {
|
|
320
378
|
status: 200,
|
|
321
379
|
headers: {
|
|
322
380
|
"Content-Type": "text/event-stream",
|
|
@@ -328,16 +386,16 @@ function re(q) {
|
|
|
328
386
|
}
|
|
329
387
|
return i;
|
|
330
388
|
}
|
|
331
|
-
function
|
|
332
|
-
const
|
|
333
|
-
return
|
|
389
|
+
function ne(w, C) {
|
|
390
|
+
const y = te(C);
|
|
391
|
+
return w.route("/", y), w;
|
|
334
392
|
}
|
|
335
|
-
function
|
|
336
|
-
const
|
|
337
|
-
return
|
|
393
|
+
function ie(w) {
|
|
394
|
+
const C = new L();
|
|
395
|
+
return ne(C, w);
|
|
338
396
|
}
|
|
339
397
|
export {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
398
|
+
ie as createCubeApp,
|
|
399
|
+
te as createCubeRoutes,
|
|
400
|
+
ne as mountCubeRoutes
|
|
343
401
|
};
|