@relayflows/sdk 2.0.17 → 2.0.19

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 (161) hide show
  1. package/dist/authored-flow-error.d.ts +21 -1
  2. package/dist/authored-flow-error.d.ts.map +1 -1
  3. package/dist/authored-flow-error.js +14 -0
  4. package/dist/authored-flow-error.js.map +1 -1
  5. package/dist/authored-flow-executor.d.ts.map +1 -1
  6. package/dist/authored-flow-executor.js +47 -3
  7. package/dist/authored-flow-executor.js.map +1 -1
  8. package/dist/authored-human.d.ts +49 -0
  9. package/dist/authored-human.d.ts.map +1 -0
  10. package/dist/authored-human.js +97 -0
  11. package/dist/authored-human.js.map +1 -0
  12. package/dist/authored-node-entry.js +3 -2
  13. package/dist/authored-node-entry.js.map +1 -1
  14. package/dist/authored-node-runner.d.ts.map +1 -1
  15. package/dist/authored-node-runner.js +15 -4
  16. package/dist/authored-node-runner.js.map +1 -1
  17. package/dist/authored-root.d.ts.map +1 -1
  18. package/dist/authored-root.js +29 -1
  19. package/dist/authored-root.js.map +1 -1
  20. package/dist/cli/answer.d.ts +17 -0
  21. package/dist/cli/answer.d.ts.map +1 -0
  22. package/dist/cli/answer.js +89 -0
  23. package/dist/cli/answer.js.map +1 -0
  24. package/dist/cli/build.d.ts +9 -0
  25. package/dist/cli/build.d.ts.map +1 -1
  26. package/dist/cli/build.js +26 -7
  27. package/dist/cli/build.js.map +1 -1
  28. package/dist/cli/check-triggers.d.ts.map +1 -1
  29. package/dist/cli/check-triggers.js +2 -0
  30. package/dist/cli/check-triggers.js.map +1 -1
  31. package/dist/cli/check.d.ts +11 -0
  32. package/dist/cli/check.d.ts.map +1 -1
  33. package/dist/cli/check.js +14 -2
  34. package/dist/cli/check.js.map +1 -1
  35. package/dist/cli/cloud-connect-cli.d.ts +54 -0
  36. package/dist/cli/cloud-connect-cli.d.ts.map +1 -0
  37. package/dist/cli/cloud-connect-cli.js +109 -0
  38. package/dist/cli/cloud-connect-cli.js.map +1 -0
  39. package/dist/cli/cloud-deploy.d.ts +3 -1
  40. package/dist/cli/cloud-deploy.d.ts.map +1 -1
  41. package/dist/cli/cloud-deploy.js +44 -6
  42. package/dist/cli/cloud-deploy.js.map +1 -1
  43. package/dist/cli/cloud-run.d.ts +9 -2
  44. package/dist/cli/cloud-run.d.ts.map +1 -1
  45. package/dist/cli/cloud-run.js +27 -15
  46. package/dist/cli/cloud-run.js.map +1 -1
  47. package/dist/cli/cloud-schedule.d.ts +3 -1
  48. package/dist/cli/cloud-schedule.d.ts.map +1 -1
  49. package/dist/cli/cloud-schedule.js +31 -6
  50. package/dist/cli/cloud-schedule.js.map +1 -1
  51. package/dist/cli/cloud-sync.d.ts +8 -1
  52. package/dist/cli/cloud-sync.d.ts.map +1 -1
  53. package/dist/cli/cloud-sync.js +79 -8
  54. package/dist/cli/cloud-sync.js.map +1 -1
  55. package/dist/cli/deploy.d.ts +6 -0
  56. package/dist/cli/deploy.d.ts.map +1 -1
  57. package/dist/cli/deploy.js +29 -4
  58. package/dist/cli/deploy.js.map +1 -1
  59. package/dist/cli/direct-run.d.ts.map +1 -1
  60. package/dist/cli/direct-run.js +5 -1
  61. package/dist/cli/direct-run.js.map +1 -1
  62. package/dist/cli/run.d.ts +22 -2
  63. package/dist/cli/run.d.ts.map +1 -1
  64. package/dist/cli/run.js +34 -1
  65. package/dist/cli/run.js.map +1 -1
  66. package/dist/cli/serve-webhook.d.ts +7 -1
  67. package/dist/cli/serve-webhook.d.ts.map +1 -1
  68. package/dist/cli/serve-webhook.js +19 -9
  69. package/dist/cli/serve-webhook.js.map +1 -1
  70. package/dist/cli-commands.d.ts +398 -0
  71. package/dist/cli-commands.d.ts.map +1 -0
  72. package/dist/cli-commands.js +254 -0
  73. package/dist/cli-commands.js.map +1 -0
  74. package/dist/cli-watch.d.ts +3 -1
  75. package/dist/cli-watch.d.ts.map +1 -1
  76. package/dist/cli-watch.js +4 -10
  77. package/dist/cli-watch.js.map +1 -1
  78. package/dist/cli.d.ts +127 -1
  79. package/dist/cli.d.ts.map +1 -1
  80. package/dist/cli.js +195 -57
  81. package/dist/cli.js.map +1 -1
  82. package/dist/cloud-connect.d.ts +52 -0
  83. package/dist/cloud-connect.d.ts.map +1 -0
  84. package/dist/cloud-connect.js +138 -0
  85. package/dist/cloud-connect.js.map +1 -0
  86. package/dist/cloud-deploy.d.ts +19 -1
  87. package/dist/cloud-deploy.d.ts.map +1 -1
  88. package/dist/cloud-deploy.js +40 -1
  89. package/dist/cloud-deploy.js.map +1 -1
  90. package/dist/cloud-http.d.ts +2 -2
  91. package/dist/cloud-http.d.ts.map +1 -1
  92. package/dist/cloud-http.js.map +1 -1
  93. package/dist/cloud-schedule.d.ts +7 -0
  94. package/dist/cloud-schedule.d.ts.map +1 -1
  95. package/dist/cloud-schedule.js +22 -1
  96. package/dist/cloud-schedule.js.map +1 -1
  97. package/dist/cloud-sync.d.ts +85 -2
  98. package/dist/cloud-sync.d.ts.map +1 -1
  99. package/dist/cloud-sync.js +123 -10
  100. package/dist/cloud-sync.js.map +1 -1
  101. package/dist/failure-kinds.d.ts +1 -1
  102. package/dist/failure-kinds.d.ts.map +1 -1
  103. package/dist/failure-kinds.js +2 -0
  104. package/dist/failure-kinds.js.map +1 -1
  105. package/dist/flow-requirements.d.ts +68 -0
  106. package/dist/flow-requirements.d.ts.map +1 -0
  107. package/dist/flow-requirements.js +152 -0
  108. package/dist/flow-requirements.js.map +1 -0
  109. package/dist/index.d.ts +3 -1
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +3 -1
  112. package/dist/index.js.map +1 -1
  113. package/dist/journal-client.d.ts +11 -0
  114. package/dist/journal-client.d.ts.map +1 -1
  115. package/dist/journal-client.js +13 -0
  116. package/dist/journal-client.js.map +1 -1
  117. package/dist/progress.d.ts +2 -1
  118. package/dist/progress.d.ts.map +1 -1
  119. package/dist/progress.js +9 -3
  120. package/dist/progress.js.map +1 -1
  121. package/dist/protocol.d.ts +25 -1
  122. package/dist/protocol.d.ts.map +1 -1
  123. package/dist/relay-cli.d.ts +50 -0
  124. package/dist/relay-cli.d.ts.map +1 -0
  125. package/dist/relay-cli.js +64 -0
  126. package/dist/relay-cli.js.map +1 -0
  127. package/package.json +7 -2
  128. package/src/authored-flow-error.ts +29 -0
  129. package/src/authored-flow-executor.ts +54 -2
  130. package/src/authored-human.ts +150 -0
  131. package/src/authored-node-entry.ts +3 -2
  132. package/src/authored-node-runner.ts +20 -5
  133. package/src/authored-root.ts +28 -1
  134. package/src/cli/answer.ts +98 -0
  135. package/src/cli/build.ts +21 -7
  136. package/src/cli/check-triggers.ts +2 -0
  137. package/src/cli/check.ts +24 -2
  138. package/src/cli/cloud-connect-cli.ts +130 -0
  139. package/src/cli/cloud-deploy.ts +40 -6
  140. package/src/cli/cloud-run.ts +26 -15
  141. package/src/cli/cloud-schedule.ts +31 -6
  142. package/src/cli/cloud-sync.ts +85 -8
  143. package/src/cli/deploy.ts +27 -5
  144. package/src/cli/direct-run.ts +5 -0
  145. package/src/cli/run.ts +48 -2
  146. package/src/cli/serve-webhook.ts +15 -8
  147. package/src/cli-commands.ts +339 -0
  148. package/src/cli-watch.ts +8 -9
  149. package/src/cli.ts +206 -54
  150. package/src/cloud-connect.ts +187 -0
  151. package/src/cloud-deploy.ts +57 -2
  152. package/src/cloud-http.ts +1 -1
  153. package/src/cloud-schedule.ts +20 -3
  154. package/src/cloud-sync.ts +164 -11
  155. package/src/failure-kinds.ts +2 -0
  156. package/src/flow-requirements.ts +201 -0
  157. package/src/index.ts +12 -2
  158. package/src/journal-client.ts +20 -0
  159. package/src/progress.ts +11 -4
  160. package/src/protocol.ts +23 -0
  161. package/src/relay-cli.ts +117 -0
