drizzle-cube 0.4.20 → 0.4.22
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 +119 -116
- package/dist/adapters/fastify/index.cjs +6 -6
- package/dist/adapters/fastify/index.js +113 -110
- package/dist/adapters/google-BAK9pnQf.cjs +2 -0
- package/dist/adapters/google-DficVAsJ.js +146 -0
- package/dist/adapters/{handler-CbDMdSY5.js → handler-9Rdn7zM2.js} +534 -461
- package/dist/adapters/handler-B-tEntiU.cjs +39 -0
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +199 -196
- 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 +245 -242
- package/dist/adapters/openai-CUSRuKTk.js +131 -0
- package/dist/adapters/openai-mLo2MCat.cjs +1 -0
- package/dist/client/charts.js +12 -12
- package/dist/client/chunks/{RetentionCombinedChart-CLq89aOJ.js → RetentionCombinedChart-BK3NPsHP.js} +2 -2
- package/dist/client/chunks/{RetentionCombinedChart-CLq89aOJ.js.map → RetentionCombinedChart-BK3NPsHP.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-3z9fHE2F.js → analysis-builder-DVrv9Q4n.js} +9 -9
- package/dist/client/chunks/{analysis-builder-3z9fHE2F.js.map → analysis-builder-DVrv9Q4n.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-shared-Da-vlQa_.js → analysis-builder-shared-CrENEvEk.js} +6 -6
- package/dist/client/chunks/{analysis-builder-shared-Da-vlQa_.js.map → analysis-builder-shared-CrENEvEk.js.map} +1 -1
- package/dist/client/chunks/{chart-activity-grid-CPGcTSuh.js → chart-activity-grid-OG6he4YS.js} +2 -2
- package/dist/client/chunks/{chart-activity-grid-CPGcTSuh.js.map → chart-activity-grid-OG6he4YS.js.map} +1 -1
- package/dist/client/chunks/{chart-area-ByJQ7NZd.js → chart-area-TawAd2k9.js} +3 -3
- package/dist/client/chunks/{chart-area-ByJQ7NZd.js.map → chart-area-TawAd2k9.js.map} +1 -1
- package/dist/client/chunks/{chart-bar-dj14frMt.js → chart-bar-D3vtCNQG.js} +2 -2
- package/dist/client/chunks/{chart-bar-dj14frMt.js.map → chart-bar-D3vtCNQG.js.map} +1 -1
- package/dist/client/chunks/{chart-box-plot-ZatBpatq.js → chart-box-plot-BXwN2rO5.js} +2 -2
- package/dist/client/chunks/{chart-box-plot-ZatBpatq.js.map → chart-box-plot-BXwN2rO5.js.map} +1 -1
- package/dist/client/chunks/{chart-bubble-CemotLx-.js → chart-bubble-ZfNe8t5k.js} +2 -2
- package/dist/client/chunks/{chart-bubble-CemotLx-.js.map → chart-bubble-ZfNe8t5k.js.map} +1 -1
- package/dist/client/chunks/{chart-candlestick-BIR4uGGt.js → chart-candlestick-DmF3haFu.js} +2 -2
- package/dist/client/chunks/{chart-candlestick-BIR4uGGt.js.map → chart-candlestick-DmF3haFu.js.map} +1 -1
- package/dist/client/chunks/{chart-data-table-BsAjHe7o.js → chart-data-table-DJZPkArt.js} +4 -4
- package/dist/client/chunks/{chart-data-table-BsAjHe7o.js.map → chart-data-table-DJZPkArt.js.map} +1 -1
- package/dist/client/chunks/{chart-funnel-dofnhD24.js → chart-funnel-CE9x0Io9.js} +2 -2
- package/dist/client/chunks/{chart-funnel-dofnhD24.js.map → chart-funnel-CE9x0Io9.js.map} +1 -1
- package/dist/client/chunks/{chart-gauge-CKJJ8m3b.js → chart-gauge-Djs5FWxB.js} +2 -2
- package/dist/client/chunks/{chart-gauge-CKJJ8m3b.js.map → chart-gauge-Djs5FWxB.js.map} +1 -1
- package/dist/client/chunks/{chart-heat-map-BVuPUKHT.js → chart-heat-map-CqtMkdxd.js} +2 -2
- package/dist/client/chunks/{chart-heat-map-BVuPUKHT.js.map → chart-heat-map-CqtMkdxd.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-delta-DUD3f8vL.js → chart-kpi-delta-DEzA74cL.js} +4 -4
- package/dist/client/chunks/{chart-kpi-delta-DUD3f8vL.js.map → chart-kpi-delta-DEzA74cL.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-number-iJh-PzsM.js → chart-kpi-number-Bab-BZtX.js} +3 -3
- package/dist/client/chunks/{chart-kpi-number-iJh-PzsM.js.map → chart-kpi-number-Bab-BZtX.js.map} +1 -1
- package/dist/client/chunks/{chart-kpi-text-x6pV9v9Q.js → chart-kpi-text-BkTgckDJ.js} +3 -3
- package/dist/client/chunks/{chart-kpi-text-x6pV9v9Q.js.map → chart-kpi-text-BkTgckDJ.js.map} +1 -1
- package/dist/client/chunks/{chart-line-DzyZkugh.js → chart-line-DhM-Hvu0.js} +3 -3
- package/dist/client/chunks/{chart-line-DzyZkugh.js.map → chart-line-DhM-Hvu0.js.map} +1 -1
- package/dist/client/chunks/{chart-measure-profile-C2IkBG3V.js → chart-measure-profile-4vQxFm69.js} +3 -3
- package/dist/client/chunks/{chart-measure-profile-C2IkBG3V.js.map → chart-measure-profile-4vQxFm69.js.map} +1 -1
- package/dist/client/chunks/{chart-pie-akbfRfb9.js → chart-pie-B86KRcHI.js} +2 -2
- package/dist/client/chunks/{chart-pie-akbfRfb9.js.map → chart-pie-B86KRcHI.js.map} +1 -1
- package/dist/client/chunks/{chart-radar-BaN-Kjww.js → chart-radar-BhDBmJRh.js} +2 -2
- package/dist/client/chunks/{chart-radar-BaN-Kjww.js.map → chart-radar-BhDBmJRh.js.map} +1 -1
- package/dist/client/chunks/{chart-radial-bar-DpptEL3s.js → chart-radial-bar-Brugya8X.js} +2 -2
- package/dist/client/chunks/{chart-radial-bar-DpptEL3s.js.map → chart-radial-bar-Brugya8X.js.map} +1 -1
- package/dist/client/chunks/{chart-sankey-CG-3hHmX.js → chart-sankey-D2L8ympI.js} +2 -2
- package/dist/client/chunks/{chart-sankey-CG-3hHmX.js.map → chart-sankey-D2L8ympI.js.map} +1 -1
- package/dist/client/chunks/{chart-scatter-l_yTVxF3.js → chart-scatter-CAkbBDkK.js} +2 -2
- package/dist/client/chunks/{chart-scatter-l_yTVxF3.js.map → chart-scatter-CAkbBDkK.js.map} +1 -1
- package/dist/client/chunks/{chart-sunburst-KhDcKhmZ.js → chart-sunburst-DaxJ-cob.js} +2 -2
- package/dist/client/chunks/{chart-sunburst-KhDcKhmZ.js.map → chart-sunburst-DaxJ-cob.js.map} +1 -1
- package/dist/client/chunks/{chart-tree-map-CBbiaBXV.js → chart-tree-map-CrDJAvZU.js} +2 -2
- package/dist/client/chunks/{chart-tree-map-CBbiaBXV.js.map → chart-tree-map-CrDJAvZU.js.map} +1 -1
- package/dist/client/chunks/{chart-waterfall-CX3vx_lI.js → chart-waterfall-BBwSfEKT.js} +3 -3
- package/dist/client/chunks/{chart-waterfall-CX3vx_lI.js.map → chart-waterfall-BBwSfEKT.js.map} +1 -1
- package/dist/client/chunks/{charts-core-CU9u_HtL.js → charts-core-B4Rbfdcn.js} +2 -2
- package/dist/client/chunks/{charts-core-CU9u_HtL.js.map → charts-core-B4Rbfdcn.js.map} +1 -1
- package/dist/client/chunks/{charts-loader-B3tt5oKG.js → charts-loader-DbrwgvCK.js} +25 -25
- package/dist/client/chunks/{charts-loader-B3tt5oKG.js.map → charts-loader-DbrwgvCK.js.map} +1 -1
- package/dist/client/chunks/{components-CMGGxqOB.js → components-GzooQM5J.js} +9 -9
- package/dist/client/chunks/{components-CMGGxqOB.js.map → components-GzooQM5J.js.map} +1 -1
- package/dist/client/chunks/{core-D_8mkGpQ.js → core-Y9e-sNfb.js} +2 -2
- package/dist/client/chunks/{core-D_8mkGpQ.js.map → core-Y9e-sNfb.js.map} +1 -1
- package/dist/client/chunks/{icons-M7shurcH.js → icons-DFJw-2HU.js} +6 -6
- package/dist/client/chunks/{icons-M7shurcH.js.map → icons-DFJw-2HU.js.map} +1 -1
- package/dist/client/chunks/{providers-CgxXm6Ll.js → providers-CCw8Kjlc.js} +2 -2
- package/dist/client/chunks/{providers-CgxXm6Ll.js.map → providers-CCw8Kjlc.js.map} +1 -1
- package/dist/client/chunks/{syntaxHighlighting-BQfjio-i.js → syntaxHighlighting-DAMSW_A6.js} +2 -2
- package/dist/client/chunks/{syntaxHighlighting-BQfjio-i.js.map → syntaxHighlighting-DAMSW_A6.js.map} +1 -1
- package/dist/client/chunks/{useDirtyStateTracking-Cu1HSjmo.js → useDirtyStateTracking-CjhwBXRw.js} +20 -20
- package/dist/client/chunks/{useDirtyStateTracking-Cu1HSjmo.js.map → useDirtyStateTracking-CjhwBXRw.js.map} +1 -1
- package/dist/client/chunks/useExplainAI-IiW55BaQ.js +182 -0
- package/dist/client/chunks/useExplainAI-IiW55BaQ.js.map +1 -0
- package/dist/client/chunks/{vendor-AVsJ2ni0.js → vendor-B2EH3V58.js} +7 -7
- package/dist/client/chunks/{vendor-AVsJ2ni0.js.map → vendor-B2EH3V58.js.map} +1 -1
- package/dist/client/components/AgenticNotebook/AgentChatPanel.d.ts +3 -0
- package/dist/client/components/AgenticNotebook/index.d.ts +6 -0
- package/dist/client/components.js +1 -1
- package/dist/client/hooks/useAgentChat.d.ts +6 -0
- package/dist/client/hooks/useNotebookLayout.d.ts +8 -0
- package/dist/client/hooks.d.ts +2 -0
- package/dist/client/hooks.js +51 -190
- package/dist/client/hooks.js.map +1 -1
- package/dist/client/icons.js +1 -1
- package/dist/client/index.js +926 -764
- package/dist/client/index.js.map +1 -1
- package/dist/client/providers.js +1 -1
- package/dist/client/styles.css +1 -1
- package/dist/client/utils.js +7 -7
- 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 +48 -46
- package/dist/server/index.d.ts +37 -10
- package/dist/server/index.js +1974 -1901
- 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-DtdjM1Vx.cjs +0 -37
|
@@ -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(
|
|
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(b,
|
|
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)})}),
|
|
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,54 +1,54 @@
|
|
|
1
|
-
import
|
|
1
|
+
import R, { Router as J } from "express";
|
|
2
2
|
import L from "cors";
|
|
3
|
-
import { S as
|
|
4
|
-
import { formatErrorResponse 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
|
-
const
|
|
22
|
-
|
|
23
|
-
const i = new
|
|
24
|
-
drizzle:
|
|
25
|
-
schema:
|
|
26
|
-
engineType:
|
|
27
|
-
cache:
|
|
21
|
+
const c = J();
|
|
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 {
|
|
33
33
|
const e = r.body.query || r.body, o = await y(r, t), a = i.validateQuery(e);
|
|
34
34
|
if (!a.isValid)
|
|
35
|
-
return t.status(400).json(
|
|
35
|
+
return t.status(400).json(u(
|
|
36
36
|
`Query validation failed: ${a.errors.join(", ")}`,
|
|
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
|
-
console.error("Query execution error:", e), t.status(500).json(
|
|
42
|
+
console.error("Query execution error:", e), t.status(500).json(u(
|
|
43
43
|
e instanceof Error ? e.message : "Query execution failed",
|
|
44
44
|
500
|
|
45
45
|
));
|
|
46
46
|
}
|
|
47
|
-
}),
|
|
47
|
+
}), c.get(`${p}/load`, async (r, t) => {
|
|
48
48
|
try {
|
|
49
49
|
const e = r.query.query;
|
|
50
50
|
if (!e)
|
|
51
|
-
return t.status(400).json(
|
|
51
|
+
return t.status(400).json(u(
|
|
52
52
|
"Query parameter is required",
|
|
53
53
|
400
|
|
54
54
|
));
|
|
@@ -56,107 +56,107 @@ function W(h) {
|
|
|
56
56
|
try {
|
|
57
57
|
o = JSON.parse(e);
|
|
58
58
|
} catch {
|
|
59
|
-
return t.status(400).json(
|
|
59
|
+
return t.status(400).json(u(
|
|
60
60
|
"Invalid JSON in query parameter",
|
|
61
61
|
400
|
|
62
62
|
));
|
|
63
63
|
}
|
|
64
64
|
const a = await y(r, t), n = i.validateQuery(o);
|
|
65
65
|
if (!n.isValid)
|
|
66
|
-
return t.status(400).json(
|
|
66
|
+
return t.status(400).json(u(
|
|
67
67
|
`Query validation failed: ${n.errors.join(", ")}`,
|
|
68
68
|
400
|
|
69
69
|
));
|
|
70
|
-
const s = r.headers["x-cache-control"] === "no-cache",
|
|
71
|
-
t.json(
|
|
70
|
+
const s = r.headers["x-cache-control"] === "no-cache", f = await i.executeMultiCubeQuery(o, a, { skipCache: s });
|
|
71
|
+
t.json(P(o, f, i));
|
|
72
72
|
} catch (e) {
|
|
73
|
-
console.error("Query execution error:", e), t.status(500).json(
|
|
73
|
+
console.error("Query execution error:", e), t.status(500).json(u(
|
|
74
74
|
e instanceof Error ? e.message : "Query execution failed",
|
|
75
75
|
500
|
|
76
76
|
));
|
|
77
77
|
}
|
|
78
|
-
}),
|
|
78
|
+
}), c.post(`${p}/batch`, async (r, t) => {
|
|
79
79
|
try {
|
|
80
80
|
const { queries: e } = r.body;
|
|
81
81
|
if (!e || !Array.isArray(e))
|
|
82
|
-
return t.status(400).json(
|
|
82
|
+
return t.status(400).json(u(
|
|
83
83
|
'Request body must contain a "queries" array',
|
|
84
84
|
400
|
|
85
85
|
));
|
|
86
86
|
if (e.length === 0)
|
|
87
|
-
return t.status(400).json(
|
|
87
|
+
return t.status(400).json(u(
|
|
88
88
|
"Queries array cannot be empty",
|
|
89
89
|
400
|
|
90
90
|
));
|
|
91
91
|
const o = await y(r, t), a = r.headers["x-cache-control"] === "no-cache", n = await X(e, o, i, { skipCache: a });
|
|
92
92
|
t.json(n);
|
|
93
93
|
} catch (e) {
|
|
94
|
-
console.error("Batch execution error:", e), t.status(500).json(
|
|
94
|
+
console.error("Batch execution error:", e), t.status(500).json(u(
|
|
95
95
|
e instanceof Error ? e.message : "Batch execution failed",
|
|
96
96
|
500
|
|
97
97
|
));
|
|
98
98
|
}
|
|
99
|
-
}),
|
|
99
|
+
}), c.get(`${p}/meta`, (r, t) => {
|
|
100
100
|
try {
|
|
101
101
|
const e = i.getMetadata();
|
|
102
102
|
t.json(G(e));
|
|
103
103
|
} catch (e) {
|
|
104
|
-
console.error("Metadata error:", e), t.status(500).json(
|
|
104
|
+
console.error("Metadata error:", e), t.status(500).json(u(
|
|
105
105
|
e instanceof Error ? e.message : "Failed to fetch metadata",
|
|
106
106
|
500
|
|
107
107
|
));
|
|
108
108
|
}
|
|
109
|
-
}),
|
|
109
|
+
}), c.post(`${p}/sql`, async (r, t) => {
|
|
110
110
|
try {
|
|
111
111
|
const e = r.body, o = await y(r, t), a = i.validateQuery(e);
|
|
112
112
|
if (!a.isValid)
|
|
113
|
-
return t.status(400).json(
|
|
113
|
+
return t.status(400).json(u(
|
|
114
114
|
`Query validation failed: ${a.errors.join(", ")}`,
|
|
115
115
|
400
|
|
116
116
|
));
|
|
117
117
|
const n = e.measures?.[0] || e.dimensions?.[0];
|
|
118
118
|
if (!n)
|
|
119
|
-
return t.status(400).json(
|
|
119
|
+
return t.status(400).json(u(
|
|
120
120
|
"No measures or dimensions specified",
|
|
121
121
|
400
|
|
122
122
|
));
|
|
123
|
-
const s = n.split(".")[0],
|
|
124
|
-
t.json(H(e,
|
|
123
|
+
const s = n.split(".")[0], f = await i.generateSQL(s, e, o);
|
|
124
|
+
t.json(H(e, f));
|
|
125
125
|
} catch (e) {
|
|
126
|
-
console.error("SQL generation error:", e), t.status(500).json(
|
|
126
|
+
console.error("SQL generation error:", e), t.status(500).json(u(
|
|
127
127
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
128
128
|
500
|
|
129
129
|
));
|
|
130
130
|
}
|
|
131
|
-
}),
|
|
131
|
+
}), c.get(`${p}/sql`, async (r, t) => {
|
|
132
132
|
try {
|
|
133
133
|
const e = r.query.query;
|
|
134
134
|
if (!e)
|
|
135
|
-
return t.status(400).json(
|
|
135
|
+
return t.status(400).json(u(
|
|
136
136
|
"Query parameter is required",
|
|
137
137
|
400
|
|
138
138
|
));
|
|
139
139
|
const o = JSON.parse(e), a = await y(r, t), n = i.validateQuery(o);
|
|
140
140
|
if (!n.isValid)
|
|
141
|
-
return t.status(400).json(
|
|
141
|
+
return t.status(400).json(u(
|
|
142
142
|
`Query validation failed: ${n.errors.join(", ")}`,
|
|
143
143
|
400
|
|
144
144
|
));
|
|
145
145
|
const s = o.measures?.[0] || o.dimensions?.[0];
|
|
146
146
|
if (!s)
|
|
147
|
-
return t.status(400).json(
|
|
147
|
+
return t.status(400).json(u(
|
|
148
148
|
"No measures or dimensions specified",
|
|
149
149
|
400
|
|
150
150
|
));
|
|
151
|
-
const
|
|
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
|
-
console.error("SQL generation error:", e), t.status(500).json(
|
|
154
|
+
console.error("SQL generation error:", e), t.status(500).json(u(
|
|
155
155
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
156
156
|
500
|
|
157
157
|
));
|
|
158
158
|
}
|
|
159
|
-
}),
|
|
159
|
+
}), c.post(`${p}/dry-run`, async (r, t) => {
|
|
160
160
|
try {
|
|
161
161
|
const e = r.body.query || r.body, o = await y(r, t), a = await M(e, o, i);
|
|
162
162
|
t.json(a);
|
|
@@ -166,7 +166,7 @@ function W(h) {
|
|
|
166
166
|
valid: !1
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
|
-
}),
|
|
169
|
+
}), c.get(`${p}/dry-run`, async (r, t) => {
|
|
170
170
|
try {
|
|
171
171
|
const e = r.query.query;
|
|
172
172
|
if (!e)
|
|
@@ -182,7 +182,7 @@ function W(h) {
|
|
|
182
182
|
valid: !1
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
}),
|
|
185
|
+
}), c.post(`${p}/explain`, async (r, t) => {
|
|
186
186
|
try {
|
|
187
187
|
const e = r.body.query || r.body, o = r.body.options || {}, a = await y(r, t), n = i.validateQuery(e);
|
|
188
188
|
if (!n.isValid)
|
|
@@ -196,47 +196,50 @@ 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 (
|
|
206
|
-
const
|
|
207
|
-
|
|
204
|
+
let s = (m.apiKey || "").trim();
|
|
205
|
+
if (m.allowClientApiKey) {
|
|
206
|
+
const l = r.headers["x-agent-api-key"];
|
|
207
|
+
l && (s = l.trim());
|
|
208
208
|
}
|
|
209
209
|
if (!s)
|
|
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
|
|
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",
|
|
217
217
|
Connection: "keep-alive"
|
|
218
218
|
});
|
|
219
219
|
try {
|
|
220
|
-
const
|
|
220
|
+
const l = e({
|
|
221
221
|
message: o,
|
|
222
222
|
sessionId: a,
|
|
223
223
|
history: n,
|
|
224
224
|
semanticLayer: i,
|
|
225
|
-
securityContext:
|
|
226
|
-
agentConfig:
|
|
225
|
+
securityContext: g,
|
|
226
|
+
agentConfig: m,
|
|
227
227
|
apiKey: s,
|
|
228
|
-
systemContext: j
|
|
228
|
+
systemContext: j,
|
|
229
|
+
providerOverride: f,
|
|
230
|
+
modelOverride: b,
|
|
231
|
+
baseURLOverride: d
|
|
229
232
|
});
|
|
230
|
-
for await (const
|
|
231
|
-
t.write(`data: ${JSON.stringify(
|
|
233
|
+
for await (const C of l)
|
|
234
|
+
t.write(`data: ${JSON.stringify(C)}
|
|
232
235
|
|
|
233
236
|
`);
|
|
234
|
-
} catch (
|
|
235
|
-
const
|
|
237
|
+
} catch (l) {
|
|
238
|
+
const C = {
|
|
236
239
|
type: "error",
|
|
237
|
-
data: { message:
|
|
240
|
+
data: { message: l instanceof Error ? l.message : "Stream failed" }
|
|
238
241
|
};
|
|
239
|
-
t.write(`data: ${JSON.stringify(
|
|
242
|
+
t.write(`data: ${JSON.stringify(C)}
|
|
240
243
|
|
|
241
244
|
`);
|
|
242
245
|
} finally {
|
|
@@ -247,18 +250,18 @@ function W(h) {
|
|
|
247
250
|
error: e instanceof Error ? e.message : "Agent chat failed"
|
|
248
251
|
});
|
|
249
252
|
}
|
|
250
|
-
}),
|
|
251
|
-
const r =
|
|
252
|
-
|
|
253
|
-
const o =
|
|
253
|
+
}), w.enabled !== !1) {
|
|
254
|
+
const r = w.basePath ?? "/mcp";
|
|
255
|
+
c.post(`${r}`, async (t, e) => {
|
|
256
|
+
const o = D(
|
|
254
257
|
t.headers.origin,
|
|
255
|
-
|
|
258
|
+
w.allowedOrigins ? { allowedOrigins: w.allowedOrigins } : {}
|
|
256
259
|
);
|
|
257
260
|
if (!o.valid)
|
|
258
|
-
return e.status(403).json(
|
|
261
|
+
return e.status(403).json(x(null, -32600, o.reason));
|
|
259
262
|
const a = t.headers.accept;
|
|
260
|
-
if (!
|
|
261
|
-
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"));
|
|
262
265
|
const n = V(t.headers);
|
|
263
266
|
if (!n.ok)
|
|
264
267
|
return e.status(426).json({
|
|
@@ -267,10 +270,10 @@ function W(h) {
|
|
|
267
270
|
});
|
|
268
271
|
const s = z(t.body);
|
|
269
272
|
if (!s)
|
|
270
|
-
return e.status(400).json(
|
|
271
|
-
const
|
|
273
|
+
return e.status(400).json(x(null, -32600, "Invalid JSON-RPC 2.0 request"));
|
|
274
|
+
const f = T(a), b = s.method === "initialize";
|
|
272
275
|
try {
|
|
273
|
-
const
|
|
276
|
+
const d = await B(
|
|
274
277
|
s.method,
|
|
275
278
|
s.params,
|
|
276
279
|
{
|
|
@@ -281,34 +284,34 @@ function W(h) {
|
|
|
281
284
|
negotiatedProtocol: n.negotiated
|
|
282
285
|
}
|
|
283
286
|
);
|
|
284
|
-
if (
|
|
287
|
+
if (I(s))
|
|
285
288
|
return e.status(202).end();
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
const
|
|
291
|
-
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: ${
|
|
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);
|
|
292
|
+
if (f) {
|
|
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}
|
|
292
295
|
|
|
293
|
-
`), e.write(
|
|
296
|
+
`), e.write(E(j, l)), e.end();
|
|
294
297
|
}
|
|
295
|
-
return e.json(
|
|
296
|
-
} catch (
|
|
297
|
-
if (
|
|
298
|
-
return console.error("MCP notification processing error:",
|
|
299
|
-
console.error("MCP RPC error:",
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
302
|
-
const
|
|
303
|
-
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: ${
|
|
298
|
+
return e.json(j);
|
|
299
|
+
} catch (d) {
|
|
300
|
+
if (I(s))
|
|
301
|
+
return console.error("MCP notification processing error:", d), e.status(202).end();
|
|
302
|
+
console.error("MCP RPC error:", d);
|
|
303
|
+
const g = d?.code ?? -32603, j = d?.data, l = d.message || "MCP request failed", C = x(s.id ?? null, g, l, j);
|
|
304
|
+
if (f) {
|
|
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}
|
|
304
307
|
|
|
305
|
-
`), e.write(
|
|
308
|
+
`), e.write(E(C, q)), e.end();
|
|
306
309
|
}
|
|
307
|
-
return e.status(200).json(
|
|
310
|
+
return e.status(200).json(C);
|
|
308
311
|
}
|
|
309
|
-
}),
|
|
310
|
-
const o =
|
|
311
|
-
e.status(200), e.setHeader("Content-Type", "text/event-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("Connection", "keep-alive"), e.write(
|
|
312
|
+
}), c.get(`${r}`, async (t, e) => {
|
|
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({
|
|
312
315
|
jsonrpc: "2.0",
|
|
313
316
|
method: "mcp/ready",
|
|
314
317
|
params: { protocol: "streamable-http" }
|
|
@@ -321,19 +324,19 @@ function W(h) {
|
|
|
321
324
|
t.on("close", () => {
|
|
322
325
|
clearInterval(a);
|
|
323
326
|
});
|
|
324
|
-
}),
|
|
327
|
+
}), c.delete(`${r}`, (t, e) => e.status(405).json({ error: "Session termination not supported" }));
|
|
325
328
|
}
|
|
326
|
-
return
|
|
327
|
-
console.error("Express adapter error:", r), e.headersSent || e.status(500).json(
|
|
328
|
-
}),
|
|
329
|
+
return c.use((r, t, e, o) => {
|
|
330
|
+
console.error("Express adapter error:", r), e.headersSent || e.status(500).json(u(r, 500));
|
|
331
|
+
}), c;
|
|
329
332
|
}
|
|
330
|
-
function Y(
|
|
331
|
-
const
|
|
332
|
-
return
|
|
333
|
+
function Y(v, h) {
|
|
334
|
+
const S = W(h);
|
|
335
|
+
return v.use("/", S), v;
|
|
333
336
|
}
|
|
334
|
-
function oe(
|
|
335
|
-
const
|
|
336
|
-
return Y(
|
|
337
|
+
function oe(v) {
|
|
338
|
+
const h = R();
|
|
339
|
+
return Y(h, v);
|
|
337
340
|
}
|
|
338
341
|
export {
|
|
339
342
|
oe as createCubeApp,
|