6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
154 lines
4.3 KiB
TypeScript
154 lines
4.3 KiB
TypeScript
import {
|
|
type CreateCommentRequest,
|
|
type CreateReplyRequest,
|
|
createCommentRequest,
|
|
createCommentResponse,
|
|
createReplyRequest,
|
|
createReplyResponse,
|
|
type DeleteCommentRequest,
|
|
deleteCommentRequest,
|
|
deleteCommentResponse,
|
|
type GetBatchCommentsRequest,
|
|
type GetCommentsRequest,
|
|
type GetMentionsRequest,
|
|
getBatchCommentsRequest,
|
|
getBatchCommentsResponse,
|
|
getCommentsRequest,
|
|
getCommentsResponse,
|
|
getMentionsRequest,
|
|
getMentionsResponse,
|
|
type UpdateCommentRequest,
|
|
updateCommentRequest,
|
|
updateCommentResponse,
|
|
} from "@/contracts/types/chat-comments.types";
|
|
import { ValidationError } from "@/lib/error";
|
|
import { baseApiService } from "./base-api.service";
|
|
|
|
class ChatCommentsApiService {
|
|
/**
|
|
* Batch-fetch comments for multiple messages in one request
|
|
*/
|
|
getBatchComments = async (request: GetBatchCommentsRequest) => {
|
|
const parsed = getBatchCommentsRequest.safeParse(request);
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
return baseApiService.post("/api/v1/messages/comments/batch", getBatchCommentsResponse, {
|
|
body: { message_ids: parsed.data.message_ids },
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Get comments for a message
|
|
*/
|
|
getComments = async (request: GetCommentsRequest) => {
|
|
const parsed = getCommentsRequest.safeParse(request);
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
return baseApiService.get(
|
|
`/api/v1/messages/${parsed.data.message_id}/comments`,
|
|
getCommentsResponse
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Create a top-level comment
|
|
*/
|
|
createComment = async (request: CreateCommentRequest) => {
|
|
const parsed = createCommentRequest.safeParse(request);
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
return baseApiService.post(
|
|
`/api/v1/messages/${parsed.data.message_id}/comments`,
|
|
createCommentResponse,
|
|
{ body: { content: parsed.data.content } }
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Create a reply to a comment
|
|
*/
|
|
createReply = async (request: CreateReplyRequest) => {
|
|
const parsed = createReplyRequest.safeParse(request);
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
return baseApiService.post(
|
|
`/api/v1/comments/${parsed.data.comment_id}/replies`,
|
|
createReplyResponse,
|
|
{ body: { content: parsed.data.content } }
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Update a comment
|
|
*/
|
|
updateComment = async (request: UpdateCommentRequest) => {
|
|
const parsed = updateCommentRequest.safeParse(request);
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
return baseApiService.put(`/api/v1/comments/${parsed.data.comment_id}`, updateCommentResponse, {
|
|
body: { content: parsed.data.content },
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Delete a comment
|
|
*/
|
|
deleteComment = async (request: DeleteCommentRequest) => {
|
|
const parsed = deleteCommentRequest.safeParse(request);
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
return baseApiService.delete(
|
|
`/api/v1/comments/${parsed.data.comment_id}`,
|
|
deleteCommentResponse
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Get mentions for current user
|
|
*/
|
|
getMentions = async (request?: GetMentionsRequest) => {
|
|
const parsed = getMentionsRequest.safeParse(request ?? {});
|
|
|
|
if (!parsed.success) {
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
}
|
|
|
|
const params = new URLSearchParams();
|
|
if (parsed.data.workspace_id !== undefined) {
|
|
params.set("workspace_id", String(parsed.data.workspace_id));
|
|
}
|
|
|
|
const queryString = params.toString();
|
|
const url = queryString ? `/api/v1/mentions?${queryString}` : "/api/v1/mentions";
|
|
|
|
return baseApiService.get(url, getMentionsResponse);
|
|
};
|
|
}
|
|
|
|
export const chatCommentsApiService = new ChatCommentsApiService();
|