package/src/progress.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type { CompletionReason } from './protocol.js';
2
2
  import type { StepType } from './spec.js';
3
+ import { AuthoredHumanParked } from './authored-flow-error.js';
3
4
 
4
5
  export interface ProgressEvent {
5
- type: 'step.started' | 'step.running' | 'step.completed' | 'step.failed';
6
+ /** `step.parked`: an `f.human` reached without an answer; the run parks, nothing failed. */
7
+ type: 'step.started' | 'step.running' | 'step.completed' | 'step.failed' | 'step.parked';
6
8
  stepId: string;
7
9
  stepType: StepType;
8
10
  elapsedMs: number;
@@ -12,13 +14,15 @@ export interface ProgressEvent {
12
14
  /** Pure terminal rendering: caller owns the event source, clock, and output. */
13
15
  export function renderProgress(events: Iterable<ProgressEvent>): string[] {
14
16
  return Array.from(events, event => {
15
- const icon = { 'step.started': '○', 'step.running': '↻', 'step.completed': '✓', 'step.failed': '✗' }[event.type];
17
+ const icon = { 'step.started': '○', 'step.running': '↻', 'step.completed': '✓', 'step.failed': '✗', 'step.parked': '⏸' }[event.type];
16
18
  const state = event.type.slice('step.'.length);
19
+ // A parked `f.human` is a question, not a step type the kernel ran.
20
+ const kind = event.type === 'step.parked' ? 'human' : event.stepType;
17
21
  const agent = event.stepType === 'agent' ? ` [agent: ${state === 'started' ? 'preparing' : state}]` : '';
18
22
  const reason = event.completionReason ? ` completionReason: ${event.completionReason}` : '';
19
23
  // Agent-authored names cannot inject terminal control sequences.
20
24
  const name = event.stepId.replace(/[\x00-\x1f\x7f-\x9f]/g, '?');
21
- return `${icon} ${name} (${event.stepType})${agent} ${(Math.max(0, event.elapsedMs) / 1000).toFixed(2)}s${reason}`;
25
+ return `${icon} ${name} (${kind})${agent} ${(Math.max(0, event.elapsedMs) / 1000).toFixed(2)}s${reason}`;
22
26
  });
23
27
  }
24
28
 
@@ -45,7 +49,10 @@ export async function observeStep<T>(
45
49
  publish({ type: 'step.completed', stepId, stepType, elapsedMs: performance.now() - started, completionReason: 'success' });
46
50
  return result;
47
51
  } catch (error) {
48
- publish({ type: 'step.failed', stepId, stepType, elapsedMs: performance.now() - started });
52
+ publish({
53
+ type: error instanceof AuthoredHumanParked ? 'step.parked' : 'step.failed',
54
+ stepId, stepType, elapsedMs: performance.now() - started,
55
+ });
49
56
  throw error;
50
57
  }
51
58
  }
package/src/protocol.ts CHANGED
@@ -52,6 +52,7 @@ export type Verb =
52
52
  | 'effect.record'
53
53
  | 'effect.confirm'
54
54
  | 'step.complete'
55
+ | 'step.wait'
55
56
  | 'event.emit'
56
57
  | 'event.submit'
57
58
  | 'stream.append'
@@ -329,6 +330,27 @@ export interface StepCompleteParams {
329
330
  }
330
331
  export type StepCompleteResult = RunOutcome;
331
332
 
333
+ /**
334
+ * Park a leased attempt on a durable human question (`wait.human`, kernel
335
+ * DESIGN.md §1.5). The attempt is not completed and no iteration is charged;
336
+ * the lease is released once the wait is journaled. The answer arrives through
337
+ * `event.emit` with `event_key` = `wait_id`, which closes the wait as
338
+ * `human_responded` and makes the step runnable for a fresh attempt.
339
+ */
340
+ export interface StepWaitParams {
341
+ run_id: string;
342
+ step_id: string;
343
+ attempt: number;
344
+ idempotency_key: string;
345
+ /** Names the question for the life of the run; the kernel refuses a reuse. */
346
+ wait_id: string;
347
+ prompt: string;
348
+ requested_of: string;
349
+ options?: string[];
350
+ timeout_at_ms?: number;
351
+ }
352
+ export type StepWaitResult = RunOutcome;
353
+
332
354
  export interface EventEmitParams {
333
355
  run_id: string;
334
356
  event_key: string;
@@ -401,6 +423,7 @@ export interface VerbContract {
401
423
  'effect.record': { params: EffectRecordParams; result: EffectRecordResult };
402
424
  'effect.confirm': { params: EffectConfirmParams; result: EffectConfirmResult };
403
425
  'step.complete': { params: StepCompleteParams; result: StepCompleteResult };
426
+ 'step.wait': { params: StepWaitParams; result: StepWaitResult };
404
427
  'event.emit': { params: EventEmitParams; result: EventEmitResult };
405
428
  'event.submit': { params: EventSubmitParams; result: EventSubmitResult };
406
429
  'stream.append': { params: StreamAppendParams; result: StreamAppendResult };
@@ -0,0 +1,117 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ import { runCli } from './cli.js';
4
+ import { CLI_VERBS, CLI_VERB_NAMES, type CliCommandSpec } from './cli-commands.js';
5
+
6
+ /**
7
+ * The `@relayflows/sdk/relay-cli` entrypoint: a mountable CLI surface.
8
+ *
9
+ * `agent-relay` mounts this as `agent-relay flows`. The surface is a thin
10
+ * projection over the CLI this package already ships -- `commands` comes from
11
+ * the same `CLI_VERBS` table `parseArgs` dispatches on, and `run` delegates
12
+ * straight to `runCli`. No command is reimplemented here, and
13
+ * `packages/relayflows/bin/flows.js` keeps calling `runCli` on the same path.
14
+ *
15
+ * Structurally typed against `@agent-relay/cli-surface` without importing it,
16
+ * so `dist/relay-cli.d.ts` has no dependency on the contract package and this
17
+ * package gains no runtime dependency on relay. `tests/relay-cli-surface.test.ts`
18
+ * asserts the assignability and runs the contract's own conformance checks.
19
+ */
20
+
21
+ /** Host-supplied output sink. Mirrors `RelayCliIo`. */
22
+ export interface RelayCliIo {
23
+ stdout(chunk: string): void;
24
+ stderr(chunk: string): void;
25
+ }
26
+
27
+ /** A mountable product CLI. Mirrors `RelayCliSurface`. */
28
+ export interface RelayCliSurface {
29
+ id: string;
30
+ version: string;
31
+ contract: 1;
32
+ commands: readonly CliCommandSpec[];
33
+ run(argv: readonly string[], io: RelayCliIo): Promise<number>;
34
+ }
35
+
36
+ /** Options for {@link createRelayCliSurface}. */
37
+ export interface CreateRelayCliSurfaceOptions {
38
+ /**
39
+ * Cancellation for the long-running verbs, owned by the host.
40
+ *
41
+ * A surface must install no global signal handlers, so one is always passed
42
+ * to `runCli` -- a never-aborting signal when the host supplies none. Pass a
43
+ * real one to get graceful cancellation (for example, the
44
+ * "Stopped observing; the hosted run has not been cancelled" path on
45
+ * `run --cloud --wait`) instead of the host's SIGINT killing the process.
46
+ */
47
+ signal?: AbortSignal;
48
+ }
49
+
50
+ /** Exit code for an argv the surface cannot route, per the contract. */
51
+ const EXIT_UNKNOWN_COMMAND = 2;
52
+
53
+ /** Drop `variants` -- the routing detail the host has no use for. */
54
+ function toCommandSpec(verb: CliCommandSpec & { variants?: unknown }): CliCommandSpec {
55
+ const { variants: _variants, ...spec } = verb;
56
+ return spec;
57
+ }
58
+
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
+ /**
82
+ * Build the relayflows CLI surface.
83
+ *
84
+ * @param options - Host-supplied cancellation.
85
+ * @returns A surface whose `run` resolves to an exit code, writes only through
86
+ * the supplied io, and installs no process signal handlers.
87
+ */
88
+ export function createRelayCliSurface(
89
+ options: CreateRelayCliSurfaceOptions = {},
90
+ ): RelayCliSurface {
91
+ return {
92
+ id: 'relayflows',
93
+ version: packageVersion(),
94
+ contract: 1,
95
+ commands: CLI_VERBS.map(toCommandSpec),
96
+ async run(argv: readonly string[], io: RelayCliIo): Promise<number> {
97
+ const verb = argv[0];
98
+ // `runCli` would refuse this too, but with the full usage block. Naming
99
+ // the offending token is the more useful answer when the host has just
100
+ // routed `agent-relay flows <typo>` here.
101
+ if (verb !== undefined && !verb.startsWith('-') && !CLI_VERB_NAMES.has(verb)) {
102
+ io.stderr(`error: '${verb}' is not a command of relayflows\n`);
103
+ io.stderr("Run 'agent-relay flows --help' for the available commands.\n");
104
+ return EXIT_UNKNOWN_COMMAND;
105
+ }
106
+ return runCli(
107
+ argv,
108
+ // `CliIo` is line-oriented and the contract's io is chunk-oriented, so
109
+ // the terminator is added here rather than by every call site.
110
+ { stdout: (line) => io.stdout(`${line}\n`), stderr: (line) => io.stderr(`${line}\n`) },
111
+ // Always pass a signal: that is what keeps `runCli` from installing the
112
+ // SIGINT/SIGTERM handlers the standalone binary still relies on.
113
+ { signal: options.signal ?? new AbortController().signal },
114
+ );
115
+ },
116
+ };
117
+ }