@bluelibs/runner-dev 4.0.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/AI.md +411 -0
- package/README.md +1103 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +58 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/documentation.d.ts +8 -0
- package/dist/client/documentation.js +144 -0
- package/dist/client/documentation.js.map +1 -0
- package/dist/components/Documentation/Documentation.d.ts +8 -0
- package/dist/components/Documentation/Documentation.js +283 -0
- package/dist/components/Documentation/Documentation.js.map +1 -0
- package/dist/components/Documentation/components/DiagnosticsPanel.d.ts +7 -0
- package/dist/components/Documentation/components/DiagnosticsPanel.js +126 -0
- package/dist/components/Documentation/components/DiagnosticsPanel.js.map +1 -0
- package/dist/components/Documentation/components/EventCard.d.ts +8 -0
- package/dist/components/Documentation/components/EventCard.js +164 -0
- package/dist/components/Documentation/components/EventCard.js.map +1 -0
- package/dist/components/Documentation/components/HookCard.d.ts +8 -0
- package/dist/components/Documentation/components/HookCard.js +111 -0
- package/dist/components/Documentation/components/HookCard.js.map +1 -0
- package/dist/components/Documentation/components/MiddlewareCard.d.ts +8 -0
- package/dist/components/Documentation/components/MiddlewareCard.js +159 -0
- package/dist/components/Documentation/components/MiddlewareCard.js.map +1 -0
- package/dist/components/Documentation/components/ResourceCard.d.ts +8 -0
- package/dist/components/Documentation/components/ResourceCard.js +94 -0
- package/dist/components/Documentation/components/ResourceCard.js.map +1 -0
- package/dist/components/Documentation/components/Sidebar.d.ts +13 -0
- package/dist/components/Documentation/components/Sidebar.js +129 -0
- package/dist/components/Documentation/components/Sidebar.js.map +1 -0
- package/dist/components/Documentation/components/TagCard.d.ts +7 -0
- package/dist/components/Documentation/components/TagCard.js +75 -0
- package/dist/components/Documentation/components/TagCard.js.map +1 -0
- package/dist/components/Documentation/components/TaskCard.d.ts +8 -0
- package/dist/components/Documentation/components/TaskCard.js +77 -0
- package/dist/components/Documentation/components/TaskCard.js.map +1 -0
- package/dist/components/Documentation/index.d.ts +2 -0
- package/dist/components/Documentation/index.js +6 -0
- package/dist/components/Documentation/index.js.map +1 -0
- package/dist/components/Documentation/utils/formatting.d.ts +8 -0
- package/dist/components/Documentation/utils/formatting.js +84 -0
- package/dist/components/Documentation/utils/formatting.js.map +1 -0
- package/dist/components/ExampleComponent.d.ts +10 -0
- package/dist/components/ExampleComponent.js +48 -0
- package/dist/components/ExampleComponent.js.map +1 -0
- package/dist/generated/resolvers-types.d.ts +1523 -0
- package/dist/generated/resolvers-types.js +3 -0
- package/dist/generated/resolvers-types.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp/env.d.ts +5 -0
- package/dist/mcp/env.js +42 -0
- package/dist/mcp/env.js.map +1 -0
- package/dist/mcp/format.d.ts +50 -0
- package/dist/mcp/format.js +249 -0
- package/dist/mcp/format.js.map +1 -0
- package/dist/mcp/help.d.ts +20 -0
- package/dist/mcp/help.js +121 -0
- package/dist/mcp/help.js.map +1 -0
- package/dist/mcp/http.d.ts +6 -0
- package/dist/mcp/http.js +47 -0
- package/dist/mcp/http.js.map +1 -0
- package/dist/mcp/projectOverview.d.ts +2 -0
- package/dist/mcp/projectOverview.js +210 -0
- package/dist/mcp/projectOverview.js.map +1 -0
- package/dist/mcp/schema.d.ts +1 -0
- package/dist/mcp/schema.js +17 -0
- package/dist/mcp/schema.js.map +1 -0
- package/dist/mcp/tools/graphql.introspect.d.ts +2 -0
- package/dist/mcp/tools/graphql.introspect.js +19 -0
- package/dist/mcp/tools/graphql.introspect.js.map +1 -0
- package/dist/mcp/tools/graphql.mutation.d.ts +2 -0
- package/dist/mcp/tools/graphql.mutation.js +43 -0
- package/dist/mcp/tools/graphql.mutation.js.map +1 -0
- package/dist/mcp/tools/graphql.ping.d.ts +2 -0
- package/dist/mcp/tools/graphql.ping.js +23 -0
- package/dist/mcp/tools/graphql.ping.js.map +1 -0
- package/dist/mcp/tools/graphql.query.d.ts +2 -0
- package/dist/mcp/tools/graphql.query.js +42 -0
- package/dist/mcp/tools/graphql.query.js.map +1 -0
- package/dist/mcp/tools/graphql.schemaSdl.d.ts +2 -0
- package/dist/mcp/tools/graphql.schemaSdl.js +15 -0
- package/dist/mcp/tools/graphql.schemaSdl.js.map +1 -0
- package/dist/mcp/tools/help.read.d.ts +2 -0
- package/dist/mcp/tools/help.read.js +67 -0
- package/dist/mcp/tools/help.read.js.map +1 -0
- package/dist/mcp/tools/help.runner.d.ts +2 -0
- package/dist/mcp/tools/help.runner.js +55 -0
- package/dist/mcp/tools/help.runner.js.map +1 -0
- package/dist/mcp/tools/help.runnerDev.d.ts +2 -0
- package/dist/mcp/tools/help.runnerDev.js +56 -0
- package/dist/mcp/tools/help.runnerDev.js.map +1 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +75 -0
- package/dist/mcp.js.map +1 -0
- package/dist/resources/dev.resource.d.ts +5 -0
- package/dist/resources/dev.resource.js +26 -0
- package/dist/resources/dev.resource.js.map +1 -0
- package/dist/resources/docs.generator.resource.d.ts +17 -0
- package/dist/resources/docs.generator.resource.js +230 -0
- package/dist/resources/docs.generator.resource.js.map +1 -0
- package/dist/resources/graphql-accumulator.resource.d.ts +7 -0
- package/dist/resources/graphql-accumulator.resource.js +41 -0
- package/dist/resources/graphql-accumulator.resource.js.map +1 -0
- package/dist/resources/introspector.resource.d.ts +129 -0
- package/dist/resources/introspector.resource.js +266 -0
- package/dist/resources/introspector.resource.js.map +1 -0
- package/dist/resources/introspector.tools.d.ts +47 -0
- package/dist/resources/introspector.tools.js +505 -0
- package/dist/resources/introspector.tools.js.map +1 -0
- package/dist/resources/live.resource.d.ts +80 -0
- package/dist/resources/live.resource.js +231 -0
- package/dist/resources/live.resource.js.map +1 -0
- package/dist/resources/server.resource.d.ts +38 -0
- package/dist/resources/server.resource.js +106 -0
- package/dist/resources/server.resource.js.map +1 -0
- package/dist/resources/swap.resource.d.ts +43 -0
- package/dist/resources/swap.resource.js +251 -0
- package/dist/resources/swap.resource.js.map +1 -0
- package/dist/resources/swap.tools.d.ts +31 -0
- package/dist/resources/swap.tools.js +207 -0
- package/dist/resources/swap.tools.js.map +1 -0
- package/dist/resources/telemetry.chain.d.ts +13 -0
- package/dist/resources/telemetry.chain.js +32 -0
- package/dist/resources/telemetry.chain.js.map +1 -0
- package/dist/resources/telemetry.resource.d.ts +1 -0
- package/dist/resources/telemetry.resource.js +90 -0
- package/dist/resources/telemetry.resource.js.map +1 -0
- package/dist/schema/context.d.ts +11 -0
- package/dist/schema/context.js +3 -0
- package/dist/schema/context.js.map +1 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +72 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/model.d.ts +97 -0
- package/dist/schema/model.js +5 -0
- package/dist/schema/model.js.map +1 -0
- package/dist/schema/mutation.d.ts +3 -0
- package/dist/schema/mutation.js +112 -0
- package/dist/schema/mutation.js.map +1 -0
- package/dist/schema/query.d.ts +3 -0
- package/dist/schema/query.js +295 -0
- package/dist/schema/query.js.map +1 -0
- package/dist/schema/types/AllType.d.ts +3 -0
- package/dist/schema/types/AllType.js +149 -0
- package/dist/schema/types/AllType.js.map +1 -0
- package/dist/schema/types/BaseElementCommon.d.ts +11 -0
- package/dist/schema/types/BaseElementCommon.js +61 -0
- package/dist/schema/types/BaseElementCommon.js.map +1 -0
- package/dist/schema/types/DiagnosticsType.d.ts +2 -0
- package/dist/schema/types/DiagnosticsType.js +15 -0
- package/dist/schema/types/DiagnosticsType.js.map +1 -0
- package/dist/schema/types/EventType.d.ts +4 -0
- package/dist/schema/types/EventType.js +97 -0
- package/dist/schema/types/EventType.js.map +1 -0
- package/dist/schema/types/HookType.d.ts +4 -0
- package/dist/schema/types/HookType.js +123 -0
- package/dist/schema/types/HookType.js.map +1 -0
- package/dist/schema/types/LiveType.d.ts +33 -0
- package/dist/schema/types/LiveType.js +553 -0
- package/dist/schema/types/LiveType.js.map +1 -0
- package/dist/schema/types/MetaType.d.ts +3 -0
- package/dist/schema/types/MetaType.js +31 -0
- package/dist/schema/types/MetaType.js.map +1 -0
- package/dist/schema/types/MiddlewareType.d.ts +4 -0
- package/dist/schema/types/MiddlewareType.js +26 -0
- package/dist/schema/types/MiddlewareType.js.map +1 -0
- package/dist/schema/types/ResourceType.d.ts +2 -0
- package/dist/schema/types/ResourceType.js +145 -0
- package/dist/schema/types/ResourceType.js.map +1 -0
- package/dist/schema/types/RunTypes.d.ts +7 -0
- package/dist/schema/types/RunTypes.js +95 -0
- package/dist/schema/types/RunTypes.js.map +1 -0
- package/dist/schema/types/SwapType.d.ts +5 -0
- package/dist/schema/types/SwapType.js +42 -0
- package/dist/schema/types/SwapType.js.map +1 -0
- package/dist/schema/types/TagType.d.ts +6 -0
- package/dist/schema/types/TagType.js +48 -0
- package/dist/schema/types/TagType.js.map +1 -0
- package/dist/schema/types/TaskLikeCommon.d.ts +7 -0
- package/dist/schema/types/TaskLikeCommon.js +86 -0
- package/dist/schema/types/TaskLikeCommon.js.map +1 -0
- package/dist/schema/types/TaskType.d.ts +11 -0
- package/dist/schema/types/TaskType.js +188 -0
- package/dist/schema/types/TaskType.js.map +1 -0
- package/dist/schema/types/index.d.ts +13 -0
- package/dist/schema/types/index.js +44 -0
- package/dist/schema/types/index.js.map +1 -0
- package/dist/schema/types/middleware/UsageTypes.d.ts +3 -0
- package/dist/schema/types/middleware/UsageTypes.js +23 -0
- package/dist/schema/types/middleware/UsageTypes.js.map +1 -0
- package/dist/schema/types/middleware/common.d.ts +6 -0
- package/dist/schema/types/middleware/common.js +156 -0
- package/dist/schema/types/middleware/common.js.map +1 -0
- package/dist/schema/utils.d.ts +12 -0
- package/dist/schema/utils.js +35 -0
- package/dist/schema/utils.js.map +1 -0
- package/dist/ui/index.html +20 -0
- package/dist/ui/static/index-D-NS5aw1.js +40 -0
- package/dist/utils/json-schema-to-readable.d.ts +1 -0
- package/dist/utils/json-schema-to-readable.js +256 -0
- package/dist/utils/json-schema-to-readable.js.map +1 -0
- package/dist/utils/path.d.ts +16 -0
- package/dist/utils/path.js +101 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/react-ssr.d.ts +9 -0
- package/dist/utils/react-ssr.js +36 -0
- package/dist/utils/react-ssr.js.map +1 -0
- package/dist/utils/zod.d.ts +6 -0
- package/dist/utils/zod.js +39 -0
- package/dist/utils/zod.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.swapManager = void 0;
|
|
4
|
+
const runner_1 = require("@bluelibs/runner");
|
|
5
|
+
const introspector_resource_1 = require("./introspector.resource");
|
|
6
|
+
const swap_tools_1 = require("./swap.tools");
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
exports.swapManager = (0, runner_1.resource)({
|
|
9
|
+
id: "runner-dev.resources.swap-manager",
|
|
10
|
+
dependencies: {
|
|
11
|
+
store: runner_1.globals.resources.store,
|
|
12
|
+
taskRunner: runner_1.globals.resources.taskRunner,
|
|
13
|
+
introspector: introspector_resource_1.introspector,
|
|
14
|
+
eventManager: runner_1.globals.resources.eventManager,
|
|
15
|
+
},
|
|
16
|
+
async init(_, { store, introspector, taskRunner, eventManager }) {
|
|
17
|
+
// Track original run functions and swap metadata
|
|
18
|
+
const originalRunFunctions = new Map();
|
|
19
|
+
const swappedTasks = new Map();
|
|
20
|
+
const api = {
|
|
21
|
+
async swap(taskId, runCode) {
|
|
22
|
+
try {
|
|
23
|
+
// Validate task exists
|
|
24
|
+
const task = (0, swap_tools_1.getTaskFromStore)(store, taskId);
|
|
25
|
+
if (!task) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: `Task '${taskId}' not found`,
|
|
29
|
+
taskId,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Compile the new run function
|
|
33
|
+
const compileResult = (0, swap_tools_1.compileRunFunction)(runCode);
|
|
34
|
+
if (!compileResult.success) {
|
|
35
|
+
return { success: false, error: compileResult.error, taskId };
|
|
36
|
+
}
|
|
37
|
+
// Store original run function if not already stored
|
|
38
|
+
if (!originalRunFunctions.has(taskId)) {
|
|
39
|
+
originalRunFunctions.set(taskId, task.run);
|
|
40
|
+
}
|
|
41
|
+
// Swap the run function
|
|
42
|
+
task.run = compileResult.func;
|
|
43
|
+
// Track the swap
|
|
44
|
+
swappedTasks.set(taskId, {
|
|
45
|
+
taskId,
|
|
46
|
+
swappedAt: Date.now(),
|
|
47
|
+
originalCode: originalRunFunctions.get(taskId)?.toString(),
|
|
48
|
+
});
|
|
49
|
+
return { success: true, taskId };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: `Swap failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
55
|
+
taskId,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
async unswap(taskId) {
|
|
60
|
+
try {
|
|
61
|
+
// Validate task exists and is swapped
|
|
62
|
+
const task = (0, swap_tools_1.getTaskFromStore)(store, taskId);
|
|
63
|
+
if (!task) {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
error: `Task '${taskId}' not found`,
|
|
67
|
+
taskId,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const originalRun = originalRunFunctions.get(taskId);
|
|
71
|
+
if (!originalRun) {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
error: `Task '${taskId}' is not swapped`,
|
|
75
|
+
taskId,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Restore original run function
|
|
79
|
+
task.run = originalRun;
|
|
80
|
+
// Clean up tracking
|
|
81
|
+
originalRunFunctions.delete(taskId);
|
|
82
|
+
swappedTasks.delete(taskId);
|
|
83
|
+
return { success: true, taskId };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
error: `Unswap failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
89
|
+
taskId,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
async unswapAll() {
|
|
94
|
+
const results = [];
|
|
95
|
+
const swappedTaskIds = Array.from(swappedTasks.keys());
|
|
96
|
+
for (const taskId of swappedTaskIds) {
|
|
97
|
+
const result = await api.unswap(taskId);
|
|
98
|
+
results.push(result);
|
|
99
|
+
}
|
|
100
|
+
return results;
|
|
101
|
+
},
|
|
102
|
+
getSwappedTasks() {
|
|
103
|
+
return Array.from(swappedTasks.values());
|
|
104
|
+
},
|
|
105
|
+
isSwapped(taskId) {
|
|
106
|
+
return swappedTasks.has(taskId);
|
|
107
|
+
},
|
|
108
|
+
async invokeTask(taskId, inputJson, pure = false, evalInput = false) {
|
|
109
|
+
const invocationId = (0, crypto_1.randomUUID)();
|
|
110
|
+
const startTime = Date.now();
|
|
111
|
+
try {
|
|
112
|
+
// Validate task exists
|
|
113
|
+
const task = (0, swap_tools_1.getTaskFromStore)(store, taskId);
|
|
114
|
+
if (!task) {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: `Task '${taskId}' not found`,
|
|
118
|
+
taskId,
|
|
119
|
+
invocationId,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// Process input - either JSON parse or JavaScript eval
|
|
123
|
+
let input = undefined;
|
|
124
|
+
if (inputJson) {
|
|
125
|
+
try {
|
|
126
|
+
if (evalInput) {
|
|
127
|
+
// Evaluate as JavaScript expression
|
|
128
|
+
input = eval(`(${inputJson})`);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Parse as JSON
|
|
132
|
+
input = (0, swap_tools_1.deserializeInput)(inputJson);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const method = evalInput
|
|
137
|
+
? "JavaScript evaluation"
|
|
138
|
+
: "JSON deserialization";
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
error: `Input ${method} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
142
|
+
taskId,
|
|
143
|
+
invocationId,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Execute exactly once based on mode
|
|
148
|
+
let result;
|
|
149
|
+
try {
|
|
150
|
+
if (pure) {
|
|
151
|
+
// Pure mode: Get computed dependencies from store (no middleware pipeline)
|
|
152
|
+
const dependencies = (0, swap_tools_1.getTaskDependencies)(store, taskId);
|
|
153
|
+
result = await task.run(input, dependencies);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// Standard mode: use taskRunner to execute through the pipeline
|
|
157
|
+
result = await taskRunner.run(task, input);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (taskError) {
|
|
161
|
+
const executionTimeMs = Date.now() - startTime;
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: `Task execution failed: ${taskError instanceof Error
|
|
165
|
+
? taskError.message
|
|
166
|
+
: String(taskError)}`,
|
|
167
|
+
taskId,
|
|
168
|
+
executionTimeMs,
|
|
169
|
+
invocationId,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// Serialize result
|
|
173
|
+
const serializedResult = (0, swap_tools_1.serializeResult)(result);
|
|
174
|
+
const executionTimeMs = Date.now() - startTime;
|
|
175
|
+
return {
|
|
176
|
+
success: true,
|
|
177
|
+
taskId,
|
|
178
|
+
result: serializedResult,
|
|
179
|
+
executionTimeMs,
|
|
180
|
+
invocationId,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
const executionTimeMs = Date.now() - startTime;
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
error: `Invocation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
188
|
+
taskId,
|
|
189
|
+
executionTimeMs,
|
|
190
|
+
invocationId,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
async runnerEval(code) {
|
|
195
|
+
const invocationId = (0, crypto_1.randomUUID)();
|
|
196
|
+
const startTime = Date.now();
|
|
197
|
+
try {
|
|
198
|
+
// Compile provided code to an async function run(input, deps)
|
|
199
|
+
const compileResult = (0, swap_tools_1.compileRunFunction)(code);
|
|
200
|
+
if (!compileResult.success) {
|
|
201
|
+
return { success: false, error: compileResult.error, invocationId };
|
|
202
|
+
}
|
|
203
|
+
// Provide a useful dependency bag for evaluation
|
|
204
|
+
const dependencies = {
|
|
205
|
+
store,
|
|
206
|
+
introspector,
|
|
207
|
+
globals: runner_1.globals,
|
|
208
|
+
taskRunner,
|
|
209
|
+
eventManager,
|
|
210
|
+
};
|
|
211
|
+
// Execute compiled function
|
|
212
|
+
let result;
|
|
213
|
+
try {
|
|
214
|
+
result = await compileResult.func(dependencies);
|
|
215
|
+
}
|
|
216
|
+
catch (execError) {
|
|
217
|
+
const executionTimeMs = Date.now() - startTime;
|
|
218
|
+
return {
|
|
219
|
+
success: false,
|
|
220
|
+
error: `Evaluation execution failed: ${execError instanceof Error
|
|
221
|
+
? execError.message
|
|
222
|
+
: String(execError)}`,
|
|
223
|
+
executionTimeMs,
|
|
224
|
+
invocationId,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// Serialize result
|
|
228
|
+
const serializedResult = (0, swap_tools_1.serializeResult)(result);
|
|
229
|
+
const executionTimeMs = Date.now() - startTime;
|
|
230
|
+
return {
|
|
231
|
+
success: true,
|
|
232
|
+
result: serializedResult,
|
|
233
|
+
executionTimeMs,
|
|
234
|
+
invocationId,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
const executionTimeMs = Date.now() - startTime;
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
error: `Evaluation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
242
|
+
executionTimeMs,
|
|
243
|
+
invocationId,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
return api;
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
//# sourceMappingURL=swap.resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.resource.js","sourceRoot":"","sources":["../../src/resources/swap.resource.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AACrD,mEAAuD;AAEvD,6CAMsB;AACtB,mCAAoC;AA8CvB,QAAA,WAAW,GAAG,IAAA,iBAAQ,EAAC;IAClC,EAAE,EAAE,mCAAmC;IACvC,YAAY,EAAE;QACZ,KAAK,EAAE,gBAAO,CAAC,SAAS,CAAC,KAAK;QAC9B,UAAU,EAAE,gBAAO,CAAC,SAAS,CAAC,UAAU;QACxC,YAAY,EAAZ,oCAAY;QACZ,YAAY,EAAE,gBAAO,CAAC,SAAS,CAAC,YAAY;KAC7C;IACD,KAAK,CAAC,IAAI,CACR,CAAC,EACD,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE;QAEjD,iDAAiD;QACjD,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAoB,CAAC;QACzD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAuB,CAAC;QAEpD,MAAM,GAAG,GAAgB;YACvB,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,OAAe;gBACxC,IAAI,CAAC;oBACH,uBAAuB;oBACvB,MAAM,IAAI,GAAG,IAAA,6BAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;oBAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;wBACV,OAAO;4BACL,OAAO,EAAE,KAAK;4BACd,KAAK,EAAE,SAAS,MAAM,aAAa;4BACnC,MAAM;yBACP,CAAC;oBACJ,CAAC;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Ae,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;oBAE/C,OAAO;wBACL,OAAO,EAAE,IAAI;wBACb,MAAM,EAAE,gBAAgB;wBACxB,eAAe;wBACf,YAAY;qBACb,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;oBAC/C,OAAO;wBACL,OAAO,EAAE,KAAK;wBACd,KAAK,EAAE,sBACL,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE;wBACF,eAAe;wBACf,YAAY;qBACb,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Store } from "@bluelibs/runner";
|
|
2
|
+
/**
|
|
3
|
+
* Compile TypeScript/JavaScript code and return the compiled function
|
|
4
|
+
*/
|
|
5
|
+
export declare function compileRunFunction(code: string): {
|
|
6
|
+
success: true;
|
|
7
|
+
func: Function;
|
|
8
|
+
} | {
|
|
9
|
+
success: false;
|
|
10
|
+
error: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Get task from store by ID
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTaskFromStore(store: Store, taskId: string): import("@bluelibs/runner/dist/defs").ITask<any, any, any, any, import("@bluelibs/runner/dist/defs").TagType[], import("@bluelibs/runner/dist/defs").TaskMiddlewareAttachmentType[]> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Get task from store by ID
|
|
18
|
+
*/
|
|
19
|
+
export declare function getEventFromStore(store: Store, eventId: string): import("@bluelibs/runner/dist/defs").IEvent<any> | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Get computed dependencies for a task from store
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTaskDependencies(store: any, taskId: string): any;
|
|
24
|
+
/**
|
|
25
|
+
* Serialize JavaScript value to JSON, handling complex types
|
|
26
|
+
*/
|
|
27
|
+
export declare function serializeResult(value: any): string;
|
|
28
|
+
/**
|
|
29
|
+
* Deserialize JSON to JavaScript value, handling basic types
|
|
30
|
+
*/
|
|
31
|
+
export declare function deserializeInput(jsonInput: string): any;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.compileRunFunction = compileRunFunction;
|
|
27
|
+
exports.getTaskFromStore = getTaskFromStore;
|
|
28
|
+
exports.getEventFromStore = getEventFromStore;
|
|
29
|
+
exports.getTaskDependencies = getTaskDependencies;
|
|
30
|
+
exports.serializeResult = serializeResult;
|
|
31
|
+
exports.deserializeInput = deserializeInput;
|
|
32
|
+
const ts = __importStar(require("typescript"));
|
|
33
|
+
/**
|
|
34
|
+
* Compile TypeScript/JavaScript code and return the compiled function
|
|
35
|
+
*/
|
|
36
|
+
function compileRunFunction(code) {
|
|
37
|
+
try {
|
|
38
|
+
// Validate input
|
|
39
|
+
if (!code || code.trim() === "") {
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
error: "Compilation failed: Code cannot be empty",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// First, try to compile as TypeScript
|
|
46
|
+
const compilerOptions = {
|
|
47
|
+
target: ts.ScriptTarget.ES2020,
|
|
48
|
+
module: ts.ModuleKind.CommonJS,
|
|
49
|
+
strict: true,
|
|
50
|
+
noImplicitAny: false,
|
|
51
|
+
skipLibCheck: true,
|
|
52
|
+
};
|
|
53
|
+
// Wrap code in a function if it's not already
|
|
54
|
+
let wrappedCode = code.trim();
|
|
55
|
+
if (!wrappedCode.startsWith("function") &&
|
|
56
|
+
!wrappedCode.startsWith("async function")) {
|
|
57
|
+
// If it's an arrow function, wrap it with return
|
|
58
|
+
if (wrappedCode.includes("=>")) {
|
|
59
|
+
wrappedCode = `async function run(input, deps) { return (${wrappedCode})(input, deps); }`;
|
|
60
|
+
}
|
|
61
|
+
else if (!wrappedCode.includes("function") &&
|
|
62
|
+
wrappedCode.includes("return")) {
|
|
63
|
+
// It's a function body with return statements
|
|
64
|
+
wrappedCode = `async function run(input, deps) { ${wrappedCode} }`;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Assume it's a complete function body
|
|
68
|
+
wrappedCode = `async function run(input, deps) {\n${wrappedCode}\n}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Basic syntax validation - only for clearly invalid code patterns
|
|
72
|
+
const hasObviousErrors = wrappedCode.includes("{{{") ||
|
|
73
|
+
wrappedCode.includes("}}}") ||
|
|
74
|
+
/[{}]\s*[{}]\s*[{}]/.test(wrappedCode);
|
|
75
|
+
if (hasObviousErrors) {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
error: "Compilation failed: Invalid syntax detected",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Try TypeScript compilation first
|
|
82
|
+
const result = ts.transpile(wrappedCode, compilerOptions);
|
|
83
|
+
// Create and validate the function
|
|
84
|
+
// The result should be a function declaration, so we need to evaluate it and extract the function
|
|
85
|
+
let func;
|
|
86
|
+
try {
|
|
87
|
+
// Create a new context to execute the compiled code
|
|
88
|
+
const context = { exports: {}, module: { exports: {} } };
|
|
89
|
+
const functionCode = `
|
|
90
|
+
${result}
|
|
91
|
+
return (typeof run !== 'undefined') ? run :
|
|
92
|
+
(typeof exports.default === 'function') ? exports.default :
|
|
93
|
+
(typeof module.exports === 'function') ? module.exports : null;
|
|
94
|
+
`;
|
|
95
|
+
func = new Function("exports", "module", functionCode)(context.exports, context.module);
|
|
96
|
+
}
|
|
97
|
+
catch (evalError) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
error: `Function evaluation failed: ${evalError instanceof Error ? evalError.message : String(evalError)}`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (typeof func !== "function") {
|
|
104
|
+
return { success: false, error: "Code must export a function" };
|
|
105
|
+
}
|
|
106
|
+
return { success: true, func };
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: `Compilation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get task from store by ID
|
|
117
|
+
*/
|
|
118
|
+
function getTaskFromStore(store, taskId) {
|
|
119
|
+
if (taskId.includes("Symbol")) {
|
|
120
|
+
for (const taskElement of store.tasks.values()) {
|
|
121
|
+
if (taskElement.task.id.toString() === taskId) {
|
|
122
|
+
return taskElement.task;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const taskStoreElement = store.tasks.get(taskId);
|
|
127
|
+
return taskStoreElement?.task;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get task from store by ID
|
|
131
|
+
*/
|
|
132
|
+
function getEventFromStore(store, eventId) {
|
|
133
|
+
if (eventId.includes("Symbol")) {
|
|
134
|
+
for (const eventElement of store.events.values()) {
|
|
135
|
+
if (eventElement.event.id.toString() === eventId) {
|
|
136
|
+
return eventElement.event;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const eventStoreElement = store.events.get(eventId);
|
|
141
|
+
return eventStoreElement?.event;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get computed dependencies for a task from store
|
|
145
|
+
*/
|
|
146
|
+
function getTaskDependencies(store, taskId) {
|
|
147
|
+
try {
|
|
148
|
+
// Prefer reading from the task store element directly to access computedDependencies
|
|
149
|
+
let storeElement = store.tasks.get(taskId);
|
|
150
|
+
if (!storeElement) {
|
|
151
|
+
// Handle symbol-based task ids where Map key may differ from id string
|
|
152
|
+
for (const candidate of store.tasks.values()) {
|
|
153
|
+
if (candidate?.task && String(candidate.task.id) === taskId) {
|
|
154
|
+
storeElement = candidate;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const dependencies = storeElement?.computedDependencies;
|
|
160
|
+
return dependencies ?? {};
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
// If anything fails, return empty dependencies to prevent crashes
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Serialize JavaScript value to JSON, handling complex types
|
|
169
|
+
*/
|
|
170
|
+
function serializeResult(value) {
|
|
171
|
+
try {
|
|
172
|
+
return JSON.stringify(value, (key, val) => {
|
|
173
|
+
// Handle functions
|
|
174
|
+
if (typeof val === "function") {
|
|
175
|
+
return `[Function: ${val.name || "anonymous"}]`;
|
|
176
|
+
}
|
|
177
|
+
// Handle undefined
|
|
178
|
+
if (val === undefined) {
|
|
179
|
+
return "[undefined]";
|
|
180
|
+
}
|
|
181
|
+
// Handle circular references
|
|
182
|
+
if (typeof val === "object" && val !== null) {
|
|
183
|
+
if (val.constructor &&
|
|
184
|
+
val.constructor.name !== "Object" &&
|
|
185
|
+
val.constructor.name !== "Array") {
|
|
186
|
+
return `[${val.constructor.name}]`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return val;
|
|
190
|
+
}, 2);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
return `[Serialization Error: ${error instanceof Error ? error.message : String(error)}]`;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Deserialize JSON to JavaScript value, handling basic types
|
|
198
|
+
*/
|
|
199
|
+
function deserializeInput(jsonInput) {
|
|
200
|
+
try {
|
|
201
|
+
return JSON.parse(jsonInput);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw new Error(`JSON deserialization failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=swap.tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.tools.js","sourceRoot":"","sources":["../../src/resources/swap.tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,gDA+FC;AAKD,4CAYC;AAKD,8CAYC;AAKD,kDAqBC;AAKD,0CAgCC;AAKD,4CAUC;AArND,+CAAiC;AAGjC;;GAEG;AACH,SAAgB,kBAAkB,CAChC,IAAY;IAEZ,IAAI,CAAC;QACH,iBAAiB;QACjB,IAAI,CAAC,IAA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,KAAK,CACvD,GAAG,CAAC;IACN,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAiB;IAChD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,gCACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,CACH,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
export type RunContext = {
|
|
3
|
+
chain: string[];
|
|
4
|
+
correlationId: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const runContext: AsyncLocalStorage<RunContext>;
|
|
7
|
+
export declare function getCurrentRunContext(): RunContext | undefined;
|
|
8
|
+
export declare function getCorrelationId(): string | null;
|
|
9
|
+
export declare function deriveParentAndRoot(taskId: string): {
|
|
10
|
+
parentId: string | null;
|
|
11
|
+
rootId: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function withTaskRunContext<T>(taskId: string, fn: () => Promise<T> | T): Promise<T>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runContext = void 0;
|
|
4
|
+
exports.getCurrentRunContext = getCurrentRunContext;
|
|
5
|
+
exports.getCorrelationId = getCorrelationId;
|
|
6
|
+
exports.deriveParentAndRoot = deriveParentAndRoot;
|
|
7
|
+
exports.withTaskRunContext = withTaskRunContext;
|
|
8
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
9
|
+
const node_crypto_1 = require("node:crypto");
|
|
10
|
+
exports.runContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
11
|
+
function getCurrentRunContext() {
|
|
12
|
+
return exports.runContext.getStore();
|
|
13
|
+
}
|
|
14
|
+
function getCorrelationId() {
|
|
15
|
+
return exports.runContext.getStore()?.correlationId ?? null;
|
|
16
|
+
}
|
|
17
|
+
function deriveParentAndRoot(taskId) {
|
|
18
|
+
const store = exports.runContext.getStore();
|
|
19
|
+
const prevChain = store?.chain ?? [];
|
|
20
|
+
const parentId = prevChain.length > 0 ? prevChain[prevChain.length - 1] : null;
|
|
21
|
+
const rootId = prevChain.length > 0 ? prevChain[0] : taskId;
|
|
22
|
+
return { parentId, rootId };
|
|
23
|
+
}
|
|
24
|
+
async function withTaskRunContext(taskId, fn) {
|
|
25
|
+
const store = exports.runContext.getStore();
|
|
26
|
+
const correlationId = store?.correlationId ?? (0, node_crypto_1.randomUUID)();
|
|
27
|
+
const prevChain = store?.chain ?? [];
|
|
28
|
+
const newChain = [...prevChain, taskId];
|
|
29
|
+
const nextStore = { chain: newChain, correlationId };
|
|
30
|
+
return await exports.runContext.run(nextStore, async () => fn());
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=telemetry.chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.chain.js","sourceRoot":"","sources":["../../src/resources/telemetry.chain.ts"],"names":[],"mappings":";;;AAUA,oDAEC;AAED,4CAEC;AAED,kDAUC;AAED,gDAUC;AAxCD,uDAAqD;AACrD,6CAAyC;AAO5B,QAAA,UAAU,GAAG,IAAI,oCAAiB,EAAc,CAAC;AAE9D,SAAgB,oBAAoB;IAClC,OAAO,kBAAU,CAAC,QAAQ,EAAE,CAAC;AAC/B,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,kBAAU,CAAC,QAAQ,EAAE,EAAE,aAAa,IAAI,IAAI,CAAC;AACtD,CAAC;AAED,SAAgB,mBAAmB,CAAC,MAAc;IAIhD,MAAM,KAAK,GAAG,kBAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC;IACrC,MAAM,QAAQ,GACZ,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAChE,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,MAAc,EACd,EAAwB;IAExB,MAAM,KAAK,GAAG,kBAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,MAAM,aAAa,GAAG,KAAK,EAAE,aAAa,IAAI,IAAA,wBAAU,GAAE,CAAC;IAC3D,MAAM,SAAS,GAAG,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,CAAC,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,SAAS,GAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;IACjE,OAAO,MAAM,kBAAU,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const telemetry: import("@bluelibs/runner/dist/defs").IResource<void, Promise<void>, {}, any, any, import("@bluelibs/runner/dist/defs").TagType[], import("@bluelibs/runner/dist/defs").ResourceMiddlewareAttachmentType[]>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.telemetry = void 0;
|
|
4
|
+
const runner_1 = require("@bluelibs/runner");
|
|
5
|
+
const live_resource_1 = require("./live.resource");
|
|
6
|
+
const telemetry_chain_1 = require("./telemetry.chain");
|
|
7
|
+
const overrideEventManagerEmittor = (0, runner_1.resource)({
|
|
8
|
+
id: "runner-dev.telemetry.overrideEventManagerEmittor",
|
|
9
|
+
meta: {
|
|
10
|
+
title: "Override event manager emittor",
|
|
11
|
+
description: "Overrides the event manager emittor to record telemetry, no other changes are made to the input.",
|
|
12
|
+
},
|
|
13
|
+
dependencies: { eventManager: runner_1.globals.resources.eventManager, live: live_resource_1.live },
|
|
14
|
+
async init(_, { eventManager, live }) {
|
|
15
|
+
eventManager.intercept((next, emission) => {
|
|
16
|
+
return (0, telemetry_chain_1.withTaskRunContext)(emission.id, async () => {
|
|
17
|
+
live.recordEmission(emission.id, emission.data, emission.source);
|
|
18
|
+
return next(emission);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const hookInterceptors = (0, runner_1.resource)({
|
|
24
|
+
id: "runner-dev.telemetry.resources.hookInterceptors",
|
|
25
|
+
dependencies: { live: live_resource_1.live, eventManager: runner_1.globals.resources.eventManager },
|
|
26
|
+
async init(_, { live, eventManager }) {
|
|
27
|
+
eventManager.interceptHook(async (next, hook, emission) => {
|
|
28
|
+
const startedAt = Date.now();
|
|
29
|
+
const { parentId, rootId } = (0, telemetry_chain_1.deriveParentAndRoot)(hook.id);
|
|
30
|
+
let error = undefined;
|
|
31
|
+
try {
|
|
32
|
+
const result = await next(hook, emission);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
live.recordError(hook.id, "HOOK", error);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
const durationMs = Date.now() - startedAt;
|
|
40
|
+
live.recordRun(hook.id, "HOOK", durationMs, !error, undefined, parentId, rootId);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const telemetryMiddleware = (0, runner_1.taskMiddleware)({
|
|
46
|
+
everywhere: true,
|
|
47
|
+
id: "runner-dev.telemetry.middleware",
|
|
48
|
+
dependencies: { live: live_resource_1.live },
|
|
49
|
+
async run({ task, next }, { live }) {
|
|
50
|
+
const id = String(task.definition.id);
|
|
51
|
+
// Skip internal dev tools nodes to avoid self-instrumentation
|
|
52
|
+
if (id.startsWith("runner-dev.")) {
|
|
53
|
+
return next(task.input);
|
|
54
|
+
}
|
|
55
|
+
const { parentId, rootId } = (0, telemetry_chain_1.deriveParentAndRoot)(id);
|
|
56
|
+
const startedAt = Date.now();
|
|
57
|
+
return (0, telemetry_chain_1.withTaskRunContext)(id, async () => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await next(task.input);
|
|
60
|
+
const durationMs = Date.now() - startedAt;
|
|
61
|
+
live.recordRun(id, "TASK", durationMs, true, undefined, parentId, rootId);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const durationMs = Date.now() - startedAt;
|
|
66
|
+
// Best-effort error capture via Live (errors buffer)
|
|
67
|
+
live.recordError(id, "TASK", error);
|
|
68
|
+
try {
|
|
69
|
+
live.recordRun(id, "TASK", durationMs, false, error, parentId, rootId);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// ignore if live lacks recordRun
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
exports.telemetry = (0, runner_1.resource)({
|
|
80
|
+
id: "runner-dev.telemetry",
|
|
81
|
+
register: [
|
|
82
|
+
telemetryMiddleware,
|
|
83
|
+
overrideEventManagerEmittor,
|
|
84
|
+
hookInterceptors,
|
|
85
|
+
],
|
|
86
|
+
async init() {
|
|
87
|
+
// no-op
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=telemetry.resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.resource.js","sourceRoot":"","sources":["../../src/resources/tel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