evo360-types 1.3.354 → 1.3.355

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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zSendMessageResponseSchema = exports.zSendMessageRequestSchema = exports.zSendTemplateMessageRequestSchema = exports.zSendTextMessageRequestSchema = exports.zTemplateHeaderMediaSchema = exports.zTemplateButtonPayloadSchema = exports.zTemplateVariableSchema = exports.zChatbeeContactHistorySchema = exports.zChatbeeContactHistoryPayloadClosedSchema = exports.zChatbeeContactHistoryPayloadCreatedSchema = exports.zChatbeeContactSchema = exports.zChatbeeStatusSchema = exports.zChatbeeDepartmentSchema = exports.zChatbeeChannelSchema = exports.zChatBeeChannelConfigSchema = void 0;
3
+ exports.zChatbeeNormalizedMessageSchema = exports.zChatbeeNormalizedInnerMessageSchema = exports.zChatbeeNormalizedMediaSchema = exports.zSendMessageResponseSchema = exports.zSendMessageRequestSchema = exports.zSendTemplateMessageRequestSchema = exports.zSendTextMessageRequestSchema = exports.zTemplateHeaderMediaSchema = exports.zTemplateButtonPayloadSchema = exports.zTemplateVariableSchema = exports.zChatbeeContactHistorySchema = exports.zChatbeeContactHistoryPayloadClosedSchema = exports.zChatbeeContactHistoryPayloadCreatedSchema = exports.zChatbeeContactSchema = exports.zChatbeeStatusSchema = exports.zChatbeeDepartmentSchema = exports.zChatbeeChannelSchema = exports.zChatBeeChannelConfigSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const zod_schemas_1 = require("../../shared/zod-schemas");
6
6
  const zod_schemas_2 = require("../../evo-hub-ia/channel/zod-schemas");
@@ -147,3 +147,75 @@ exports.zSendMessageResponseSchema = zod_1.z.object({
147
147
  message_id: zod_1.z.string().optional(),
148
148
  data: zod_1.z.any().optional(),
149
149
  });
150
+ // ───────── ChatBee Normalized Message (input do tópico chatbee-messages-normalized) ─────────
151
+ //
152
+ // Publisher: Cloud Run `message-normalizer` em google-chat-functions/.
153
+ // Consumer atual: BQ sink (`hr-evo360.chatbee.msgs_raw`).
154
+ // Consumer futuro (S4): adapter `chatbee_inbound_to_hubia` em functions-chatbee.
155
+ //
156
+ // Validação confirmada com 12 amostras reais lidas do BQ em 2026-05-05.
157
+ /** Tipo da mídia do Chatbee (se message.type !== 'text'). */
158
+ exports.zChatbeeNormalizedMediaSchema = zod_1.z.object({
159
+ /** Bucket GCS onde o normalizer reuploadou a mídia. Confirmado em prod: `hr-evo360-evo-chat`. */
160
+ bucket: zod_1.z.string(),
161
+ /** Path no bucket (ex.: `tenants/{tenant}/{channel_uuid}/{contact_id}/document_{msg_id}.pdf`). */
162
+ path: zod_1.z.string(),
163
+ type: zod_1.z.string(),
164
+ }).passthrough();
165
+ /** Inner message do payload Chatbee normalizado. */
166
+ exports.zChatbeeNormalizedInnerMessageSchema = zod_1.z.object({
167
+ /** ID Chatbee da mensagem (ex.: "249199900"). String mas formato numérico. */
168
+ id: zod_1.z.string(),
169
+ /** Texto OU URL signed do GCS para mídia. */
170
+ content: zod_1.z.string().default(""),
171
+ /** Direção semântica do payload. FILTRO ESSENCIAL no adapter — 'out' = eco. */
172
+ event: zod_1.z.enum(["in", "out"]),
173
+ type: zod_1.z.enum([
174
+ "text",
175
+ "audio",
176
+ "image",
177
+ "document",
178
+ "template",
179
+ "ptt",
180
+ "sticker",
181
+ "story_mention",
182
+ "video",
183
+ "vcard",
184
+ ]),
185
+ media: exports.zChatbeeNormalizedMediaSchema.optional(),
186
+ }).passthrough();
187
+ /** Mensagem completa publicada no tópico `chatbee-messages-normalized`. */
188
+ exports.zChatbeeNormalizedMessageSchema = zod_1.z.object({
189
+ type: zod_1.z.literal("MESSAGE"),
190
+ channel: zod_1.z.object({
191
+ /** ID Chatbee — INTEGER em origem, mas castado para STRING na borda do adapter (DA-4). */
192
+ id: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).transform(v => String(v)),
193
+ /** Tenant slug — premissa P6 confiável (drabanzoli, clinica-moema, ...). */
194
+ external_id: zod_1.z.string(),
195
+ name: zod_1.z.string().optional(),
196
+ }).passthrough(),
197
+ contact: zod_1.z.object({
198
+ id: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).transform(v => String(v)),
199
+ name: zod_1.z.string().optional().default(""),
200
+ address: zod_1.z.string().optional().default(""),
201
+ type: zod_1.z.string().optional(),
202
+ external_id: zod_1.z.string().nullable().optional(),
203
+ is_group: zod_1.z.boolean().optional(),
204
+ }).passthrough(),
205
+ history: zod_1.z.object({
206
+ id: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).transform(v => String(v)),
207
+ channel_id: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).transform(v => String(v)),
208
+ is_out_of_office_hours: zod_1.z.boolean().optional(),
209
+ automatic: zod_1.z.boolean().optional(),
210
+ }).passthrough().optional(),
211
+ /** Populado quando operador humano envia (event=out + user.id) — sinal de presença para handoff (DA-10). */
212
+ user: zod_1.z.object({
213
+ id: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).transform(v => String(v)),
214
+ name: zod_1.z.string().optional(),
215
+ external_id: zod_1.z.string().nullable().optional(),
216
+ }).passthrough().optional(),
217
+ payload: zod_1.z.object({
218
+ message: exports.zChatbeeNormalizedInnerMessageSchema,
219
+ }).passthrough(),
220
+ timestamp: zod_1.z.string().optional(),
221
+ }).passthrough();
@@ -157,3 +157,83 @@ export const zSendMessageResponseSchema = z.object({
157
157
  message_id: z.string().optional(),
158
158
  data: z.any().optional(),
159
159
  });
