UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.75 kB
import{o as redactSensitiveUrlLikeString}from"./redact-sensitive-url-Byg68d6v.mjs";import{t as PLUGIN_MANIFEST_CONTRACT_KEYS}from"./manifest-contract-keys-BTtgVkx2.mjs";import{n as PLUGIN_DECLARED_SURFACE_GROUPS}from"./plugin-declared-surface-groups-DvoqL-Pm.mjs";import{n as resolvePromptInjectionAllowed,t as resolveConversationAccessAllowed}from"./hook-policy-decisions-DtkkRrTZ.mjs";import{createHash}from"node:crypto"; //!src/plugins/capability-summary.ts function diffDeclaredSurfaceWidening(e,t){const n={};for(const r of PLUGIN_DECLARED_SURFACE_GROUPS){const i=new Set(e[r]);const a=t[r].filter(e=>!i.has(e)).toSorted();if(a.length>0)n[r]=a}return{widened:n,hasWidening:Object.keys(n).length>0}}function mergePluginDeclaredSurfaces(e){const t={channels:[],providers:[],tools:[],contracts:[],hooks:[],mcpServers:[],cliCommands:[],cliBackends:[],skills:[],dangerousConfigFlags:[]};for(const n of e)for(const e of PLUGIN_DECLARED_SURFACE_GROUPS)t[e].push(...n[e]);for(const e of PLUGIN_DECLARED_SURFACE_GROUPS)t[e]=[...new Set(t[e])].toSorted();return t}function resolvePluginPackageDeclaredSurface(e,t){const n=[];for(const r of e.pluginIds){const e=t.get(r);if(!e)return;n.push(buildPluginCapabilitySummary({manifest:e,origin:e.origin}).declared)}return mergePluginDeclaredSurfaces(n)}function computeDeclaredSurfaceHash(e){const t=Object.fromEntries(PLUGIN_DECLARED_SURFACE_GROUPS.map(t=>[t,e[t].toSorted()]));return createHash(`sha256`).update(JSON.stringify(t)).digest(`hex`)}function resolvePluginInstallRecordIntegrity(e){const t=e.integrity??e.npmIntegrity;if(t)return{integrity:t,integrityKind:`ssri`};if(e.clawpackSha256)return{integrity:e.clawpackSha256,integrityKind:`sha256`};return e.gitCommit?{integrity:e.gitCommit,integrityKind:`git-commit`}:void 0}function resolveAcceptedSurfaceCurrent(e,t){return e.acceptedSurface!==void 0&&e.acceptedSurfaceHash!==void 0&&e.acceptedSurfaceHash===computeDeclaredSurfaceHash(e.acceptedSurface)&&e.acceptedSurfaceHash===computeDeclaredSurfaceHash(t)&&e.acceptedSurfaceIntegrity===resolvePluginInstallRecordIntegrity(e)?.integrity}function formatPluginCapabilityConsentRequired(e){return`Plugin "${e}" requires capability consent; disable and re-enable it or run \`openclaw plugins enable ${e} --accept-capabilities\`.`}function buildHookGrant(e,t){return{effective:e,...typeof t===`boolean`?{configured:t}:{}}}function buildPluginCapabilitySummary(e){const{manifest:t,entryConfig:n}=e;const r=n?.hooks;const i=n?.llm;const a=n?.subagent;return{declared:{channels:(t.channels??(t.channel?.id?[t.channel.id]:[])).toSorted(),providers:(t.providers??[]).flatMap(e=>typeof e===`string`?[e]:e.id?[e.id]:[]).toSorted(),tools:[.../* @__PURE__ */ new Set([...t.contracts?.tools??[],...Object.keys(t.toolMetadata??{})])].toSorted(),contracts:[...new Set(PLUGIN_MANIFEST_CONTRACT_KEYS.flatMap(e=>(t.contracts?.[e]??[]).map(t=>`${e}: ${t}`)))].toSorted(),hooks:(t.hooks??[]).toSorted(),mcpServers:Object.keys(t.mcpServers??{}).toSorted(),cliCommands:(t.cliCommands??[]).map(e=>e.name).toSorted(),cliBackends:(t.cliBackends??[]).toSorted(),skills:(t.skills??[]).toSorted(),dangerousConfigFlags:(t.configContracts?.dangerousFlags??[]).map(e=>e.path).toSorted()},grants:{hooks:{allowPromptInjection:buildHookGrant(resolvePromptInjectionAllowed(r),r?.allowPromptModification),allowConversationAccess:buildHookGrant(resolveConversationAccessAllowed(e.origin,r),r?.allowConversationAccess)},...i?{llm:{...i.allowModelOverride!==void 0?{allowModelOverride:i.allowModelOverride}:{},...i.allowedModels?{allowedModels:i.allowedModels.toSorted()}:{},...i.allowedCompletionModels?{allowedCompletionModels:i.allowedCompletionModels.toSorted()}:{},...i.allowAuthProfileOverride!==void 0?{allowAuthProfileOverride:i.allowAuthProfileOverride}:{},...i.allowAgentIdOverride!==void 0?{allowAgentIdOverride:i.allowAgentIdOverride}:{}}}:{},...a?{subagent:{...a.allowModelOverride!==void 0?{allowModelOverride:a.allowModelOverride}:{},...a.allowedModels?{allowedModels:a.allowedModels.toSorted()}:{}}}:{}}}}function resolvePluginInstallRecordTrust(e){if(!e?.clawhubTrustDisposition)return;return{disposition:e.clawhubTrustDisposition,...e.clawhubTrustReasons?{reasons:[...e.clawhubTrustReasons]}:{},...e.clawhubTrustCheckedAt?{checkedAt:e.clawhubTrustCheckedAt}:{},...e.clawhubTrustAcknowledgedAt?{acknowledgedAt:e.clawhubTrustAcknowledgedAt}:{},...e.clawhubTrustPending!==void 0?{pending:e.clawhubTrustPending}:{},...e.clawhubTrustStale!==void 0?{stale:e.clawhubTrustStale}:{}}}function buildPluginCapabilityConsentReview(e){const{pluginId:t,manifest:n,record:r}=e;const i=buildPluginCapabilitySummary({manifest:n,origin:`global`,entryConfig:e.config.plugins?.entries?.[t]});const a=e.declared??i.declared;const o=r.resolvedSpec??r.spec;const s=r.clawhubPackage??r.resolvedName;const c=e.previousDeclared??r.acceptedSurface;const l=e.widened??(c?diffDeclaredSurfaceWidening(c,a).widened:void 0);const u=resolvePluginInstallRecordTrust(r);return{pluginId:t,name:n.name??t,...n.version??r.version?{version:n.version??r.version}:{},...i,declared:a,reviewToken:computeDeclaredSurfaceHash(a),source:{kind:r.source,...o?{spec:redactSensitiveUrlLikeString(o)}:{},...s?{packageName:s}:{},...resolvePluginInstallRecordIntegrity(r)},...u?{trust:u}:{},...l&&Object.keys(l).length>0?{widened:l}:{},...r.acceptedSurfaceAt?{acceptedAt:r.acceptedSurfaceAt}:{}}}export{formatPluginCapabilityConsentRequired as a,resolvePluginInstallRecordIntegrity as c,diffDeclaredSurfaceWidening as i,resolvePluginInstallRecordTrust as l,buildPluginCapabilitySummary as n,mergePluginDeclaredSurfaces as o,computeDeclaredSurfaceHash as r,resolveAcceptedSurfaceCurrent as s,buildPluginCapabilityConsentReview as t,resolvePluginPackageDeclaredSurface as u};