@growgroup/visual-editor 0.1.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.
Files changed (219) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +52 -0
  3. package/README.md +143 -0
  4. package/dist/editor.css +2 -0
  5. package/package.json +94 -0
  6. package/src/components/DeckSlideRender.tsx +21 -0
  7. package/src/components/SaveNote.tsx +21 -0
  8. package/src/components/auth/AuthProvider.tsx +44 -0
  9. package/src/components/ui/accordion.tsx +57 -0
  10. package/src/components/ui/alert-dialog.tsx +141 -0
  11. package/src/components/ui/badge.tsx +36 -0
  12. package/src/components/ui/button.tsx +56 -0
  13. package/src/components/ui/card.tsx +76 -0
  14. package/src/components/ui/checkbox.tsx +30 -0
  15. package/src/components/ui/collapsible.tsx +11 -0
  16. package/src/components/ui/context-menu.tsx +200 -0
  17. package/src/components/ui/dialog.tsx +122 -0
  18. package/src/components/ui/dropdown-menu.tsx +201 -0
  19. package/src/components/ui/input.tsx +22 -0
  20. package/src/components/ui/label.tsx +26 -0
  21. package/src/components/ui/popover.tsx +33 -0
  22. package/src/components/ui/scroll-area.tsx +48 -0
  23. package/src/components/ui/scrubbable-label.tsx +95 -0
  24. package/src/components/ui/select.tsx +159 -0
  25. package/src/components/ui/separator.tsx +31 -0
  26. package/src/components/ui/slider.tsx +28 -0
  27. package/src/components/ui/switch.tsx +29 -0
  28. package/src/components/ui/tabs.tsx +55 -0
  29. package/src/components/ui/textarea.tsx +22 -0
  30. package/src/components/ui/tooltip.tsx +32 -0
  31. package/src/components/viewer/useDeck.ts +58 -0
  32. package/src/editor/EditorContext.tsx +632 -0
  33. package/src/editor/EditorToolbar.tsx +446 -0
  34. package/src/editor/FrontendVisualEditor.tsx +2595 -0
  35. package/src/editor/autosave.ts +34 -0
  36. package/src/editor/components/AiPromptPopover.tsx +378 -0
  37. package/src/editor/components/BreakpointGuides.tsx +323 -0
  38. package/src/editor/components/BreakpointSelector.tsx +180 -0
  39. package/src/editor/components/ComponentPropertyEditor.tsx +426 -0
  40. package/src/editor/components/CssEditorDialog.tsx +168 -0
  41. package/src/editor/components/EditorCanvas.tsx +987 -0
  42. package/src/editor/components/EditorContextMenu.tsx +515 -0
  43. package/src/editor/components/EditorFooter.tsx +81 -0
  44. package/src/editor/components/EditorHeader.tsx +524 -0
  45. package/src/editor/components/EditorLayerPanel.tsx +1197 -0
  46. package/src/editor/components/EditorPropertyPanel.tsx +2996 -0
  47. package/src/editor/components/EditorSidebar.tsx +226 -0
  48. package/src/editor/components/FigmaColorPicker.tsx +1577 -0
  49. package/src/editor/components/HtmlEditorDialog.tsx +71 -0
  50. package/src/editor/components/HtmlImportDialog.tsx +346 -0
  51. package/src/editor/components/JsEditorDialog.tsx +175 -0
  52. package/src/editor/components/LayerTreeItem.tsx +494 -0
  53. package/src/editor/components/MasterComponentEditor.tsx +846 -0
  54. package/src/editor/components/MediaLibraryDialog.tsx +447 -0
  55. package/src/editor/components/PageSettingsDialog.tsx +776 -0
  56. package/src/editor/components/VariablePicker.tsx +355 -0
  57. package/src/editor/components/VariablesDialog.tsx +564 -0
  58. package/src/editor/components/VariantEditor.tsx +687 -0
  59. package/src/editor/components/VariantMatrix.tsx +507 -0
  60. package/src/editor/components/component-panel/CategoryAccordion.tsx +139 -0
  61. package/src/editor/components/component-panel/ComponentGrid.tsx +51 -0
  62. package/src/editor/components/component-panel/ComponentItem.tsx +368 -0
  63. package/src/editor/components/component-panel/ComponentPanel.tsx +275 -0
  64. package/src/editor/components/component-panel/ComponentSearch.tsx +82 -0
  65. package/src/editor/components/component-panel/VariantList.tsx +260 -0
  66. package/src/editor/components/component-panel/index.ts +12 -0
  67. package/src/editor/components/index.ts +48 -0
  68. package/src/editor/components/multi-page/CanvasZoomControls.tsx +71 -0
  69. package/src/editor/components/multi-page/InfiniteCanvas.tsx +95 -0
  70. package/src/editor/components/multi-page/MultiPageCanvasView.tsx +1404 -0
  71. package/src/editor/components/multi-page/PageFrameOverlay.tsx +76 -0
  72. package/src/editor/components/multi-page/PageLabel.tsx +34 -0
  73. package/src/editor/components/multi-page/PageLivePreview.tsx +242 -0
  74. package/src/editor/components/multi-page/PageThumbnail.tsx +59 -0
  75. package/src/editor/components/multi-page/index.ts +7 -0
  76. package/src/editor/components/ppt/PptChrome.tsx +2508 -0
  77. package/src/editor/components/ppt/PptComments.tsx +589 -0
  78. package/src/editor/components/ppt/PptDesignProposals.tsx +275 -0
  79. package/src/editor/components/ppt/PptFormatPane.tsx +320 -0
  80. package/src/editor/components/ppt/PptNotes.tsx +246 -0
  81. package/src/editor/components/property-panel/AlignmentPanel.tsx +110 -0
  82. package/src/editor/components/property-panel/AutoLayoutPanel.tsx +615 -0
  83. package/src/editor/components/property-panel/BorderSection.tsx +104 -0
  84. package/src/editor/components/property-panel/CompactNumberInput.tsx +237 -0
  85. package/src/editor/components/property-panel/CompactSizeInput.tsx +148 -0
  86. package/src/editor/components/property-panel/EffectSection.tsx +157 -0
  87. package/src/editor/components/property-panel/FillSection.tsx +69 -0
  88. package/src/editor/components/property-panel/GoogleFontPicker.tsx +192 -0
  89. package/src/editor/components/property-panel/ImageSection.tsx +206 -0
  90. package/src/editor/components/property-panel/ImgSrcSection.tsx +125 -0
  91. package/src/editor/components/property-panel/InstanceOverrideSection.tsx +413 -0
  92. package/src/editor/components/property-panel/LayoutSection.tsx +105 -0
  93. package/src/editor/components/property-panel/LinkSection.tsx +103 -0
  94. package/src/editor/components/property-panel/PropertyVariablePicker.tsx +311 -0
  95. package/src/editor/components/property-panel/ScalePanel.tsx +212 -0
  96. package/src/editor/components/property-panel/TypographySection.tsx +230 -0
  97. package/src/editor/components/property-panel/UnitAwareNumberInput.tsx +238 -0
  98. package/src/editor/components/property-panel/VariableAwareColorInput.tsx +477 -0
  99. package/src/editor/components/property-panel/VariableAwareInput.tsx +606 -0
  100. package/src/editor/components/property-panel/VariableAwareSizeInput.tsx +588 -0
  101. package/src/editor/components/property-panel/VariableAwareUnitInput.tsx +546 -0
  102. package/src/editor/components/property-panel/index.ts +24 -0
  103. package/src/editor/components/property-panel/unit-utils.ts +261 -0
  104. package/src/editor/components/shell/EditorTopBar.tsx +392 -0
  105. package/src/editor/components/shell/LeftPanel.tsx +47 -0
  106. package/src/editor/components/shell/PagesPanel.tsx +118 -0
  107. package/src/editor/components/variables-panel/ColorValueCell.tsx +165 -0
  108. package/src/editor/components/variables-panel/TextValueCell.tsx +116 -0
  109. package/src/editor/components/variables-panel/VariablesPanel.tsx +518 -0
  110. package/src/editor/components/variables-panel/index.ts +7 -0
  111. package/src/editor/constants.ts +468 -0
  112. package/src/editor/contexts/EditorArtboardContext.tsx +229 -0
  113. package/src/editor/contexts/EditorComponentsContext.tsx +1320 -0
  114. package/src/editor/contexts/EditorDocumentContext.tsx +113 -0
  115. package/src/editor/contexts/EditorHistoryContext.tsx +516 -0
  116. package/src/editor/contexts/EditorRefsContext.tsx +204 -0
  117. package/src/editor/contexts/EditorSelectionContext.tsx +54 -0
  118. package/src/editor/contexts/EditorToolContext.tsx +58 -0
  119. package/src/editor/contexts/EditorUIStateContext.tsx +122 -0
  120. package/src/editor/contexts/EditorVariablesContext.tsx +397 -0
  121. package/src/editor/contexts/EditorViewContext.tsx +101 -0
  122. package/src/editor/contexts/MultiPageCanvasContext.tsx +498 -0
  123. package/src/editor/contexts/index.ts +17 -0
  124. package/src/editor/editor-skin.css +122 -0
  125. package/src/editor/hooks/index.ts +38 -0
  126. package/src/editor/hooks/useAiReplace.ts +397 -0
  127. package/src/editor/hooks/useAltMeasure.ts +67 -0
  128. package/src/editor/hooks/useBrowserZoomPrevention.ts +121 -0
  129. package/src/editor/hooks/useCanvasControls.ts +1222 -0
  130. package/src/editor/hooks/useComponentEditMode.ts +658 -0
  131. package/src/editor/hooks/useComponentInstances.ts +515 -0
  132. package/src/editor/hooks/useContextMenuHandler.ts +157 -0
  133. package/src/editor/hooks/useCoordinateTransform.ts +207 -0
  134. package/src/editor/hooks/useDragResize.ts +1317 -0
  135. package/src/editor/hooks/useDrawingMode.ts +472 -0
  136. package/src/editor/hooks/useEditorColors.ts +144 -0
  137. package/src/editor/hooks/useEditorMessages.ts +108 -0
  138. package/src/editor/hooks/useElementActions.ts +1754 -0
  139. package/src/editor/hooks/useElementSelection.ts +1573 -0
  140. package/src/editor/hooks/useFocusManagement.ts +249 -0
  141. package/src/editor/hooks/useGoogleFonts.ts +305 -0
  142. package/src/editor/hooks/useIframeInitializer.ts +584 -0
  143. package/src/editor/hooks/useIframeSetup.ts +360 -0
  144. package/src/editor/hooks/useImageUpload.ts +270 -0
  145. package/src/editor/hooks/useInfiniteCanvas.ts +301 -0
  146. package/src/editor/hooks/useKeyboardShortcuts.ts +205 -0
  147. package/src/editor/hooks/useMarqueeSelection.ts +388 -0
  148. package/src/editor/hooks/useMediaLibrary.ts +129 -0
  149. package/src/editor/hooks/usePageSettingsManager.ts +739 -0
  150. package/src/editor/hooks/useResizablePanel.ts +163 -0
  151. package/src/editor/hooks/useRichPaste.ts +255 -0
  152. package/src/editor/hooks/useTouchGestures.ts +197 -0
  153. package/src/editor/index.ts +27 -0
  154. package/src/editor/types/page-settings.ts +513 -0
  155. package/src/editor/types.ts +382 -0
  156. package/src/editor/utils/align-elements.ts +169 -0
  157. package/src/editor/utils/api-json.ts +21 -0
  158. package/src/editor/utils/aspect-lock.ts +50 -0
  159. package/src/editor/utils/component-renderer.ts +702 -0
  160. package/src/editor/utils/component-sync.ts +845 -0
  161. package/src/editor/utils/crop-mode.ts +265 -0
  162. package/src/editor/utils/dom-utils.ts +2238 -0
  163. package/src/editor/utils/element-effects.ts +218 -0
  164. package/src/editor/utils/eyedropper.ts +35 -0
  165. package/src/editor/utils/figma-export.ts +560 -0
  166. package/src/editor/utils/figma-kiwi-decoder.ts +722 -0
  167. package/src/editor/utils/figma-kiwi-encoder.ts +583 -0
  168. package/src/editor/utils/figma-paste.ts +2262 -0
  169. package/src/editor/utils/flex-reorder.ts +231 -0
  170. package/src/editor/utils/flex-utils.ts +1230 -0
  171. package/src/editor/utils/geometry.ts +232 -0
  172. package/src/editor/utils/grid-layout.ts +210 -0
  173. package/src/editor/utils/html-utils.ts +470 -0
  174. package/src/editor/utils/index.ts +11 -0
  175. package/src/editor/utils/ink-style.ts +57 -0
  176. package/src/editor/utils/inline-format.ts +236 -0
  177. package/src/editor/utils/measure-distance.ts +120 -0
  178. package/src/editor/utils/override-apply.ts +526 -0
  179. package/src/editor/utils/override-detection.ts +613 -0
  180. package/src/editor/utils/paste-processors.ts +609 -0
  181. package/src/editor/utils/paste-sanitizer.ts +244 -0
  182. package/src/editor/utils/restore-flow.ts +188 -0
  183. package/src/editor/utils/shape-library.ts +171 -0
  184. package/src/editor/utils/slide-root.ts +29 -0
  185. package/src/editor/utils/smart-guides.ts +218 -0
  186. package/src/editor/utils/style-utils.ts +685 -0
  187. package/src/editor/utils/table-edit.ts +151 -0
  188. package/src/editor/utils/tailwind-mappings.ts +778 -0
  189. package/src/editor/utils/tailwind-utils.ts +804 -0
  190. package/src/editor/utils/text-highlight.ts +216 -0
  191. package/src/editor/utils/theme-to-variables.ts +341 -0
  192. package/src/editor/utils/variant-resolver.ts +456 -0
  193. package/src/editor/utils/viewport-utils.ts +295 -0
  194. package/src/hooks/useEditorHistory.ts +195 -0
  195. package/src/hooks/useEditorShortcuts.ts +260 -0
  196. package/src/index.ts +40 -0
  197. package/src/io.ts +134 -0
  198. package/src/lib/agent/slide-agent/types.ts +547 -0
  199. package/src/lib/agent/website-agent/types.ts +805 -0
  200. package/src/lib/api/auth-fetch.ts +58 -0
  201. package/src/lib/deck.ts +69 -0
  202. package/src/lib/export.ts +47 -0
  203. package/src/lib/firebase/config.ts +29 -0
  204. package/src/lib/firebase/css-variables.ts +378 -0
  205. package/src/lib/firebase/editor-components.ts +677 -0
  206. package/src/lib/firebase/storage.ts +469 -0
  207. package/src/lib/utils.ts +6 -0
  208. package/src/styles/editor.css +52 -0
  209. package/src/styles/skin.css +122 -0
  210. package/src/types/css-variables.ts +645 -0
  211. package/src/types/editor-components.ts +944 -0
  212. package/src/types/editor.ts +420 -0
  213. package/src/types/page-master.ts +197 -0
  214. package/src/types/page.ts +419 -0
  215. package/src/types/slide.ts +402 -0
  216. package/src/types/website-theme.ts +788 -0
  217. package/src/types/website.ts +374 -0
  218. package/src/vendor/firebase-firestore.ts +13 -0
  219. package/src/vendor/firebase-functions.ts +17 -0
