Skip to content

Commit ac70596

Browse files
committed
refactor: send feedback via backend
1 parent 57d8d3a commit ac70596

File tree

7 files changed

+58
-59
lines changed

7 files changed

+58
-59
lines changed

package-lock.json

Lines changed: 0 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/src/helpers/csp.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const helmetOptions: HelmetOptions = {
1919
'https://rum-proxy.plumber.gov.sg',
2020
// For Lens Survey
2121
'https://lens.open.gov.sg',
22-
// For Pair Rome and Istanbul
23-
'https://istanbul.pair.gov.sg',
24-
'https://rome.pair.gov.sg',
2522
// For S3 bucket
2623
'https://plumber-uat-attachment-bucket-private-0d9400e.s3.ap-southeast-1.amazonaws.com',
2724
'https://plumber-staging-attachment-bucket-private-ab28487.s3.ap-southeast-1.amazonaws.com',
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { Request, Response } from 'express'
2+
import { Router } from 'express'
3+
4+
import { langfuseClient } from '@/helpers/langfuse'
5+
import logger from '@/helpers/logger'
6+
7+
import { getAuthenticatedContext } from './middleware/authentication'
8+
9+
interface ChatFeedbackRequest {
10+
traceId: string
11+
feedback: string
12+
}
13+
14+
const handleChatFeedback = async (
15+
req: Request,
16+
res: Response,
17+
): Promise<void> => {
18+
const context = getAuthenticatedContext(req)
19+
20+
try {
21+
const { traceId, feedback } = req.body as ChatFeedbackRequest
22+
23+
if (!traceId || !feedback) {
24+
res.status(400).json({ error: 'Trace ID and feedback are required' })
25+
}
26+
27+
langfuseClient.score.create({
28+
traceId,
29+
id: `feedback-${traceId}-${context.currentUser.email}`,
30+
name: 'user-feedback',
31+
value: 0, // 1 for positive, 0 for negative
32+
comment: feedback,
33+
})
34+
res.status(200).json({ success: true })
35+
} catch (error) {
36+
logger.error('Error submitting ai builder chat feedback:', error)
37+
res.status(400).json({ error: 'Failed to submit feedback' })
38+
}
39+
}
40+
41+
const router = Router()
42+
43+
router.post('/', handleChatFeedback)
44+
45+
export default router

packages/backend/src/routes/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
setCurrentUserContext,
66
} from './middleware/authentication'
77
import chatRouter from './chat'
8+
import chatFeedbackRouter from './chat-feedback'
89

910
const router = Router()
1011

@@ -15,6 +16,7 @@ router.use(requireAuthentication)
1516

1617
// Mount individual API routes
1718
router.use('/chat', chatRouter)
19+
router.use('/chat-feedback', chatFeedbackRouter)
1820

1921
// Future routes can be added here:
2022
// router.use('/users', usersRouter)

packages/frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"dedent": "1.5.1",
4242
"escape-html": "1.0.3",
4343
"file-saver": "2.0.5",
44-
"langfuse": "3.38.6",
4544
"lens-widget": "^1.37.0",
4645
"lodash": "^4.17.21",
4746
"lottie-web": "5.12.2",

packages/frontend/src/components/AiBuilder/components/ChatInterface/ChatMessageToolbar.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ import {
1818
Textarea,
1919
useDisclosure,
2020
} from '@chakra-ui/react'
21-
import { LangfuseWeb } from 'langfuse'
22-
23-
import appConfig from '@/config/app'
24-
25-
const langfuse = new LangfuseWeb({
26-
baseUrl: appConfig.pairRomeBaseUrl,
27-
publicKey: appConfig.pairRomePublicKey,
28-
})
2921

3022
interface ChatMessageToolbarProps {
3123
traceId: string
@@ -38,22 +30,23 @@ export default function ChatMessageToolbar({
3830
const firstFieldRef = React.useRef(null)
3931
const [comment, setComment] = useState('')
4032

41-
const handleSubmitFeedback = (comment: string) => {
33+
const handleSubmitFeedback = async (comment: string) => {
4234
try {
4335
if (!traceId) {
4436
return
4537
}
4638

47-
// Send feedback to Rome / Istanbul
48-
langfuse.score({
49-
traceId,
50-
id: `user-feedback-${traceId}`,
51-
name: 'user-feedback',
52-
value: 0, // 1 for positive, 0 for negative
53-
comment,
39+
// NOTE: we send feedback to the backend instead of using Langfuse directly
40+
// as there are additional headers required to call Rome/Istanbul endpoints
41+
// that should not be exposed to the frontend
42+
await fetch('/api/chat-feedback', {
43+
method: 'POST',
44+
headers: { 'Content-Type': 'application/json' },
45+
body: JSON.stringify({ traceId, feedback: comment }),
5446
})
55-
} catch (error) {
56-
console.error('Error submitting feedback:', error)
47+
} catch {
48+
// don't throw error if feedback submission fails
49+
// as it is not critical to the user experience
5750
} finally {
5851
onClose()
5952
setComment('')

packages/frontend/src/config/app.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ interface AppConfig {
77
lensSurveyClientKey: string
88
ssoClientId: string
99
ssoHostname: string
10-
pairRomeBaseUrl: string
11-
pairRomePublicKey: string
1210
}
1311

1412
function getAppConfig(): AppConfig {
@@ -30,8 +28,6 @@ function getAppConfig(): AppConfig {
3028
lensSurveyClientKey: 'cm85ca2f300053ooz4vydrmyw',
3129
ssoClientId: 'plumber-prod',
3230
ssoHostname: 'https://sso.open.gov.sg',
33-
pairRomeBaseUrl: 'https://rome.pair.gov.sg',
34-
pairRomePublicKey: '', // TODO: add public key
3531
...commonEnv,
3632
}
3733
// UAT and staging differ for the lens survey client key only
@@ -43,8 +39,6 @@ function getAppConfig(): AppConfig {
4339
lensSurveyClientKey: 'cm8fp8i030008zm2tbuc07xe5',
4440
ssoClientId: 'plumber-uat',
4541
ssoHostname: 'https://sso.open.gov.sg',
46-
pairRomeBaseUrl: 'https://rome.pair.gov.sg',
47-
pairRomePublicKey: '', // TODO: add public key
4842
...commonEnv,
4943
}
5044
case 'staging':
@@ -55,9 +49,6 @@ function getAppConfig(): AppConfig {
5549
lensSurveyClientKey: 'cm86psst900052orfqetz3gz5',
5650
ssoClientId: 'plumber-staging',
5751
ssoHostname: 'https://sso.open.gov.sg',
58-
// TODO: update to use Rome when ready
59-
pairRomeBaseUrl: 'https://istanbul.pair.gov.sg',
60-
pairRomePublicKey: 'pk-lf-1f6acb1e-85c0-4af7-bea7-6f465f7c0141',
6152
...commonEnv,
6253
}
6354
default:
@@ -68,9 +59,6 @@ function getAppConfig(): AppConfig {
6859
lensSurveyClientKey: 'cm8fpeah2000gzm2t572lhfti',
6960
ssoClientId: 'plumber-local',
7061
ssoHostname: 'http://localhost:5354',
71-
// TODO: update to use Rome when ready
72-
pairRomeBaseUrl: 'https://istanbul.pair.gov.sg',
73-
pairRomePublicKey: 'pk-lf-1f6acb1e-85c0-4af7-bea7-6f465f7c0141',
7462
...commonEnv,
7563
}
7664
}

0 commit comments

Comments
 (0)