Line data Source code
1 : import { truncate } from 'es-toolkit/compat'
2 :
3 : /** Cap on the doc-host's raw refusal message appended to the localized detail
4 : * below — the host's `message` is developer text of unbounded length, not
5 : * meant to replace the reassurance the localized copy gives the person. */
6 1 : const SYNC_ERROR_RAW_MESSAGE_MAX_LENGTH = 200
7 :
8 : /** Returns localized sync guidance with safe raw context when applicable. */
9 0 : export function formatWorkflowSyncErrorDetail(
10 : translate: (key: string) => string,
11 : message: string | undefined,
12 : code?: string
13 : ): string {
14 0 : const detail = translate(detailKey(code))
15 0 : if (!message || code === 'catalog_mismatch') return detail
16 0 : return `${detail} (${truncate(message, { length: SYNC_ERROR_RAW_MESSAGE_MAX_LENGTH })})`
17 : }
18 :
19 0 : function detailKey(code: string | undefined): string {
20 0 : switch (code) {
21 : case 'catalog_mismatch':
22 0 : return 'agent.workflowSyncFailedDetailCatalogMismatch'
23 : case 'stale_client_schema':
24 0 : return 'agent.workflowSyncFailedDetailStaleClient'
25 : case 'stale_host_schema':
26 0 : return 'agent.workflowSyncFailedDetailStaleHost'
27 : default:
28 0 : return 'agent.workflowSyncFailedDetail'
29 : }
30 : }
|