diff --git a/web/app.js b/web/app.js index 9498b27f0..ecbaed046 100644 --- a/web/app.js +++ b/web/app.js @@ -213,6 +213,9 @@ function afNextDialog(){ if(rerunFields)rerunFields.hidden=true; const okBtn=$('#confirmOkBtn'),cancelBtn=$('#confirmCancelBtn'); cancelBtn.hidden=false; + // afConfirm({messageData}) marks the shared message node for one dialog; clear it first so afPrompt, + // afAlert and other setups that write #confirmMessage directly translate normally. + $('#confirmMessage')?.removeAttribute('data-i18n-data'); let opened; try{opened=job.setup(modal)||{}}catch(err){job.resolve(null);console.error(err);return afNextDialog()} window.HuiPopover?.closeAll?.(); @@ -280,7 +283,10 @@ function afConfirm(options){ return afOpenDialog(()=>{ const danger=!!opt.danger; $('#confirmTitle').textContent=opt.title||(danger?'危险操作确认':'操作确认'); - $('#confirmMessage').textContent=opt.message||'确定要继续吗?'; + // messageData: the message quotes user data (a name), so English mode only takes whole-message dictionary hits. + const message=$('#confirmMessage'); + if(opt.messageData)message.setAttribute('data-i18n-data',''); + message.textContent=opt.message||'确定要继续吗?'; const okBtn=$('#confirmOkBtn'); okBtn.textContent=opt.confirmText||(danger?'确定执行':'确定'); okBtn.className=`button ${danger?'danger-btn':'primary'}`; diff --git a/web/app/assets.js b/web/app/assets.js index c619de30b..c1c3e8707 100644 --- a/web/app/assets.js +++ b/web/app/assets.js @@ -17,10 +17,18 @@ function assetMatchesQuery(a,query){const q=String(query||'').trim().toLowerCase function assetFilteredItems(){return assetScopeItems(state[assetScopeKey(state.assetType)]).filter(a=>assetMatchesQuery(a,state.assetQuery))} // Owned assets win over a same-id shared copy so the editable one opens. function assetFindVisible(id){if(!id)return null;const owned=assetScopeItems('project').find(x=>x.id===id);if(owned)return {asset:owned,scope:'project'};const shared=assetScopeItems('shared').find(x=>x.id===id);return shared?{asset:shared,scope:'shared'}:null} -function assetProjectName(a){return (state.data.projects||[]).find(p=>p.id===a?.projectId)?.name||a?.projectId||'平台'} +// Platform-owned assets (projectId "platform", e.g. generic-docker) have no +// project entry; they read as 平台 rather than the raw id. +function assetOwnerProjectName(a){return (state.data.projects||[]).find(p=>p.id===a?.projectId)?.name||(a?.projectId&&a.projectId!=='platform'?a.projectId:'')} +function assetProjectName(a){return assetOwnerProjectName(a)||'平台'} +// Names people typed stay as typed in English mode (data-i18n-skip): even a +// whole-string dictionary hit would rename a project called 「测试」 to Testing. +// Only the 平台 fallback is product copy and still translates. +function assetProjectNameHTML(a){const name=assetOwnerProjectName(a);return name?`${escapeHTML(name)}`:'平台'} +function assetUserDataAttr(value){return value?' data-i18n-skip':''} function assetIsBuiltin(a,type=state.assetType){return type==='sandboxes'&&a?.id==='generic-docker'} function assetStatusHTML(a){ - if(!catalogOwned(a.projectId))return `来自 ${escapeHTML(assetProjectName(a))}`; + if(!catalogOwned(a.projectId))return `来自 ${assetProjectNameHTML(a)}`; return `${a.shared?'已共享':'未共享'}`; } function assetMetaHTML(a){ @@ -33,19 +41,20 @@ function assetMetaHTML(a){ } if(state.assetType==='sandboxes'){ const driver=sandboxDriverOption(a.driver);meta.push(item('server',sandboxDriverLabel(driver))); - if(driver==='docker'&&a.dockerfile?.content)meta.push(item('layers',`Dockerfile ${a.dockerfile.content.trimEnd().split('\n').length} 行`)); + if(driver==='docker'&&a.dockerfile?.content){const lines=a.dockerfile.content.trimEnd().split('\n').length;meta.push(item('layers',lfT(`Dockerfile ${lines} 行`,`Dockerfile · ${lines} ${lines===1?'line':'lines'}`)))} } const refs=assetReferenceNames(a).length; - meta.push(item(assetRefIconName(),refs?`${refs} 个${assetRefKindLabel()}引用`:'未被引用')); + meta.push(item(assetRefIconName(),refs?lfT(`${refs} 个${assetRefKindLabel()}引用`,`Used by ${refs} ${assetRefKindLabelEn(refs)}`):'未被引用')); return meta.join(''); } function assetCardHTML(a){ const readonly=!catalogOwned(a.projectId);const go=readonly?'查看':'编辑'; - return `
${huiIcon(assetIconName())}

${escapeHTML(a.name||a.id)}

${escapeHTML(a.id)}

${escapeHTML(a.description||'暂无说明')}

${assetMetaHTML(a)}
${assetStatusHTML(a)}${go}${huiIcon('chevron-right')}
`; + const name=a.name||a.id,label=lfT(`${go}${assetKindLabel()}「${name}」`,`${readonly?'View':'Edit'} ${assetKindLabelEn()} "${name}"`); + return `
${huiIcon(assetIconName())}

${escapeHTML(name)}

${escapeHTML(a.id)}

${escapeHTML(a.description||'暂无说明')}

${assetMetaHTML(a)}
${assetStatusHTML(a)}${go}${huiIcon('chevron-right')}
`; } function assetGridEmptyHTML(){ const kind=assetKindLabel(),copy=assetPageCopy(); - if(String(state.assetQuery||'').trim())return `
没有匹配「${escapeHTML(state.assetQuery.trim())}」的${escapeHTML(kind)}

换个关键词试试。

`; + if(String(state.assetQuery||'').trim())return `
${escapeHTML(lfT(`没有匹配「${state.assetQuery.trim()}」的${kind}`,`No ${assetKindLabelEn()} matches "${state.assetQuery.trim()}"`))}

换个关键词试试。

`; if(state[assetScopeKey(state.assetType)]==='shared'){const hint=['rules','skills'].includes(state.assetType)?'请在资产所属项目中共享,或共享一个引用它的角色。':'请在沙箱所属项目中共享。';return `
其他项目还没有共享${escapeHTML(kind)}

${hint}

`} return `
当前项目还没有${/^[A-Za-z]/.test(kind)?' ':''}${escapeHTML(kind)}

${assetEmptyHint()}

`; } @@ -53,7 +62,7 @@ function renderAssetGrid(){ const list=$('#assetList');if(!list)return; const scope=state[assetScopeKey(state.assetType)]; const items=assetFilteredItems(); - const count=$('#assetCount');if(count)count.innerHTML=`${scope==='shared'?'共享':'本项目'}${escapeHTML(assetKindLabel())}${items.length}`; + const count=$('#assetCount');if(count)count.innerHTML=`${escapeHTML(lfT(`${scope==='shared'?'共享':'本项目'}${assetKindLabel()}`,scope==='shared'?`Shared ${assetKindLabelEn(true)}`:`${assetKindLabelEn(true).replace(/^./,c=>c.toUpperCase())} in this project`))}${items.length}`; list.innerHTML=items.map(assetCardHTML).join('')||assetGridEmptyHTML(); const emptyAction=list.querySelector('[data-empty-new]'); if($('#newAsset'))$('#newAsset').hidden=scope!=='project'||!!emptyAction; @@ -100,7 +109,7 @@ function assetCurrent(){ } function assetDetailHeadHTML(a,{creating=false,dirty=false}={}){ const kind=assetKindLabel(),copy=assetPageCopy(),readonly=!creating&&!catalogOwned(a.projectId); - const badge=creating?'':readonly?`来自 ${escapeHTML(assetProjectName(a))}`:`${a.shared?'已共享':'未共享'}`; + const badge=creating?'':readonly?`来自 ${assetProjectNameHTML(a)}`:`${a.shared?'已共享':'未共享'}`; const title=creating?`新建${kind}`:(a.name||a.id); const desc=creating?`填写标识和名称后创建${state.assetType==='skills'?',创建后即可上传文件':''}。`:(a.description||'暂无说明'); let actions; @@ -111,15 +120,15 @@ function assetDetailHeadHTML(a,{creating=false,dirty=false}={}){ actions=`未保存`+ ``+ `
`+ - `
`+ + ``+ ``; } - return `

${escapeHTML(title)}${badge}

${escapeHTML(desc)}

${actions}
`; + return `

${escapeHTML(title)}${badge}

${escapeHTML(desc)}

${actions}
`; } function renderAssetDetailHead(a){ const creating=state.selectedAsset==='__new__',copy=assetPageCopy(); const crumbs=$('#assetCrumbs'); - if(crumbs)crumbs.innerHTML=`${escapeHTML(copy.crumb||`${copy.page} · ${copy.tab}`)}${huiIcon('chevron-right')}${escapeHTML(creating?`新建${assetKindLabel()}`:(a.name||a.id))}`; + if(crumbs)crumbs.innerHTML=`${escapeHTML(copy.crumb||`${copy.page} · ${copy.tab}`)}${huiIcon('chevron-right')}${escapeHTML(creating?`新建${assetKindLabel()}`:(a.name||a.id))}`; const head=$('#assetDetailHead');if(!head)return; closeAssetMenu(); head.innerHTML=assetDetailHeadHTML(a,{creating,dirty:!!state.assetDirty}); @@ -155,7 +164,7 @@ function updateAssetStuck(){ } function assetRefsCardHTML(a){ const refs=assetReferenceNames(a),kind=assetRefKindLabel(); - return `

被引用${refs.length}

`; + return `

被引用${refs.length}

`; } function assetSkillSource(a){const s=a?.source;return state.assetType==='skills'&&s&&s.provider==='skillhub'?s:null} function assetSkillLatest(src){return typeof skillhubLatestFor==='function'?skillhubLatestFor(src):''} @@ -172,7 +181,7 @@ function assetSkillSourceActionHTML(a){ } function assetOverviewCardHTML(a){ const readonly=!catalogOwned(a.projectId); - return `

概览

归属
${readonly?escapeHTML(assetProjectName(a)):'本项目'}
共享
${readonly?'其他项目共享':a.shared?'已共享':'未共享'}
${assetIsBuiltin(a)?'
类型
内置
':''}${assetSkillSourceRowsHTML(a)}
${assetSkillSourceActionHTML(a)}`; + return `

概览

归属
${readonly?assetProjectNameHTML(a):'本项目'}
共享
${readonly?'其他项目共享':a.shared?'已共享':'未共享'}
${assetIsBuiltin(a)?'
类型
内置
':''}${assetSkillSourceRowsHTML(a)}
${assetSkillSourceActionHTML(a)}`; } function bindAssetSourceActions(a){ const card=$('#assetForm [data-asset-overview]');if(!card||!assetSkillSource(a))return; @@ -202,7 +211,7 @@ function scrollAssetTop(){ } async function confirmAssetLeave(){ if(!state.selectedAsset||!state.assetDirty||!isProjectSharedAsset(activeViewName()))return true; - const ok=await afConfirm({title:'未保存的修改',message:`当前${assetKindLabel()}有未保存修改,离开将放弃这些修改。继续?`,confirmText:'放弃并离开',danger:true}); + const ok=await afConfirm({title:lfT('未保存的修改','Unsaved changes'),message:lfT(`当前${assetKindLabel()}有未保存修改,离开将放弃这些修改。继续?`,`This ${assetKindLabelEn()} has unsaved changes. Leaving discards them. Continue?`),confirmText:'放弃并离开',danger:true}); if(ok)state.assetDirty=false; return ok; } @@ -259,7 +268,9 @@ async function toggleAssetShare(id){ } function assetEmptyHint(){return ({rules:'规则是写给 Agent 的行为约束,例如编码规范、禁止事项。建好后在「角色定义」里绑定到角色。',skills:'技能是 Agent 可按需加载的说明和附加文件,例如某个框架的操作手册。建好后在「角色定义」里绑定到角色。',sandboxes:'沙箱决定 LOOP 节点和对话工作区在什么隔离环境里执行:docker 沙箱自带 Dockerfile,native 沙箱使用执行机器上已安装的工具。建好后在流程设置里选用;也可以直接用「共享」里的现成配置。'})[state.assetType]||''} function assetKindLabel(){return ({rules:'规则',skills:'技能',sandboxes:'沙箱'})[state.assetType]||'资产'} +function assetKindLabelEn(plural=false){return (plural?{rules:'rules',skills:'skills',sandboxes:'sandboxes'}:{rules:'rule',skills:'skill',sandboxes:'sandbox'})[state.assetType]||(plural?'assets':'asset')} function assetRefKindLabel(){return ({rules:'角色',skills:'角色',sandboxes:'流程'})[state.assetType]||'引用'} +function assetRefKindLabelEn(n){return n===1?(state.assetType==='sandboxes'?'LOOP':'role'):(state.assetType==='sandboxes'?'LOOPs':'roles')} function assetReferenceNames(a){ if(!a?.id)return []; if(state.assetType==='rules')return (state.data.agents||[]).filter(x=>(x.rules||[]).includes(a.id)).map(x=>x.name||x.id); @@ -270,9 +281,9 @@ function assetReferenceNames(a){ function assetDeleteBlocked(a){ if(!a?.id)return '无法删除'; if(state.assetType==='sandboxes'&&a.id==='generic-docker')return `内置沙箱 ${a.id} 不能删除`; - if(a.shared)return `共享状态的${assetKindLabel()}不能删除,请先取消共享`; + if(a.shared)return lfT(`共享状态的${assetKindLabel()}不能删除,请先取消共享`,`A shared ${assetKindLabelEn()} can't be deleted. Stop sharing it first`); const refs=assetReferenceNames(a); - if(refs.length)return `${assetKindLabel()}仍被 ${refs.length} 个${assetRefKindLabel()}引用(${refs.join('、')}),请先解除引用`; + if(refs.length)return lfT(`${assetKindLabel()}仍被 ${refs.length} 个${assetRefKindLabel()}引用(${refs.join('、')}),请先解除引用`,`This ${assetKindLabelEn()} is still used by ${refs.length} ${assetRefKindLabelEn(refs.length)} (${refs.join(', ')}). Remove those references first`); return ''; } async function deleteAsset(id){ @@ -282,13 +293,13 @@ async function deleteAsset(id){ const blocked=assetDeleteBlocked(item); if(blocked)return toast(blocked); const label=assetKindLabel(); - if(!await afConfirm({title:`删除${label}确认`,message:`确认删除${label}「${item.name}」?此操作不可恢复。`,confirmText:'确认删除',danger:true}))return; + if(!await afConfirm({title:lfT(`删除${label}确认`,`Delete ${assetKindLabelEn()}`),message:lfT(`确认删除${label}「${item.name}」?此操作不可恢复。`,`Delete ${assetKindLabelEn()} "${item.name}"? This can't be undone.`),messageData:true,confirmText:'确认删除',danger:true}))return; try{ await api(`/api/${state.assetType}?id=${encodeURIComponent(id)}`,{method:'DELETE'}); state.data[state.assetType]=(state.data[state.assetType]||[]).filter(x=>x.id!==id); if(state.selectedAsset===id)await closeAssetDetail({force:true}); else renderAssets(); - toast(`${label}已删除`); + toast(lfT(`${label}已删除`,`${assetKindLabelEn().replace(/^./,c=>c.toUpperCase())} deleted`)); }catch(e){toast(e.message||'删除失败')} } function assetKind(){return assetKindLabel()} @@ -311,8 +322,8 @@ function syncSandboxDriverFields(select){ } function resolveAssetSaveIdentity(items,selectedID,requestedID){if(selectedID!=='__new__'){const existing=(items||[]).find(item=>item.id===selectedID);return existing?{id:existing.id,existing,created:false}:{error:'选中的资产已不存在,请刷新后重试'}}if((items||[]).some(item=>item.id===requestedID))return {error:'该标识已存在,请换一个标识,或回到列表打开已有资产修改'};return {id:requestedID,existing:null,created:true}} function assetPaneTabs(type=state.assetType){return ({rules:[['edit','编辑'],['preview','预览']],skills:[['files','文件']],sandboxes:[['setup','配置']]})[type]||[['edit','编辑']]} -function assetPaneHint(type=state.assetType){return ({rules:'支持 Markdown',skills:'每次上传都会完整替换现有文件',sandboxes:'隔离方式决定沙箱在哪里、怎样执行'})[type]||''} -function assetFieldLabel(text,help,forId=''){return `
${forId?``:`${escapeHTML(text)}`}${help?``:''}
`} +function assetPaneHint(type=state.assetType){return ({rules:lfT('支持 Markdown','Markdown supported'),skills:'每次上传都会完整替换现有文件',sandboxes:'隔离方式决定沙箱在哪里、怎样执行'})[type]||''} +function assetFieldLabel(text,help,forId=''){return `
${forId?``:`${escapeHTML(text)}`}${help?``:''}
`} function sandboxSetupHTML(a){ const driver=sandboxDriverOption(a.driver); const privilegeHelp=lfT('执行机器须允许特权沙箱。容器内进程可访问宿主机设备,并可能控制执行机器。','The execution machine must allow privileged sandboxes. Processes in the container can access host devices and may take control of the machine.'); diff --git a/web/app/mcp.js b/web/app/mcp.js index a4d0bccf0..c83346394 100644 --- a/web/app/mcp.js +++ b/web/app/mcp.js @@ -187,11 +187,12 @@ function renderMCPManagement(){ const matchedInstalled=installed.filter(item=>mcpMatchesQuery(item,query)); const installedCount=$('#mcpInstalledCount'); if(installedCount)installedCount.textContent=String(matchedInstalled.length); - hint.innerHTML=personal?`个人 MCP仅 ${escapeHTML(userDisplay(state.currentUser)||'当前用户')} 可见。`:`项目 MCP添加到「${escapeHTML(project?.name||'未选择项目')}」,不会出现在其他项目中。`; + const owner=personal?(userDisplay(state.currentUser)||lfT('当前用户','you')):(project?.name||lfT('未选择项目','no project selected')); + hint.innerHTML=personal?`个人 MCP${escapeHTML(lfT(`仅 ${owner} 可见。`,`Only visible to ${owner}.`))}`:`项目 MCP${escapeHTML(lfT(`添加到「${owner}」,不会出现在其他项目中。`,`Added to "${owner}"; it won't appear in other projects.`))}`; if(personal&&(!state.currentUser||state.currentUser.isGuest)){grid.innerHTML='
登录后才能管理个人 MCP

项目级 MCP 仍可在当前项目中管理。

';return} const pagedMCP=paginateList('mcp',matchedInstalled); const catalog=personal?'':mcpCatalogSuggestionsHTML(installed,query); - const cards=pagedMCP.items.map(item=>`

${escapeHTML(item.name)}

${personal?'个人专属':escapeHTML(project?.name||item.projectId)}
${item.marketId?'市场':'自定义'}

${escapeHTML(item.description||'暂无说明')}

${item.authType==='github-token'?'GitHub 令牌认证':'自定义认证'}${escapeHTML(item.transport||'http')}
${item.marketId?'':``}
`).join(''); + const cards=pagedMCP.items.map(item=>`

${escapeHTML(item.name)}

${personal?'个人专属':escapeHTML(project?.name||item.projectId)}
${item.marketId?'市场':'自定义'}
${escapeHTML(item.description||'暂无说明')}

${item.authType==='github-token'?'GitHub 令牌认证':'自定义认证'}${escapeHTML(item.transport||'http')}
${item.marketId?'':``}
`).join(''); grid.innerHTML=catalog+(cards||(query?'
没有匹配的 MCP

换个关键词试试。

':`
当前范围还没有 MCP

点击右上角「添加 MCP」,${personal?'创建个人专属配置':'为本项目接入工具'}。

`)); if(cards)grid.insertAdjacentHTML('beforeend',pagerHTML('mcp',pagedMCP)); bindMCPLogoFallbacks(grid); diff --git a/web/assets_detail_test.js b/web/assets_detail_test.js index 8278ab517..7ce6055b3 100644 --- a/web/assets_detail_test.js +++ b/web/assets_detail_test.js @@ -74,7 +74,7 @@ const shared = ctx.assetCardHTML(ctx.state.data.rules[1]); assert.ok(shared.includes('已共享'), shared); assert.ok(shared.includes('暂无说明') && shared.includes('未被引用'), shared); const foreign = ctx.assetCardHTML(ctx.state.data.rules[2]); -assert.ok(foreign.includes('来自 平台公共'), foreign); +assert.ok(foreign.includes('来自 平台公共'), foreign); assert.ok(foreign.includes('查看'), foreign); for (const html of [own, shared, foreign]) { assert.ok(!/