@grapesjs/studio-sdk-plugins 1.0.33-rc.1 → 1.0.33

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.
Files changed (130) hide show
  1. package/dist/accordionComponent/index.cjs.js +7 -7
  2. package/dist/accordionComponent/index.es.js +161 -156
  3. package/dist/accordionComponent/index.umd.js +9 -9
  4. package/dist/aiChat/chatManager.d.ts +15 -0
  5. package/dist/aiChat/clientTools.d.ts +3 -3
  6. package/dist/aiChat/clientToolsProcessors.d.ts +14 -1
  7. package/dist/aiChat/components/AiChatEmptyState.d.ts +4 -6
  8. package/dist/aiChat/components/AiChatError.d.ts +2 -1
  9. package/dist/aiChat/components/AiChatHeader.d.ts +2 -1
  10. package/dist/aiChat/components/AiChatInput/AssetsSection.d.ts +7 -0
  11. package/dist/aiChat/components/AiChatInput/AttachButton.d.ts +10 -0
  12. package/dist/aiChat/components/AiChatInput/ContextSection.d.ts +5 -0
  13. package/dist/aiChat/components/AiChatInput/DictateButton.d.ts +7 -0
  14. package/dist/aiChat/components/AiChatInput/TextAreaWithAutoResize.d.ts +6 -0
  15. package/dist/aiChat/components/AiChatInput/constants.d.ts +6 -0
  16. package/dist/aiChat/components/AiChatInput/hooks/useSpeechToText.d.ts +15 -0
  17. package/dist/aiChat/components/AiChatInput/index.d.ts +37 -0
  18. package/dist/aiChat/components/AiChatLoadingState.d.ts +2 -1
  19. package/dist/aiChat/components/AiChatMessage.d.ts +21 -9
  20. package/dist/aiChat/components/AiChatMessages.d.ts +5 -7
  21. package/dist/aiChat/components/AiChatMessagesStatus.d.ts +5 -0
  22. package/dist/aiChat/components/AiChatPanel.d.ts +2 -3
  23. package/dist/aiChat/components/AiChatProvider.d.ts +14 -0
  24. package/dist/aiChat/components/MemoizedMarkdown.d.ts +9 -0
  25. package/dist/aiChat/components/index.d.ts +24 -25
  26. package/dist/aiChat/components/utils.d.ts +12 -4
  27. package/dist/aiChat/index.cjs.d.ts +5 -0
  28. package/dist/aiChat/index.cjs.js +453 -0
  29. package/dist/aiChat/index.d.ts +4 -3
  30. package/dist/aiChat/index.es.d.ts +5 -0
  31. package/dist/aiChat/index.es.js +30930 -0
  32. package/dist/aiChat/index.js +453 -0
  33. package/dist/aiChat/index.umd.js +453 -0
  34. package/dist/aiChat/locales/en.d.ts +64 -0
  35. package/dist/aiChat/server/index.cjs.d.ts +4 -0
  36. package/dist/aiChat/server/index.cjs.js +309 -0
  37. package/dist/aiChat/server/index.d.ts +0 -50
  38. package/dist/aiChat/server/index.es.d.ts +4 -0
  39. package/dist/aiChat/server/index.es.js +876 -0
  40. package/dist/aiChat/server/index.js +309 -0
  41. package/dist/aiChat/server/index.umd.js +309 -0
  42. package/dist/aiChat/server/stream.d.ts +0 -6
  43. package/dist/aiChat/server/tools.d.ts +157 -51
  44. package/dist/aiChat/server/types.d.ts +108 -64
  45. package/dist/aiChat/types.d.ts +148 -108
  46. package/dist/aiChat/typesSchema.d.ts +238 -25
  47. package/dist/animationComponent/index.cjs.js +3 -3
  48. package/dist/animationComponent/index.es.js +174 -169
  49. package/dist/animationComponent/index.umd.js +3 -3
  50. package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
  51. package/dist/canvasAbsoluteMode/index.es.js +161 -156
  52. package/dist/canvasAbsoluteMode/index.umd.js +1 -1
  53. package/dist/canvasEmptyState/index.cjs.js +1 -1
  54. package/dist/canvasEmptyState/index.es.js +113 -108
  55. package/dist/canvasEmptyState/index.umd.js +1 -1
  56. package/dist/canvasFullSize/index.cjs.js +9 -9
  57. package/dist/canvasFullSize/index.es.js +137 -132
  58. package/dist/canvasFullSize/index.umd.js +9 -9
  59. package/dist/canvasGridMode/index.cjs.js +4 -4
  60. package/dist/canvasGridMode/index.es.js +168 -163
  61. package/dist/canvasGridMode/index.umd.js +8 -8
  62. package/dist/canvasScreenshot/index.cjs.js +1 -1
  63. package/dist/canvasScreenshot/index.es.js +132 -127
  64. package/dist/canvasScreenshot/index.umd.js +1 -1
  65. package/dist/dataSourceEjs/index.cjs.js +5 -5
  66. package/dist/dataSourceEjs/index.es.js +151 -146
  67. package/dist/dataSourceEjs/index.umd.js +5 -5
  68. package/dist/dataSourceHandlebars/index.cjs.js +4 -4
  69. package/dist/dataSourceHandlebars/index.es.js +91 -86
  70. package/dist/dataSourceHandlebars/index.umd.js +5 -5
  71. package/dist/dialogComponent/index.cjs.js +16 -16
  72. package/dist/dialogComponent/index.es.js +117 -112
  73. package/dist/dialogComponent/index.umd.js +16 -16
  74. package/dist/flexComponent/index.cjs.js +11 -11
  75. package/dist/flexComponent/index.es.js +416 -411
  76. package/dist/flexComponent/index.umd.js +11 -11
  77. package/dist/fsLightboxComponent/index.cjs.js +3 -3
  78. package/dist/fsLightboxComponent/index.es.js +152 -147
  79. package/dist/fsLightboxComponent/index.umd.js +3 -3
  80. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  81. package/dist/googleFontsAssetProvider/index.es.js +127 -122
  82. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  83. package/dist/iconifyComponent/index.cjs.js +2 -2
  84. package/dist/iconifyComponent/index.es.js +170 -165
  85. package/dist/iconifyComponent/index.umd.js +2 -2
  86. package/dist/index.cjs.js +1 -1
  87. package/dist/index.es.js +27 -22
  88. package/dist/index.umd.js +1 -1
  89. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  90. package/dist/layoutSidebarButtons/index.es.js +156 -151
  91. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  92. package/dist/lightGalleryComponent/index.cjs.js +1 -1
  93. package/dist/lightGalleryComponent/index.es.js +197 -192
  94. package/dist/lightGalleryComponent/index.umd.js +1 -1
  95. package/dist/linkImageComponent/index.cjs.js +2 -2
  96. package/dist/linkImageComponent/index.es.js +86 -81
  97. package/dist/linkImageComponent/index.umd.js +2 -2
  98. package/dist/listPagesComponent/index.cjs.js +5 -5
  99. package/dist/listPagesComponent/index.es.js +121 -116
  100. package/dist/listPagesComponent/index.umd.js +5 -5
  101. package/dist/presetPrintable/index.cjs.js +4 -4
  102. package/dist/presetPrintable/index.es.js +180 -175
  103. package/dist/presetPrintable/index.umd.js +4 -4
  104. package/dist/prosemirror/index.cjs.js +6 -6
  105. package/dist/prosemirror/index.es.js +128 -123
  106. package/dist/prosemirror/index.umd.js +8 -8
  107. package/dist/rendererReact/index.cjs.js +1 -1
  108. package/dist/rendererReact/index.es.js +127 -122
  109. package/dist/rendererReact/index.js +1 -1
  110. package/dist/rendererReact/index.umd.js +1 -1
  111. package/dist/rteTinyMce/index.cjs.js +2 -2
  112. package/dist/rteTinyMce/index.es.js +160 -155
  113. package/dist/rteTinyMce/index.umd.js +2 -2
  114. package/dist/shapeDividerComponent/index.cjs.js +25 -25
  115. package/dist/shapeDividerComponent/index.es.js +127 -122
  116. package/dist/shapeDividerComponent/index.umd.js +25 -25
  117. package/dist/swiperComponent/index.cjs.js +9 -9
  118. package/dist/swiperComponent/index.es.js +197 -192
  119. package/dist/swiperComponent/index.umd.js +9 -9
  120. package/dist/tableComponent/index.cjs.js +1 -1
  121. package/dist/tableComponent/index.es.js +227 -222
  122. package/dist/tableComponent/index.umd.js +1 -1
  123. package/dist/types.d.ts +1 -1
  124. package/dist/utils.d.ts +12 -1
  125. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  126. package/dist/youtubeAssetProvider/index.es.js +124 -119
  127. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  128. package/package.json +5 -2
  129. package/dist/aiChat/components/AiChatInput.d.ts +0 -17
  130. package/dist/aiChat/server/stream-utils.d.ts +0 -16
