project-graph-mcp 2.3.2 → 2.4.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 (279) hide show
  1. package/package.json +3 -2
  2. package/src/analysis/analysis-cache.ctx +9 -0
  3. package/src/analysis/analysis-cache.js +1 -1
  4. package/src/analysis/complexity.ctx +6 -0
  5. package/src/analysis/complexity.js +1 -1
  6. package/src/analysis/custom-rules.ctx +14 -0
  7. package/src/analysis/custom-rules.js +1 -1
  8. package/src/analysis/db-analysis.ctx +7 -0
  9. package/src/analysis/db-analysis.js +1 -1
  10. package/src/analysis/dead-code.ctx +6 -0
  11. package/src/analysis/dead-code.js +1 -1
  12. package/src/analysis/full-analysis.ctx +9 -0
  13. package/src/analysis/full-analysis.js +1 -1
  14. package/src/analysis/jsdoc-checker.ctx +10 -0
  15. package/src/analysis/jsdoc-checker.js +1 -1
  16. package/src/analysis/jsdoc-generator.ctx +9 -0
  17. package/src/analysis/jsdoc-generator.js +1 -1
  18. package/src/analysis/large-files.ctx +6 -0
  19. package/src/analysis/large-files.js +1 -1
  20. package/src/analysis/outdated-patterns.ctx +7 -0
  21. package/src/analysis/outdated-patterns.js +1 -1
  22. package/src/analysis/similar-functions.ctx +6 -0
  23. package/src/analysis/similar-functions.js +1 -1
  24. package/src/analysis/test-annotations.ctx +11 -0
  25. package/src/analysis/test-annotations.js +1 -1
  26. package/src/analysis/type-checker.ctx +6 -0
  27. package/src/analysis/type-checker.js +1 -1
  28. package/src/analysis/undocumented.ctx +8 -0
  29. package/src/analysis/undocumented.js +1 -1
  30. package/src/cli/cli-handlers.ctx +7 -0
  31. package/src/cli/cli-handlers.js +1 -1
  32. package/src/cli/cli.ctx +6 -0
  33. package/src/cli/cli.js +1 -1
  34. package/src/compact/ai-context.ctx +6 -0
  35. package/src/compact/ai-context.js +1 -1
  36. package/src/compact/compact-migrate.ctx +8 -0
  37. package/src/compact/compact-migrate.js +1 -1
  38. package/src/compact/compact.ctx +11 -0
  39. package/src/compact/compact.js +1 -1
  40. package/src/compact/compress.ctx +7 -0
  41. package/src/compact/compress.js +1 -1
  42. package/src/compact/ctx-resolver.ctx +2 -0
  43. package/src/compact/ctx-resolver.js +1 -1
  44. package/src/compact/ctx-to-jsdoc.ctx +11 -0
  45. package/src/compact/ctx-to-jsdoc.js +1 -1
  46. package/src/compact/doc-dialect.ctx +11 -0
  47. package/src/compact/doc-dialect.js +2 -2
  48. package/src/compact/expand.ctx +14 -0
  49. package/src/compact/expand.js +1 -1
  50. package/src/compact/framework-references.ctx +7 -0
  51. package/src/compact/framework-references.js +1 -1
  52. package/src/compact/instructions.ctx +6 -0
  53. package/src/compact/instructions.js +1 -1
  54. package/src/compact/jsdoc-builder.ctx +4 -0
  55. package/src/compact/jsdoc-builder.js +1 -1
  56. package/src/compact/mode-config.ctx +8 -0
  57. package/src/compact/mode-config.js +1 -1
  58. package/src/compact/split-declarations.ctx +6 -0
  59. package/src/compact/split-declarations.js +1 -1
  60. package/src/compact/validate-pipeline.ctx +12 -0
  61. package/src/compact/validate-pipeline.js +1 -1
  62. package/src/core/event-bus.ctx +9 -0
  63. package/src/core/event-bus.js +1 -1
  64. package/src/core/file-walker.ctx +1 -0
  65. package/src/core/file-walker.js +1 -1
  66. package/src/core/filters.ctx +12 -0
  67. package/src/core/filters.js +1 -1
  68. package/src/core/graph-builder.ctx +7 -0
  69. package/src/core/graph-builder.js +1 -1
  70. package/src/core/parser.ctx +12 -0
  71. package/src/core/parser.js +1 -1
  72. package/src/core/utils.ctx +1 -0
  73. package/src/core/utils.js +1 -1
  74. package/src/core/workspace.ctx +7 -0
  75. package/src/core/workspace.js +1 -1
  76. package/src/lang/lang-go.ctx +8 -0
  77. package/src/lang/lang-go.js +1 -1
  78. package/src/lang/lang-python.ctx +5 -0
  79. package/src/lang/lang-python.js +1 -1
  80. package/src/lang/lang-sql.ctx +10 -0
  81. package/src/lang/lang-sql.js +1 -1
  82. package/src/lang/lang-typescript.ctx +6 -0
  83. package/src/lang/lang-typescript.js +1 -1
  84. package/src/lang/lang-utils.ctx +5 -0
  85. package/src/lang/lang-utils.js +1 -1
  86. package/src/mcp/mcp-server.ctx +6 -0
  87. package/src/mcp/mcp-server.js +1 -1
  88. package/src/mcp/tool-defs.ctx +2 -0
  89. package/src/mcp/tool-defs.js +1 -1
  90. package/src/mcp/tools.ctx +13 -0
  91. package/src/mcp/tools.js +1 -1
  92. package/src/network/backend-lifecycle.ctx +10 -0
  93. package/src/network/backend-lifecycle.js +1 -1
  94. package/src/network/backend.ctx +5 -0
  95. package/src/network/backend.js +1 -1
  96. package/src/network/local-gateway.ctx +9 -0
  97. package/src/network/local-gateway.js +1 -1
  98. package/src/network/mdns.ctx +6 -0
  99. package/src/network/mdns.js +1 -1
  100. package/src/network/server.ctx +2 -0
  101. package/src/network/server.js +2 -2
  102. package/src/network/web-server.ctx +17 -0
  103. package/src/network/web-server.js +2 -2
  104. package/web/follow-controller.js +94 -25
  105. package/web/panels/dep-graph.js +207 -21
  106. package/project-graph-mcp-2.3.0.tgz +0 -0
  107. package/vendor/symbiote-node/CHANGELOG.md +0 -31
  108. package/vendor/symbiote-node/LICENSE +0 -21
  109. package/vendor/symbiote-node/README.md +0 -206
  110. package/vendor/symbiote-node/canvas/AutoLayout.js +0 -725
  111. package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.css.js +0 -73
  112. package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.js +0 -93
  113. package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.tpl.js +0 -9
  114. package/vendor/symbiote-node/canvas/CanvasConnectionRenderer.js +0 -962
  115. package/vendor/symbiote-node/canvas/ConnectionRenderer.js +0 -1468
  116. package/vendor/symbiote-node/canvas/FlowSimulator.js +0 -323
  117. package/vendor/symbiote-node/canvas/ForceLayout.js +0 -189
  118. package/vendor/symbiote-node/canvas/ForceWorker.js +0 -1325
  119. package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.css.js +0 -97
  120. package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.js +0 -176
  121. package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.tpl.js +0 -12
  122. package/vendor/symbiote-node/canvas/LODManager.js +0 -88
  123. package/vendor/symbiote-node/canvas/Minimap/Minimap.css.js +0 -71
  124. package/vendor/symbiote-node/canvas/Minimap/Minimap.js +0 -207
  125. package/vendor/symbiote-node/canvas/Minimap/Minimap.tpl.js +0 -9
  126. package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.css.js +0 -261
  127. package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.js +0 -1840
  128. package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.tpl.js +0 -22
  129. package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.css.js +0 -97
  130. package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.js +0 -132
  131. package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.tpl.js +0 -21
  132. package/vendor/symbiote-node/canvas/NodeViewManager.js +0 -584
  133. package/vendor/symbiote-node/canvas/PinExpansion.js +0 -131
  134. package/vendor/symbiote-node/canvas/PseudoConnection.js +0 -80
  135. package/vendor/symbiote-node/canvas/SubgraphManager.js +0 -201
  136. package/vendor/symbiote-node/canvas/SubgraphRouter.js +0 -443
  137. package/vendor/symbiote-node/canvas/ViewportActions.js +0 -446
  138. package/vendor/symbiote-node/core/Connection.js +0 -45
  139. package/vendor/symbiote-node/core/Editor.js +0 -451
  140. package/vendor/symbiote-node/core/Frame.js +0 -31
  141. package/vendor/symbiote-node/core/GraphMermaid.js +0 -348
  142. package/vendor/symbiote-node/core/GraphText.js +0 -210
  143. package/vendor/symbiote-node/core/Node.js +0 -143
  144. package/vendor/symbiote-node/core/Portal.js +0 -104
  145. package/vendor/symbiote-node/core/Socket.js +0 -185
  146. package/vendor/symbiote-node/core/SubgraphNode.js +0 -125
  147. package/vendor/symbiote-node/engine/AgentUICommands.js +0 -100
  148. package/vendor/symbiote-node/engine/Executor.js +0 -371
  149. package/vendor/symbiote-node/engine/Graph.js +0 -314
  150. package/vendor/symbiote-node/engine/GraphServer.js +0 -353
  151. package/vendor/symbiote-node/engine/HandlerLoader.js +0 -145
  152. package/vendor/symbiote-node/engine/History.js +0 -83
  153. package/vendor/symbiote-node/engine/Lifecycle.js +0 -118
  154. package/vendor/symbiote-node/engine/Persistence.js +0 -84
  155. package/vendor/symbiote-node/engine/Registry.js +0 -264
  156. package/vendor/symbiote-node/engine/SocketTypes.js +0 -79
  157. package/vendor/symbiote-node/engine/cli.js +0 -404
  158. package/vendor/symbiote-node/engine/index.js +0 -56
  159. package/vendor/symbiote-node/engine/nanoid.js +0 -28
  160. package/vendor/symbiote-node/engine/package.json +0 -26
  161. package/vendor/symbiote-node/engine/packs/ai/beat-detect.handler.js +0 -215
  162. package/vendor/symbiote-node/engine/packs/ai/content-adapt.handler.js +0 -238
  163. package/vendor/symbiote-node/engine/packs/ai/face-detect.handler.js +0 -287
  164. package/vendor/symbiote-node/engine/packs/ai/grok-generate.handler.js +0 -565
  165. package/vendor/symbiote-node/engine/packs/ai/kling-lipsync.handler.js +0 -414
  166. package/vendor/symbiote-node/engine/packs/ai/lesson-generate.handler.js +0 -343
  167. package/vendor/symbiote-node/engine/packs/ai/opencode.handler.js +0 -164
  168. package/vendor/symbiote-node/engine/packs/ai/replicate-lipsync.handler.js +0 -341
  169. package/vendor/symbiote-node/engine/packs/ai/tts.handler.js +0 -241
  170. package/vendor/symbiote-node/engine/packs/ai/whisper.handler.js +0 -191
  171. package/vendor/symbiote-node/engine/packs/data/db-query.handler.js +0 -67
  172. package/vendor/symbiote-node/engine/packs/data/news-accumulate.handler.js +0 -281
  173. package/vendor/symbiote-node/engine/packs/data/personas.handler.js +0 -160
  174. package/vendor/symbiote-node/engine/packs/data/prompt-loader.handler.js +0 -193
  175. package/vendor/symbiote-node/engine/packs/data/roles.handler.js +0 -216
  176. package/vendor/symbiote-node/engine/packs/data/rss-feed.handler.js +0 -244
  177. package/vendor/symbiote-node/engine/packs/debug/inject.handler.js +0 -52
  178. package/vendor/symbiote-node/engine/packs/flow/agent.handler.js +0 -73
  179. package/vendor/symbiote-node/engine/packs/flow/if.handler.js +0 -107
  180. package/vendor/symbiote-node/engine/packs/flow/loop.handler.js +0 -58
  181. package/vendor/symbiote-node/engine/packs/flow/merge.handler.js +0 -60
  182. package/vendor/symbiote-node/engine/packs/flow/retry.handler.js +0 -65
  183. package/vendor/symbiote-node/engine/packs/flow/switch.handler.js +0 -64
  184. package/vendor/symbiote-node/engine/packs/flow/wait-all.handler.js +0 -39
  185. package/vendor/symbiote-node/engine/packs/io/http-request.handler.js +0 -82
  186. package/vendor/symbiote-node/engine/packs/io/read-file.handler.js +0 -60
  187. package/vendor/symbiote-node/engine/packs/io/write-file.handler.js +0 -63
  188. package/vendor/symbiote-node/engine/packs/transform/anchor-match.handler.js +0 -494
  189. package/vendor/symbiote-node/engine/packs/transform/effects-skeleton.handler.js +0 -417
  190. package/vendor/symbiote-node/engine/packs/transform/json-parse.handler.js +0 -43
  191. package/vendor/symbiote-node/engine/packs/transform/lipsync-select.handler.js +0 -339
  192. package/vendor/symbiote-node/engine/packs/transform/riopla-adapt.handler.js +0 -432
  193. package/vendor/symbiote-node/engine/packs/transform/set.handler.js +0 -57
  194. package/vendor/symbiote-node/engine/packs/transform/template-builder.handler.js +0 -134
  195. package/vendor/symbiote-node/engine/packs/transform/template.handler.js +0 -79
  196. package/vendor/symbiote-node/engine/packs/transform/timeline-build.handler.js +0 -399
  197. package/vendor/symbiote-node/engine/packs/util/delay.handler.js +0 -39
  198. package/vendor/symbiote-node/engine/packs/util/log.handler.js +0 -44
  199. package/vendor/symbiote-node/engine/packs/video-pack.js +0 -323
  200. package/vendor/symbiote-node/index.js +0 -103
  201. package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.css.js +0 -361
  202. package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.js +0 -332
  203. package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.tpl.js +0 -96
  204. package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.css.js +0 -104
  205. package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.js +0 -133
  206. package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.tpl.js +0 -33
  207. package/vendor/symbiote-node/interactions/ConnectFlow.js +0 -307
  208. package/vendor/symbiote-node/interactions/Drag.js +0 -102
  209. package/vendor/symbiote-node/interactions/Selector.js +0 -132
  210. package/vendor/symbiote-node/interactions/SnapGrid.js +0 -65
  211. package/vendor/symbiote-node/interactions/Zoom.js +0 -140
  212. package/vendor/symbiote-node/layout/ActionZone/ActionZone.css.js +0 -88
  213. package/vendor/symbiote-node/layout/ActionZone/ActionZone.js +0 -254
  214. package/vendor/symbiote-node/layout/ActionZone/ActionZone.tpl.js +0 -11
  215. package/vendor/symbiote-node/layout/Layout/Layout.css.js +0 -88
  216. package/vendor/symbiote-node/layout/Layout/Layout.js +0 -622
  217. package/vendor/symbiote-node/layout/Layout/Layout.tpl.js +0 -25
  218. package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.css.js +0 -293
  219. package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.js +0 -467
  220. package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.tpl.js +0 -33
  221. package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.css.js +0 -46
  222. package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.js +0 -102
  223. package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.tpl.js +0 -6
  224. package/vendor/symbiote-node/layout/LayoutRouter/LayoutRouter.js +0 -156
  225. package/vendor/symbiote-node/layout/LayoutRouter/routerSync.js +0 -250
  226. package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.css.js +0 -379
  227. package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.js +0 -263
  228. package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.tpl.js +0 -20
  229. package/vendor/symbiote-node/layout/LayoutSidebar/SidebarSection.js +0 -183
  230. package/vendor/symbiote-node/layout/LayoutTree.js +0 -246
  231. package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.css.js +0 -43
  232. package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.js +0 -89
  233. package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.tpl.js +0 -14
  234. package/vendor/symbiote-node/layout/index.js +0 -16
  235. package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.css.js +0 -61
  236. package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.js +0 -79
  237. package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.tpl.js +0 -19
  238. package/vendor/symbiote-node/node/CtrlItem/CtrlItem.css.js +0 -41
  239. package/vendor/symbiote-node/node/CtrlItem/CtrlItem.js +0 -24
  240. package/vendor/symbiote-node/node/CtrlItem/CtrlItem.tpl.js +0 -16
  241. package/vendor/symbiote-node/node/GraphFrame/GraphFrame.css.js +0 -65
  242. package/vendor/symbiote-node/node/GraphFrame/GraphFrame.js +0 -29
  243. package/vendor/symbiote-node/node/GraphFrame/GraphFrame.tpl.js +0 -13
  244. package/vendor/symbiote-node/node/GraphNode/GraphNode.css.js +0 -683
  245. package/vendor/symbiote-node/node/GraphNode/GraphNode.js +0 -92
  246. package/vendor/symbiote-node/node/GraphNode/GraphNode.tpl.js +0 -17
  247. package/vendor/symbiote-node/node/NodeSocket/NodeSocket.js +0 -25
  248. package/vendor/symbiote-node/node/NodeSocket/NodeSocket.tpl.js +0 -7
  249. package/vendor/symbiote-node/node/PortItem/PortItem.css.js +0 -90
  250. package/vendor/symbiote-node/node/PortItem/PortItem.js +0 -87
  251. package/vendor/symbiote-node/node/PortItem/PortItem.tpl.js +0 -10
  252. package/vendor/symbiote-node/package.json +0 -59
  253. package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.css.js +0 -143
  254. package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.js +0 -131
  255. package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.tpl.js +0 -16
  256. package/vendor/symbiote-node/plugins/History.js +0 -384
  257. package/vendor/symbiote-node/plugins/Readonly.js +0 -59
  258. package/vendor/symbiote-node/shapes/CircleShape.js +0 -80
  259. package/vendor/symbiote-node/shapes/CommentShape.js +0 -35
  260. package/vendor/symbiote-node/shapes/DiamondShape.js +0 -115
  261. package/vendor/symbiote-node/shapes/NodeShape.js +0 -80
  262. package/vendor/symbiote-node/shapes/PillShape.js +0 -91
  263. package/vendor/symbiote-node/shapes/RectShape.js +0 -72
  264. package/vendor/symbiote-node/shapes/SVGShape.js +0 -494
  265. package/vendor/symbiote-node/shapes/index.js +0 -53
  266. package/vendor/symbiote-node/themes/Palette.js +0 -32
  267. package/vendor/symbiote-node/themes/Skin.js +0 -113
  268. package/vendor/symbiote-node/themes/Theme.js +0 -84
  269. package/vendor/symbiote-node/themes/carbon.js +0 -137
  270. package/vendor/symbiote-node/themes/dark.js +0 -137
  271. package/vendor/symbiote-node/themes/ebook.js +0 -138
  272. package/vendor/symbiote-node/themes/grey.js +0 -137
  273. package/vendor/symbiote-node/themes/light.js +0 -137
  274. package/vendor/symbiote-node/themes/neon.js +0 -138
  275. package/vendor/symbiote-node/themes/pcb.js +0 -273
  276. package/vendor/symbiote-node/themes/synthwave.js +0 -137
  277. package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.css.js +0 -86
  278. package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.js +0 -128
  279. package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.tpl.js +0 -29
