UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

193 lines (192 loc) 8.91 kB
import "./src-vebZIeLe.js"; import { t as stableStringify } from "./stable-stringify-C8X7niaI.js"; import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { l as readToolAllowlistIntersection, r as attachToolAllowlistIntersection } from "./tool-policy-shared-DIyS0iQC.js"; import "./tool-policy-Wi0C45cX.js"; import { t as cloneConfigWithResolutionFacts } from "./resolution-facts-Dks1tbik.js"; import { t as normalizeChatType } from "./chat-type-CG0X_HJM.js"; import { r as resolveGroupSessionKey } from "./group-DlTf9maP.js"; import { n as resolveSandboxRuntimeStatus } from "./runtime-status-6c8Jb1Kg.js"; import { t as resolveConversationCapabilityProfile } from "./conversation-capability-profile-B6PkMXFD.js"; import { t as resolveOriginMessageProvider } from "./origin-routing-CgwQQ0I7.js"; import { createHash } from "node:crypto"; //#region src/auto-reply/reply/reply-tool-authority.ts /** Projects current inbound facts against the active run's frozen authority snapshot. */ function resolveInboundReplyToolAuthorityOverlay(params) { const { ctx } = params; return { permissionMode: params.sessionEntry?.permissionMode, toolOverrides: params.sessionEntry?.toolOverrides, originatingChannel: ctx.OriginatingChannel, messageProvider: resolveOriginMessageProvider({ originatingChannel: ctx.OriginatingChannel, provider: ctx.Provider ?? ctx.Surface }), chatType: normalizeChatType(ctx.ChatType), agentAccountId: ctx.AccountId, conversationToolPolicy: ctx.ConversationToolPolicy, groupId: resolveGroupSessionKey(ctx)?.id, groupChannel: normalizeOptionalString(ctx.GroupChannel) ?? normalizeOptionalString(ctx.GroupSubject), groupSpace: normalizeOptionalString(ctx.GroupSpace), memberRoleIds: Array.isArray(ctx.MemberRoleIds) ? ctx.MemberRoleIds.map((roleId) => normalizeOptionalString(roleId)).filter((roleId) => Boolean(roleId)) : void 0, spawnedBy: normalizeOptionalString(params.sessionEntry?.spawnedBy), senderId: normalizeOptionalString(ctx.SenderId), senderName: normalizeOptionalString(ctx.SenderName), senderUsername: normalizeOptionalString(ctx.SenderUsername), senderE164: normalizeOptionalString(ctx.SenderE164), senderIsOwner: params.senderIsOwner, inputProvenance: ctx.InputProvenance, trustedInternalHandoff: void 0, scheduledToolPolicy: void 0, runtimePluginToolGrant: void 0, toolsAllow: params.toolsAllow, disableTools: params.disableTools, traceAuthorized: params.senderIsOwner || (ctx.GatewayClientScopes ?? []).includes("operator.admin"), approvalReviewerDeviceId: normalizeOptionalString(ctx.ApprovalReviewerDeviceId), clientCaps: ctx.GatewayClientCaps, toolBindings: ctx.GatewayRunToolBindings }; } function snapshotFollowupRunToolAuthority(run) { const toolsAllow = run.toolsAllow ? [...run.toolsAllow] : void 0; const intersection = run.toolsAllow ? readToolAllowlistIntersection(run.toolsAllow)?.map((restriction) => restriction.slice()) : void 0; if (toolsAllow && intersection) attachToolAllowlistIntersection(toolsAllow, intersection); return { originatingChannel: run.originatingChannel, toolsAllow, disableTools: run.disableTools === true, run: { ...run.run, config: run.run.config ? cloneConfigWithResolutionFacts(run.run.config) : void 0, conversationToolPolicy: structuredClone(run.run.conversationToolPolicy), inputProvenance: structuredClone(run.run.inputProvenance), scheduledToolPolicy: structuredClone(run.run.scheduledToolPolicy), runtimePluginToolGrant: structuredClone(run.run.runtimePluginToolGrant), trustedInternalHandoff: structuredClone(run.run.trustedInternalHandoff), toolOverrides: structuredClone(run.run.toolOverrides), execOverrides: structuredClone(run.run.execOverrides), bashElevated: structuredClone(run.run.bashElevated), toolBindings: structuredClone(run.run.toolBindings), clientCaps: run.run.clientCaps ? [...run.run.clientCaps] : void 0, memberRoleIds: run.run.memberRoleIds ? [...run.run.memberRoleIds] : void 0 } }; } function applyReplyToolAuthorityOverlay(snapshot, overlay) { return { ...snapshot, originatingChannel: overlay.originatingChannel, toolsAllow: overlay.toolsAllow, disableTools: overlay.disableTools, run: { ...snapshot.run, permissionMode: overlay.permissionMode, toolOverrides: overlay.toolOverrides, messageProvider: overlay.messageProvider, chatType: overlay.chatType, agentAccountId: overlay.agentAccountId, conversationToolPolicy: overlay.conversationToolPolicy, groupId: overlay.groupId, groupChannel: overlay.groupChannel, groupSpace: overlay.groupSpace, memberRoleIds: overlay.memberRoleIds, spawnedBy: overlay.spawnedBy, senderId: overlay.senderId, senderName: overlay.senderName, senderUsername: overlay.senderUsername, senderE164: overlay.senderE164, senderIsOwner: overlay.senderIsOwner, inputProvenance: overlay.inputProvenance, trustedInternalHandoff: overlay.trustedInternalHandoff, scheduledToolPolicy: overlay.scheduledToolPolicy, runtimePluginToolGrant: overlay.runtimePluginToolGrant, traceAuthorized: overlay.traceAuthorized, approvalReviewerDeviceId: overlay.approvalReviewerDeviceId, clientCaps: overlay.clientCaps, toolBindings: overlay.toolBindings } }; } function resolveReplyToolAuthorityInputFingerprint(snapshot, route) { const execution = snapshot.run; const provider = route?.provider ?? execution.provider; const model = route?.model ?? execution.model; const policySessionKey = execution.runtimePolicySessionKey ?? execution.sessionKey; const sandboxRuntime = resolveSandboxRuntimeStatus({ cfg: execution.config, agentId: execution.agentId, sessionKey: execution.sessionKey, classificationSessionKey: policySessionKey }); const capabilityProfile = resolveConversationCapabilityProfile({ config: execution.config, sessionId: execution.sessionId, sessionKey: execution.sessionKey, sandboxSessionKey: policySessionKey, agentId: execution.agentId, agentDir: execution.agentDir, agentAccountId: execution.agentAccountId, modelProvider: provider, modelId: model, messageProvider: execution.messageProvider, messageChannel: snapshot.originatingChannel, chatType: execution.chatType, conversationToolPolicy: execution.conversationToolPolicy, groupId: execution.groupId, groupChannel: execution.groupChannel, groupSpace: execution.groupSpace, memberRoleIds: execution.memberRoleIds, spawnedBy: execution.spawnedBy, senderId: execution.senderId, senderName: execution.senderName, senderUsername: execution.senderUsername, senderE164: execution.senderE164, senderIsOwner: execution.senderIsOwner, workspaceDir: execution.workspaceDir, cwd: execution.cwd, sandboxToolPolicy: sandboxRuntime.sandboxed ? sandboxRuntime.toolPolicy : void 0, inputProvenance: execution.inputProvenance, trustedInternalHandoff: execution.trustedInternalHandoff, scheduledToolPolicy: execution.scheduledToolPolicy, runtimePluginToolGrant: execution.runtimePluginToolGrant }); return createHash("sha256").update(stableStringify({ provider, model, policy: capabilityProfile.policy, toolsAllow: snapshot.toolsAllow, toolsAllowIntersection: snapshot.toolsAllow ? readToolAllowlistIntersection(snapshot.toolsAllow) : void 0, disableTools: snapshot.disableTools === true, sessionFile: execution.sessionFile, agentDir: execution.agentDir, workspaceDir: execution.workspaceDir, cwd: execution.cwd, permissionMode: execution.permissionMode, toolOverrides: execution.toolOverrides, execOverrides: execution.execOverrides, elevatedLevel: execution.elevatedLevel, bashElevated: execution.bashElevated, traceAuthorized: execution.traceAuthorized === true, approvalReviewerDeviceId: execution.approvalReviewerDeviceId, authProfileId: execution.authProfileId, clientCaps: [...new Set(execution.clientCaps ?? [])].toSorted(), toolBindings: execution.toolBindings })).digest("hex"); } /** Fingerprints the complete model-facing tool authority owned by one queued turn. */ function resolveFollowupRunToolAuthorityFingerprint(run, route) { return resolveReplyToolAuthorityInputFingerprint(snapshotFollowupRunToolAuthority(run), route); } /** Capture execution policy once; incoming overlays replace only caller-owned facts. */ function prepareReplyToolAuthority(run, narrow) { const snapshot = snapshotFollowupRunToolAuthority(run); return { fingerprint: (route) => resolveReplyToolAuthorityInputFingerprint(snapshot, route), project: (overlay, route) => { const incoming = applyReplyToolAuthorityOverlay(snapshot, overlay); return resolveReplyToolAuthorityInputFingerprint(narrow ? narrow(incoming) : incoming, route); } }; } //#endregion export { resolveFollowupRunToolAuthorityFingerprint as n, resolveInboundReplyToolAuthorityOverlay as r, prepareReplyToolAuthority as t };