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 baseDelayMs = 1000;
const startMs = Date.now();
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const result = await withTimeout(provider.chatCompletion({
@ -74,7 +75,7 @@ export async function runCopilotTransform(action: CopilotAction, text: string):
}), 60_000);
const out = result.content.trim();
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;
}
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 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 = {
id: string;
@ -12,15 +12,16 @@ export type MobilePromptTemplate = {
category: PromptCategory;
inputType: PromptInputType;
outputType: PromptOutputType;
builtIn: boolean;
isBuiltin: boolean;
};
export type RunPromptInput = {
templateId: string;
noteId: string;
workspaceId: string;
inputText?: string;
imageUrl?: string;
parameters?: Record<string, string>;
variables?: Record<string, string>;
};
export type RunPromptOutput = {
@ -29,6 +30,9 @@ export type RunPromptOutput = {
outputType: PromptOutputType;
model?: string;
usage?: { promptTokens: number; completionTokens: number; totalTokens: number };
approvalState?: string;
createdNoteId?: string;
createdArtifactId?: string;
};
export async function listPromptTemplates(): Promise<MobilePromptTemplate[]> {

View File

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

View File

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

View File

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

View File

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

View File

@ -177,9 +177,9 @@ export type NoteRelationshipDoc = {
// ── 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 PromptOutputType = "new_note" | "artifact" | "update_note" | "replace" | "clipboard";
export type PromptOutputType = "new_note" | "artifact" | "replace" | "inline";
export interface PromptTemplate {
id: string;
@ -189,7 +189,7 @@ export interface PromptTemplate {
category: PromptCategory;
inputType: PromptInputType;
outputType: PromptOutputType;
builtIn: boolean;
isBuiltin: boolean;
systemPrompt?: string;
userPromptTemplate?: string;
}
@ -198,8 +198,9 @@ export interface RunPromptInput {
templateId: string;
noteId: string;
workspaceId: string;
inputText?: string;
imageUrl?: string;
parameters?: Record<string, string>;
variables?: Record<string, string>;
}
export interface RunPromptOutput {