@nyxa/automation 0.1.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.
Files changed (48) hide show
  1. package/README.md +559 -0
  2. package/dist/cancellation.d.ts +1 -0
  3. package/dist/cancellation.js +5 -0
  4. package/dist/claude-code.d.ts +19 -0
  5. package/dist/claude-code.js +182 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +487 -0
  8. package/dist/codex-output.d.ts +6 -0
  9. package/dist/codex-output.js +167 -0
  10. package/dist/codex.d.ts +17 -0
  11. package/dist/codex.js +228 -0
  12. package/dist/doctor.d.ts +17 -0
  13. package/dist/doctor.js +138 -0
  14. package/dist/errors.d.ts +30 -0
  15. package/dist/errors.js +51 -0
  16. package/dist/events.d.ts +55 -0
  17. package/dist/events.js +51 -0
  18. package/dist/filesystem.d.ts +2 -0
  19. package/dist/filesystem.js +13 -0
  20. package/dist/harness-process.d.ts +39 -0
  21. package/dist/harness-process.js +359 -0
  22. package/dist/harness-prompt.d.ts +2 -0
  23. package/dist/harness-prompt.js +14 -0
  24. package/dist/harness.d.ts +44 -0
  25. package/dist/harness.js +68 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +9 -0
  28. package/dist/init.d.ts +1 -0
  29. package/dist/init.js +305 -0
  30. package/dist/json.d.ts +4 -0
  31. package/dist/json.js +1 -0
  32. package/dist/kimi-code.d.ts +16 -0
  33. package/dist/kimi-code.js +299 -0
  34. package/dist/opencode.d.ts +15 -0
  35. package/dist/opencode.js +164 -0
  36. package/dist/run-coordination.d.ts +10 -0
  37. package/dist/run-coordination.js +96 -0
  38. package/dist/run-journal.d.ts +14 -0
  39. package/dist/run-journal.js +129 -0
  40. package/dist/schema.d.ts +167 -0
  41. package/dist/schema.js +516 -0
  42. package/dist/standard-input.d.ts +1 -0
  43. package/dist/standard-input.js +7 -0
  44. package/dist/type-utils.d.ts +1 -0
  45. package/dist/type-utils.js +1 -0
  46. package/dist/workflow.d.ts +160 -0
  47. package/dist/workflow.js +530 -0
  48. package/package.json +51 -0
