optio-contracts 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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optio-engine-to-api.d.ts","sourceRoot":"","sources":["../src/optio-engine-to-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+CxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmD9B,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { z } from 'zod';
2
+ import { defineContract, defineMethod, defineNotification } from '@clamator/protocol';
3
+ import { ProcessSchema, ProcessMetadataFilterSchema } from './schemas/process.js';
4
+ import { LaunchFailureReason, CancelFailureReason, DismissFailureReason, GroupCancelFailureReason, BlockLaunchesFailureReason, } from './engine-failure-reasons.js';
5
+ const ProcessIdParam = z.string().min(1);
6
+ const launchResult = z.discriminatedUnion('ok', [
7
+ z.object({ ok: z.literal(true), process: ProcessSchema }),
8
+ z.object({ ok: z.literal(false), reason: LaunchFailureReason }),
9
+ ]);
10
+ const cancelResult = z.discriminatedUnion('ok', [
11
+ z.object({ ok: z.literal(true), process: ProcessSchema }),
12
+ z.object({ ok: z.literal(false), reason: CancelFailureReason }),
13
+ ]);
14
+ const dismissResult = z.discriminatedUnion('ok', [
15
+ z.object({ ok: z.literal(true), process: ProcessSchema }),
16
+ z.object({ ok: z.literal(false), reason: DismissFailureReason }),
17
+ ]);
18
+ const groupCancelResult = z.discriminatedUnion('ok', [
19
+ z.object({ ok: z.literal(true), cancelledCount: z.number().int().nonnegative() }),
20
+ z.object({ ok: z.literal(false), reason: GroupCancelFailureReason }),
21
+ ]);
22
+ const groupCancelAndWaitResult = z.discriminatedUnion('ok', [
23
+ z.object({ ok: z.literal(true), cancelledCount: z.number().int().nonnegative() }),
24
+ z.object({ ok: z.literal(false), reason: GroupCancelFailureReason }),
25
+ ]);
26
+ const blockLaunchesResult = z.discriminatedUnion('ok', [
27
+ z.object({ ok: z.literal(true) }),
28
+ z.object({ ok: z.literal(false), reason: BlockLaunchesFailureReason }),
29
+ ]);
30
+ const unblockLaunchesResult = z.object({
31
+ removed: z.number().int().nonnegative(),
32
+ });
33
+ export const optioEngineContract = defineContract('optio-engine', {
34
+ launch: defineMethod({
35
+ params: z.object({
36
+ processId: ProcessIdParam,
37
+ resume: z.boolean().optional(),
38
+ }),
39
+ result: launchResult,
40
+ }),
41
+ cancel: defineMethod({
42
+ params: z.object({ processId: ProcessIdParam }),
43
+ result: cancelResult,
44
+ }),
45
+ dismiss: defineMethod({
46
+ params: z.object({ processId: ProcessIdParam }),
47
+ result: dismissResult,
48
+ }),
49
+ groupCancel: defineMethod({
50
+ params: z.object({
51
+ metadataFilter: ProcessMetadataFilterSchema,
52
+ blockNewLaunches: z.boolean().optional(),
53
+ persist: z.boolean().optional(),
54
+ reason: z.string().optional(),
55
+ }),
56
+ result: groupCancelResult,
57
+ }),
58
+ groupCancelAndWait: defineMethod({
59
+ params: z.object({
60
+ metadataFilter: ProcessMetadataFilterSchema,
61
+ blockNewLaunches: z.boolean().optional(),
62
+ persist: z.boolean().optional(),
63
+ reason: z.string().optional(),
64
+ }),
65
+ result: groupCancelAndWaitResult,
66
+ }),
67
+ blockLaunches: defineMethod({
68
+ params: z.object({
69
+ launchFilter: ProcessMetadataFilterSchema,
70
+ reason: z.string().optional(),
71
+ }),
72
+ result: blockLaunchesResult,
73
+ }),
74
+ unblockLaunches: defineMethod({
75
+ params: z.object({ launchFilter: ProcessMetadataFilterSchema }),
76
+ result: unblockLaunchesResult,
77
+ }),
78
+ resync: defineNotification({
79
+ params: z.object({
80
+ clean: z.boolean().optional(),
81
+ metadataFilter: ProcessMetadataFilterSchema.optional(),
82
+ }),
83
+ }),
84
+ });
85
+ //# sourceMappingURL=optio-engine-to-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optio-engine-to-api.js","sourceRoot":"","sources":["../src/optio-engine-to-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EACL,mBA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MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAC9B,CAAC;QACF,MAAM,EAAE,mBAAmB;KAC5B,CAAC;IACF,eAAe,EAAE,YAAY,CAAC;QAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,2BAA2B,EAAE,CAAC;QAC/D,MAAM,EAAE,qBAAqB;KAC9B,CAAC;IACF,MAAM,EAAE,kBAAkB,CAAC;QACzB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;YAC7B,cAAc,EAAE,2BAA2B,CAAC,QAAQ,EAAE;SACvD,CAAC;KACH,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const apiToFrontendRouteErrorReasons: {
2
+ readonly 'processes.launch': ["not-found", "not-launchable", "no-resume-support", "launch-blocked"];
3
+ readonly 'processes.cancel': ["not-found", "not-cancellable"];
4
+ readonly 'processes.dismiss': ["not-found", "not-dismissable"];
5
+ };
6
+ export type ApiToFrontendRouteId = keyof typeof apiToFrontendRouteErrorReasons;
7
+ //# sourceMappingURL=route-error-reasons.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-error-reasons.d.ts","sourceRoot":"","sources":["../src/route-error-reasons.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,8BAA8B;;;;CAIjC,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,MAAM,OAAO,8BAA8B,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Cross-package manifest of typed-error routes exposed by the api-to-frontend
2
+ // contract. Consumers (e.g. excavator's frontend `lint:error-coverage`) read
3
+ // this to enforce exhaustive (route, reason) coverage in their error-routing
4
+ // registries for routes the frontend reaches via optio-ui.
5
+ //
6
+ // Only api-to-frontend routes whose responses carry a typed
7
+ // `{reason, message}` body are listed; engine-internal admin RPCs
8
+ // (groupCancel, blockLaunches) are not exposed to the frontend.
9
+ import { LaunchFailureReason, CancelFailureReason, DismissFailureReason, } from './engine-failure-reasons.js';
10
+ export const apiToFrontendRouteErrorReasons = {
11
+ 'processes.launch': LaunchFailureReason.options,
12
+ 'processes.cancel': CancelFailureReason.options,
13
+ 'processes.dismiss': DismissFailureReason.options,
14
+ };
15
+ //# sourceMappingURL=route-error-reasons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-error-reasons.js","sourceRoot":"","sources":["../src/route-error-reasons.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,6EAA6E;AAC7E,2DAA2D;AAC3D,EAAE;AACF,4DAA4D;AAC5D,kEAAkE;AAClE,gEAAgE;AAEhE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAErC,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,kBAAkB,EAAG,mBAAmB,CAAC,OAAO;IAChD,kBAAkB,EAAG,mBAAmB,CAAC,OAAO;IAChD,mBAAmB,EAAE,oBAAoB,CAAC,OAAO;CACzC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+ export declare const ObjectIdSchema: z.ZodString;
3
+ /**
4
+ * Path-parameter schema for routes that look up a process by id. Accepts
5
+ * either form the system uses to identify a process: the Mongo ObjectId hex
6
+ * (24 hex chars) used in `_id`, or the application-level `processId` string
7
+ * produced by `mkPid()` (typically of the form
8
+ * `<project>__<kind>_<resource>_<uuid>`). Resolution to a single document
9
+ * is the handler's responsibility — see `findProcessByEitherId` in optio-api.
10
+ *
11
+ * Why permissive: callers (e.g. excavator's recipe-debug flow) may know the
12
+ * `processId` string before the engine has materialized the row in mongo
13
+ * and assigned an ObjectId. Validating strictly as ObjectId here would
14
+ * 400-reject those callers at the contract layer.
15
+ */
16
+ export declare const ProcessIdParamSchema: z.ZodString;
17
+ export declare const PaginationQuerySchema: z.ZodObject<{
18
+ cursor: z.ZodOptional<z.ZodString>;
19
+ limit: z.ZodDefault<z.ZodNumber>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ limit: number;
22
+ cursor?: string | undefined;
23
+ }, {
24
+ cursor?: string | undefined;
25
+ limit?: number | undefined;
26
+ }>;
27
+ export declare const PaginatedResponseSchema: <T extends z.ZodTypeAny>(itemSchema: T) => z.ZodObject<{
28
+ items: z.ZodArray<T, "many">;
29
+ nextCursor: z.ZodNullable<z.ZodString>;
30
+ totalCount: z.ZodNumber;
31
+ }, "strip", z.ZodTypeAny, {
32
+ items: T["_output"][];
33
+ nextCursor: string | null;
34
+ totalCount: number;
35
+ }, {
36
+ items: T["_input"][];
37
+ nextCursor: string | null;
38
+ totalCount: number;
39
+ }>;
40
+ export declare const ErrorSchema: z.ZodObject<{
41
+ message: z.ZodString;
42
+ }, "strip", z.ZodTypeAny, {
43
+ message: string;
44
+ }, {
45
+ message: string;
46
+ }>;
47
+ export declare const DateSchema: z.ZodDate;
48
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/schemas/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc,aAAyD,CAAC;AAErF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,aAAoB,CAAC;AAEtD,eAAO,MAAM,qBAAqB;;;;;;;;;EAGhC,CAAC;AAEH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC;;;;;;;;;;;;EAKzE,CAAC;AAEL,eAAO,MAAM,WAAW;;;;;;EAEtB,CAAC;AAEH,eAAO,MAAM,UAAU,WAAkB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ export const ObjectIdSchema = z.string().regex(/^[a-f\d]{24}$/i, 'Invalid ObjectId');
3
+ /**
4
+ * Path-parameter schema for routes that look up a process by id. Accepts
5
+ * either form the system uses to identify a process: the Mongo ObjectId hex
6
+ * (24 hex chars) used in `_id`, or the application-level `processId` string
7
+ * produced by `mkPid()` (typically of the form
8
+ * `<project>__<kind>_<resource>_<uuid>`). Resolution to a single document
9
+ * is the handler's responsibility — see `findProcessByEitherId` in optio-api.
10
+ *
11
+ * Why permissive: callers (e.g. excavator's recipe-debug flow) may know the
12
+ * `processId` string before the engine has materialized the row in mongo
13
+ * and assigned an ObjectId. Validating strictly as ObjectId here would
14
+ * 400-reject those callers at the contract layer.
15
+ */
16
+ export const ProcessIdParamSchema = z.string().min(1);
17
+ export const PaginationQuerySchema = z.object({
18
+ cursor: z.string().optional(),
19
+ limit: z.coerce.number().int().min(1).max(100).default(20),
20
+ });
21
+ export const PaginatedResponseSchema = (itemSchema) => z.object({
22
+ items: z.array(itemSchema),
23
+ nextCursor: z.string().nullable(),
24
+ totalCount: z.number().int(),
25
+ });
26
+ export const ErrorSchema = z.object({
27
+ message: z.string(),
28
+ });
29
+ export const DateSchema = z.coerce.date();
30
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/schemas/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;AAErF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;CAC3D,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAyB,UAAa,EAAE,EAAE,CAC/E,CAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;IAC1B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;CAC7B,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC"}
@@ -0,0 +1,172 @@
1
+ import { z } from 'zod';
2
+ export declare const ProcessStateSchema: z.ZodEnum<["idle", "scheduled", "running", "done", "failed", "cancel_requested", "cancelling", "cancelled"]>;
3
+ export declare const LogEntrySchema: z.ZodObject<{
4
+ timestamp: z.ZodDate;
5
+ level: z.ZodEnum<["event", "info", "debug", "warning", "error"]>;
6
+ message: z.ZodString;
7
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ message: string;
10
+ timestamp: Date;
11
+ level: "error" | "event" | "info" | "debug" | "warning";
12
+ data?: Record<string, unknown> | undefined;
13
+ }, {
14
+ message: string;
15
+ timestamp: Date;
16
+ level: "error" | "event" | "info" | "debug" | "warning";
17
+ data?: Record<string, unknown> | undefined;
18
+ }>;
19
+ export declare const ProcessSchema: z.ZodObject<{
20
+ _id: z.ZodString;
21
+ processId: z.ZodString;
22
+ name: z.ZodString;
23
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
24
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
25
+ parentId: z.ZodOptional<z.ZodString>;
26
+ rootId: z.ZodString;
27
+ depth: z.ZodNumber;
28
+ order: z.ZodNumber;
29
+ cancellable: z.ZodBoolean;
30
+ special: z.ZodOptional<z.ZodBoolean>;
31
+ warning: z.ZodOptional<z.ZodString>;
32
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
33
+ status: z.ZodObject<{
34
+ state: z.ZodEnum<["idle", "scheduled", "running", "done", "failed", "cancel_requested", "cancelling", "cancelled"]>;
35
+ error: z.ZodOptional<z.ZodString>;
36
+ runningSince: z.ZodOptional<z.ZodDate>;
37
+ doneAt: z.ZodOptional<z.ZodDate>;
38
+ duration: z.ZodOptional<z.ZodNumber>;
39
+ failedAt: z.ZodOptional<z.ZodDate>;
40
+ stoppedAt: z.ZodOptional<z.ZodDate>;
41
+ }, "strip", z.ZodTypeAny, {
42
+ state: "idle" | "scheduled" | "running" | "done" | "failed" | "cancel_requested" | "cancelling" | "cancelled";
43
+ error?: string | undefined;
44
+ runningSince?: Date | undefined;
45
+ doneAt?: Date | undefined;
46
+ duration?: number | undefined;
47
+ failedAt?: Date | undefined;
48
+ stoppedAt?: Date | undefined;
49
+ }, {
50
+ state: "idle" | "scheduled" | "running" | "done" | "failed" | "cancel_requested" | "cancelling" | "cancelled";
51
+ error?: string | undefined;
52
+ runningSince?: Date | undefined;
53
+ doneAt?: Date | undefined;
54
+ duration?: number | undefined;
55
+ failedAt?: Date | undefined;
56
+ stoppedAt?: Date | undefined;
57
+ }>;
58
+ progress: z.ZodObject<{
59
+ percent: z.ZodNullable<z.ZodNumber>;
60
+ message: z.ZodOptional<z.ZodString>;
61
+ }, "strip", z.ZodTypeAny, {
62
+ percent: number | null;
63
+ message?: string | undefined;
64
+ }, {
65
+ percent: number | null;
66
+ message?: string | undefined;
67
+ }>;
68
+ log: z.ZodArray<z.ZodObject<{
69
+ timestamp: z.ZodDate;
70
+ level: z.ZodEnum<["event", "info", "debug", "warning", "error"]>;
71
+ message: z.ZodString;
72
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
73
+ }, "strip", z.ZodTypeAny, {
74
+ message: string;
75
+ timestamp: Date;
76
+ level: "error" | "event" | "info" | "debug" | "warning";
77
+ data?: Record<string, unknown> | undefined;
78
+ }, {
79
+ message: string;
80
+ timestamp: Date;
81
+ level: "error" | "event" | "info" | "debug" | "warning";
82
+ data?: Record<string, unknown> | undefined;
83
+ }>, "many">;
84
+ uiWidget: z.ZodOptional<z.ZodNullable<z.ZodString>>;
85
+ widgetData: z.ZodOptional<z.ZodUnknown>;
86
+ supportsResume: z.ZodOptional<z.ZodBoolean>;
87
+ hasSavedState: z.ZodOptional<z.ZodBoolean>;
88
+ createdAt: z.ZodDate;
89
+ }, "strip", z.ZodTypeAny, {
90
+ status: {
91
+ state: "idle" | "scheduled" | "running" | "done" | "failed" | "cancel_requested" | "cancelling" | "cancelled";
92
+ error?: string | undefined;
93
+ runningSince?: Date | undefined;
94
+ doneAt?: Date | undefined;
95
+ duration?: number | undefined;
96
+ failedAt?: Date | undefined;
97
+ stoppedAt?: Date | undefined;
98
+ };
99
+ _id: string;
100
+ processId: string;
101
+ name: string;
102
+ rootId: string;
103
+ depth: number;
104
+ order: number;
105
+ cancellable: boolean;
106
+ progress: {
107
+ percent: number | null;
108
+ message?: string | undefined;
109
+ };
110
+ log: {
111
+ message: string;
112
+ timestamp: Date;
113
+ level: "error" | "event" | "info" | "debug" | "warning";
114
+ data?: Record<string, unknown> | undefined;
115
+ }[];
116
+ createdAt: Date;
117
+ params?: Record<string, unknown> | undefined;
118
+ warning?: string | undefined;
119
+ metadata?: Record<string, unknown> | undefined;
120
+ parentId?: string | undefined;
121
+ special?: boolean | undefined;
122
+ description?: string | null | undefined;
123
+ uiWidget?: string | null | undefined;
124
+ widgetData?: unknown;
125
+ supportsResume?: boolean | undefined;
126
+ hasSavedState?: boolean | undefined;
127
+ }, {
128
+ status: {
129
+ state: "idle" | "scheduled" | "running" | "done" | "failed" | "cancel_requested" | "cancelling" | "cancelled";
130
+ error?: string | undefined;
131
+ runningSince?: Date | undefined;
132
+ doneAt?: Date | undefined;
133
+ duration?: number | undefined;
134
+ failedAt?: Date | undefined;
135
+ stoppedAt?: Date | undefined;
136
+ };
137
+ _id: string;
138
+ processId: string;
139
+ name: string;
140
+ rootId: string;
141
+ depth: number;
142
+ order: number;
143
+ cancellable: boolean;
144
+ progress: {
145
+ percent: number | null;
146
+ message?: string | undefined;
147
+ };
148
+ log: {
149
+ message: string;
150
+ timestamp: Date;
151
+ level: "error" | "event" | "info" | "debug" | "warning";
152
+ data?: Record<string, unknown> | undefined;
153
+ }[];
154
+ createdAt: Date;
155
+ params?: Record<string, unknown> | undefined;
156
+ warning?: string | undefined;
157
+ metadata?: Record<string, unknown> | undefined;
158
+ parentId?: string | undefined;
159
+ special?: boolean | undefined;
160
+ description?: string | null | undefined;
161
+ uiWidget?: string | null | undefined;
162
+ widgetData?: unknown;
163
+ supportsResume?: boolean | undefined;
164
+ hasSavedState?: boolean | undefined;
165
+ }>;
166
+ export declare const ProcessMetadataFilterSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
167
+ export declare const MetadataFilterQueryParamSchema: z.ZodOptional<z.ZodPipeline<z.ZodEffects<z.ZodString, any, string>, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
168
+ export type Process = z.infer<typeof ProcessSchema>;
169
+ export type ProcessState = z.infer<typeof ProcessStateSchema>;
170
+ export type LogEntry = z.infer<typeof LogEntrySchema>;
171
+ export type ProcessMetadataFilter = z.infer<typeof ProcessMetadataFilterSchema>;
172
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/schemas/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,kBAAkB,8GAG7B,CAAC;AAiBH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;EAKzB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCxB,CAAC;AAEH,eAAO,MAAM,2BAA2B,wCAAwB,CAAC;AAEjE,eAAO,MAAM,8BAA8B,8GAW9B,CAAC;AAEd,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AACtD,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod';
2
+ import { ObjectIdSchema, DateSchema } from './common.js';
3
+ export const ProcessStateSchema = z.enum([
4
+ 'idle', 'scheduled', 'running', 'done', 'failed',
5
+ 'cancel_requested', 'cancelling', 'cancelled',
6
+ ]);
7
+ const ProcessStatusSchema = z.object({
8
+ state: ProcessStateSchema,
9
+ error: z.string().optional(),
10
+ runningSince: DateSchema.optional(),
11
+ doneAt: DateSchema.optional(),
12
+ duration: z.number().optional(),
13
+ failedAt: DateSchema.optional(),
14
+ stoppedAt: DateSchema.optional(),
15
+ });
16
+ const ProgressSchema = z.object({
17
+ percent: z.number().min(0).max(100).nullable(),
18
+ message: z.string().optional(),
19
+ });
20
+ export const LogEntrySchema = z.object({
21
+ timestamp: DateSchema,
22
+ level: z.enum(['event', 'info', 'debug', 'warning', 'error']),
23
+ message: z.string(),
24
+ data: z.record(z.unknown()).optional(),
25
+ });
26
+ export const ProcessSchema = z.object({
27
+ _id: ObjectIdSchema,
28
+ processId: z.string(),
29
+ name: z.string(),
30
+ params: z.record(z.unknown()).optional(),
31
+ metadata: z.record(z.unknown()).optional(),
32
+ // Tree structure
33
+ parentId: ObjectIdSchema.optional(),
34
+ rootId: ObjectIdSchema,
35
+ depth: z.number().int().min(0),
36
+ order: z.number().int().min(0),
37
+ // Definition metadata
38
+ cancellable: z.boolean(),
39
+ special: z.boolean().optional(),
40
+ warning: z.string().optional(),
41
+ description: z.string().nullable().optional(),
42
+ // Runtime
43
+ status: ProcessStatusSchema,
44
+ progress: ProgressSchema,
45
+ log: z.array(LogEntrySchema),
46
+ // Widget extensions (widgetUpstream is server-side only and must never appear here)
47
+ uiWidget: z.string().nullable().optional(),
48
+ widgetData: z.unknown().optional(),
49
+ // Resume feature — default false when absent in stored doc (UI treats
50
+ // missing fields as false defensively)
51
+ supportsResume: z.boolean().optional(),
52
+ hasSavedState: z.boolean().optional(),
53
+ createdAt: DateSchema,
54
+ });
55
+ export const ProcessMetadataFilterSchema = z.record(z.unknown());
56
+ export const MetadataFilterQueryParamSchema = z
57
+ .string()
58
+ .transform((s, ctx) => {
59
+ try {
60
+ return JSON.parse(s);
61
+ }
62
+ catch {
63
+ ctx.addIssue({ code: 'custom', message: 'metadataFilter must be valid JSON' });
64
+ return z.NEVER;
65
+ }
66
+ })
67
+ .pipe(ProcessMetadataFilterSchema)
68
+ .optional();
69
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/schemas/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,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CACtB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC;KAC5C,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;IACpB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,mCAAmC,EAAE,CAAC,CAAC;QAC/E,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;AACH,CAAC,CAAC;KACD,IAAI,CAAC,2BAA2B,CAAC;KACjC,QAAQ,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "optio-contracts",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "description": "Shared wire-protocol types and ts-rest contracts for the optio task runner.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/deai-network/optio.git",
9
+ "directory": "packages/optio-contracts"
10
+ },
11
+ "homepage": "https://github.com/deai-network/optio/tree/main/packages/optio-contracts#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/deai-network/optio/issues"
14
+ },
15
+ "author": "Kristof Csillag <kristof.csillag@deai-labs.com>",
16
+ "type": "module",
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.js",
27
+ "types": "./dist/index.d.ts"
28
+ },
29
+ "./optio-engine": {
30
+ "import": "./dist/optio-engine-to-api.js",
31
+ "types": "./dist/optio-engine-to-api.d.ts"
32
+ }
33
+ },
34
+ "dependencies": {
35
+ "@clamator/protocol": "^0.1.9",
36
+ "@ts-rest/core": "^3.51.0",
37
+ "zod": "^3.24.0"
38
+ },
39
+ "devDependencies": {
40
+ "typescript": "^5.7.0",
41
+ "vitest": "^3.0.0"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "dev": "tsc --watch",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest"
48
+ }
49
+ }