UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 12.3 kB
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{Gu as n,Qo as r,Xc as i,Ya as a,al as o,h as s,li as c,mi as l,ms as u,na as d,oi as f,ol as p,os as m,pi as h,v as g}from"./_4____________________________.js";import{AN as _,EN as v,GA as y,GN as b,WC as x,fk as S,mk as C,qN as w,zA as T}from"./_2_____________________________.js";import{N as E,P as D}from"./deferred-ui-support-DZEPWjAk.js";import{c as O,d as k,f as A,s as j}from"./template-draft-runtime-DZoxdWm2.js";var M,N;function P(){return(P=e((()=>{l(),M={templatesDraft:{railHint:`Turn this agent into a shareable template`,reviewTitle:`Review your template`,intro:`Preview the assembled package, then publish it to ClawHub.`,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`,workspaceFilesHint:`Instructions and reference material.`,skillsHint:`Skills required by this template.`,pluginsHint:`Plugins this template needs to work.`,mcpServersHint:`External tool servers used by this template.`,automationsHint:`Scheduled tasks included with this template.`,content:`Content`,skillDocument:`SKILL.md · {ref} · {version}`,packageDetails:`Package requirement`,package:`Package`,version:`Version`,source:`Source`,bundled:`Bundled with template`,installation:`Installation`,pluginInstallation:`Required when this template is added`,contentUnavailable:`Package preview is unavailable for this version.`,timezone:`Timezone`,session:`Session`,isolatedSession:`Separate session`,mainSession:`Main session`,pausedInstallation:`Paused when installed`,enabledInstallation:`Enabled when installed`,message:`Prompt`,connectionDetails:`Connection details`,schedule:`Schedule`,serverValues:{"streamable-http":`Streamable HTTP`,sse:`Server-sent events`,stdio:`Standard input/output`,oauth:`OAuth · Sign-in required`},serverFields:{server:`Server`,auth:`Authentication`,transport:`Transport`,url:`Endpoint`,command:`Command`,args:`Arguments`,env:`Environment`,headers:`Headers`,toolFilter:`Tools`,timeout:`Timeout`,connectTimeout:`Connection timeout`},packageContents:`Package contents`,packageNote:`These are the exact text files in the current archive. Dependencies above are declarations.`,view:`View`,viewAll:`View all`,updating:`Updating package preview…`,reviewNeeded:`Review the current package before publishing.`,refreshReview:`Refresh review`,publish:`Publish`,publishing:`Publishing…`,published:`Published`,unpublished:`Unpublished`,pending:`Pending`,awaitingReview:`Awaiting security review`,viewSubmission:`View submission`,copyLink:`Copy link`,byCreator:`by {creator}`,backToTemplate:`Back to Template`,backToContents:`Back to contents`,fileNavigation:`Package files`,emptyContents:`No files`,job:`Job`,notPublished:`Not published`,unconfirmed:`Submission unconfirmed`,checkStatus:`Check status`,registryFailed:`ClawHub did not publish this package ({reason}). Review it before retrying.`,invalidTarget:`This Template review does not belong to the current conversation.`,retryReview:`Retry review`,reopen:`Review template package`,openingChat:`Opening the agent’s main session…`,sendFailed:`Couldn’t start template creation. Try again.`}},N=Object.assign(()=>x(h,M),{catalog:M})})))()}var F=t({TemplateCreatorFlow:()=>R,templateCreatorFlow:()=>L});function I(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 L(e,t){let n=D(e);if(t){let r=n.inlineFlows??=new Map,i=JSON.stringify([t.agentId,t.draftId,t.sessionKey]),a=r.get(i)??(n.flow?.matches(t)?n.flow:void 0);return a||=new R(e),r.set(i,a),a}return(!n.flow||n.flow.inlineReview)&&(n.flow=new R(e),n.publish()),n.flow}var R;function z(){return(z=e((()=>{s(),f(),k(),P(),_(),b(),T(),r(),S(),p(),E(),O(),w(A),w(N),R=class{get hasActiveDraft(){return this.target!==null}constructor(e){this.context=e,this.listeners=a(),this.target=null,this.pollTimer=null,this.generation=0,this.reviewRequest=0,this.seenRevision=null,this.busy=null,this.review=null,this.reviewCurrent=!1,this.choices=null,this.inlineReview=!1,this.publication=null,this.publicationIssue=null,this.error=null,this.subscribe=this.listeners.subscribe,this.changed=this.listeners.publish;let t=e.router,n=t.getState().location.pathname;t.subscribe(()=>{let e=t.getState().location.pathname;e!==n&&(n=e,this.retirePresentation())});let r=e.gateway.snapshot.client;e.gateway.subscribe(e=>{e.client!==r&&(r=e.client,this.busy=null,this.reset(null))})}retirePresentation(){this.pollTimer&&clearTimeout(this.pollTimer)}mainSessionKey(e){let t=u({agentsList:this.context.agents.state.agentsList,hello:this.context.gateway.snapshot.hello});return i({agentId:e,mainKey:t})}navigate(e){this.context.navigate(`chat`,y({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.target=e,this.seenRevision=null,this.review=null,this.reviewCurrent=!1,this.choices=null,this.publication=null,this.inlineReview=!1,this.publicationIssue=null,this.publicationAttemptId=void 0,this.publicationReviewToken=void 0,this.error=null,this.changed(),this.generation}async start(e){let t=this.context.gateway.snapshot.client;if(!t||this.busy===`starting`)return;this.retirePendingStart();let n=this.generation;this.busy=`starting`,this.error=null,this.changed();try{let r=await t.request(`templates.drafts.create`,{agentId:e});if(this.context.gateway.snapshot.client!==t||this.generation!==n)return;let i={agentId:e,draftId:r.draftId,sessionKey:this.mainSessionKey(e),client:t};n=this.reset(i);let a=await t.request(`chat.send`,{sessionKey:i.sessionKey,...m(i.sessionKey)?{agentId:e}:{},message:r.prompt,workContext:{page:`template-create`,title:c(`templatesDraft.title`),agentId:e,sessionKey:i.sessionKey,detail:{draftId:i.draftId}},deliver:!1,idempotencyKey:o()});if(!this.current(i,n))return;if(![`ok`,`started`,`in_flight`].includes(a.status??``))throw Error(c(`templatesDraft.sendFailed`));this.navigate(i),this.schedulePoll(i,n)}catch(r){if(this.context.gateway.snapshot.client===t&&this.generation===n){let t=v(r);n=this.reset(null),this.error=t,C({severity:`error`,message:t,actionLabel:c(`common.retry`),onAction:()=>void this.start(e)})}}finally{this.context.gateway.snapshot.client===t&&this.generation===n&&(this.busy=null,this.changed())}}open(e,t,n=this.mainSessionKey(e)){let r=this.context.gateway.snapshot.client;if(!r)return;let i={agentId:e,draftId:t,sessionKey:n,client:r};this.busy=null;let a=this.reset(i);this.navigate(i),this.schedulePoll(i,a,0)}matches(e){return this.target?.client===this.context.gateway.snapshot.client&&this.target.agentId===e.agentId&&this.target.draftId===e.draftId&&this.target.sessionKey===e.sessionKey}get sessionKey(){return this.target?.sessionKey}hydrate(e,t,n){let r=this.context.gateway.snapshot.client;if(!r)return;if(this.matches({agentId:e,draftId:t,sessionKey:n})){if(this.inlineReview=!0,this.changed(),this.busy===`publishing`)return;this.publication||this.publicationIssue?this.checkPublication():this.schedulePoll(this.target,this.generation,0);return}this.busy=null;let i={agentId:e,draftId:t,sessionKey:n,client:r},a=this.reset(i);this.inlineReview=!0,this.changed(),this.schedulePoll(i,a,0)}schedulePoll(e,t,n=2500){this.pollTimer&&clearTimeout(this.pollTimer),this.pollTimer=setTimeout(()=>{this.current(e,t)&&(this.publication?.publicationStatus===`pending`?this.checkPublication():this.poll(e,t))},n)}async poll(e,t){if(!(!this.current(e,t)||this.publication||this.publicationIssue))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,I(n.content)&&await this.refreshReview(e,t))}catch(n){this.current(e,t)&&(this.error=v(n),this.changed())}finally{this.current(e,t)&&!this.publication&&!this.publicationIssue&&this.schedulePoll(e,t)}}async refreshReview(e,t){if(!this.current(e,t))return;this.busy=`reviewing`;let n=++this.reviewRequest;this.changed();try{let r=await e.client.request(`templates.drafts.review`,{agentId:e.agentId,draftId:e.draftId,...this.choices?{choices:this.choices}:{}});if(!this.current(e,t)||n!==this.reviewRequest)return;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.error=null}catch(r){this.current(e,t)&&n===this.reviewRequest&&(this.error=v(r))}finally{this.current(e,t)&&n===this.reviewRequest&&(this.busy=null,this.changed())}}async publish(){let e=this.target,t=this.review,r=this.choices;if(!e||!t||!r||!this.reviewCurrent||this.busy||this.publication||this.publicationIssue===`unconfirmed`)return;if(!j(this.context)){this.error=c(`templatesDraft.reviewUnavailable`),this.changed();return}let i=this.generation;this.pollTimer&&clearTimeout(this.pollTimer),this.publicationReviewToken=t.reviewToken,this.publicationIssue=null,this.busy=`publishing`,this.reviewCurrent=!1,this.changed();try{let n=await e.client.request(`templates.drafts.publish`,{agentId:e.agentId,draftId:e.draftId,reviewToken:t.reviewToken,choices:r});this.current(e,i)&&(this.publication=n,this.publicationAttemptId=n.attemptId,this.error=null)}catch(t){if(this.current(e,i)){let e=t instanceof g?n(n(t.details)?.templatePublication)?.effect:void 0;this.publicationIssue=e===`none`?`failed`:`unconfirmed`,this.error=v(t)}}finally{this.current(e,i)&&(this.busy=null,this.publication?.publicationStatus===`pending`&&this.schedulePoll(e,i,5e3),this.changed())}}async checkPublication(){let e=this.target,t=this.review;if(!e||!t||this.busy||!j(this.context))return;let n=this.generation;this.busy=`reviewing`,this.changed();try{let r=await e.client.request(`templates.drafts.review`,{agentId:e.agentId,draftId:e.draftId,choices:this.choices??void 0,checkPublication:!0,reviewToken:this.publicationReviewToken??t.reviewToken,...this.publicationAttemptId?{attemptId:this.publicationAttemptId}:{}});if(!this.current(e,n))return;let i=r.publicationState;i?.status===`published`||i?.status===`pending`?(this.publication=i.publication,this.publicationIssue=null,this.error=null):i?.status===`failed`?(this.publication=null,this.publicationIssue=`failed`,this.error=c(`templatesDraft.registryFailed`,{reason:i.reason})):(this.publicationIssue=`unconfirmed`,this.publication=null)}catch(t){this.current(e,n)&&(this.error=v(t))}finally{this.current(e,n)&&(this.busy=null,this.changed(),this.publication?.publicationStatus===`pending`&&this.schedulePoll(e,n,5e3))}}retryReview(){if(this.publicationIssue===`unconfirmed`)return;this.publicationIssue=null;let e=this.target;e&&this.refreshReview(e,this.generation)}async readPackagePreview(e){let t=this.target,n=this.review,r=this.generation;if(!t||!n?.items.includes(e)||!e.requirement)return null;let i=e.requirement;if(i.source===`bundled`)return{content:e.kind===`skill`?n.files.find(e=>e.path===`${i.path}/SKILL.md`)?.content:void 0};let{ref:a,version:o}=i,s;if(e.kind===`skill`){let e=await t.client.request(`skills.detail`,{slug:a,version:o});s={description:e.skill?.summary,content:e.card?.status===`available`?e.card.content:void 0}}else if(e.kind===`plugin`){let e=`ch_`+d(new TextEncoder().encode(a)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/[=]+$/u,``),n=await t.client.request(`plugins.catalog.get`,{id:e,version:o});s=n.detail.origin===`clawhub`&&n.detail.packageName===a&&n.detail.selectedRelease?.version===o&&!n.detail.remoteError?{description:n.plugin.catalog.summary}:{}}else return null;return this.current(t,r)&&this.review===n?s:null}retirePendingStart(){let e=D(this.context);e.flow===this&&(e.pending=null)}}})))()}export{N as a,P as i,z as n,L as r,F as t};