evo360-types 1.3.762 → 1.3.764

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.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zAutomationTriggerRequestSchema = exports.zAutomationDryRunRequestSchema = exports.zHubAutomationConfigSchema = exports.zAutomationRoutineUpdateRequestSchema = exports.zAutomationRoutineWriteSchema = exports.zAutomationRoutineSchema = exports.zAutomationBranchModeSchema = exports.zAutomationBranchSchema = exports.zAutomationOutputSchema = exports.zAutomationActionOutputSchema = exports.zAutomationHumanTaskOutputSchema = exports.zAutomationAutoTaskOutputSchema = exports.zAutomationExecuteAtSchema = exports.zAutomationConditionGroupSchema = exports.zAutomationConditionSchema = exports.zAutomationOperatorSchema = exports.zAutomationSelectionSchema = exports.zAutomationPatientSelectionSchema = exports.zAutomationLeadSelectionSchema = exports.zAutomationAppointmentSelectionSchema = exports.zAutomationAppointmentModeSchema = exports.zAutomationTimeOfDayRangeSchema = exports.zAutomationTimeOfDaySchema = exports.zAutomationDateWindowSchema = exports.zAutomationDateOffsetModeSchema = exports.zAutomationTriggerSchema = exports.zAutomationEventTriggerSchema = exports.zAutomationWebhookTriggerSchema = exports.zAutomationCronTriggerSchema = void 0;
3
+ exports.zMessagePreviewRequestSchema = exports.zPatientBirthdayMessagePayloadSchema = exports.zGeneratedMessageChannelSchema = exports.zAutomationTriggerRequestSchema = exports.zAutomationDryRunRequestSchema = exports.zHubAutomationConfigSchema = exports.zAutomationRoutineUpdateRequestSchema = exports.zAutomationRoutineWriteSchema = exports.zAutomationRoutineSchema = exports.zAutomationBranchModeSchema = exports.zAutomationBranchSchema = exports.zAutomationOutputSchema = exports.zAutomationActionOutputSchema = exports.zAutomationHumanTaskOutputSchema = exports.zAutomationAutoTaskOutputSchema = exports.zAutomationExecuteAtSchema = exports.zAutomationConditionGroupSchema = exports.zAutomationConditionSchema = exports.zAutomationOperatorSchema = exports.zAutomationSelectionSchema = exports.zAutomationPatientSelectionSchema = exports.zAutomationLeadSelectionSchema = exports.zAutomationAppointmentSelectionSchema = exports.zAutomationAgeRangeSchema = exports.zAutomationPatientSexSchema = exports.zAutomationAppointmentModeSchema = exports.zAutomationTimeOfDayRangeSchema = exports.zAutomationTimeOfDaySchema = exports.zAutomationDateWindowSchema = exports.zAutomationDateOffsetModeSchema = exports.zAutomationTriggerSchema = exports.zAutomationEventTriggerSchema = exports.zAutomationWebhookTriggerSchema = exports.zAutomationCronTriggerSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const domain_events_1 = require("../../types/domain-events");
6
+ const hub_automation_1 = require("../../types/hub-automation");
6
7
  const zod_schemas_1 = require("../evo-task/zod-schemas");
7
8
  // ------------------------------------------------------
8
9
  // Trigger (cron sweep | webhook reverse-trigger)
@@ -62,6 +63,22 @@ exports.zAutomationAppointmentModeSchema = zod_1.z.enum([
62
63
  "telemedicine",
63
64
  "in_person",
64
65
  ]);
66
+ // feat-311: patient filters (shared by the `appointment` and `patient` blocks).
67
+ // Data comes from the PATIENT doc; absence is strict (see the TS contract).
68
+ exports.zAutomationPatientSexSchema = zod_1.z.enum(["female", "male", "other"]);
69
+ // Inclusive age range in full years; at least one bound, min <= max.
70
+ exports.zAutomationAgeRangeSchema = zod_1.z
71
+ .object({
72
+ min: zod_1.z.number().int().min(0).max(130).optional(),
73
+ max: zod_1.z.number().int().min(0).max(130).optional(),
74
+ })
75
+ .refine((r) => r.min !== undefined || r.max !== undefined, {
76
+ message: "min or max required",
77
+ })
78
+ .refine((r) => r.min === undefined || r.max === undefined || r.min <= r.max, {
79
+ message: "min must be <= max",
80
+ path: ["max"],
81
+ });
65
82
  exports.zAutomationAppointmentSelectionSchema = zod_1.z.object({
66
83
  target: zod_1.z.literal("appointment"),
67
84
  appointment: zod_1.z.object({
@@ -105,12 +122,18 @@ exports.zAutomationAppointmentSelectionSchema = zod_1.z.object({
105
122
  message: "time_range.start and time_range.end must differ",
106
123
  })
107
124
  .optional(),
125
+ // ---- feat-311: patient filters (patient doc; strict absence).
126
+ patient_sex_in: zod_1.z.array(exports.zAutomationPatientSexSchema).optional(),
127
+ patient_sex_not_in: zod_1.z.array(exports.zAutomationPatientSexSchema).optional(),
128
+ patient_age: exports.zAutomationAgeRangeSchema.optional(),
108
129
  }),
109
130
  });
