@livetronics/wocul-domain 0.0.0-stage → 1.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/README.md +91 -2
- package/dist/api/generated.d.ts +39302 -0
- package/dist/api/generated.js +2 -0
- package/dist/api/index.d.ts +37 -0
- package/dist/api/index.js +2 -0
- package/dist/channels.d.ts +31 -0
- package/dist/channels.js +34 -0
- package/dist/events/data.d.ts +427 -0
- package/dist/events/data.js +154 -0
- package/dist/events/message.d.ts +188 -0
- package/dist/events/message.js +99 -0
- package/dist/events/types.d.ts +27 -0
- package/dist/events/types.js +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +45 -0
- package/dist/intents.d.ts +305 -0
- package/dist/intents.js +149 -0
- package/package.json +40 -5
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { IntentType } from './events/types';
|
|
3
|
+
/**
|
|
4
|
+
* Intents: outbox rows core-ts's relay sends to one service's Redis stream
|
|
5
|
+
* (XADD, field `e`) instead of a channel. Each wakes its consumer to claim a
|
|
6
|
+
* queue row; the row stays the record (core-ts docs/realtime-events.md
|
|
7
|
+
* § Intents).
|
|
8
|
+
*/
|
|
9
|
+
export declare const INTENT_STREAMS: {
|
|
10
|
+
readonly notification: "wocul:intents:notification";
|
|
11
|
+
readonly email: "wocul:intents:email";
|
|
12
|
+
readonly worker: "wocul:intents:worker";
|
|
13
|
+
readonly agent: "wocul:intents:agent";
|
|
14
|
+
};
|
|
15
|
+
export type IntentStream = (typeof INTENT_STREAMS)[keyof typeof INTENT_STREAMS];
|
|
16
|
+
export declare const INTENT_STREAM_OF: Record<IntentType, IntentStream>;
|
|
17
|
+
/** The stream entry field holding the JSON message. */
|
|
18
|
+
export declare const INTENT_FIELD = "e";
|
|
19
|
+
/**
|
|
20
|
+
* Intent payloads. A consumer needs only `queueId` to claim the row, so that
|
|
21
|
+
* is the one required field; the content is a convenience and may be absent
|
|
22
|
+
* (`truncated`). Unknown fields pass through.
|
|
23
|
+
*/
|
|
24
|
+
export declare const intentPayloadSchemas: {
|
|
25
|
+
'notification.requested': z.ZodObject<{
|
|
26
|
+
queueId: z.ZodString;
|
|
27
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
29
|
+
category: z.ZodOptional<z.ZodString>;
|
|
30
|
+
eventType: z.ZodOptional<z.ZodString>;
|
|
31
|
+
projectName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
recipients: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
33
|
+
idStaff: z.ZodNumber;
|
|
34
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
36
|
+
idStaff: z.ZodNumber;
|
|
37
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
39
|
+
idStaff: z.ZodNumber;
|
|
40
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
42
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
43
|
+
navigation: z.ZodOptional<z.ZodUnknown>;
|
|
44
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
45
|
+
language: z.ZodOptional<z.ZodString>;
|
|
46
|
+
channels: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
47
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
49
|
+
queueId: z.ZodString;
|
|
50
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
51
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
52
|
+
category: z.ZodOptional<z.ZodString>;
|
|
53
|
+
eventType: z.ZodOptional<z.ZodString>;
|
|
54
|
+
projectName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
55
|
+
recipients: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
56
|
+
idStaff: z.ZodNumber;
|
|
57
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
59
|
+
idStaff: z.ZodNumber;
|
|
60
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
62
|
+
idStaff: z.ZodNumber;
|
|
63
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
65
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
66
|
+
navigation: z.ZodOptional<z.ZodUnknown>;
|
|
67
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
68
|
+
language: z.ZodOptional<z.ZodString>;
|
|
69
|
+
channels: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
70
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
71
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
72
|
+
queueId: z.ZodString;
|
|
73
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
74
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
75
|
+
category: z.ZodOptional<z.ZodString>;
|
|
76
|
+
eventType: z.ZodOptional<z.ZodString>;
|
|
77
|
+
projectName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
78
|
+
recipients: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
79
|
+
idStaff: z.ZodNumber;
|
|
80
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
82
|
+
idStaff: z.ZodNumber;
|
|
83
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
84
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
85
|
+
idStaff: z.ZodNumber;
|
|
86
|
+
recipientType: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
88
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
89
|
+
navigation: z.ZodOptional<z.ZodUnknown>;
|
|
90
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
91
|
+
language: z.ZodOptional<z.ZodString>;
|
|
92
|
+
channels: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
93
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
94
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
95
|
+
'email.requested': z.ZodObject<{
|
|
96
|
+
queueId: z.ZodString;
|
|
97
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
99
|
+
category: z.ZodOptional<z.ZodString>;
|
|
100
|
+
subCategory: z.ZodOptional<z.ZodString>;
|
|
101
|
+
eventType: z.ZodOptional<z.ZodString>;
|
|
102
|
+
recipients: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
103
|
+
/** Null for an invite to someone without an account. */
|
|
104
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
105
|
+
email: z.ZodString;
|
|
106
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
107
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
108
|
+
/** Null for an invite to someone without an account. */
|
|
109
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
110
|
+
email: z.ZodString;
|
|
111
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
112
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
113
|
+
/** Null for an invite to someone without an account. */
|
|
114
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
115
|
+
email: z.ZodString;
|
|
116
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
117
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
118
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
119
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
120
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
121
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
122
|
+
queueId: z.ZodString;
|
|
123
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
124
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
125
|
+
category: z.ZodOptional<z.ZodString>;
|
|
126
|
+
subCategory: z.ZodOptional<z.ZodString>;
|
|
127
|
+
eventType: z.ZodOptional<z.ZodString>;
|
|
128
|
+
recipients: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
129
|
+
/** Null for an invite to someone without an account. */
|
|
130
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
131
|
+
email: z.ZodString;
|
|
132
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
133
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
134
|
+
/** Null for an invite to someone without an account. */
|
|
135
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
136
|
+
email: z.ZodString;
|
|
137
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
138
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
139
|
+
/** Null for an invite to someone without an account. */
|
|
140
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
141
|
+
email: z.ZodString;
|
|
142
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
143
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
144
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
145
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
146
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
147
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
148
|
+
queueId: z.ZodString;
|
|
149
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
150
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
151
|
+
category: z.ZodOptional<z.ZodString>;
|
|
152
|
+
subCategory: z.ZodOptional<z.ZodString>;
|
|
153
|
+
eventType: z.ZodOptional<z.ZodString>;
|
|
154
|
+
recipients: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
155
|
+
/** Null for an invite to someone without an account. */
|
|
156
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
157
|
+
email: z.ZodString;
|
|
158
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
159
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
160
|
+
/** Null for an invite to someone without an account. */
|
|
161
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
162
|
+
email: z.ZodString;
|
|
163
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
164
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
165
|
+
/** Null for an invite to someone without an account. */
|
|
166
|
+
idStaff: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
167
|
+
email: z.ZodString;
|
|
168
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
169
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
170
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
171
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
172
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
173
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
174
|
+
'aicomment.requested': z.ZodObject<{
|
|
175
|
+
queueId: z.ZodString;
|
|
176
|
+
idTask: z.ZodNumber;
|
|
177
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
178
|
+
queueId: z.ZodString;
|
|
179
|
+
idTask: z.ZodNumber;
|
|
180
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
181
|
+
queueId: z.ZodString;
|
|
182
|
+
idTask: z.ZodNumber;
|
|
183
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
184
|
+
'kbproposal.requested': z.ZodObject<{
|
|
185
|
+
queueId: z.ZodString;
|
|
186
|
+
idAgentRun: z.ZodNumber;
|
|
187
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
188
|
+
queueId: z.ZodString;
|
|
189
|
+
idAgentRun: z.ZodNumber;
|
|
190
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
191
|
+
queueId: z.ZodString;
|
|
192
|
+
idAgentRun: z.ZodNumber;
|
|
193
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
194
|
+
'run.requested': z.ZodObject<{
|
|
195
|
+
queueId: z.ZodString;
|
|
196
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
197
|
+
idAgentRun: z.ZodNumber;
|
|
198
|
+
idTask: z.ZodNumber;
|
|
199
|
+
triggerType: z.ZodOptional<z.ZodString>;
|
|
200
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
201
|
+
seeded: z.ZodOptional<z.ZodBoolean>;
|
|
202
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
203
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
204
|
+
queueId: z.ZodString;
|
|
205
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
206
|
+
idAgentRun: z.ZodNumber;
|
|
207
|
+
idTask: z.ZodNumber;
|
|
208
|
+
triggerType: z.ZodOptional<z.ZodString>;
|
|
209
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
210
|
+
seeded: z.ZodOptional<z.ZodBoolean>;
|
|
211
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
212
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
213
|
+
queueId: z.ZodString;
|
|
214
|
+
idempotencyKey: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
215
|
+
idAgentRun: z.ZodNumber;
|
|
216
|
+
idTask: z.ZodNumber;
|
|
217
|
+
triggerType: z.ZodOptional<z.ZodString>;
|
|
218
|
+
priority: z.ZodOptional<z.ZodString>;
|
|
219
|
+
seeded: z.ZodOptional<z.ZodBoolean>;
|
|
220
|
+
scheduledFor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
221
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
222
|
+
};
|
|
223
|
+
export type IntentPayload<T extends IntentType> = z.infer<(typeof intentPayloadSchemas)[T]>;
|
|
224
|
+
/**
|
|
225
|
+
* The envelope core-ts's relay writes to a stream entry, as JSON under
|
|
226
|
+
* `INTENT_FIELD`; the payload above is its `data`.
|
|
227
|
+
*/
|
|
228
|
+
export declare const intentMessageSchema: z.ZodObject<{
|
|
229
|
+
eventId: z.ZodString;
|
|
230
|
+
type: z.ZodString;
|
|
231
|
+
idOrganisation: z.ZodNumber;
|
|
232
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
233
|
+
entity: z.ZodObject<{
|
|
234
|
+
type: z.ZodString;
|
|
235
|
+
id: z.ZodString;
|
|
236
|
+
}, "strip", z.ZodTypeAny, {
|
|
237
|
+
type: string;
|
|
238
|
+
id: string;
|
|
239
|
+
}, {
|
|
240
|
+
type: string;
|
|
241
|
+
id: string;
|
|
242
|
+
}>;
|
|
243
|
+
createdAt: z.ZodString;
|
|
244
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
245
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
246
|
+
eventId: z.ZodString;
|
|
247
|
+
type: z.ZodString;
|
|
248
|
+
idOrganisation: z.ZodNumber;
|
|
249
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
250
|
+
entity: z.ZodObject<{
|
|
251
|
+
type: z.ZodString;
|
|
252
|
+
id: z.ZodString;
|
|
253
|
+
}, "strip", z.ZodTypeAny, {
|
|
254
|
+
type: string;
|
|
255
|
+
id: string;
|
|
256
|
+
}, {
|
|
257
|
+
type: string;
|
|
258
|
+
id: string;
|
|
259
|
+
}>;
|
|
260
|
+
createdAt: z.ZodString;
|
|
261
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
262
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
263
|
+
eventId: z.ZodString;
|
|
264
|
+
type: z.ZodString;
|
|
265
|
+
idOrganisation: z.ZodNumber;
|
|
266
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
267
|
+
entity: z.ZodObject<{
|
|
268
|
+
type: z.ZodString;
|
|
269
|
+
id: z.ZodString;
|
|
270
|
+
}, "strip", z.ZodTypeAny, {
|
|
271
|
+
type: string;
|
|
272
|
+
id: string;
|
|
273
|
+
}, {
|
|
274
|
+
type: string;
|
|
275
|
+
id: string;
|
|
276
|
+
}>;
|
|
277
|
+
createdAt: z.ZodString;
|
|
278
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
279
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
280
|
+
export type IntentEnvelope = z.infer<typeof intentMessageSchema>;
|
|
281
|
+
/** An intent whose type this package knows, with its payload typed. */
|
|
282
|
+
export type IntentMessage = {
|
|
283
|
+
[T in IntentType]: Omit<IntentEnvelope, 'type' | 'data'> & {
|
|
284
|
+
type: T;
|
|
285
|
+
data: IntentPayload<T>;
|
|
286
|
+
};
|
|
287
|
+
}[IntentType];
|
|
288
|
+
export type IntentParseResult = {
|
|
289
|
+
kind: 'known';
|
|
290
|
+
message: IntentMessage;
|
|
291
|
+
}
|
|
292
|
+
/** A well-formed envelope of an intent type this version does not know. */
|
|
293
|
+
| {
|
|
294
|
+
kind: 'unknown';
|
|
295
|
+
message: IntentEnvelope;
|
|
296
|
+
} | {
|
|
297
|
+
kind: 'invalid';
|
|
298
|
+
error: string;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Validates one stream entry's message: pass `JSON.parse(entry[INTENT_FIELD])`.
|
|
302
|
+
* Never throws. A consumer that gets `invalid` should still claim by
|
|
303
|
+
* `entity.id` if it can, since the queue row is the record.
|
|
304
|
+
*/
|
|
305
|
+
export declare function parseIntent(raw: unknown): IntentParseResult;
|
package/dist/intents.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.intentMessageSchema = exports.intentPayloadSchemas = exports.INTENT_FIELD = exports.INTENT_STREAM_OF = exports.INTENT_STREAMS = void 0;
|
|
4
|
+
exports.parseIntent = parseIntent;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const types_1 = require("./events/types");
|
|
7
|
+
/**
|
|
8
|
+
* Intents: outbox rows core-ts's relay sends to one service's Redis stream
|
|
9
|
+
* (XADD, field `e`) instead of a channel. Each wakes its consumer to claim a
|
|
10
|
+
* queue row; the row stays the record (core-ts docs/realtime-events.md
|
|
11
|
+
* § Intents).
|
|
12
|
+
*/
|
|
13
|
+
exports.INTENT_STREAMS = {
|
|
14
|
+
notification: 'wocul:intents:notification',
|
|
15
|
+
email: 'wocul:intents:email',
|
|
16
|
+
worker: 'wocul:intents:worker',
|
|
17
|
+
agent: 'wocul:intents:agent'
|
|
18
|
+
};
|
|
19
|
+
exports.INTENT_STREAM_OF = {
|
|
20
|
+
'notification.requested': exports.INTENT_STREAMS.notification,
|
|
21
|
+
'email.requested': exports.INTENT_STREAMS.email,
|
|
22
|
+
'aicomment.requested': exports.INTENT_STREAMS.worker,
|
|
23
|
+
'kbproposal.requested': exports.INTENT_STREAMS.worker,
|
|
24
|
+
'run.requested': exports.INTENT_STREAMS.agent
|
|
25
|
+
};
|
|
26
|
+
/** The stream entry field holding the JSON message. */
|
|
27
|
+
exports.INTENT_FIELD = 'e';
|
|
28
|
+
const queueId = zod_1.z.string().min(1);
|
|
29
|
+
const idempotencyKey = zod_1.z.string().nullable().optional();
|
|
30
|
+
/** core-ts drops the content of an intent over 256 KiB and sets this. */
|
|
31
|
+
const truncated = zod_1.z.literal(true).optional();
|
|
32
|
+
/**
|
|
33
|
+
* Intent payloads. A consumer needs only `queueId` to claim the row, so that
|
|
34
|
+
* is the one required field; the content is a convenience and may be absent
|
|
35
|
+
* (`truncated`). Unknown fields pass through.
|
|
36
|
+
*/
|
|
37
|
+
exports.intentPayloadSchemas = {
|
|
38
|
+
'notification.requested': zod_1.z
|
|
39
|
+
.object({
|
|
40
|
+
queueId,
|
|
41
|
+
idempotencyKey,
|
|
42
|
+
truncated,
|
|
43
|
+
category: zod_1.z.string().optional(),
|
|
44
|
+
eventType: zod_1.z.string().optional(),
|
|
45
|
+
projectName: zod_1.z.string().nullable().optional(),
|
|
46
|
+
recipients: zod_1.z
|
|
47
|
+
.array(zod_1.z
|
|
48
|
+
.object({
|
|
49
|
+
idStaff: zod_1.z.number().int(),
|
|
50
|
+
recipientType: zod_1.z.string().optional()
|
|
51
|
+
})
|
|
52
|
+
.passthrough())
|
|
53
|
+
.optional(),
|
|
54
|
+
data: zod_1.z.unknown().optional(),
|
|
55
|
+
navigation: zod_1.z.unknown().optional(),
|
|
56
|
+
priority: zod_1.z.string().optional(),
|
|
57
|
+
language: zod_1.z.string().optional(),
|
|
58
|
+
channels: zod_1.z.array(zod_1.z.string()).nullable().optional(),
|
|
59
|
+
scheduledFor: zod_1.z.string().nullable().optional()
|
|
60
|
+
})
|
|
61
|
+
.passthrough(),
|
|
62
|
+
'email.requested': zod_1.z
|
|
63
|
+
.object({
|
|
64
|
+
queueId,
|
|
65
|
+
idempotencyKey,
|
|
66
|
+
truncated,
|
|
67
|
+
category: zod_1.z.string().optional(),
|
|
68
|
+
subCategory: zod_1.z.string().optional(),
|
|
69
|
+
eventType: zod_1.z.string().optional(),
|
|
70
|
+
recipients: zod_1.z
|
|
71
|
+
.array(zod_1.z
|
|
72
|
+
.object({
|
|
73
|
+
/** Null for an invite to someone without an account. */
|
|
74
|
+
idStaff: zod_1.z.number().int().nullable().optional(),
|
|
75
|
+
email: zod_1.z.string(),
|
|
76
|
+
name: zod_1.z.string().nullable().optional()
|
|
77
|
+
})
|
|
78
|
+
.passthrough())
|
|
79
|
+
.optional(),
|
|
80
|
+
data: zod_1.z.unknown().optional(),
|
|
81
|
+
priority: zod_1.z.string().optional(),
|
|
82
|
+
scheduledFor: zod_1.z.string().nullable().optional()
|
|
83
|
+
})
|
|
84
|
+
.passthrough(),
|
|
85
|
+
'aicomment.requested': zod_1.z
|
|
86
|
+
.object({ queueId, idTask: zod_1.z.number().int().positive() })
|
|
87
|
+
.passthrough(),
|
|
88
|
+
'kbproposal.requested': zod_1.z
|
|
89
|
+
.object({ queueId, idAgentRun: zod_1.z.number().int().positive() })
|
|
90
|
+
.passthrough(),
|
|
91
|
+
'run.requested': zod_1.z
|
|
92
|
+
.object({
|
|
93
|
+
queueId,
|
|
94
|
+
idempotencyKey,
|
|
95
|
+
idAgentRun: zod_1.z.number().int().positive(),
|
|
96
|
+
idTask: zod_1.z.number().int().positive(),
|
|
97
|
+
triggerType: zod_1.z.string().optional(),
|
|
98
|
+
priority: zod_1.z.string().optional(),
|
|
99
|
+
seeded: zod_1.z.boolean().optional(),
|
|
100
|
+
scheduledFor: zod_1.z.string().nullable().optional()
|
|
101
|
+
})
|
|
102
|
+
.passthrough()
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* The envelope core-ts's relay writes to a stream entry, as JSON under
|
|
106
|
+
* `INTENT_FIELD`; the payload above is its `data`.
|
|
107
|
+
*/
|
|
108
|
+
exports.intentMessageSchema = zod_1.z
|
|
109
|
+
.object({
|
|
110
|
+
eventId: zod_1.z.string().min(1),
|
|
111
|
+
type: zod_1.z.string().min(1),
|
|
112
|
+
idOrganisation: zod_1.z.number().int(),
|
|
113
|
+
idProject: zod_1.z.number().int().nullable(),
|
|
114
|
+
entity: zod_1.z.object({ type: zod_1.z.string(), id: zod_1.z.string() }),
|
|
115
|
+
createdAt: zod_1.z.string(),
|
|
116
|
+
data: zod_1.z.record(zod_1.z.unknown()).nullable()
|
|
117
|
+
})
|
|
118
|
+
.passthrough();
|
|
119
|
+
/**
|
|
120
|
+
* Validates one stream entry's message: pass `JSON.parse(entry[INTENT_FIELD])`.
|
|
121
|
+
* Never throws. A consumer that gets `invalid` should still claim by
|
|
122
|
+
* `entity.id` if it can, since the queue row is the record.
|
|
123
|
+
*/
|
|
124
|
+
function parseIntent(raw) {
|
|
125
|
+
const envelope = exports.intentMessageSchema.safeParse(raw);
|
|
126
|
+
if (!envelope.success) {
|
|
127
|
+
const issue = envelope.error.issues[0];
|
|
128
|
+
return {
|
|
129
|
+
kind: 'invalid',
|
|
130
|
+
error: `${issue?.path.join('.') || 'message'}: ${issue?.message ?? 'not an intent'}`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const { type } = envelope.data;
|
|
134
|
+
if (!(0, types_1.isIntentType)(type)) {
|
|
135
|
+
return { kind: 'unknown', message: envelope.data };
|
|
136
|
+
}
|
|
137
|
+
const payload = exports.intentPayloadSchemas[type].safeParse(envelope.data.data ?? {});
|
|
138
|
+
if (!payload.success) {
|
|
139
|
+
const issue = payload.error.issues[0];
|
|
140
|
+
return {
|
|
141
|
+
kind: 'invalid',
|
|
142
|
+
error: `${type}: data.${issue?.path.join('.') ?? ''} ${issue?.message ?? ''}`.trim()
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
kind: 'known',
|
|
147
|
+
message: { ...envelope.data, type, data: payload.data }
|
|
148
|
+
};
|
|
149
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@livetronics/wocul-domain",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Shared Wocul domain contracts: realtime event and intent schemas, channel names, and Core API types generated from the OpenAPI spec",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
12
|
+
"gen:api": "node scripts/gen-api.mjs",
|
|
13
|
+
"check:api": "node scripts/gen-api.mjs --check",
|
|
14
|
+
"type-check": "tsc --noEmit",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"prepublishOnly": "npm run check:api && npm test && npm run build"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/livetronics/wocul-service-core-ts.git",
|
|
21
|
+
"directory": "packages/wocul-domain"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"license": "UNLICENSED",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"zod": "^3.24.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"@types/node": "^22.20.5",
|
|
34
|
+
"jest": "^29.7.0",
|
|
35
|
+
"openapi-typescript": "^7.13.0",
|
|
36
|
+
"rimraf": "^5.0.10",
|
|
37
|
+
"ts-jest": "^29.4.15",
|
|
38
|
+
"typescript": "~5.8.3",
|
|
39
|
+
"zod": "^3.25.76"
|
|
40
|
+
}
|
|
41
|
+
}
|