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

Function createPolicy

packages/plugins/toolkits/src/server.ts:367–399  ·  view source on GitHub ↗
(
    toolkitId: string,
    input: {
      readonly pattern: string;
      readonly action: ToolPolicyAction;
      readonly position?: string;
    },
  )

Source from the content-addressed store, hash-verified

365 requireToolkit(toolkitId).pipe(Effect.flatMap(() => listPoliciesForRecord(toolkitId)));
366
367 const createPolicy = (
368 toolkitId: string,
369 input: {
370 readonly pattern: string;
371 readonly action: ToolPolicyAction;
372 readonly position?: string;
373 },
374 ) =>
375 Effect.gen(function* () {
376 yield* validatePolicyPattern(input.pattern);
377 const toolkit = yield* requireToolkit(toolkitId);
378 const existing = yield* listPoliciesForRecord(toolkitId);
379 const minPosition = existing
380 .map((row) => row.position)
381 .sort()
382 .at(0);
383 const now = Date.now();
384 const id = newId("tkpol");
385 const entry = yield* storage.policies.put({
386 owner: toolkit.owner,
387 key: id,
388 data: {
389 id,
390 toolkitId,
391 pattern: input.pattern,
392 action: input.action,
393 position: input.position ?? generateKeyBetween(null, minPosition ?? null),
394 createdAt: now,
395 updatedAt: now,
396 },
397 });
398 return policyToResponse(entry.data);
399 });
400
401 const updatePolicy = (
402 toolkitId: string,

Callers

nothing calls this directly

Calls 6

validatePolicyPatternFunction · 0.85
requireToolkitFunction · 0.85
listPoliciesForRecordFunction · 0.85
newIdFunction · 0.85
policyToResponseFunction · 0.70
putMethod · 0.65

Tested by

no test coverage detected