@adatechnology/conversations-ui 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as react from 'react';
2
2
  import react__default, { ReactNode, CSSProperties, UIEvent, FormEvent, RefObject, KeyboardEvent } from 'react';
3
3
  import { M as MessagePayload, I as InteractiveSelection, a as MessageTranscription, C as ConversationChannel, e as InteractivePayload, f as ConversationsFeatures, Q as QuickReply$1, T as TranscriptionMode, g as QueuedAttachment, b as QuickReplyInput, c as QuickReplyAttachment, h as ConversationVariable, i as ChannelFilter, j as ChannelFilterOption } from './quickReply.types-DzWH3NYV.js';
4
4
  export { k as CHANNEL_CAPABILITIES, l as CHANNEL_FILTER_ALL, m as CONVERSATION_CHANNEL, n as ChannelCapabilities, d as ConversationsTheme, o as ConversationsUIConfig, D as DEFAULT_CONVERSATION_CHANNEL, F as FormatContactHandleParams, H as HANDLE_KIND, p as HandleKind, q as InteractiveOption, r as InteractiveSection, s as QUICK_REPLY_ATTACHMENT_LIMIT, R as REOPEN_MECHANISM, t as ReopenMechanism, S as StoredAttachmentSendResult, u as TranscriptionStatus, v as capabilitiesOf, w as channelFiltersFor, x as contactFlag, y as formatContactHandle } from './quickReply.types-DzWH3NYV.js';
5
- import { R as ResolveMediaUrl, C as ConversationSummary, L as ListConversationsParams, b as ConversationsApi, S as SSEProvider, Q as ListDocumentsParams, d as ConversationDocument, U as ConversationTemplate, k as ConversationSimulatorClient, m as ConversationSimulatorPanelLabels, P as PreviewUploadedMedia } from './ConversationSimulatorPanel-P6eqTSAO.js';
6
- export { A as AudioRecorderButton, g as AudioRecorderButtonLabels, h as AudioRecorderButtonProps, V as CompanyDocument, W as CompanyDocumentPage, X as ConversationDocumentPage, a as ConversationEventSource, c as ConversationPage, D as DEFAULT_AUDIO_RECORDER_BUTTON_LABELS, Y as MediaRenderer, Z as MediaRendererProps, y as SendSimulatorMediaParams, z as SimulatorMediaKind } from './ConversationSimulatorPanel-P6eqTSAO.js';
5
+ import { R as ResolveMediaUrl, C as ConversationSummary, L as ListConversationsParams, b as ConversationsApi, S as SSEProvider, Q as ListDocumentsParams, d as ConversationDocument, U as ConversationTemplate, j as ConversationSimulatorClient, l as ConversationSimulatorPanelLabels, P as PreviewUploadedMedia } from './ConversationSimulatorPanel-DSVIch04.js';
6
+ export { A as AudioRecorderButton, f as AudioRecorderButtonLabels, g as AudioRecorderButtonProps, V as CompanyDocument, W as CompanyDocumentPage, X as ConversationDocumentPage, a as ConversationEventSource, c as ConversationPage, D as DEFAULT_AUDIO_RECORDER_BUTTON_LABELS, Y as MediaRenderer, Z as MediaRendererProps, y as SendSimulatorMediaParams, z as SimulatorMediaKind } from './ConversationSimulatorPanel-DSVIch04.js';
7
7
  import { ChannelCapability } from '@adatechnology/conversation-contracts';
8
8
  export { ChannelCapability } from '@adatechnology/conversation-contracts';
9
9
  import '@adatechnology/meta-whatsapp-contracts/testing';
@@ -1,7 +1,8 @@
1
1
  import { M as MessagePayload } from '../quickReply.types-DzWH3NYV.js';
