drizzle-cube 0.4.23 → 0.4.24
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 +1 -1
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/{handler-t7Qd1IYi.js → handler-BV2_dul8.js} +1 -1
- package/dist/adapters/{handler-C3hT7g2W.cjs → handler-LMRPeTNJ.cjs} +1 -1
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +1 -1
- package/dist/{server/index-CFEJ62GJ.js → adapters/index-C3PskWTr.js} +209 -193
- package/dist/{server/index-BIMhF5KZ.cjs → adapters/index-ht4NPca9.cjs} +11 -11
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/{openai-mLo2MCat.cjs → openai-BvA6eLs8.cjs} +1 -1
- package/dist/adapters/{openai-CUSRuKTk.js → openai-mcE24du8.js} +1 -1
- package/dist/client/chunks/{analysis-builder-DVrv9Q4n.js → analysis-builder-KeTsXp1G.js} +141 -141
- package/dist/client/chunks/{analysis-builder-DVrv9Q4n.js.map → analysis-builder-KeTsXp1G.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-shared-CrENEvEk.js → analysis-builder-shared-KSvGUzx6.js} +2 -2
- package/dist/client/chunks/{analysis-builder-shared-CrENEvEk.js.map → analysis-builder-shared-KSvGUzx6.js.map} +1 -1
- package/dist/client/chunks/{components-GzooQM5J.js → components-Dz6XHgnZ.js} +49 -49
- package/dist/client/chunks/{components-GzooQM5J.js.map → components-Dz6XHgnZ.js.map} +1 -1
- package/dist/client/components/AgenticNotebook/NotebookCanvas.d.ts +4 -1
- package/dist/client/components/AgenticNotebook/NotebookPortletBlock.d.ts +2 -0
- package/dist/client/components.js +3 -3
- package/dist/client/index.js +678 -672
- package/dist/client/index.js.map +1 -1
- package/dist/client-bundle-stats.html +1 -1
- package/dist/{adapters/index-CFEJ62GJ.js → server/index-C3PskWTr.js} +209 -193
- package/dist/{adapters/index-BIMhF5KZ.cjs → server/index-ht4NPca9.cjs} +11 -11
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/{openai-mLo2MCat.cjs → openai-BvA6eLs8.cjs} +1 -1
- package/dist/server/{openai-CUSRuKTk.js → openai-mcE24du8.js} +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("express"),H=require("cors"),c=require("../mcp-transport-DCiSGtp1.cjs"),n=require("../utils.cjs");function $(C){const{cubes:v,drizzle:x,schema:I,extractSecurityContext:y,engineType:P,cors:S,basePath:f="/cubejs-api/v1",jsonLimit:Q="10mb",cache:O,mcp:E={enabled:!0},agent:h}=C;if(!v||v.length===0)throw new Error("At least one cube must be provided in the cubes array");const d=w.Router();S&&d.use(H(S)),d.use(w.json({limit:Q})),d.use(w.urlencoded({extended:!0,limit:Q}));const u=new c.SemanticLayerCompiler({drizzle:x,schema:I,engineType:P,cache:O});if(v.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],R=await u.generateSQL(m,o,s);t.json(n.formatSqlResponse(o,R))}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"})}}),h&&d.post(`${f}/agent/chat`,async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("express"),H=require("cors"),c=require("../mcp-transport-DCiSGtp1.cjs"),n=require("../utils.cjs");function $(C){const{cubes:v,drizzle:x,schema:I,extractSecurityContext:y,engineType:P,cors:S,basePath:f="/cubejs-api/v1",jsonLimit:Q="10mb",cache:O,mcp:E={enabled:!0},agent:h}=C;if(!v||v.length===0)throw new Error("At least one cube must be provided in the cubes array");const d=w.Router();S&&d.use(H(S)),d.use(w.json({limit:Q})),d.use(w.urlencoded({extended:!0,limit:Q}));const u=new c.SemanticLayerCompiler({drizzle:x,schema:I,engineType:P,cache:O});if(v.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],R=await u.generateSQL(m,o,s);t.json(n.formatSqlResponse(o,R))}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"})}}),h&&d.post(`${f}/agent/chat`,async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-LMRPeTNJ.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=(h.apiKey||"").trim();if(h.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=h.allowClientApiKey?r.headers["x-agent-provider"]:void 0,R=h.allowClientApiKey?r.headers["x-agent-model"]:void 0,l=h.allowClientApiKey?r.headers["x-agent-provider-endpoint"]:void 0,g=await y(r,t),b=h.buildSystemContext?.(g);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:g,agentConfig:h,apiKey:i,systemContext:b,providerOverride:m,modelOverride:R,baseURLOverride:l});for await(const j of p)t.write(`data: ${JSON.stringify(j)}
|
|
2
2
|
|
|
3
3
|
`)}catch(p){const j={type:"error",data:{message:p instanceof Error?p.message:"Stream failed"}};t.write(`data: ${JSON.stringify(j)}
|
|
4
4
|
|
|
@@ -198,7 +198,7 @@ function W(v) {
|
|
|
198
198
|
}
|
|
199
199
|
}), m && 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-BV2_dul8.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
204
|
let s = (m.apiKey || "").trim();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var N=Object.create;var j=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var D=(l,n,v,S)=>{if(n&&typeof n=="object"||typeof n=="function")for(let f of J(n))!K.call(l,f)&&f!==v&&j(l,f,{get:()=>n[f],enumerable:!(S=k(n,f))||S.enumerable});return l};var H=(l,n,v)=>(v=l!=null?N(L(l)):{},D(n||!l||!l.__esModule?j(v,"default",{value:l,enumerable:!0}):v,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../mcp-transport-DCiSGtp1.cjs"),a=require("../utils.cjs"),Q=function(n,v,S){const{cubes:f,drizzle:A,schema:I,extractSecurityContext:m,engineType:O,cors:$,basePath:g="/cubejs-api/v1",bodyLimit:C=10485760,cache:M,mcp:q={enabled:!0},agent:b}=v;if(!f||f.length===0)return S(new Error("At least one cube must be provided in the cubes array"));$&&n.register(import("@fastify/cors"),$),n.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const u=new d.SemanticLayerCompiler({drizzle:A,schema:I,engineType:O,cache:M});if(f.forEach(r=>{u.registerCube(r)}),n.post(`${g}/load`,{bodyLimit:C,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await m(r),i=u.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",p=await u.executeMultiCubeQuery(o,s,{skipCache:c});return a.formatCubeResponse(o,p,u)}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=u.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",p=await u.executeMultiCubeQuery(o,s,{skipCache:c});return a.formatCubeResponse(o,p,u)}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:C,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,u,{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=u.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:C,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await m(r),s=u.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],p=await u.generateSQL(c,e,o);return a.formatSqlResponse(e,p)}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=u.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 p=c.split(".")[0],P=await u.generateSQL(p,o,s);return a.formatSqlResponse(o,P)}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:C,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,u)}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,u)}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:C,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=u.validateQuery(o);return c.isValid?await u.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"})}}),b&&n.post(`${g}/agent/chat`,{bodyLimit:C,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-
|
|
1
|
+
"use strict";var N=Object.create;var j=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var D=(l,n,v,S)=>{if(n&&typeof n=="object"||typeof n=="function")for(let f of J(n))!K.call(l,f)&&f!==v&&j(l,f,{get:()=>n[f],enumerable:!(S=k(n,f))||S.enumerable});return l};var H=(l,n,v)=>(v=l!=null?N(L(l)):{},D(n||!l||!l.__esModule?j(v,"default",{value:l,enumerable:!0}):v,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../mcp-transport-DCiSGtp1.cjs"),a=require("../utils.cjs"),Q=function(n,v,S){const{cubes:f,drizzle:A,schema:I,extractSecurityContext:m,engineType:O,cors:$,basePath:g="/cubejs-api/v1",bodyLimit:C=10485760,cache:M,mcp:q={enabled:!0},agent:b}=v;if(!f||f.length===0)return S(new Error("At least one cube must be provided in the cubes array"));$&&n.register(import("@fastify/cors"),$),n.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const u=new d.SemanticLayerCompiler({drizzle:A,schema:I,engineType:O,cache:M});if(f.forEach(r=>{u.registerCube(r)}),n.post(`${g}/load`,{bodyLimit:C,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await m(r),i=u.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",p=await u.executeMultiCubeQuery(o,s,{skipCache:c});return a.formatCubeResponse(o,p,u)}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=u.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",p=await u.executeMultiCubeQuery(o,s,{skipCache:c});return a.formatCubeResponse(o,p,u)}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:C,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,u,{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=u.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:C,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await m(r),s=u.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],p=await u.generateSQL(c,e,o);return a.formatSqlResponse(e,p)}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=u.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 p=c.split(".")[0],P=await u.generateSQL(p,o,s);return a.formatSqlResponse(o,P)}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:C,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,u)}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,u)}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:C,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=u.validateQuery(o);return c.isValid?await u.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"})}}),b&&n.post(`${g}/agent/chat`,{bodyLimit:C,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-LMRPeTNJ.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 p=(b.apiKey||"").trim();if(b.allowClientApiKey){const h=r.headers["x-agent-api-key"];h&&(p=h.trim())}if(!p)return t.status(401).send({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const P=b.allowClientApiKey?r.headers["x-agent-provider"]:void 0,y=b.allowClientApiKey?r.headers["x-agent-model"]:void 0,E=b.allowClientApiKey?r.headers["x-agent-provider-endpoint"]:void 0,w=await m(r),R=b.buildSystemContext?.(w);t.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const h=e({message:s,sessionId:i,history:c,semanticLayer:u,securityContext:w,agentConfig:b,apiKey:p,systemContext:R,providerOverride:P,modelOverride:y,baseURLOverride:E});for await(const x of h)t.raw.write(`data: ${JSON.stringify(x)}
|
|
2
2
|
|
|
3
3
|
`)}catch(h){const x={type:"error",data:{message:h instanceof Error?h.message:"Stream failed"}};t.raw.write(`data: ${JSON.stringify(x)}
|
|
4
4
|
|
|
@@ -262,7 +262,7 @@ const M = function(i, N, $) {
|
|
|
262
262
|
}
|
|
263
263
|
}, async (t, r) => {
|
|
264
264
|
try {
|
|
265
|
-
const { handleAgentChat: e } = await import("../handler-
|
|
265
|
+
const { handleAgentChat: e } = await import("../handler-BV2_dul8.js"), a = t.body, { message: n, sessionId: o, history: s } = a;
|
|
266
266
|
if (!n || typeof n != "string")
|
|
267
267
|
return r.status(400).send({ error: "message is required and must be a string" });
|
|
268
268
|
let u = (h.apiKey || "").trim();
|
|
@@ -2444,7 +2444,7 @@ async function Ve(d, s, a) {
|
|
|
2444
2444
|
return new o(s);
|
|
2445
2445
|
}
|
|
2446
2446
|
case "openai": {
|
|
2447
|
-
const { OpenAIProvider: o } = await import("./openai-
|
|
2447
|
+
const { OpenAIProvider: o } = await import("./openai-mcE24du8.js");
|
|
2448
2448
|
return new o(s, a);
|
|
2449
2449
|
}
|
|
2450
2450
|
case "google": {
|
|
@@ -32,7 +32,7 @@ ${JSON.stringify(t,null,2)}`,isError:!0};const p=!!(t.funnel||t.flow||t.retentio
|
|
|
32
32
|
${u.errors.join(`
|
|
33
33
|
`)}`,isError:!0};l=b}const i=`portlet-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,g={id:i,title:e.title,query:e.query,chartType:r,chartConfig:l,displayConfig:e.displayConfig};return{result:`Portlet "${e.title}" added to notebook (id: ${i}, chart: ${r}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,sideEffect:{type:"add_portlet",data:g}}}),o.set("add_markdown",async e=>{const n=`markdown-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,r=e.content||e.text||e.markdown||"",t={id:n,title:e.title,content:r};return{result:`Markdown block added to notebook (id: ${n}). [Reminder: in your next response, start with a brief sentence about what you will do next BEFORE making any tool calls.]`,sideEffect:{type:"add_markdown",data:t}}}),o.set("save_as_dashboard",async e=>{try{const n=e.portlets;if(!n||n.length===0)return{result:"Dashboard must contain at least one portlet.",isError:!0};const r=[];for(const i of n){if(i.chartType==="markdown")continue;const b=i.query;if(!b){r.push(`Portlet "${i.title}": missing query`);continue}let u;try{u=JSON.parse(b)}catch{r.push(`Portlet "${i.title}": invalid JSON query`);continue}const x=s.validateQuery(u);x.isValid||r.push(`Portlet "${i.title}": ${x.errors.join(", ")}`)}if(r.length>0)return{result:`Dashboard has invalid portlets — fix these errors and retry:
|
|
34
34
|
${r.join(`
|
|
35
|
-
`)}`,isError:!0};const t={portlets:n.map(i=>{const g=i.chartType,b=g==="markdown",u=b?"query":i.analysisType||"query",x=u==="funnel"?"funnel":u==="flow"?"flow":u==="retention"?"retention":"query",D=i.query||"{}";let A;try{A=JSON.parse(D)}catch{A={}}const C={version:1,analysisType:x,activeView:"chart",charts:{[x]:{chartType:g,chartConfig:i.chartConfig||{},displayConfig:i.displayConfig||{}}},query:b?{}:A};return{id:i.id,title:i.title,analysisConfig:C,dashboardFilterMapping:i.dashboardFilterMapping,w:i.w,h:i.h,x:i.x,y:i.y}}),filters:e.filters,colorPalette:e.colorPalette},m=e.title,p=t.portlets.length,l=t.filters?.length||0;return{result:`Dashboard "${m}" created with ${p} portlets and ${l} filters.`,sideEffect:{type:"dashboard_saved",data:{title:m,description:e.description,dashboardConfig:t}}}}catch(n){return{result:`Failed to save dashboard: ${n instanceof Error?n.message:"Unknown error"}`,isError:!0}}}),o}async function De(d,s,a){switch(d){case"anthropic":{const{AnthropicProvider:o}=await Promise.resolve().then(()=>require("./anthropic-BTkjgFpT.cjs"));return new o(s)}case"openai":{const{OpenAIProvider:o}=await Promise.resolve().then(()=>require("./openai-
|
|
35
|
+
`)}`,isError:!0};const t={portlets:n.map(i=>{const g=i.chartType,b=g==="markdown",u=b?"query":i.analysisType||"query",x=u==="funnel"?"funnel":u==="flow"?"flow":u==="retention"?"retention":"query",D=i.query||"{}";let A;try{A=JSON.parse(D)}catch{A={}}const C={version:1,analysisType:x,activeView:"chart",charts:{[x]:{chartType:g,chartConfig:i.chartConfig||{},displayConfig:i.displayConfig||{}}},query:b?{}:A};return{id:i.id,title:i.title,analysisConfig:C,dashboardFilterMapping:i.dashboardFilterMapping,w:i.w,h:i.h,x:i.x,y:i.y}}),filters:e.filters,colorPalette:e.colorPalette},m=e.title,p=t.portlets.length,l=t.filters?.length||0;return{result:`Dashboard "${m}" created with ${p} portlets and ${l} filters.`,sideEffect:{type:"dashboard_saved",data:{title:m,description:e.description,dashboardConfig:t}}}}catch(n){return{result:`Failed to save dashboard: ${n instanceof Error?n.message:"Unknown error"}`,isError:!0}}}),o}async function De(d,s,a){switch(d){case"anthropic":{const{AnthropicProvider:o}=await Promise.resolve().then(()=>require("./anthropic-BTkjgFpT.cjs"));return new o(s)}case"openai":{const{OpenAIProvider:o}=await Promise.resolve().then(()=>require("./openai-BvA6eLs8.cjs"));return new o(s,a)}case"google":{const{GoogleProvider:o}=await Promise.resolve().then(()=>require("./google-BAK9pnQf.cjs"));return new o(s)}default:throw new Error(`Unknown LLM provider: "${d}". Supported providers: anthropic, openai, google`)}}const Se={anthropic:"claude-sonnet-4-6",openai:"gpt-4.1-mini",google:"gemini-3-flash-preview"};async function*Fe(d){const{message:s,history:a,semanticLayer:o,securityContext:y,agentConfig:h,apiKey:e}=d,n=d.sessionId||crypto.randomUUID(),r=h.observability,t=crypto.randomUUID(),m=Date.now(),p=d.providerOverride||h.provider||"anthropic",l=d.modelOverride||h.model||Se[p]||"claude-sonnet-4-6",i=d.baseURLOverride||h.baseURL,g=h.maxTurns||25,b=h.maxTokens||4096;let u;try{u=await De(p,e,{baseURL:i})}catch(f){console.error(`[agent] Failed to create ${p} provider:`,f),yield{type:"error",data:{message:f instanceof Error?f.message:"Failed to initialize LLM provider"}};return}const x=Te(),D=Ae({semanticLayer:o,securityContext:y}),A=o.getMetadata();let C=G(A);d.systemContext&&(C+=`
|
|
36
36
|
|
|
37
37
|
## User Context
|
|
38
38
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("hono"),a=require("../mcp-transport-DCiSGtp1.cjs"),R=require("../utils.cjs");var L=g=>{const y={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...g},T=(d=>typeof d=="string"?d==="*"?()=>d:c=>d===c?c:null:typeof d=="function"?d:c=>d.includes(c)?c:null)(y.origin),h=(d=>typeof d=="function"?d:Array.isArray(d)?()=>d:()=>[])(y.allowMethods);return async function(c,q){function b(f,i){c.res.headers.set(f,i)}const E=await T(c.req.header("origin")||"",c);if(E&&b("Access-Control-Allow-Origin",E),y.credentials&&b("Access-Control-Allow-Credentials","true"),y.exposeHeaders?.length&&b("Access-Control-Expose-Headers",y.exposeHeaders.join(",")),c.req.method==="OPTIONS"){y.origin!=="*"&&b("Vary","Origin"),y.maxAge!=null&&b("Access-Control-Max-Age",y.maxAge.toString());const f=await h(c.req.header("origin")||"",c);f.length&&b("Access-Control-Allow-Methods",f.join(","));let i=y.allowHeaders;if(!i?.length){const s=c.req.header("Access-Control-Request-Headers");s&&(i=s.split(/\s*,\s*/))}return i?.length&&(b("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,{headers:c.res.headers,status:204,statusText:"No Content"})}await q(),y.origin!=="*"&&c.header("Vary","Origin",{append:!0})}};function N(g){const{cubes:j,drizzle:y,schema:T,extractSecurityContext:h,engineType:d,cors:c,basePath:q="/cubejs-api/v1",cache:b,mcp:E={enabled:!0},agent:f}=g;if(!g.semanticLayer&&(!j||j.length===0))throw new Error("Either semanticLayer or a non-empty cubes array must be provided");const i=new M.Hono;c&&i.use("/*",L(c));const s=g.semanticLayer??new a.SemanticLayerCompiler({drizzle:y,schema:T,engineType:d,cache:b});if(!g.semanticLayer&&j&&j.forEach(e=>{s.registerCube(e)}),i.post(`${q}/load`,async e=>{try{const r=await e.req.json(),n=r.query||r,o=await h(e),t=s.validateQuery(n);if(!t.isValid)return e.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=e.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return e.json(R.formatCubeResponse(n,l,s))}catch(r){return console.error("Query execution error:",r),e.json({error:r instanceof Error?r.message:"Query execution failed"},500)}}),i.get(`${q}/load`,async e=>{try{const r=e.req.query("query");if(!r)return e.json({error:"Query parameter is required"},400);let n;try{n=JSON.parse(r)}catch{return e.json({error:"Invalid JSON in query parameter"},400)}const o=await h(e),t=s.validateQuery(n);if(!t.isValid)return e.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=e.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return e.json(R.formatCubeResponse(n,l,s))}catch(r){return console.error("Query execution error:",r),e.json({error:r instanceof Error?r.message:"Query execution failed"},500)}}),i.post(`${q}/batch`,async e=>{try{const r=await e.req.json(),{queries:n}=r;if(!n||!Array.isArray(n))return e.json({error:'Request body must contain a "queries" array'},400);if(n.length===0)return e.json({error:"Queries array cannot be empty"},400);const o=await h(e),t=e.req.header("x-cache-control")==="no-cache",u=await R.handleBatchRequest(n,o,s,{skipCache:t});return e.json(u)}catch(r){return console.error("Batch execution error:",r),e.json({error:r instanceof Error?r.message:"Batch execution failed"},500)}}),i.get(`${q}/meta`,e=>{try{const r=s.getMetadata();return e.json(R.formatMetaResponse(r))}catch(r){return console.error("Metadata error:",r),e.json({error:r instanceof Error?r.message:"Failed to fetch metadata"},500)}}),i.post(`${q}/sql`,async e=>{try{const r=await e.req.json(),n=await h(e),o=s.validateQuery(r);if(!o.isValid)return e.json({error:`Query validation failed: ${o.errors.join(", ")}`},400);const t=r.measures?.[0]||r.dimensions?.[0];if(!t)return e.json({error:"No measures or dimensions specified"},400);const u=t.split(".")[0],l=await s.generateSQL(u,r,n);return e.json(R.formatSqlResponse(r,l))}catch(r){return console.error("SQL generation error:",r),e.json({error:r instanceof Error?r.message:"SQL generation failed"},500)}}),i.get(`${q}/sql`,async e=>{try{const r=e.req.query("query");if(!r)return e.json({error:"Query parameter is required"},400);const n=JSON.parse(r),o=await h(e),t=s.validateQuery(n);if(!t.isValid)return e.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=n.measures?.[0]||n.dimensions?.[0];if(!u)return e.json({error:"No measures or dimensions specified"},400);const l=u.split(".")[0],v=await s.generateSQL(l,n,o);return e.json(R.formatSqlResponse(n,v))}catch(r){return console.error("SQL generation error:",r),e.json({error:r instanceof Error?r.message:"SQL generation failed"},500)}}),i.post(`${q}/dry-run`,async e=>{try{const r=await e.req.json(),n=r.query||r,o=await h(e),t=await R.handleDryRun(n,o,s);return e.json(t)}catch(r){return console.error("Dry-run error:",r),e.json({error:r instanceof Error?r.message:"Dry-run validation failed",valid:!1},400)}}),i.get(`${q}/dry-run`,async e=>{try{const r=e.req.query("query");if(!r)return e.json({error:"Query parameter is required",valid:!1},400);const n=JSON.parse(r),o=await h(e),t=await R.handleDryRun(n,o,s);return e.json(t)}catch(r){return console.error("Dry-run error:",r),e.json({error:r instanceof Error?r.message:"Dry-run validation failed",valid:!1},400)}}),i.post(`${q}/explain`,async e=>{try{const r=await e.req.json(),n=r.query||r,o=r.options||{},t=await h(e),u=s.validateQuery(n);if(!u.isValid)return e.json({error:`Query validation failed: ${u.errors.join(", ")}`},400);const l=await s.explainQuery(n,t,o);return e.json(l)}catch(r){return console.error("Explain error:",r),e.json({error:r instanceof Error?r.message:"Explain query failed"},500)}}),f&&i.post(`${q}/agent/chat`,async e=>{try{const{handleAgentChat:r}=await Promise.resolve().then(()=>require("../handler-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("hono"),a=require("../mcp-transport-DCiSGtp1.cjs"),R=require("../utils.cjs");var L=g=>{const y={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...g},T=(d=>typeof d=="string"?d==="*"?()=>d:c=>d===c?c:null:typeof d=="function"?d:c=>d.includes(c)?c:null)(y.origin),h=(d=>typeof d=="function"?d:Array.isArray(d)?()=>d:()=>[])(y.allowMethods);return async function(c,q){function b(f,i){c.res.headers.set(f,i)}const E=await T(c.req.header("origin")||"",c);if(E&&b("Access-Control-Allow-Origin",E),y.credentials&&b("Access-Control-Allow-Credentials","true"),y.exposeHeaders?.length&&b("Access-Control-Expose-Headers",y.exposeHeaders.join(",")),c.req.method==="OPTIONS"){y.origin!=="*"&&b("Vary","Origin"),y.maxAge!=null&&b("Access-Control-Max-Age",y.maxAge.toString());const f=await h(c.req.header("origin")||"",c);f.length&&b("Access-Control-Allow-Methods",f.join(","));let i=y.allowHeaders;if(!i?.length){const s=c.req.header("Access-Control-Request-Headers");s&&(i=s.split(/\s*,\s*/))}return i?.length&&(b("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,{headers:c.res.headers,status:204,statusText:"No Content"})}await q(),y.origin!=="*"&&c.header("Vary","Origin",{append:!0})}};function N(g){const{cubes:j,drizzle:y,schema:T,extractSecurityContext:h,engineType:d,cors:c,basePath:q="/cubejs-api/v1",cache:b,mcp:E={enabled:!0},agent:f}=g;if(!g.semanticLayer&&(!j||j.length===0))throw new Error("Either semanticLayer or a non-empty cubes array must be provided");const i=new M.Hono;c&&i.use("/*",L(c));const s=g.semanticLayer??new a.SemanticLayerCompiler({drizzle:y,schema:T,engineType:d,cache:b});if(!g.semanticLayer&&j&&j.forEach(e=>{s.registerCube(e)}),i.post(`${q}/load`,async e=>{try{const r=await e.req.json(),n=r.query||r,o=await h(e),t=s.validateQuery(n);if(!t.isValid)return e.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=e.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return e.json(R.formatCubeResponse(n,l,s))}catch(r){return console.error("Query execution error:",r),e.json({error:r instanceof Error?r.message:"Query execution failed"},500)}}),i.get(`${q}/load`,async e=>{try{const r=e.req.query("query");if(!r)return e.json({error:"Query parameter is required"},400);let n;try{n=JSON.parse(r)}catch{return e.json({error:"Invalid JSON in query parameter"},400)}const o=await h(e),t=s.validateQuery(n);if(!t.isValid)return e.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=e.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return e.json(R.formatCubeResponse(n,l,s))}catch(r){return console.error("Query execution error:",r),e.json({error:r instanceof Error?r.message:"Query execution failed"},500)}}),i.post(`${q}/batch`,async e=>{try{const r=await e.req.json(),{queries:n}=r;if(!n||!Array.isArray(n))return e.json({error:'Request body must contain a "queries" array'},400);if(n.length===0)return e.json({error:"Queries array cannot be empty"},400);const o=await h(e),t=e.req.header("x-cache-control")==="no-cache",u=await R.handleBatchRequest(n,o,s,{skipCache:t});return e.json(u)}catch(r){return console.error("Batch execution error:",r),e.json({error:r instanceof Error?r.message:"Batch execution failed"},500)}}),i.get(`${q}/meta`,e=>{try{const r=s.getMetadata();return e.json(R.formatMetaResponse(r))}catch(r){return console.error("Metadata error:",r),e.json({error:r instanceof Error?r.message:"Failed to fetch metadata"},500)}}),i.post(`${q}/sql`,async e=>{try{const r=await e.req.json(),n=await h(e),o=s.validateQuery(r);if(!o.isValid)return e.json({error:`Query validation failed: ${o.errors.join(", ")}`},400);const t=r.measures?.[0]||r.dimensions?.[0];if(!t)return e.json({error:"No measures or dimensions specified"},400);const u=t.split(".")[0],l=await s.generateSQL(u,r,n);return e.json(R.formatSqlResponse(r,l))}catch(r){return console.error("SQL generation error:",r),e.json({error:r instanceof Error?r.message:"SQL generation failed"},500)}}),i.get(`${q}/sql`,async e=>{try{const r=e.req.query("query");if(!r)return e.json({error:"Query parameter is required"},400);const n=JSON.parse(r),o=await h(e),t=s.validateQuery(n);if(!t.isValid)return e.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=n.measures?.[0]||n.dimensions?.[0];if(!u)return e.json({error:"No measures or dimensions specified"},400);const l=u.split(".")[0],v=await s.generateSQL(l,n,o);return e.json(R.formatSqlResponse(n,v))}catch(r){return console.error("SQL generation error:",r),e.json({error:r instanceof Error?r.message:"SQL generation failed"},500)}}),i.post(`${q}/dry-run`,async e=>{try{const r=await e.req.json(),n=r.query||r,o=await h(e),t=await R.handleDryRun(n,o,s);return e.json(t)}catch(r){return console.error("Dry-run error:",r),e.json({error:r instanceof Error?r.message:"Dry-run validation failed",valid:!1},400)}}),i.get(`${q}/dry-run`,async e=>{try{const r=e.req.query("query");if(!r)return e.json({error:"Query parameter is required",valid:!1},400);const n=JSON.parse(r),o=await h(e),t=await R.handleDryRun(n,o,s);return e.json(t)}catch(r){return console.error("Dry-run error:",r),e.json({error:r instanceof Error?r.message:"Dry-run validation failed",valid:!1},400)}}),i.post(`${q}/explain`,async e=>{try{const r=await e.req.json(),n=r.query||r,o=r.options||{},t=await h(e),u=s.validateQuery(n);if(!u.isValid)return e.json({error:`Query validation failed: ${u.errors.join(", ")}`},400);const l=await s.explainQuery(n,t,o);return e.json(l)}catch(r){return console.error("Explain error:",r),e.json({error:r instanceof Error?r.message:"Explain query failed"},500)}}),f&&i.post(`${q}/agent/chat`,async e=>{try{const{handleAgentChat:r}=await Promise.resolve().then(()=>require("../handler-LMRPeTNJ.cjs")),n=await e.req.json(),{message:o,sessionId:t,history:u}=n;if(!o||typeof o!="string")return e.json({error:"message is required and must be a string"},400);let l=(f.apiKey||"").trim();if(f.allowClientApiKey){const C=e.req.header("x-agent-api-key");C&&(l=C.trim())}if(!l)return e.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},401);const v=f.allowClientApiKey?e.req.header("x-agent-provider"):void 0,Q=f.allowClientApiKey?e.req.header("x-agent-model"):void 0,m=f.allowClientApiKey?e.req.header("x-agent-provider-endpoint"):void 0,P=await h(e),H=f.buildSystemContext?.(P),p=new TextEncoder,A=new ReadableStream({async start(C){try{const w=r({message:o,sessionId:t,history:u,semanticLayer:s,securityContext:P,agentConfig:f,apiKey:l,systemContext:H,providerOverride:v,modelOverride:Q,baseURLOverride:m});for await(const x of w){const S=`data: ${JSON.stringify(x)}
|
|
2
2
|
|
|
3
3
|
`;C.enqueue(p.encode(S))}}catch(w){const x={type:"error",data:{message:w instanceof Error?w.message:"Stream failed"}};C.enqueue(p.encode(`data: ${JSON.stringify(x)}
|
|
4
4
|
|
|
@@ -212,7 +212,7 @@ function te(g) {
|
|
|
212
212
|
}
|
|
213
213
|
}), p && a.post(`${h}/agent/chat`, async (e) => {
|
|
214
214
|
try {
|
|
215
|
-
const { handleAgentChat: r } = await import("../handler-
|
|
215
|
+
const { handleAgentChat: r } = await import("../handler-BV2_dul8.js"), n = await e.req.json(), { message: o, sessionId: t, history: c } = n;
|
|
216
216
|
if (!o || typeof o != "string")
|
|
217
217
|
return e.json({ error: "message is required and must be a string" }, 400);
|
|
218
218
|
let u = (p.apiKey || "").trim();
|