@@ -1,8 +1,22 @@
1
1
  import { LanguageModelV3 } from '@ai-sdk/provider';
2
- import { ModelMessage, Tool, UIMessage, UIMessageStreamOptions, UIMessageStreamWriter, streamText } from 'ai';
3
- import { JSONSchema7 } from 'json-schema';
2
+ import { FinishReason, LanguageModelUsage, Tool, UIMessage, UIMessageStreamOptions, UIMessageStreamWriter, streamText } from 'ai';
4
3
  import { ProjectContext } from '../types';
5
4
  export type StreamTextOptions = Parameters<typeof streamText>[0];
5
+ /**
6
+ * Callback invoked when a streamText call finishes, useful for tracking LLM usage.
7
+ */
8
+ export interface OnEndCallback {
9
+ (props: {
10
+ /** Token usage for this call. */
11
+ usage: LanguageModelUsage;
12
+ /** Reason the model stopped generating. */
13
+ finishReason: FinishReason;
14
+ /** Model used for this call. */
15
+ model: LanguageModelV3;
16
+ /** The agent code tool name, when the call originates from a built-in agent tool. */
17
+ toolName?: string;
18
+ }): void;
19
+ }
6
20
  /**
7
21
  * Options for configuring an agent that generates code (e.g., add/edit components).
8
22
  */
