evo360-types 1.3.374 → 1.3.376

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.
Files changed (28) hide show
  1. package/dist/apps/evo-hub-ia/v1/zod-schemas.d.ts +1191 -135
  2. package/dist/apps/evo-hub-ia/v1/zod-schemas.js +31 -4
  3. package/dist/apps/evo-hub-ia/v1/zod-schemas.ts +31 -4
  4. package/dist/types/evo-chat/call-session/index.d.ts +41 -0
  5. package/dist/types/evo-chat/call-session/index.js +2 -0
  6. package/dist/types/evo-chat/call-session/index.ts +81 -0
  7. package/dist/types/evo-chat/channel/index.d.ts +18 -0
  8. package/dist/types/evo-chat/channel/index.ts +20 -0
  9. package/dist/types/evo-chat/fb_collections.d.ts +1 -0
  10. package/dist/types/evo-chat/fb_collections.js +2 -1
  11. package/dist/types/evo-chat/fb_collections.ts +1 -0
  12. package/dist/types/evo-chat/index.d.ts +1 -0
  13. package/dist/types/evo-chat/index.js +1 -0
  14. package/dist/types/evo-chat/index.ts +1 -0
  15. package/dist/types/evo-chat/thread-message/index.d.ts +3 -1
  16. package/dist/types/evo-chat/thread-message/index.ts +6 -1
  17. package/dist/types/evo-finops/fb_collections.d.ts +1 -0
  18. package/dist/types/evo-finops/fb_collections.js +2 -1
  19. package/dist/types/evo-finops/fb_collections.ts +1 -0
  20. package/dist/types/evo-finops/payment-links/index.d.ts +12 -0
  21. package/dist/types/evo-finops/payment-links/index.js +12 -2
  22. package/dist/types/evo-finops/payment-links/index.ts +18 -1
  23. package/dist/types/evo-hub-ia/v1/index.d.ts +16 -7
  24. package/dist/types/evo-hub-ia/v1/index.js +1 -1
  25. package/dist/types/evo-hub-ia/v1/index.ts +17 -8
  26. package/dist/types/evo-med/appointment/index.d.ts +15 -0
  27. package/dist/types/evo-med/appointment/index.ts +16 -0
  28. package/package.json +1 -1
@@ -84,9 +84,16 @@ exports.zHubiaConversationModeSchema = zod_1.z.enum(["ai_only", "hybrid_assist",
84
84
  // ───────── evo-hubia-rules (deterministic rule layer) ─────────
85
85
  //
86
86
  // Camada de regras determinísticas avaliada pelo motor `evo-hubia-rules`
87
- // (ver cloud-functions/docs/evo-hubia-rules/). Roda ANTES do LLM (fase
88
- // `pre_llm`, único escopo de implementação atual). O campo `phase` já
89
- // reserva espaço arquitetural para um hook `post_llm` futuro.
87
+ // (ver cloud-functions/docs/evo-hubia-rules/). Hooks suportados:
88
+ // - `pre_llm` (v1.0) : avalia ANTES do orchestrator LLM rodar.
89
+ // - `post_llm` (v1.1) : avalia DEPOIS do orchestrator e ANTES do envio
90
+ // outbound; cobre safety/governance (content gate,
91
+ // circuit breaker, salvaguarda pós-tool).
92
+ //
93
+ // Matriz phase × outcome × when (enforced pelo superRefine de
94
+ // `zHubiaRuleSchema` abaixo):
95
+ // - pre_llm + when=inbound_message + outcome ∈ {stop,to_llm,to_llm_with_context}
96
+ // - post_llm + when=llm_completed + outcome = stop
90
97
  //
91
98
  // As regras moram em `binding.rules[]` — o binding É o cruzamento canal⨯
92
99
  // departamento, então o escopo de departamento é implícito.
@@ -207,7 +214,27 @@ exports.zHubiaRuleSchema = zod_1.z.object({
207
214
  dry_run: zod_1.z.boolean().default(false),
208
215
  /** Aborta sequência de ações no primeiro erro. */
209
216
  stop_actions_on_error: zod_1.z.boolean().default(true),
210
- }).passthrough();
217
+ }).passthrough().superRefine((rule, ctx) => {
218
+ // Matriz phase × outcome × when. pre_llm é permissivo (back-compat com
219
+ // regras v1.0); post_llm é restrito a outcome=stop + when=llm_completed
220
+ // (decisão C2 em features/feat-026-hubia-rules-v1-1/decisions.md).
221
+ if (rule.phase === "post_llm") {
222
+ if (rule.outcome !== "stop") {
223
+ ctx.addIssue({
224
+ code: zod_1.z.ZodIssueCode.custom,
225
+ path: ["outcome"],
226
+ message: "phase=post_llm aceita apenas outcome=stop",
227
+ });
228
+ }
229
+ if (rule.when !== "llm_completed") {
230
+ ctx.addIssue({
231
+ code: zod_1.z.ZodIssueCode.custom,
232
+ path: ["when"],
233
+ message: "phase=post_llm requer when=llm_completed",
234
+ });
235
+ }
236
+ }
237
+ });
211
238
  // ───────── AI Binding (department → AI agent routing) ─────────
