TypeScript SDK — Policy Evaluation
Evaluate actions and enforce policies with @korclaw/sdk.
typescript
import {
KorClaw,
PolicyBlockedError,
PolicyApprovalRequiredError,
} from "@korclaw/sdk";
const result = await korclaw.policies.evaluate({
input: {
action: "deploy",
resource: "production",
agent: "ops-bot",
environment: "production",
},
approval_id: "optional-uuid",
agentKey: process.env.KORCLAW_AGENT_KEY,
});
if (!result.allowed) {
if (result.result === "approval_required") {
// Handle approval flow
}
}policies.enforce()
typescript
// Enforce with runtime execution
const exec = await korclaw.policies.enforce({
input: { action: "api_call", agent: "ops-bot", resource: url },
execution: { mode: "http_proxy", method: "GET", url },
});
// Enforce with custom callback
const data = await korclaw.policies.enforce(
{ input: { action: "read", agent: "bot", resource: "file.txt" } },
async () => readFile("file.txt"),
);
// Throws PolicyBlockedError (403) or PolicyApprovalRequiredError (403)