langflower 0.0.8 → 0.0.10

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 (221) hide show
  1. package/package.json +2 -2
  2. package/ui-dist/{chunk-Y6VMBLSJ.js → chunk-7UMVYN3A.js} +1 -1
  3. package/ui-dist/{chunk-6DQ2XSRW.js → chunk-MDGXX73Z.js} +3 -3
  4. package/ui-dist/index.html +2 -2
  5. package/ui-dist/main-Z7CPFXFA.js +313 -0
  6. package/ui-dist/styles-2TMDAUD7.css +1 -0
  7. package/vendor/common-nodes/dist/ai/chat-completion-stream.d.ts +2 -0
  8. package/vendor/common-nodes/dist/ai/critique/node.d.ts +246 -0
  9. package/vendor/common-nodes/dist/ai/critique/node.js +2 -2
  10. package/vendor/common-nodes/dist/ai/fake-llm/node.d.ts +246 -0
  11. package/vendor/common-nodes/dist/ai/features/chat-completion-stream.d.ts +53 -0
  12. package/vendor/common-nodes/dist/ai/features/chat-completion-stream.js +1 -0
  13. package/vendor/common-nodes/dist/ai/features/llm-loop/autokick-recovery.d.ts +13 -0
  14. package/vendor/common-nodes/dist/ai/features/llm-loop/autokick-recovery.js +17 -0
  15. package/vendor/common-nodes/dist/ai/features/llm-loop/classify-llm-failure.d.ts +2 -0
  16. package/vendor/common-nodes/dist/ai/features/llm-loop/classify-llm-failure.js +113 -0
  17. package/vendor/common-nodes/dist/ai/features/llm-loop/dead-loop-detector.d.ts +28 -0
  18. package/vendor/common-nodes/dist/ai/features/llm-loop/dead-loop-detector.js +194 -0
  19. package/vendor/common-nodes/dist/ai/features/llm-loop/live-get-tools.d.ts +9 -0
  20. package/vendor/common-nodes/dist/ai/features/llm-loop/live-get-tools.js +21 -0
  21. package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-reducer.d.ts +2 -0
  22. package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-reducer.js +204 -0
  23. package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-types.d.ts +120 -0
  24. package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-types.js +39 -0
  25. package/vendor/common-nodes/dist/ai/features/llm-loop/normalize-llm-recovery-policy.d.ts +2 -0
  26. package/vendor/common-nodes/dist/ai/features/llm-loop/normalize-llm-recovery-policy.js +59 -0
  27. package/vendor/common-nodes/dist/ai/features/llm-loop/operators/normalize-tool-result.d.ts +1 -0
  28. package/vendor/common-nodes/dist/ai/features/llm-loop/operators/normalize-tool-result.js +7 -0
  29. package/vendor/common-nodes/dist/ai/features/llm-loop/operators/observe-provider-stream.d.ts +43 -0
  30. package/vendor/common-nodes/dist/ai/features/llm-loop/operators/observe-provider-stream.js +96 -0
  31. package/vendor/common-nodes/dist/ai/features/llm-loop/run-agent-loop.d.ts +29 -0
  32. package/vendor/common-nodes/dist/ai/features/llm-loop/run-agent-loop.js +44 -0
  33. package/vendor/common-nodes/dist/ai/features/llm-loop/run-llm-loop.d.ts +74 -0
  34. package/vendor/common-nodes/dist/ai/features/llm-loop/run-llm-loop.js +658 -0
  35. package/vendor/common-nodes/dist/ai/features/llm-role-preset.d.ts +69 -0
  36. package/vendor/common-nodes/dist/ai/features/llm-role-preset.js +265 -0
  37. package/vendor/common-nodes/dist/ai/features/llm-session/llm-session-shell.d.ts +141 -0
  38. package/vendor/common-nodes/dist/ai/features/llm-session/llm-session-shell.js +193 -0
  39. package/vendor/common-nodes/dist/ai/features/llm-session/run-session-machine.d.ts +21 -0
  40. package/vendor/common-nodes/dist/ai/features/llm-session/run-session-machine.js +118 -0
  41. package/vendor/common-nodes/dist/ai/features/openai/context-length-error.d.ts +14 -0
  42. package/vendor/common-nodes/dist/ai/features/openai/context-length-error.js +63 -0
  43. package/vendor/common-nodes/dist/ai/features/openai/create-chat-completion-stream.d.ts +19 -0
  44. package/vendor/common-nodes/dist/ai/features/openai/create-chat-completion-stream.js +182 -0
  45. package/vendor/common-nodes/dist/ai/features/openai/list-provider-models.d.ts +28 -0
  46. package/vendor/common-nodes/dist/ai/features/openai/list-provider-models.js +52 -0
  47. package/vendor/common-nodes/dist/ai/features/openai/llm-context-compaction.d.ts +31 -0
  48. package/vendor/common-nodes/dist/ai/features/openai/llm-context-compaction.js +326 -0
  49. package/vendor/common-nodes/dist/ai/features/openai/normalize-compaction-params.d.ts +14 -0
  50. package/vendor/common-nodes/dist/ai/features/openai/normalize-compaction-params.js +21 -0
  51. package/vendor/common-nodes/dist/ai/features/openai/prepare-chat-completion.d.ts +30 -0
  52. package/vendor/common-nodes/dist/ai/features/openai/prepare-chat-completion.js +132 -0
  53. package/vendor/common-nodes/dist/ai/features/path-choice/control-tools.d.ts +20 -0
  54. package/vendor/common-nodes/dist/ai/features/path-choice/control-tools.js +70 -0
  55. package/vendor/common-nodes/dist/ai/features/path-choice/run-reactive-path-choice-loop.d.ts +32 -0
  56. package/vendor/common-nodes/dist/ai/features/path-choice/run-reactive-path-choice-loop.js +93 -0
  57. package/vendor/common-nodes/dist/ai/features/prompt/build-effective-system-prompt.d.ts +9 -0
  58. package/vendor/common-nodes/dist/ai/features/prompt/build-effective-system-prompt.js +21 -0
  59. package/vendor/common-nodes/dist/ai/features/prompt/normalize-max-iterations.d.ts +13 -0
  60. package/vendor/common-nodes/dist/ai/features/prompt/normalize-max-iterations.js +23 -0
  61. package/vendor/common-nodes/dist/ai/features/prompt/resolve-chat-provider-model.d.ts +10 -0
  62. package/vendor/common-nodes/dist/ai/features/prompt/resolve-chat-provider-model.js +8 -0
  63. package/vendor/common-nodes/dist/ai/features/run-host-services.d.ts +54 -0
  64. package/vendor/common-nodes/dist/ai/features/run-host-services.js +29 -0
  65. package/vendor/common-nodes/dist/ai/features/scripted-chat-completion-stream.d.ts +17 -0
  66. package/vendor/common-nodes/dist/ai/features/scripted-chat-completion-stream.js +61 -0
  67. package/vendor/common-nodes/dist/ai/features/sub-agent-protocol.d.ts +40 -0
  68. package/vendor/common-nodes/dist/ai/features/sub-agent-protocol.js +44 -0
  69. package/vendor/common-nodes/dist/ai/features/ui-schema/llm-compaction-ui-schema.d.ts +14 -0
  70. package/vendor/common-nodes/dist/ai/features/ui-schema/llm-compaction-ui-schema.js +18 -0
  71. package/vendor/common-nodes/dist/ai/features/ui-schema/llm-panel-ui-schema.d.ts +80 -0
  72. package/vendor/common-nodes/dist/ai/features/ui-schema/llm-panel-ui-schema.js +76 -0
  73. package/vendor/common-nodes/dist/ai/features/ui-schema/llm-recovery-ui-schema.d.ts +113 -0
  74. package/vendor/common-nodes/dist/ai/features/ui-schema/llm-recovery-ui-schema.js +131 -0
  75. package/vendor/common-nodes/dist/ai/features/wait-for-subagent-result.d.ts +7 -0
  76. package/vendor/common-nodes/dist/ai/features/wait-for-subagent-result.js +31 -0
  77. package/vendor/common-nodes/dist/ai/llm-loop/autokick-recovery.d.ts +13 -0
  78. package/vendor/common-nodes/dist/ai/llm-loop/autokick-recovery.js +17 -0
  79. package/vendor/common-nodes/dist/ai/llm-loop/dead-loop-detector.d.ts +28 -0
  80. package/vendor/common-nodes/dist/ai/llm-loop/dead-loop-detector.js +194 -0
  81. package/vendor/common-nodes/dist/ai/llm-loop/llm-loop-reducer.js +36 -0
  82. package/vendor/common-nodes/dist/ai/llm-loop/llm-loop-types.d.ts +35 -0
  83. package/vendor/common-nodes/dist/ai/llm-loop/llm-loop-types.js +19 -0
  84. package/vendor/common-nodes/dist/ai/llm-loop/normalize-llm-recovery-policy.js +52 -9
  85. package/vendor/common-nodes/dist/ai/llm-loop/operators/observe-provider-stream.d.ts +8 -2
  86. package/vendor/common-nodes/dist/ai/llm-loop/operators/observe-provider-stream.js +43 -13
  87. package/vendor/common-nodes/dist/ai/llm-loop/run-llm-loop.d.ts +3 -5
  88. package/vendor/common-nodes/dist/ai/llm-loop/run-llm-loop.js +116 -1
  89. package/vendor/common-nodes/dist/ai/llm-recovery-ui-schema.d.ts +82 -0
  90. package/vendor/common-nodes/dist/ai/llm-recovery-ui-schema.js +95 -0
  91. package/vendor/common-nodes/dist/ai/llm-session-shell.d.ts +4 -9
  92. package/vendor/common-nodes/dist/ai/llm-session-shell.js +2 -4
  93. package/vendor/common-nodes/dist/ai/nodes/critique/node.d.ts +588 -0
  94. package/vendor/common-nodes/dist/ai/nodes/critique/node.js +227 -0
  95. package/vendor/common-nodes/dist/ai/nodes/fake-llm/node.d.ts +571 -0
  96. package/vendor/common-nodes/dist/ai/nodes/fake-llm/node.js +201 -0
  97. package/vendor/common-nodes/dist/ai/nodes/openai-llm/node.d.ts +587 -0
  98. package/vendor/common-nodes/dist/ai/nodes/openai-llm/node.js +84 -0
  99. package/vendor/common-nodes/dist/ai/nodes/review/node.d.ts +593 -0
  100. package/vendor/common-nodes/dist/ai/nodes/review/node.js +227 -0
  101. package/vendor/common-nodes/dist/ai/nodes/sub-agent/node.d.ts +630 -0
  102. package/vendor/common-nodes/dist/ai/nodes/sub-agent/node.js +417 -0
  103. package/vendor/common-nodes/dist/ai/openai/create-chat-completion-stream.js +6 -0
  104. package/vendor/common-nodes/dist/ai/openai/prepare-chat-completion.d.ts +2 -0
  105. package/vendor/common-nodes/dist/ai/openai/prepare-chat-completion.js +18 -0
  106. package/vendor/common-nodes/dist/ai/openai-llm/node.d.ts +246 -0
  107. package/vendor/common-nodes/dist/ai/review/node.d.ts +246 -0
  108. package/vendor/common-nodes/dist/ai/review/node.js +2 -2
  109. package/vendor/common-nodes/dist/ai/sub-agent/node.d.ts +246 -0
  110. package/vendor/common-nodes/dist/ai/sub-agent/node.js +2 -2
  111. package/vendor/common-nodes/dist/catalog.js +9 -5
  112. package/vendor/common-nodes/dist/compile-custom-nodes/node.d.ts +21 -0
  113. package/vendor/common-nodes/dist/compile-custom-nodes/node.js +45 -0
  114. package/vendor/common-nodes/dist/crawl/crawl/node.js +1 -1
  115. package/vendor/common-nodes/dist/crawl/fetch-url/node.js +1 -1
  116. package/vendor/common-nodes/dist/flow/repeat/node.js +6 -1
  117. package/vendor/common-nodes/dist/langflower-tools/emit-registration-tools.d.ts +18 -0
  118. package/vendor/common-nodes/dist/langflower-tools/emit-registration-tools.js +29 -0
  119. package/vendor/common-nodes/dist/langflower-tools/node.d.ts +20 -0
  120. package/vendor/common-nodes/dist/langflower-tools/node.js +77 -0
  121. package/vendor/common-nodes/dist/mcp/mcp-http/node.d.ts +4 -4
  122. package/vendor/common-nodes/dist/mcp/mcp-http/node.js +9 -10
  123. package/vendor/common-nodes/dist/mcp/mcp-stdio/node.d.ts +4 -4
  124. package/vendor/common-nodes/dist/mcp/mcp-stdio/node.js +9 -10
  125. package/vendor/common-nodes/dist/text/append-file/node.js +1 -1
  126. package/vendor/common-nodes/dist/text/read-file/node.js +1 -1
  127. package/vendor/common-nodes/dist/text/write-file/node.js +1 -1
  128. package/vendor/common-nodes/dist/tools/collect-agent-tool-handles.d.ts +4 -4
  129. package/vendor/common-nodes/dist/tools/collect-agent-tool-handles.js +3 -11
  130. package/vendor/common-nodes/dist/tools/inventory-tool-round.d.ts +1 -11
  131. package/vendor/common-nodes/dist/tools/inventory-tool-round.js +0 -84
  132. package/vendor/common-nodes/dist/tools/tool-collection/node.d.ts +20 -0
  133. package/vendor/common-nodes/dist/tools/tool-collection/node.js +42 -0
  134. package/vendor/common-nodes/package.json +9 -13
  135. package/vendor/compiler/dist/compile-project-nodes.d.ts +2 -1
  136. package/vendor/compiler/dist/compile-project-nodes.js +35 -6
  137. package/vendor/compiler/dist/resolve-host-types.d.ts +0 -5
  138. package/vendor/compiler/dist/resolve-host-types.js +0 -8
  139. package/vendor/compiler/package.json +1 -1
  140. package/vendor/node-sdk/dist/node-factory/define-llm-node/default-llm-ports.d.ts +3 -7
  141. package/vendor/node-sdk/dist/node-factory/define-llm-node/default-llm-ports.js +4 -44
  142. package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.d.ts +4 -6
  143. package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.js +4 -6
  144. package/vendor/node-sdk/dist/node-factory/define-llm-node/llm-inventory-wire.d.ts +1 -0
  145. package/vendor/node-sdk/dist/node-factory/define-llm-node/llm-inventory-wire.js +1 -0
  146. package/vendor/node-sdk/dist/node-factory/define-llm-node/recovery-notice.d.ts +8 -0
  147. package/vendor/node-sdk/dist/node-factory/define-llm-node/recovery-notice.js +14 -0
  148. package/vendor/node-sdk/dist/node-factory/define-mcp/mcp-handle.d.ts +3 -4
  149. package/vendor/node-sdk/dist/node-factory/define-mcp/mcp-handle.js +1 -1
  150. package/vendor/node-sdk/dist/node-factory/define-reactive-node/types.d.ts +2 -4
  151. package/vendor/node-sdk/dist/node-factory/define-reactive-node/ui-schema-inference.d.ts +1 -1
  152. package/vendor/node-sdk/package.json +1 -1
  153. package/vendor/runtime/dist/port-feed-override.d.ts +13 -0
  154. package/vendor/runtime/dist/port-feed-override.js +21 -0
  155. package/vendor/runtime/dist/port-signal-from-response.d.ts +15 -0
  156. package/vendor/runtime/dist/port-signal-from-response.js +48 -0
  157. package/vendor/runtime/dist/runtime-editor.d.ts +5 -1
  158. package/vendor/runtime/dist/runtime-editor.js +19 -0
  159. package/vendor/runtime/dist/runtime-runner.d.ts +8 -3
  160. package/vendor/runtime/dist/runtime-runner.js +108 -87
  161. package/vendor/runtime/dist/runtime.d.ts +3 -1
  162. package/vendor/runtime/dist/runtime.js +1 -0
  163. package/vendor/runtime/dist/testing/workflows/workflow-events.d.ts +10 -6
  164. package/vendor/runtime/dist/testing/workflows/workflow-events.js +21 -31
  165. package/vendor/runtime/dist/types.d.ts +52 -40
  166. package/vendor/runtime/dist/types.js +5 -1
  167. package/vendor/runtime/package.json +1 -1
  168. package/vendor/server/dist/bridge/attach-langflower-bridge.js +3 -2
  169. package/vendor/server/dist/bridge/bridge-event-log.js +17 -102
  170. package/vendor/server/dist/bridge/build-execution-context.d.ts +5 -2
  171. package/vendor/server/dist/bridge/build-execution-context.js +48 -8
  172. package/vendor/server/dist/bridge/forward-runner-event.d.ts +1 -1
  173. package/vendor/server/dist/bridge/forward-runner-event.js +7 -12
  174. package/vendor/server/dist/bridge/get-live-wired-tools.d.ts +13 -0
  175. package/vendor/server/dist/bridge/get-live-wired-tools.js +83 -0
  176. package/vendor/server/dist/bridge/langflower-tools-rpc.d.ts +7 -0
  177. package/vendor/server/dist/bridge/langflower-tools-rpc.js +29 -0
  178. package/vendor/server/dist/bridge/wire-custom-palette-handlers.d.ts +2 -1
  179. package/vendor/server/dist/bridge/wire-custom-palette-handlers.js +3 -5
  180. package/vendor/server/dist/bridge/wire-runner-handlers.js +17 -10
  181. package/vendor/server/dist/bridge/wire-workflow-handlers.js +23 -9
  182. package/vendor/server/dist/checkpoint/run-checkpoint-session.d.ts +1 -1
  183. package/vendor/server/dist/checkpoint/run-checkpoint-session.js +10 -9
  184. package/vendor/server/dist/palette/compile-and-hot-swap-custom-nodes.d.ts +10 -0
  185. package/vendor/server/dist/palette/compile-and-hot-swap-custom-nodes.js +23 -0
  186. package/vendor/server/dist/session/reset-session-execution-feed.d.ts +6 -0
  187. package/vendor/server/dist/session/reset-session-execution-feed.js +8 -0
  188. package/vendor/server/dist/workflow/apply-editor-mutation.d.ts +5 -0
  189. package/vendor/server/dist/workflow/apply-editor-mutation.js +32 -0
  190. package/vendor/server/skeleton/instructions.md +9 -5
  191. package/vendor/server/skeleton/nodes/my-nodes/README.md +4 -3
  192. package/vendor/server/skeleton/nodes/my-nodes/package.json +1 -1
  193. package/vendor/server/skeleton/skills/langflower-helper/SKILL.md +82 -38
  194. package/vendor/server/skeleton/skills/langflower-helper/architecture.md +29 -10
  195. package/vendor/server/skeleton/skills/langflower-helper/layout.md +16 -15
  196. package/vendor/server/skeleton/skills/langflower-node-writer/SKILL.md +19 -9
  197. package/vendor/server/skeleton/skills/langflower-workflow-writer/SKILL.md +23 -15
  198. package/vendor/server/skeleton/workflows/kb-create.json +15 -43
  199. package/vendor/server/skeleton/workflows/kb-navigate.json +8 -22
  200. package/vendor/server/skeleton/workflows/simple-coder.json +18 -46
  201. package/vendor/server/skeleton/workflows/starter.json +35 -22
  202. package/vendor/shared/dist/execution/derive-run-settle-outcome.d.ts +1 -1
  203. package/vendor/shared/dist/execution/derive-run-settle-outcome.js +4 -3
  204. package/vendor/shared/dist/execution/derive-run-settle-outcome.test.js +18 -15
  205. package/vendor/shared/dist/langflower-bus-config.d.ts +6 -14
  206. package/vendor/shared/dist/langflower-bus-config.js +4 -12
  207. package/vendor/shared/dist/langflower-config/resolve-wired-tool-options.js +6 -0
  208. package/vendor/shared/dist/langflower-config/resolve-wired-tool-options.test.js +30 -0
  209. package/vendor/shared/dist/langflower-ws-waits.d.ts +9 -14
  210. package/vendor/shared/dist/langflower-ws-waits.js +14 -14
  211. package/vendor/websocket-bridge/dist/bridge-codec.d.ts +1 -0
  212. package/vendor/websocket-bridge/dist/bridge-codec.js +11 -11
  213. package/vendor/websocket-bridge/dist/bridge-frame.js +1 -1
  214. package/vendor/websocket-bridge/dist/bridge-subjects.d.ts +1 -1
  215. package/vendor/websocket-bridge/dist/bridge-subjects.js +2 -2
  216. package/vendor/websocket-bridge/dist/bridge-types.d.ts +13 -1
  217. package/vendor/websocket-bridge/dist/create-client.js +3 -3
  218. package/vendor/websocket-bridge/dist/create-server.js +12 -6
  219. package/vendor/websocket-bridge/package.json +8 -0
  220. package/ui-dist/main-ECEWAM6V.js +0 -311
  221. package/ui-dist/styles-EOXODOI7.css +0 -1
