evo360-types 1.3.759 → 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
+ });
@@ -898,6 +898,8 @@ export interface ICsqLeadReport extends IFireDoc {
898
898
  * Transcricao e prompt ficam em `artifacts/` para auditoria. */
899
899
  deleted_by_login_id?: string;
900
900
  deleted_reason?: string;
901
+ /** feat-313: laudo regravado por reavaliacao manual (Nexus/MCP). Ausente = avaliacao do fechamento. */
902
+ reevaluation?: ICsqReevaluationInfo;
901
903
  /** Estado da rechecagem agendada da agenda no nivel do laudo (adendo §B). */
902
904
  verification?: CsqVerificationState;
903
905
  /** Hash do snapshot de politicas (stack de prompts do tenant). */
@@ -924,6 +926,15 @@ export interface ICsqLeadReport extends IFireDoc {
924
926
  * Ausente quando o detector esta `off` ou o laudo e anterior a F3. */
925
927
  detector?: ICsqDetectorReport;
926
928
  }
929
+ /** feat-313: quem regravou o laudo por reavaliacao manual, e o que havia antes. */
930
+ export interface ICsqReevaluationInfo {
931
+ by_login_id: string;
932
+ at: Date;
933
+ reason?: string;
934
+ previous_score: number | null;
935
+ previous_status: string | null;
936
+ previous_version: number | null;
937
+ }
927
938
  /**
928
939
  * Pedido de reavaliacao (dry-run) do nex-mcp para o `hubia_csq_dry_run`.
929
940
  * Roda o pipeline com o juiz REAL e grava NADA (laudo, runs, BQ, evo_log do
@@ -945,6 +956,14 @@ export interface ICsqDryRunRequest {
945
956
  login_id: string;
946
957
  client_id?: string | null;
947
958
  } | null;
959
+ /**
960
+ * feat-313: true = GRAVA o laudo reavaliado no lugar do atual (nova `version`
961
+ * da mesma `evaluation_id`). So vale para o ticket do laudo atual do lead (ou
962
+ * lead sem laudo). Exige `requested_by`. Default false (dry-run).
963
+ */
964
+ persist?: boolean;
965
+ /** feat-313: motivo da substituicao (auditoria). */
966
+ reason?: string | null;
948
967
  }
949
968
  /** Resposta do dry-run. `report` vem serializado (datas em ISO). */
950
969
  export interface ICsqDryRunResult {
@@ -964,4 +983,15 @@ export interface ICsqDryRunResult {
964
983
  triage_mode: CsqTriageMode | null;
965
984
  cost_usd_est: number | null;
966
985
  duration_ms: number;
986
+ /** feat-313: o laudo foi gravado? (false no dry-run ou quando a substituicao foi recusada). */
987
+ persisted?: boolean;
988
+ /** feat-313: decisao de escrita — `overwrite` | `trail_only` | `duplicate` | `refused_not_current_ticket`. */
989
+ persist_action?: string | null;
990
+ /** feat-313: laudo atual ANTES da reavaliacao (para comparar). */
991
+ previous?: {
992
+ evaluation_id: string | null;
993
+ score: number | null;
994
+ status: string | null;
995
+ version: number | null;
996
+ } | null;
967
997
  }
@@ -1226,6 +1226,8 @@ export interface ICsqLeadReport extends IFireDoc {
1226
1226
  * Transcricao e prompt ficam em `artifacts/` para auditoria. */
1227
1227
  deleted_by_login_id?: string;
1228
1228
  deleted_reason?: string;
1229
+ /** feat-313: laudo regravado por reavaliacao manual (Nexus/MCP). Ausente = avaliacao do fechamento. */
1230
+ reevaluation?: ICsqReevaluationInfo;
1229
1231
  /** Estado da rechecagem agendada da agenda no nivel do laudo (adendo §B). */
1230
1232
  verification?: CsqVerificationState;
1231
1233
 
@@ -1257,6 +1259,16 @@ export interface ICsqLeadReport extends IFireDoc {
1257
1259
 
1258
1260
  // ───────── Reavaliacao sob demanda (feat-280 F4) ─────────
1259
1261
 
1262
+ /** feat-313: quem regravou o laudo por reavaliacao manual, e o que havia antes. */
1263
+ export interface ICsqReevaluationInfo {
1264
+ by_login_id: string;
1265
+ at: Date;
1266
+ reason?: string;
1267
+ previous_score: number | null;
1268
+ previous_status: string | null;
1269
+ previous_version: number | null;
1270
+ }
1271
+
1260
1272
  /**
1261
1273
  * Pedido de reavaliacao (dry-run) do nex-mcp para o `hubia_csq_dry_run`.
1262
1274
  * Roda o pipeline com o juiz REAL e grava NADA (laudo, runs, BQ, evo_log do
@@ -1275,6 +1287,14 @@ export interface ICsqDryRunRequest {
1275
1287
  force_review?: boolean;
1276
1288
  /** Quem pediu (so log/auditoria do lado do hubia). */
1277
1289
  requested_by?: { login_id: string; client_id?: string | null } | null;
1290
+ /**
1291
+ * feat-313: true = GRAVA o laudo reavaliado no lugar do atual (nova `version`
1292
+ * da mesma `evaluation_id`). So vale para o ticket do laudo atual do lead (ou
1293
+ * lead sem laudo). Exige `requested_by`. Default false (dry-run).
1294
+ */
1295
+ persist?: boolean;
1296
+ /** feat-313: motivo da substituicao (auditoria). */
1297
+ reason?: string | null;
1278
1298
  }
1279
1299
 
1280
1300
  /** Resposta do dry-run. `report` vem serializado (datas em ISO). */
@@ -1295,4 +1315,10 @@ export interface ICsqDryRunResult {
1295
1315
  triage_mode: CsqTriageMode | null;
1296
1316
  cost_usd_est: number | null;
1297
1317
  duration_ms: number;
1318
+ /** feat-313: o laudo foi gravado? (false no dry-run ou quando a substituicao foi recusada). */
1319
+ persisted?: boolean;
1320
+ /** feat-313: decisao de escrita — `overwrite` | `trail_only` | `duplicate` | `refused_not_current_ticket`. */
1321
+ persist_action?: string | null;
1322
+ /** feat-313: laudo atual ANTES da reavaliacao (para comparar). */
1323
+ previous?: { evaluation_id: string | null; score: number | null; status: string | null; version: number | null } | null;
1298
1324
  }
@@ -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;