110
131
  // feat-085 (F3): lead/patient selections (domain-event targets). The `target`
111
- // discriminant selects the branch. Filters are reserved (see the TS contract);
112
- // the event consumer pre-loads the single target, so they are not enforced at
113
- // runtime today but are validated to allow authoring lead/patient routines.
132
+ // discriminant selects the branch. Lead filters and the patient status/source/
133
+ // tag filters are reserved (see the TS contract): the event consumer pre-loads
134
+ // the single target, so they are not enforced at event runtime.
135
+ // feat-311: `patient.birthday` turns the patient selection into a cron/webhook
136
+ // birthday SWEEP, where the patient sex/age filters ARE enforced.
114
137
  exports.zAutomationLeadSelectionSchema = zod_1.z.object({
115
138
  target: zod_1.z.literal("lead"),
116
139
  lead: zod_1.z.object({
@@ -126,6 +149,13 @@ exports.zAutomationPatientSelectionSchema = zod_1.z.object({
126
149
  status_in: zod_1.z.array(zod_1.z.string()).optional(),
127
150
  source_codes: zod_1.z.array(zod_1.z.string()).optional(),
128
151
  tag_names: zod_1.z.array(zod_1.z.string()).optional(),
152
+ // ---- feat-311: birthday sweep (cron/webhook only) + patient filters.
153
+ birthday: zod_1.z
154
+ .object({ offset_days: zod_1.z.number().int().min(-30).max(30) })
155
+ .optional(),
156
+ patient_sex_in: zod_1.z.array(exports.zAutomationPatientSexSchema).optional(),
157
+ patient_sex_not_in: zod_1.z.array(exports.zAutomationPatientSexSchema).optional(),
158
+ patient_age: exports.zAutomationAgeRangeSchema.optional(),
129
159
  }),
130
160
  });
131
161
  exports.zAutomationSelectionSchema = zod_1.z.discriminatedUnion("target", [
@@ -335,3 +365,37 @@ exports.zAutomationTriggerRequestSchema = zod_1.z.object({
335
365
  .optional(),
336
366
  force: zod_1.z.boolean().optional().default(false),
337
367
  });
368
+ // ------------------------------------------------------
369
+ // feat-311 (F3): "Mensagem de aniversário (IA)" output
370
+ // ------------------------------------------------------
371
+ exports.zGeneratedMessageChannelSchema = zod_1.z.enum(["whatsapp", "email"]);
372
+ // Payload of the `patient_birthday_message` auto task. `.passthrough()` because
373
+ // the materializer injects extra keys (e.g. `externalLinks`). `prompt` is
374
+ // OPTIONAL here on purpose: the handler itself reports `prompt_missing` (P3).
375
+ exports.zPatientBirthdayMessagePayloadSchema = zod_1.z
376
+ .object({
377
+ patient_id: zod_1.z.string().min(1),
378
+ channels: zod_1.z.array(exports.zGeneratedMessageChannelSchema).optional(),
379
+ whatsapp_channel_id: zod_1.z.string().optional(),
380
+ whatsapp_template_id: zod_1.z.string().optional(),
381
+ email_channel_id: zod_1.z.string().optional(),
382
+ email_template_id: zod_1.z.string().optional(),
383
+ department_id: zod_1.z.string().optional(),
384
+ prompt: zod_1.z.string().max(hub_automation_1.MESSAGE_PROMPT_MAX_CHARS).optional(),
385
+ birthday_date: zod_1.z
386
+ .string()
387
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
388
+ .optional(),
389
+ force_send: zod_1.z.boolean().optional(),
390
+ })
391
+ .passthrough();
392
+ // "Testar prompt" (POST /outputs/preview-message on hub_automation_admin).
393
+ exports.zMessagePreviewRequestSchema = zod_1.z.object({
394
+ patient_id: zod_1.z.string().min(1),
395
+ prompt: zod_1.z.string().trim().min(1).max(hub_automation_1.MESSAGE_PROMPT_MAX_CHARS),
396
+ channel: exports.zGeneratedMessageChannelSchema,
397
+ birthday_date: zod_1.z
398
+ .string()
399
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
400
+ .optional(),
401
+ });
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { DOMAIN_EVENT_ORIGINS } from "../../types/domain-events";
3
+ import { MESSAGE_PROMPT_MAX_CHARS } from "../../types/hub-automation";
3
4
  import {
4
5
  zTaskAutoHandlerSchema,
5
6
  zTaskRetryPolicySchema,
@@ -73,6 +74,24 @@ export const zAutomationAppointmentModeSchema = z.enum([
73
74
  "in_person",
74
75
  ]);
75
76
 
77
+ // feat-311: patient filters (shared by the `appointment` and `patient` blocks).
78
+ // Data comes from the PATIENT doc; absence is strict (see the TS contract).
79
+ export const zAutomationPatientSexSchema = z.enum(["female", "male", "other"]);
80
+
81
+ // Inclusive age range in full years; at least one bound, min <= max.
82
+ export const zAutomationAgeRangeSchema = z
83
+ .object({
84
+ min: z.number().int().min(0).max(130).optional(),
85
+ max: z.number().int().min(0).max(130).optional(),
86
+ })
87
+ .refine((r) => r.min !== undefined || r.max !== undefined, {
88
+ message: "min or max required",
89
+ })
90
+ .refine((r) => r.min === undefined || r.max === undefined || r.min <= r.max, {
91
+ message: "min must be <= max",
92
+ path: ["max"],
93
+ });
94
+
76
95
  export const zAutomationAppointmentSelectionSchema = z.object({
77
96
  target: z.literal("appointment"),
78
97
  appointment: z.object({
@@ -117,13 +136,19 @@ export const zAutomationAppointmentSelectionSchema = z.object({
117
136
  message: "time_range.start and time_range.end must differ",
118
137
  })
119
138
  .optional(),
139
+ // ---- feat-311: patient filters (patient doc; strict absence).
140
+ patient_sex_in: z.array(zAutomationPatientSexSchema).optional(),
141
+ patient_sex_not_in: z.array(zAutomationPatientSexSchema).optional(),
142
+ patient_age: zAutomationAgeRangeSchema.optional(),
120
143
  }),
121
144
  });
122
145
 
123
146
  // feat-085 (F3): lead/patient selections (domain-event targets). The `target`
124
- // discriminant selects the branch. Filters are reserved (see the TS contract);
125
- // the event consumer pre-loads the single target, so they are not enforced at
126
- // runtime today but are validated to allow authoring lead/patient routines.
147
+ // discriminant selects the branch. Lead filters and the patient status/source/
148
+ // tag filters are reserved (see the TS contract): the event consumer pre-loads
149
+ // the single target, so they are not enforced at event runtime.
150
+ // feat-311: `patient.birthday` turns the patient selection into a cron/webhook
151
+ // birthday SWEEP, where the patient sex/age filters ARE enforced.
127
152
  export const zAutomationLeadSelectionSchema = z.object({
128
153
  target: z.literal("lead"),
129
154
  lead: z.object({
@@ -140,6 +165,13 @@ export const zAutomationPatientSelectionSchema = z.object({
140
165
  status_in: z.array(z.string()).optional(),
141
166
  source_codes: z.array(z.string()).optional(),
142
167
  tag_names: z.array(z.string()).optional(),
168
+ // ---- feat-311: birthday sweep (cron/webhook only) + patient filters.
169
+ birthday: z
170
+ .object({ offset_days: z.number().int().min(-30).max(30) })
171
+ .optional(),
172
+ patient_sex_in: z.array(zAutomationPatientSexSchema).optional(),
173
+ patient_sex_not_in: z.array(zAutomationPatientSexSchema).optional(),
174
+ patient_age: zAutomationAgeRangeSchema.optional(),
143
175
  }),
144
176
  });
145
177
 
@@ -378,3 +410,40 @@ export const zAutomationTriggerRequestSchema = z.object({
378
410
  .optional(),
379
411
  force: z.boolean().optional().default(false),
380
412
  });
413
+
414
+ // ------------------------------------------------------
415
+ // feat-311 (F3): "Mensagem de aniversário (IA)" output
416
+ // ------------------------------------------------------
417
+ export const zGeneratedMessageChannelSchema = z.enum(["whatsapp", "email"]);
418
+
419
+ // Payload of the `patient_birthday_message` auto task. `.passthrough()` because
420
+ // the materializer injects extra keys (e.g. `externalLinks`). `prompt` is
421
+ // OPTIONAL here on purpose: the handler itself reports `prompt_missing` (P3).
422
+ export const zPatientBirthdayMessagePayloadSchema = z
423
+ .object({
424
+ patient_id: z.string().min(1),
425
+ channels: z.array(zGeneratedMessageChannelSchema).optional(),
426
+ whatsapp_channel_id: z.string().optional(),
427
+ whatsapp_template_id: z.string().optional(),
428
+ email_channel_id: z.string().optional(),
429
+ email_template_id: z.string().optional(),
430
+ department_id: z.string().optional(),
431
+ prompt: z.string().max(MESSAGE_PROMPT_MAX_CHARS).optional(),
432
+ birthday_date: z
433
+ .string()
434
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
435
+ .optional(),
436
+ force_send: z.boolean().optional(),
437
+ })
438
+ .passthrough();
439
+
440
+ // "Testar prompt" (POST /outputs/preview-message on hub_automation_admin).
441
+ export const zMessagePreviewRequestSchema = z.object({
442
+ patient_id: z.string().min(1),
443
+ prompt: z.string().trim().min(1).max(MESSAGE_PROMPT_MAX_CHARS),
444
+ channel: zGeneratedMessageChannelSchema,
445
+ birthday_date: z
446
+ .string()
447
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "expected yyyy-MM-dd")
448
+ .optional(),
449
+ });
@@ -124,8 +124,10 @@ export interface IUsageLlm {
124
124
  * - `attachment_analysis`: leitura de foto/PDF pelo classificador de anexos.
125
125
  * - `audio_synthesis`: nota de voz gerada pela HubIA (feat-303).
126
126
  * - `human_audio_synthesis`: "Enviar como áudio" do atendente (TTS; 1 linha por áudio enviado).
127
+ * - `message_generation`: mensagem gerada por IA nas saídas do hub-automation
128
+ * (feat-311: aniversário; envio e "Testar prompt").
127
129
  */
128
- export type UsageAiCategory = "hubia" | "attachment_analysis" | "audio_synthesis" | "human_audio_synthesis";
130
+ export type UsageAiCategory = "hubia" | "attachment_analysis" | "audio_synthesis" | "human_audio_synthesis" | "message_generation";
129
131
  export interface IUsageLlmCategory {
130
132
  /** Chamadas ao LLM nesta categoria (execuções/análises, dedup por evento). */
131
133
  turnos: number;
@@ -145,8 +145,15 @@ export interface IUsageLlm {
145
145
  * - `attachment_analysis`: leitura de foto/PDF pelo classificador de anexos.
146
146
  * - `audio_synthesis`: nota de voz gerada pela HubIA (feat-303).
147
147
  * - `human_audio_synthesis`: "Enviar como áudio" do atendente (TTS; 1 linha por áudio enviado).
148
+ * - `message_generation`: mensagem gerada por IA nas saídas do hub-automation
149
+ * (feat-311: aniversário; envio e "Testar prompt").
148
150
  */
149
- export type UsageAiCategory = "hubia" | "attachment_analysis" | "audio_synthesis" | "human_audio_synthesis";
151
+ export type UsageAiCategory =
152
+ | "hubia"
153
+ | "attachment_analysis"
154
+ | "audio_synthesis"
155
+ | "human_audio_synthesis"
156
+ | "message_generation";
150
157
 
151
158
  export interface IUsageLlmCategory {
152
159
  /** Chamadas ao LLM nesta categoria (execuções/análises, dedup por evento). */
@@ -68,6 +68,7 @@ export declare const TaskAutoHandlerEnum: {
68
68
  readonly AppointmentCancelled: "appointment_cancelled";
69
69
  readonly AppointmentPayment: "appointment_payment";
70
70
  readonly AppointmentPaymentDone: "appointment_payment_done";
71
+ readonly PatientBirthdayMessage: "patient_birthday_message";
71
72
  };
72
73
  export type TaskAutoHandler = (typeof TaskAutoHandlerEnum)[keyof typeof TaskAutoHandlerEnum];
73
74
  export declare const TaskRetryStrategyEnum: {
@@ -159,6 +159,13 @@ exports.TaskAutoHandlerEnum = {
159
159
  AppointmentCancelled: "appointment_cancelled",
160
160
  AppointmentPayment: "appointment_payment",
161
161
  AppointmentPaymentDone: "appointment_payment_done",
162
+ // feat-311: mensagem de aniversário gerada por IA (saída da rotina de
163
+ // aniversariantes do hub-automation; executor em functions-integrations).
164
+ // Gera o texto `{{mensagem}}` com o prompt da rotina e envia pelo canal
165
+ // escolhido (WhatsApp/e-mail). Tópico:
166
+ // `patient_birthday_message.execute_requests`.
167
+ // Espelhado à mão em `zTaskAutoHandlerSchema` — sem lá, criar a task estoura ZodError.
168
+ PatientBirthdayMessage: "patient_birthday_message",
162
169
  };
163
170
  // ----- Retry policy
164
171
  exports.TaskRetryStrategyEnum = {
@@ -170,6 +170,13 @@ export const TaskAutoHandlerEnum = {
170
170
  AppointmentCancelled: "appointment_cancelled",
171
171
  AppointmentPayment: "appointment_payment",
172
172
  AppointmentPaymentDone: "appointment_payment_done",
173
+ // feat-311: mensagem de aniversário gerada por IA (saída da rotina de
174
+ // aniversariantes do hub-automation; executor em functions-integrations).
175
+ // Gera o texto `{{mensagem}}` com o prompt da rotina e envia pelo canal
176
+ // escolhido (WhatsApp/e-mail). Tópico:
177
+ // `patient_birthday_message.execute_requests`.
178
+ // Espelhado à mão em `zTaskAutoHandlerSchema` — sem lá, criar a task estoura ZodError.
179
+ PatientBirthdayMessage: "patient_birthday_message",
173
180
  } as const;
174
181
 
175
182
  export type TaskAutoHandler =
@@ -30,6 +30,11 @@ export interface IAutomationDateWindow {
30
30
  offset_days: number;
31
31
  offset_mode: AutomationDateOffsetMode;
32
32
  }
33
+ export type AutomationPatientSex = "female" | "male" | "other";
34
+ export interface IAutomationAgeRange {
35
+ min?: number;
36
+ max?: number;
37
+ }
33
38
  export interface IAutomationAppointmentSelection {
34
39
  target: "appointment";
35
40
  appointment: {
@@ -59,6 +64,9 @@ export interface IAutomationAppointmentSelection {
59
64
  start: string;
60
65
  end: string;
61
66
  };
67
+ patient_sex_in?: AutomationPatientSex[];
68
+ patient_sex_not_in?: AutomationPatientSex[];
69
+ patient_age?: IAutomationAgeRange;
62
70
  };
63
71
  }
64
72
  export interface IAutomationLeadSelection {
@@ -76,6 +84,12 @@ export interface IAutomationPatientSelection {
76
84
  status_in?: string[];
77
85
  source_codes?: string[];
78
86
  tag_names?: string[];
87
+ birthday?: {
88
+ offset_days: number;
89
+ };
90
+ patient_sex_in?: AutomationPatientSex[];
91
+ patient_sex_not_in?: AutomationPatientSex[];
92
+ patient_age?: IAutomationAgeRange;
79
93
  };
80
94
  }
81
95
  export type IAutomationSelection = IAutomationAppointmentSelection | IAutomationLeadSelection | IAutomationPatientSelection;
@@ -277,8 +291,10 @@ export interface IAutomationRunTrace {
277
291
  duration_ms: number;
278
292
  }
279
293
  export interface IAutomationSelectedTargetProjection {
280
- appointment_id: string;
281
- calendar_id: string;
294
+ target_kind?: "appointment" | "patient";
295
+ appointment_id?: string;
296
+ calendar_id?: string;
297
+ patient_id?: string;
282
298
  target_date: string;
283
299
  start_date?: string;
284
300
  patient_name?: string;
@@ -289,5 +305,46 @@ export interface IAutomationSelectedTargetProjection {
289
305
  address_name?: string;
290
306
  appointment_type?: string;
291
307
  appointment_base_type?: string;
308
+ patient_sex?: AutomationPatientSex;
309
+ patient_age?: number;
292
310
  branch_ids?: string[];
293
311
  }
312
+ export declare const PATIENT_BIRTHDAY_MESSAGE_KIND = "birthday_message.send";
313
+ export declare const GENERATED_MESSAGE_VARIABLE = "mensagem";
314
+ export declare const MESSAGE_PROMPT_MAX_CHARS = 2000;
315
+ export type GeneratedMessageChannel = "whatsapp" | "email";
316
+ export interface IPatientBirthdayMessagePayload {
317
+ patient_id: string;
318
+ channels?: GeneratedMessageChannel[];
319
+ whatsapp_channel_id?: string;
320
+ whatsapp_template_id?: string;
321
+ email_channel_id?: string;
322
+ email_template_id?: string;
323
+ department_id?: string;
324
+ prompt?: string;
325
+ birthday_date?: string;
326
+ force_send?: boolean;
327
+ }
328
+ export interface IMessagePreviewRequest {
329
+ patient_id: string;
330
+ prompt: string;
331
+ channel: GeneratedMessageChannel;
332
+ birthday_date?: string;
333
+ }
334
+ export interface IMessagePreviewResponse {
335
+ ok: boolean;
336
+ error?: string;
337
+ text?: string;
338
+ chars?: number;
339
+ recipient?: {
340
+ is_patient: boolean;
341
+ first_name?: string;
342
+ relation?: string;
343
+ };
344
+ model?: string;
345
+ usage?: {
346
+ input_tokens: number;
347
+ output_tokens: number;
348
+ cost_usd: number | null;
349
+ };
350
+ }
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AutomationRunStatusEnum = exports.AutomationOutputTypeEnum = exports.AUTOMATION_TIME_RANGE_OPERATORS = exports.AutomationOperatorEnum = exports.AUTOMATION_PATIENT_FACTS = exports.AUTOMATION_LEAD_FACTS = exports.AUTOMATION_APPOINTMENT_FACTS = exports.HubAutomationPermissions = void 0;
17
+ exports.MESSAGE_PROMPT_MAX_CHARS = exports.GENERATED_MESSAGE_VARIABLE = exports.PATIENT_BIRTHDAY_MESSAGE_KIND = exports.AutomationRunStatusEnum = exports.AutomationOutputTypeEnum = exports.AUTOMATION_TIME_RANGE_OPERATORS = exports.AutomationOperatorEnum = exports.AUTOMATION_PATIENT_FACTS = exports.AUTOMATION_LEAD_FACTS = exports.AUTOMATION_APPOINTMENT_FACTS = exports.HubAutomationPermissions = void 0;
18
18
  __exportStar(require("./fb_collections"), exports);
19
19
  // ======================================================
20
20
  // hub-automation
@@ -28,8 +28,10 @@ __exportStar(require("./fb_collections"), exports);
28
28
  // NOTE:
29
29
  // - These are hand-written contracts (no z.infer). Zod schemas live in
30
30
  // src/apps/hub-automation/zod-schemas.ts.
31
- // - F1 has no `patient.*` facts and no patient hydration (decision Q15):
32
- // contact-data validation is the handler's responsibility at run time.
31
+ // - F1 has no `patient.*` facts and no patient hydration (decision Q15),
32
+ // except for the patient filters (feat-311: sex/age, read from the patient
33
+ // doc only when one of them is active): contact-data validation is the
34
+ // handler's responsibility at run time.
33
35
  // ======================================================
34
36
  // ----- Permissions (Firestore path: tenants/{t}/apps/hub-automation/...)
35
37
  exports.HubAutomationPermissions = {
@@ -123,3 +125,14 @@ exports.AutomationRunStatusEnum = {
123
125
  BlockedDryRunRequired: "blocked_dry_run_required",
124
126
  Error: "error",
125
127
  };
128
+ // ------------------------------------------------------
129
+ // feat-311 (F3): "Mensagem de aniversário (IA)" output
130
+ //
131
+ // Auto task `patient_birthday_message` (TaskAutoHandlerEnum.PatientBirthdayMessage):
132
+ // generates the text with the routine's prompt (LLM) and sends it through the
133
+ // chosen channel's template, filling the reserved variable `{{mensagem}}`.
134
+ // ------------------------------------------------------
135
+ exports.PATIENT_BIRTHDAY_MESSAGE_KIND = "birthday_message.send";
136
+ // Reserved template variable filled with the generated text (P3).
137
+ exports.GENERATED_MESSAGE_VARIABLE = "mensagem";
138
+ exports.MESSAGE_PROMPT_MAX_CHARS = 2000;
@@ -15,8 +15,10 @@ import type { DomainEventOrigin } from "../domain-events";
15
15
  // NOTE:
16
16
  // - These are hand-written contracts (no z.infer). Zod schemas live in
17
17
  // src/apps/hub-automation/zod-schemas.ts.
18
- // - F1 has no `patient.*` facts and no patient hydration (decision Q15):
19
- // contact-data validation is the handler's responsibility at run time.
18
+ // - F1 has no `patient.*` facts and no patient hydration (decision Q15),
19
+ // except for the patient filters (feat-311: sex/age, read from the patient
20
+ // doc only when one of them is active): contact-data validation is the
21
+ // handler's responsibility at run time.
20
22
  // ======================================================
21
23
 
22
24
  // ----- Permissions (Firestore path: tenants/{t}/apps/hub-automation/...)
@@ -86,6 +88,16 @@ export interface IAutomationDateWindow {
86
88
  offset_mode: AutomationDateOffsetMode;
87
89
  }
88
90
 
91
+ // feat-311: patient filters, shared by the `appointment` and `patient` blocks
92
+ // (same key names in both, so the backend has a single predicate).
93
+ export type AutomationPatientSex = "female" | "male" | "other";
94
+
95
+ // Inclusive age range in full years (0..130). At least one bound; min <= max.
96
+ export interface IAutomationAgeRange {
97
+ min?: number;
98
+ max?: number;
99
+ }
100
+
89
101
  export interface IAutomationAppointmentSelection {
90
102
  target: "appointment";
91
103
  appointment: {
@@ -147,15 +159,31 @@ export interface IAutomationAppointmentSelection {
147
159
  // `start === end` is invalid (rejected by zod). An appointment without a
148
160
  // coercible startDate does not match.
149
161
  time_range?: { start: string; end: string };
162
+
163
+ // ---- feat-311: patient filters. All optional and additive.
164
+ // - Data comes from the PATIENT doc (`gender`, `birthdate`), not from the
165
+ // appointment embeds.
166
+ // - The patient is read (one batched read per run) ONLY when one of these
167
+ // filters is active; otherwise there is no patient hydration.
168
+ // - Age = full years at the LOCAL appointment date (tenant timezone).
169
+ // - Absence is STRICT (deliberate divergence from the feat-147 rule): with
170
+ // any of these filters active, an appointment whose patient cannot be
171
+ // resolved/found, or lacks the field the filter uses, is EXCLUDED — this
172
+ // holds for `patient_sex_not_in` too.
173
+ patient_sex_in?: AutomationPatientSex[];
174
+ patient_sex_not_in?: AutomationPatientSex[];
175
+ patient_age?: IAutomationAgeRange;
150
176
  };
151
177
  }
152
178
 
153
- // feat-085 (F3): lead/patient selections. Cron selection is appointment-only;
154
- // these targets only arrive via the domain-event trigger, where the consumer
155
- // PRE-LOADS the single target from the event (the `lead`/`patient` filters below
156
- // are therefore not enforced at event runtime — they exist so a routine can be
157
- // authored/validated with a lead/patient target and, later, for a possible
158
- // lead/patient sweep). Discriminated by `target`.
179
+ // feat-085 (F3): lead/patient selections. Discriminated by `target`.
180
+ // - Lead targets only arrive via the domain-event trigger, where the consumer
181
+ // PRE-LOADS the single target from the event; the `lead` filters below are
182
+ // therefore not enforced at runtime (reserved, authoring/validation only).
183
+ // - Patient: without `patient.birthday` it is the domain-event selection above
184
+ // (status/source/tag filters reserved, not enforced). feat-311: WITH
185
+ // `patient.birthday` it is the cron/webhook birthday SWEEP, where the patient
186
+ // sex/age filters ARE enforced (status/source/tag stay reserved).
159
187
  export interface IAutomationLeadSelection {
160
188
  target: "lead";
161
189
  lead: {
@@ -173,6 +201,20 @@ export interface IAutomationPatientSelection {
173
201
  status_in?: string[];
174
202
  source_codes?: string[];
175
203
  tag_names?: string[];
204
+
205
+ // ---- feat-311: birthday sweep. Target date = runDate + offset_days in the
206
+ // tenant timezone (yyyy-MM-dd); selects the patients whose birthday falls on
207
+ // it (29/02 counts as 28/02 in non-leap years). `0` = today's birthdays;
208
+ // `1` = tomorrow's ("1 day before"). Range -30..30.
209
+ // PRESENT ⇒ sweep, valid only with a cron/webhook trigger (an event trigger
210
+ // with `birthday` is rejected on save). ABSENT ⇒ the domain-event patient
211
+ // selection, unchanged.
212
+ birthday?: { offset_days: number };
213
+ // Patient filters (same semantics/strict absence as in the appointment
214
+ // block). Age = the age the patient COMPLETES on the birthday (D3).
215
+ patient_sex_in?: AutomationPatientSex[];
216
+ patient_sex_not_in?: AutomationPatientSex[];
217
+ patient_age?: IAutomationAgeRange;
176
218
  };
177
219
  }
178
220
 
@@ -553,10 +595,18 @@ export interface IAutomationRunTrace {
553
595
  // `POST /routines/:id/dry-run` (capped, alongside `selected_targets_total`).
554
596
  // It is NEVER persisted in the run doc — IAutomationRunTrace keeps its counts +
555
597
  // capped samples so the 1MB Firestore limit stays intact.
598
+ //
599
+ // feat-311: also projects PATIENT targets (birthday sweep). `appointment_id` /
600
+ // `calendar_id` are therefore optional (present for appointment targets);
601
+ // `target_kind` absent = "appointment" (legacy responses).
556
602
  export interface IAutomationSelectedTargetProjection {
557
- appointment_id: string;
558
- calendar_id: string;
559
- // yyyy-MM-dd (target date the run resolved for this appointment)
603
+ target_kind?: "appointment" | "patient";
604
+ appointment_id?: string;
605
+ calendar_id?: string;
606
+ // Patient targets (and appointment targets when the patient was hydrated).
607
+ patient_id?: string;
608
+ // yyyy-MM-dd (target date the run resolved for this target; for a birthday
609
+ // target it is this year's birthday)
560
610
  target_date: string;
561
611
  // ISO 8601 instant; the client formats it in the tenant timezone.
562
612
  start_date?: string;
@@ -570,8 +620,63 @@ export interface IAutomationSelectedTargetProjection {
570
620
  // (`appointmentType`) and the BASE enum (`appointmentBaseType`).
571
621
  appointment_type?: string;
572
622
  appointment_base_type?: string;
623
+ // feat-311: filled only when the selection hydrated the patient (patient
624
+ // filter active, or a birthday target). Age at the target date.
625
+ patient_sex?: AutomationPatientSex;
626
+ patient_age?: number;
573
627
  // feat-270: ids of the branches this target matched in the same dry-run
574
628
  // (exclusive mode → 0..1; all-matching → 0..N; the fallback branch counts).
575
629
  // Empty array = "no branch". Absent = not computed.
576
630
  branch_ids?: string[];
577
631
  }
632
+
633
+ // ------------------------------------------------------
634
+ // feat-311 (F3): "Mensagem de aniversário (IA)" output
635
+ //
636
+ // Auto task `patient_birthday_message` (TaskAutoHandlerEnum.PatientBirthdayMessage):
637
+ // generates the text with the routine's prompt (LLM) and sends it through the
638
+ // chosen channel's template, filling the reserved variable `{{mensagem}}`.
639
+ // ------------------------------------------------------
640
+ export const PATIENT_BIRTHDAY_MESSAGE_KIND = "birthday_message.send";
641
+ // Reserved template variable filled with the generated text (P3).
642
+ export const GENERATED_MESSAGE_VARIABLE = "mensagem";
643
+ export const MESSAGE_PROMPT_MAX_CHARS = 2000;
644
+
645
+ export type GeneratedMessageChannel = "whatsapp" | "email";
646
+
647
+ export interface IPatientBirthdayMessagePayload {
648
+ // "{{patient.id}}"
649
+ patient_id: string;
650
+ channels?: GeneratedMessageChannel[];
651
+ whatsapp_channel_id?: string;
652
+ whatsapp_template_id?: string;
653
+ email_channel_id?: string;
654
+ email_template_id?: string;
655
+ department_id?: string;
656
+ // Required to send (P3) — the handler reports `prompt_missing` without it;
657
+ // <= MESSAGE_PROMPT_MAX_CHARS.
658
+ prompt?: string;
659
+ // yyyy-MM-dd; injected by the materializer (the birthday this task is for).
660
+ birthday_date?: string;
661
+ force_send?: boolean;
662
+ }
663
+
664
+ // "Testar prompt" — POST /outputs/preview-message (hub_automation_admin,
665
+ // RBAC hub_automation_write).
666
+ export interface IMessagePreviewRequest {
667
+ patient_id: string;
668
+ prompt: string;
669
+ channel: GeneratedMessageChannel;
670
+ // yyyy-MM-dd; absent = the patient's next birthday (tenant timezone).
671
+ birthday_date?: string;
672
+ }
673
+
674
+ export interface IMessagePreviewResponse {
675
+ ok: boolean;
676
+ error?: string;
677
+ text?: string;
678
+ chars?: number;
679
+ recipient?: { is_patient: boolean; first_name?: string; relation?: string };
680
+ model?: string;
681
+ usage?: { input_tokens: number; output_tokens: number; cost_usd: number | null };
682
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evo360-types",
3
- "version": "1.3.762",
3
+ "version": "1.3.764",
4
4
  "description": "HREVO360 Shared Types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",