2
- import { C as ConversationSummary, a as ConversationEventSource, b as ConversationsApi, L as ListConversationsParams, c as ConversationPage, S as SSEProvider, d as ConversationDocument, e as SendPreviewMediaParams, P as PreviewUploadedMedia, f as PreviewWebhookClient, R as ResolveMediaUrl } from '../ConversationSimulatorPanel-P6eqTSAO.js';
3
- export { A as AudioRecorderButton, g as AudioRecorderButtonLabels, h as AudioRecorderButtonProps, i as ConversationPreview, j as ConversationPreviewProps, k as ConversationSimulatorClient, l as ConversationSimulatorPanel, m as ConversationSimulatorPanelLabels, n as ConversationSimulatorPanelProps, o as CreatePreviewMediaUploaderParams, p as CreatePreviewWebhookClientParams, D as DEFAULT_AUDIO_RECORDER_BUTTON_LABELS, q as DEFAULT_CONVERSATION_SIMULATOR_PANEL_LABELS, r as DEFAULT_MEDIA_UPLOAD_PATH, s as PreviewInProductionError, t as PreviewMediaUploadRejectedError, u as PreviewMediaUploadRequest, v as PreviewUploadedMedia, w as PreviewWebhookRejectedError, x as SIMULATOR_FILE_MEDIA_KINDS, y as SendSimulatorMediaParams, z as SimulatorMediaKind, T as ToSimulatorClientParams, B as acceptsMediaKind, E as assertPreviewEnvironment, F as createPreviewMediaPoster, G as createPreviewMediaUploader, H as createPreviewWebhookClient, I as isConversationSimulatorClient, J as mediaKindOf, K as mediaTypeOf, M as signPreviewPayload, N as simulatorPanelLabelsOf, O as toConversationSimulatorClient } from '../ConversationSimulatorPanel-P6eqTSAO.js';
4
- import { InteractiveReplyOption } from '@adatechnology/meta-whatsapp-contracts/testing';
2
+ import { C as ConversationSummary, a as ConversationEventSource, b as ConversationsApi, L as ListConversationsParams, c as ConversationPage, S as SSEProvider, d as ConversationDocument, P as PreviewUploadedMedia, e as PreviewWebhookClient, R as ResolveMediaUrl } from '../ConversationSimulatorPanel-DSVIch04.js';
3
+ export { A as AudioRecorderButton, f as AudioRecorderButtonLabels, g as AudioRecorderButtonProps, h as ConversationPreview, i as ConversationPreviewProps, j as ConversationSimulatorClient, k as ConversationSimulatorPanel, l as ConversationSimulatorPanelLabels, m as ConversationSimulatorPanelProps, n as CreatePreviewMediaUploaderParams, o as CreatePreviewWebhookClientParams, D as DEFAULT_AUDIO_RECORDER_BUTTON_LABELS, p as DEFAULT_CONVERSATION_SIMULATOR_PANEL_LABELS, q as DEFAULT_MEDIA_UPLOAD_PATH, r as PreviewInProductionError, s as PreviewMediaUploadRejectedError, t as PreviewMediaUploadRequest, u as PreviewUploadedMedia, v as PreviewWebhookRejectedError, w as SIMULATOR_FILE_MEDIA_KINDS, x as SendPreviewMediaParams, y as SendSimulatorMediaParams, z as SimulatorMediaKind, T as ToSimulatorClientParams, B as acceptsMediaKind, E as assertPreviewEnvironment, F as createPreviewMediaPoster, G as createPreviewMediaUploader, H as createPreviewWebhookClient, I as isConversationSimulatorClient, J as mediaKindOf, K as mediaTypeOf, M as signPreviewPayload, N as simulatorPanelLabelsOf, O as toConversationSimulatorClient } from '../ConversationSimulatorPanel-DSVIch04.js';
4
+ import { PreviewInboundCommand } from '@adatechnology/meta-whatsapp-contracts/testing';
5
+ export { PreviewInboundCommand } from '@adatechnology/meta-whatsapp-contracts/testing';
5
6
  import * as react from 'react';
6
7
  export { PREVIEW_MEDIA_ID_PREFIX } from '@adatechnology/meta-whatsapp-contracts';
7
8
  import '@adatechnology/conversation-contracts';
@@ -132,37 +133,20 @@ declare const PREVIEW_DOCUMENTS: Readonly<Record<string, readonly ConversationDo
132
133
  * porque token, cookie e cabeçalho de sessão são do produto, não da biblioteca.
133
134
  */
134
135
 