@@ -1,565 +0,0 @@
1
- /**
2
- * ai/grok-generate — Image/Video generation via Grok browser automation
3
- *
4
- * Uses Chrome extension bridge to automate grok.com for:
5
- * - Text-to-image generation (via WebSocket injection)
6
- * - Image editing (reference-based generation)
7
- * - Image-to-video conversion
8
- * - Batch processing with worker pool
9
- *
10
- * Architecture:
11
- * - Bridge server (localhost:3333) ↔ Chrome extension (grok-bridge)
12
- * - SELECTORS: stable DOM selectors (aria-label preferred)
13
- * - ACTIONS: atomic bridge commands
14
- * - WORKFLOWS: composed sequences
15
- *
16
- * Ported from Mr-Computer/modules/ai-music-video/src/services/grok-*.js
17
- *
18
- * @module agi-graph/packs/ai/grok-generate
19
- */
20
-
21
- import { readFile, writeFile, mkdir, rename } from 'fs/promises';
22
- import { existsSync } from 'fs';
23
- import path from 'path';
24
-
25
- export default {
26
- type: 'ai/grok-generate',
27
- category: 'ai',
28
- icon: 'auto_awesome',
29
-
30
- driver: {
31
- description: 'Generate images/videos via Grok browser automation',
32
- inputs: [
33
- { name: 'prompt', type: 'string' },
34
- { name: 'referencePath', type: 'string' },
35
- ],
36
- outputs: [
37
- { name: 'result', type: 'any' },
38
- { name: 'error', type: 'string' },
39
- ],
40
- params: {
41
- operation: { type: 'string', default: 'image', description: 'Operation: image | image-edit | video | batch-images | batch-videos | check' },
42
- bridgeUrl: { type: 'string', default: 'http://localhost:3333', description: 'Bridge server URL' },
43
- outputDir: { type: 'string', default: '/tmp/grok-output', description: 'Output directory' },
44
- globalStyle: { type: 'string', default: '', description: 'Global style prefix for prompts' },
45
- filename: { type: 'string', default: '', description: 'Output filename (without extension)' },
46
- enableUpscale: { type: 'boolean', default: false, description: 'HD upscale for videos' },
47
- workerId: { type: 'string', default: '', description: 'Worker ID for multi-tab' },
48
- // Batch params
49
- segments: { type: 'any', default: null, description: 'Segments for batch operations' },
50
- workers: { type: 'int', default: 1, description: 'Parallel workers for batch' },
51
- // Image params
52
- imagePath: { type: 'string', default: '', description: 'Source image for video gen' },
53
- videoPrompt: { type: 'string', default: '', description: 'Camera movement prompt for video' },
54
- },
55
- },
56
-
57
- lifecycle: {
58
- validate: (inputs, params) => {
59
- if (params.operation === 'check') return true;
60
- if (params.operation === 'image' && !inputs.prompt) return false;
61
- if (params.operation === 'image-edit' && (!inputs.prompt || !inputs.referencePath)) return false;
62
- if (params.operation === 'video' && !params.imagePath) return false;
63
- return true;
64
- },
65
-
66
- cacheKey: (inputs, params) => {
67
- return `grok:${params.operation}:${params.filename || inputs.prompt?.substring(0, 30) || ''}`;
68
- },
69
-
70
- execute: async (inputs, params) => {
71
- try {
72
- const op = params.operation;
73
- const bridge = createBridgeClient(params.bridgeUrl);
74
-
75
- if (op === 'check') {
76
- const ok = await bridge.checkHealth();
77
- return { result: { healthy: ok }, error: null };
78
- }
79
-
80
- if (op === 'image') {
81
- const result = await generateImage(bridge, inputs.prompt, params);
82
- return { result, error: null };
83
- }
84
-
85
- if (op === 'image-edit') {
86
- const result = await editImage(bridge, inputs.prompt, inputs.referencePath, params);
87
- return { result, error: null };
88
- }
89
-
90
- if (op === 'video') {
91
- const result = await generateVideo(bridge, params);
92
- return { result, error: null };
93
- }
94
-
95
- if (op === 'batch-images') {
96
- const results = await batchImages(bridge, params);
97
- return { result: results, error: null };
98
- }
99
-
100
- if (op === 'batch-videos') {
101
- const results = await batchVideos(bridge, params);
102
- return { result: results, error: null };
103
- }
104
-
105
- return { result: null, error: `Unknown operation: ${op}` };
106
- } catch (err) {
107
- return { result: null, error: err.message };
108
- }
109
- },
110
- },
111
- };
112
-
113
- // --- Bridge Client ---
114
-
115
- /**
116
- * Create bridge client for communication with grok-bridge Chrome extension
117
- * @param {string} baseUrl
118
- * @returns {Object}
119
- */
120
- function createBridgeClient(baseUrl) {
121
- const sleep = (ms) => new Promise(r => setTimeout(r, ms));
122
-
123
- async function sendCommand(action, cmdParams = {}, timeout = 30000, workerId = null) {
124
- const payload = { action, params: cmdParams };
125
- if (workerId) payload.workerId = workerId;
126
-
127
- const sendRes = await fetch(`${baseUrl}/command`, {
128
- method: 'POST',
129
- headers: { 'Content-Type': 'application/json' },
130
- body: JSON.stringify(payload),
131
- signal: AbortSignal.timeout(10000),
132
- });
133
-
134
- if (!sendRes.ok) throw new Error('Failed to send command');
135
- const { id } = await sendRes.json();
136
-
137
- const start = Date.now();
138
- while (Date.now() - start < timeout) {
139
- await sleep(500);
140
- try {
141
- const res = await fetch(`${baseUrl}/result/${id}`, {
142
- signal: AbortSignal.timeout(5000),
143
- });
144
- if (!res.ok) continue;
145
- const data = await res.json();
146
- if (data.error && data.error !== 'Result not found or not ready') {
147
- throw new Error(data.error);
148
- }
149
- if (data.result !== undefined) return data.result;
150
- } catch (e) {
151
- if (e.message !== 'Result not found or not ready') {
152
- // Connection issue — retry poll
153
- }
154
- }
155
- }
156
- throw new Error(`Timeout: ${action}`);
157
- }
158
-
159
- return {
160
- sendCommand,
161
- sleep,
162
-
163
- async checkHealth() {
164
- try {
165
- const res = await fetch(`${baseUrl}/health`, { signal: AbortSignal.timeout(2000) });
166
- return res.ok;
167
- } catch {
168
- return false;
169
- }
170
- },
171
-
172
- // Atomic actions
173
- async navigate(url, workerId) { return sendCommand('navigate', { url }, 30000, workerId); },
174
- async waitFor(selector, timeout = 15000, workerId = null) { return sendCommand('waitForSelector', { selector, timeout }, timeout + 5000, workerId); },
175
- async click(selector, workerId) { return sendCommand('click', { selector }, 30000, workerId); },
176
- async type(selector, text, workerId) { return sendCommand('type', { selector, text }, 30000, workerId); },
177
- async uploadFile(base64, mimeType, filename, workerId) { return sendCommand('uploadFile', { base64, mimeType, filename }, 30000, workerId); },
178
- async queryAll(selector, workerId) { return sendCommand('querySelectorAll', { selector }, 30000, workerId); },
179
- async getAttribute(selector, attribute, workerId) { return sendCommand('getAttribute', { selector, attribute }, 30000, workerId); },
180
- async getPageInfo(workerId) { return sendCommand('getPageInfo', {}, 30000, workerId); },
181
- async refresh(workerId) { return sendCommand('refresh', {}, 30000, workerId); },
182
-
183
- // WebSocket-based direct generation
184
- async generateImageWS(prompt, options, workerId) { return sendCommand('generateImage', { prompt, options }, 90000, workerId); },
185
- async fetchImage(url, workerId) { return sendCommand('fetchImage', { url }, 30000, workerId); },
186
- async waitForImageComplete(timeout = 120000, workerId) { return sendCommand('waitForImageComplete', { timeout }, timeout + 5000, workerId); },
187
-
188
- // Zone-based interaction
189
- async showZones(layer = 'all', workerId) { return sendCommand('showClickableZones', { layer }, 30000, workerId); },
190
- async clickZone(zone, workerId) { return sendCommand('clickZone', { zone }, 30000, workerId); },
191
- async hideZones(workerId) { return sendCommand('hideZones', {}, 30000, workerId); },
192
- };
193
- }
194
-
195
- // --- Selectors ---
196
-
197
- const SEL = {
198
- promptEditor: '.tiptap.ProseMirror',
199
- editPrompt: '[aria-label="Введите для изменения изображения..."]',
200
- videoPrompt: 'textarea[aria-label="Сделать видео"]',
201
- imageCard: 'div.group\\/media-post-masonry-card img',
202
- firstImage: 'div.group\\/media-post-masonry-card:first-child img',
203
- video: 'video',
204
- downloadBtn: '[aria-label="Скачать"]',
205
- sendBtn: '[aria-label="Отправить"]',
206
- preferenceBtn: 'button:has(svg.lucide-thumbs-up)',
207
- moderatedContent: 'img[alt="Moderated"], svg.lucide-eye-off',
208
- errorToast: '[data-sonner-toast][data-type="error"]',
209
- hdButton: 'button .text-\\[10px\\].font-bold',
210
- };
211
-
212
- // --- Workflows ---
213
-
214
- /**
215
- * Navigate to /imagine page (skip if already there)
216
- * @param {Object} bridge
217
- * @param {string} workerId
218
- */
219
- async function ensureOnImagine(bridge, workerId) {
220
- try {
221
- const pageInfo = await bridge.getPageInfo(workerId);
222
- const url = pageInfo?.url || '';
223
-
224
- if (url.includes('grok.com/imagine') && !url.includes('/imagine/post/')) {
225
- try {
226
- await bridge.waitFor(SEL.promptEditor, 5000, workerId);
227
- return;
228
- } catch {
229
- await bridge.refresh(workerId);
230
- await bridge.sleep(3000);
231
- }
232
- }
233
- } catch { /* not on page */ }
234
-
235
- await bridge.navigate('https://grok.com/imagine', workerId);
236
- await bridge.sleep(3000);
237
- await bridge.waitFor(SEL.promptEditor, 15000, workerId);
238
- }
239
-
240
- /**
241
- * Generate image via WebSocket (text-to-image)
242
- * @param {Object} bridge
243
- * @param {string} prompt
244
- * @param {Object} params
245
- * @returns {Promise<Object>}
246
- */
247
- async function generateImage(bridge, prompt, params) {
248
- const { outputDir, filename, globalStyle, workerId } = params;
249
- const fullPrompt = globalStyle ? `${globalStyle}, ${prompt}` : prompt;
250
-
251
- await mkdir(outputDir, { recursive: true });
252
-
253
- // Generate via WebSocket
254
- const wsResult = await bridge.generateImageWS(fullPrompt, {}, workerId || null);
255
-
256
- if (!wsResult?.imageUrl) {
257
- throw new Error('No image URL from WebSocket generation');
258
- }
259
-
260
- // Download image via bridge (authenticated)
261
- const imageData = await bridge.fetchImage(wsResult.imageUrl, workerId || null);
262
-
263
- // Save to file
264
- const outputName = filename || `grok-${Date.now()}`;
265
- const outputPath = path.join(outputDir, `${outputName}.png`);
266
-
267
- const base64Data = imageData.dataUrl.split(',')[1];
268
- await writeFile(outputPath, Buffer.from(base64Data, 'base64'));
269
-
270
- return {
271
- imagePath: outputPath,
272
- imageUrl: wsResult.imageUrl,
273
- prompt: fullPrompt,
274
- };
275
- }
276
-
277
- /**
278
- * Edit image with reference (upload + prompt)
279
- * @param {Object} bridge
280
- * @param {string} prompt
281
- * @param {string} referencePath
282
- * @param {Object} params
283
- * @returns {Promise<Object>}
284
- */
285
- async function editImage(bridge, prompt, referencePath, params) {
286
- const { outputDir, filename, workerId } = params;
287
- await mkdir(outputDir, { recursive: true });
288
-
289
- // Navigate to /imagine
290
- await ensureOnImagine(bridge, workerId || null);
291
-
292
- // Upload reference image
293
- const imageBuffer = await readFile(path.resolve(referencePath));
294
- const base64 = imageBuffer.toString('base64');
295
- const ext = path.extname(referencePath).toLowerCase();
296
- const mimeType = ext === '.png' ? 'image/png' : 'image/jpeg';
297
-
298
- await bridge.uploadFile(base64, mimeType, `image${ext}`, workerId || null);
299
- await bridge.sleep(2000);
300
-
301
- // Enter edit prompt
302
- await bridge.waitFor(SEL.editPrompt, 15000, workerId || null);
303
- await bridge.type(SEL.editPrompt, prompt, workerId || null);
304
-
305
- // Submit
306
- await bridge.click(SEL.sendBtn, workerId || null);
307
-
308
- // Wait for result via WebSocket
309
- const wsResult = await bridge.waitForImageComplete(120000, workerId || null);
310
-
311
- if (!wsResult?.firstUrl) {
312
- throw new Error('No image from edit generation');
313
- }
314
-
315
- // Download
316
- const imageData = await bridge.fetchImage(wsResult.firstUrl, workerId || null);
317
- const outputName = filename || `grok-edit-${Date.now()}`;
318
- const outputPath = path.join(outputDir, `${outputName}.png`);
319
-
320
- const base64Data = imageData.dataUrl.split(',')[1];
321
- await writeFile(outputPath, Buffer.from(base64Data, 'base64'));
322
-
323
- return { imagePath: outputPath, imageUrl: wsResult.firstUrl };
324
- }
325
-
326
- /**
327
- * Generate video from image (image-to-video)
328
- * @param {Object} bridge
329
- * @param {Object} params
330
- * @returns {Promise<Object>}
331
- */
332
- async function generateVideo(bridge, params) {
333
- const { imagePath, videoPrompt, outputDir, filename, enableUpscale, workerId } = params;
334
- await mkdir(outputDir, { recursive: true });
335
-
336
- // Navigate to /imagine
337
- await ensureOnImagine(bridge, workerId || null);
338
-
339
- // Upload image
340
- const imageBuffer = await readFile(path.resolve(imagePath));
341
- const base64 = imageBuffer.toString('base64');
342
- const ext = path.extname(imagePath).toLowerCase();
343
- const mimeType = ext === '.png' ? 'image/png' : 'image/jpeg';
344
-
345
- await bridge.uploadFile(base64, mimeType, `image${ext}`, workerId || null);
346
- await bridge.sleep(3000);
347
-
348
- // Enter video prompt
349
- if (videoPrompt) {
350
- await bridge.waitFor(SEL.videoPrompt, 15000, workerId || null);
351
- await bridge.type(SEL.videoPrompt, videoPrompt, workerId || null);
352
- await bridge.sleep(500);
353
- }
354
-
355
- // Show zones and submit
356
- await bridge.showZones('all', workerId || null);
357
- await bridge.sleep(500);
358
-
359
- // Find and click submit button (zone-based)
360
- await bridge.click(SEL.sendBtn, workerId || null);
361
- try { await bridge.hideZones(workerId || null); } catch { /* ignore */ }
362
-
363
- // Wait for video
364
- const videoUrl = await waitForVideo(bridge, 90000, workerId || null);
365
-
366
- // Download video
367
- const outputName = filename || `grok-video-${Date.now()}`;
368
- const outputPath = path.join(outputDir, `${outputName}.mp4`);
369
-
370
- const videoResponse = await fetch(videoUrl);
371
- if (!videoResponse.ok) throw new Error(`Failed to download video: ${videoResponse.status}`);
372
- const buffer = await videoResponse.arrayBuffer();
373
- await writeFile(outputPath, Buffer.from(buffer));
374
-
375
- const result = { videoPath: outputPath, videoUrl };
376
-
377
- // HD upscale if requested
378
- if (enableUpscale) {
379
- try {
380
- await triggerUpscale(bridge, workerId || null);
381
- const hdUrl = await waitForHD(bridge, 120000, workerId || null, videoUrl);
382
-
383
- const hdPath = path.join(outputDir, `${outputName}_hd.mp4`);
384
- const hdResponse = await fetch(hdUrl);
385
- if (hdResponse.ok) {
386
- const hdBuffer = await hdResponse.arrayBuffer();
387
- await writeFile(hdPath, Buffer.from(hdBuffer));
388
- result.hdVideoPath = hdPath;
389
- result.hdVideoUrl = hdUrl;
390
- }
391
- } catch (e) {
392
- result.upscaleError = e.message;
393
- }
394
- }
395
-
396
- return result;
397
- }
398
-
399
- // --- Helper workflows ---
400
-
401
- /**
402
- * Wait for video element with mp4 src
403
- * @param {Object} bridge
404
- * @param {number} timeout
405
- * @param {string} workerId
406
- * @param {string} prevUrl
407
- * @returns {Promise<string>}
408
- */
409
- async function waitForVideo(bridge, timeout = 90000, workerId = null, prevUrl = null) {
410
- const start = Date.now();
411
-
412
- while (Date.now() - start < timeout) {
413
- await bridge.sleep(3000);
414
-
415
- // Check rate limit
416
- try {
417
- const errors = await bridge.queryAll(SEL.errorToast, workerId);
418
- if (errors.count > 0) throw new Error('RATE_LIMIT_REACHED');
419
- } catch (e) {
420
- if (e.message === 'RATE_LIMIT_REACHED') throw e;
421
- }
422
-
423
- // Check content moderation
424
- try {
425
- const moderated = await bridge.queryAll(SEL.moderatedContent, workerId);
426
- if (moderated.count > 0) throw new Error('CONTENT_MODERATED');
427
- } catch (e) {
428
- if (e.message === 'CONTENT_MODERATED') throw e;
429
- }
430
-
431
- // Check preference selection (A/B test) — refresh to skip
432
- try {
433
- const prefs = await bridge.queryAll(SEL.preferenceBtn, workerId);
434
- if (prefs.count >= 2) {
435
- await bridge.refresh(workerId);
436
- await bridge.sleep(3000);
437
- continue;
438
- }
439
- } catch { /* ignore */ }
440
-
441
- // Check for video
442
- try {
443
- const result = await bridge.getAttribute(SEL.video, 'src', workerId);
444
- const videoUrl = result.value;
445
- if (videoUrl?.includes('.mp4')) {
446
- if (prevUrl && videoUrl === prevUrl) continue;
447
- return videoUrl;
448
- }
449
- } catch { /* not yet */ }
450
- }
451
-
452
- throw new Error('Timeout waiting for video');
453
- }
454
-
455
- /**
456
- * Trigger HD upscale via menu
457
- * @param {Object} bridge
458
- * @param {string} workerId
459
- */
460
- async function triggerUpscale(bridge, workerId) {
461
- await bridge.showZones('all', workerId);
462
- await bridge.sleep(500);
463
- // Menu button→upscale is zone-dependent, use click by text as fallback
464
- try {
465
- await bridge.click('[aria-label="Больше опций"]', workerId);
466
- await bridge.sleep(1000);
467
- // Click 5th menu item (upscale)
468
- await bridge.click('[role="menuitem"]:nth-child(5)', workerId);
469
- } catch {
470
- // Fallback
471
- await bridge.sendCommand('clickByText', { text: 'Улучшить' }, 30000, workerId);
472
- }
473
- try { await bridge.hideZones(workerId); } catch { /* ignore */ }
474
- }
475
-
476
- /**
477
- * Wait for HD video after upscale
478
- * @param {Object} bridge
479
- * @param {number} timeout
480
- * @param {string} workerId
481
- * @param {string} sdUrl
482
- * @returns {Promise<string>}
483
- */
484
- async function waitForHD(bridge, timeout = 120000, workerId = null, sdUrl = null) {
485
- const start = Date.now();
486
-
487
- while (Date.now() - start < timeout) {
488
- await bridge.sleep(3000);
489
-
490
- try {
491
- const hdExists = await bridge.waitFor(SEL.hdButton, 5000, workerId).catch(() => null);
492
- if (hdExists) {
493
- const result = await bridge.getAttribute(SEL.video, 'src', workerId);
494
- if (result.value?.includes('.mp4')) return result.value;
495
- }
496
-
497
- if (sdUrl) {
498
- const result = await bridge.getAttribute(SEL.video, 'src', workerId);
499
- if (result.value?.includes('.mp4') && result.value !== sdUrl) return result.value;
500
- }
501
- } catch { /* not yet */ }
502
- }
503
-
504
- throw new Error('Timeout waiting for HD video');
505
- }
506
-
507
- // --- Batch processing ---
508
-
509
- /**
510
- * Batch image generation
511
- * @param {Object} bridge
512
- * @param {Object} params
513
- * @returns {Promise<Object>}
514
- */
515
- async function batchImages(bridge, params) {
516
- const { segments, outputDir, globalStyle } = params;
517
- const results = {};
518
- await mkdir(outputDir, { recursive: true });
519
-
520
- for (const seg of segments) {
521
- try {
522
- const result = await generateImage(bridge, seg.prompt || seg.text, {
523
- ...params,
524
- filename: seg.promptId || seg.id,
525
- });
526
- results[seg.promptId || seg.id] = result.imagePath;
527
- } catch (e) {
528
- console.error(`[GrokBatch] Image failed: ${seg.promptId} - ${e.message}`);
529
- results[seg.promptId || seg.id] = null;
530
- }
531
- }
532
-
533
- return { total: segments.length, success: Object.values(results).filter(Boolean).length, results };
534
- }
535
-
536
- /**
537
- * Batch video generation
538
- * @param {Object} bridge
539
- * @param {Object} params
540
- * @returns {Promise<Object>}
541
- */
542
- async function batchVideos(bridge, params) {
543
- const { segments, outputDir } = params;
544
- const results = {};
545
- await mkdir(outputDir, { recursive: true });
546
-
547
- for (const seg of segments) {
548
- if (!seg.imagePath) continue;
549
-
550
- try {
551
- const result = await generateVideo(bridge, {
552
- ...params,
553
- imagePath: seg.imagePath,
554
- videoPrompt: seg.videoPrompt || seg.cameraPrompt || '',
555
- filename: seg.promptId || seg.id,
556
- });
557
- results[seg.promptId || seg.id] = result.videoPath;
558
- } catch (e) {
559
- console.error(`[GrokBatch] Video failed: ${seg.promptId} - ${e.message}`);
560
- results[seg.promptId || seg.id] = null;
561
- }
562
- }
563
-
564
- return { total: segments.length, success: Object.values(results).filter(Boolean).length, results };
565
- }