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

Function createPolicy

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

Source from the content-addressed store, hash-verified

411 requireToolkit(toolkitId).pipe(Effect.flatMap(() => listPoliciesForRecord(toolkitId)));
412
413 const createPolicy = (
414 toolkitId: string,
415 input: {
416 readonly pattern: string;
417 readonly action: ToolPolicyAction;
418 readonly position?: string;
419 },
420 ) =>
421 Effect.gen(function* () {
422 yield* validatePolicyPattern(input.pattern);
423 const toolkit = yield* requireToolkit(toolkitId);
424 const existing = yield* listPoliciesForRecord(toolkitId);
425 const minPosition = existing
426 .map((row) => row.position)
427 .sort()
428 .at(0);
429 const now = Date.now();
430 const id = newId("tkpol");
431 const entry = yield* storage.policies.put({
432 owner: toolkit.owner,
433 key: id,
434 data: {
435 id,
436 toolkitId,
437 pattern: input.pattern,
438 action: input.action,
439 position: input.position ?? generateKeyBetween(null, minPosition ?? null),
440 createdAt: now,
441 updatedAt: now,
442 },
443 });
444 return policyToResponse(entry.data);
445 });
446
447 const updatePolicy = (
448 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