160
+
161
+ // ───────── ChatBee Normalized Message (input do tópico chatbee-messages-normalized) ─────────
162
+ //
163
+ // Publisher: Cloud Run `message-normalizer` em google-chat-functions/.
164
+ // Consumer atual: BQ sink (`hr-evo360.chatbee.msgs_raw`).
165
+ // Consumer futuro (S4): adapter `chatbee_inbound_to_hubia` em functions-chatbee.
166
+ //
167
+ // Validação confirmada com 12 amostras reais lidas do BQ em 2026-05-05.
168
+
169
+ /** Tipo da mídia do Chatbee (se message.type !== 'text'). */
170
+ export const zChatbeeNormalizedMediaSchema = z.object({
171
+ /** Bucket GCS onde o normalizer reuploadou a mídia. Confirmado em prod: `hr-evo360-evo-chat`. */
172
+ bucket: z.string(),
173
+ /** Path no bucket (ex.: `tenants/{tenant}/{channel_uuid}/{contact_id}/document_{msg_id}.pdf`). */
174
+ path: z.string(),
175
+ type: z.string(),
176
+ }).passthrough();
177
+
178
+ /** Inner message do payload Chatbee normalizado. */
179
+ export const zChatbeeNormalizedInnerMessageSchema = z.object({
180
+ /** ID Chatbee da mensagem (ex.: "249199900"). String mas formato numérico. */
181
+ id: z.string(),
182
+ /** Texto OU URL signed do GCS para mídia. */
183
+ content: z.string().default(""),
184
+ /** Direção semântica do payload. FILTRO ESSENCIAL no adapter — 'out' = eco. */
185
+ event: z.enum(["in", "out"]),
186
+ type: z.enum([
187
+ "text",
188
+ "audio",
189
+ "image",
190
+ "document",
191
+ "template",
192
+ "ptt",
193
+ "sticker",
194
+ "story_mention",
195
+ "video",
196
+ "vcard",
197
+ ]),
198
+ media: zChatbeeNormalizedMediaSchema.optional(),
199
+ }).passthrough();
200
+
201
+ /** Mensagem completa publicada no tópico `chatbee-messages-normalized`. */
202
+ export const zChatbeeNormalizedMessageSchema = z.object({
203
+ type: z.literal("MESSAGE"),
204
+ channel: z.object({
205
+ /** ID Chatbee — INTEGER em origem, mas castado para STRING na borda do adapter (DA-4). */
206
+ id: z.union([z.number(), z.string()]).transform(v => String(v)),
207
+ /** Tenant slug — premissa P6 confiável (drabanzoli, clinica-moema, ...). */
208
+ external_id: z.string(),
209
+ name: z.string().optional(),
210
+ }).passthrough(),
211
+ contact: z.object({
212
+ id: z.union([z.number(), z.string()]).transform(v => String(v)),
213
+ name: z.string().optional().default(""),
214
+ address: z.string().optional().default(""),
215
+ type: z.string().optional(),
216
+ external_id: z.string().nullable().optional(),
217
+ is_group: z.boolean().optional(),
218
+ }).passthrough(),
219
+ history: z.object({
220
+ id: z.union([z.number(), z.string()]).transform(v => String(v)),
221
+ channel_id: z.union([z.number(), z.string()]).transform(v => String(v)),
222
+ is_out_of_office_hours: z.boolean().optional(),
223
+ automatic: z.boolean().optional(),
224
+ }).passthrough().optional(),
225
+ /** Populado quando operador humano envia (event=out + user.id) — sinal de presença para handoff (DA-10). */
226
+ user: z.object({
227
+ id: z.union([z.number(), z.string()]).transform(v => String(v)),
228
+ name: z.string().optional(),
229
+ external_id: z.string().nullable().optional(),
230
+ }).passthrough().optional(),
231
+ payload: z.object({
232
+ message: zChatbeeNormalizedInnerMessageSchema,
233
+ }).passthrough(),
234
+ timestamp: z.string().optional(),
235
+ }).passthrough();
236
+
237
+ export type IChatbeeNormalizedMessage = z.infer<typeof zChatbeeNormalizedMessageSchema>;
238
+ export type IChatbeeNormalizedInnerMessage = z.infer<typeof zChatbeeNormalizedInnerMessageSchema>;
239
+ export type IChatbeeNormalizedMedia = z.infer<typeof zChatbeeNormalizedMediaSchema>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Adapter Tool Registry — DA-7 do plano hubia-chatbee.
3
+ *
4
+ * Tools com mesmo schema podem ter executores diferentes por provider:
5
+ * - handoff_to_human (hub-waba escreve ticket v3; chatbee escreve em conversations/{X}.mode)
6
+ * - transfer_to_department (idem)
7
+ * - get_conversation_history (hub-waba lê threads v3; chatbee lê apps/evo-chatbee-adapter)
8
+ *
9
+ * Tools shared (get_lead, get_contact, schedule_*, etc.) operam em coleções neutras
10
+ * (evo-people, evo-crm, evo-cale) e ficam fora do registry — são sempre disponíveis.
11
+ *
12
+ * Interfaces puramente TS (não-zod) — executors são funções callable em runtime,
13
+ * não há shape estável para validação JSON.
14
+ */
15
+ import type { IHubiaV1ChannelConfig } from "./zod-schemas";
16
+ export type IAdapterProvider = "chatbee" | "hub-waba";
17
+ export interface IAdapterToolDefinition {
18
+ /** Nome da tool conforme exposto ao Claude. Mesma string para tools compartilháveis entre adapters. */
19
+ name: string;
20
+ /** Descrição em inglês ou pt-BR — visível para o LLM. */
21
+ description: string;
22
+ /** JSON Schema Anthropic-compatible (objeto, properties, required, ...). */
23
+ input_schema: Record<string, unknown>;
24
+ }
25
+ export interface IToolExecutionContext {
26
+ tenant: string;
27
+ /** ID da conversation v3 (hub-waba) ou cb_<contactId> (chatbee). */
28
+ conversationId?: string;
29
+ contactId?: string;
30
+ channelId?: string;
31
+ threadId?: string;
32
+ ticketId?: string;
33
+ executionId?: string;
34
+ /** Snapshot da config hubia do canal — útil para tools provider-aware. */
35
+ cfg?: Partial<IHubiaV1ChannelConfig>;
36
+ }
37
+ export interface IToolExecutor {
38
+ execute(input: Record<string, unknown>, ctx: IToolExecutionContext): Promise<unknown>;
39
+ }
40
+ export interface IAdapterToolRegistry {
41
+ provider: IAdapterProvider;
42
+ /** Tools provider-specific definidas neste adapter. */
43
+ tools: IAdapterToolDefinition[];
44
+ /** Executores indexados por `tool.name`. */
45
+ executors: Record<string, IToolExecutor>;
46
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /**
3
+ * Adapter Tool Registry — DA-7 do plano hubia-chatbee.
4
+ *
5
+ * Tools com mesmo schema podem ter executores diferentes por provider:
6
+ * - handoff_to_human (hub-waba escreve ticket v3; chatbee escreve em conversations/{X}.mode)
7
+ * - transfer_to_department (idem)
8
+ * - get_conversation_history (hub-waba lê threads v3; chatbee lê apps/evo-chatbee-adapter)
9
+ *
10
+ * Tools shared (get_lead, get_contact, schedule_*, etc.) operam em coleções neutras
11
+ * (evo-people, evo-crm, evo-cale) e ficam fora do registry — são sempre disponíveis.
12
+ *
13
+ * Interfaces puramente TS (não-zod) — executors são funções callable em runtime,
14
+ * não há shape estável para validação JSON.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Adapter Tool Registry — DA-7 do plano hubia-chatbee.
3
+ *
4
+ * Tools com mesmo schema podem ter executores diferentes por provider:
5
+ * - handoff_to_human (hub-waba escreve ticket v3; chatbee escreve em conversations/{X}.mode)
6
+ * - transfer_to_department (idem)
7
+ * - get_conversation_history (hub-waba lê threads v3; chatbee lê apps/evo-chatbee-adapter)
8
+ *
9
+ * Tools shared (get_lead, get_contact, schedule_*, etc.) operam em coleções neutras
10
+ * (evo-people, evo-crm, evo-cale) e ficam fora do registry — são sempre disponíveis.
11
+ *
12
+ * Interfaces puramente TS (não-zod) — executors são funções callable em runtime,
13
+ * não há shape estável para validação JSON.
14
+ */
15
+
16
+ import type { IHubiaV1ChannelConfig } from "./zod-schemas";
17
+
18
+ export type IAdapterProvider = "chatbee" | "hub-waba";
19
+
20
+ export interface IAdapterToolDefinition {
21
+ /** Nome da tool conforme exposto ao Claude. Mesma string para tools compartilháveis entre adapters. */
22
+ name: string;
23
+ /** Descrição em inglês ou pt-BR — visível para o LLM. */
24
+ description: string;
25
+ /** JSON Schema Anthropic-compatible (objeto, properties, required, ...). */
26
+ input_schema: Record<string, unknown>;
27
+ }
28
+
29
+ export interface IToolExecutionContext {
30
+ tenant: string;
31
+ /** ID da conversation v3 (hub-waba) ou cb_<contactId> (chatbee). */
32
+ conversationId?: string;
33
+ contactId?: string;
34
+ channelId?: string;
35
+ threadId?: string;
36
+ ticketId?: string;
37
+ executionId?: string;
38
+ /** Snapshot da config hubia do canal — útil para tools provider-aware. */
39
+ cfg?: Partial<IHubiaV1ChannelConfig>;
40
+ }
41
+
42
+ export interface IToolExecutor {
43
+ execute(
44
+ input: Record<string, unknown>,
45
+ ctx: IToolExecutionContext,
46
+ ): Promise<unknown>;
47
+ }
48
+
49
+ export interface IAdapterToolRegistry {
50
+ provider: IAdapterProvider;
51
+ /** Tools provider-specific definidas neste adapter. */
52
+ tools: IAdapterToolDefinition[];
53
+ /** Executores indexados por `tool.name`. */
54
+ executors: Record<string, IToolExecutor>;
55
+ }
@@ -121,6 +121,16 @@ export declare const zHubiaV1ChannelConfigSchema: z.ZodObject<{
121
121
  can_read_finops?: boolean | undefined;
122
122
  }>>;
123
123
  timezone: z.ZodDefault<z.ZodString>;
124
+ /** Provider que entrega mensagens deste canal. Quando ausente, runtime assume 'hub-waba' (back-compat). */
125
+ provider: z.ZodOptional<z.ZodEnum<["chatbee", "hub-waba"]>>;
126
+ /** Para provider='chatbee': id do canal no Chatbee (numérico stringificado). */
127
+ chatbee_channel_id: z.ZodOptional<z.ZodString>;
128
+ /** Para provider='chatbee': company_id que resolve a API key do Chatbee. */
129
+ chatbee_company_id: z.ZodOptional<z.ZodNumber>;
130
+ /** Department padrão para AI router. Para Chatbee, único caminho (não há canal v3). Para hub-waba, fallback caso ticket não tenha department. */
131
+ default_department_id: z.ZodOptional<z.ZodString>;
132
+ /** Quantidade máxima de mensagens carregadas pela tool `get_conversation_history` (auto-injection). Default runtime: 30. */
133
+ history_size: z.ZodOptional<z.ZodNumber>;
124
134
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
125
135
  id: z.ZodString;
126
136
  ref: z.ZodAny;
@@ -241,6 +251,16 @@ export declare const zHubiaV1ChannelConfigSchema: z.ZodObject<{
241
251
  can_read_finops?: boolean | undefined;
242
252
  }>>;
243
253
  timezone: z.ZodDefault<z.ZodString>;
254
+ /** Provider que entrega mensagens deste canal. Quando ausente, runtime assume 'hub-waba' (back-compat). */
255
+ provider: z.ZodOptional<z.ZodEnum<["chatbee", "hub-waba"]>>;
256
+ /** Para provider='chatbee': id do canal no Chatbee (numérico stringificado). */
257
+ chatbee_channel_id: z.ZodOptional<z.ZodString>;
258
+ /** Para provider='chatbee': company_id que resolve a API key do Chatbee. */
259
+ chatbee_company_id: z.ZodOptional<z.ZodNumber>;
260
+ /** Department padrão para AI router. Para Chatbee, único caminho (não há canal v3). Para hub-waba, fallback caso ticket não tenha department. */
261
+ default_department_id: z.ZodOptional<z.ZodString>;
262
+ /** Quantidade máxima de mensagens carregadas pela tool `get_conversation_history` (auto-injection). Default runtime: 30. */
263
+ history_size: z.ZodOptional<z.ZodNumber>;
244
264
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
245
265
  id: z.ZodString;
246
266
  ref: z.ZodAny;
@@ -361,8 +381,92 @@ export declare const zHubiaV1ChannelConfigSchema: z.ZodObject<{
361
381
  can_read_finops?: boolean | undefined;
362
382
  }>>;
363
383
  timezone: z.ZodDefault<z.ZodString>;
384
+ /** Provider que entrega mensagens deste canal. Quando ausente, runtime assume 'hub-waba' (back-compat). */
385
+ provider: z.ZodOptional<z.ZodEnum<["chatbee", "hub-waba"]>>;
386
+ /** Para provider='chatbee': id do canal no Chatbee (numérico stringificado). */
387
+ chatbee_channel_id: z.ZodOptional<z.ZodString>;
388
+ /** Para provider='chatbee': company_id que resolve a API key do Chatbee. */
389
+ chatbee_company_id: z.ZodOptional<z.ZodNumber>;
390
+ /** Department padrão para AI router. Para Chatbee, único caminho (não há canal v3). Para hub-waba, fallback caso ticket não tenha department. */
391
+ default_department_id: z.ZodOptional<z.ZodString>;
392
+ /** Quantidade máxima de mensagens carregadas pela tool `get_conversation_history` (auto-injection). Default runtime: 30. */
393
+ history_size: z.ZodOptional<z.ZodNumber>;
364
394
  }, z.ZodTypeAny, "passthrough">>;
