- Add reversible write tools to the per-user agent toolset (page create/update/ move/soft-delete; comment reply + resolve), exposed under the user's JWT and enforced by Docmost CASL; no permanent/force delete (D3). - Non-spoofable agent provenance: sign actor/aiChatId into the access and collab tokens (TokenService), propagate via jwt.strategy onto the request, and set pages.last_updated_source/last_updated_ai_chat_id on REST create/update/move and comments.created_source/resolved_source/ai_chat_id. - packages/mcp: add an optional getCollabToken provider (content-edit provenance) and guard against empty tokens; service-account /mcp path unchanged. Frontend: - Admin 'AI / Models' settings section: provider/model/embedding/base URL, a write-only API key field, system prompt, and Test connection. - AI chat panel (useChat + DefaultChatTransport): conversation list, streamed messages, tool-call action log and page citations; header entry point gated on settings.ai.chat. Compile-verified (server nest build + client tsc/vite); not yet live-tested. Known gaps: history 'AI agent' badge (C3), vector RAG (D), external MCP (E); chat tool-card citation links pending a fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import api from "@/lib/api-client";
|
|
import { IPagination } from "@/lib/types.ts";
|
|
import {
|
|
IAiChat,
|
|
IAiChatListParams,
|
|
IAiChatMessageRow,
|
|
IAiChatMessagesParams,
|
|
} from "@/features/ai-chat/types/ai-chat.types.ts";
|
|
|
|
/**
|
|
* Per-user AI chat CRUD. The server uses POST for reads (its convention) and
|
|
* wraps every (non-stream) response in `{ data }` via the global transform
|
|
* interceptor, which the axios client unwraps to the body — so we read `.data`
|
|
* (mirroring `comment-service`). The `/ai-chat/stream` endpoint is consumed by
|
|
* the AI SDK `useChat` transport directly, not here.
|
|
*/
|
|
|
|
/** List the current user's chats (most recent first, paginated). */
|
|
export async function getAiChats(
|
|
params: IAiChatListParams,
|
|
): Promise<IPagination<IAiChat>> {
|
|
const req = await api.post<IPagination<IAiChat>>("/ai-chat/chats", params);
|
|
return req.data;
|
|
}
|
|
|
|
/** Fetch a chat's messages (oldest first, paginated). */
|
|
export async function getAiChatMessages(
|
|
params: IAiChatMessagesParams,
|
|
): Promise<IPagination<IAiChatMessageRow>> {
|
|
const req = await api.post<IPagination<IAiChatMessageRow>>(
|
|
"/ai-chat/messages",
|
|
params,
|
|
);
|
|
return req.data;
|
|
}
|
|
|
|
/** Rename a chat. */
|
|
export async function renameAiChat(data: {
|
|
chatId: string;
|
|
title: string;
|
|
}): Promise<void> {
|
|
await api.post("/ai-chat/rename", data);
|
|
}
|
|
|
|
/** Soft-delete a chat. */
|
|
export async function deleteAiChat(chatId: string): Promise<void> {
|
|
await api.post("/ai-chat/delete", { chatId });
|
|
}
|