@@ -12,9 +26,43 @@ export interface AgentCodeOptions {
12
26
  */
13
27
  model: LanguageModelV3;
14
28
  /**
15
- * Project context containing information about the current project
29
+ * Additional stream text options passed to the agent's internal streamText calls
16
30
  */
17
- projectContext: ProjectContext;
31
+ streamOptions?: Partial<Omit<StreamTextOptions, 'model' | 'system' | 'prompt' | 'abortSignal' | 'toolChoice' | 'messages' | 'tools' | 'onToolCall'>>;
32
+ }
33
+ /**
34
+ * Return type of createToolStatusWriter function
35
+ */
36
+ export interface ToolStatusWriter {
37
+ /** Write in-progress status when tool starts */
38
+ start(): void;
39
+ /** Write streaming status with content chunk */
40
+ update(content: string, props?: {
41
+ replace?: boolean;
42
+ }): void;
43
+ /** Write done status */
44
+ done(): void;
45
+ /** Write complete status (persisted) with metadata */
46
+ complete(metadata: Record<string, unknown>): void;
47
+ /** Write error status */
48
+ error(err: unknown): void;
49
+ }
50
+ /**
51
+ * Options for creating a tool status writer
52
+ */
53
+ export interface CreateToolStatusWriterOptions {
54
+ writer: UIMessageStreamWriter;
55
+ /** The tool call ID from ToolExecutionOptions */
56
+ toolCallId: string;
57
+ /** The name of the tool */
58
+ name: string;
59
+ /** The input passed to the tool */
60
+ input: unknown;
61
+ }
62
+ /**
63
+ * Options for creating a tool status writer
64
+ */
65
+ export interface CreateToolStatusWriterOptionsFactory extends Omit<CreateToolStatusWriterOptions, 'writer'> {
18
66
  }
19
67
  /**
20
68
  * Options passed to the tools callback function
@@ -32,6 +80,37 @@ export interface ToolsCallbackOptions {
32
80
  * Abort signal passed from the request, useful for cancelling long-running tool operations
33
81
  */
34
82
  abortSignal?: AbortSignal;
83
+ /**
84
+ * Create a tool status writer for sending progress updates.
85
+ * Use this in custom tool execute functions to report status.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * execute: async (input, { toolCallId }) => {
90
+ * const statusWriter = createToolStatusWriter({ toolCallId, name: 'myTool', input });
91
+ * statusWriter.writeStart();
92
+ * try {
93
+ * // ... do work ...
94
+ * statusWriter.writeDone();
95
+ * return result;
96
+ * } catch (err) {
97
+ * statusWriter.writeError(err);
98
+ * throw err;
99
+ * }
100
+ * }
101
+ * ```
102
+ */
103
+ createToolStatusWriter: (options: CreateToolStatusWriterOptionsFactory) => ToolStatusWriter;
104
+ }
105
+ export interface ChatSystemPrompt {
106
+ /**
107
+ * Initial part of the system prompt that sets the overall context and instructions for the AI assistant.
108
+ */
109
+ preamble?: string;
110
+ /**
111
+ * Additional instructions or information that can be appended to the system prompt.
112
+ */
113
+ postamble?: string;
35
114
  }