135
- /**
136
- * Comando semântico entregue ao host. É deliberadamente o QUE o cliente fez, não o payload da Meta:
137
- * se o navegador mandasse o payload pronto, a rota viraria um injetor de webhook arbitrário para
138
- * quem tivesse sessão. Mandando a intenção, o servidor é quem escolhe a forma.
139
- */
140
- type PreviewInboundCommand = {
141
- readonly kind: 'text';
142
- readonly from: string;
143
- readonly text: string;
144
- } | {
145
- readonly kind: 'buttonReply';
146
- readonly from: string;
147
- readonly reply: InteractiveReplyOption;
148
- } | {
149
- readonly kind: 'listReply';
150
- readonly from: string;
151
- readonly reply: InteractiveReplyOption;
152
- } | {
153
- readonly kind: 'audio';
154
- readonly from: string;
155
- readonly mediaId: string;
156
- } | ({
157
- readonly kind: 'media';
158
- readonly from: string;
159
- } & SendPreviewMediaParams);
160
136
  type SendPreviewInboundCommand = (command: PreviewInboundCommand) => Promise<void>;
161
137
  declare class PreviewBridgeRejectedError extends Error {
162
138
  readonly status: number;
163
139
  constructor(status: number);
164
140
  }
165
141
  type CreatePreviewBridgeClientParams = {
142
+ /**
143
+ * Número do contato simulado, usado como veio — trocar o número abre outra conversa.
144
+ *
145
+ * Contato de simulador sem chamar a Meta é opt-in nas DUAS pontas: aqui
146
+ * `from: DEFAULT_PREVIEW_CONTACT` (começa com `0`, que nenhum número real usa) e, no servidor,
147
+ * `features.previewContacts: true`. Só um dos lados ligado não serve: sem a flag, o servidor tentaria
148
+ * responder pela Meta a um número que não existe.
149
+ */
166
150
  readonly from: string;
167
151
  /**
168
152
  * Entrega o comando. Use quando o host já tem um cliente HTTP com sessão, interceptors e refresh
@@ -286,4 +270,4 @@ type MediaTypesPreviewProps = {
286
270
  };
287
271
  declare function MediaTypesPreview({ conversationId, className, }: MediaTypesPreviewProps): react.JSX.Element;
288
272
 
289
- export { type AppendMessageParams, type CreateMockConversationsApiParams, type CreateMockSSEProviderParams, type CreatePreviewBridgeClientParams, type CreatePreviewStoreParams, DEFAULT_PREVIEW_SCRIPT, GLOBAL_CHANNEL, type ListConversationsFilters, MEDIA_TYPES_CONVERSATION_ID, MediaTypesPreview, type MediaTypesPreviewProps, type MockEventSource, PREVIEW_CONVERSATIONS, PREVIEW_DOCUMENTS, PREVIEW_FILE_SAMPLES, PREVIEW_MESSAGES, PreviewBridgeRejectedError, type PreviewEmission, type PreviewInboundCommand, type PreviewScriptStep, type PreviewStore, type PreviewStoreListener, PreviewWebhookClient, type SendPreviewInboundCommand, SendPreviewMediaParams, type SetModeParams, type StartPreviewScriptParams, conversationChannel, createMockConversationsApi, createMockEventSource, createMockSSEProvider, createPreviewBridgeClient, createPreviewMediaResolver, createPreviewStore, previewFileBase64, previewFileUrl, resolvePreviewFileSample, startPreviewScript };
273
+ export { type AppendMessageParams, type CreateMockConversationsApiParams, type CreateMockSSEProviderParams, type CreatePreviewBridgeClientParams, type CreatePreviewStoreParams, DEFAULT_PREVIEW_SCRIPT, GLOBAL_CHANNEL, type ListConversationsFilters, MEDIA_TYPES_CONVERSATION_ID, MediaTypesPreview, type MediaTypesPreviewProps, type MockEventSource, PREVIEW_CONVERSATIONS, PREVIEW_DOCUMENTS, PREVIEW_FILE_SAMPLES, PREVIEW_MESSAGES, PreviewBridgeRejectedError, type PreviewEmission, type PreviewScriptStep, type PreviewStore, type PreviewStoreListener, PreviewWebhookClient, type SendPreviewInboundCommand, type SetModeParams, type StartPreviewScriptParams, conversationChannel, createMockConversationsApi, createMockEventSource, createMockSSEProvider, createPreviewBridgeClient, createPreviewMediaResolver, createPreviewStore, previewFileBase64, previewFileUrl, resolvePreviewFileSample, startPreviewScript };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adatechnology/conversations-ui",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "WhatsApp conversation UI components — parametrizável por endpoint, tema e feature flags",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -36,7 +36,7 @@
36
36
  "lucide-react": "^1.21.0",
37
37
  "tailwind-merge": "^3.6.0",
38
38
  "@adatechnology/conversation-contracts": "0.7.0",
39
- "@adatechnology/meta-whatsapp-contracts": "0.6.1"
39
+ "@adatechnology/meta-whatsapp-contracts": "0.8.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@xyflow/react": "^12",
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Copyright (c) 2026 Ada Technology. MIT License.
3
+ *
4
+ * Rotas por palavra-chave (`next.byKeyword`): texto livre que contém a palavra leva ao destino.
5
+ */
6
+
7
+ import type { ReactNode } from 'react'
8
+ import { Plus, Trash2 } from 'lucide-react'
9
+ import type { FlowNodeData } from './flowGraph'
10
+ import type { FlowRunnerFieldLabels } from './labels'
11
+ import { PANEL_FIELD_CLASSNAME, PANEL_HINT_CLASSNAME, PANEL_LABEL_CLASSNAME } from './flowPanelStyles'
12
+
13
+ export type FlowKeywordRoutesFieldProps = {
14
+ draft: FlowNodeData
15
+ onDraftChange: (update: (previous: FlowNodeData) => FlowNodeData) => void
16
+ renderTargetOptions: () => ReactNode
17
+ labels: FlowRunnerFieldLabels
18
+ }
19
+
20
+ function withRoutes(node: FlowNodeData, routes: [string, string][]): FlowNodeData {
21
+ const current: Exclude<FlowNodeData['next'], string | undefined> =
22
+ typeof node.next === 'object' && node.next ? node.next : { byAnswer: {}, default: node.next ?? '' }
23
+ const rest = { ...current }
24
+ delete rest.byKeyword
25
+ return { ...node, next: routes.length > 0 ? { ...rest, byKeyword: Object.fromEntries(routes) } : rest }
26
+ }
27
+
28
+ export function FlowKeywordRoutesField({
29
+ draft,
30
+ onDraftChange,
31
+ renderTargetOptions,
32
+ labels,
33
+ }: FlowKeywordRoutesFieldProps) {
34
+ const routes: [string, string][] =
35
+ typeof draft.next === 'object' && draft.next?.byKeyword ? Object.entries(draft.next.byKeyword) : []
36
+
37
+ function updateRoute(index: number, field: 0 | 1, value: string) {
38
+ const next = routes.map((route, routeIndex): [string, string] => {
39
+ if (routeIndex !== index) return route
40
+ return field === 0 ? [value, route[1]] : [route[0], value]
41
+ })
42
+ onDraftChange((previous) => withRoutes(previous, next))
43
+ }
44
+
45
+ function addRoute() {
46
+ onDraftChange((previous) => withRoutes(previous, [...routes, [labels.keywordPlaceholder, '']]))
47
+ }
48
+
49
+ function removeRoute(index: number) {
50
+ onDraftChange((previous) =>
51
+ withRoutes(
52
+ previous,
53
+ routes.filter((_, routeIndex) => routeIndex !== index),
54
+ ),
55
+ )
56
+ }
57
+
58
+ return (
59
+ <div>
60
+ <div className="flex items-center justify-between">
61
+ <label className={PANEL_LABEL_CLASSNAME}>{labels.keywordRoutes}</label>
62
+ <button
63
+ type="button"
64
+ data-cv-tooltip={labels.addKeywordRoute}
65
+ aria-label={labels.addKeywordRoute}
66
+ onClick={addRoute}
67
+ className="text-xs text-blue-600 hover:underline flex items-center gap-1"
68
+ >
69
+ <Plus size={12} aria-hidden="true" /> {labels.addKeywordRoute}
70
+ </button>
71
+ </div>
72
+ <p className={PANEL_HINT_CLASSNAME}>{labels.keywordRoutesHint}</p>
73
+ <div className="space-y-2 mt-1">
74
+ {routes.map(([keyword, target], index) => (
75
+ <div key={index} className="flex items-center gap-2">
76
+ <input
77
+ value={keyword}
78
+ aria-label={labels.keywordRoutes}
79
+ onChange={(event) => updateRoute(index, 0, event.target.value)}
80
+ className={`w-28 ${PANEL_FIELD_CLASSNAME}`}
81
+ />
82
+ <select
83
+ value={target}
84
+ aria-label={labels.keywordRoutes}
85
+ onChange={(event) => updateRoute(index, 1, event.target.value)}
86
+ className={`flex-1 ${PANEL_FIELD_CLASSNAME}`}
87
+ >
88
+ <option value="">—</option>
89
+ {renderTargetOptions()}
90
+ </select>
91
+ <button
92
+ type="button"
93
+ data-cv-tooltip={labels.removeKeywordRoute}
94
+ aria-label={labels.removeKeywordRoute}
95
+ onClick={() => removeRoute(index)}
96
+ className="text-gray-400 hover:text-red-600"
97
+ >
98
+ <Trash2 size={14} aria-hidden="true" />
99
+ </button>
100
+ </div>
101
+ ))}
102
+ </div>
103
+ </div>
104
+ )
105
+ }
@@ -17,7 +17,7 @@
17
17
  import { useState } from 'react'
18
18
  import { ChevronDown, ChevronUp, RotateCcw } from 'lucide-react'
19
19
 
20
- import type { FlowEditorLabels } from './labels'
20
+ import { DEFAULT_FLOW_EDITOR_LABELS, type FlowEditorLabels } from './labels'
21
21
  import type { FlowNodeType } from './flowGraph'
22
22
 
23
23
  export type FlowLegendEdgeSample = {
@@ -88,7 +88,7 @@ export function FlowLegend({ labels, edgeSamples, nodeSwatches }: FlowLegendProp
88
88
  <li key={swatch.type} className="flex items-center gap-2">
89
89
  <span className={`h-3 w-5 shrink-0 rounded border-2 ${swatch.className}`} aria-hidden="true" />
90
90
  <span className="text-[11px] leading-tight text-gray-600 dark:text-gray-300">
91
- {labels.legend[swatch.type]}
91
+ {labels.legend[swatch.type] ?? DEFAULT_FLOW_EDITOR_LABELS.legend.dynamic_choice}
92
92
  </span>
93
93
  </li>
94
94
  ))}
