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

Function policiesCreate

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

Source from the content-addressed store, hash-verified

5376 );
5377
5378 const policiesCreate = (
5379 input: CreateToolPolicyInput,
5380 ): Effect.Effect<ToolPolicy, StorageFailure> =>
5381 Effect.gen(function* () {
5382 if (!isValidPattern(input.pattern)) {
5383 return yield* new StorageError({
5384 message: `Invalid tool policy pattern: ${input.pattern}`,
5385 cause: undefined,
5386 });
5387 }
5388 if (!isToolPolicyAction(input.action)) {
5389 return yield* new StorageError({
5390 message: `Invalid tool policy action: ${String(input.action)}`,
5391 cause: undefined,
5392 });
5393 }
5394 yield* requireUserSubject(input.owner);
5395 const keys = yield* Effect.try({
5396 try: () => ownedKeys(input.owner),
5397 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
5398 });
5399 const existing = yield* core.findMany("tool_policy", {
5400 where: byOwner(input.owner),
5401 });
5402 // Default placement is specificity-aware (below any more-specific
5403 // rule), not top-of-list: a client that omits position — the UI when
5404 // its policy list is stale, the API, an agent tool — must not have its
5405 // broad rule silently shadow an existing narrow one.
5406 const position = input.position ?? positionForNewPattern(input.pattern, existing);
5407 const id = PolicyId.make(
5408 `pol_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
5409 );
5410 const now = new Date();
5411 const created = yield* core.create("tool_policy", {
5412 tenant: keys.tenant,
5413 owner: keys.owner,
5414 subject: keys.subject,
5415 id: String(id),
5416 pattern: input.pattern,
5417 action: input.action,
5418 position,
5419 created_at: now,
5420 updated_at: now,
5421 });
5422 return rowToToolPolicy(created);
5423 });
5424
5425 const policiesUpdate = (
5426 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