212
239
  const zHubiaCapabilitiesSchema = zod_1.z.object({
213
240
  can_schedule: zod_1.z.boolean().default(false),
@@ -98,9 +98,16 @@ export type IHubiaConversationMode = z.infer<typeof zHubiaConversationModeSchema
98
98
  // ───────── evo-hubia-rules (deterministic rule layer) ─────────
99
99
  //
100
100
  // Camada de regras determinísticas avaliada pelo motor `evo-hubia-rules`
101
- // (ver cloud-functions/docs/evo-hubia-rules/). Roda ANTES do LLM (fase
102
- // `pre_llm`, único escopo de implementação atual). O campo `phase` já
103
- // reserva espaço arquitetural para um hook `post_llm` futuro.
101
+ // (ver cloud-functions/docs/evo-hubia-rules/). Hooks suportados:
102
+ // - `pre_llm` (v1.0) : avalia ANTES do orchestrator LLM rodar.
103
+ // - `post_llm` (v1.1) : avalia DEPOIS do orchestrator e ANTES do envio
104
+ // outbound; cobre safety/governance (content gate,
105
+ // circuit breaker, salvaguarda pós-tool).
106
+ //
107
+ // Matriz phase × outcome × when (enforced pelo superRefine de
108
+ // `zHubiaRuleSchema` abaixo):
109
+ // - pre_llm + when=inbound_message + outcome ∈ {stop,to_llm,to_llm_with_context}
110
+ // - post_llm + when=llm_completed + outcome = stop
104
111
  //
105
112
  // As regras moram em `binding.rules[]` — o binding É o cruzamento canal⨯
106
113
  // departamento, então o escopo de departamento é implícito.
@@ -242,7 +249,27 @@ export const zHubiaRuleSchema = z.object({
242
249
 
243
250
  /** Aborta sequência de ações no primeiro erro. */
244
251
  stop_actions_on_error: z.boolean().default(true),
245
- }).passthrough();
252
+ }).passthrough().superRefine((rule, ctx) => {
253
+ // Matriz phase × outcome × when. pre_llm é permissivo (back-compat com
254
+ // regras v1.0); post_llm é restrito a outcome=stop + when=llm_completed
255
+ // (decisão C2 em features/feat-026-hubia-rules-v1-1/decisions.md).
256
+ if (rule.phase === "post_llm") {
257
+ if (rule.outcome !== "stop") {
258
+ ctx.addIssue({
259
+ code: z.ZodIssueCode.custom,
260
+ path: ["outcome"],
261
+ message: "phase=post_llm aceita apenas outcome=stop",
262
+ });
263
+ }
264
+ if (rule.when !== "llm_completed") {
265
+ ctx.addIssue({
266
+ code: z.ZodIssueCode.custom,
267
+ path: ["when"],
268
+ message: "phase=post_llm requer when=llm_completed",
269
+ });
270
+ }
271
+ }
272
+ });
246
273
 
247
274
  // ───────── AI Binding (department → AI agent routing) ─────────
248
275
 
