@webiny/api-aco 6.4.11 → 6.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AcoFeature.d.ts +5 -0
- package/AcoFeature.js +129 -0
- package/AcoFeature.js.map +1 -0
- package/AcoFolderSchemaFactory.d.ts +30 -0
- package/AcoFolderSchemaFactory.js +64 -0
- package/AcoFolderSchemaFactory.js.map +1 -0
- package/createAcoGraphQL.d.ts +8 -4
- package/createAcoGraphQL.js +56 -96
- package/createAcoGraphQL.js.map +1 -1
- package/domain/folder/abstractions.d.ts +12 -5
- package/domain/folder/abstractions.js +2 -2
- package/domain/folder/abstractions.js.map +1 -1
- package/exports/api/aco/folder.d.ts +1 -1
- package/exports/api/aco/folder.js +1 -1
- package/features/ai/CreateFolderTool.d.ts +44 -0
- package/features/ai/CreateFolderTool.js +49 -0
- package/features/ai/CreateFolderTool.js.map +1 -0
- package/features/ai/CreateTeamTool.d.ts +43 -0
- package/features/ai/CreateTeamTool.js +47 -0
- package/features/ai/CreateTeamTool.js.map +1 -0
- package/features/ai/GrantFolderAccessTool.d.ts +72 -0
- package/features/ai/GrantFolderAccessTool.js +71 -0
- package/features/ai/GrantFolderAccessTool.js.map +1 -0
- package/features/ai/ListFoldersTool.d.ts +42 -0
- package/features/ai/ListFoldersTool.js +48 -0
- package/features/ai/ListFoldersTool.js.map +1 -0
- package/features/ai/ListRolesTool.d.ts +34 -0
- package/features/ai/ListRolesTool.js +39 -0
- package/features/ai/ListRolesTool.js.map +1 -0
- package/features/ai/ListTeamsTool.d.ts +34 -0
- package/features/ai/ListTeamsTool.js +39 -0
- package/features/ai/ListTeamsTool.js.map +1 -0
- package/features/ai/RevokeFolderAccessTool.d.ts +58 -0
- package/features/ai/RevokeFolderAccessTool.js +60 -0
- package/features/ai/RevokeFolderAccessTool.js.map +1 -0
- package/features/ai/assertTargetIsUsable.d.ts +10 -0
- package/features/ai/assertTargetIsUsable.js +14 -0
- package/features/ai/assertTargetIsUsable.js.map +1 -0
- package/features/ai/feature.d.ts +12 -0
- package/features/ai/feature.js +23 -0
- package/features/ai/feature.js.map +1 -0
- package/features/ai/index.d.ts +8 -0
- package/features/ai/index.js +8 -0
- package/features/ai/loadFolderPermissions.d.ts +16 -0
- package/features/ai/loadFolderPermissions.js +14 -0
- package/features/ai/loadFolderPermissions.js.map +1 -0
- package/features/cms/decorators/MoveEntryWithFlpDecorator.d.ts +1 -1
- package/features/flp/CreateFlp/CreateFlpUseCase.d.ts +3 -3
- package/features/flp/CreateFlp/CreateFlpUseCase.js +4 -4
- package/features/flp/CreateFlp/CreateFlpUseCase.js.map +1 -1
- package/features/flp/CreateFlp/feature.d.ts +1 -6
- package/features/flp/CreateFlp/feature.js +3 -2
- package/features/flp/CreateFlp/feature.js.map +1 -1
- package/features/flp/DeleteFlp/DeleteFlpUseCase.d.ts +3 -3
- package/features/flp/DeleteFlp/DeleteFlpUseCase.js +3 -3
- package/features/flp/DeleteFlp/DeleteFlpUseCase.js.map +1 -1
- package/features/flp/DeleteFlp/feature.d.ts +1 -6
- package/features/flp/DeleteFlp/feature.js +3 -2
- package/features/flp/DeleteFlp/feature.js.map +1 -1
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.d.ts +3 -3
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js +6 -6
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js.map +1 -1
- package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.d.ts +25 -0
- package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js +48 -0
- package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js.map +1 -0
- package/features/flp/FolderLevelPermissions/index.d.ts +1 -0
- package/features/flp/FolderLevelPermissions/index.js +1 -0
- package/features/flp/GetFlp/feature.d.ts +1 -1
- package/features/flp/GetFlp/feature.js +3 -2
- package/features/flp/GetFlp/feature.js.map +1 -1
- package/features/flp/ListFlps/feature.d.ts +1 -1
- package/features/flp/ListFlps/feature.js +3 -2
- package/features/flp/ListFlps/feature.js.map +1 -1
- package/features/flp/UpdateFlp/UpdateFlpUseCase.d.ts +11 -3
- package/features/flp/UpdateFlp/UpdateFlpUseCase.js +15 -13
- package/features/flp/UpdateFlp/UpdateFlpUseCase.js.map +1 -1
- package/features/flp/UpdateFlp/feature.d.ts +1 -6
- package/features/flp/UpdateFlp/feature.js +7 -2
- package/features/flp/UpdateFlp/feature.js.map +1 -1
- package/features/folder/CreateFolder/CreateFolderRepository.d.ts +3 -3
- package/features/folder/CreateFolder/CreateFolderRepository.js +10 -7
- package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
- package/features/folder/DeleteFolder/DeleteFolderRepository.d.ts +3 -3
- package/features/folder/DeleteFolder/DeleteFolderRepository.js +6 -5
- package/features/folder/DeleteFolder/DeleteFolderRepository.js.map +1 -1
- package/features/folder/DeleteFolder/decorators/DeleteFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.d.ts +1 -3
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +4 -7
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
- package/features/folder/EnsureHcmsFolderIsEmptyOnDelete/ModelFolderBeforeDeleteHandler.js +4 -1
- package/features/folder/EnsureHcmsFolderIsEmptyOnDelete/ModelFolderBeforeDeleteHandler.js.map +1 -1
- package/features/folder/FolderModelProvider.d.ts +26 -0
- package/features/folder/FolderModelProvider.js +22 -0
- package/features/folder/FolderModelProvider.js.map +1 -0
- package/features/folder/GetAncestors/GetAncestorsRepository.d.ts +3 -3
- package/features/folder/GetAncestors/GetAncestorsRepository.js +6 -5
- package/features/folder/GetAncestors/GetAncestorsRepository.js.map +1 -1
- package/features/folder/GetFolder/GetFolderRepository.d.ts +3 -3
- package/features/folder/GetFolder/GetFolderRepository.js +6 -5
- package/features/folder/GetFolder/GetFolderRepository.js.map +1 -1
- package/features/folder/GetFolder/decorators/GetFolderWithFolderLevelPermissions.d.ts +8 -8
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.d.ts +3 -3
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +10 -8
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
- package/features/folder/ListFolders/ListFoldersRepository.d.ts +3 -3
- package/features/folder/ListFolders/ListFoldersRepository.js +8 -7
- package/features/folder/ListFolders/ListFoldersRepository.js.map +1 -1
- package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +3 -3
- package/features/folder/UpdateFolder/UpdateFolderRepository.js +11 -8
- package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
- package/features/folder/shared/abstractions.d.ts +14 -0
- package/features/folder/shared/abstractions.js +4 -1
- package/features/folder/shared/abstractions.js.map +1 -1
- package/filter/filter.gql.d.ts +2 -3
- package/filter/filter.gql.js +61 -27
- package/filter/filter.gql.js.map +1 -1
- package/filter/filter.so.d.ts +10 -2
- package/filter/filter.so.js +2 -2
- package/filter/filter.so.js.map +1 -1
- package/flp/index.d.ts +0 -1
- package/flp/index.js +0 -1
- package/flp/tasks/createFlp.task.d.ts +2 -2
- package/flp/tasks/deleteFlp.task.d.ts +2 -2
- package/flp/tasks/index.d.ts +0 -1
- package/flp/tasks/index.js +1 -14
- package/flp/tasks/index.js.map +1 -1
- package/flp/tasks/syncFlp.task.d.ts +2 -2
- package/flp/tasks/syncFlp.task.js +7 -1
- package/flp/tasks/syncFlp.task.js.map +1 -1
- package/flp/tasks/updateFlp.task.d.ts +2 -2
- package/folder/folder.gql.d.ts +1 -1
- package/folder/folder.gql.js +10 -4
- package/folder/folder.gql.js.map +1 -1
- package/index.d.ts +1 -6
- package/index.js +1 -11
- package/package.json +24 -25
- package/utils/createOperationsWrapper.d.ts +5 -2
- package/utils/createOperationsWrapper.js +2 -2
- package/utils/createOperationsWrapper.js.map +1 -1
- package/utils/decorators/CmsEntriesCrudDecorators.js +9 -5
- package/utils/decorators/CmsEntriesCrudDecorators.js.map +1 -1
- package/utils/resolve.d.ts +2 -2
- package/utils/resolve.js +1 -1
- package/utils/resolve.js.map +1 -1
- package/createAcoContext.d.ts +0 -9
- package/createAcoContext.js +0 -108
- package/createAcoContext.js.map +0 -1
- package/createAcoStorageOperations.d.ts +0 -12
- package/createAcoStorageOperations.js +0 -9
- package/createAcoStorageOperations.js.map +0 -1
- package/createAcoTasks.d.ts +0 -1
- package/createAcoTasks.js +0 -14
- package/createAcoTasks.js.map +0 -1
- package/flp/flp.so.d.ts +0 -20
- package/flp/flp.so.js +0 -183
- package/flp/flp.so.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { CreateFolderUseCase } from "../folder/CreateFolder/index.js";
|
|
4
|
+
const inputSchema = z.object({
|
|
5
|
+
title: z.string().describe("Human-readable folder name, e.g. 'Marketing'."),
|
|
6
|
+
slug: z.string().describe("URL-safe identifier, e.g. 'marketing'. Lowercase, hyphens instead of spaces."),
|
|
7
|
+
type: z.string().describe("Folder namespace: 'FmFile' for File Manager, or 'cms:<modelId>' for a content model's folders."),
|
|
8
|
+
parentId: z.string().optional().describe("Id of the parent folder. Omit to create at the root of that namespace.")
|
|
9
|
+
});
|
|
10
|
+
class CreateFolderToolImpl {
|
|
11
|
+
constructor(createFolder){
|
|
12
|
+
this.createFolder = createFolder;
|
|
13
|
+
this.name = "createFolder";
|
|
14
|
+
this.title = "Create folder";
|
|
15
|
+
this.description = "Creates a folder in the File Manager ('FmFile') or under a content model ('cms:<modelId>'). Call listFolders first to pick a parent, or omit parentId for the root. Requires user approval.";
|
|
16
|
+
this.inputSchema = inputSchema;
|
|
17
|
+
this.annotations = {
|
|
18
|
+
readOnlyHint: false
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async execute(input) {
|
|
22
|
+
const params = {
|
|
23
|
+
title: input.title,
|
|
24
|
+
slug: input.slug,
|
|
25
|
+
type: input.type,
|
|
26
|
+
parentId: null
|
|
27
|
+
};
|
|
28
|
+
if (input.parentId) params.parentId = input.parentId;
|
|
29
|
+
const result = await this.createFolder.execute(params);
|
|
30
|
+
if (result.isFail()) throw new Error(`Could not create the folder: ${result.error.message}`);
|
|
31
|
+
const folder = result.value;
|
|
32
|
+
return {
|
|
33
|
+
id: folder.id,
|
|
34
|
+
title: folder.title,
|
|
35
|
+
slug: folder.slug,
|
|
36
|
+
path: folder.path,
|
|
37
|
+
type: folder.type
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const CreateFolderTool = AiSdkTool.createImplementation({
|
|
42
|
+
implementation: CreateFolderToolImpl,
|
|
43
|
+
dependencies: [
|
|
44
|
+
CreateFolderUseCase
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
export { CreateFolderTool };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=CreateFolderTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/CreateFolderTool.js","sources":["../../../src/features/ai/CreateFolderTool.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 { CreateFolderUseCase } from \"~/features/folder/CreateFolder/index.js\";\n\nconst inputSchema = z.object({\n title: z.string().describe(\"Human-readable folder name, e.g. 'Marketing'.\"),\n slug: z\n .string()\n .describe(\"URL-safe identifier, e.g. 'marketing'. Lowercase, hyphens instead of spaces.\"),\n type: z\n .string()\n .describe(\n \"Folder namespace: 'FmFile' for File Manager, or 'cms:<modelId>' for a content model's folders.\"\n ),\n parentId: z\n .string()\n .optional()\n .describe(\"Id of the parent folder. Omit to create at the root of that namespace.\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface CreatedFolder {\n id: string;\n title: string;\n slug: string;\n path: string;\n type: string;\n}\n\n/**\n * Creates a folder.\n *\n * Additive and reversible, so it is not flagged destructive — but it still changes the project, so it\n * is not read-only either and therefore needs the user to approve the exact arguments.\n */\nclass CreateFolderToolImpl implements IAiSdkTool<Input> {\n readonly name = \"createFolder\";\n readonly title = \"Create folder\";\n readonly description =\n \"Creates a folder in the File Manager ('FmFile') or under a content model ('cms:<modelId>'). Call listFolders first to pick a parent, or omit parentId for the root. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n\n constructor(private createFolder: CreateFolderUseCase.Interface) {}\n\n async execute(input: Input): Promise<CreatedFolder> {\n const params: {\n title: string;\n slug: string;\n type: string;\n parentId: string | null;\n } = {\n title: input.title,\n slug: input.slug,\n type: input.type,\n parentId: null\n };\n\n if (input.parentId) {\n params.parentId = input.parentId;\n }\n\n const result = await this.createFolder.execute(params);\n\n if (result.isFail()) {\n throw new Error(`Could not create the folder: ${result.error.message}`);\n }\n\n const folder = result.value;\n\n return {\n id: folder.id,\n title: folder.title,\n slug: folder.slug,\n path: folder.path,\n type: folder.type\n };\n }\n}\n\nexport const CreateFolderTool = AiSdkTool.createImplementation({\n implementation: CreateFolderToolImpl,\n dependencies: [CreateFolderUseCase]\n});\n"],"names":["inputSchema","z","CreateFolderToolImpl","createFolder","input","params","result","Error","folder","CreateFolderTool","AiSdkTool","CreateFolderUseCase"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,OAAOA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3B,MAAMA,EAAAA,MACK,GACN,QAAQ,CAAC;IACd,MAAMA,EAAAA,MACK,GACN,QAAQ,CACL;IAER,UAAUA,EAAAA,MACC,GACN,QAAQ,GACR,QAAQ,CAAC;AAClB;AAkBA,MAAMC;IAQF,YAAoBC,YAA2C,CAAE;aAA7CA,YAAY,GAAZA;aAPX,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGH;aACd,WAAW,GAAG;YAAE,cAAc;QAAM;IAEqB;IAElE,MAAM,QAAQI,KAAY,EAA0B;QAChD,MAAMC,SAKF;YACA,OAAOD,MAAM,KAAK;YAClB,MAAMA,MAAM,IAAI;YAChB,MAAMA,MAAM,IAAI;YAChB,UAAU;QACd;QAEA,IAAIA,MAAM,QAAQ,EACdC,OAAO,QAAQ,GAAGD,MAAM,QAAQ;QAGpC,MAAME,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACD;QAE/C,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,6BAA6B,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAG1E,MAAME,SAASF,OAAO,KAAK;QAE3B,OAAO;YACH,IAAIE,OAAO,EAAE;YACb,OAAOA,OAAO,KAAK;YACnB,MAAMA,OAAO,IAAI;YACjB,MAAMA,OAAO,IAAI;YACjB,MAAMA,OAAO,IAAI;QACrB;IACJ;AACJ;AAEO,MAAMC,mBAAmBC,UAAU,oBAAoB,CAAC;IAC3D,gBAAgBR;IAChB,cAAc;QAACS;KAAoB;AACvC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { IAiSdkTool } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { CreateTeam } from "@webiny/api-core/features/security/teams/CreateTeam/index.js";
|
|
4
|
+
declare const inputSchema: z.ZodObject<{
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
slug: z.ZodString;
|
|
7
|
+
description: z.ZodOptional<z.ZodString>;
|
|
8
|
+
roles: z.ZodArray<z.ZodString>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
type Input = z.infer<typeof inputSchema>;
|
|
11
|
+
interface CreatedTeam {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
slug: string;
|
|
15
|
+
roles: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a team.
|
|
19
|
+
*
|
|
20
|
+
* Not read-only, so it needs approval: a team is an access-control object, and the roles it carries
|
|
21
|
+
* decide what its members can do. The user should see which roles are being granted before it exists.
|
|
22
|
+
*/
|
|
23
|
+
declare class CreateTeamToolImpl implements IAiSdkTool<Input> {
|
|
24
|
+
private createTeam;
|
|
25
|
+
readonly name = "createTeam";
|
|
26
|
+
readonly title = "Create team";
|
|
27
|
+
readonly description = "Creates a team with a set of roles. Call listRoles first and pass what it returns; do not guess role identifiers. Requires user approval.";
|
|
28
|
+
readonly inputSchema: z.ZodObject<{
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
slug: z.ZodString;
|
|
31
|
+
description: z.ZodOptional<z.ZodString>;
|
|
32
|
+
roles: z.ZodArray<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
readonly annotations: {
|
|
35
|
+
readOnlyHint: boolean;
|
|
36
|
+
};
|
|
37
|
+
constructor(createTeam: CreateTeam.Interface);
|
|
38
|
+
execute(input: Input): Promise<CreatedTeam>;
|
|
39
|
+
}
|
|
40
|
+
export declare const CreateTeamTool: typeof CreateTeamToolImpl & {
|
|
41
|
+
__abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { CreateTeam } from "@webiny/api-core/features/security/teams/CreateTeam/index.js";
|
|
4
|
+
import { descriptionOnCreate } from "@webiny/api-core/features/security/shared/index.js";
|
|
5
|
+
const inputSchema = z.object({
|
|
6
|
+
name: z.string().describe("Human-readable team name, e.g. 'Marketing'."),
|
|
7
|
+
slug: z.string().describe("URL-safe identifier, e.g. 'marketing'. Lowercase, hyphens instead of spaces."),
|
|
8
|
+
description: z.string().max(500).optional().describe("What the team is for. Shown in the admin UI. Omit it if the user did not say."),
|
|
9
|
+
roles: z.array(z.string()).describe("Roles from listRoles. Prefer the `id`; a `slug` is accepted and resolved for you. Resolve them with listRoles first, since an unknown value is rejected rather than stored.")
|
|
10
|
+
});
|
|
11
|
+
class CreateTeamToolImpl {
|
|
12
|
+
constructor(createTeam){
|
|
13
|
+
this.createTeam = createTeam;
|
|
14
|
+
this.name = "createTeam";
|
|
15
|
+
this.title = "Create team";
|
|
16
|
+
this.description = "Creates a team with a set of roles. Call listRoles first and pass what it returns; do not guess role identifiers. Requires user approval.";
|
|
17
|
+
this.inputSchema = inputSchema;
|
|
18
|
+
this.annotations = {
|
|
19
|
+
readOnlyHint: false
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async execute(input) {
|
|
23
|
+
const result = await this.createTeam.execute({
|
|
24
|
+
name: input.name,
|
|
25
|
+
slug: input.slug,
|
|
26
|
+
description: descriptionOnCreate(input.description),
|
|
27
|
+
roles: input.roles
|
|
28
|
+
});
|
|
29
|
+
if (result.isFail()) throw new Error(`Could not create the team: ${result.error.message}`);
|
|
30
|
+
const team = result.value;
|
|
31
|
+
return {
|
|
32
|
+
id: team.id,
|
|
33
|
+
name: team.name,
|
|
34
|
+
slug: team.slug,
|
|
35
|
+
roles: team.roles
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const CreateTeamTool = AiSdkTool.createImplementation({
|
|
40
|
+
implementation: CreateTeamToolImpl,
|
|
41
|
+
dependencies: [
|
|
42
|
+
CreateTeam
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
export { CreateTeamTool };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=CreateTeamTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/CreateTeamTool.js","sources":["../../../src/features/ai/CreateTeamTool.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 { CreateTeam } from \"@webiny/api-core/features/security/teams/CreateTeam/index.js\";\nimport { descriptionOnCreate } from \"@webiny/api-core/features/security/shared/index.js\";\n\nconst inputSchema = z.object({\n name: z.string().describe(\"Human-readable team name, e.g. 'Marketing'.\"),\n slug: z\n .string()\n .describe(\"URL-safe identifier, e.g. 'marketing'. Lowercase, hyphens instead of spaces.\"),\n /*\n * Optional and capped, mirroring the use case's own schema. Requiring it made the model invent a\n * description for every team; `CreateTeam` treats an absent one as empty via `descriptionOnCreate`.\n */\n description: z\n .string()\n .max(500)\n .optional()\n .describe(\"What the team is for. Shown in the admin UI. Omit it if the user did not say.\"),\n roles: z\n .array(z.string())\n .describe(\n \"Roles from listRoles. Prefer the `id`; a `slug` is accepted and resolved for you. Resolve them with listRoles first, since an unknown value is rejected rather than stored.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface CreatedTeam {\n id: string;\n name: string;\n slug: string;\n roles: string[];\n}\n\n/**\n * Creates a team.\n *\n * Not read-only, so it needs approval: a team is an access-control object, and the roles it carries\n * decide what its members can do. The user should see which roles are being granted before it exists.\n */\nclass CreateTeamToolImpl implements IAiSdkTool<Input> {\n readonly name = \"createTeam\";\n readonly title = \"Create team\";\n readonly description =\n \"Creates a team with a set of roles. Call listRoles first and pass what it returns; do not guess role identifiers. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n\n constructor(private createTeam: CreateTeam.Interface) {}\n\n async execute(input: Input): Promise<CreatedTeam> {\n /*\n * Roles go through untouched. `CreateTeam` accepts a role id or a slug and resolves either to\n * the id a team stores, so the tool has nothing to add: doing it here too would read the roles\n * a second time and leave two copies of the same rule to keep in step.\n */\n const result = await this.createTeam.execute({\n name: input.name,\n slug: input.slug,\n // An omitted description becomes \"\", the same mapping the use case applies to its own input.\n description: descriptionOnCreate(input.description),\n roles: input.roles\n });\n\n if (result.isFail()) {\n throw new Error(`Could not create the team: ${result.error.message}`);\n }\n\n const team = result.value;\n\n return {\n id: team.id,\n name: team.name,\n slug: team.slug,\n // From the created team, so the caller sees the resolved ids that were actually stored.\n roles: team.roles\n };\n }\n}\n\nexport const CreateTeamTool = AiSdkTool.createImplementation({\n implementation: CreateTeamToolImpl,\n dependencies: [CreateTeam]\n});\n"],"names":["inputSchema","z","CreateTeamToolImpl","createTeam","input","result","descriptionOnCreate","Error","team","CreateTeamTool","AiSdkTool","CreateTeam"],"mappings":";;;;AAMA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,MAAMA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,MAAMA,EAAAA,MACK,GACN,QAAQ,CAAC;IAKd,aAAaA,EAAAA,MACF,GACN,GAAG,CAAC,KACJ,QAAQ,GACR,QAAQ,CAAC;IACd,OAAOA,EAAAA,KACG,CAACA,EAAE,MAAM,IACd,QAAQ,CACL;AAEZ;AAiBA,MAAMC;IAQF,YAAoBC,UAAgC,CAAE;aAAlCA,UAAU,GAAVA;aAPX,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGH;aACd,WAAW,GAAG;YAAE,cAAc;QAAM;IAEU;IAEvD,MAAM,QAAQI,KAAY,EAAwB;QAM9C,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACzC,MAAMD,MAAM,IAAI;YAChB,MAAMA,MAAM,IAAI;YAEhB,aAAaE,oBAAoBF,MAAM,WAAW;YAClD,OAAOA,MAAM,KAAK;QACtB;QAEA,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIE,MAAM,CAAC,2BAA2B,EAAEF,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,MAAMG,OAAOH,OAAO,KAAK;QAEzB,OAAO;YACH,IAAIG,KAAK,EAAE;YACX,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YAEf,OAAOA,KAAK,KAAK;QACrB;IACJ;AACJ;AAEO,MAAMC,iBAAiBC,UAAU,oBAAoB,CAAC;IACzD,gBAAgBR;IAChB,cAAc;QAACS;KAAW;AAC9B"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
import { GetFolderUseCase } from "../../features/folder/GetFolder/index.js";
|
|
5
|
+
import { UpdateFolderUseCase } from "../../features/folder/UpdateFolder/index.js";
|
|
6
|
+
declare const inputSchema: z.ZodObject<{
|
|
7
|
+
folderId: z.ZodString;
|
|
8
|
+
target: z.ZodString;
|
|
9
|
+
level: z.ZodEnum<{
|
|
10
|
+
editor: "editor";
|
|
11
|
+
"no-access": "no-access";
|
|
12
|
+
owner: "owner";
|
|
13
|
+
public: "public";
|
|
14
|
+
viewer: "viewer";
|
|
15
|
+
}>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
type Input = z.infer<typeof inputSchema>;
|
|
18
|
+
interface GrantResult {
|
|
19
|
+
folderId: string;
|
|
20
|
+
title: string;
|
|
21
|
+
path: string;
|
|
22
|
+
/**
|
|
23
|
+
* Every direct rule on the folder afterwards.
|
|
24
|
+
*
|
|
25
|
+
* This is the set the update was asked to store, not an independent read of it:
|
|
26
|
+
* `UpdateFolderWithFolderLevelPermissions` returns the permissions it derived from the input
|
|
27
|
+
* rather than the ones the repository wrote. Treating it as a verification would let the tool
|
|
28
|
+
* confirm its own request back to itself.
|
|
29
|
+
*/
|
|
30
|
+
permissions: {
|
|
31
|
+
target: string;
|
|
32
|
+
level: string;
|
|
33
|
+
}[];
|
|
34
|
+
/** True when the target already had a direct rule and its level was changed. */
|
|
35
|
+
replacedExistingLevel?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Grants one target access to one folder, leaving every other rule alone.
|
|
39
|
+
*
|
|
40
|
+
* Additive by design. The earlier tool took the complete permission set and replaced it, which meant
|
|
41
|
+
* approving a change showed what would be SET and said nothing about what would be removed — a rule
|
|
42
|
+
* the model omitted disappeared silently. One target per call keeps the approval honest: what the user
|
|
43
|
+
* sees in the plan is the whole change.
|
|
44
|
+
*/
|
|
45
|
+
declare class GrantFolderAccessToolImpl implements IAiSdkTool<Input> {
|
|
46
|
+
private getFolder;
|
|
47
|
+
private updateFolder;
|
|
48
|
+
private listTeams;
|
|
49
|
+
readonly name = "grantFolderAccess";
|
|
50
|
+
readonly title = "Grant folder access";
|
|
51
|
+
readonly 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.";
|
|
52
|
+
readonly inputSchema: z.ZodObject<{
|
|
53
|
+
folderId: z.ZodString;
|
|
54
|
+
target: z.ZodString;
|
|
55
|
+
level: z.ZodEnum<{
|
|
56
|
+
editor: "editor";
|
|
57
|
+
"no-access": "no-access";
|
|
58
|
+
owner: "owner";
|
|
59
|
+
public: "public";
|
|
60
|
+
viewer: "viewer";
|
|
61
|
+
}>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
readonly annotations: {
|
|
64
|
+
readOnlyHint: boolean;
|
|
65
|
+
};
|
|
66
|
+
constructor(getFolder: GetFolderUseCase.Interface, updateFolder: UpdateFolderUseCase.Interface, listTeams: ListTeamsUseCase.Interface);
|
|
67
|
+
execute(input: Input): Promise<GrantResult>;
|
|
68
|
+
}
|
|
69
|
+
export declare const GrantFolderAccessTool: typeof GrantFolderAccessToolImpl & {
|
|
70
|
+
__abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
|
|
71
|
+
};
|
|
72
|
+
export {};
|
|
@@ -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"}
|