diff options
Diffstat (limited to 'makima/frontend/src/lib')
| -rw-r--r-- | makima/frontend/src/lib/api.ts | 466 | ||||
| -rw-r--r-- | makima/frontend/src/lib/listenApi.ts | 168 |
2 files changed, 14 insertions, 620 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts index b34f786..b7b904e 100644 --- a/makima/frontend/src/lib/api.ts +++ b/makima/frontend/src/lib/api.ts @@ -220,51 +220,9 @@ export class VersionConflictError extends Error { } } -// Available LLM models -export type LlmModel = "claude-sonnet" | "claude-opus" | "groq"; - -// Chat API types -export interface ChatMessage { - role: "user" | "assistant"; - content: string; -} - -export interface ChatRequest { - message: string; - model?: LlmModel; - history?: ChatMessage[]; - focusedElementIndex?: number; -} - -export interface ToolCallInfo { - name: string; - result: { - success: boolean; - message: string; - }; -} - -// User question types for interactive LLM tool -export interface UserQuestion { - id: string; - question: string; - options: string[]; - allowMultiple: boolean; - allowCustom: boolean; -} - -export interface UserAnswer { - id: string; - answers: string[]; -} - -export interface ChatResponse { - response: string; - toolCalls: ToolCallInfo[]; - updatedBody: BodyElement[]; - updatedSummary: string | null; - pendingQuestions?: UserQuestion[]; -} +// (LlmModel, ChatMessage, ChatRequest, UserQuestion, UserAnswer, +// ChatResponse, ToolCallInfo removed alongside the LLM module — +// see Chat API function block further down + the deleted /llm/ tree.) // File API functions export async function listFiles(): Promise<FileListResponse> { @@ -323,34 +281,7 @@ export async function deleteFile(id: string): Promise<void> { } } -// Chat API function -export async function chatWithFile( - id: string, - message: string, - model?: LlmModel, - history?: ChatMessage[], - focusedElementIndex?: number -): Promise<ChatResponse> { - const body: ChatRequest = { message }; - if (model) { - body.model = model; - } - if (history && history.length > 0) { - body.history = history; - } - if (focusedElementIndex !== undefined) { - body.focusedElementIndex = focusedElementIndex; - } - const res = await authFetch(`${API_BASE}/api/v1/files/${id}/chat`, { - method: "POST", - body: JSON.stringify(body), - }); - if (!res.ok) { - const errorText = await res.text(); - throw new Error(`Chat failed: ${errorText || res.statusText}`); - } - return res.json(); -} +// chatWithFile removed — handler `/api/v1/files/{id}/chat` is gone. // Version history types export type VersionSource = "user" | "llm" | "system"; @@ -1327,186 +1258,9 @@ export async function getDaemonReauthStatus( return res.json(); } -// ============================================================================= -// Mesh Chat Types for Task Orchestration -// ============================================================================= - -export interface MeshChatMessage { - role: "user" | "assistant"; - content: string; -} - -export interface MeshChatRequest { - message: string; - model?: LlmModel; - history?: MeshChatMessage[]; -} - -export interface MeshToolCallInfo { - name: string; - result: { - success: boolean; - message: string; - }; -} - -export interface MeshChatResponse { - response: string; - toolCalls: MeshToolCallInfo[]; - pendingQuestions?: UserQuestion[]; -} - -// Mesh Chat API functions - -// Top-level mesh chat (no specific task context) -export async function chatWithMesh( - message: string, - model?: LlmModel, - history?: MeshChatMessage[] -): Promise<MeshChatResponse> { - const body: MeshChatRequest = { message }; - if (model) { - body.model = model; - } - if (history && history.length > 0) { - body.history = history; - } - const res = await authFetch(`${API_BASE}/api/v1/mesh/chat`, { - method: "POST", - body: JSON.stringify(body), - }); - if (!res.ok) { - const errorText = await res.text(); - throw new Error(`Mesh chat failed: ${errorText || res.statusText}`); - } - return res.json(); -} - -// Task-scoped mesh chat -export async function chatWithTask( - taskId: string, - message: string, - model?: LlmModel, - history?: MeshChatMessage[] -): Promise<MeshChatResponse> { - const body: MeshChatRequest = { message }; - if (model) { - body.model = model; - } - if (history && history.length > 0) { - body.history = history; - } - const res = await authFetch(`${API_BASE}/api/v1/mesh/tasks/${taskId}/chat`, { - method: "POST", - body: JSON.stringify(body), - }); - if (!res.ok) { - const errorText = await res.text(); - throw new Error(`Mesh chat failed: ${errorText || res.statusText}`); - } - return res.json(); -} - -// ============================================================================= -// Mesh Chat History Types -// ============================================================================= - -export type MeshChatContextType = "mesh" | "task" | "subtask"; - -export interface MeshChatContext { - type: MeshChatContextType; - taskId?: string; - parentTaskId?: string; -} - -export interface MeshChatMessageRecord { - id: string; - conversationId: string; - role: "user" | "assistant" | "error"; - content: string; - contextType: MeshChatContextType; - contextTaskId: string | null; - toolCalls: MeshToolCallInfo[] | null; - pendingQuestions: UserQuestion[] | null; - createdAt: string; -} - -export interface MeshChatHistoryResponse { - conversationId: string; - messages: MeshChatMessageRecord[]; -} - -export interface MeshChatWithContextRequest { - message: string; - model?: LlmModel; - contextType?: MeshChatContextType; - contextTaskId?: string; -} - -// ============================================================================= -// Mesh Chat History API Functions -// ============================================================================= - -/** - * Get the current chat history from the database - */ -export async function getMeshChatHistory(): Promise<MeshChatHistoryResponse> { - const res = await authFetch(`${API_BASE}/api/v1/mesh/chat/history`); - if (!res.ok) { - throw new Error(`Failed to get chat history: ${res.statusText}`); - } - return res.json(); -} - -/** - * Clear chat history (archives current conversation, starts new one) - */ -export async function clearMeshChatHistory(): Promise<{ success: boolean; conversationId: string }> { - const res = await authFetch(`${API_BASE}/api/v1/mesh/chat/history`, { - method: "DELETE", - }); - if (!res.ok) { - throw new Error(`Failed to clear chat history: ${res.statusText}`); - } - return res.json(); -} - -/** - * Chat with mesh using context (new approach with DB history) - */ -export async function chatWithMeshContext( - message: string, - context: MeshChatContext, - model?: LlmModel -): Promise<MeshChatResponse> { - const body: MeshChatWithContextRequest = { - message, - contextType: context.type, - }; - - if (model) { - body.model = model; - } - - // Set contextTaskId based on context type - if (context.type === "task" && context.taskId) { - body.contextTaskId = context.taskId; - } else if (context.type === "subtask" && context.taskId) { - body.contextTaskId = context.taskId; - } - - // Use top-level endpoint (it now loads history from DB) - const res = await authFetch(`${API_BASE}/api/v1/mesh/chat`, { - method: "POST", - body: JSON.stringify(body), - }); - - if (!res.ok) { - const errorText = await res.text(); - throw new Error(`Mesh chat failed: ${errorText || res.statusText}`); - } - return res.json(); -} +// (Mesh chat types + chatWithMesh / chatWithTask / getMeshChatHistory / +// clearMeshChatHistory / chatWithMeshContext / MeshChatContext etc. +// removed alongside the LLM module — backend handlers gone.) // ============================================================================= // API Key Management @@ -1770,58 +1524,10 @@ export function getDefaultPhase(contractType: ContractType): ContractPhase { return "research"; } -// ============================================================================= -// Contract Type Templates -// ============================================================================= - -/** Contract type template returned by the API */ -export interface ContractTypeTemplate { - /** Template identifier (e.g., "simple", "specification") */ - id: string; - /** Display name */ - name: string; - /** Description of the contract type workflow */ - description: string; - /** Ordered list of phases for this contract type */ - phases: ContractPhase[]; - /** Default starting phase */ - defaultPhase: ContractPhase; - /** Whether this is a built-in type (always available) */ - isBuiltin: boolean; - /** Optional mapping from phase ID to display name */ - phaseNames?: Record<string, string>; -} - -/** Response from list contract types endpoint */ -export interface ListContractTypesResponse { - contractTypes: ContractTypeTemplate[]; -} - -/** Phase definition for custom templates */ -export interface PhaseDefinition { - id: string; - name: string; - order: number; -} - -/** Deliverable definition for custom templates */ -export interface DeliverableDefinition { - id: string; - name: string; - priority: "required" | "recommended" | "optional"; -} - -/** - * List available contract types. - * Returns built-in types only (simple, specification, execute). - */ -export async function listContractTypes(): Promise<ListContractTypesResponse> { - const res = await authFetch(`${API_BASE}/api/v1/contract-types`); - if (!res.ok) { - throw new Error(`Failed to list contract types: ${res.statusText}`); - } - return res.json(); -} +// (ContractTypeTemplate / ListContractTypesResponse / PhaseDefinition / +// DeliverableDefinition / listContractTypes removed alongside the LLM +// module — the templates handler was the only consumer and the +// endpoint /api/v1/contract-types is gone.) export interface ContractRepository { id: string; @@ -2194,153 +1900,9 @@ export async function removeTaskFromContract( } } -// ============================================================================= -// Contract Chat Types and API -// ============================================================================= - -export interface ContractChatRequest { - message: string; - model?: LlmModel; - history?: ChatMessage[]; -} - -export interface ContractToolCallInfo { - name: string; - result: { - success: boolean; - message: string; - }; -} - -export interface ContractChatResponse { - response: string; - toolCalls: ContractToolCallInfo[]; - pendingQuestions?: UserQuestion[]; -} - -/** - * Chat with a contract using LLM-powered management tools. - */ -export async function chatWithContract( - contractId: string, - message: string, - model?: LlmModel, - history?: ChatMessage[] -): Promise<ContractChatResponse> { - const body: ContractChatRequest = { message }; - if (model) { - body.model = model; - } - if (history && history.length > 0) { - body.history = history; - } - const res = await authFetch(`${API_BASE}/api/v1/contracts/${contractId}/chat`, { - method: "POST", - body: JSON.stringify(body), - }); - if (!res.ok) { - const errorText = await res.text(); - throw new Error(`Contract chat failed: ${errorText || res.statusText}`); - } - return res.json(); -} - -// Contract chat history types -export interface ContractChatMessage { - id: string; - conversationId: string; - role: "user" | "assistant" | "error"; - content: string; - toolCalls?: unknown; - pendingQuestions?: unknown; - createdAt: string; -} - -export interface ContractChatHistoryResponse { - contractId: string; - conversationId: string; - messages: ContractChatMessage[]; -} - -/** Get contract chat history */ -export async function getContractChatHistory( - contractId: string -): Promise<ContractChatHistoryResponse> { - const res = await authFetch( - `${API_BASE}/api/v1/contracts/${contractId}/chat/history` - ); - if (!res.ok) { - throw new Error(`Failed to fetch contract chat history: ${res.statusText}`); - } - return res.json(); -} - -/** Clear contract chat history (starts a new conversation) */ -export async function clearContractChatHistory( - contractId: string -): Promise<void> { - const res = await authFetch( - `${API_BASE}/api/v1/contracts/${contractId}/chat/history`, - { method: "DELETE" } - ); - if (!res.ok) { - throw new Error(`Failed to clear contract chat history: ${res.statusText}`); - } -} - -// ============================================================================= -// Contract Discussion Types and API -// ============================================================================= - -export interface DiscussContractRequest { - message: string; - model?: LlmModel; - history?: ChatMessage[]; - transcriptContext?: string; -} - -export interface CreatedContractInfo { - id: string; - name: string; - description: string | null; - contractType: string; - initialPhase: string; -} - -export interface DiscussContractResponse { - response: string; - toolCalls: ContractToolCallInfo[]; - createdContract?: CreatedContractInfo; - pendingQuestions?: UserQuestion[]; -} - -/** - * Discuss a potential contract with Makima. - * This is an ephemeral conversation that can result in contract creation. - */ -export async function discussContract( - message: string, - model?: LlmModel, - history?: ChatMessage[], - transcriptContext?: string -): Promise<DiscussContractResponse> { - const body: DiscussContractRequest = { message }; - if (model) body.model = model; - if (history && history.length > 0) body.history = history; - if (transcriptContext) body.transcriptContext = transcriptContext; - - const res = await authFetch(`${API_BASE}/api/v1/contracts/discuss`, { - method: "POST", - body: JSON.stringify(body), - }); - - if (!res.ok) { - const errorText = await res.text(); - throw new Error(`Discussion failed: ${errorText || res.statusText}`); - } - - return res.json(); -} +// (Contract Chat / Contract Discussion API removed alongside the LLM +// module — legacy contracts chat handlers were already Phase-5 +// removed; these were the dead frontend half.) // ============================================================================= // Template Types and API diff --git a/makima/frontend/src/lib/listenApi.ts b/makima/frontend/src/lib/listenApi.ts deleted file mode 100644 index 187ebe0..0000000 --- a/makima/frontend/src/lib/listenApi.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { API_BASE } from './api'; -import { supabase } from './supabase'; - -// ============================================================================= -// Authentication helper (same pattern as api.ts) -// ============================================================================= - -/** Storage key for API key */ -const API_KEY_STORAGE_KEY = "makima_api_key"; - -/** Get stored API key from localStorage */ -function getStoredApiKey(): string | null { - if (typeof window === "undefined") return null; - return localStorage.getItem(API_KEY_STORAGE_KEY); -} - -/** Get auth headers for API requests */ -async function getAuthHeaders(): Promise<HeadersInit> { - const headers: HeadersInit = { - "Content-Type": "application/json", - }; - - // Try Supabase session first - if (supabase) { - const { data: { session } } = await supabase.auth.getSession(); - if (session?.access_token) { - headers["Authorization"] = `Bearer ${session.access_token}`; - return headers; - } - } - - // Fall back to API key if available - const apiKey = getStoredApiKey(); - if (apiKey) { - headers["X-Makima-API-Key"] = apiKey; - } - - return headers; -} - -// ============================================================================= -// Transcript Analysis Types -// ============================================================================= - -export interface TranscriptAnalysisResult { - requirements: Array<{ - text: string; - speaker: string; - timestamp: number; - confidence: number; - category?: string; - }>; - decisions: Array<{ - text: string; - speaker: string; - timestamp: number; - confidence: number; - context?: string; - }>; - actionItems: Array<{ - text: string; - speaker: string; - timestamp: number; - assignee?: string; - priority?: string; - }>; - keyTopics: string[]; - suggestedContractName?: string; - suggestedDescription?: string; - speakerSummary: Array<{ - speaker: string; - wordCount: number; - speakingTimeSeconds: number; - contributionPercentage: number; - }>; -} - -export interface AnalyzeResponse { - fileId: string; - analysis: TranscriptAnalysisResult; -} - -export interface CreateContractResponse { - contractId: string; - contractName: string; - filesCreated: Array<{ id: string; name: string; fileType: string }>; - tasksCreated: Array<{ id: string; name: string }>; -} - -export interface CreateContractOptions { - name?: string; - description?: string; - includeRequirements?: boolean; - includeDecisions?: boolean; - includeActionItems?: boolean; -} - -// ============================================================================= -// Listen API Functions -// ============================================================================= - -/** - * Analyze a transcript file to extract requirements, decisions, and action items. - */ -export async function analyzeTranscript(fileId: string): Promise<AnalyzeResponse> { - const response = await fetch(`${API_BASE}/api/v1/listen/analyze`, { - method: 'POST', - headers: await getAuthHeaders(), - body: JSON.stringify({ fileId }), - }); - - if (!response.ok) { - const error = await response.json().catch(() => ({ message: 'Failed to analyze transcript' })); - throw new Error(error.message || 'Failed to analyze transcript'); - } - - return response.json(); -} - -/** - * Create a contract from a transcript analysis. - */ -export async function createContractFromTranscript( - fileId: string, - options?: CreateContractOptions -): Promise<CreateContractResponse> { - const response = await fetch(`${API_BASE}/api/v1/listen/create-contract`, { - method: 'POST', - headers: await getAuthHeaders(), - body: JSON.stringify({ - fileId, - ...options, - }), - }); - - if (!response.ok) { - const error = await response.json().catch(() => ({ message: 'Failed to create contract' })); - throw new Error(error.message || 'Failed to create contract'); - } - - return response.json(); -} - -/** - * Update an existing contract with transcript analysis. - */ -export async function updateContractFromTranscript( - fileId: string, - contractId: string, - options?: Omit<CreateContractOptions, 'name'> -): Promise<CreateContractResponse> { - const response = await fetch(`${API_BASE}/api/v1/listen/update-contract`, { - method: 'POST', - headers: await getAuthHeaders(), - body: JSON.stringify({ - fileId, - contractId, - ...options, - }), - }); - - if (!response.ok) { - const error = await response.json().catch(() => ({ message: 'Failed to update contract' })); - throw new Error(error.message || 'Failed to update contract'); - } - - return response.json(); -} |
