@evandu/super-pi-server 0.0.0-stage → 0.1.259
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.
- package/README.md +248 -3
- package/agents/code-auditor.md +64 -0
- package/agents/code-designer.md +64 -0
- package/agents/coder.md +24 -0
- package/agents/critic.md +24 -0
- package/agents/document-organizer.md +48 -0
- package/agents/patcher.md +27 -0
- package/agents/planner.md +30 -0
- package/agents/project-leader.md +28 -0
- package/agents/reviewer.md +27 -0
- package/agents/scout.md +27 -0
- package/agents/solution-designer.md +62 -0
- package/agents/super-pi-documents/index.ts +92 -0
- package/agents/super-pi-feishu/index.ts +88 -0
- package/agents/super-pi-knowledge/index.ts +70 -0
- package/agents/super-pi-managed-model/index.ts +9 -0
- package/agents/super-pi-memory/index.ts +75 -0
- package/agents/super-pi-native-tools/index.ts +1 -0
- package/agents/super-pi-task/core.ts +2262 -0
- package/agents/super-pi-task/index.ts +814 -0
- package/agents/super-pi-task/workflow-schema.ts +34 -0
- package/agents/super-pi-web/index.ts +32 -0
- package/agents/verifier.md +25 -0
- package/assets/fonts/LICENSE +92 -0
- package/assets/fonts/NotoSansSC-Bold.otf +0 -0
- package/assets/fonts/NotoSansSC-Regular.otf +0 -0
- package/assets/knowledge-model/README.md +37 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/config.json +31 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/special_tokens_map.json +7 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer.json +21278 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer_config.json +15 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/vocab.txt +21128 -0
- package/bin/npm-prefix.d.ts +1 -0
- package/bin/npm-prefix.js +10 -0
- package/bin/super-pi.js +349 -0
- package/dist/client/.super-pi-client-sources.json +82 -0
- package/dist/client/assets/CodeMirrorEditor-mi9rGUce.js +2 -0
- package/dist/client/assets/GitDiffEditor-CpoDDQrA.css +1 -0
- package/dist/client/assets/GitDiffEditor-FQBfGxOY.js +29 -0
- package/dist/client/assets/diff-ChtP43wD.js +1 -0
- package/dist/client/assets/dist-AW5lyI3I.js +1 -0
- package/dist/client/assets/dist-B3-a6uF0.js +7 -0
- package/dist/client/assets/dist-BGxkyh6e.js +1 -0
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/dist-BRVQKlcp.js +1 -0
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/dist-BXAOrsjq.js +1 -0
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/dist-Cus6_oaF.js +2 -0
- package/dist/client/assets/dist-Cx00EZKR.js +23 -0
- package/dist/client/assets/dist-D71y2EI1.js +1 -0
- package/dist/client/assets/dist-D978o95T.js +5 -0
- package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/dist-DeD9copn.js +1 -0
- package/dist/client/assets/dist-DuvGReu-.js +6 -0
- package/dist/client/assets/dist-Dvb0SqcK.js +2 -0
- package/dist/client/assets/dist-J6XWqRpB.js +3 -0
- package/dist/client/assets/dist-QzbOCAU6.js +1 -0
- package/dist/client/assets/dist-moiMRpw_.js +1 -0
- package/dist/client/assets/dist-scBkrwv-.js +2 -0
- package/dist/client/assets/dockerfile-BDePf5PZ.js +1 -0
- package/dist/client/assets/index-Cn7hdrDw.js +350 -0
- package/dist/client/assets/index-UfzqdECL.css +1 -0
- package/dist/client/assets/powershell-D8WpQPaX.js +1 -0
- package/dist/client/assets/properties-C357ku5U.js +1 -0
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/ruby-ChfNwlCY.js +1 -0
- package/dist/client/assets/shell-DwuoZtxw.js +1 -0
- package/dist/client/assets/swift-DKB6_1j6.js +1 -0
- package/dist/client/assets/toml-BPTmHmyx.js +1 -0
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +10 -0
- package/dist/client/index.html +18 -0
- package/dist/extension.d.ts +15 -0
- package/dist/extension.js +126 -0
- package/dist/server/active-memory.d.ts +247 -0
- package/dist/server/active-memory.js +669 -0
- package/dist/server/agents.d.ts +245 -0
- package/dist/server/agents.js +701 -0
- package/dist/server/application/catalog-service.d.ts +98 -0
- package/dist/server/application/catalog-service.js +245 -0
- package/dist/server/application/conversation-service.d.ts +245 -0
- package/dist/server/application/conversation-service.js +654 -0
- package/dist/server/application/document-service.d.ts +68 -0
- package/dist/server/application/document-service.js +120 -0
- package/dist/server/application/extension-ui-service.d.ts +44 -0
- package/dist/server/application/extension-ui-service.js +135 -0
- package/dist/server/application/feishu-service.d.ts +179 -0
- package/dist/server/application/feishu-service.js +358 -0
- package/dist/server/application/group-chat-service.d.ts +75 -0
- package/dist/server/application/group-chat-service.js +953 -0
- package/dist/server/application/group-execution.d.ts +15 -0
- package/dist/server/application/group-execution.js +77 -0
- package/dist/server/application/project-service.d.ts +464 -0
- package/dist/server/application/project-service.js +2523 -0
- package/dist/server/application/provider-service.d.ts +174 -0
- package/dist/server/application/provider-service.js +510 -0
- package/dist/server/application/run-service.d.ts +547 -0
- package/dist/server/application/run-service.js +2683 -0
- package/dist/server/application/scheduled-task-service.d.ts +184 -0
- package/dist/server/application/scheduled-task-service.js +391 -0
- package/dist/server/application/session-orchestrator-service.d.ts +388 -0
- package/dist/server/application/session-orchestrator-service.js +1146 -0
- package/dist/server/application/session-reminder-service.d.ts +59 -0
- package/dist/server/application/session-reminder-service.js +141 -0
- package/dist/server/application/session-watchdog.d.ts +171 -0
- package/dist/server/application/session-watchdog.js +284 -0
- package/dist/server/application/workspace-service.d.ts +52 -0
- package/dist/server/application/workspace-service.js +186 -0
- package/dist/server/application/worktree-service.d.ts +13 -0
- package/dist/server/application/worktree-service.js +76 -0
- package/dist/server/browser-access.d.ts +34 -0
- package/dist/server/browser-access.js +89 -0
- package/dist/server/capability.d.ts +105 -0
- package/dist/server/capability.js +170 -0
- package/dist/server/command-handler.d.ts +93 -0
- package/dist/server/command-handler.js +540 -0
- package/dist/server/content-search.d.ts +16 -0
- package/dist/server/content-search.js +235 -0
- package/dist/server/conversation-usage.d.ts +22 -0
- package/dist/server/conversation-usage.js +43 -0
- package/dist/server/documents.d.ts +152 -0
- package/dist/server/documents.js +998 -0
- package/dist/server/engineering-learning.d.ts +30 -0
- package/dist/server/engineering-learning.js +106 -0
- package/dist/server/exec-service.d.ts +45 -0
- package/dist/server/exec-service.js +167 -0
- package/dist/server/explicit-file-open.d.ts +34 -0
- package/dist/server/explicit-file-open.js +105 -0
- package/dist/server/failure-text.d.ts +18 -0
- package/dist/server/failure-text.js +44 -0
- package/dist/server/feishu-cli.d.ts +223 -0
- package/dist/server/feishu-cli.js +464 -0
- package/dist/server/file-changes.d.ts +119 -0
- package/dist/server/file-changes.js +280 -0
- package/dist/server/file-diff.d.ts +41 -0
- package/dist/server/file-diff.js +97 -0
- package/dist/server/file-index.d.ts +100 -0
- package/dist/server/file-index.js +296 -0
- package/dist/server/file-name-index.d.ts +160 -0
- package/dist/server/file-name-index.js +411 -0
- package/dist/server/files.d.ts +269 -0
- package/dist/server/files.js +748 -0
- package/dist/server/git.d.ts +245 -0
- package/dist/server/git.js +903 -0
- package/dist/server/http-server.d.ts +45 -0
- package/dist/server/http-server.js +3830 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +485 -0
- package/dist/server/inline-thinking.d.ts +90 -0
- package/dist/server/inline-thinking.js +181 -0
- package/dist/server/json-comments.d.ts +14 -0
- package/dist/server/json-comments.js +71 -0
- package/dist/server/knowledge-embedding-worker.d.ts +1 -0
- package/dist/server/knowledge-embedding-worker.js +27 -0
- package/dist/server/knowledge-vectors.d.ts +150 -0
- package/dist/server/knowledge-vectors.js +385 -0
- package/dist/server/knowledge.d.ts +273 -0
- package/dist/server/knowledge.js +848 -0
- package/dist/server/length-continuation.d.ts +83 -0
- package/dist/server/length-continuation.js +118 -0
- package/dist/server/logging.d.ts +32 -0
- package/dist/server/logging.js +185 -0
- package/dist/server/managed-http-tunnel.d.ts +6 -0
- package/dist/server/managed-http-tunnel.js +85 -0
- package/dist/server/managed-http.d.ts +4 -0
- package/dist/server/managed-http.js +85 -0
- package/dist/server/managed-model-adapter.d.ts +17 -0
- package/dist/server/managed-model-adapter.js +75 -0
- package/dist/server/managed-model-gateway.d.ts +49 -0
- package/dist/server/managed-model-gateway.js +73 -0
- package/dist/server/managed-servers.d.ts +55 -0
- package/dist/server/managed-servers.js +392 -0
- package/dist/server/managed-ssh.d.ts +26 -0
- package/dist/server/managed-ssh.js +73 -0
- package/dist/server/manager-vault.d.ts +11 -0
- package/dist/server/manager-vault.js +67 -0
- package/dist/server/memory-recall.d.ts +25 -0
- package/dist/server/memory-recall.js +45 -0
- package/dist/server/memory.d.ts +67 -0
- package/dist/server/memory.js +216 -0
- package/dist/server/message-media.d.ts +7 -0
- package/dist/server/message-media.js +54 -0
- package/dist/server/model-context-window.d.ts +186 -0
- package/dist/server/model-context-window.js +444 -0
- package/dist/server/model-filter.d.ts +23 -0
- package/dist/server/model-filter.js +48 -0
- package/dist/server/models-store.d.ts +36 -0
- package/dist/server/models-store.js +132 -0
- package/dist/server/native-tool-settings.d.ts +25 -0
- package/dist/server/native-tool-settings.js +41 -0
- package/dist/server/native-tools-extension.d.ts +2 -0
- package/dist/server/native-tools-extension.js +39 -0
- package/dist/server/native-tools-service.d.ts +39 -0
- package/dist/server/native-tools-service.js +240 -0
- package/dist/server/persistence/app-state-repository.d.ts +65 -0
- package/dist/server/persistence/app-state-repository.js +1 -0
- package/dist/server/persistence/json-state-repository.d.ts +14 -0
- package/dist/server/persistence/json-state-repository.js +43 -0
- package/dist/server/persistence/open-state-store.d.ts +3 -0
- package/dist/server/persistence/open-state-store.js +35 -0
- package/dist/server/persistence/rename.d.ts +22 -0
- package/dist/server/persistence/rename.js +44 -0
- package/dist/server/persistence/sqlite-state-repository.d.ts +12 -0
- package/dist/server/persistence/sqlite-state-repository.js +264 -0
- package/dist/server/pi-command.d.ts +94 -0
- package/dist/server/pi-command.js +265 -0
- package/dist/server/pi-native.d.ts +12 -0
- package/dist/server/pi-native.js +16 -0
- package/dist/server/pi-session-events.d.ts +158 -0
- package/dist/server/pi-session-events.js +373 -0
- package/dist/server/pi-session-pool.d.ts +233 -0
- package/dist/server/pi-session-pool.js +382 -0
- package/dist/server/pi-session.d.ts +642 -0
- package/dist/server/pi-session.js +655 -0
- package/dist/server/presentations/schema.d.ts +120 -0
- package/dist/server/presentations/schema.js +128 -0
- package/dist/server/provider-network.d.ts +16 -0
- package/dist/server/provider-network.js +106 -0
- package/dist/server/provider-proxy.d.ts +18 -0
- package/dist/server/provider-proxy.js +200 -0
- package/dist/server/providers.d.ts +333 -0
- package/dist/server/providers.js +989 -0
- package/dist/server/remote-bootstrap.d.ts +17 -0
- package/dist/server/remote-bootstrap.js +119 -0
- package/dist/server/rpc-channel.d.ts +131 -0
- package/dist/server/rpc-channel.js +135 -0
- package/dist/server/runtime.d.ts +1393 -0
- package/dist/server/runtime.js +3286 -0
- package/dist/server/scheduled-tasks.d.ts +101 -0
- package/dist/server/scheduled-tasks.js +138 -0
- package/dist/server/server-context.d.ts +119 -0
- package/dist/server/server-context.js +1 -0
- package/dist/server/session-cwd.d.ts +19 -0
- package/dist/server/session-cwd.js +58 -0
- package/dist/server/session-ledger.d.ts +67 -0
- package/dist/server/session-ledger.js +76 -0
- package/dist/server/session-memory-scope.d.ts +4 -0
- package/dist/server/session-memory-scope.js +30 -0
- package/dist/server/session-repository.d.ts +100 -0
- package/dist/server/session-repository.js +246 -0
- package/dist/server/session-tree-scope.d.ts +125 -0
- package/dist/server/session-tree-scope.js +337 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +190 -0
- package/dist/server/store.d.ts +1062 -0
- package/dist/server/store.js +3305 -0
- package/dist/server/subagent-runs.d.ts +185 -0
- package/dist/server/subagent-runs.js +383 -0
- package/dist/server/subagents.d.ts +200 -0
- package/dist/server/subagents.js +619 -0
- package/dist/server/task-tool.d.ts +282 -0
- package/dist/server/task-tool.js +507 -0
- package/dist/server/tavily.d.ts +32 -0
- package/dist/server/tavily.js +136 -0
- package/dist/server/team-context.d.ts +12 -0
- package/dist/server/team-context.js +180 -0
- package/dist/server/terminal.d.ts +163 -0
- package/dist/server/terminal.js +557 -0
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +183 -0
- package/dist/server/time-zone.d.ts +20 -0
- package/dist/server/time-zone.js +32 -0
- package/dist/server/tool-calls.d.ts +130 -0
- package/dist/server/tool-calls.js +341 -0
- package/dist/server/tool-llm.d.ts +72 -0
- package/dist/server/tool-llm.js +146 -0
- package/dist/server/tool-registry.d.ts +129 -0
- package/dist/server/tool-registry.js +249 -0
- package/dist/server/tool-runner.d.ts +112 -0
- package/dist/server/tool-runner.js +306 -0
- package/dist/server/turn-failure.d.ts +48 -0
- package/dist/server/turn-failure.js +148 -0
- package/dist/server/types.d.ts +2315 -0
- package/dist/server/types.js +11 -0
- package/dist/server/update-status.d.ts +14 -0
- package/dist/server/update-status.js +69 -0
- package/dist/server/update.d.ts +46 -0
- package/dist/server/update.js +104 -0
- package/dist/server/upload.d.ts +35 -0
- package/dist/server/upload.js +177 -0
- package/dist/server/version.d.ts +33 -0
- package/dist/server/version.js +111 -0
- package/dist/server/web.d.ts +27 -0
- package/dist/server/web.js +183 -0
- package/dist/server/workflow-engine.d.ts +47 -0
- package/dist/server/workflow-engine.js +255 -0
- package/dist/server/workflow.d.ts +329 -0
- package/dist/server/workflow.js +469 -0
- package/dist/server/workspace-file-indexes.d.ts +2 -0
- package/dist/server/workspace-file-indexes.js +61 -0
- package/dist/server/workspace-file-operations.d.ts +36 -0
- package/dist/server/workspace-file-operations.js +281 -0
- package/dist/server/workspace-file-response.d.ts +7 -0
- package/dist/server/workspace-file-response.js +79 -0
- package/dist/server/ws-server.d.ts +149 -0
- package/dist/server/ws-server.js +640 -0
- package/dist/shared/agent-order.d.ts +44 -0
- package/dist/shared/agent-order.js +50 -0
- package/dist/shared/archive-decisions.d.ts +44 -0
- package/dist/shared/archive-decisions.js +98 -0
- package/dist/shared/background-task.d.ts +25 -0
- package/dist/shared/background-task.js +183 -0
- package/dist/shared/child-session-lock.d.ts +37 -0
- package/dist/shared/child-session-lock.js +59 -0
- package/dist/shared/content-search.d.ts +22 -0
- package/dist/shared/content-search.js +1 -0
- package/dist/shared/conversation-title.d.ts +4 -0
- package/dist/shared/conversation-title.js +4 -0
- package/dist/shared/file-mentions.d.ts +17 -0
- package/dist/shared/file-mentions.js +91 -0
- package/dist/shared/git-commit.d.ts +11 -0
- package/dist/shared/git-commit.js +1 -0
- package/dist/shared/git-graph.d.ts +42 -0
- package/dist/shared/git-graph.js +30 -0
- package/dist/shared/group-chat.d.ts +132 -0
- package/dist/shared/group-chat.js +6 -0
- package/dist/shared/managed-servers.d.ts +36 -0
- package/dist/shared/managed-servers.js +1 -0
- package/dist/shared/message-media.d.ts +12 -0
- package/dist/shared/message-media.js +27 -0
- package/dist/shared/model-window-label.d.ts +39 -0
- package/dist/shared/model-window-label.js +55 -0
- package/dist/shared/native-tools.d.ts +43 -0
- package/dist/shared/native-tools.js +1 -0
- package/dist/shared/pi-cache-warming.d.ts +9 -0
- package/dist/shared/pi-cache-warming.js +4 -0
- package/dist/shared/project-overview.d.ts +107 -0
- package/dist/shared/project-overview.js +92 -0
- package/dist/shared/project-presentation.d.ts +55 -0
- package/dist/shared/project-presentation.js +111 -0
- package/dist/shared/provider-network.d.ts +30 -0
- package/dist/shared/provider-network.js +1 -0
- package/dist/shared/session-reporting.d.ts +40 -0
- package/dist/shared/session-reporting.js +97 -0
- package/dist/shared/session-search.d.ts +14 -0
- package/dist/shared/session-search.js +1 -0
- package/dist/shared/team-context-view.d.ts +33 -0
- package/dist/shared/team-context-view.js +49 -0
- package/dist/shared/team-context.d.ts +59 -0
- package/dist/shared/team-context.js +3 -0
- package/dist/shared/terminal-protocol.d.ts +71 -0
- package/dist/shared/terminal-protocol.js +1 -0
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/dist/shared/tool-glyph.d.ts +7 -0
- package/dist/shared/tool-glyph.js +19 -0
- package/dist/shared/transcript-order.d.ts +7 -0
- package/dist/shared/transcript-order.js +12 -0
- package/dist/shared/update-status.d.ts +28 -0
- package/dist/shared/update-status.js +1 -0
- package/dist/shared/workspace-file-preview.d.ts +4 -0
- package/dist/shared/workspace-file-preview.js +28 -0
- package/package.json +448 -4
- package/scripts/diagnose.mjs +603 -0
- package/scripts/patch-brace-expansion.mjs +260 -0
- package/scripts/restart-server.mjs +104 -0
- package/skills/presentation/SKILL.md +30 -0
- package/skills/presentation/references/data.md +10 -0
- package/skills/presentation/references/quality.md +12 -0
- package/skills/presentation/references/story.md +12 -0
- package/skills/presentation/references/templates-and-editing.md +11 -0
- package/skills/presentation/references/visual-system.md +10 -0
- package/skills/super-pi-agent-development/SKILL.md +25 -0
- package/skills/super-pi-development/SKILL.md +31 -0
- package/skills/super-pi-tool-development/SKILL.md +39 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
import { lookup } from "node:dns/promises";
|
|
3
|
+
import { request as httpRequest } from "node:http";
|
|
4
|
+
import { request as httpsRequest } from "node:https";
|
|
5
|
+
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
6
|
+
export const WEB_SEARCH_TOOL_NAME = "web_search";
|
|
7
|
+
export const WEB_FETCH_TOOL_NAME = "web_fetch";
|
|
8
|
+
export const MAX_WEB_REQUEST_BYTES = 64 * 1024;
|
|
9
|
+
const SEARCH_LIMIT = 10;
|
|
10
|
+
const RESPONSE_LIMIT = 2 * 1024 * 1024;
|
|
11
|
+
const TEXT_LIMIT = 30_000;
|
|
12
|
+
const REDIRECT_LIMIT = 5;
|
|
13
|
+
const TIMEOUT_MS = 15_000;
|
|
14
|
+
const USER_AGENT = "Mozilla/5.0 (compatible; SuperPi/1.0; +https://www.npmjs.com/package/@evandu/super-pi)";
|
|
15
|
+
function decodeEntities(value) {
|
|
16
|
+
const named = { amp: "&", quot: '"', apos: "'", lt: "<", gt: ">", nbsp: " " };
|
|
17
|
+
return value.replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (_all, entity) => {
|
|
18
|
+
if (entity[0] === "#") {
|
|
19
|
+
const code = entity[1]?.toLowerCase() === "x" ? Number.parseInt(entity.slice(2), 16) : Number.parseInt(entity.slice(1), 10);
|
|
20
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : "";
|
|
21
|
+
}
|
|
22
|
+
return named[entity.toLowerCase()] ?? `&${entity};`;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function plainText(html) {
|
|
26
|
+
return decodeEntities(html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ").replace(/<[^>]+>/g, " "))
|
|
27
|
+
.replace(/\s+/g, " ").trim();
|
|
28
|
+
}
|
|
29
|
+
/** Parse DuckDuckGo Lite result rows and unwrap their destination URLs. */
|
|
30
|
+
export function parseDuckDuckGoResults(html, limit = 5) {
|
|
31
|
+
const results = [];
|
|
32
|
+
const starts = [...html.matchAll(/<a\b(?=[^>]*\bclass=["'][^"']*\bresult-link\b[^"']*["'])[^>]*>/gi)].map(match => match.index);
|
|
33
|
+
const blocks = starts.map((start, index) => html.slice(start, starts[index + 1] ?? html.length));
|
|
34
|
+
for (const block of blocks) {
|
|
35
|
+
const anchor = /<a\b(?=[^>]*\bclass=["'][^"']*\bresult-link\b[^"']*["'])[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/i.exec(block);
|
|
36
|
+
if (!anchor)
|
|
37
|
+
continue;
|
|
38
|
+
let url;
|
|
39
|
+
try {
|
|
40
|
+
url = new URL(decodeEntities(anchor[1]), "https://duckduckgo.com");
|
|
41
|
+
if (url.hostname === "duckduckgo.com" && url.pathname === "/l/") {
|
|
42
|
+
const destination = url.searchParams.get("uddg");
|
|
43
|
+
if (!destination)
|
|
44
|
+
continue;
|
|
45
|
+
url = new URL(destination);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!/^https?:$/.test(url.protocol) || url.username || url.password || /(^|\.)duckduckgo\.com$/i.test(url.hostname))
|
|
52
|
+
continue;
|
|
53
|
+
const cleanTitle = plainText(anchor[2]);
|
|
54
|
+
const caption = /<td\b[^>]*class=["'][^"']*\bresult-snippet\b[^"']*["'][^>]*>([\s\S]*?)<\/td>/i.exec(block)?.[1] ?? "";
|
|
55
|
+
if (!cleanTitle)
|
|
56
|
+
continue;
|
|
57
|
+
results.push({ title: cleanTitle, url: url.href, snippet: plainText(caption) });
|
|
58
|
+
if (results.length >= Math.min(SEARCH_LIMIT, Math.max(1, limit)))
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return results;
|
|
62
|
+
}
|
|
63
|
+
function blockedAddress(address) {
|
|
64
|
+
if (address === "::" || address === "::1")
|
|
65
|
+
return true;
|
|
66
|
+
const v4 = address.startsWith("::ffff:") ? address.slice(7) : address;
|
|
67
|
+
if (isIP(v4) === 4) {
|
|
68
|
+
const [a, b] = v4.split(".").map(Number);
|
|
69
|
+
return a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || a >= 224;
|
|
70
|
+
}
|
|
71
|
+
const normalized = address.toLowerCase();
|
|
72
|
+
return normalized.startsWith("fc") || normalized.startsWith("fd") || normalized.startsWith("fe8") || normalized.startsWith("fe9") || normalized.startsWith("fea") || normalized.startsWith("feb") || normalized.startsWith("ff");
|
|
73
|
+
}
|
|
74
|
+
async function publicAddress(hostname) {
|
|
75
|
+
if (hostname.toLowerCase() === "localhost" || hostname.endsWith(".localhost"))
|
|
76
|
+
throw new Error("不允许访问本机或私网地址");
|
|
77
|
+
const records = isIP(hostname) ? [{ address: hostname, family: isIP(hostname) }] : await lookup(hostname, { all: true, verbatim: true });
|
|
78
|
+
const record = records.find(item => !blockedAddress(item.address));
|
|
79
|
+
if (!record || records.some(item => blockedAddress(item.address)))
|
|
80
|
+
throw new Error("不允许访问本机或私网地址");
|
|
81
|
+
return record;
|
|
82
|
+
}
|
|
83
|
+
async function download(input, signal, redirects = 0) {
|
|
84
|
+
const url = new URL(input);
|
|
85
|
+
if (!/^https?:$/.test(url.protocol) || url.username || url.password)
|
|
86
|
+
throw new Error("只允许无凭据的 HTTP/HTTPS URL");
|
|
87
|
+
if (redirects > REDIRECT_LIMIT)
|
|
88
|
+
throw new Error("网页重定向次数过多");
|
|
89
|
+
const resolved = await publicAddress(url.hostname);
|
|
90
|
+
const requester = url.protocol === "https:" ? httpsRequest : httpRequest;
|
|
91
|
+
// Node may ask a custom lookup for one address or an array (`all: true`). Honor both overloads;
|
|
92
|
+
// returning the wrong shape makes net.connect report the misleading "Invalid IP address: undefined".
|
|
93
|
+
const pinnedLookup = ((_hostname, options, callback) => {
|
|
94
|
+
if (options?.all)
|
|
95
|
+
callback(null, [resolved]);
|
|
96
|
+
else
|
|
97
|
+
callback(null, resolved.address, resolved.family);
|
|
98
|
+
});
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
const req = requester(url, {
|
|
101
|
+
headers: { "user-agent": USER_AGENT, accept: "text/html,text/plain,application/xhtml+xml", "accept-encoding": "gzip, deflate, br" },
|
|
102
|
+
lookup: pinnedLookup,
|
|
103
|
+
servername: url.hostname,
|
|
104
|
+
timeout: TIMEOUT_MS,
|
|
105
|
+
signal,
|
|
106
|
+
}, response => {
|
|
107
|
+
const status = response.statusCode ?? 0;
|
|
108
|
+
const location = response.headers.location;
|
|
109
|
+
if (status >= 300 && status < 400 && location) {
|
|
110
|
+
response.resume();
|
|
111
|
+
download(new URL(location, url).href, signal, redirects + 1).then(resolve, reject);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (status < 200 || status >= 300) {
|
|
115
|
+
response.resume();
|
|
116
|
+
reject(new Error(`网页请求失败(HTTP ${status})`));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const chunks = [];
|
|
120
|
+
let bytes = 0;
|
|
121
|
+
response.on("data", chunk => {
|
|
122
|
+
bytes += chunk.length;
|
|
123
|
+
if (bytes > RESPONSE_LIMIT) {
|
|
124
|
+
req.destroy(new Error("网页响应超过 2 MB 限制"));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
chunks.push(chunk);
|
|
128
|
+
});
|
|
129
|
+
response.on("end", () => {
|
|
130
|
+
try {
|
|
131
|
+
let body = Buffer.concat(chunks);
|
|
132
|
+
const encoding = String(response.headers["content-encoding"] ?? "").toLowerCase();
|
|
133
|
+
if (encoding === "gzip")
|
|
134
|
+
body = gunzipSync(body);
|
|
135
|
+
else if (encoding === "deflate")
|
|
136
|
+
body = inflateSync(body);
|
|
137
|
+
else if (encoding === "br")
|
|
138
|
+
body = brotliDecompressSync(body);
|
|
139
|
+
resolve({ url: url.href, body, contentType: String(response.headers["content-type"] ?? "application/octet-stream") });
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
reject(error);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
req.on("timeout", () => req.destroy(new Error("网页请求超时")));
|
|
147
|
+
req.on("error", reject);
|
|
148
|
+
req.end();
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function extractHtml(html) {
|
|
152
|
+
const title = plainText(/<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(html)?.[1] ?? "");
|
|
153
|
+
let body = /<article\b[^>]*>([\s\S]*?)<\/article>/i.exec(html)?.[1]
|
|
154
|
+
?? /<main\b[^>]*>([\s\S]*?)<\/main>/i.exec(html)?.[1]
|
|
155
|
+
?? /<body\b[^>]*>([\s\S]*?)<\/body>/i.exec(html)?.[1]
|
|
156
|
+
?? html;
|
|
157
|
+
body = body.replace(/<(nav|aside|footer|form|noscript|svg)\b[^>]*>[\s\S]*?<\/\1>/gi, " ")
|
|
158
|
+
.replace(/<(br|p|div|li|h[1-6]|tr)\b[^>]*>/gi, "\n")
|
|
159
|
+
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
|
|
160
|
+
.replace(/<[^>]+>/g, " ");
|
|
161
|
+
const text = decodeEntities(body).replace(/[ \t]+/g, " ").replace(/\n\s*/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
162
|
+
return { title, text };
|
|
163
|
+
}
|
|
164
|
+
export class WebService {
|
|
165
|
+
tavily;
|
|
166
|
+
constructor(tavily) {
|
|
167
|
+
this.tavily = tavily;
|
|
168
|
+
}
|
|
169
|
+
async search(query, limit = 5, signal) {
|
|
170
|
+
if (!this.tavily)
|
|
171
|
+
throw new Error("网页搜索服务未配置。");
|
|
172
|
+
return this.tavily.search(query, limit, signal);
|
|
173
|
+
}
|
|
174
|
+
async fetch(url, signal) {
|
|
175
|
+
const response = await download(url, signal);
|
|
176
|
+
if (!/^(text\/html|application\/xhtml\+xml|text\/plain)\b/i.test(response.contentType))
|
|
177
|
+
throw new Error(`不支持的网页类型:${response.contentType}`);
|
|
178
|
+
const decoded = response.body.toString("utf8");
|
|
179
|
+
const extracted = /^text\/plain\b/i.test(response.contentType) ? { title: "", text: decoded.trim() } : extractHtml(decoded);
|
|
180
|
+
const truncated = extracted.text.length > TEXT_LIMIT;
|
|
181
|
+
return { title: extracted.title, url: response.url, text: extracted.text.slice(0, TEXT_LIMIT), truncated, contentType: response.contentType };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SubagentRunRecorder } from "./subagent-runs.js";
|
|
2
|
+
import type { Store } from "./store.js";
|
|
3
|
+
import type { ModelSelection, ServerEvent } from "./types.js";
|
|
4
|
+
import { type WorkflowPlan, type WorkflowRun } from "./workflow.js";
|
|
5
|
+
/**
|
|
6
|
+
* Recursive descent over the primary's plan. This engine owns execution order and the mechanical `until`
|
|
7
|
+
* comparison; it does not infer tasks, discover foreach items, or ask a child whether another round should
|
|
8
|
+
* run. Spawning, streaming and teardown remain behind `SubagentRunRecorder.dispatch`, which always resolves
|
|
9
|
+
* with a settled record.
|
|
10
|
+
*/
|
|
11
|
+
export type WorkflowEngineHooks = {
|
|
12
|
+
store: Store;
|
|
13
|
+
broadcast: (event: ServerEvent) => void;
|
|
14
|
+
};
|
|
15
|
+
export type WorkflowRunInput = {
|
|
16
|
+
conversationId: string;
|
|
17
|
+
cwd: string;
|
|
18
|
+
plan: WorkflowPlan;
|
|
19
|
+
model?: ModelSelection;
|
|
20
|
+
denyTools?: readonly string[];
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
};
|
|
23
|
+
export type WorkflowOutcome = {
|
|
24
|
+
workflow: WorkflowRun;
|
|
25
|
+
};
|
|
26
|
+
export declare class WorkflowEngine {
|
|
27
|
+
private readonly recorder;
|
|
28
|
+
private readonly hooks;
|
|
29
|
+
private readonly controllers;
|
|
30
|
+
private readonly owners;
|
|
31
|
+
constructor(recorder: SubagentRunRecorder, hooks: WorkflowEngineHooks);
|
|
32
|
+
stop(workflowId: string): boolean;
|
|
33
|
+
stopConversation(conversationId: string): number;
|
|
34
|
+
abortAll(): void;
|
|
35
|
+
waitForIdle(): Promise<void>;
|
|
36
|
+
private conversationOf;
|
|
37
|
+
run(input: WorkflowRunInput): Promise<WorkflowOutcome>;
|
|
38
|
+
/** Allocates execution rows once per statically known occurrence; loop occurrences are allocated per round. */
|
|
39
|
+
private materializeNodes;
|
|
40
|
+
private runNodes;
|
|
41
|
+
private runLoop;
|
|
42
|
+
private runForeach;
|
|
43
|
+
private runStep;
|
|
44
|
+
private haltRemaining;
|
|
45
|
+
/** Persist first, announce second, so a reload never contradicts an event already shown. */
|
|
46
|
+
private commit;
|
|
47
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { attemptFromRun, composeStepPrompt, newWorkflowRunId, retriesFor, substituteWorkflowVariables, workflowUntilMet, WORKFLOW_DEFAULT_LOOP_MAX, } from "./workflow.js";
|
|
2
|
+
const now = () => new Date().toISOString();
|
|
3
|
+
export class WorkflowEngine {
|
|
4
|
+
recorder;
|
|
5
|
+
hooks;
|
|
6
|
+
controllers = new Map();
|
|
7
|
+
owners = new Map();
|
|
8
|
+
constructor(recorder, hooks) {
|
|
9
|
+
this.recorder = recorder;
|
|
10
|
+
this.hooks = hooks;
|
|
11
|
+
}
|
|
12
|
+
stop(workflowId) {
|
|
13
|
+
const controller = this.controllers.get(workflowId);
|
|
14
|
+
if (!controller)
|
|
15
|
+
return false;
|
|
16
|
+
controller.abort();
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
stopConversation(conversationId) {
|
|
20
|
+
let stopped = 0;
|
|
21
|
+
for (const [id, controller] of this.controllers) {
|
|
22
|
+
if (this.conversationOf(id) === conversationId) {
|
|
23
|
+
controller.abort();
|
|
24
|
+
stopped += 1;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return stopped;
|
|
28
|
+
}
|
|
29
|
+
abortAll() {
|
|
30
|
+
for (const controller of this.controllers.values())
|
|
31
|
+
controller.abort();
|
|
32
|
+
}
|
|
33
|
+
async waitForIdle() {
|
|
34
|
+
while (this.controllers.size > 0)
|
|
35
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
36
|
+
}
|
|
37
|
+
conversationOf(workflowId) {
|
|
38
|
+
return this.owners.get(workflowId);
|
|
39
|
+
}
|
|
40
|
+
async run(input) {
|
|
41
|
+
const id = newWorkflowRunId();
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const onCallerAbort = () => controller.abort();
|
|
44
|
+
input.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
45
|
+
if (input.signal?.aborted)
|
|
46
|
+
controller.abort();
|
|
47
|
+
this.controllers.set(id, controller);
|
|
48
|
+
this.owners.set(id, input.conversationId);
|
|
49
|
+
const definitions = input.plan.nodes ?? input.plan.steps.map((step) => ({ kind: "step", ...step }));
|
|
50
|
+
const plan = {
|
|
51
|
+
id,
|
|
52
|
+
conversationId: input.conversationId,
|
|
53
|
+
summary: input.plan.summary,
|
|
54
|
+
onFailure: input.plan.onFailure,
|
|
55
|
+
status: "running",
|
|
56
|
+
steps: [],
|
|
57
|
+
currentIndex: 0,
|
|
58
|
+
startedAt: now(),
|
|
59
|
+
};
|
|
60
|
+
// The complete definition and every statically known iteration are persisted before the first dispatch.
|
|
61
|
+
// Loop rounds are materialized as they begin because their number depends on prior conclusion lines.
|
|
62
|
+
plan.nodes = this.materializeNodes(definitions, plan);
|
|
63
|
+
try {
|
|
64
|
+
const created = await this.hooks.store.beginWorkflow(plan);
|
|
65
|
+
this.hooks.broadcast({ type: "workflow.event", workflow: created });
|
|
66
|
+
const history = [];
|
|
67
|
+
await this.runNodes(plan.nodes, plan, input, controller.signal, {}, history);
|
|
68
|
+
if (controller.signal.aborted || plan.steps.some((step) => step.status === "stopped")) {
|
|
69
|
+
this.haltRemaining(plan);
|
|
70
|
+
plan.status = "stopped";
|
|
71
|
+
}
|
|
72
|
+
else if (plan.steps.every((step) => step.status === "completed" || step.status === "skipped")) {
|
|
73
|
+
plan.status = "completed";
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.haltRemaining(plan);
|
|
77
|
+
plan.status = "failed";
|
|
78
|
+
}
|
|
79
|
+
plan.finishedAt = now();
|
|
80
|
+
await this.commit(plan);
|
|
81
|
+
return { workflow: structuredClone(plan) };
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
input.signal?.removeEventListener("abort", onCallerAbort);
|
|
85
|
+
this.controllers.delete(id);
|
|
86
|
+
this.owners.delete(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Allocates execution rows once per statically known occurrence; loop occurrences are allocated per round. */
|
|
90
|
+
materializeNodes(definitions, plan) {
|
|
91
|
+
return definitions.map((definition) => {
|
|
92
|
+
if (definition.kind === "step") {
|
|
93
|
+
const stepIndex = plan.steps.length;
|
|
94
|
+
plan.steps.push({
|
|
95
|
+
index: stepIndex,
|
|
96
|
+
agentId: definition.agentId,
|
|
97
|
+
...(definition.label ? { label: definition.label } : {}),
|
|
98
|
+
prompt: definition.prompt,
|
|
99
|
+
attempts: [],
|
|
100
|
+
status: "pending",
|
|
101
|
+
});
|
|
102
|
+
return { kind: "step", stepIndex };
|
|
103
|
+
}
|
|
104
|
+
if (definition.kind === "foreach") {
|
|
105
|
+
return {
|
|
106
|
+
kind: "foreach",
|
|
107
|
+
items: [...definition.items],
|
|
108
|
+
iterations: definition.items.map((item) => ({ item, nodes: this.materializeNodes(definition.do, plan) })),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
kind: "loop",
|
|
113
|
+
until: definition.until,
|
|
114
|
+
max: definition.max ?? WORKFLOW_DEFAULT_LOOP_MAX,
|
|
115
|
+
do: structuredClone(definition.do),
|
|
116
|
+
rounds: [],
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async runNodes(nodes, plan, input, signal, variables, history) {
|
|
121
|
+
let output;
|
|
122
|
+
for (const node of nodes) {
|
|
123
|
+
if (signal.aborted)
|
|
124
|
+
return { halted: true, output };
|
|
125
|
+
let result;
|
|
126
|
+
if (node.kind === "step") {
|
|
127
|
+
const step = plan.steps[node.stepIndex];
|
|
128
|
+
result = await this.runStep(plan, step, input, signal, variables, history);
|
|
129
|
+
if (!result.halted) {
|
|
130
|
+
history.push(step);
|
|
131
|
+
plan.currentIndex = history.length;
|
|
132
|
+
await this.commit(plan);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (node.kind === "loop") {
|
|
136
|
+
result = await this.runLoop(node, plan, input, signal, variables, history);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
result = await this.runForeach(node, plan, input, signal, variables, history);
|
|
140
|
+
}
|
|
141
|
+
// The last node's output replaces the earlier one even when it is absent; an empty final node must
|
|
142
|
+
// not accidentally satisfy `until` by exposing an older sibling's conclusion.
|
|
143
|
+
output = result.output;
|
|
144
|
+
if (result.halted)
|
|
145
|
+
return { halted: true, output };
|
|
146
|
+
}
|
|
147
|
+
return { halted: false, output };
|
|
148
|
+
}
|
|
149
|
+
async runLoop(node, plan, input, signal, variables, history) {
|
|
150
|
+
let last = "";
|
|
151
|
+
let output;
|
|
152
|
+
for (let n = 1; n <= node.max; n += 1) {
|
|
153
|
+
if (signal.aborted)
|
|
154
|
+
return { halted: true, output };
|
|
155
|
+
const round = { n, nodes: this.materializeNodes(node.do, plan), untilMet: false };
|
|
156
|
+
node.rounds.push(round);
|
|
157
|
+
await this.commit(plan);
|
|
158
|
+
const result = await this.runNodes(round.nodes, plan, input, signal, { ...variables, last }, history);
|
|
159
|
+
output = result.output;
|
|
160
|
+
if (output !== undefined)
|
|
161
|
+
round.output = output;
|
|
162
|
+
round.untilMet = !result.halted && workflowUntilMet(output, node.until);
|
|
163
|
+
await this.commit(plan);
|
|
164
|
+
if (result.halted)
|
|
165
|
+
return { halted: true, output };
|
|
166
|
+
if (round.untilMet)
|
|
167
|
+
return { halted: false, output };
|
|
168
|
+
last = output ?? "";
|
|
169
|
+
}
|
|
170
|
+
// Exhausting the declared bound is a completed bounded plan, with every round's untilMet=false visible.
|
|
171
|
+
return { halted: false, output };
|
|
172
|
+
}
|
|
173
|
+
async runForeach(node, plan, input, signal, variables, history) {
|
|
174
|
+
let output;
|
|
175
|
+
for (const iteration of node.iterations) {
|
|
176
|
+
if (signal.aborted)
|
|
177
|
+
return { halted: true, output };
|
|
178
|
+
const result = await this.runNodes(iteration.nodes, plan, input, signal, { ...variables, item: iteration.item }, history);
|
|
179
|
+
output = result.output;
|
|
180
|
+
if (result.halted)
|
|
181
|
+
return { halted: true, output };
|
|
182
|
+
}
|
|
183
|
+
return { halted: false, output };
|
|
184
|
+
}
|
|
185
|
+
async runStep(plan, step, input, signal, variables, history) {
|
|
186
|
+
const retries = retriesFor(plan.onFailure);
|
|
187
|
+
let attempt = 0;
|
|
188
|
+
while (attempt <= retries) {
|
|
189
|
+
if (signal.aborted) {
|
|
190
|
+
step.status = "stopped";
|
|
191
|
+
await this.commit(plan);
|
|
192
|
+
return { halted: true };
|
|
193
|
+
}
|
|
194
|
+
attempt += 1;
|
|
195
|
+
step.status = "running";
|
|
196
|
+
plan.currentIndex = history.length;
|
|
197
|
+
const prompt = substituteWorkflowVariables(step.prompt, variables);
|
|
198
|
+
const composed = composeStepPrompt(prompt, history);
|
|
199
|
+
const previousAttempt = step.attempts.at(-1);
|
|
200
|
+
if (previousAttempt) {
|
|
201
|
+
const evidence = [previousAttempt.error, previousAttempt.output].filter(Boolean).join("\n").slice(-8000);
|
|
202
|
+
composed.prompt += `\n\n[Previous attempt ${previousAttempt.n} failed]\n${evidence}\nAddress the failure above before completing this step.`;
|
|
203
|
+
}
|
|
204
|
+
await this.commit(plan);
|
|
205
|
+
const run = await this.recorder.dispatch({
|
|
206
|
+
conversationId: input.conversationId,
|
|
207
|
+
cwd: input.cwd,
|
|
208
|
+
agentId: step.agentId,
|
|
209
|
+
task: composed.prompt,
|
|
210
|
+
dispatchedBy: "model",
|
|
211
|
+
loopId: plan.id,
|
|
212
|
+
role: step.label,
|
|
213
|
+
model: input.model,
|
|
214
|
+
denyTools: input.denyTools,
|
|
215
|
+
signal,
|
|
216
|
+
});
|
|
217
|
+
step.attempts.push(attemptFromRun(run, attempt));
|
|
218
|
+
const output = step.attempts.at(-1)?.output;
|
|
219
|
+
if (run.status === "completed") {
|
|
220
|
+
step.status = "completed";
|
|
221
|
+
await this.commit(plan);
|
|
222
|
+
return { halted: false, output };
|
|
223
|
+
}
|
|
224
|
+
if (run.status === "stopped") {
|
|
225
|
+
step.status = "stopped";
|
|
226
|
+
await this.commit(plan);
|
|
227
|
+
return { halted: true, output };
|
|
228
|
+
}
|
|
229
|
+
if (attempt <= retries) {
|
|
230
|
+
await this.commit(plan);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (plan.onFailure === "skip") {
|
|
234
|
+
step.status = "skipped";
|
|
235
|
+
await this.commit(plan);
|
|
236
|
+
return { halted: false, output };
|
|
237
|
+
}
|
|
238
|
+
step.status = "failed";
|
|
239
|
+
await this.commit(plan);
|
|
240
|
+
return { halted: true, output };
|
|
241
|
+
}
|
|
242
|
+
step.status = "failed";
|
|
243
|
+
return { halted: true };
|
|
244
|
+
}
|
|
245
|
+
haltRemaining(plan) {
|
|
246
|
+
for (const step of plan.steps)
|
|
247
|
+
if (step.status === "pending" || step.status === "running")
|
|
248
|
+
step.status = "stopped";
|
|
249
|
+
}
|
|
250
|
+
/** Persist first, announce second, so a reload never contradicts an event already shown. */
|
|
251
|
+
async commit(plan) {
|
|
252
|
+
const persisted = await this.hooks.store.setWorkflow(plan);
|
|
253
|
+
this.hooks.broadcast({ type: "workflow.event", workflow: persisted });
|
|
254
|
+
}
|
|
255
|
+
}
|