From 8d094a9c67c30335fcb2f837d122d1221bcf382f Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sat, 23 May 2026 14:15:15 -0700 Subject: [PATCH] sitesmith: typescript types for messages, responses, patch ops --- craft/src/types/sitesmith.ts | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 craft/src/types/sitesmith.ts diff --git a/craft/src/types/sitesmith.ts b/craft/src/types/sitesmith.ts new file mode 100644 index 0000000..2467ed1 --- /dev/null +++ b/craft/src/types/sitesmith.ts @@ -0,0 +1,49 @@ +import { SerializedNodes } from '@craftjs/core'; + +export type SitesmithStatus = + | 'OK_BONUS' | 'OK_MONTHLY' + | 'DISABLED' | 'CAP_REACHED' + | 'USER_KILLSWITCH' | 'SERVER_KILLSWITCH' + | 'RATE_LIMITED' | 'BLOCKED' | 'AI_ERROR' | 'AI_INVALID'; + +export interface SitesmithSummary { + enabled: boolean; + monthly_cap: number; + monthly_used: number; + bonus_credits: number; + resets_on: string; + status: SitesmithStatus; +} + +export interface SitesmithMessage { + role: 'user' | 'assistant'; + content: string; + response_type: 'replace' | 'patch' | 'ask' | 'error' | null; + created_at: string; +} + +export interface SerializedTreeNode { + type: { resolvedName: string }; + props: Record & { aiName?: string; node_id?: string }; + nodes?: SerializedTreeNode[]; +} + +export type SitesmithPatchOp = + | { op: 'update_props'; node_id: string; props: Record } + | { op: 'replace_node'; node_id: string; tree: SerializedTreeNode } + | { op: 'insert_after'; node_id: string; tree: SerializedTreeNode } + | { op: 'insert_before'; node_id: string; tree: SerializedTreeNode } + | { op: 'delete_node'; node_id: string }; + +export type SitesmithResponse = + | { type: 'replace'; scope: 'site' | 'page' | 'section'; + pages: Array<{ name: string; tree: SerializedTreeNode }>; + header?: { tree: SerializedTreeNode }; + footer?: { tree: SerializedTreeNode }; + message: string; } + | { type: 'patch'; ops: SitesmithPatchOp[]; message: string; } + | { type: 'ask'; question: string; options?: string[]; }; + +export interface SendResultOk { ok: true; response: SitesmithResponse; } +export interface SendResultErr { ok: false; status: SitesmithStatus | 'BLOCKED'; message: string; } +export type SendResult = SendResultOk | SendResultErr;