@@ -14,9 +14,10 @@ import {
14
14
  ShoppingBag,
15
15
  RotateCcw,
16
16
  type LucideIcon,
17
+ ListChecks,
17
18
  } from 'lucide-react'
18
- import type { FlowEditorLabels } from './labels'
19
- import { PASS_THROUGH_ACTION_KINDS, type FlowNodeData, type GraphIssue } from './flowGraph'
19
+ import { DEFAULT_FLOW_EDITOR_LABELS, type FlowEditorLabels } from './labels'
20
+ import { isPassThroughAction, keywordHandle, type FlowNodeData, type GraphIssue } from './flowGraph'
20
21
 
21
22
  /**
22
23
  * Diâmetro dos pontos de ligação.
@@ -32,6 +33,7 @@ export const NODE_TYPE_COLOR: Record<FlowNodeData['type'], string> = {
32
33
  action: 'border-orange-300 bg-orange-50 dark:bg-orange-950/40 dark:border-orange-800',
33
34
  menu: 'border-emerald-300 bg-emerald-50 dark:bg-emerald-950/40 dark:border-emerald-800',
34
35
  condition: 'border-cyan-300 bg-cyan-50 dark:bg-cyan-950/40 dark:border-cyan-800',
36
+ dynamic_choice: 'border-teal-300 bg-teal-50 dark:bg-teal-950/40 dark:border-teal-800',
35
37
  }
36
38
 
37
39
  const NODE_TYPE_ICON: Record<FlowNodeData['type'], LucideIcon> = {
@@ -40,6 +42,7 @@ const NODE_TYPE_ICON: Record<FlowNodeData['type'], LucideIcon> = {
40
42
  action: Zap,
41
43
  menu: GitBranch,
42
44
  condition: Diamond,
45
+ dynamic_choice: ListChecks,
43
46
  }
44
47
 
45
48
  // Ícone por função da ação — o host estende via `actionKindIcons` (FlowNodeCardData) para
@@ -116,15 +119,18 @@ function selfLoopHandles(node: FlowNodeData): Set<string> {
116
119
  for (const [optionId, target] of Object.entries(node.next.byAnswer ?? {})) {
117
120
  if (target === node.id) loops.add(optionId)
118
121
  }
122
+ for (const [keyword, target] of Object.entries(node.next.byKeyword ?? {})) {
123
+ if (target === node.id) loops.add(keywordHandle(keyword))
124
+ }
119
125
  if (node.next.default === node.id) loops.add('__default')
120
126
 
121
127
  return loops
122
128
  }
123
129
 
124
130
  function sourceRows(node: FlowNodeData, labels: FlowEditorLabels): SourceRowSpec[] {
125
- // Ação de passagem tem saída; ação terminal, não — ver `PASS_THROUGH_ACTION_KINDS`.
131
+ // Ação de passagem tem saída; ação terminal, não — ver `isPassThroughAction`.
126
132
  if (node.type === 'action') {
127
- return node.actionKind && PASS_THROUGH_ACTION_KINDS.includes(node.actionKind)
133
+ return isPassThroughAction(node)
128
134
  ? [{ id: 'next', label: labels.nodePanel.nextRowLabel, isDefault: false, isSelfLoop: false }]
129
135
  : []
130
136
  }
@@ -136,12 +142,25 @@ function sourceRows(node: FlowNodeData, labels: FlowEditorLabels): SourceRowSpec
136
142
  { id: 'false', label: labels.nodePanel.conditionFalse, isDefault: false, isSelfLoop: loops.has('false') },
137
143
  ]
138
144
  }
145
+ // Palavra-chave é uma saída a mais: "horário" leva à resposta sem o cliente tocar em opção.
146
+ const keywordRows = Object.keys(typeof node.next === 'object' ? (node.next.byKeyword ?? {}) : {}).map((keyword) => ({
147
+ id: keywordHandle(keyword),
148
+ label: `“${keyword}”`,
149
+ isDefault: false,
150
+ isSelfLoop: loops.has(keywordHandle(keyword)),
151
+ }))
139
152
  const isChoice = node.type === 'menu' || node.questionType === 'choice'
140
- if (!isChoice)
153
+ if (!isChoice && typeof node.next !== 'object')
141
154
  return [{ id: 'next', label: labels.nodePanel.nextRowLabel, isDefault: false, isSelfLoop: loops.has('next') }]
155
+ if (!isChoice)
156
+ return [
157
+ ...keywordRows,
158
+ { id: '__default', label: labels.nodePanel.nextRowLabel, isDefault: true, isSelfLoop: loops.has('__default') },
159
+ ]
142
160
  const options = node.options ?? []
143
161
  return [
144
162
  ...options.map(([id, label]) => ({ id, label, isDefault: false, isSelfLoop: loops.has(id) })),
163
+ ...keywordRows,
145
164
  { id: '__default', label: labels.edgeFallbackLabel, isDefault: true, isSelfLoop: loops.has('__default') },
146
165
  ]
147
166
  }
@@ -278,7 +297,7 @@ export function FlowNodeCard({ data }: NodeProps) {
278
297
  <span className="flex items-center gap-1.5 uppercase tracking-wide font-semibold text-gray-500 dark:text-gray-400 text-xs">
279
298
  <Icon size={12} strokeWidth={2.5} />
280
299
  {isStart && <span className="h-1.5 w-1.5 rounded-full bg-emerald-500" data-cv-tooltip={labels.startNodeTooltip} />}
281
- {labels.legend[node.type]}
300
+ {labels.legend[node.type] ?? DEFAULT_FLOW_EDITOR_LABELS.legend.dynamic_choice}
282
301
  </span>
283
302
  <div className="flex items-center gap-1">
284
303
  {hasError && (
@@ -2,14 +2,14 @@ import { useState, type ReactNode } from 'react'
2
2
  import { Plus, Trash2, Save, X, AlertTriangle, AlertCircle } from 'lucide-react'
3
3
  import { FlowWhatsAppPreview } from './FlowWhatsAppPreview'
4
4
  import { nodeLabel } from './FlowNodeCard'
5
- import { CROSS_FLOW_PREFIX, CONDITION_OPERATORS, BUILT_IN_ACTION_KINDS, PASS_THROUGH_ACTION_KINDS } from './flowGraph'
6
- import { DEFAULT_FLOW_EDITOR_LABELS, type FlowEditorLabels } from './labels'
5
+ import { CROSS_FLOW_PREFIX, CONDITION_OPERATORS, BUILT_IN_ACTION_KINDS, isPassThroughAction as passesThrough } from './flowGraph'
6
+ import { DEFAULT_FLOW_EDITOR_LABELS, DEFAULT_FLOW_RUNNER_FIELD_LABELS, type FlowEditorLabels } from './labels'
7
+ import { FlowRunnerFields } from './FlowRunnerFields'
7
8
  import type { FlowGraphData, FlowNodeData, GraphIssue } from './flowGraph'
9
+ import { PANEL_FIELD_CLASSNAME } from './flowPanelStyles'
8
10
 
9
- const SELECT_CLASSNAME =
10
- 'border border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent transition-all'
11
- const INPUT_CLASSNAME =
12
- 'border border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent transition-all'
11
+ const SELECT_CLASSNAME = PANEL_FIELD_CLASSNAME
12
+ const INPUT_CLASSNAME = PANEL_FIELD_CLASSNAME
13
13
 
14
14
  function truncateLabel(value: string, max = 60): string {
15
15
  if (!value) return '—'
@@ -21,6 +21,7 @@ function WhatsAppTextField({
21
21
  value,
22
22
  onValueChange,
23
23
  options,
24
+ optionDetails,
24
25
  placeholder,
25
26
  labels,
26
27
  }: {
@@ -28,6 +29,7 @@ function WhatsAppTextField({
28
29
  value: string
29
30
  onValueChange: (value: string) => void
30
31
  options?: [string, string][]
32
+ optionDetails?: FlowNodeData['optionDetails']
31
33
  placeholder?: string
32
34
  labels: FlowEditorLabels
33
35
  }) {
@@ -46,7 +48,7 @@ function WhatsAppTextField({
46
48
  <div>
47
49
  <label className="text-xs font-medium text-gray-500 dark:text-gray-400">{labels.nodePanel.preview}</label>
48
50
  <div className="mt-1">
49
- <FlowWhatsAppPreview body={value} options={options} labels={labels.nodePanel} />
51
+ <FlowWhatsAppPreview body={value} options={options} optionDetails={optionDetails} labels={labels.nodePanel} />
50
52
  </div>
51
53
  </div>
52
54
  </div>
@@ -102,8 +104,9 @@ export function FlowNodePanel({
102
104
  const isFixedLogic = draft.type === 'entrada_choice'
103
105
  const isAction = draft.type === 'action'
104
106
  const isSendMedia = isAction && draft.actionKind === BUILT_IN_ACTION_KINDS.SEND_MEDIA
105
- const isPassThroughAction = isAction && Boolean(draft.actionKind && PASS_THROUGH_ACTION_KINDS.includes(draft.actionKind))
107
+ const isPassThroughAction = passesThrough(draft)
106
108
  const isCondition = draft.type === 'condition'
109
+ const isDynamicChoice = draft.type === 'dynamic_choice'
107
110
  const isStart = graph.startNodeId === node.id
108
111
  const nodeIssues = issues.filter((i) => i.nodeId === node.id)
109
112
  // Chaves já usadas por perguntas deste fluxo — sugestão pro campo de variável da condição,
@@ -238,7 +241,7 @@ export function FlowNodePanel({
238
241
  </div>
239
242
  )}
240
243
 
241
- {!isFixedLogic && !isAction && !isCondition && (
244
+ {!isFixedLogic && !isAction && !isCondition && !isDynamicChoice && (
242
245
  <div>
243
246
  <label className="text-xs font-medium text-gray-500 dark:text-gray-400">
244
247
  {labels.nodePanel.questionType}
@@ -263,7 +266,8 @@ export function FlowNodePanel({
263
266
  <WhatsAppTextField
264
267
  label={labels.nodePanel.question}
265
268
  value={draft.question ?? ''}
266
- options={draft.questionType === 'choice' ? draft.options : undefined}
269
+ options={draft.questionType === 'choice' || draft.type === 'menu' ? draft.options : undefined}
270
+ optionDetails={draft.optionDetails}
267
271
  onValueChange={(value) => setDraft((prev) => ({ ...prev, question: value }))}
268
272
  labels={labels}
269
273
  />
@@ -387,6 +391,16 @@ export function FlowNodePanel({
387
391
  </div>
388
392
  )}
389
393
 
394
+ {!isFixedLogic && !isAction && !isCondition && (
395
+ <FlowRunnerFields
396
+ draft={draft}
397
+ onDraftChange={setDraft}
398
+ renderTargetOptions={nextNodeOptions}
399
+ knownContextKeys={knownContextKeys}
400
+ labels={labels.runnerFields ?? DEFAULT_FLOW_RUNNER_FIELD_LABELS}
401
+ />
402
+ )}
403
+
390
404
  {/* Ação de passagem também escolhe destino: sem isto, o material era enviado e a conversa
391
405
  parava ali, sem caminho para o atendimento. Ação terminal continua sem o campo. */}
