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

Function policiesCreate

packages/core/sdk/src/executor.ts:3497–3542  ·  view source on GitHub ↗
(
      input: CreateToolPolicyInput,
    )

Source from the content-addressed store, hash-verified

3495 );
3496
3497 const policiesCreate = (
3498 input: CreateToolPolicyInput,
3499 ): Effect.Effect<ToolPolicy, StorageFailure> =>
3500 Effect.gen(function* () {
3501 if (!isValidPattern(input.pattern)) {
3502 return yield* new StorageError({
3503 message: `Invalid tool policy pattern: ${input.pattern}`,
3504 cause: undefined,
3505 });
3506 }
3507 if (!isToolPolicyAction(input.action)) {
3508 return yield* new StorageError({
3509 message: `Invalid tool policy action: ${String(input.action)}`,
3510 cause: undefined,
3511 });
3512 }
3513 yield* requireUserSubject(input.owner);
3514 const keys = yield* Effect.try({
3515 try: () => ownedKeys(input.owner),
3516 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
3517 });
3518 const existing = yield* core.findMany("tool_policy", {
3519 where: byOwner(input.owner),
3520 });
3521 // Default placement is specificity-aware (below any more-specific
3522 // rule), not top-of-list: a client that omits position — the UI when
3523 // its policy list is stale, the API, an agent tool — must not have its
3524 // broad rule silently shadow an existing narrow one.
3525 const position = input.position ?? positionForNewPattern(input.pattern, existing);
3526 const id = PolicyId.make(
3527 `pol_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
3528 );
3529 const now = new Date();
3530 const created = yield* core.create("tool_policy", {
3531 tenant: keys.tenant,
3532 owner: keys.owner,
3533 subject: keys.subject,
3534 id: String(id),
3535 pattern: input.pattern,
3536 action: input.action,
3537 position,
3538 created_at: now,
3539 updated_at: now,
3540 });
3541 return rowToToolPolicy(created);
3542 });
3543
3544 const policiesUpdate = (
3545 input: UpdateToolPolicyInput,

Callers 1

createExecutorFunction · 0.85

Calls 9

isValidPatternFunction · 0.90
isToolPolicyActionFunction · 0.90
positionForNewPatternFunction · 0.90
rowToToolPolicyFunction · 0.90
requireUserSubjectFunction · 0.85
ownedKeysFunction · 0.85
byOwnerFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected