permdock 0.0.0 → 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/README.md +268 -1
- package/dist/a2a/index.d.ts +178 -0
- package/dist/a2a/index.js +271 -0
- package/dist/ai-sdk/index.d.ts +74 -0
- package/dist/ai-sdk/index.js +137 -0
- package/dist/approval-required-TzNB9oQA.js +6 -0
- package/dist/approvals/index.d.ts +3 -0
- package/dist/approvals/index.js +4 -0
- package/dist/approvals-DaxY-Bdg.js +218 -0
- package/dist/approvers-aH0PJkmf.js +20 -0
- package/dist/arazzo-CTeVuXr5.js +70 -0
- package/dist/arazzo-aoTkqYsJ.js +54 -0
- package/dist/authzen/index.d.ts +48 -0
- package/dist/authzen/index.js +336 -0
- package/dist/better-auth/index.d.ts +92 -0
- package/dist/better-auth/index.js +324 -0
- package/dist/budget-JqcRqyhK.d.ts +11 -0
- package/dist/budget-NbEtbJC_.js +11 -0
- package/dist/capability-B68OFnZx.js +171 -0
- package/dist/capability-BDG_nkxt.d.ts +99 -0
- package/dist/catalog/index.d.ts +12 -0
- package/dist/catalog/index.js +2 -0
- package/dist/catalog-B0E6bggc.js +48 -0
- package/dist/catalog-H-vFGwWK.js +55 -0
- package/dist/catalog-doc-BSo_Q_-6.js +298 -0
- package/dist/catalog-idsHc0vo.js +2 -0
- package/dist/catalog-path-CnI0XTFK.js +12 -0
- package/dist/claude-agent/index.d.ts +81 -0
- package/dist/claude-agent/index.js +83 -0
- package/dist/clerk/index.d.ts +56 -0
- package/dist/clerk/index.js +280 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +20 -0
- package/dist/cli/index.d.ts +46 -0
- package/dist/cli/index.js +5 -0
- package/dist/cloud/index.d.ts +91 -0
- package/dist/cloud/index.js +390 -0
- package/dist/cloud-BNQTrmrr.js +50 -0
- package/dist/cloud-Cuxr6Czw.js +117 -0
- package/dist/collect-B7_TIfmg.js +49 -0
- package/dist/collect-O-tOtbnk.js +350 -0
- package/dist/collect-fRPAQIWb.js +2 -0
- package/dist/commands-BMh_Etm2.js +93 -0
- package/dist/compact-y6vfu2_f.js +19 -0
- package/dist/compare-pfyVnBjE.js +12 -0
- package/dist/compile-CQbvyIBr.d.ts +30 -0
- package/dist/compile-D22iwvuV.js +558 -0
- package/dist/config-BPYmjTOp.js +26 -0
- package/dist/connection-JvqwHODC.js +194 -0
- package/dist/context-CKEAabd7.js +73 -0
- package/dist/context-gtAwAILx.js +6 -0
- package/dist/convex/index.d.ts +40 -0
- package/dist/convex/index.js +55 -0
- package/dist/create-BKF3dgFk.d.ts +162 -0
- package/dist/create-CSkhDU9T.js +222 -0
- package/dist/credential-B_rkUNlY.js +326 -0
- package/dist/credentials-BgRX3WEg.js +268 -0
- package/dist/describe-Bt1YD5uS.js +99 -0
- package/dist/describe-DernyItf.d.ts +37 -0
- package/dist/diff-BUzf5Poi.js +48 -0
- package/dist/diff-x5Il8LVa.js +418 -0
- package/dist/digest-B3kc_PgQ.d.ts +19 -0
- package/dist/digest-BI-6aa6d.js +27 -0
- package/dist/doctor-BGle8Gqi.js +1314 -0
- package/dist/doctor-Bqo6FwUa.js +53 -0
- package/dist/drizzle/index.d.ts +72 -0
- package/dist/drizzle/index.js +160 -0
- package/dist/duration-xK2jGFVc.js +25 -0
- package/dist/elysia/index.d.ts +71 -0
- package/dist/elysia/index.js +103 -0
- package/dist/errors-DSMnAVNa.js +43 -0
- package/dist/errors-DbZ1YOnb.d.ts +138 -0
- package/dist/errors-Iy71s7Oj.js +177 -0
- package/dist/errors-m3u9TmDu.js +27 -0
- package/dist/evaluations-DsAU9ppl.js +479 -0
- package/dist/eve/index.d.ts +95 -0
- package/dist/eve/index.js +181 -0
- package/dist/express/index.d.ts +46 -0
- package/dist/express/index.js +108 -0
- package/dist/fastify/index.d.ts +56 -0
- package/dist/fastify/index.js +141 -0
- package/dist/files-B_wAGYmt.js +121 -0
- package/dist/fixtures-Cvaw0gDG.js +64 -0
- package/dist/freeze-y1_jQL4v.js +31 -0
- package/dist/from-snapshot-BMGnhmgv.js +552 -0
- package/dist/generate-CH7ThJ14.js +173 -0
- package/dist/grantee-Bv04_Vzf.js +521 -0
- package/dist/headers-B5RRv3Xm.js +6 -0
- package/dist/headers-C8SHQccD.d.ts +6 -0
- package/dist/helpers-DnSOrhB9.js +682 -0
- package/dist/hono/index.d.ts +70 -0
- package/dist/hono/index.js +131 -0
- package/dist/hosted-BwKQ1BTA.js +265 -0
- package/dist/http-DPuDaChb.d.ts +13 -0
- package/dist/http-GgVApX1k.js +111 -0
- package/dist/index-CltcQ4Bf.d.ts +138 -0
- package/dist/index-LF_hS-yn.d.ts +177 -0
- package/dist/index-fG6NSXlc.d.ts +9 -0
- package/dist/index-xIxJLwOQ.d.ts +415 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +21 -0
- package/dist/jwt/index.d.ts +87 -0
- package/dist/jwt/index.js +571 -0
- package/dist/kernel-YOGCWNLf.js +211 -0
- package/dist/kysely/index.d.ts +77 -0
- package/dist/kysely/index.js +129 -0
- package/dist/load-BZ24CpZP.js +69 -0
- package/dist/load-QOOm1z70.js +2 -0
- package/dist/load-jose-BL6LH4bL.js +11 -0
- package/dist/lru-8q4WZjBV.js +28 -0
- package/dist/manifest-DDQbC6K0.d.ts +118 -0
- package/dist/map-DowSO96j.js +158 -0
- package/dist/map-claims-B_6I1Rn-.js +360 -0
- package/dist/map-error-RJ3ZsUyA.js +16 -0
- package/dist/markers-B0hYLvMD.js +60 -0
- package/dist/may-use-CnFEjVEp.js +37 -0
- package/dist/mcp/index.d.ts +127 -0
- package/dist/mcp/index.js +563 -0
- package/dist/nest/index.d.ts +80 -0
- package/dist/nest/index.js +270 -0
- package/dist/next/client.d.ts +24 -0
- package/dist/next/client.js +31 -0
- package/dist/next/index.d.ts +110 -0
- package/dist/next/index.js +195 -0
- package/dist/next/plugin.d.ts +14 -0
- package/dist/next/plugin.js +2 -0
- package/dist/node/index.d.ts +43 -0
- package/dist/node/index.js +66 -0
- package/dist/openai/index.d.ts +71 -0
- package/dist/openai/index.js +105 -0
- package/dist/openapi/index.d.ts +93 -0
- package/dist/openapi/index.js +3 -0
- package/dist/openapi-CwePaF7C.js +164 -0
- package/dist/openapi-DWD0Uc_4.js +250 -0
- package/dist/openapi-DcqM8nU7.js +306 -0
- package/dist/openapi-import-BWRUNNeW.js +5959 -0
- package/dist/openapi-schema-D8j_T9tO.js +6902 -0
- package/dist/orpc/index.d.ts +64 -0
- package/dist/orpc/index.js +188 -0
- package/dist/otel/index.d.ts +13 -0
- package/dist/otel/index.js +202 -0
- package/dist/package-root-zGkxO3oN.js +30 -0
- package/dist/parse-DPfIvFMU.js +135 -0
- package/dist/pdp/index.d.ts +22 -0
- package/dist/pdp/index.js +795 -0
- package/dist/peer-BOr_kJE1.js +31 -0
- package/dist/permdock-yoZ7EjxX.js +2956 -0
- package/dist/permissions-B4apnahQ.d.ts +185 -0
- package/dist/permissions-B8vCg_bI.d.ts +52 -0
- package/dist/permissions-CofRqesP.js +142 -0
- package/dist/permissions-DC7GROPA.js +600 -0
- package/dist/pg-4GJWDUxG.js +953 -0
- package/dist/pins-CqE1jZuF.js +12 -0
- package/dist/plugin-4gr7IxFJ.js +65 -0
- package/dist/policy-ANp36PnI.js +971 -0
- package/dist/policy-CInmNGkM.d.ts +1959 -0
- package/dist/policy-Cq2fB8Q5.d.ts +20 -0
- package/dist/prisma/index.d.ts +135 -0
- package/dist/prisma/index.js +430 -0
- package/dist/problem-Cgp9-KZA.js +226 -0
- package/dist/prompt-CXYhLfsS.js +32 -0
- package/dist/protected-B4K3BKoX.js +138 -0
- package/dist/protected-BuPAycJT.d.ts +26 -0
- package/dist/protected-wY7nXhY9.d.ts +23 -0
- package/dist/provider-_wx46HpB.js +48 -0
- package/dist/provider-wTAUda2v.d.ts +6 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +6 -0
- package/dist/react/provider-client.d.ts +2 -0
- package/dist/react/provider-client.js +3 -0
- package/dist/react-native/index.d.ts +42 -0
- package/dist/react-native/index.js +174 -0
- package/dist/refs-ChLSxbST.js +90 -0
- package/dist/relations-r4soIFZB.js +426 -0
- package/dist/revocations-Cy06JNx2.d.ts +21 -0
- package/dist/rls-BOFU3chG.js +233 -0
- package/dist/rls-CJVja9Ww.js +2119 -0
- package/dist/rls-graph-DxQ39PJj.js +371 -0
- package/dist/rls-helpers-BxRuif0l.js +1346 -0
- package/dist/rls-import-CXV6LBlS.js +942 -0
- package/dist/rls-migrate-DrFPbf8p.js +366 -0
- package/dist/row-check-BajTgQZ-.d.ts +43 -0
- package/dist/run-CJ6UvS3a.js +155 -0
- package/dist/runtime-DP9ttFh1.js +27 -0
- package/dist/saas-BRrZzJkM.js +1193 -0
- package/dist/schema-P8yoma__.js +296 -0
- package/dist/scim/index.d.ts +2 -0
- package/dist/scim/index.js +2 -0
- package/dist/scim-9NFa0XVZ.js +1445 -0
- package/dist/scopes-cKVp_WTw.js +212 -0
- package/dist/server/index.d.ts +123 -0
- package/dist/server/index.js +8 -0
- package/dist/sha256-BO0swRXL.js +150 -0
- package/dist/sink-Bd9PSyfq.js +141 -0
- package/dist/sink-Cfr9-7YC.d.ts +104 -0
- package/dist/skills-C_lpV4Jx.js +50 -0
- package/dist/skills-Dx3QLnMY.js +110 -0
- package/dist/snapshot-DE8dE_hz.js +1051 -0
- package/dist/solid/index.d.ts +63 -0
- package/dist/solid/index.js +197 -0
- package/dist/source-DoBBYJi2.js +6 -0
- package/dist/sources-DOpW5Ila.d.ts +347 -0
- package/dist/sources-DVHM3Mwq.js +284 -0
- package/dist/sql-Bll1d7y0.js +22 -0
- package/dist/src-CTNT-PBW.js +430 -0
- package/dist/ssf/index.d.ts +3 -0
- package/dist/ssf/index.js +622 -0
- package/dist/store-Bq90395i.d.ts +27 -0
- package/dist/store-C6hFW6ta.js +508 -0
- package/dist/stores-CkG2HrSg.js +140 -0
- package/dist/stores-CvOnu_2T.d.ts +41 -0
- package/dist/stream-BhMfZOwr.d.ts +12 -0
- package/dist/stream-Q_xlB6Ko.js +52 -0
- package/dist/style-CTm1AXDT.js +22 -0
- package/dist/subject-C6dLxqHU.js +24 -0
- package/dist/subject-settings-xt7V845g.js +82 -0
- package/dist/supabase/index.d.ts +67 -0
- package/dist/supabase/index.js +4 -0
- package/dist/supabase/middleware.d.ts +77 -0
- package/dist/supabase/middleware.js +68 -0
- package/dist/supabase-D8UlBA7Z.js +83 -0
- package/dist/supabase-DTxGtYdi.js +796 -0
- package/dist/supabase-hook-DW-xP4hU.js +2 -0
- package/dist/supabase-hook-D_OqGb_V.js +1528 -0
- package/dist/svelte/Protected.svelte +34 -0
- package/dist/svelte/index.d.ts +10 -0
- package/dist/svelte/index.js +53 -0
- package/dist/svelte/runtime.d.ts +6 -0
- package/dist/svelte/runtime.js +3 -0
- package/dist/svelte/source.d.ts +10 -0
- package/dist/svelte/source.js +8 -0
- package/dist/terminal/index.d.ts +171 -0
- package/dist/terminal/index.js +821 -0
- package/dist/testing/index.d.ts +656 -0
- package/dist/testing/index.js +3208 -0
- package/dist/testing/saas/index.d.ts +194 -0
- package/dist/testing/saas/index.js +3 -0
- package/dist/testing/saas/permissions.d.ts +2 -0
- package/dist/testing/saas/permissions.js +2 -0
- package/dist/text-diff-BdkkYSbi.js +15 -0
- package/dist/thenable-okc2xDsj.js +10 -0
- package/dist/timeout-D51niuQP.js +8 -0
- package/dist/trpc/index.d.ts +80 -0
- package/dist/trpc/index.js +205 -0
- package/dist/types-B8w5PFtS.d.ts +141 -0
- package/dist/types-B9dmiiab.d.ts +66 -0
- package/dist/types-BBK-exvJ.d.ts +177 -0
- package/dist/types-BvBk1wgn.d.ts +118 -0
- package/dist/types-CxquUByI.d.ts +9 -0
- package/dist/types-D6Z6-rKJ.d.ts +312 -0
- package/dist/types-DbWdEfcm.d.ts +87 -0
- package/dist/types-bva3i4Gf.d.ts +98 -0
- package/dist/types-i4BAOvdb.d.ts +97 -0
- package/dist/unplugin/index.d.ts +7 -0
- package/dist/unplugin/index.js +30 -0
- package/dist/usage-1ozMubLY.js +42 -0
- package/dist/usage-CUnK6Ou9.js +530 -0
- package/dist/usage-PyEor6GA.js +2 -0
- package/dist/validity-D0uRmJKJ.js +224 -0
- package/dist/verifier-B90agnhl.js +461 -0
- package/dist/version-CnSh33Fj.js +16 -0
- package/dist/vocabulary-Dk0fs-Jk.d.ts +56 -0
- package/dist/vue/index.d.ts +57 -0
- package/dist/vue/index.js +203 -0
- package/dist/webmcp/index.d.ts +75 -0
- package/dist/webmcp/index.js +313 -0
- package/package.json +423 -4
- package/rulesets/permdock.yaml +29 -0
- package/schemas/catalog-v1.json +507 -0
- package/schemas/openapi/oas-3.1.json +1298 -0
- package/schemas/openapi/oas-3.2.json +1516 -0
- package/schemas/openapi/overlay-1.1.json +79 -0
- package/schemas/supabase-claims-v1.json +139 -0
- package/schemas/supabase-manifest-v1.json +217 -0
- package/skills/permdock/SKILL.md +66 -0
- package/skills/permdock-agents/SKILL.md +77 -0
- package/skills/permdock-agents/references/runtimes.md +211 -0
- package/skills/permdock-approvals/SKILL.md +80 -0
- package/skills/permdock-approvals/references/stores-and-resume.md +83 -0
- package/skills/permdock-audit/SKILL.md +67 -0
- package/skills/permdock-credentials/SKILL.md +55 -0
- package/skills/permdock-credentials/references/tokens-keys-links.md +127 -0
- package/skills/permdock-data/SKILL.md +57 -0
- package/skills/permdock-data/references/queries-and-rls.md +54 -0
- package/skills/permdock-data/references/relationships.md +65 -0
- package/skills/permdock-tenancy/SKILL.md +77 -0
- package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +83 -0
- package/skills/permdock-wire/SKILL.md +116 -0
- package/skills/permdock-wire/references/adapters.md +480 -0
- package/skills/permdock-wire/references/policy-options.md +43 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { t as compact } from "../compact-y6vfu2_f.js";
|
|
2
|
+
import { n as PermDockDeniedError, t as PermDockApprovalRequiredError } from "../errors-Iy71s7Oj.js";
|
|
3
|
+
import { l as canonicalJson } from "../snapshot-DE8dE_hz.js";
|
|
4
|
+
import { t as bytesToBase64Url } from "../sha256-BO0swRXL.js";
|
|
5
|
+
import { t as createPermDock$1 } from "../permdock-yoZ7EjxX.js";
|
|
6
|
+
import { t as mayUse } from "../may-use-CnFEjVEp.js";
|
|
7
|
+
import { l as storedApprovalToken, s as resumeDecision } from "../helpers-DnSOrhB9.js";
|
|
8
|
+
import { r as bearerChallenge } from "../problem-Cgp9-KZA.js";
|
|
9
|
+
//#region src/a2a/create.ts
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function firstScheme(options) {
|
|
14
|
+
return Object.keys(options.securitySchemes)[0];
|
|
15
|
+
}
|
|
16
|
+
function skillOf(id, config, scheme) {
|
|
17
|
+
return {
|
|
18
|
+
id,
|
|
19
|
+
name: id,
|
|
20
|
+
description: config.description ?? config.permission.key,
|
|
21
|
+
tags: config.tags ?? [config.permission.resource],
|
|
22
|
+
securityRequirements: scheme === void 0 ? [] : [{ schemes: { [scheme]: { list: [config.permission.scope] } } }]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function publicSkills(options) {
|
|
26
|
+
const scheme = firstScheme(options);
|
|
27
|
+
return Object.entries(options.skills).map(([id, config]) => skillOf(id, config, scheme));
|
|
28
|
+
}
|
|
29
|
+
function wireScheme(scheme) {
|
|
30
|
+
switch (scheme.type) {
|
|
31
|
+
case "oauth2": return { oauth2SecurityScheme: compact({
|
|
32
|
+
oauth2MetadataUrl: scheme.oauth2MetadataUrl,
|
|
33
|
+
description: scheme.description
|
|
34
|
+
}) };
|
|
35
|
+
case "http": return { httpAuthSecurityScheme: compact({
|
|
36
|
+
scheme: scheme.scheme,
|
|
37
|
+
bearerFormat: scheme.bearerFormat,
|
|
38
|
+
description: scheme.description
|
|
39
|
+
}) };
|
|
40
|
+
case "openIdConnect": return { openIdConnectSecurityScheme: compact({
|
|
41
|
+
openIdConnectUrl: scheme.openIdConnectUrl,
|
|
42
|
+
description: scheme.description
|
|
43
|
+
}) };
|
|
44
|
+
case "mutualTLS": return { mtlsSecurityScheme: compact({ description: scheme.description }) };
|
|
45
|
+
case "apiKey": return { apiKeySecurityScheme: compact({
|
|
46
|
+
location: scheme.in,
|
|
47
|
+
name: scheme.name,
|
|
48
|
+
description: scheme.description
|
|
49
|
+
}) };
|
|
50
|
+
default: return scheme;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function cardOf(options, skills) {
|
|
54
|
+
const info = options.card;
|
|
55
|
+
return compact({
|
|
56
|
+
name: info.name,
|
|
57
|
+
description: info.description ?? info.name,
|
|
58
|
+
version: info.version,
|
|
59
|
+
supportedInterfaces: [{
|
|
60
|
+
url: info.url,
|
|
61
|
+
protocolBinding: info.protocolBinding ?? "JSONRPC",
|
|
62
|
+
protocolVersion: "1.0"
|
|
63
|
+
}],
|
|
64
|
+
provider: info.provider,
|
|
65
|
+
documentationUrl: info.documentationUrl,
|
|
66
|
+
iconUrl: info.iconUrl,
|
|
67
|
+
capabilities: compact({
|
|
68
|
+
extendedAgentCard: true,
|
|
69
|
+
streaming: info.streaming,
|
|
70
|
+
pushNotifications: info.pushNotifications
|
|
71
|
+
}),
|
|
72
|
+
defaultInputModes: info.defaultInputModes ?? DEFAULT_MODES,
|
|
73
|
+
defaultOutputModes: info.defaultOutputModes ?? DEFAULT_MODES,
|
|
74
|
+
securitySchemes: Object.fromEntries(Object.entries(options.securitySchemes).map(([name, scheme]) => [name, wireScheme(scheme)])),
|
|
75
|
+
skills
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const DEFAULT_MODES = ["text/plain"];
|
|
79
|
+
function delegationOf(auth) {
|
|
80
|
+
return compact({
|
|
81
|
+
scopes: auth.scopes,
|
|
82
|
+
authorizationDetails: auth.extra?.authorizationDetails
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function actorOf(auth) {
|
|
86
|
+
return typeof auth.clientId === "string" && auth.clientId !== "" ? {
|
|
87
|
+
id: auth.clientId,
|
|
88
|
+
kind: "oauth-client"
|
|
89
|
+
} : void 0;
|
|
90
|
+
}
|
|
91
|
+
async function resolveTenant(tenant, auth) {
|
|
92
|
+
if (tenant === void 0 || typeof tenant === "string") return tenant;
|
|
93
|
+
try {
|
|
94
|
+
return await tenant(auth);
|
|
95
|
+
} catch {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function hasScope(auth, scope) {
|
|
100
|
+
return auth.scopes?.includes(scope) === true;
|
|
101
|
+
}
|
|
102
|
+
function resourceRef(permission, data) {
|
|
103
|
+
if (!isRecord(data)) return { type: permission.resource };
|
|
104
|
+
const id = data["id"];
|
|
105
|
+
return typeof id === "string" || typeof id === "number" ? {
|
|
106
|
+
type: permission.resource,
|
|
107
|
+
id: String(id)
|
|
108
|
+
} : { type: permission.resource };
|
|
109
|
+
}
|
|
110
|
+
const LOAD_FAILED = {
|
|
111
|
+
outcome: "denied",
|
|
112
|
+
denials: [{
|
|
113
|
+
role: null,
|
|
114
|
+
reason: "validation"
|
|
115
|
+
}],
|
|
116
|
+
alternatives: []
|
|
117
|
+
};
|
|
118
|
+
function deniedOutcome(decision, permission, data, permdock) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
status: 403,
|
|
122
|
+
state: "failed",
|
|
123
|
+
problem: new PermDockDeniedError({
|
|
124
|
+
decision,
|
|
125
|
+
permission: permission.key,
|
|
126
|
+
scope: permission.scope,
|
|
127
|
+
resource: resourceRef(permission, data),
|
|
128
|
+
subject: permdock.subject,
|
|
129
|
+
message: `${permission.key} denied.`
|
|
130
|
+
}).toProblemDetails()
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function approvalOutcome(decision, permission, data) {
|
|
134
|
+
return {
|
|
135
|
+
ok: false,
|
|
136
|
+
status: 403,
|
|
137
|
+
state: "input-required",
|
|
138
|
+
problem: new PermDockApprovalRequiredError({
|
|
139
|
+
decision,
|
|
140
|
+
permission: permission.key,
|
|
141
|
+
scope: permission.scope,
|
|
142
|
+
resource: resourceRef(permission, data),
|
|
143
|
+
message: `${permission.key} requires human approval.`
|
|
144
|
+
}).toProblemDetails()
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** A2A 1.0 section 8.4: a detached JWS over the RFC 8785 form of the card. */
|
|
148
|
+
async function signCard(card, signPayload) {
|
|
149
|
+
const { signatures = [], ...unsigned } = card;
|
|
150
|
+
const payload = canonicalJson(unsigned);
|
|
151
|
+
const [header, body, signature, extra] = (await signPayload(payload)).split(".");
|
|
152
|
+
if (header === void 0 || signature === void 0 || extra !== void 0 || body !== bytesToBase64Url(new TextEncoder().encode(payload))) throw new TypeError("PermDock: an A2A card signer must return a compact JWS over the payload it was given");
|
|
153
|
+
return {
|
|
154
|
+
...card,
|
|
155
|
+
signatures: [...signatures, {
|
|
156
|
+
protected: header,
|
|
157
|
+
signature
|
|
158
|
+
}]
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function missingScope(permission) {
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
status: 401,
|
|
165
|
+
state: "failed",
|
|
166
|
+
problem: {
|
|
167
|
+
type: "https://permdock.dev/problems/unauthenticated",
|
|
168
|
+
title: "Insufficient scope",
|
|
169
|
+
status: 401,
|
|
170
|
+
detail: `insufficient_scope: ${permission.scope}`,
|
|
171
|
+
permission: permission.key,
|
|
172
|
+
scope: permission.scope
|
|
173
|
+
},
|
|
174
|
+
wwwAuthenticate: bearerChallenge({
|
|
175
|
+
error: "insufficient_scope",
|
|
176
|
+
scopes: [permission.scope]
|
|
177
|
+
})
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function createPermDock(policy, options) {
|
|
181
|
+
for (const [id, config] of Object.entries(options.skills)) if (config.permission.kind === "instance" && config.data === void 0) throw new TypeError(`PermDock: A2A skill '${id}' checks ${config.permission.key} on a row and needs a data loader; the task body is never used as the row`);
|
|
182
|
+
const instanceFor = async (auth) => {
|
|
183
|
+
let user = null;
|
|
184
|
+
try {
|
|
185
|
+
user = await options.subject(auth);
|
|
186
|
+
} catch {
|
|
187
|
+
user = null;
|
|
188
|
+
}
|
|
189
|
+
const tenant = await resolveTenant(options.tenant, auth);
|
|
190
|
+
return createPermDock$1(policy, user, compact({
|
|
191
|
+
tenant,
|
|
192
|
+
actor: actorOf(auth),
|
|
193
|
+
delegation: delegationOf(auth),
|
|
194
|
+
memberships: options.memberships,
|
|
195
|
+
relations: options.relations,
|
|
196
|
+
entitlements: options.entitlements,
|
|
197
|
+
customRoles: options.customRoles,
|
|
198
|
+
policies: options.policies,
|
|
199
|
+
sink: options.sink,
|
|
200
|
+
limits: options.limits
|
|
201
|
+
}));
|
|
202
|
+
};
|
|
203
|
+
const agentCard = () => cardOf(options, publicSkills(options));
|
|
204
|
+
const extendedAgentCard = async (auth) => {
|
|
205
|
+
const permdock = await instanceFor(auth);
|
|
206
|
+
const scheme = firstScheme(options);
|
|
207
|
+
const skills = [];
|
|
208
|
+
for (const [id, config] of Object.entries(options.skills)) if (mayUse(permdock, config.permission)) skills.push(skillOf(id, config, scheme));
|
|
209
|
+
return cardOf(options, skills);
|
|
210
|
+
};
|
|
211
|
+
const protectSkill = (selector) => async (task, auth) => {
|
|
212
|
+
const id = selector(task);
|
|
213
|
+
const config = Object.hasOwn(options.skills, id) ? options.skills[id] : void 0;
|
|
214
|
+
if (config === void 0) return {
|
|
215
|
+
ok: false,
|
|
216
|
+
status: 403,
|
|
217
|
+
state: "failed",
|
|
218
|
+
problem: {
|
|
219
|
+
type: "https://permdock.dev/problems/denied",
|
|
220
|
+
title: "Permission denied",
|
|
221
|
+
status: 403,
|
|
222
|
+
detail: "unknown skill"
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
if (!hasScope(auth, config.permission.scope)) return missingScope(config.permission);
|
|
226
|
+
const permdock = await instanceFor(auth);
|
|
227
|
+
let data;
|
|
228
|
+
if (config.data !== void 0) {
|
|
229
|
+
try {
|
|
230
|
+
data = await config.data(task);
|
|
231
|
+
} catch {
|
|
232
|
+
return deniedOutcome(LOAD_FAILED, config.permission, void 0, permdock);
|
|
233
|
+
}
|
|
234
|
+
if (config.permission.kind === "instance" && (data === null || data === void 0)) return deniedOutcome(LOAD_FAILED, config.permission, void 0, permdock);
|
|
235
|
+
}
|
|
236
|
+
let decision;
|
|
237
|
+
try {
|
|
238
|
+
const raw = permdock.decide(config.permission, data, compact({
|
|
239
|
+
source: "adapter",
|
|
240
|
+
adapter: "a2a",
|
|
241
|
+
trusted: false,
|
|
242
|
+
boundary: "tool-args"
|
|
243
|
+
}));
|
|
244
|
+
decision = await resumeDecision({
|
|
245
|
+
decision: raw,
|
|
246
|
+
permission: config.permission,
|
|
247
|
+
subject: permdock.subject,
|
|
248
|
+
store: options.store,
|
|
249
|
+
resource: resourceRef(config.permission, data),
|
|
250
|
+
adapter: "a2a",
|
|
251
|
+
token: auth.extra?.approval ?? await storedApprovalToken(options.store, raw, false)
|
|
252
|
+
});
|
|
253
|
+
} catch {
|
|
254
|
+
return deniedOutcome(LOAD_FAILED, config.permission, data, permdock);
|
|
255
|
+
}
|
|
256
|
+
switch (decision.outcome) {
|
|
257
|
+
case "granted": return { ok: true };
|
|
258
|
+
case "denied": return deniedOutcome(decision, config.permission, data, permdock);
|
|
259
|
+
case "approval-required": return approvalOutcome(decision, config.permission, data);
|
|
260
|
+
default: return decision;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
agentCard,
|
|
265
|
+
extendedAgentCard,
|
|
266
|
+
protectSkill,
|
|
267
|
+
sign: signCard
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
export { createPermDock };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { $ as DecisionSink, C as Policy, at as LimitStore, ct as MembershipSource, ft as RelationSource, mr as Principal, pt as RoleSource, sn as PolicySource, tt as EntitlementSource, ur as Delegation, xt as SnapshotSource } from "../policy-CInmNGkM.js";
|
|
2
|
+
import { d as Permission } from "../permissions-B4apnahQ.js";
|
|
3
|
+
import { f as ApprovalStore } from "../types-B8w5PFtS.js";
|
|
4
|
+
import { t as ToolMap } from "../types-CxquUByI.js";
|
|
5
|
+
//#region src/ai-sdk/create.d.ts
|
|
6
|
+
type AiSdkContext = {
|
|
7
|
+
readonly runtimeContext?: unknown;
|
|
8
|
+
readonly permdockApproval?: string;
|
|
9
|
+
readonly [key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
type AiSdkPermDockOptions<TUser = unknown> = {
|
|
12
|
+
readonly subject: (context: AiSdkContext) => TUser | Promise<TUser>;
|
|
13
|
+
readonly actor?: (context: AiSdkContext) => unknown;
|
|
14
|
+
readonly delegation?: (context: AiSdkContext) => Delegation | undefined | Promise<Delegation | undefined>;
|
|
15
|
+
readonly tenant?: string | ((context: AiSdkContext) => string | undefined | Promise<string | undefined>);
|
|
16
|
+
readonly tools: ToolMap;
|
|
17
|
+
readonly memberships?: MembershipSource | readonly MembershipSource[];
|
|
18
|
+
/** The object graph for relation grants that walk a parent chain; without it they deny. */
|
|
19
|
+
readonly relations?: RelationSource;
|
|
20
|
+
readonly entitlements?: EntitlementSource;
|
|
21
|
+
readonly customRoles?: RoleSource;
|
|
22
|
+
/** Hosted grants, read once per instance; see `PolicySource`. */
|
|
23
|
+
readonly policies?: PolicySource;
|
|
24
|
+
readonly store?: ApprovalStore;
|
|
25
|
+
readonly sink?: DecisionSink;
|
|
26
|
+
readonly limits?: LimitStore;
|
|
27
|
+
readonly snapshots?: SnapshotSource;
|
|
28
|
+
};
|
|
29
|
+
type ToolApprovalStatus = "approved" | {
|
|
30
|
+
readonly type: "denied";
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "user-approval";
|
|
34
|
+
readonly reason: string;
|
|
35
|
+
readonly token: string;
|
|
36
|
+
};
|
|
37
|
+
/** Structural `GenericToolApprovalFunction` options from `ai`. */
|
|
38
|
+
type ToolApprovalCall = {
|
|
39
|
+
readonly toolCall: {
|
|
40
|
+
readonly toolName: string;
|
|
41
|
+
readonly toolCallId?: string;
|
|
42
|
+
readonly input?: unknown;
|
|
43
|
+
};
|
|
44
|
+
readonly messages?: readonly unknown[];
|
|
45
|
+
readonly runtimeContext?: unknown;
|
|
46
|
+
};
|
|
47
|
+
/** Structural `ToolNeedsApprovalFunction` options from `ai`. */
|
|
48
|
+
type NeedsApprovalOptions = {
|
|
49
|
+
readonly toolCallId?: string;
|
|
50
|
+
readonly messages?: readonly unknown[];
|
|
51
|
+
readonly context?: unknown;
|
|
52
|
+
};
|
|
53
|
+
type CallParams = {
|
|
54
|
+
readonly tools?: readonly {
|
|
55
|
+
readonly name?: string;
|
|
56
|
+
}[];
|
|
57
|
+
readonly toolChoice?: unknown;
|
|
58
|
+
};
|
|
59
|
+
/** Structural `LanguageModelMiddleware` (specification `v4`) from `ai`. */
|
|
60
|
+
type LanguageModelMiddleware = {
|
|
61
|
+
readonly specificationVersion: "v4";
|
|
62
|
+
readonly transformParams: <TParams extends CallParams>(options: {
|
|
63
|
+
readonly params: TParams;
|
|
64
|
+
}) => Promise<TParams>;
|
|
65
|
+
};
|
|
66
|
+
type AiSdkPermDock = {
|
|
67
|
+
readonly toolApproval: (call: ToolApprovalCall) => Promise<ToolApprovalStatus>;
|
|
68
|
+
/** Hides tools the subject in `context` can never use, before the model sees them. */
|
|
69
|
+
readonly capabilityMiddleware: (context: AiSdkContext) => LanguageModelMiddleware;
|
|
70
|
+
readonly needsApproval: (permission: Permission) => (input: unknown, options?: NeedsApprovalOptions) => Promise<boolean>;
|
|
71
|
+
};
|
|
72
|
+
export declare function createPermDock<TUser, TPrincipal extends Principal = Principal>(policy: Policy<TUser, TPrincipal>, options: AiSdkPermDockOptions<TUser>): AiSdkPermDock;
|
|
73
|
+
//#endregion
|
|
74
|
+
export type { AiSdkContext, AiSdkPermDock, AiSdkPermDockOptions, LanguageModelMiddleware, NeedsApprovalOptions, ToolApprovalCall, ToolApprovalStatus };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { t as compact } from "../compact-y6vfu2_f.js";
|
|
2
|
+
import { n as PermDockDeniedError, t as PermDockApprovalRequiredError } from "../errors-Iy71s7Oj.js";
|
|
3
|
+
import { n as createAgentKernel, t as approvalTokenOf } from "../kernel-YOGCWNLf.js";
|
|
4
|
+
//#region src/ai-sdk/create.ts
|
|
5
|
+
function contextOf(call) {
|
|
6
|
+
const runtime = call.runtimeContext !== null && typeof call.runtimeContext === "object" ? call.runtimeContext : {};
|
|
7
|
+
return compact({
|
|
8
|
+
...runtime,
|
|
9
|
+
runtimeContext: call.runtimeContext
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function toolContextOf(options) {
|
|
13
|
+
const tool = options.context !== null && typeof options.context === "object" ? options.context : {};
|
|
14
|
+
return compact({
|
|
15
|
+
...tool,
|
|
16
|
+
toolContext: options.context
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether `messages` already carry an approval request for `toolCallId`: the
|
|
21
|
+
* SDK is re-checking a call a user approved, and treats any answer other
|
|
22
|
+
* than `denied` as approval.
|
|
23
|
+
*/
|
|
24
|
+
function isRecheck(messages, toolCallId) {
|
|
25
|
+
if (!Array.isArray(messages) || typeof toolCallId !== "string") return false;
|
|
26
|
+
return messages.some((message) => {
|
|
27
|
+
if (typeof message !== "object" || message === null) return false;
|
|
28
|
+
const { role, content } = message;
|
|
29
|
+
return role === "assistant" && Array.isArray(content) && content.some((part) => typeof part === "object" && part !== null && part.type === "tool-approval-request" && part.toolCallId === toolCallId);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function resourceOf(permission, data) {
|
|
33
|
+
const id = typeof data === "object" && data !== null ? data.id : void 0;
|
|
34
|
+
return typeof id === "string" || typeof id === "number" ? {
|
|
35
|
+
type: permission.resource,
|
|
36
|
+
id: String(id)
|
|
37
|
+
} : { type: permission.resource };
|
|
38
|
+
}
|
|
39
|
+
function deniedError(verdict, permission, permdock) {
|
|
40
|
+
return new PermDockDeniedError({
|
|
41
|
+
decision: verdict.decision ?? {
|
|
42
|
+
outcome: "denied",
|
|
43
|
+
denials: [],
|
|
44
|
+
alternatives: []
|
|
45
|
+
},
|
|
46
|
+
permission: permission.key,
|
|
47
|
+
scope: permission.scope,
|
|
48
|
+
resource: { type: permission.resource },
|
|
49
|
+
subject: permdock.subject,
|
|
50
|
+
message: verdict.reason
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function createPermDock(policy, options) {
|
|
54
|
+
const kernel = createAgentKernel(policy, {
|
|
55
|
+
...compact({
|
|
56
|
+
actor: options.actor,
|
|
57
|
+
delegation: options.delegation,
|
|
58
|
+
tenant: options.tenant,
|
|
59
|
+
memberships: options.memberships,
|
|
60
|
+
relations: options.relations,
|
|
61
|
+
entitlements: options.entitlements,
|
|
62
|
+
customRoles: options.customRoles,
|
|
63
|
+
policies: options.policies,
|
|
64
|
+
store: options.store,
|
|
65
|
+
sink: options.sink,
|
|
66
|
+
limits: options.limits,
|
|
67
|
+
snapshots: options.snapshots
|
|
68
|
+
}),
|
|
69
|
+
subject: options.subject,
|
|
70
|
+
tools: options.tools,
|
|
71
|
+
adapter: "ai-sdk"
|
|
72
|
+
});
|
|
73
|
+
const byPermission = /* @__PURE__ */ new Map();
|
|
74
|
+
for (const [name, binding] of Object.entries(options.tools)) byPermission.set(binding.permission.key, name);
|
|
75
|
+
const decide = (toolName, args, context) => kernel.decideTool(toolName, args, context, compact({ resumeToken: approvalTokenOf(context) }));
|
|
76
|
+
const toolApproval = async (call) => {
|
|
77
|
+
const context = contextOf(call);
|
|
78
|
+
const verdict = await decide(call.toolCall.toolName, call.toolCall.input, context);
|
|
79
|
+
if (verdict.outcome === "granted") return "approved";
|
|
80
|
+
if (verdict.outcome === "denied") return {
|
|
81
|
+
type: "denied",
|
|
82
|
+
reason: verdict.reason
|
|
83
|
+
};
|
|
84
|
+
if (isRecheck(call.messages, call.toolCall.toolCallId)) return {
|
|
85
|
+
type: "denied",
|
|
86
|
+
reason: `${verdict.summary} No approval is recorded for this call.`
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
type: "user-approval",
|
|
90
|
+
reason: verdict.summary,
|
|
91
|
+
token: verdict.token
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const capabilityMiddleware = (context) => ({
|
|
95
|
+
specificationVersion: "v4",
|
|
96
|
+
transformParams: async ({ params }) => {
|
|
97
|
+
if (params.tools === void 0) return params;
|
|
98
|
+
const allowed = await kernel.allowedToolNames(context);
|
|
99
|
+
const tools = params.tools.filter((tool) => typeof tool.name === "string" && allowed.has(tool.name));
|
|
100
|
+
const choice = params.toolChoice;
|
|
101
|
+
const forcedAway = choice?.type === "tool" && !(typeof choice.toolName === "string" && allowed.has(choice.toolName));
|
|
102
|
+
return {
|
|
103
|
+
...params,
|
|
104
|
+
tools,
|
|
105
|
+
...forcedAway ? { toolChoice: { type: "none" } } : {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const needsApproval = (permission) => async (input, needsOptions = {}) => {
|
|
110
|
+
const context = toolContextOf(needsOptions);
|
|
111
|
+
const toolName = byPermission.get(permission.key);
|
|
112
|
+
if (toolName === void 0) throw deniedError({
|
|
113
|
+
outcome: "denied",
|
|
114
|
+
decision: null,
|
|
115
|
+
permission,
|
|
116
|
+
reason: `${permission.key} is not bound to a tool.`
|
|
117
|
+
}, permission, await kernel.instance(context));
|
|
118
|
+
const verdict = await decide(toolName, input, context);
|
|
119
|
+
if (verdict.outcome === "granted") return false;
|
|
120
|
+
if (verdict.outcome === "denied") throw deniedError(verdict, permission, await kernel.instance(context));
|
|
121
|
+
if (isRecheck(needsOptions.messages, needsOptions.toolCallId)) throw new PermDockApprovalRequiredError({
|
|
122
|
+
decision: verdict.decision,
|
|
123
|
+
permission: permission.key,
|
|
124
|
+
scope: permission.scope,
|
|
125
|
+
resource: resourceOf(permission, verdict.data),
|
|
126
|
+
message: `${verdict.summary} No approval is recorded for this call.`
|
|
127
|
+
});
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
toolApproval,
|
|
132
|
+
capabilityMiddleware,
|
|
133
|
+
needsApproval
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
export { createPermDock };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as approverRelationKey, a as ApprovalListFilter, c as ApprovalRequest, d as ApprovalStatus, f as ApprovalStore, g as approvalQuorum, h as DEFAULT_APPROVAL_TTL_MS, i as ApprovalInspectResult, l as ApprovalResumeFailure, m as ApprovalVerdict, n as ApprovalApprovers, o as ApprovalListQuery, p as ApprovalSubjectSummary, r as ApprovalCancelMeta, s as ApprovalPage, t as APPROVAL_HEADER, u as ApprovalSignature, v as escalationOpenAt } from "../types-B8w5PFtS.js";
|
|
2
|
+
import { _ as approvalsHandler, a as cancelApprovals, b as isApprovalError, c as readApprovalHeader, d as resumeDecision, f as resumeFromHeader, g as ApprovalsHandlerOptions, h as approverRelations, i as memoryApprovalStore, l as requestApproval, m as ApproverRelationsOptions, n as applyApprovalVerdict, o as consumeApproval, p as summariseSubject, r as assertApprover, s as inspectApproval, t as MemoryApprovalStore, u as resolveApproval, v as ApprovalError, y as ApprovalErrorCode } from "../index-CltcQ4Bf.js";
|
|
3
|
+
export { APPROVAL_HEADER, type ApprovalApprovers, type ApprovalCancelMeta, ApprovalError, type ApprovalErrorCode, type ApprovalInspectResult, type ApprovalListFilter, type ApprovalListQuery, type ApprovalPage, type ApprovalRequest, type ApprovalResumeFailure, type ApprovalSignature, type ApprovalStatus, type ApprovalStore, type ApprovalSubjectSummary, type ApprovalVerdict, type ApprovalsHandlerOptions, type ApproverRelationsOptions, DEFAULT_APPROVAL_TTL_MS, type MemoryApprovalStore, applyApprovalVerdict, approvalQuorum, approvalsHandler, approverRelationKey, approverRelations, assertApprover, cancelApprovals, consumeApproval, escalationOpenAt, inspectApproval, isApprovalError, memoryApprovalStore, readApprovalHeader, requestApproval, resolveApproval, resumeDecision, resumeFromHeader, summariseSubject };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as isApprovalError, t as ApprovalError } from "../errors-m3u9TmDu.js";
|
|
2
|
+
import { _ as approvalQuorum, a as requestApproval, c as resumeFromHeader, d as applyApprovalVerdict, f as assertApprover, g as DEFAULT_APPROVAL_TTL_MS, h as APPROVAL_HEADER, i as readApprovalHeader, m as approverRelations, n as consumeApproval, o as resolveApproval, p as memoryApprovalStore, r as inspectApproval, s as resumeDecision, t as cancelApprovals, u as summariseSubject, v as approverRelationKey, y as escalationOpenAt } from "../helpers-DnSOrhB9.js";
|
|
3
|
+
import { t as approvalsHandler } from "../approvals-DaxY-Bdg.js";
|
|
4
|
+
export { APPROVAL_HEADER, ApprovalError, DEFAULT_APPROVAL_TTL_MS, applyApprovalVerdict, approvalQuorum, approvalsHandler, approverRelationKey, approverRelations, assertApprover, cancelApprovals, consumeApproval, escalationOpenAt, inspectApproval, isApprovalError, memoryApprovalStore, readApprovalHeader, requestApproval, resolveApproval, resumeDecision, resumeFromHeader, summariseSubject };
|