@kb-labs/workflow-daemon 2.77.0 → 2.80.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/dist/index.js +25 -12
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createServiceBootstrap, platform } from '@kb-labs/core-runtime';
|
|
|
3
3
|
import { WorkflowEngine, WorkflowService } from '@kb-labs/workflow-engine';
|
|
4
4
|
import { createCorrelatedLogger, registerOpenAPI, HttpObservabilityCollector, createServiceReadyResponse, metricLine } from '@kb-labs/shared-http';
|
|
5
5
|
import { logDiagnosticEvent } from '@kb-labs/core-platform';
|
|
6
|
-
import { PluginCronJobSchema, UserCronJobSchema, evaluateExpression, interpolateObject, resolveValue } from '@kb-labs/workflow-contracts';
|
|
6
|
+
import { PluginCronJobSchema, UserCronJobSchema, evaluateExpression, interpolateObject, resolveValue, interpolateString } from '@kb-labs/workflow-contracts';
|
|
7
7
|
import { SandboxRunner } from '@kb-labs/workflow-runtime';
|
|
8
8
|
import * as cron from 'node-cron';
|
|
9
9
|
import { CronExpressionParser } from 'cron-parser';
|
|
@@ -97,7 +97,7 @@ async function createWorkflowWorker(options) {
|
|
|
97
97
|
const jobTarget = job.target;
|
|
98
98
|
const target = jobTarget ?? runTarget;
|
|
99
99
|
const wsProvider = platform2.getAdapter("workspace");
|
|
100
|
-
let runWorkspace = workspaceRoot;
|
|
100
|
+
let runWorkspace = wsProvider ? workspaceRoot : process.env["KB_PROJECT_ROOT"] ?? workspaceRoot;
|
|
101
101
|
let provisionedWorkspaceId;
|
|
102
102
|
if (wsProvider) {
|
|
103
103
|
const wsId = `wt_${run.id.slice(0, 8)}`;
|
|
@@ -156,6 +156,7 @@ async function createWorkflowWorker(options) {
|
|
|
156
156
|
const exprCtx = {
|
|
157
157
|
env: freshRun?.env ?? {},
|
|
158
158
|
trigger: freshRun?.trigger ?? { type: "manual" },
|
|
159
|
+
inputs: freshRun?.inputs ?? {},
|
|
159
160
|
steps: {}
|
|
160
161
|
};
|
|
161
162
|
if (freshRun) {
|
|
@@ -341,8 +342,12 @@ async function createWorkflowWorker(options) {
|
|
|
341
342
|
await engine.markStepStarted(run.id, job.id, step.id);
|
|
342
343
|
let baseSpec = step.spec;
|
|
343
344
|
if (baseSpec.run && !baseSpec.uses) {
|
|
344
|
-
const { run:
|
|
345
|
-
|
|
345
|
+
const { run: rawRun, with: existingWith, ...rest } = baseSpec;
|
|
346
|
+
const command = typeof rawRun === "string" ? interpolateString(rawRun, exprCtx) : rawRun;
|
|
347
|
+
baseSpec = { ...rest, uses: "builtin:shell", with: { ...existingWith, command } };
|
|
348
|
+
}
|
|
349
|
+
if (typeof baseSpec.summary === "string") {
|
|
350
|
+
baseSpec.summary = interpolateString(baseSpec.summary, exprCtx);
|
|
346
351
|
}
|
|
347
352
|
const interpolatedSpec = interpolatedWith ? { ...baseSpec, with: { ...baseSpec.with ?? {}, ...interpolatedWith } } : baseSpec;
|
|
348
353
|
const result = await runner.execute({
|
|
@@ -1354,12 +1359,19 @@ var WorkflowHostService = class {
|
|
|
1354
1359
|
...request.isolation ? { isolation: request.isolation } : {}
|
|
1355
1360
|
};
|
|
1356
1361
|
const triggerType = request.trigger?.type === "cron" ? "schedule" : request.trigger?.type === "api" ? "webhook" : "manual";
|
|
1362
|
+
const specInputDefs = specInput["inputs"] ?? {};
|
|
1363
|
+
const userInputs = request.input && typeof request.input === "object" ? request.input : {};
|
|
1364
|
+
const resolvedInputs = {};
|
|
1365
|
+
for (const [key, def] of Object.entries(specInputDefs)) {
|
|
1366
|
+
resolvedInputs[key] = key in userInputs ? userInputs[key] : def.default;
|
|
1367
|
+
}
|
|
1357
1368
|
const run = await this.options.engine.runFromSpec(spec, {
|
|
1358
1369
|
trigger: {
|
|
1359
1370
|
type: triggerType,
|
|
1360
1371
|
actor: request.trigger?.user,
|
|
1361
|
-
payload:
|
|
1362
|
-
}
|
|
1372
|
+
payload: userInputs
|
|
1373
|
+
},
|
|
1374
|
+
inputs: resolvedInputs
|
|
1363
1375
|
});
|
|
1364
1376
|
return {
|
|
1365
1377
|
runId: run.id,
|
|
@@ -1805,7 +1817,7 @@ function registerCronAPI(options) {
|
|
|
1805
1817
|
|
|
1806
1818
|
// src/api/workflows-api.ts
|
|
1807
1819
|
var TERMINAL_EVENTS = ["run.finished", "run.failed", "run.cancelled"];
|
|
1808
|
-
var TERMINAL_STATUSES = ["success", "failed", "cancelled", "skipped"];
|
|
1820
|
+
var TERMINAL_STATUSES = ["success", "failed", "cancelled", "skipped", "dlq"];
|
|
1809
1821
|
var KEEP_ALIVE_MS = 3e4;
|
|
1810
1822
|
var IDLE_TIMEOUT_MS = 6e4;
|
|
1811
1823
|
function registerWorkflowsAPI(options) {
|
|
@@ -2388,6 +2400,7 @@ var serverInstance = null;
|
|
|
2388
2400
|
var cronSchedulerInstance = null;
|
|
2389
2401
|
async function bootstrap(cwd = process.cwd()) {
|
|
2390
2402
|
const repoRoot = await findRepoRoot(cwd);
|
|
2403
|
+
const projectRoot = process.env["KB_PROJECT_ROOT"] ?? repoRoot;
|
|
2391
2404
|
await createServiceBootstrap({ appId: "workflow-daemon", repoRoot });
|
|
2392
2405
|
if (!platform.isConfigured("workspace")) {
|
|
2393
2406
|
process.stderr.write(
|
|
@@ -2416,7 +2429,7 @@ async function bootstrap(cwd = process.cwd()) {
|
|
|
2416
2429
|
executionId: startupSpanId
|
|
2417
2430
|
}
|
|
2418
2431
|
});
|
|
2419
|
-
bootstrapLogger.info("Workflow daemon starting", { repoRoot });
|
|
2432
|
+
bootstrapLogger.info("Workflow daemon starting", { repoRoot, projectRoot });
|
|
2420
2433
|
const createWorkflowLogger = (service, operation, bindings) => createCorrelatedLogger(platform.logger, {
|
|
2421
2434
|
serviceId: "workflow",
|
|
2422
2435
|
logsSource: "workflow",
|
|
@@ -2445,7 +2458,7 @@ async function bootstrap(cwd = process.cwd()) {
|
|
|
2445
2458
|
events: platform.eventBus,
|
|
2446
2459
|
logger: createWorkflowLogger("engine", "workflow.engine"),
|
|
2447
2460
|
snapshotManager: platform.snapshotManager,
|
|
2448
|
-
workspaceRoot:
|
|
2461
|
+
workspaceRoot: projectRoot
|
|
2449
2462
|
});
|
|
2450
2463
|
bootstrapLogger.info("Cleaning up stale runs from previous daemon process");
|
|
2451
2464
|
await engine.cleanupStaleRuns();
|
|
@@ -2466,7 +2479,7 @@ async function bootstrap(cwd = process.cwd()) {
|
|
|
2466
2479
|
cliApi,
|
|
2467
2480
|
scheduler: cronScheduler,
|
|
2468
2481
|
logger: createWorkflowLogger("cron-discovery", "workflow.cron-discovery"),
|
|
2469
|
-
workspaceRoot:
|
|
2482
|
+
workspaceRoot: projectRoot
|
|
2470
2483
|
});
|
|
2471
2484
|
const discovered = await cronDiscovery.discoverAll();
|
|
2472
2485
|
bootstrapLogger.info("Cron job discovery complete", discovered);
|
|
@@ -2474,7 +2487,7 @@ async function bootstrap(cwd = process.cwd()) {
|
|
|
2474
2487
|
const workflowService = new WorkflowService({
|
|
2475
2488
|
cliApi,
|
|
2476
2489
|
platform,
|
|
2477
|
-
workspaceRoot:
|
|
2490
|
+
workspaceRoot: projectRoot
|
|
2478
2491
|
});
|
|
2479
2492
|
bootstrapLogger.info("Creating HTTP server");
|
|
2480
2493
|
const server = await createServer({
|
|
@@ -2496,7 +2509,7 @@ async function bootstrap(cwd = process.cwd()) {
|
|
|
2496
2509
|
logger: createWorkflowLogger("worker", "workflow.worker"),
|
|
2497
2510
|
analytics: platform.analytics,
|
|
2498
2511
|
platform,
|
|
2499
|
-
workspaceRoot:
|
|
2512
|
+
workspaceRoot: projectRoot,
|
|
2500
2513
|
concurrency: parseInt(process.env.WORKFLOW_CONCURRENCY || "5", 10)
|
|
2501
2514
|
});
|
|
2502
2515
|
workerInstance = worker;
|