drizzle-cube 0.4.19 → 0.4.21
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/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/adapters/anthropic-CTu9E801.js +126 -0
- package/dist/adapters/express/index.cjs +6 -6
- package/dist/adapters/express/index.js +73 -69
- package/dist/adapters/fastify/index.cjs +6 -6
- package/dist/adapters/fastify/index.js +133 -129
- package/dist/adapters/google-BAK9pnQf.cjs +2 -0
- package/dist/adapters/google-DficVAsJ.js +146 -0
- package/dist/adapters/{handler-BV4JuWNW.js → handler-9Rdn7zM2.js} +537 -457
- package/dist/adapters/handler-B-tEntiU.cjs +39 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +199 -195
- package/dist/adapters/index-BIMhF5KZ.cjs +23 -0
- package/dist/adapters/index-BgCeQBuN.cjs +2 -0
- package/dist/adapters/index-C45_meK_.js +719 -0
- package/dist/adapters/index-CFEJ62GJ.js +5337 -0
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +215 -211
- package/dist/adapters/openai-CUSRuKTk.js +131 -0
- package/dist/adapters/openai-mLo2MCat.cjs +1 -0
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +3 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
- package/dist/client/hooks/useAgentChat.d.ts +6 -0
- package/dist/client/index.js +730 -697
- package/dist/client/index.js.map +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/anthropic-BTkjgFpT.cjs +1 -0
- package/dist/server/anthropic-CTu9E801.js +126 -0
- package/dist/server/google-BAK9pnQf.cjs +2 -0
- package/dist/server/google-DficVAsJ.js +146 -0
- package/dist/server/index-BIMhF5KZ.cjs +23 -0
- package/dist/server/index-BgCeQBuN.cjs +2 -0
- package/dist/server/index-C45_meK_.js +719 -0
- package/dist/server/index-CFEJ62GJ.js +5337 -0
- package/dist/server/index.cjs +51 -45
- package/dist/server/index.d.ts +49 -10
- package/dist/server/index.js +1978 -1898
- package/dist/server/openai-CUSRuKTk.js +131 -0
- package/dist/server/openai-mLo2MCat.cjs +1 -0
- package/package.json +12 -2
- package/dist/adapters/handler-D4MVKkVy.cjs +0 -33
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.create;var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var y=(o,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of u(e))!d.call(o,t)&&t!==r&&i(o,t,{get:()=>e[t],enumerable:!(s=c(e,t))||s.enumerable});return o};var m=(o,e,r)=>(r=o!=null?l(p(o)):{},y(e||!o||!o.__esModule?i(r,"default",{value:o,enumerable:!0}):r,o));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class _{client;constructor(e){this.apiKey=e}apiKey;initialized=!1;async ensureClient(){if(this.initialized)return;let e;try{const r=await import("@anthropic-ai/sdk");e=r.default||r.Anthropic||r}catch{throw new Error("@anthropic-ai/sdk is required for the Anthropic provider. Install it with: npm install @anthropic-ai/sdk")}this.client=new e({apiKey:this.apiKey}),this.initialized=!0}async createStream(e){await this.ensureClient();const{messages:r,system:s}=this.formatMessages(e.messages,e.system);return this.client.messages.create({model:e.model,max_tokens:e.maxTokens,system:s,tools:this.formatTools(e.tools),messages:r,stream:!0})}async*parseStreamEvents(e){for await(const r of e){const s=r;switch(s.type){case"content_block_start":{const t=s.content_block;t.type==="tool_use"&&(yield{type:"tool_use_start",id:t.id,name:t.name});break}case"content_block_delta":{const t=s.delta;t.type==="text_delta"&&t.text?yield{type:"text_delta",text:t.text}:t.type==="input_json_delta"&&t.partial_json&&(yield{type:"tool_input_delta",json:t.partial_json});break}case"content_block_stop":{yield{type:"tool_use_end"};break}case"message_start":{const t=s.message;t?.usage?.input_tokens!=null&&(yield{type:"message_meta",inputTokens:t.usage.input_tokens,stopReason:""});break}case"message_delta":{const t=s.usage,a=s.delta?.stop_reason||"";yield{type:"message_meta",outputTokens:t?.output_tokens,stopReason:a};break}}}}formatTools(e){return e.map(r=>({name:r.name,description:r.description,input_schema:r.parameters}))}formatMessages(e,r){return{messages:e.map(t=>t.role==="tool_result"?{role:"user",content:t.content}:{role:t.role,content:t.content}),system:r}}formatToolResults(e){return{role:"user",content:e.map(r=>({type:"tool_result",tool_use_id:r.toolUseId,content:r.content,...r.isError?{is_error:!0}:{}}))}}shouldContinue(e){return e==="tool_use"}formatError(e){if(!e||!(e instanceof Error))return"Something went wrong. Please try again.";const r=e.message||"",s={overloaded_error:"The AI service is temporarily overloaded. Please try again in a moment.",rate_limit_error:"Too many requests. Please wait a moment and try again.",api_error:"The AI service encountered an error. Please try again.",authentication_error:"Authentication failed. Please check your API key configuration.",invalid_request_error:"There was a problem with the request. Please try again."},t=e;if(t.status||t.type){const a=t.error?.type||t.type||"";if(s[a])return s[a]}if(r.startsWith("{")||r.startsWith("Error: {")){try{const a=JSON.parse(r.replace(/^Error:\s*/,"")),n=a.error?.type||a.type||"";if(s[n])return s[n]}catch{}return"The AI service encountered an error. Please try again."}return r}}exports.AnthropicProvider=_;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
class i {
|
|
2
|
+
client;
|
|
3
|
+
constructor(e) {
|
|
4
|
+
this.apiKey = e;
|
|
5
|
+
}
|
|
6
|
+
apiKey;
|
|
7
|
+
initialized = !1;
|
|
8
|
+
async ensureClient() {
|
|
9
|
+
if (this.initialized) return;
|
|
10
|
+
let e;
|
|
11
|
+
try {
|
|
12
|
+
const r = await import(
|
|
13
|
+
/* webpackIgnore: true */
|
|
14
|
+
"@anthropic-ai/sdk"
|
|
15
|
+
);
|
|
16
|
+
e = r.default || r.Anthropic || r;
|
|
17
|
+
} catch {
|
|
18
|
+
throw new Error("@anthropic-ai/sdk is required for the Anthropic provider. Install it with: npm install @anthropic-ai/sdk");
|
|
19
|
+
}
|
|
20
|
+
this.client = new e({ apiKey: this.apiKey }), this.initialized = !0;
|
|
21
|
+
}
|
|
22
|
+
async createStream(e) {
|
|
23
|
+
await this.ensureClient();
|
|
24
|
+
const { messages: r, system: s } = this.formatMessages(e.messages, e.system);
|
|
25
|
+
return this.client.messages.create({
|
|
26
|
+
model: e.model,
|
|
27
|
+
max_tokens: e.maxTokens,
|
|
28
|
+
system: s,
|
|
29
|
+
tools: this.formatTools(e.tools),
|
|
30
|
+
messages: r,
|
|
31
|
+
stream: !0
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async *parseStreamEvents(e) {
|
|
35
|
+
for await (const r of e) {
|
|
36
|
+
const s = r;
|
|
37
|
+
switch (s.type) {
|
|
38
|
+
case "content_block_start": {
|
|
39
|
+
const t = s.content_block;
|
|
40
|
+
t.type === "tool_use" && (yield { type: "tool_use_start", id: t.id, name: t.name });
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "content_block_delta": {
|
|
44
|
+
const t = s.delta;
|
|
45
|
+
t.type === "text_delta" && t.text ? yield { type: "text_delta", text: t.text } : t.type === "input_json_delta" && t.partial_json && (yield { type: "tool_input_delta", json: t.partial_json });
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "content_block_stop": {
|
|
49
|
+
yield { type: "tool_use_end" };
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "message_start": {
|
|
53
|
+
const t = s.message;
|
|
54
|
+
t?.usage?.input_tokens != null && (yield {
|
|
55
|
+
type: "message_meta",
|
|
56
|
+
inputTokens: t.usage.input_tokens,
|
|
57
|
+
stopReason: ""
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "message_delta": {
|
|
62
|
+
const t = s.usage, o = s.delta?.stop_reason || "";
|
|
63
|
+
yield {
|
|
64
|
+
type: "message_meta",
|
|
65
|
+
outputTokens: t?.output_tokens,
|
|
66
|
+
stopReason: o
|
|
67
|
+
};
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
formatTools(e) {
|
|
74
|
+
return e.map((r) => ({
|
|
75
|
+
name: r.name,
|
|
76
|
+
description: r.description,
|
|
77
|
+
input_schema: r.parameters
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
formatMessages(e, r) {
|
|
81
|
+
return { messages: e.map((t) => t.role === "tool_result" ? { role: "user", content: t.content } : { role: t.role, content: t.content }), system: r };
|
|
82
|
+
}
|
|
83
|
+
formatToolResults(e) {
|
|
84
|
+
return {
|
|
85
|
+
role: "user",
|
|
86
|
+
content: e.map((r) => ({
|
|
87
|
+
type: "tool_result",
|
|
88
|
+
tool_use_id: r.toolUseId,
|
|
89
|
+
content: r.content,
|
|
90
|
+
...r.isError ? { is_error: !0 } : {}
|
|
91
|
+
}))
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
shouldContinue(e) {
|
|
95
|
+
return e === "tool_use";
|
|
96
|
+
}
|
|
97
|
+
formatError(e) {
|
|
98
|
+
if (!e || !(e instanceof Error))
|
|
99
|
+
return "Something went wrong. Please try again.";
|
|
100
|
+
const r = e.message || "", s = {
|
|
101
|
+
overloaded_error: "The AI service is temporarily overloaded. Please try again in a moment.",
|
|
102
|
+
rate_limit_error: "Too many requests. Please wait a moment and try again.",
|
|
103
|
+
api_error: "The AI service encountered an error. Please try again.",
|
|
104
|
+
authentication_error: "Authentication failed. Please check your API key configuration.",
|
|
105
|
+
invalid_request_error: "There was a problem with the request. Please try again."
|
|
106
|
+
}, t = e;
|
|
107
|
+
if (t.status || t.type) {
|
|
108
|
+
const o = t.error?.type || t.type || "";
|
|
109
|
+
if (s[o])
|
|
110
|
+
return s[o];
|
|
111
|
+
}
|
|
112
|
+
if (r.startsWith("{") || r.startsWith("Error: {")) {
|
|
113
|
+
try {
|
|
114
|
+
const o = JSON.parse(r.replace(/^Error:\s*/, "")), a = o.error?.type || o.type || "";
|
|
115
|
+
if (s[a])
|
|
116
|
+
return s[a];
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
return "The AI service encountered an error. Please try again.";
|
|
120
|
+
}
|
|
121
|
+
return r;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
i as AnthropicProvider
|
|
126
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("express"),H=require("cors"),c=require("../mcp-transport-8u9G5oNa.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-B-tEntiU.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
|
-
`)}catch(p){const
|
|
3
|
+
`)}catch(p){const j={type:"error",data:{message:p instanceof Error?p.message:"Stream failed"}};t.write(`data: ${JSON.stringify(j)}
|
|
4
4
|
|
|
5
|
-
`)}finally{t.end()}}catch(e){console.error("Agent chat error:",e),t.headersSent||t.status(500).json({error:e instanceof Error?e.message:"Agent chat failed"})}}),
|
|
5
|
+
`)}finally{t.end()}}catch(e){console.error("Agent chat error:",e),t.headersSent||t.status(500).json({error:e instanceof Error?e.message:"Agent chat failed"})}}),E.enabled!==!1){const r=E.basePath??"/mcp";d.post(`${r}`,async(t,e)=>{const o=c.validateOriginHeader(t.headers.origin,E.allowedOrigins?{allowedOrigins:E.allowedOrigins}:{});if(!o.valid)return e.status(403).json(c.buildJsonRpcError(null,-32600,o.reason));const s=t.headers.accept;if(!c.validateAcceptHeader(s))return e.status(400).json(c.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const a=c.negotiateProtocol(t.headers);if(!a.ok)return e.status(426).json({error:"Unsupported MCP protocol version",supported:a.supported});const i=c.parseJsonRpc(t.body);if(!i)return e.status(400).json(c.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const m=c.wantsEventStream(s),R=i.method==="initialize";try{const l=await c.dispatchMcpMethod(i.method,i.params,{semanticLayer:u,extractSecurityContext:y,rawRequest:t,rawResponse:e,negotiatedProtocol:a.negotiated});if(c.isNotification(i))return e.status(202).end();const g=R&&l&&typeof l=="object"&&"sessionId"in l?l.sessionId:void 0;g&&e.setHeader(c.MCP_SESSION_ID_HEADER,g);const b=c.buildJsonRpcResult(i.id??null,l);if(m){const p=c.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${p}
|
|
6
6
|
|
|
7
|
-
`),e.write(c.serializeSseEvent(
|
|
7
|
+
`),e.write(c.serializeSseEvent(b,p)),e.end()}return e.json(b)}catch(l){if(c.isNotification(i))return console.error("MCP notification processing error:",l),e.status(202).end();console.error("MCP RPC error:",l);const g=l?.code??-32603,b=l?.data,p=l.message||"MCP request failed",j=c.buildJsonRpcError(i.id??null,g,p,b);if(m){const q=c.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${q}
|
|
8
8
|
|
|
9
|
-
`),e.write(c.serializeSseEvent(
|
|
9
|
+
`),e.write(c.serializeSseEvent(j,q)),e.end()}return e.status(200).json(j)}}),d.get(`${r}`,async(t,e)=>{const o=c.primeEventId();e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(c.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const s=setInterval(()=>{e.write(`: keep-alive
|
|
10
10
|
|
|
11
|
-
`)},15e3);t.on("close",()=>{clearInterval(s)})}),d.delete(`${r}`,(t,e)=>e.status(405).json({error:"Session termination not supported"}))}return d.use((r,t,e,o)=>{console.error("Express adapter error:",r),e.headersSent||e.status(500).json(n.formatErrorResponse(r,500))}),d}function
|
|
11
|
+
`)},15e3);t.on("close",()=>{clearInterval(s)})}),d.delete(`${r}`,(t,e)=>e.status(405).json({error:"Session termination not supported"}))}return d.use((r,t,e,o)=>{console.error("Express adapter error:",r),e.headersSent||e.status(500).json(n.formatErrorResponse(r,500))}),d}function A(C,v){const x=$(v);return C.use("/",x),C}function M(C){const v=w();return A(v,C)}exports.createCubeApp=M;exports.createCubeRouter=$;exports.mountCubeRoutes=A;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import R, { Router as J } from "express";
|
|
2
2
|
import L from "cors";
|
|
3
|
-
import { S as
|
|
4
|
-
import { formatErrorResponse as u, formatCubeResponse as
|
|
5
|
-
function W(
|
|
3
|
+
import { S as K, v as D, b as x, a as _, n as V, p as z, w as T, d as B, i as I, M as U, c as F, e as Q, s as E } from "../mcp-transport-m1X1GtwG.js";
|
|
4
|
+
import { formatErrorResponse as u, formatCubeResponse as P, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as H, handleDryRun as M } from "../utils.js";
|
|
5
|
+
function W(v) {
|
|
6
6
|
const {
|
|
7
|
-
cubes:
|
|
8
|
-
drizzle:
|
|
9
|
-
schema:
|
|
7
|
+
cubes: h,
|
|
8
|
+
drizzle: S,
|
|
9
|
+
schema: O,
|
|
10
10
|
extractSecurityContext: y,
|
|
11
|
-
engineType:
|
|
12
|
-
cors:
|
|
11
|
+
engineType: N,
|
|
12
|
+
cors: $,
|
|
13
13
|
basePath: p = "/cubejs-api/v1",
|
|
14
|
-
jsonLimit:
|
|
15
|
-
cache:
|
|
16
|
-
mcp:
|
|
17
|
-
agent:
|
|
18
|
-
} =
|
|
19
|
-
if (!
|
|
14
|
+
jsonLimit: A = "10mb",
|
|
15
|
+
cache: k,
|
|
16
|
+
mcp: w = { enabled: !0 },
|
|
17
|
+
agent: m
|
|
18
|
+
} = v;
|
|
19
|
+
if (!h || h.length === 0)
|
|
20
20
|
throw new Error("At least one cube must be provided in the cubes array");
|
|
21
21
|
const c = J();
|
|
22
|
-
|
|
23
|
-
const i = new
|
|
24
|
-
drizzle:
|
|
25
|
-
schema:
|
|
26
|
-
engineType:
|
|
27
|
-
cache:
|
|
22
|
+
$ && c.use(L($)), c.use(R.json({ limit: A })), c.use(R.urlencoded({ extended: !0, limit: A }));
|
|
23
|
+
const i = new K({
|
|
24
|
+
drizzle: S,
|
|
25
|
+
schema: O,
|
|
26
|
+
engineType: N,
|
|
27
|
+
cache: k
|
|
28
28
|
});
|
|
29
|
-
if (
|
|
29
|
+
if (h.forEach((r) => {
|
|
30
30
|
i.registerCube(r);
|
|
31
31
|
}), c.post(`${p}/load`, async (r, t) => {
|
|
32
32
|
try {
|
|
@@ -37,7 +37,7 @@ function W(h) {
|
|
|
37
37
|
400
|
|
38
38
|
));
|
|
39
39
|
const n = r.headers["x-cache-control"] === "no-cache", s = await i.executeMultiCubeQuery(e, o, { skipCache: n });
|
|
40
|
-
t.json(
|
|
40
|
+
t.json(P(e, s, i));
|
|
41
41
|
} catch (e) {
|
|
42
42
|
console.error("Query execution error:", e), t.status(500).json(u(
|
|
43
43
|
e instanceof Error ? e.message : "Query execution failed",
|
|
@@ -68,7 +68,7 @@ function W(h) {
|
|
|
68
68
|
400
|
|
69
69
|
));
|
|
70
70
|
const s = r.headers["x-cache-control"] === "no-cache", f = await i.executeMultiCubeQuery(o, a, { skipCache: s });
|
|
71
|
-
t.json(
|
|
71
|
+
t.json(P(o, f, i));
|
|
72
72
|
} catch (e) {
|
|
73
73
|
console.error("Query execution error:", e), t.status(500).json(u(
|
|
74
74
|
e instanceof Error ? e.message : "Query execution failed",
|
|
@@ -148,8 +148,8 @@ function W(h) {
|
|
|
148
148
|
"No measures or dimensions specified",
|
|
149
149
|
400
|
|
150
150
|
));
|
|
151
|
-
const f = s.split(".")[0],
|
|
152
|
-
t.json(H(o,
|
|
151
|
+
const f = s.split(".")[0], b = await i.generateSQL(f, o, a);
|
|
152
|
+
t.json(H(o, b));
|
|
153
153
|
} catch (e) {
|
|
154
154
|
console.error("SQL generation error:", e), t.status(500).json(u(
|
|
155
155
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
@@ -196,13 +196,13 @@ function W(h) {
|
|
|
196
196
|
error: e instanceof Error ? e.message : "Explain query failed"
|
|
197
197
|
});
|
|
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-9Rdn7zM2.js"), { message: o, sessionId: a, history: n } = r.body;
|
|
202
202
|
if (!o || typeof o != "string")
|
|
203
203
|
return t.status(400).json({ error: "message is required and must be a string" });
|
|
204
|
-
let s = (
|
|
205
|
-
if (
|
|
204
|
+
let s = (m.apiKey || "").trim();
|
|
205
|
+
if (m.allowClientApiKey) {
|
|
206
206
|
const l = r.headers["x-agent-api-key"];
|
|
207
207
|
l && (s = l.trim());
|
|
208
208
|
}
|
|
@@ -210,7 +210,7 @@ function W(h) {
|
|
|
210
210
|
return t.status(401).json({
|
|
211
211
|
error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
|
|
212
212
|
});
|
|
213
|
-
const f = await y(r, t);
|
|
213
|
+
const f = m.allowClientApiKey ? r.headers["x-agent-provider"] : void 0, b = m.allowClientApiKey ? r.headers["x-agent-model"] : void 0, d = m.allowClientApiKey ? r.headers["x-agent-provider-endpoint"] : void 0, g = await y(r, t), j = m.buildSystemContext?.(g);
|
|
214
214
|
t.writeHead(200, {
|
|
215
215
|
"Content-Type": "text/event-stream",
|
|
216
216
|
"Cache-Control": "no-cache",
|
|
@@ -222,20 +222,24 @@ function W(h) {
|
|
|
222
222
|
sessionId: a,
|
|
223
223
|
history: n,
|
|
224
224
|
semanticLayer: i,
|
|
225
|
-
securityContext:
|
|
226
|
-
agentConfig:
|
|
227
|
-
apiKey: s
|
|
225
|
+
securityContext: g,
|
|
226
|
+
agentConfig: m,
|
|
227
|
+
apiKey: s,
|
|
228
|
+
systemContext: j,
|
|
229
|
+
providerOverride: f,
|
|
230
|
+
modelOverride: b,
|
|
231
|
+
baseURLOverride: d
|
|
228
232
|
});
|
|
229
|
-
for await (const
|
|
230
|
-
t.write(`data: ${JSON.stringify(
|
|
233
|
+
for await (const C of l)
|
|
234
|
+
t.write(`data: ${JSON.stringify(C)}
|
|
231
235
|
|
|
232
236
|
`);
|
|
233
237
|
} catch (l) {
|
|
234
|
-
const
|
|
238
|
+
const C = {
|
|
235
239
|
type: "error",
|
|
236
240
|
data: { message: l instanceof Error ? l.message : "Stream failed" }
|
|
237
241
|
};
|
|
238
|
-
t.write(`data: ${JSON.stringify(
|
|
242
|
+
t.write(`data: ${JSON.stringify(C)}
|
|
239
243
|
|
|
240
244
|
`);
|
|
241
245
|
} finally {
|
|
@@ -246,18 +250,18 @@ function W(h) {
|
|
|
246
250
|
error: e instanceof Error ? e.message : "Agent chat failed"
|
|
247
251
|
});
|
|
248
252
|
}
|
|
249
|
-
}),
|
|
250
|
-
const r =
|
|
253
|
+
}), w.enabled !== !1) {
|
|
254
|
+
const r = w.basePath ?? "/mcp";
|
|
251
255
|
c.post(`${r}`, async (t, e) => {
|
|
252
|
-
const o =
|
|
256
|
+
const o = D(
|
|
253
257
|
t.headers.origin,
|
|
254
|
-
|
|
258
|
+
w.allowedOrigins ? { allowedOrigins: w.allowedOrigins } : {}
|
|
255
259
|
);
|
|
256
260
|
if (!o.valid)
|
|
257
|
-
return e.status(403).json(
|
|
261
|
+
return e.status(403).json(x(null, -32600, o.reason));
|
|
258
262
|
const a = t.headers.accept;
|
|
259
|
-
if (!
|
|
260
|
-
return e.status(400).json(
|
|
263
|
+
if (!_(a))
|
|
264
|
+
return e.status(400).json(x(null, -32600, "Accept header must include both application/json and text/event-stream"));
|
|
261
265
|
const n = V(t.headers);
|
|
262
266
|
if (!n.ok)
|
|
263
267
|
return e.status(426).json({
|
|
@@ -266,8 +270,8 @@ function W(h) {
|
|
|
266
270
|
});
|
|
267
271
|
const s = z(t.body);
|
|
268
272
|
if (!s)
|
|
269
|
-
return e.status(400).json(
|
|
270
|
-
const f = T(a),
|
|
273
|
+
return e.status(400).json(x(null, -32600, "Invalid JSON-RPC 2.0 request"));
|
|
274
|
+
const f = T(a), b = s.method === "initialize";
|
|
271
275
|
try {
|
|
272
276
|
const d = await B(
|
|
273
277
|
s.method,
|
|
@@ -280,34 +284,34 @@ function W(h) {
|
|
|
280
284
|
negotiatedProtocol: n.negotiated
|
|
281
285
|
}
|
|
282
286
|
);
|
|
283
|
-
if (
|
|
287
|
+
if (I(s))
|
|
284
288
|
return e.status(202).end();
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
const
|
|
289
|
+
const g = b && d && typeof d == "object" && "sessionId" in d ? d.sessionId : void 0;
|
|
290
|
+
g && e.setHeader(U, g);
|
|
291
|
+
const j = F(s.id ?? null, d);
|
|
288
292
|
if (f) {
|
|
289
|
-
const
|
|
290
|
-
return e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(`id: ${
|
|
293
|
+
const l = Q();
|
|
294
|
+
return e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(`id: ${l}
|
|
291
295
|
|
|
292
|
-
`), e.write(
|
|
296
|
+
`), e.write(E(j, l)), e.end();
|
|
293
297
|
}
|
|
294
|
-
return e.json(
|
|
298
|
+
return e.json(j);
|
|
295
299
|
} catch (d) {
|
|
296
|
-
if (
|
|
300
|
+
if (I(s))
|
|
297
301
|
return console.error("MCP notification processing error:", d), e.status(202).end();
|
|
298
302
|
console.error("MCP RPC error:", d);
|
|
299
|
-
const
|
|
303
|
+
const g = d?.code ?? -32603, j = d?.data, l = d.message || "MCP request failed", C = x(s.id ?? null, g, l, j);
|
|
300
304
|
if (f) {
|
|
301
|
-
const
|
|
302
|
-
return e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(`id: ${
|
|
305
|
+
const q = Q();
|
|
306
|
+
return e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(`id: ${q}
|
|
303
307
|
|
|
304
|
-
`), e.write(
|
|
308
|
+
`), e.write(E(C, q)), e.end();
|
|
305
309
|
}
|
|
306
|
-
return e.status(200).json(
|
|
310
|
+
return e.status(200).json(C);
|
|
307
311
|
}
|
|
308
312
|
}), c.get(`${r}`, async (t, e) => {
|
|
309
|
-
const o =
|
|
310
|
-
e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(
|
|
313
|
+
const o = Q();
|
|
314
|
+
e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(E({
|
|
311
315
|
jsonrpc: "2.0",
|
|
312
316
|
method: "mcp/ready",
|
|
313
317
|
params: { protocol: "streamable-http" }
|
|
@@ -326,13 +330,13 @@ function W(h) {
|
|
|
326
330
|
console.error("Express adapter error:", r), e.headersSent || e.status(500).json(u(r, 500));
|
|
327
331
|
}), c;
|
|
328
332
|
}
|
|
329
|
-
function Y(
|
|
330
|
-
const
|
|
331
|
-
return
|
|
333
|
+
function Y(v, h) {
|
|
334
|
+
const S = W(h);
|
|
335
|
+
return v.use("/", S), v;
|
|
332
336
|
}
|
|
333
|
-
function oe(
|
|
334
|
-
const
|
|
335
|
-
return Y(
|
|
337
|
+
function oe(v) {
|
|
338
|
+
const h = R();
|
|
339
|
+
return Y(h, v);
|
|
336
340
|
}
|
|
337
341
|
export {
|
|
338
342
|
oe as createCubeApp,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";var
|
|
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-8u9G5oNa.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-B-tEntiU.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
|
-
`)}catch(
|
|
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
|
|
|
5
|
-
`)}finally{t.raw.end()}}catch(e){if(r.log.error(e,"Agent chat error"),!t.raw.headersSent)return t.status(500).send({error:e instanceof Error?e.message:"Agent chat failed"})}}),
|
|
5
|
+
`)}finally{t.raw.end()}}catch(e){if(r.log.error(e,"Agent chat error"),!t.raw.headersSent)return t.status(500).send({error:e instanceof Error?e.message:"Agent chat failed"})}}),q.enabled!==!1){const r=q.basePath??"/mcp";n.post(`${r}`,{bodyLimit:C,schema:{body:{type:"object",additionalProperties:!0}}},async(t,e)=>{const o=d.validateOriginHeader(t.headers.origin,q.allowedOrigins?{allowedOrigins:q.allowedOrigins}:{});if(!o.valid)return e.status(403).send(d.buildJsonRpcError(null,-32600,o.reason));const s=t.headers.accept;if(!d.validateAcceptHeader(s))return e.status(400).send(d.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const i=d.negotiateProtocol(t.headers);if(!i.ok)return e.status(426).send({error:"Unsupported MCP protocol version",supported:i.supported});const c=d.parseJsonRpc(t.body);if(!c)return e.status(400).send(d.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const p=d.wantsEventStream(s),P=c.method==="initialize";try{const y=await d.dispatchMcpMethod(c.method,c.params,{semanticLayer:u,extractSecurityContext:m,rawRequest:t,rawResponse:e,negotiatedProtocol:i.negotiated});if(d.isNotification(c))return e.status(202).send();const E=P&&y&&typeof y=="object"&&"sessionId"in y?y.sessionId:void 0;E&&e.header(d.MCP_SESSION_ID_HEADER,E);const w=d.buildJsonRpcResult(c.id??null,y);if(p){const R=d.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${R}
|
|
6
6
|
|
|
7
|
-
${
|
|
7
|
+
${d.serializeSseEvent(w,R)}`);return}return e.send(w)}catch(y){if(d.isNotification(c))return t.log.error(y,"MCP notification processing error"),e.status(202).send();t.log.error(y,"MCP RPC error");const E=y?.code??-32603,w=y?.data,R=y.message||"MCP request failed",h=d.buildJsonRpcError(c.id??null,E,R,w);if(p){const x=d.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${x}
|
|
8
8
|
|
|
9
|
-
${
|
|
9
|
+
${d.serializeSseEvent(h,x)}`);return}return e.send(h)}}),n.get(`${r}`,async(t,e)=>{const o=d.primeEventId();e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),e.raw.write(d.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const s=setInterval(()=>{e.raw.write(`: keep-alive
|
|
10
10
|
|
|
11
|
-
`)},15e3);t.raw.on("close",()=>{clearInterval(s)})}),n.delete(`${r}`,async(t,e)=>e.status(405).send({error:"Session termination not supported"}))}n.setErrorHandler(async(r,t,e)=>{t.log.error(r,"Fastify cube adapter error"),e.statusCode<400&&e.status(500);const o=r instanceof Error?r:String(r);return a.formatErrorResponse(o,e.statusCode)}),
|
|
11
|
+
`)},15e3);t.raw.on("close",()=>{clearInterval(s)})}),n.delete(`${r}`,async(t,e)=>e.status(405).send({error:"Session termination not supported"}))}n.setErrorHandler(async(r,t,e)=>{t.log.error(r,"Fastify cube adapter error"),e.statusCode<400&&e.status(500);const o=r instanceof Error?r:String(r);return a.formatErrorResponse(o,e.statusCode)}),S()};async function T(l,n){await l.register(Q,n)}function z(l){const n=require("fastify")({logger:!0});return n.register(Q,l),n}exports.createCubeApp=z;exports.cubePlugin=Q;exports.registerCubeRoutes=T;
|