openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 10.6 kB
JavaScript
import{Sn as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import{t}from"./openclaw-state-read-node-crypto-40z5rHq3.mjs";import{t as n}from"./openclaw-state-read-closed-object-D3QW4nRZ.mjs";import{t as r}from"./openclaw-state-read-primitives-B8yGv9fM.mjs";import{t as i}from"./openclaw-state-read-string-literal-union-A6jxKQ93.mjs";import{n as a,r as o,t as s}from"./openclaw-state-read-users-DoeulYXf.mjs";import{AsyncLocalStorage as c}from"node:async_hooks";import{Type as l}from"typebox";e(Symbol.for(`openclaw.sessionLifecycleEventListeners`),`close-and-restart`),e(Symbol.for(`openclaw.sessionIdentityMutationListeners`),`close-and-restart`),new c;const u=i([`system-detected`,`system-configured`,`agent-override`]),d=n({source:l.Union([l.Literal(`personal`),...u.anyOf]),...s.properties}),f=n({...d.properties,source:u}),p=l.Union([n({source:l.Literal(`shared`),expected:l.Optional(f)}),n({source:l.Literal(`personal`),generation:a,account:s})]),m=l.String({minLength:1,maxLength:256,pattern:`^[^\\r\\n]*\\S[^\\r\\n]*$`}),h=l.String({minLength:1,maxLength:8192}),g=n({action:l.Literal(`inspect_pr`),pullRequestUrl:l.String({minLength:1,maxLength:2048})}),_=n({action:l.Literal(`prepare_pr`),pullRequestUrl:g.properties.pullRequestUrl,conflictsResolved:l.Optional(l.Boolean()),expectedHeadCommit:l.Optional(l.String({pattern:`^[a-f0-9]{40}$`}))}),v=n({repository:r,repositoryId:l.Integer({minimum:1,maximum:2**53-1}),branch:r,commit:l.String({pattern:`^[a-f0-9]{40}$`})});n({url:r,host:r,number:l.Integer({minimum:1,maximum:2**53-1}),author:n({accountId:s.properties.accountId,login:l.String({minLength:1,maxLength:39,pattern:`^[A-Za-z0-9](?:[A-Za-z0-9_-]{0,37}[A-Za-z0-9])?$`})}),state:i([`open`,`draft`,`closed`,`merged`]),base:v,head:l.Union([v,l.Null()])}),n({sessionKey:l.Optional(r),agentId:l.Optional(r),idempotencyKey:r,workspacePath:l.Optional(l.String({minLength:1,maxLength:2048})),title:l.Optional(m),body:l.Optional(h),draft:l.Optional(l.Boolean()),selection:l.Optional(p)});const y=n({action:l.Union([l.Literal(`inspect`),l.Literal(`ready`),l.Literal(`merge`),l.Literal(`close`)]),publishingSessionKey:l.Optional(r),requestId:l.Optional(a),expectedHeadCommit:l.Optional(l.String({pattern:`^[a-f0-9]{40}$`})),mergeMethod:l.Optional(l.Union([l.Literal(`merge`),l.Literal(`squash`),l.Literal(`rebase`)]))}),b=n({action:l.Literal(`refresh_base`),conflictsResolved:l.Optional(l.Boolean()),baseCommit:l.Optional(l.String({pattern:`^[a-f0-9]{40}(?:[a-f0-9]{24})?$`}))}),x=n({action:l.Literal(`edit`),requestId:l.Optional(a),expectedHeadCommit:l.Optional(l.String({pattern:`^[a-f0-9]{40}$`})),title:l.Optional(m),body:l.Optional(l.String({maxLength:65536})),expectedTitle:l.Optional(m),expectedBody:l.Optional(l.String({maxLength:65536}))}),S=n({action:l.Literal(`request_review`),requestId:l.Optional(a),expectedHeadCommit:l.String({pattern:`^[a-f0-9]{40}$`})}),C=n({path:l.String({minLength:1,maxLength:1024}),sha256:l.String({pattern:`^[a-f0-9]{64}$`}),sizeBytes:l.Integer({minimum:1,maximum:1e7})}),w=n({action:l.Literal(`upload_evidence`),requestId:l.Optional(a),expectedHeadCommit:l.String({pattern:`^[a-f0-9]{40}$`}),evidence:C});l.Union([n({..._.properties,sessionKey:r,agentId:l.Optional(r)}),n({...g.properties,sessionKey:r,agentId:l.Optional(r)}),n({...S.properties,sessionKey:r,agentId:l.Optional(r)}),n({...w.properties,sessionKey:r,agentId:l.Optional(r)}),n({...x.properties,sessionKey:r,agentId:l.Optional(r)}),n({...y.properties,sessionKey:r,agentId:l.Optional(r)}),n({...b.properties,sessionKey:r,agentId:l.Optional(r)})]),n({status:i([`current`,`refreshed`,`conflicts`]),repository:r,baseBranch:r,baseCommit:r,changedPaths:l.Array(l.String()),conflictPaths:l.Array(l.String()),review:l.Optional(n({mode:l.Literal(`local`),base:r}))}),n({status:i([`prepared`,`conflicts`]),url:r,headCommit:l.String({pattern:`^[a-f0-9]{40}$`}),headChanged:l.Boolean(),changedPaths:l.Array(l.String()),conflictPaths:l.Array(l.String()),review:l.Optional(n({mode:l.Literal(`local`),base:r}))});const T={requestId:r,publisher:l.Optional(d),effect:l.Optional(n({kind:i([`push`,`pull_request`]),status:i([`dispatched`,`observed`]),headCommit:l.Optional(l.String({maxLength:64})),url:l.Optional(l.String({maxLength:2048}))}))},E=n({...T,status:l.Literal(`requested`),message:r}),D=n({...T,status:l.Literal(`publishing`),message:r}),O=n({...T,status:l.Literal(`published`),url:r,repository:r,branch:r,headCommit:r}),k={publishingSessionKey:r,state:l.Union([l.Literal(`draft`),l.Literal(`open`),l.Literal(`closed`),l.Literal(`merged`)]),headCommit:r,mergeCommit:l.Union([l.String(),l.Null()]),mergeable:l.Union([l.Boolean(),l.Null()]),mergeState:l.String(),reviewRequest:l.Optional(n({status:l.Literal(`posted`),url:r,message:r})),title:l.Optional(l.String()),body:l.Optional(l.String()),evidence:l.Optional(l.Union([n({status:l.Literal(`uploaded`),url:r,sha256:r,sizeBytes:l.Integer({minimum:1}),mimeType:r,publicAccess:l.Literal(`unverified`)}),n({status:l.Literal(`unconfirmed`),message:r})]))};l.Union([n({...k,publication:O}),n({...k,pullRequest:n({url:r,repository:r,branch:r})})]);const A=n({...T,status:l.Literal(`failed`),code:i([`identity_changed`,`identity_unavailable`,`session_changed`,`workspace_changed`,`not_git`,`not_github`,`no_changes`,`push_rejected`,`github_rejected`,`unavailable`]),message:r,nextAction:r}),j=n({...T,status:l.Literal(`needs_confirmation`),message:r}),M=l.Union([E,D,O,A,j]);n({sessionKey:r,agentId:l.Optional(r),idempotencyKey:l.Optional(r)}),n({sessionKey:r,agentId:l.Optional(r),requestId:a}),n({sessionKey:r,agentId:l.Optional(r),requestId:l.Optional(a)});const N=l.Union([n(l.Omit(E,[`publisher`,`message`]).properties),n(l.Omit(D,[`publisher`,`message`]).properties),n(l.Omit(O,[`publisher`]).properties),n(l.Omit(A,[`publisher`,`message`,`nextAction`]).properties)]);n({policy:n({read:l.Literal(`admitted`),write:l.Literal(`unknown`)}),custody:l.Union([n({kind:l.Literal(`qualified`),source:i([`worktree`,`repository`,`imported-pr`])}),n({kind:i([`unbound_workspace`,`archived`,`changed`])}),n({kind:l.Literal(`unknown`),reason:l.Literal(`unavailable`)})]),target:l.Union([n({kind:l.Literal(`supported`),basis:i([`registered-repository`,`repository-url`,`prepared-imported-pr`]),freshness:i([`observed`,`cached`])}),n({kind:l.Literal(`unsupported`)}),n({kind:l.Literal(`unknown`),reason:i([`not-qualified`,`unavailable`])})]),request:l.Union([n({kind:l.Literal(`observed`),selection:i([`exact`,`current`]),receipt:N}),n({kind:l.Literal(`none`),selection:l.Literal(`current`)}),n({kind:l.Literal(`unknown`),reason:i([`unavailable`,`not-observable`]),selectedRequestId:l.Optional(a)})]),remedies:l.Array(l.Union([n({kind:l.Literal(`select_bound_session`)}),n({kind:l.Literal(`inspect_source`)}),n({kind:l.Literal(`retry_read`)}),n({kind:l.Literal(`observe_request`),requestId:r})]),{maxItems:3})}),n({sessionKey:r,agentId:l.Optional(r),requestId:a,generation:a,account:s,requestDigest:l.String({minLength:64,maxLength:64,pattern:`^[a-f0-9]+$`})});const P=n({result:M,confirmation:l.Union([l.Null(),n({requestDigest:l.String({minLength:64,maxLength:64}),generation:a,account:s,pushRepository:l.String({maxLength:256}),repository:l.String({maxLength:256}),branch:l.String({maxLength:256}),baseBranch:l.String({maxLength:256}),sourceHeadCommit:l.String({maxLength:64}),sourceIndexTree:l.String({maxLength:64}),workspaceTree:l.String({maxLength:64})})])});n({stale:l.Optional(l.Boolean()),personal:l.Union([o,l.Null()]),shared:l.Union([f,l.Null()]),sharedUnavailableReason:l.Optional(i([`unavailable`,`changed`,`rate_limited`,`unverified`,`unsupported_workspace`])),pendingPersonal:l.Union([P,l.Null()]),latestShared:l.Union([P,l.Null()])});const F=new Set(A.properties.code.anyOf.map(e=>e.const));function publicationFailureCode(e){return F.has(e)?e:`unavailable`}function checkSharedWorktreeReceipt(e){if(assertReadableSharedGitHubPublication(e),e.request_digest!==digestGitHubPublicationRequest({sessionId:e.session_id,idempotencyKey:e.idempotency_key,title:e.title??void 0,body:e.body??void 0,draft:e.draft==null?void 0:e.draft===1}))throw Error(`GitHub publication receipt is corrupt.`)}function assertReadableSharedGitHubPublication(e){if(![`agent-override`,`system-configured`,`system-detected`].includes(e.identity_source)||!Number.isSafeInteger(e.identity_account_id)||e.identity_account_id<=0||!e.identity_login||![`requested`,`publishing`,`published`,`failed`].includes(e.status)||e.status===`published`&&(!e.pull_request_url||!e.repository||!e.branch||!e.head_commit)||e.status===`failed`&&(!e.error_code||!F.has(e.error_code)||!e.next_action))throw Error(`Shared GitHub publication receipt is corrupt.`)}function digestGitHubPublicationRequest(e){return t(JSON.stringify({sessionId:e.sessionId,idempotencyKey:e.idempotencyKey,title:e.title??null,body:e.body??null,...e.draft===void 0?{}:{draft:e.draft}}))}function projectGitHubPublicationResult(e){let t=(e.last_effect===`push`||e.last_effect===`pull_request`)&&(e.effect_state===`dispatched`||e.effect_state===`observed`)?{effect:{kind:e.last_effect,status:e.effect_state,...e.head_commit?{headCommit:e.head_commit}:{},...e.pull_request_url?{url:e.pull_request_url}:{}}}:{},n={requestId:e.request_id,publisher:{source:e.identity_source===`personal`||e.identity_source===`agent-override`||e.identity_source===`system-configured`?e.identity_source:`system-detected`,accountId:e.identity_account_id,login:e.identity_login},...t};return e.status===`published`&&e.pull_request_url&&e.repository&&e.branch?{...n,status:`published`,url:e.pull_request_url,repository:e.repository,branch:e.branch,headCommit:e.head_commit??`unknown`}:e.status===`failed`&&e.error_code&&e.next_action?{...n,status:`failed`,code:publicationFailureCode(e.error_code),message:`GitHub publication failed.`,nextAction:e.next_action}:e.status===`needs_confirmation`?{...n,status:`needs_confirmation`,message:`Confirm the original My GitHub account, target, and workspace to continue this interrupted publication. Already-dispatched GitHub effects may have completed; confirmation checks them before retrying.`}:{...n,status:e.status===`publishing`?`publishing`:`requested`,message:e.status===`publishing`?`The Gateway is publishing the reconciled workspace.`:e.identity_source===`personal`?`My GitHub publication was accepted for the selected account and workspace.`:`Publication was accepted. Finish the turn so the Gateway can reconcile and publish the workspace.`}}export{checkSharedWorktreeReceipt as n,projectGitHubPublicationResult as r,assertReadableSharedGitHubPublication as t};