windmill-components 1.677.1 → 1.687.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 (354) hide show
  1. package/package/components/AppConnectInner.svelte +6 -0
  2. package/package/components/CiTestResults.svelte +64 -0
  3. package/package/components/CiTestResults.svelte.d.ts +7 -0
  4. package/package/components/CompareWorkspaces.svelte +626 -418
  5. package/package/components/DBManager.svelte +35 -4
  6. package/package/components/DBManager.svelte.d.ts +2 -0
  7. package/package/components/DBManagerContent.svelte +3 -1
  8. package/package/components/DBManagerContent.svelte.d.ts +3 -0
  9. package/package/components/DBManagerDrawer.svelte +145 -3
  10. package/package/components/DBTableEditor.svelte +14 -4
  11. package/package/components/DatatablePicker.svelte +2 -5
  12. package/package/components/DatatableSchemaDiff.svelte +531 -0
  13. package/package/components/DatatableSchemaDiff.svelte.d.ts +29 -0
  14. package/package/components/DedicatedWorkersSelector.svelte +4 -2
  15. package/package/components/DefaultTagsInner.svelte +42 -2
  16. package/package/components/DeployWorkspaceDrawer.svelte +1 -1
  17. package/package/components/Dev.svelte +20 -3
  18. package/package/components/Editor.svelte +1 -1
  19. package/package/components/EditorBar.svelte +1 -1
  20. package/package/components/EditorBar.svelte.d.ts +1 -1
  21. package/package/components/FlowStatusViewerInner.svelte +269 -220
  22. package/package/components/FlowTimeline.svelte +1 -1
  23. package/package/components/FolderEditor.svelte +189 -4
  24. package/package/components/ForkWorkspaceBanner.svelte +82 -11
  25. package/package/components/GlobalUserOffboardingModal.svelte +293 -0
  26. package/package/components/GlobalUserOffboardingModal.svelte.d.ts +10 -0
  27. package/package/components/InstanceSettings.svelte +22 -3
  28. package/package/components/Login.svelte +22 -10
  29. package/package/components/ModuleTest.svelte +2 -1
  30. package/package/components/NoMainFuncBadge.svelte +1 -1
  31. package/package/components/OffboardItemsBox.svelte +56 -0
  32. package/package/components/OffboardItemsBox.svelte.d.ts +12 -0
  33. package/package/components/OffboardReassignControls.svelte +47 -0
  34. package/package/components/OffboardReassignControls.svelte.d.ts +20 -0
  35. package/package/components/OffboardWorkspaceSection.svelte +110 -0
  36. package/package/components/OffboardWorkspaceSection.svelte.d.ts +24 -0
  37. package/package/components/OnBehalfOfSelector.svelte +21 -3
  38. package/package/components/OnBehalfOfSelector.svelte.d.ts +7 -0
  39. package/package/components/QueueAlerts.svelte +10 -10
  40. package/package/components/ResourcePicker.svelte +2 -2
  41. package/package/components/ScriptBuilder.svelte +52 -11
  42. package/package/components/ScriptEditor.svelte +1 -3
  43. package/package/components/ScriptEditor.svelte.d.ts +1 -1
  44. package/package/components/ShareModal.svelte +236 -98
  45. package/package/components/SuperadminSettingsInner.svelte +362 -315
  46. package/package/components/UserOffboardingModal.svelte +238 -0
  47. package/package/components/UserOffboardingModal.svelte.d.ts +10 -0
  48. package/package/components/WorkspaceDeployLayout.svelte +3 -3
  49. package/package/components/WorkspaceDeployLayout.svelte.d.ts +1 -0
  50. package/package/components/apps/editor/inlineScriptsPanel/InlineScriptRunnableByPath.svelte +4 -2
  51. package/package/components/apps/editor/settingsPanel/mainInput/RunnableSelector.svelte +12 -0
  52. package/package/components/assets/AssetsDropdownButton.svelte +1 -1
  53. package/package/components/common/confirmationModal/ConfirmationModal.svelte +1 -1
  54. package/package/components/common/table/AppRow.svelte +3 -3
  55. package/package/components/common/table/FlowRow.svelte +3 -3
  56. package/package/components/common/table/RawAppRow.svelte +4 -4
  57. package/package/components/common/table/Row.svelte +6 -2
  58. package/package/components/common/table/ScriptRow.svelte +11 -3
  59. package/package/components/copilot/chat/AIChatManager.svelte.js +2 -2
  60. package/package/components/copilot/chat/anthropic.d.ts +7 -1
  61. package/package/components/copilot/chat/anthropic.js +5 -2
  62. package/package/components/copilot/chat/app/core.js +129 -1
  63. package/package/components/copilot/chat/app/core.test.js +192 -0
  64. package/package/components/copilot/chat/chatLoop.d.ts +3 -0
  65. package/package/components/copilot/chat/chatLoop.js +13 -5
  66. package/package/components/copilot/chat/flow/FlowAIChat.svelte +55 -76
  67. package/package/components/copilot/chat/flow/core.d.ts +13 -3
  68. package/package/components/copilot/chat/flow/core.js +467 -116
  69. package/package/components/copilot/chat/flow/helperUtils.d.ts +19 -0
  70. package/package/components/copilot/chat/flow/helperUtils.js +68 -0
  71. package/package/components/copilot/chat/flow/helperUtils.test.js +116 -0
  72. package/package/components/copilot/chat/flow/inlineScriptsUtils.d.ts +5 -24
  73. package/package/components/copilot/chat/flow/inlineScriptsUtils.js +30 -55
  74. package/package/components/copilot/chat/flow/utils.test.js +59 -0
  75. package/package/components/copilot/chat/openai-responses.d.ts +7 -1
  76. package/package/components/copilot/chat/openai-responses.js +5 -2
  77. package/package/components/copilot/chat/shared.d.ts +1 -2
  78. package/package/components/copilot/chat/shared.js +94 -52
  79. package/package/components/copilot/chat/tokenUsage.d.ts +23 -0
  80. package/package/components/copilot/chat/tokenUsage.js +42 -0
  81. package/package/components/copilot/lib.d.ts +5 -1
  82. package/package/components/copilot/lib.js +21 -5
  83. package/package/components/deploymentRequest/DeploymentRequestPanel.svelte +337 -0
  84. package/package/components/deploymentRequest/DeploymentRequestPanel.svelte.d.ts +15 -0
  85. package/package/components/details/CopyableCodeBlock.svelte +18 -8
  86. package/package/components/details/CopyableCodeBlock.svelte.d.ts +1 -0
  87. package/package/components/flows/FlowAssetsHandler.svelte +19 -21
  88. package/package/components/flows/agentToolTree.d.ts +17 -0
  89. package/package/components/flows/agentToolTree.js +114 -0
  90. package/package/components/flows/agentToolTree.test.d.ts +1 -0
  91. package/package/components/flows/agentToolTree.test.js +86 -0
  92. package/package/components/flows/agentToolUtils.d.ts +0 -5
  93. package/package/components/flows/agentToolUtils.js +0 -49
  94. package/package/components/flows/content/FlowLoop.svelte +7 -4
  95. package/package/components/flows/content/FlowModuleDeleteAfterUse.svelte +15 -7
  96. package/package/components/flows/content/FlowSettings.svelte +29 -0
  97. package/package/components/flows/dfs.d.ts +6 -2
  98. package/package/components/flows/dfs.js +19 -11
  99. package/package/components/flows/flowDeleteController.d.ts +32 -0
  100. package/package/components/flows/flowDeleteController.js +54 -0
  101. package/package/components/flows/flowDeleteController.test.d.ts +1 -0
  102. package/package/components/flows/flowDeleteController.test.js +121 -0
  103. package/package/components/flows/flowDeleteUtils.d.ts +48 -0
  104. package/package/components/flows/flowDeleteUtils.js +150 -0
  105. package/package/components/flows/flowDeleteUtils.test.d.ts +1 -0
  106. package/package/components/flows/flowDeleteUtils.test.js +131 -0
  107. package/package/components/flows/flowDiff.d.ts +2 -47
  108. package/package/components/flows/flowDiff.js +16 -293
  109. package/package/components/flows/flowDiff.testUtils.d.ts +8 -0
  110. package/package/components/flows/flowDiff.testUtils.js +26 -0
  111. package/package/components/flows/flowDiffManager.svelte.js +20 -75
  112. package/package/components/flows/flowDiffManager.svelte.test.js +103 -2
  113. package/package/components/flows/flowExplorer.d.ts +4 -0
  114. package/package/components/flows/flowExplorer.js +7 -30
  115. package/package/components/flows/flowState.d.ts +1 -0
  116. package/package/components/flows/flowStateUtils.svelte.js +6 -1
  117. package/package/components/flows/flowTree.d.ts +91 -0
  118. package/package/components/flows/flowTree.js +326 -0
  119. package/package/components/flows/flowTree.test.d.ts +1 -0
  120. package/package/components/flows/flowTree.test.js +236 -0
  121. package/package/components/flows/map/FlowJobsMenu.svelte +36 -30
  122. package/package/components/flows/map/FlowModuleSchemaItem.svelte +1 -1
  123. package/package/components/flows/map/FlowModuleSchemaMap.svelte +70 -227
  124. package/package/components/flows/map/FlowModuleSchemaMap.svelte.d.ts +0 -2
  125. package/package/components/flows/pickers/PickHubScriptQuick.svelte +2 -2
  126. package/package/components/flows/previousResults.js +13 -41
  127. package/package/components/flows/previousResults.test.d.ts +1 -0
  128. package/package/components/flows/previousResults.test.js +65 -0
  129. package/package/components/flows/propPicker/OutputPicker.svelte +2 -1
  130. package/package/components/flows/propPicker/OutputPickerInner.svelte +41 -4
  131. package/package/components/flows/propPicker/StepHistory.svelte +9 -1
  132. package/package/components/git_sync/GitSyncContext.svelte.js +11 -5
  133. package/package/components/git_sync/GitSyncRepositoryCard.svelte +2 -29
  134. package/package/components/git_sync/PullWorkspaceModal.svelte +6 -7
  135. package/package/components/graph/FlowGraphV2.svelte +2 -2
  136. package/package/components/graph/FlowGraphV2.svelte.d.ts +1 -0
  137. package/package/components/graph/groupedModulesProxy.svelte.d.ts +10 -0
  138. package/package/components/graph/groupedModulesProxy.svelte.js +17 -1
  139. package/package/components/graph/renderers/triggers/TriggersBadge.svelte +5 -2
  140. package/package/components/home/HomeConnectDrawer.svelte +125 -0
  141. package/package/components/home/HomeConnectDrawer.svelte.d.ts +5 -0
  142. package/package/components/icons/GithubIcon.svelte +4 -4
  143. package/package/components/icons/GithubIcon.svelte.d.ts +5 -2
  144. package/package/components/instanceSettings/ExternalJwtTokens.svelte +85 -0
  145. package/package/components/instanceSettings/ExternalJwtTokens.svelte.d.ts +12 -0
  146. package/package/components/instanceSettings/GhesAppSettings.svelte +17 -0
  147. package/package/components/instanceSettings/IndexerMemorySettings.svelte +56 -29
  148. package/package/components/instanceSettings/SecretBackendConfig.svelte +9 -2
  149. package/package/components/instanceSettings.d.ts +1 -0
  150. package/package/components/instanceSettings.js +42 -8
  151. package/package/components/offboarding-utils.d.ts +11 -0
  152. package/package/components/offboarding-utils.js +100 -0
  153. package/package/components/raw_apps/RawAppDataTableDrawer.svelte +1 -1
  154. package/package/components/raw_apps/RawAppEditor.svelte +27 -0
  155. package/package/components/raw_apps/RawAppEditorHeader.svelte +6 -1
  156. package/package/components/raw_apps/RawAppEditorHeader.svelte.d.ts +1 -0
  157. package/package/components/raw_apps/RawAppYamlEditor.svelte +81 -0
  158. package/package/components/raw_apps/RawAppYamlEditor.svelte.d.ts +20 -0
  159. package/package/components/raw_apps/datatableUtils.svelte.js +1 -1
  160. package/package/components/runs/runsFilter.d.ts +1 -1
  161. package/package/components/script_builder.d.ts +1 -1
  162. package/package/components/select/Select.svelte +2 -1
  163. package/package/components/select/Select.svelte.d.ts +1 -0
  164. package/package/components/settings/CreateToken.svelte +113 -64
  165. package/package/components/settings/CreateToken.svelte.d.ts +3 -0
  166. package/package/components/settings/WorkspaceUserSettings.svelte +34 -28
  167. package/package/components/sidebar/SidebarContent.svelte +58 -2
  168. package/package/components/sidebar/WorkspaceMenu.svelte +8 -4
  169. package/package/components/triggers/AddTriggersButton.svelte +11 -0
  170. package/package/components/triggers/PermissionedAsLine.svelte +37 -3
  171. package/package/components/triggers/PermissionedAsLine.svelte.d.ts +6 -0
  172. package/package/components/triggers/TriggersEditor.svelte +5 -1
  173. package/package/components/triggers/TriggersWrapper.svelte +10 -0
  174. package/package/components/triggers/email/EmailTriggerEditorInner.svelte +13 -11
  175. package/package/components/triggers/gcp/GcpTriggerEditorInner.svelte +13 -11
  176. package/package/components/triggers/http/RouteEditorConfigSection.svelte +15 -7
  177. package/package/components/triggers/http/RouteEditorInner.svelte +14 -14
  178. package/package/components/triggers/http/RoutesGenerator.svelte +6 -1
  179. package/package/components/triggers/http/RoutesPanel.svelte +1 -1
  180. package/package/components/triggers/http/utils.d.ts +1 -1
  181. package/package/components/triggers/http/utils.js +2 -2
  182. package/package/components/triggers/kafka/KafkaTriggerEditorInner.svelte +13 -11
  183. package/package/components/triggers/mqtt/MqttTriggerEditorInner.svelte +13 -11
  184. package/package/components/triggers/native/NativeTriggerEditor.svelte +3 -0
  185. package/package/components/triggers/native/services/github/GitHubTriggerForm.svelte +118 -0
  186. package/package/components/triggers/native/services/github/GitHubTriggerForm.svelte.d.ts +17 -0
  187. package/package/components/triggers/native/utils.js +14 -0
  188. package/package/components/triggers/nats/NatsTriggerEditor.svelte.d.ts +4 -3
  189. package/package/components/triggers/nats/NatsTriggerEditorInner.svelte +13 -11
  190. package/package/components/triggers/postgres/PostgresTriggerEditor.svelte.d.ts +4 -3
  191. package/package/components/triggers/postgres/PostgresTriggerEditorInner.svelte +13 -11
  192. package/package/components/triggers/schedules/ScheduleEditorInner.svelte +13 -11
  193. package/package/components/triggers/sqs/SqsTriggerEditor.svelte.d.ts +4 -3
  194. package/package/components/triggers/sqs/SqsTriggerEditorInner.svelte +13 -11
  195. package/package/components/triggers/triggers.svelte.js +1 -0
  196. package/package/components/triggers/utils.js +27 -6
  197. package/package/components/triggers/websocket/WebsocketTriggerEditorInner.svelte +13 -11
  198. package/package/components/triggers.d.ts +1 -1
  199. package/package/components/useFolderDefaultPermissionedAs.svelte.d.ts +13 -0
  200. package/package/components/useFolderDefaultPermissionedAs.svelte.js +63 -0
  201. package/package/components/workspaceSettings/CreateWorkspace.svelte +16 -677
  202. package/package/components/workspaceSettings/CreateWorkspaceInner.svelte +604 -0
  203. package/package/components/workspaceSettings/CreateWorkspaceInner.svelte.d.ts +7 -0
  204. package/package/components/workspaceSettings/CustomInstanceDbSelect.svelte +27 -25
  205. package/package/components/workspaceSettings/CustomInstanceDbWizardModal.svelte +46 -8
  206. package/package/components/workspaceSettings/DataTableSettings.svelte +27 -22
  207. package/package/components/workspaceSettings/DucklakeSettings.svelte +1 -1
  208. package/package/components/workspaceSettings/ForkDatatableSection.svelte +228 -0
  209. package/package/components/workspaceSettings/ForkDatatableSection.svelte.d.ts +28 -0
  210. package/package/components/workspaceSettings/GitSyncFilterSettings.svelte +8 -2
  211. package/package/components/workspaceSettings/RulesetEditor.svelte +27 -2
  212. package/package/components/workspaceSettings/VolumeStorageSettings.svelte +1 -1
  213. package/package/components/workspaceSettings/WorkspaceIntegrations.svelte +17 -1
  214. package/package/consts.d.ts +3 -0
  215. package/package/consts.js +10 -0
  216. package/package/gen/core/OpenAPI.js +1 -1
  217. package/package/gen/schemas.gen.d.ts +485 -19
  218. package/package/gen/schemas.gen.js +489 -20
  219. package/package/gen/services.gen.d.ts +229 -2
  220. package/package/gen/services.gen.js +463 -1
  221. package/package/gen/types.gen.d.ts +866 -29
  222. package/package/githubApp.js +5 -1
  223. package/package/hubPaths.json +1 -4
  224. package/package/infer.js +13 -1
  225. package/package/infer.svelte.js +10 -1
  226. package/package/monaco_workers/sqlTypePlugin.worker.d.ts +10 -0
  227. package/package/monaco_workers/sqlTypePlugin.worker.js +39 -0
  228. package/package/script_helpers.d.ts +8 -2
  229. package/package/script_helpers.js +14 -0
  230. package/package/stores.d.ts +4 -0
  231. package/package/stores.js +1 -0
  232. package/package/system_prompts/prompts.d.ts +4 -3
  233. package/package/system_prompts/prompts.js +270 -20
  234. package/package/templates/ci_test_bun.ts.template +19 -0
  235. package/package/templates/ci_test_python.py.template +18 -0
  236. package/package/utils_workspace_deploy.d.ts +8 -8
  237. package/package/utils_workspace_deploy.js +86 -420
  238. package/package.json +3 -3
  239. package/package/components/copilot/chat/__tests__/app/appChat.eval.test.js +0 -153
  240. package/package/components/copilot/chat/__tests__/app/appEvalComparison.d.ts +0 -21
  241. package/package/components/copilot/chat/__tests__/app/appEvalComparison.js +0 -136
  242. package/package/components/copilot/chat/__tests__/app/appEvalHelpers.d.ts +0 -15
  243. package/package/components/copilot/chat/__tests__/app/appEvalHelpers.js +0 -107
  244. package/package/components/copilot/chat/__tests__/app/appEvalRunner.d.ts +0 -50
  245. package/package/components/copilot/chat/__tests__/app/appEvalRunner.js +0 -93
  246. package/package/components/copilot/chat/__tests__/app/appFixtureLoader.d.ts +0 -29
  247. package/package/components/copilot/chat/__tests__/app/appFixtureLoader.js +0 -134
  248. package/package/components/copilot/chat/__tests__/app/appResultsWriter.d.ts +0 -30
  249. package/package/components/copilot/chat/__tests__/app/appResultsWriter.js +0 -197
  250. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/createFolder/main.d.ts +0 -10
  251. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/createFolder/main.js +0 -9
  252. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/createFolder/meta.json +0 -4
  253. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/deleteItem/main.d.ts +0 -6
  254. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/deleteItem/main.js +0 -5
  255. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/deleteItem/meta.json +0 -4
  256. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/listFiles/main.d.ts +0 -12
  257. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/listFiles/main.js +0 -14
  258. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/listFiles/meta.json +0 -4
  259. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/listFolders/main.d.ts +0 -8
  260. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/listFolders/main.js +0 -25
  261. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/listFolders/meta.json +0 -4
  262. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/moveItem/main.d.ts +0 -7
  263. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/moveItem/main.js +0 -5
  264. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/moveItem/meta.json +0 -4
  265. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/renameItem/main.d.ts +0 -8
  266. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/renameItem/main.js +0 -5
  267. package/package/components/copilot/chat/__tests__/app/initial/file_manager/backend/renameItem/meta.json +0 -4
  268. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/Breadcrumb.d.ts +0 -10
  269. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/Breadcrumb.tsx +0 -26
  270. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/FileItem.d.ts +0 -10
  271. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/FileItem.tsx +0 -79
  272. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/FileList.d.ts +0 -10
  273. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/FileList.tsx +0 -46
  274. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/FolderTree.d.ts +0 -10
  275. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/FolderTree.tsx +0 -56
  276. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/Toolbar.d.ts +0 -6
  277. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/components/Toolbar.tsx +0 -59
  278. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/index.d.ts +0 -16
  279. package/package/components/copilot/chat/__tests__/app/initial/file_manager/frontend/index.tsx +0 -119
  280. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/addToCart/main.d.ts +0 -15
  281. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/addToCart/main.js +0 -14
  282. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/addToCart/meta.json +0 -4
  283. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/calculateTotal/main.d.ts +0 -14
  284. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/calculateTotal/main.js +0 -5
  285. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/calculateTotal/meta.json +0 -4
  286. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/getProducts/main.d.ts +0 -6
  287. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/getProducts/main.js +0 -41
  288. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/getProducts/meta.json +0 -4
  289. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/removeFromCart/main.d.ts +0 -15
  290. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/removeFromCart/main.js +0 -3
  291. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/backend/removeFromCart/meta.json +0 -4
  292. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/components/Cart.d.ts +0 -9
  293. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/components/Cart.tsx +0 -51
  294. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/components/ProductCard.d.ts +0 -8
  295. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/components/ProductCard.tsx +0 -27
  296. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/components/ProductList.d.ts +0 -8
  297. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/components/ProductList.tsx +0 -18
  298. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/index.d.ts +0 -12
  299. package/package/components/copilot/chat/__tests__/app/initial/shopping_cart/frontend/index.tsx +0 -81
  300. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/backend/decrementCounter/main.d.ts +0 -3
  301. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/backend/decrementCounter/main.js +0 -3
  302. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/backend/decrementCounter/meta.json +0 -4
  303. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/backend/incrementCounter/main.d.ts +0 -3
  304. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/backend/incrementCounter/main.js +0 -3
  305. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/backend/incrementCounter/meta.json +0 -4
  306. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/frontend/index.d.ts +0 -2
  307. package/package/components/copilot/chat/__tests__/app/initial/test1_counter_app/frontend/index.tsx +0 -38
  308. package/package/components/copilot/chat/__tests__/app/variants/baseline.d.ts +0 -6
  309. package/package/components/copilot/chat/__tests__/app/variants/baseline.js +0 -10
  310. package/package/components/copilot/chat/__tests__/app/variants/index.d.ts +0 -3
  311. package/package/components/copilot/chat/__tests__/app/variants/index.js +0 -3
  312. package/package/components/copilot/chat/__tests__/app/variants/streamlined.d.ts +0 -6
  313. package/package/components/copilot/chat/__tests__/app/variants/streamlined.js +0 -137
  314. package/package/components/copilot/chat/__tests__/flow/expected/test1.json +0 -134
  315. package/package/components/copilot/chat/__tests__/flow/expected/test2.json +0 -183
  316. package/package/components/copilot/chat/__tests__/flow/expected/test3.json +0 -204
  317. package/package/components/copilot/chat/__tests__/flow/expected/test4.json +0 -175
  318. package/package/components/copilot/chat/__tests__/flow/expected/test5_modify_simple.json +0 -68
  319. package/package/components/copilot/chat/__tests__/flow/expected/test6_modify_medium.json +0 -142
  320. package/package/components/copilot/chat/__tests__/flow/expected/test7_modify_complex.json +0 -136
  321. package/package/components/copilot/chat/__tests__/flow/flowChat.eval.test.js +0 -294
  322. package/package/components/copilot/chat/__tests__/flow/flowEvalComparison.d.ts +0 -17
  323. package/package/components/copilot/chat/__tests__/flow/flowEvalComparison.js +0 -49
  324. package/package/components/copilot/chat/__tests__/flow/flowEvalHelpers.d.ts +0 -12
  325. package/package/components/copilot/chat/__tests__/flow/flowEvalHelpers.js +0 -79
  326. package/package/components/copilot/chat/__tests__/flow/flowEvalRunner.d.ts +0 -50
  327. package/package/components/copilot/chat/__tests__/flow/flowEvalRunner.js +0 -102
  328. package/package/components/copilot/chat/__tests__/flow/initial/test5_initial.json +0 -53
  329. package/package/components/copilot/chat/__tests__/flow/initial/test6_initial.json +0 -68
  330. package/package/components/copilot/chat/__tests__/flow/initial/test7_initial.json +0 -120
  331. package/package/components/copilot/chat/__tests__/flow/variants/baseline.d.ts +0 -6
  332. package/package/components/copilot/chat/__tests__/flow/variants/baseline.js +0 -10
  333. package/package/components/copilot/chat/__tests__/flow/variants/index.d.ts +0 -3
  334. package/package/components/copilot/chat/__tests__/flow/variants/index.js +0 -3
  335. package/package/components/copilot/chat/__tests__/flow/variants/minimal-single-tool.d.ts +0 -15
  336. package/package/components/copilot/chat/__tests__/flow/variants/minimal-single-tool.js +0 -388
  337. package/package/components/copilot/chat/__tests__/shared/baseEvalRunner.d.ts +0 -45
  338. package/package/components/copilot/chat/__tests__/shared/baseEvalRunner.js +0 -121
  339. package/package/components/copilot/chat/__tests__/shared/baseLLMEvaluator.d.ts +0 -28
  340. package/package/components/copilot/chat/__tests__/shared/baseLLMEvaluator.js +0 -96
  341. package/package/components/copilot/chat/__tests__/shared/baseResultsWriter.d.ts +0 -32
  342. package/package/components/copilot/chat/__tests__/shared/baseResultsWriter.js +0 -130
  343. package/package/components/copilot/chat/__tests__/shared/baseVariants.d.ts +0 -45
  344. package/package/components/copilot/chat/__tests__/shared/baseVariants.js +0 -57
  345. package/package/components/copilot/chat/__tests__/shared/index.d.ts +0 -10
  346. package/package/components/copilot/chat/__tests__/shared/index.js +0 -5
  347. package/package/components/copilot/chat/__tests__/shared/types.d.ts +0 -105
  348. package/package/components/copilot/chat/__tests__/shared/types.js +0 -9
  349. package/package/components/copilot/chat/flow/utils.d.ts +0 -14
  350. package/package/components/copilot/chat/flow/utils.js +0 -108
  351. package/package/components/flows/agentToolUtils.test.js +0 -55
  352. /package/package/components/copilot/chat/{__tests__/app/appChat.eval.test.d.ts → app/core.test.d.ts} +0 -0
  353. /package/package/components/copilot/chat/{__tests__/flow/flowChat.eval.test.d.ts → flow/helperUtils.test.d.ts} +0 -0
  354. /package/package/components/{flows/agentToolUtils.test.d.ts → copilot/chat/flow/utils.test.d.ts} +0 -0
