@webiny/api-aco 6.6.0-alpha.0 → 6.6.0-alpha.2

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.
Files changed (80) hide show
  1. package/AcoFeature.js +9 -2
  2. package/AcoFeature.js.map +1 -1
  3. package/AcoFolderSchemaFactory.d.ts +30 -0
  4. package/AcoFolderSchemaFactory.js +64 -0
  5. package/AcoFolderSchemaFactory.js.map +1 -0
  6. package/createAcoGraphQL.d.ts +3 -2
  7. package/createAcoGraphQL.js.map +1 -1
  8. package/domain/folder/abstractions.d.ts +12 -5
  9. package/domain/folder/abstractions.js +2 -2
  10. package/domain/folder/abstractions.js.map +1 -1
  11. package/features/ai/CreateFolderTool.d.ts +44 -0
  12. package/features/ai/CreateFolderTool.js +49 -0
  13. package/features/ai/CreateFolderTool.js.map +1 -0
  14. package/features/ai/CreateTeamTool.d.ts +43 -0
  15. package/features/ai/CreateTeamTool.js +47 -0
  16. package/features/ai/CreateTeamTool.js.map +1 -0
  17. package/features/ai/GrantFolderAccessTool.d.ts +72 -0
  18. package/features/ai/GrantFolderAccessTool.js +71 -0
  19. package/features/ai/GrantFolderAccessTool.js.map +1 -0
  20. package/features/ai/ListFoldersTool.d.ts +42 -0
  21. package/features/ai/ListFoldersTool.js +48 -0
  22. package/features/ai/ListFoldersTool.js.map +1 -0
  23. package/features/ai/ListRolesTool.d.ts +34 -0
  24. package/features/ai/ListRolesTool.js +39 -0
  25. package/features/ai/ListRolesTool.js.map +1 -0
  26. package/features/ai/ListTeamsTool.d.ts +34 -0
  27. package/features/ai/ListTeamsTool.js +39 -0
  28. package/features/ai/ListTeamsTool.js.map +1 -0
  29. package/features/ai/RevokeFolderAccessTool.d.ts +58 -0
  30. package/features/ai/RevokeFolderAccessTool.js +60 -0
  31. package/features/ai/RevokeFolderAccessTool.js.map +1 -0
  32. package/features/ai/assertTargetIsUsable.d.ts +10 -0
  33. package/features/ai/assertTargetIsUsable.js +14 -0
  34. package/features/ai/assertTargetIsUsable.js.map +1 -0
  35. package/features/ai/feature.d.ts +12 -0
  36. package/features/ai/feature.js +23 -0
  37. package/features/ai/feature.js.map +1 -0
  38. package/features/ai/index.d.ts +8 -0
  39. package/features/ai/index.js +8 -0
  40. package/features/ai/loadFolderPermissions.d.ts +16 -0
  41. package/features/ai/loadFolderPermissions.js +14 -0
  42. package/features/ai/loadFolderPermissions.js.map +1 -0
  43. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.d.ts +3 -3
  44. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js +6 -6
  45. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js.map +1 -1
  46. package/features/flp/UpdateFlp/UpdateFlpUseCase.d.ts +3 -3
  47. package/features/flp/UpdateFlp/UpdateFlpUseCase.js +4 -3
  48. package/features/flp/UpdateFlp/UpdateFlpUseCase.js.map +1 -1
  49. package/features/flp/UpdateFlp/feature.js +2 -2
  50. package/features/flp/UpdateFlp/feature.js.map +1 -1
  51. package/features/folder/CreateFolder/CreateFolderRepository.d.ts +3 -3
  52. package/features/folder/CreateFolder/CreateFolderRepository.js +10 -7
  53. package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
  54. package/features/folder/DeleteFolder/DeleteFolderRepository.d.ts +3 -3
  55. package/features/folder/DeleteFolder/DeleteFolderRepository.js +6 -5
  56. package/features/folder/DeleteFolder/DeleteFolderRepository.js.map +1 -1
  57. package/features/folder/FolderModelProvider.d.ts +26 -0
  58. package/features/folder/FolderModelProvider.js +22 -0
  59. package/features/folder/FolderModelProvider.js.map +1 -0
  60. package/features/folder/GetAncestors/GetAncestorsRepository.d.ts +3 -3
  61. package/features/folder/GetAncestors/GetAncestorsRepository.js +6 -5
  62. package/features/folder/GetAncestors/GetAncestorsRepository.js.map +1 -1
  63. package/features/folder/GetFolder/GetFolderRepository.d.ts +3 -3
  64. package/features/folder/GetFolder/GetFolderRepository.js +6 -5
  65. package/features/folder/GetFolder/GetFolderRepository.js.map +1 -1
  66. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.d.ts +3 -3
  67. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +10 -8
  68. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
  69. package/features/folder/ListFolders/ListFoldersRepository.d.ts +3 -3
  70. package/features/folder/ListFolders/ListFoldersRepository.js +8 -7
  71. package/features/folder/ListFolders/ListFoldersRepository.js.map +1 -1
  72. package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +3 -3
  73. package/features/folder/UpdateFolder/UpdateFolderRepository.js +11 -8
  74. package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
  75. package/folder/folder.gql.js +2 -2
  76. package/folder/folder.gql.js.map +1 -1
  77. package/package.json +23 -22
  78. package/AcoInitializer.d.ts +0 -25
  79. package/AcoInitializer.js +0 -79
  80. package/AcoInitializer.js.map +0 -1
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListTeamsUseCase } from "@webiny/api-core/features/security/teams/ListTeams/index.js";
4
+ import { GetFolderUseCase } from "../folder/GetFolder/index.js";
5
+ import { UpdateFolderUseCase } from "../folder/UpdateFolder/index.js";
6
+ import { loadFolderPermissions } from "./loadFolderPermissions.js";
7
+ import { assertTargetIsUsable } from "./assertTargetIsUsable.js";
8
+ const ACCESS_LEVELS = [
9
+ "owner",
10
+ "editor",
11
+ "viewer",
12
+ "public",
13
+ "no-access"
14
+ ];
15
+ const inputSchema = z.object({
16
+ folderId: z.string().describe("Folder id as returned by listFolders."),
17
+ target: z.string().describe("Who to grant access to. A team is 'team:<slug>' — the SLUG, not the id. A user is 'admin:<userId>'. Resolve with listTeams first."),
18
+ level: z["enum"](ACCESS_LEVELS).describe("owner = full control including permissions; editor = change content; viewer = read only; no-access = explicitly denied.")
19
+ });
20
+ class GrantFolderAccessToolImpl {
21
+ constructor(getFolder, updateFolder, listTeams){
22
+ this.getFolder = getFolder;
23
+ this.updateFolder = updateFolder;
24
+ this.listTeams = listTeams;
25
+ this.name = "grantFolderAccess";
26
+ this.title = "Grant folder access";
27
+ this.description = "Grants one team or user a level of access on one folder, leaving all other permissions untouched. Use listFolders for the folder id and listTeams for a team slug. Requires user approval.";
28
+ this.inputSchema = inputSchema;
29
+ this.annotations = {
30
+ readOnlyHint: false
31
+ };
32
+ }
33
+ async execute(input) {
34
+ const loaded = await loadFolderPermissions(this.getFolder, input.folderId);
35
+ await assertTargetIsUsable(this.listTeams, input.target, loaded.inheritedTargets);
36
+ const existing = loaded.direct.find((permission)=>String(permission.target) === input.target);
37
+ const permissions = loaded.direct.filter((permission)=>String(permission.target) !== input.target).concat([
38
+ {
39
+ target: input.target,
40
+ level: input.level
41
+ }
42
+ ]);
43
+ const result = await this.updateFolder.execute(input.folderId, {
44
+ permissions
45
+ });
46
+ if (result.isFail()) throw new Error(`Could not grant access: ${result.error.message}`);
47
+ const folder = result.value;
48
+ const granted = {
49
+ folderId: folder.id,
50
+ title: folder.title,
51
+ path: folder.path,
52
+ permissions: (folder.permissions ?? []).filter((permission)=>!permission.inheritedFrom).map((permission)=>({
53
+ target: String(permission.target),
54
+ level: permission.level
55
+ }))
56
+ };
57
+ if (existing) granted.replacedExistingLevel = existing.level;
58
+ return granted;
59
+ }
60
+ }
61
+ const GrantFolderAccessTool = AiSdkTool.createImplementation({
62
+ implementation: GrantFolderAccessToolImpl,
63
+ dependencies: [
64
+ GetFolderUseCase,
65
+ UpdateFolderUseCase,
66
+ ListTeamsUseCase
67
+ ]
68
+ });
69
+ export { GrantFolderAccessTool };
70
+
71
+ //# sourceMappingURL=GrantFolderAccessTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/GrantFolderAccessTool.js","sources":["../../../src/features/ai/GrantFolderAccessTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport type { IAiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListTeamsUseCase } from \"@webiny/api-core/features/security/teams/ListTeams/index.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { UpdateFolderUseCase } from \"~/features/folder/UpdateFolder/index.js\";\nimport type { FolderPermission } from \"~/types.js\";\nimport { loadFolderPermissions } from \"./loadFolderPermissions.js\";\nimport { assertTargetIsUsable } from \"./assertTargetIsUsable.js\";\n\nconst ACCESS_LEVELS = [\"owner\", \"editor\", \"viewer\", \"public\", \"no-access\"] as const;\n\nconst inputSchema = z.object({\n folderId: z.string().describe(\"Folder id as returned by listFolders.\"),\n target: z\n .string()\n .describe(\n \"Who to grant access to. A team is 'team:<slug>' — the SLUG, not the id. A user is 'admin:<userId>'. Resolve with listTeams first.\"\n ),\n level: z\n .enum(ACCESS_LEVELS)\n .describe(\n \"owner = full control including permissions; editor = change content; viewer = read only; no-access = explicitly denied.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface GrantResult {\n folderId: string;\n title: string;\n path: string;\n /**\n * Every direct rule on the folder afterwards.\n *\n * This is the set the update was asked to store, not an independent read of it:\n * `UpdateFolderWithFolderLevelPermissions` returns the permissions it derived from the input\n * rather than the ones the repository wrote. Treating it as a verification would let the tool\n * confirm its own request back to itself.\n */\n permissions: { target: string; level: string }[];\n /** True when the target already had a direct rule and its level was changed. */\n replacedExistingLevel?: string;\n}\n\n/**\n * Grants one target access to one folder, leaving every other rule alone.\n *\n * Additive by design. The earlier tool took the complete permission set and replaced it, which meant\n * approving a change showed what would be SET and said nothing about what would be removed — a rule\n * the model omitted disappeared silently. One target per call keeps the approval honest: what the user\n * sees in the plan is the whole change.\n */\nclass GrantFolderAccessToolImpl implements IAiSdkTool<Input> {\n readonly name = \"grantFolderAccess\";\n readonly title = \"Grant folder access\";\n readonly description =\n \"Grants one team or user a level of access on one folder, leaving all other permissions untouched. Use listFolders for the folder id and listTeams for a team slug. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n private updateFolder: UpdateFolderUseCase.Interface,\n private listTeams: ListTeamsUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<GrantResult> {\n const loaded = await loadFolderPermissions(this.getFolder, input.folderId);\n\n await assertTargetIsUsable(this.listTeams, input.target, loaded.inheritedTargets);\n\n const existing = loaded.direct.find(\n permission => String(permission.target) === input.target\n );\n\n const permissions: FolderPermission[] = loaded.direct\n .filter(permission => String(permission.target) !== input.target)\n .concat([{ target: input.target, level: input.level } as FolderPermission]);\n\n const result = await this.updateFolder.execute(input.folderId, { permissions });\n\n if (result.isFail()) {\n throw new Error(`Could not grant access: ${result.error.message}`);\n }\n\n const folder = result.value;\n\n const granted: GrantResult = {\n folderId: folder.id,\n title: folder.title,\n path: folder.path,\n permissions: (folder.permissions ?? [])\n .filter(permission => !permission.inheritedFrom)\n .map(permission => ({ target: String(permission.target), level: permission.level }))\n };\n\n if (existing) {\n granted.replacedExistingLevel = existing.level;\n }\n\n return granted;\n }\n}\n\nexport const GrantFolderAccessTool = AiSdkTool.createImplementation({\n implementation: GrantFolderAccessToolImpl,\n dependencies: [GetFolderUseCase, UpdateFolderUseCase, ListTeamsUseCase]\n});\n"],"names":["ACCESS_LEVELS","inputSchema","z","GrantFolderAccessToolImpl","getFolder","updateFolder","listTeams","input","loaded","loadFolderPermissions","assertTargetIsUsable","existing","permission","String","permissions","result","Error","folder","granted","GrantFolderAccessTool","AiSdkTool","GetFolderUseCase","UpdateFolderUseCase","ListTeamsUseCase"],"mappings":";;;;;;;AAUA,MAAMA,gBAAgB;IAAC;IAAS;IAAU;IAAU;IAAU;CAAY;AAE1E,MAAMC,cAAcC,EAAE,MAAM,CAAC;IACzB,UAAUA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC9B,QAAQA,EAAAA,MACG,GACN,QAAQ,CACL;IAER,OAAOA,CAAC,CAADA,OACE,CAACF,eACL,QAAQ,CACL;AAEZ;AA6BA,MAAMG;IAQF,YACYC,SAAqC,EACrCC,YAA2C,EAC3CC,SAAqC,CAC/C;aAHUF,SAAS,GAATA;aACAC,YAAY,GAAZA;aACAC,SAAS,GAATA;aAVH,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGL;aACd,WAAW,GAAG;YAAE,cAAc;QAAM;IAM1C;IAEH,MAAM,QAAQM,KAAY,EAAwB;QAC9C,MAAMC,SAAS,MAAMC,sBAAsB,IAAI,CAAC,SAAS,EAAEF,MAAM,QAAQ;QAEzE,MAAMG,qBAAqB,IAAI,CAAC,SAAS,EAAEH,MAAM,MAAM,EAAEC,OAAO,gBAAgB;QAEhF,MAAMG,WAAWH,OAAO,MAAM,CAAC,IAAI,CAC/BI,CAAAA,aAAcC,OAAOD,WAAW,MAAM,MAAML,MAAM,MAAM;QAG5D,MAAMO,cAAkCN,OAAO,MAAM,CAChD,MAAM,CAACI,CAAAA,aAAcC,OAAOD,WAAW,MAAM,MAAML,MAAM,MAAM,EAC/D,MAAM,CAAC;YAAC;gBAAE,QAAQA,MAAM,MAAM;gBAAE,OAAOA,MAAM,KAAK;YAAC;SAAsB;QAE9E,MAAMQ,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACR,MAAM,QAAQ,EAAE;YAAEO;QAAY;QAE7E,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGrE,MAAME,SAASF,OAAO,KAAK;QAE3B,MAAMG,UAAuB;YACzB,UAAUD,OAAO,EAAE;YACnB,OAAOA,OAAO,KAAK;YACnB,MAAMA,OAAO,IAAI;YACjB,aAAcA,AAAAA,CAAAA,OAAO,WAAW,IAAI,EAAC,EAChC,MAAM,CAACL,CAAAA,aAAc,CAACA,WAAW,aAAa,EAC9C,GAAG,CAACA,CAAAA,aAAe;oBAAE,QAAQC,OAAOD,WAAW,MAAM;oBAAG,OAAOA,WAAW,KAAK;gBAAC;QACzF;QAEA,IAAID,UACAO,QAAQ,qBAAqB,GAAGP,SAAS,KAAK;QAGlD,OAAOO;IACX;AACJ;AAEO,MAAMC,wBAAwBC,UAAU,oBAAoB,CAAC;IAChE,gBAAgBjB;IAChB,cAAc;QAACkB;QAAkBC;QAAqBC;KAAiB;AAC3E"}
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import type { IAiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListFoldersUseCase } from "../../features/folder/ListFolders/index.js";
4
+ declare const inputSchema: z.ZodObject<{
5
+ type: z.ZodString;
6
+ }, z.core.$strip>;
7
+ type Input = z.infer<typeof inputSchema>;
8
+ interface FolderSummary {
9
+ id: string;
10
+ title: string;
11
+ slug: string;
12
+ path: string;
13
+ parentId?: string | null;
14
+ permissions: {
15
+ target: string;
16
+ level: string;
17
+ inherited: boolean;
18
+ }[];
19
+ }
20
+ /**
21
+ * Lists folders with their current access rules, so a permission change is proposed against a real
22
+ * folder id and the user can see what the access already is before approving a change to it.
23
+ */
24
+ declare class ListFoldersToolImpl implements IAiSdkTool<Input> {
25
+ private listFolders;
26
+ readonly name = "listFolders";
27
+ readonly title = "List folders";
28
+ readonly description = "Lists folders of a given type with their ids, paths and current access permissions. Call this before changing folder permissions so the change targets a real folder.";
29
+ readonly inputSchema: z.ZodObject<{
30
+ type: z.ZodString;
31
+ }, z.core.$strip>;
32
+ readonly annotations: {
33
+ readOnlyHint: boolean;
34
+ idempotentHint: boolean;
35
+ };
36
+ constructor(listFolders: ListFoldersUseCase.Interface);
37
+ execute(input: Input): Promise<FolderSummary[]>;
38
+ }
39
+ export declare const ListFoldersTool: typeof ListFoldersToolImpl & {
40
+ __abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
41
+ };
42
+ export {};
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListFoldersUseCase } from "../folder/ListFolders/index.js";
4
+ const inputSchema = z.object({
5
+ type: z.string().describe("Folder namespace, e.g. 'FmFile' for the file manager or 'cms:<modelId>' for a content model's folders.")
6
+ });
7
+ class ListFoldersToolImpl {
8
+ constructor(listFolders){
9
+ this.listFolders = listFolders;
10
+ this.name = "listFolders";
11
+ this.title = "List folders";
12
+ this.description = "Lists folders of a given type with their ids, paths and current access permissions. Call this before changing folder permissions so the change targets a real folder.";
13
+ this.inputSchema = inputSchema;
14
+ this.annotations = {
15
+ readOnlyHint: true,
16
+ idempotentHint: true
17
+ };
18
+ }
19
+ async execute(input) {
20
+ const result = await this.listFolders.execute({
21
+ where: {
22
+ type: input.type
23
+ }
24
+ });
25
+ if (result.isFail()) throw new Error(`Could not list folders: ${result.error.message}`);
26
+ return result.value.folders.map((folder)=>({
27
+ id: folder.id,
28
+ title: folder.title,
29
+ slug: folder.slug,
30
+ path: folder.path,
31
+ parentId: folder.parentId,
32
+ permissions: (folder.permissions ?? []).map((permission)=>({
33
+ target: permission.target,
34
+ level: permission.level,
35
+ inherited: Boolean(permission.inheritedFrom)
36
+ }))
37
+ }));
38
+ }
39
+ }
40
+ const ListFoldersTool = AiSdkTool.createImplementation({
41
+ implementation: ListFoldersToolImpl,
42
+ dependencies: [
43
+ ListFoldersUseCase
44
+ ]
45
+ });
46
+ export { ListFoldersTool };
47
+
48
+ //# sourceMappingURL=ListFoldersTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/ListFoldersTool.js","sources":["../../../src/features/ai/ListFoldersTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport type { IAiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\n\nconst inputSchema = z.object({\n type: z\n .string()\n .describe(\n \"Folder namespace, e.g. 'FmFile' for the file manager or 'cms:<modelId>' for a content model's folders.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface FolderSummary {\n id: string;\n title: string;\n slug: string;\n path: string;\n parentId?: string | null;\n permissions: { target: string; level: string; inherited: boolean }[];\n}\n\n/**\n * Lists folders with their current access rules, so a permission change is proposed against a real\n * folder id and the user can see what the access already is before approving a change to it.\n */\nclass ListFoldersToolImpl implements IAiSdkTool<Input> {\n readonly name = \"listFolders\";\n readonly title = \"List folders\";\n readonly description =\n \"Lists folders of a given type with their ids, paths and current access permissions. Call this before changing folder permissions so the change targets a real folder.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n\n constructor(private listFolders: ListFoldersUseCase.Interface) {}\n\n async execute(input: Input): Promise<FolderSummary[]> {\n const result = await this.listFolders.execute({ where: { type: input.type } });\n\n if (result.isFail()) {\n throw new Error(`Could not list folders: ${result.error.message}`);\n }\n\n return result.value.folders.map(folder => ({\n id: folder.id,\n title: folder.title,\n slug: folder.slug,\n path: folder.path,\n parentId: folder.parentId,\n permissions: (folder.permissions ?? []).map(permission => ({\n target: permission.target,\n level: permission.level,\n // Inherited rules cannot be edited on this folder — only on the ancestor that set them.\n inherited: Boolean(permission.inheritedFrom)\n }))\n }));\n }\n}\n\nexport const ListFoldersTool = AiSdkTool.createImplementation({\n implementation: ListFoldersToolImpl,\n dependencies: [ListFoldersUseCase]\n});\n"],"names":["inputSchema","z","ListFoldersToolImpl","listFolders","input","result","Error","folder","permission","Boolean","ListFoldersTool","AiSdkTool","ListFoldersUseCase"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,MAAMA,EAAAA,MACK,GACN,QAAQ,CACL;AAEZ;AAiBA,MAAMC;IAQF,YAAoBC,WAAyC,CAAE;aAA3CA,WAAW,GAAXA;aAPX,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGH;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;IAEF;IAEhE,MAAM,QAAQI,KAAY,EAA4B;QAClD,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;YAAE,OAAO;gBAAE,MAAMD,MAAM,IAAI;YAAC;QAAE;QAE5E,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGrE,OAAOA,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAACE,CAAAA,SAAW;gBACvC,IAAIA,OAAO,EAAE;gBACb,OAAOA,OAAO,KAAK;gBACnB,MAAMA,OAAO,IAAI;gBACjB,MAAMA,OAAO,IAAI;gBACjB,UAAUA,OAAO,QAAQ;gBACzB,aAAcA,AAAAA,CAAAA,OAAO,WAAW,IAAI,EAAC,EAAG,GAAG,CAACC,CAAAA,aAAe;wBACvD,QAAQA,WAAW,MAAM;wBACzB,OAAOA,WAAW,KAAK;wBAEvB,WAAWC,QAAQD,WAAW,aAAa;oBAC/C;YACJ;IACJ;AACJ;AAEO,MAAME,kBAAkBC,UAAU,oBAAoB,CAAC;IAC1D,gBAAgBT;IAChB,cAAc;QAACU;KAAmB;AACtC"}
@@ -0,0 +1,34 @@
1
+ import { z } from "zod";
2
+ import type { IAiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListRolesUseCase } from "@webiny/api-core/features/security/roles/ListRoles/index.js";
4
+ interface RoleSummary {
5
+ id: string;
6
+ name: string;
7
+ slug: string;
8
+ description?: string;
9
+ }
10
+ /**
11
+ * Resolves role names to the IDs `createTeam` takes. Separate from the write, so the user approves a
12
+ * team with roles that were looked up rather than guessed.
13
+ *
14
+ * Returns the slug too, because it is what a human recognises and what the admin UI shows, while
15
+ * `id` is what a team actually stores. Nothing at the type level separates the two, so `createTeam`
16
+ * accepts either and resolves it rather than making the caller guess which one that field wants.
17
+ */
18
+ declare class ListRolesToolImpl implements IAiSdkTool<Record<string, never>> {
19
+ private listRoles;
20
+ readonly name = "listRoles";
21
+ readonly title = "List roles";
22
+ readonly description = "Lists the security roles in this project. Call this before createTeam and pass the `id` of each role you want. A slug also works, but a value that is neither is rejected.";
23
+ readonly inputSchema: z.ZodObject<{}, z.core.$strip>;
24
+ readonly annotations: {
25
+ readOnlyHint: boolean;
26
+ idempotentHint: boolean;
27
+ };
28
+ constructor(listRoles: ListRolesUseCase.Interface);
29
+ execute(): Promise<RoleSummary[]>;
30
+ }
31
+ export declare const ListRolesTool: typeof ListRolesToolImpl & {
32
+ __abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
33
+ };
34
+ export {};
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListRolesUseCase } from "@webiny/api-core/features/security/roles/ListRoles/index.js";
4
+ const inputSchema = z.object({});
5
+ class ListRolesToolImpl {
6
+ constructor(listRoles){
7
+ this.listRoles = listRoles;
8
+ this.name = "listRoles";
9
+ this.title = "List roles";
10
+ this.description = "Lists the security roles in this project. Call this before createTeam and pass the `id` of each role you want. A slug also works, but a value that is neither is rejected.";
11
+ this.inputSchema = inputSchema;
12
+ this.annotations = {
13
+ readOnlyHint: true,
14
+ idempotentHint: true
15
+ };
16
+ }
17
+ async execute() {
18
+ const result = await this.listRoles.execute();
19
+ if (result.isFail()) throw new Error(`Could not list roles: ${result.error.message}`);
20
+ return result.value.map((role)=>{
21
+ const summary = {
22
+ id: role.id,
23
+ name: role.name,
24
+ slug: role.slug
25
+ };
26
+ if (role.description) summary.description = role.description;
27
+ return summary;
28
+ });
29
+ }
30
+ }
31
+ const ListRolesTool = AiSdkTool.createImplementation({
32
+ implementation: ListRolesToolImpl,
33
+ dependencies: [
34
+ ListRolesUseCase
35
+ ]
36
+ });
37
+ export { ListRolesTool };
38
+
39
+ //# sourceMappingURL=ListRolesTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/ListRolesTool.js","sources":["../../../src/features/ai/ListRolesTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport type { IAiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListRolesUseCase } from \"@webiny/api-core/features/security/roles/ListRoles/index.js\";\n\nconst inputSchema = z.object({});\n\ninterface RoleSummary {\n id: string;\n name: string;\n slug: string;\n description?: string;\n}\n\n/**\n * Resolves role names to the IDs `createTeam` takes. Separate from the write, so the user approves a\n * team with roles that were looked up rather than guessed.\n *\n * Returns the slug too, because it is what a human recognises and what the admin UI shows, while\n * `id` is what a team actually stores. Nothing at the type level separates the two, so `createTeam`\n * accepts either and resolves it rather than making the caller guess which one that field wants.\n */\nclass ListRolesToolImpl implements IAiSdkTool<Record<string, never>> {\n readonly name = \"listRoles\";\n readonly title = \"List roles\";\n readonly description =\n \"Lists the security roles in this project. Call this before createTeam and pass the `id` of each role you want. A slug also works, but a value that is neither is rejected.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n\n constructor(private listRoles: ListRolesUseCase.Interface) {}\n\n async execute(): Promise<RoleSummary[]> {\n const result = await this.listRoles.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not list roles: ${result.error.message}`);\n }\n\n return result.value.map(role => {\n const summary: RoleSummary = {\n id: role.id,\n name: role.name,\n slug: role.slug\n };\n\n if (role.description) {\n summary.description = role.description;\n }\n\n return summary;\n });\n }\n}\n\nexport const ListRolesTool = AiSdkTool.createImplementation({\n implementation: ListRolesToolImpl,\n dependencies: [ListRolesUseCase]\n});\n"],"names":["inputSchema","z","ListRolesToolImpl","listRoles","result","Error","role","summary","ListRolesTool","AiSdkTool","ListRolesUseCase"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC,CAAC;AAiB9B,MAAMC;IAQF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;aAPX,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGH;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;IAEN;IAE5D,MAAM,UAAkC;QACpC,MAAMI,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO;QAE3C,IAAIA,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,sBAAsB,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGnE,OAAOA,OAAO,KAAK,CAAC,GAAG,CAACE,CAAAA;YACpB,MAAMC,UAAuB;gBACzB,IAAID,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;YACnB;YAEA,IAAIA,KAAK,WAAW,EAChBC,QAAQ,WAAW,GAAGD,KAAK,WAAW;YAG1C,OAAOC;QACX;IACJ;AACJ;AAEO,MAAMC,gBAAgBC,UAAU,oBAAoB,CAAC;IACxD,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC"}
@@ -0,0 +1,34 @@
1
+ import { z } from "zod";
2
+ import type { IAiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListTeamsUseCase } from "@webiny/api-core/features/security/teams/ListTeams/index.js";
4
+ declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
5
+ type Input = z.infer<typeof inputSchema>;
6
+ interface TeamSummary {
7
+ id: string;
8
+ name: string;
9
+ slug: string;
10
+ description?: string;
11
+ }
12
+ /**
13
+ * Resolves human names ("team A") to the ids folder permissions actually take.
14
+ *
15
+ * Kept separate from setFolderPermissions rather than accepting a team name there: the user approves
16
+ * the arguments of a write, so the id has to be looked up and shown, not guessed inside the write.
17
+ */
18
+ declare class ListTeamsToolImpl implements IAiSdkTool<Input> {
19
+ private listTeams;
20
+ readonly name = "listTeams";
21
+ readonly title = "List teams";
22
+ readonly description = "Lists the teams in this project with their ids, names and slugs. Folder permission targets use the SLUG (`team:<slug>`), not the id.";
23
+ readonly inputSchema: z.ZodObject<{}, z.core.$strip>;
24
+ readonly annotations: {
25
+ readOnlyHint: boolean;
26
+ idempotentHint: boolean;
27
+ };
28
+ constructor(listTeams: ListTeamsUseCase.Interface);
29
+ execute(): Promise<TeamSummary[]>;
30
+ }
31
+ export declare const ListTeamsTool: typeof ListTeamsToolImpl & {
32
+ __abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
33
+ };
34
+ export {};
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { ListTeamsUseCase } from "@webiny/api-core/features/security/teams/ListTeams/index.js";
4
+ const inputSchema = z.object({});
5
+ class ListTeamsToolImpl {
6
+ constructor(listTeams){
7
+ this.listTeams = listTeams;
8
+ this.name = "listTeams";
9
+ this.title = "List teams";
10
+ this.description = "Lists the teams in this project with their ids, names and slugs. Folder permission targets use the SLUG (`team:<slug>`), not the id.";
11
+ this.inputSchema = inputSchema;
12
+ this.annotations = {
13
+ readOnlyHint: true,
14
+ idempotentHint: true
15
+ };
16
+ }
17
+ async execute() {
18
+ const result = await this.listTeams.execute();
19
+ if (result.isFail()) throw new Error(`Could not list teams: ${result.error.message}`);
20
+ return result.value.map((team)=>{
21
+ const summary = {
22
+ id: team.id,
23
+ name: team.name,
24
+ slug: team.slug
25
+ };
26
+ if (team.description) summary.description = team.description;
27
+ return summary;
28
+ });
29
+ }
30
+ }
31
+ const ListTeamsTool = AiSdkTool.createImplementation({
32
+ implementation: ListTeamsToolImpl,
33
+ dependencies: [
34
+ ListTeamsUseCase
35
+ ]
36
+ });
37
+ export { ListTeamsTool };
38
+
39
+ //# sourceMappingURL=ListTeamsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/ListTeamsTool.js","sources":["../../../src/features/ai/ListTeamsTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport type { IAiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListTeamsUseCase } from \"@webiny/api-core/features/security/teams/ListTeams/index.js\";\n\nconst inputSchema = z.object({});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface TeamSummary {\n id: string;\n name: string;\n slug: string;\n description?: string;\n}\n\n/**\n * Resolves human names (\"team A\") to the ids folder permissions actually take.\n *\n * Kept separate from setFolderPermissions rather than accepting a team name there: the user approves\n * the arguments of a write, so the id has to be looked up and shown, not guessed inside the write.\n */\nclass ListTeamsToolImpl implements IAiSdkTool<Input> {\n readonly name = \"listTeams\";\n readonly title = \"List teams\";\n readonly description =\n \"Lists the teams in this project with their ids, names and slugs. Folder permission targets use the SLUG (`team:<slug>`), not the id.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n\n constructor(private listTeams: ListTeamsUseCase.Interface) {}\n\n async execute(): Promise<TeamSummary[]> {\n const result = await this.listTeams.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not list teams: ${result.error.message}`);\n }\n\n return result.value.map(team => {\n const summary: TeamSummary = {\n id: team.id,\n name: team.name,\n slug: team.slug\n };\n\n if (team.description) {\n summary.description = team.description;\n }\n\n return summary;\n });\n }\n}\n\nexport const ListTeamsTool = AiSdkTool.createImplementation({\n implementation: ListTeamsToolImpl,\n dependencies: [ListTeamsUseCase]\n});\n"],"names":["inputSchema","z","ListTeamsToolImpl","listTeams","result","Error","team","summary","ListTeamsTool","AiSdkTool","ListTeamsUseCase"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC,CAAC;AAiB9B,MAAMC;IAQF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;aAPX,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGH;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;IAEN;IAE5D,MAAM,UAAkC;QACpC,MAAMI,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO;QAE3C,IAAIA,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,sBAAsB,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGnE,OAAOA,OAAO,KAAK,CAAC,GAAG,CAACE,CAAAA;YACpB,MAAMC,UAAuB;gBACzB,IAAID,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;YACnB;YAEA,IAAIA,KAAK,WAAW,EAChBC,QAAQ,WAAW,GAAGD,KAAK,WAAW;YAG1C,OAAOC;QACX;IACJ;AACJ;AAEO,MAAMC,gBAAgBC,UAAU,oBAAoB,CAAC;IACxD,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC"}
@@ -0,0 +1,58 @@
1
+ import { z } from "zod";
2
+ import type { IAiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetFolderUseCase } from "../../features/folder/GetFolder/index.js";
4
+ import { UpdateFolderUseCase } from "../../features/folder/UpdateFolder/index.js";
5
+ declare const inputSchema: z.ZodObject<{
6
+ folderId: z.ZodString;
7
+ target: z.ZodString;
8
+ }, z.core.$strip>;
9
+ type Input = z.infer<typeof inputSchema>;
10
+ interface RevokeResult {
11
+ folderId: string;
12
+ title: string;
13
+ path: string;
14
+ removed: {
15
+ target: string;
16
+ level: string;
17
+ };
18
+ /**
19
+ * Every direct rule remaining afterwards.
20
+ *
21
+ * This is the set the update was asked to store, not an independent read of it:
22
+ * `UpdateFolderWithFolderLevelPermissions` returns the permissions it derived from the input
23
+ * rather than the ones the repository wrote. Treating it as a verification would let the tool
24
+ * confirm its own request back to itself.
25
+ */
26
+ permissions: {
27
+ target: string;
28
+ level: string;
29
+ }[];
30
+ }
31
+ /**
32
+ * Removes one target's direct access to one folder.
33
+ *
34
+ * Destructive: somebody loses access, and there is no undo. Refuses when the target has no DIRECT rule
35
+ * rather than reporting a removal that changed nothing — an inherited grant cannot be revoked here,
36
+ * only where it is defined, and saying otherwise would leave the user believing access was withdrawn.
37
+ */
38
+ declare class RevokeFolderAccessToolImpl implements IAiSdkTool<Input> {
39
+ private getFolder;
40
+ private updateFolder;
41
+ readonly name = "revokeFolderAccess";
42
+ readonly title = "Revoke folder access";
43
+ readonly description = "Removes one team's or user's direct access to one folder, leaving all other permissions untouched. Cannot remove inherited access. Requires user approval.";
44
+ readonly inputSchema: z.ZodObject<{
45
+ folderId: z.ZodString;
46
+ target: z.ZodString;
47
+ }, z.core.$strip>;
48
+ readonly annotations: {
49
+ readOnlyHint: boolean;
50
+ destructiveHint: boolean;
51
+ };
52
+ constructor(getFolder: GetFolderUseCase.Interface, updateFolder: UpdateFolderUseCase.Interface);
53
+ execute(input: Input): Promise<RevokeResult>;
54
+ }
55
+ export declare const RevokeFolderAccessTool: typeof RevokeFolderAccessToolImpl & {
56
+ __abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
57
+ };
58
+ export {};
@@ -0,0 +1,60 @@
1
+ import { z } from "zod";
2
+ import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetFolderUseCase } from "../folder/GetFolder/index.js";
4
+ import { UpdateFolderUseCase } from "../folder/UpdateFolder/index.js";
5
+ import { loadFolderPermissions } from "./loadFolderPermissions.js";
6
+ const inputSchema = z.object({
7
+ folderId: z.string().describe("Folder id as returned by listFolders."),
8
+ target: z.string().describe("Whose access to remove: 'team:<slug>' or 'admin:<userId>', exactly as listFolders reports it.")
9
+ });
10
+ class RevokeFolderAccessToolImpl {
11
+ constructor(getFolder, updateFolder){
12
+ this.getFolder = getFolder;
13
+ this.updateFolder = updateFolder;
14
+ this.name = "revokeFolderAccess";
15
+ this.title = "Revoke folder access";
16
+ this.description = "Removes one team's or user's direct access to one folder, leaving all other permissions untouched. Cannot remove inherited access. Requires user approval.";
17
+ this.inputSchema = inputSchema;
18
+ this.annotations = {
19
+ readOnlyHint: false,
20
+ destructiveHint: true
21
+ };
22
+ }
23
+ async execute(input) {
24
+ const loaded = await loadFolderPermissions(this.getFolder, input.folderId);
25
+ const existing = loaded.direct.find((permission)=>String(permission.target) === input.target);
26
+ if (!existing) {
27
+ if (loaded.inheritedTargets.has(input.target)) throw new Error(`"${input.target}" has inherited access to this folder, not a direct rule, so it cannot be revoked here. Change it where it is defined.`);
28
+ throw new Error(`"${input.target}" has no direct access to this folder, so there is nothing to revoke.`);
29
+ }
30
+ const permissions = loaded.direct.filter((permission)=>String(permission.target) !== input.target);
31
+ const result = await this.updateFolder.execute(input.folderId, {
32
+ permissions
33
+ });
34
+ if (result.isFail()) throw new Error(`Could not revoke access: ${result.error.message}`);
35
+ const folder = result.value;
36
+ return {
37
+ folderId: folder.id,
38
+ title: folder.title,
39
+ path: folder.path,
40
+ removed: {
41
+ target: input.target,
42
+ level: existing.level
43
+ },
44
+ permissions: (folder.permissions ?? []).filter((permission)=>!permission.inheritedFrom).map((permission)=>({
45
+ target: String(permission.target),
46
+ level: permission.level
47
+ }))
48
+ };
49
+ }
50
+ }
51
+ const RevokeFolderAccessTool = AiSdkTool.createImplementation({
52
+ implementation: RevokeFolderAccessToolImpl,
53
+ dependencies: [
54
+ GetFolderUseCase,
55
+ UpdateFolderUseCase
56
+ ]
57
+ });
58
+ export { RevokeFolderAccessTool };
59
+
60
+ //# sourceMappingURL=RevokeFolderAccessTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/RevokeFolderAccessTool.js","sources":["../../../src/features/ai/RevokeFolderAccessTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport type { IAiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { UpdateFolderUseCase } from \"~/features/folder/UpdateFolder/index.js\";\nimport { loadFolderPermissions } from \"./loadFolderPermissions.js\";\n\nconst inputSchema = z.object({\n folderId: z.string().describe(\"Folder id as returned by listFolders.\"),\n target: z\n .string()\n .describe(\n \"Whose access to remove: 'team:<slug>' or 'admin:<userId>', exactly as listFolders reports it.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface RevokeResult {\n folderId: string;\n title: string;\n path: string;\n removed: { target: string; level: string };\n /**\n * Every direct rule remaining afterwards.\n *\n * This is the set the update was asked to store, not an independent read of it:\n * `UpdateFolderWithFolderLevelPermissions` returns the permissions it derived from the input\n * rather than the ones the repository wrote. Treating it as a verification would let the tool\n * confirm its own request back to itself.\n */\n permissions: { target: string; level: string }[];\n}\n\n/**\n * Removes one target's direct access to one folder.\n *\n * Destructive: somebody loses access, and there is no undo. Refuses when the target has no DIRECT rule\n * rather than reporting a removal that changed nothing — an inherited grant cannot be revoked here,\n * only where it is defined, and saying otherwise would leave the user believing access was withdrawn.\n */\nclass RevokeFolderAccessToolImpl implements IAiSdkTool<Input> {\n readonly name = \"revokeFolderAccess\";\n readonly title = \"Revoke folder access\";\n readonly description =\n \"Removes one team's or user's direct access to one folder, leaving all other permissions untouched. Cannot remove inherited access. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, destructiveHint: true };\n\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n private updateFolder: UpdateFolderUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<RevokeResult> {\n const loaded = await loadFolderPermissions(this.getFolder, input.folderId);\n\n const existing = loaded.direct.find(\n permission => String(permission.target) === input.target\n );\n\n if (!existing) {\n if (loaded.inheritedTargets.has(input.target)) {\n throw new Error(\n `\"${input.target}\" has inherited access to this folder, not a direct rule, so it cannot be revoked here. Change it where it is defined.`\n );\n }\n\n throw new Error(\n `\"${input.target}\" has no direct access to this folder, so there is nothing to revoke.`\n );\n }\n\n const permissions = loaded.direct.filter(\n permission => String(permission.target) !== input.target\n );\n\n const result = await this.updateFolder.execute(input.folderId, { permissions });\n\n if (result.isFail()) {\n throw new Error(`Could not revoke access: ${result.error.message}`);\n }\n\n const folder = result.value;\n\n return {\n folderId: folder.id,\n title: folder.title,\n path: folder.path,\n removed: { target: input.target, level: existing.level },\n permissions: (folder.permissions ?? [])\n .filter(permission => !permission.inheritedFrom)\n .map(permission => ({ target: String(permission.target), level: permission.level }))\n };\n }\n}\n\nexport const RevokeFolderAccessTool = AiSdkTool.createImplementation({\n implementation: RevokeFolderAccessToolImpl,\n dependencies: [GetFolderUseCase, UpdateFolderUseCase]\n});\n"],"names":["inputSchema","z","RevokeFolderAccessToolImpl","getFolder","updateFolder","input","loaded","loadFolderPermissions","existing","permission","String","Error","permissions","result","folder","RevokeFolderAccessTool","AiSdkTool","GetFolderUseCase","UpdateFolderUseCase"],"mappings":";;;;;AAOA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,UAAUA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC9B,QAAQA,EAAAA,MACG,GACN,QAAQ,CACL;AAEZ;AA2BA,MAAMC;IAQF,YACYC,SAAqC,EACrCC,YAA2C,CACrD;aAFUD,SAAS,GAATA;aACAC,YAAY,GAAZA;aATH,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGJ;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,iBAAiB;QAAK;IAKjE;IAEH,MAAM,QAAQK,KAAY,EAAyB;QAC/C,MAAMC,SAAS,MAAMC,sBAAsB,IAAI,CAAC,SAAS,EAAEF,MAAM,QAAQ;QAEzE,MAAMG,WAAWF,OAAO,MAAM,CAAC,IAAI,CAC/BG,CAAAA,aAAcC,OAAOD,WAAW,MAAM,MAAMJ,MAAM,MAAM;QAG5D,IAAI,CAACG,UAAU;YACX,IAAIF,OAAO,gBAAgB,CAAC,GAAG,CAACD,MAAM,MAAM,GACxC,MAAM,IAAIM,MACN,CAAC,CAAC,EAAEN,MAAM,MAAM,CAAC,sHAAsH,CAAC;YAIhJ,MAAM,IAAIM,MACN,CAAC,CAAC,EAAEN,MAAM,MAAM,CAAC,qEAAqE,CAAC;QAE/F;QAEA,MAAMO,cAAcN,OAAO,MAAM,CAAC,MAAM,CACpCG,CAAAA,aAAcC,OAAOD,WAAW,MAAM,MAAMJ,MAAM,MAAM;QAG5D,MAAMQ,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACR,MAAM,QAAQ,EAAE;YAAEO;QAAY;QAE7E,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIF,MAAM,CAAC,yBAAyB,EAAEE,OAAO,KAAK,CAAC,OAAO,EAAE;QAGtE,MAAMC,SAASD,OAAO,KAAK;QAE3B,OAAO;YACH,UAAUC,OAAO,EAAE;YACnB,OAAOA,OAAO,KAAK;YACnB,MAAMA,OAAO,IAAI;YACjB,SAAS;gBAAE,QAAQT,MAAM,MAAM;gBAAE,OAAOG,SAAS,KAAK;YAAC;YACvD,aAAcM,AAAAA,CAAAA,OAAO,WAAW,IAAI,EAAC,EAChC,MAAM,CAACL,CAAAA,aAAc,CAACA,WAAW,aAAa,EAC9C,GAAG,CAACA,CAAAA,aAAe;oBAAE,QAAQC,OAAOD,WAAW,MAAM;oBAAG,OAAOA,WAAW,KAAK;gBAAC;QACzF;IACJ;AACJ;AAEO,MAAMM,yBAAyBC,UAAU,oBAAoB,CAAC;IACjE,gBAAgBd;IAChB,cAAc;QAACe;QAAkBC;KAAoB;AACzD"}
@@ -0,0 +1,10 @@
1
+ import type { ListTeamsUseCase } from "@webiny/api-core/features/security/teams/ListTeams/index.js";
2
+ /**
3
+ * Rejects a permission target that would be stored happily and then match nobody.
4
+ *
5
+ * A folder rule identifies a team by SLUG (`team:<slug>`) and a user by id (`admin:<userId>`) — see
6
+ * ListFolderLevelPermissionsTargets. The field is only typed as a template string, so a team id where
7
+ * a slug belongs is accepted and silently grants nothing. Also refuses a target the folder inherits,
8
+ * since rewriting it as a direct rule detaches the folder from where the grant came from.
9
+ */
10
+ export declare const assertTargetIsUsable: (listTeams: ListTeamsUseCase.Interface, target: string, inheritedTargets: Set<string>) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ const assertTargetIsUsable = async (listTeams, target, inheritedTargets)=>{
2
+ if (inheritedTargets.has(target)) throw new Error(`"${target}" is inherited from an ancestor folder or a role, so it cannot be changed on this folder. Change it where it is defined.`);
3
+ if (!target.startsWith("team:")) return;
4
+ const result = await listTeams.execute();
5
+ if (result.isFail()) throw new Error(`Could not verify the teams: ${result.error.message}`);
6
+ const value = target.slice(5);
7
+ if (result.value.some((team)=>team.slug === value)) return;
8
+ const byId = result.value.find((team)=>team.id === value);
9
+ if (byId) throw new Error(`"${target}" uses a team id. Use the slug instead: "team:${byId.slug}".`);
10
+ throw new Error(`"${target}" is not a known team. Call listTeams first.`);
11
+ };
12
+ export { assertTargetIsUsable };
13
+
14
+ //# sourceMappingURL=assertTargetIsUsable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/assertTargetIsUsable.js","sources":["../../../src/features/ai/assertTargetIsUsable.ts"],"sourcesContent":["import type { ListTeamsUseCase } from \"@webiny/api-core/features/security/teams/ListTeams/index.js\";\n\n/**\n * Rejects a permission target that would be stored happily and then match nobody.\n *\n * A folder rule identifies a team by SLUG (`team:<slug>`) and a user by id (`admin:<userId>`) — see\n * ListFolderLevelPermissionsTargets. The field is only typed as a template string, so a team id where\n * a slug belongs is accepted and silently grants nothing. Also refuses a target the folder inherits,\n * since rewriting it as a direct rule detaches the folder from where the grant came from.\n */\nexport const assertTargetIsUsable = async (\n listTeams: ListTeamsUseCase.Interface,\n target: string,\n inheritedTargets: Set<string>\n): Promise<void> => {\n if (inheritedTargets.has(target)) {\n throw new Error(\n `\"${target}\" is inherited from an ancestor folder or a role, so it cannot be changed on this folder. Change it where it is defined.`\n );\n }\n\n if (!target.startsWith(\"team:\")) {\n return;\n }\n\n const result = await listTeams.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not verify the teams: ${result.error.message}`);\n }\n\n const value = target.slice(\"team:\".length);\n\n if (result.value.some(team => team.slug === value)) {\n return;\n }\n\n const byId = result.value.find(team => team.id === value);\n\n if (byId) {\n throw new Error(`\"${target}\" uses a team id. Use the slug instead: \"team:${byId.slug}\".`);\n }\n\n throw new Error(`\"${target}\" is not a known team. Call listTeams first.`);\n};\n"],"names":["assertTargetIsUsable","listTeams","target","inheritedTargets","Error","result","value","team","byId"],"mappings":"AAUO,MAAMA,uBAAuB,OAChCC,WACAC,QACAC;IAEA,IAAIA,iBAAiB,GAAG,CAACD,SACrB,MAAM,IAAIE,MACN,CAAC,CAAC,EAAEF,OAAO,wHAAwH,CAAC;IAI5I,IAAI,CAACA,OAAO,UAAU,CAAC,UACnB;IAGJ,MAAMG,SAAS,MAAMJ,UAAU,OAAO;IAEtC,IAAII,OAAO,MAAM,IACb,MAAM,IAAID,MAAM,CAAC,4BAA4B,EAAEC,OAAO,KAAK,CAAC,OAAO,EAAE;IAGzE,MAAMC,QAAQJ,OAAO,KAAK,CAAC;IAE3B,IAAIG,OAAO,KAAK,CAAC,IAAI,CAACE,CAAAA,OAAQA,KAAK,IAAI,KAAKD,QACxC;IAGJ,MAAME,OAAOH,OAAO,KAAK,CAAC,IAAI,CAACE,CAAAA,OAAQA,KAAK,EAAE,KAAKD;IAEnD,IAAIE,MACA,MAAM,IAAIJ,MAAM,CAAC,CAAC,EAAEF,OAAO,8CAA8C,EAAEM,KAAK,IAAI,CAAC,EAAE,CAAC;IAG5F,MAAM,IAAIJ,MAAM,CAAC,CAAC,EAAEF,OAAO,4CAA4C,CAAC;AAC5E"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Folder and team tools for AI callers.
3
+ *
4
+ * The list tools are read-only and run unattended. Anything that creates or changes access is a write,
5
+ * so it pauses for the user to approve the exact arguments. Access changes are deliberately one target
6
+ * per call — granting and revoking separately means the approval block shows the entire change, rather
7
+ * than a desired end state whose omissions quietly remove somebody's access.
8
+ */
9
+ export declare const AcoAiToolsFeature: {
10
+ name: string;
11
+ register(container: import("@webiny/di").Container): void;
12
+ };
@@ -0,0 +1,23 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ListTeamsTool } from "./ListTeamsTool.js";
3
+ import { ListFoldersTool } from "./ListFoldersTool.js";
4
+ import { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
5
+ import { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
6
+ import { CreateFolderTool } from "./CreateFolderTool.js";
7
+ import { CreateTeamTool } from "./CreateTeamTool.js";
8
+ import { ListRolesTool } from "./ListRolesTool.js";
9
+ const AcoAiToolsFeature = createFeature({
10
+ name: "Aco/AiTools",
11
+ register (container) {
12
+ container.register(ListTeamsTool);
13
+ container.register(ListFoldersTool);
14
+ container.register(GrantFolderAccessTool);
15
+ container.register(RevokeFolderAccessTool);
16
+ container.register(CreateFolderTool);
17
+ container.register(CreateTeamTool);
18
+ container.register(ListRolesTool);
19
+ }
20
+ });
21
+ export { AcoAiToolsFeature };
22
+
23
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTeamsTool } from \"./ListTeamsTool.js\";\nimport { ListFoldersTool } from \"./ListFoldersTool.js\";\nimport { GrantFolderAccessTool } from \"./GrantFolderAccessTool.js\";\nimport { RevokeFolderAccessTool } from \"./RevokeFolderAccessTool.js\";\nimport { CreateFolderTool } from \"./CreateFolderTool.js\";\nimport { CreateTeamTool } from \"./CreateTeamTool.js\";\nimport { ListRolesTool } from \"./ListRolesTool.js\";\n\n/**\n * Folder and team tools for AI callers.\n *\n * The list tools are read-only and run unattended. Anything that creates or changes access is a write,\n * so it pauses for the user to approve the exact arguments. Access changes are deliberately one target\n * per call — granting and revoking separately means the approval block shows the entire change, rather\n * than a desired end state whose omissions quietly remove somebody's access.\n */\nexport const AcoAiToolsFeature = createFeature({\n name: \"Aco/AiTools\",\n register(container) {\n container.register(ListTeamsTool);\n container.register(ListFoldersTool);\n container.register(GrantFolderAccessTool);\n container.register(RevokeFolderAccessTool);\n container.register(CreateFolderTool);\n container.register(CreateTeamTool);\n container.register(ListRolesTool);\n }\n});\n"],"names":["AcoAiToolsFeature","createFeature","container","ListTeamsTool","ListFoldersTool","GrantFolderAccessTool","RevokeFolderAccessTool","CreateFolderTool","CreateTeamTool","ListRolesTool"],"mappings":";;;;;;;;AAiBO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;IACvB;AACJ"}
@@ -0,0 +1,8 @@
1
+ export { AcoAiToolsFeature } from "./feature.js";
2
+ export { ListTeamsTool } from "./ListTeamsTool.js";
3
+ export { ListFoldersTool } from "./ListFoldersTool.js";
4
+ export { ListRolesTool } from "./ListRolesTool.js";
5
+ export { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
6
+ export { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
7
+ export { CreateFolderTool } from "./CreateFolderTool.js";
8
+ export { CreateTeamTool } from "./CreateTeamTool.js";
@@ -0,0 +1,8 @@
1
+ export { AcoAiToolsFeature } from "./feature.js";
2
+ export { ListTeamsTool } from "./ListTeamsTool.js";
3
+ export { ListFoldersTool } from "./ListFoldersTool.js";
4
+ export { ListRolesTool } from "./ListRolesTool.js";
5
+ export { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
6
+ export { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
7
+ export { CreateFolderTool } from "./CreateFolderTool.js";
8
+ export { CreateTeamTool } from "./CreateTeamTool.js";
@@ -0,0 +1,16 @@
1
+ import type { GetFolderUseCase } from "../../features/folder/GetFolder/index.js";
2
+ import type { Folder, FolderPermission } from "../../types.js";
3
+ export interface LoadedFolderPermissions {
4
+ folder: Folder;
5
+ /** Rules set on this folder. The only ones it may change. */
6
+ direct: FolderPermission[];
7
+ /** Targets granted by an ancestor or a role. Writing these back would detach the inheritance. */
8
+ inheritedTargets: Set<string>;
9
+ }
10
+ /**
11
+ * Reads a folder and separates the rules it owns from the ones it merely inherits.
12
+ *
13
+ * Every permission write starts here, because the field holds both kinds and a change has to preserve
14
+ * the direct rules while leaving the inherited ones alone.
15
+ */
16
+ export declare const loadFolderPermissions: (getFolder: GetFolderUseCase.Interface, folderId: string) => Promise<LoadedFolderPermissions>;
@@ -0,0 +1,14 @@
1
+ const loadFolderPermissions = async (getFolder, folderId)=>{
2
+ const result = await getFolder.execute(folderId);
3
+ if (result.isFail()) throw new Error(`Folder "${folderId}" not found: ${result.error.message}. Call listFolders for valid ids.`);
4
+ const folder = result.value;
5
+ const permissions = folder.permissions ?? [];
6
+ return {
7
+ folder,
8
+ direct: permissions.filter((permission)=>!permission.inheritedFrom),
9
+ inheritedTargets: new Set(permissions.filter((permission)=>permission.inheritedFrom).map((p)=>String(p.target)))
10
+ };
11
+ };
12
+ export { loadFolderPermissions };
13
+
14
+ //# sourceMappingURL=loadFolderPermissions.js.map