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

Function policiesCreate

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

Source from the content-addressed store, hash-verified

3938 );
3939
3940 const policiesCreate = (
3941 input: CreateToolPolicyInput,
3942 ): Effect.Effect<ToolPolicy, StorageFailure> =>
3943 Effect.gen(function* () {
3944 if (!isValidPattern(input.pattern)) {
3945 return yield* new StorageError({
3946 message: `Invalid tool policy pattern: ${input.pattern}`,
3947 cause: undefined,
3948 });
3949 }
3950 if (!isToolPolicyAction(input.action)) {
3951 return yield* new StorageError({
3952 message: `Invalid tool policy action: ${String(input.action)}`,
3953 cause: undefined,
3954 });
3955 }
3956 yield* requireUserSubject(input.owner);
3957 const keys = yield* Effect.try({
3958 try: () => ownedKeys(input.owner),
3959 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
3960 });
3961 const existing = yield* core.findMany("tool_policy", {
3962 where: byOwner(input.owner),
3963 });
3964 // Default placement is specificity-aware (below any more-specific
3965 // rule), not top-of-list: a client that omits position — the UI when
3966 // its policy list is stale, the API, an agent tool — must not have its
3967 // broad rule silently shadow an existing narrow one.
3968 const position = input.position ?? positionForNewPattern(input.pattern, existing);
3969 const id = PolicyId.make(
3970 `pol_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`,
3971 );
3972 const now = new Date();
3973 const created = yield* core.create("tool_policy", {
3974 tenant: keys.tenant,
3975 owner: keys.owner,
3976 subject: keys.subject,
3977 id: String(id),
3978 pattern: input.pattern,
3979 action: input.action,
3980 position,
3981 created_at: now,
3982 updated_at: now,
3983 });
3984 return rowToToolPolicy(created);
3985 });
3986
3987 const policiesUpdate = (
3988 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