@relayflows/sdk 2.0.31 → 2.0.32

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.
Files changed (76) hide show
  1. package/dist/authored-preflight.d.ts +4 -0
  2. package/dist/authored-preflight.d.ts.map +1 -0
  3. package/dist/authored-preflight.js +50 -0
  4. package/dist/authored-preflight.js.map +1 -0
  5. package/dist/authored-worker-step.d.ts.map +1 -1
  6. package/dist/authored-worker-step.js +3 -2
  7. package/dist/authored-worker-step.js.map +1 -1
  8. package/dist/cli/check.d.ts +10 -2
  9. package/dist/cli/check.d.ts.map +1 -1
  10. package/dist/cli/check.js +16 -137
  11. package/dist/cli/check.js.map +1 -1
  12. package/dist/cli/cli-probe.d.ts +20 -0
  13. package/dist/cli/cli-probe.d.ts.map +1 -0
  14. package/dist/cli/cli-probe.js +166 -0
  15. package/dist/cli/cli-probe.js.map +1 -0
  16. package/dist/cli/cloud-mirror-session.d.ts +97 -0
  17. package/dist/cli/cloud-mirror-session.d.ts.map +1 -0
  18. package/dist/cli/cloud-mirror-session.js +264 -0
  19. package/dist/cli/cloud-mirror-session.js.map +1 -0
  20. package/dist/cli-commands.d.ts +6 -0
  21. package/dist/cli-commands.d.ts.map +1 -1
  22. package/dist/cli-commands.js +1 -0
  23. package/dist/cli-commands.js.map +1 -1
  24. package/dist/cli.d.ts +7 -0
  25. package/dist/cli.d.ts.map +1 -1
  26. package/dist/cli.js +84 -18
  27. package/dist/cli.js.map +1 -1
  28. package/dist/cloud-deploy.d.ts +1 -1
  29. package/dist/cloud-deploy.d.ts.map +1 -1
  30. package/dist/cloud-deploy.js +24 -8
  31. package/dist/cloud-deploy.js.map +1 -1
  32. package/dist/cloud-mirror-ledger.d.ts +40 -0
  33. package/dist/cloud-mirror-ledger.d.ts.map +1 -0
  34. package/dist/cloud-mirror-ledger.js +142 -0
  35. package/dist/cloud-mirror-ledger.js.map +1 -0
  36. package/dist/cloud-mirror-step.d.ts +168 -0
  37. package/dist/cloud-mirror-step.d.ts.map +1 -0
  38. package/dist/cloud-mirror-step.js +504 -0
  39. package/dist/cloud-mirror-step.js.map +1 -0
  40. package/dist/cloud-mirror-transport.d.ts +94 -0
  41. package/dist/cloud-mirror-transport.d.ts.map +1 -0
  42. package/dist/cloud-mirror-transport.js +163 -0
  43. package/dist/cloud-mirror-transport.js.map +1 -0
  44. package/dist/cloud-mirror.d.ts +132 -0
  45. package/dist/cloud-mirror.d.ts.map +1 -0
  46. package/dist/cloud-mirror.js +556 -0
  47. package/dist/cloud-mirror.js.map +1 -0
  48. package/dist/hosted-extension-runtime.js +1 -1
  49. package/dist/package-version.d.ts +10 -0
  50. package/dist/package-version.d.ts.map +1 -0
  51. package/dist/package-version.js +22 -0
  52. package/dist/package-version.js.map +1 -0
  53. package/dist/preflight.d.ts +14 -0
  54. package/dist/preflight.d.ts.map +1 -1
  55. package/dist/preflight.js +18 -3
  56. package/dist/preflight.js.map +1 -1
  57. package/dist/relay-cli.d.ts.map +1 -1
  58. package/dist/relay-cli.js +1 -21
  59. package/dist/relay-cli.js.map +1 -1
  60. package/package.json +2 -2
  61. package/src/authored-preflight.ts +46 -0
  62. package/src/authored-worker-step.ts +4 -3
  63. package/src/cli/check.ts +25 -163
  64. package/src/cli/cli-probe.ts +194 -0
  65. package/src/cli/cloud-mirror-session.ts +329 -0
  66. package/src/cli-commands.ts +1 -0
  67. package/src/cli.ts +94 -19
  68. package/src/cloud-deploy.ts +26 -8
  69. package/src/cloud-mirror-ledger.ts +161 -0
  70. package/src/cloud-mirror-step.ts +618 -0
  71. package/src/cloud-mirror-transport.ts +261 -0
  72. package/src/cloud-mirror.ts +633 -0
  73. package/src/hosted-extension-runtime.ts +1 -1
  74. package/src/package-version.ts +23 -0
  75. package/src/preflight.ts +31 -7
  76. package/src/relay-cli.ts +1 -24
