@agentvault/agentvault 0.16.0 → 0.17.1
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/README.md +214 -59
- package/dist/channel.d.ts.map +1 -1
- package/dist/cli.js +86 -56
- package/dist/cli.js.map +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -57
- package/dist/index.js.map +4 -4
- package/dist/mcp-server.d.ts +18 -0
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/openclaw-entry.js.map +2 -2
- package/dist/policy-enforcer.d.ts +78 -0
- package/dist/policy-enforcer.d.ts.map +1 -0
- package/dist/skill-manifest.d.ts.map +1 -1
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SecureChannel } from "./channel.js";
|
|
2
|
-
export type { SecureChannelConfig, ChannelState, MessageMetadata, AttachmentData, PersistedState, LegacyPersistedState, DeviceSession, HistoryEntry, SendOptions, DecisionOption, DecisionRequest, DecisionResponse, ContextRef, HeartbeatStatus, StatusAlert, RoomInfo, RoomMemberInfo, RoomConversationInfo, RoomState, A2AChannel, A2AMessage, RoomParticipantEvent, DeliveryTarget, DeliveryContent, DeliveryOptions, DeliveryReceipt, TargetInfo, ActionConfirmation, ArtifactPayload, } from "./types.js";
|
|
2
|
+
export type { SecureChannelConfig, ChannelState, MessageMetadata, AttachmentData, PersistedState, LegacyPersistedState, DeviceSession, HistoryEntry, SendOptions, DecisionOption, DecisionRequest, DecisionResponse, ContextRef, HeartbeatStatus, StatusAlert, RoomInfo, RoomMemberInfo, RoomConversationInfo, RoomState, A2AChannel, A2AMessage, RoomParticipantEvent, DeliveryTarget, DeliveryContent, DeliveryOptions, DeliveryReceipt, TargetInfo, ActionConfirmation, ArtifactPayload, PolicyAlert, ApprovalRequest, ApprovalResponse, } from "./types.js";
|
|
3
3
|
export { parseTarget } from "./types.js";
|
|
4
4
|
export { listAccountIds, resolveAccount } from "./account-config.js";
|
|
5
5
|
export type { ResolvedAccount } from "./account-config.js";
|
|
@@ -18,6 +18,8 @@ export type { SkillManifest } from "./skill-manifest.js";
|
|
|
18
18
|
export { invokeSkill } from "./skill-invoker.js";
|
|
19
19
|
export type { InvocationResult, InvocationOpts } from "./skill-invoker.js";
|
|
20
20
|
export { wrapSkillExecution, reportSkillInvocation, drainSkillSpans } from "./skill-telemetry.js";
|
|
21
|
+
export { PolicyEnforcer } from "./policy-enforcer.js";
|
|
22
|
+
export type { PolicyContext, PolicyResult, PolicyViolation, PolicyMetrics } from "./policy-enforcer.js";
|
|
21
23
|
export type { OpenClawPluginApi, PluginRuntime, ChannelGatewayContext, ChannelOutboundPayloadContext, ReplyPayload, MessageSentEvent, SessionStartEvent, SessionEndEvent, AgentEventPayload, TranscriptUpdatePayload, } from "./openclaw-types.js";
|
|
22
24
|
export declare const VERSION = "0.14.1";
|
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,WAAW,EACX,QAAQ,EACR,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,WAAW,EACX,QAAQ,EACR,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC1H,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9I,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGtE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGnE,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5G,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG3E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGlG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGxG,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,6BAA6B,EAC7B,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -45996,6 +45996,37 @@ function buildEvalSpan(opts) {
|
|
|
45996
45996
|
status: { code: 0 }
|
|
45997
45997
|
};
|
|
45998
45998
|
}
|
|
45999
|
+
function buildPolicyViolationSpan(opts) {
|
|
46000
|
+
const now = Date.now();
|
|
46001
|
+
const attributes = {
|
|
46002
|
+
"av.policy.rule_id": opts.ruleId,
|
|
46003
|
+
"av.policy.scope": opts.policyScope,
|
|
46004
|
+
"av.policy.action_taken": opts.actionTaken,
|
|
46005
|
+
"av.policy.violation_type": opts.violationType
|
|
46006
|
+
};
|
|
46007
|
+
if (opts.targetTool)
|
|
46008
|
+
attributes["av.policy.target_tool"] = opts.targetTool;
|
|
46009
|
+
if (opts.targetModel)
|
|
46010
|
+
attributes["av.policy.target_model"] = opts.targetModel;
|
|
46011
|
+
if (opts.messageType)
|
|
46012
|
+
attributes["av.policy.message_type"] = opts.messageType;
|
|
46013
|
+
applySkillName(attributes, opts.skillName);
|
|
46014
|
+
const isBlock = opts.actionTaken === "block";
|
|
46015
|
+
return {
|
|
46016
|
+
traceId: opts.traceId ?? generateTraceId(),
|
|
46017
|
+
spanId: opts.spanId ?? generateSpanId(),
|
|
46018
|
+
parentSpanId: opts.parentSpanId,
|
|
46019
|
+
name: "av.policy.evaluate",
|
|
46020
|
+
kind: "internal",
|
|
46021
|
+
startTime: now,
|
|
46022
|
+
endTime: now,
|
|
46023
|
+
attributes,
|
|
46024
|
+
status: isBlock ? { code: 2, message: `Policy violation: ${opts.violationType}` } : { code: 0 }
|
|
46025
|
+
};
|
|
46026
|
+
}
|
|
46027
|
+
function buildTraceparent(span) {
|
|
46028
|
+
return `00-${span.traceId}-${span.spanId}-01`;
|
|
46029
|
+
}
|
|
45999
46030
|
var init_telemetry = __esm({
|
|
46000
46031
|
"../crypto/dist/telemetry.js"() {
|
|
46001
46032
|
"use strict";
|
|
@@ -46018,6 +46049,9 @@ function toOtlpAttributes(attrs) {
|
|
|
46018
46049
|
});
|
|
46019
46050
|
}
|
|
46020
46051
|
function spanToOtlp(span) {
|
|
46052
|
+
const enrichedAttrs = { ...span.attributes };
|
|
46053
|
+
enrichedAttrs["w3c.traceparent"] = buildTraceparent(span);
|
|
46054
|
+
enrichedAttrs["w3c.tracestate"] = `av=s:${span.spanId}`;
|
|
46021
46055
|
const otlp = {
|
|
46022
46056
|
traceId: span.traceId,
|
|
46023
46057
|
spanId: span.spanId,
|
|
@@ -46025,7 +46059,7 @@ function spanToOtlp(span) {
|
|
|
46025
46059
|
kind: span.kind,
|
|
46026
46060
|
startTimeUnixNano: String(span.startTime * 1e6),
|
|
46027
46061
|
endTimeUnixNano: String(span.endTime * 1e6),
|
|
46028
|
-
attributes: toOtlpAttributes(
|
|
46062
|
+
attributes: toOtlpAttributes(enrichedAttrs)
|
|
46029
46063
|
};
|
|
46030
46064
|
if (span.parentSpanId !== void 0) {
|
|
46031
46065
|
otlp.parentSpanId = span.parentSpanId;
|
|
@@ -46202,6 +46236,14 @@ var init_backup = __esm({
|
|
|
46202
46236
|
}
|
|
46203
46237
|
});
|
|
46204
46238
|
|
|
46239
|
+
// ../crypto/dist/approval.js
|
|
46240
|
+
var init_approval = __esm({
|
|
46241
|
+
async "../crypto/dist/approval.js"() {
|
|
46242
|
+
"use strict";
|
|
46243
|
+
await init_did();
|
|
46244
|
+
}
|
|
46245
|
+
});
|
|
46246
|
+
|
|
46205
46247
|
// ../crypto/dist/index.js
|
|
46206
46248
|
var init_dist = __esm({
|
|
46207
46249
|
async "../crypto/dist/index.js"() {
|
|
@@ -46219,6 +46261,7 @@ var init_dist = __esm({
|
|
|
46219
46261
|
init_telemetry();
|
|
46220
46262
|
init_telemetry_reporter();
|
|
46221
46263
|
await init_backup();
|
|
46264
|
+
await init_approval();
|
|
46222
46265
|
}
|
|
46223
46266
|
});
|
|
46224
46267
|
|
|
@@ -48513,10 +48556,11 @@ var init_channel = __esm({
|
|
|
48513
48556
|
}
|
|
48514
48557
|
if (data.event === "hub_identity_sync") {
|
|
48515
48558
|
if (this._persisted && data.data?.hub_id) {
|
|
48516
|
-
const changed = this._persisted.hubId !== data.data.hub_id;
|
|
48559
|
+
const changed = this._persisted.hubId !== data.data.hub_id || this._persisted.agentRole !== (data.data.agent_role ?? "peer");
|
|
48517
48560
|
this._persisted.hubAddress = data.data.hub_address;
|
|
48518
48561
|
this._persisted.hubId = data.data.hub_id;
|
|
48519
48562
|
this._persisted.agentHubId = data.data.hub_id;
|
|
48563
|
+
this._persisted.agentRole = data.data.agent_role ?? "peer";
|
|
48520
48564
|
if (changed) this._persistState();
|
|
48521
48565
|
if (!this._telemetryReporter && this._persisted.deviceJwt && this._persisted.hubId) {
|
|
48522
48566
|
this._telemetryReporter = new TelemetryReporter({
|
|
@@ -48538,6 +48582,14 @@ var init_channel = __esm({
|
|
|
48538
48582
|
}
|
|
48539
48583
|
this.emit("hub_identity_assigned", data.data);
|
|
48540
48584
|
}
|
|
48585
|
+
if (data.event === "hub_identity_role_changed") {
|
|
48586
|
+
if (this._persisted && data.data?.agent_role) {
|
|
48587
|
+
this._persisted.agentRole = data.data.agent_role;
|
|
48588
|
+
this._persistState();
|
|
48589
|
+
console.log(`[SecureChannel] Agent role changed to: ${data.data.agent_role}`);
|
|
48590
|
+
}
|
|
48591
|
+
this.emit("hub_identity_role_changed", data.data);
|
|
48592
|
+
}
|
|
48541
48593
|
if (data.event === "hub_identity_removed") {
|
|
48542
48594
|
if (this._persisted) {
|
|
48543
48595
|
delete this._persisted.hubAddress;
|
|
@@ -49204,6 +49256,9 @@ ${messageText}`;
|
|
|
49204
49256
|
_resolveWorkspaceDir() {
|
|
49205
49257
|
const homedir = process.env.HOME ?? process.env.USERPROFILE ?? "/tmp";
|
|
49206
49258
|
const agentName = this.config.agentName;
|
|
49259
|
+
if (this._persisted?.agentRole === "lead") {
|
|
49260
|
+
return join3(homedir, ".openclaw", "workspace");
|
|
49261
|
+
}
|
|
49207
49262
|
try {
|
|
49208
49263
|
const configPath = join3(homedir, ".openclaw", "openclaw.json");
|
|
49209
49264
|
const raw = __require("node:fs").readFileSync(configPath, "utf-8");
|
|
@@ -76132,7 +76187,13 @@ var init_mcp_server2 = __esm({
|
|
|
76132
76187
|
tags: s2.tags,
|
|
76133
76188
|
sla: s2.slaDefinition,
|
|
76134
76189
|
hasSchema: !!s2.inputSchema,
|
|
76135
|
-
hasInstructions: !!s2.instructions
|
|
76190
|
+
hasInstructions: !!s2.instructions,
|
|
76191
|
+
certificationTier: s2.certificationTier,
|
|
76192
|
+
modelRouting: s2.modelRouting,
|
|
76193
|
+
allowedModels: s2.allowedModels,
|
|
76194
|
+
hasToolPolicy: !!(s2.toolsAllowed || s2.toolsDenied),
|
|
76195
|
+
hasOutputSchema: !!s2.outputSchema,
|
|
76196
|
+
requiredPolicies: s2.requiredPolicies
|
|
76136
76197
|
}));
|
|
76137
76198
|
return {
|
|
76138
76199
|
contents: [{
|
|
@@ -76328,7 +76389,7 @@ function parseSkillMd(content) {
|
|
|
76328
76389
|
if (!frontmatter.name) return null;
|
|
76329
76390
|
const instructionLines = lines.slice(endIdx + 1);
|
|
76330
76391
|
const instructions = instructionLines.join("\n").trim();
|
|
76331
|
-
|
|
76392
|
+
const skill = {
|
|
76332
76393
|
name: frontmatter.name,
|
|
76333
76394
|
version: frontmatter.version,
|
|
76334
76395
|
description: frontmatter.description,
|
|
@@ -76337,82 +76398,76 @@ function parseSkillMd(content) {
|
|
|
76337
76398
|
slaDefinition: frontmatter.sla,
|
|
76338
76399
|
instructions: instructions || void 0
|
|
76339
76400
|
};
|
|
76401
|
+
if (frontmatter.agentVault) {
|
|
76402
|
+
const av = frontmatter.agentVault;
|
|
76403
|
+
if (av.certification) skill.certificationTier = av.certification;
|
|
76404
|
+
if (av.runtime?.capabilities) skill.toolsAllowed = av.runtime.capabilities;
|
|
76405
|
+
if (av.runtime?.forbidden) skill.toolsDenied = av.runtime.forbidden;
|
|
76406
|
+
if (av.runtime?.output_schema) skill.outputSchema = av.runtime.output_schema;
|
|
76407
|
+
if (av.model?.routing) skill.modelRouting = av.model.routing;
|
|
76408
|
+
if (av.model?.allowed) skill.allowedModels = av.model.allowed;
|
|
76409
|
+
if (av.model?.default) skill.defaultModel = av.model.default;
|
|
76410
|
+
if (av.integrity) skill.integrity = av.integrity;
|
|
76411
|
+
if (av.requiredPolicies) skill.requiredPolicies = av.requiredPolicies;
|
|
76412
|
+
}
|
|
76413
|
+
return skill;
|
|
76340
76414
|
}
|
|
76341
76415
|
function parseSimpleYaml(yaml) {
|
|
76342
76416
|
const result = {};
|
|
76343
76417
|
const lines = yaml.split("\n");
|
|
76344
|
-
|
|
76345
|
-
let
|
|
76346
|
-
|
|
76418
|
+
const stack = [];
|
|
76419
|
+
let currentObj = result;
|
|
76420
|
+
function parseValue(raw) {
|
|
76421
|
+
const value = raw.replace(/^["']|["']$/g, "");
|
|
76422
|
+
const num = Number(value);
|
|
76423
|
+
if (!isNaN(num) && value !== "") return num;
|
|
76424
|
+
if (value === "true") return true;
|
|
76425
|
+
if (value === "false") return false;
|
|
76426
|
+
return value;
|
|
76427
|
+
}
|
|
76347
76428
|
for (const line of lines) {
|
|
76348
76429
|
const trimmed = line.trim();
|
|
76349
76430
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
76350
76431
|
const indent = line.length - line.trimStart().length;
|
|
76351
|
-
|
|
76432
|
+
while (stack.length > 0 && indent <= stack[stack.length - 1].indent) {
|
|
76433
|
+
const popped = stack.pop();
|
|
76434
|
+
currentObj = stack.length > 0 ? stack[stack.length - 1].obj : result;
|
|
76435
|
+
currentObj[popped.key] = popped.obj;
|
|
76436
|
+
}
|
|
76437
|
+
const inlineArrayMatch = trimmed.match(/^(\w[\w_-]*)\s*:\s*\[(.+)\]$/);
|
|
76352
76438
|
if (inlineArrayMatch) {
|
|
76353
76439
|
const key = inlineArrayMatch[1];
|
|
76354
76440
|
const values = inlineArrayMatch[2].split(",").map((v2) => v2.trim().replace(/^["']|["']$/g, ""));
|
|
76355
|
-
if (
|
|
76356
|
-
|
|
76441
|
+
if (stack.length > 0) {
|
|
76442
|
+
stack[stack.length - 1].obj[key] = values;
|
|
76357
76443
|
} else {
|
|
76358
|
-
|
|
76359
|
-
result[currentKey] = nestedObj;
|
|
76360
|
-
nestedObj = null;
|
|
76361
|
-
}
|
|
76362
|
-
result[key] = values;
|
|
76444
|
+
currentObj[key] = values;
|
|
76363
76445
|
}
|
|
76364
76446
|
continue;
|
|
76365
76447
|
}
|
|
76366
|
-
const kvMatch = trimmed.match(/^(\w[\
|
|
76367
|
-
if (kvMatch
|
|
76368
|
-
if (nestedObj && currentKey) {
|
|
76369
|
-
result[currentKey] = nestedObj;
|
|
76370
|
-
nestedObj = null;
|
|
76371
|
-
}
|
|
76448
|
+
const kvMatch = trimmed.match(/^(\w[\w_-]*)\s*:\s*(.+)$/);
|
|
76449
|
+
if (kvMatch) {
|
|
76372
76450
|
const key = kvMatch[1];
|
|
76373
|
-
const
|
|
76374
|
-
|
|
76375
|
-
|
|
76376
|
-
result[key] = num;
|
|
76377
|
-
} else if (value === "true") {
|
|
76378
|
-
result[key] = true;
|
|
76379
|
-
} else if (value === "false") {
|
|
76380
|
-
result[key] = false;
|
|
76451
|
+
const val = parseValue(kvMatch[2]);
|
|
76452
|
+
if (stack.length > 0) {
|
|
76453
|
+
stack[stack.length - 1].obj[key] = val;
|
|
76381
76454
|
} else {
|
|
76382
|
-
|
|
76455
|
+
currentObj[key] = val;
|
|
76383
76456
|
}
|
|
76384
76457
|
continue;
|
|
76385
76458
|
}
|
|
76386
|
-
const nestedMatch = trimmed.match(/^(\w[\
|
|
76387
|
-
if (nestedMatch
|
|
76388
|
-
|
|
76389
|
-
|
|
76390
|
-
}
|
|
76391
|
-
currentKey = nestedMatch[1];
|
|
76392
|
-
currentIndent = indent;
|
|
76393
|
-
nestedObj = {};
|
|
76459
|
+
const nestedMatch = trimmed.match(/^(\w[\w_-]*)\s*:$/);
|
|
76460
|
+
if (nestedMatch) {
|
|
76461
|
+
const key = nestedMatch[1];
|
|
76462
|
+
const newObj = {};
|
|
76463
|
+
stack.push({ key, obj: newObj, indent });
|
|
76394
76464
|
continue;
|
|
76395
76465
|
}
|
|
76396
|
-
if (nestedObj && indent > 0) {
|
|
76397
|
-
const nestedKv = trimmed.match(/^(\w[\w-]*)\s*:\s*(.+)$/);
|
|
76398
|
-
if (nestedKv) {
|
|
76399
|
-
const key = nestedKv[1];
|
|
76400
|
-
const value = nestedKv[2].replace(/^["']|["']$/g, "");
|
|
76401
|
-
const num = Number(value);
|
|
76402
|
-
if (!isNaN(num) && value !== "") {
|
|
76403
|
-
nestedObj[key] = num;
|
|
76404
|
-
} else if (value === "true") {
|
|
76405
|
-
nestedObj[key] = true;
|
|
76406
|
-
} else if (value === "false") {
|
|
76407
|
-
nestedObj[key] = false;
|
|
76408
|
-
} else {
|
|
76409
|
-
nestedObj[key] = value;
|
|
76410
|
-
}
|
|
76411
|
-
}
|
|
76412
|
-
}
|
|
76413
76466
|
}
|
|
76414
|
-
|
|
76415
|
-
|
|
76467
|
+
while (stack.length > 0) {
|
|
76468
|
+
const popped = stack.pop();
|
|
76469
|
+
const parent = stack.length > 0 ? stack[stack.length - 1].obj : result;
|
|
76470
|
+
parent[popped.key] = popped.obj;
|
|
76416
76471
|
}
|
|
76417
76472
|
return result;
|
|
76418
76473
|
}
|
|
@@ -76684,6 +76739,151 @@ var init_skill_telemetry = __esm({
|
|
|
76684
76739
|
}
|
|
76685
76740
|
});
|
|
76686
76741
|
|
|
76742
|
+
// src/policy-enforcer.ts
|
|
76743
|
+
var PolicyEnforcer;
|
|
76744
|
+
var init_policy_enforcer = __esm({
|
|
76745
|
+
async "src/policy-enforcer.ts"() {
|
|
76746
|
+
"use strict";
|
|
76747
|
+
await init_dist();
|
|
76748
|
+
PolicyEnforcer = class {
|
|
76749
|
+
skills = /* @__PURE__ */ new Map();
|
|
76750
|
+
metrics = {
|
|
76751
|
+
totalEvaluations: 0,
|
|
76752
|
+
totalBlocks: 0,
|
|
76753
|
+
totalWarnings: 0,
|
|
76754
|
+
bySkill: {},
|
|
76755
|
+
byRule: {}
|
|
76756
|
+
};
|
|
76757
|
+
spanBuffer = [];
|
|
76758
|
+
/**
|
|
76759
|
+
* Register a skill definition for policy evaluation.
|
|
76760
|
+
*/
|
|
76761
|
+
registerSkill(skill) {
|
|
76762
|
+
this.skills.set(skill.name, skill);
|
|
76763
|
+
}
|
|
76764
|
+
/**
|
|
76765
|
+
* Full 5-stage policy pipeline evaluation.
|
|
76766
|
+
*/
|
|
76767
|
+
evaluate(ctx) {
|
|
76768
|
+
this.metrics.totalEvaluations++;
|
|
76769
|
+
const skillMetrics = this.metrics.bySkill[ctx.skillName] ??= { evaluations: 0, blocks: 0 };
|
|
76770
|
+
skillMetrics.evaluations++;
|
|
76771
|
+
const violations = [];
|
|
76772
|
+
const skill = this.skills.get(ctx.skillName);
|
|
76773
|
+
if (skill) {
|
|
76774
|
+
if (ctx.toolName && skill.toolsDenied?.length) {
|
|
76775
|
+
if (skill.toolsDenied.includes(ctx.toolName)) {
|
|
76776
|
+
violations.push({
|
|
76777
|
+
ruleId: `deny:${ctx.skillName}:${ctx.toolName}`,
|
|
76778
|
+
scope: "tool",
|
|
76779
|
+
action: "block",
|
|
76780
|
+
type: "forbidden_tool",
|
|
76781
|
+
message: `Tool "${ctx.toolName}" is forbidden for skill "${ctx.skillName}"`
|
|
76782
|
+
});
|
|
76783
|
+
}
|
|
76784
|
+
}
|
|
76785
|
+
if (ctx.toolName && skill.toolsAllowed?.length) {
|
|
76786
|
+
if (!skill.toolsAllowed.includes(ctx.toolName)) {
|
|
76787
|
+
violations.push({
|
|
76788
|
+
ruleId: `allow:${ctx.skillName}:${ctx.toolName}`,
|
|
76789
|
+
scope: "tool",
|
|
76790
|
+
action: "block",
|
|
76791
|
+
type: "tool_not_allowed",
|
|
76792
|
+
message: `Tool "${ctx.toolName}" is not in the allowed list for skill "${ctx.skillName}"`
|
|
76793
|
+
});
|
|
76794
|
+
}
|
|
76795
|
+
}
|
|
76796
|
+
if (ctx.model && skill.allowedModels?.length) {
|
|
76797
|
+
if (!skill.allowedModels.includes(ctx.model)) {
|
|
76798
|
+
violations.push({
|
|
76799
|
+
ruleId: `model:${ctx.skillName}:${ctx.model}`,
|
|
76800
|
+
scope: "model",
|
|
76801
|
+
action: "block",
|
|
76802
|
+
type: "model_not_allowed",
|
|
76803
|
+
message: `Model "${ctx.model}" is not allowed for skill "${ctx.skillName}". Allowed: ${skill.allowedModels.join(", ")}`
|
|
76804
|
+
});
|
|
76805
|
+
}
|
|
76806
|
+
}
|
|
76807
|
+
}
|
|
76808
|
+
const blocked = violations.some((v2) => v2.action === "block");
|
|
76809
|
+
for (const v2 of violations) {
|
|
76810
|
+
this.metrics.byRule[v2.ruleId] = (this.metrics.byRule[v2.ruleId] ?? 0) + 1;
|
|
76811
|
+
if (v2.action === "block") this.metrics.totalBlocks++;
|
|
76812
|
+
if (v2.action === "warn") this.metrics.totalWarnings++;
|
|
76813
|
+
this.spanBuffer.push(
|
|
76814
|
+
buildPolicyViolationSpan({
|
|
76815
|
+
ruleId: v2.ruleId,
|
|
76816
|
+
policyScope: v2.scope,
|
|
76817
|
+
actionTaken: v2.action,
|
|
76818
|
+
violationType: v2.type,
|
|
76819
|
+
targetTool: ctx.toolName,
|
|
76820
|
+
targetModel: ctx.model,
|
|
76821
|
+
skillName: ctx.skillName
|
|
76822
|
+
})
|
|
76823
|
+
);
|
|
76824
|
+
}
|
|
76825
|
+
if (blocked) {
|
|
76826
|
+
skillMetrics.blocks++;
|
|
76827
|
+
}
|
|
76828
|
+
return {
|
|
76829
|
+
allowed: !blocked,
|
|
76830
|
+
violations,
|
|
76831
|
+
stage: "report"
|
|
76832
|
+
};
|
|
76833
|
+
}
|
|
76834
|
+
/**
|
|
76835
|
+
* Wrap an MCP tool handler with policy enforcement.
|
|
76836
|
+
* Returns a function that checks policy before calling the original handler.
|
|
76837
|
+
*/
|
|
76838
|
+
wrapHandler(skillName, handler) {
|
|
76839
|
+
return async (args) => {
|
|
76840
|
+
const result = this.evaluate({
|
|
76841
|
+
skillName,
|
|
76842
|
+
args
|
|
76843
|
+
});
|
|
76844
|
+
if (!result.allowed) {
|
|
76845
|
+
return {
|
|
76846
|
+
blocked: true,
|
|
76847
|
+
violations: result.violations.map((v2) => ({
|
|
76848
|
+
rule: v2.ruleId,
|
|
76849
|
+
reason: v2.message,
|
|
76850
|
+
scope: v2.scope
|
|
76851
|
+
}))
|
|
76852
|
+
};
|
|
76853
|
+
}
|
|
76854
|
+
return handler(args);
|
|
76855
|
+
};
|
|
76856
|
+
}
|
|
76857
|
+
/**
|
|
76858
|
+
* Get accumulated policy metrics.
|
|
76859
|
+
*/
|
|
76860
|
+
getMetrics() {
|
|
76861
|
+
return { ...this.metrics };
|
|
76862
|
+
}
|
|
76863
|
+
/**
|
|
76864
|
+
* Drain buffered telemetry spans.
|
|
76865
|
+
*/
|
|
76866
|
+
drainSpans() {
|
|
76867
|
+
const spans = this.spanBuffer;
|
|
76868
|
+
this.spanBuffer = [];
|
|
76869
|
+
return spans;
|
|
76870
|
+
}
|
|
76871
|
+
/**
|
|
76872
|
+
* Reset all metrics (for testing).
|
|
76873
|
+
*/
|
|
76874
|
+
resetMetrics() {
|
|
76875
|
+
this.metrics = {
|
|
76876
|
+
totalEvaluations: 0,
|
|
76877
|
+
totalBlocks: 0,
|
|
76878
|
+
totalWarnings: 0,
|
|
76879
|
+
bySkill: {},
|
|
76880
|
+
byRule: {}
|
|
76881
|
+
};
|
|
76882
|
+
}
|
|
76883
|
+
};
|
|
76884
|
+
}
|
|
76885
|
+
});
|
|
76886
|
+
|
|
76687
76887
|
// src/index.ts
|
|
76688
76888
|
var VERSION;
|
|
76689
76889
|
var init_index = __esm({
|
|
@@ -76701,12 +76901,14 @@ var init_index = __esm({
|
|
|
76701
76901
|
init_skill_manifest();
|
|
76702
76902
|
init_skill_invoker();
|
|
76703
76903
|
await init_skill_telemetry();
|
|
76904
|
+
await init_policy_enforcer();
|
|
76704
76905
|
VERSION = "0.14.1";
|
|
76705
76906
|
}
|
|
76706
76907
|
});
|
|
76707
76908
|
await init_index();
|
|
76708
76909
|
export {
|
|
76709
76910
|
AgentVaultMcpServer,
|
|
76911
|
+
PolicyEnforcer,
|
|
76710
76912
|
SecureChannel,
|
|
76711
76913
|
VERSION,
|
|
76712
76914
|
agentVaultPlugin,
|