36
115
  /**
37
116
  * Options for creating a streaming response
@@ -42,13 +121,17 @@ export interface CreateStreamResponseOptions extends Pick<StreamTextOptions, 'to
42
121
  */
43
122
  model: LanguageModelV3;
44
123
  /**
45
- * Messages from the conversation
124
+ * Messages from the UI conversation
46
125
  */
47
126
  messages: UIMessage[];
127
+ /**
128
+ * Project context containing information about the current project
129
+ */
130
+ projectContext: ProjectContext;
48
131
  /**
49
132
  * System prompt for the chat
50
133
  */
51
- systemPrompt?: string;
134
+ systemPrompt?: string | ChatSystemPrompt;
52
135
  /**
53
136
  * Abort signal for cancelling the stream and tool operations
54
137
  */
@@ -65,11 +148,6 @@ export interface CreateStreamResponseOptions extends Pick<StreamTextOptions, 'to
65
148
  * @see https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data
66
149
  */
67
150
  tools?: Record<string, Tool> | ((options: ToolsCallbackOptions) => Record<string, Tool>);
68
- /**
69
- * Image URLs to add to the last user message
70
- * These will be formatted as image content parts for vision models
71
- */
72
- imageUrls?: string[];
73
151
  /**
74
152
  * Additional stream text options
75
153
  */
@@ -78,6 +156,25 @@ export interface CreateStreamResponseOptions extends Pick<StreamTextOptions, 'to
78
156
  * Additional response options
79
157
  */
80
158
  responseOptions?: Partial<UIMessageStreamOptions<UIMessage>>;
159
+ /**
160
+ * Whether to prune messages before sending to the model.
161
+ * When true (default), removes reasoning/tool calls from older messages to reduce token usage.
162
+ * @default true
163
+ * @see https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages
164
+ */
165
+ pruneMessages?: boolean;
166
+ /**
167
+ * Callback invoked when a stream call finishes (including built-in agent code tools).
168
+ * Useful for tracking LLM model usage.
169
+ */
170
+ onEnd?: OnEndCallback;
171
+ /**
172
+ * Extract metadata to attach to each message.
173
+ * Called on `start` and `finish` stream events.
174
+ */
175
+ getMessageMetadata?: (options: Parameters<NonNullable<UIMessageStreamOptions<UIMessage>['messageMetadata']>>[0] & {
176
+ model: LanguageModelV3;
177
+ }) => ReturnType<NonNullable<UIMessageStreamOptions<UIMessage>['messageMetadata']>>;
81
178
  }
82
179
  /**
83
180
  * Options for creating a text streaming response (using toTextStreamResponse)
@@ -105,61 +202,8 @@ export interface CreateStreamTextResponseOptions extends Pick<StreamTextOptions,
105
202
  */
106
203
  streamOptions?: Partial<Omit<StreamTextOptions, 'toolChoice' | 'providerOptions' | 'model' | 'system' | 'prompt' | 'messages' | 'tools' | 'abortSignal' | 'onFinish' | 'onAbort' | 'onError'>>;
107
204
  }
108
- export interface StreamFinishResult {
109
- text: string;
110
- usage: {
111
- promptTokens: number;
112
- completionTokens: number;
113
- totalTokens: number;
114
- };
115
- model: string;
116
- /**
117
- * Uses AI SDK's official type to ensure compatibility
118
- * Extracted from streamText's onFinish callback parameter type
119
- */
120
- finishReason: Parameters<NonNullable<Parameters<typeof streamText>[0]['onFinish']>>[0]['finishReason'];
121
- toolCalls?: ToolCallInfo[];
122
- }
123
- export interface ToolCallInfo {
124
- toolCallId: string;
125
- toolName: string;
126
- args: Record<string, unknown>;
127
- }
128
205
  export interface CreateModelOptions {
129
206
  apiKey?: string;
130
207
  baseURL?: string;
131
208
  [key: string]: unknown;
132
209
  }