package/src/preflight.ts CHANGED
@@ -65,7 +65,7 @@ export class CliProbeError extends Error {
65
65
  }
66
66
  }
67
67
 
68
- type CliProbeOutcome =
68
+ export type CliProbeOutcome =
69
69
  | { result: CliProbeResult }
70
70
  | { failure: CliProbeFailureDetail | null };
71
71
 
@@ -89,6 +89,8 @@ export interface PreflightProbes {
89
89
  }
90
90
 
91
91
  export interface PreflightOptions {
92
+ /** Reuse only within one run and one CLI resolution environment; failures are cached too. */
93
+ cliProbeCache?: Map<string, CliProbeOutcome>;
92
94
  pluginSearchStart?: string;
93
95
  /** Validated tools.mcp header and nearest flows.json connections. */
94
96
  mcpServers?: readonly string[];
@@ -99,6 +101,7 @@ export interface PreflightOptions {
99
101
  /** Exact, project-owned model allowlist from the nearest flows.json. */
100
102
  models?: readonly string[];
101
103
  modelRegistryPath?: string;
104
+ probeCache?: Map<string, CliProbeOutcome>;
102
105
  probes: PreflightProbes;
103
106
  }
104
107
 
@@ -194,7 +197,12 @@ async function probeMcp(result: PreflightResult, options: PreflightOptions): Pro
194
197
  return { ...result, ok: !result.diagnostics.some(d => d.severity === 'refusal'), mcpTools: Object.freeze(inventory) };
195
198
  }
196
199
 