package/dist/schema.js ADDED
@@ -0,0 +1,516 @@
1
+ const schemaOutput = Symbol.for("@nyxa/automation/schema-output");
2
+ const schemaOptional = Symbol.for("@nyxa/automation/schema-optional");
3
+ const schemaParser = Symbol.for("@nyxa/automation/schema-parser");
4
+ const schemaJson = Symbol.for("@nyxa/automation/schema-json");
5
+ export class SchemaValidationError extends Error {
6
+ issues;
7
+ constructor(issues) {
8
+ super("Schema validation failed.");
9
+ this.name = "SchemaValidationError";
10
+ this.issues = Object.freeze([...issues]);
11
+ }
12
+ }
13
+ class BaseSchema {
14
+ [schemaOptional];
15
+ #description;
16
+ constructor(optional, description) {
17
+ this[schemaOptional] = optional;
18
+ this.#description = description;
19
+ }
20
+ get description() {
21
+ return this.#description;
22
+ }
23
+ parse(value) {
24
+ const result = this[schemaParser](value, []);
25
+ if (result.issues.length > 0) {
26
+ throw new SchemaValidationError(result.issues);
27
+ }
28
+ return result.value;
29
+ }
30
+ safeParse(value) {
31
+ const result = this[schemaParser](value, []);
32
+ return result.issues.length === 0
33
+ ? { success: true, data: result.value }
34
+ : { success: false, error: new SchemaValidationError(result.issues) };
35
+ }
36
+ describe(description) {
37
+ if (description.length === 0) {
38
+ throw new TypeError("A schema description cannot be empty.");
39
+ }
40
+ return this.cloneWithDescription(description);
41
+ }
42
+ nullable() {
43
+ return new NullableSchema(this, this[schemaOptional]);
44
+ }
45
+ optional() {
46
+ if (this[schemaOptional]) {
47
+ return this;
48
+ }
49
+ return new OptionalSchema(this);
50
+ }
51
+ toJSONSchema() {
52
+ const jsonSchema = this[schemaJson]();
53
+ return this.#description === undefined
54
+ ? jsonSchema
55
+ : { ...jsonSchema, description: this.#description };
56
+ }
57
+ }
58
+ export class StringSchema extends BaseSchema {
59
+ #constraints;
60
+ constructor(constraints = {
61
+ maximumLength: undefined,
62
+ minimumLength: undefined,
63
+ pattern: undefined,
64
+ }, description) {
65
+ super(false, description);
66
+ this.#constraints = constraints;
67
+ }
68
+ minLength(minimumLength) {
69
+ assertNonNegativeInteger(minimumLength, "minimum length");
70
+ return new StringSchema({ ...this.#constraints, minimumLength }, this.description);
71
+ }
72
+ maxLength(maximumLength) {
73
+ assertNonNegativeInteger(maximumLength, "maximum length");
74
+ return new StringSchema({ ...this.#constraints, maximumLength }, this.description);
75
+ }
76
+ pattern(pattern) {
77
+ new RegExp(pattern);
78
+ return new StringSchema({ ...this.#constraints, pattern }, this.description);
79
+ }
80
+ cloneWithDescription(description) {
81
+ return new StringSchema(this.#constraints, description);
82
+ }
83
+ [schemaParser](value, path) {
84
+ if (typeof value !== "string") {
85
+ return { issues: [invalidTypeIssue(path, "string", value)] };
86
+ }
87
+ const issues = [];
88
+ const length = [...value].length;
89
+ const { maximumLength, minimumLength, pattern } = this.#constraints;
90
+ if (minimumLength !== undefined && length < minimumLength) {
91
+ issues.push(tooSmallIssue(path, `String must contain at least ${minimumLength} characters.`, minimumLength));
92
+ }
93
+ if (maximumLength !== undefined && length > maximumLength) {
94
+ issues.push(tooBigIssue(path, `String must contain at most ${maximumLength} characters.`, maximumLength));
95
+ }
96
+ if (pattern !== undefined && !new RegExp(pattern).test(value)) {
97
+ issues.push({
98
+ code: "invalid_string",
99
+ path,
100
+ message: `String must match pattern ${pattern}.`,
101
+ pattern,
102
+ });
103
+ }
104
+ return { value, issues };
105
+ }
106
+ [schemaJson]() {
107
+ const { maximumLength, minimumLength, pattern } = this.#constraints;
108
+ return compactJsonSchema({
109
+ type: "string",
110
+ minLength: minimumLength,
111
+ maxLength: maximumLength,
112
+ pattern,
113
+ });
114
+ }
115
+ }
116
+ export class NumberSchema extends BaseSchema {
117
+ #constraints;
118
+ constructor(integer = false, constraints = {
119
+ maximum: undefined,
120
+ minimum: undefined,
121
+ }, description) {
122
+ super(false, description);
123
+ this.#constraints = { ...constraints, integer };
124
+ }
125
+ minimum(minimum) {
126
+ assertFiniteNumber(minimum, "minimum");
127
+ return new NumberSchema(this.#constraints.integer, {
128
+ maximum: this.#constraints.maximum,
129
+ minimum,
130
+ }, this.description);
131
+ }
132
+ maximum(maximum) {
133
+ assertFiniteNumber(maximum, "maximum");
134
+ return new NumberSchema(this.#constraints.integer, {
135
+ maximum,
136
+ minimum: this.#constraints.minimum,
137
+ }, this.description);
138
+ }
139
+ cloneWithDescription(description) {
140
+ return new NumberSchema(this.#constraints.integer, this.#constraints, description);
141
+ }
142
+ [schemaParser](value, path) {
143
+ const expected = this.#constraints.integer ? "integer" : "number";
144
+ if (typeof value !== "number" ||
145
+ !Number.isFinite(value) ||
146
+ (this.#constraints.integer && !Number.isInteger(value))) {
147
+ return { issues: [invalidTypeIssue(path, expected, value)] };
148
+ }
149
+ const issues = [];
150
+ const { maximum, minimum } = this.#constraints;
151
+ if (minimum !== undefined && value < minimum) {
152
+ issues.push(tooSmallIssue(path, `Number must be at least ${minimum}.`, minimum));
153
+ }
154
+ if (maximum !== undefined && value > maximum) {
155
+ issues.push(tooBigIssue(path, `Number must be at most ${maximum}.`, maximum));
156
+ }
157
+ return { value, issues };
158
+ }
159
+ [schemaJson]() {
160
+ const { integer, maximum, minimum } = this.#constraints;
161
+ return compactJsonSchema({
162
+ type: integer ? "integer" : "number",
163
+ minimum,
164
+ maximum,
165
+ });
166
+ }
167
+ }
168
+ export class BooleanSchema extends BaseSchema {
169
+ constructor(description) {
170
+ super(false, description);
171
+ }
172
+ cloneWithDescription(description) {
173
+ return new BooleanSchema(description);
174
+ }
175
+ [schemaParser](value, path) {
176
+ return typeof value === "boolean"
177
+ ? { value, issues: [] }
178
+ : { issues: [invalidTypeIssue(path, "boolean", value)] };
179
+ }
180
+ [schemaJson]() {
181
+ return { type: "boolean" };
182
+ }
183
+ }
184
+ export class NullSchema extends BaseSchema {
185
+ constructor(description) {
186
+ super(false, description);
187
+ }
188
+ cloneWithDescription(description) {
189
+ return new NullSchema(description);
190
+ }
191
+ [schemaParser](value, path) {
192
+ return value === null
193
+ ? { value, issues: [] }
194
+ : { issues: [invalidTypeIssue(path, "null", value)] };
195
+ }
196
+ [schemaJson]() {
197
+ return { type: "null" };
198
+ }
199
+ }
200
+ export class LiteralSchema extends BaseSchema {
201
+ #expected;
202
+ constructor(expected, description) {
203
+ super(false, description);
204
+ assertJsonPrimitive(expected, "literal");
205
+ this.#expected = expected;
206
+ }
207
+ cloneWithDescription(description) {
208
+ return new LiteralSchema(this.#expected, description);
209
+ }
210
+ [schemaParser](value, path) {
211
+ return value === this.#expected
212
+ ? { value: value, issues: [] }
213
+ : {
214
+ issues: [
215
+ {
216
+ code: "invalid_literal",
217
+ path,
218
+ message: `Expected literal ${JSON.stringify(this.#expected)}.`,
219
+ expected: this.#expected,
220
+ received: value,
221
+ },
222
+ ],
223
+ };
224
+ }
225
+ [schemaJson]() {
226
+ return { const: normalizeJsonPrimitive(this.#expected) };
227
+ }
228
+ }
229
+ export class EnumSchema extends BaseSchema {
230
+ #values;
231
+ constructor(values, description) {
232
+ super(false, description);
233
+ if (values.length === 0) {
234
+ throw new TypeError("An enum schema requires at least one value.");
235
+ }
236
+ for (const value of values) {
237
+ assertJsonPrimitive(value, "enum value");
238
+ }
239
+ this.#values = Object.freeze([...values]);
240
+ }
241
+ cloneWithDescription(description) {
242
+ return new EnumSchema(this.#values, description);
243
+ }
244
+ [schemaParser](value, path) {
245
+ const matches = this.#values.some((candidate) => candidate === value);
246
+ return matches
247
+ ? { value: value, issues: [] }
248
+ : {
249
+ issues: [
250
+ {
251
+ code: "invalid_enum_value",
252
+ path,
253
+ message: "Value must match one of the enum values.",
254
+ options: [...this.#values],
255
+ received: value,
256
+ },
257
+ ],
258
+ };
259
+ }
260
+ [schemaJson]() {
261
+ return {
262
+ enum: [...new Set(this.#values.map(normalizeJsonPrimitive))],
263
+ };
264
+ }
265
+ }
266
+ export class ArraySchema extends BaseSchema {
267
+ #item;
268
+ #constraints;
269
+ constructor(item, constraints = {
270
+ maximumItems: undefined,
271
+ minimumItems: undefined,
272
+ }, description) {
273
+ super(false, description);
274
+ this.#item = item;
275
+ this.#constraints = constraints;
276
+ }
277
+ minItems(minimumItems) {
278
+ assertNonNegativeInteger(minimumItems, "minimum item count");
279
+ return new ArraySchema(this.#item, {
280
+ ...this.#constraints,
281
+ minimumItems,
282
+ }, this.description);
283
+ }
284
+ maxItems(maximumItems) {
285
+ assertNonNegativeInteger(maximumItems, "maximum item count");
286
+ return new ArraySchema(this.#item, {
287
+ ...this.#constraints,
288
+ maximumItems,
289
+ }, this.description);
290
+ }
291
+ cloneWithDescription(description) {
292
+ return new ArraySchema(this.#item, this.#constraints, description);
293
+ }
294
+ [schemaParser](value, path) {
295
+ if (!Array.isArray(value)) {
296
+ return { issues: [invalidTypeIssue(path, "array", value)] };
297
+ }
298
+ const issues = [];
299
+ const { maximumItems, minimumItems } = this.#constraints;
300
+ if (minimumItems !== undefined && value.length < minimumItems) {
301
+ issues.push(tooSmallIssue(path, `Array must contain at least ${minimumItems} items.`, minimumItems));
302
+ }
303
+ if (maximumItems !== undefined && value.length > maximumItems) {
304
+ issues.push(tooBigIssue(path, `Array must contain at most ${maximumItems} items.`, maximumItems));
305
+ }
306
+ for (let index = 0; index < value.length; index += 1) {
307
+ if (!Object.hasOwn(value, index)) {
308
+ issues.push({
309
+ code: "invalid_type",
310
+ path: [...path, index],
311
+ message: "Expected array item.",
312
+ expected: "array item",
313
+ received: "missing",
314
+ });
315
+ continue;
316
+ }
317
+ issues.push(...parseWithSchema(this.#item, value[index], [...path, index]).issues);
318
+ }
319
+ return { value: value, issues };
320
+ }
321
+ [schemaJson]() {
322
+ const { maximumItems, minimumItems } = this.#constraints;
323
+ return compactJsonSchema({
324
+ type: "array",
325
+ items: this.#item.toJSONSchema(),
326
+ minItems: minimumItems,
327
+ maxItems: maximumItems,
328
+ });
329
+ }
330
+ }
331
+ export class ObjectSchema extends BaseSchema {
332
+ #shape;
333
+ constructor(shape, description) {
334
+ super(false, description);
335
+ this.#shape = Object.freeze({ ...shape });
336
+ }
337
+ cloneWithDescription(description) {
338
+ return new ObjectSchema(this.#shape, description);
339
+ }
340
+ [schemaParser](value, path) {
341
+ if (!isPlainObject(value)) {
342
+ return { issues: [invalidTypeIssue(path, "object", value)] };
343
+ }
344
+ const issues = [];
345
+ for (const [key, propertySchema] of Object.entries(this.#shape)) {
346
+ const hasProperty = Object.hasOwn(value, key);
347
+ if (!hasProperty && propertySchema[schemaOptional]) {
348
+ continue;
349
+ }
350
+ if (hasProperty && value[key] === undefined) {
351
+ issues.push(invalidTypeIssue([...path, key], "JSON value", undefined));
352
+ continue;
353
+ }
354
+ issues.push(...parseWithSchema(propertySchema, value[key], [...path, key]).issues);
355
+ }
356
+ for (const key of Object.keys(value)) {
357
+ if (!Object.hasOwn(this.#shape, key)) {
358
+ issues.push({
359
+ code: "unrecognized_key",
360
+ path: [...path, key],
361
+ message: `Unrecognized key "${key}".`,
362
+ key,
363
+ });
364
+ }
365
+ }
366
+ return { value: value, issues };
367
+ }
368
+ [schemaJson]() {
369
+ const properties = Object.fromEntries(Object.entries(this.#shape).map(([key, propertySchema]) => [
370
+ key,
371
+ propertySchema.toJSONSchema(),
372
+ ]));
373
+ const required = Object.entries(this.#shape)
374
+ .filter(([, propertySchema]) => !propertySchema[schemaOptional])
375
+ .map(([key]) => key);
376
+ return {
377
+ type: "object",
378
+ properties,
379
+ required,
380
+ additionalProperties: false,
381
+ };
382
+ }
383
+ }
384
+ export class UnionSchema extends BaseSchema {
385
+ #schemas;
386
+ constructor(schemas, description) {
387
+ super(false, description);
388
+ if (schemas.length < 2) {
389
+ throw new TypeError("A union schema requires at least two alternatives.");
390
+ }
391
+ this.#schemas = Object.freeze([...schemas]);
392
+ }
393
+ cloneWithDescription(description) {
394
+ return new UnionSchema(this.#schemas, description);
395
+ }
396
+ [schemaParser](value, path) {
397
+ const alternatives = this.#schemas.map((candidate) => parseWithSchema(candidate, value, path));
398
+ const match = alternatives.find((candidate) => candidate.issues.length === 0);
399
+ if (match !== undefined) {
400
+ return { value: match.value, issues: [] };
401
+ }
402
+ return {
403
+ issues: [
404
+ {
405
+ code: "invalid_union",
406
+ path,
407
+ message: "Value does not match any union alternative.",
408
+ alternatives: alternatives.map((candidate) => candidate.issues),
409
+ },
410
+ ],
411
+ };
412
+ }
413
+ [schemaJson]() {
414
+ return { anyOf: this.#schemas.map((candidate) => candidate.toJSONSchema()) };
415
+ }
416
+ }
417
+ class OptionalSchema extends BaseSchema {
418
+ #inner;
419
+ constructor(inner, description) {
420
+ super(true, description);
421
+ this.#inner = inner;
422
+ }
423
+ cloneWithDescription(description) {
424
+ return new OptionalSchema(this.#inner, description);
425
+ }
426
+ [schemaParser](value, path) {
427
+ return value === undefined
428
+ ? { value: undefined, issues: [] }
429
+ : parseWithSchema(this.#inner, value, path);
430
+ }
431
+ [schemaJson]() {
432
+ return this.#inner.toJSONSchema();
433
+ }
434
+ }
435
+ class NullableSchema extends BaseSchema {
436
+ #inner;
437
+ constructor(inner, optional, description) {
438
+ super(optional, description);
439
+ this.#inner = inner;
440
+ }
441
+ cloneWithDescription(description) {
442
+ return new NullableSchema(this.#inner, this[schemaOptional], description);
443
+ }
444
+ [schemaParser](value, path) {
445
+ return value === null
446
+ ? { value: null, issues: [] }
447
+ : parseWithSchema(this.#inner, value, path);
448
+ }
449
+ [schemaJson]() {
450
+ return {
451
+ anyOf: [this.#inner.toJSONSchema(), { type: "null" }],
452
+ };
453
+ }
454
+ }
455
+ export const schema = Object.freeze({
456
+ array: (item) => new ArraySchema(item),
457
+ boolean: () => new BooleanSchema(),
458
+ enum: (values) => new EnumSchema(values),
459
+ integer: () => new NumberSchema(true),
460
+ literal: (value) => new LiteralSchema(value),
461
+ null: () => new NullSchema(),
462
+ number: () => new NumberSchema(),
463
+ object: (shape) => new ObjectSchema(shape),
464
+ string: () => new StringSchema(),
465
+ union: (schemas) => new UnionSchema(schemas),
466
+ });
467
+ function parseWithSchema(candidate, value, path) {
468
+ return candidate[schemaParser](value, path);
469
+ }
470
+ function invalidTypeIssue(path, expected, value) {
471
+ return {
472
+ code: "invalid_type",
473
+ path,
474
+ message: `Expected ${expected}.`,
475
+ expected,
476
+ received: value === null ? "null" : Array.isArray(value) ? "array" : typeof value,
477
+ };
478
+ }
479
+ function tooSmallIssue(path, message, minimum) {
480
+ return { code: "too_small", path, message, minimum };
481
+ }
482
+ function tooBigIssue(path, message, maximum) {
483
+ return { code: "too_big", path, message, maximum };
484
+ }
485
+ function compactJsonSchema(value) {
486
+ return Object.fromEntries(Object.entries(value).filter((entry) => {
487
+ return entry[1] !== undefined;
488
+ }));
489
+ }
490
+ function isPlainObject(value) {
491
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
492
+ return false;
493
+ }
494
+ const prototype = Object.getPrototypeOf(value);
495
+ return prototype === Object.prototype || prototype === null;
496
+ }
497
+ function assertNonNegativeInteger(value, name) {
498
+ if (!Number.isInteger(value) || value < 0) {
499
+ throw new TypeError(`The ${name} must be a non-negative integer.`);
500
+ }
501
+ }
502
+ function assertFiniteNumber(value, name) {
503
+ if (!Number.isFinite(value)) {
504
+ throw new TypeError(`The ${name} must be a finite number.`);
505
+ }
506
+ }
507
+ function assertJsonPrimitive(value, name) {
508
+ if (typeof value === "number" && !Number.isFinite(value)) {
509
+ throw new TypeError(`The ${name} must be a finite JSON number.`);
510
+ }
511
+ }
512
+ function normalizeJsonPrimitive(value) {
513
+ return (typeof value === "number" && Object.is(value, -0)
514
+ ? 0
515
+ : value);
516
+ }
@@ -0,0 +1 @@
1
+ export declare function readStandardInput(): Promise<string>;
@@ -0,0 +1,7 @@
1
+ export async function readStandardInput() {
2
+ const chunks = [];
3
+ for await (const chunk of process.stdin) {
4
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
5
+ }
6
+ return Buffer.concat(chunks).toString("utf8");
7
+ }
@@ -0,0 +1 @@
1
+ export type NoExtraKeys<TActual, TAllowed> = Exclude<keyof TActual, keyof TAllowed> extends never ? unknown : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,160 @@
1
+ import { type AutomationEventObserver } from "./events.js";
2
+ import { type AccessPolicy, type ApprovalPolicy, type EnvironmentOverrides, type Harness } from "./harness.js";
3
+ import type { JsonPrimitive as InternalJsonPrimitive, JsonValue as InternalJsonValue } from "./json.js";
4
+ import type { InferSchema, Schema } from "./schema.js";
5
+ import { type RunJournalMode } from "./run-journal.js";
6
+ import type { NoExtraKeys } from "./type-utils.js";
7
+ export type JsonPrimitive = InternalJsonPrimitive;
8
+ export type JsonValue = InternalJsonValue;
9
+ export type WorkflowResult = JsonValue | undefined;
10
+ type MaybePromise<T> = PromiseLike<T> | T;
11
+ type JsonCompatible<T> = T extends JsonPrimitive ? T : T extends (...arguments_: never[]) => unknown ? never : T extends readonly (infer TItem)[] ? readonly JsonCompatible<TItem>[] : T extends object ? {
12
+ readonly [TKey in keyof T]: JsonCompatible<T[TKey]>;
13
+ } : never;
14
+ type NormalizedWorkflowResult<TResult> = TResult extends void ? undefined : TResult;
15
+ type JsonCompatibleWorkflowResult<TResult> = TResult extends undefined ? undefined : JsonCompatible<TResult>;
16
+ type WorkflowResultConstraint<TResult> = [
17
+ NormalizedWorkflowResult<TResult>
18
+ ] extends [JsonCompatibleWorkflowResult<NormalizedWorkflowResult<TResult>>] ? unknown : never;
19
+ declare const workflowDefinitionBrand: unique symbol;
20
+ declare const workflowRunner: unique symbol;
21
+ declare const workflowInputSchema: unique symbol;
22
+ declare const workflowOutputSchema: unique symbol;
23
+ declare const workflowHarness: unique symbol;
24
+ type AnySchema = Schema<any, boolean>;
25
+ export interface WorkflowContext<TInput> {
26
+ readonly input: TInput;
27
+ readonly signal: AbortSignal;
28
+ run<TOutputSchema extends AnySchema>(prompt: string, options: StructuredRunOptions<TOutputSchema>): Promise<InferSchema<TOutputSchema>>;
29
+ run(prompt: string, options: RunOptions): Promise<string>;
30
+ session(options?: SessionOptions): Session;
31
+ }
32
+ interface RunExecutionOptions {
33
+ readonly access: AccessPolicy;
34
+ readonly approval?: ApprovalPolicy;
35
+ readonly cwd?: string;
36
+ readonly env?: EnvironmentOverrides;
37
+ readonly harness?: Harness;
38
+ readonly name?: string;
39
+ readonly timeout?: number | false;
40
+ }
41
+ export interface RunOptions extends RunExecutionOptions {
42
+ readonly output?: never;
43
+ }
44
+ export interface StructuredRunOptions<TOutputSchema extends AnySchema> extends RunExecutionOptions {
45
+ readonly output: TOutputSchema;
46
+ }
47
+ type SessionRunExecutionOptions = Omit<RunExecutionOptions, "cwd" | "harness">;
48
+ export interface SessionOptions {
49
+ readonly cwd?: string;
50
+ readonly env?: EnvironmentOverrides;
51
+ readonly harness?: Harness;
52
+ readonly name?: string;
53
+ }
54
+ export interface SessionRunOptions extends SessionRunExecutionOptions {
55
+ readonly output?: never;
56
+ }
57
+ export interface StructuredSessionRunOptions<TOutputSchema extends AnySchema> extends SessionRunExecutionOptions {
58
+ readonly output: TOutputSchema;
59
+ }
60
+ export interface Session {
61
+ run<TOutputSchema extends AnySchema>(prompt: string, options: StructuredSessionRunOptions<TOutputSchema>): Promise<InferSchema<TOutputSchema>>;
62
+ run(prompt: string, options: SessionRunOptions): Promise<string>;
63
+ }
64
+ export interface WorkflowDefinition<TResult, TInput = never, THasInput extends boolean = false> {
65
+ readonly [workflowDefinitionBrand]: true;
66
+ readonly [workflowRunner]: (context: WorkflowContext<TInput>) => MaybePromise<TResult>;
67
+ readonly [workflowInputSchema]: THasInput extends true ? Schema<TInput, boolean> : undefined;
68
+ readonly [workflowOutputSchema]: Schema<TResult, boolean> | undefined;
69
+ readonly [workflowHarness]: Harness | undefined;
70
+ }
71
+ type WorkflowDefinitionOptionsBase<TResult, TInput> = {
72
+ readonly harness?: Harness;
73
+ readonly output?: Schema<TResult, boolean>;
74
+ readonly run: (context: WorkflowContext<TInput>) => MaybePromise<TResult>;
75
+ };
76
+ export type WorkflowDefinitionOptions<TResult, TInput = never> = WorkflowDefinitionOptionsBase<TResult, TInput> & ([TInput] extends [never] ? {
77
+ readonly input?: never;
78
+ } : {
79
+ readonly input: Schema<TInput, boolean>;
80
+ });
81
+ type InputAndOutputWorkflowOptions<TInputSchema extends AnySchema, TOutputSchema extends AnySchema> = {
82
+ readonly harness?: Harness;
83
+ readonly input: TInputSchema;
84
+ readonly output: TOutputSchema;
85
+ readonly run: (context: WorkflowContext<InferSchema<TInputSchema>>) => MaybePromise<InferSchema<TOutputSchema>>;
86
+ };
87
+ type InputWorkflowOptions<TInputSchema extends AnySchema, TResult> = {
88
+ readonly harness?: Harness;
89
+ readonly input: TInputSchema;
90
+ readonly output?: never;
91
+ readonly run: (context: WorkflowContext<InferSchema<TInputSchema>>) => MaybePromise<TResult>;
92
+ } & WorkflowResultConstraint<TResult>;
93
+ type AsyncJsonInputWorkflowOptions<TInputSchema extends AnySchema, TResult extends WorkflowResult | void> = {
94
+ readonly harness?: Harness;
95
+ readonly input: TInputSchema;
96
+ readonly output?: never;
97
+ readonly run: (context: WorkflowContext<InferSchema<TInputSchema>>) => PromiseLike<TResult>;
98
+ };
99
+ type OutputWorkflowOptions<TOutputSchema extends AnySchema> = {
100
+ readonly harness?: Harness;
101
+ readonly input?: never;
102
+ readonly output: TOutputSchema;
103
+ readonly run: (context: WorkflowContext<never>) => MaybePromise<InferSchema<TOutputSchema>>;
104
+ };
105
+ type InferredWorkflowOptions<TResult> = {
106
+ readonly harness?: Harness;
107
+ readonly input?: never;
108
+ readonly output?: never;
109
+ readonly run: (context: WorkflowContext<never>) => MaybePromise<TResult>;
110
+ } & WorkflowResultConstraint<TResult>;
111
+ type AsyncJsonWorkflowOptions<TResult extends WorkflowResult | void> = {
112
+ readonly harness?: Harness;
113
+ readonly input?: never;
114
+ readonly output?: never;
115
+ readonly run: (context: WorkflowContext<never>) => PromiseLike<TResult>;
116
+ };
117
+ type HasDeclaredOutput<TOptions> = TOptions extends {
118
+ readonly output: AnySchema;
119
+ } ? true : false;
120
+ type ReusableWorkflowOptionsShape = {
121
+ readonly harness?: Harness;
122
+ readonly input?: Schema<any, boolean>;
123
+ readonly output?: Schema<any, boolean>;
124
+ readonly run: (...arguments_: never[]) => unknown;
125
+ };
126
+ type UnwrapMaybePromise<TValue> = TValue extends PromiseLike<infer TAwaited> ? TAwaited : TValue;
127
+ type ReusableWorkflowResult<TOptions extends ReusableWorkflowOptionsShape> = UnwrapMaybePromise<ReturnType<TOptions["run"]>>;
128
+ type ReusableWorkflowInput<TOptions extends ReusableWorkflowOptionsShape> = TOptions extends {
129
+ readonly input: Schema<infer TInput, boolean>;
130
+ } ? TInput : never;
131
+ export declare function defineWorkflow<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, const TOptions extends InputAndOutputWorkflowOptions<TInputSchema, TOutputSchema>>(options: TOptions & InputAndOutputWorkflowOptions<TInputSchema, TOutputSchema> & NoExtraKeys<TOptions, InputAndOutputWorkflowOptions<TInputSchema, TOutputSchema>>): WorkflowDefinition<InferSchema<TOutputSchema>, InferSchema<TInputSchema>, true>;
132
+ export declare function defineWorkflow<TInputSchema extends AnySchema, TResult extends WorkflowResult | void, const TOptions extends AsyncJsonInputWorkflowOptions<TInputSchema, TResult>>(options: TOptions & AsyncJsonInputWorkflowOptions<TInputSchema, TResult> & NoExtraKeys<TOptions, AsyncJsonInputWorkflowOptions<TInputSchema, TResult>>): WorkflowDefinition<NormalizedWorkflowResult<TResult>, InferSchema<TInputSchema>, true>;
133
+ export declare function defineWorkflow<TInputSchema extends AnySchema, TResult, const TOptions extends InputWorkflowOptions<TInputSchema, TResult>>(options: TOptions & InputWorkflowOptions<TInputSchema, TResult> & NoExtraKeys<TOptions, InputWorkflowOptions<TInputSchema, TResult>>): WorkflowDefinition<NormalizedWorkflowResult<TResult>, InferSchema<TInputSchema>, true>;
134
+ export declare function defineWorkflow<TOutputSchema extends AnySchema, const TOptions extends OutputWorkflowOptions<TOutputSchema>>(options: TOptions & OutputWorkflowOptions<TOutputSchema> & NoExtraKeys<TOptions, OutputWorkflowOptions<TOutputSchema>>): WorkflowDefinition<InferSchema<TOutputSchema>>;
135
+ export declare function defineWorkflow<TResult extends WorkflowResult | void, const TOptions extends AsyncJsonWorkflowOptions<TResult>>(options: TOptions & AsyncJsonWorkflowOptions<TResult> & NoExtraKeys<TOptions, AsyncJsonWorkflowOptions<TResult>>): WorkflowDefinition<NormalizedWorkflowResult<TResult>>;
136
+ export declare function defineWorkflow<TResult, const TOptions extends InferredWorkflowOptions<TResult>>(options: TOptions & InferredWorkflowOptions<TResult> & NoExtraKeys<TOptions, InferredWorkflowOptions<TResult>>): WorkflowDefinition<NormalizedWorkflowResult<TResult>>;
137
+ export declare function defineWorkflow<const TOptions extends ReusableWorkflowOptionsShape>(options: TOptions & WorkflowResultConstraint<ReusableWorkflowResult<TOptions>> & (HasDeclaredOutput<TOptions> extends true ? never : unknown) & NoExtraKeys<TOptions, ReusableWorkflowOptionsShape>): WorkflowDefinition<NormalizedWorkflowResult<ReusableWorkflowResult<TOptions>>, ReusableWorkflowInput<TOptions>, [
138
+ ReusableWorkflowInput<TOptions>
139
+ ] extends [never] ? false : true>;
140
+ export declare function isWorkflowDefinition(value: unknown): value is WorkflowDefinition<unknown, unknown, boolean>;
141
+ export interface ExecuteWorkflowOptions<TInput> {
142
+ readonly concurrency?: number;
143
+ readonly input: TInput;
144
+ readonly onEvent?: AutomationEventObserver;
145
+ readonly record?: RunJournalMode | false;
146
+ readonly signal?: AbortSignal;
147
+ readonly workspaceRoot?: string;
148
+ }
149
+ export interface ExecuteWorkflowWithoutInputOptions {
150
+ readonly concurrency?: number;
151
+ readonly input?: never;
152
+ readonly onEvent?: AutomationEventObserver;
153
+ readonly record?: RunJournalMode | false;
154
+ readonly signal?: AbortSignal;
155
+ readonly workspaceRoot?: string;
156
+ }
157
+ export declare function executeWorkflow<TResult, TInput>(definition: WorkflowDefinition<TResult, TInput, true>, options: ExecuteWorkflowOptions<TInput>): Promise<TResult>;
158
+ export declare function executeWorkflow<TResult>(definition: WorkflowDefinition<TResult, never, false>, options?: ExecuteWorkflowWithoutInputOptions): Promise<TResult>;
159
+ export declare function executeWorkflowWithControls(definition: any, options?: any, forceSignal?: AbortSignal): Promise<any>;
160
+ export {};