@aswin.dev/core 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +56 -0
- package/README.md +64 -0
- package/dist/cloud/index.d.ts +487 -0
- package/dist/cloud/index.js +2853 -0
- package/dist/cloud/index.js.map +1 -0
- package/dist/editor-Cp6y4tLN.d.ts +52 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +645 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cloud/auth.ts","../../src/cloud/api.ts","../../src/cloud/url-builder.ts","../../src/cloud/websocket-client.ts","../../src/cloud/mcp-operation-handler.ts","../../src/cloud/editor.ts","../../src/cloud/ai-chat.ts","../../src/cloud/ai-rewrite.ts","../../src/cloud/ai-config.ts","../../src/cloud/template-scoring.ts","../../src/cloud/design-reference.ts","../../src/cloud/comments.ts","../../src/cloud/comment-listener.ts","../../src/cloud/collaboration.ts","../../src/cloud/collaboration-broadcast.ts","../../src/cloud/web-socket.ts","../../src/cloud/saved-modules.ts","../../src/cloud/snapshots.ts","../../src/cloud/test-email.ts","../../src/cloud/export.ts","../../src/cloud/plan-config.ts","../../src/cloud/health-check.ts","../../src/cloud/mcp-listener.ts"],"sourcesContent":["import type {\n AuthConfig,\n AuthRequestOptions,\n SdkAuthConfig,\n TestEmailConfig,\n TokenData,\n UserConfig,\n} from \"@aswin.dev/types\";\nimport { SdkError } from \"@aswin.dev/types\";\n\nexport type {\n AuthConfig,\n AuthRequestOptions,\n SdkAuthConfig,\n TestEmailConfig,\n UserConfig,\n};\n\nexport class AuthManager {\n private static readonly DEFAULT_BASE_URL = \"https://templatical.com\";\n\n private accessToken: string | null = null;\n private expiresAt: Date | null = null;\n private _projectId: string | null = null;\n private _tenantId: string | null = null;\n private _tenantSlug: string | null = null;\n private _testEmailConfig: TestEmailConfig | null = null;\n private _userConfig: UserConfig | null = null;\n private readonly url: string;\n private readonly baseUrl: string;\n private readonly requestOptions: AuthRequestOptions;\n private readonly onError?: (error: Error) => void;\n private refreshPromise: Promise<string> | null = null;\n\n private static readonly REFRESH_THRESHOLD_MS = 60 * 1000;\n\n constructor(config: AuthConfig) {\n this.url = config.url;\n this.baseUrl = (config.baseUrl ?? AuthManager.DEFAULT_BASE_URL).replace(\n /\\/$/,\n \"\",\n );\n this.requestOptions = config.requestOptions ?? {};\n this.onError = config.onError;\n }\n\n resolveUrl(path: string): string {\n if (path.startsWith(\"http://\") || path.startsWith(\"https://\")) {\n return path;\n }\n\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${this.baseUrl}${normalizedPath}`;\n }\n\n get projectId(): string {\n if (!this._projectId) {\n throw new Error(\"Project ID not available. Call initialize() first.\");\n }\n return this._projectId;\n }\n\n get tenantId(): string {\n if (!this._tenantId) {\n throw new Error(\"Tenant ID not available. Call initialize() first.\");\n }\n return this._tenantId;\n }\n\n get tenantSlug(): string {\n if (!this._tenantSlug) {\n throw new Error(\"Tenant slug not available. Call initialize() first.\");\n }\n return this._tenantSlug;\n }\n\n get testEmailConfig(): TestEmailConfig | null {\n return this._testEmailConfig;\n }\n\n get userConfig(): UserConfig | null {\n return this._userConfig;\n }\n\n get accessTokenValue(): string | null {\n return this.accessToken;\n }\n\n async initialize(): Promise<void> {\n await this.ensureToken();\n }\n\n private async ensureToken(): Promise<string> {\n if (this.accessToken && !this.isTokenExpiringSoon()) {\n return this.accessToken;\n }\n return this.refreshToken();\n }\n\n private isTokenExpiringSoon(): boolean {\n if (!this.expiresAt) {\n return true;\n }\n const timeUntilExpiry = this.expiresAt.getTime() - Date.now();\n return timeUntilExpiry < AuthManager.REFRESH_THRESHOLD_MS;\n }\n\n async refreshToken(): Promise<string> {\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.refreshPromise = this.performRefresh();\n\n try {\n const token = await this.refreshPromise;\n return token;\n } finally {\n this.refreshPromise = null;\n }\n }\n\n private async performRefresh(): Promise<string> {\n try {\n const method = this.requestOptions.method ?? \"POST\";\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n ...this.requestOptions.headers,\n };\n\n const fetchOptions: RequestInit = {\n method,\n headers,\n credentials: this.requestOptions.credentials ?? \"include\",\n };\n\n if (method === \"POST\" && this.requestOptions.body) {\n headers[\"Content-Type\"] = \"application/json\";\n fetchOptions.body = JSON.stringify(this.requestOptions.body);\n }\n\n const response = await fetch(this.url, fetchOptions);\n\n if (!response.ok) {\n throw new SdkError(\n `Token refresh failed: ${response.status}`,\n response.status,\n );\n }\n\n const data: TokenData = await response.json();\n\n if (!data.token || !data.expires_at || !data.project_id || !data.tenant) {\n throw new Error(\n \"Invalid token response: missing token, expires_at, project_id, or tenant\",\n );\n }\n\n this.accessToken = data.token;\n this.expiresAt = new Date(data.expires_at * 1000);\n this._projectId = data.project_id;\n this._tenantSlug = data.tenant;\n\n if (data.test_email?.allowed_emails && data.test_email?.signature) {\n this._testEmailConfig = {\n allowedEmails: data.test_email.allowed_emails,\n signature: data.test_email.signature,\n };\n } else {\n this._testEmailConfig = null;\n }\n\n if (data.user?.id && data.user?.name && data.user?.signature) {\n this._userConfig = {\n id: data.user.id,\n name: data.user.name,\n signature: data.user.signature,\n };\n } else {\n this._userConfig = null;\n }\n\n return this.accessToken;\n } catch (error) {\n const wrappedError =\n error instanceof Error\n ? error\n : new Error(\"Token refresh failed\", { cause: error });\n this.onError?.(wrappedError);\n throw wrappedError;\n }\n }\n\n async authenticatedFetch(\n url: string,\n options: RequestInit = {},\n ): Promise<Response> {\n const token = await this.ensureToken();\n const resolvedUrl = this.resolveUrl(url);\n\n const makeRequest = async (authToken: string): Promise<Response> => {\n return fetch(resolvedUrl, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Bearer ${authToken}`,\n },\n });\n };\n\n let response = await makeRequest(token);\n\n if (response.status === 401) {\n const newToken = await this.refreshToken();\n response = await makeRequest(newToken);\n }\n\n return response;\n }\n}\n\nexport function createSdkAuthManager(\n config: SdkAuthConfig,\n onError?: (error: Error) => void,\n): AuthManager {\n if (config.mode === \"direct\") {\n const baseUrl = (config.baseUrl ?? \"https://templatical.com\").replace(\n /\\/$/,\n \"\",\n );\n\n return new AuthManager({\n url: `${baseUrl}/api/v1/auth/token`,\n baseUrl: config.baseUrl,\n requestOptions: {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: {\n client_id: config.clientId,\n client_secret: config.clientSecret,\n tenant: config.tenant,\n client_type: \"sdk\",\n },\n },\n onError,\n });\n }\n\n return new AuthManager({\n url: config.url,\n baseUrl: config.baseUrl,\n requestOptions: config.requestOptions,\n onError,\n });\n}\n","import type {\n ApiError,\n ApiResponse,\n Comment,\n CustomFont,\n PlanConfig,\n SavedModule,\n Template,\n TemplateContent,\n TemplateSnapshot,\n} from \"@aswin.dev/types\";\nimport { SdkError } from \"@aswin.dev/types\";\nimport type { Block } from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\n\nexport class ApiClient {\n constructor(private readonly authManager: AuthManager) {}\n\n private get projectId(): string {\n return this.authManager.projectId;\n }\n\n private get tenantSlug(): string {\n return this.authManager.tenantSlug;\n }\n\n private get baseParams(): Record<string, string> {\n return { project: this.projectId, tenant: this.tenantSlug };\n }\n\n private async request<T>(\n path: string,\n options: RequestInit = {},\n ): Promise<T> {\n const response = await this.authManager.authenticatedFetch(path, {\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error: ApiError = await response.json().catch(() => ({\n message: `HTTP error ${response.status}`,\n }));\n\n const errorMessage = this.extractFirstValidationError(error);\n throw new SdkError(errorMessage, response.status);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n const json: ApiResponse<T> = await response.json();\n return json.data;\n }\n\n private extractFirstValidationError(error: ApiError): string {\n if (error.errors) {\n const firstField = Object.keys(error.errors)[0];\n if (firstField && error.errors[firstField]?.length > 0) {\n return error.errors[firstField][0];\n }\n }\n return error.message;\n }\n\n async createTemplate(content: TemplateContent): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.store\"], this.baseParams),\n {\n method: \"POST\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async getTemplate(id: string): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.show\"], {\n ...this.baseParams,\n template: id,\n }),\n );\n }\n\n async updateTemplate(\n id: string,\n content: TemplateContent,\n ): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"templates.update\"], {\n ...this.baseParams,\n template: id,\n }),\n {\n method: \"PUT\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async createSnapshot(\n templateId: string,\n content: TemplateContent,\n ): Promise<TemplateSnapshot> {\n return this.request<TemplateSnapshot>(\n buildUrl(API_ROUTES[\"snapshots.store\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify({ content }),\n },\n );\n }\n\n async deleteTemplate(id: string): Promise<void> {\n return this.request<void>(\n buildUrl(API_ROUTES[\"templates.destroy\"], {\n ...this.baseParams,\n template: id,\n }),\n {\n method: \"DELETE\",\n },\n );\n }\n\n async getSnapshots(templateId: string): Promise<TemplateSnapshot[]> {\n return this.request<TemplateSnapshot[]>(\n buildUrl(API_ROUTES[\"snapshots.index\"], {\n ...this.baseParams,\n template: templateId,\n }),\n );\n }\n\n async restoreSnapshot(\n templateId: string,\n snapshotId: string,\n ): Promise<Template> {\n return this.request<Template>(\n buildUrl(API_ROUTES[\"snapshots.restore\"], {\n ...this.baseParams,\n template: templateId,\n snapshot: snapshotId,\n }),\n {\n method: \"POST\",\n },\n );\n }\n\n async exportTemplate(\n templateId: string,\n fontsPayload?: {\n customFonts: CustomFont[];\n defaultFallback: string;\n },\n ): Promise<{ html: string; mjml: string }> {\n const body = fontsPayload\n ? JSON.stringify({\n custom_fonts: fontsPayload.customFonts,\n default_fallback: fontsPayload.defaultFallback,\n })\n : undefined;\n\n return this.request<{ html: string; mjml: string }>(\n buildUrl(API_ROUTES[\"templates.export\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body,\n },\n );\n }\n\n async sendTestEmail(\n templateId: string,\n payload: {\n recipient: string;\n html: string;\n allowed_emails: string[];\n signature: string;\n },\n ): Promise<void> {\n await this.request<void>(\n buildUrl(API_ROUTES[\"templates.sendTestEmail\"], {\n ...this.baseParams,\n template: templateId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n }\n\n private commentsUrl(templateId: string, commentId?: string): string {\n if (commentId) {\n return buildUrl(API_ROUTES[\"comments.update\"], {\n ...this.baseParams,\n template: templateId,\n comment: commentId,\n });\n }\n return buildUrl(API_ROUTES[\"comments.index\"], {\n ...this.baseParams,\n template: templateId,\n });\n }\n\n async getComments(templateId: string): Promise<Comment[]> {\n return this.request<Comment[]>(this.commentsUrl(templateId));\n }\n\n async createComment(\n templateId: string,\n data: {\n body: string;\n block_id?: string;\n parent_id?: string;\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(this.commentsUrl(templateId), {\n method: \"POST\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async updateComment(\n templateId: string,\n commentId: string,\n data: {\n body: string;\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(this.commentsUrl(templateId, commentId), {\n method: \"PUT\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async deleteComment(\n templateId: string,\n commentId: string,\n data: {\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<void> {\n return this.request<void>(this.commentsUrl(templateId, commentId), {\n method: \"DELETE\",\n body: JSON.stringify(data),\n headers,\n });\n }\n\n async resolveComment(\n templateId: string,\n commentId: string,\n data: {\n user_id: string;\n user_name: string;\n user_signature: string;\n },\n headers?: Record<string, string>,\n ): Promise<Comment> {\n return this.request<Comment>(\n buildUrl(API_ROUTES[\"comments.resolve\"], {\n ...this.baseParams,\n template: templateId,\n comment: commentId,\n }),\n {\n method: \"POST\",\n body: JSON.stringify(data),\n headers,\n },\n );\n }\n\n async fetchConfig(): Promise<PlanConfig> {\n return this.request<PlanConfig>(\n buildUrl(API_ROUTES[\"projects.config\"], this.baseParams),\n );\n }\n\n async listModules(search?: string): Promise<SavedModule[]> {\n const url = buildUrl(API_ROUTES[\"savedModules.index\"], this.baseParams);\n const query = search ? `?search=${encodeURIComponent(search)}` : \"\";\n return this.request<SavedModule[]>(`${url}${query}`);\n }\n\n async createModule(data: {\n name: string;\n content: Block[];\n }): Promise<SavedModule> {\n return this.request<SavedModule>(\n buildUrl(API_ROUTES[\"savedModules.store\"], this.baseParams),\n {\n method: \"POST\",\n body: JSON.stringify(data),\n },\n );\n }\n\n async updateModule(\n id: string,\n data: Partial<{ name: string; content: Block[] }>,\n ): Promise<SavedModule> {\n return this.request<SavedModule>(\n buildUrl(API_ROUTES[\"savedModules.update\"], {\n ...this.baseParams,\n savedModule: id,\n }),\n {\n method: \"PUT\",\n body: JSON.stringify(data),\n },\n );\n }\n\n async deleteModule(id: string): Promise<void> {\n return this.request<void>(\n buildUrl(API_ROUTES[\"savedModules.destroy\"], {\n ...this.baseParams,\n savedModule: id,\n }),\n {\n method: \"DELETE\",\n },\n );\n }\n}\n","export function buildUrl(\n template: string,\n params: Record<string, string>,\n): string {\n return template.replace(/\\{(\\w+)\\}/g, (_, key: string) =>\n encodeURIComponent(params[key] ?? \"\"),\n );\n}\n\nconst BASE = \"/api/v1/projects/{project}/tenants/{tenant}\";\nconst TEMPLATE = `${BASE}/templates/{template}`;\nconst AI = `${TEMPLATE}/ai`;\nconst MEDIA = `${BASE}/media`;\nconst FOLDERS = `${MEDIA}/folders`;\nconst MODULES = `${BASE}/saved-modules`;\n\nexport const API_ROUTES = {\n health: \"/api/v1/health\",\n \"projects.config\": `${BASE}/config`,\n \"broadcasting.auth\": `${BASE}/broadcasting/auth`,\n \"templates.store\": `${BASE}/templates`,\n \"templates.show\": `${TEMPLATE}`,\n \"templates.update\": `${TEMPLATE}`,\n \"templates.destroy\": `${TEMPLATE}`,\n \"templates.export\": `${TEMPLATE}/export`,\n \"templates.importFromBeefree\": `${BASE}/templates/import/from-beefree`,\n \"templates.sendTestEmail\": `${TEMPLATE}/send-test-email`,\n \"snapshots.index\": `${TEMPLATE}/snapshots`,\n \"snapshots.store\": `${TEMPLATE}/snapshots`,\n \"snapshots.show\": `${TEMPLATE}/snapshots/{snapshot}`,\n \"snapshots.restore\": `${TEMPLATE}/snapshots/{snapshot}/restore`,\n \"comments.index\": `${TEMPLATE}/comments`,\n \"comments.store\": `${TEMPLATE}/comments`,\n \"comments.update\": `${TEMPLATE}/comments/{comment}`,\n \"comments.destroy\": `${TEMPLATE}/comments/{comment}`,\n \"comments.resolve\": `${TEMPLATE}/comments/{comment}/resolve`,\n \"ai.generate\": `${AI}/generate`,\n \"ai.conversationMessages\": `${AI}/conversation-messages`,\n \"ai.suggestions\": `${AI}/suggestions`,\n \"ai.rewriteText\": `${AI}/rewrite-text`,\n \"ai.score\": `${AI}/score`,\n \"ai.fixFinding\": `${AI}/fix-finding`,\n \"ai.generateFromDesign\": `${AI}/generate-from-design`,\n \"media.upload\": `${MEDIA}/upload`,\n \"media.browse\": `${MEDIA}/browse`,\n \"media.delete\": `${MEDIA}/delete`,\n \"media.move\": `${MEDIA}/move`,\n \"media.update\": `${MEDIA}/{media}`,\n \"media.replace\": `${MEDIA}/{media}/replace`,\n \"media.checkUsage\": `${MEDIA}/check-usage`,\n \"media.frequentlyUsed\": `${MEDIA}/frequently-used`,\n \"media.importFromUrl\": `${MEDIA}/import-from-url`,\n \"folders.index\": `${FOLDERS}`,\n \"folders.store\": `${FOLDERS}`,\n \"folders.update\": `${FOLDERS}/{mediaFolder}`,\n \"folders.destroy\": `${FOLDERS}/{mediaFolder}`,\n \"savedModules.index\": `${MODULES}`,\n \"savedModules.store\": `${MODULES}`,\n \"savedModules.update\": `${MODULES}/{savedModule}`,\n \"savedModules.destroy\": `${MODULES}/{savedModule}`,\n} as const;\n","import type { WebSocketServerConfig } from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type Pusher from \"pusher-js\";\nimport type { Channel, PresenceChannel } from \"pusher-js\";\n\ntype PusherType = Pusher;\n\nexport interface WebSocketConfig {\n host: string;\n port: number;\n appKey: string;\n}\n\nexport function resolveWebSocketConfig(\n serverConfig: WebSocketServerConfig,\n): WebSocketConfig {\n return {\n host: serverConfig.host,\n port: serverConfig.port,\n appKey: serverConfig.app_key,\n };\n}\n\nexport interface PresenceMember {\n id: string;\n name: string;\n type: \"user\" | \"mcp\";\n}\n\nexport interface WebSocketClientOptions {\n authManager: AuthManager;\n config: WebSocketConfig;\n onError?: (error: Error) => void;\n}\n\nexport class WebSocketClient {\n private pusher: PusherType | null = null;\n private readonly authManager: AuthManager;\n private readonly config: WebSocketConfig;\n private readonly onError?: (error: Error) => void;\n\n constructor(options: WebSocketClientOptions) {\n this.authManager = options.authManager;\n this.config = options.config;\n this.onError = options.onError;\n }\n\n async connect(): Promise<void> {\n if (this.pusher) {\n return;\n }\n\n let Pusher: typeof import(\"pusher-js\").default;\n try {\n ({ default: Pusher } = await import(\"pusher-js\"));\n } catch {\n throw new Error(\n \"Cloud features require the optional peer dependency 'pusher-js'. Install it with: npm install pusher-js\",\n );\n }\n\n const { host, port, appKey } = this.config;\n const authEndpoint = this.authManager.resolveUrl(\n buildUrl(API_ROUTES[\"broadcasting.auth\"], {\n project: this.authManager.projectId,\n tenant: this.authManager.tenantSlug,\n }),\n );\n\n this.pusher = new Pusher(appKey, {\n wsHost: host,\n wsPort: port,\n wssPort: port,\n forceTLS: true,\n disableStats: true,\n enabledTransports: [\"ws\", \"wss\"],\n cluster: \"\",\n channelAuthorization: {\n transport: \"ajax\",\n endpoint: authEndpoint,\n headers: {\n Authorization: `Bearer ${this.authManager.accessTokenValue}`,\n Accept: \"application/json\",\n },\n params: {\n user_id: this.authManager.userConfig?.id ?? \"\",\n user_name: this.authManager.userConfig?.name ?? \"\",\n user_signature: this.authManager.userConfig?.signature ?? \"\",\n },\n },\n });\n\n this.pusher.connection.bind(\"error\", (error: unknown) => {\n this.onError?.(\n error instanceof Error\n ? error\n : new Error(\"WebSocket connection error\"),\n );\n });\n }\n\n subscribePresence(channelName: string): PresenceChannel {\n if (!this.pusher) {\n throw new Error(\"WebSocketClient not connected. Call connect() first.\");\n }\n\n return this.pusher.subscribe(channelName) as PresenceChannel;\n }\n\n unsubscribe(channelName: string): void {\n this.pusher?.unsubscribe(channelName);\n }\n\n getChannel(channelName: string): Channel | undefined {\n return this.pusher?.channel(channelName);\n }\n\n disconnect(): void {\n if (this.pusher) {\n this.pusher.disconnect();\n this.pusher = null;\n }\n }\n\n getSocketId(): string | null {\n return this.pusher?.connection.socket_id ?? null;\n }\n\n get isConnected(): boolean {\n return this.pusher?.connection.state === \"connected\";\n }\n}\n","import type { McpOperationPayload } from \"@aswin.dev/types\";\nimport type {\n Block,\n TemplateContent,\n TemplateSettings,\n} from \"@aswin.dev/types\";\nimport type { UseEditorReturn } from \"./editor\";\n\nexport function handleOperation(\n editor: UseEditorReturn,\n payload: McpOperationPayload,\n): void {\n const { operation, data } = payload;\n\n switch (operation) {\n case \"add_block\":\n editor.addBlock(\n data.block as Block,\n data.section_id as string | undefined,\n data.column_index as number | undefined,\n data.index as number | undefined,\n );\n break;\n\n case \"update_block\":\n editor.updateBlock(\n data.block_id as string,\n data.updates as Partial<Block>,\n );\n break;\n\n case \"delete_block\":\n editor.removeBlock(data.block_id as string);\n break;\n\n case \"move_block\":\n editor.moveBlock(\n data.block_id as string,\n data.index as number,\n data.section_id as string | undefined,\n data.column_index as number | undefined,\n );\n break;\n\n case \"update_settings\":\n editor.updateSettings(data.updates as Partial<TemplateSettings>);\n break;\n\n case \"set_content\":\n editor.setContent(data.content as TemplateContent);\n break;\n\n case \"update_block_style\":\n editor.updateBlock(\n data.block_id as string,\n {\n styles: data.styles,\n } as Partial<Block>,\n );\n break;\n }\n}\n","import type {\n EditorState,\n Template,\n TemplateDefaults,\n UiTheme,\n ViewportSize,\n} from \"@aswin.dev/types\";\nimport { SdkError } from \"@aswin.dev/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport type {\n Block,\n TemplateContent,\n TemplateSettings,\n} from \"@aswin.dev/types\";\nimport {\n createDefaultTemplateContent,\n normalizeTemplateContentPages,\n} from \"@aswin.dev/types\";\nimport { computed, reactive, readonly, type DeepReadonly, type Ref } from \"vue\";\n\nexport interface UseEditorOptions {\n authManager: AuthManager;\n defaultFontFamily?: string;\n templateDefaults?: TemplateDefaults;\n onError?: (error: Error) => void;\n lockedBlocks?: Ref<Map<string, unknown>>;\n}\n\nexport interface UseEditorReturn {\n state: DeepReadonly<EditorState>;\n content: Ref<TemplateContent>;\n selectedBlock: Ref<Block | null>;\n setContent: (content: TemplateContent, markDirty?: boolean) => void;\n selectBlock: (blockId: string | null) => void;\n setViewport: (viewport: ViewportSize) => void;\n setDarkMode: (darkMode: boolean) => void;\n setPreviewMode: (previewMode: boolean) => void;\n setUiTheme: (theme: UiTheme) => void;\n updateBlock: (blockId: string, updates: Partial<Block>) => void;\n updateSettings: (updates: Partial<TemplateSettings>) => void;\n addBlock: (\n block: Block,\n targetSectionId?: string,\n columnIndex?: number,\n index?: number,\n ) => void;\n removeBlock: (blockId: string) => void;\n moveBlock: (\n blockId: string,\n newIndex: number,\n targetSectionId?: string,\n columnIndex?: number,\n ) => void;\n savedBlockIds: Ref<Set<string>>;\n isBlockLocked: (blockId: string) => boolean;\n create: (content?: TemplateContent) => Promise<Template>;\n load: (templateId: string) => Promise<Template>;\n save: () => Promise<Template>;\n createSnapshot: () => Promise<void>;\n hasTemplate: () => boolean;\n markDirty: () => void;\n ensureCanvasPages: () => void;\n switchCanvasPage: (pageId: string) => void;\n addCanvasPage: () => void;\n removeCanvasPage: (pageId: string) => void;\n renameCanvasPage: (pageId: string, title: string) => void;\n switchToNextCanvasPage: () => boolean;\n switchToPreviousCanvasPage: () => boolean;\n}\n\nexport function useEditor(options: UseEditorOptions): UseEditorReturn {\n const api = new ApiClient(options.authManager);\n\n const state = reactive<EditorState>({\n template: null,\n content: normalizeTemplateContentPages(\n createDefaultTemplateContent(\n options.defaultFontFamily,\n options.templateDefaults,\n ),\n ),\n selectedBlockId: null,\n viewport: \"desktop\",\n darkMode: false,\n previewMode: false,\n isDirty: false,\n isSaving: false,\n isLoading: false,\n uiTheme: \"auto\",\n });\n\n const content = computed({\n get: () => state.content,\n set: (value: TemplateContent) => {\n state.content = normalizeTemplateContentPages(value);\n state.isDirty = true;\n },\n });\n\n const selectedBlock = computed(() => {\n if (!state.selectedBlockId) return null;\n return findBlockById(state.content.blocks, state.selectedBlockId);\n });\n\n const savedBlockIds = computed<Set<string>>(() => {\n const ids = new Set<string>();\n const blocks = state.template?.content?.blocks;\n if (!blocks) {\n return ids;\n }\n for (const block of blocks) {\n ids.add(block.id);\n if (block.type === \"section\") {\n for (const column of block.children) {\n for (const child of column) {\n ids.add(child.id);\n }\n }\n }\n }\n return ids;\n });\n\n function findBlockById(blocks: Block[], id: string): Block | null {\n for (const block of blocks) {\n if (block.id === id) return block;\n if (block.type === \"section\") {\n for (const column of block.children) {\n const found = findBlockById(column, id);\n if (found) return found;\n }\n }\n }\n return null;\n }\n\n function findBlockParent(\n blocks: Block[],\n id: string,\n parent: {\n blocks: Block[];\n sectionId?: string;\n columnIndex?: number;\n } = { blocks },\n ): { blocks: Block[]; sectionId?: string; columnIndex?: number } | null {\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n if (block.id === id) return parent;\n if (block.type === \"section\") {\n for (let colIdx = 0; colIdx < block.children.length; colIdx++) {\n const result = findBlockParent(block.children[colIdx], id, {\n blocks: block.children[colIdx],\n sectionId: block.id,\n columnIndex: colIdx,\n });\n if (result) return result;\n }\n }\n }\n return null;\n }\n\n function isBlockLocked(blockId: string): boolean {\n return options.lockedBlocks?.value.has(blockId) ?? false;\n }\n\n function setContent(newContent: TemplateContent, markDirty = true): void {\n state.content = normalizeTemplateContentPages(newContent);\n if (markDirty) {\n state.isDirty = true;\n }\n }\n\n function selectBlock(blockId: string | null): void {\n if (blockId && isBlockLocked(blockId)) {\n return;\n }\n state.selectedBlockId = blockId;\n }\n\n function setViewport(viewport: ViewportSize): void {\n state.viewport = viewport;\n }\n\n function setDarkMode(darkMode: boolean): void {\n state.darkMode = darkMode;\n }\n\n function setUiTheme(theme: UiTheme): void {\n state.uiTheme = theme;\n }\n\n function setPreviewMode(previewMode: boolean): void {\n state.previewMode = previewMode;\n if (previewMode) {\n state.selectedBlockId = null;\n }\n }\n\n function updateBlock(blockId: string, updates: Partial<Block>): void {\n if (isBlockLocked(blockId)) {\n return;\n }\n const block = findBlockById(state.content.blocks, blockId);\n if (block) {\n Object.assign(block, updates);\n state.isDirty = true;\n }\n }\n\n function updateSettings(updates: Partial<TemplateSettings>): void {\n state.content.settings = { ...state.content.settings, ...updates };\n state.isDirty = true;\n }\n\n function addBlock(\n block: Block,\n targetSectionId?: string,\n columnIndex = 0,\n index?: number,\n ): void {\n if (targetSectionId) {\n const section = findBlockById(state.content.blocks, targetSectionId);\n if (section && section.type === \"section\") {\n section.children[columnIndex] = section.children[columnIndex] || [];\n const targetArray = section.children[columnIndex];\n if (index !== undefined && index < targetArray.length) {\n targetArray.splice(index, 0, block);\n } else {\n targetArray.push(block);\n }\n }\n } else {\n if (index !== undefined && index < state.content.blocks.length) {\n state.content.blocks.splice(index, 0, block);\n } else {\n state.content.blocks.push(block);\n }\n }\n state.isDirty = true;\n }\n\n function removeBlock(blockId: string): void {\n if (isBlockLocked(blockId)) {\n return;\n }\n const parent = findBlockParent(state.content.blocks, blockId);\n if (parent) {\n const index = parent.blocks.findIndex((b) => b.id === blockId);\n if (index !== -1) {\n parent.blocks.splice(index, 1);\n if (state.selectedBlockId === blockId) {\n state.selectedBlockId = null;\n }\n state.isDirty = true;\n }\n }\n }\n\n function moveBlock(\n blockId: string,\n newIndex: number,\n targetSectionId?: string,\n columnIndex = 0,\n ): void {\n const parent = findBlockParent(state.content.blocks, blockId);\n if (!parent) return;\n\n const oldIndex = parent.blocks.findIndex((b) => b.id === blockId);\n if (oldIndex === -1) return;\n\n const [block] = parent.blocks.splice(oldIndex, 1);\n\n if (targetSectionId) {\n const section = findBlockById(state.content.blocks, targetSectionId);\n if (section && section.type === \"section\") {\n section.children[columnIndex] = section.children[columnIndex] || [];\n section.children[columnIndex].splice(newIndex, 0, block);\n }\n } else {\n state.content.blocks.splice(newIndex, 0, block);\n }\n\n state.isDirty = true;\n }\n\n async function create(content?: TemplateContent): Promise<Template> {\n state.isLoading = true;\n try {\n if (content) {\n state.content = normalizeTemplateContentPages(content);\n }\n const template = await api.createTemplate(state.content);\n state.template = template;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isLoading = false;\n }\n }\n\n async function load(templateId: string): Promise<Template> {\n state.isLoading = true;\n try {\n const template = await api.getTemplate(templateId);\n state.template = template;\n state.content = normalizeTemplateContentPages(template.content);\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isLoading = false;\n }\n }\n\n async function save(): Promise<Template> {\n if (!state.template?.id) {\n throw new SdkError(\n \"No template loaded. Call create() or load() before saving.\",\n );\n }\n\n state.isSaving = true;\n try {\n const template = await api.updateTemplate(\n state.template.id,\n state.content,\n );\n state.template = template;\n state.isDirty = false;\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n state.isSaving = false;\n }\n }\n\n async function createSnapshot(): Promise<void> {\n if (!state.template?.id) {\n return;\n }\n\n try {\n await api.createSnapshot(state.template.id, state.content);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n }\n }\n\n function hasTemplate(): boolean {\n return state.template?.id !== undefined;\n }\n\n function markDirty(): void {\n state.isDirty = true;\n }\n\n function ensureCanvasPages(): void {\n if (state.content.canvasPages?.length) {\n return;\n }\n const id = crypto.randomUUID();\n const blocks = state.content.blocks;\n state.content.canvasPages = [{ id, title: \"Step 1\", blocks }];\n state.content.activeCanvasPageId = id;\n state.content.blocks = blocks;\n state.isDirty = true;\n }\n\n function switchCanvasPage(pageId: string): void {\n const pages = state.content.canvasPages;\n if (!pages?.length) {\n return;\n }\n const page = pages.find((p) => p.id === pageId);\n if (!page) {\n return;\n }\n state.selectedBlockId = null;\n state.content.blocks = page.blocks;\n state.content.activeCanvasPageId = pageId;\n state.isDirty = true;\n }\n\n function addCanvasPage(): void {\n ensureCanvasPages();\n const pages = state.content.canvasPages!;\n const id = crypto.randomUUID();\n const title = `Step ${pages.length + 1}`;\n const newBlocks: Block[] = [];\n pages.push({ id, title, blocks: newBlocks });\n switchCanvasPage(id);\n }\n\n function removeCanvasPage(pageId: string): void {\n const pages = state.content.canvasPages;\n if (!pages || pages.length <= 1) {\n return;\n }\n const idx = pages.findIndex((p) => p.id === pageId);\n if (idx === -1) {\n return;\n }\n pages.splice(idx, 1);\n if (state.content.activeCanvasPageId === pageId) {\n const next = pages[Math.min(idx, pages.length - 1)];\n switchCanvasPage(next.id);\n } else {\n state.content.canvasPages = [...pages];\n state.isDirty = true;\n }\n }\n\n function renameCanvasPage(pageId: string, title: string): void {\n const pages = state.content.canvasPages;\n if (!pages) {\n return;\n }\n const page = pages.find((p) => p.id === pageId);\n if (!page) {\n return;\n }\n page.title = title.trim() || page.title;\n state.isDirty = true;\n }\n\n function switchToNextCanvasPage(): boolean {\n const pages = state.content.canvasPages;\n if (!pages?.length) {\n return false;\n }\n const activeId = state.content.activeCanvasPageId;\n const idx = pages.findIndex((p) => p.id === activeId);\n if (idx === -1 || idx >= pages.length - 1) {\n return false;\n }\n switchCanvasPage(pages[idx + 1].id);\n return true;\n }\n\n function switchToPreviousCanvasPage(): boolean {\n const pages = state.content.canvasPages;\n if (!pages?.length) {\n return false;\n }\n const activeId = state.content.activeCanvasPageId;\n const idx = pages.findIndex((p) => p.id === activeId);\n if (idx <= 0) {\n return false;\n }\n switchCanvasPage(pages[idx - 1].id);\n return true;\n }\n\n return {\n state: readonly(state),\n content,\n selectedBlock,\n savedBlockIds,\n isBlockLocked,\n setContent,\n selectBlock,\n setViewport,\n setDarkMode,\n setUiTheme,\n setPreviewMode,\n updateBlock,\n updateSettings,\n addBlock,\n removeBlock,\n moveBlock,\n create,\n load,\n save,\n createSnapshot,\n hasTemplate,\n markDirty,\n ensureCanvasPages,\n switchCanvasPage,\n addCanvasPage,\n removeCanvasPage,\n renameCanvasPage,\n switchToNextCanvasPage,\n switchToPreviousCanvasPage,\n };\n}\n","import type { AiChatMessage } from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { MergeTag, TemplateContent } from \"@aswin.dev/types\";\nimport { ref } from \"vue\";\n\nexport interface UseAiChatOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n onApply?: (content: TemplateContent) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseAiChatReturn {\n messages: ReturnType<typeof ref<AiChatMessage[]>>;\n isGenerating: ReturnType<typeof ref<boolean>>;\n isLoadingHistory: ReturnType<typeof ref<boolean>>;\n isLastChangeReverted: ReturnType<typeof ref<boolean>>;\n lastApplyMessageId: ReturnType<typeof ref<string | null>>;\n error: ReturnType<typeof ref<string | null>>;\n failedPrompt: ReturnType<typeof ref<string | null>>;\n suggestions: ReturnType<typeof ref<string[]>>;\n isLoadingSuggestions: ReturnType<typeof ref<boolean>>;\n sendPrompt: (\n prompt: string,\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<TemplateContent | null>;\n toggleLastRevert: () => void;\n loadConversation: () => Promise<void>;\n loadSuggestions: (\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<void>;\n clearChat: () => void;\n}\n\nlet messageIdCounter = 0;\n\nfunction generateMessageId(): string {\n return `msg_${Date.now()}_${++messageIdCounter}`;\n}\n\nexport function useAiChat(options: UseAiChatOptions): UseAiChatReturn {\n const { authManager, getTemplateId, onApply, onError } = options;\n\n const messages = ref<AiChatMessage[]>([]);\n const isGenerating = ref(false);\n const isLoadingHistory = ref(false);\n const error = ref<string | null>(null);\n const failedPrompt = ref<string | null>(null);\n const conversationId = ref<string | null>(null);\n const lastApplyMessageId = ref<string | null>(null);\n const lastPreviousContent = ref<TemplateContent | null>(null);\n const lastAppliedContent = ref<TemplateContent | null>(null);\n const isLastChangeReverted = ref(false);\n const suggestions = ref<string[]>([]);\n const isLoadingSuggestions = ref(false);\n\n function updateMessage(msgId: string, updates: Partial<AiChatMessage>): void {\n const idx = messages.value.findIndex((m) => m.id === msgId);\n if (idx === -1) {\n return;\n }\n\n const updated = { ...messages.value[idx], ...updates };\n messages.value = [\n ...messages.value.slice(0, idx),\n updated,\n ...messages.value.slice(idx + 1),\n ];\n }\n\n async function loadConversation(): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoadingHistory.value = true;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.conversationMessages\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n },\n });\n\n if (!response.ok) {\n return;\n }\n\n const data = await response.json();\n\n if (data.conversation_id) {\n conversationId.value = data.conversation_id;\n }\n\n if (Array.isArray(data.data) && data.data.length > 0) {\n messages.value = data.data.map(\n (msg: {\n id: string;\n role: \"user\" | \"assistant\";\n content: string;\n created_at: string;\n }) => ({\n id: msg.id,\n role: msg.role,\n content: msg.content,\n timestamp: new Date(msg.created_at).getTime(),\n }),\n );\n }\n } catch {\n // Silently fail - chat will start fresh\n } finally {\n isLoadingHistory.value = false;\n }\n }\n\n async function loadSuggestions(\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoadingSuggestions.value = true;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.suggestions\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n current_content: currentContent,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n return;\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n return;\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"done\" && Array.isArray(event.suggestions)) {\n suggestions.value = event.suggestions.slice(0, 3);\n }\n }\n }\n } catch {\n // Silently fail - suggestions are non-critical\n } finally {\n isLoadingSuggestions.value = false;\n }\n }\n\n async function sendPrompt(\n prompt: string,\n currentContent: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<TemplateContent | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before using AI generation\");\n }\n\n isGenerating.value = true;\n error.value = null;\n failedPrompt.value = null;\n suggestions.value = [];\n\n const userMsgId = generateMessageId();\n messages.value = [\n ...messages.value,\n {\n id: userMsgId,\n role: \"user\",\n content: prompt,\n timestamp: Date.now(),\n },\n ];\n\n const assistantMsgId = generateMessageId();\n messages.value = [\n ...messages.value,\n {\n id: assistantMsgId,\n role: \"assistant\",\n content: \"\",\n timestamp: Date.now(),\n },\n ];\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.generate\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n prompt,\n current_content: currentContent,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n conversation_id: conversationId.value,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => null);\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n throw new Error(errorData?.message || \"Failed to generate template\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: TemplateContent | null = null;\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n const jsonStr = line.slice(6);\n\n let event;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n updateMessage(assistantMsgId, {\n content:\n (messages.value.find((m) => m.id === assistantMsgId)\n ?.content ?? \"\") + event.text,\n });\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to generate template\");\n } else if (event.type === \"done\") {\n if (event.conversation_id) {\n conversationId.value = event.conversation_id;\n }\n\n updateMessage(assistantMsgId, {\n content: event.text,\n });\n\n result = event.content ?? null;\n\n if (result) {\n lastPreviousContent.value = currentContent;\n lastAppliedContent.value = result;\n lastApplyMessageId.value = assistantMsgId;\n isLastChangeReverted.value = false;\n onApply?.(result);\n } else {\n error.value = \"ai_apply_failed\";\n }\n }\n }\n }\n } finally {\n // Release the underlying network resource even on early exit.\n // Without this, throwing out of the loop (e.g. on an `error` SSE\n // event) leaves the socket and read buffer attached until GC.\n reader.cancel().catch(() => {});\n }\n\n return result;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to generate template\", { cause: err });\n error.value = wrappedError.message;\n failedPrompt.value = prompt;\n onError?.(wrappedError);\n\n messages.value = messages.value.filter(\n (m) => m.id !== userMsgId && m.id !== assistantMsgId,\n );\n\n return null;\n } finally {\n isGenerating.value = false;\n }\n }\n\n function toggleLastRevert(): void {\n if (isLastChangeReverted.value) {\n if (lastAppliedContent.value) {\n onApply?.(lastAppliedContent.value);\n }\n isLastChangeReverted.value = false;\n } else {\n if (lastPreviousContent.value) {\n onApply?.(lastPreviousContent.value);\n }\n isLastChangeReverted.value = true;\n }\n }\n\n function clearChat(): void {\n messages.value = [];\n conversationId.value = null;\n error.value = null;\n lastApplyMessageId.value = null;\n lastPreviousContent.value = null;\n lastAppliedContent.value = null;\n isLastChangeReverted.value = false;\n }\n\n return {\n messages,\n isGenerating,\n isLoadingHistory,\n isLastChangeReverted,\n lastApplyMessageId,\n error,\n failedPrompt,\n suggestions,\n isLoadingSuggestions,\n sendPrompt,\n toggleLastRevert,\n loadConversation,\n loadSuggestions,\n clearChat,\n };\n}\n","import type { MergeTag } from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport { ref } from \"vue\";\n\nexport interface UseAiRewriteOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n}\n\nexport interface UseAiRewriteReturn {\n isRewriting: ReturnType<typeof ref<boolean>>;\n streamingText: ReturnType<typeof ref<string>>;\n previousContent: ReturnType<typeof ref<string | null>>;\n rewrittenContent: ReturnType<typeof ref<string | null>>;\n isReverted: ReturnType<typeof ref<boolean>>;\n error: ReturnType<typeof ref<string | null>>;\n rewrite: (\n content: string,\n instruction: string,\n mergeTags: MergeTag[],\n ) => Promise<string | null>;\n undo: () => string | null;\n redo: () => string | null;\n reset: () => void;\n}\n\nexport function useAiRewrite(options: UseAiRewriteOptions): UseAiRewriteReturn {\n const { authManager, getTemplateId } = options;\n\n const isRewriting = ref(false);\n const streamingText = ref(\"\");\n const previousContent = ref<string | null>(null);\n const rewrittenContent = ref<string | null>(null);\n const isReverted = ref(false);\n const error = ref<string | null>(null);\n\n async function rewrite(\n content: string,\n instruction: string,\n mergeTags: MergeTag[],\n ): Promise<string | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isRewriting.value = true;\n streamingText.value = \"\";\n error.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.rewriteText\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n content,\n instruction,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to rewrite text\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: string | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n streamingText.value += event.text;\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to rewrite text\");\n } else if (event.type === \"done\") {\n result = event.content ?? null;\n\n if (result) {\n previousContent.value = content;\n rewrittenContent.value = result;\n isReverted.value = false;\n }\n }\n }\n }\n\n return result;\n } catch (err) {\n error.value =\n err instanceof Error ? err.message : \"Failed to rewrite text\";\n return null;\n } finally {\n isRewriting.value = false;\n }\n }\n\n function undo(): string | null {\n if (!previousContent.value) {\n return null;\n }\n\n isReverted.value = true;\n return previousContent.value;\n }\n\n function redo(): string | null {\n if (!rewrittenContent.value) {\n return null;\n }\n\n isReverted.value = false;\n return rewrittenContent.value;\n }\n\n function reset(): void {\n isRewriting.value = false;\n streamingText.value = \"\";\n previousContent.value = null;\n rewrittenContent.value = null;\n isReverted.value = false;\n error.value = null;\n }\n\n return {\n isRewriting,\n streamingText,\n previousContent,\n rewrittenContent,\n isReverted,\n error,\n rewrite,\n undo,\n redo,\n reset,\n };\n}\n","import type { AiConfig } from \"@aswin.dev/types\";\nimport { computed, type ComputedRef } from \"vue\";\n\nexport interface UseAiConfigReturn {\n isFeatureEnabled: (feature: keyof AiConfig) => boolean;\n hasAnyMenuFeature: ComputedRef<boolean>;\n}\n\nexport function useAiConfig(config?: AiConfig | false): UseAiConfigReturn {\n function isFeatureEnabled(feature: keyof AiConfig): boolean {\n if (config === false) {\n return false;\n }\n\n return config?.[feature] !== false;\n }\n\n const hasAnyMenuFeature = computed(\n () =>\n isFeatureEnabled(\"chat\") ||\n isFeatureEnabled(\"scoring\") ||\n isFeatureEnabled(\"designToTemplate\"),\n );\n\n return {\n isFeatureEnabled,\n hasAnyMenuFeature,\n };\n}\n","import type {\n ScoringCategory,\n ScoringFinding,\n ScoringResult,\n} from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { MergeTag, TemplateContent } from \"@aswin.dev/types\";\nimport { ref } from \"vue\";\n\nexport interface UseTemplateScoringOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n}\n\nexport interface UseTemplateScoringReturn {\n isScoring: ReturnType<typeof ref<boolean>>;\n scoringResult: ReturnType<typeof ref<ScoringResult | null>>;\n error: ReturnType<typeof ref<string | null>>;\n fixingFindingId: ReturnType<typeof ref<string | null>>;\n fixStreamingText: ReturnType<typeof ref<string>>;\n fixError: ReturnType<typeof ref<string | null>>;\n score: (\n content: TemplateContent,\n mergeTags: MergeTag[],\n ) => Promise<ScoringResult | null>;\n fixFinding: (\n blockContent: string,\n finding: ScoringFinding,\n mergeTags: MergeTag[],\n ) => Promise<string | null>;\n removeFinding: (category: ScoringCategory, findingId: string) => void;\n reset: () => void;\n}\n\nexport function useTemplateScoring(\n options: UseTemplateScoringOptions,\n): UseTemplateScoringReturn {\n const { authManager, getTemplateId } = options;\n\n const isScoring = ref(false);\n const scoringResult = ref<ScoringResult | null>(null);\n const error = ref<string | null>(null);\n const fixingFindingId = ref<string | null>(null);\n const fixStreamingText = ref(\"\");\n const fixError = ref<string | null>(null);\n\n async function score(\n content: TemplateContent,\n mergeTags: MergeTag[],\n ): Promise<ScoringResult | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isScoring.value = true;\n error.value = null;\n scoringResult.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.score\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n current_content: content,\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to score template\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: ScoringResult | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to score template\");\n }\n\n if (event.type === \"done\") {\n result = event.result ?? null;\n }\n }\n }\n\n if (result) {\n for (const [category, categoryData] of Object.entries(\n result.categories,\n )) {\n for (const finding of categoryData.findings) {\n finding.category = category as ScoringCategory;\n }\n }\n }\n\n scoringResult.value = result;\n return result;\n } catch (err) {\n error.value =\n err instanceof Error ? err.message : \"Failed to score template\";\n return null;\n } finally {\n isScoring.value = false;\n }\n }\n\n async function fixFinding(\n blockContent: string,\n finding: ScoringFinding,\n mergeTags: MergeTag[],\n ): Promise<string | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n fixingFindingId.value = finding.id;\n fixStreamingText.value = \"\";\n fixError.value = null;\n\n try {\n const url = buildUrl(API_ROUTES[\"ai.fixFinding\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n content: blockContent,\n finding: {\n id: finding.id,\n message: finding.message,\n suggestion: finding.suggestion,\n category: finding.category,\n },\n merge_tags: mergeTags.map((p) => ({\n label: p.label,\n value: p.value,\n })),\n }),\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n const errorData = await response.json().catch(() => null);\n throw new Error(errorData?.message || \"Failed to fix finding\");\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: string | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n let event;\n try {\n event = JSON.parse(line.slice(6));\n } catch {\n continue;\n }\n\n if (event.type === \"text\") {\n fixStreamingText.value += event.text;\n } else if (event.type === \"error\") {\n throw new Error(event.message || \"Failed to fix finding\");\n } else if (event.type === \"done\") {\n result = event.content ?? null;\n }\n }\n }\n\n return result;\n } catch (err) {\n fixError.value =\n err instanceof Error ? err.message : \"Failed to fix finding\";\n return null;\n } finally {\n fixingFindingId.value = null;\n }\n }\n\n function removeFinding(category: ScoringCategory, findingId: string): void {\n if (!scoringResult.value) {\n return;\n }\n\n const cat = scoringResult.value.categories[category];\n if (!cat) {\n return;\n }\n\n cat.findings = cat.findings.filter((f) => f.id !== findingId);\n }\n\n function reset(): void {\n isScoring.value = false;\n scoringResult.value = null;\n error.value = null;\n fixingFindingId.value = null;\n fixStreamingText.value = \"\";\n fixError.value = null;\n }\n\n return {\n isScoring,\n scoringResult,\n error,\n fixingFindingId,\n fixStreamingText,\n fixError,\n score,\n fixFinding,\n removeFinding,\n reset,\n };\n}\n","import type { AuthManager } from \"./auth\";\nimport { API_ROUTES, buildUrl } from \"./url-builder\";\nimport type { TemplateContent } from \"@aswin.dev/types\";\nimport { ref } from \"vue\";\n\nexport interface UseDesignReferenceOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n onApply?: (content: TemplateContent) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseDesignReferenceReturn {\n isGenerating: ReturnType<typeof ref<boolean>>;\n error: ReturnType<typeof ref<string | null>>;\n generate: (input: DesignReferenceInput) => Promise<TemplateContent | null>;\n reset: () => void;\n}\n\nexport interface DesignReferenceInput {\n prompt?: string;\n imageUpload?: File;\n pdfUpload?: File;\n}\n\nexport function useDesignReference(\n options: UseDesignReferenceOptions,\n): UseDesignReferenceReturn {\n const { authManager, getTemplateId, onApply, onError } = options;\n\n const isGenerating = ref(false);\n const error = ref<string | null>(null);\n\n async function generate(\n input: DesignReferenceInput,\n ): Promise<TemplateContent | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before using design reference\");\n }\n\n isGenerating.value = true;\n error.value = null;\n\n try {\n const formData = new FormData();\n\n if (input.prompt) {\n formData.append(\"prompt\", input.prompt);\n }\n\n if (input.imageUpload) {\n formData.append(\"image_upload\", input.imageUpload);\n }\n\n if (input.pdfUpload) {\n formData.append(\"pdf_upload\", input.pdfUpload);\n }\n\n const url = buildUrl(API_ROUTES[\"ai.generateFromDesign\"], {\n project: authManager.projectId,\n tenant: authManager.tenantSlug,\n template: templateId,\n });\n\n const response = await authManager.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n Accept: \"text/event-stream\",\n },\n body: formData,\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => null);\n if (response.status === 403) {\n throw new Error(\"ai_generation_not_available\");\n }\n throw new Error(\n errorData?.message || \"Failed to generate template from design\",\n );\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error(\"Failed to read stream\");\n }\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n let result: TemplateContent | null = null;\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) {\n continue;\n }\n\n const jsonStr = line.slice(6);\n\n let event;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"error\") {\n throw new Error(\n event.message || \"Failed to generate template from design\",\n );\n }\n\n if (event.type === \"done\") {\n result = event.content ?? null;\n\n if (result) {\n onApply?.(result);\n }\n }\n }\n }\n\n return result;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to generate template from design\", {\n cause: err,\n });\n error.value = wrappedError.message;\n onError?.(wrappedError);\n\n return null;\n } finally {\n isGenerating.value = false;\n }\n }\n\n function reset(): void {\n isGenerating.value = false;\n error.value = null;\n }\n\n return {\n isGenerating,\n error,\n generate,\n reset,\n };\n}\n","import type {\n Comment,\n CommentEvent,\n CommentThread,\n UserConfig,\n} from \"@aswin.dev/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { computed, ref, type ComputedRef, type Ref } from \"vue\";\n\nexport interface UseCommentsOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n getSocketId?: () => string | null;\n onComment?: (event: CommentEvent) => void;\n onError?: (error: Error) => void;\n isAuthReady?: Ref<boolean>;\n hasCommentingFeature?: () => boolean;\n}\n\nexport interface UseCommentsReturn {\n comments: Ref<CommentThread[]>;\n isLoading: Ref<boolean>;\n isSubmitting: Ref<boolean>;\n isEnabled: ComputedRef<boolean>;\n commentCountByBlock: ComputedRef<Map<string, number>>;\n totalCount: ComputedRef<number>;\n unresolvedCount: ComputedRef<number>;\n loadComments: () => Promise<void>;\n addComment: (\n body: string,\n blockId?: string,\n parentId?: string,\n ) => Promise<Comment | null>;\n editComment: (commentId: string, body: string) => Promise<Comment | null>;\n removeComment: (commentId: string) => Promise<boolean>;\n toggleResolve: (commentId: string) => Promise<Comment | null>;\n applyRemoteCreate: (comment: Comment) => void;\n applyRemoteUpdate: (comment: Comment) => void;\n applyRemoteDelete: (commentId: string, parentId: string | null) => void;\n}\n\nexport function useComments(options: UseCommentsOptions): UseCommentsReturn {\n const {\n authManager,\n getTemplateId,\n getSocketId,\n onComment,\n onError,\n hasCommentingFeature,\n } = options;\n\n const api = new ApiClient(authManager);\n const comments = ref<CommentThread[]>([]);\n const isLoading = ref(false);\n const isSubmitting = ref(false);\n\n const isEnabled = computed<boolean>(() => {\n const featureAvailable = hasCommentingFeature?.() ?? false;\n return featureAvailable && authManager.userConfig !== null;\n });\n\n const totalCount = computed<number>(() => {\n let count = 0;\n for (const thread of comments.value) {\n count += 1 + (thread.replies?.length ?? 0);\n }\n return count;\n });\n\n const unresolvedCount = computed<number>(() => {\n return comments.value.filter((c) => !c.resolved_at).length;\n });\n\n const commentCountByBlock = computed<Map<string, number>>(() => {\n const map = new Map<string, number>();\n for (const thread of comments.value) {\n if (thread.block_id) {\n map.set(\n thread.block_id,\n (map.get(thread.block_id) ?? 0) + 1 + (thread.replies?.length ?? 0),\n );\n }\n }\n return map;\n });\n\n function getUserPayload(): {\n user_id: string;\n user_name: string;\n user_signature: string;\n } {\n const user: UserConfig | null = authManager.userConfig;\n if (!user) {\n throw new Error(\"User config not available\");\n }\n return {\n user_id: user.id,\n user_name: user.name,\n user_signature: user.signature,\n };\n }\n\n function socketHeaders(): Record<string, string> | undefined {\n const socketId = getSocketId?.();\n if (!socketId) {\n return undefined;\n }\n return { \"X-Socket-ID\": socketId };\n }\n\n function emitEvent(type: CommentEvent[\"type\"], comment: Comment): void {\n onComment?.({ type, comment });\n }\n\n function findComment(commentId: string): Comment | null {\n for (const thread of comments.value) {\n if (thread.id === commentId) {\n return thread;\n }\n for (const reply of thread.replies ?? []) {\n if (reply.id === commentId) {\n return reply;\n }\n }\n }\n return null;\n }\n\n async function loadComments(): Promise<void> {\n const templateId = getTemplateId();\n if (!templateId) {\n return;\n }\n\n isLoading.value = true;\n\n try {\n comments.value = await api.getComments(templateId);\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to load comments\", { cause: err });\n onError?.(wrappedError);\n } finally {\n isLoading.value = false;\n }\n }\n\n async function addComment(\n body: string,\n blockId?: string,\n parentId?: string,\n ): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const comment = await api.createComment(\n templateId,\n {\n body,\n block_id: blockId,\n parent_id: parentId,\n ...getUserPayload(),\n },\n socketHeaders(),\n );\n\n if (parentId) {\n const parent = findComment(parentId);\n if (parent) {\n parent.replies = [...(parent.replies ?? []), comment];\n }\n } else {\n comments.value = [...comments.value, comment];\n }\n\n emitEvent(\"created\", comment);\n return comment;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to create comment\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function editComment(\n commentId: string,\n body: string,\n ): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const updated = await api.updateComment(\n templateId,\n commentId,\n {\n body,\n ...getUserPayload(),\n },\n socketHeaders(),\n );\n\n updateCommentInState(commentId, updated);\n emitEvent(\"updated\", updated);\n return updated;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to update comment\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function removeComment(commentId: string): Promise<boolean> {\n const templateId = getTemplateId();\n if (!templateId) {\n return false;\n }\n\n const comment = findComment(commentId);\n if (!comment) {\n return false;\n }\n\n const commentSnapshot = {\n ...comment,\n replies: [...(comment.replies ?? [])],\n };\n\n isSubmitting.value = true;\n\n try {\n await api.deleteComment(\n templateId,\n commentId,\n getUserPayload(),\n socketHeaders(),\n );\n\n if (comment.parent_id) {\n const parent = findComment(comment.parent_id);\n if (parent) {\n parent.replies = (parent.replies ?? []).filter(\n (r) => r.id !== commentId,\n );\n }\n } else {\n comments.value = comments.value.filter((c) => c.id !== commentId);\n }\n\n emitEvent(\"deleted\", commentSnapshot);\n return true;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to delete comment\", { cause: err });\n onError?.(wrappedError);\n return false;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n async function toggleResolve(commentId: string): Promise<Comment | null> {\n const templateId = getTemplateId();\n if (!templateId) {\n return null;\n }\n\n isSubmitting.value = true;\n\n try {\n const updated = await api.resolveComment(\n templateId,\n commentId,\n getUserPayload(),\n socketHeaders(),\n );\n\n updateCommentInState(commentId, updated);\n\n const eventType = updated.resolved_at ? \"resolved\" : \"unresolved\";\n emitEvent(eventType, updated);\n return updated;\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to toggle comment resolution\", { cause: err });\n onError?.(wrappedError);\n return null;\n } finally {\n isSubmitting.value = false;\n }\n }\n\n function applyRemoteCreate(comment: Comment): void {\n if (comment.parent_id) {\n const parent = findComment(comment.parent_id);\n if (parent) {\n parent.replies = [...(parent.replies ?? []), comment];\n }\n } else {\n comments.value = [...comments.value, comment];\n }\n emitEvent(\"created\", comment);\n }\n\n function applyRemoteUpdate(comment: Comment): void {\n updateCommentInState(comment.id, comment);\n emitEvent(\"updated\", comment);\n }\n\n function applyRemoteDelete(commentId: string, parentId: string | null): void {\n const comment = findComment(commentId);\n const snapshot = comment\n ? { ...comment, replies: [...(comment.replies ?? [])] }\n : null;\n\n if (parentId) {\n const parent = findComment(parentId);\n if (parent) {\n parent.replies = (parent.replies ?? []).filter(\n (r) => r.id !== commentId,\n );\n }\n } else {\n comments.value = comments.value.filter((c) => c.id !== commentId);\n }\n\n if (snapshot) {\n emitEvent(\"deleted\", snapshot);\n }\n }\n\n function updateCommentInState(commentId: string, updated: Comment): void {\n for (let i = 0; i < comments.value.length; i++) {\n if (comments.value[i].id === commentId) {\n comments.value = [\n ...comments.value.slice(0, i),\n { ...updated, replies: comments.value[i].replies },\n ...comments.value.slice(i + 1),\n ];\n return;\n }\n\n const replies = comments.value[i].replies ?? [];\n for (let j = 0; j < replies.length; j++) {\n if (replies[j].id === commentId) {\n const newReplies = [\n ...replies.slice(0, j),\n updated,\n ...replies.slice(j + 1),\n ];\n comments.value = [\n ...comments.value.slice(0, i),\n { ...comments.value[i], replies: newReplies },\n ...comments.value.slice(i + 1),\n ];\n return;\n }\n }\n }\n }\n\n return {\n comments,\n isLoading,\n isSubmitting,\n isEnabled,\n commentCountByBlock,\n totalCount,\n unresolvedCount,\n loadComments,\n addComment,\n editComment,\n removeComment,\n toggleResolve,\n applyRemoteCreate,\n applyRemoteUpdate,\n applyRemoteDelete,\n };\n}\n","import type { UseCommentsReturn } from \"./comments\";\nimport type { Comment } from \"@aswin.dev/types\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { onScopeDispose, watch, type Ref } from \"vue\";\n\nexport interface CommentBroadcastPayload {\n action:\n | \"comment_created\"\n | \"comment_updated\"\n | \"comment_deleted\"\n | \"comment_resolved\"\n | \"comment_unresolved\";\n comment: Comment;\n}\n\nexport interface UseCommentListenerOptions {\n comments: UseCommentsReturn;\n channel: Ref<PresenceChannel | null>;\n}\n\nexport function useCommentListener(options: UseCommentListenerOptions): void {\n const { comments, channel } = options;\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n oldChannel.unbind(\"comment-broadcast\");\n }\n\n if (newChannel) {\n newChannel.bind(\n \"comment-broadcast\",\n (payload: CommentBroadcastPayload) => {\n handleCommentBroadcast(comments, payload);\n },\n );\n }\n });\n\n // The watch only unbinds on channel *transitions*. On scope dispose the\n // currently-bound handler stays attached, processing broadcasts on a\n // dead component. Explicitly tear it down.\n onScopeDispose(() => {\n channel.value?.unbind(\"comment-broadcast\");\n });\n}\n\nfunction handleCommentBroadcast(\n comments: UseCommentsReturn,\n payload: CommentBroadcastPayload,\n): void {\n switch (payload.action) {\n case \"comment_created\":\n comments.applyRemoteCreate(payload.comment);\n break;\n case \"comment_updated\":\n comments.applyRemoteUpdate(payload.comment);\n break;\n case \"comment_deleted\":\n comments.applyRemoteDelete(payload.comment.id, payload.comment.parent_id);\n break;\n case \"comment_resolved\":\n case \"comment_unresolved\":\n comments.applyRemoteUpdate(payload.comment);\n break;\n }\n}\n","import type { UseEditorReturn } from \"./editor\";\nimport type { AuthManager } from \"./auth\";\nimport type { Collaborator, McpOperationPayload } from \"@aswin.dev/types\";\nimport { handleOperation } from \"./mcp-operation-handler\";\nimport type { PresenceMember } from \"./websocket-client\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { computed, onScopeDispose, ref, watch, type Ref } from \"vue\";\n\nconst COLLAB_EVENTS = [\n \"pusher:member_added\",\n \"pusher:member_removed\",\n \"client-block_locked\",\n \"client-block_unlocked\",\n \"client-operation\",\n \"mcp-operation\",\n] as const;\n\nfunction unbindCollabEvents(channel: PresenceChannel): void {\n for (const event of COLLAB_EVENTS) {\n channel.unbind(event);\n }\n}\n\nconst COLLABORATOR_COLORS = [\n \"#3b82f6\",\n \"#ef4444\",\n \"#10b981\",\n \"#f59e0b\",\n \"#8b5cf6\",\n \"#ec4899\",\n \"#06b6d4\",\n \"#f97316\",\n \"#6366f1\",\n \"#14b8a6\",\n];\n\nexport interface UseCollaborationOptions {\n authManager: AuthManager;\n editor: UseEditorReturn;\n channel: Ref<PresenceChannel | null>;\n onError?: (error: Error) => void;\n onCollaboratorJoined?: (collaborator: Collaborator) => void;\n onCollaboratorLeft?: (collaborator: Collaborator) => void;\n onBlockLocked?: (event: {\n blockId: string;\n collaborator: Collaborator;\n }) => void;\n onBlockUnlocked?: (event: {\n blockId: string;\n collaborator: Collaborator;\n }) => void;\n}\n\nexport interface UseCollaborationReturn {\n collaborators: Ref<Collaborator[]>;\n lockedBlocks: Ref<Map<string, Collaborator>>;\n}\n\nexport function useCollaboration(\n options: UseCollaborationOptions,\n): UseCollaborationReturn & {\n _broadcastOperation: (payload: McpOperationPayload) => void;\n _isProcessingRemoteOperation: () => boolean;\n} {\n const { authManager, editor, channel } = options;\n\n const collaborators = ref<Collaborator[]>([]);\n const lockedBlocks = ref<Map<string, Collaborator>>(new Map());\n\n let colorIndex = 0;\n let isProcessingRemoteOperation = false;\n\n const myUserId = computed(() => authManager.userConfig?.id ?? \"\");\n\n function assignColor(): string {\n const color = COLLABORATOR_COLORS[colorIndex % COLLABORATOR_COLORS.length];\n colorIndex++;\n return color;\n }\n\n function addCollaborator(member: PresenceMember): Collaborator | undefined {\n if (member.id === myUserId.value) {\n return undefined;\n }\n\n if (collaborators.value.some((c) => c.id === member.id)) {\n return undefined;\n }\n\n const collaborator: Collaborator = {\n id: member.id,\n name: member.name,\n color: assignColor(),\n selectedBlockId: null,\n };\n\n collaborators.value = [...collaborators.value, collaborator];\n\n return collaborator;\n }\n\n function removeCollaborator(memberId: string): void {\n const newLockedBlocks = new Map(lockedBlocks.value);\n for (const [blockId, collaborator] of newLockedBlocks) {\n if (collaborator.id === memberId) {\n newLockedBlocks.delete(blockId);\n }\n }\n lockedBlocks.value = newLockedBlocks;\n\n collaborators.value = collaborators.value.filter((c) => c.id !== memberId);\n }\n\n function handleBlockLocked(data: { blockId: string; userId: string }): void {\n const collaborator = collaborators.value.find((c) => c.id === data.userId);\n if (!collaborator) {\n return;\n }\n\n collaborators.value = collaborators.value.map((c) =>\n c.id === data.userId ? { ...c, selectedBlockId: data.blockId } : c,\n );\n\n const newLockedBlocks = new Map(lockedBlocks.value);\n for (const [blockId, holder] of newLockedBlocks) {\n if (holder.id === data.userId) {\n newLockedBlocks.delete(blockId);\n }\n }\n\n newLockedBlocks.set(data.blockId, {\n ...collaborator,\n selectedBlockId: data.blockId,\n });\n lockedBlocks.value = newLockedBlocks;\n\n if (editor.state.selectedBlockId === data.blockId) {\n editor.selectBlock(null);\n }\n }\n\n function handleBlockUnlocked(data: { blockId: string }): void {\n const newLockedBlocks = new Map(lockedBlocks.value);\n const holder = newLockedBlocks.get(data.blockId);\n newLockedBlocks.delete(data.blockId);\n lockedBlocks.value = newLockedBlocks;\n\n if (holder) {\n collaborators.value = collaborators.value.map((c) =>\n c.id === holder.id ? { ...c, selectedBlockId: null } : c,\n );\n }\n }\n\n function handleRemoteOperation(payload: McpOperationPayload): void {\n isProcessingRemoteOperation = true;\n try {\n handleOperation(editor, payload);\n } finally {\n isProcessingRemoteOperation = false;\n }\n }\n\n function broadcastOperation(payload: McpOperationPayload): void {\n if (!channel.value || isProcessingRemoteOperation) {\n return;\n }\n\n channel.value.trigger(\"client-operation\", payload);\n }\n\n function broadcastBlockLocked(blockId: string): void {\n if (!channel.value) {\n return;\n }\n\n channel.value.trigger(\"client-block_locked\", {\n blockId,\n userId: myUserId.value,\n });\n }\n\n function broadcastBlockUnlocked(blockId: string): void {\n if (!channel.value) {\n return;\n }\n\n channel.value.trigger(\"client-block_unlocked\", { blockId });\n }\n\n watch(\n () => editor.state.selectedBlockId,\n (newBlockId, oldBlockId) => {\n if (isProcessingRemoteOperation) {\n return;\n }\n\n if (oldBlockId) {\n broadcastBlockUnlocked(oldBlockId);\n }\n\n if (newBlockId) {\n broadcastBlockLocked(newBlockId);\n }\n },\n );\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n unbindCollabEvents(oldChannel);\n }\n\n if (!newChannel) {\n collaborators.value = [];\n lockedBlocks.value = new Map();\n colorIndex = 0;\n return;\n }\n\n const members = (\n newChannel as PresenceChannel & {\n members: {\n each: (\n callback: (member: { id: string; info: PresenceMember }) => void,\n ) => void;\n };\n }\n ).members;\n if (members) {\n members.each((member: { id: string; info: PresenceMember }) => {\n addCollaborator(member.info);\n });\n }\n\n newChannel.bind(\n \"pusher:member_added\",\n (member: { id: string; info: PresenceMember }) => {\n const collaborator = addCollaborator(member.info);\n if (collaborator) {\n options.onCollaboratorJoined?.(collaborator);\n }\n },\n );\n\n newChannel.bind(\n \"pusher:member_removed\",\n (member: { id: string; info: PresenceMember }) => {\n const collaborator = collaborators.value.find(\n (c) => c.id === member.id,\n );\n removeCollaborator(member.id);\n if (collaborator) {\n options.onCollaboratorLeft?.(collaborator);\n }\n },\n );\n\n newChannel.bind(\n \"client-block_locked\",\n (data: { blockId: string; userId: string }) => {\n handleBlockLocked(data);\n const collaborator = collaborators.value.find(\n (c) => c.id === data.userId,\n );\n if (collaborator) {\n options.onBlockLocked?.({\n blockId: data.blockId,\n collaborator,\n });\n }\n },\n );\n\n newChannel.bind(\"client-block_unlocked\", (data: { blockId: string }) => {\n const holder = lockedBlocks.value.get(data.blockId);\n handleBlockUnlocked(data);\n if (holder) {\n options.onBlockUnlocked?.({\n blockId: data.blockId,\n collaborator: holder,\n });\n }\n });\n\n newChannel.bind(\"client-operation\", (payload: McpOperationPayload) => {\n handleRemoteOperation(payload);\n });\n\n newChannel.bind(\"mcp-operation\", (payload: McpOperationPayload) => {\n handleRemoteOperation(payload);\n });\n });\n\n // The watch above only unbinds when the channel ref *changes*. On scope\n // dispose (component unmount) the watch is auto-stopped but the currently\n // bound listeners stay attached forever — handlers fire on a dead component\n // and accumulate on remount. Tear them down explicitly.\n onScopeDispose(() => {\n if (channel.value) {\n unbindCollabEvents(channel.value);\n }\n });\n\n return {\n collaborators,\n lockedBlocks,\n _broadcastOperation: broadcastOperation,\n _isProcessingRemoteOperation: () => isProcessingRemoteOperation,\n };\n}\n","import type { McpOperationPayload } from \"@aswin.dev/types\";\nimport type { UseEditorReturn } from \"../editor\";\n\ninterface BroadcastTarget {\n _broadcastOperation: (payload: McpOperationPayload) => void;\n}\n\n/**\n * Wraps editor mutation methods to broadcast operations to collaboration\n * peers after each mutation executes. Mutates the editor object in place.\n *\n * Must be applied **before** the history interceptor so the call chain is:\n * history.record() → broadcast + original mutation.\n */\nexport function useCollaborationBroadcast(\n editor: UseEditorReturn,\n collaboration: BroadcastTarget,\n): void {\n const originalAddBlock = editor.addBlock;\n const originalUpdateBlock = editor.updateBlock;\n const originalRemoveBlock = editor.removeBlock;\n const originalMoveBlock = editor.moveBlock;\n const originalUpdateSettings = editor.updateSettings;\n const originalSetContent = editor.setContent;\n\n editor.addBlock = (block, targetSectionId?, columnIndex?) => {\n originalAddBlock(block, targetSectionId, columnIndex);\n collaboration._broadcastOperation({\n operation: \"add_block\",\n data: {\n block,\n section_id: targetSectionId,\n column_index: columnIndex,\n },\n timestamp: Date.now(),\n });\n };\n\n editor.updateBlock = (blockId, updates) => {\n originalUpdateBlock(blockId, updates);\n collaboration._broadcastOperation({\n operation: \"update_block\",\n data: { block_id: blockId, updates },\n timestamp: Date.now(),\n });\n };\n\n editor.removeBlock = (blockId) => {\n originalRemoveBlock(blockId);\n collaboration._broadcastOperation({\n operation: \"delete_block\",\n data: { block_id: blockId },\n timestamp: Date.now(),\n });\n };\n\n editor.moveBlock = (blockId, newIndex, targetSectionId?, columnIndex?) => {\n originalMoveBlock(blockId, newIndex, targetSectionId, columnIndex);\n collaboration._broadcastOperation({\n operation: \"move_block\",\n data: {\n block_id: blockId,\n index: newIndex,\n section_id: targetSectionId,\n column_index: columnIndex,\n },\n timestamp: Date.now(),\n });\n };\n\n editor.updateSettings = (updates) => {\n originalUpdateSettings(updates);\n collaboration._broadcastOperation({\n operation: \"update_settings\",\n data: { updates },\n timestamp: Date.now(),\n });\n };\n\n editor.setContent = (content, markDirty?) => {\n originalSetContent(content, markDirty);\n collaboration._broadcastOperation({\n operation: \"set_content\",\n data: { content },\n timestamp: Date.now(),\n });\n };\n}\n","import type { AuthManager } from \"./auth\";\nimport type { WebSocketConfig } from \"./websocket-client\";\nimport { WebSocketClient } from \"./websocket-client\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseWebSocketOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UseWebSocketReturn {\n channel: Ref<PresenceChannel | null>;\n isConnected: Ref<boolean>;\n connect: (templateId: string, config: WebSocketConfig) => Promise<void>;\n disconnect: () => void;\n getSocketId: () => string | null;\n}\n\nexport function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {\n const { authManager, onError } = options;\n\n const channel = ref<PresenceChannel | null>(\n null,\n ) as Ref<PresenceChannel | null>;\n const isConnected = ref(false);\n\n let wsClient: WebSocketClient | null = null;\n let channelName: string | null = null;\n\n async function connect(\n templateId: string,\n config: WebSocketConfig,\n ): Promise<void> {\n if (wsClient) {\n return;\n }\n\n wsClient = new WebSocketClient({\n authManager,\n config,\n onError,\n });\n\n await wsClient.connect();\n\n channelName = `presence-template.${templateId}`;\n const presenceChannel = wsClient.subscribePresence(channelName);\n\n presenceChannel.bind(\"pusher:subscription_succeeded\", () => {\n isConnected.value = true;\n channel.value = presenceChannel;\n });\n\n presenceChannel.bind(\"pusher:subscription_error\", (error: unknown) => {\n isConnected.value = false;\n channel.value = null;\n onError?.(\n error instanceof Error\n ? error\n : new Error(\"Failed to subscribe to template channel\"),\n );\n });\n }\n\n function disconnect(): void {\n if (channelName && wsClient) {\n wsClient.unsubscribe(channelName);\n }\n\n wsClient?.disconnect();\n wsClient = null;\n channelName = null;\n channel.value = null;\n isConnected.value = false;\n }\n\n function getSocketId(): string | null {\n return wsClient?.getSocketId() ?? null;\n }\n\n return {\n channel,\n isConnected,\n connect,\n disconnect,\n getSocketId,\n };\n}\n","import type { SavedModule } from \"@aswin.dev/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport type { Block } from \"@aswin.dev/types\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseSavedModulesOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UseSavedModulesReturn {\n modules: Ref<SavedModule[]>;\n isLoading: Ref<boolean>;\n loadModules: (search?: string) => Promise<void>;\n createModule: (name: string, content: Block[]) => Promise<SavedModule>;\n updateModule: (\n id: string,\n data: Partial<{ name: string; content: Block[] }>,\n ) => Promise<SavedModule>;\n deleteModule: (id: string) => Promise<void>;\n}\n\nexport function useSavedModules(\n options: UseSavedModulesOptions,\n): UseSavedModulesReturn {\n const api = new ApiClient(options.authManager);\n\n const modules = ref<SavedModule[]>([]);\n const isLoading = ref(false);\n\n async function loadModules(search?: string): Promise<void> {\n isLoading.value = true;\n try {\n modules.value = await api.listModules(search);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isLoading.value = false;\n }\n }\n\n async function createModule(\n name: string,\n content: Block[],\n ): Promise<SavedModule> {\n try {\n const module = await api.createModule({ name, content });\n modules.value = [module, ...modules.value];\n return module;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n }\n }\n\n async function updateModule(\n id: string,\n data: Partial<{ name: string; content: Block[] }>,\n ): Promise<SavedModule> {\n try {\n const updated = await api.updateModule(id, data);\n modules.value = modules.value.map((m) => (m.id === id ? updated : m));\n return updated;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n }\n }\n\n async function deleteModule(id: string): Promise<void> {\n try {\n await api.deleteModule(id);\n modules.value = modules.value.filter((m) => m.id !== id);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n }\n }\n\n return {\n modules,\n isLoading,\n loadModules,\n createModule,\n updateModule,\n deleteModule,\n };\n}\n","import type { Template, TemplateSnapshot } from \"@aswin.dev/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { ref, type Ref } from \"vue\";\n\nexport interface UseSnapshotHistoryOptions {\n authManager: AuthManager;\n templateId: string;\n onRestore?: (template: Template) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseSnapshotHistoryReturn {\n snapshots: Ref<TemplateSnapshot[]>;\n isLoading: Ref<boolean>;\n isRestoring: Ref<boolean>;\n loadSnapshots: () => Promise<void>;\n restoreSnapshot: (snapshotId: string) => Promise<Template>;\n}\n\nexport function useSnapshotHistory(\n options: UseSnapshotHistoryOptions,\n): UseSnapshotHistoryReturn {\n const api = new ApiClient(options.authManager);\n\n const snapshots = ref<TemplateSnapshot[]>([]);\n const isLoading = ref(false);\n const isRestoring = ref(false);\n\n async function loadSnapshots(): Promise<void> {\n isLoading.value = true;\n try {\n snapshots.value = await api.getSnapshots(options.templateId);\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isLoading.value = false;\n }\n }\n\n async function restoreSnapshot(snapshotId: string): Promise<Template> {\n isRestoring.value = true;\n try {\n const template = await api.restoreSnapshot(\n options.templateId,\n snapshotId,\n );\n options.onRestore?.(template);\n return template;\n } catch (error) {\n options.onError?.(error as Error);\n throw error;\n } finally {\n isRestoring.value = false;\n }\n }\n\n return {\n snapshots,\n isLoading,\n isRestoring,\n loadSnapshots,\n restoreSnapshot,\n };\n}\n","import type { ExportResult, Template, TestEmailConfig } from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { ApiClient } from \"./api\";\nimport type { ComputedRef, Ref } from \"vue\";\nimport { computed, ref, watch } from \"vue\";\n\nexport interface UseTestEmailOptions {\n authManager: AuthManager;\n getTemplateId: () => string | null;\n save: () => Promise<Template>;\n exportHtml: (templateId: string) => Promise<ExportResult>;\n onError?: (error: Error) => void;\n isAuthReady?: Ref<boolean>;\n onBeforeTestEmail?: (html: string) => string | Promise<string>;\n}\n\nexport interface UseTestEmailReturn {\n isEnabled: ComputedRef<boolean>;\n allowedEmails: ComputedRef<string[]>;\n isSending: Ref<boolean>;\n error: Ref<string | null>;\n sendTestEmail: (recipient: string) => Promise<void>;\n}\n\nexport function useTestEmail(options: UseTestEmailOptions): UseTestEmailReturn {\n const {\n authManager,\n getTemplateId,\n save,\n exportHtml,\n onError,\n isAuthReady,\n onBeforeTestEmail,\n } = options;\n const api = new ApiClient(authManager);\n\n const isSending = ref(false);\n const error = ref<string | null>(null);\n\n const testEmailConfig = ref<TestEmailConfig | null>(null);\n\n if (isAuthReady) {\n watch(\n isAuthReady,\n (ready) => {\n if (ready) {\n testEmailConfig.value = authManager.testEmailConfig;\n }\n },\n { immediate: true },\n );\n }\n\n const isEnabled = computed<boolean>(() => testEmailConfig.value !== null);\n\n const allowedEmails = computed<string[]>(\n () => testEmailConfig.value?.allowedEmails ?? [],\n );\n\n async function sendTestEmail(recipient: string): Promise<void> {\n if (!testEmailConfig.value) {\n throw new Error(\"Test email is not enabled for this project\");\n }\n\n const templateId = getTemplateId();\n if (!templateId) {\n throw new Error(\"Template must be saved before sending a test email\");\n }\n\n isSending.value = true;\n error.value = null;\n\n try {\n await save();\n\n let { html } = await exportHtml(templateId);\n\n if (onBeforeTestEmail) {\n html = await onBeforeTestEmail(html);\n }\n\n await api.sendTestEmail(templateId, {\n recipient,\n html,\n allowed_emails: testEmailConfig.value.allowedEmails,\n signature: testEmailConfig.value.signature,\n });\n } catch (err) {\n const wrappedError =\n err instanceof Error\n ? err\n : new Error(\"Failed to send test email\", { cause: err });\n error.value = wrappedError.message;\n onError?.(wrappedError);\n throw wrappedError;\n } finally {\n isSending.value = false;\n }\n }\n\n return {\n isEnabled,\n allowedEmails,\n isSending,\n error,\n sendTestEmail,\n };\n}\n","import type { CustomFont, ExportResult, FontsConfig } from \"@aswin.dev/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\n\nexport interface UseExportOptions {\n authManager: AuthManager;\n getFontsConfig?: () => FontsConfig | undefined;\n canUseCustomFonts?: () => boolean;\n}\n\nexport interface UseExportReturn {\n exportHtml: (templateId: string) => Promise<ExportResult>;\n getMjmlSource: (templateId: string) => Promise<string>;\n}\n\nexport function useExport(options: UseExportOptions): UseExportReturn {\n const { authManager, getFontsConfig, canUseCustomFonts } = options;\n const api = new ApiClient(authManager);\n\n function getExportFontsPayload(): {\n customFonts: CustomFont[];\n defaultFallback: string;\n } {\n const fontsConfig = getFontsConfig?.();\n const customFontsAllowed = canUseCustomFonts?.() ?? true;\n\n return {\n customFonts:\n customFontsAllowed && fontsConfig?.customFonts\n ? fontsConfig.customFonts\n : [],\n defaultFallback: fontsConfig?.defaultFallback ?? \"Arial, sans-serif\",\n };\n }\n\n async function exportHtml(templateId: string): Promise<ExportResult> {\n const fontsPayload = getExportFontsPayload();\n const result = await api.exportTemplate(templateId, fontsPayload);\n\n return {\n html: result.html,\n mjml: result.mjml,\n };\n }\n\n async function getMjmlSource(templateId: string): Promise<string> {\n const fontsPayload = getExportFontsPayload();\n const result = await api.exportTemplate(templateId, fontsPayload);\n return result.mjml;\n }\n\n return {\n exportHtml,\n getMjmlSource,\n };\n}\n","import type { PlanConfig, PlanFeatures } from \"@aswin.dev/types\";\nimport { ApiClient } from \"./api\";\nimport type { AuthManager } from \"./auth\";\nimport { computed, ref, type ComputedRef, type Ref } from \"vue\";\n\nexport interface UsePlanConfigOptions {\n authManager: AuthManager;\n onError?: (error: Error) => void;\n}\n\nexport interface UsePlanConfigReturn {\n config: Ref<PlanConfig | null>;\n isLoading: Ref<boolean>;\n hasFeature: (feature: keyof PlanFeatures) => boolean;\n features: ComputedRef<PlanFeatures | null>;\n fetchConfig: () => Promise<void>;\n}\n\nexport function usePlanConfig(\n options: UsePlanConfigOptions,\n): UsePlanConfigReturn {\n const { authManager, onError } = options;\n\n const config = ref<PlanConfig | null>(null);\n const isLoading = ref(false);\n\n const apiClient = new ApiClient(authManager);\n\n const features = computed(() => config.value?.features ?? null);\n\n function hasFeature(feature: keyof PlanFeatures): boolean {\n return config.value?.features[feature] ?? false;\n }\n\n async function fetchConfig(): Promise<void> {\n if (isLoading.value) {\n return;\n }\n\n isLoading.value = true;\n\n try {\n config.value = await apiClient.fetchConfig();\n } catch (error) {\n onError?.(\n error instanceof Error\n ? error\n : new Error(\"Failed to fetch config\", { cause: error }),\n );\n } finally {\n isLoading.value = false;\n }\n }\n\n return {\n config,\n isLoading,\n hasFeature,\n features,\n fetchConfig,\n };\n}\n","import type { HealthCheckResult } from \"@aswin.dev/types\";\nimport type { AuthManager } from \"./auth\";\nimport { API_ROUTES } from \"./url-builder\";\n\ninterface HealthCheckOptions {\n authManager?: AuthManager;\n baseUrl?: string;\n}\n\nconst WS_HANDSHAKE_TIMEOUT = 5000;\n\nfunction resolveHealthUrl(options: HealthCheckOptions): string {\n if (options.authManager) {\n return options.authManager.resolveUrl(API_ROUTES.health);\n }\n\n const base = (options.baseUrl ?? \"https://templatical.com\").replace(\n /\\/$/,\n \"\",\n );\n return `${base}${API_ROUTES.health}`;\n}\n\nasync function checkApiAndAuth(\n url: string,\n authManager?: AuthManager,\n): Promise<{\n api: { ok: boolean; latency: number };\n auth: { ok: boolean; error?: string };\n wsConfig?: { host: string; port: number; app_key: string };\n}> {\n const start = performance.now();\n\n try {\n const response = authManager\n ? await authManager.authenticatedFetch(API_ROUTES.health, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n })\n : await fetch(url, {\n method: \"GET\",\n headers: { Accept: \"application/json\" },\n });\n\n const latency = Math.round(performance.now() - start);\n\n if (response.status === 401) {\n return {\n api: { ok: true, latency },\n auth: { ok: false, error: \"HTTP 401\" },\n };\n }\n\n if (!response.ok) {\n return {\n api: { ok: false, latency },\n auth: {\n ok: !authManager,\n error: authManager ? `HTTP ${response.status}` : undefined,\n },\n };\n }\n\n const data = await response.json();\n\n return {\n api: { ok: data.status === \"ok\", latency },\n auth: { ok: true },\n wsConfig: data.websocket,\n };\n } catch (error) {\n const latency = Math.round(performance.now() - start);\n\n return {\n api: { ok: false, latency },\n auth: {\n ok: !authManager,\n error: authManager\n ? error instanceof Error\n ? error.message\n : \"Authentication check failed\"\n : undefined,\n },\n };\n }\n}\n\nasync function checkWebSocket(wsConfig?: {\n host: string;\n port: number;\n app_key: string;\n}): Promise<{ ok: boolean; error?: string }> {\n if (!wsConfig?.host || !wsConfig?.app_key) {\n return { ok: false, error: \"WebSocket configuration not available\" };\n }\n\n if (typeof WebSocket === \"undefined\") {\n return {\n ok: false,\n error: \"WebSocket not supported in this environment\",\n };\n }\n\n const protocol = wsConfig.port === 443 ? \"wss\" : \"ws\";\n const url = `${protocol}://${wsConfig.host}:${wsConfig.port}/app/${wsConfig.app_key}?protocol=7&client=js&version=8.4.0-rc2&flash=false`;\n\n return new Promise((resolve) => {\n let ws: WebSocket | null = null;\n\n const timeout = setTimeout(() => {\n ws?.close();\n resolve({ ok: false, error: \"WebSocket connection timed out\" });\n }, WS_HANDSHAKE_TIMEOUT);\n\n try {\n ws = new WebSocket(url);\n } catch (error) {\n // Some browsers throw synchronously from `new WebSocket(...)`\n // (e.g. SecurityError on mixed content, InvalidAccessError on\n // malformed URL). Without this catch the queued timeout would\n // later access `ws` in TDZ and the outer promise would hang.\n clearTimeout(timeout);\n resolve({\n ok: false,\n error:\n error instanceof Error\n ? error.message\n : \"WebSocket connection failed\",\n });\n return;\n }\n\n ws.onopen = () => {\n clearTimeout(timeout);\n ws?.close();\n resolve({ ok: true });\n };\n\n ws.onerror = () => {\n clearTimeout(timeout);\n resolve({ ok: false, error: \"WebSocket connection failed\" });\n };\n });\n}\n\nexport async function performHealthCheck(\n options: HealthCheckOptions = {},\n): Promise<HealthCheckResult> {\n const healthUrl = resolveHealthUrl(options);\n\n const result = await checkApiAndAuth(healthUrl, options.authManager);\n const wsResult = await checkWebSocket(result.wsConfig);\n\n return {\n api: result.api,\n websocket: wsResult,\n auth: result.auth,\n overall: result.api.ok && result.auth.ok,\n };\n}\n","import type { UseEditorReturn } from \"./editor\";\nimport type { McpOperationPayload } from \"@aswin.dev/types\";\nimport { handleOperation } from \"./mcp-operation-handler\";\nimport type { PresenceChannel } from \"pusher-js\";\nimport { watch, type Ref } from \"vue\";\n\nexport interface UseMcpListenerOptions {\n editor: UseEditorReturn;\n channel: Ref<PresenceChannel | null>;\n onOperation?: (payload: McpOperationPayload) => void;\n}\n\nexport function useMcpListener(options: UseMcpListenerOptions): void {\n const { editor, channel, onOperation } = options;\n\n watch(channel, (newChannel, oldChannel) => {\n if (oldChannel) {\n oldChannel.unbind(\"mcp-operation\");\n }\n\n if (newChannel) {\n newChannel.bind(\"mcp-operation\", (payload: McpOperationPayload) => {\n handleOperation(editor, payload);\n onOperation?.(payload);\n });\n }\n });\n}\n"],"mappings":";AAQA,SAAS,gBAAgB;AAUlB,IAAM,cAAN,MAAM,aAAY;AAAA,EACvB,OAAwB,mBAAmB;AAAA,EAEnC,cAA6B;AAAA,EAC7B,YAAyB;AAAA,EACzB,aAA4B;AAAA,EAC5B,YAA2B;AAAA,EAC3B,cAA6B;AAAA,EAC7B,mBAA2C;AAAA,EAC3C,cAAiC;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,iBAAyC;AAAA,EAEjD,OAAwB,uBAAuB,KAAK;AAAA,EAEpD,YAAY,QAAoB;AAC9B,SAAK,MAAM,OAAO;AAClB,SAAK,WAAW,OAAO,WAAW,aAAY,kBAAkB;AAAA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OAAO;AACpB,cAAQ,EAAE,IAAI,OAAO,OAAO,8BAA8B,CAAC;AAAA,IAC7D;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,mBACpB,UAA8B,CAAC,GACH;AAC5B,QAAM,YAAY,iBAAiB,OAAO;AAE1C,QAAM,SAAS,MAAM,gBAAgB,WAAW,QAAQ,WAAW;AACnE,QAAM,WAAW,MAAM,eAAe,OAAO,QAAQ;AAErD,SAAO;AAAA,IACL,KAAK,OAAO;AAAA,IACZ,WAAW;AAAA,IACX,MAAM,OAAO;AAAA,IACb,SAAS,OAAO,IAAI,MAAM,OAAO,KAAK;AAAA,EACxC;AACF;;;AC3JA,SAAS,SAAAE,cAAuB;AAQzB,SAAS,eAAe,SAAsC;AACnE,QAAM,EAAE,QAAQ,SAAS,YAAY,IAAI;AAEzC,EAAAA,OAAM,SAAS,CAAC,YAAY,eAAe;AACzC,QAAI,YAAY;AACd,iBAAW,OAAO,eAAe;AAAA,IACnC;AAEA,QAAI,YAAY;AACd,iBAAW,KAAK,iBAAiB,CAAC,YAAiC;AACjE,wBAAgB,QAAQ,OAAO;AAC/B,sBAAc,OAAO;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["SdkError","SdkError","SdkError","markDirty","content","SdkError","ref","computed","ref","ref","computed","ref","computed","onScopeDispose","ref","watch","ref","ref","ref","computed","ref","watch","computed","ref","watch"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TemplateContent, ViewportSize, UiTheme, TemplateDefaults, Block, TemplateSettings } from '@aswin.dev/types';
|
|
2
|
+
import { Ref, DeepReadonly } from '@vue/reactivity';
|
|
3
|
+
|
|
4
|
+
interface EditorState {
|
|
5
|
+
content: TemplateContent;
|
|
6
|
+
selectedBlockId: string | null;
|
|
7
|
+
viewport: ViewportSize;
|
|
8
|
+
darkMode: boolean;
|
|
9
|
+
previewMode: boolean;
|
|
10
|
+
isDirty: boolean;
|
|
11
|
+
uiTheme: UiTheme;
|
|
12
|
+
}
|
|
13
|
+
interface UseEditorOptions {
|
|
14
|
+
content: TemplateContent;
|
|
15
|
+
defaultFontFamily?: string;
|
|
16
|
+
templateDefaults?: TemplateDefaults;
|
|
17
|
+
lockedBlocks?: Ref<Map<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
interface UseEditorReturn {
|
|
20
|
+
state: DeepReadonly<EditorState>;
|
|
21
|
+
content: Ref<TemplateContent>;
|
|
22
|
+
selectedBlock: Ref<Block | null>;
|
|
23
|
+
setContent: (content: TemplateContent, markDirty?: boolean) => void;
|
|
24
|
+
selectBlock: (blockId: string | null) => void;
|
|
25
|
+
setViewport: (viewport: ViewportSize) => void;
|
|
26
|
+
setDarkMode: (darkMode: boolean) => void;
|
|
27
|
+
setPreviewMode: (previewMode: boolean) => void;
|
|
28
|
+
setUiTheme: (theme: UiTheme) => void;
|
|
29
|
+
updateBlock: (blockId: string, updates: Partial<Block>) => void;
|
|
30
|
+
updateSettings: (updates: Partial<TemplateSettings>) => void;
|
|
31
|
+
addBlock: (block: Block, targetSectionId?: string, columnIndex?: number, index?: number) => void;
|
|
32
|
+
removeBlock: (blockId: string) => void;
|
|
33
|
+
moveBlock: (blockId: string, newIndex: number, targetSectionId?: string, columnIndex?: number) => void;
|
|
34
|
+
isBlockLocked: (blockId: string) => boolean;
|
|
35
|
+
markDirty: () => void;
|
|
36
|
+
/** Wrap existing blocks as step 1 (popup / wizard canvases). No-op if already set. */
|
|
37
|
+
ensureCanvasPages: () => void;
|
|
38
|
+
/** Switch active canvas step; clears selection. */
|
|
39
|
+
switchCanvasPage: (pageId: string) => void;
|
|
40
|
+
/** Append an empty step and activate it. */
|
|
41
|
+
addCanvasPage: () => void;
|
|
42
|
+
/** Remove a step (must keep at least one). If active is removed, selects another. */
|
|
43
|
+
removeCanvasPage: (pageId: string) => void;
|
|
44
|
+
/** Update a step title shown in the canvas strip. */
|
|
45
|
+
renameCanvasPage: (pageId: string, title: string) => void;
|
|
46
|
+
/** Activate the next canvas step when using multi-page mode; returns false if none. */
|
|
47
|
+
switchToNextCanvasPage: () => boolean;
|
|
48
|
+
switchToPreviousCanvasPage: () => boolean;
|
|
49
|
+
}
|
|
50
|
+
declare function useEditor(options: UseEditorOptions): UseEditorReturn;
|
|
51
|
+
|
|
52
|
+
export { type EditorState as E, type UseEditorReturn as U, type UseEditorOptions as a, useEditor as u };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { U as UseEditorReturn } from './editor-Cp6y4tLN.js';
|
|
2
|
+
export { E as EditorState, a as UseEditorOptions, u as useEditor } from './editor-Cp6y4tLN.js';
|
|
3
|
+
import { TemplateContent, Block, BlockDefaults, BlockType, CustomBlockDefinition, CustomBlock } from '@aswin.dev/types';
|
|
4
|
+
import { Ref, ComputedRef } from '@vue/reactivity';
|
|
5
|
+
|
|
6
|
+
interface UseHistoryOptions {
|
|
7
|
+
content: Ref<TemplateContent>;
|
|
8
|
+
setContent: (content: TemplateContent, markDirty?: boolean) => void;
|
|
9
|
+
isRemoteOperation?: () => boolean;
|
|
10
|
+
maxSize?: number;
|
|
11
|
+
}
|
|
12
|
+
interface UseHistoryReturn {
|
|
13
|
+
canUndo: ComputedRef<boolean>;
|
|
14
|
+
canRedo: ComputedRef<boolean>;
|
|
15
|
+
isNavigating: Ref<boolean>;
|
|
16
|
+
undo: () => void;
|
|
17
|
+
redo: () => void;
|
|
18
|
+
record: () => void;
|
|
19
|
+
recordDebounced: (blockId: string) => void;
|
|
20
|
+
clear: () => void;
|
|
21
|
+
destroy: () => void;
|
|
22
|
+
}
|
|
23
|
+
declare function useHistory(options: UseHistoryOptions): UseHistoryReturn;
|
|
24
|
+
|
|
25
|
+
interface UseBlockActionsOptions {
|
|
26
|
+
addBlock: (block: Block, targetSectionId?: string, columnIndex?: number) => void;
|
|
27
|
+
removeBlock: (blockId: string) => void;
|
|
28
|
+
updateBlock: (blockId: string, updates: Partial<Block>) => void;
|
|
29
|
+
selectBlock: (blockId: string | null) => void;
|
|
30
|
+
blockDefaults?: BlockDefaults;
|
|
31
|
+
}
|
|
32
|
+
interface UseBlockActionsReturn {
|
|
33
|
+
createAndAddBlock: (type: BlockType, targetSectionId?: string, columnIndex?: number) => Block;
|
|
34
|
+
duplicateBlock: (block: Block, targetSectionId?: string, columnIndex?: number) => Block;
|
|
35
|
+
deleteBlock: (blockId: string) => void;
|
|
36
|
+
updateBlockProperty: <K extends keyof Block>(blockId: string, key: K, value: Block[K]) => void;
|
|
37
|
+
}
|
|
38
|
+
declare function useBlockActions(options: UseBlockActionsOptions): UseBlockActionsReturn;
|
|
39
|
+
|
|
40
|
+
interface UseAutoSaveOptions {
|
|
41
|
+
content: Ref<TemplateContent>;
|
|
42
|
+
isDirty: () => boolean;
|
|
43
|
+
onChange: (content: TemplateContent) => void;
|
|
44
|
+
debounce?: number;
|
|
45
|
+
enabled?: boolean | (() => boolean);
|
|
46
|
+
}
|
|
47
|
+
interface UseAutoSaveReturn {
|
|
48
|
+
flush: () => void;
|
|
49
|
+
cancel: () => void;
|
|
50
|
+
pause: () => void;
|
|
51
|
+
resume: () => void;
|
|
52
|
+
destroy: () => void;
|
|
53
|
+
}
|
|
54
|
+
declare function useAutoSave(options: UseAutoSaveOptions): UseAutoSaveReturn;
|
|
55
|
+
|
|
56
|
+
interface UseConditionPreviewReturn {
|
|
57
|
+
isHidden: (blockId: string) => boolean;
|
|
58
|
+
toggleBlock: (blockId: string) => void;
|
|
59
|
+
reset: () => void;
|
|
60
|
+
hasHiddenBlocks: ComputedRef<boolean>;
|
|
61
|
+
}
|
|
62
|
+
declare function useConditionPreview(editor: UseEditorReturn): UseConditionPreviewReturn;
|
|
63
|
+
|
|
64
|
+
declare function useDataSourceFetch(options: {
|
|
65
|
+
definition: ComputedRef<CustomBlockDefinition | undefined>;
|
|
66
|
+
block: ComputedRef<CustomBlock>;
|
|
67
|
+
onUpdate: (fieldValues: Record<string, unknown>, fetched: boolean) => void;
|
|
68
|
+
}): {
|
|
69
|
+
isFetching: Ref<boolean>;
|
|
70
|
+
fetchError: Ref<boolean>;
|
|
71
|
+
fetch: () => Promise<void>;
|
|
72
|
+
hasDataSource: ComputedRef<boolean>;
|
|
73
|
+
needsFetch: ComputedRef<boolean>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Wraps editor mutation methods to record history snapshots before each
|
|
78
|
+
* operation. Mutates the editor object in place.
|
|
79
|
+
*
|
|
80
|
+
* Must be applied **after** any collaboration broadcast wrapping so the
|
|
81
|
+
* call chain is: history.record() → broadcast → original mutation.
|
|
82
|
+
*/
|
|
83
|
+
declare function useHistoryInterceptor(editor: UseEditorReturn, history: UseHistoryReturn): void;
|
|
84
|
+
|
|
85
|
+
export { type UseAutoSaveOptions, type UseAutoSaveReturn, type UseBlockActionsOptions, type UseBlockActionsReturn, type UseConditionPreviewReturn, UseEditorReturn, type UseHistoryOptions, type UseHistoryReturn, useAutoSave, useBlockActions, useConditionPreview, useDataSourceFetch, useHistory, useHistoryInterceptor };
|