365
395
  export type IHubiaV1ChannelConfig = z.infer<typeof zHubiaV1ChannelConfigSchema>;
396
+ export declare const zHubiaConversationMessageSchema: z.ZodObject<{
397
+ id: z.ZodString;
398
+ direction: z.ZodEnum<["in", "out"]>;
399
+ /** Role pronto para LLM (Anthropic messages API). */
400
+ role: z.ZodEnum<["user", "assistant"]>;
401
+ text: z.ZodDefault<z.ZodString>;
402
+ type: z.ZodDefault<z.ZodEnum<["text", "audio", "image", "document", "event"]>>;
403
+ audio_transcript: z.ZodOptional<z.ZodString>;
404
+ source: z.ZodEnum<["patient", "ai", "operator", "n8n"]>;
405
+ provider: z.ZodEnum<["chatbee", "hub-waba"]>;
406
+ provider_message_id: z.ZodString;
407
+ execution_id: z.ZodOptional<z.ZodString>;
408
+ created_by: z.ZodOptional<z.ZodObject<{
409
+ user_id: z.ZodOptional<z.ZodString>;
410
+ agent: z.ZodOptional<z.ZodString>;
411
+ }, "strip", z.ZodTypeAny, {
412
+ agent?: string | undefined;
413
+ user_id?: string | undefined;
414
+ }, {
415
+ agent?: string | undefined;
416
+ user_id?: string | undefined;
417
+ }>>;
418
+ /** Timestamp do payload original — NÃO serverTimestamp (preserva ordem cronológica real). */
419
+ occurred_at: z.ZodAny;
420
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
421
+ id: z.ZodString;
422
+ direction: z.ZodEnum<["in", "out"]>;
423
+ /** Role pronto para LLM (Anthropic messages API). */
424
+ role: z.ZodEnum<["user", "assistant"]>;
425
+ text: z.ZodDefault<z.ZodString>;
426
+ type: z.ZodDefault<z.ZodEnum<["text", "audio", "image", "document", "event"]>>;
427
+ audio_transcript: z.ZodOptional<z.ZodString>;
428
+ source: z.ZodEnum<["patient", "ai", "operator", "n8n"]>;
429
+ provider: z.ZodEnum<["chatbee", "hub-waba"]>;
430
+ provider_message_id: z.ZodString;
431
+ execution_id: z.ZodOptional<z.ZodString>;
432
+ created_by: z.ZodOptional<z.ZodObject<{
433
+ user_id: z.ZodOptional<z.ZodString>;
434
+ agent: z.ZodOptional<z.ZodString>;
435
+ }, "strip", z.ZodTypeAny, {
436
+ agent?: string | undefined;
437
+ user_id?: string | undefined;
438
+ }, {
439
+ agent?: string | undefined;
440
+ user_id?: string | undefined;
441
+ }>>;
442
+ /** Timestamp do payload original — NÃO serverTimestamp (preserva ordem cronológica real). */
443
+ occurred_at: z.ZodAny;
444
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
445
+ id: z.ZodString;
446
+ direction: z.ZodEnum<["in", "out"]>;
447
+ /** Role pronto para LLM (Anthropic messages API). */
448
+ role: z.ZodEnum<["user", "assistant"]>;
449
+ text: z.ZodDefault<z.ZodString>;
450
+ type: z.ZodDefault<z.ZodEnum<["text", "audio", "image", "document", "event"]>>;
451
+ audio_transcript: z.ZodOptional<z.ZodString>;
452
+ source: z.ZodEnum<["patient", "ai", "operator", "n8n"]>;
453
+ provider: z.ZodEnum<["chatbee", "hub-waba"]>;
454
+ provider_message_id: z.ZodString;
455
+ execution_id: z.ZodOptional<z.ZodString>;
456
+ created_by: z.ZodOptional<z.ZodObject<{
457
+ user_id: z.ZodOptional<z.ZodString>;
458
+ agent: z.ZodOptional<z.ZodString>;
459
+ }, "strip", z.ZodTypeAny, {
460
+ agent?: string | undefined;
461
+ user_id?: string | undefined;
462
+ }, {
463
+ agent?: string | undefined;
464
+ user_id?: string | undefined;
465
+ }>>;
466
+ /** Timestamp do payload original — NÃO serverTimestamp (preserva ordem cronológica real). */
467
+ occurred_at: z.ZodAny;
468
+ }, z.ZodTypeAny, "passthrough">>;
469
+ export type IHubiaConversationMessage = z.infer<typeof zHubiaConversationMessageSchema>;
366
470
  export declare const zHubiaConversationModeSchema: z.ZodEnum<["ai_only", "hybrid_assist", "human_only", "blocked"]>;
