learning_ai_notes/web/src/lib/copilot-client.ts
saravanakumardb1 3260b7ea0a feat(smart-actions): F1-F4 inline editor AI, F15-F19 mobile capture modes, F25-F27 scheduler/webhooks/approval
F1-F4: Inline editor AI
- Backend: expand CopilotAction with fix-rewrite, change-tone, continue, explain
- Backend: add tone parameter to copilot route for change-tone action
- Web: copilot-client adds CopilotTone type and tone parameter
- Web: NoteEditor toolbar gains AI row with Fix & Rewrite, Change Tone dropdown,
  Continue Writing (appends at cursor), Explain (inline popover)

F15-F19: Mobile capture enhancements
- Backend: POST /note-prompts/url-extract endpoint (fetch, strip HTML, LLM summarize)
- Mobile API: extractFromUrl() and copilotTransform() client functions
- Mobile: capture tab rewritten with 6 capture modes grid (text, photo, voice,
  URL, scan, paste) — URL extract + clipboard paste fully wired, camera/voice/scan
  surface native permission prompts (require expo-av/expo-image-picker)
- expo-clipboard added as dependency

F25-F27: Scheduled actions, webhook triggers, approval-gated actions
- New scheduler.ts module with PromptScheduleDoc + PromptWebhookDoc types
- Schedule CRUD: GET/POST/PATCH/DELETE /prompt-schedules
- Webhook CRUD: GET/POST/PATCH/DELETE /prompt-webhooks
- POST /prompt-webhooks/:id/trigger — execute template against note
- Scheduler loop (60s tick) with cron next-run calculation
- Diagnostics endpoint: GET /prompt-schedules/diagnostics
- Cosmos containers: note_prompt_schedules, note_prompt_webhooks
- PromptTemplateDoc gains requiresApproval field (F27)
- Runner produces approvalState: proposed|applied based on template flag
- Create/Update schemas accept requiresApproval boolean
2026-04-06 10:25:34 -07:00

31 lines
1.0 KiB
TypeScript

"use client";
import { createNotesApiClient } from "@/lib/api-helpers";
export type CopilotAction = "shorten" | "expand" | "bulletize" | "grammar" | "fix-rewrite" | "change-tone" | "continue" | "explain";
export type CopilotTone = "formal" | "casual" | "professional" | "friendly";
export async function copilotTransform(
noteId: string,
workspaceId: string,
action: CopilotAction,
text: string,
tone?: CopilotTone,
): Promise<string> {
const api = createNotesApiClient();
const res = await api.fetch<{ text: string }>(`/notes/${encodeURIComponent(noteId)}/copilot`, {
method: "POST",
body: JSON.stringify({ workspaceId, action, text, ...(tone ? { tone } : {}) }),
});
return res.text;
}
export async function suggestNoteTitle(noteId: string, workspaceId: string): Promise<string> {
const api = createNotesApiClient();
const res = await api.fetch<{ title: string }>(`/notes/${encodeURIComponent(noteId)}/suggest-title`, {
method: "POST",
body: JSON.stringify({ workspaceId }),
});
return res.title;
}