Anonymous public-share AI assistant: - Add a workspace setting `publicShareAssistantRoleId` so an admin can pick which agent role (identity/persona) the anonymous assistant adopts. The role's instructions REPLACE the built-in persona while the immutable safety framework is still always appended; the role's optional model override takes precedence over the cheap publicShareChatModel. Resolved server-authoritatively (workspace-scoped, soft-delete aware; disabled/missing roles fall back to the built-in persona, so the tool scope remains the real security boundary). - Plumb the field through the update DTO, ai-settings service, the workspace.repo ALLOWED whitelist, resolve()/getMasked(), stream-time role resolution and the prompt/model, plus the settings UI: a new "Assistant identity" Select listing enabled roles (and surfacing a saved-but-disabled role explicitly). Public-share branding / floating icon: - Fix the AI assistant FAB overlapping the "Powered by ..." button (both were Affixed bottom-right): stack the FAB above the bottom-right branding. - Rename "Powered by Docmost" -> "Powered by Gitmost" and point the link at the gitmost repo. Tests: extend public-share-chat.spec (role persona replacement still appends the safety framework, resolveShareRole edge cases, model-override precedence). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
102 lines
3.4 KiB
TypeScript
102 lines
3.4 KiB
TypeScript
import api from "@/lib/api-client";
|
|
|
|
// Supported LLM providers/drivers.
|
|
export type AiDriver = "openai" | "gemini" | "ollama";
|
|
|
|
// How STT (speech-to-text) requests are encoded for the transcription endpoint.
|
|
// - 'multipart' -> OpenAI-compatible multipart/form-data (OpenAI, speaches,
|
|
// faster-whisper-server)
|
|
// - 'json' -> JSON body with base64-encoded audio (OpenRouter)
|
|
export type SttApiStyle = "multipart" | "json";
|
|
|
|
// Masked AI provider settings returned by the server.
|
|
// No API key is ever returned; only `hasApiKey` / `hasEmbeddingApiKey` indicate
|
|
// whether one is stored. `embeddingBaseUrl` is the RAW stored value (empty means
|
|
// "uses the chat base URL").
|
|
export interface IAiSettings {
|
|
driver?: AiDriver;
|
|
chatModel?: string;
|
|
// Cheap model id for the anonymous public-share assistant; empty = chatModel.
|
|
publicShareChatModel?: string;
|
|
// Agent-role id whose persona the public-share assistant adopts; empty =
|
|
// built-in locked persona.
|
|
publicShareAssistantRoleId?: string;
|
|
embeddingModel?: string;
|
|
baseUrl?: string;
|
|
embeddingBaseUrl?: string;
|
|
systemPrompt?: string;
|
|
hasApiKey: boolean;
|
|
hasEmbeddingApiKey: boolean;
|
|
// STT-specific settings. `sttBaseUrl` is the RAW stored value (empty means
|
|
// "uses the chat base URL"). `hasSttApiKey` indicates whether an STT-specific
|
|
// key is stored (empty means "uses the chat API key").
|
|
sttModel?: string;
|
|
sttBaseUrl?: string;
|
|
sttApiStyle?: SttApiStyle;
|
|
hasSttApiKey: boolean;
|
|
// RAG indexing coverage (pages indexed for semantic search).
|
|
indexedPages: number;
|
|
totalPages: number;
|
|
}
|
|
|
|
// Update payload. Key semantics (same for `apiKey` and `embeddingApiKey`):
|
|
// - omit the key -> key unchanged
|
|
// - `key: ''` -> clear the stored key
|
|
// - `key: 'non-empty'` -> set the key
|
|
// Non-secret fields are saved as given.
|
|
export interface IAiSettingsUpdate {
|
|
driver?: AiDriver;
|
|
chatModel?: string;
|
|
publicShareChatModel?: string;
|
|
// Agent-role id whose persona the public-share assistant adopts; empty =
|
|
// built-in locked persona.
|
|
publicShareAssistantRoleId?: string;
|
|
embeddingModel?: string;
|
|
baseUrl?: string;
|
|
embeddingBaseUrl?: string;
|
|
systemPrompt?: string;
|
|
apiKey?: string;
|
|
embeddingApiKey?: string;
|
|
sttModel?: string;
|
|
sttBaseUrl?: string;
|
|
sttApiStyle?: SttApiStyle;
|
|
// Write-only STT key (same semantics as `apiKey` / `embeddingApiKey`).
|
|
sttApiKey?: string;
|
|
}
|
|
|
|
// Result of a connection test against the configured provider.
|
|
// The error string is already sanitized server-side.
|
|
export interface IAiTestResult {
|
|
ok: boolean;
|
|
error?: string;
|
|
}
|
|
|
|
// Which endpoint a connection test probes.
|
|
export type AiTestCapability = "chat" | "embeddings" | "stt";
|
|
|
|
export async function getAiSettings(): Promise<IAiSettings> {
|
|
const req = await api.post<IAiSettings>("/workspace/ai-settings");
|
|
return req.data;
|
|
}
|
|
|
|
export async function updateAiSettings(
|
|
data: IAiSettingsUpdate,
|
|
): Promise<IAiSettings> {
|
|
const req = await api.post<IAiSettings>("/workspace/ai-settings/update", data);
|
|
return req.data;
|
|
}
|
|
|
|
export async function testAiConnection(
|
|
capability: AiTestCapability,
|
|
): Promise<IAiTestResult> {
|
|
const req = await api.post<IAiTestResult>("/workspace/ai-settings/test", {
|
|
capability,
|
|
});
|
|
return req.data;
|
|
}
|
|
|
|
export async function reindexAiEmbeddings(): Promise<IAiSettings> {
|
|
const req = await api.post<IAiSettings>("/workspace/ai-settings/reindex");
|
|
return req.data;
|
|
}
|