133
- export interface ToolDefinition<TArgs = Record<string, unknown>, TResult = unknown> {
134
- description: string;
135
- /**
136
- * JSON schema for the tool's input parameters (ai-sdk v6)
137
- */
138
- inputSchema: JSONSchema7;
139
- execute?: (args: TArgs, context: ToolExecuteContext) => Promise<TResult>;
140
- }
141
- export interface ToolExecuteContext {
142
- toolCallId: string;
143
- messages: ModelMessage[];
144
- abortSignal?: AbortSignal;
145
- }
146
- /**
147
- * Options for creating the chat system prompt
148
- */
149
- export interface CreateSystemPromptChatOptions {
150
- /**
151
- * Project context from the client
152
- */
153
- projectContext?: ProjectContext;
154
- }
155
- export interface PromptConfig {
156
- currentSiteCode?: string;
157
- currentSelectedCode?: string;
158
- userPrompt?: string;
159
- projectType?: 'web' | 'email';
160
- globalStyles?: string;
161
- devices?: ProjectContext['devices'];
162
- availablePages?: ProjectContext['availablePages'];
163
- installedPlugins?: ProjectContext['installedPlugins'];
164
- imageUrls?: string[];
165
- }
@@ -1,13 +1,13 @@
1
- import { UIMessage, useChat, UseChatHelpers } from '@ai-sdk/react';
2
- import { ChatInit, HttpChatTransportInitOptions } from 'ai';
3
- import { Editor } from 'grapesjs';
4
- import { ReactNode, CSSProperties } from 'react';
5
- import { PluginWithInit, SDKPluginOptions } from '../utils';
6
- import { AiChatHeaderProps } from './components/AiChatHeader';
7
- import { AiChatInputProps } from './components/AiChatInput';
1
+ import { Chat, UIMessage, useChat, UseChatHelpers } from '@ai-sdk/react';
2
+ import { ChatInit, DynamicToolUIPart, HttpChatTransportInitOptions, ToolUIPart } from 'ai';
3
+ import { Component, Editor } from 'grapesjs';
4
+ import { LicenseCheckResult } from '../utils';
5
+ import { StudioLayoutComponentsConfig } from '../types';
6
+ import { AiChatLayoutComponentsRegistryEntries } from './components/index';
7
+ import { ToolStatusProgressMap } from './clientToolsProcessors';
8
+ import { AiChatOptions as AiChatOptionsSchema, CommonComponentPropsSchema } from './typesSchema';
8
9
  /**
9
10
  * ChatMessage is a direct alias of AI SDK's UIMessage
10
- * This keeps us aligned with AI SDK types - we only extend when necessary
11
11
  */
12
12
  export type ChatMessage = UIMessage;
13
13
  /**
@@ -38,6 +38,11 @@ export declare enum AvailablePanels {
38
38
  IMPORT_HTML = "importHTML",
39
39
  PREVIEW = "preview"
40
40
  }
41
+ export declare enum AiChatCommands {
42
+ getChatManager = "aiChat:getChatManager",
43
+ getChatState = "aiChat:getChatState",
44
+ getChatApi = "aiChat:getChatApi"
45
+ }
41
46
  export interface AiChatToolsArguments {
42
47
  [AiChatToolName.ADD_NEW_COMPONENT]: {
43
48
  name: string;
@@ -90,12 +95,19 @@ export interface ProjectContext {
90
95
  content?: string;
91
96
  };
92
97
  /**
93
- * Selected component information
98
+ * Last selected component information
94
99
  */
95
100
  selectedComponent?: {
96
101
  id: string;
97
102
  content: string;
98
103
  };
104
+ /**
105
+ * Selected components
106
+ */
107
+ selectedComponents: {
108
+ id: string;
109
+ content: string;
110
+ }[];
99
111
  /**
100
112
  * Project type (web, email, etc.)
101
113
  */
