@agentpolicyspecification/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +187 -0
- package/README.md +13 -0
- package/coverage/clover.xml +458 -0
- package/coverage/coverage-final.json +7 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +146 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/core/errors.ts.html +217 -0
- package/coverage/lcov-report/src/core/index.html +146 -0
- package/coverage/lcov-report/src/core/policy.ts.html +142 -0
- package/coverage/lcov-report/src/core/types.ts.html +364 -0
- package/coverage/lcov-report/src/engine/aps-engine.ts.html +703 -0
- package/coverage/lcov-report/src/engine/index.html +131 -0
- package/coverage/lcov-report/src/engine/policy-set.ts.html +115 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +244 -0
- package/coverage/lcov.info +558 -0
- package/dist/core/errors.d.ts +29 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +21 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/policy.d.ts +17 -0
- package/dist/core/policy.d.ts.map +1 -0
- package/dist/core/policy.js +2 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/types.d.ts +67 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +3 -0
- package/dist/core/types.js.map +1 -0
- package/dist/engine/aps-engine.d.ts +22 -0
- package/dist/engine/aps-engine.d.ts.map +1 -0
- package/dist/engine/aps-engine.js +167 -0
- package/dist/engine/aps-engine.js.map +1 -0
- package/dist/engine/policy-set.d.ts +9 -0
- package/dist/engine/policy-set.d.ts.map +1 -0
- package/dist/engine/policy-set.js +2 -0
- package/dist/engine/policy-set.js.map +1 -0
- package/dist/generated/base.d.ts +7 -0
- package/dist/generated/base.d.ts.map +1 -0
- package/dist/generated/base.js +4 -0
- package/dist/generated/base.js.map +1 -0
- package/dist/generated/dsl-policy.d.ts +130 -0
- package/dist/generated/dsl-policy.d.ts.map +1 -0
- package/dist/generated/dsl-policy.js +4 -0
- package/dist/generated/dsl-policy.js.map +1 -0
- package/dist/generated/input-context.d.ts +48 -0
- package/dist/generated/input-context.d.ts.map +1 -0
- package/dist/generated/input-context.js +4 -0
- package/dist/generated/input-context.js.map +1 -0
- package/dist/generated/output-context.d.ts +42 -0
- package/dist/generated/output-context.d.ts.map +1 -0
- package/dist/generated/output-context.js +4 -0
- package/dist/generated/output-context.js.map +1 -0
- package/dist/generated/policy-decision.d.ts +95 -0
- package/dist/generated/policy-decision.d.ts.map +1 -0
- package/dist/generated/policy-decision.js +4 -0
- package/dist/generated/policy-decision.js.map +1 -0
- package/dist/generated/policy-set.d.ts +139 -0
- package/dist/generated/policy-set.d.ts.map +1 -0
- package/dist/generated/policy-set.js +4 -0
- package/dist/generated/policy-set.js.map +1 -0
- package/dist/generated/tool-call-context.d.ts +52 -0
- package/dist/generated/tool-call-context.d.ts.map +1 -0
- package/dist/generated/tool-call-context.js +4 -0
- package/dist/generated/tool-call-context.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/examples/basic-usage.ts +89 -0
- package/jest.config.js +20 -0
- package/package.json +46 -0
- package/scripts/generate-types.mjs +24 -0
- package/src/core/errors.ts +44 -0
- package/src/core/policy.ts +19 -0
- package/src/core/types.ts +93 -0
- package/src/engine/aps-engine.ts +206 -0
- package/src/engine/policy-set.ts +10 -0
- package/src/generated/base.ts +9 -0
- package/src/generated/dsl-policy.ts +133 -0
- package/src/generated/input-context.ts +51 -0
- package/src/generated/output-context.ts +45 -0
- package/src/generated/policy-decision.ts +98 -0
- package/src/generated/policy-set.ts +142 -0
- package/src/generated/tool-call-context.ts +55 -0
- package/src/index.ts +53 -0
- package/test/aps-engine.test.ts +264 -0
- package/tsconfig.json +22 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { InputContext } from "../generated/input-context.js";
|
|
2
|
+
import type { OutputContext } from "../generated/output-context.js";
|
|
3
|
+
import type { ToolCallContext } from "../generated/tool-call-context.js";
|
|
4
|
+
import { AuditRecord } from "../core/errors.js";
|
|
5
|
+
import type { PolicySet } from "./policy-set.js";
|
|
6
|
+
export type AuditHandler = (record: AuditRecord) => void | Promise<void>;
|
|
7
|
+
export interface ApsEngineOptions {
|
|
8
|
+
policySet: PolicySet;
|
|
9
|
+
onAudit?: AuditHandler;
|
|
10
|
+
}
|
|
11
|
+
export declare class ApsEngine {
|
|
12
|
+
private readonly policySet;
|
|
13
|
+
private readonly onAudit;
|
|
14
|
+
constructor({ policySet, onAudit }: ApsEngineOptions);
|
|
15
|
+
static fromJson(absolutePath: string, options?: Pick<ApsEngineOptions, "onAudit">): Promise<ApsEngine>;
|
|
16
|
+
evaluateInput(context: InputContext): Promise<void>;
|
|
17
|
+
evaluateToolCall(context: ToolCallContext): Promise<void>;
|
|
18
|
+
evaluateOutput(context: OutputContext): Promise<void>;
|
|
19
|
+
private runPolicies;
|
|
20
|
+
private audit;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=aps-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aps-engine.d.ts","sourceRoot":"","sources":["../../src/engine/aps-engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,EAAE,WAAW,EAA+D,MAAM,mBAAmB,CAAC;AAC7G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;gBAEvC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,gBAAgB;WAKvC,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAsCtG,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAI7C,WAAW;YA+EX,KAAK;CAKpB"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { PolicyDenialError, PolicyEvaluationError } from "../core/errors.js";
|
|
3
|
+
export class ApsEngine {
|
|
4
|
+
policySet;
|
|
5
|
+
onAudit;
|
|
6
|
+
constructor({ policySet, onAudit }) {
|
|
7
|
+
this.policySet = policySet;
|
|
8
|
+
this.onAudit = onAudit;
|
|
9
|
+
}
|
|
10
|
+
static async fromJson(absolutePath, options) {
|
|
11
|
+
const raw = await readFile(absolutePath, "utf-8");
|
|
12
|
+
const jsonPolicySet = JSON.parse(raw);
|
|
13
|
+
const input = [];
|
|
14
|
+
const tool_call = [];
|
|
15
|
+
const output = [];
|
|
16
|
+
for (const [index, entry] of jsonPolicySet.policies.entries()) {
|
|
17
|
+
const id = `policy-${index}`;
|
|
18
|
+
const appliesTo = entry.applies_to;
|
|
19
|
+
const appliesToAll = !appliesTo || appliesTo.length === 0;
|
|
20
|
+
if (appliesToAll || appliesTo.includes("input")) {
|
|
21
|
+
input.push({ id, evaluate: (ctx) => evaluateEntry(entry, ctx) });
|
|
22
|
+
}
|
|
23
|
+
if (appliesToAll || appliesTo.includes("tool_call")) {
|
|
24
|
+
tool_call.push({
|
|
25
|
+
id,
|
|
26
|
+
evaluate: (ctx) => {
|
|
27
|
+
const tools = entry.tools;
|
|
28
|
+
if (tools && tools.length > 0 && !tools.includes(ctx.tool_name)) {
|
|
29
|
+
return Promise.resolve({ decision: "allow" });
|
|
30
|
+
}
|
|
31
|
+
return evaluateEntry(entry, ctx);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (appliesToAll || appliesTo.includes("output")) {
|
|
36
|
+
output.push({ id, evaluate: (ctx) => evaluateEntry(entry, ctx) });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return new ApsEngine({ policySet: { input, tool_call, output }, ...options });
|
|
40
|
+
}
|
|
41
|
+
async evaluateInput(context) {
|
|
42
|
+
await this.runPolicies(this.policySet.input ?? [], context, "input");
|
|
43
|
+
}
|
|
44
|
+
async evaluateToolCall(context) {
|
|
45
|
+
await this.runPolicies(this.policySet.tool_call ?? [], context, "tool_call");
|
|
46
|
+
}
|
|
47
|
+
async evaluateOutput(context) {
|
|
48
|
+
await this.runPolicies(this.policySet.output ?? [], context, "output");
|
|
49
|
+
}
|
|
50
|
+
async runPolicies(policies, context, interceptionPoint) {
|
|
51
|
+
for (const policy of policies) {
|
|
52
|
+
let decision;
|
|
53
|
+
try {
|
|
54
|
+
decision = await policy.evaluate(context);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.error('err: ', err);
|
|
58
|
+
if (err instanceof PolicyEvaluationError) {
|
|
59
|
+
await this.audit({
|
|
60
|
+
policy_id: policy.id,
|
|
61
|
+
decision: "evaluation_error",
|
|
62
|
+
interception_point: interceptionPoint,
|
|
63
|
+
reason: String(err.cause),
|
|
64
|
+
context,
|
|
65
|
+
timestamp: new Date().toISOString(),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if ((this.policySet.on_error ?? "deny") === "deny") {
|
|
69
|
+
throw err instanceof PolicyEvaluationError
|
|
70
|
+
? err
|
|
71
|
+
: new PolicyEvaluationError({ policy_id: policy.id, interception_point: interceptionPoint, cause: err });
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (decision.decision === "audit") {
|
|
76
|
+
await this.audit({
|
|
77
|
+
policy_id: policy.id,
|
|
78
|
+
decision: "audit",
|
|
79
|
+
interception_point: interceptionPoint,
|
|
80
|
+
reason: decision.reason,
|
|
81
|
+
context,
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (decision.decision === "deny") {
|
|
87
|
+
await this.audit({
|
|
88
|
+
policy_id: policy.id,
|
|
89
|
+
decision: "deny",
|
|
90
|
+
interception_point: interceptionPoint,
|
|
91
|
+
reason: decision.reason,
|
|
92
|
+
context,
|
|
93
|
+
timestamp: new Date().toISOString(),
|
|
94
|
+
});
|
|
95
|
+
throw new PolicyDenialError({
|
|
96
|
+
policy_id: decision.policy_id ?? policy.id,
|
|
97
|
+
interception_point: interceptionPoint,
|
|
98
|
+
reason: decision.reason ?? "Policy denied without reason",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// allow, redact, transform — log and continue
|
|
102
|
+
// (redact/transform mutation is left to the runtime adapter layer)
|
|
103
|
+
if (decision.decision !== "allow") {
|
|
104
|
+
await this.audit({
|
|
105
|
+
policy_id: policy.id,
|
|
106
|
+
decision: decision.decision,
|
|
107
|
+
interception_point: interceptionPoint,
|
|
108
|
+
reason: undefined,
|
|
109
|
+
context,
|
|
110
|
+
timestamp: new Date().toISOString(),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async audit(record) {
|
|
116
|
+
if (this.onAudit) {
|
|
117
|
+
await this.onAudit(record);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// ── fromJson helpers ──────────────────────────────────────────────────────────
|
|
122
|
+
function evaluateEntry(entry, ctx) {
|
|
123
|
+
if (!evaluateCondition(entry.condition, ctx)) {
|
|
124
|
+
return Promise.resolve({ decision: "allow" });
|
|
125
|
+
}
|
|
126
|
+
return Promise.resolve(buildDecision(entry, ctx));
|
|
127
|
+
}
|
|
128
|
+
function evaluateCondition(condition, ctx) {
|
|
129
|
+
const cond = condition;
|
|
130
|
+
if ("always" in cond)
|
|
131
|
+
return true;
|
|
132
|
+
const field = cond.field;
|
|
133
|
+
const value = resolveField(ctx, field);
|
|
134
|
+
if ("equals" in cond)
|
|
135
|
+
return value === cond.equals;
|
|
136
|
+
if ("contains" in cond)
|
|
137
|
+
return cond.contains.some(v => String(value).toLowerCase().includes(v.toLowerCase()));
|
|
138
|
+
if ("not_in" in cond)
|
|
139
|
+
return !cond.not_in.includes(value);
|
|
140
|
+
if ("greater_than" in cond)
|
|
141
|
+
return Number(value) > cond.greater_than;
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
function resolveField(obj, fieldPath) {
|
|
145
|
+
return fieldPath.split(".").reduce((acc, key) => acc?.[key], obj);
|
|
146
|
+
}
|
|
147
|
+
function buildDecision(entry, ctx) {
|
|
148
|
+
if (entry.action === "allow")
|
|
149
|
+
return { decision: "allow" };
|
|
150
|
+
if (entry.action === "deny") {
|
|
151
|
+
return {
|
|
152
|
+
decision: "deny",
|
|
153
|
+
...(entry.reason ? { reason: entry.reason } : {}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
decision: "transform",
|
|
158
|
+
transformation: {
|
|
159
|
+
operations: Object.entries(entry.transformation ?? {}).map(([field, template]) => ({
|
|
160
|
+
field,
|
|
161
|
+
op: "set",
|
|
162
|
+
value: template.replace(/\{\{(.+?)\}\}/g, (_, expr) => String(resolveField(ctx, expr.trim()) ?? "")),
|
|
163
|
+
})),
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=aps-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aps-engine.js","sourceRoot":"","sources":["../../src/engine/aps-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAO5C,OAAO,EAAkC,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAU7G,MAAM,OAAO,SAAS;IACH,SAAS,CAAY;IACrB,OAAO,CAA2B;IAEnD,YAAY,EAAE,SAAS,EAAE,OAAO,EAAoB;QAClD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAoB,EAAE,OAA2C;QACrF,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAkB,CAAC;QAEvD,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,MAAM,SAAS,GAAqB,EAAE,CAAC;QACvC,MAAM,MAAM,GAAmB,EAAE,CAAC;QAElC,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9D,MAAM,EAAE,GAAG,UAAU,KAAK,EAAE,CAAC;YAC7B,MAAM,SAAS,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AAS,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAwC;aAC5J,CAAC,CAAC;SACJ;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InputPolicy, OutputPolicy, ToolCallPolicy } from "../core/policy.js";
|
|
2
|
+
export type OnErrorBehavior = "deny" | "allow";
|
|
3
|
+
export interface PolicySet {
|
|
4
|
+
on_error?: OnErrorBehavior;
|
|
5
|
+
input?: InputPolicy[];
|
|
6
|
+
tool_call?: ToolCallPolicy[];
|
|
7
|
+
output?: OutputPolicy[];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=policy-set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-set.d.ts","sourceRoot":"","sources":["../../src/engine/policy-set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-set.js","sourceRoot":"","sources":["../../src/engine/policy-set.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/generated/base.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/generated/base.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,2EAA2E"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A condition that is evaluated against the context
|
|
3
|
+
*/
|
|
4
|
+
export type Condition = EqualsCondition | ContainsCondition | NotInCondition | GreaterThanCondition | AlwaysCondition;
|
|
5
|
+
/**
|
|
6
|
+
* A single Agent Policy Specification DSL policy rule
|
|
7
|
+
*/
|
|
8
|
+
export interface DSLPolicy {
|
|
9
|
+
condition: Condition;
|
|
10
|
+
/**
|
|
11
|
+
* The action to take when the condition matches
|
|
12
|
+
*/
|
|
13
|
+
action: "allow" | "deny" | "redact" | "transform" | "audit";
|
|
14
|
+
/**
|
|
15
|
+
* Optional human-readable reason for the action, typically used with deny
|
|
16
|
+
*/
|
|
17
|
+
reason?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Redaction instructions to apply when action is 'redact'.
|
|
20
|
+
*
|
|
21
|
+
* @minItems 1
|
|
22
|
+
*/
|
|
23
|
+
redactions?: [
|
|
24
|
+
{
|
|
25
|
+
/**
|
|
26
|
+
* Dot-notation path to the field being redacted (e.g. 'response.content').
|
|
27
|
+
*/
|
|
28
|
+
field: string;
|
|
29
|
+
/**
|
|
30
|
+
* 'mask' replaces with a fixed string, 'remove' deletes the field, 'replace' substitutes matched patterns.
|
|
31
|
+
*/
|
|
32
|
+
strategy: "mask" | "remove" | "replace";
|
|
33
|
+
/**
|
|
34
|
+
* Replacement string. Required when strategy is 'mask' or 'replace'.
|
|
35
|
+
*/
|
|
36
|
+
replacement?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Regex pattern identifying the content to redact. Required when strategy is 'replace'.
|
|
39
|
+
*/
|
|
40
|
+
pattern?: string;
|
|
41
|
+
},
|
|
42
|
+
...{
|
|
43
|
+
/**
|
|
44
|
+
* Dot-notation path to the field being redacted (e.g. 'response.content').
|
|
45
|
+
*/
|
|
46
|
+
field: string;
|
|
47
|
+
/**
|
|
48
|
+
* 'mask' replaces with a fixed string, 'remove' deletes the field, 'replace' substitutes matched patterns.
|
|
49
|
+
*/
|
|
50
|
+
strategy: "mask" | "remove" | "replace";
|
|
51
|
+
/**
|
|
52
|
+
* Replacement string. Required when strategy is 'mask' or 'replace'.
|
|
53
|
+
*/
|
|
54
|
+
replacement?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Regex pattern identifying the content to redact. Required when strategy is 'replace'.
|
|
57
|
+
*/
|
|
58
|
+
pattern?: string;
|
|
59
|
+
}[]
|
|
60
|
+
];
|
|
61
|
+
/**
|
|
62
|
+
* Field transformations to apply when action is 'transform'. Keys are dot-notation field paths, values are template strings supporting {{field.path}} interpolation.
|
|
63
|
+
*/
|
|
64
|
+
transformation?: {
|
|
65
|
+
[k: string]: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Matches when the resolved field value strictly equals the operand
|
|
70
|
+
*/
|
|
71
|
+
export interface EqualsCondition {
|
|
72
|
+
/**
|
|
73
|
+
* Dot-notation path to the field in the context (e.g. 'tool_name', 'messages.0.content')
|
|
74
|
+
*/
|
|
75
|
+
field: string;
|
|
76
|
+
/**
|
|
77
|
+
* The value to compare against using strict equality
|
|
78
|
+
*/
|
|
79
|
+
equals: {
|
|
80
|
+
[k: string]: unknown;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Matches when the resolved field value contains any of the given substrings (case-insensitive)
|
|
85
|
+
*/
|
|
86
|
+
export interface ContainsCondition {
|
|
87
|
+
/**
|
|
88
|
+
* Dot-notation path to the field in the context
|
|
89
|
+
*/
|
|
90
|
+
field: string;
|
|
91
|
+
/**
|
|
92
|
+
* List of substrings to search for
|
|
93
|
+
*
|
|
94
|
+
* @minItems 1
|
|
95
|
+
*/
|
|
96
|
+
contains: [string, ...string[]];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Matches when the resolved field value is not present in the given list
|
|
100
|
+
*/
|
|
101
|
+
export interface NotInCondition {
|
|
102
|
+
/**
|
|
103
|
+
* Dot-notation path to the field in the context
|
|
104
|
+
*/
|
|
105
|
+
field: string;
|
|
106
|
+
/**
|
|
107
|
+
* List of values the field must not be equal to
|
|
108
|
+
*/
|
|
109
|
+
not_in: unknown[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Matches when the resolved field value is numerically greater than the operand
|
|
113
|
+
*/
|
|
114
|
+
export interface GreaterThanCondition {
|
|
115
|
+
/**
|
|
116
|
+
* Dot-notation path to the field in the context
|
|
117
|
+
*/
|
|
118
|
+
field: string;
|
|
119
|
+
/**
|
|
120
|
+
* The numeric threshold
|
|
121
|
+
*/
|
|
122
|
+
greater_than: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Always matches, regardless of context
|
|
126
|
+
*/
|
|
127
|
+
export interface AlwaysCondition {
|
|
128
|
+
always: true;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=dsl-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsl-policy.d.ts","sourceRoot":"","sources":["../../src/generated/dsl-policy.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,eAAe,GAAG,iBAAiB,GAAG,cAAc,GAAG,oBAAoB,GAAG,eAAe,CAAC;AAEtH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB;;OAEG;IACH,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;IAC5D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE;QACX;YACE;;eAEG;YACH,KAAK,EAAE,MAAM,CAAC;YACd;;eAEG;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","sources":["../../src/generated/dsl-policy.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,iFAAiF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The evaluation input provided to policies at the Input Interception point.
|
|
3
|
+
*/
|
|
4
|
+
export type InputContext = ApsBase & {
|
|
5
|
+
/**
|
|
6
|
+
* The ordered message history to be forwarded to the LLM runtime.
|
|
7
|
+
*/
|
|
8
|
+
messages: Message[];
|
|
9
|
+
metadata: Metadata;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Base schema for the Agent Policy Specification v0.1.0. All other APS schemas extend this schema. Defines shared types used across the specification.
|
|
13
|
+
*/
|
|
14
|
+
export interface ApsBase {
|
|
15
|
+
[k: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A single message in a conversation.
|
|
19
|
+
*/
|
|
20
|
+
export interface Message {
|
|
21
|
+
/**
|
|
22
|
+
* The role of the message author.
|
|
23
|
+
*/
|
|
24
|
+
role: "system" | "user" | "assistant";
|
|
25
|
+
/**
|
|
26
|
+
* The text content of the message.
|
|
27
|
+
*/
|
|
28
|
+
content: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Common metadata attached to every APS context object.
|
|
32
|
+
*/
|
|
33
|
+
export interface Metadata {
|
|
34
|
+
/**
|
|
35
|
+
* Unique identifier for the agent that owns this session.
|
|
36
|
+
*/
|
|
37
|
+
agent_id: string;
|
|
38
|
+
/**
|
|
39
|
+
* Unique identifier for the current session.
|
|
40
|
+
*/
|
|
41
|
+
session_id: string;
|
|
42
|
+
/**
|
|
43
|
+
* ISO 8601 timestamp of when the interception occurred.
|
|
44
|
+
*/
|
|
45
|
+
timestamp: string;
|
|
46
|
+
[k: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=input-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-context.d.ts","sourceRoot":"","sources":["../../src/generated/input-context.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG;IACnC;;OAEG;IACH,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AACD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-context.js","sourceRoot":"","sources":["../../src/generated/input-context.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,oFAAoF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The evaluation input provided to policies at the Output Interception point.
|
|
3
|
+
*/
|
|
4
|
+
export type OutputContext = ApsBase & {
|
|
5
|
+
response: AssistantMessage;
|
|
6
|
+
metadata: Metadata;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Base schema for the Agent Policy Specification v0.1.0. All other APS schemas extend this schema. Defines shared types used across the specification.
|
|
10
|
+
*/
|
|
11
|
+
export interface ApsBase {
|
|
12
|
+
[k: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A message produced by the LLM (role must be 'assistant').
|
|
16
|
+
*/
|
|
17
|
+
export interface AssistantMessage {
|
|
18
|
+
role: "assistant";
|
|
19
|
+
/**
|
|
20
|
+
* The text content of the assistant message.
|
|
21
|
+
*/
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Common metadata attached to every APS context object.
|
|
26
|
+
*/
|
|
27
|
+
export interface Metadata {
|
|
28
|
+
/**
|
|
29
|
+
* Unique identifier for the agent that owns this session.
|
|
30
|
+
*/
|
|
31
|
+
agent_id: string;
|
|
32
|
+
/**
|
|
33
|
+
* Unique identifier for the current session.
|
|
34
|
+
*/
|
|
35
|
+
session_id: string;
|
|
36
|
+
/**
|
|
37
|
+
* ISO 8601 timestamp of when the interception occurred.
|
|
38
|
+
*/
|
|
39
|
+
timestamp: string;
|
|
40
|
+
[k: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=output-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-context.d.ts","sourceRoot":"","sources":["../../src/generated/output-context.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AACD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-context.js","sourceRoot":"","sources":["../../src/generated/output-context.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,qFAAqF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The result produced by a policy evaluation at any interception point.
|
|
3
|
+
*/
|
|
4
|
+
export type PolicyDecision = AllowDecision | DenyDecision | RedactDecision | TransformDecision | AuditDecision;
|
|
5
|
+
export interface AllowDecision {
|
|
6
|
+
decision: "allow";
|
|
7
|
+
/**
|
|
8
|
+
* When true, an audit record is also produced for this interaction.
|
|
9
|
+
*/
|
|
10
|
+
audit?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface DenyDecision {
|
|
13
|
+
decision: "deny";
|
|
14
|
+
/**
|
|
15
|
+
* Human-readable explanation for the denial. MAY be omitted for security-sensitive denials.
|
|
16
|
+
*/
|
|
17
|
+
reason?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Identifier of the policy that produced this denial.
|
|
20
|
+
*/
|
|
21
|
+
policy_id?: string;
|
|
22
|
+
/**
|
|
23
|
+
* When true, an audit record is also produced for this interaction.
|
|
24
|
+
*/
|
|
25
|
+
audit?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface RedactDecision {
|
|
28
|
+
decision: "redact";
|
|
29
|
+
/**
|
|
30
|
+
* @minItems 1
|
|
31
|
+
*/
|
|
32
|
+
redactions: [Redaction, ...Redaction[]];
|
|
33
|
+
/**
|
|
34
|
+
* When true, an audit record is also produced for this interaction.
|
|
35
|
+
*/
|
|
36
|
+
audit?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface Redaction {
|
|
39
|
+
/**
|
|
40
|
+
* Dot-notation path to the field being redacted (e.g. 'response.content').
|
|
41
|
+
*/
|
|
42
|
+
field: string;
|
|
43
|
+
/**
|
|
44
|
+
* 'mask' replaces with a fixed string, 'remove' deletes the field, 'replace' substitutes matched patterns.
|
|
45
|
+
*/
|
|
46
|
+
strategy: "mask" | "remove" | "replace";
|
|
47
|
+
/**
|
|
48
|
+
* Replacement string. Required when strategy is 'mask' or 'replace'.
|
|
49
|
+
*/
|
|
50
|
+
replacement?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Regex pattern identifying the content to redact. Required when strategy is 'replace'.
|
|
53
|
+
*/
|
|
54
|
+
pattern?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface TransformDecision {
|
|
57
|
+
decision: "transform";
|
|
58
|
+
transformation: Transformation;
|
|
59
|
+
/**
|
|
60
|
+
* When true, an audit record is also produced for this interaction.
|
|
61
|
+
*/
|
|
62
|
+
audit?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface Transformation {
|
|
65
|
+
/**
|
|
66
|
+
* Ordered list of transformation operations to apply.
|
|
67
|
+
*/
|
|
68
|
+
operations: {
|
|
69
|
+
/**
|
|
70
|
+
* 'set' replaces the field value, 'prepend'/'append' adds content to a string field.
|
|
71
|
+
*/
|
|
72
|
+
op: "set" | "prepend" | "append";
|
|
73
|
+
/**
|
|
74
|
+
* Dot-notation path to the field to transform.
|
|
75
|
+
*/
|
|
76
|
+
field: string;
|
|
77
|
+
/**
|
|
78
|
+
* The value to apply. Type must match the target field.
|
|
79
|
+
*/
|
|
80
|
+
value: {
|
|
81
|
+
[k: string]: unknown;
|
|
82
|
+
};
|
|
83
|
+
}[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Produces only an audit record; the interaction proceeds unchanged.
|
|
87
|
+
*/
|
|
88
|
+
export interface AuditDecision {
|
|
89
|
+
decision: "audit";
|
|
90
|
+
/**
|
|
91
|
+
* Optional note to include in the audit record.
|
|
92
|
+
*/
|
|
93
|
+
reason?: string;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=policy-decision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-decision.d.ts","sourceRoot":"","sources":["../../src/generated/policy-decision.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM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CACL;AACD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-decision.js","sourceRoot":"","sources":["../../src/generated/policy-decision.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,sFAAsF"}
|