drizzle-cube 0.4.10 → 0.4.11

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("express"),M=require("cors"),c=require("../mcp-transport-KX92EgkF.cjs"),n=require("../utils.cjs");function $(g){const{cubes:m,drizzle:w,schema:P,extractSecurityContext:y,engineType:A,cors:x,basePath:f="/cubejs-api/v1",jsonLimit:S="10mb",cache:H,mcp:v={enabled:!0},agent:j}=g;if(!m||m.length===0)throw new Error("At least one cube must be provided in the cubes array");const d=R.Router();x&&d.use(M(x)),d.use(R.json({limit:S})),d.use(R.urlencoded({extended:!0,limit:S}));const u=new c.SemanticLayerCompiler({drizzle:w,schema:P,engineType:A,cache:H});if(m.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),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const s=r.headers["x-cache-control"]==="no-cache",i=await u.executeMultiCubeQuery(e,o,{skipCache:s});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 a=await y(r,t),s=u.validateQuery(o);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const i=r.headers["x-cache-control"]==="no-cache",l=await u.executeMultiCubeQuery(o,a,{skipCache:i});t.json(n.formatCubeResponse(o,l,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),a=r.headers["x-cache-control"]==="no-cache",s=await n.handleBatchRequest(e,o,u,{skipCache:a});t.json(s)}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),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const s=e.measures?.[0]||e.dimensions?.[0];if(!s)return t.status(400).json(n.formatErrorResponse("No measures or dimensions specified",400));const i=s.split(".")[0],l=await u.generateSQL(i,e,o);t.json(n.formatSqlResponse(e,l))}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),a=await y(r,t),s=u.validateQuery(o);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.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 l=i.split(".")[0],h=await u.generateSQL(l,o,a);t.json(n.formatSqlResponse(o,h))}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),a=await n.handleDryRun(e,o,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.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),a=await y(r,t),s=await n.handleDryRun(o,a,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.post(`${f}/explain`,async(r,t)=>{try{const e=r.body.query||r.body,o=r.body.options||{},a=await y(r,t),s=u.validateQuery(e);if(!s.isValid)return t.status(400).json({error:`Query validation failed: ${s.errors.join(", ")}`});const i=await u.explainQuery(e,a,o);t.json(i)}catch(e){console.error("Explain error:",e),t.status(500).json({error:e instanceof Error?e.message:"Explain query failed"})}}),j&&d.post(`${f}/agent/chat`,async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-e6zofK2k.cjs")),{message:o,sessionId:a}=r.body;if(!o||typeof o!="string")return t.status(400).json({error:"message is required and must be a string"});let s=(j.apiKey||"").trim();if(j.allowClientApiKey){const l=r.headers["x-agent-api-key"];l&&(s=l.trim())}if(!s)return t.status(401).json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const i=await y(r,t);t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const l=e({message:o,sessionId:a,semanticLayer:u,securityContext:i,agentConfig:j,apiKey:s});for await(const h of l)t.write(`data: ${JSON.stringify(h)}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("express"),M=require("cors"),c=require("../mcp-transport-8u9G5oNa.cjs"),n=require("../utils.cjs");function $(g){const{cubes:m,drizzle:w,schema:P,extractSecurityContext:y,engineType:A,cors:x,basePath:f="/cubejs-api/v1",jsonLimit:S="10mb",cache:H,mcp:v={enabled:!0},agent:j}=g;if(!m||m.length===0)throw new Error("At least one cube must be provided in the cubes array");const d=R.Router();x&&d.use(M(x)),d.use(R.json({limit:S})),d.use(R.urlencoded({extended:!0,limit:S}));const u=new c.SemanticLayerCompiler({drizzle:w,schema:P,engineType:A,cache:H});if(m.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),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const s=r.headers["x-cache-control"]==="no-cache",i=await u.executeMultiCubeQuery(e,o,{skipCache:s});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 a=await y(r,t),s=u.validateQuery(o);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const i=r.headers["x-cache-control"]==="no-cache",l=await u.executeMultiCubeQuery(o,a,{skipCache:i});t.json(n.formatCubeResponse(o,l,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),a=r.headers["x-cache-control"]==="no-cache",s=await n.handleBatchRequest(e,o,u,{skipCache:a});t.json(s)}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),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const s=e.measures?.[0]||e.dimensions?.[0];if(!s)return t.status(400).json(n.formatErrorResponse("No measures or dimensions specified",400));const i=s.split(".")[0],l=await u.generateSQL(i,e,o);t.json(n.formatSqlResponse(e,l))}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),a=await y(r,t),s=u.validateQuery(o);if(!s.isValid)return t.status(400).json(n.formatErrorResponse(`Query validation failed: ${s.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 l=i.split(".")[0],h=await u.generateSQL(l,o,a);t.json(n.formatSqlResponse(o,h))}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),a=await n.handleDryRun(e,o,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.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),a=await y(r,t),s=await n.handleDryRun(o,a,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.post(`${f}/explain`,async(r,t)=>{try{const e=r.body.query||r.body,o=r.body.options||{},a=await y(r,t),s=u.validateQuery(e);if(!s.isValid)return t.status(400).json({error:`Query validation failed: ${s.errors.join(", ")}`});const i=await u.explainQuery(e,a,o);t.json(i)}catch(e){console.error("Explain error:",e),t.status(500).json({error:e instanceof Error?e.message:"Explain query failed"})}}),j&&d.post(`${f}/agent/chat`,async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-dnkqpznh.cjs")),{message:o,sessionId:a}=r.body;if(!o||typeof o!="string")return t.status(400).json({error:"message is required and must be a string"});let s=(j.apiKey||"").trim();if(j.allowClientApiKey){const l=r.headers["x-agent-api-key"];l&&(s=l.trim())}if(!s)return t.status(401).json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const i=await y(r,t);t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const l=e({message:o,sessionId:a,semanticLayer:u,securityContext:i,agentConfig:j,apiKey:s});for await(const h of l)t.write(`data: ${JSON.stringify(h)}
2
2
 
3
3
  `)}catch(l){const h={type:"error",data:{message:l instanceof Error?l.message:"Stream failed"}};t.write(`data: ${JSON.stringify(h)}
4
4
 
@@ -1,6 +1,6 @@
1
1
  import E, { Router as J } from "express";
2
2
  import L from "cors";
3
- import { S as D, v as _, b as w, a as K, n as V, p as z, w as T, d as B, i as P, M as F, c as U, e as S, s as Q } from "../mcp-transport-CU5g9bxj.js";
3
+ import { S as D, v as _, b as w, a as K, n as V, p as z, w as T, d as B, i as P, M as F, c as U, e as S, s as Q } from "../mcp-transport-m1X1GtwG.js";
4
4
  import { formatErrorResponse as u, formatCubeResponse as A, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as H, handleDryRun as M } from "../utils.js";
5
5
  function W(h) {
6
6
  const {
@@ -198,7 +198,7 @@ function W(h) {
198
198
  }
199
199
  }), j && c.post(`${p}/agent/chat`, async (r, t) => {
200
200
  try {
201
- const { handleAgentChat: e } = await import("../handler-CySCodwi.js"), { message: o, sessionId: n } = r.body;
201
+ const { handleAgentChat: e } = await import("../handler-CQkIwtxp.js"), { message: o, sessionId: 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 a = (j.apiKey || "").trim();
@@ -1,4 +1,4 @@
1
- "use strict";var O=Object.create;var j=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var H=(l,n,b,C)=>{if(n&&typeof n=="object"||typeof n=="function")for(let f of J(n))!D.call(l,f)&&f!==b&&j(l,f,{get:()=>n[f],enumerable:!(C=k(n,f))||C.enumerable});return l};var T=(l,n,b)=>(b=l!=null?O(L(l)):{},H(n||!l||!l.__esModule?j(b,"default",{value:l,enumerable:!0}):b,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../mcp-transport-KX92EgkF.cjs"),i=require("../utils.cjs"),q=function(n,b,C){const{cubes:f,drizzle:I,schema:A,extractSecurityContext:g,engineType:M,cors:P,basePath:h="/cubejs-api/v1",bodyLimit:v=10485760,cache:N,mcp:E={enabled:!0},agent:R}=b;if(!f||f.length===0)return C(new Error("At least one cube must be provided in the cubes array"));P&&n.register(import("@fastify/cors"),P),n.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const d=new u.SemanticLayerCompiler({drizzle:I,schema:A,engineType:M,cache:N});if(f.forEach(r=>{d.registerCube(r)}),n.post(`${h}/load`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:a});return i.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.get(`${h}/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(i.formatErrorResponse("Invalid JSON in query parameter",400))}const s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:a});return i.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.post(`${h}/batch`,{bodyLimit:v,schema:{body:{type:"object",required:["queries"],properties:{queries:{type:"array",items:{type:"object"}}}}}},async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).send(i.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).send(i.formatErrorResponse("Queries array cannot be empty",400));const o=await g(r),s=r.headers["x-cache-control"]==="no-cache";return await i.handleBatchRequest(e,o,d,{skipCache:s})}catch(e){return r.log.error(e,"Batch execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),n.get(`${h}/meta`,async(r,t)=>{try{const e=d.getMetadata();return i.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),n.post(`${h}/sql`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await g(r),s=d.validateQuery(e);if(!s.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const c=e.measures?.[0]||e.dimensions?.[0];if(!c)return t.status(400).send(i.formatErrorResponse("No measures or dimensions specified",400));const a=c.split(".")[0],y=await d.generateSQL(a,e,o);return i.formatSqlResponse(e,y)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.get(`${h}/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 g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=o.measures?.[0]||o.dimensions?.[0];if(!a)return t.status(400).send(i.formatErrorResponse("No measures or dimensions specified",400));const y=a.split(".")[0],m=await d.generateSQL(y,o,s);return i.formatSqlResponse(o,m)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.post(`${h}/dry-run`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await g(r);return await i.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.get(`${h}/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 g(r);return await i.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.post(`${h}/explain`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=e.options||{},c=await g(r),a=d.validateQuery(o);return a.isValid?await d.explainQuery(o,c,s):t.status(400).send({error:`Query validation failed: ${a.errors.join(", ")}`})}catch(e){return r.log.error(e,"Explain error"),t.status(500).send({error:e instanceof Error?e.message:"Explain query failed"})}}),R&&n.post(`${h}/agent/chat`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-e6zofK2k.cjs")),o=r.body,{message:s,sessionId:c}=o;if(!s||typeof s!="string")return t.status(400).send({error:"message is required and must be a string"});let a=(R.apiKey||"").trim();if(R.allowClientApiKey){const m=r.headers["x-agent-api-key"];m&&(a=m.trim())}if(!a)return t.status(401).send({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const y=await g(r);t.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const m=e({message:s,sessionId:c,semanticLayer:d,securityContext:y,agentConfig:R,apiKey:a});for await(const p of m)t.raw.write(`data: ${JSON.stringify(p)}
1
+ "use strict";var O=Object.create;var j=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var H=(l,n,b,C)=>{if(n&&typeof n=="object"||typeof n=="function")for(let f of J(n))!D.call(l,f)&&f!==b&&j(l,f,{get:()=>n[f],enumerable:!(C=k(n,f))||C.enumerable});return l};var T=(l,n,b)=>(b=l!=null?O(L(l)):{},H(n||!l||!l.__esModule?j(b,"default",{value:l,enumerable:!0}):b,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../mcp-transport-8u9G5oNa.cjs"),i=require("../utils.cjs"),q=function(n,b,C){const{cubes:f,drizzle:I,schema:A,extractSecurityContext:g,engineType:M,cors:P,basePath:h="/cubejs-api/v1",bodyLimit:v=10485760,cache:N,mcp:E={enabled:!0},agent:R}=b;if(!f||f.length===0)return C(new Error("At least one cube must be provided in the cubes array"));P&&n.register(import("@fastify/cors"),P),n.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const d=new u.SemanticLayerCompiler({drizzle:I,schema:A,engineType:M,cache:N});if(f.forEach(r=>{d.registerCube(r)}),n.post(`${h}/load`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:a});return i.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.get(`${h}/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(i.formatErrorResponse("Invalid JSON in query parameter",400))}const s=await g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",y=await d.executeMultiCubeQuery(o,s,{skipCache:a});return i.formatCubeResponse(o,y,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.post(`${h}/batch`,{bodyLimit:v,schema:{body:{type:"object",required:["queries"],properties:{queries:{type:"array",items:{type:"object"}}}}}},async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).send(i.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).send(i.formatErrorResponse("Queries array cannot be empty",400));const o=await g(r),s=r.headers["x-cache-control"]==="no-cache";return await i.handleBatchRequest(e,o,d,{skipCache:s})}catch(e){return r.log.error(e,"Batch execution error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),n.get(`${h}/meta`,async(r,t)=>{try{const e=d.getMetadata();return i.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),n.post(`${h}/sql`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await g(r),s=d.validateQuery(e);if(!s.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${s.errors.join(", ")}`,400));const c=e.measures?.[0]||e.dimensions?.[0];if(!c)return t.status(400).send(i.formatErrorResponse("No measures or dimensions specified",400));const a=c.split(".")[0],y=await d.generateSQL(a,e,o);return i.formatSqlResponse(e,y)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.get(`${h}/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 g(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(i.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const a=o.measures?.[0]||o.dimensions?.[0];if(!a)return t.status(400).send(i.formatErrorResponse("No measures or dimensions specified",400));const y=a.split(".")[0],m=await d.generateSQL(y,o,s);return i.formatSqlResponse(o,m)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.post(`${h}/dry-run`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=await g(r);return await i.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.get(`${h}/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 g(r);return await i.handleDryRun(o,s,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.post(`${h}/explain`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,s=e.options||{},c=await g(r),a=d.validateQuery(o);return a.isValid?await d.explainQuery(o,c,s):t.status(400).send({error:`Query validation failed: ${a.errors.join(", ")}`})}catch(e){return r.log.error(e,"Explain error"),t.status(500).send({error:e instanceof Error?e.message:"Explain query failed"})}}),R&&n.post(`${h}/agent/chat`,{bodyLimit:v,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-dnkqpznh.cjs")),o=r.body,{message:s,sessionId:c}=o;if(!s||typeof s!="string")return t.status(400).send({error:"message is required and must be a string"});let a=(R.apiKey||"").trim();if(R.allowClientApiKey){const m=r.headers["x-agent-api-key"];m&&(a=m.trim())}if(!a)return t.status(401).send({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."});const y=await g(r);t.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});try{const m=e({message:s,sessionId:c,semanticLayer:d,securityContext:y,agentConfig:R,apiKey:a});for await(const p of m)t.raw.write(`data: ${JSON.stringify(p)}
2
2
 
3
3
  `)}catch(m){const p={type:"error",data:{message:m instanceof Error?m.message:"Stream failed"}};t.raw.write(`data: ${JSON.stringify(p)}
4
4
 
@@ -1,4 +1,4 @@
1
- import { S as D, v as K, b as x, a as T, n as V, p as z, w as _, d as B, i as j, M as F, c as U, e as E, s as P } from "../mcp-transport-CU5g9bxj.js";
1
+ import { S as D, v as K, b as x, a as T, n as V, p as z, w as _, d as B, i as j, M as F, c as U, e as E, s as P } from "../mcp-transport-m1X1GtwG.js";
2
2
  import { formatErrorResponse as d, formatCubeResponse as A, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as I, handleDryRun as M } from "../utils.js";
3
3
  const N = function(i, k, R) {
4
4
  const {
@@ -262,7 +262,7 @@ const N = function(i, k, R) {
262
262
  }
263
263
  }, async (t, r) => {
264
264
  try {
265
- const { handleAgentChat: e } = await import("../handler-CySCodwi.js"), a = t.body, { message: n, sessionId: o } = a;
265
+ const { handleAgentChat: e } = await import("../handler-CQkIwtxp.js"), a = t.body, { message: n, sessionId: o } = 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 s = (f.apiKey || "").trim();
@@ -1,6 +1,6 @@
1
- import { h as O, Q as q, j as P, D as Y } from "./mcp-transport-CU5g9bxj.js";
2
- import { handleDiscover as z, handleLoad as R } from "./utils.js";
3
- function M(o) {
1
+ import { h as N, Q as P, j as O, D as R } from "./mcp-transport-m1X1GtwG.js";
2
+ import { handleDiscover as Y, handleLoad as M } from "./utils.js";
3
+ function z(o) {
4
4
  if (o.length === 0)
5
5
  return "No cubes are currently available.";
6
6
  const t = ["## Available Cubes", ""];
@@ -52,6 +52,7 @@ function L(o) {
52
52
  "## Important Guidelines",
53
53
  "",
54
54
  "- ALWAYS discover cubes first before attempting queries",
55
+ "- Field names MUST be `CubeName.fieldName` (e.g. `PullRequests.count`, `Teams.name`). NEVER use just the cube name as a field — `PullRequests.PullRequests` is WRONG.",
55
56
  "- Use `add_portlet` to create visualizations after getting query results",
56
57
  "- Use `add_markdown` to explain your findings, methodology, and insights",
57
58
  "- Choose appropriate chart types: bar for categories, line for trends, table for detailed data",
@@ -63,15 +64,20 @@ function L(o) {
63
64
  "### CRITICAL: Always think before acting",
64
65
  "- EVERY single turn MUST begin with a text message (1-2 sentences) BEFORE any tool calls. This is your #1 rule — never violate it.",
65
66
  "- This applies to EVERY turn, including turns where you are adding visualizations or explanations to the notebook.",
66
- `- Even when adding multiple portlets/markdowns in sequence, each turn must start with text like "Now I'll add the productivity chart." or "Next, let me visualize the department breakdown."`,
67
- '- Example good turn: "Let me discover what data is available." → discover_cubes',
68
- `- Example good turn: "I'll add a bar chart showing the top employees." → add_markdown → add_portlet`,
67
+ `- Even when adding multiple charts in sequence, each turn must start with a brief status like "Now I'll chart the productivity breakdown." or "Next, let me show the department comparison."`,
68
+ '- Example good turn: "Let me see what data is available." → discover_cubes',
69
+ `- Example good turn: "I'll add a chart showing the top employees." → add_markdown → add_portlet`,
69
70
  "- Example bad turn: (no text) → add_portlet ← NEVER do this",
70
71
  "",
71
72
  "### Text vs Notebook",
72
73
  "- ALL analysis, findings, methodology, and insights MUST go through `add_markdown` tool calls — never in your text responses",
73
74
  "- Your text responses must be 1-2 short sentences (under 50 words) summarizing what you are about to do next — status updates only",
74
75
  "- Never use markdown formatting (headers, bullets, bold, code blocks) in text responses — plain sentences only",
76
+ "- Write text responses as a friendly analyst would — use plain business language the user understands",
77
+ '- NEVER mention internal terms like "cube", "query syntax", "field names", "measures", "dimensions", "portlet", "prefix format", or tool names in text responses',
78
+ '- Instead of "Let me correct the query syntax and retry" → "Let me fix that and try again"',
79
+ `- Instead of "I'll query the PullRequests cube" → "I'll look at the pull request data"`,
80
+ `- Instead of "Adding a portlet with the results" → "Here's a chart of the results"`,
75
81
  "",
76
82
  "### Notebook content rules",
77
83
  "- Before each `add_portlet`, ALWAYS call `add_markdown` first to explain WHY you are adding this visualization and what it shows",
@@ -154,27 +160,27 @@ function L(o) {
154
160
  "",
155
161
  "---",
156
162
  "",
157
- S(O),
163
+ S(N),
158
164
  "",
159
165
  "---",
160
166
  "",
161
- S(q),
167
+ S(P),
162
168
  "",
163
169
  "---",
164
170
  "",
165
- S(P),
171
+ S(O),
166
172
  "",
167
173
  "---",
168
174
  "",
169
- S(Y),
175
+ S(R),
170
176
  "",
171
177
  "---",
172
178
  "",
173
- M(o)
179
+ z(o)
174
180
  ].join(`
175
181
  `);
176
182
  }
177
- const $ = {
183
+ const H = {
178
184
  label: "Bar Chart",
179
185
  description: "Compare values across categories",
180
186
  useCase: "Best for comparing discrete categories, showing rankings, or displaying changes over time",
@@ -240,7 +246,7 @@ const $ = {
240
246
  description: "Number formatting for right Y-axis"
241
247
  }
242
248
  ]
243
- }, B = {
249
+ }, $ = {
244
250
  label: "Line Chart",
245
251
  description: "Show trends and changes over time",
246
252
  useCase: "Best for continuous data, trends, time series, and showing relationships between multiple series",
@@ -323,7 +329,7 @@ const $ = {
323
329
  description: "Number formatting for right Y-axis"
324
330
  }
325
331
  ]
326
- }, H = {
332
+ }, B = {
327
333
  label: "Area Chart",
328
334
  description: "Emphasize magnitude of change over time",
329
335
  useCase: "Best for showing cumulative totals, volume changes, or stacked comparisons over time",
@@ -429,7 +435,7 @@ const $ = {
429
435
  description: "Number formatting for values"
430
436
  }
431
437
  ]
432
- }, K = {
438
+ }, G = {
433
439
  label: "Scatter Plot",
434
440
  description: "Reveal correlations between variables",
435
441
  useCase: "Best for identifying patterns, correlations, outliers, and relationships between two measures",
@@ -477,7 +483,7 @@ const $ = {
477
483
  description: "Number formatting for Y-axis"
478
484
  }
479
485
  ]
480
- }, G = {
486
+ }, K = {
481
487
  label: "Bubble Chart",
482
488
  description: "Compare three dimensions of data",
483
489
  useCase: "Best for showing relationships between three variables (X, Y, and size), market analysis",
@@ -679,7 +685,7 @@ const $ = {
679
685
  description: "Number formatting for numeric values"
680
686
  }
681
687
  ]
682
- }, Q = {
688
+ }, J = {
683
689
  label: "Activity Grid",
684
690
  description: "GitHub-style activity grid showing temporal patterns across different time scales",
685
691
  useCase: "Best for visualizing activity patterns over time. Supports hour (3hr blocks × days), day (days × weeks), week (weeks × months), month (months × quarters), and quarter (quarters × years) granularities",
@@ -724,7 +730,7 @@ const $ = {
724
730
  } : { isValid: !0 };
725
731
  },
726
732
  clickableElements: { cell: !0 }
727
- }, J = {
733
+ }, Q = {
728
734
  label: "KPI Number",
729
735
  description: "Display key performance indicators as large numbers",
730
736
  useCase: "Perfect for showing important metrics like revenue, user count, or other key business metrics in a prominent, easy-to-read format",
@@ -1427,19 +1433,19 @@ Use --- for horizontal rules.`,
1427
1433
  description: "Number formatting for the value axis"
1428
1434
  }
1429
1435
  ]
1430
- }, V = {
1431
- bar: $,
1432
- line: B,
1433
- area: H,
1436
+ }, _ = {
1437
+ bar: H,
1438
+ line: $,
1439
+ area: B,
1434
1440
  pie: j,
1435
- scatter: K,
1436
- bubble: G,
1441
+ scatter: G,
1442
+ bubble: K,
1437
1443
  radar: Z,
1438
1444
  radialBar: X,
1439
1445
  treemap: U,
1440
1446
  table: W,
1441
- activityGrid: Q,
1442
- kpiNumber: J,
1447
+ activityGrid: J,
1448
+ kpiNumber: Q,
1443
1449
  kpiDelta: ee,
1444
1450
  kpiText: te,
1445
1451
  markdown: ie,
@@ -1452,7 +1458,7 @@ Use --- for horizontal rules.`,
1452
1458
  boxPlot: de
1453
1459
  };
1454
1460
  function pe(o, t, i) {
1455
- const s = V[o];
1461
+ const s = _[o];
1456
1462
  if (!s)
1457
1463
  return { isValid: !0, errors: [] };
1458
1464
  if (s.skipQuery)
@@ -1490,7 +1496,7 @@ function pe(o, t, i) {
1490
1496
  return { isValid: e.length === 0, errors: e };
1491
1497
  }
1492
1498
  function ue(o, t, i) {
1493
- const s = V[o];
1499
+ const s = _[o];
1494
1500
  if (!s)
1495
1501
  return t ?? {};
1496
1502
  const e = { ...t }, a = i.measures ?? [], n = i.dimensions ?? [], u = (i.timeDimensions ?? []).map((d) => d.dimension);
@@ -1503,8 +1509,8 @@ function ue(o, t, i) {
1503
1509
  const m = /* @__PURE__ */ new Set();
1504
1510
  for (const y of s.dropZones) {
1505
1511
  if (y.key === d.key) continue;
1506
- const g = e[y.key];
1507
- Array.isArray(g) ? g.forEach((w) => m.add(w)) : typeof g == "string" && m.add(g);
1512
+ const x = e[y.key];
1513
+ Array.isArray(x) ? x.forEach((w) => m.add(w)) : typeof x == "string" && m.add(x);
1508
1514
  }
1509
1515
  const C = a.filter((y) => !m.has(y));
1510
1516
  C.length > 0 && (e[d.key] = C[0]);
@@ -1513,14 +1519,14 @@ function ue(o, t, i) {
1513
1519
  }
1514
1520
  const c = [];
1515
1521
  if (f.includes("dimension") && c.push(...n), f.includes("timeDimension") && c.push(...u), f.includes("measure") && c.push(...a), c.length === 0) continue;
1516
- let b = c;
1522
+ let g = c;
1517
1523
  if (d.key === "series") {
1518
1524
  const m = new Set(
1519
1525
  Array.isArray(e.xAxis) ? e.xAxis : e.xAxis ? [e.xAxis] : []
1520
1526
  );
1521
- if (b = c.filter((C) => !m.has(C)), b.length === 0) continue;
1527
+ if (g = c.filter((C) => !m.has(C)), g.length === 0) continue;
1522
1528
  }
1523
- const F = d.maxItems ?? 1 / 0, v = b.slice(0, F);
1529
+ const F = d.maxItems ?? 1 / 0, v = g.slice(0, F);
1524
1530
  v.length > 0 && (e[d.key] = v);
1525
1531
  }
1526
1532
  return e;
@@ -1529,7 +1535,7 @@ function me(o) {
1529
1535
  const t = [`
1530
1536
  Chart config requirements by type:`];
1531
1537
  for (const i of o) {
1532
- const s = V[i];
1538
+ const s = _[i];
1533
1539
  if (!s) continue;
1534
1540
  const e = s.description ?? "", a = s.useCase ?? "", n = [e, a].filter(Boolean).join(". "), l = n ? ` — ${n}.` : "", u = s.dropZones.filter((p) => p.mandatory);
1535
1541
  if (u.length === 0 && !s.skipQuery) {
@@ -1549,7 +1555,7 @@ Chart config requirements by type:`];
1549
1555
  return t.join(`
1550
1556
  `);
1551
1557
  }
1552
- const N = [
1558
+ const q = [
1553
1559
  "bar",
1554
1560
  "line",
1555
1561
  "area",
@@ -1720,7 +1726,7 @@ function ce() {
1720
1726
  {
1721
1727
  name: "add_portlet",
1722
1728
  description: `Add a chart visualization to the notebook.
1723
- ` + me(N) + `
1729
+ ` + me(q) + `
1724
1730
  The query is validated before adding. The portlet fetches its own data.`,
1725
1731
  input_schema: {
1726
1732
  type: "object",
@@ -1732,7 +1738,7 @@ The query is validated before adding. The portlet fetches its own data.`,
1732
1738
  },
1733
1739
  chartType: {
1734
1740
  type: "string",
1735
- enum: N,
1741
+ enum: q,
1736
1742
  description: "Chart type to render"
1737
1743
  },
1738
1744
  chartConfig: {
@@ -1779,7 +1785,7 @@ The query is validated before adding. The portlet fetches its own data.`,
1779
1785
  function ye(o) {
1780
1786
  const { semanticLayer: t, securityContext: i } = o, s = /* @__PURE__ */ new Map();
1781
1787
  return s.set("discover_cubes", async (e) => {
1782
- const a = await z(t, {
1788
+ const a = await Y(t, {
1783
1789
  topic: e.topic,
1784
1790
  intent: e.intent,
1785
1791
  limit: e.limit,
@@ -1800,7 +1806,7 @@ function ye(o) {
1800
1806
  order: e.order,
1801
1807
  limit: e.limit
1802
1808
  };
1803
- const n = await R(t, i, { query: a });
1809
+ const n = await M(t, i, { query: a });
1804
1810
  return {
1805
1811
  result: JSON.stringify({
1806
1812
  rowCount: n.data.length,
@@ -1841,11 +1847,11 @@ ${u.errors.join(`
1841
1847
  if (d)
1842
1848
  p = e.chartConfig ?? {};
1843
1849
  else {
1844
- const c = ue(n, e.chartConfig, l), b = pe(n, c, l);
1845
- if (!b.isValid)
1850
+ const c = ue(n, e.chartConfig, l), g = pe(n, c, l);
1851
+ if (!g.isValid)
1846
1852
  return {
1847
1853
  result: `Chart config invalid — fix these errors and retry:
1848
- ${b.errors.join(`
1854
+ ${g.errors.join(`
1849
1855
  `)}`,
1850
1856
  isError: !0
1851
1857
  };
@@ -1875,7 +1881,7 @@ ${b.errors.join(`
1875
1881
  };
1876
1882
  }), s;
1877
1883
  }
1878
- async function* be(o) {
1884
+ async function* ge(o) {
1879
1885
  const { message: t, sessionId: i, semanticLayer: s, securityContext: e, agentConfig: a, apiKey: n } = o;
1880
1886
  let l;
1881
1887
  try {
@@ -1893,11 +1899,11 @@ async function* be(o) {
1893
1899
  };
1894
1900
  return;
1895
1901
  }
1896
- const u = new l({ apiKey: n }), d = ce(), p = ye({ semanticLayer: s, securityContext: e }), k = s.getMetadata(), f = L(k), c = a.model || "claude-sonnet-4-6", b = a.maxTurns || 25, F = a.maxTokens || 4096, v = [
1902
+ const u = new l({ apiKey: n }), d = ce(), p = ye({ semanticLayer: s, securityContext: e }), k = s.getMetadata(), f = L(k), c = a.model || "claude-sonnet-4-6", g = a.maxTurns || 25, F = a.maxTokens || 4096, v = [
1897
1903
  { role: "user", content: t }
1898
1904
  ];
1899
1905
  try {
1900
- for (let m = 0; m < b; m++) {
1906
+ for (let m = 0; m < g; m++) {
1901
1907
  const C = await u.messages.create({
1902
1908
  model: c,
1903
1909
  max_tokens: F,
@@ -1906,11 +1912,11 @@ async function* be(o) {
1906
1912
  messages: v,
1907
1913
  stream: !0
1908
1914
  }), y = [];
1909
- let g = -1, w = "", _ = "";
1915
+ let x = -1, w = "", V = "";
1910
1916
  for await (const h of C)
1911
1917
  switch (h.type) {
1912
1918
  case "content_block_start": {
1913
- g++;
1919
+ x++;
1914
1920
  const r = h.content_block;
1915
1921
  r.type === "tool_use" ? (y.push({ type: "tool_use", id: r.id, name: r.name, input: {} }), w = "", yield {
1916
1922
  type: "tool_use_start",
@@ -1921,13 +1927,13 @@ async function* be(o) {
1921
1927
  case "content_block_delta": {
1922
1928
  const r = h.delta;
1923
1929
  if (r.type === "text_delta" && r.text) {
1924
- const A = y[g];
1930
+ const A = y[x];
1925
1931
  A && (A.text = (A.text || "") + r.text), yield { type: "text_delta", data: r.text };
1926
1932
  } else r.type === "input_json_delta" && r.partial_json && (w += r.partial_json);
1927
1933
  break;
1928
1934
  }
1929
1935
  case "content_block_stop": {
1930
- const r = y[g];
1936
+ const r = y[x];
1931
1937
  if (r?.type === "tool_use" && w) {
1932
1938
  try {
1933
1939
  r.input = JSON.parse(w);
@@ -1940,17 +1946,17 @@ async function* be(o) {
1940
1946
  }
1941
1947
  case "message_delta": {
1942
1948
  const r = h.delta;
1943
- r.stop_reason && (_ = r.stop_reason);
1949
+ r.stop_reason && (V = r.stop_reason);
1944
1950
  break;
1945
1951
  }
1946
1952
  }
1947
- if (v.push({ role: "assistant", content: y }), _ !== "tool_use")
1953
+ if (v.push({ role: "assistant", content: y }), V !== "tool_use")
1948
1954
  break;
1949
1955
  const D = [];
1950
1956
  for (const h of y) {
1951
1957
  if (h.type !== "tool_use") continue;
1952
- const r = h.name, A = h.input || {}, T = h.id, I = p.get(r);
1953
- if (!I) {
1958
+ const r = h.name, A = h.input || {}, T = h.id, E = p.get(r);
1959
+ if (!E) {
1954
1960
  D.push({
1955
1961
  type: "tool_result",
1956
1962
  tool_use_id: T,
@@ -1958,31 +1964,31 @@ async function* be(o) {
1958
1964
  is_error: !0
1959
1965
  }), yield {
1960
1966
  type: "tool_use_result",
1961
- data: { id: T, name: r, result: `Unknown tool: ${r}` }
1967
+ data: { id: T, name: r, result: `Unknown tool: ${r}`, isError: !0 }
1962
1968
  };
1963
1969
  continue;
1964
1970
  }
1965
1971
  try {
1966
- const x = await I(A);
1967
- x.sideEffect && (yield x.sideEffect), D.push({
1972
+ const b = await E(A);
1973
+ b.sideEffect && (yield b.sideEffect), D.push({
1968
1974
  type: "tool_result",
1969
1975
  tool_use_id: T,
1970
- content: x.result,
1971
- ...x.isError ? { is_error: !0 } : {}
1976
+ content: b.result,
1977
+ ...b.isError ? { is_error: !0 } : {}
1972
1978
  }), yield {
1973
1979
  type: "tool_use_result",
1974
- data: { id: T, name: r, result: x.result }
1980
+ data: { id: T, name: r, result: b.result, ...b.isError ? { isError: !0 } : {} }
1975
1981
  };
1976
- } catch (x) {
1977
- const E = x instanceof Error ? x.message : "Tool execution failed";
1982
+ } catch (b) {
1983
+ const I = b instanceof Error ? b.message : "Tool execution failed";
1978
1984
  D.push({
1979
1985
  type: "tool_result",
1980
1986
  tool_use_id: T,
1981
- content: E,
1987
+ content: I,
1982
1988
  is_error: !0
1983
1989
  }), yield {
1984
1990
  type: "tool_use_result",
1985
- data: { id: T, name: r, result: E }
1991
+ data: { id: T, name: r, result: I, isError: !0 }
1986
1992
  };
1987
1993
  }
1988
1994
  }
@@ -1996,11 +2002,37 @@ async function* be(o) {
1996
2002
  yield {
1997
2003
  type: "error",
1998
2004
  data: {
1999
- message: m instanceof Error ? m.message : "Agent execution failed"
2005
+ message: fe(m)
2000
2006
  }
2001
2007
  };
2002
2008
  }
2003
2009
  }
2010
+ function fe(o) {
2011
+ if (!o || !(o instanceof Error))
2012
+ return "Something went wrong. Please try again.";
2013
+ const t = o.message || "", i = {
2014
+ overloaded_error: "The AI service is temporarily overloaded. Please try again in a moment.",
2015
+ rate_limit_error: "Too many requests. Please wait a moment and try again.",
2016
+ api_error: "The AI service encountered an error. Please try again.",
2017
+ authentication_error: "Authentication failed. Please check your API key configuration.",
2018
+ invalid_request_error: "There was a problem with the request. Please try again."
2019
+ }, s = o;
2020
+ if (s.status || s.type) {
2021
+ const e = s.error?.type || s.type || "";
2022
+ if (i[e])
2023
+ return i[e];
2024
+ }
2025
+ if (t.startsWith("{") || t.startsWith("Error: {")) {
2026
+ try {
2027
+ const e = JSON.parse(t.replace(/^Error:\s*/, "")), a = e.error?.type || e.type || "";
2028
+ if (i[a])
2029
+ return i[a];
2030
+ } catch {
2031
+ }
2032
+ return "The AI service encountered an error. Please try again.";
2033
+ }
2034
+ return t;
2035
+ }
2004
2036
  export {
2005
- be as handleAgentChat
2037
+ ge as handleAgentChat
2006
2038
  };