feat(shipping-notice): 增强发货通知与订单抽取功能,支持多进程处理与紧急停止

- 移除不再使用的 SHIPPING_NOTICE_LAYOUT_PARSER_REVISION 配置
- 在环境配置中新增 SHIPPING_NOTICE_WORKER_CONCURRENCY 和 SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS
- 实现发货通知 worker 进程,支持并发处理订单抽取任务
- 引入紧急停止功能,允许管理员在运行中控制订单解析状态
- 更新相关 API,支持读取与设置紧急停止状态
- 增强文档与代码注释,反映新的业务逻辑与功能要求
This commit is contained in:
hugo committed 2026-07-31 18:00:49 +08:00
1 parent d0fe084999
commit b352c281d5
149 files changed
+12550 -1874

No files matched your search

@@ -0,0 +1,85 @@
<!--
features/chat/components/shipping-review/ReviewLlmEvidenceComparison.vue
用途:三列对比当前草稿、AI 建议与原文证据。
依赖:vue-i18n、ShippingOrderReviewEvidence / LlmSuggestion 类型。
逻辑:嵌入 ReviewLlmSuggestionDialog;逐字失败码与后端 value_not_in_evidence 对齐;只读展示。
-->
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingOrderReviewEvidence, ShippingOrderReviewLlmSuggestion } from '../../types/shipping.api.types';
/** 三列对比入参;建议/证据可空,标签缺省为空串。 */
const props = withDefaults(
defineProps<{
draftValue?: unknown;
suggestion?: ShippingOrderReviewLlmSuggestion | null;
evidence?: ShippingOrderReviewEvidence | null;
fieldLabel?: string;
}>(),
{
fieldLabel: '',
},
);
const { t } = useI18n();
const suggestedValue = computed(() => props.suggestion?.suggested_value ?? '-');
const draftDisplay = computed(() => {
const value = props.draftValue;
if (value === null || value === undefined || value === '') return '-';
return String(value);
});
const evidenceQuote = computed(() => props.evidence?.quote || '-');
const evidenceLocation = computed(() => {
const page = props.evidence?.page_no;
const cell = props.evidence?.cell_id;
if (page && cell) return t('chat.shippingOrderReview.llmSuggestion.evidenceAtCell', { page, cell });
if (page) return t('chat.shippingOrderReview.evidenceAt', { page });
return t('chat.shippingOrderReview.llmSuggestion.noEvidenceCoords');
});
/** 与后端 rejection_reason 对齐;含历史别名 suggested_value_not_in_evidence。 */
const VERBATIM_FAIL_CODES = new Set([
'value_not_in_evidence',
'suggested_value_not_in_evidence',
'empty_suggestion',
'field_id_mismatch',
]);
const verbatimOk = computed(() => {
if (String(props.suggestion?.status || '') === 'validation_failed') return false;
const issues = props.suggestion?.validation_issues || [];
return !issues.some((item) => VERBATIM_FAIL_CODES.has(String(item.code || '')));
});
</script>
<template>
<div class="grid gap-3 md:grid-cols-3" data-testid="review-llm-evidence-comparison">
<div class="rounded-lg border border-slate-200 bg-slate-50 p-3">
<p class="text-xs font-medium uppercase tracking-wide text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.currentDraft') }}
</p>
<p class="mt-2 text-sm font-semibold text-slate-900">{{ props.fieldLabel }}</p>
<p class="mt-1 text-sm text-slate-700">{{ draftDisplay }}</p>
</div>
<div class="rounded-lg border border-indigo-200 bg-indigo-50/60 p-3">
<p class="text-xs font-medium uppercase tracking-wide text-indigo-600">
{{ t('chat.shippingOrderReview.llmSuggestion.aiSuggestion') }}
</p>
<p class="mt-2 text-sm font-semibold text-slate-900">{{ suggestedValue }}</p>
<p class="mt-1 text-xs" :class="verbatimOk ? 'text-emerald-700' : 'text-amber-700'">
{{
verbatimOk
? t('chat.shippingOrderReview.llmSuggestion.verbatimOk')
: t('chat.shippingOrderReview.llmSuggestion.verbatimFailed')
}}
</p>
</div>
<div class="rounded-lg border border-slate-200 bg-white p-3">
<p class="text-xs font-medium uppercase tracking-wide text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.sourceEvidence') }}
</p>
<p class="mt-2 text-sm text-slate-800">{{ evidenceQuote }}</p>
<p class="mt-1 text-xs text-slate-500">{{ evidenceLocation }}</p>
</div>
</div>
</template>
@@ -0,0 +1,233 @@
<!--
features/chat/components/shipping-review/ReviewLlmSuggestionDialog.vue
用途:复核工作台内 AI 建议对比与裁决对话框。
依赖:vue-i18n、ReviewLlmEvidenceComparison、ShippingOrderReview* 类型。
逻辑:接受可备注;修改/拒绝必须填写原因;validation_failed 仅允许拒绝;
含 dialog 语义、Escape、焦点陷阱与恢复。
-->
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type {
ShippingOrderReviewEvidence,
ShippingOrderReviewLlmSuggestion,
} from '../../types/shipping.api.types';
import ReviewLlmEvidenceComparison from './ReviewLlmEvidenceComparison.vue';
const props = defineProps<{
open: boolean;
suggestion?: ShippingOrderReviewLlmSuggestion | null;
evidence?: ShippingOrderReviewEvidence | null;
draftValue?: unknown;
/** Schema 字段展示名;缺省回退 field_id。 */
fieldLabel?: string;
}>();
const emit = defineEmits<{
close: [];
decide: [payload: { decision: 'accept' | 'modify' | 'reject'; reason: string; value?: unknown }];
}>();
const { t, te } = useI18n();
const decision = ref<'accept' | 'modify' | 'reject'>('accept');
const reason = ref('');
const modifiedValue = ref('');
const panelRef = ref<HTMLElement | null>(null);
const previousFocus = ref<HTMLElement | null>(null);
/** 逐字验证失败时仅允许拒绝,禁止 accept/modify。 */
const rejectOnly = computed(() => String(props.suggestion?.status || '') === 'validation_failed');
const displayFieldLabel = computed(() =>
String(props.fieldLabel || props.suggestion?.field_id || '').trim(),
);
const evidenceLevelText = computed(() => {
const code = String(props.suggestion?.evidence_level || 'L1_field').trim() || 'L1_field';
const key = `chat.shippingOrderReview.llmSuggestion.evidenceLevel.${code}`;
return te(key) ? t(key) : t('chat.shippingOrderReview.llmSuggestion.scope', { level: code });
});
const canSubmit = computed(() => {
if (decision.value === 'accept') return !rejectOnly.value;
return Boolean(reason.value.trim());
});
/**
* 提交裁决;修改/拒绝无原因时按钮禁用。
*/
function submit() {
if (!canSubmit.value) return;
emit('decide', {
decision: decision.value,
reason: reason.value.trim(),
value: decision.value === 'modify' ? modifiedValue.value : undefined,
});
}
/**
* 关闭弹窗并通知父级。
*/
function close() {
emit('close');
}
/**
* 收集面板内可聚焦控件,供焦点陷阱使用。
*/
function focusableElements(): HTMLElement[] {
const root = panelRef.value;
if (!root) return [];
return Array.from(
root.querySelectorAll<HTMLElement>(
'button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [href], [tabindex]:not([tabindex="-1"])',
),
).filter((el) => !el.hasAttribute('disabled') && el.tabIndex !== -1);
}
/**
* 打开时聚焦首个可交互控件;关闭时恢复触发焦点。
*/
async function restoreOrCaptureFocus(open: boolean) {
if (typeof document === 'undefined') return;
if (open) {
previousFocus.value = document.activeElement instanceof HTMLElement ? document.activeElement : null;
await nextTick();
const first = focusableElements()[0];
first?.focus();
return;
}
previousFocus.value?.focus?.();
previousFocus.value = null;
}
/**
* Escape 关闭;Tab 在对话框内循环,防止焦点落到遮罩后的复核页。
*/
function onKeydown(event: KeyboardEvent) {
if (!props.open) return;
if (event.key === 'Escape') {
event.preventDefault();
close();
return;
}
if (event.key !== 'Tab') return;
const nodes = focusableElements();
const first = nodes[0];
const last = nodes[nodes.length - 1];
// [STEP] noUncheckedIndexedAccess:空数组或越界时 first/last 为 undefined,禁止直接 .focus()。
if (!first || !last) {
event.preventDefault();
return;
}
const active = document.activeElement as HTMLElement | null;
if (event.shiftKey && active === first) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && active === last) {
event.preventDefault();
first.focus();
}
}
watch(
() => props.open,
(open) => {
if (open) {
decision.value = rejectOnly.value ? 'reject' : 'accept';
reason.value = '';
modifiedValue.value = String(props.suggestion?.suggested_value ?? '');
}
void restoreOrCaptureFocus(open);
if (typeof document === 'undefined') return;
if (open) document.addEventListener('keydown', onKeydown);
else document.removeEventListener('keydown', onKeydown);
},
);
onBeforeUnmount(() => {
if (typeof document !== 'undefined') document.removeEventListener('keydown', onKeydown);
});
</script>
<template>
<Teleport to="body">
<div
v-if="open"
class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
role="dialog"
aria-modal="true"
:aria-label="t('chat.shippingOrderReview.llmSuggestion.dialogTitle')"
data-testid="review-llm-suggestion-dialog"
@click.self="close"
>
<div
ref="panelRef"
class="max-h-[80vh] w-full max-w-3xl overflow-auto rounded-lg bg-white p-4 shadow-lg dark:bg-slate-900"
data-testid="review-llm-suggestion-panel"
>
<h3 class="text-base font-semibold">{{ t('chat.shippingOrderReview.llmSuggestion.dialogTitle') }}</h3>
<p class="mt-1 text-xs text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.dialogHint') }}
· {{ evidenceLevelText }}
</p>
<div class="mt-4">
<ReviewLlmEvidenceComparison
:draft-value="draftValue"
:suggestion="suggestion"
:evidence="evidence"
:field-label="displayFieldLabel"
/>
</div>
<div class="mt-4 flex flex-wrap gap-4 text-sm">
<label v-if="!rejectOnly" class="inline-flex items-center gap-1">
<input v-model="decision" type="radio" value="accept" />
{{ t('chat.shippingOrderReview.llmSuggestion.decisions.accept') }}
</label>
<label v-if="!rejectOnly" class="inline-flex items-center gap-1">
<input v-model="decision" type="radio" value="modify" />
{{ t('chat.shippingOrderReview.llmSuggestion.decisions.modify') }}
</label>
<label class="inline-flex items-center gap-1">
<input v-model="decision" type="radio" value="reject" />
{{ t('chat.shippingOrderReview.llmSuggestion.decisions.reject') }}
</label>
</div>
<input
v-if="decision === 'modify'"
v-model="modifiedValue"
class="mt-2 w-full rounded border p-2 text-sm dark:border-slate-700 dark:bg-slate-950"
:placeholder="t('chat.shippingOrderReview.llmSuggestion.modifiedValue')"
/>
<textarea
v-model="reason"
class="mt-2 w-full rounded border p-2 text-sm dark:border-slate-700 dark:bg-slate-950"
rows="2"
:placeholder="
decision === 'accept'
? t('chat.shippingOrderReview.llmSuggestion.noteOptional')
: t('chat.shippingOrderReview.llmSuggestion.reasonRequired')
"
/>
<div class="mt-3 flex justify-end gap-2">
<button type="button" class="rounded border px-3 py-1 text-sm" @click="close">
{{ t('chat.shippingOrderReview.llmSuggestion.cancel') }}
</button>
<button
type="button"
class="rounded border px-3 py-1 text-sm disabled:opacity-50"
:disabled="!canSubmit"
data-testid="review-llm-submit-decision"
@click="submit"
>
{{ t('chat.shippingOrderReview.llmSuggestion.submit') }}
</button>
</div>
</div>
</div>
</Teleport>
</template>
@@ -0,0 +1,162 @@
/**
* features/chat/components/shipping-review/ReviewLlmSuggestionPanel.spec.ts
* 用途:锁定 LLM 建议面板的草稿对比与裁决弹窗契约。
* 依赖:vitest、@vue/test-utils、vue-i18n。
* 逻辑:按建议字段解析 header 草稿值;弹窗含 dialog 语义;修改/拒绝无原因不可提交。
*/
import { describe, expect, it } from 'vitest';
import { flushPromises, mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import ReviewLlmSuggestionPanel from './ReviewLlmSuggestionPanel.vue';
import type {
ShippingOrderReviewCase,
ShippingOrderReviewLlmSuggestion,
} from '@/features/chat/types/shipping.api.types';
const messages = {
en: {
chat: {
shippingOrderReview: {
llmSuggestion: {
panelTitle: 'AI suggestion',
panelHint: 'Minimal evidence only',
request: 'Request',
requesting: 'Requesting',
review: 'Review',
empty: 'No suggestions',
scope: 'Scope {level}',
dialogTitle: 'AI suggestion dialog',
dialogHint: 'Compare draft and evidence',
currentDraft: 'Current draft',
aiSuggestion: 'AI suggestion',
sourceEvidence: 'Evidence',
verbatimOk: 'OK',
verbatimFailed: 'Failed',
evidenceAtCell: 'page {page} {cell}',
noEvidenceCoords: 'no coords',
cancel: 'Cancel',
submit: 'Submit',
modifiedValue: 'Modified',
noteOptional: 'Note',
reasonRequired: 'Reason required',
status: { idle: 'Idle', pending: 'Pending', validated: 'Validated' },
decisions: { accept: 'Accept', modify: 'Modify', reject: 'Reject' },
},
},
},
},
};
/**
* 构造最小 Case + 建议夹具。
*/
function fixtures() {
const suggestion: ShippingOrderReviewLlmSuggestion = {
suggestion_no: 'RSG-TEST001',
field_id: 'fld-po',
scope: 'header',
evidence_level: 'L1_field',
status: 'validated',
suggested_value: 'PO-NEW',
validation_issues: [],
};
const activeCase = {
case_no: 'SRC-1',
draft: {
draft_version: 3,
header_values: {
values: { 'fld-po': { value: 'PO-OLD', source: 'manual' } },
machine_fields: [{ field_id: 'fld-po', value: 'PO-MACHINE' }],
},
lines: [],
},
} as unknown as ShippingOrderReviewCase;
return { suggestion, activeCase };
}
/**
* 挂载建议面板。
*/
function mountPanel(overrides?: {
suggestions?: ShippingOrderReviewLlmSuggestion[];
editable?: boolean;
focusedFieldId?: string;
}) {
const { suggestion, activeCase } = fixtures();
const i18n = createI18n({ legacy: false, locale: 'en', messages });
return mount(ReviewLlmSuggestionPanel, {
props: {
activeCase,
evidence: [{ evidence_id: 'e1', field_id: 'fld-po', quote: 'PO-NEW', page_no: 1, source: 'layout' }],
editable: overrides?.editable ?? true,
saving: false,
suggestions: overrides?.suggestions ?? [suggestion],
suggestionLoading: false,
focusedFieldId: overrides?.focusedFieldId ?? 'fld-po',
focusedLineKey: null,
draftValue: null,
},
global: { plugins: [i18n] },
attachTo: document.body,
});
}
describe('ReviewLlmSuggestionPanel', () => {
it('opens dialog with current draft value for three-way compare', async () => {
const wrapper = mountPanel();
await wrapper.get('ul button').trigger('click');
await flushPromises();
const dialog = document.querySelector('[data-testid="review-llm-suggestion-dialog"]');
expect(dialog).not.toBeNull();
expect(dialog?.getAttribute('role')).toBe('dialog');
expect(dialog?.getAttribute('aria-modal')).toBe('true');
expect(document.body.textContent).toContain('PO-OLD');
expect(document.body.textContent).toContain('PO-NEW');
wrapper.unmount();
});
it('blocks submit for reject without reason and closes on Escape', async () => {
const wrapper = mountPanel();
await wrapper.get('ul button').trigger('click');
await flushPromises();
const radios = Array.from(document.querySelectorAll<HTMLInputElement>('input[type="radio"]'));
const reject = radios.find((el) => el.value === 'reject');
expect(reject).toBeTruthy();
reject!.checked = true;
reject!.dispatchEvent(new Event('change'));
await flushPromises();
const submit = document.querySelector<HTMLButtonElement>('[data-testid="review-llm-submit-decision"]');
expect(submit?.disabled).toBe(true);
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
await flushPromises();
expect(document.querySelector('[data-testid="review-llm-suggestion-dialog"]')).toBeNull();
wrapper.unmount();
});
it('keeps validation_failed suggestions out of accept list and reject-only in dialog', async () => {
const failed: ShippingOrderReviewLlmSuggestion = {
suggestion_no: 'RSG-FAIL',
field_id: 'fld-po',
scope: 'header',
evidence_level: 'L1_field',
status: 'validation_failed',
suggested_value: 'PO-BAD',
validation_issues: [{ code: 'value_not_in_evidence', severity: 'blocking' }],
};
const wrapper = mountPanel({ suggestions: [failed] });
expect(wrapper.find('ul:not([data-testid="review-llm-failed-list"])').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-llm-failed-list"]').exists()).toBe(true);
await wrapper.get('[data-testid="review-llm-open-failed"]').trigger('click');
await flushPromises();
const radios = Array.from(document.querySelectorAll<HTMLInputElement>('input[type="radio"]'));
expect(radios.map((el) => el.value)).toEqual(['reject']);
expect(document.body.textContent).toContain('Failed');
wrapper.unmount();
});
});
@@ -0,0 +1,251 @@
<!--
features/chat/components/shipping-review/ReviewLlmSuggestionPanel.vue
用途:复核工作台内嵌 AI 建议入口、列表与裁决触发(非顶级导航)。
依赖:vue-i18n、ReviewLlmSuggestionDialog、ShippingOrderReview* 类型。
逻辑:请求/裁决由父级 composable 执行;仅 validated 可接受;validation_failed 单独列表仅可拒绝;
证据按 field_id + line_key/line_index 绑定;打开弹窗时按建议字段解析当前草稿值。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type {
ShippingOrderReviewCase,
ShippingOrderReviewEvidence,
ShippingOrderReviewLlmAdjudicationPayload,
ShippingOrderReviewLlmSuggestion,
} from '../../types/shipping.api.types';
import ReviewLlmSuggestionDialog from './ReviewLlmSuggestionDialog.vue';
const props = defineProps<{
activeCase?: ShippingOrderReviewCase | null;
evidence?: ShippingOrderReviewEvidence[] | null;
editable?: boolean;
saving?: boolean;
suggestions?: ShippingOrderReviewLlmSuggestion[];
suggestionLoading?: boolean;
focusedFieldId?: string | null;
focusedLineKey?: string | null;
/** 父级传入的聚焦字段草稿;弹窗优先用建议字段自身解析值。 */
draftValue?: unknown;
}>();
const emit = defineEmits<{
requestSuggestion: [];
adjudicate: [payload: {
suggestion: ShippingOrderReviewLlmSuggestion;
body: ShippingOrderReviewLlmAdjudicationPayload;
}];
}>();
const { t, te } = useI18n();
const dialogOpen = ref(false);
const selected = ref<ShippingOrderReviewLlmSuggestion | null>(null);
/** 仅已通过逐字校验的建议可进入 accept/modify 待裁决列表。 */
const pendingSuggestions = computed(() =>
(props.suggestions || []).filter((item) => String(item.status || '') === 'validated' && !item.decision),
);
/** 验证失败建议仅可查看/拒绝,不进入可接受列表。 */
const failedSuggestions = computed(() =>
(props.suggestions || []).filter((item) => String(item.status || '') === 'validation_failed' && !item.decision),
);
const statusLabel = computed(() => {
if (props.suggestionLoading) return t('chat.shippingOrderReview.llmSuggestion.status.pending');
const latest = (props.suggestions || [])[0];
const code = String(latest?.status || latest?.decision || 'idle');
const key = `chat.shippingOrderReview.llmSuggestion.status.${code}`;
return te(key) ? t(key) : code;
});
const canRequest = computed(() =>
Boolean(props.editable && props.activeCase && props.focusedFieldId && !props.suggestionLoading && !props.saving),
);
/**
* 证据须同时匹配 field_id 与明细行(machine-N → line_index)。
*/
function evidenceMatchesFieldLine(
item: ShippingOrderReviewEvidence,
fieldId: string,
lineKey: string | null | undefined,
): boolean {
if (String(item.field_id || '') !== fieldId) return false;
const key = String(lineKey || '').trim();
if (!key) {
return item.line_index == null || item.line_index === undefined;
}
const matched = /^machine-(\d+)$/i.exec(key);
if (matched) {
const idx = Number(matched[1]) - 1;
return Number(item.line_index) === idx;
}
return false;
}
const selectedEvidence = computed(() => {
const items = props.evidence || [];
const fieldId = String(selected.value?.field_id || props.focusedFieldId || '');
const lineKey = selected.value?.line_key ?? props.focusedLineKey;
return items.find((item) => evidenceMatchesFieldLine(item, fieldId, lineKey)) || null;
});
/**
* 从草稿容器读取字段当前值(人工值优先,否则机器投影)。
*/
function readContainerDraftValue(container: Record<string, unknown> | null | undefined, fieldId: string): unknown {
if (!container || !fieldId) return null;
const values = container.values as Record<string, { value?: unknown }> | undefined;
if (values?.[fieldId] && 'value' in values[fieldId]) return values[fieldId].value ?? null;
const machine = Array.isArray(container.machine_fields)
? (container.machine_fields as Array<Record<string, unknown>>)
: [];
const hit = machine.find((item) => String(item.field_id || '') === fieldId);
return hit?.value ?? null;
}
/**
* 按建议(或聚焦字段)解析当前草稿值,供三方对比。
*/
const dialogDraftValue = computed(() => {
const fieldId = String(selected.value?.field_id || props.focusedFieldId || '');
const lineKey = selected.value?.line_key ?? props.focusedLineKey;
const draft = props.activeCase?.draft;
if (!draft || !fieldId) return props.draftValue ?? null;
if (lineKey) {
const lines = Array.isArray(draft.lines) ? draft.lines : [];
const line = lines.find((item) => String((item as { line_key?: string }).line_key || '') === String(lineKey));
return readContainerDraftValue(line as Record<string, unknown> | undefined, fieldId);
}
return readContainerDraftValue(draft.header_values as Record<string, unknown> | undefined, fieldId);
});
/**
* 打开指定建议的对比裁决对话框。
*/
function openSuggestion(item: ShippingOrderReviewLlmSuggestion) {
selected.value = item;
dialogOpen.value = true;
}
/**
* 将建议字段解析为 Schema 展示名;缺失时回退 field_id。
*/
function suggestionFieldLabel(item: ShippingOrderReviewLlmSuggestion): string {
const fieldId = String(item.field_id || '').trim();
const fields = props.activeCase?.schema?.fields || [];
const hit = fields.find((field) => String(field.field_id || '') === fieldId);
const name = String(hit?.display_name || hit?.field_code || '').trim();
if (name && item.line_key) {
return `${name} · ${item.line_key}`;
}
return name || fieldId || '—';
}
/**
* 将证据等级转为业务文案,避免直接展示 L1_field。
*/
function evidenceLevelLabel(level?: string | null): string {
const code = String(level || 'L1_field').trim() || 'L1_field';
const key = `chat.shippingOrderReview.llmSuggestion.evidenceLevel.${code}`;
return te(key) ? t(key) : t('chat.shippingOrderReview.llmSuggestion.scope', { level: code });
}
/**
* 将对话框裁决转发给父级。
*/
function onDecide(payload: { decision: 'accept' | 'modify' | 'reject'; reason: string; value?: unknown }) {
if (!selected.value) return;
emit('adjudicate', {
suggestion: selected.value,
body: {
decision: payload.decision,
reason: payload.reason || undefined,
value: payload.value,
expected_draft_version: props.activeCase?.draft?.draft_version,
},
});
dialogOpen.value = false;
}
</script>
<template>
<section class="rounded-xl border border-slate-200 bg-white p-3 text-sm shadow-sm dark:border-slate-800 dark:bg-slate-900">
<div class="flex flex-wrap items-center justify-between gap-2">
<div>
<div class="font-semibold">{{ t('chat.shippingOrderReview.llmSuggestion.panelTitle') }}</div>
<div class="mt-1 text-xs text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.panelHint') }}
· {{ evidenceLevelLabel(selected?.evidence_level || 'L1_field') }}
· {{ statusLabel }}
<span v-if="suggestions?.length">· {{ suggestions.length }}</span>
</div>
</div>
<button
type="button"
class="rounded border px-2 py-1 text-xs disabled:opacity-50"
:disabled="!canRequest"
data-testid="review-llm-request"
@click="emit('requestSuggestion')"
>
{{
suggestionLoading
? t('chat.shippingOrderReview.llmSuggestion.requesting')
: t('chat.shippingOrderReview.llmSuggestion.request')
}}
</button>
</div>
<p v-if="!pendingSuggestions.length && !failedSuggestions.length" class="mt-3 text-xs text-slate-500">
{{ t('chat.shippingOrderReview.llmSuggestion.empty') }}
</p>
<ul v-if="pendingSuggestions.length" class="mt-3 space-y-2">
<li
v-for="item in pendingSuggestions"
:key="item.suggestion_no"
class="flex items-center justify-between gap-2 rounded border border-slate-200 px-2 py-1.5 dark:border-slate-700"
>
<div class="min-w-0 truncate text-xs">
<span class="font-medium">{{ suggestionFieldLabel(item) }}</span>
<span class="ml-2 opacity-70">{{ item.suggested_value ?? '—' }}</span>
</div>
<button type="button" class="shrink-0 rounded border px-2 py-0.5 text-xs" @click="openSuggestion(item)">
{{ t('chat.shippingOrderReview.llmSuggestion.review') }}
</button>
</li>
</ul>
<ul v-if="failedSuggestions.length" class="mt-3 space-y-2" data-testid="review-llm-failed-list">
<li
v-for="item in failedSuggestions"
:key="item.suggestion_no"
class="flex items-center justify-between gap-2 rounded border border-amber-200 bg-amber-50/50 px-2 py-1.5 dark:border-amber-900 dark:bg-amber-950/30"
>
<div class="min-w-0 truncate text-xs">
<span class="font-medium">{{ suggestionFieldLabel(item) }}</span>
<span class="ml-2 text-amber-700 dark:text-amber-300">
{{ t('chat.shippingOrderReview.llmSuggestion.verbatimFailed') }}
</span>
</div>
<button
type="button"
class="shrink-0 rounded border px-2 py-0.5 text-xs"
data-testid="review-llm-open-failed"
@click="openSuggestion(item)"
>
{{ t('chat.shippingOrderReview.llmSuggestion.review') }}
</button>
</li>
</ul>
<ReviewLlmSuggestionDialog
:open="dialogOpen"
:suggestion="selected"
:evidence="selectedEvidence"
:draft-value="dialogDraftValue"
:field-label="selected ? suggestionFieldLabel(selected) : ''"
@close="dialogOpen = false"
@decide="onDecide"
/>
</section>
</template>