367
471
  export type IHubiaConversationMode = z.infer<typeof zHubiaConversationModeSchema>;
368
472
  export declare const zAiBindingSchema: z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zAiBindingSchema = exports.zHubiaConversationModeSchema = exports.zHubiaV1ChannelConfigSchema = exports.zHubiaAttendanceModeSchema = void 0;
3
+ exports.zAiBindingSchema = exports.zHubiaConversationModeSchema = exports.zHubiaConversationMessageSchema = exports.zHubiaV1ChannelConfigSchema = exports.zHubiaAttendanceModeSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const zod_schemas_1 = require("../../shared/zod-schemas");
6
6
  // ───────── Attendance Mode (how AI operates on this channel) ─────────
@@ -43,6 +43,41 @@ exports.zHubiaV1ChannelConfigSchema = zod_schemas_1.zFireDocSchema.extend({
43
43
  can_read_finops: zod_1.z.boolean().default(false),
44
44
  }).optional(),
45
45
  timezone: zod_1.z.string().default("America/Sao_Paulo"),
46
+ // ───── Multi-provider (chatbee adapter) ─────
47
+ /** Provider que entrega mensagens deste canal. Quando ausente, runtime assume 'hub-waba' (back-compat). */
48
+ provider: zod_1.z.enum(["chatbee", "hub-waba"]).optional(),
49
+ /** Para provider='chatbee': id do canal no Chatbee (numérico stringificado). */
50
+ chatbee_channel_id: zod_1.z.string().optional(),
51
+ /** Para provider='chatbee': company_id que resolve a API key do Chatbee. */
52
+ chatbee_company_id: zod_1.z.number().optional(),
53
+ /** Department padrão para AI router. Para Chatbee, único caminho (não há canal v3). Para hub-waba, fallback caso ticket não tenha department. */
54
+ default_department_id: zod_1.z.string().optional(),
55
+ /** Quantidade máxima de mensagens carregadas pela tool `get_conversation_history` (auto-injection). Default runtime: 30. */
56
+ history_size: zod_1.z.number().int().positive().optional(),
57
+ }).passthrough();
58
+ // ───────── Conversation Message (histórico provider-agnostic) ─────────
59
+ //
60
+ // Schema usado pela tool `get_conversation_history` (DA-7/DA-8).
61
+ // Hub-waba lê de `apps/evo-chat/threads/{tid}/messages` (v3 existente).
62
+ // Chatbee lê de `apps/evo-chatbee-adapter/conversations/{cb}/messages` (criada pelo adapter).
63
+ exports.zHubiaConversationMessageSchema = zod_1.z.object({
64
+ id: zod_1.z.string(),
65
+ direction: zod_1.z.enum(["in", "out"]),
66
+ /** Role pronto para LLM (Anthropic messages API). */
67
+ role: zod_1.z.enum(["user", "assistant"]),
68
+ text: zod_1.z.string().default(""),
69
+ type: zod_1.z.enum(["text", "audio", "image", "document", "event"]).default("text"),
70
+ audio_transcript: zod_1.z.string().optional(),
71
+ source: zod_1.z.enum(["patient", "ai", "operator", "n8n"]),
72
+ provider: zod_1.z.enum(["chatbee", "hub-waba"]),
73
+ provider_message_id: zod_1.z.string(),
74
+ execution_id: zod_1.z.string().optional(),
75
+ created_by: zod_1.z.object({
76
+ user_id: zod_1.z.string().optional(),
77
+ agent: zod_1.z.string().optional(),
78
+ }).optional(),
79
+ /** Timestamp do payload original — NÃO serverTimestamp (preserva ordem cronológica real). */
80
+ occurred_at: zod_1.z.any(),
46
81
  }).passthrough();
47
82
  // ───────── Conversation Mode ─────────
48
83
  exports.zHubiaConversationModeSchema = zod_1.z.enum(["ai_only", "hybrid_assist", "human_only", "blocked"]);
@@ -46,10 +46,50 @@ export const zHubiaV1ChannelConfigSchema = zFireDocSchema.extend({
46
46
  can_read_finops: z.boolean().default(false),
47
47
  }).optional(),
48
48
  timezone: z.string().default("America/Sao_Paulo"),
49
+
50
+ // ───── Multi-provider (chatbee adapter) ─────
51
+ /** Provider que entrega mensagens deste canal. Quando ausente, runtime assume 'hub-waba' (back-compat). */
52
+ provider: z.enum(["chatbee", "hub-waba"]).optional(),
53
+ /** Para provider='chatbee': id do canal no Chatbee (numérico stringificado). */
54
+ chatbee_channel_id: z.string().optional(),
55
+ /** Para provider='chatbee': company_id que resolve a API key do Chatbee. */
56
+ chatbee_company_id: z.number().optional(),
57
+ /** Department padrão para AI router. Para Chatbee, único caminho (não há canal v3). Para hub-waba, fallback caso ticket não tenha department. */
58
+ default_department_id: z.string().optional(),
59
+ /** Quantidade máxima de mensagens carregadas pela tool `get_conversation_history` (auto-injection). Default runtime: 30. */
60
+ history_size: z.number().int().positive().optional(),
49
61
  }).passthrough();
