@relayflows/sdk 2.0.1 → 2.0.3

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 (72) hide show
  1. package/dist/cli/daemon-refusal.d.ts +12 -0
  2. package/dist/cli/daemon-refusal.d.ts.map +1 -0
  3. package/dist/cli/daemon-refusal.js +42 -0
  4. package/dist/cli/daemon-refusal.js.map +1 -0
  5. package/dist/cli/direct-run.d.ts +1 -1
  6. package/dist/cli/direct-run.d.ts.map +1 -1
  7. package/dist/cli/direct-run.js +2 -2
  8. package/dist/cli/direct-run.js.map +1 -1
  9. package/dist/cli/run.d.ts +26 -4
  10. package/dist/cli/run.d.ts.map +1 -1
  11. package/dist/cli/run.js +51 -6
  12. package/dist/cli/run.js.map +1 -1
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +39 -8
  15. package/dist/cli.js.map +1 -1
  16. package/dist/compile.d.ts.map +1 -1
  17. package/dist/compile.js +35 -4
  18. package/dist/compile.js.map +1 -1
  19. package/dist/daemon-connection.d.ts +127 -0
  20. package/dist/daemon-connection.d.ts.map +1 -0
  21. package/dist/daemon-connection.js +249 -0
  22. package/dist/daemon-connection.js.map +1 -0
  23. package/dist/daemon-lifecycle.d.ts +29 -0
  24. package/dist/daemon-lifecycle.d.ts.map +1 -0
  25. package/dist/daemon-lifecycle.js +152 -0
  26. package/dist/daemon-lifecycle.js.map +1 -0
  27. package/dist/failure-kinds.d.ts +19 -2
  28. package/dist/failure-kinds.d.ts.map +1 -1
  29. package/dist/failure-kinds.js +23 -1
  30. package/dist/failure-kinds.js.map +1 -1
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/journal-client.d.ts +12 -0
  35. package/dist/journal-client.d.ts.map +1 -1
  36. package/dist/journal-client.js +10 -0
  37. package/dist/journal-client.js.map +1 -1
  38. package/dist/protocol.d.ts +21 -1
  39. package/dist/protocol.d.ts.map +1 -1
  40. package/dist/relayflowd-path.d.ts +39 -0
  41. package/dist/relayflowd-path.d.ts.map +1 -0
  42. package/dist/relayflowd-path.js +162 -0
  43. package/dist/relayflowd-path.js.map +1 -0
  44. package/dist/spec.d.ts +30 -2
  45. package/dist/spec.d.ts.map +1 -1
  46. package/dist/spec.js.map +1 -1
  47. package/dist/step-fields.d.ts +1 -1
  48. package/dist/step-fields.d.ts.map +1 -1
  49. package/dist/step-fields.js +2 -0
  50. package/dist/step-fields.js.map +1 -1
  51. package/dist/validate.d.ts.map +1 -1
  52. package/dist/validate.js +53 -6
  53. package/dist/validate.js.map +1 -1
  54. package/dist/worker.js +6 -1
  55. package/dist/worker.js.map +1 -1
  56. package/package.json +2 -2
  57. package/src/cli/daemon-refusal.ts +49 -0
  58. package/src/cli/direct-run.ts +2 -2
  59. package/src/cli/run.ts +62 -9
  60. package/src/cli.ts +42 -15
  61. package/src/compile.ts +37 -4
  62. package/src/daemon-connection.ts +336 -0
  63. package/src/daemon-lifecycle.ts +198 -0
  64. package/src/failure-kinds.ts +25 -1
  65. package/src/index.ts +6 -0
  66. package/src/journal-client.ts +21 -0
  67. package/src/protocol.ts +19 -1
  68. package/src/relayflowd-path.ts +190 -0
  69. package/src/spec.ts +34 -2
  70. package/src/step-fields.ts +2 -0
  71. package/src/validate.ts +50 -6
  72. package/src/worker.ts +7 -1
package/src/validate.ts CHANGED
@@ -203,28 +203,69 @@ class Validator {
203
203
  }
204
204
  }
205
205
 
