openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.38 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{n as isArtifactPreservingStateRead}from"./artifact-preserving-state-reads-CWuQPqxe.mjs";import{t as INTERNAL_MESSAGE_CHANNEL}from"./message-channel-constants-BbP_hczw.mjs";import{s as isOperatorUiClient}from"./message-channel-514k57tV.mjs";import{i as ErrorCodes}from"./missing-scope-error-CkgBgh6d.mjs";import{p as errorShape}from"./error-codes-CQNGhXT-.mjs";import{f as resolveGatewayOperatorRoleActor}from"./operator-role-policy-g-dxw0h4.mjs";import{d as withCommandSenderAuthority,u as getCommandSenderAuthority}from"./command-auth-CCzMsjar.mjs";import{t as ConnectErrorDetailCodes}from"./connect-error-details-CJ6aH8Ny.mjs";import{n as gitHubPublicApi}from"./github-public-api-oVU11ON0.mjs";import{i as isSyntheticGatewayCaller}from"./gateway-personal-caller-BTiNMUbk.mjs";
//!src/gateway/server-methods/gateway-client-identity.ts
function isGatewayClientProfilePending(e){return Boolean(e?.authenticatedGitHubIdentitySync&&!e.authenticatedUserProfile)}function authenticatedProfileUnavailableError(e){const t=e instanceof Error&&e.name===`ControlUiGitHubError`&&e instanceof gitHubPublicApi.ControlUiGitHubError&&e.statusCode===429;return errorShape(ErrorCodes.UNAVAILABLE,t?`GitHub is rate limiting profile verification. Retry shortly; if this continues, ask a gateway administrator to check the GitHub API credential.`:`Authenticated profile verification is unavailable. Retry shortly; if this continues, contact a gateway administrator.`,{retryable:true,retryAfterMs:t&&e.retryAfterMs||1e3,details:{code:ConnectErrorDetailCodes.AUTHENTICATED_PROFILE_UNAVAILABLE}})}async function authorizeAuthenticatedProfileForMethod(e){const t=e.sessionScope!==void 0;const sessionProfileError=()=>{const n=resolveGatewayOperatorRoleActor(e.client);return t&&(n?.kind!==`operator`||!n.profileId.trim())?errorShape(ErrorCodes.FORBIDDEN,`Session-scoped access requires a verified user profile.`):null};const n=e.client?.authenticatedGitHubIdentitySync;if(!n||e.client?.authenticatedUserProfile?.profileId.trim())return sessionProfileError();if(!t&&!e.requiresProfile())return null;if(isArtifactPreservingStateRead())return authenticatedProfileUnavailableError();try{await n()}catch(e){return authenticatedProfileUnavailableError(e)}return e.client?.authenticatedUserProfile?.profileId.trim()?sessionProfileError():authenticatedProfileUnavailableError()}function gatewayClientSenderFields(e){if(e?.internal?.senderAttribution)return{sender:e.internal.senderAttribution};const t=e?.authenticatedUserProfile;if(t)return{sender:{id:t.profileId,...!e?.internal?.syntheticClient?{identity:{type:`profile`,id:t.profileId}}:{},...t.displayName?{name:t.displayName}:{}}};return!e?.authenticatedGitHubIdentitySync&&e?.authenticatedUserId?{sender:{id:e.authenticatedUserId}}:{}}function gatewayClientSessionCreator(e){const t=e?.authenticatedUserProfile;return t?{type:`human`,id:t.profileId,...t.displayName?{label:t.displayName}:{}}:void 0}function resolveChatSendCallerContext(e,t=e?.connect?.client,n=INTERNAL_MESSAGE_CHANNEL){const r=isSyntheticGatewayCaller(e??null);const i=r?void 0:getCommandSenderAuthority(e)??(()=>{if(!e||e.invalidated||e.connectionSignal?.aborted||isSyntheticGatewayCaller(e))return;const t=e.internal?.remoteIngressPrincipal;if(t){try{t.signal.throwIfAborted();t.assertCurrent()}catch{return}return t.operatorRoleActor.kind===`operator`&&e.internal?.operatorRoleActor?.kind===`operator`&&t.operatorRoleActor.profileId===e.internal.operatorRoleActor.profileId&&t.operatorRoleActor.profileId===e.authenticatedUserProfile?.profileId?t.operatorRoleActor.profileId:void 0}return e.authenticatedUserId?e.authenticatedUserProfile?.profileId:void 0});return withCommandSenderAuthority({Provider:INTERNAL_MESSAGE_CHANNEL,Surface:INTERNAL_MESSAGE_CHANNEL,OriginatingChannel:n,ChatType:`direct`,ApprovalReviewerDeviceId:normalizeOptionalString(e?.connect?.device?.id),...!r&&!isOperatorUiClient(t)?{SenderId:t?.id,SenderName:t?.displayName,SenderUsername:t?.displayName}:{},GatewayClientScopes:e?.connect?.scopes??[],GatewayClientCaps:r?void 0:e?.connect?.caps??[]},i)}export{isGatewayClientProfilePending as a,gatewayClientSessionCreator as i,authorizeAuthenticatedProfileForMethod as n,resolveChatSendCallerContext as o,gatewayClientSenderFields as r,authenticatedProfileUnavailableError as t};