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

Function policiesCreate

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

Source from the content-addressed store, hash-verified

4368 );
4369
4370 const policiesCreate = (
4371 input: CreateToolPolicyInput,
4372 ): Effect.Effect<ToolPolicy, StorageFailure> =>
4373 Effect.gen(function* () {
4374 if (!isValidPattern(input.pattern)) {
4375 return yield* new StorageError({
4376 message: `Invalid tool policy pattern: ${input.pattern}`,
4377 cause: undefined,
4378 });
4379 }
4380 if (!isToolPolicyAction(input.action)) {
4381 return yield* new StorageError({
4382 message: `Invalid tool policy action: ${String(input.action)}`,
4383 cause: undefined,
4384 });
4385 }
4386 yield* requireUserSubject(input.owner);
4387 const keys = yield* Effect.try({
4388 try: () => ownedKeys(input.owner),
4389 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
4390 });
4391 const existing = yield* core.findMany("tool_policy", {
4392 where: byOwner(input.owner),
4393 });
4394 // Default placement is specificity-aware (below any more-specific
4395 // rule), not top-of-list: a client that omits position — the UI when
4396 // its policy list is stale, the API, an agent tool — must not have its
4397 // broad rule silently shadow an existing narrow one.
4398 const position = input.position ?? positionForNewPattern(input.pattern, existing);
4399 const id = PolicyId.make(
4400 `pol_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
4401 );
4402 const now = new Date();
4403 const created = yield* core.create("tool_policy", {
4404 tenant: keys.tenant,
4405 owner: keys.owner,
4406 subject: keys.subject,
4407 id: String(id),
4408 pattern: input.pattern,
4409 action: input.action,
4410 position,
4411 created_at: now,
4412 updated_at: now,
4413 });
4414 return rowToToolPolicy(created);
4415 });
4416
4417 const policiesUpdate = (
4418 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