sitesmith: typescript types for messages, responses, patch ops

This commit is contained in:
2026-05-23 14:15:15 -07:00
parent 14a957f57c
commit 8d094a9c67

View File

@@ -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<string, unknown> & { aiName?: string; node_id?: string };
nodes?: SerializedTreeNode[];
}
export type SitesmithPatchOp =
| { op: 'update_props'; node_id: string; props: Record<string, unknown> }
| { 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;