From fad8b10247581a579fb58935954c8f89cf9ea15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Sun, 13 Sep 2026 22:25:19 +0800 Subject: [PATCH] feat(web): annotation result copy matches policy-driven ingestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Saved strategies now report intents/fetch/planned/blocked counts and point at 解析监控 → 待入库; the blocked note explains the 需下架 lane instead of the deprecated snapshot-diff confirmation step. --- web/src/SourceCatalogBrowser.test.tsx | 2 +- web/src/SourceCatalogBrowser.tsx | 4 ++-- web/src/sourceCatalog.test.ts | 11 ++++++----- web/src/sourceCatalog.ts | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/web/src/SourceCatalogBrowser.test.tsx b/web/src/SourceCatalogBrowser.test.tsx index e25c878..3485c36 100644 --- a/web/src/SourceCatalogBrowser.test.tsx +++ b/web/src/SourceCatalogBrowser.test.tsx @@ -91,7 +91,7 @@ describe('SourceCatalogBrowserView',()=>{ it('shows policy as a read-only table state and offers top-level policy buttons',()=>{ const nested={...page,current:{...page.current,node_id:'folder-1',parent_node_id:'root-1',name:'01|产品总览与定位'},breadcrumbs:[...page.breadcrumbs,{node_id:'folder-1',name:'01|产品总览与定位'}],items:[node('可入队.pdf','file','file-ready'),node('已知目录','folder','folder-known'),{...node('大小未知目录','folder','folder-unknown'),subtree_bytes:0},{...node('只有元数据.pdf','file','file-meta'),size_bytes:undefined,routable_count:0}],total:4} const html=renderToStaticMarkup() - for(const text of ['名称','处理策略','全选当前页','对内','对外','禁止导入','禁止导入只保存期望策略;经“快照差异”确认后才会从测试知识库移除','aria-label="选择可入队.pdf"','大小未提供','已知合计 1.0 KB'])expect(html).toContain(text) + for(const text of ['名称','处理策略','全选当前页','对内','对外','禁止导入','禁止导入即生效:待入库条目自动撤销','aria-label="选择可入队.pdf"','大小未提供','已知合计 1.0 KB'])expect(html).toContain(text) for(const text of ['class="catalog-policy-actions"','class="internal-policy-button"','class="external-policy-button"','class="blocked-policy-button"','class="selected-count"'])expect(html).toContain(text) for(const text of ['操作人','判断原因','名称与处理策略','当前策略','选择策略','批量处理策略','应用策略','对内 + 对外','0&&selectableNodes.every(node=>selectedIDs.includes(node.node_id))} disabled={!selectableNodes.length} onChange={event=>setSelectedIDs(event.target.checked?selectableNodes.map(node=>node.node_id):[])} />全选当前页
已选 {selectedCount} 项
- 禁止导入只保存期望策略;经“快照差异”确认后才会从测试知识库移除,不删除来源文件,也不操作生产知识库。 + 禁止导入即生效:待入库条目自动撤销;仍在知识库里的文件会出现在“解析监控 → 需下架”,在知识清单停用检索,不删除来源文件,也不操作生产知识库。 {routingMessage?

{routingMessage}

:null} :null} {visibleItems.length?
{visibleItems.map(node=>{const visibility=appliedPolicies[node.node_id]||node.visibility;const size=node.node_type==='folder'?(node.subtree_bytes>0?`已知合计 ${bytes(node.subtree_bytes)}`:'大小未提供'):typeof node.size_bytes==='number'?bytes(node.size_bytes):'大小未提供';return })}
名称类型处理策略文件数量导入与解析大小更新时间
{node.node_type==='folder'?
toggleNode(node.node_id)} />
:}
{node.node_type==='folder'?'文件夹':'文件'}
{scope(visibility)}
{node.node_type==='folder'?`${node.subtree_file_count} 份`:'—'}{progress(node)}{node.active_count?处理中 {node.active_count}:null}{node.failed_count?失败 {node.failed_count}:null}{size}{node.modified_at?new Date(node.modified_at).toLocaleString('zh-CN',{hour12:false}):'—'}
:
当前目录为空。
} @@ -105,7 +105,7 @@ export function SourceCatalogBrowser(){ useEffect(()=>{if(!selected||!page){setContextTabs([]);return}setContextTabs(page.breadcrumbs.map(item=>({key:item.node_id,label:item.name,onActivate:()=>{setParentID(item.node_id);setOffset(0)}})));return()=>setContextTabs([])},[selected,page,setContextTabs]) const selectSource=(source:CatalogSource)=>{setSelected(source);setParentID(source.root_node_id);setOffset(0);setPage(null);setRefreshJob(null);closeHistory()} const back=()=>{if(!page||page.breadcrumbs.length<2)return;setParentID(page.breadcrumbs[page.breadcrumbs.length-2].node_id);setOffset(0)} - const route=async(nodeIDs:string[],policy:CatalogPolicy):Promise=>{if(!selected||routingLoading)return false;setRoutingLoading(true);setRoutingMessage('');try{const result=await routeCatalogFiles({connection_id:selected.connection_id,node_ids:nodeIDs,policy,reason:`目录页策略:${scope(policy)}`});setRoutingMessage(`策略已保存 ${result.selected_files} 份;可处理 ${result.routable_files} 份;内容未校验 ${result.hash_unknown_files} 份;未关联来源文件 ${result.unbound_files} 份;其余 ${result.unavailable_files} 份暂不可处理。变化需到“快照差异”确认后才会进入解析队列。`);setRevision(value=>value+1);return true}catch(cause){setRoutingMessage(cause instanceof Error?cause.message:'文件处理失败');return false}finally{setRoutingLoading(false)}} + const route=async(nodeIDs:string[],policy:CatalogPolicy):Promise=>{if(!selected||routingLoading)return false;setRoutingLoading(true);setRoutingMessage('');try{const result=await routeCatalogFiles({connection_id:selected.connection_id,node_ids:nodeIDs,policy,reason:`目录页策略:${scope(policy)}`});setRoutingMessage(`策略已保存 ${result.selected_files} 份;已记入意图 ${result.intents_recorded} 份;排队从源头取件 ${result.fetch_queued} 份;列入待入库 ${result.planned_publications} 份;标记禁止 ${result.blocked_items} 份;目录外无文件可标注 ${result.unbound_files} 份。到“解析监控 → 待入库”点开始处理即可。`);setRevision(value=>value+1);return true}catch(cause){setRoutingMessage(cause instanceof Error?cause.message:'文件处理失败');return false}finally{setRoutingLoading(false)}} const refresh=async()=>{if(!selected||refreshJob&&['pending','running','retry'].includes(refreshJob.state))return;setError(null);try{setRefreshJob(await triggerCatalogRefresh(selected.connection_id))}catch(cause){setError(cause instanceof Error?cause.message:'启动实时刷新失败')}} return {setRoutingMessage('');selectSource(source)}} onOpenFolder={node=>{setRoutingMessage('');setParentID(node.node_id);setOffset(0)}} onNavigateTo={nodeID=>{setRoutingMessage('');setParentID(nodeID);setOffset(0)}} onBack={back} onPageChange={setOffset} onRefresh={()=>void refresh()} onRoute={(nodeIDs,visibility)=>route(nodeIDs,visibility)} history={{open:historyOpen,snapshots:historySnapshots,active:historyActive,page:historyPage,loading:historyLoading,error:historyError,onOpen:()=>void openHistory(),onClose:closeHistory,onOpenSnapshot:snapshot=>void openHistorySnapshot(snapshot),onOpenFolder:(snapshot,nodeID)=>void openHistoryFolder(snapshot,nodeID)}} refreshHidden={refreshHidden} onToggleRefreshHidden={()=>setRefreshHidden(value=>!value)} /> } diff --git a/web/src/sourceCatalog.test.ts b/web/src/sourceCatalog.test.ts index 200d3d2..36a0994 100644 --- a/web/src/sourceCatalog.test.ts +++ b/web/src/sourceCatalog.test.ts @@ -36,11 +36,11 @@ describe('source catalog API',()=>{ it('routes selected files without exposing target knowledge-base IDs to the browser',async()=>{ const fetchMock=vi.fn() .mockResolvedValueOnce(new Response(JSON.stringify({data:{internal_enabled:true,external_enabled:true}}))) - .mockResolvedValueOnce(new Response(JSON.stringify({data:{selected_files:2,routable_files:2,unbound_files:0,hash_unknown_files:0,unavailable_files:0}}))) + .mockResolvedValueOnce(new Response(JSON.stringify({data:{selected_files:2,intents_recorded:2,fetch_queued:1,planned_publications:4,blocked_items:0,unbound_files:0}}))) vi.stubGlobal('fetch',fetchMock) expect((await fetchCatalogRoutingCapabilities()).internal_enabled).toBe(true) const result=await routeCatalogFiles({connection_id:'conn-1',node_ids:['a','b'],policy:'both',reason:'批量标注'}) - expect(result.routable_files).toBe(2) + expect(result.planned_publications).toBe(4) expect(result.unbound_files).toBe(0) const payload=JSON.parse(fetchMock.mock.calls[1][1].body) expect(payload.policy).toBe('both') @@ -49,11 +49,12 @@ describe('source catalog API',()=>{ expect(fetchMock.mock.calls[1][1].headers).toMatchObject({Accept:'application/json','Content-Type':'application/json','Idempotency-Key':expect.any(String)}) expect(fetchMock.mock.calls[1][1].headers['Idempotency-Key']).not.toBe('') }) - it('returns the number of test-knowledge removals requested by a blocked policy',async()=>{ - const fetchMock=vi.fn().mockResolvedValue(new Response(JSON.stringify({data:{selected_files:2,routable_files:0,unbound_files:2,hash_unknown_files:0,unavailable_files:0}}))) + it('reports blocked items without planning anything',async()=>{ + const fetchMock=vi.fn().mockResolvedValue(new Response(JSON.stringify({data:{selected_files:2,intents_recorded:2,fetch_queued:0,planned_publications:0,blocked_items:2,unbound_files:0}}))) vi.stubGlobal('fetch',fetchMock) const result=await routeCatalogFiles({connection_id:'conn-1',node_ids:['a','b'],policy:'blocked',reason:'禁止导入'}) - expect(result.unbound_files).toBe(2) + expect(result.blocked_items).toBe(2) + expect(result.planned_publications).toBe(0) }) it('starts a durable background refresh job with no source credential payload',async()=>{ const job={id:'job-refresh',type:'source.catalog.refresh',payload:{connection_id:'conn-1',stage:'queued',progress:0,message:'等待后台刷新'},state:'pending',priority:20,available_at:'2026-09-09T00:00:00Z',attempt:0,max_attempts:3,idempotency_key:'safe',created_at:'2026-09-09T00:00:00Z',updated_at:'2026-09-09T00:00:00Z'} diff --git a/web/src/sourceCatalog.ts b/web/src/sourceCatalog.ts index 35cbd9e..25e48d1 100644 --- a/web/src/sourceCatalog.ts +++ b/web/src/sourceCatalog.ts @@ -78,7 +78,7 @@ export async function fetchAllCatalogFolders(connectionID:string,parentID:string export interface CatalogRoutingCapabilities{internal_enabled:boolean;external_enabled:boolean} export interface CatalogRouteInput{connection_id:string;node_ids:string[];policy:CatalogPolicy;reason:string} -export interface CatalogRouteResult{selected_files:number;routable_files:number;unbound_files:number;hash_unknown_files:number;unavailable_files:number} +export interface CatalogRouteResult{selected_files:number;intents_recorded:number;fetch_queued:number;planned_publications:number;blocked_items:number;unbound_files:number} export async function fetchCatalogRoutingCapabilities(signal?:AbortSignal):Promise{ const response=await fetch('/api/v1/source-catalog/routing-capabilities',{headers:{Accept:'application/json'},signal});if(!response.ok)throw new Error(`加载分流配置失败(HTTP ${response.status})`) @@ -87,7 +87,7 @@ export async function fetchCatalogRoutingCapabilities(signal?:AbortSignal):Promi } export async function routeCatalogFiles(input:CatalogRouteInput):Promise{ const response=await fetch('/api/v1/source-catalog/route',{method:'POST',headers:{Accept:'application/json','Content-Type':'application/json','Idempotency-Key':newOperationID()},body:JSON.stringify(input)});if(!response.ok)throw new Error(response.status===503?'对内/对外知识库尚未配置':`处理策略保存失败(HTTP ${response.status})`) - const value=await response.json() as unknown;if(!record(value)||!record(value.data)||!count(value.data.selected_files)||!count(value.data.routable_files)||!count(value.data.unbound_files)||!count(value.data.hash_unknown_files)||!count(value.data.unavailable_files))throw new Error('文件处理响应无效') + const value=await response.json() as unknown;if(!record(value)||!record(value.data)||!count(value.data.selected_files)||!count(value.data.intents_recorded)||!count(value.data.fetch_queued)||!count(value.data.planned_publications)||!count(value.data.blocked_items)||!count(value.data.unbound_files))throw new Error('文件处理响应无效') return value.data as unknown as CatalogRouteResult } export async function triggerCatalogRefresh(connectionID:string):Promise{