|
1 | 1 | import { Hono } from 'hono' |
| 2 | +import { zValidator } from '@hono/zod-validator' |
2 | 3 | import type { Props } from '../utils'; |
3 | | -import { McpServerError } from '../utils'; |
4 | | -import { getDataSources, ThoughtSpotService } from '../thoughtspot/thoughtspot-service'; |
| 4 | +import { ThoughtSpotService } from '../thoughtspot/thoughtspot-service'; |
5 | 5 | import { getThoughtSpotClient } from '../thoughtspot/thoughtspot-client'; |
6 | 6 | import { getActiveSpan, WithSpan } from '../metrics/tracing/tracing-utils'; |
7 | | -import { context, type Span, SpanStatusCode, trace } from "@opentelemetry/api"; |
| 7 | +import { CreateLiveboardSchema, GetAnswerSchema, GetRelevantQuestionsSchema } from './mcp-server'; |
8 | 8 |
|
9 | 9 | const apiServer = new Hono<{ Bindings: Env & { props: Props } }>() |
10 | 10 |
|
@@ -35,9 +35,9 @@ class ApiHandler { |
35 | 35 | } |
36 | 36 |
|
37 | 37 | @WithSpan('api-create-liveboard') |
38 | | - async createLiveboard(props: Props, name: string, answers: any[]) { |
| 38 | + async createLiveboard(props: Props, name: string, answers: any[], noteTileParsedHtml: string) { |
39 | 39 | const service = this.getThoughtSpotService(props); |
40 | | - const result = await service.fetchTMLAndCreateLiveboard(name, answers); |
| 40 | + const result = await service.fetchTMLAndCreateLiveboard(name, answers, noteTileParsedHtml); |
41 | 41 | return result.url || ''; |
42 | 42 | } |
43 | 43 |
|
@@ -88,25 +88,51 @@ class ApiHandler { |
88 | 88 |
|
89 | 89 | const handler = new ApiHandler(); |
90 | 90 |
|
91 | | -apiServer.post("/api/tools/relevant-questions", async (c) => { |
92 | | - const { props } = c.executionCtx; |
93 | | - const { query, datasourceIds, additionalContext } = await c.req.json(); |
94 | | - const questions = await handler.getRelevantQuestions(props, query, datasourceIds, additionalContext); |
95 | | - return c.json(questions); |
96 | | -}); |
97 | | - |
98 | | -apiServer.post("/api/tools/get-answer", async (c) => { |
99 | | - const { props } = c.executionCtx; |
100 | | - const { question, datasourceId } = await c.req.json(); |
101 | | - const answer = await handler.getAnswer(props, question, datasourceId); |
102 | | - return c.json(answer); |
103 | | -}); |
| 91 | +apiServer.post( |
| 92 | + "/api/tools/relevant-questions", |
| 93 | + zValidator('json', GetRelevantQuestionsSchema), |
| 94 | + async (c) => { |
| 95 | + const { props } = c.executionCtx; |
| 96 | + const { query, datasourceIds, additionalContext } = c.req.valid('json'); |
| 97 | + const questions = await handler.getRelevantQuestions(props, query, datasourceIds, additionalContext); |
| 98 | + return c.json(questions); |
| 99 | + } |
| 100 | +); |
| 101 | + |
| 102 | +apiServer.post( |
| 103 | + "/api/tools/get-answer", |
| 104 | + zValidator('json', GetAnswerSchema), |
| 105 | + async (c) => { |
| 106 | + const { props } = c.executionCtx; |
| 107 | + const { question, datasourceId } = c.req.valid('json'); |
| 108 | + const answer = await handler.getAnswer(props, question, datasourceId); |
| 109 | + return c.json(answer); |
| 110 | + } |
| 111 | +); |
| 112 | + |
| 113 | +apiServer.post( |
| 114 | + "/api/tools/create-liveboard", |
| 115 | + zValidator('json', CreateLiveboardSchema), |
| 116 | + async (c) => { |
| 117 | + const { props } = c.executionCtx; |
| 118 | + const { name, answers, noteTile } = c.req.valid('json'); |
| 119 | + const liveboardUrl = await handler.createLiveboard(props, name, answers, noteTile); |
| 120 | + return c.text(liveboardUrl); |
| 121 | + } |
| 122 | +); |
104 | 123 |
|
105 | | -apiServer.post("/api/tools/create-liveboard", async (c) => { |
| 124 | +apiServer.get("/api/tools/ping", async (c) => { |
106 | 125 | const { props } = c.executionCtx; |
107 | | - const { name, answers } = await c.req.json(); |
108 | | - const liveboardUrl = await handler.createLiveboard(props, name, answers); |
109 | | - return c.text(liveboardUrl); |
| 126 | + console.log("Received Ping request"); |
| 127 | + if (props.accessToken && props.instanceUrl) { |
| 128 | + return c.json({ |
| 129 | + content: [{ type: "text", text: "Pong" }], |
| 130 | + }); |
| 131 | + } |
| 132 | + return c.json({ |
| 133 | + isError: true, |
| 134 | + content: [{ type: "text", text: "ERROR: Not authenticated" }], |
| 135 | + }); |
110 | 136 | }); |
111 | 137 |
|
112 | 138 | apiServer.get("/api/resources/datasources", async (c) => { |
|
0 commit comments