@outputai/core 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.
- package/LICENSE +201 -0
- package/README.md +11 -0
- package/bin/healthcheck.mjs +36 -0
- package/bin/healthcheck.spec.js +90 -0
- package/bin/worker.sh +26 -0
- package/package.json +67 -0
- package/src/activity_integration/context.d.ts +27 -0
- package/src/activity_integration/context.js +17 -0
- package/src/activity_integration/context.spec.js +42 -0
- package/src/activity_integration/events.d.ts +7 -0
- package/src/activity_integration/events.js +10 -0
- package/src/activity_integration/index.d.ts +9 -0
- package/src/activity_integration/index.js +3 -0
- package/src/activity_integration/tracing.d.ts +32 -0
- package/src/activity_integration/tracing.js +37 -0
- package/src/async_storage.js +19 -0
- package/src/bus.js +3 -0
- package/src/consts.js +32 -0
- package/src/errors.d.ts +15 -0
- package/src/errors.js +14 -0
- package/src/hooks/index.d.ts +28 -0
- package/src/hooks/index.js +32 -0
- package/src/index.d.ts +49 -0
- package/src/index.js +4 -0
- package/src/interface/evaluation_result.d.ts +173 -0
- package/src/interface/evaluation_result.js +215 -0
- package/src/interface/evaluator.d.ts +70 -0
- package/src/interface/evaluator.js +34 -0
- package/src/interface/evaluator.spec.js +565 -0
- package/src/interface/index.d.ts +9 -0
- package/src/interface/index.js +26 -0
- package/src/interface/step.d.ts +138 -0
- package/src/interface/step.js +22 -0
- package/src/interface/types.d.ts +27 -0
- package/src/interface/validations/runtime.js +20 -0
- package/src/interface/validations/runtime.spec.js +29 -0
- package/src/interface/validations/schema_utils.js +8 -0
- package/src/interface/validations/schema_utils.spec.js +67 -0
- package/src/interface/validations/static.js +136 -0
- package/src/interface/validations/static.spec.js +366 -0
- package/src/interface/webhook.d.ts +84 -0
- package/src/interface/webhook.js +64 -0
- package/src/interface/webhook.spec.js +122 -0
- package/src/interface/workflow.d.ts +273 -0
- package/src/interface/workflow.js +128 -0
- package/src/interface/workflow.spec.js +467 -0
- package/src/interface/workflow_context.js +31 -0
- package/src/interface/workflow_utils.d.ts +76 -0
- package/src/interface/workflow_utils.js +50 -0
- package/src/interface/workflow_utils.spec.js +190 -0
- package/src/interface/zod_integration.spec.js +646 -0
- package/src/internal_activities/index.js +66 -0
- package/src/internal_activities/index.spec.js +102 -0
- package/src/logger.js +73 -0
- package/src/tracing/internal_interface.js +71 -0
- package/src/tracing/processors/local/index.js +111 -0
- package/src/tracing/processors/local/index.spec.js +149 -0
- package/src/tracing/processors/s3/configs.js +31 -0
- package/src/tracing/processors/s3/configs.spec.js +64 -0
- package/src/tracing/processors/s3/index.js +114 -0
- package/src/tracing/processors/s3/index.spec.js +153 -0
- package/src/tracing/processors/s3/redis_client.js +62 -0
- package/src/tracing/processors/s3/redis_client.spec.js +185 -0
- package/src/tracing/processors/s3/s3_client.js +27 -0
- package/src/tracing/processors/s3/s3_client.spec.js +62 -0
- package/src/tracing/tools/build_trace_tree.js +83 -0
- package/src/tracing/tools/build_trace_tree.spec.js +135 -0
- package/src/tracing/tools/utils.js +21 -0
- package/src/tracing/tools/utils.spec.js +14 -0
- package/src/tracing/trace_engine.js +97 -0
- package/src/tracing/trace_engine.spec.js +199 -0
- package/src/utils/index.d.ts +134 -0
- package/src/utils/index.js +2 -0
- package/src/utils/resolve_invocation_dir.js +34 -0
- package/src/utils/resolve_invocation_dir.spec.js +102 -0
- package/src/utils/utils.js +211 -0
- package/src/utils/utils.spec.js +448 -0
- package/src/worker/bundler_options.js +43 -0
- package/src/worker/catalog_workflow/catalog.js +114 -0
- package/src/worker/catalog_workflow/index.js +54 -0
- package/src/worker/catalog_workflow/index.spec.js +196 -0
- package/src/worker/catalog_workflow/workflow.js +24 -0
- package/src/worker/configs.js +49 -0
- package/src/worker/configs.spec.js +130 -0
- package/src/worker/index.js +89 -0
- package/src/worker/index.spec.js +177 -0
- package/src/worker/interceptors/activity.js +62 -0
- package/src/worker/interceptors/activity.spec.js +212 -0
- package/src/worker/interceptors/workflow.js +70 -0
- package/src/worker/interceptors/workflow.spec.js +167 -0
- package/src/worker/interceptors.js +10 -0
- package/src/worker/loader.js +151 -0
- package/src/worker/loader.spec.js +236 -0
- package/src/worker/loader_tools.js +132 -0
- package/src/worker/loader_tools.spec.js +156 -0
- package/src/worker/log_hooks.js +95 -0
- package/src/worker/log_hooks.spec.js +217 -0
- package/src/worker/sandboxed_utils.js +18 -0
- package/src/worker/shutdown.js +26 -0
- package/src/worker/shutdown.spec.js +82 -0
- package/src/worker/sinks.js +74 -0
- package/src/worker/start_catalog.js +36 -0
- package/src/worker/start_catalog.spec.js +118 -0
- package/src/worker/webpack_loaders/consts.js +9 -0
- package/src/worker/webpack_loaders/tools.js +548 -0
- package/src/worker/webpack_loaders/tools.spec.js +330 -0
- package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.js +221 -0
- package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.spec.js +336 -0
- package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +61 -0
- package/src/worker/webpack_loaders/workflow_rewriter/index.spec.js +216 -0
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_fn_bodies.js +196 -0
- package/src/worker/webpack_loaders/workflow_rewriter/rewrite_fn_bodies.spec.js +123 -0
- package/src/worker/webpack_loaders/workflow_validator/index.mjs +205 -0
- package/src/worker/webpack_loaders/workflow_validator/index.spec.js +613 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AnyZodSchema, TemporalActivityOptions } from './types.d.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for a step.
|
|
6
|
+
*/
|
|
7
|
+
export type StepOptions = {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Temporal activity options for this step.
|
|
11
|
+
*/
|
|
12
|
+
activityOptions?: TemporalActivityOptions
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The handler function of a step.
|
|
17
|
+
*
|
|
18
|
+
* @param input - The step input; it matches the schema defined by `inputSchema`.
|
|
19
|
+
*
|
|
20
|
+
* @returns A value matching the schema defined by `outputSchema`.
|
|
21
|
+
*/
|
|
22
|
+
export type StepFunction<
|
|
23
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
24
|
+
OutputSchema extends AnyZodSchema | undefined = undefined
|
|
25
|
+
> = InputSchema extends AnyZodSchema ?
|
|
26
|
+
( input: z.infer<InputSchema> ) => Promise<OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void> :
|
|
27
|
+
() => Promise<OutputSchema extends AnyZodSchema ? z.infer<OutputSchema> : void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A wrapper around the user defined `fn` handler function.
|
|
31
|
+
*
|
|
32
|
+
* It accepts the same input and returns the same value, calling the user function inside.
|
|
33
|
+
*
|
|
34
|
+
* It adds input and output validation based on the `inputSchema`, `outputSchema`.
|
|
35
|
+
*
|
|
36
|
+
* @param input - The Step input; it matches the schema defined by `inputSchema`.
|
|
37
|
+
* @returns A value matching the schema defined by `outputSchema`.
|
|
38
|
+
*/
|
|
39
|
+
export type StepFunctionWrapper<StepFunction> =
|
|
40
|
+
Parameters<StepFunction> extends [infer Input] ?
|
|
41
|
+
( input: Input ) => ReturnType<StepFunction> :
|
|
42
|
+
() => ReturnType<StepFunction>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Creates a step.
|
|
46
|
+
*
|
|
47
|
+
* A step is a logical unit of work that can perform I/O. It is translated to a Temporal Activity.
|
|
48
|
+
*
|
|
49
|
+
* The step logic is defined in the `fn` handler function.
|
|
50
|
+
*
|
|
51
|
+
* The schema of the input that the function receives as the first argument is defined by the `inputSchema` option.
|
|
52
|
+
*
|
|
53
|
+
* The output of the `fn` handler must match the schema defined by `outputSchema`; otherwise, a validation error is raised.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```
|
|
57
|
+
* step( {
|
|
58
|
+
* name: 'process',
|
|
59
|
+
* description: 'A generic process',
|
|
60
|
+
* inputSchema: z.object( {
|
|
61
|
+
* value: z.number()
|
|
62
|
+
* } ),
|
|
63
|
+
* outputSchema: z.string(),
|
|
64
|
+
* fn: async input => {
|
|
65
|
+
* const result = await ai.call( input.value );
|
|
66
|
+
* return result as string;
|
|
67
|
+
* }
|
|
68
|
+
* } )
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Step without outputSchema
|
|
72
|
+
* ```
|
|
73
|
+
* step( {
|
|
74
|
+
* name: 'process',
|
|
75
|
+
* description: 'A generic process',
|
|
76
|
+
* inputSchema: z.object( {
|
|
77
|
+
* value: z.number()
|
|
78
|
+
* } ),
|
|
79
|
+
* fn: async input => {
|
|
80
|
+
* await ai.call( input.value );
|
|
81
|
+
* }
|
|
82
|
+
* } )
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Step without inputSchema
|
|
86
|
+
* ```
|
|
87
|
+
* step( {
|
|
88
|
+
* name: 'process',
|
|
89
|
+
* description: 'A generic process',
|
|
90
|
+
* outputSchema: z.string(),
|
|
91
|
+
* fn: async () => {
|
|
92
|
+
* const result = await ai.call();
|
|
93
|
+
* return result as string;
|
|
94
|
+
* }
|
|
95
|
+
* } )
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Step without inputSchema and outputSchema
|
|
99
|
+
* ```
|
|
100
|
+
* step( {
|
|
101
|
+
* name: 'process',
|
|
102
|
+
* description: 'A generic process',
|
|
103
|
+
* fn: async () => {
|
|
104
|
+
* await ai.call();
|
|
105
|
+
* }
|
|
106
|
+
* } )
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* - Never call another step from within a step.
|
|
111
|
+
* - Never call a workflow from within a step.
|
|
112
|
+
*
|
|
113
|
+
* @typeParam InputSchema - Zod schema of the fn's input.
|
|
114
|
+
* @typeParam OutputSchema - Zod schema of the fn's return.
|
|
115
|
+
*
|
|
116
|
+
* @throws {@link ValidationError}
|
|
117
|
+
* @throws {@link FatalError}
|
|
118
|
+
*
|
|
119
|
+
* @param params - Step parameters
|
|
120
|
+
* @param params.name - Human-readable step name (must start with a letter or underscore, followed by letters, numbers, or underscores)
|
|
121
|
+
* @param params.description - Description of the step
|
|
122
|
+
* @param params.inputSchema - Zod schema for the `fn` input
|
|
123
|
+
* @param params.outputSchema - Zod schema for the `fn` output
|
|
124
|
+
* @param params.fn - A handler function containing the step code
|
|
125
|
+
* @param params.options - Optional step options.
|
|
126
|
+
* @returns The same handler function set at `fn`
|
|
127
|
+
*/
|
|
128
|
+
export declare function step<
|
|
129
|
+
InputSchema extends AnyZodSchema | undefined = undefined,
|
|
130
|
+
OutputSchema extends AnyZodSchema | undefined = undefined
|
|
131
|
+
>( params: {
|
|
132
|
+
name: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
inputSchema?: InputSchema;
|
|
135
|
+
outputSchema?: OutputSchema;
|
|
136
|
+
fn: StepFunction<InputSchema, OutputSchema>;
|
|
137
|
+
options?: StepOptions;
|
|
138
|
+
} ): StepFunctionWrapper<StepFunction<InputSchema, OutputSchema>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// THIS RUNS IN THE TEMPORAL'S SANDBOX ENVIRONMENT
|
|
2
|
+
import { setMetadata } from '#utils';
|
|
3
|
+
import { validateStep } from './validations/static.js';
|
|
4
|
+
import { validateWithSchema } from './validations/runtime.js';
|
|
5
|
+
import { ComponentType } from '#consts';
|
|
6
|
+
|
|
7
|
+
export function step( { name, description, inputSchema, outputSchema, fn, options } ) {
|
|
8
|
+
validateStep( { name, description, inputSchema, outputSchema, fn, options } );
|
|
9
|
+
|
|
10
|
+
const wrapper = async input => {
|
|
11
|
+
validateWithSchema( inputSchema, input, `Step ${name} input` );
|
|
12
|
+
|
|
13
|
+
const output = await fn( input );
|
|
14
|
+
|
|
15
|
+
validateWithSchema( outputSchema, output, `Step ${name} output` );
|
|
16
|
+
|
|
17
|
+
return output;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
setMetadata( wrapper, { name, description, inputSchema, outputSchema, type: ComponentType.STEP, options } );
|
|
21
|
+
return wrapper;
|
|
22
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ActivityOptions } from '@temporalio/workflow';
|
|
3
|
+
/**
|
|
4
|
+
* Similar to `Partial<T>` but applies to nested properties recursively, creating a deep optional variant of `T`:
|
|
5
|
+
* - Objects: All properties become optional, recursively.
|
|
6
|
+
* - Functions: Preserved as‑is (only the property itself becomes optional).
|
|
7
|
+
* - Primitives: Returned unchanged.
|
|
8
|
+
* Useful for config overrides with strong IntelliSense on nested fields and methods.
|
|
9
|
+
*/
|
|
10
|
+
export type DeepPartial<T> =
|
|
11
|
+
T extends ( ...args: any[] ) => unknown ? T : // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
12
|
+
T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } :
|
|
13
|
+
T;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Type alias for any Zod schema type.
|
|
17
|
+
*/
|
|
18
|
+
export type AnyZodSchema = z.ZodType<any, any, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Native Temporal configurations for activities.
|
|
22
|
+
*
|
|
23
|
+
* All native options are accepted except 'versioningIntent', 'taskQueue', 'allowEagerDispatch'.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://typescript.temporal.io/api/interfaces/common.ActivityOptions}
|
|
26
|
+
*/
|
|
27
|
+
export type TemporalActivityOptions = Omit<ActivityOptions, 'versioningIntent' | 'taskQueue' | 'allowEagerDispatch'>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ValidationError } from '#errors';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validates data against a Zod schema using safeParse
|
|
5
|
+
* @param {unknown} schema - The Zod schema to validate against
|
|
6
|
+
* @param {unknown} data - The data to validate
|
|
7
|
+
* @param {string} context - Description of what's being validated (for error messages)
|
|
8
|
+
* @throws {ValidationError} If validation fails
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
11
|
+
export function validateWithSchema( schema, data, context ) {
|
|
12
|
+
if ( !schema ) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const result = schema.safeParse( data );
|
|
17
|
+
if ( !result.success ) {
|
|
18
|
+
throw new ValidationError( `${context} validation failed: ${result.error.message}` );
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { validateWithSchema } from './runtime.js';
|
|
4
|
+
import { ValidationError } from '#errors';
|
|
5
|
+
|
|
6
|
+
describe( 'runtime validations', () => {
|
|
7
|
+
describe( 'validateWithSchema', () => {
|
|
8
|
+
it( 'no-ops when schema is falsy', () => {
|
|
9
|
+
expect( () => validateWithSchema( undefined, { a: 1 }, 'X' ) ).not.toThrow();
|
|
10
|
+
expect( () => validateWithSchema( null, { a: 1 }, 'X' ) ).not.toThrow();
|
|
11
|
+
} );
|
|
12
|
+
|
|
13
|
+
it( 'passes on valid data', () => {
|
|
14
|
+
const schema = z.object( { a: z.string(), b: z.number().optional() } );
|
|
15
|
+
expect( () => validateWithSchema( schema, { a: 'ok' }, 'Test' ) ).not.toThrow();
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
it( 'throws ValidationError on invalid data and prefixes context', () => {
|
|
19
|
+
const schema = z.object( { a: z.string() } );
|
|
20
|
+
const call = () => validateWithSchema( schema, { a: 1 }, 'MyCtx' );
|
|
21
|
+
expect( call ).toThrow( ValidationError );
|
|
22
|
+
try {
|
|
23
|
+
call();
|
|
24
|
+
} catch ( e ) {
|
|
25
|
+
expect( String( e.message ) ).toContain( 'MyCtx validation failed:' );
|
|
26
|
+
}
|
|
27
|
+
} );
|
|
28
|
+
} );
|
|
29
|
+
} );
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// Import the actual implementations
|
|
5
|
+
import { isZodSchema } from './schema_utils.js';
|
|
6
|
+
|
|
7
|
+
describe( 'Schema Detection', () => {
|
|
8
|
+
describe( 'isZodSchema', () => {
|
|
9
|
+
it( 'should correctly identify Zod schemas', () => {
|
|
10
|
+
const zodSchema = z.object( {
|
|
11
|
+
name: z.string(),
|
|
12
|
+
age: z.number()
|
|
13
|
+
} );
|
|
14
|
+
|
|
15
|
+
expect( isZodSchema( zodSchema ) ).toBe( true );
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
it( 'should correctly identify Zod string schema', () => {
|
|
19
|
+
const zodString = z.string();
|
|
20
|
+
expect( isZodSchema( zodString ) ).toBe( true );
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
it( 'should correctly identify Zod array schema', () => {
|
|
24
|
+
const zodArray = z.array( z.number() );
|
|
25
|
+
expect( isZodSchema( zodArray ) ).toBe( true );
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
it( 'should correctly identify Zod union schema', () => {
|
|
29
|
+
const zodUnion = z.union( [ z.string(), z.number() ] );
|
|
30
|
+
expect( isZodSchema( zodUnion ) ).toBe( true );
|
|
31
|
+
} );
|
|
32
|
+
|
|
33
|
+
it( 'should return false for JSON Schema objects', () => {
|
|
34
|
+
const jsonSchema = {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
name: { type: 'string' },
|
|
38
|
+
age: { type: 'number' }
|
|
39
|
+
},
|
|
40
|
+
required: [ 'name' ]
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
expect( isZodSchema( jsonSchema ) ).toBe( false );
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
it( 'should return false for plain objects', () => {
|
|
47
|
+
expect( isZodSchema( {} ) ).toBe( false );
|
|
48
|
+
expect( isZodSchema( { type: 'string' } ) ).toBe( false );
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
it( 'should return false for null and undefined', () => {
|
|
52
|
+
expect( isZodSchema( null ) ).toBeFalsy();
|
|
53
|
+
expect( isZodSchema( undefined ) ).toBeFalsy();
|
|
54
|
+
} );
|
|
55
|
+
|
|
56
|
+
it( 'should return false for primitive values', () => {
|
|
57
|
+
expect( isZodSchema( 'string' ) ).toBe( false );
|
|
58
|
+
expect( isZodSchema( 123 ) ).toBe( false );
|
|
59
|
+
expect( isZodSchema( true ) ).toBe( false );
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
it( 'should return false for arrays', () => {
|
|
63
|
+
expect( isZodSchema( [] ) ).toBe( false );
|
|
64
|
+
expect( isZodSchema( [ 1, 2, 3 ] ) ).toBe( false );
|
|
65
|
+
} );
|
|
66
|
+
} );
|
|
67
|
+
} );
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { isZodSchema } from './schema_utils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error is thrown when the definition of a step/workflow has problems
|
|
6
|
+
*/
|
|
7
|
+
export class StaticValidationError extends Error {};
|
|
8
|
+
|
|
9
|
+
const refineSchema = ( value, ctx ) => {
|
|
10
|
+
if ( !value || isZodSchema( value ) ) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
ctx.addIssue( {
|
|
15
|
+
code: 'invalid_type',
|
|
16
|
+
message: 'Schema must be a Zod schema'
|
|
17
|
+
} );
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const executeInParallelSchema = z.object( {
|
|
21
|
+
jobs: z.array( z.function() ),
|
|
22
|
+
concurrency: z.number().min( 1 ).or( z.literal( Infinity ) ),
|
|
23
|
+
onJobCompleted: z.function().optional()
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
export const durationSchema = z.union( [ z.string().regex(
|
|
27
|
+
/^(\d+)(ms|s|m|h|d)$/,
|
|
28
|
+
'Expected duration like "500ms", "10s", "5m", "2h", or "1d"'
|
|
29
|
+
), z.number() ] );
|
|
30
|
+
|
|
31
|
+
export const prioritySchema = z.object( {
|
|
32
|
+
fairnessKey: z.string().optional(),
|
|
33
|
+
fairnessWeight: z.number().min( 0.0001 ).max( 1000 ).optional(),
|
|
34
|
+
priorityKey: z.number().min( 1 ).optional()
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
const baseSchema = z.strictObject( {
|
|
38
|
+
name: z.string().regex( /^[a-z_][a-z0-9_]*$/i ),
|
|
39
|
+
description: z.string().optional(),
|
|
40
|
+
inputSchema: z.any().optional().superRefine( refineSchema ),
|
|
41
|
+
outputSchema: z.any().optional().superRefine( refineSchema ),
|
|
42
|
+
fn: z.function(),
|
|
43
|
+
options: z.object( {
|
|
44
|
+
activityOptions: z.strictObject( {
|
|
45
|
+
activityId: z.string().optional(),
|
|
46
|
+
cancellationType: z.enum( [ 'TRY_CANCEL', 'WAIT_CANCELLATION_COMPLETED', 'ABANDON' ] ).optional(),
|
|
47
|
+
heartbeatTimeout: durationSchema.optional(),
|
|
48
|
+
priority: prioritySchema.optional(),
|
|
49
|
+
retry: z.strictObject( {
|
|
50
|
+
initialInterval: durationSchema.optional(),
|
|
51
|
+
backoffCoefficient: z.number().gte( 1 ).optional(),
|
|
52
|
+
maximumInterval: durationSchema.optional(),
|
|
53
|
+
maximumAttempts: z.number().gte( 1 ).int().optional(),
|
|
54
|
+
nonRetryableErrorTypes: z.array( z.string() ).optional()
|
|
55
|
+
} ).optional(),
|
|
56
|
+
scheduleToCloseTimeout: durationSchema.optional(),
|
|
57
|
+
scheduleToStartTimeout: durationSchema.optional(),
|
|
58
|
+
startToCloseTimeout: durationSchema.optional(),
|
|
59
|
+
summary: z.string().optional()
|
|
60
|
+
} ).optional()
|
|
61
|
+
} ).optional()
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
const stepSchema = baseSchema;
|
|
65
|
+
|
|
66
|
+
const workflowSchema = baseSchema.extend( {
|
|
67
|
+
options: baseSchema.shape.options.unwrap().extend( {
|
|
68
|
+
disableTrace: z.boolean().optional().default( false )
|
|
69
|
+
} ).optional()
|
|
70
|
+
} );
|
|
71
|
+
|
|
72
|
+
const evaluatorSchema = baseSchema.omit( { outputSchema: true } );
|
|
73
|
+
|
|
74
|
+
const httpRequestSchema = z.object( {
|
|
75
|
+
url: z.url( { protocol: /^https?$/ } ),
|
|
76
|
+
method: z.enum( [ 'GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE' ] ),
|
|
77
|
+
payload: z.any().optional(),
|
|
78
|
+
headers: z.record( z.string(), z.string() ).optional()
|
|
79
|
+
} );
|
|
80
|
+
|
|
81
|
+
const validateAgainstSchema = ( schema, args ) => {
|
|
82
|
+
const result = schema.safeParse( args );
|
|
83
|
+
if ( !result.success ) {
|
|
84
|
+
throw new StaticValidationError( z.prettifyError( result.error ) );
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Validate step payload
|
|
90
|
+
*
|
|
91
|
+
* @param {object} args - The step arguments
|
|
92
|
+
* @throws {StaticValidationError} Throws if args are invalid
|
|
93
|
+
*/
|
|
94
|
+
export function validateStep( args ) {
|
|
95
|
+
validateAgainstSchema( stepSchema, args );
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Validate evaluator payload
|
|
100
|
+
*
|
|
101
|
+
* @param {object} args - The evaluator arguments
|
|
102
|
+
* @throws {StaticValidationError} Throws if args are invalid
|
|
103
|
+
*/
|
|
104
|
+
export function validateEvaluator( args ) {
|
|
105
|
+
validateAgainstSchema( evaluatorSchema, args );
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Validate workflow payload
|
|
110
|
+
*
|
|
111
|
+
* @param {object} args - The workflow arguments
|
|
112
|
+
* @throws {StaticValidationError} Throws if args are invalid
|
|
113
|
+
*/
|
|
114
|
+
export function validateWorkflow( args ) {
|
|
115
|
+
validateAgainstSchema( workflowSchema, args );
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Validate request payload
|
|
120
|
+
*
|
|
121
|
+
* @param {object} args - The request arguments
|
|
122
|
+
* @throws {StaticValidationError} Throws if args are invalid
|
|
123
|
+
*/
|
|
124
|
+
export function validateRequestPayload( args ) {
|
|
125
|
+
validateAgainstSchema( httpRequestSchema, args );
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Validate executeInParallel
|
|
130
|
+
*
|
|
131
|
+
* @param {object} args - The request arguments
|
|
132
|
+
* @throws {StaticValidationError} Throws if args are invalid
|
|
133
|
+
*/
|
|
134
|
+
export function validateExecuteInParallel( args ) {
|
|
135
|
+
validateAgainstSchema( executeInParallelSchema, args );
|
|
136
|
+
};
|