392
406
  {(!isAction || isPassThroughAction) && (
@@ -1,14 +1,16 @@
1
1
  import { useEffect, useLayoutEffect, useRef, useState } from 'react'
2
- import { Plus, MessageCircleQuestion, GitBranch, Zap, Diamond, ChevronRight } from 'lucide-react'
2
+ import { Plus, MessageCircleQuestion, GitBranch, Zap, Diamond, ChevronRight, ListChecks, MessageSquareText } from 'lucide-react'
3
3
 
4
4
  import { placeFloatingPanel, type FloatingPlacement } from './flowMenuPlacement'
5
- import { DEFAULT_FLOW_EDITOR_LABELS, type FlowEditorLabels } from './labels'
5
+ import { DEFAULT_FLOW_EDITOR_LABELS, DEFAULT_FLOW_RUNNER_FIELD_LABELS, type FlowEditorLabels } from './labels'
6
6
  import type { FlowActionKind, FlowQuestionType } from './flowGraph'
7
7
 
8
8
  export type NewNodeSpec =
9
9
  | { kind: 'question'; questionType: FlowQuestionType }
10
10
  | { kind: 'decision' }
11
11
  | { kind: 'condition' }
12
+ | { kind: 'dynamicChoice' }
13
+ | { kind: 'message' }
12
14
  | { kind: 'action'; actionKind: FlowActionKind }
13
15
 
14
16
  export interface FlowPaletteActionOption {
@@ -46,6 +48,7 @@ export function FlowPaletteMenu({ onSelect, labels, actionOptions }: FlowPalette
46
48
  const resolvedActionOptions = actionOptions ?? [
47
49
  { actionKind: 'handoff', label: labels.actionKindLabels.handoff ?? 'Encaminhar para atendimento' },
48
50
  ]
51
+ const runnerLabels = labels.runnerFields ?? DEFAULT_FLOW_RUNNER_FIELD_LABELS
49
52
  const [submenu, setSubmenu] = useState<'question' | 'action' | null>(null)
50
53
  const questionTriggerRef = useRef<HTMLButtonElement>(null)
51
54
  const actionTriggerRef = useRef<HTMLButtonElement>(null)
@@ -143,6 +146,26 @@ export function FlowPaletteMenu({ onSelect, labels, actionOptions }: FlowPalette
143
146
  <Diamond size={15} className="text-cyan-500" /> {labels.palette.condition}
144
147
  </button>
145
148
 
149
+ <button
150
+ onMouseEnter={() => setSubmenu(null)}
151
+ onClick={() => select({ kind: 'dynamicChoice' })}
152
+ className="w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700"
153
+ data-cv-tooltip={runnerLabels.paletteDynamicChoiceHint}
154
+ aria-label={runnerLabels.paletteDynamicChoiceHint}
155
+ >
156
+ <ListChecks size={15} className="text-teal-500" aria-hidden="true" /> {runnerLabels.paletteDynamicChoice}
157
+ </button>
158
+
159
+ <button
160
+ onMouseEnter={() => setSubmenu(null)}
161
+ onClick={() => select({ kind: 'message' })}
162
+ className="w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700"
163
+ data-cv-tooltip={runnerLabels.paletteMessageHint}
164
+ aria-label={runnerLabels.paletteMessageHint}
165
+ >
166
+ <MessageSquareText size={15} className="text-orange-500" aria-hidden="true" /> {runnerLabels.paletteMessage}
167
+ </button>
168
+
146
169
  <div className="relative">
147
170
  <button
148
171
  ref={actionTriggerRef}