-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can get conversationsId in the feedback card
- Loading branch information
Showing
5 changed files
with
161 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Fetcher } from "swr"; | ||
|
||
import { fetcher, useSWRWithDefaults } from "@app/lib/swr/swr"; | ||
|
||
export function useFeedbackConversation({ | ||
workspaceId, | ||
feedbackId, | ||
}: { | ||
feedbackId: string; | ||
workspaceId: string; | ||
}) { | ||
const feedbackFetcher: Fetcher<{ | ||
conversationId: string; | ||
}> = fetcher; | ||
|
||
const { data, error } = useSWRWithDefaults( | ||
`/api/w/${workspaceId}/assistant/feedbacks/${feedbackId}/conversation`, | ||
feedbackFetcher | ||
); | ||
|
||
return { | ||
conversationId: data ? data.conversationId : null, | ||
isLoading: !error && !data, | ||
isError: error, | ||
}; | ||
} |
59 changes: 59 additions & 0 deletions
59
front/pages/api/w/[wId]/assistant/feedbacks/[fId]/conversation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { WithAPIErrorResponse } from "@dust-tt/types"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { withSessionAuthenticationForWorkspace } from "@app/lib/api/auth_wrappers"; | ||
import type { Authenticator } from "@app/lib/auth"; | ||
import { AgentMessageFeedbackResource } from "@app/lib/resources/agent_message_feedback_resource"; | ||
import { apiError } from "@app/logger/withlogging"; | ||
|
||
export type GetAgentConfigurationsResponseBody = { | ||
conversationId: string; | ||
}; | ||
|
||
async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse< | ||
WithAPIErrorResponse<GetAgentConfigurationsResponseBody | void> | ||
>, | ||
auth: Authenticator | ||
): Promise<void> { | ||
switch (req.method) { | ||
case "GET": | ||
if (typeof req.query.fId !== "string" || req.query.fId === "") { | ||
return apiError(req, res, { | ||
status_code: 400, | ||
api_error: { | ||
type: "invalid_request_error", | ||
message: "Invalid query parameters, `fId` (string) is required.", | ||
}, | ||
}); | ||
} | ||
|
||
const conversationId = | ||
await AgentMessageFeedbackResource.fetchConversationId(req.query.fId); | ||
|
||
if (!conversationId) { | ||
return apiError(req, res, { | ||
status_code: 404, | ||
api_error: { | ||
type: "conversation_not_found", | ||
message: `Conversation not found for feedback ${req.query.fId}`, | ||
}, | ||
}); | ||
} | ||
|
||
return res.status(200).json({ | ||
conversationId, | ||
}); | ||
default: | ||
return apiError(req, res, { | ||
status_code: 405, | ||
api_error: { | ||
type: "method_not_supported_error", | ||
message: "The method passed is not supported, GET is expected.", | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export default withSessionAuthenticationForWorkspace(handler); |