206
- private validateBudget(b: unknown): void {
206
+ private validateBudget(b: unknown, at = 'spec.budget'): void {
207
207
  if (!isObject(b)) {
208
- this.fail('spec.budget: expected an object');
208
+ this.fail(`${at}: expected an object`);
209
209
  return;
210
210
  }
211
- this.checkKeys(b, BUDGET_KEYS, 'spec.budget');
211
+ this.checkKeys(b, BUDGET_KEYS, at);
212
212
  const budget = b as BudgetSpec;
213
213
  if (
214
214
  budget.maxTokensIn !== undefined &&
215
215
  !isNonNegInt(budget.maxTokensIn)
216
216
  ) {
217
- this.fail('spec.budget.maxTokensIn: expected a non-negative integer');
217
+ this.fail(`${at}.maxTokensIn: expected a non-negative integer`);
218
218
  }
219
219
  if (
220
220
  budget.maxTokensOut !== undefined &&
221
221
  !isNonNegInt(budget.maxTokensOut)
222
222
  ) {
223
- this.fail('spec.budget.maxTokensOut: expected a non-negative integer');
223
+ this.fail(`${at}.maxTokensOut: expected a non-negative integer`);
224
224
  }
225
225
  if (budget.maxDollars !== undefined) {
226
226
  if (typeof budget.maxDollars !== 'string' || !DECIMAL_RE.test(budget.maxDollars)) {
227
- this.fail('spec.budget.maxDollars: expected a decimal string, e.g. "1.50"');
227
+ this.fail(`${at}.maxDollars: expected a decimal string, e.g. "1.50"`);
228
+ }
229
+ }
230
+ }
231
+
232
+ private validateRequirements(value: unknown, at: string): void {
233
+ if (!isObject(value)) { this.fail(`${at}: expected an object`); return; }
234
+ this.checkKeys(value, ['execution', 'workspace', 'network', 'expectedDurationMs', 'preference'], at);
235
+ for (const field of ['workspace', 'network']) {
236
+ if (value[field] !== undefined && typeof value[field] !== 'boolean') this.fail(`${at}.${field}: expected a boolean`);
237
+ }
238
+ if (value['execution'] !== undefined && !['batch', 'interactive'].includes(value['execution'] as string)) {
239
+ this.fail(`${at}.execution: expected batch | interactive`);
240
+ }
241
+ if (value['preference'] !== undefined && !['cost', 'latency', 'reliability', 'balanced'].includes(value['preference'] as string)) {
242
+ this.fail(`${at}.preference: expected cost | latency | reliability | balanced`);
243
+ }
244
+ if (value['expectedDurationMs'] !== undefined &&
245
+ (!Number.isSafeInteger(value['expectedDurationMs']) || (value['expectedDurationMs'] as number) <= 0)) {
246
+ this.fail(`${at}.expectedDurationMs: expected a positive safe integer`);
247
+ }
248
+ }
249
+
250
+ private validateMemory(value: unknown, at: string): void {
251
+ if (!isObject(value)) {
252
+ this.fail(`${at}: expected an object`);
253
+ return;
254
+ }
255
+ this.checkKeys(value, ['scope', 'query', 'budget'], at);
256
+ if (value['scope'] !== 'script' && value['scope'] !== 'agent') {
257
+ this.fail(`${at}.scope: expected script | agent`);
258
+ }
259
+ if (typeof value['query'] !== 'string' || value['query'].trim().length === 0) {
260
+ this.fail(`${at}.query: expected a non-empty string`);
261
+ }
262
+ this.validateBudget(value['budget'], `${at}.budget`);
263
+ if (isObject(value['budget'])) {
264
+ for (const key of ['maxTokensIn', 'maxTokensOut']) {
265
+ const limit = value['budget'][key];
266
+ if (limit !== undefined && !Number.isSafeInteger(limit)) {
267
+ this.fail(`${at}.budget.${key}: expected a safe integer`);
268
+ }
228
269
  }
229
270
  }
230
271
  }
@@ -305,6 +346,9 @@ class Validator {
305
346
  const type = st['type'] as StepType;
306
347
  this.checkKeys(st, [...STEP_COMMON_FIELDS, ...STEP_FIELDS_BY_TYPE[type]], at);
307
348
 
349
+ if (st['requirements'] !== undefined) this.validateRequirements(st['requirements'], `${at}.requirements`);
350
+ if (st['memory'] !== undefined) this.validateMemory(st['memory'], `${at}.memory`);
351
+
308
352
  if (st['dependsOn'] !== undefined) {
309
353
  if (!Array.isArray(st['dependsOn']) || !(st['dependsOn'] as unknown[]).every(isNonEmptyString)) {
310
354
  this.fail(`${at}.dependsOn: expected an array of step ids`);
package/src/worker.ts CHANGED
@@ -91,7 +91,7 @@ export class AgentWorker extends EventEmitter {
91
91
  private async execute(dispatch: StepDispatchEvent): Promise<void> {
92
92
  const spec = dispatch.spec as Partial<KernelAgentStep>;
93
93
  const result = typeof spec.cli === 'string' && typeof spec.instruction === 'string'
94
- ? await runAgentCli(spec.cli, spec.instruction, dispatch.wake_context, spec.model)
94
+ ? await runAgentCli(spec.cli, memoryInstruction(spec.instruction, dispatch.memory), dispatch.wake_context, spec.model)
95
95
  : { exit_code: null, stdout_tail: '', stderr_tail: 'agent step has no declared CLI' };
96
96
  const completionReason = result.exit_code === 0 ? 'success' : 'worker_error';
97
97
 
@@ -148,3 +148,9 @@ export function parseJsonOutput(stdout: string): Record<string, unknown> | null
148
148
  }
149
149
  return parsed as Record<string, unknown>;
150
150
  }
151
+
152
+ /** Pass the journaled pack to both raw CLI and wrapper execution paths. */
153
+ function memoryInstruction(instruction: string, memory: StepDispatchEvent['memory']): string {
154
+ return memory === undefined ? instruction
155
+ : `${instruction}\n\nMemory context (journaled):\n${JSON.stringify(memory.pack)}`;
156
+ }