arvo-core 1.1.15 → 1.1.16
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -0
- package/dist/ArvoContract/helpers.js +6 -2
- package/dist/ArvoOrchestratorContract/helpers.d.ts +43 -7
- package/dist/ArvoOrchestratorContract/helpers.js +37 -5
- package/dist/ArvoOrchestratorContract/schema.d.ts +13 -0
- package/dist/ArvoOrchestratorContract/schema.js +18 -0
- package/dist/ArvoOrchestratorContract/typegen.js +9 -3
- package/dist/index.d.ts +9 -1
- package/dist/index.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -34,8 +34,12 @@ var utils_1 = require("../utils");
|
|
34
34
|
* });
|
35
35
|
*/
|
36
36
|
var createArvoContract = function (contract) {
|
37
|
-
var createErrorMessage = function (source, type) {
|
38
|
-
|
37
|
+
var createErrorMessage = function (source, type) {
|
38
|
+
return (0, utils_1.cleanString)("\n In contract (uri=".concat(contract.uri, "), the '").concat(source, "' event (type=").concat(type, ") must not start \n with '").concat(typegen_1.ArvoOrchestratorEventTypeGen.__prefix, "' becuase this a reserved pattern \n for Arvo orchestrators.\n "));
|
39
|
+
};
|
40
|
+
var validator = function (value) {
|
41
|
+
return value.startsWith(typegen_1.ArvoOrchestratorEventTypeGen.__prefix);
|
42
|
+
};
|
39
43
|
if (validator(contract.accepts.type)) {
|
40
44
|
throw new Error(createErrorMessage('accepts', contract.accepts.type));
|
41
45
|
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { z } from
|
2
|
-
import { ICreateArvoOrchestratorContract } from
|
3
|
-
import ArvoOrchestratorContract from
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { ICreateArvoOrchestratorContract } from './types';
|
3
|
+
import ArvoOrchestratorContract from '.';
|
4
4
|
/**
|
5
5
|
* Creates an ArvoOrchestratorContract with specified parameters.
|
6
6
|
*
|
@@ -10,22 +10,58 @@ import ArvoOrchestratorContract from ".";
|
|
10
10
|
*
|
11
11
|
* Key features:
|
12
12
|
* 1. Initialization: Defines the structure and validation for the initial event that starts the orchestration.
|
13
|
+
* The init schema is automatically intersected with OrchestrationInitEventBaseSchema.
|
13
14
|
* 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
|
14
15
|
* 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
|
15
16
|
* 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
|
16
17
|
*
|
18
|
+
* Base Schema:
|
19
|
+
* The OrchestrationInitEventBaseSchema is automatically intersected with the user-provided init schema.
|
20
|
+
* This base schema includes essential fields for orchestration, such as:
|
21
|
+
* - parentSubject$$: Identifies the subject of the parent process or event in the ArvoEvent system.
|
22
|
+
*
|
17
23
|
* This contract serves as a crucial component in maintaining consistency and type safety
|
18
24
|
* throughout the orchestration process, from initiation to completion.
|
19
25
|
*
|
20
26
|
* @param param - The configuration object for creating the contract.
|
21
27
|
* @param param.uri - The URI for the contract.
|
22
|
-
* @param param.name - The name of the contract (must be alphanumeric).
|
28
|
+
* @param param.name - The name of the contract (must be lowercase alphanumeric with dots).
|
23
29
|
* @param param.schema - The schema object containing init and complete Zod schemas.
|
24
|
-
* @param param.schema.init - The Zod schema for initialization.
|
30
|
+
* @param param.schema.init - The Zod schema for initialization (will be intersected with OrchestrationInitEventBaseSchema).
|
25
31
|
* @param param.schema.complete - The Zod schema for completion.
|
26
32
|
*
|
27
|
-
* @throws {Error} Throws an error if the name is not alphanumeric.
|
33
|
+
* @throws {Error} Throws an error if the name is not lowercase alphanumeric with dots.
|
28
34
|
*
|
29
35
|
* @returns Returns a new ArvoOrchestratorContract instance with the specified parameters.
|
36
|
+
*
|
37
|
+
* @example
|
38
|
+
* ```typescript
|
39
|
+
* import { createArvoOrchestratorContract } from 'arvo-core'
|
40
|
+
* import { z } from 'zod'
|
41
|
+
*
|
42
|
+
* const contract = createArvoOrchestratorContract({
|
43
|
+
* uri: '#/example/contract',
|
44
|
+
* name: 'rag.orchestrator',
|
45
|
+
* schema: {
|
46
|
+
* init: z.object({
|
47
|
+
* request: z.string(),
|
48
|
+
* vectorStore: z.string(),
|
49
|
+
* llm: z.string()
|
50
|
+
* }),
|
51
|
+
* complete: z.object({
|
52
|
+
* response: z.string()
|
53
|
+
* })
|
54
|
+
* }
|
55
|
+
* })
|
56
|
+
* ```
|
57
|
+
*
|
58
|
+
* In this example, the actual init schema will be an intersection of the provided schema
|
59
|
+
* and the OrchestrationInitEventBaseSchema, ensuring all necessary fields are included.
|
30
60
|
*/
|
31
|
-
export declare const createArvoOrchestratorContract: <TUri extends string, TName extends string, TInit extends z.ZodTypeAny, TComplete extends z.ZodTypeAny>(param: ICreateArvoOrchestratorContract<TUri, TName, TInit, TComplete>) => ArvoOrchestratorContract<TUri, `arvo.orc.${TName}`,
|
61
|
+
export declare const createArvoOrchestratorContract: <TUri extends string, TName extends string, TInit extends z.ZodTypeAny, TComplete extends z.ZodTypeAny>(param: ICreateArvoOrchestratorContract<TUri, TName, TInit, TComplete>) => ArvoOrchestratorContract<TUri, `arvo.orc.${TName}`, z.ZodIntersection<z.ZodObject<{
|
62
|
+
parentSubject$$: z.ZodNullable<z.ZodString>;
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
64
|
+
parentSubject$$: string | null;
|
65
|
+
}, {
|
66
|
+
parentSubject$$: string | null;
|
67
|
+
}>, TInit>, `arvo.orc.${TName}.done`, TComplete>;
|
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.createArvoOrchestratorContract = void 0;
|
7
|
+
var zod_1 = require("zod");
|
7
8
|
var _1 = __importDefault(require("."));
|
8
9
|
var typegen_1 = require("./typegen");
|
10
|
+
var schema_1 = require("./schema");
|
9
11
|
/**
|
10
12
|
* Validates if a string contains only uppercase or lowercase alphanumeric characters.
|
11
13
|
*
|
@@ -32,23 +34,53 @@ function isLowerAlphanumeric(input) {
|
|
32
34
|
*
|
33
35
|
* Key features:
|
34
36
|
* 1. Initialization: Defines the structure and validation for the initial event that starts the orchestration.
|
37
|
+
* The init schema is automatically intersected with OrchestrationInitEventBaseSchema.
|
35
38
|
* 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
|
36
39
|
* 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
|
37
40
|
* 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
|
38
41
|
*
|
42
|
+
* Base Schema:
|
43
|
+
* The OrchestrationInitEventBaseSchema is automatically intersected with the user-provided init schema.
|
44
|
+
* This base schema includes essential fields for orchestration, such as:
|
45
|
+
* - parentSubject$$: Identifies the subject of the parent process or event in the ArvoEvent system.
|
46
|
+
*
|
39
47
|
* This contract serves as a crucial component in maintaining consistency and type safety
|
40
48
|
* throughout the orchestration process, from initiation to completion.
|
41
49
|
*
|
42
50
|
* @param param - The configuration object for creating the contract.
|
43
51
|
* @param param.uri - The URI for the contract.
|
44
|
-
* @param param.name - The name of the contract (must be alphanumeric).
|
52
|
+
* @param param.name - The name of the contract (must be lowercase alphanumeric with dots).
|
45
53
|
* @param param.schema - The schema object containing init and complete Zod schemas.
|
46
|
-
* @param param.schema.init - The Zod schema for initialization.
|
54
|
+
* @param param.schema.init - The Zod schema for initialization (will be intersected with OrchestrationInitEventBaseSchema).
|
47
55
|
* @param param.schema.complete - The Zod schema for completion.
|
48
56
|
*
|
49
|
-
* @throws {Error} Throws an error if the name is not alphanumeric.
|
57
|
+
* @throws {Error} Throws an error if the name is not lowercase alphanumeric with dots.
|
50
58
|
*
|
51
59
|
* @returns Returns a new ArvoOrchestratorContract instance with the specified parameters.
|
60
|
+
*
|
61
|
+
* @example
|
62
|
+
* ```typescript
|
63
|
+
* import { createArvoOrchestratorContract } from 'arvo-core'
|
64
|
+
* import { z } from 'zod'
|
65
|
+
*
|
66
|
+
* const contract = createArvoOrchestratorContract({
|
67
|
+
* uri: '#/example/contract',
|
68
|
+
* name: 'rag.orchestrator',
|
69
|
+
* schema: {
|
70
|
+
* init: z.object({
|
71
|
+
* request: z.string(),
|
72
|
+
* vectorStore: z.string(),
|
73
|
+
* llm: z.string()
|
74
|
+
* }),
|
75
|
+
* complete: z.object({
|
76
|
+
* response: z.string()
|
77
|
+
* })
|
78
|
+
* }
|
79
|
+
* })
|
80
|
+
* ```
|
81
|
+
*
|
82
|
+
* In this example, the actual init schema will be an intersection of the provided schema
|
83
|
+
* and the OrchestrationInitEventBaseSchema, ensuring all necessary fields are included.
|
52
84
|
*/
|
53
85
|
var createArvoOrchestratorContract = function (param) {
|
54
86
|
if (!isLowerAlphanumeric(param.name)) {
|
@@ -58,12 +90,12 @@ var createArvoOrchestratorContract = function (param) {
|
|
58
90
|
uri: param.uri,
|
59
91
|
init: {
|
60
92
|
type: typegen_1.ArvoOrchestratorEventTypeGen.init(param.name),
|
61
|
-
schema: param.schema.init,
|
93
|
+
schema: zod_1.z.intersection(schema_1.OrchestrationInitEventBaseSchema, param.schema.init),
|
62
94
|
},
|
63
95
|
complete: {
|
64
96
|
type: typegen_1.ArvoOrchestratorEventTypeGen.complete(param.name),
|
65
97
|
schema: param.schema.complete,
|
66
|
-
}
|
98
|
+
},
|
67
99
|
});
|
68
100
|
};
|
69
101
|
exports.createArvoOrchestratorContract = createArvoOrchestratorContract;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
/**
|
3
|
+
* Defines the base schema for orchestrator acceptance in the context of ArvoEvents.
|
4
|
+
* This schema is used to validate and type-check the minimal required fields
|
5
|
+
* for an orchestrator to accept a task or event.
|
6
|
+
*/
|
7
|
+
export declare const OrchestrationInitEventBaseSchema: z.ZodObject<{
|
8
|
+
parentSubject$$: z.ZodNullable<z.ZodString>;
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
10
|
+
parentSubject$$: string | null;
|
11
|
+
}, {
|
12
|
+
parentSubject$$: string | null;
|
13
|
+
}>;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.OrchestrationInitEventBaseSchema = void 0;
|
4
|
+
var zod_1 = require("zod");
|
5
|
+
var utils_1 = require("../utils");
|
6
|
+
/**
|
7
|
+
* Defines the base schema for orchestrator acceptance in the context of ArvoEvents.
|
8
|
+
* This schema is used to validate and type-check the minimal required fields
|
9
|
+
* for an orchestrator to accept a task or event.
|
10
|
+
*/
|
11
|
+
exports.OrchestrationInitEventBaseSchema = zod_1.z
|
12
|
+
.object({
|
13
|
+
parentSubject$$: zod_1.z
|
14
|
+
.string()
|
15
|
+
.min(1, 'The parent subject must not be an empty string')
|
16
|
+
.nullable()
|
17
|
+
.describe((0, utils_1.cleanString)("\n Identifies the subject of the parent process or event in the ArvoEvent system.\n \n Purpose:\n 1. Enables the orchestrator to return its final output to the initiating process or orchestrator.\n 2. Maintains the event chain and process hierarchy in a distributed system.\n 3. Facilitates proper event routing and traceability.\n \n Usage:\n - For non-root processes: Set to the subject of the parent process/orchestrator.\n - For root processes/orchestrations: Must be set to null.\n \n This field aligns with the ArvoEvent 'subject' field, which is a URI identifying the event's subject.\n It plays a crucial role in distributed tracing, debugging, and maintaining system coherence.\n \n Example:\n - Parent process subject: \"process/parent-id-123\"\n - Child process parentSubject$$: \"process/parent-id-123\"\n \n Note: Ensure this value is a valid URI as per ArvoEvent specifications.\n ")),
|
18
|
+
});
|
@@ -3,7 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArvoOrchestratorEventTypeGen = void 0;
|
4
4
|
exports.ArvoOrchestratorEventTypeGen = {
|
5
5
|
__prefix: "arvo.orc",
|
6
|
-
init: function (name) {
|
7
|
-
|
8
|
-
|
6
|
+
init: function (name) {
|
7
|
+
return "".concat(exports.ArvoOrchestratorEventTypeGen.__prefix, ".").concat(name);
|
8
|
+
},
|
9
|
+
complete: function (name) {
|
10
|
+
return "".concat(exports.ArvoOrchestratorEventTypeGen.init(name), ".done");
|
11
|
+
},
|
12
|
+
systemError: function (name) {
|
13
|
+
return "sys.".concat(exports.ArvoOrchestratorEventTypeGen.init(name), ".error");
|
14
|
+
},
|
9
15
|
};
|
package/dist/index.d.ts
CHANGED
@@ -35,6 +35,7 @@ import { ArvoOrchestratorEventTypeGen } from './ArvoOrchestratorContract/typegen
|
|
35
35
|
* @property {z.ZodRecord} ArvoDataSchema - Schema for Arvo event data payload.
|
36
36
|
* @property {z.ZodObject} ArvoExtensionSchema - Schema for Arvo-specific CloudEvent extensions.
|
37
37
|
* @property {z.ZodObject} OpenTelemetryExtensionSchema - Schema for OpenTelemetry extensions.
|
38
|
+
* @property {z.ZodObject} OrchestrationInitEventBaseSchema - The base schema for the orchestrator init events.
|
38
39
|
*/
|
39
40
|
declare const ArvoEventSchemas: {
|
40
41
|
CloudEventContextSchema: import("zod").ZodObject<{
|
@@ -93,5 +94,12 @@ declare const ArvoEventSchemas: {
|
|
93
94
|
traceparent: string | null;
|
94
95
|
tracestate: string | null;
|
95
96
|
}>;
|
97
|
+
OrchestrationInitEventBaseSchema: import("zod").ZodObject<{
|
98
|
+
parentSubject$$: import("zod").ZodNullable<import("zod").ZodString>;
|
99
|
+
}, "strip", import("zod").ZodTypeAny, {
|
100
|
+
parentSubject$$: string | null;
|
101
|
+
}, {
|
102
|
+
parentSubject$$: string | null;
|
103
|
+
}>;
|
96
104
|
};
|
97
|
-
export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOrchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOrchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, createArvoOrchestratorContract, ArvoOrchestratorContract, ICreateArvoOrchestratorContract, IArvoOrchestratorContract, InferArvoOrchestratorContract, ArvoOrchestratorEventTypeGen };
|
105
|
+
export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOrchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOrchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, createArvoOrchestratorContract, ArvoOrchestratorContract, ICreateArvoOrchestratorContract, IArvoOrchestratorContract, InferArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, };
|
package/dist/index.js
CHANGED
@@ -55,6 +55,7 @@ var ArvoOrchestratorContract_1 = __importDefault(require("./ArvoOrchestratorCont
|
|
55
55
|
exports.ArvoOrchestratorContract = ArvoOrchestratorContract_1.default;
|
56
56
|
var typegen_1 = require("./ArvoOrchestratorContract/typegen");
|
57
57
|
Object.defineProperty(exports, "ArvoOrchestratorEventTypeGen", { enumerable: true, get: function () { return typegen_1.ArvoOrchestratorEventTypeGen; } });
|
58
|
+
var schema_4 = require("./ArvoOrchestratorContract/schema");
|
58
59
|
/**
|
59
60
|
* Collection of Zod schemas for validating various aspects of Arvo events.
|
60
61
|
* @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
|
@@ -62,6 +63,7 @@ Object.defineProperty(exports, "ArvoOrchestratorEventTypeGen", { enumerable: tru
|
|
62
63
|
* @property {z.ZodRecord} ArvoDataSchema - Schema for Arvo event data payload.
|
63
64
|
* @property {z.ZodObject} ArvoExtensionSchema - Schema for Arvo-specific CloudEvent extensions.
|
64
65
|
* @property {z.ZodObject} OpenTelemetryExtensionSchema - Schema for OpenTelemetry extensions.
|
66
|
+
* @property {z.ZodObject} OrchestrationInitEventBaseSchema - The base schema for the orchestrator init events.
|
65
67
|
*/
|
66
68
|
var ArvoEventSchemas = {
|
67
69
|
CloudEventContextSchema: schema_1.CloudEventContextSchema,
|
@@ -69,5 +71,6 @@ var ArvoEventSchemas = {
|
|
69
71
|
ArvoDataSchema: schema_1.ArvoDataSchema,
|
70
72
|
ArvoExtensionSchema: schema_1.ArvoExtensionSchema,
|
71
73
|
OpenTelemetryExtensionSchema: schema_1.OpenTelemetryExtensionSchema,
|
74
|
+
OrchestrationInitEventBaseSchema: schema_4.OrchestrationInitEventBaseSchema,
|
72
75
|
};
|
73
76
|
exports.ArvoEventSchemas = ArvoEventSchemas;
|