MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / effectivePolicyFromSorted

Function effectivePolicyFromSorted

packages/core/sdk/src/policies.ts:257–281  ·  view source on GitHub ↗
(
  toolId: string,
  sortedPolicies: readonly (Pick<ToolPolicy, "pattern" | "action" | "id"> &
    Partial<Pick<ToolPolicy, "owner">>)[],
  defaultRequiresApproval?: boolean,
)

Source from the content-addressed store, hash-verified

255};
256
257export const effectivePolicyFromSorted = (
258 toolId: string,
259 sortedPolicies: readonly (Pick<ToolPolicy, "pattern" | "action" | "id"> &
260 Partial<Pick<ToolPolicy, "owner">>)[],
261 defaultRequiresApproval?: boolean,
262): EffectivePolicy => {
263 const firstMatchByOwner = new Map<string, EffectivePolicy>();
264 for (const p of sortedPolicies) {
265 const ownerKey = "owner" in p && p.owner ? String(p.owner) : "__flat__";
266 if (firstMatchByOwner.has(ownerKey)) continue;
267 if (matchPattern(p.pattern, toolId)) {
268 firstMatchByOwner.set(ownerKey, {
269 action: p.action,
270 source: "user",
271 pattern: p.pattern,
272 policyId: p.id,
273 });
274 }
275 }
276 let selected: EffectivePolicy | undefined;
277 for (const match of firstMatchByOwner.values()) {
278 selected = moreRestrictive(selected, match);
279 }
280 return selected ?? liftPlugin(defaultRequiresApproval);
281};
282
283// ---------------------------------------------------------------------------
284// Row → public projection.

Callers 3

policies.test.tsFile · 0.90
IntegrationDetailPageFunction · 0.85
ToolsPageFunction · 0.85

Calls 5

moreRestrictiveFunction · 0.85
liftPluginFunction · 0.85
setMethod · 0.80
valuesMethod · 0.80
matchPatternFunction · 0.70

Tested by

no test coverage detected