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

Function policiesCreate

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

Source from the content-addressed store, hash-verified

3412 );
3413
3414 const policiesCreate = (
3415 input: CreateToolPolicyInput,
3416 ): Effect.Effect<ToolPolicy, StorageFailure> =>
3417 Effect.gen(function* () {
3418 if (!isValidPattern(input.pattern)) {
3419 return yield* new StorageError({
3420 message: `Invalid tool policy pattern: ${input.pattern}`,
3421 cause: undefined,
3422 });
3423 }
3424 if (!isToolPolicyAction(input.action)) {
3425 return yield* new StorageError({
3426 message: `Invalid tool policy action: ${String(input.action)}`,
3427 cause: undefined,
3428 });
3429 }
3430 yield* requireUserSubject(input.owner);
3431 const keys = yield* Effect.try({
3432 try: () => ownedKeys(input.owner),
3433 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
3434 });
3435 const existing = yield* core.findMany("tool_policy", {
3436 where: byOwner(input.owner),
3437 });
3438 // Default placement is specificity-aware (below any more-specific
3439 // rule), not top-of-list: a client that omits position — the UI when
3440 // its policy list is stale, the API, an agent tool — must not have its
3441 // broad rule silently shadow an existing narrow one.
3442 const position = input.position ?? positionForNewPattern(input.pattern, existing);
3443 const id = PolicyId.make(
3444 `pol_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
3445 );
3446 const now = new Date();
3447 const created = yield* core.create("tool_policy", {
3448 tenant: keys.tenant,
3449 owner: keys.owner,
3450 subject: keys.subject,
3451 id: String(id),
3452 pattern: input.pattern,
3453 action: input.action,
3454 position,
3455 created_at: now,
3456 updated_at: now,
3457 });
3458 return rowToToolPolicy(created);
3459 });
3460
3461 const policiesUpdate = (
3462 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