Files
codecraft/web/src/templates.ts
T
Richard ZinkandClaude Opus 5.5 428e2df40a Add share target, prompt templates, command palette and session organisation
- PWA share target: shared text/links start a new chat or go into a
  recent session (chooser dialog)
- Prompt templates (personal + global for admins) with {{placeholders}}
  that are asked for on insert; managed under Settings → Templates
- Ctrl/Cmd+K command palette; Alt+N new session, Alt+Up/Down switch
  sessions, Ctrl+, settings
- Sessions can be pinned, archived and filed into folders; the list can
  be grouped by date or by project, groups are collapsible
- Fix: the "What's new" dialog was never shown to signed-in users

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 05:27:45 +01:00

30 lines
1023 B
TypeScript

import { get, put } from "./api";
export interface Template {
id: string;
name: string;
text: string;
}
export interface TemplateLists {
personal: Template[];
global: Template[];
can_edit_global: boolean;
}
export const loadTemplates = () => get<TemplateLists>("/templates");
export const saveTemplates = (scope: "personal" | "global", list: Template[]) => put<Template[]>(`/templates/${scope}`, list);
/** Placeholders like {{file}} or {{goal: what should change}} (name, optional hint). */
export function placeholders(text: string): { name: string; hint: string }[] {
const seen = new Map<string, string>();
for (const m of text.matchAll(/\{\{\s*([^}:]+?)\s*(?::\s*([^}]*?))?\s*\}\}/g)) {
if (!seen.has(m[1])) seen.set(m[1], m[2] ?? "");
}
return [...seen].map(([name, hint]) => ({ name, hint }));
}
export function fill(text: string, values: Record<string, string>): string {
return text.replace(/\{\{\s*([^}:]+?)\s*(?::\s*([^}]*?))?\s*\}\}/g, (_, name: string) => values[name] ?? "");
}