Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

refac: Use SDK to submit feedback

Rene Wang0f0eb40b4115
diff --git a/package.json b/package.json
index 1fb08b19a47..292a2ca6e50 100644
--- a/package.json
+++ b/package.json
@@ -204,7 +204,7 @@
"@lobehub/desktop-ipc-typings": "workspace:*",
"@lobehub/editor": "^3.4.1",
"@lobehub/icons": "^4.0.2",
- "@lobehub/market-sdk": "^0.25.0",
+ "@lobehub/market-sdk": "^0.25.1",
"@lobehub/tts": "^4.0.2",
"@lobehub/ui": "^4.5.0",
"@modelcontextprotocol/sdk": "^1.25.1",
@@ -454,4 +454,4 @@
"access": "public",
"registry": "https://registry.npmjs.org"
}
-}
+}
\ No newline at end of file
diff --git a/src/components/FeedbackModal/index.tsx b/src/components/FeedbackModal/index.tsx
index a5136146074..b91bcb7ba36 100644
--- a/src/components/FeedbackModal/index.tsx
+++ b/src/components/FeedbackModal/index.tsx
@@ -6,9 +6,12 @@ import { ImagePlus, Send } from 'lucide-react';
import { memo, useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { MarketSDK } from '@lobehub/market-sdk';
+
import TextArea from '@/components/TextArea';
-import { lambdaClient } from '@/libs/trpc/client';
import { useFileStore } from '@/store/file';
+import { userProfileSelectors } from '@/store/user/selectors';
+import { useUserStore } from '@/store/user/store';
interface FeedbackModalProps {
onClose: () => void;
@@ -30,6 +33,7 @@ const FeedbackModal = memo<FeedbackModalProps>(({ onClose, open }) => {
const [uploadingScreenshot, setUploadingScreenshot] = useState(false);
const uploadWithProgress = useFileStore((s) => s.uploadWithProgress);
+ const userEmail = useUserStore(userProfileSelectors.email);
const handleScreenshotUpload = useCallback(
async (file: File) => {
@@ -65,20 +69,23 @@ const FeedbackModal = memo<FeedbackModalProps>(({ onClose, open }) => {
const values = await form.validateFields();
setLoading(true);
- // Collect client information
- const clientInfo = {
- language: navigator.language,
- screenResolution: `${window.screen.width}x${window.screen.height}`,
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
- url: window.location.href,
- userAgent: navigator.userAgent,
- viewport: `${window.innerWidth}x${window.innerHeight}`,
- };
-
- await lambdaClient.feedback.submitFeedback.mutate({
- clientInfo,
- message: values.message,
- screenshotUrl: screenshotUrl || undefined,
+ const sdk = new MarketSDK();
+
+ // Build message with screenshot if available
+ let feedbackMessage = values.message;
+ if (screenshotUrl) {
+ feedbackMessage += `\n\n**Screenshot**: ${screenshotUrl}`;
+ }
+
+ const response = await sdk.feedback.submitFeedback({
+ clientInfo: {
+ language: navigator.language,
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
+ url: window.location.href,
+ userAgent: navigator.userAgent,
+ },
+ email: userEmail,
+ message: feedbackMessage,
title: values.title,
});
@@ -86,19 +93,18 @@ const FeedbackModal = memo<FeedbackModalProps>(({ onClose, open }) => {
form.resetFields();
setScreenshotUrl(null);
onClose();
- } catch (error: any) {
- console.error('[FeedbackModal] Submission failed:', error);
- // Handle specific error types
- if (error?.message?.includes('team')) {
- message.error(t('feedback.errors.teamNotFound'));
- } else {
- message.error(t('feedback.errors.submitFailed'));
+ // Optionally show the issue URL to the user
+ if (response.issueUrl) {
+ console.log('Feedback submitted:', response.issueUrl);
}
+ } catch (error: any) {
+ console.error('[FeedbackModal] Submission failed:', error);
+ message.error(t('feedback.errors.submitFailed'));
} finally {
setLoading(false);
}
- }, [form, message, onClose, screenshotUrl, t]);
+ }, [form, message, onClose, screenshotUrl, t, userEmail]);
const handleCancel = useCallback(() => {
form.resetFields();
diff --git a/src/server/routers/lambda/feedback.ts b/src/server/routers/lambda/feedback.ts
deleted file mode 100644
index d22450b66b6..00000000000
--- a/src/server/routers/lambda/feedback.ts
+++ /dev/null
@@ -1,172 +0,0 @@
-import { TRPCError } from '@trpc/server';
-import { z } from 'zod';
-
-import { UserModel } from '@/database/models/user';
-import { authedProcedure, router } from '@/libs/trpc/lambda';
-import { serverDatabase } from '@/libs/trpc/lambda/middleware';
-
-const submitFeedbackSchema = z.object({
- clientInfo: z
- .object({
- language: z.string().optional(),
- screenResolution: z.string().optional(),
- timezone: z.string().optional(),
- url: z.string().optional(),
- userAgent: z.string().optional(),
- viewport: z.string().optional(),
- })
- .optional(),
- message: z.string().min(1).max(5000),
- screenshotUrl: z.string().url().optional(),
- title: z.string().min(1).max(200),
-});
-
-const feedbackProcedure = authedProcedure.use(serverDatabase).use(async ({ ctx, next }) => {
- return next({
- ctx: {
- userModel: new UserModel(ctx.serverDB, ctx.userId),
- },
- });
-});
-
-// Linear GraphQL API helper
-async function createLinearIssue(params: {
- description: string;
- labelIds?: string[];
- teamId: string;
- title: string;
-}): Promise<{ id: string; url: string }> {
- const LINEAR_API_KEY = process.env.LINEAR_API_KEY;
-
- if (!LINEAR_API_KEY) {
- throw new TRPCError({
- code: 'INTERNAL_SERVER_ERROR',
- message: 'Linear API key not configured',
- });
- }
-
- const query = `
- mutation IssueCreate($title: String!, $description: String!, $teamId: String!, $labelIds: [String!]) {
- issueCreate(input: {
- title: $title
- description: $description
- teamId: $teamId
- labelIds: $labelIds
- }) {
- success
- issue {
- id
- url
- }
- }
- }
- `;
-
- const variables: Record<string, any> = {
- description: params.description,
- teamId: params.teamId,
- title: params.title,
- };
-
- // Only include labelIds if provided
- if (params.labelIds && params.labelIds.length > 0) {
- variables.labelIds = params.labelIds;
- }
-
- const response = await fetch('https://api.linear.app/graphql', {
- body: JSON.stringify({ query, variables }),
- headers: {
- 'Authorization': LINEAR_API_KEY,
- 'Content-Type': 'application/json',
- },
- method: 'POST',
- });
-
- if (!response.ok) {
- throw new TRPCError({
- code: 'INTERNAL_SERVER_ERROR',
- message: `Linear API error: ${response.statusText}`,
- });
- }
-
- const result: any = await response.json();
-
- if (result.errors) {
- throw new TRPCError({
- code: 'INTERNAL_SERVER_ERROR',
- message: `Linear GraphQL error: ${result.errors[0]?.message}`,
- });
- }
-
- if (!result.data?.issueCreate?.success) {
- throw new TRPCError({
- code: 'INTERNAL_SERVER_ERROR',
- message: 'Failed to create Linear issue',
- });
- }
-
- return result.data.issueCreate.issue;
-}
-
-export const feedbackRouter = router({
- submitFeedback: feedbackProcedure.input(submitFeedbackSchema).mutation(async ({ ctx, input }) => {
- const LINEAR_TEAM_ID = process.env.LINEAR_TEAM_ID;
-
- if (!LINEAR_TEAM_ID) {
- throw new TRPCError({
- code: 'INTERNAL_SERVER_ERROR',
- message: 'Linear team ID not configured',
- });
- }
-
- // 1. Get user email
- const userState = await ctx.userModel.getUserState(async () => ({}));
-
- // 2. Build description with email, screenshot, and client info
- let description = input.message;
-
- // Add user email
- if (userState.email) {
- description += `\n\n---\n**Submitted by**: ${userState.email}`;
- }
-
- // Add screenshot
- if (input.screenshotUrl) {
- description += `\n\n**Screenshot**: ${input.screenshotUrl}`;
- }
-
- // Add client information as a table
- if (input.clientInfo) {
- description += '\n\n## System Information\n\n';
- description += '| Property | Value |\n';
- description += '|----------|-------|\n';
- if (input.clientInfo.url) description += `| URL | ${input.clientInfo.url} |\n`;
- if (input.clientInfo.userAgent)
- description += `| User Agent | ${input.clientInfo.userAgent} |\n`;
- if (input.clientInfo.language)
- description += `| Language | ${input.clientInfo.language} |\n`;
- if (input.clientInfo.timezone)
- description += `| Timezone | ${input.clientInfo.timezone} |\n`;
- if (input.clientInfo.screenResolution)
- description += `| Screen | ${input.clientInfo.screenResolution} |\n`;
- if (input.clientInfo.viewport)
- description += `| Viewport | ${input.clientInfo.viewport} |\n`;
- }
-
- // 3. Get label ID if configured
- const LINEAR_FEEDBACK_LABEL_ID = process.env.LINEAR_FEEDBACK_LABEL_ID;
- const labelIds = LINEAR_FEEDBACK_LABEL_ID ? [LINEAR_FEEDBACK_LABEL_ID] : undefined;
-
- // 4. Create Linear issue via GraphQL API
- const issue = await createLinearIssue({
- description,
- labelIds,
- teamId: LINEAR_TEAM_ID,
- title: input.title,
- });
-
- return { issueId: issue.id, issueUrl: issue.url, success: true };
- }),
-});
-
-export type FeedbackRouter = typeof feedbackRouter;
diff --git a/src/server/routers/lambda/index.ts b/src/server/routers/lambda/index.ts
index 19346af1985..7ba8b49f578 100644
--- a/src/server/routers/lambda/index.ts
+++ b/src/server/routers/lambda/index.ts
@@ -19,7 +19,6 @@ import { comfyuiRouter } from './comfyui';
import { configRouter } from './config';
import { documentRouter } from './document';
import { exporterRouter } from './exporter';
-import { feedbackRouter } from './feedback';
import { fileRouter } from './file';
import { generationRouter } from './generation';
import { generationBatchRouter } from './generationBatch';
@@ -57,7 +56,6 @@ export const lambdaRouter = router({
config: configRouter,
document: documentRouter,
exporter: exporterRouter,
- feedback: feedbackRouter,
file: fileRouter,
generation: generationRouter,
generationBatch: generationBatchRouter,