@@ -1,11 +1,12 @@
1
1
  import { ScriptService, JobService } from '../../../../gen';
2
2
  import { z } from 'zod';
3
3
  import { createDbSchemaTool, getFormattedResourceTypes, getLangContext, SUPPORTED_CHAT_SCRIPT_LANGUAGES } from '../script/core';
4
- import { createSearchHubScriptsTool, createToolDef, executeTestRun, buildSchemaForTool, buildTestRunArgs, buildContextString, applyCodePiecesToFlowModules, findModuleById, SPECIAL_MODULE_IDS, formatScriptLintResult, createSearchWorkspaceTool, createGetRunnableDetailsTool } from '../shared';
5
- import { inlineScriptStore, extractAndReplaceInlineScripts } from './inlineScriptsUtils';
6
- import { flowModulesSchema } from './openFlowZod';
7
- import { collectAllModuleIdsFromArray } from './utils';
8
- import { getFlowPrompt } from '../../../../system_prompts';
4
+ import { createSearchHubScriptsTool, createToolDef, executeTestRun, buildSchemaForTool, buildTestRunArgs, buildContextString, applyCodePiecesToFlowModules, SPECIAL_MODULE_IDS, formatScriptLintResult, createSearchWorkspaceTool, createGetRunnableDetailsTool } from '../shared';
5
+ import { findModuleInFlow, findModuleInModules } from '../../../flows/flowTree';
6
+ import { createInlineScriptSession } from './inlineScriptsUtils';
7
+ import { flowModuleSchema, flowModulesSchema } from './openFlowZod';
8
+ import { collectAllFlowModuleIdsFromModules } from '../../../flows/flowTree';
9
+ import { FLOW_CHAT_SPECIAL_MODULES, getFlowPrompt } from '../../../../system_prompts';
9
10
  /**
10
11
  * Navigate to a schema at a given path, handling arrays, objects, unions, and wrappers.
11
12
  * Uses Zod 4 internal structure.
@@ -181,6 +182,174 @@ function getExpectedFormat(schema) {
181
182
  }
182
183
  return null;
183
184
  }
185
+ function countExactMatches(content, search) {
186
+ if (search.length === 0) {
187
+ return 0;
188
+ }
189
+ let count = 0;
190
+ let index = 0;
191
+ while ((index = content.indexOf(search, index)) !== -1) {
192
+ count++;
193
+ index += search.length;
194
+ }
195
+ return count;
196
+ }
197
+ function replaceFirstExactMatch(content, search, replace) {
198
+ const index = content.indexOf(search);
199
+ if (index === -1) {
200
+ return content;
201
+ }
202
+ return content.slice(0, index) + replace + content.slice(index + search.length);
203
+ }
204
+ function formatEmptyInlineScriptWarning({ emptyInlineScriptModuleIds }) {
205
+ if (emptyInlineScriptModuleIds.length === 0) {
206
+ return '';
207
+ }
208
+ const moduleList = emptyInlineScriptModuleIds.map((id) => `'${id}'`).join(', ');
209
+ return ` Warning: inline scripts ${moduleList} are empty for now. Use set_module_code to fill them in.`;
210
+ }
211
+ function validateFlowModules(rawModules) {
212
+ if (!Array.isArray(rawModules)) {
213
+ throw new Error('Flow modules must be an array');
214
+ }
215
+ const parsedModules = rawModules;
216
+ const result = flowModulesSchema.safeParse(parsedModules);
217
+ if (!result.success) {
218
+ const errors = result.error.issues.slice(0, 5).map((e) => {
219
+ const path = e.path;
220
+ // Try to find module id for better context
221
+ const moduleIndex = typeof path[0] === 'number' ? path[0] : undefined;
222
+ const moduleId = moduleIndex !== undefined ? parsedModules[moduleIndex]?.id : undefined;
223
+ const fieldPath = path.slice(1).join('.');
224
+ let message = e.message;
225
+ if (e.code === 'invalid_type') {
226
+ // Zod 4 message already contains "expected X, received Y"
227
+ // Try to extract expected format from schema, passing actual data
228
+ // to help resolve discriminated unions correctly
229
+ const targetSchema = getSchemaAtPath(flowModulesSchema, path, parsedModules);
230
+ if (targetSchema) {
231
+ const expectedFormat = getExpectedFormat(targetSchema);
232
+ if (expectedFormat) {
233
+ message += `\n Expected format: ${expectedFormat}`;
234
+ }
235
+ }
236
+ }
237
+ if (moduleId) {
238
+ return `Module "${moduleId}" -> ${fieldPath}: ${message}`;
239
+ }
240
+ return `${path.join('.')}: ${message}`;
241
+ });
242
+ throw new Error(`Invalid flow modules:\n${errors.join('\n')}`);
243
+ }
244
+ const ids = collectAllFlowModuleIdsFromModules(parsedModules);
245
+ if (ids.length !== new Set(ids).size) {
246
+ throw new Error('Duplicate module IDs found in flow');
247
+ }
248
+ const reservedIds = ids.filter((id) => id === SPECIAL_MODULE_IDS.PREPROCESSOR || id === SPECIAL_MODULE_IDS.FAILURE);
249
+ if (reservedIds.length > 0) {
250
+ throw new Error('Special modules must be provided via preprocessor_module and failure_module, not inside modules');
251
+ }
252
+ return parsedModules;
253
+ }
254
+ function validateFlowSchema(rawSchema) {
255
+ if (rawSchema == null) {
256
+ return null;
257
+ }
258
+ if (typeof rawSchema !== 'object' || Array.isArray(rawSchema)) {
259
+ throw new Error('Flow schema must be an object or null');
260
+ }
261
+ return rawSchema;
262
+ }
263
+ function validateOptionalFlowModule(rawModule, fieldName) {
264
+ if (rawModule == null) {
265
+ return null;
266
+ }
267
+ const result = flowModuleSchema.safeParse(rawModule);
268
+ if (!result.success) {
269
+ const error = result.error.issues[0];
270
+ throw new Error(`Invalid ${fieldName}: ${error?.message ?? 'unknown error'}`);
271
+ }
272
+ return result.data;
273
+ }
274
+ function validateEditableFlowJson(rawFlow) {
275
+ if (!rawFlow || typeof rawFlow !== 'object' || Array.isArray(rawFlow)) {
276
+ throw new Error('Flow JSON must be an object');
277
+ }
278
+ const flow = rawFlow;
279
+ const modules = validateFlowModules(flow.modules);
280
+ const schema = validateFlowSchema(flow.schema);
281
+ const preprocessorModule = validateOptionalFlowModule(flow.preprocessor_module, 'preprocessor_module');
282
+ const failureModule = validateOptionalFlowModule(flow.failure_module, 'failure_module');
283
+ if (preprocessorModule) {
284
+ if (preprocessorModule.id !== SPECIAL_MODULE_IDS.PREPROCESSOR) {
285
+ throw new Error(`Invalid preprocessor_module: id must be "${SPECIAL_MODULE_IDS.PREPROCESSOR}"`);
286
+ }
287
+ if (preprocessorModule.value.type !== 'rawscript' && preprocessorModule.value.type !== 'script') {
288
+ throw new Error('Invalid preprocessor_module: only "rawscript" and "script" modules are supported');
289
+ }
290
+ }
291
+ if (failureModule) {
292
+ if (failureModule.id !== SPECIAL_MODULE_IDS.FAILURE) {
293
+ throw new Error(`Invalid failure_module: id must be "${SPECIAL_MODULE_IDS.FAILURE}"`);
294
+ }
295
+ if (failureModule.value.type !== 'rawscript' && failureModule.value.type !== 'script') {
296
+ throw new Error('Invalid failure_module: only "rawscript" and "script" modules are supported');
297
+ }
298
+ }
299
+ const ids = new Set(collectAllFlowModuleIdsFromModules(modules));
300
+ if (preprocessorModule) {
301
+ if (ids.has(preprocessorModule.id)) {
302
+ throw new Error(`Duplicate module ID found in preprocessor_module: ${preprocessorModule.id}`);
303
+ }
304
+ ids.add(preprocessorModule.id);
305
+ }
306
+ if (failureModule && ids.has(failureModule.id)) {
307
+ throw new Error(`Duplicate module ID found in failure_module: ${failureModule.id}`);
308
+ }
309
+ return {
310
+ modules,
311
+ schema,
312
+ preprocessor_module: preprocessorModule,
313
+ failure_module: failureModule
314
+ };
315
+ }
316
+ function buildEditableFlowJson(flow, inlineScriptSession, selectedContext = []) {
317
+ const codePieces = selectedContext.filter((c) => c.type === 'flow_module_code_piece');
318
+ const optimizedModules = inlineScriptSession
319
+ ? inlineScriptSession.extractAndReplaceInlineScripts(flow.value.modules)
320
+ : flow.value.modules;
321
+ const modules = applyCodePiecesToFlowModules(codePieces, optimizedModules);
322
+ let preprocessorModule = flow.value.preprocessor_module;
323
+ if (preprocessorModule?.value?.type === 'rawscript' &&
324
+ preprocessorModule.value.content &&
325
+ inlineScriptSession) {
326
+ inlineScriptSession.set(preprocessorModule.id, preprocessorModule.value.content);
327
+ preprocessorModule = {
328
+ ...preprocessorModule,
329
+ value: {
330
+ ...preprocessorModule.value,
331
+ content: `inline_script.${preprocessorModule.id}`
332
+ }
333
+ };
334
+ }
335
+ let failureModule = flow.value.failure_module;
336
+ if (failureModule?.value?.type === 'rawscript' && failureModule.value.content && inlineScriptSession) {
337
+ inlineScriptSession.set(failureModule.id, failureModule.value.content);
338
+ failureModule = {
339
+ ...failureModule,
340
+ value: {
341
+ ...failureModule.value,
342
+ content: `inline_script.${failureModule.id}`
343
+ }
344
+ };
345
+ }
346
+ return {
347
+ modules,
348
+ schema: flow.schema ?? null,
349
+ preprocessor_module: preprocessorModule ?? null,
350
+ failure_module: failureModule ?? null
351
+ };
352
+ }
184
353
  const langSchema = z.enum(SUPPORTED_CHAT_SCRIPT_LANGUAGES);
185
354
  const resourceTypeToolSchema = z.object({
186
355
  query: z.string().describe('The query to search for, e.g. stripe, google, etc..'),
@@ -191,12 +360,85 @@ const getInstructionsForCodeGenerationToolSchema = z.object({
191
360
  language: langSchema.describe('The programming language the code will be written in')
192
361
  });
193
362
  const getInstructionsForCodeGenerationToolDef = createToolDef(getInstructionsForCodeGenerationToolSchema, 'get_instructions_for_code_generation', 'Get instructions for code generation for a raw script step');
363
+ const specialModuleToolArgSchema = z
364
+ .string()
365
+ .nullable()
366
+ .describe('JSON string containing the special module object. Use null to remove the special module.');
194
367
  // Using string for modules and schema because Gemini-2.5-flash performs better with strings (MALFORMED_FUNCTION_CALL errors happens more often with objects)
195
368
  const setFlowJsonToolSchema = z.object({
196
369
  modules: z.string().optional().nullable().describe('JSON string containing the flow modules'),
197
- schema: z.string().optional().nullable().describe('JSON string containing the flow input schema')
370
+ schema: z.string().optional().nullable().describe('JSON string containing the flow input schema'),
371
+ preprocessor_module: z
372
+ .string()
373
+ .optional()
374
+ .nullable()
375
+ .describe('JSON string containing the optional preprocessor module'),
376
+ failure_module: z
377
+ .string()
378
+ .optional()
379
+ .nullable()
380
+ .describe('JSON string containing the optional failure module')
381
+ });
382
+ const setFlowJsonToolDef = createToolDef(setFlowJsonToolSchema, 'set_flow_json', 'Set the complete flow modules array and optionally the flow input schema, preprocessor module, and failure module.', { strict: false });
383
+ const setPreprocessorModuleToolSchema = z.object({
384
+ module: specialModuleToolArgSchema
385
+ });
386
+ const setPreprocessorModuleToolDef = createToolDef(setPreprocessorModuleToolSchema, 'set_preprocessor_module', 'Set or replace the flow preprocessor module. Use this when the flow needs logic that runs before the main modules.');
387
+ const setFailureModuleToolSchema = z.object({
388
+ module: specialModuleToolArgSchema
389
+ });
390
+ const setFailureModuleToolDef = createToolDef(setFailureModuleToolSchema, 'set_failure_module', 'Set or replace the flow failure module. Use this when the flow needs a dedicated error handler.');
391
+ const specialFlowModuleFields = {
392
+ preprocessor_module: SPECIAL_MODULE_IDS.PREPROCESSOR,
393
+ failure_module: SPECIAL_MODULE_IDS.FAILURE
394
+ };
395
+ function parseOptionalJsonArg(value, field) {
396
+ if (value === undefined || value === null) {
397
+ return value;
398
+ }
399
+ try {
400
+ return typeof value === 'string' ? JSON.parse(value) : value;
401
+ }
402
+ catch (e) {
403
+ const errorMessage = e instanceof Error ? e.message : String(e);
404
+ throw new Error(`Invalid JSON for ${field}: ${errorMessage}`);
405
+ }
406
+ }
407
+ function validateSpecialFlowModule(module, field) {
408
+ if (module === undefined || module === null) {
409
+ return module;
410
+ }
411
+ const result = flowModuleSchema.safeParse(module);
412
+ if (!result.success) {
413
+ const errors = result.error.issues.slice(0, 5).map((issue) => {
414
+ const path = issue.path.length > 0 ? issue.path.join('.') : field;
415
+ return `${path}: ${issue.message}`;
416
+ });
417
+ throw new Error(`Invalid ${field}:\n${errors.join('\n')}`);
418
+ }
419
+ const parsedModule = result.data;
420
+ const expectedId = specialFlowModuleFields[field];
421
+ if (parsedModule.id !== expectedId) {
422
+ throw new Error(`Invalid ${field}: id must be "${expectedId}"`);
423
+ }
424
+ if (parsedModule.value.type !== 'rawscript' && parsedModule.value.type !== 'script') {
425
+ throw new Error(`Invalid ${field}: only "rawscript" and "script" modules are supported`);
426
+ }
427
+ return parsedModule;
428
+ }
429
+ const patchFlowJsonSchema = z.object({
430
+ old_string: z
431
+ .string()
432
+ .min(1)
433
+ .describe('Exact text to find in the current compact flow JSON'),
434
+ new_string: z.string().describe('Replacement JSON text'),
435
+ replace_all: z
436
+ .boolean()
437
+ .optional()
438
+ .default(false)
439
+ .describe('When true, replace every exact match. When false, the search text must match exactly once.')
198
440
  });
199
- const setFlowJsonToolDef = createToolDef(setFlowJsonToolSchema, 'set_flow_json', 'Set the entire flow by providing the complete flow object. This replaces all existing modules and schema.', { strict: false });
441
+ const patchFlowJsonToolDef = createToolDef(patchFlowJsonSchema, 'patch_flow_json', 'Make a quick exact text edit in the current compact flow JSON. Prefer this for small localized changes; use set_flow_json for larger structural rewrites.');
200
442
  // Will be overridden by setSchema
201
443
  const testRunFlowSchema = z.object({
202
444
  args: z
@@ -312,15 +554,14 @@ export const flowTools = [
312
554
  }
313
555
  const stepId = args.stepId;
314
556
  const stepArgs = args.args || {};
315
- // Find the step in the flow
316
- const modules = helpers.getModules();
317
- let targetModule = findModuleById(modules, stepId);
557
+ // Find the step in the flow (includes preprocessor/failure modules)
558
+ let targetModule = findModuleInFlow(flow.value, stepId) ?? undefined;
318
559
  if (!targetModule) {
319
560
  toolCallbacks.setToolStatus(toolId, {
320
561
  content: `Step '${stepId}' not found in flow`,
321
562
  error: `Step with id '${stepId}' does not exist in the current flow`
322
563
  });
323
- throw new Error(`Step with id '${stepId}' not found in flow. Available steps: ${modules.map((m) => m.id).join(', ')}`);
564
+ throw new Error(`Step with id '${stepId}' not found in flow. Available steps: ${(flow.value.modules ?? []).map((m) => m.id).join(', ')}`);
324
565
  }
325
566
  const module = targetModule;
326
567
  const moduleValue = module.value;
@@ -402,13 +643,13 @@ export const flowTools = [
402
643
  },
403
644
  {
404
645
  def: inspectInlineScriptToolDef,
405
- fn: async ({ args, toolCallbacks, toolId }) => {
646
+ fn: async ({ args, helpers, toolCallbacks, toolId }) => {
406
647
  const parsedArgs = inspectInlineScriptSchema.parse(args);
407
648
  const moduleId = parsedArgs.moduleId;
408
649
  toolCallbacks.setToolStatus(toolId, {
409
650
  content: `Retrieving inline script content for module '${moduleId}'...`
410
651
  });
411
- const content = inlineScriptStore.get(moduleId);
652
+ const content = helpers.inlineScriptSession.get(moduleId);
412
653
  if (content === undefined) {
413
654
  toolCallbacks.setToolStatus(toolId, {
414
655
  content: `Module '${moduleId}' not found in inline script store`,
@@ -435,8 +676,6 @@ export const flowTools = [
435
676
  const parsedArgs = setModuleCodeSchema.parse(args);
436
677
  const { moduleId, code } = parsedArgs;
437
678
  toolCallbacks.setToolStatus(toolId, { content: `Setting code for module '${moduleId}'...` });
438
- // Update store to keep it coherent (for subsequent set_flow_json calls with references)
439
- inlineScriptStore.set(moduleId, code);
440
679
  // Update the flow directly via helper
441
680
  await helpers.setCode(moduleId, code);
442
681
  toolCallbacks.setToolStatus(toolId, {
@@ -446,78 +685,185 @@ export const flowTools = [
446
685
  return `Code for module '${moduleId}' has been updated successfully.`;
447
686
  }
448
687
  },
688
+ {
689
+ def: patchFlowJsonToolDef,
690
+ streamArguments: true,
691
+ showDetails: true,
692
+ showFade: true,
693
+ fn: async ({ args, helpers, toolId, toolCallbacks }) => {
694
+ const parsedArgs = patchFlowJsonSchema.parse(args);
695
+ const { old_string: oldString, new_string: newString, replace_all: replaceAll } = parsedArgs;
696
+ const { flow, selectedId } = helpers.getFlowAndSelectedId();
697
+ // Snapshot the current flow with a fresh session so the compact JSON matches what the model saw,
698
+ // then copy extracted inline scripts back into the helper session before applying the patch.
699
+ const inlineScriptSession = createInlineScriptSession();
700
+ const currentFlowJson = JSON.stringify(buildEditableFlowJson(flow, inlineScriptSession));
701
+ const matchCount = countExactMatches(currentFlowJson, oldString);
702
+ if (matchCount === 0) {
703
+ throw new Error('old_string was not found in the current flow JSON.');
704
+ }
705
+ if (!replaceAll && matchCount !== 1) {
706
+ throw new Error(`old_string matched ${matchCount} locations. Make it more specific or set replace_all to true.`);
707
+ }
708
+ toolCallbacks.setToolStatus(toolId, {
709
+ content: 'Applying JSON patch...'
710
+ });
711
+ const updatedFlowJson = replaceAll
712
+ ? currentFlowJson.split(oldString).join(newString)
713
+ : replaceFirstExactMatch(currentFlowJson, oldString, newString);
714
+ let parsedFlow;
715
+ try {
716
+ parsedFlow = validateEditableFlowJson(JSON.parse(updatedFlowJson));
717
+ }
718
+ catch (error) {
719
+ const message = error instanceof Error ? error.message : String(error);
720
+ throw new Error(`Invalid JSON after replacement: ${message}`);
721
+ }
722
+ for (const [moduleId, content] of Object.entries(inlineScriptSession.getAll())) {
723
+ helpers.inlineScriptSession.set(moduleId, content);
724
+ }
725
+ const updateResult = await helpers.setFlowJson({
726
+ modules: parsedFlow.modules,
727
+ schema: parsedFlow.schema,
728
+ preprocessorModule: parsedFlow.preprocessor_module,
729
+ failureModule: parsedFlow.failure_module
730
+ });
731
+ const warning = formatEmptyInlineScriptWarning(updateResult);
732
+ const selectedModule = findModuleInFlow(parsedFlow, selectedId) ?? undefined;
733
+ if (selectedModule &&
734
+ 'input_transforms' in selectedModule.value &&
735
+ selectedModule.value.input_transforms) {
736
+ helpers.updateExprsToSet(selectedId, selectedModule.value.input_transforms);
737
+ }
738
+ toolCallbacks.setToolStatus(toolId, {
739
+ content: `Updated flow JSON`,
740
+ result: 'Success'
741
+ });
742
+ return `Flow JSON updated.${warning}`;
743
+ }
744
+ },
745
+ {
746
+ def: setPreprocessorModuleToolDef,
747
+ streamArguments: true,
748
+ showDetails: true,
749
+ showFade: true,
750
+ fn: async ({ args, helpers, toolId, toolCallbacks }) => {
751
+ const parsedArgs = setPreprocessorModuleToolSchema.parse(args);
752
+ const parsedModule = validateSpecialFlowModule(parseOptionalJsonArg(parsedArgs.module, 'module'), 'preprocessor_module');
753
+ toolCallbacks.setToolStatus(toolId, {
754
+ content: parsedModule === null ? 'Removing preprocessor module...' : 'Setting preprocessor module...'
755
+ });
756
+ const updateResult = await helpers.setFlowJson({ preprocessorModule: parsedModule });
757
+ const warning = formatEmptyInlineScriptWarning(updateResult);
758
+ if (parsedModule &&
759
+ helpers.getFlowAndSelectedId().selectedId === SPECIAL_MODULE_IDS.PREPROCESSOR &&
760
+ 'input_transforms' in parsedModule.value &&
761
+ parsedModule.value.input_transforms) {
762
+ helpers.updateExprsToSet(parsedModule.id, parsedModule.value.input_transforms);
763
+ }
764
+ toolCallbacks.setToolStatus(toolId, {
765
+ content: parsedModule === null ? 'Preprocessor module removed' : 'Preprocessor module updated',
766
+ result: 'Success'
767
+ });
768
+ return parsedModule === null
769
+ ? 'Preprocessor module removed'
770
+ : `Preprocessor module updated successfully.${warning}`;
771
+ }
772
+ },
773
+ {
774
+ def: setFailureModuleToolDef,
775
+ streamArguments: true,
776
+ showDetails: true,
777
+ showFade: true,
778
+ fn: async ({ args, helpers, toolId, toolCallbacks }) => {
779
+ const parsedArgs = setFailureModuleToolSchema.parse(args);
780
+ const parsedModule = validateSpecialFlowModule(parseOptionalJsonArg(parsedArgs.module, 'module'), 'failure_module');
781
+ toolCallbacks.setToolStatus(toolId, {
782
+ content: parsedModule === null ? 'Removing failure module...' : 'Setting failure module...'
783
+ });
784
+ const updateResult = await helpers.setFlowJson({ failureModule: parsedModule });
785
+ const warning = formatEmptyInlineScriptWarning(updateResult);
786
+ if (parsedModule &&
787
+ helpers.getFlowAndSelectedId().selectedId === SPECIAL_MODULE_IDS.FAILURE &&
788
+ 'input_transforms' in parsedModule.value &&
789
+ parsedModule.value.input_transforms) {
790
+ helpers.updateExprsToSet(parsedModule.id, parsedModule.value.input_transforms);
791
+ }
792
+ toolCallbacks.setToolStatus(toolId, {
793
+ content: parsedModule === null ? 'Failure module removed' : 'Failure module updated',
794
+ result: 'Success'
795
+ });
796
+ return parsedModule === null
797
+ ? 'Failure module removed'
798
+ : `Failure module updated successfully.${warning}`;
799
+ }
800
+ },
449
801
  {
450
802
  def: setFlowJsonToolDef,
451
803
  streamArguments: true,
452
804
  showDetails: true,
453
805
  showFade: true,
454
806
  fn: async ({ args, helpers, toolId, toolCallbacks }) => {
455
- const { modules, schema } = args;
807
+ const { modules, schema, preprocessor_module, failure_module } = args;
456
808
  let parsedModules;
457
809
  let parsedSchema;
810
+ let parsedPreprocessorModule;
811
+ let parsedFailureModule;
458
812
  // Parse JSON strings
459
- try {
460
- parsedModules = modules
461
- ? typeof modules === 'string'
462
- ? JSON.parse(modules)
463
- : modules
464
- : undefined;
465
- parsedSchema = schema
466
- ? typeof schema === 'string'
467
- ? JSON.parse(schema)
468
- : schema
469
- : undefined;
470
- }
471
- catch (e) {
472
- const errorMessage = e instanceof Error ? e.message : String(e);
473
- throw new Error(`Invalid JSON: ${errorMessage}`);
474
- }
475
- // Validate modules against OpenFlow schema
476
- if (parsedModules) {
477
- const result = flowModulesSchema.safeParse(parsedModules);
478
- if (!result.success) {
479
- const errors = result.error.issues.slice(0, 5).map((e) => {
480
- const path = e.path;
481
- // Try to find module id for better context
482
- const moduleIndex = typeof path[0] === 'number' ? path[0] : undefined;
483
- const moduleId = moduleIndex !== undefined ? parsedModules[moduleIndex]?.id : undefined;
484
- const fieldPath = path.slice(1).join('.');
485
- let message = e.message;
486
- if (e.code === 'invalid_type') {
487
- // Zod 4 message already contains "expected X, received Y"
488
- // Try to extract expected format from schema, passing actual data
489
- // to help resolve discriminated unions correctly
490
- const targetSchema = getSchemaAtPath(flowModulesSchema, path, parsedModules);
491
- if (targetSchema) {
492
- const expectedFormat = getExpectedFormat(targetSchema);
493
- if (expectedFormat) {
494
- message += `\n Expected format: ${expectedFormat}`;
495
- }
496
- }
497
- }
498
- if (moduleId) {
499
- return `Module "${moduleId}" -> ${fieldPath}: ${message}`;
500
- }
501
- return `${path.join('.')}: ${message}`;
502
- });
503
- throw new Error(`Invalid flow modules:\n${errors.join('\n')}`);
504
- }
505
- else {
506
- // check for duplicate ids
507
- const ids = collectAllModuleIdsFromArray(parsedModules);
508
- if (ids.length !== new Set(ids).size) {
509
- throw new Error('Duplicate module IDs found in flow');
510
- }
813
+ parsedModules = parseOptionalJsonArg(modules, 'modules');
814
+ parsedSchema = parseOptionalJsonArg(schema, 'schema');
815
+ parsedPreprocessorModule = parseOptionalJsonArg(preprocessor_module, 'preprocessor_module');
816
+ parsedFailureModule = parseOptionalJsonArg(failure_module, 'failure_module');
817
+ if (parsedModules === null) {
818
+ parsedModules = undefined;
819
+ }
820
+ if (parsedSchema === null) {
821
+ parsedSchema = undefined;
822
+ }
823
+ if (parsedModules !== undefined) {
824
+ parsedModules = validateFlowModules(parsedModules);
825
+ const reservedIds = collectAllFlowModuleIdsFromModules(parsedModules).filter((id) => id === SPECIAL_MODULE_IDS.PREPROCESSOR || id === SPECIAL_MODULE_IDS.FAILURE);
826
+ if (reservedIds.length > 0) {
827
+ throw new Error('Special modules must be provided via preprocessor_module and failure_module, not inside modules');
511
828
  }
512
829
  }
830
+ if (parsedSchema !== undefined) {
831
+ parsedSchema = validateFlowSchema(parsedSchema);
832
+ }
833
+ parsedPreprocessorModule = validateSpecialFlowModule(parsedPreprocessorModule, 'preprocessor_module');
834
+ parsedFailureModule = validateSpecialFlowModule(parsedFailureModule, 'failure_module');
835
+ const ids = [
836
+ ...(parsedModules ? collectAllFlowModuleIdsFromModules(parsedModules) : []),
837
+ ...([parsedPreprocessorModule, parsedFailureModule].filter((module) => module !== undefined && module !== null)
838
+ .map((module) => module.id))
839
+ ];
840
+ if (ids.length !== new Set(ids).size) {
841
+ throw new Error('Duplicate module IDs found in flow');
842
+ }
513
843
  toolCallbacks.setToolStatus(toolId, {
514
844
  content: `Setting flow...`
515
845
  });
516
- await helpers.setFlowJson(parsedModules, parsedSchema);
846
+ const updateResult = await helpers.setFlowJson({
847
+ ...(parsedModules !== undefined ? { modules: parsedModules } : {}),
848
+ ...(parsedSchema !== undefined ? { schema: parsedSchema } : {}),
849
+ ...(parsedPreprocessorModule !== undefined
850
+ ? { preprocessorModule: parsedPreprocessorModule }
851
+ : {}),
852
+ ...(parsedFailureModule !== undefined ? { failureModule: parsedFailureModule } : {})
853
+ });
854
+ const warning = formatEmptyInlineScriptWarning(updateResult);
517
855
  // Update exprsToSet if the selected module has input_transforms
518
- if (parsedModules) {
856
+ if (parsedModules !== undefined ||
857
+ parsedPreprocessorModule !== undefined ||
858
+ parsedFailureModule !== undefined) {
519
859
  const { selectedId } = helpers.getFlowAndSelectedId();
520
- const selectedModule = findModuleById(parsedModules, selectedId);
860
+ const selectedModule = selectedId === SPECIAL_MODULE_IDS.PREPROCESSOR
861
+ ? parsedPreprocessorModule ?? undefined
862
+ : selectedId === SPECIAL_MODULE_IDS.FAILURE
863
+ ? parsedFailureModule ?? undefined
864
+ : parsedModules
865
+ ? findModuleInModules(parsedModules, selectedId)
866
+ : undefined;
521
867
  if (selectedModule &&
522
868
  'input_transforms' in selectedModule.value &&
523
869
  selectedModule.value.input_transforms) {
@@ -528,7 +874,7 @@ export const flowTools = [
528
874
  content: `Flow updated`,
529
875
  result: 'Success'
530
876
  });
531
- return `Flow updated`;
877
+ return `Flow updated.${warning}`;
532
878
  }
533
879
  },
534
880
  {
@@ -558,7 +904,10 @@ export function prepareFlowSystemMessage(customPrompt) {
558
904
  ## Tool Selection Guide
559
905
 
560
906
  **Flow Modification:**
561
- - **Create or modify the entire flow** → \`set_flow_json\` (provide complete modules array and optional schema)
907
+ - **Quick exact edits to current flow JSON** → \`patch_flow_json\` (provide \`old_string\` and \`new_string\`; default is one exact match)
908
+ - **Update only the preprocessor** → \`set_preprocessor_module\`
909
+ - **Update only the failure handler** → \`set_failure_module\`
910
+ - **Create or replace the full flow** → \`set_flow_json\`
562
911
 
563
912
  **Code & Scripts:**
564
913
  - **View existing inline script code** → \`inspect_inline_script\`
@@ -580,13 +929,39 @@ export function prepareFlowSystemMessage(customPrompt) {
580
929
  - **Search resource types** → \`resource_type\`
581
930
  - **Get database schema** → \`get_db_schema\`
582
931
 
932
+ ## Quick Edits with patch_flow_json
933
+
934
+ Use \`patch_flow_json\` for small, localized changes when you can target an exact snippet from the \`CURRENT FLOW JSON COMPACT\` block below.
935
+
936
+ Always copy the exact search text from the \`CURRENT FLOW JSON COMPACT\` block below.
937
+ The compact JSON is a single object with \`modules\`, \`schema\`, \`preprocessor_module\`, and \`failure_module\` keys.
938
+
939
+ **Parameters:**
940
+ - \`old_string\`: Exact JSON text to find
941
+ - \`new_string\`: Replacement JSON text
942
+ - \`replace_all\`: Optional boolean. Leave false unless you intentionally want to replace every exact match.
943
+
944
+ **Example - Rename a referenced result:**
945
+ \`\`\`javascript
946
+ patch_flow_json({
947
+ old_string: "\"expr\":\"results.fetch_data\"",
948
+ new_string: "\"expr\":\"results.load_data\""
949
+ })
950
+ \`\`\`
951
+
952
+ Use \`set_flow_json\` instead when you need to do a larger rewrite, add many new modules, or change the flow schema.
953
+
954
+ ${FLOW_CHAT_SPECIAL_MODULES}
955
+
583
956
  ## Flow Modification with set_flow_json
584
957
 
585
- Use the \`set_flow_json\` tool to set the entire flow structure at once. Provide the complete modules array and optionally the flow input schema.
958
+ Use the \`set_flow_json\` tool to set the entire flow structure at once. Provide the complete modules array and optionally the flow input schema, \`preprocessor_module\`, and \`failure_module\`.
586
959
 
587
960
  **Parameters:**
588
961
  - \`modules\`: Array of flow modules (required)
589
962
  - \`schema\`: Flow input schema in JSON Schema format (optional)
963
+ - \`preprocessor_module\`: Special module that runs before \`modules\` (optional, separate from \`modules\`)
964
+ - \`failure_module\`: Special module that runs on failure (optional, separate from \`modules\`)
590
965
 
591
966
  **Example - Simple flow:**
592
967
  \`\`\`javascript
@@ -763,6 +1138,10 @@ To reduce token usage, rawscript content in the flow you receive is replaced wit
763
1138
  **To inspect existing code:**
764
1139
  - Use \`inspect_inline_script\` tool to view the current code: \`inspect_inline_script({ moduleId: "step_a" })\`
765
1140
 
1141
+ **If a flow update tool warns that inline scripts are empty:**
1142
+ - The module structure was created successfully, but the code is still empty
1143
+ - Immediately call \`set_module_code\` for each warned module ID
1144
+
766
1145
  ### Writing Code for Modules
767
1146
 
768
1147
  **IMPORTANT: Before writing any code for a rawscript module, you MUST call the \`get_instructions_for_code_generation\` tool with the target language.** This tool provides essential language-specific instructions.
@@ -771,14 +1150,15 @@ Example: Before writing TypeScript/Bun code, call \`get_instructions_for_code_ge
771
1150
 
772
1151
  ### Creating Flows
773
1152
 
774
- 1. **Search for existing scripts first** (unless user explicitly asks to write from scratch):
775
- - First: \`search_workspace\` to find workspace scripts and flows
776
- - Use \`get_runnable_details\` to inspect a specific script or flow (inputs, description, code)
1153
+ 1. **Search for existing scripts and flows first** (unless user explicitly asks to write from scratch):
1154
+ - First: \`search_workspace\` to find workspace scripts **and flows**. Existing flows can be reused as subflow steps — prefer this over rebuilding equivalent logic inline.
1155
+ - Use \`get_runnable_details\` to inspect a specific script or flow (inputs, description, code) so you know how to wire its \`input_transforms\`
777
1156
  - Then: \`search_hub_scripts\` (only consider highly relevant results)
778
- - Only create raw scripts if no suitable script is found
1157
+ - Only create raw scripts if no suitable script or flow is found
779
1158
 
780
1159
  2. **Build the complete flow using \`set_flow_json\`:**
781
- - If using existing script: use \`type: "script"\` with \`path\`
1160
+ - If using an existing script: use \`type: "script"\` with \`path\`
1161
+ - If using an existing flow as a subflow step: use \`type: "flow"\` with \`path\` (e.g. \`{ type: "flow", path: "f/flows/process_user", input_transforms: { ... } }\`). The step's \`input_transforms\` must cover the subflow's inputs.
782
1162
  - If creating rawscript: use \`type: "rawscript"\` with \`language\` and \`content\`
783
1163
  - **First call \`get_instructions_for_code_generation\` to get the correct code format**
784
1164
  - Always define \`input_transforms\` to connect parameters to flow inputs or previous step results
@@ -839,7 +1219,7 @@ You have access to the following contexts:
839
1219
  content
840
1220
  };
841
1221
  }
842
- export function prepareFlowUserMessage(instructions, flowAndSelectedId, selectedContext = []) {
1222
+ export function prepareFlowUserMessage(instructions, flowAndSelectedId, selectedContext = [], inlineScriptSession) {
843
1223
  const flow = flowAndSelectedId?.flow;
844
1224
  const selectedId = flowAndSelectedId?.selectedId;
845
1225
  // Handle context elements
@@ -852,43 +1232,14 @@ ${instructions}`;
852
1232
  content: userMessage
853
1233
  };
854
1234
  }
855
- const codePieces = selectedContext.filter((c) => c.type === 'flow_module_code_piece');
1235
+ const scriptSession = inlineScriptSession;
856
1236
  // Clear the inline script store and extract inline scripts for token optimization
857
- inlineScriptStore.clear();
858
- const optimizedModules = extractAndReplaceInlineScripts(flow.value.modules);
859
- // Apply code pieces to the optimized modules (returns YAML string)
860
- const flowModulesYaml = applyCodePiecesToFlowModules(codePieces, optimizedModules);
861
- // Handle preprocessor and failure modules
862
- let optimizedPreprocessor = flow.value.preprocessor_module;
863
- if (optimizedPreprocessor?.value?.type === 'rawscript' && optimizedPreprocessor.value.content) {
864
- inlineScriptStore.set(optimizedPreprocessor.id, optimizedPreprocessor.value.content);
865
- optimizedPreprocessor = {
866
- ...optimizedPreprocessor,
867
- value: {
868
- ...optimizedPreprocessor.value,
869
- content: `inline_script.${optimizedPreprocessor.id}`
870
- }
871
- };
872
- }
873
- let optimizedFailure = flow.value.failure_module;
874
- if (optimizedFailure?.value?.type === 'rawscript' && optimizedFailure.value.content) {
875
- inlineScriptStore.set(optimizedFailure.id, optimizedFailure.value.content);
876
- optimizedFailure = {
877
- ...optimizedFailure,
878
- value: {
879
- ...optimizedFailure.value,
880
- content: `inline_script.${optimizedFailure.id}`
881
- }
882
- };
883
- }
884
- const finalFlow = {
885
- schema: flow.schema,
886
- modules: flowModulesYaml,
887
- preprocessor_module: optimizedPreprocessor,
888
- failure_module: optimizedFailure
889
- };
890
- let flowContent = `## CURRENT FLOW JSON:
891
- ${JSON.stringify(finalFlow, null, 2)}
1237
+ scriptSession?.clear();
1238
+ const editableFlowJson = buildEditableFlowJson(flow, scriptSession, selectedContext);
1239
+ let flowContent = `## CURRENT FLOW JSON COMPACT:
1240
+ \`\`\`json
1241
+ ${JSON.stringify(editableFlowJson)}
1242
+ \`\`\`
892
1243
 
893
1244
  currently selected step:
894
1245
  ${selectedId}`;