197
- function preflightSync(flow: unknown, options: PreflightOptions): PreflightResult {
200
+ type ResolutionOptions = Omit<PreflightOptions, 'probes' | 'probeCache'>;
201
+
202
+ /** Resolve static declarations before any CLI, model, command or trigger probe. */
203
+ export function resolvePreflight(flow: unknown, options: ResolutionOptions): PreflightResult & {
204
+ compiled?: import('./compile.js').CompiledFlowSpec;
205
+ } {
198
206
  // Compile before touching any environment fact. `compileSpec` snapshots raw
199
207
  // input into inert data, validates it against the closed authoring schema,
200
208
  // and lowers `output` sugar into its json_schema gate — so the gate plan
@@ -235,7 +243,7 @@ function preflightSync(flow: unknown, options: PreflightOptions): PreflightResul
235
243
  const cliResolutionDiagnostics: PreflightDiagnostic[] = [];
236
244
  const resolutions: CliResolution[] = [];
237
245
  const resolutionByStep = new Map<string, CliResolution>();
238
- const cliProbeResults = new Map<string, CliProbeOutcome>();
246
+ const cliProbeResults = options.cliProbeCache ?? new Map<string, CliProbeOutcome>();
239
247
 
240
248
  // A pure fact about the compiled snapshot, collected before anything that
241
249
  // can return early. An unresolved CLI, an unknown model or a bad scope all
@@ -289,6 +297,18 @@ function preflightSync(flow: unknown, options: PreflightOptions): PreflightResul
289
297
  return { ok: false, gates: compiled.steps.map(inspectStepGate), resolutions, diagnostics };
290
298
  }
291
299
 
300
+ return { ok: true, gates: compiled.steps.map(inspectStepGate), resolutions, diagnostics, compiled };
301
+ }
302
+
303
+ function preflightSync(flow: unknown, options: PreflightOptions): PreflightResult {
304
+ const { compiled, ...result } = resolvePreflight(flow, options);
305
+ if (!result.ok || compiled === undefined) return result;
306
+ const { diagnostics, resolutions } = result;
307
+ const resolutionByStep = new Map(resolutions.map(resolution => [resolution.stepId, resolution]));
308
+ // `cliProbeCache` is the public run-scoped name; `probeCache` is retained as
309
+ // a compatibility alias for the async authored-preflight path.
310
+ const cliProbeResults = options.cliProbeCache ?? options.probeCache ?? new Map<string, CliProbeOutcome>();
311
+
292
312
  for (const step of compiled.steps) {
293
313
  probeNamedGate(step, options.probes, diagnostics);
294
314
  warnOnVacuousGate(step, diagnostics);
@@ -333,7 +353,7 @@ function preflightSync(flow: unknown, options: PreflightOptions): PreflightResul
333
353
  * fact about the filesystem. Missing manifest means no known mounts — a grant
334
354
  * still parses but refuses as `mount_unknown` in that case.
335
355
  */
336
- function scopeDiagnostics(flow: FlowSpec, options: PreflightOptions): PreflightRefusal[] {
356
+ function scopeDiagnostics(flow: FlowSpec, options: ResolutionOptions): PreflightRefusal[] {
337
357
  const workspace = flow.workspace;
338
358
  const toolsFs = flow.tools?.fs;
339
359
  if (workspace === undefined && toolsFs === undefined) return [];
@@ -357,7 +377,7 @@ function scopeDiagnostics(flow: FlowSpec, options: PreflightOptions): PreflightR
357
377
  /** Pure authoring validation: no executable, command, trigger, or daemon probe. */
358
378
  function unknownModelDiagnostics(
359
379
  flow: FlowSpec,
360
- options: PreflightOptions,
380
+ options: ResolutionOptions,
361
381
  resolutionByStep: ReadonlyMap<string, CliResolution> = new Map(),
362
382
  ): PreflightRefusal[] {
363
383
  const diagnostics: PreflightRefusal[] = [];
@@ -471,7 +491,7 @@ function unknownModelMessage(
471
491
  return `Step "${stepId}" declares model "${model}"${cliContext}, but it is not listed in ${source}; add the exact model only after verifying that project is allowed to use it.`;
472
492
  }
473
493
 
474
- function unresolvedCliMessage(stepId: string, options: PreflightOptions): string {
494
+ function unresolvedCliMessage(stepId: string, options: ResolutionOptions): string {
475
495
  const context = options.projectConfigPath !== undefined
476
496
  ? ` Nearest project config "${options.projectConfigPath}" declares no cli; outer configs are shadowed.`
477
497
  : options.projectSearchStart !== undefined
@@ -501,6 +521,10 @@ function resolveCli(
501
521
  return undefined;
502
522
  }
503
523
 
524
+ export function cliProbeKey(resolution: CliResolution, managed = false): string {
525
+ return JSON.stringify([resolution.cli, resolution.source, resolution.model ?? null, managed]);
526
+ }
527
+
504
528
  function probeResolvedCli(
505
529
  resolution: CliResolution,
506
530
  probes: PreflightProbes,
@@ -514,7 +538,7 @@ function probeResolvedCli(
514
538
  // Model is part of the key: the same CLI probed with two different models
515
539
  // is two different questions, and caching on the CLI alone would let a
516
540
  // model that the CLI cannot resolve inherit an earlier model's pass.
517
- const cacheKey = JSON.stringify([resolution.cli, resolution.source, resolution.model ?? null, managed]);
541
+ const cacheKey = cliProbeKey(resolution, managed);
518
542
  let outcome = cache.get(cacheKey);
519
543
  if (outcome === undefined) {
520
544
  try {
package/src/relay-cli.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { readFileSync } from 'node:fs';
2
-
3
1
  import { runCli } from './cli.js';
4
2
  import { CLI_VERBS, CLI_VERB_NAMES, type CliCommandSpec } from './cli-commands.js';
3
+ import { packageVersion } from './package-version.js';
5
4
 
6
5
  /**
7
6
  * The `@relayflows/sdk/relay-cli` entrypoint: a mountable CLI surface.
@@ -56,28 +55,6 @@ function toCommandSpec(verb: CliCommandSpec & { variants?: unknown }): CliComman
56
55
  return spec;
57
56
  }
58
57
 
59
- /**
60
- * Read this package's version from its own manifest.
61
- *
62
- * Resolved from `import.meta.url` rather than imported, because `package.json`
63
- * sits outside `rootDir` and a hardcoded literal would silently go stale at the
64
- * next release. `src/` and `dist/` are both one level below the manifest, so
65
- * the same relative path is correct before and after a build.
66
- */
67
- function packageVersion(): string {
68
- try {
69
- const manifest: unknown = JSON.parse(
70
- readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
71
- );
72
- const version = (manifest as { version?: unknown }).version;
73
- return typeof version === 'string' && version.length > 0 ? version : '0.0.0';
74
- } catch {
75
- // A surface that cannot read its own manifest is still perfectly runnable;
76
- // refusing to mount over a cosmetic field would be the worse failure.
77
- return '0.0.0';
78
- }
79
- }
80
-
81
58
  /**
82
59
  * Build the relayflows CLI surface.
83
60
  *