@@ -133,9 +145,9 @@ export interface ProjectContext {
133
145
  */
134
146
  isEmail: boolean;
135
147
  /**
136
- * Is this a new project (no existing content).
148
+ * Indicates if the project is empty.
137
149
  */
138
- isNewProject?: boolean;
150
+ isNewProject: boolean;
139
151
  /**
140
152
  * Image URLs associated with the project
141
153
  */
@@ -149,17 +161,34 @@ export interface ChatRequestBody {
149
161
  userPrompt: string;
150
162
  [key: string]: unknown;
151
163
  }
152
- export interface ChatContext extends Pick<UseChatHelpers<UIMessage>, 'id' | 'setMessages' | 'messages' | 'sendMessage' | 'status' | 'stop' | 'addToolApprovalResponse' | 'addToolOutput' | 'clearError' | 'error'> {
164
+ export interface ChatContext extends Pick<UseChatHelpers<UIMessage>, 'id' | 'setMessages' | 'messages' | 'sendMessage' | 'status' | 'stop' | 'addToolApprovalResponse' | 'addToolOutput' | 'clearError' | 'error'>, Pick<ChatState, 'toolStatusProgress' | 'contextComponents'> {
153
165
  setError: (error: Error | string | undefined) => void;
154
166
  }
167
+ export interface AiChatMessageLayoutProps {
168
+ editor: Editor;
169
+ chatContext: ChatContext;
170
+ message: UIMessage;
171
+ }
172
+ export interface AiChatMessagePartLayoutProps extends AiChatMessageLayoutProps {
173
+ part: ChatMessage['parts'][0];
174
+ partIndex: number;
175
+ }
176
+ export interface AiChatMessageToolDetailLayoutProps extends AiChatMessagePartLayoutProps {
177
+ part: ToolUIPart | DynamicToolUIPart;
178
+ toolName: string;
179
+ }
155
180
  /**
156
181
  * Client-side tool definition
157
182
  */
158
- export interface AiChatClientTool<Args extends Record<string, unknown> = any> {
183
+ export interface AiChatClientTool<TInput extends Record<string, unknown> = any> {
159
184
  /**
160
185
  * Execute the tool on the client side
161
186
  */
162
- execute: (args: Args, context: AiChatToolContext) => Promise<string | Record<string, unknown>>;
187
+ execute?: (input: TInput, context: AiChatToolContext) => Promise<string | Record<string, unknown>>;
188
+ /**
189
+ * Custom layout for tool in the message.
190
+ */
191
+ layoutToolResult?: (props: AiChatMessageToolDetailLayoutProps) => StudioLayoutComponentsConfig | undefined | void;
163
192
  }
164
193
  /**
165
194
  * Context passed to client-side tools
@@ -187,82 +216,77 @@ export type AiChatToolsFn = (props: {
187
216
  editor: Editor;
188
217
  }) => AiChatTools;
189
218
  /**
190
- * API endpoints for built-in tools that make sub-calls
219
+ * Props for custom message component
191
220
  */
192
- export interface AiChatToolApis {
193
- /**
194
- * Endpoint for adding new components
195
- * @default '/api/ai/add-component-stream'
196
- */
197
- addComponent?: string;
198
- /**
199
- * Endpoint for editing components
200
- * @default '/api/ai/edit-component-stream'
201
- */
202
- editComponent?: string;
221
+ export interface AiChatMessageProps {
222
+ editor: Editor;
223
+ message: UIMessage;
224
+ isStreaming?: boolean;
225
+ }
226
+ export interface AiChatSuggestion {
203
227
  /**
204
- * Endpoint for adding new pages
205
- * @default '/api/ai/add-page-stream'
228
+ * Unique identifier for the suggestion. Used as i18n key suffix.
206
229
  */
207
- addPage?: string;
230
+ id: string;
208
231
  /**
209
- * Endpoint for generating projects
210
- * @default '/api/ai/generate-project-stream'
232
+ * Label to display if i18n key is not found.
211
233
  */
212
- generateProject?: string;
234
+ label?: string;
213
235
  /**
214
- * Endpoint for scraping websites
215
- * @default '/api/ai/scrape-website'
236
+ * Prompt to send when clicked. If not provided, uses the resolved label.
216
237
  */
217
- scrapeWebsite?: string;
238
+ prompt?: string;
218
239
  }
219
240
  /**
220
- * Props for custom message component
241
+ * Props for custom empty state component
221
242
  */
222
- export interface AiChatMessageProps {
243
+ export interface AiChatEmptyStateProps {
223
244
  editor: Editor;
224
- message: ChatMessage;
225
- isStreaming?: boolean;
245
+ onSuggestionClick?: (suggestion: string) => void;
226
246
  }
227
247
  /**
228
- * Props for custom empty state component
248
+ * Context passed to layout component customizers
229
249
  */
230
- export interface AiChatEmptyStateProps {
250
+ export interface LayoutComponentContext<T> {
231
251
  editor: Editor;
232
- onSuggestionClick?: (suggestion: string) => void;
252
+ props: Omit<T, 'chatContext' | 'type'>;
233
253
  }
254
+ type CustomLayoutComponentPropsFn<T> = (props: LayoutComponentContext<T>) => Partial<Omit<T, 'chatContext' | 'type'>>;
234
255
  /**
235
256
  * Customizable layout components
257
+ * @example
258
+ * layoutComponents: {
259
+ * aiChatInput: ({ editor, props }) => ({
260
+ * ...props,
261
+ * maxImages: 3,
262
+ * })
263
+ * }
236
264
  */
237
265
  export interface AiChatLayoutComponents {
238
266
  /**
239
- * Custom message component
267
+ * Custom aiChatInput component props
240
268
  */
241
- chatMessage?: (props: AiChatMessageProps) => {
242
- type: 'custom';
243
- component: () => ReactNode;
244
- };
269
+ aiChatInput?: CustomLayoutComponentPropsFn<AiChatLayoutComponentsRegistryEntries['aiChatInput']>;
245
270
  /**
246
- * Custom input component
271
+ * Custom aiChatMessage component props
247
272
  */
248
- chatInput?: (props: AiChatInputProps) => {
249
- type: 'custom';
250
- component: () => ReactNode;
251
- };
273
+ aiChatMessage?: CustomLayoutComponentPropsFn<AiChatLayoutComponentsRegistryEntries['aiChatMessage']>;
252
274
  /**
253
- * Custom header component
275
+ * Custom aiChatLoadingState component props
254
276
  */
255
- chatHeader?: (props: AiChatHeaderProps) => {
256
- type: 'custom';
257
- component: () => ReactNode;
258
- };
277
+ aiChatLoadingState?: CustomLayoutComponentPropsFn<AiChatLayoutComponentsRegistryEntries['aiChatLoadingState']>;
259
278
  /**
260
- * Custom empty state component
279
+ * Custom aiChatHeader component props
261
280
  */
262
- chatEmptyState?: (props: AiChatEmptyStateProps) => {
263
- type: 'custom';
264
- component: () => ReactNode;
265
- };
281
+ aiChatHeader?: CustomLayoutComponentPropsFn<AiChatLayoutComponentsRegistryEntries['aiChatHeader']>;
282
+ /**
283
+ * Custom aiChatError component props
284
+ */
285
+ aiChatError?: CustomLayoutComponentPropsFn<AiChatLayoutComponentsRegistryEntries['aiChatError']>;
286
+ /**
287
+ * Custom aiChatEmptyState component props
288
+ */
289
+ aiChatEmptyState?: CustomLayoutComponentPropsFn<AiChatLayoutComponentsRegistryEntries['aiChatEmptyState']>;
266
290
  }
267
291
  export type ChatOptions = Partial<Omit<Parameters<typeof useChat>[0], 'api' | 'transport'>>;
268
292
  /**
@@ -276,19 +300,16 @@ export interface UploadedAsset {
276
300
  size: number;
277
301
  type?: string;
278
302
  }
279
- export interface CommonComponentProps {
303
+ export interface CommonComponentProps extends CommonComponentPropsSchema {
280
304
  editor: Editor;
281
305
  chatContext: ChatContext;
282
- className?: string;
283
- style?: CSSProperties;
284
306
  }
285
307
  /**
286
308
  * AI Chat plugin options
287
309
  */
288
- export interface AiChatOptions extends SDKPluginOptions {
310
+ export interface AiChatOptions extends Omit<AiChatOptionsSchema, 'getAccessToken' | 'chatOptions' | 'chatApi' | 'tools' | 'onTool' | 'layoutComponents' | 'messages' | 'onMessagesUpdate' | 'body'> {
289
311
  /**
290
312
  * Custom endpoint for the chat API
291
- * @default '/api/ai/chat'
292
313
  */
293
314
  chatApi?: string | (() => string);
294
315
  /**
@@ -310,36 +331,34 @@ export interface AiChatOptions extends SDKPluginOptions {
310
331
  */
311
332
  onTool?: ChatInit<UIMessage>['onToolCall'];
312
333
  /**
313
- * Customize API endpoints for built-in tools
314
- */
315
- toolApis?: AiChatToolApis;
316
- /**
317
- * Customize layout components
334
+ * Customize UI layout component props
335
+ * layoutComponents: {
336
+ * aiChatInput: () => ({
337
+ * maxImages: 3,
338
+ * }),
339
+ * }
318
340
  */
319
341
  layoutComponents?: AiChatLayoutComponents;
320
342
  /**
321
343
  * Initial messages or async function to load messages
322
344
  * @example
323
- * // Static messages
324
- * messages: [{ id: '1', role: 'user', content: 'Hello' }]
325
345
  * // Dynamic loading
326
- * messages: async ({ editor }) => {
327
- * const msgs = await loadFromDatabase();
328
- * return msgs;
346
+ * messages: async () => {
347
+ * return await loadFromDatabase();
329
348
  * }
330
349
  */
331
- messages?: ChatMessage[] | ((props: {
350
+ messages?: UIMessage[] | ((props: {
332
351
  editor: Editor;
333
- }) => Promise<ChatMessage[]>);
352
+ }) => Promise<UIMessage[]>);
334
353
  /**
335
354
  * Callback when messages are updated (for persistence)
336
355
  * @example
337
- * onMessagesUpdate: async ({ messages, editor }) => {
356
+ * onMessagesUpdate: async ({ messages }) => {
338
357
  * await saveToDatabase(messages);
339
358
  * }
340
359
  */
341
360
  onMessagesUpdate?: (props: {
342
- messages: ChatMessage[];
361
+ messages: UIMessage[];
343
362
  editor: Editor;
344
363
  }) => void | Promise<void>;
345
364
  /**
@@ -351,36 +370,40 @@ export interface AiChatOptions extends SDKPluginOptions {
351
370
  messages: UIMessage[];
352
371
  }) => Record<string, unknown>);
353
372
  /**
354
- * Custom suggestions to show
355
- */
356
- suggestions?: string[];
357
- /**
358
- * Maximum number of images per message. Set to 0 to disable images.
359
- * @default 5
360
- */
361
- maxImages?: number;
362
- /**
363
- * Upload project assets (images) to server
364
- * Consumer must implement this function to handle file uploads
373
+ * Additional chat options.
374
+ * Refer to https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat
365
375
  * @example
366
- * uploadProjectAssets: async ({ files }) => {
367
- * const uploaded = await uploadToServer(files);
368
- * return uploaded.map(asset => ({ id: asset.id, src: asset.url, ... }));
376
+ * chatOptions: {
377
+ * onData: data => console.log('onData:', data),
378
+ * onError: error => console.log('onError:', error),
379
+ * onFinish: result => console.log('onFinish:', result)
369
380
  * }
370
381
  */
371
- uploadProjectAssets?: (props: {
372
- files: File[];
373
- }) => Promise<UploadedAsset[]>;
374
- /**
375
- * Additional chat options for ai-sdk
376
- * Uses AI SDK's UseChatOptions directly to stay aligned with their interface
377
- * @see https://ai-sdk.dev/docs/ai-sdk-ui/chatbot
378
- */
379
382
  chatOptions?: Partial<ChatInit<UIMessage>>;
380
383
  /**
381
384
  * Default transport options for chat API calls
382
385
  */
383
386
  defaultTransportOptions?: Partial<Omit<HttpChatTransportInitOptions<UIMessage>, 'prepareSendMessagesRequest'>>;
387
+ /**
388
+ * Function to get the access token
389
+ * @example
390
+ * getAccessToken: async () => {
391
+ * const response = await fetch('/api/access-tokens');
392
+ * const result = await response.json();
393
+ * return result;
394
+ * }
395
+ */
396
+ getAccessToken?: () => Promise<AccessTokenData>;
397
+ }
398
+ export interface AccessTokenData {
399
+ accessToken: string;
400
+ expiresAt?: string;
401
+ }
402
+ export interface AccessTokenStore {
403
+ accessToken: string;
404
+ timeout?: NodeJS.Timeout;
405
+ license?: LicenseCheckResult;
406
+ getAccessToken?: () => Promise<AccessTokenData>;
384
407
  }
385
408
  export interface ToolDataAddComponentCommon {
386
409
  name: typeof ChatToolAgentCode.ADD_COMPONENT_CODE;
@@ -463,8 +486,25 @@ export interface ToolDataAddProjectPage {
463
486
  data: ToolDataAddProjectPageStreaming | ToolDataAddProjectPageDone | ToolDataAddProjectPageError;
464
487
  }
465
488
  export type ToolDataTypes = ToolDataAddComponent | ToolDataEditComponent | ToolDataAddPage | ToolDataAddProjectPage;
466
- /**
467
- * Plugin with init method
468
- */
469
- export interface SDKPluginWithAiChat extends PluginWithInit<AiChatOptions> {
470
- }
489
+ export interface ChatApi {
490
+ readonly messages: UIMessage[];
491
+ readonly lastMessage: UIMessage | undefined;
492
+ readonly status: Chat<UIMessage>['status'];
493
+ readonly error: Error | undefined;
494
+ sendMessage: Chat<UIMessage>['sendMessage'];
495
+ setMessages: (messages: UIMessage[]) => void;
496
+ clearError: () => void;
497
+ stop: () => Promise<void>;
498
+ setError: (error: Error | string) => void;
499
+ }
500
+ export interface ChatState {
501
+ chat: Chat<UIMessage>;
502
+ chatApi: ChatApi;
503
+ isMessagesLoaded: boolean;
504
+ toolStatusProgress: ToolStatusProgressMap;
505
+ toolAbortControllers: Set<AbortController>;
506
+ contextComponents: Set<Component>;
507
+ onUpdate: (listener: () => void) => () => void;
508
+ emitUpdate: () => void;
509
+ }
510
+ export {};