@jshookmcp/jshook 0.2.8 → 0.3.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.
- package/README.md +36 -5
- package/README.zh.md +36 -5
- package/dist/{AntiCheatDetector-S8VRj-dD.mjs → AntiCheatDetector-CqGDXmfc.mjs} +160 -54
- package/dist/{CodeInjector-4Z3ngPoX.mjs → CodeInjector-BdjRfNx7.mjs} +5 -5
- package/dist/ConsoleMonitor-DykL3IAw.mjs +2269 -0
- package/dist/{DarwinAPI-B8hg_yhz.mjs → DarwinAPI-ETyy0xyo.mjs} +1 -1
- package/dist/DetailedDataManager-HT49OrvF.mjs +217 -0
- package/dist/EventBus-DFKvADm3.mjs +141 -0
- package/dist/EvidenceGraphBridge-318Oi0Lf.mjs +153 -0
- package/dist/{ExtensionManager-D5-bO9D8.mjs → ExtensionManager-BDMsY2Dz.mjs} +27 -13
- package/dist/{FingerprintManager-BVxFJL2-.mjs → FingerprintManager-BN4UQWnX.mjs} +1 -1
- package/dist/{HardwareBreakpoint-DK1yjWkV.mjs → HardwareBreakpoint-Cc2AFq1Y.mjs} +3 -3
- package/dist/{HeapAnalyzer-CEbo10xU.mjs → HeapAnalyzer-DruMgsgj.mjs} +21 -21
- package/dist/HookGeneratorBuilders.core.generators.storage-CTbB4Lcx.mjs +566 -0
- package/dist/InstrumentationSession-DLH0vd-z.mjs +244 -0
- package/dist/{MemoryController-DdtnBdD4.mjs → MemoryController-CMtviNW_.mjs} +3 -3
- package/dist/{MemoryScanSession-RMixN3bX.mjs → MemoryScanSession-ITgb_NMi.mjs} +81 -78
- package/dist/{MemoryScanner-QjK4ld0B.mjs → MemoryScanner-CiL7Z3ey.mjs} +50 -21
- package/dist/{NativeMemoryManager.impl-CB6gJ0NM.mjs → NativeMemoryManager.impl-D9Lkovvn.mjs} +20 -56
- package/dist/{NativeMemoryManager.utils-BML4q1ry.mjs → NativeMemoryManager.utils-BBlAixF5.mjs} +1 -1
- package/dist/{PEAnalyzer-CK0xe0Fs.mjs → PEAnalyzer-DMQ44gen.mjs} +16 -16
- package/dist/PageController-BPJNqqBN.mjs +431 -0
- package/dist/{PointerChainEngine-Cd73qu5b.mjs → PointerChainEngine-K7wN8Z-w.mjs} +10 -7
- package/dist/PrerequisiteError-TuyZIs6n.mjs +20 -0
- package/dist/ProcessRegistry-zGg12QbE.mjs +74 -0
- package/dist/ResponseBuilder-CJXWmWNw.mjs +143 -0
- package/dist/ReverseEvidenceGraph-C02-gXOh.mjs +269 -0
- package/dist/ScriptManager-ZuWD-0Jg.mjs +3003 -0
- package/dist/{Speedhack-CeF0XmEz.mjs → Speedhack-D-z0umeT.mjs} +2 -2
- package/dist/{StructureAnalyzer-D4GkMduU.mjs → StructureAnalyzer-Cav5AVSL.mjs} +9 -6
- package/dist/ToolCatalog-5OJdMiF0.mjs +582 -0
- package/dist/ToolError-jh9whhMd.mjs +15 -0
- package/dist/ToolProbe-DbCFGyrg.mjs +45 -0
- package/dist/ToolRegistry-B9krbTtI.mjs +180 -0
- package/dist/ToolRouter.policy-BGDAGyeH.mjs +344 -0
- package/dist/TraceRecorder-B41Z5XBj.mjs +1286 -0
- package/dist/{Win32API-Bc0QnQsN.mjs → Win32API-C2kjj0ze.mjs} +19 -13
- package/dist/{Win32Debug-DUHt9XUn.mjs → Win32Debug-CKrGOTpo.mjs} +3 -3
- package/dist/WorkflowEngine-DJ6M4opp.mjs +569 -0
- package/dist/analysis-BHeJW2Nb.mjs +1234 -0
- package/dist/antidebug-BRKeyt27.mjs +1081 -0
- package/dist/artifactRetention-CPXkUJXp.mjs +598 -0
- package/dist/artifacts-DkfosXH3.mjs +59 -0
- package/dist/authorization-schema-DRqyJMSk.mjs +31 -0
- package/dist/betterSqlite3-DLSBZodi.mjs +74 -0
- package/dist/binary-instrument--V3MAhJ4.mjs +971 -0
- package/dist/bind-helpers-ClV34xdn.mjs +42 -0
- package/dist/boringssl-inspector-Bo_LOLaS.mjs +180 -0
- package/dist/browser-Dx3_S2cG.mjs +4369 -0
- package/dist/capabilities-CcHlvWgK.mjs +33 -0
- package/dist/concurrency-Drev_Vz9.mjs +41 -0
- package/dist/{constants-CCvsN80K.mjs → constants-CDZLOoVv.mjs} +105 -48
- package/dist/coordination-DgItD9DL.mjs +259 -0
- package/dist/debugger-RS3RSAqs.mjs +1288 -0
- package/dist/definitions-BEoYofW5.mjs +47 -0
- package/dist/definitions-BRaefg3u.mjs +365 -0
- package/dist/definitions-BbkvZkiv.mjs +96 -0
- package/dist/definitions-BtWSHJ3o.mjs +17 -0
- package/dist/definitions-C1gCHO0i.mjs +43 -0
- package/dist/definitions-CDOg_b-l.mjs +138 -0
- package/dist/definitions-CVPD9hzZ.mjs +54 -0
- package/dist/definitions-Cea8Lgl7.mjs +94 -0
- package/dist/definitions-DAgIyjxM.mjs +10 -0
- package/dist/definitions-DJA27nsL.mjs +66 -0
- package/dist/definitions-DKPFU3LW.mjs +25 -0
- package/dist/definitions-DPRpZQ96.mjs +47 -0
- package/dist/definitions-DUE5gmdn.mjs +18 -0
- package/dist/definitions-DYVjOtxa.mjs +26 -0
- package/dist/definitions-DcYLVLCo.mjs +37 -0
- package/dist/definitions-Pp5LI2H4.mjs +27 -0
- package/dist/definitions-j9KdHVNR.mjs +14 -0
- package/dist/definitions-uzkjBwa7.mjs +258 -0
- package/dist/definitions-va-AnLuQ.mjs +28 -0
- package/dist/encoding-DJeqHmpd.mjs +1079 -0
- package/dist/evidence-graph-bridge-DcYizFk2.mjs +136 -0
- package/dist/{factory-CibqTNC8.mjs → factory-C90tBff6.mjs} +41 -56
- package/dist/flat-target-session-Dgax2Cy3.mjs +29 -0
- package/dist/graphql-CoHrhweh.mjs +1197 -0
- package/dist/handlers-4jmR0nMs.mjs +898 -0
- package/dist/handlers-BAHPxcch.mjs +789 -0
- package/dist/handlers-BOs9b907.mjs +2600 -0
- package/dist/handlers-BWXEy6ef.mjs +917 -0
- package/dist/handlers-Bndn6QvE.mjs +111 -0
- package/dist/handlers-BqC4bD4s.mjs +681 -0
- package/dist/handlers-BtYq60bM2.mjs +276 -0
- package/dist/handlers-BzgcB4iv.mjs +799 -0
- package/dist/handlers-CRyRWj2b.mjs +859 -0
- package/dist/handlers-CVv2H1uq.mjs +592 -0
- package/dist/handlers-Dl5a7JS4.mjs +572 -0
- package/dist/handlers-Dx2d7jt7.mjs +2537 -0
- package/dist/handlers-Dz9PYsCa.mjs +2805 -0
- package/dist/handlers-HujRKC3b.mjs +661 -0
- package/dist/handlers.impl-XWXkQfyi.mjs +807 -0
- package/dist/hooks-B1B8NRHL.mjs +898 -0
- package/dist/index.mjs +491 -259
- package/dist/{logger-BmWzC2lM.mjs → logger-Dh_xb7_2.mjs} +14 -6
- package/dist/maintenance-PRMkLVRW.mjs +835 -0
- package/dist/manifest-67Bok-Si.mjs +58 -0
- package/dist/manifest-6lNTMZAB2.mjs +87 -0
- package/dist/manifest-B2duEHiH.mjs +90 -0
- package/dist/manifest-B6EY9Vm8.mjs +57 -0
- package/dist/manifest-B6nKSbyY.mjs +95 -0
- package/dist/manifest-BL8AQNPF.mjs +106 -0
- package/dist/manifest-BSZvJJmV.mjs +47 -0
- package/dist/manifest-BU7qzUyX.mjs +418 -0
- package/dist/manifest-Bl62e8WK.mjs +49 -0
- package/dist/manifest-Bo5cXjdt.mjs +82 -0
- package/dist/manifest-BpS4gtUK.mjs +1347 -0
- package/dist/manifest-Bv65_e2W.mjs +101 -0
- package/dist/manifest-BytNIF4Z.mjs +117 -0
- package/dist/manifest-C-xtsjS3.mjs +81 -0
- package/dist/manifest-CDYl7OhA.mjs +66 -0
- package/dist/manifest-CRZ3xmkD.mjs +61 -0
- package/dist/manifest-CoW6u4Tp.mjs +132 -0
- package/dist/manifest-Cq5zN_8A.mjs +50 -0
- package/dist/manifest-D7YZM_2e.mjs +194 -0
- package/dist/manifest-DE_VrAeQ.mjs +314 -0
- package/dist/manifest-DGsXSCpT.mjs +39 -0
- package/dist/manifest-DJ2vfEuW.mjs +156 -0
- package/dist/manifest-DPXDYhEu.mjs +80 -0
- package/dist/manifest-Dd4fQb0a.mjs +322 -0
- package/dist/manifest-Deq6opGg.mjs +223 -0
- package/dist/manifest-DfJTafJK.mjs +37 -0
- package/dist/manifest-DgOdgN_j.mjs +50 -0
- package/dist/manifest-DlbMW4v4.mjs +47 -0
- package/dist/manifest-DmVfbH0w.mjs +374 -0
- package/dist/manifest-Dog6Ddjr.mjs +109 -0
- package/dist/manifest-DvgU5FWb.mjs +58 -0
- package/dist/manifest-HsfDBs7j.mjs +50 -0
- package/dist/manifest-I8oQHvCG.mjs +186 -0
- package/dist/manifest-NvH_a-av.mjs +786 -0
- package/dist/manifest-cEJU1v0Z.mjs +129 -0
- package/dist/manifest-wOl5XLB12.mjs +112 -0
- package/dist/modules-tZozf0LQ.mjs +10635 -0
- package/dist/mojo-ipc-DXNEXEqb.mjs +640 -0
- package/dist/network-CPVvwvFg.mjs +3852 -0
- package/dist/{artifacts-BbdOMET5.mjs → outputPaths-um7lCRY3.mjs} +219 -216
- package/dist/parse-args-B4cY5Vx5.mjs +39 -0
- package/dist/platform-CYeFoTWp.mjs +2161 -0
- package/dist/process-BTbgcVc6.mjs +1306 -0
- package/dist/proxy-r8YN6nP1.mjs +192 -0
- package/dist/registry-Bl8ZQW61.mjs +34 -0
- package/dist/response-CWhh2aLo.mjs +34 -0
- package/dist/server/plugin-api.mjs +2 -2
- package/dist/shared-state-board-BoZnSoj-.mjs +586 -0
- package/dist/sourcemap-BIDHUVXy.mjs +934 -0
- package/dist/ssrf-policy-Dsqd-DTX.mjs +166 -0
- package/dist/streaming-Dal6utPp.mjs +725 -0
- package/dist/tool-builder-BHJp32mV.mjs +186 -0
- package/dist/transform-DRVgGG90.mjs +1011 -0
- package/dist/types-Bx92KJfT.mjs +4 -0
- package/dist/wasm-BYx5UOeG.mjs +1044 -0
- package/dist/webcrack-Be0_FccV.mjs +747 -0
- package/dist/workflow-BpuKEtvn.mjs +725 -0
- package/package.json +82 -49
- package/dist/ExtensionManager-CPTJhHFg.mjs +0 -2
- package/dist/ToolCatalog-Bq4V2sbJ.mjs +0 -67201
- package/dist/{CacheAdapters-CzFNpD9a.mjs → CacheAdapters-jJFy20G-.mjs} +0 -0
- package/dist/{StealthVerifier-BzBCFiwx.mjs → StealthVerifier-BWmPgQsv.mjs} +0 -0
- package/dist/{VersionDetector-CNXcvD46.mjs → VersionDetector-K3V4vGsw.mjs} +0 -0
- package/dist/{formatAddress-ChCSIRWT.mjs → formatAddress-nnMvEohD.mjs} +0 -0
- package/dist/{types-BBjOqye-.mjs → types-DDBWs9UP.mjs} +1 -1
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-CjcI7cDX.mjs";
|
|
2
|
+
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
3
|
+
import { l as getRoutingState, o as getEffectivePrerequisites } from "./ToolRouter.policy-BGDAGyeH.mjs";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
//#region src/server/workflows/WorkflowDataBus.ts
|
|
6
|
+
/**
|
|
7
|
+
* Cross-node data bus for dynamic parameter passing.
|
|
8
|
+
*
|
|
9
|
+
* Supports expression templates like "${get-requests.scriptId}" to reference
|
|
10
|
+
* outputs from previous steps.
|
|
11
|
+
*/
|
|
12
|
+
var WorkflowDataBus = class {
|
|
13
|
+
store = /* @__PURE__ */ new Map();
|
|
14
|
+
set(key, value) {
|
|
15
|
+
this.store.set(key, value);
|
|
16
|
+
}
|
|
17
|
+
get(key) {
|
|
18
|
+
return this.store.get(key);
|
|
19
|
+
}
|
|
20
|
+
getValueAtPath(key, path) {
|
|
21
|
+
const value = this.store.get(key);
|
|
22
|
+
if (!value || typeof value !== "object") return value;
|
|
23
|
+
const obj = parseToolPayload(value) || value;
|
|
24
|
+
return path.split(".").reduce((current, segment) => {
|
|
25
|
+
if (current && typeof current === "object") {
|
|
26
|
+
const arrayMatch = segment.match(/^(\d+)$/);
|
|
27
|
+
if (arrayMatch && Array.isArray(current)) return current[Number(arrayMatch[1])];
|
|
28
|
+
return current[segment];
|
|
29
|
+
}
|
|
30
|
+
}, obj);
|
|
31
|
+
}
|
|
32
|
+
resolve(template) {
|
|
33
|
+
const match = template.match(/^\$\{(.+)\}$/);
|
|
34
|
+
if (!match || !match[1]) return template;
|
|
35
|
+
const ref = match[1];
|
|
36
|
+
const dotIndex = ref.indexOf(".");
|
|
37
|
+
if (dotIndex === -1) return this.store.get(ref);
|
|
38
|
+
return this.getValueAtPath(ref.slice(0, dotIndex), ref.slice(dotIndex + 1));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function parseToolPayload(response) {
|
|
42
|
+
if (!response || typeof response !== "object") return;
|
|
43
|
+
const text = response.content?.find((item) => item.type === "text")?.text;
|
|
44
|
+
if (typeof text !== "string") return;
|
|
45
|
+
try {
|
|
46
|
+
const parsed = JSON.parse(text);
|
|
47
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function responseIndicatesFailure(response) {
|
|
53
|
+
if (!response || typeof response !== "object") return;
|
|
54
|
+
if (response.isError) return "Tool returned MCP error response";
|
|
55
|
+
const payload = parseToolPayload(response);
|
|
56
|
+
if (payload?.success === false) return typeof payload.error === "string" ? payload.error : "Tool reported success=false";
|
|
57
|
+
}
|
|
58
|
+
function collectSuccessStats(value) {
|
|
59
|
+
if (Array.isArray(value)) return value.reduce((acc, item) => {
|
|
60
|
+
const next = collectSuccessStats(item);
|
|
61
|
+
acc.success += next.success;
|
|
62
|
+
acc.failure += next.failure;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {
|
|
65
|
+
success: 0,
|
|
66
|
+
failure: 0
|
|
67
|
+
});
|
|
68
|
+
if (!value || typeof value !== "object") return {
|
|
69
|
+
success: 0,
|
|
70
|
+
failure: 0
|
|
71
|
+
};
|
|
72
|
+
const obj = value;
|
|
73
|
+
if (Array.isArray(obj["__order"])) return obj["__order"].reduce((acc, key) => {
|
|
74
|
+
const next = collectSuccessStats(obj[key]);
|
|
75
|
+
acc.success += next.success;
|
|
76
|
+
acc.failure += next.failure;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {
|
|
79
|
+
success: 0,
|
|
80
|
+
failure: 0
|
|
81
|
+
});
|
|
82
|
+
const payload = parseToolPayload(value);
|
|
83
|
+
if (payload?.success === true) return {
|
|
84
|
+
success: 1,
|
|
85
|
+
failure: 0
|
|
86
|
+
};
|
|
87
|
+
/* istanbul ignore next */
|
|
88
|
+
if (payload?.success === false) return {
|
|
89
|
+
success: 0,
|
|
90
|
+
failure: 1
|
|
91
|
+
};
|
|
92
|
+
if ("error" in obj) return {
|
|
93
|
+
success: 0,
|
|
94
|
+
failure: 1
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
success: 0,
|
|
98
|
+
failure: 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function resolveInputFrom(mapping, dataBus) {
|
|
102
|
+
const resolved = {};
|
|
103
|
+
for (const [targetKey, sourceRef] of Object.entries(mapping)) {
|
|
104
|
+
const template = sourceRef.startsWith("${") ? sourceRef : `\${${sourceRef}}`;
|
|
105
|
+
resolved[targetKey] = dataBus.resolve(template);
|
|
106
|
+
}
|
|
107
|
+
return resolved;
|
|
108
|
+
}
|
|
109
|
+
function resolveInputValues(input, dataBus) {
|
|
110
|
+
if (!input) return {};
|
|
111
|
+
const resolved = {};
|
|
112
|
+
for (const [key, value] of Object.entries(input)) resolved[key] = resolveValue(value, dataBus);
|
|
113
|
+
return resolved;
|
|
114
|
+
}
|
|
115
|
+
function resolveValue(value, dataBus) {
|
|
116
|
+
if (typeof value === "string") return dataBus.resolve(value);
|
|
117
|
+
if (Array.isArray(value)) return value.map((item) => resolveValue(item, dataBus));
|
|
118
|
+
if (value && typeof value === "object") {
|
|
119
|
+
const resolved = {};
|
|
120
|
+
for (const [key, nestedValue] of Object.entries(value)) resolved[key] = resolveValue(nestedValue, dataBus);
|
|
121
|
+
return resolved;
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/server/workflows/WorkflowPredicates.ts
|
|
127
|
+
function getWorkflowVariable(stepResults, keyPath) {
|
|
128
|
+
if (stepResults.has(keyPath)) return stepResults.get(keyPath);
|
|
129
|
+
const [stepId, ...fieldSegments] = keyPath.split(".");
|
|
130
|
+
if (!stepId || !stepResults.has(stepId)) return;
|
|
131
|
+
let current = stepResults.get(stepId);
|
|
132
|
+
if (current && typeof current === "object") {
|
|
133
|
+
const payload = parseToolPayload(current);
|
|
134
|
+
if (payload) current = payload;
|
|
135
|
+
}
|
|
136
|
+
for (const segment of fieldSegments) {
|
|
137
|
+
if (current && typeof current === "object") {
|
|
138
|
+
const arrayMatch = segment.match(/^(\d+)$/);
|
|
139
|
+
if (arrayMatch && Array.isArray(current)) {
|
|
140
|
+
current = current[Number(arrayMatch[1])];
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
current = current[segment];
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
return current;
|
|
149
|
+
}
|
|
150
|
+
function deepEquals(left, right) {
|
|
151
|
+
if (left === right) return true;
|
|
152
|
+
if (typeof left !== typeof right) return false;
|
|
153
|
+
if (left && right && typeof left === "object" && typeof right === "object") {
|
|
154
|
+
if (Array.isArray(left) !== Array.isArray(right)) return false;
|
|
155
|
+
if (Array.isArray(left)) {
|
|
156
|
+
const leftArray = left;
|
|
157
|
+
const rightArray = right;
|
|
158
|
+
return leftArray.length === rightArray.length && leftArray.every((value, index) => deepEquals(value, rightArray[index]));
|
|
159
|
+
}
|
|
160
|
+
const leftKeys = Object.keys(left);
|
|
161
|
+
const rightKeys = Object.keys(right);
|
|
162
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
163
|
+
return leftKeys.every((key) => deepEquals(left[key], right[key]));
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
async function evaluatePredicate(node, ctx) {
|
|
168
|
+
if (node.predicateFn) return await node.predicateFn(ctx);
|
|
169
|
+
if (node.predicateId === "always_true") return true;
|
|
170
|
+
if (node.predicateId === "always_false") return false;
|
|
171
|
+
if (node.predicateId === "any_step_failed") return [...ctx.stepResults.values()].some((value) => collectSuccessStats(value).failure > 0);
|
|
172
|
+
const successRateMatch = node.predicateId.match(/success_rate_gte_(\d+)/i);
|
|
173
|
+
if (successRateMatch?.[1]) {
|
|
174
|
+
const threshold = Number(successRateMatch[1]);
|
|
175
|
+
const aggregate = [...ctx.stepResults.values()].reduce((acc, value) => {
|
|
176
|
+
const next = collectSuccessStats(value);
|
|
177
|
+
acc.success += next.success;
|
|
178
|
+
acc.failure += next.failure;
|
|
179
|
+
return acc;
|
|
180
|
+
}, {
|
|
181
|
+
success: 0,
|
|
182
|
+
failure: 0
|
|
183
|
+
});
|
|
184
|
+
const total = aggregate.success + aggregate.failure;
|
|
185
|
+
return total > 0 && aggregate.success / total >= threshold / 100;
|
|
186
|
+
}
|
|
187
|
+
const equalsMatch = node.predicateId.match(/^variable_equals_(.+?)_(.+)$/);
|
|
188
|
+
if (equalsMatch?.[1] && equalsMatch[2]) return deepEquals(getWorkflowVariable(ctx.stepResults, equalsMatch[1]), equalsMatch[2]);
|
|
189
|
+
const containsMatch = node.predicateId.match(/^variable_contains_(.+?)_(.+)$/);
|
|
190
|
+
if (containsMatch?.[1] && containsMatch[2]) {
|
|
191
|
+
const value = getWorkflowVariable(ctx.stepResults, containsMatch[1]);
|
|
192
|
+
if (typeof value !== "string" && !Array.isArray(value)) return false;
|
|
193
|
+
return String(value).includes(containsMatch[2]);
|
|
194
|
+
}
|
|
195
|
+
const matchesMatch = node.predicateId.match(/^variable_matches_(.+?)_(.+)$/);
|
|
196
|
+
if (matchesMatch?.[1] && matchesMatch[2]) {
|
|
197
|
+
const value = getWorkflowVariable(ctx.stepResults, matchesMatch[1]);
|
|
198
|
+
if (typeof value !== "string") return false;
|
|
199
|
+
try {
|
|
200
|
+
return new RegExp(matchesMatch[2]).test(value);
|
|
201
|
+
} catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
throw new Error(`Unknown workflow predicateId "${node.predicateId}"`);
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/server/workflows/WorkflowPreflight.ts
|
|
209
|
+
function collectToolNodes(node) {
|
|
210
|
+
switch (node.kind) {
|
|
211
|
+
case "tool": return [node];
|
|
212
|
+
case "sequence":
|
|
213
|
+
case "parallel": return node.steps.flatMap((step) => collectToolNodes(step));
|
|
214
|
+
case "branch": return [...collectToolNodes(node.whenTrue), ...node.whenFalse ? collectToolNodes(node.whenFalse) : []];
|
|
215
|
+
case "fallback": return [...collectToolNodes(node.primary), ...collectToolNodes(node.fallback)];
|
|
216
|
+
default: return [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function getEvidenceState(ctx) {
|
|
220
|
+
try {
|
|
221
|
+
const evidenceGraph = ctx.getDomainInstance("evidenceGraph");
|
|
222
|
+
return evidenceGraph ? {
|
|
223
|
+
hasGraph: true,
|
|
224
|
+
nodeCount: evidenceGraph.nodeCount,
|
|
225
|
+
edgeCount: evidenceGraph.edgeCount
|
|
226
|
+
} : {
|
|
227
|
+
hasGraph: false,
|
|
228
|
+
nodeCount: 0,
|
|
229
|
+
edgeCount: 0
|
|
230
|
+
};
|
|
231
|
+
} catch {
|
|
232
|
+
return {
|
|
233
|
+
hasGraph: false,
|
|
234
|
+
nodeCount: 0,
|
|
235
|
+
edgeCount: 0
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function collectUnsatisfiedPrerequisites(graph, routingState) {
|
|
240
|
+
const prerequisites = getEffectivePrerequisites();
|
|
241
|
+
const warnings = [];
|
|
242
|
+
for (const toolNode of collectToolNodes(graph)) {
|
|
243
|
+
const toolPrerequisites = prerequisites[toolNode.toolName] ?? [];
|
|
244
|
+
for (const prerequisite of toolPrerequisites) {
|
|
245
|
+
if (prerequisite.check(routingState)) continue;
|
|
246
|
+
warnings.push({
|
|
247
|
+
nodeId: toolNode.id,
|
|
248
|
+
toolName: toolNode.toolName,
|
|
249
|
+
condition: prerequisite.condition,
|
|
250
|
+
fix: prerequisite.fix
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return warnings;
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/server/workflows/WorkflowRunStore.ts
|
|
258
|
+
var WorkflowRunStore = class {
|
|
259
|
+
runs = /* @__PURE__ */ new Map();
|
|
260
|
+
lastSuccess = /* @__PURE__ */ new Map();
|
|
261
|
+
recordSuccess(result) {
|
|
262
|
+
const entry = {
|
|
263
|
+
workflowId: result.workflowId,
|
|
264
|
+
runId: result.runId,
|
|
265
|
+
startedAt: result.startedAt,
|
|
266
|
+
finishedAt: result.finishedAt,
|
|
267
|
+
durationMs: result.durationMs,
|
|
268
|
+
status: "success",
|
|
269
|
+
stepResultKeys: Object.keys(result.stepResults)
|
|
270
|
+
};
|
|
271
|
+
this.runs.set(result.runId, entry);
|
|
272
|
+
this.lastSuccess.set(result.workflowId, result);
|
|
273
|
+
logger.debug(`workflow run recorded: ${result.runId} (${result.workflowId})`);
|
|
274
|
+
}
|
|
275
|
+
recordError(workflowId, runId, startedAt, error) {
|
|
276
|
+
const entry = {
|
|
277
|
+
workflowId,
|
|
278
|
+
runId,
|
|
279
|
+
startedAt,
|
|
280
|
+
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
281
|
+
durationMs: Date.now() - new Date(startedAt).getTime(),
|
|
282
|
+
status: "error",
|
|
283
|
+
stepResultKeys: []
|
|
284
|
+
};
|
|
285
|
+
this.runs.set(runId, entry);
|
|
286
|
+
logger.debug(`workflow run error: ${runId} (${workflowId}): ${error}`);
|
|
287
|
+
}
|
|
288
|
+
getRun(runId) {
|
|
289
|
+
return this.runs.get(runId);
|
|
290
|
+
}
|
|
291
|
+
getLastSuccess(workflowId) {
|
|
292
|
+
return this.lastSuccess.get(workflowId);
|
|
293
|
+
}
|
|
294
|
+
listRuns(workflowId) {
|
|
295
|
+
const entries = [...this.runs.values()];
|
|
296
|
+
if (workflowId) return entries.filter((e) => e.workflowId === workflowId);
|
|
297
|
+
return entries;
|
|
298
|
+
}
|
|
299
|
+
clear() {
|
|
300
|
+
this.runs.clear();
|
|
301
|
+
this.lastSuccess.clear();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/server/workflows/WorkflowEngine.types.ts
|
|
306
|
+
var PreflightError = class extends Error {
|
|
307
|
+
constructor(warnings) {
|
|
308
|
+
super(`Workflow preflight failed with ${warnings.length} unsatisfied prerequisite(s)`);
|
|
309
|
+
this.warnings = warnings;
|
|
310
|
+
this.name = "PreflightError";
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/server/workflows/WorkflowEngine.ts
|
|
315
|
+
var WorkflowEngine_exports = /* @__PURE__ */ __exportAll({ executeExtensionWorkflow: () => executeExtensionWorkflow });
|
|
316
|
+
const globalRunStore = new WorkflowRunStore();
|
|
317
|
+
function extractConfigValue(config, path, fallback) {
|
|
318
|
+
const segments = path.split(".").filter(Boolean);
|
|
319
|
+
let current = config;
|
|
320
|
+
for (const segment of segments) {
|
|
321
|
+
if (!current || typeof current !== "object") return fallback;
|
|
322
|
+
current = current[segment];
|
|
323
|
+
}
|
|
324
|
+
return current ?? fallback;
|
|
325
|
+
}
|
|
326
|
+
function sleep(ms) {
|
|
327
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
328
|
+
}
|
|
329
|
+
async function withTimeout(promise, timeoutMs, label) {
|
|
330
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) return promise;
|
|
331
|
+
return new Promise((resolve, reject) => {
|
|
332
|
+
const timeoutId = setTimeout(() => reject(/* @__PURE__ */ new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
333
|
+
promise.then((value) => {
|
|
334
|
+
clearTimeout(timeoutId);
|
|
335
|
+
resolve(value);
|
|
336
|
+
}, (error) => {
|
|
337
|
+
clearTimeout(timeoutId);
|
|
338
|
+
reject(error);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
async function runToolNode(ctx, node, overrides, executionContext) {
|
|
343
|
+
const fromResolved = node.inputFrom ? resolveInputFrom(node.inputFrom, executionContext.dataBus) : {};
|
|
344
|
+
const mergedInput = {
|
|
345
|
+
...node.input ? resolveInputValues(node.input, executionContext.dataBus) : {},
|
|
346
|
+
...fromResolved,
|
|
347
|
+
...overrides?.[node.id]
|
|
348
|
+
};
|
|
349
|
+
const runAttempt = async () => {
|
|
350
|
+
const response = await withTimeout(ctx.executeToolWithTracking(node.toolName, mergedInput), node.timeoutMs ?? 0, `Workflow tool node "${node.id}"`);
|
|
351
|
+
const failure = responseIndicatesFailure(response);
|
|
352
|
+
if (failure) throw new Error(failure);
|
|
353
|
+
executionContext.dataBus.set(node.id, response);
|
|
354
|
+
return response;
|
|
355
|
+
};
|
|
356
|
+
const retry = node.retry;
|
|
357
|
+
if (!retry) return runAttempt();
|
|
358
|
+
let attempt = 0;
|
|
359
|
+
let backoffMs = retry.backoffMs;
|
|
360
|
+
while (attempt < retry.maxAttempts) try {
|
|
361
|
+
return await runAttempt();
|
|
362
|
+
} catch (error) {
|
|
363
|
+
attempt += 1;
|
|
364
|
+
if (attempt >= retry.maxAttempts) throw error;
|
|
365
|
+
await sleep(backoffMs);
|
|
366
|
+
backoffMs = Math.max(0, Math.floor(backoffMs * (retry.multiplier ?? 1)));
|
|
367
|
+
}
|
|
368
|
+
throw new Error(`Workflow tool node "${node.id}" exhausted retries`);
|
|
369
|
+
}
|
|
370
|
+
async function runParallelNode(ctx, node, executionContext, options) {
|
|
371
|
+
const concurrency = Math.max(1, node.maxConcurrency ?? 4);
|
|
372
|
+
const keyedResults = { __order: [] };
|
|
373
|
+
let nextIndex = 0;
|
|
374
|
+
let stopped = false;
|
|
375
|
+
const worker = async () => {
|
|
376
|
+
while (true) {
|
|
377
|
+
if (stopped) return;
|
|
378
|
+
const currentIndex = nextIndex;
|
|
379
|
+
nextIndex += 1;
|
|
380
|
+
if (currentIndex >= node.steps.length) return;
|
|
381
|
+
const step = node.steps[currentIndex];
|
|
382
|
+
/* istanbul ignore next */
|
|
383
|
+
if (!step) return;
|
|
384
|
+
try {
|
|
385
|
+
const result = await executeNode(ctx, step, executionContext, options);
|
|
386
|
+
keyedResults[step.id] = result;
|
|
387
|
+
keyedResults.__order.push(step.id);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
if (node.failFast) {
|
|
390
|
+
stopped = true;
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
keyedResults[step.id] = {
|
|
394
|
+
success: false,
|
|
395
|
+
error: error instanceof Error ? error.message : String(error)
|
|
396
|
+
};
|
|
397
|
+
keyedResults.__order.push(step.id);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, node.steps.length) }, () => worker()));
|
|
402
|
+
return keyedResults;
|
|
403
|
+
}
|
|
404
|
+
async function executeNode(ctx, node, executionContext, options) {
|
|
405
|
+
executionContext.emitSpan("workflow.node.start", {
|
|
406
|
+
nodeId: node.id,
|
|
407
|
+
kind: node.kind
|
|
408
|
+
});
|
|
409
|
+
let result;
|
|
410
|
+
switch (node.kind) {
|
|
411
|
+
case "tool":
|
|
412
|
+
result = await runToolNode(ctx, node, options.nodeInputOverrides, executionContext);
|
|
413
|
+
break;
|
|
414
|
+
case "sequence": {
|
|
415
|
+
const sequenceNode = node;
|
|
416
|
+
const items = [];
|
|
417
|
+
for (const step of sequenceNode.steps) items.push(await executeNode(ctx, step, executionContext, options));
|
|
418
|
+
result = items;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
case "parallel":
|
|
422
|
+
result = await runParallelNode(ctx, node, executionContext, options);
|
|
423
|
+
break;
|
|
424
|
+
case "branch": {
|
|
425
|
+
const branchNode = node;
|
|
426
|
+
const selected = await evaluatePredicate(branchNode, executionContext) ? branchNode.whenTrue : branchNode.whenFalse;
|
|
427
|
+
if (selected) result = await executeNode(ctx, selected, executionContext, options);
|
|
428
|
+
else result = void 0;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
case "fallback": {
|
|
432
|
+
const fallbackNode = node;
|
|
433
|
+
try {
|
|
434
|
+
result = await executeNode(ctx, fallbackNode.primary, executionContext, options);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
executionContext.emitSpan("workflow.node.fallback", {
|
|
437
|
+
nodeId: fallbackNode.id,
|
|
438
|
+
primaryNodeId: fallbackNode.primary.id,
|
|
439
|
+
fallbackNodeId: fallbackNode.fallback.id,
|
|
440
|
+
error: error instanceof Error ? error.message : String(error)
|
|
441
|
+
});
|
|
442
|
+
result = await executeNode(ctx, fallbackNode.fallback, executionContext, options);
|
|
443
|
+
}
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
default: throw new Error(`Unsupported workflow node kind: ${node.kind}`);
|
|
447
|
+
}
|
|
448
|
+
executionContext.stepResults.set(node.id, result);
|
|
449
|
+
executionContext.emitSpan("workflow.node.finish", {
|
|
450
|
+
nodeId: node.id,
|
|
451
|
+
kind: node.kind
|
|
452
|
+
});
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
async function executeExtensionWorkflow(ctx, workflow, options = {}) {
|
|
456
|
+
const runId = randomUUID();
|
|
457
|
+
const profile = options.profile ?? String(ctx.baseTier ?? "workflow");
|
|
458
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
459
|
+
const startedAtMs = Date.now();
|
|
460
|
+
const metrics = [];
|
|
461
|
+
const spans = [];
|
|
462
|
+
const stepResults = /* @__PURE__ */ new Map();
|
|
463
|
+
const dataBus = new WorkflowDataBus();
|
|
464
|
+
const mergedConfig = options.config ? {
|
|
465
|
+
...ctx.config,
|
|
466
|
+
...options.config
|
|
467
|
+
} : ctx.config;
|
|
468
|
+
const executionContext = {
|
|
469
|
+
workflowRunId: runId,
|
|
470
|
+
profile,
|
|
471
|
+
stepResults,
|
|
472
|
+
dataBus,
|
|
473
|
+
invokeTool(toolName, args) {
|
|
474
|
+
return ctx.executeToolWithTracking(toolName, args);
|
|
475
|
+
},
|
|
476
|
+
emitSpan(name, attrs) {
|
|
477
|
+
spans.push({
|
|
478
|
+
name,
|
|
479
|
+
attrs,
|
|
480
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
emitMetric(name, value, type, attrs) {
|
|
484
|
+
metrics.push({
|
|
485
|
+
name,
|
|
486
|
+
value,
|
|
487
|
+
type,
|
|
488
|
+
attrs,
|
|
489
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
490
|
+
});
|
|
491
|
+
},
|
|
492
|
+
getConfig(path, fallback) {
|
|
493
|
+
return extractConfigValue(mergedConfig, path, fallback);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
try {
|
|
497
|
+
await workflow.onStart?.(executionContext);
|
|
498
|
+
const graph = workflow.build(executionContext);
|
|
499
|
+
const preflightMode = options.preflightMode ?? "warn";
|
|
500
|
+
let preflightWarnings = [];
|
|
501
|
+
if (preflightMode === "skip") executionContext.emitSpan("workflow.preflight", {
|
|
502
|
+
mode: preflightMode,
|
|
503
|
+
skipped: true,
|
|
504
|
+
evidenceState: getEvidenceState(ctx),
|
|
505
|
+
warningCount: 0
|
|
506
|
+
});
|
|
507
|
+
else try {
|
|
508
|
+
const routingState = await getRoutingState(ctx);
|
|
509
|
+
const evidenceState = getEvidenceState(ctx);
|
|
510
|
+
preflightWarnings = collectUnsatisfiedPrerequisites(graph, routingState);
|
|
511
|
+
executionContext.emitSpan("workflow.preflight", {
|
|
512
|
+
mode: preflightMode,
|
|
513
|
+
routingState,
|
|
514
|
+
evidenceState,
|
|
515
|
+
warningCount: preflightWarnings.length,
|
|
516
|
+
warnings: preflightWarnings
|
|
517
|
+
});
|
|
518
|
+
if (preflightMode === "strict" && preflightWarnings.length > 0) throw new PreflightError(preflightWarnings);
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (error instanceof PreflightError) throw error;
|
|
521
|
+
executionContext.emitSpan("workflow.preflight", {
|
|
522
|
+
mode: preflightMode,
|
|
523
|
+
warningCount: 0,
|
|
524
|
+
skipped: true,
|
|
525
|
+
error: error instanceof Error ? error.message : String(error),
|
|
526
|
+
evidenceState: getEvidenceState(ctx)
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
const result = await withTimeout(executeNode(ctx, graph, executionContext, options), options.timeoutMs ?? workflow.timeoutMs ?? 0, `Workflow "${workflow.id}"`);
|
|
530
|
+
await workflow.onFinish?.(executionContext, result);
|
|
531
|
+
try {
|
|
532
|
+
const evidenceGraph = typeof ctx.getDomainInstance === "function" ? ctx.getDomainInstance("evidenceGraph") : void 0;
|
|
533
|
+
if (evidenceGraph && evidenceGraph.nodeCount > 0) {
|
|
534
|
+
stepResults.set("__evidenceSnapshot", evidenceGraph.exportJson());
|
|
535
|
+
executionContext.emitSpan("workflow.evidence.auto-export", {
|
|
536
|
+
nodeCount: evidenceGraph.nodeCount,
|
|
537
|
+
edgeCount: evidenceGraph.edgeCount
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
} catch (exportError) {
|
|
541
|
+
executionContext.emitSpan("workflow.evidence.auto-export", {
|
|
542
|
+
skipped: true,
|
|
543
|
+
error: exportError instanceof Error ? exportError.message : String(exportError)
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
const runResult = {
|
|
547
|
+
workflowId: workflow.id,
|
|
548
|
+
displayName: workflow.displayName,
|
|
549
|
+
runId,
|
|
550
|
+
profile,
|
|
551
|
+
startedAt,
|
|
552
|
+
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
553
|
+
durationMs: Date.now() - startedAtMs,
|
|
554
|
+
result,
|
|
555
|
+
stepResults: Object.fromEntries(stepResults.entries()),
|
|
556
|
+
metrics,
|
|
557
|
+
spans
|
|
558
|
+
};
|
|
559
|
+
globalRunStore.recordSuccess(runResult);
|
|
560
|
+
return runResult;
|
|
561
|
+
} catch (error) {
|
|
562
|
+
const workflowError = error instanceof Error ? error : new Error(String(error));
|
|
563
|
+
globalRunStore.recordError(workflow.id, runId, startedAt, workflowError);
|
|
564
|
+
await workflow.onError?.(executionContext, workflowError);
|
|
565
|
+
throw workflowError;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
//#endregion
|
|
569
|
+
export { executeExtensionWorkflow as n, WorkflowEngine_exports as t };
|