@@ -0,0 +1,805 @@
1
+ /**
2
+ * Website Agent 型定義
3
+ *
4
+ * Interactions API を使用したWebサイト生成エージェントの型定義
5
+ */
6
+
7
+ import type { WebsitePlan, PageGenerationResult, WebPage, PageCategory, SectionCategory } from '../../../types/website';
8
+ import type { PageMaster } from '../../../types/page-master';
9
+
10
+ // =====================
11
+ // Interactions API 型
12
+ // =====================
13
+
14
+ /**
15
+ * ツール定義
16
+ */
17
+ export interface WebsiteAgentTool {
18
+ type: 'function';
19
+ name: string;
20
+ description: string;
21
+ parameters: {
22
+ type: 'object';
23
+ properties: Record<string, ToolParameter>;
24
+ required?: string[];
25
+ };
26
+ }
27
+
28
+ export interface ToolParameter {
29
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object';
30
+ description?: string;
31
+ enum?: string[];
32
+ items?: ToolParameter;
33
+ properties?: Record<string, ToolParameter>;
34
+ required?: string[];
35
+ }
36
+
37
+ /**
38
+ * インタラクションオプション
39
+ */
40
+ export interface InteractionOptions {
41
+ model?: string;
42
+ previousInteractionId?: string;
43
+ stream?: boolean;
44
+ systemInstruction?: string;
45
+ generationConfig?: {
46
+ temperature?: number;
47
+ maxOutputTokens?: number;
48
+ thinkingLevel?: 'minimal' | 'low' | 'medium' | 'high';
49
+ thinkingSummaries?: 'auto' | 'none';
50
+ };
51
+ store?: boolean;
52
+ }
53
+
54
+ /**
55
+ * インタラクション出力
56
+ */
57
+ export type InteractionOutput =
58
+ | TextOutput
59
+ | ThoughtOutput
60
+ | ToolCallOutput
61
+ | ToolResultOutput;
62
+
63
+ export interface TextOutput {
64
+ type: 'text';
65
+ text: string;
66
+ }
67
+
68
+ export interface ThoughtOutput {
69
+ type: 'thought';
70
+ summary?: string;
71
+ signature: string;
72
+ }
73
+
74
+ export interface ToolCallOutput {
75
+ type: 'function_call';
76
+ id: string;
77
+ name: string;
78
+ arguments: Record<string, unknown>;
79
+ }
80
+
81
+ export interface ToolResultOutput {
82
+ type: 'function_result';
83
+ name: string;
84
+ call_id: string;
85
+ result: unknown;
86
+ }
87
+
88
+ /**
89
+ * インタラクション結果
90
+ */
91
+ export interface InteractionResult {
92
+ id: string;
93
+ status: 'completed' | 'in_progress' | 'requires_action' | 'failed' | 'cancelled';
94
+ outputs: InteractionOutput[];
95
+ usage?: {
96
+ input_tokens: number;
97
+ output_tokens: number;
98
+ total_tokens: number;
99
+ };
100
+ }
101
+
102
+ // =====================
103
+ // ツール引数型
104
+ // =====================
105
+
106
+ /**
107
+ * generate_website_plan ツール引数
108
+ */
109
+ export interface GenerateWebsitePlanArgs {
110
+ prompt: string;
111
+ pageCount?: number;
112
+ theme?: 'light' | 'dark' | 'corporate' | 'modern';
113
+ primaryColor?: string;
114
+ attachedFiles?: Array<{
115
+ name: string;
116
+ type: string;
117
+ data: string; // base64
118
+ }>;
119
+ /** figma_get_design で取得したデザインデータ */
120
+ figmaDesignData?: {
121
+ fileKey?: string; // FigmaファイルキーURL再構築用)
122
+ nodeId?: string;
123
+ nodeName?: string;
124
+ structure?: Record<string, unknown>;
125
+ hint?: string;
126
+ image?: {
127
+ base64: string;
128
+ mimeType: string;
129
+ };
130
+ };
131
+ }
132
+
133
+ /**
134
+ * generate_page_html ツール引数
135
+ */
136
+ export interface GeneratePageHtmlArgs {
137
+ pageIndex: number;
138
+ plan: WebsitePlan;
139
+ pageMasterId?: string;
140
+ theme?: string;
141
+ primaryColor?: string;
142
+ /** figma_get_design で取得したFigmaデザインコンテキスト */
143
+ figmaDesignContext?: {
144
+ nodeId?: string;
145
+ nodeName?: string;
146
+ structure?: Record<string, unknown>;
147
+ hint?: string;
148
+ image?: {
149
+ base64: string;
150
+ mimeType: string;
151
+ };
152
+ };
153
+ }
154
+
155
+ /**
156
+ * search_page_masters ツール引数
157
+ */
158
+ export interface SearchPageMastersArgs {
159
+ query?: string;
160
+ category?: SectionCategory;
161
+ limit?: number;
162
+ }
163
+
164
+ /**
165
+ * get_page_master ツール引数
166
+ */
167
+ export interface GetPageMasterArgs {
168
+ masterId: string;
169
+ }
170
+
171
+ /**
172
+ * save_page ツール引数
173
+ */
174
+ export interface SavePageArgs {
175
+ websiteId: string;
176
+ pageData: {
177
+ title: string;
178
+ slug: string;
179
+ pageNumber: number;
180
+ html: string;
181
+ css?: string;
182
+ category?: PageCategory;
183
+ pageMasterId?: string;
184
+ seo?: {
185
+ metaTitle?: string;
186
+ metaDescription?: string;
187
+ keywords?: string[];
188
+ };
189
+ };
190
+ }
191
+
192
+ /**
193
+ * update_page ツール引数
194
+ */
195
+ export interface UpdatePageArgs {
196
+ websiteId: string;
197
+ pageId: string;
198
+ updates: Partial<{
199
+ title: string;
200
+ slug: string;
201
+ content: WebPage['content'];
202
+ seo: WebPage['seo'];
203
+ }>;
204
+ }
205
+
206
+ /**
207
+ * google_search ツール引数
208
+ */
209
+ export interface GoogleSearchArgs {
210
+ query: string;
211
+ maxResults?: number;
212
+ }
213
+
214
+ /**
215
+ * generate_image ツール引数
216
+ */
217
+ export interface GenerateImageArgs {
218
+ prompt: string;
219
+ style?: 'realistic' | 'illustration' | 'icon' | 'diagram' | 'flat' | 'minimal';
220
+ aspectRatio?: '1:1' | '16:9' | '4:3' | '3:4' | '9:16';
221
+ backgroundColor?: string;
222
+ }
223
+
224
+ /**
225
+ * fetch_page ツール引数
226
+ */
227
+ export interface FetchPageArgs {
228
+ url: string;
229
+ extractText?: boolean;
230
+ }
231
+
232
+ // =====================
233
+ // ツール結果型
234
+ // =====================
235
+
236
+ export interface GenerateWebsitePlanResult {
237
+ success: boolean;
238
+ plan?: WebsitePlan;
239
+ error?: string;
240
+ }
241
+
242
+ export interface GeneratePageHtmlResult {
243
+ success: boolean;
244
+ page?: PageGenerationResult;
245
+ error?: string;
246
+ // 自動生成された画像情報
247
+ generatedImage?: {
248
+ dataUri: string;
249
+ description?: string;
250
+ };
251
+ }
252
+
253
+ export interface SearchPageMastersResult {
254
+ success: boolean;
255
+ masters?: Array<{
256
+ id: string;
257
+ name: string;
258
+ description: string;
259
+ category: string;
260
+ }>;
261
+ error?: string;
262
+ }
263
+
264
+ export interface GetPageMasterResult {
265
+ success: boolean;
266
+ master?: PageMaster;
267
+ error?: string;
268
+ }
269
+
270
+ export interface SavePageResult {
271
+ success: boolean;
272
+ pageId?: string;
273
+ error?: string;
274
+ }
275
+
276
+ export interface UpdatePageResult {
277
+ success: boolean;
278
+ error?: string;
279
+ }
280
+
281
+ export interface GoogleSearchResult {
282
+ success: boolean;
283
+ results?: Array<{
284
+ title: string;
285
+ url: string;
286
+ snippet: string;
287
+ }>;
288
+ error?: string;
289
+ }
290
+
291
+ export interface GenerateImageResult {
292
+ success: boolean;
293
+ imageUrl?: string; // data URI形式の画像(内部用)
294
+ imageId?: string; // 画像ID(キャッシュ参照用)
295
+ message?: string; // メッセージ
296
+ error?: string;
297
+ }
298
+
299
+ export interface FetchPageResult {
300
+ success: boolean;
301
+ content?: string;
302
+ title?: string;
303
+ error?: string;
304
+ }
305
+
306
+ // =====================
307
+ // Figma ツール型
308
+ // =====================
309
+
310
+ /**
311
+ * Figma内で検出された画像ノード情報
312
+ */
313
+ export interface FigmaImageNodeInfo {
314
+ id: string;
315
+ name: string;
316
+ type: string;
317
+ width: number;
318
+ height: number;
319
+ isImageFill: boolean;
320
+ isVectorNode: boolean;
321
+ }
322
+
323
+ /**
324
+ * figma_get_design ツール引数
325
+ */
326
+ export interface FigmaGetDesignArgs {
327
+ figmaUrl: string;
328
+ depth?: number;
329
+ includeImage?: boolean;
330
+ /** 画像ノードを自動的に抽出してFirebase Storageにアップロードするか */
331
+ extractAssets?: boolean;
332
+ }
333
+
334
+ /**
335
+ * figma_get_design ツール結果
336
+ */
337
+ export interface FigmaGetDesignResult {
338
+ success: boolean;
339
+ fileKey?: string;
340
+ nodeId?: string;
341
+ nodeName?: string;
342
+ nodeType?: string;
343
+ absoluteBoundingBox?: {
344
+ x: number;
345
+ y: number;
346
+ width: number;
347
+ height: number;
348
+ };
349
+ structure?: Record<string, unknown>;
350
+ image?: {
351
+ base64: string;
352
+ mimeType: string;
353
+ url?: string;
354
+ };
355
+ hint?: string;
356
+ /** 検出された画像ノード一覧 */
357
+ detectedImageNodes?: FigmaImageNodeInfo[];
358
+ /** 抽出されたアセット(ノードID → Firebase Storage URL) */
359
+ extractedAssets?: Record<string, string>;
360
+ /** Figma APIから取得した生のノードデータ(決定論的変換用) */
361
+ rawNode?: Record<string, unknown>;
362
+ error?: string;
363
+ }
364
+
365
+ /**
366
+ * figma_list_components ツール引数
367
+ */
368
+ export interface FigmaListComponentsArgs {
369
+ figmaUrl: string;
370
+ }
371
+
372
+ /**
373
+ * figma_list_components ツール結果
374
+ */
375
+ export interface FigmaListComponentsResult {
376
+ success: boolean;
377
+ fileName?: string;
378
+ lastModified?: string;
379
+ pages?: Array<{
380
+ id: string;
381
+ name: string;
382
+ frames: Array<{
383
+ id: string;
384
+ name: string;
385
+ type: string;
386
+ width?: number;
387
+ height?: number;
388
+ }>;
389
+ }>;
390
+ hint?: string;
391
+ error?: string;
392
+ }
393
+
394
+ /**
395
+ * figma_export_image ツール引数
396
+ */
397
+ export interface FigmaExportImageArgs {
398
+ figmaUrl: string;
399
+ format?: 'png' | 'jpg' | 'svg';
400
+ scale?: number;
401
+ }
402
+
403
+ /**
404
+ * figma_export_image ツール結果
405
+ */
406
+ export interface FigmaExportImageResult {
407
+ success: boolean;
408
+ url?: string;
409
+ storagePath?: string;
410
+ format?: string;
411
+ scale?: number;
412
+ originalFigmaUrl?: string;
413
+ hint?: string;
414
+ error?: string;
415
+ }
416
+
417
+ // =====================
418
+ // Progressive Generation 型
419
+ // =====================
420
+
421
+ /**
422
+ * セクションタイプ
423
+ */
424
+ export type FigmaSectionType = 'header' | 'hero' | 'content' | 'features' | 'cta' | 'footer' | 'navigation' | 'sidebar' | 'other';
425
+
426
+ /**
427
+ * Figmaセクション情報
428
+ */
429
+ export interface FigmaSection {
430
+ id: string;
431
+ name: string;
432
+ type: FigmaSectionType;
433
+ order: number;
434
+ boundingBox: {
435
+ x: number;
436
+ y: number;
437
+ width: number;
438
+ height: number;
439
+ };
440
+ figmaUrl?: string;
441
+ childCount: number;
442
+ description?: string;
443
+ }
444
+
445
+ /**
446
+ * analyze_figma_sections ツール引数
447
+ */
448
+ export interface AnalyzeFigmaSectionsArgs {
449
+ figmaUrl: string;
450
+ pageCategory?: string;
451
+ }
452
+
453
+ /**
454
+ * 親フレームのスタイル情報
455
+ */
456
+ export interface ParentFrameStyles {
457
+ backgroundColor?: string;
458
+ fills?: Array<{
459
+ type: string;
460
+ color?: { r: number; g: number; b: number; a?: number };
461
+ opacity?: number;
462
+ }>;
463
+ width?: number;
464
+ height?: number;
465
+ }
466
+
467
+ /**
468
+ * analyze_figma_sections ツール結果
469
+ */
470
+ export interface AnalyzeFigmaSectionsResult {
471
+ success: boolean;
472
+ sections?: FigmaSection[];
473
+ totalSections?: number;
474
+ analysisHint?: string;
475
+ parentStyles?: ParentFrameStyles;
476
+ error?: string;
477
+ }
478
+
479
+ /**
480
+ * 生成されたセクションHTML
481
+ */
482
+ export interface GeneratedSectionHtml {
483
+ sectionId: string;
484
+ sectionType: FigmaSectionType;
485
+ html: string;
486
+ css: string;
487
+ order: number;
488
+ }
489
+
490
+ /**
491
+ * generate_section_html ツール引数
492
+ */
493
+ export interface GenerateSectionHtmlArgs {
494
+ sectionIndex: number;
495
+ section: FigmaSection;
496
+ plan: WebsitePlan;
497
+ pageIndex: number;
498
+ previousSections?: GeneratedSectionHtml[];
499
+ parentStyles?: ParentFrameStyles;
500
+ figmaDesignContext?: {
501
+ nodeId?: string;
502
+ nodeName?: string;
503
+ structure?: Record<string, unknown>;
504
+ hint?: string;
505
+ image?: {
506
+ base64: string;
507
+ mimeType: string;
508
+ };
509
+ };
510
+ }
511
+
512
+ /**
513
+ * generate_section_html ツール結果
514
+ */
515
+ export interface GenerateSectionHtmlResult {
516
+ success: boolean;
517
+ section?: GeneratedSectionHtml;
518
+ error?: string;
519
+ /** 生成に使用したプロンプト(デバッグ用) */
520
+ generatedPrompt?: string;
521
+ }
522
+
523
+ /**
524
+ * unify_page_styles ツール引数
525
+ */
526
+ export interface UnifyPageStylesArgs {
527
+ sections: GeneratedSectionHtml[];
528
+ pageTitle: string;
529
+ pageSlug: string;
530
+ parentStyles?: ParentFrameStyles;
531
+ }
532
+
533
+ /**
534
+ * unify_page_styles ツール結果
535
+ */
536
+ export interface UnifyPageStylesResult {
537
+ success: boolean;
538
+ html?: string;
539
+ css?: string;
540
+ unifiedStyles?: {
541
+ colorPalette: string[];
542
+ fontFamilies: string[];
543
+ spacingScale: number[];
544
+ };
545
+ error?: string;
546
+ }
547
+
548
+ // =====================
549
+ // エージェントモード
550
+ // =====================
551
+
552
+ /**
553
+ * エージェント実行モード
554
+ * - plan: 計画のみ生成(generate_website_planのみ使用)
555
+ * - generate: ページ生成(generate_page_html, save_page等を使用)
556
+ * - generate_single: 単一ページ生成(1ページ=1インタラクション)
557
+ * - full: 計画からページ生成まで一括実行
558
+ * - element_replace: 要素置換(選択要素をAI生成HTMLで置換)
559
+ */
560
+ export type WebsiteAgentMode = 'plan' | 'generate' | 'generate_single' | 'generate_single_progressive' | 'full' | 'element_replace';
561
+
562
+ // =====================
563
+ // 要素置換(element_replace)関連
564
+ // =====================
565
+
566
+ /**
567
+ * 添付ファイル型
568
+ */
569
+ export interface AttachedFile {
570
+ name: string;
571
+ type: string; // MIME type (e.g., 'image/png', 'application/pdf')
572
+ size: number;
573
+ data: string; // Base64 encoded data
574
+ }
575
+
576
+ /**
577
+ * generate_element_html ツール引数
578
+ */
579
+ export interface GenerateElementHtmlArgs {
580
+ prompt: string; // ユーザーのプロンプト
581
+ pageHtml: string; // 現在のページ全体HTML
582
+ selectedElementHtml: string; // 選択中の要素HTML
583
+ selectedElementInfo: { // 要素のメタ情報
584
+ tagName: string;
585
+ width: number;
586
+ height: number;
587
+ position: { x: number; y: number };
588
+ };
589
+ imageId?: string; // 使用する画像ID(generate_imageで生成した場合)
590
+ attachedFiles?: AttachedFile[]; // 添付ファイル(画像、PDF等)
591
+ }
592
+
593
+ /**
594
+ * generate_element_html ツール結果
595
+ */
596
+ export interface GenerateElementHtmlResult {
597
+ success: boolean;
598
+ html?: string; // 生成されたHTML
599
+ explanation?: string; // 生成内容の説明
600
+ error?: string;
601
+ }
602
+
603
+ // =====================
604
+ // 画像キャッシュ
605
+ // =====================
606
+
607
+ /**
608
+ * 生成された画像のキャッシュエントリ
609
+ * Firebase Storageにアップロードされた画像のメタデータを保持
610
+ */
611
+ export interface GeneratedImageCache {
612
+ imageId: string;
613
+ storageUrl: string; // Firebase StorageのURL
614
+ storagePath?: string; // Storage内のパス
615
+ prompt: string;
616
+ style?: string;
617
+ createdAt: number;
618
+ }
619
+
620
+ // =====================
621
+ // エージェントコンテキスト
622
+ // =====================
623
+
624
+ /**
625
+ * Webサイトエージェントのコンテキスト
626
+ */
627
+ /**
628
+ * CSSメソドロジー
629
+ */
630
+ export type CssMethodology = 'tailwind' | 'flocss';
631
+
632
+ export interface WebsiteAgentContext {
633
+ userId: string;
634
+ websiteId?: string;
635
+ modelName?: string;
636
+ originalPrompt?: string; // ユーザーの元のプロンプト(ページ生成時に使用)
637
+ currentPlan?: WebsitePlan;
638
+ generatedPages?: PageGenerationResult[];
639
+ // 画像キャッシュ(generate_imageの結果を内部保持)
640
+ generatedImages?: Map<string, GeneratedImageCache>;
641
+ latestImageId?: string;
642
+ // 要素置換用コンテキスト
643
+ elementReplaceContext?: {
644
+ pageHtml: string;
645
+ selectedElementHtml: string;
646
+ selectedElementInfo: {
647
+ tagName: string;
648
+ width: number;
649
+ height: number;
650
+ position: { x: number; y: number };
651
+ };
652
+ };
653
+ // Progressive mode用コンテキスト
654
+ analyzedSections?: FigmaSection[];
655
+ generatedSections?: GeneratedSectionHtml[];
656
+ // CSSメソドロジー設定
657
+ cssMethodology?: CssMethodology;
658
+ }
659
+
660
+ /**
661
+ * ツールハンドラー
662
+ */
663
+ export type ToolHandler<TArgs = unknown, TResult = unknown> = (
664
+ args: TArgs,
665
+ context: WebsiteAgentContext
666
+ ) => Promise<TResult>;
667
+
668
+ /**
669
+ * ツールレジストリ
670
+ */
671
+ export interface ToolRegistry {
672
+ tools: WebsiteAgentTool[];
673
+ handlers: Map<string, ToolHandler>;
674
+ }
675
+
676
+ // =====================
677
+ // SSE ストリーミング型
678
+ // =====================
679
+
680
+ export interface SSEEvent {
681
+ type: 'status' | 'progress' | 'tool_call' | 'tool_result' | 'text' | 'error' | 'complete';
682
+ data: unknown;
683
+ }
684
+
685
+ export interface SSEStatusEvent extends SSEEvent {
686
+ type: 'status';
687
+ data: {
688
+ stage: 'initializing' | 'planning' | 'generating' | 'saving' | 'complete' | 'error';
689
+ message: string;
690
+ };
691
+ }
692
+
693
+ export interface SSEProgressEvent extends SSEEvent {
694
+ type: 'progress';
695
+ data: {
696
+ current: number;
697
+ total: number;
698
+ message: string;
699
+ };
700
+ }
701
+
702
+ export interface SSEToolCallEvent extends SSEEvent {
703
+ type: 'tool_call';
704
+ data: {
705
+ name: string;
706
+ arguments: Record<string, unknown>;
707
+ };
708
+ }
709
+
710
+ export interface SSEToolResultEvent extends SSEEvent {
711
+ type: 'tool_result';
712
+ data: {
713
+ name: string;
714
+ success: boolean;
715
+ result?: unknown;
716
+ error?: string;
717
+ };
718
+ }
719
+
720
+ export interface SSETextEvent extends SSEEvent {
721
+ type: 'text';
722
+ data: {
723
+ text: string;
724
+ isPartial?: boolean;
725
+ };
726
+ }
727
+
728
+ export interface SSEErrorEvent extends SSEEvent {
729
+ type: 'error';
730
+ data: {
731
+ message: string;
732
+ code?: string;
733
+ };
734
+ }
735
+
736
+ export interface SSECompleteEvent extends SSEEvent {
737
+ type: 'complete';
738
+ data: {
739
+ plan?: WebsitePlan;
740
+ pages?: PageGenerationResult[];
741
+ message: string;
742
+ };
743
+ }
744
+
745
+ // =====================
746
+ // API リクエスト/レスポンス
747
+ // =====================
748
+
749
+ /**
750
+ * Webサイトエージェント API リクエスト
751
+ */
752
+ export interface WebsiteAgentRequest {
753
+ prompt: string;
754
+ websiteId?: string; // element_replaceモードではオプショナル
755
+ userId: string;
756
+ options?: {
757
+ /** エージェント実行モード(plan: 計画のみ, generate: ページ生成, generate_single: 単一ページ, full: 一括, element_replace: 要素置換) */
758
+ mode?: WebsiteAgentMode;
759
+ /** 生成するページのインデックス(generate_singleモード時に必須、0から開始) */
760
+ pageIndex?: number;
761
+ pageCount?: number;
762
+ theme?: 'light' | 'dark' | 'corporate' | 'modern';
763
+ primaryColor?: string;
764
+ pageMasterId?: string;
765
+ websiteMasterId?: string;
766
+ modelName?: string;
767
+ attachedFiles?: Array<{
768
+ name: string;
769
+ type: string;
770
+ size: number;
771
+ data: string;
772
+ }>;
773
+ stream?: boolean;
774
+ /** 既存の計画(generate/generate_singleモード時に使用) */
775
+ existingPlan?: WebsitePlan;
776
+ /** グローバルFigma URL(ページ固有のfigmaReferenceがない場合のフォールバック) */
777
+ globalFigmaUrl?: string;
778
+ /** 要素置換用オプション(element_replaceモード時に使用) */
779
+ elementReplace?: {
780
+ pageHtml: string;
781
+ selectedElementHtml: string;
782
+ selectedElementInfo: {
783
+ tagName: string;
784
+ width: number;
785
+ height: number;
786
+ position: { x: number; y: number };
787
+ };
788
+ attachedFiles?: AttachedFile[]; // 添付ファイル(画像、PDF等)
789
+ };
790
+ };
791
+ }
792
+
793
+ /**
794
+ * Webサイトエージェント API レスポンス
795
+ */
796
+ export interface WebsiteAgentResponse {
797
+ success: boolean;
798
+ interactionId?: string;
799
+ plan?: WebsitePlan;
800
+ pages?: PageGenerationResult[];
801
+ /** 要素置換モード用: 生成されたHTML */
802
+ generatedHtml?: string;
803
+ message?: string;
804
+ error?: string;
805
+ }