fix: align web+mobile types with backend (categories, output types, field names, durationMs telemetry)

This commit is contained in:
saravanakumardb1 2026-04-06 16:24:31 -07:00
parent f1c08d1a83
commit 192c7baf2f
7 changed files with 20 additions and 14 deletions

View File

@ -62,6 +62,7 @@ export async function runCopilotTransform(action: CopilotAction, text: string):
const maxRetries = 3; const maxRetries = 3;
const baseDelayMs = 1000; const baseDelayMs = 1000;
const startMs = Date.now();
for (let attempt = 0; attempt < maxRetries; attempt++) { for (let attempt = 0; attempt < maxRetries; attempt++) {
try { try {
const result = await withTimeout(provider.chatCompletion({ const result = await withTimeout(provider.chatCompletion({
@ -74,7 +75,7 @@ export async function runCopilotTransform(action: CopilotAction, text: string):
}), 60_000); }), 60_000);
const out = result.content.trim(); const out = result.content.trim();
if (out.length > 0) { if (out.length > 0) {
trackEvent('copilot_transform', 'system', { action, durationMs: String(Date.now()) }); trackEvent('copilot_transform', 'system', { action, durationMs: String(Date.now() - startMs) });
return out; return out;
} }
break; // empty response — fall through to heuristic break; // empty response — fall through to heuristic

View File

@ -2,7 +2,7 @@ import { getApiClient } from './client';
export type PromptCategory = 'transform' | 'extract' | 'generate' | 'analyze' | 'export'; export type PromptCategory = 'transform' | 'extract' | 'generate' | 'analyze' | 'export';
export type PromptInputType = 'text' | 'image' | 'text+image' | 'multi-note'; export type PromptInputType = 'text' | 'image' | 'text+image' | 'multi-note';
export type PromptOutputType = 'new_note' | 'artifact' | 'update_note'; export type PromptOutputType = 'new_note' | 'artifact' | 'replace' | 'inline';
export type MobilePromptTemplate = { export type MobilePromptTemplate = {
id: string; id: string;
@ -12,15 +12,16 @@ export type MobilePromptTemplate = {
category: PromptCategory; category: PromptCategory;
inputType: PromptInputType; inputType: PromptInputType;
outputType: PromptOutputType; outputType: PromptOutputType;
builtIn: boolean; isBuiltin: boolean;
}; };
export type RunPromptInput = { export type RunPromptInput = {
templateId: string; templateId: string;
noteId: string; noteId: string;
workspaceId: string; workspaceId: string;
inputText?: string;
imageUrl?: string; imageUrl?: string;
parameters?: Record<string, string>; variables?: Record<string, string>;
}; };
export type RunPromptOutput = { export type RunPromptOutput = {
@ -29,6 +30,9 @@ export type RunPromptOutput = {
outputType: PromptOutputType; outputType: PromptOutputType;
model?: string; model?: string;
usage?: { promptTokens: number; completionTokens: number; totalTokens: number }; usage?: { promptTokens: number; completionTokens: number; totalTokens: number };
approvalState?: string;
createdNoteId?: string;
createdArtifactId?: string;
}; };
export async function listPromptTemplates(): Promise<MobilePromptTemplate[]> { export async function listPromptTemplates(): Promise<MobilePromptTemplate[]> {

View File

@ -60,8 +60,8 @@ export default function PromptsPage() {
? templates ? templates
: templates.filter((t) => t.category === activeCategory); : templates.filter((t) => t.category === activeCategory);
const builtIn = filtered.filter((t) => t.builtIn); const builtIn = filtered.filter((t) => t.isBuiltin);
const custom = filtered.filter((t) => !t.builtIn); const custom = filtered.filter((t) => !t.isBuiltin);
return ( return (
<AppShell <AppShell

View File

@ -20,7 +20,7 @@ const baseTemplate: PromptTemplate = {
category: "transform", category: "transform",
inputType: "text", inputType: "text",
outputType: "new_note", outputType: "new_note",
builtIn: true, isBuiltin: true,
}; };
describe("RunPromptModal", () => { describe("RunPromptModal", () => {

View File

@ -4,8 +4,8 @@ import { render, screen } from "@testing-library/react";
// Mock prompt-client // Mock prompt-client
vi.mock("@/lib/prompt-client", () => ({ vi.mock("@/lib/prompt-client", () => ({
listPromptTemplates: vi.fn().mockResolvedValue([ listPromptTemplates: vi.fn().mockResolvedValue([
{ id: "t1", slug: "summarize", name: "Summarize", description: "Summarize note", category: "transform", inputType: "text", outputType: "new_note", builtIn: true }, { id: "t1", slug: "summarize", name: "Summarize", description: "Summarize note", category: "transform", inputType: "text", outputType: "new_note", isBuiltin: true },
{ id: "t2", slug: "bulletize", name: "Bullet Points", description: "Bullets", category: "transform", inputType: "text", outputType: "replace", builtIn: true }, { id: "t2", slug: "bulletize", name: "Bullet Points", description: "Bullets", category: "transform", inputType: "text", outputType: "replace", isBuiltin: true },
]), ]),
runPrompt: vi.fn().mockResolvedValue({ content: "Result", templateSlug: "summarize", outputType: "new_note" }), runPrompt: vi.fn().mockResolvedValue({ content: "Result", templateSlug: "summarize", outputType: "new_note" }),
suggestTags: vi.fn().mockResolvedValue(["tag1", "tag2"]), suggestTags: vi.fn().mockResolvedValue(["tag1", "tag2"]),

View File

@ -23,7 +23,7 @@ export async function getPromptTemplate(id: string): Promise<PromptTemplate> {
} }
export async function createPromptTemplate( export async function createPromptTemplate(
input: Omit<PromptTemplate, "id" | "builtIn">, input: Omit<PromptTemplate, "id" | "isBuiltin">,
): Promise<PromptTemplate> { ): Promise<PromptTemplate> {
const api = createNotesApiClient(); const api = createNotesApiClient();
return api.fetch<PromptTemplate>("/note-prompts", { return api.fetch<PromptTemplate>("/note-prompts", {

View File

@ -177,9 +177,9 @@ export type NoteRelationshipDoc = {
// ── Smart Actions / Prompt types ── // ── Smart Actions / Prompt types ──
export type PromptCategory = "transform" | "extract" | "generate" | "analysis" | "vision" | "export" | "custom"; export type PromptCategory = "transform" | "extract" | "generate" | "analyze" | "export";
export type PromptInputType = "text" | "image" | "text+image" | "multi-note"; export type PromptInputType = "text" | "image" | "text+image" | "multi-note";
export type PromptOutputType = "new_note" | "artifact" | "update_note" | "replace" | "clipboard"; export type PromptOutputType = "new_note" | "artifact" | "replace" | "inline";
export interface PromptTemplate { export interface PromptTemplate {
id: string; id: string;
@ -189,7 +189,7 @@ export interface PromptTemplate {
category: PromptCategory; category: PromptCategory;
inputType: PromptInputType; inputType: PromptInputType;
outputType: PromptOutputType; outputType: PromptOutputType;
builtIn: boolean; isBuiltin: boolean;
systemPrompt?: string; systemPrompt?: string;
userPromptTemplate?: string; userPromptTemplate?: string;
} }
@ -198,8 +198,9 @@ export interface RunPromptInput {
templateId: string; templateId: string;
noteId: string; noteId: string;
workspaceId: string; workspaceId: string;
inputText?: string;
imageUrl?: string; imageUrl?: string;
parameters?: Record<string, string>; variables?: Record<string, string>;
} }
export interface RunPromptOutput { export interface RunPromptOutput {