主要变更: 1. 移除废弃的发货通知字段抽取独立Workflow Agent相关代码 2. 重构Dify服务调用,新增inputs参数支持注入环境变量配置的工具API地址与密钥 3. 新增auto_progress工具API与checkpoint catalog接口,支持流程自动推进 4. 统一字段命名,将column_mapping_json改为map_json并兼容旧有调用 5. 重构库存匹配、解析结果的展示格式,改为标准化多语言Markdown表格 6. 新增ODM ID库存字段支持,优化库存解析与映射逻辑 7. 新增LibreOffice转换隔离Profile配置,避免多实例运行冲突 8. 新增完整环境变量配置、数据库迁移脚本与测试用例 9. 适配前端代码,更新字段命名与聊天跳转逻辑 10. 更新OpenAPI规范适配Dify工具调用,删除已归档的旧部署文档
263 lines
8.6 KiB
TypeScript
263 lines
8.6 KiB
TypeScript
import { getAuthHeaders } from '../utils/auth';
|
|
|
|
export interface ShippingTaskSummary {
|
|
id: number;
|
|
task_no: string;
|
|
source_type: string;
|
|
customer_name?: string | null;
|
|
process_status: string;
|
|
review_status?: string | null;
|
|
match_status?: string | null;
|
|
pending_human_reason?: string | null;
|
|
conversation_id?: string | null;
|
|
export_file_name?: string | null;
|
|
freight_ref_no?: string | null;
|
|
created_at?: string | null;
|
|
updated_at?: string | null;
|
|
}
|
|
|
|
export interface ShippingTaskEvent {
|
|
event_type: string;
|
|
detail_json?: Record<string, unknown> | null;
|
|
created_at?: string | null;
|
|
}
|
|
|
|
export interface ShippingTaskDetail extends ShippingTaskSummary {
|
|
customer_code?: string | null;
|
|
ship_to?: string | null;
|
|
po_number?: string | null;
|
|
required_date?: string | null;
|
|
lines: Array<Record<string, unknown>>;
|
|
shortage?: Record<string, unknown> | null;
|
|
line_results?: Array<Record<string, unknown>>;
|
|
parse_confidence?: number | null;
|
|
error_message?: string | null;
|
|
events: ShippingTaskEvent[];
|
|
}
|
|
|
|
async function getJson<T>(url: string): Promise<T> {
|
|
const res = await fetch(url, { headers: getAuthHeaders() });
|
|
if (!res.ok) {
|
|
const body = await res.json().catch(() => ({}));
|
|
throw new Error((body as { error?: string }).error || res.statusText);
|
|
}
|
|
return res.json() as Promise<T>;
|
|
}
|
|
|
|
export const listWorkspaceShippingTasks = (params?: { process_status?: string; limit?: number }) => {
|
|
const sp = new URLSearchParams();
|
|
if (params?.process_status) sp.set('process_status', params.process_status);
|
|
if (params?.limit) sp.set('limit', String(params.limit));
|
|
const qs = sp.toString();
|
|
return getJson<ShippingTaskSummary[]>(`/api/workspace/shipping-tasks${qs ? '?' + qs : ''}`);
|
|
};
|
|
|
|
export const getWorkspaceShippingTask = (taskNo: string) =>
|
|
getJson<ShippingTaskDetail>(`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}`);
|
|
|
|
export const workspaceShippingExportUrl = (taskNo: string) =>
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/export`;
|
|
|
|
export interface ShippingChatAction {
|
|
id: string;
|
|
label: string;
|
|
message: string;
|
|
variant: 'primary' | 'secondary' | 'danger';
|
|
}
|
|
|
|
export interface ShippingChatActionsResponse {
|
|
task_no: string;
|
|
checkpoint?: string | null;
|
|
process_status: string;
|
|
review_status?: string | null;
|
|
pending_human_reason?: string | null;
|
|
action_buttons: ShippingChatAction[];
|
|
}
|
|
|
|
export const getShippingChatActions = (taskNo: string) =>
|
|
getJson<ShippingChatActionsResponse>(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/chat-actions`,
|
|
);
|
|
|
|
export async function uploadWorkspaceShippingInventory(taskNo: string, file: File) {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const headers = getAuthHeaders();
|
|
delete (headers as Record<string, string>)['Content-Type'];
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/upload-inventory`,
|
|
{ method: 'POST', headers, body: form },
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingInventoryUploadResponse & { error?: string };
|
|
if (!res.ok) {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export async function applyWorkspaceShippingInventoryMapping(taskNo: string, columnMappingJson: Record<string, unknown>) {
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/apply-inventory-mapping`,
|
|
{
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ map_json: columnMappingJson }),
|
|
},
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingInventoryUploadResponse & { error?: string };
|
|
if (!res.ok) {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export interface ShippingInventoryUploadResponse {
|
|
status: string;
|
|
message?: string;
|
|
task_id?: string;
|
|
checkpoint?: string;
|
|
data?: Record<string, unknown>;
|
|
}
|
|
|
|
export interface ShippingTaskCreateResponse {
|
|
status: string;
|
|
message?: string;
|
|
task_id?: string;
|
|
checkpoint?: string;
|
|
data?: Record<string, unknown>;
|
|
}
|
|
|
|
export async function createWorkspaceShippingTask(params?: {
|
|
source_type?: string;
|
|
conversation_id?: string;
|
|
raw_content?: string;
|
|
}) {
|
|
const res = await fetch('/api/workspace/shipping-tasks', {
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(params || {}),
|
|
});
|
|
const body = (await res.json().catch(() => ({}))) as ShippingTaskCreateResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export interface ShippingNoticeUploadResponse {
|
|
status: string;
|
|
message?: string;
|
|
task_id?: string;
|
|
checkpoint?: string;
|
|
data?: Record<string, unknown>;
|
|
human_options?: string[];
|
|
}
|
|
|
|
export async function createWorkspaceShippingTaskFromNotice(file: File) {
|
|
const form = new FormData();
|
|
form.append('file', file);
|
|
const headers = getAuthHeaders();
|
|
delete (headers as Record<string, string>)['Content-Type'];
|
|
const res = await fetch('/api/workspace/shipping-tasks/create-from-notice', {
|
|
method: 'POST',
|
|
headers,
|
|
body: form,
|
|
});
|
|
const body = (await res.json().catch(() => ({}))) as ShippingNoticeUploadResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export interface ShippingDecisionResponse {
|
|
status: string;
|
|
message?: string;
|
|
task_id?: string;
|
|
checkpoint?: string;
|
|
data?: Record<string, unknown>;
|
|
}
|
|
|
|
export async function submitWorkspaceShippingDecision(taskNo: string, decision: string, comment?: string) {
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/submit-decision`,
|
|
{
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ decision, ...(comment ? { comment } : {}) }),
|
|
},
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export async function matchWorkspaceShippingInventory(taskNo: string) {
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/match-inventory`,
|
|
{
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
/** Hxops 聊天兜底:等同 Dify auto_progress Tool */
|
|
export async function autoProgressWorkspaceShippingTask(taskNo: string, lang?: string) {
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/auto-progress`,
|
|
{
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(lang ? { lang } : {}),
|
|
},
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export async function markWorkspaceShippingManualUploaded(taskNo: string) {
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/mark-manual-uploaded`,
|
|
{
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export async function generateWorkspaceShippingExcel(taskNo: string) {
|
|
const res = await fetch(
|
|
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/generate-excel`,
|
|
{
|
|
method: 'POST',
|
|
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
const body = (await res.json().catch(() => ({}))) as ShippingDecisionResponse & { error?: string };
|
|
if (!res.ok || body.status === 'failed') {
|
|
throw new Error(body.error || body.message || res.statusText);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
export const SHIPPING_NOTICE_AGENT_NAME = '货代发货通知 Agent';
|