@@ -0,0 +1,227 @@
1
+ import { filter, map, Observable } from 'rxjs';
2
+ import { defineLlmNode, isSteerControlPayload, toLlmRecoveryPortValue, } from '@langflower/node-sdk/llm';
3
+ import { collectAgentToolHandles } from '../../../tools/collect-agent-tool-handles.js';
4
+ import { buildEffectiveSystemPrompt } from '../../features/prompt/build-effective-system-prompt.js';
5
+ import { resolveChatProviderModel } from '../../features/prompt/resolve-chat-provider-model.js';
6
+ import { createLlmSessionCycle$, demuxByKind, normalizeMaxFeedbackTurns, } from '../../features/llm-session/llm-session-shell.js';
7
+ import { llmCompactionUiSchema } from '../../features/ui-schema/llm-compaction-ui-schema.js';
8
+ import { llmRecoveryUiSchema } from '../../features/ui-schema/llm-recovery-ui-schema.js';
9
+ import { llmMaxIterationsUiField, llmPanelUiSchema, } from '../../features/ui-schema/llm-panel-ui-schema.js';
10
+ import { parseLlmRolePreset, resolveEffectiveSkillId, } from '../../features/llm-role-preset.js';
11
+ import { DEFAULT_PATH_CHOICE_MAX_ITERATIONS, PATH_CHOICE_MAX_ITERATIONS_CAP, normalizeMaxIterations, } from '../../features/prompt/normalize-max-iterations.js';
12
+ import { normalizeLlmRecoveryPolicy } from '../../features/llm-loop/normalize-llm-recovery-policy.js';
13
+ import { normalizeCompactionConfig } from '../../features/openai/normalize-compaction-params.js';
14
+ import { REVIEW_ACCEPT_TOOL, REVIEW_FEEDBACK_TOOL, } from '../../features/path-choice/control-tools.js';
15
+ import { runPathChoiceToolLoop, } from '../../features/path-choice/run-reactive-path-choice-loop.js';
16
+ import { getRunHostServices } from '../../features/run-host-services.js';
17
+ const FORCED_TOOL_SYSTEM = [
18
+ 'You are an adversarial Critique node — not the author of the assignment.',
19
+ `Finish by calling exactly one control tool: ${REVIEW_ACCEPT_TOOL} or ${REVIEW_FEEDBACK_TOOL}.`,
20
+ 'Do not complete or rewrite the original assignment yourself.',
21
+ 'Your job is to attack the packet: contradictions, overclaim, unsafe assumptions, missing evidence, scope creep.',
22
+ 'You may call optional inventory tools first when they help investigate.',
23
+ 'Do not write free-form accept/reject essays.',
24
+ `Call ${REVIEW_FEEDBACK_TOOL} with concrete findings when the packet is not yet defensible.`,
25
+ `Call ${REVIEW_ACCEPT_TOOL} only when further attack is non-blocking — agreed enough to stop critiquing.`,
26
+ ].join(' ');
27
+ const requireChatConfig = (providerId, model) => {
28
+ if (providerId.trim().length === 0) {
29
+ throw new Error('Provider is required for Critique chat');
30
+ }
31
+ if (model.trim().length === 0) {
32
+ throw new Error('Model is required for Critique chat');
33
+ }
34
+ };
35
+ const buildEffectiveCritiqueSystem = (input) => {
36
+ const merged = buildEffectiveSystemPrompt(input);
37
+ const parts = [FORCED_TOOL_SYSTEM];
38
+ if (merged.trim().length > 0) {
39
+ parts.push(merged);
40
+ }
41
+ return parts.join('\n\n---\n\n');
42
+ };
43
+ const buildUserContent = (assignment, packet) => [
44
+ '## Original assignment',
45
+ assignment.trim().length > 0 ? assignment : '(empty assignment)',
46
+ '',
47
+ '## Packet to attack',
48
+ packet.trim().length > 0 ? packet : '(empty packet)',
49
+ ].join('\n');
50
+ const buildRevisedPacketUserContent = (packet) => [
51
+ '## Revised packet to attack',
52
+ packet.trim().length > 0 ? packet : '(empty packet)',
53
+ ].join('\n');
54
+ const hasUserMessage = (history) => history.some((message) => message.role === 'user');
55
+ const runCritiqueTurn = (context, packet, history) => {
56
+ const factory = context.factory;
57
+ if (factory === undefined) {
58
+ return new Observable((subscriber) => {
59
+ subscriber.error(new Error('Critique chat is only available during server workflow runs'));
60
+ });
61
+ }
62
+ requireChatConfig(context.providerId, context.model);
63
+ const userContent = hasUserMessage(history)
64
+ ? buildRevisedPacketUserContent(packet)
65
+ : buildUserContent(context.assignment, packet);
66
+ const messages = [
67
+ ...history,
68
+ { role: 'user', content: userContent },
69
+ ];
70
+ return runPathChoiceToolLoop({
71
+ factory,
72
+ providerId: context.providerId,
73
+ model: context.model,
74
+ messages,
75
+ maxIterations: context.maxIterations,
76
+ tools: context.tools,
77
+ compaction: context.compaction,
78
+ recovery: context.recovery,
79
+ steerControl$: context.steerControl$,
80
+ toolCtx: context.toolCtx,
81
+ }).pipe(map((chunk) => {
82
+ if (chunk.kind === 'accept') {
83
+ return {
84
+ kind: 'accept',
85
+ notes: chunk.notes,
86
+ result: packet,
87
+ };
88
+ }
89
+ return chunk;
90
+ }));
91
+ };
92
+ /**
93
+ * Adversarial Critique: path choice via the same Review-private control tools
94
+ * (`accept` / `feedback`). First input is the original assignment; second is
95
+ * the packet under attack. Optional inventory / MCP / Sub-Agents may run first.
96
+ *
97
+ * Session history uses the shared {@link createLlmSessionCycle$} (ADR-016):
98
+ * init = assignment / system / inventory; turn driver = `packet`.
99
+ */
100
+ export const critiqueNode = defineLlmNode({
101
+ type: 'common-critique',
102
+ displayName: 'Critique',
103
+ category: 'AI',
104
+ description: 'Adversarial Critique: first input is the original assignment/topic; second is the packet to attack. Finish with accept (agreed enough) or feedback (findings). Requires native tool / function calling. Optional wired tools / MCP / Sub-Agents may run via harness first.',
105
+ uiSchema: [
106
+ ...llmPanelUiSchema.filter((item) => item.field !== 'maxIterations'),
107
+ llmMaxIterationsUiField(DEFAULT_PATH_CHOICE_MAX_ITERATIONS, PATH_CHOICE_MAX_ITERATIONS_CAP),
108
+ ...llmCompactionUiSchema,
109
+ ...llmRecoveryUiSchema,
110
+ ],
111
+ bind(ctx, { makeInput, configureOutput, combineInputs }, inventory) {
112
+ const { tools, steerControl } = inventory;
113
+ const assignment = makeInput('assignment', {
114
+ name: 'assignment',
115
+ wireType: 'string',
116
+ inline: 'text-multiline',
117
+ required: true,
118
+ });
119
+ const packet = makeInput('packet', {
120
+ name: 'packet',
121
+ wireType: 'string',
122
+ inline: 'text-multiline',
123
+ required: true,
124
+ });
125
+ const systemPrompt = makeInput('systemPrompt', {
126
+ name: 'systemPrompt',
127
+ wireType: 'string',
128
+ inline: 'text-multiline',
129
+ defaultValue: '',
130
+ });
131
+ // Init peers only — packet is the session turn driver (ADR-016).
132
+ const context$ = combineInputs([assignment, systemPrompt, tools, ctx], ([assignmentValue, systemPromptValue, toolList, ec]) => {
133
+ const rolePreset = parseLlmRolePreset(ec.params.rolePreset);
134
+ const skillId = resolveEffectiveSkillId(rolePreset, ec.params.skillId);
135
+ const hostServices = getRunHostServices(ec);
136
+ const skillMarkdown = hostServices?.skillMarkdown ?? '';
137
+ const agentsMarkdown = hostServices?.agentsMarkdown ?? '';
138
+ return {
139
+ assignment: String(assignmentValue ?? ''),
140
+ ...resolveChatProviderModel(ec.params, hostServices),
141
+ skillId,
142
+ skillMarkdown,
143
+ effectiveSystemPrompt: buildEffectiveCritiqueSystem({
144
+ rolePreset,
145
+ systemPromptInput: String(systemPromptValue ?? ''),
146
+ agentsMarkdown,
147
+ skillMarkdown,
148
+ }),
149
+ factory: hostServices?.createChatCompletionStream,
150
+ maxIterations: normalizeMaxIterations(ec.params.maxIterations, {
151
+ fallback: DEFAULT_PATH_CHOICE_MAX_ITERATIONS,
152
+ maxCap: PATH_CHOICE_MAX_ITERATIONS_CAP,
153
+ }),
154
+ maxFeedbackTurns: normalizeMaxFeedbackTurns(ec.params.maxFeedbackTurns),
155
+ ...(hostServices?.requestPermission !== undefined
156
+ ? { requestPermission: hostServices.requestPermission }
157
+ : {}),
158
+ compaction: normalizeCompactionConfig(ec.params),
159
+ recovery: normalizeLlmRecoveryPolicy(ec.params),
160
+ steerControl$: steerControl.value$.pipe(filter(isSteerControlPayload)),
161
+ tools: collectAgentToolHandles({
162
+ toolHandles: ec.toolHandles,
163
+ toolsPort: toolList,
164
+ }),
165
+ toolCtx: {
166
+ projectDir: ec.projectDir,
167
+ runId: ec.runId,
168
+ ...(hostServices?.authorize !== undefined
169
+ ? { authorize: hostServices.authorize }
170
+ : {}),
171
+ ...(hostServices?.denyPaths !== undefined
172
+ ? { denyPaths: hostServices.denyPaths }
173
+ : {}),
174
+ ...(hostServices?.allowedHosts !== undefined
175
+ ? { allowedHosts: hostServices.allowedHosts }
176
+ : {}),
177
+ },
178
+ };
179
+ });
180
+ const cycle$ = createLlmSessionCycle$(context$, packet.value$, (context) => ({
181
+ history: [
182
+ {
183
+ role: 'system',
184
+ content: context.effectiveSystemPrompt,
185
+ },
186
+ ],
187
+ trackAssistantHistory: false,
188
+ appendUserFeedbackToHistory: false,
189
+ session: undefined,
190
+ }), (context, turnPayload, history) => runCritiqueTurn(context, String(turnPayload ?? ''), history), { primeTurn0: false });
191
+ const reasoning$ = cycle$.pipeValue(demuxByKind('reasoning', (chunk) => chunk
192
+ .text));
193
+ const draftResponse$ = cycle$.pipeValue(demuxByKind('draftResponse', (chunk) => chunk
194
+ .text));
195
+ const toolLog$ = cycle$.pipeValue(demuxByKind('toolLog', (chunk) => chunk.text));
196
+ const recovery$ = cycle$.pipeValue(demuxByKind('recoveryNotice', (chunk) => {
197
+ const notice = chunk;
198
+ return toLlmRecoveryPortValue(notice);
199
+ }));
200
+ const response$ = cycle$.pipeValue(demuxByKind('accept', (chunk) => chunk
201
+ .result));
202
+ const feedback$ = cycle$.pipeValue(demuxByKind('feedback', (chunk) => chunk
203
+ .notes));
204
+ return {
205
+ inputs: [assignment, packet, systemPrompt],
206
+ outputs: [
207
+ configureOutput('reasoning', reasoning$, {
208
+ wireType: 'string',
209
+ feed: { role: 'reasoning', streaming: true },
210
+ }),
211
+ configureOutput('draftResponse', draftResponse$, {
212
+ wireType: 'string',
213
+ feed: { role: 'draft', streaming: true },
214
+ }),
215
+ configureOutput('response', response$, {
216
+ wireType: 'string',
217
+ feed: { role: 'result' },
218
+ }),
219
+ configureOutput('feedback', feedback$, {
220
+ wireType: 'string',
221
+ feed: { role: 'result' },
222
+ }),
223
+ ],
224
+ inventoryOutputs: { toolLog$, recovery$ },
225
+ };
226
+ },
227
+ });