-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
poke: useSwr for Conversation (#5727)
* poke: useSwr for Conversation * with the route
- Loading branch information
Showing
3 changed files
with
149 additions
and
48 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
front/pages/api/poke/workspaces/[wId]/conversations/[cId]/index.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,70 @@ | ||
import type { ConversationType, WithAPIErrorReponse } from "@dust-tt/types"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { getConversation } from "@app/lib/api/assistant/conversation"; | ||
import { Authenticator, getSession } from "@app/lib/auth"; | ||
import { apiError, withLogging } from "@app/logger/withlogging"; | ||
|
||
export type GetConversationResponseBody = { | ||
conversation: ConversationType; | ||
}; | ||
|
||
async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<WithAPIErrorReponse<GetConversationResponseBody>> | ||
): Promise<void> { | ||
const session = await getSession(req, res); | ||
const auth = await Authenticator.fromSuperUserSession( | ||
session, | ||
req.query.wId as string | ||
); | ||
|
||
if (!auth.isDustSuperUser()) { | ||
return apiError(req, res, { | ||
status_code: 404, | ||
api_error: { | ||
type: "user_not_found", | ||
message: "Could not find the user.", | ||
}, | ||
}); | ||
} | ||
|
||
const { cId } = req.query; | ||
if (!cId || typeof cId !== "string") { | ||
return apiError(req, res, { | ||
status_code: 400, | ||
api_error: { | ||
type: "invalid_request_error", | ||
message: "The request query is invalid, expects { cId: string }.", | ||
}, | ||
}); | ||
} | ||
|
||
switch (req.method) { | ||
case "GET": | ||
const conversation = await getConversation(auth, cId, true); | ||
|
||
if (!conversation) { | ||
return apiError(req, res, { | ||
status_code: 404, | ||
api_error: { | ||
type: "conversation_not_found", | ||
message: "Could not find the conversation.", | ||
}, | ||
}); | ||
} | ||
|
||
return res.status(200).json({ conversation }); | ||
|
||
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 withLogging(handler); |
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