openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 7.49 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{$s as n,Ei as r,Oa as i,Pi as a,Qs as o,Qt as s,Xt as c,Yn as l,ka as u,vi as d,wa as f,xa as p,zs as m}from"./control-ui-connection-Bfj9beF_.js";import{Fc as h,Pc as g,XO as _,bD as v,dj as y,nk as b,pj as x,vD as S}from"./control-ui-boot-shared-DFTSUQQ0.js";import{gc as C,o as w,s as T}from"./control-ui-boot-chat-DewxEbIm.js";import{a as E,i as D}from"./virtual-core-runtime-BYd4CRBu.js";var O,k;function A(){return(A=e((()=>{u(),O={templatesDraft:{railHint:`Turn this agent into a shareable Template`,reviewTitle:`Review your Template`,intro:`Choose what to include. The archive below is rebuilt before publication.`,name:`Name`,description:`Description`,behavior:`Behavior and authority`,input:`Input`,output:`Output`,authority:`Authority`,workspaceFiles:`Workspace files`,skills:`Skills`,plugins:`Plugins`,mcpServers:`MCP servers`,automations:`Automations`,packageContents:`Package contents`,packageNote:`These are the exact text files in the current archive. Dependencies above are declarations.`,view:`View`,updating:`Updating package preview…`,reviewNeeded:`Review the current package before publishing.`,askChanges:`Ask for changes`,refreshReview:`Refresh review`,publish:`Publish to ClawHub`,publishing:`Publishing…`,published:`Published on ClawHub.`,pending:`Submitted to ClawHub. Publication pending security review.`,viewPublication:`View on ClawHub`,retryReview:`Retry review`,reopen:`Review Template package`,openingChat:`Opening the agent’s main chat…`,sendFailed:`The main chat did not accept the Create Template message.`}},k=Object.assign(()=>C(i,O),{catalog:O})})))()}var j=t({TemplateCreatorFlow:()=>P,templateCreatorFlow:()=>N});function M(e){let t=JSON.parse(e);if(typeof t!=`object`||!t||!(`scope`in t))return!1;let n=t.scope;return typeof n==`object`&&!!n&&[`input`,`job`,`output`,`authority`].every(e=>{let t=Reflect.get(n,e);return typeof t==`string`&&t.trim().length>0})}function N(e){let t=T(e);return t.flow||(t.flow=new P(e),t.publish()),t.flow}var P;function F(){return(F=e((()=>{p(),D(),A(),s(),g(),y(),_(),d(),S(),n(),w(),x(E),x(k),P=class{get hasActiveDraft(){return this.target!==null}constructor(e){this.context=e,this.listeners=l(),this.target=null,this.pollTimer=null,this.editTimer=null,this.generation=0,this.reviewRequest=0,this.seenRevision=null,this.busy=null,this.review=null,this.reviewRead=null,this.reviewCurrent=!1,this.choices=null,this.modalOpen=!1,this.publication=null,this.error=null,this.presentationLifetime=Promise.withResolvers(),this.subscribe=this.listeners.subscribe,this.changed=this.listeners.publish;let t=e.gateway.snapshot.client;e.gateway.subscribe(e=>{e.client!==t&&(t=e.client,this.busy=null,this.reset(null))})}retirePresentation(){this.presentationLifetime.resolve(),this.presentationLifetime=Promise.withResolvers()}mainSessionKey(e){let t=a({agentsList:this.context.agents.state.agentsList,hello:this.context.gateway.snapshot.hello});return m({agentId:e,mainKey:t})}navigate(e){this.context.navigate(`chat`,b({context:this.context,face:`chat`,sessionKey:e.sessionKey,agentId:e.agentId,navigationKey:e.sessionKey}).options)}current(e,t){return this.target===e&&this.generation===t&&this.context.gateway.snapshot.client===e.client}reset(e){return this.retirePendingStart(),this.retirePresentation(),this.generation+=1,this.reviewRequest+=1,this.pollTimer&&clearTimeout(this.pollTimer),this.editTimer&&clearTimeout(this.editTimer),this.target=e,this.seenRevision=null,this.review=null,this.reviewRead=null,this.reviewCurrent=!1,this.choices=null,this.modalOpen=!1,this.publication=null,this.error=null,this.changed(),this.generation}async start(e){let t=this.context.gateway.snapshot.client;if(t&&this.busy!==`starting`){this.retirePendingStart(),this.busy=`starting`,this.error=null,this.changed();try{let n=await t.request(`templates.drafts.create`,{agentId:e});if(this.context.gateway.snapshot.client!==t)return;let i={agentId:e,draftId:n.draftId,sessionKey:this.mainSessionKey(e),client:t},a=this.reset(i),s=await t.request(`chat.send`,{sessionKey:i.sessionKey,...r(i.sessionKey)?{agentId:e}:{},message:n.prompt,workContext:{page:`template-create`,title:f(`templatesDraft.title`),agentId:e,sessionKey:i.sessionKey,detail:{draftId:i.draftId}},deliver:!1,idempotencyKey:o()});if(!this.current(i,a))return;if(![`ok`,`started`,`in_flight`].includes(s.status??``))throw Error(f(`templatesDraft.sendFailed`));this.navigate(i),this.schedulePoll(i,a)}catch(n){if(this.context.gateway.snapshot.client===t){let t=c(n);this.reset(null),this.error=t,v({message:t,actionLabel:f(`common.retry`),onAction:()=>void this.start(e)})}}finally{this.context.gateway.snapshot.client===t&&(this.busy=null,this.changed())}}}open(e,t){let n=this.context.gateway.snapshot.client;if(!n)return;let r={agentId:e,draftId:t,sessionKey:this.mainSessionKey(e),client:n},i=this.reset(r);this.navigate(r),this.schedulePoll(r,i,0)}schedulePoll(e,t,n=2500){this.pollTimer=setTimeout(()=>void this.poll(e,t),n)}async poll(e,t){if(this.current(e,t)&&!this.publication)try{let n=await e.client.request(`templates.drafts.read`,{agentId:e.agentId,draftId:e.draftId});if(!this.current(e,t))return;n.revision!==this.seenRevision&&(this.seenRevision!==null&&(this.choices=null,this.reviewCurrent=!1),this.seenRevision=n.revision,M(n.content)&&await this.refreshReview(e,t))}catch(n){this.current(e,t)&&(this.error=c(n),this.changed())}finally{this.current(e,t)&&!this.publication&&this.schedulePoll(e,t)}}async refreshReview(e,t){if(!this.current(e,t))return;this.busy=`reviewing`;let n=++this.reviewRequest,r=(async()=>{let r=await e.client.request(`templates.drafts.review`,{agentId:e.agentId,draftId:e.draftId,...this.choices?{choices:this.choices}:{}});this.current(e,t)&&n===this.reviewRequest&&(this.review=r,this.reviewCurrent=!0,this.choices??={name:r.name.split(`/`).at(-1)??r.name,displayName:r.displayName,description:r.description,excluded:r.items.filter(e=>!e.included).map(e=>e.id)},this.modalOpen=!0,this.error=null)})();this.reviewRead={result:r},this.changed();try{await r}catch(r){this.current(e,t)&&n===this.reviewRequest&&(this.error=c(r))}finally{this.current(e,t)&&n===this.reviewRequest&&(this.busy=null,this.changed())}}updateChoices(e){let t=this.target;if(!t||!this.choices)return;this.choices=e,this.reviewCurrent=!1,this.changed(),this.editTimer&&clearTimeout(this.editTimer);let n=this.generation;this.editTimer=setTimeout(()=>void this.refreshReview(t,n),350)}async publish(){let e=this.target,t=this.review,n=this.choices;if(!e||!t||!n||!this.reviewCurrent||this.busy)return;let r=this.generation;this.busy=`publishing`,this.reviewCurrent=!1,this.changed();try{let i=await e.client.request(`templates.drafts.publish`,{agentId:e.agentId,draftId:e.draftId,reviewToken:t.reviewToken,choices:n});this.current(e,r)&&(this.publication=i,this.modalOpen=!1,this.error=null,v({message:f(i.publicationStatus===`published`?`templatesDraft.published`:`templatesDraft.pending`),actionLabel:f(`templatesDraft.viewPublication`),onAction:()=>h(i.url)}))}catch(t){this.current(e,r)&&(this.error=c(t))}finally{this.current(e,r)&&(this.busy=null,this.changed())}}close(){this.retirePresentation(),this.modalOpen=!1,this.changed()}reopen(){this.review&&(this.modalOpen=!0,this.changed())}retryReview(){let e=this.target;e&&this.refreshReview(e,this.generation)}retirePendingStart(){let e=T(this.context);e.flow===this&&(e.pending=null)}}})))()}export{F as n,N as r,j as t};