50
62
 
51
63
  export type IHubiaV1ChannelConfig = z.infer<typeof zHubiaV1ChannelConfigSchema>;
52
64
 
65
+ // ───────── Conversation Message (histórico provider-agnostic) ─────────
66
+ //
67
+ // Schema usado pela tool `get_conversation_history` (DA-7/DA-8).
68
+ // Hub-waba lê de `apps/evo-chat/threads/{tid}/messages` (v3 existente).
69
+ // Chatbee lê de `apps/evo-chatbee-adapter/conversations/{cb}/messages` (criada pelo adapter).
70
+
71
+ export const zHubiaConversationMessageSchema = z.object({
72
+ id: z.string(),
73
+ direction: z.enum(["in", "out"]),
74
+ /** Role pronto para LLM (Anthropic messages API). */
75
+ role: z.enum(["user", "assistant"]),
76
+ text: z.string().default(""),
77
+ type: z.enum(["text", "audio", "image", "document", "event"]).default("text"),
78
+ audio_transcript: z.string().optional(),
79
+ source: z.enum(["patient", "ai", "operator", "n8n"]),
80
+ provider: z.enum(["chatbee", "hub-waba"]),
81
+ provider_message_id: z.string(),
82
+ execution_id: z.string().optional(),
83
+ created_by: z.object({
84
+ user_id: z.string().optional(),
85
+ agent: z.string().optional(),
86
+ }).optional(),
87
+ /** Timestamp do payload original — NÃO serverTimestamp (preserva ordem cronológica real). */
88
+ occurred_at: z.any(),
89
+ }).passthrough();
90
+
91
+ export type IHubiaConversationMessage = z.infer<typeof zHubiaConversationMessageSchema>;
92
+
53
93
  // ───────── Conversation Mode ─────────