@@ -0,0 +1,41 @@
1
+ import { IFireDoc } from "../../shared";
2
+ import type { MessageDirection } from "../thread-message";
3
+ export type CallProviderDirection = 'USER_INITIATED' | 'BUSINESS_INITIATED';
4
+ export type CallStatus = 'ringing' | 'pre_accepted' | 'accepted' | 'connected' | 'missed' | 'rejected' | 'failed' | 'completed' | 'terminated';
5
+ export interface ICallProviderError {
6
+ code: number;
7
+ title?: string;
8
+ message?: string;
9
+ details?: string;
10
+ }
11
+ export interface IMessageCall {
12
+ provider_call_id: string;
13
+ call_session_id: string;
14
+ status: CallStatus;
15
+ direction: MessageDirection;
16
+ started_at?: Date;
17
+ ended_at?: Date;
18
+ duration_s?: number;
19
+ end_reason?: string;
20
+ }
21
+ export interface ICallSession extends IFireDoc {
22
+ model_ver: number;
23
+ provider_call_id: string;
24
+ channel_id: string;
25
+ thread_id: string;
26
+ ticket_id: string;
27
+ contact_id: string;
28
+ lead_id?: string;
29
+ direction: MessageDirection;
30
+ provider_direction?: CallProviderDirection;
31
+ status: CallStatus;
32
+ end_reason?: string;
33
+ provider_status?: string;
34
+ provider_errors?: ICallProviderError[];
35
+ started_at?: Date;
36
+ connected_at?: Date;
37
+ ended_at?: Date;
38
+ duration_s?: number;
39
+ timeline_at: Date;
40
+ last_event_at: Date;
41
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,81 @@
1
+ import { IFireDoc } from "../../shared";
2
+ import type { MessageDirection } from "../thread-message";
3
+
4
+ // ── Call enums ──
5
+
6
+ // Direção crua da Meta Calling API (preservada para debug/suporte).
7
+ export type CallProviderDirection = 'USER_INITIATED' | 'BUSINESS_INITIATED';
8
+
9
+ // Status de negócio normalizado da chamada.
10
+ // Fase 1 (feat-029) produz apenas: ringing | missed | rejected | failed | completed.
11
+ // Os demais (pre_accepted/accepted/connected/terminated) são reservados para a Fase 2
12
+ // (voz via WebRTC) e já existem aqui para a state machine de precedência ser estável
13
+ // sem exigir republish do evo360-types quando a Fase 2 chegar.
14
+ export type CallStatus =
15
+ | 'ringing'
16
+ | 'pre_accepted'
17
+ | 'accepted'
18
+ | 'connected'
19
+ | 'missed'
20
+ | 'rejected'
21
+ | 'failed'
22
+ | 'completed'
23
+ | 'terminated';
24
+
25
+ export interface ICallProviderError {
26
+ code: number;
27
+ title?: string;
28
+ message?: string;
29
+ details?: string;
30
+ }
31
+
32
+ // ── Call timeline projection ──
33
+
34
+ // Projeção FINA da chamada na timeline omnichannel. NÃO é fonte de verdade.
35
+ // A verdade canônica vive em ICallSession (referenciada por call_session_id).
36
+ // Sem accepted_at/connected_at na Fase 1 (são campos da Fase 2).
37
+ export interface IMessageCall {
38
+ provider_call_id: string; // wacid.* (== call_session_id na Fase 1)
39
+ call_session_id: string;
40
+ status: CallStatus;
41
+ direction: MessageDirection;
42
+ started_at?: Date;
43
+ ended_at?: Date;
44
+ duration_s?: number;
45
+ end_reason?: string;
46
+ }
47
+
48
+ // ── Call Session (entidade canônica — fonte de verdade) ──
49
+
50
+ // Path: tenants/{tenant}/apps/evo-chat/call_sessions/{provider_call_id}
51
+ // Fase 1 = MÍNIMO. Campos operacionais da Fase 2 (claim/sdp refs/agent/presence)
52
+ // NÃO devem ser adicionados aqui agora.
53
+ export interface ICallSession extends IFireDoc {
54
+ model_ver: number;
55
+ provider_call_id: string; // wacid.* (também é o doc id)
56
+ channel_id: string;
57
+ thread_id: string;
58
+ ticket_id: string;
59
+ contact_id: string;
60
+ lead_id?: string;
61
+
62
+ direction: MessageDirection; // 'in' (USER_INITIATED) | 'out' (BUSINESS_INITIATED)
63
+ provider_direction?: CallProviderDirection;
64
+
65
+ status: CallStatus; // normalizado, governado pela state machine de precedência
66
+ end_reason?: string; // 'completed' | 'not_answered' | 'failed' | 'rejected'
67
+
68
+ // Cru da Meta — não colapsar cedo (FAILED é ambíguo).
69
+ provider_status?: string; // ex.: 'COMPLETED' | 'FAILED'
70
+ provider_errors?: ICallProviderError[];
71
+
72
+ // Semântica de tempo.
73
+ started_at?: Date; // chamada iniciada no WhatsApp (connect ts)
74
+ connected_at?: Date; // mídia atendida — Fase 2 (não setado na Fase 1)
75
+ ended_at?: Date; // terminate
76
+ duration_s?: number;
77
+
78
+ // Ordenação/observação na timeline.
79
+ timeline_at: Date; // primeiro timestamp de provider observado
80
+ last_event_at: Date; // último timestamp de provider observado
81
+ }
@@ -10,6 +10,23 @@ export interface IChannelProviderRef {
10
10
  phone_number_id?: string;
11
11
  business_id?: string;
12
12
  }
13
+ export interface ICallDeflectionConfig {
14
+ enabled: boolean;
15
+ mode: 'template' | 'text';
16
+ template?: {
17
+ name: string;
18
+ language: string;
19
+ category?: string;
20
+ };
21
+ text?: string;
22
+ end_call: boolean;
23
+ only_outside_business_hours?: boolean;
24
+ cooldown_minutes?: number;
25
+ }
26
+ export interface ICallsChannelConfig {
27
+ enabled: boolean;
28
+ deflection?: ICallDeflectionConfig;
29
+ }
13
30
  export interface IChannel extends IFireDoc {
14
31
  model_ver: number;
15
32
  provider: ChannelProvider | string;
@@ -21,5 +38,6 @@ export interface IChannel extends IFireDoc {
21
38
  status: ChannelStatus;
22
39
  provider_ref: IChannelProviderRef;
23
40
  hub_ia?: IHubIAConfig;
41
+ calls?: ICallsChannelConfig;
24
42
  [key: string]: unknown;
25
43
  }
@@ -19,6 +19,25 @@ export interface IChannelProviderRef {
19
19
  business_id?: string;
20
20
  }
21
21
 
22
+ // ── Calls config (feat-029) ──
23
+
24
+ // Deflection de chamada recebida (inbound). Distinta de outbound_permission (Fase 2).
25
+ export interface ICallDeflectionConfig {
26
+ enabled: boolean;
27
+ mode: 'template' | 'text';
28
+ template?: { name: string; language: string; category?: string };
29
+ text?: string; // mode 'text' — só aplicado com janela de 24h aberta
30
+ end_call: boolean; // default true — terminate/reject via call-control
31
+ only_outside_business_hours?: boolean;
32
+ cooldown_minutes?: number; // hardening leve (notificação repetida)
33
+ }
34
+
35
+ export interface ICallsChannelConfig {
36
+ enabled: boolean;
37
+ deflection?: ICallDeflectionConfig;
38
+ // outbound_permission?: ICallOutboundPermissionConfig; // Fase 2 — não definir agora
39
+ }
40
+
22
41
  // ── Channel (evo-chat v3) ──
23
42
 
24
43
  export interface IChannel extends IFireDoc {
@@ -32,5 +51,6 @@ export interface IChannel extends IFireDoc {
32
51
  status: ChannelStatus;
33
52
  provider_ref: IChannelProviderRef;
34
53
  hub_ia?: IHubIAConfig;
54
+ calls?: ICallsChannelConfig;
35
55
  [key: string]: unknown;
36
56
  }
@@ -12,6 +12,7 @@ export declare const THREADS_COLLECTION = "threads";
12
12
  export declare const THREAD_MESSAGES_COLLECTION = "messages";
13
13
  export declare const TICKETS_COLLECTION = "tickets";
14
14
  export declare const INBOXES_COLLECTION = "inboxes";
15
+ export declare const CALL_SESSIONS_COLLECTION = "call_sessions";
15
16
  export declare const HubWabaCollections: {
16
17
  readonly TEMPLATES: "waba-templates";
17
18
  readonly QUICK_REPLIES: "quick-replies";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WABA_CHANNEL_INDEX_PATH = exports.WABA_SETUP_PATH = exports.HubWabaCollections = exports.INBOXES_COLLECTION = exports.TICKETS_COLLECTION = exports.THREAD_MESSAGES_COLLECTION = exports.THREADS_COLLECTION = exports.CHANNELS_COLLECTION = exports.CHATBEE_CHANNELS_COLLECTION = exports.HSM_MESSAGES_COLLECTION = exports.PROTOCOLS_COLLECTION = exports.CONTACTS_COLLECTION = exports.TICKET_CLOSE_TYPES_COLLECTION = exports.TICKET_CLOSES_COLLECTION = exports.TICKET_CLOSES = exports.CHAT_DICS_COLLECTION = exports.EVO_CHAT_APP = void 0;
3
+ exports.WABA_CHANNEL_INDEX_PATH = exports.WABA_SETUP_PATH = exports.HubWabaCollections = exports.CALL_SESSIONS_COLLECTION = exports.INBOXES_COLLECTION = exports.TICKETS_COLLECTION = exports.THREAD_MESSAGES_COLLECTION = exports.THREADS_COLLECTION = exports.CHANNELS_COLLECTION = exports.CHATBEE_CHANNELS_COLLECTION = exports.HSM_MESSAGES_COLLECTION = exports.PROTOCOLS_COLLECTION = exports.CONTACTS_COLLECTION = exports.TICKET_CLOSE_TYPES_COLLECTION = exports.TICKET_CLOSES_COLLECTION = exports.TICKET_CLOSES = exports.CHAT_DICS_COLLECTION = exports.EVO_CHAT_APP = void 0;
4
4
  //EVO Chat Application Doc
5
5
  exports.EVO_CHAT_APP = "evo-chat";
6
6
  //dictionaries
@@ -22,6 +22,7 @@ exports.THREADS_COLLECTION = "threads";
22
22
  exports.THREAD_MESSAGES_COLLECTION = "messages"; // subcollection de threads
23
23
  exports.TICKETS_COLLECTION = "tickets";
24
24
  exports.INBOXES_COLLECTION = "inboxes";
25
+ exports.CALL_SESSIONS_COLLECTION = "call_sessions"; // entidade canônica de chamadas (feat-029)
25
26
  // hub-waba template subcollection (under channels)
26
27
  exports.HubWabaCollections = {
27
28
  TEMPLATES: 'waba-templates',
@@ -25,6 +25,7 @@ export const THREADS_COLLECTION = "threads";
25
25
  export const THREAD_MESSAGES_COLLECTION = "messages"; // subcollection de threads
26
26
  export const TICKETS_COLLECTION = "tickets";
27
27
  export const INBOXES_COLLECTION = "inboxes";
28
+ export const CALL_SESSIONS_COLLECTION = "call_sessions"; // entidade canônica de chamadas (feat-029)
28
29
 
29
30
  // hub-waba template subcollection (under channels)
30
31
  export const HubWabaCollections = {
@@ -5,6 +5,7 @@ export * from "./chatbee";
5
5
  export * from "./channel";
6
6
  export * from "./thread";
7
7
  export * from "./thread-message";
8
+ export * from "./call-session";
8
9
  export * from "./ticket";
9
10
  export * from "./inbox";
10
11
  export * from "./waba-template";
@@ -22,6 +22,7 @@ __exportStar(require("./chatbee"), exports);
22
22
  __exportStar(require("./channel"), exports);
23
23
  __exportStar(require("./thread"), exports);
24
24
  __exportStar(require("./thread-message"), exports);
25
+ __exportStar(require("./call-session"), exports);
25
26
  __exportStar(require("./ticket"), exports);
26
27
  __exportStar(require("./inbox"), exports);
27
28
  __exportStar(require("./waba-template"), exports);
@@ -5,6 +5,7 @@ export * from "./chatbee";
5
5
  export * from "./channel";
6
6
  export * from "./thread";
7
7
  export * from "./thread-message";
8
+ export * from "./call-session";
8
9
  export * from "./ticket";
9
10
  export * from "./inbox";
10
11
  export * from "./waba-template";
@@ -1,5 +1,6 @@
1
1
  import { IFireDoc } from "../../shared";
2
- export type EvoChatMessageType = 'text' | 'image' | 'audio' | 'video' | 'document' | 'sticker' | 'location' | 'contacts' | 'interactive' | 'reaction' | 'template' | 'system';
2
+ import type { IMessageCall } from "../call-session";
3
+ export type EvoChatMessageType = 'text' | 'image' | 'audio' | 'video' | 'document' | 'sticker' | 'location' | 'contacts' | 'interactive' | 'reaction' | 'template' | 'system' | 'call';
3
4
  export type MessageDirection = 'in' | 'out';
4
5
  export interface IMessageStatus {
5
6
  sent_at?: Date;
@@ -91,6 +92,7 @@ export interface IThreadMessage extends IFireDoc {
91
92
  components?: unknown[];
92
93
  };
93
94
  context?: IMessageContext;
95
+ call?: IMessageCall;
94
96
  provider_message_id?: string;
95
97
  status?: IMessageStatus;
96
98
  reactions?: Record<string, {
@@ -1,4 +1,5 @@
1
1
  import { IFireDoc } from "../../shared";
2
+ import type { IMessageCall } from "../call-session";
2
3
 
3
4
  // ── Message type/direction enums ──
4
5
 
@@ -6,7 +7,8 @@ export type EvoChatMessageType =
6
7
  | 'text' | 'image' | 'audio' | 'video'
7
8
  | 'document' | 'sticker' | 'location'
8
9
  | 'contacts' | 'interactive' | 'reaction'
9
- | 'template' | 'system';
10
+ | 'template' | 'system'
11
+ | 'call';
10
12
 
11
13
  export type MessageDirection = 'in' | 'out';
12
14
 
@@ -112,6 +114,9 @@ export interface IThreadMessage extends IFireDoc {
112
114
  };
113
115
  context?: IMessageContext;
114
116
 
117
+ // Call timeline projection (feat-029). Fonte de verdade em ICallSession.
118
+ call?: IMessageCall;
119
+
115
120
  // Provider reference
116
121
  provider_message_id?: string;
117
122
 
@@ -11,3 +11,4 @@ export declare const FINOPS_DICS_SERVICES_ID = "services";
11
11
  export declare const FINOPS_SERVICES_COLLECTION = "services";
12
12
  export declare const FINOPS_TAKERS_COLLECTION = "takers";
13
13
  export declare const FINOPS_INVOICES_COLLECTION = "invoices";
14
+ export declare const FINOPS_PAYMENT_LINKS_COLLECTION = "payment_links";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FINOPS_INVOICES_COLLECTION = exports.FINOPS_TAKERS_COLLECTION = exports.FINOPS_SERVICES_COLLECTION = exports.FINOPS_DICS_SERVICES_ID = exports.FINOPS_ISSUER_PROFILES_COLLECTION = exports.FINOPS_DICS_ISSUERS_ID = exports.FINOPS_PROVIDERS_COLLECTION = exports.FINOPS_DICS_COLLECTION = exports.EVO_FINOPS_APP = void 0;
3
+ exports.FINOPS_PAYMENT_LINKS_COLLECTION = exports.FINOPS_INVOICES_COLLECTION = exports.FINOPS_TAKERS_COLLECTION = exports.FINOPS_SERVICES_COLLECTION = exports.FINOPS_DICS_SERVICES_ID = exports.FINOPS_ISSUER_PROFILES_COLLECTION = exports.FINOPS_DICS_ISSUERS_ID = exports.FINOPS_PROVIDERS_COLLECTION = exports.FINOPS_DICS_COLLECTION = exports.EVO_FINOPS_APP = void 0;
4
4
  // evo-finops app identifier for Firestore paths
5
5
  exports.EVO_FINOPS_APP = "evo-finops";
6
6
  // Collection names for evo-finops
@@ -16,3 +16,4 @@ exports.FINOPS_DICS_SERVICES_ID = "services";
16
16
  exports.FINOPS_SERVICES_COLLECTION = "services";
17
17
  exports.FINOPS_TAKERS_COLLECTION = "takers";
18
18
  exports.FINOPS_INVOICES_COLLECTION = "invoices";
19
+ exports.FINOPS_PAYMENT_LINKS_COLLECTION = "payment_links";
@@ -14,4 +14,5 @@ export const FINOPS_DICS_SERVICES_ID = "services";
14
14
  export const FINOPS_SERVICES_COLLECTION = "services";
15
15
  export const FINOPS_TAKERS_COLLECTION = "takers";
16
16
  export const FINOPS_INVOICES_COLLECTION = "invoices";
17
+ export const FINOPS_PAYMENT_LINKS_COLLECTION = "payment_links";
17
18
 
@@ -1,5 +1,15 @@
1
1
  import type { IFireDoc, IExternalLink } from "../../shared";
2
2
  import type { IInvoiceTakerRef } from "../invoices";
3
+ export declare const EvoFinopsPaymentLinkPermissions: {
4
+ readonly List: "evo_finops_payment_link_read";
5
+ readonly Get: "evo_finops_payment_link_read";
6
+ readonly Create: "evo_finops_payment_link_write";
7
+ readonly Update: "evo_finops_payment_link_write";
8
+ readonly Delete: "evo_finops_payment_link_write";
9
+ readonly AddExternalLink: "evo_finops_payment_link_write";
10
+ readonly RemoveExternalLink: "evo_finops_payment_link_write";
11
+ };
12
+ export type EvoFinopsPaymentLinkPermissions = (typeof EvoFinopsPaymentLinkPermissions)[keyof typeof EvoFinopsPaymentLinkPermissions];
3
13
  /** Asaas `billingType` for payment links */
4
14
  export declare enum AsaasPaymentLinkBillingTypeEnum {
5
15
  UNDEFINED = "UNDEFINED",
@@ -83,3 +93,5 @@ export interface IPaymentLink extends IFireDoc {
83
93
  }>;
84
94
  [key: string]: unknown;
85
95
  }
96
+ /** Alias semântico para uso em evo-finops (tenant-scoped). Mesma forma de IPaymentLink. */
97
+ export type IEvoFinopsPaymentLink = IPaymentLink;
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
- // Nexus / FinOps — Payment links (Asaas) persisted in Firestore
2
+ // FinOps — Payment links (Asaas) persisted in Firestore
3
+ // Shared between nex-finops (cross-tenant) and evo-finops (tenant-scoped).
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.PaymentLinkDocumentStateEnum = exports.AsaasPaymentLinkSubscriptionCycleEnum = exports.AsaasPaymentLinkChargeTypeEnum = exports.AsaasPaymentLinkBillingTypeEnum = void 0;
5
+ exports.PaymentLinkDocumentStateEnum = exports.AsaasPaymentLinkSubscriptionCycleEnum = exports.AsaasPaymentLinkChargeTypeEnum = exports.AsaasPaymentLinkBillingTypeEnum = exports.EvoFinopsPaymentLinkPermissions = void 0;
6
+ exports.EvoFinopsPaymentLinkPermissions = {
7
+ List: "evo_finops_payment_link_read",
8
+ Get: "evo_finops_payment_link_read",
9
+ Create: "evo_finops_payment_link_write",
10
+ Update: "evo_finops_payment_link_write",
11
+ Delete: "evo_finops_payment_link_write",
12
+ AddExternalLink: "evo_finops_payment_link_write",
13
+ RemoveExternalLink: "evo_finops_payment_link_write",
14
+ };
5
15
  /** Asaas `billingType` for payment links */
6
16
  var AsaasPaymentLinkBillingTypeEnum;
7
17
  (function (AsaasPaymentLinkBillingTypeEnum) {
@@ -1,8 +1,22 @@
1
- // Nexus / FinOps — Payment links (Asaas) persisted in Firestore
1
+ // FinOps — Payment links (Asaas) persisted in Firestore
2
+ // Shared between nex-finops (cross-tenant) and evo-finops (tenant-scoped).
2
3
 
3
4
  import type { IFireDoc, IExternalLink } from "../../shared";
4
5
  import type { IInvoiceTakerRef } from "../invoices";
5
6
 
7
+ export const EvoFinopsPaymentLinkPermissions = {
8
+ List: "evo_finops_payment_link_read",
9
+ Get: "evo_finops_payment_link_read",
10
+ Create: "evo_finops_payment_link_write",
11
+ Update: "evo_finops_payment_link_write",
12
+ Delete: "evo_finops_payment_link_write",
13
+ AddExternalLink: "evo_finops_payment_link_write",
14
+ RemoveExternalLink: "evo_finops_payment_link_write",
15
+ } as const;
16
+
17
+ export type EvoFinopsPaymentLinkPermissions =
18
+ (typeof EvoFinopsPaymentLinkPermissions)[keyof typeof EvoFinopsPaymentLinkPermissions];
19
+
6
20
  /** Asaas `billingType` for payment links */
7
21
  export enum AsaasPaymentLinkBillingTypeEnum {
8
22
  UNDEFINED = "UNDEFINED",
@@ -101,3 +115,6 @@ export interface IPaymentLink extends IFireDoc {
101
115
 
102
116
  [key: string]: unknown;
103
117
  }
118
+
119
+ /** Alias semântico para uso em evo-finops (tenant-scoped). Mesma forma de IPaymentLink. */
120
+ export type IEvoFinopsPaymentLink = IPaymentLink;
@@ -1,13 +1,20 @@
1
- /** Fase de avaliação. `pre_llm` roda antes do orchestrator;
2
- * `post_llm` está reservado (não implementado nesta entrega). */
1
+ /** Fase de avaliação.
2
+ * - `pre_llm` (v1.0) : avalia antes do orchestrator LLM.
3
+ * - `post_llm` (v1.1) : avalia depois do orchestrator e antes do envio
4
+ * outbound (safety/governance). */
3
5
  export type IHubiaRulePhase = "pre_llm" | "post_llm";
4
- /** Gatilho que dispara a avaliação. */
6
+ /** Gatilho que dispara a avaliação. Correlacionado com `phase`:
7
+ * pre_llm → inbound_message; post_llm → llm_completed (validado pelo
8
+ * superRefine de `zHubiaRuleSchema`). */
5
9
  export type IHubiaRuleTrigger = "inbound_message" | "llm_completed";
6
10
  /** Desfecho do turno após a regra disparar:
7
- * - `stop` — finaliza turno sem chamar o LLM.
8
- * - `to_llm` — segue para o orchestrator normalmente.
11
+ * - `stop` — finaliza turno; em pre_llm pula o LLM,
12
+ * em post_llm bloqueia o envio outbound (único
13
+ * outcome permitido em post_llm).
14
+ * - `to_llm` — segue para o orchestrator normalmente
15
+ * (apenas pre_llm).
9
16
  * - `to_llm_with_context` — segue para o orchestrator com trace das ações
10
- * injetado como bloco de sistema.
17
+ * injetado como bloco de sistema (apenas pre_llm).
11
18
  * Quando o LLM está desligado no binding (default_mode `human_only`/`blocked`),
12
19
  * `to_llm`/`to_llm_with_context` degradam para "cai pro humano". */
13
20
  export type IHubiaRuleOutcome = "stop" | "to_llm" | "to_llm_with_context";
@@ -95,11 +102,13 @@ export interface IHubiaRule {
95
102
  priority?: number;
96
103
  /** Default: "pre_llm". */
97
104
  phase?: IHubiaRulePhase;
98
- /** Default: "inbound_message" (compatível com `phase: pre_llm`). */
105
+ /** Default: "inbound_message" (compatível com `phase: pre_llm`).
106
+ * Para `phase: post_llm`, precisa ser "llm_completed" (zod superRefine). */
99
107
  when?: IHubiaRuleTrigger;
100
108
  scope?: IHubiaRuleScope;
101
109
  conditions: IHubiaConditionGroup;
102
110
  actions: IHubiaRuleAction[];
111
+ /** Para `phase: post_llm`, único valor permitido é "stop" (zod superRefine). */
103
112
  outcome: IHubiaRuleOutcome;
104
113
  /** Shadow mode por regra (característica permanente, não só de rollout):
105
114
  * avalia + grava trace, mas NÃO executa as actions. Permite canário de
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Tipos da camada evo-hubia-rules (motor determinístico pré-LLM).
2
+ // Tipos da camada evo-hubia-rules (motor determinístico de regras).
3
3
  // Schemas zod correspondentes ficam em src/apps/evo-hub-ia/v1/zod-schemas.ts;
4
4
  // estes tipos são escritos à mão e mantidos em paralelo (convenção do projeto:
5
5
  // `apps/` = zod, `types/` = interfaces TS).
@@ -1,4 +1,4 @@
1
- // Tipos da camada evo-hubia-rules (motor determinístico pré-LLM).
1
+ // Tipos da camada evo-hubia-rules (motor determinístico de regras).
2
2
  // Schemas zod correspondentes ficam em src/apps/evo-hub-ia/v1/zod-schemas.ts;
3
3
  // estes tipos são escritos à mão e mantidos em paralelo (convenção do projeto:
4
4
  // `apps/` = zod, `types/` = interfaces TS).
@@ -7,18 +7,25 @@
7
7
 
8
8
  // ── Enums / Literals ──
9
9
 
10
- /** Fase de avaliação. `pre_llm` roda antes do orchestrator;
11
- * `post_llm` está reservado (não implementado nesta entrega). */
10
+ /** Fase de avaliação.
11
+ * - `pre_llm` (v1.0) : avalia antes do orchestrator LLM.
12
+ * - `post_llm` (v1.1) : avalia depois do orchestrator e antes do envio
13
+ * outbound (safety/governance). */
12
14
  export type IHubiaRulePhase = "pre_llm" | "post_llm";
13
15
 
14
- /** Gatilho que dispara a avaliação. */
16
+ /** Gatilho que dispara a avaliação. Correlacionado com `phase`:
17
+ * pre_llm → inbound_message; post_llm → llm_completed (validado pelo
18
+ * superRefine de `zHubiaRuleSchema`). */
15
19
  export type IHubiaRuleTrigger = "inbound_message" | "llm_completed";
16
20
 
17
21
  /** Desfecho do turno após a regra disparar:
18
- * - `stop` — finaliza turno sem chamar o LLM.
19
- * - `to_llm` — segue para o orchestrator normalmente.
22
+ * - `stop` — finaliza turno; em pre_llm pula o LLM,
23
+ * em post_llm bloqueia o envio outbound (único
24
+ * outcome permitido em post_llm).
25
+ * - `to_llm` — segue para o orchestrator normalmente
26
+ * (apenas pre_llm).
20
27
  * - `to_llm_with_context` — segue para o orchestrator com trace das ações
21
- * injetado como bloco de sistema.
28
+ * injetado como bloco de sistema (apenas pre_llm).
22
29
  * Quando o LLM está desligado no binding (default_mode `human_only`/`blocked`),
23
30
  * `to_llm`/`to_llm_with_context` degradam para "cai pro humano". */
24
31
  export type IHubiaRuleOutcome = "stop" | "to_llm" | "to_llm_with_context";
@@ -138,12 +145,14 @@ export interface IHubiaRule {
138
145
 
139
146
  /** Default: "pre_llm". */
140
147
  phase?: IHubiaRulePhase;
141
- /** Default: "inbound_message" (compatível com `phase: pre_llm`). */
148
+ /** Default: "inbound_message" (compatível com `phase: pre_llm`).
149
+ * Para `phase: post_llm`, precisa ser "llm_completed" (zod superRefine). */
142
150
  when?: IHubiaRuleTrigger;
143
151
 
144
152
  scope?: IHubiaRuleScope;
145
153
  conditions: IHubiaConditionGroup;
146
154
  actions: IHubiaRuleAction[];
155
+ /** Para `phase: post_llm`, único valor permitido é "stop" (zod superRefine). */
147
156
  outcome: IHubiaRuleOutcome;
148
157
 
149
158
  /** Shadow mode por regra (característica permanente, não só de rollout):
@@ -79,6 +79,15 @@ export interface IAppointmentPaymentInvoiceRef {
79
79
  /** Indica se a invoice foi enviada ao contato (ex.: via evo-chat/WhatsApp) */
80
80
  evo_chat_sent?: boolean;
81
81
  }
82
+ /** Origem da quitação do pagamento (ex.: link de pagamento Asaas via webhook). */
83
+ export interface IAppointmentPaymentPaidVia {
84
+ kind: "payment_link" | "manual" | "pix" | "boleto";
85
+ payment_link_id?: string;
86
+ asaas_payment_id?: string;
87
+ event?: string;
88
+ received_at?: string;
89
+ raw_status?: string;
90
+ }
82
91
  export interface IAppointmentPayment {
83
92
  total?: number | null;
84
93
  paid?: number | null;
@@ -87,6 +96,12 @@ export interface IAppointmentPayment {
87
96
  payment_type: PaymentType;
88
97
  /** Correspondência com invoices do evo-finops (NFSe) vinculadas a este pagamento */
89
98
  invoices?: IAppointmentPaymentInvoiceRef[];
99
+ /** Quando o pagamento foi marcado como pago (ISO 8601 ou Date). */
100
+ paid_at?: string | Date;
101
+ /** Origem da quitação (payment_link Asaas, manual, etc.). */
102
+ paid_via?: IAppointmentPaymentPaidVia | null;
103
+ /** Método/canal de pagamento livre (ex.: 'payment_link', 'cash', 'card_terminal'). */
104
+ payment_method?: string;
90
105
  metadata?: Record<string, unknown>;
91
106
  [key: string]: unknown;
92
107
  }