+ {['overview', 'investigate', 'inventory', 'ads'].includes(page) &&
}
- {page === 'agent' &&
+ {page === 'investigate' &&
}
- {page === 'ops' &&
+ {page === 'runs' &&
{!isApprover ?
: <>
}
- {page === 'weekly' && identity &&
}
+ {page === 'inventory' &&
+
+
+
+
{
+ if (!identity || !demo?.data_range) return
+ void action('replenish', async () => {
+ const result = await api.proposeReplenishment(identity.token, demo.data_range!.end_date, scope.storeId)
+ setSelectedId(result.id)
+ setPage('approvals')
+ setNotice(result.replayed ? '相同账本下的补货提案已存在。' : '补货提案已写入审批中心,尚未执行。')
+ await refresh()
+ })
+ }} />
+ {showWeekly && identity && }
+ }
- {page === 'imports' && identity &&
{ setPage(next); setError('') }} onInvestigate={startAnalysis} />}
+ {page === 'ads' && {
+ if (!identity || !demo) return
+ void action('budget', async () => {
+ const result = await api.proposeBudget(identity.token, demo, scope)
+ setSelectedId(result.id)
+ setPage('approvals')
+ setNotice(result.replayed ? '相同账本下的预算提案已存在。' : '预算提案已进入审批中心。真实广告预算未改变。')
+ await refresh()
+ })
+ }} />}
+ {page === 'settings' && }
+
+ {page === 'knowledge' && identity &&
+ 演示数据
+ 订单和库存 CSV 按当前租户的店铺与 SKU 生成,预览和提交都走后端。广告 CSV 会返回拒绝,避免把活动花费再加进已有每日广告账单。
+
+
+
+
+
+ }
+ {page === 'knowledge' && identity && { void refresh() }}
/>}
- {page === 'approvals' &&
+ {page === 'approvals' &&
+
{
+ if (!identity) return
+ void action('price', async () => {
+ const result = await api.proposePrice(identity.token, storeId, sku, cents)
+ setSelectedId(result.id)
+ setNotice(result.margin_check?.text ?? '调价校验已写入审批中心。')
+ await refresh()
+ })
+ }} />
+
{recommendations.length}} />
{!recommendations.length ?
: recommendations.map(item =>
@@ -734,7 +856,7 @@ export default function App() {
-
+
>}
{selected.approval_reason && 审批意见:{selected.approval_reason}
}
@@ -758,7 +880,7 @@ export default function App() {
{(selected.execution || execution?.recommendation_id === selected.id) && }
: }
- }
+
}
{page === 'knowledge' &&
@@ -795,8 +917,17 @@ export default function App() {
}
- {page === 'audit' &&
- 请求级追踪} />
+ {page === 'runs' && {
+ if (!identity) return
+ void action('eval', async () => {
+ const result = await api.runEval(identity.token)
+ setEvalReport(result)
+ setEvalHistory(await api.evals(identity.token))
+ setNotice(`离线评测已写入审计:通过 ${result.passed} / ${result.total},模型调用 ${result.llm_calls}。`)
+ })
+ }} />}
+ {page === 'runs' &&
+ 请求级追踪} />
+
}
diff --git a/frontend/src/api.ts b/frontend/src/api.ts
index 32cb07d..c5626f2 100644
--- a/frontend/src/api.ts
+++ b/frontend/src/api.ts
@@ -1,4 +1,4 @@
-import type { Analysis, Audit, Demo, Execution, ImportAdapter, ImportSummary, KnowledgeDocument, KnowledgeDocumentInput, KnowledgeSearch, Metrics, OpsSummary, Recommendation, Scope } from './types'
+import type { AccessView, Analysis, Audit, CampaignReport, Demo, EvalList, EvalReport, Execution, ImportAdapter, ImportSummary, InventoryReport, KnowledgeDocument, KnowledgeDocumentInput, KnowledgeSearch, Metrics, OpsSummary, Recommendation, Scope, WorkspaceOverview } from './types'
export class ApiError extends Error {
constructor(message: string, public code: string, public requestId: string, public status: number, public payload?: unknown) { super(message) }
@@ -64,4 +64,24 @@ export const api = {
previewImport: (token: string, kind: 'orders' | 'operations' | 'ads' | 'inventory', text: string, filename: string, mapping = '', adapter = '') => csvRequest(kind === 'operations' ? `/api/imports/${kind}/preview` : `/api/data/${kind}/preview`, token, text, filename, mapping, adapter),
commitImport: (token: string, kind: 'orders' | 'operations' | 'ads' | 'inventory', text: string, filename: string, mapping = '', adapter = '') => csvRequest(kind === 'operations' ? `/api/imports/${kind}` : `/api/data/${kind}/commit`, token, text, filename, mapping, adapter),
importTemplateUrl: (kind: 'orders' | 'operations' | 'ads' | 'inventory') => `/api/data/template/${kind}`,
+ workspace: (token: string, demo: Demo, scope: Scope) => request
(`/api/workspace/overview?${new URLSearchParams(scopeBody(demo, scope))}`, token),
+ campaigns: (token: string, demo: Demo, scope: Scope) => request(`/api/workspace/campaigns?${new URLSearchParams(scopeBody(demo, scope))}`, token),
+ inventory: (token: string, asOf: string, storeId = '') => request(`/api/inventory?as_of=${asOf}${storeId ? `&store_id=${encodeURIComponent(storeId)}` : ''}`, token),
+ access: (token: string) => request('/api/workspace/access', token),
+ evals: (token: string) => request('/api/evals', token),
+ runEval: (token: string) => request('/api/evals/offline', token, { method: 'POST' }),
+ proposeReplenishment: (token: string, asOf: string, storeId = '') => request('/api/proposals/replenishment', token, { method: 'POST', body: JSON.stringify({ as_of: asOf, ...(storeId ? { store_id: storeId } : {}) }) }),
+ proposeBudget: (token: string, demo: Demo, scope: Scope) => request('/api/proposals/budget', token, { method: 'POST', body: JSON.stringify(scopeBody(demo, scope)) }),
+ proposePrice: (token: string, storeId: string, sku: string, proposedPriceCents: number) => request('/api/proposals/price', token, { method: 'POST', body: JSON.stringify({ store_id: storeId, sku, proposed_price_cents: proposedPriceCents }) }),
+ demoCsv: async (token: string, kind: 'orders' | 'inventory' | 'ads') => {
+ const headers = new Headers({ Authorization: `Bearer ${token}` })
+ const response = await fetch(`/api/workspace/demo-csv/${kind}`, { headers })
+ const text = await response.text()
+ if (!response.ok) {
+ let message = '演示 CSV 不可用'
+ try { message = JSON.parse(text)?.error?.message ?? message } catch { /* 文本错误 */ }
+ throw new ApiError(message, 'demo_csv_unavailable', response.headers.get('X-Request-ID') ?? '', response.status)
+ }
+ return text
+ },
}
diff --git a/frontend/src/components/layout/app-sidebar.tsx b/frontend/src/components/layout/app-sidebar.tsx
index 161fde6..d87f3dd 100644
--- a/frontend/src/components/layout/app-sidebar.tsx
+++ b/frontend/src/components/layout/app-sidebar.tsx
@@ -38,8 +38,8 @@ export function AppSidebar({ page, pending, collapsed, mobileOpen, demo, identit