${name}
${desc}
本地确定性工具 · Tool Gateway/* Small, owned extension surfaces: install -> adapt -> use, with explicit context and scheduling. */ (()=>{ const $p=id=>document.getElementById(id),h=esc; const dialog=document.createElement('dialog');dialog.id='platformDialog';dialog.className='platform-dialog';document.body.append(dialog); function show(title,html){dialog.innerHTML=`
安装一个技能,改成自己的方法;需要多步协作,再组合为数字员工。
${desc}
本地确定性工具 · Tool Gateway${h(x.description)}
${h(x.publisher)} · v${x.version}${h(x.content.slice(0,150))}
${x.owner_scope==='personal'?'个人技能':'系统共享'} · v${x.version}没有匹配项,可以创建自己的技能。
'; } function skillEditor(id){const x=mine.find(x=>x.skill_id===id),own=x?.owner_scope==='personal';show(own?'编辑个人技能':'创建个人技能',``);$p('personalSkillForm').onsubmit=async e=>{e.preventDefault();try{const data=Object.fromEntries(new FormData(e.target));await api('/skills'+(own?'/'+id:''),own?'PUT':'POST',{...data,...(own?{expected_version:x.version}:{})},rid());tab='mine';await skills();toast('技能已保存')}catch(err){toast(err.message)}}} async function utility(id){const entry=utilities.find(x=>x[0]===id);const sample=id==='rows-csv'?{rows:[{编号:'001',事项:'资料归档',负责人:'待确认'}]}:id==='action-checklist'?{actions:[{owner:'',task:'资料归档',due:''}]}:{text:'请在这里粘贴需要处理的文本。'};show(entry[1],`${entry[2]};仅处理当前输入,不向外部发送。
`);$p('utilityForm').onsubmit=async e=>{e.preventDefault();try{const wid=await ensureSpace(entry[1]),r=await api('/workspaces/'+wid+'/tools/'+id+'/invoke','POST',{arguments:JSON.parse($p('utilityInput').value)},rid());$p('utilityResult').textContent=JSON.stringify(r.result,null,2)}catch(err){toast(err.message)}}} document.getElementById('skillsNav').onclick=()=>skills().catch(e=>toast(e.message)); dialog.addEventListener('click',async e=>{const b=e.target.closest('button');if(!b)return;try{if(b.dataset.skillTab){tab=b.dataset.skillTab;renderSkills()}if(b.dataset.skillCategory){category=b.dataset.skillCategory;renderSkills()}if(b.dataset.installSkill){if(!canNavigate())return;if($p('prompt').value.trim()&&!confirm('用此技能的示例替换当前尚未发送的输入?'))return;b.disabled=true;const value=await api('/platform/market/'+b.dataset.installSkill+'/install','POST');S.skills=(await api('/skills')).items;S.selectedSkills.add(value.skill_id);selections();if(!canNavigate())throw new Error('当前任务执行中,请完成后使用。');$p('prompt').value=value.starter;dialog.close();$p('prompt').focus();toast('技能已安装并用于当前对话')}if(b.dataset.useSkill){if(!canNavigate())return;S.selectedSkills.add(b.dataset.useSkill);selections();dialog.close();toast('已用于本轮对话')}if(b.dataset.editSkill)skillEditor(b.dataset.editSkill);if(b.dataset.exportSkill){const x=mine.find(x=>x.skill_id===b.dataset.exportSkill);saveFile(x.name+'.json',JSON.stringify({name:x.name,category:x.category,content:x.content},null,2))}if(b.dataset.utility)utility(b.dataset.utility)}catch(err){toast(err.message)}finally{if(b.isConnected)b.disabled=false}}); let memories=[],facts=[],suggestions=[]; async function context(){memories=(await api('/personal-context')).items;const c=S.wid?await api('/workspaces/'+S.wid+'/context'):null;facts=c?.facts||[];show('我的上下文',`个人记忆跨本人事项使用;事项事实只用于当前事项。模型提取的候选必须由你核对保存。
${h(m.value)}
仅本人 · v${m.revision}记住你的写作风格、常用称谓或阶段工作目标。
'}尚无已确认事实。
'}${S.wid?``:'进入一个对话后,可管理事项事实和查看快照。
'}`); $p('addMemory').onclick=()=>memoryEditor();$p('exportMemory').onclick=()=>saveFile('我的上下文.json',JSON.stringify(memories,null,2));$p('suggestMemory').onclick=async e=>{e.target.disabled=true;try{const r=await api('/workspaces/'+S.wid+'/context/suggestions','POST');suggestions=r.items;$p('memorySuggestions').innerHTML='未发现适合保存的长期上下文。
')}catch(err){toast(err.message)}finally{e.target.disabled=false}}; if(S.wid){$p('workspaceFactForm').onsubmit=async e=>{e.preventDefault();try{const d=Object.fromEntries(new FormData(e.target));await api('/workspaces/'+S.wid+'/context/facts','PUT',{...d,expected_revision:facts.find(x=>x.key===d.key)?.revision||0});await context()}catch(err){toast(err.message)}};$p('previewMyContext').onclick=async()=>{try{const r=await api('/workspaces/'+S.wid+'/context/preview');$p('myContextPreview').textContent=JSON.stringify({snapshot_id:r.snapshot_id,personal_context:r.personal_context,confirmed_facts:r.confirmed_facts,missing_fields:r.missing_fields,budget_chars:r.budget_chars,used_chars:r.used_chars,omitted_message_count:r.omitted_message_count,policy:r.policy},null,2)}catch(err){toast(err.message)}};$p('historyMyContext').onclick=async()=>{try{$p('myContextPreview').textContent=JSON.stringify((await api('/workspaces/'+S.wid+'/context/snapshots')).items,null,2)}catch(err){toast(err.message)}}} } function memoryEditor(id,candidate){const m=memories.find(x=>x.id===id)||candidate||{};show(id?'编辑个人上下文':'确认个人上下文',``);$p('memoryForm').onsubmit=async e=>{e.preventDefault();try{const f=new FormData(e.target);await api('/personal-context'+(id?'/'+id:''),id?'PUT':'POST',{name:f.get('name'),value:f.get('value'),kind:f.get('kind'),enabled:f.has('enabled'),source_workspace_id:m.source_workspace_id||S.wid||null,...(id?{expected_revision:m.revision}:{})});await context();toast('上下文已保存')}catch(err){toast(err.message)}}} dialog.addEventListener('click',async e=>{const b=e.target.closest('button');if(!b)return;try{const id=b.dataset.memoryEdit||b.dataset.memoryToggle||b.dataset.memoryDelete,m=memories.find(x=>x.id===id);if(b.dataset.memoryEdit)memoryEditor(id);if(b.dataset.memorySuggestion!==undefined)memoryEditor(null,{...suggestions[Number(b.dataset.memorySuggestion)],source_workspace_id:S.wid});if(b.dataset.memoryToggle){const d={name:m.name,value:m.value,kind:m.kind,source_workspace_id:m.source_workspace_id,enabled:!m.enabled,expected_revision:m.revision};await api('/personal-context/'+id,'PUT',d);await context()}if(b.dataset.memoryDelete&&confirm('删除此条个人记忆?后续对话不再注入;历史快照仍保留。')){await api('/personal-context/'+id+'?expected_revision='+m.revision,'DELETE');await context()}if(b.dataset.factDelete){await api('/workspaces/'+S.wid+'/context/facts/'+encodeURIComponent(b.dataset.factDelete)+'?expected_revision='+b.dataset.revision,'DELETE');await context()}}catch(err){toast(err.message)}}); const personalContextNav=document.createElement('button');personalContextNav.id='personalContextNav';personalContextNav.hidden=true;personalContextNav.setAttribute('aria-hidden','true'); let tasks=[]; const taskNav=document.createElement('button');taskNav.id='schedulesNav';taskNav.innerHTML='';taskNav.title='定时任务';taskNav.setAttribute('aria-label','定时任务');taskNav.onclick=()=>schedules().catch(e=>toast(e.message));document.getElementById('scheduleNavGroup').append(taskNav); async function schedules(){const r=await api('/schedules');tasks=r.items;show('我的定时任务',`服务端按北京时间(UTC+8)执行,可选择模型、技能、知识库与数字员工。输出保存在本人事项;人工确认和外发授权不会被跳过。${r.public_lifetime_minutes?'公开演示仅在访客会话存活期间运行,15分钟闲置后会清理。':''}
${tasks.map(t=>`${h(t.prompt)}
${t.frequency==='once'?'单次':t.frequency==='daily'?'每天':'每周'+['一','二','三','四','五','六','日'][t.weekday]} ${h(t.frequency==='once'?t.run_at:t.time)} · 下次:${t.next_at?new Date(t.next_at).toLocaleString():'—'} · 模型 ${h(t.model_route)}${h(x.summary||x.message||x.note||'执行中')}
${x.workspace_id?``:''}尚未执行。
'}