54
94
 
55
95
  export const zHubiaConversationModeSchema = z.enum(["ai_only", "hybrid_assist", "human_only", "blocked"]);
package/dist/index.d.ts CHANGED
@@ -46,6 +46,7 @@ export * from "./apps/evo-chat/waba-setup/zod-schemas";
46
46
  export * from "./apps/evo-chat/quick-reply/zod-schemas";
47
47
  export * from "./apps/evo-hub-ia/channel/zod-schemas";
48
48
  export * from "./apps/evo-hub-ia/v1/zod-schemas";
49
+ export * from "./apps/evo-hub-ia/v1/adapter-tool-registry";
49
50
  export * from "./apps/evo-med/calendar/zod-schemas";
50
51
  export * from "./apps/evo-med/appointment/zod-schemas";
51
52
  export * from "./apps/evo-med/dic/zod-schemas";
package/dist/index.js CHANGED
@@ -64,6 +64,7 @@ __exportStar(require("./apps/evo-chat/waba-setup/zod-schemas"), exports);
64
64
  __exportStar(require("./apps/evo-chat/quick-reply/zod-schemas"), exports);
65
65
  __exportStar(require("./apps/evo-hub-ia/channel/zod-schemas"), exports);
66
66
  __exportStar(require("./apps/evo-hub-ia/v1/zod-schemas"), exports);
67
+ __exportStar(require("./apps/evo-hub-ia/v1/adapter-tool-registry"), exports);
67
68
  __exportStar(require("./apps/evo-med/calendar/zod-schemas"), exports);
68
69
  __exportStar(require("./apps/evo-med/appointment/zod-schemas"), exports);
69
70
  __exportStar(require("./apps/evo-med/dic/zod-schemas"), exports);
package/dist/index.ts CHANGED
@@ -49,6 +49,7 @@ export * from "./apps/evo-chat/waba-setup/zod-schemas";
49
49
  export * from "./apps/evo-chat/quick-reply/zod-schemas";
50
50
  export * from "./apps/evo-hub-ia/channel/zod-schemas";
51
51
  export * from "./apps/evo-hub-ia/v1/zod-schemas";
52
+ export * from "./apps/evo-hub-ia/v1/adapter-tool-registry";
52
53
  export * from "./apps/evo-med/calendar/zod-schemas";
53
54
  export * from "./apps/evo-med/appointment/zod-schemas";
54
55
  export * from "./apps/evo-med/dic/zod-schemas";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evo360-types",
3
- "version": "1.3.354",
3
+ "version": "1.3.355",
4
4
  "description": "HREVO360 Shared Types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",