101 lines
2.8 KiB
TypeScript
101 lines
2.8 KiB
TypeScript
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' | 'replace' | 'inline';
|
|
|
|
export type MobilePromptTemplate = {
|
|
id: string;
|
|
slug: string;
|
|
name: string;
|
|
description: string;
|
|
category: PromptCategory;
|
|
inputType: PromptInputType;
|
|
outputType: PromptOutputType;
|
|
isBuiltin: boolean;
|
|
};
|
|
|
|
export type RunPromptInput = {
|
|
templateId: string;
|
|
noteId: string;
|
|
workspaceId: string;
|
|
inputText?: string;
|
|
imageUrl?: string;
|
|
variables?: Record<string, string>;
|
|
};
|
|
|
|
export type RunPromptOutput = {
|
|
content: string;
|
|
templateSlug: string;
|
|
outputType: PromptOutputType;
|
|
model?: string;
|
|
usage?: { promptTokens: number; completionTokens: number; totalTokens: number };
|
|
approvalState?: string;
|
|
createdNoteId?: string;
|
|
createdArtifactId?: string;
|
|
};
|
|
|
|
export async function listPromptTemplates(): Promise<MobilePromptTemplate[]> {
|
|
const res = await getApiClient().fetch<{ items: MobilePromptTemplate[] }>('/note-prompts');
|
|
return res.items;
|
|
}
|
|
|
|
export async function runPrompt(input: RunPromptInput): Promise<RunPromptOutput> {
|
|
return getApiClient().fetch<RunPromptOutput>('/note-prompts/run', {
|
|
method: 'POST',
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export async function suggestTags(noteId: string, workspaceId: string): Promise<string[]> {
|
|
const res = await getApiClient().fetch<{ tags: string[] }>(
|
|
`/notes/${encodeURIComponent(noteId)}/suggest-tags`,
|
|
{ method: 'POST', body: JSON.stringify({ workspaceId }) },
|
|
);
|
|
return res.tags;
|
|
}
|
|
|
|
export type UrlExtractResult = {
|
|
title: string;
|
|
content: string;
|
|
url: string;
|
|
summarized: boolean;
|
|
model?: string;
|
|
};
|
|
|
|
export async function extractFromUrl(
|
|
url: string,
|
|
workspaceId: string,
|
|
summarize = true,
|
|
): Promise<UrlExtractResult> {
|
|
return getApiClient().fetch<UrlExtractResult>('/note-prompts/url-extract', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ url, workspaceId, summarize }),
|
|
});
|
|
}
|
|
|
|
export type CopilotTone = 'formal' | 'casual' | 'professional' | 'friendly';
|
|
|
|
export async function copilotTransform(
|
|
noteId: string,
|
|
workspaceId: string,
|
|
action: string,
|
|
text: string,
|
|
tone?: CopilotTone,
|
|
): Promise<string> {
|
|
const res = await getApiClient().fetch<{ text: string }>(
|
|
`/notes/${encodeURIComponent(noteId)}/copilot`,
|
|
{ method: 'POST', body: JSON.stringify({ workspaceId, action, text, ...(tone ? { tone } : {}) }) },
|
|
);
|
|
return res.text;
|
|
}
|
|
|
|
export async function getReadingTime(
|
|
noteId: string,
|
|
workspaceId: string,
|
|
): Promise<{ wordCount: number; readingTimeMinutes: number }> {
|
|
return getApiClient().fetch(
|
|
`/notes/${encodeURIComponent(noteId)}/reading-time?workspaceId=${encodeURIComponent(workspaceId)}`,
|
|
);
|
|
}
|