@kb-labs/workflow-daemon 2.75.0 → 2.79.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 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,9 @@ 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: run2, with: existingWith, ...rest } = baseSpec;
345
- baseSpec = { ...rest, uses: "builtin:shell", with: { ...existingWith, command: run2 } };
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 } };
346
348
  }
347
349
  const interpolatedSpec = interpolatedWith ? { ...baseSpec, with: { ...baseSpec.with ?? {}, ...interpolatedWith } } : baseSpec;
348
350
  const result = await runner.execute({
@@ -1354,12 +1356,19 @@ var WorkflowHostService = class {
1354
1356
  ...request.isolation ? { isolation: request.isolation } : {}
1355
1357
  };
1356
1358
  const triggerType = request.trigger?.type === "cron" ? "schedule" : request.trigger?.type === "api" ? "webhook" : "manual";
1359
+ const specInputDefs = specInput["inputs"] ?? {};
1360
+ const userInputs = request.input && typeof request.input === "object" ? request.input : {};
1361
+ const resolvedInputs = {};
1362
+ for (const [key, def] of Object.entries(specInputDefs)) {
1363
+ resolvedInputs[key] = key in userInputs ? userInputs[key] : def.default;
1364
+ }
1357
1365
  const run = await this.options.engine.runFromSpec(spec, {
1358
1366
  trigger: {
1359
1367
  type: triggerType,
1360
1368
  actor: request.trigger?.user,
1361
- payload: request.input && typeof request.input === "object" ? request.input : void 0
1362
- }
1369
+ payload: userInputs
1370
+ },
1371
+ inputs: resolvedInputs
1363
1372
  });
1364
1373
  return {
1365
1374
  runId: run.id,
@@ -2388,6 +2397,7 @@ var serverInstance = null;
2388
2397
  var cronSchedulerInstance = null;
2389
2398
  async function bootstrap(cwd = process.cwd()) {
2390
2399
  const repoRoot = await findRepoRoot(cwd);
2400
+ const projectRoot = process.env["KB_PROJECT_ROOT"] ?? repoRoot;
2391
2401
  await createServiceBootstrap({ appId: "workflow-daemon", repoRoot });
2392
2402
  if (!platform.isConfigured("workspace")) {
2393
2403
  process.stderr.write(
@@ -2416,7 +2426,7 @@ async function bootstrap(cwd = process.cwd()) {
2416
2426
  executionId: startupSpanId
2417
2427
  }
2418
2428
  });
2419
- bootstrapLogger.info("Workflow daemon starting", { repoRoot });
2429
+ bootstrapLogger.info("Workflow daemon starting", { repoRoot, projectRoot });
2420
2430
  const createWorkflowLogger = (service, operation, bindings) => createCorrelatedLogger(platform.logger, {
2421
2431
  serviceId: "workflow",
2422
2432
  logsSource: "workflow",
@@ -2445,7 +2455,7 @@ async function bootstrap(cwd = process.cwd()) {
2445
2455
  events: platform.eventBus,
2446
2456
  logger: createWorkflowLogger("engine", "workflow.engine"),
2447
2457
  snapshotManager: platform.snapshotManager,
2448
- workspaceRoot: repoRoot
2458
+ workspaceRoot: projectRoot
2449
2459
  });
2450
2460
  bootstrapLogger.info("Cleaning up stale runs from previous daemon process");
2451
2461
  await engine.cleanupStaleRuns();
@@ -2466,7 +2476,7 @@ async function bootstrap(cwd = process.cwd()) {
2466
2476
  cliApi,
2467
2477
  scheduler: cronScheduler,
2468
2478
  logger: createWorkflowLogger("cron-discovery", "workflow.cron-discovery"),
2469
- workspaceRoot: repoRoot
2479
+ workspaceRoot: projectRoot
2470
2480
  });
2471
2481
  const discovered = await cronDiscovery.discoverAll();
2472
2482
  bootstrapLogger.info("Cron job discovery complete", discovered);
@@ -2474,7 +2484,7 @@ async function bootstrap(cwd = process.cwd()) {
2474
2484
  const workflowService = new WorkflowService({
2475
2485
  cliApi,
2476
2486
  platform,
2477
- workspaceRoot: repoRoot
2487
+ workspaceRoot: projectRoot
2478
2488
  });
2479
2489
  bootstrapLogger.info("Creating HTTP server");
2480
2490
  const server = await createServer({
@@ -2496,7 +2506,7 @@ async function bootstrap(cwd = process.cwd()) {
2496
2506
  logger: createWorkflowLogger("worker", "workflow.worker"),
2497
2507
  analytics: platform.analytics,
2498
2508
  platform,
2499
- workspaceRoot: repoRoot,
2509
+ workspaceRoot: projectRoot,
2500
2510
  concurrency: parseInt(process.env.WORKFLOW_CONCURRENCY || "5", 10)
2501
2511
  });
2502
2512
  workerInstance = worker;