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,313 @@
|
|
|
1
|
+
import { t as compact } from "../compact-y6vfu2_f.js";
|
|
2
|
+
import { b as resourceOfNode, g as listPermissions, m as isRegistryTree, s as getRegistry, t as annotationsFor } from "../permissions-DC7GROPA.js";
|
|
3
|
+
import { t as describe } from "../describe-Bt1YD5uS.js";
|
|
4
|
+
import { i as PermDockValidationError, s as wireDenials } from "../errors-Iy71s7Oj.js";
|
|
5
|
+
import { n as isThenable, t as ignoreRejection } from "../thenable-okc2xDsj.js";
|
|
6
|
+
//#region src/webmcp/register.ts
|
|
7
|
+
const MISSING_CONTEXT = "permdock/webmcp: document.modelContext is absent; registerTools is a no-op.";
|
|
8
|
+
function isRecord(value) {
|
|
9
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
const CURRENT = Symbol.for("permdock.current");
|
|
12
|
+
function current(permdock) {
|
|
13
|
+
const latest = permdock[CURRENT];
|
|
14
|
+
return typeof latest === "function" ? latest() : permdock;
|
|
15
|
+
}
|
|
16
|
+
function snapshotOf(permdock) {
|
|
17
|
+
const value = permdock.snapshot();
|
|
18
|
+
if (value instanceof Promise || typeof value === "string") return;
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function toolName(permission) {
|
|
22
|
+
return permission.key.replaceAll(".", "_");
|
|
23
|
+
}
|
|
24
|
+
function untrustedHint(permission, fallback) {
|
|
25
|
+
if (permission.meta.tags?.includes("untrusted") === true) return true;
|
|
26
|
+
return fallback === true;
|
|
27
|
+
}
|
|
28
|
+
function schemaFor(group, permission, option) {
|
|
29
|
+
if (option !== void 0 || "key" in group || permission.kind !== "instance") return option;
|
|
30
|
+
if (isRegistryTree(group)) return getRegistry(group).get(permission.resource)?.schema;
|
|
31
|
+
return resourceIn(group, permission.resource)?.schema;
|
|
32
|
+
}
|
|
33
|
+
function resourceIn(group, name) {
|
|
34
|
+
const own = resourceOfNode(group);
|
|
35
|
+
if (own !== void 0) return own.name === name ? own : void 0;
|
|
36
|
+
for (const child of Object.values(group)) if (!("key" in child)) {
|
|
37
|
+
const found = resourceIn(child, name);
|
|
38
|
+
if (found !== void 0) return found;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function jsonSchemaOf(schema) {
|
|
42
|
+
if (schema === void 0) return;
|
|
43
|
+
const standard = schema["~standard"];
|
|
44
|
+
const converter = standard.jsonSchema;
|
|
45
|
+
if (typeof converter?.input === "function") try {
|
|
46
|
+
const converted = converter.input({ target: "draft-2020-12" });
|
|
47
|
+
if (isRecord(converted)) return converted;
|
|
48
|
+
} catch {
|
|
49
|
+
return { type: "object" };
|
|
50
|
+
}
|
|
51
|
+
if (isRecord(standard.jsonSchema) && converter?.input === void 0) return standard.jsonSchema;
|
|
52
|
+
return { type: "object" };
|
|
53
|
+
}
|
|
54
|
+
function validateInput(schema, args, permission) {
|
|
55
|
+
if (schema === void 0) return args;
|
|
56
|
+
const result = schema["~standard"].validate(args);
|
|
57
|
+
if (isThenable(result)) {
|
|
58
|
+
ignoreRejection(result);
|
|
59
|
+
throw new PermDockValidationError({
|
|
60
|
+
code: "async-schema",
|
|
61
|
+
permission: permission.key,
|
|
62
|
+
resource: permission.resource,
|
|
63
|
+
boundary: "webmcp-args",
|
|
64
|
+
message: `${permission.key}: inputSchema is async.`,
|
|
65
|
+
issues: []
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const sync = result;
|
|
69
|
+
if ("issues" in sync && sync.issues !== void 0) throw new PermDockValidationError({
|
|
70
|
+
code: "invalid-data",
|
|
71
|
+
permission: permission.key,
|
|
72
|
+
resource: permission.resource,
|
|
73
|
+
boundary: "webmcp-args",
|
|
74
|
+
message: `${permission.key}: invalid tool arguments.`,
|
|
75
|
+
issues: [...sync.issues]
|
|
76
|
+
});
|
|
77
|
+
return "value" in sync ? sync.value : args;
|
|
78
|
+
}
|
|
79
|
+
function bindTenant(input, tenantKey, tenant) {
|
|
80
|
+
if (tenantKey === void 0 || tenant === void 0) return {
|
|
81
|
+
ok: true,
|
|
82
|
+
input
|
|
83
|
+
};
|
|
84
|
+
if (!isRecord(input)) return {
|
|
85
|
+
ok: true,
|
|
86
|
+
input: { [tenantKey]: tenant }
|
|
87
|
+
};
|
|
88
|
+
const given = input[tenantKey];
|
|
89
|
+
if (given !== void 0 && given !== tenant) return {
|
|
90
|
+
ok: false,
|
|
91
|
+
reason: "tenant-mismatch"
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
ok: true,
|
|
95
|
+
input: {
|
|
96
|
+
...input,
|
|
97
|
+
[tenantKey]: tenant
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function resourceRef(permission, data) {
|
|
102
|
+
if (permission.kind === "collection" || !isRecord(data)) return { type: permission.resource };
|
|
103
|
+
const id = data["id"];
|
|
104
|
+
return typeof id === "string" || typeof id === "number" ? {
|
|
105
|
+
type: permission.resource,
|
|
106
|
+
id: String(id)
|
|
107
|
+
} : { type: permission.resource };
|
|
108
|
+
}
|
|
109
|
+
function alternativesOf(decision) {
|
|
110
|
+
return decision.alternatives.map((leaf) => leaf.key);
|
|
111
|
+
}
|
|
112
|
+
function deniedResult(decision, permission, data) {
|
|
113
|
+
const described = describe(decision);
|
|
114
|
+
const alternatives = alternativesOf(decision);
|
|
115
|
+
const suffix = alternatives.length === 0 ? "" : ` You may: ${alternatives.join(", ")}.`;
|
|
116
|
+
return {
|
|
117
|
+
isError: true,
|
|
118
|
+
content: [{
|
|
119
|
+
type: "text",
|
|
120
|
+
text: `Denied: ${permission.key}.${suffix}`
|
|
121
|
+
}],
|
|
122
|
+
structuredContent: compact({
|
|
123
|
+
outcome: "denied",
|
|
124
|
+
permission: permission.key,
|
|
125
|
+
resource: resourceRef(permission, data),
|
|
126
|
+
denials: wireDenials(decision.denials),
|
|
127
|
+
alternatives,
|
|
128
|
+
detail: described.detail
|
|
129
|
+
})
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function approvalResult(decision, permission, data) {
|
|
133
|
+
return {
|
|
134
|
+
content: [{
|
|
135
|
+
type: "text",
|
|
136
|
+
text: describe(decision).detail
|
|
137
|
+
}],
|
|
138
|
+
structuredContent: {
|
|
139
|
+
outcome: "approval-required",
|
|
140
|
+
permission: permission.key,
|
|
141
|
+
resource: resourceRef(permission, data),
|
|
142
|
+
token: decision.token
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function validationResult(error) {
|
|
147
|
+
return {
|
|
148
|
+
isError: true,
|
|
149
|
+
content: [{
|
|
150
|
+
type: "text",
|
|
151
|
+
text: error.message
|
|
152
|
+
}],
|
|
153
|
+
structuredContent: {
|
|
154
|
+
outcome: "denied",
|
|
155
|
+
permission: error.permission,
|
|
156
|
+
denials: [{
|
|
157
|
+
role: null,
|
|
158
|
+
reason: "validation"
|
|
159
|
+
}],
|
|
160
|
+
alternatives: [],
|
|
161
|
+
issues: error.issues
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function problemResult(error) {
|
|
166
|
+
if (error !== null && typeof error === "object" && "toProblemDetails" in error && typeof error.toProblemDetails === "function") {
|
|
167
|
+
const problem = error.toProblemDetails();
|
|
168
|
+
return {
|
|
169
|
+
isError: true,
|
|
170
|
+
content: [{
|
|
171
|
+
type: "text",
|
|
172
|
+
text: `${problem.title}: ${problem.detail}`
|
|
173
|
+
}],
|
|
174
|
+
structuredContent: {
|
|
175
|
+
outcome: "denied",
|
|
176
|
+
problem
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (isRecord(error) && error["type"] === "application/problem+json") return {
|
|
181
|
+
isError: true,
|
|
182
|
+
content: [{
|
|
183
|
+
type: "text",
|
|
184
|
+
text: `${typeof error["title"] === "string" ? error["title"] : "Denied"}: ${typeof error["detail"] === "string" ? error["detail"] : ""}`
|
|
185
|
+
}],
|
|
186
|
+
structuredContent: {
|
|
187
|
+
outcome: "denied",
|
|
188
|
+
problem: error
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function wrapResult(value) {
|
|
193
|
+
if (isRecord(value) && Array.isArray(value["content"]) && value["content"].every((item) => isRecord(item) && item["type"] === "text" && typeof item["text"] === "string")) return value;
|
|
194
|
+
if (typeof value === "string") return { content: [{
|
|
195
|
+
type: "text",
|
|
196
|
+
text: value
|
|
197
|
+
}] };
|
|
198
|
+
return { content: [{
|
|
199
|
+
type: "text",
|
|
200
|
+
text: JSON.stringify(value ?? null)
|
|
201
|
+
}] };
|
|
202
|
+
}
|
|
203
|
+
function instanceAllowed(snapshot, permission) {
|
|
204
|
+
return snapshot.grants.some((grant) => grant.permission === permission.key && grant.effect === "allow" && grant.portable !== false);
|
|
205
|
+
}
|
|
206
|
+
function shouldRegister(permdock, snapshot, permission) {
|
|
207
|
+
if (snapshot.simulated === true) return false;
|
|
208
|
+
if (permdock.status?.(permission) === "server-only" || permdock.status?.(permission) === "pending") return false;
|
|
209
|
+
if (permission.kind === "collection") return permdock.can(permission);
|
|
210
|
+
return instanceAllowed(snapshot, permission);
|
|
211
|
+
}
|
|
212
|
+
function warnMissing(warn) {
|
|
213
|
+
if (warn !== void 0) {
|
|
214
|
+
warn(MISSING_CONTEXT);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
globalThis.console?.warn?.(MISSING_CONTEXT);
|
|
218
|
+
}
|
|
219
|
+
async function runTool(permission, raw, options, permdock, schema) {
|
|
220
|
+
try {
|
|
221
|
+
const validated = validateInput(schema, raw, permission);
|
|
222
|
+
const bound = bindTenant(validated, options.tenantKey, options.tenant);
|
|
223
|
+
if (!bound.ok) return deniedResult({
|
|
224
|
+
outcome: "denied",
|
|
225
|
+
denials: [{
|
|
226
|
+
role: null,
|
|
227
|
+
reason: "tenant-mismatch"
|
|
228
|
+
}],
|
|
229
|
+
alternatives: []
|
|
230
|
+
}, permission, validated);
|
|
231
|
+
const decision = permdock.decide(permission, bound.input);
|
|
232
|
+
switch (decision.outcome) {
|
|
233
|
+
case "denied": return deniedResult(decision, permission, bound.input);
|
|
234
|
+
case "approval-required":
|
|
235
|
+
if (await options.onApprovalRequired?.({
|
|
236
|
+
permission,
|
|
237
|
+
decision,
|
|
238
|
+
input: bound.input
|
|
239
|
+
}) !== true) return approvalResult(decision, permission, bound.input);
|
|
240
|
+
break;
|
|
241
|
+
case "granted": break;
|
|
242
|
+
default: return decision;
|
|
243
|
+
}
|
|
244
|
+
const handler = options.handlers?.[permission.action];
|
|
245
|
+
if (handler === void 0) return {
|
|
246
|
+
isError: true,
|
|
247
|
+
content: [{
|
|
248
|
+
type: "text",
|
|
249
|
+
text: `${permission.key}: no handler registered.`
|
|
250
|
+
}]
|
|
251
|
+
};
|
|
252
|
+
return wrapResult(await handler({
|
|
253
|
+
input: bound.input,
|
|
254
|
+
token: decision.token
|
|
255
|
+
}));
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (error instanceof PermDockValidationError) return validationResult(error);
|
|
258
|
+
return problemResult(error) ?? {
|
|
259
|
+
isError: true,
|
|
260
|
+
content: [{
|
|
261
|
+
type: "text",
|
|
262
|
+
text: error instanceof Error ? error.message : "Tool failed."
|
|
263
|
+
}]
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function registerGeneration(modelContext, group, options, signal) {
|
|
268
|
+
const root = current(options.permdock);
|
|
269
|
+
const permdock = options.tenant !== void 0 && root.tenant !== void 0 ? root.tenant(options.tenant) : root;
|
|
270
|
+
const snapshot = snapshotOf(permdock);
|
|
271
|
+
if (snapshot === void 0) return;
|
|
272
|
+
for (const permission of listPermissions(group)) {
|
|
273
|
+
if (!shouldRegister(permdock, snapshot, permission)) continue;
|
|
274
|
+
const schema = schemaFor(group, permission, options.schema);
|
|
275
|
+
const tenantTitle = options.tenant === void 0 ? void 0 : ` [tenant ${options.tenant}]`;
|
|
276
|
+
const description = `${permission.meta.description ?? permission.key}${tenantTitle ?? ""}`;
|
|
277
|
+
modelContext.registerTool(compact({
|
|
278
|
+
name: toolName(permission),
|
|
279
|
+
title: permission.meta.title ?? permission.action,
|
|
280
|
+
description,
|
|
281
|
+
inputSchema: permission.kind === "instance" || schema !== void 0 ? jsonSchemaOf(schema) : void 0,
|
|
282
|
+
annotations: compact({
|
|
283
|
+
readOnlyHint: annotationsFor(permission).readOnlyHint,
|
|
284
|
+
untrustedContentHint: untrustedHint(permission, options.untrustedContentHint)
|
|
285
|
+
}),
|
|
286
|
+
execute: (input) => runTool(permission, input, options, permdock, schema)
|
|
287
|
+
}), { signal });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function registerTools(modelContext, group, options) {
|
|
291
|
+
if (modelContext === null || modelContext === void 0) {
|
|
292
|
+
warnMissing(options.warn);
|
|
293
|
+
return { unregister() {} };
|
|
294
|
+
}
|
|
295
|
+
let generation;
|
|
296
|
+
const parent = options.signal;
|
|
297
|
+
const start = () => {
|
|
298
|
+
generation?.abort();
|
|
299
|
+
if (parent?.aborted === true) return;
|
|
300
|
+
generation = new AbortController();
|
|
301
|
+
registerGeneration(modelContext, group, options, generation.signal);
|
|
302
|
+
};
|
|
303
|
+
start();
|
|
304
|
+
const unsubscribe = options.permdock.subscribe?.(start);
|
|
305
|
+
const unregister = () => {
|
|
306
|
+
generation?.abort();
|
|
307
|
+
unsubscribe?.();
|
|
308
|
+
};
|
|
309
|
+
parent?.addEventListener("abort", unregister, { once: true });
|
|
310
|
+
return { unregister };
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
export { registerTools };
|