@webiny/api-aco 6.6.0-alpha.10 → 6.6.0-alpha.11
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/features/ai/CreateRoleTool.d.ts +54 -0
- package/features/ai/CreateRoleTool.js +71 -0
- package/features/ai/CreateRoleTool.js.map +1 -0
- package/features/ai/DeleteRoleTool.d.ts +52 -0
- package/features/ai/DeleteRoleTool.js +79 -0
- package/features/ai/DeleteRoleTool.js.map +1 -0
- package/features/ai/DeleteTeamTool.d.ts +46 -0
- package/features/ai/DeleteTeamTool.js +56 -0
- package/features/ai/DeleteTeamTool.js.map +1 -0
- package/features/ai/ListRolesTool.d.ts +1 -1
- package/features/ai/ListRolesTool.js +1 -1
- package/features/ai/ListRolesTool.js.map +1 -1
- package/features/ai/ListTeamsTool.d.ts +3 -1
- package/features/ai/ListTeamsTool.js +3 -2
- package/features/ai/ListTeamsTool.js.map +1 -1
- package/features/ai/UpdateFolderTool.d.ts +57 -0
- package/features/ai/UpdateFolderTool.js +72 -0
- package/features/ai/UpdateFolderTool.js.map +1 -0
- package/features/ai/UpdateRoleTool.d.ts +46 -0
- package/features/ai/UpdateRoleTool.js +53 -0
- package/features/ai/UpdateRoleTool.js.map +1 -0
- package/features/ai/UpdateTeamTool.d.ts +52 -0
- package/features/ai/UpdateTeamTool.js +56 -0
- package/features/ai/UpdateTeamTool.js.map +1 -0
- package/features/ai/feature.d.ts +2 -2
- package/features/ai/feature.js +12 -0
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +6 -0
- package/features/ai/index.js +6 -0
- package/features/ai/loadFolderPermissions.d.ts +4 -1
- package/features/ai/loadFolderPermissions.js +1 -1
- package/features/ai/loadFolderPermissions.js.map +1 -1
- package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.d.ts +1 -1
- package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js +1 -1
- package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js.map +1 -1
- package/features/folder/UpdateFolder/UpdateFolderUseCase.d.ts +1 -0
- package/features/folder/UpdateFolder/UpdateFolderUseCase.js +13 -0
- package/features/folder/UpdateFolder/UpdateFolderUseCase.js.map +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +4 -2
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
- package/flpTaskCatalog/tasks/syncFlp.task.js +20 -13
- package/flpTaskCatalog/tasks/syncFlp.task.js.map +1 -1
- package/folder/folder.types.d.ts +2 -1
- package/package.json +18 -19
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
4
|
+
import { CreateRoleUseCase } from "@webiny/api-core/features/security/roles/CreateRole/index.js";
|
|
5
|
+
import { GetRoleUseCase } from "@webiny/api-core/features/security/roles/GetRole/index.js";
|
|
6
|
+
declare const inputSchema: z.ZodObject<{
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
slug: z.ZodString;
|
|
9
|
+
description: z.ZodOptional<z.ZodString>;
|
|
10
|
+
copyPermissionsFrom: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
type Input = z.infer<typeof inputSchema>;
|
|
13
|
+
interface CreatedRole {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
/** The role the permissions were copied from, so the reply can say where they came from. */
|
|
18
|
+
permissionsCopiedFrom?: string;
|
|
19
|
+
}
|
|
20
|
+
declare class CreateRoleToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
|
|
21
|
+
private getRole;
|
|
22
|
+
private createRole;
|
|
23
|
+
constructor(getRole: GetRoleUseCase.Interface, createRole: CreateRoleUseCase.Interface);
|
|
24
|
+
execute(input: Input): Promise<CreatedRole>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a role, empty or with the permissions of an existing one.
|
|
28
|
+
*
|
|
29
|
+
* The model never writes permission objects. They are app-specific records with keys the model
|
|
30
|
+
* would have to guess, and the approval card would show a list of them the user cannot check. A
|
|
31
|
+
* role it creates either starts empty, for the user to fill in on the Roles screen, or copies a
|
|
32
|
+
* role the user names, which the approval shows by id.
|
|
33
|
+
*/
|
|
34
|
+
declare class CreateRoleToolImpl implements AiSdkToolDefinition.Interface<Input> {
|
|
35
|
+
readonly name = "createRole";
|
|
36
|
+
readonly title = "Create role";
|
|
37
|
+
readonly description = "Creates a security role. It starts with no permissions, or with a copy of an existing role's permissions when `copyPermissionsFrom` is given (call listRoles for the id). Permissions cannot be written directly; the user edits them on the Roles screen. Requires user approval.";
|
|
38
|
+
readonly inputSchema: z.ZodObject<{
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
slug: z.ZodString;
|
|
41
|
+
description: z.ZodOptional<z.ZodString>;
|
|
42
|
+
copyPermissionsFrom: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
readonly annotations: {
|
|
45
|
+
readOnlyHint: boolean;
|
|
46
|
+
};
|
|
47
|
+
readonly handler: typeof CreateRoleToolHandlerImpl & {
|
|
48
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export declare const CreateRoleTool: typeof CreateRoleToolImpl & {
|
|
52
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
|
|
53
|
+
};
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { CreateRoleUseCase } from "@webiny/api-core/features/security/roles/CreateRole/index.js";
|
|
4
|
+
import { GetRoleUseCase } from "@webiny/api-core/features/security/roles/GetRole/index.js";
|
|
5
|
+
import { descriptionOnCreate } from "@webiny/api-core/features/security/shared/index.js";
|
|
6
|
+
const inputSchema = z.object({
|
|
7
|
+
name: z.string().min(3).describe("Human-readable role name, e.g. 'Blog editor'."),
|
|
8
|
+
slug: z.string().min(3).describe("URL-safe identifier, e.g. 'blog-editor'. Lowercase, hyphens instead of spaces."),
|
|
9
|
+
description: z.string().max(500).optional().describe("What the role is for. Shown in the admin UI. Omit it if the user did not say."),
|
|
10
|
+
copyPermissionsFrom: z.string().optional().describe("Id of an existing role, from listRoles, whose permissions the new role starts with. Omit it to create the role with no permissions.")
|
|
11
|
+
});
|
|
12
|
+
class CreateRoleToolHandlerImpl {
|
|
13
|
+
constructor(getRole, createRole){
|
|
14
|
+
this.getRole = getRole;
|
|
15
|
+
this.createRole = createRole;
|
|
16
|
+
}
|
|
17
|
+
async execute(input) {
|
|
18
|
+
let permissions = [];
|
|
19
|
+
let source;
|
|
20
|
+
if (input.copyPermissionsFrom) {
|
|
21
|
+
const found = await this.getRole.execute({
|
|
22
|
+
id: input.copyPermissionsFrom
|
|
23
|
+
});
|
|
24
|
+
if (found.isFail()) throw new Error(`Role "${input.copyPermissionsFrom}" not found: ${found.error.message}. Call listRoles for valid ids.`);
|
|
25
|
+
permissions = found.value.permissions;
|
|
26
|
+
source = found.value.name;
|
|
27
|
+
}
|
|
28
|
+
const description = descriptionOnCreate(input.description);
|
|
29
|
+
const result = await this.createRole.execute({
|
|
30
|
+
name: input.name,
|
|
31
|
+
slug: input.slug,
|
|
32
|
+
description,
|
|
33
|
+
permissions
|
|
34
|
+
});
|
|
35
|
+
if (result.isFail()) throw new Error(`Could not create the role: ${result.error.message}`);
|
|
36
|
+
const role = result.value;
|
|
37
|
+
const created = {
|
|
38
|
+
id: role.id,
|
|
39
|
+
name: role.name,
|
|
40
|
+
slug: role.slug
|
|
41
|
+
};
|
|
42
|
+
if (source) created.permissionsCopiedFrom = source;
|
|
43
|
+
return created;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const CreateRoleToolHandler = AiSdkToolHandler.createImplementation({
|
|
47
|
+
implementation: CreateRoleToolHandlerImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
GetRoleUseCase,
|
|
50
|
+
CreateRoleUseCase
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
class CreateRoleToolImpl {
|
|
54
|
+
constructor(){
|
|
55
|
+
this.name = "createRole";
|
|
56
|
+
this.title = "Create role";
|
|
57
|
+
this.description = "Creates a security role. It starts with no permissions, or with a copy of an existing role's permissions when `copyPermissionsFrom` is given (call listRoles for the id). Permissions cannot be written directly; the user edits them on the Roles screen. Requires user approval.";
|
|
58
|
+
this.inputSchema = inputSchema;
|
|
59
|
+
this.annotations = {
|
|
60
|
+
readOnlyHint: false
|
|
61
|
+
};
|
|
62
|
+
this.handler = CreateRoleToolHandler;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const CreateRoleTool = AiSdkToolDefinition.createImplementation({
|
|
66
|
+
implementation: CreateRoleToolImpl,
|
|
67
|
+
dependencies: []
|
|
68
|
+
});
|
|
69
|
+
export { CreateRoleTool };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=CreateRoleTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/CreateRoleTool.js","sources":["../../../src/features/ai/CreateRoleTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"@webiny/api-core/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { CreateRoleUseCase } from \"@webiny/api-core/features/security/roles/CreateRole/index.js\";\nimport { GetRoleUseCase } from \"@webiny/api-core/features/security/roles/GetRole/index.js\";\nimport { descriptionOnCreate } from \"@webiny/api-core/features/security/shared/index.js\";\nimport type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\n\nconst inputSchema = z.object({\n name: z.string().min(3).describe(\"Human-readable role name, e.g. 'Blog editor'.\"),\n slug: z\n .string()\n .min(3)\n .describe(\"URL-safe identifier, e.g. 'blog-editor'. Lowercase, hyphens instead of spaces.\"),\n description: z\n .string()\n .max(500)\n .optional()\n .describe(\"What the role is for. Shown in the admin UI. Omit it if the user did not say.\"),\n copyPermissionsFrom: z\n .string()\n .optional()\n .describe(\n \"Id of an existing role, from listRoles, whose permissions the new role starts with. Omit it to create the role with no permissions.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface CreatedRole {\n id: string;\n name: string;\n slug: string;\n /** The role the permissions were copied from, so the reply can say where they came from. */\n permissionsCopiedFrom?: string;\n}\n\nclass CreateRoleToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getRole: GetRoleUseCase.Interface,\n private createRole: CreateRoleUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<CreatedRole> {\n let permissions: SecurityPermission[] = [];\n let source: string | undefined;\n\n if (input.copyPermissionsFrom) {\n const found = await this.getRole.execute({ id: input.copyPermissionsFrom });\n\n if (found.isFail()) {\n throw new Error(\n `Role \"${input.copyPermissionsFrom}\" not found: ${found.error.message}. Call listRoles for valid ids.`\n );\n }\n\n permissions = found.value.permissions;\n source = found.value.name;\n }\n\n const description = descriptionOnCreate(input.description);\n const result = await this.createRole.execute({\n name: input.name,\n slug: input.slug,\n description,\n permissions\n });\n\n if (result.isFail()) {\n throw new Error(`Could not create the role: ${result.error.message}`);\n }\n\n const role = result.value;\n const created: CreatedRole = { id: role.id, name: role.name, slug: role.slug };\n\n if (source) {\n created.permissionsCopiedFrom = source;\n }\n\n return created;\n }\n}\n\nconst CreateRoleToolHandler = AiSdkToolHandler.createImplementation({\n implementation: CreateRoleToolHandlerImpl,\n dependencies: [GetRoleUseCase, CreateRoleUseCase]\n});\n\n/**\n * Creates a role, empty or with the permissions of an existing one.\n *\n * The model never writes permission objects. They are app-specific records with keys the model\n * would have to guess, and the approval card would show a list of them the user cannot check. A\n * role it creates either starts empty, for the user to fill in on the Roles screen, or copies a\n * role the user names, which the approval shows by id.\n */\nclass CreateRoleToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"createRole\";\n readonly title = \"Create role\";\n readonly description =\n \"Creates a security role. It starts with no permissions, or with a copy of an existing role's permissions when `copyPermissionsFrom` is given (call listRoles for the id). Permissions cannot be written directly; the user edits them on the Roles screen. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n readonly handler = CreateRoleToolHandler;\n}\n\nexport const CreateRoleTool = AiSdkToolDefinition.createImplementation({\n implementation: CreateRoleToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","CreateRoleToolHandlerImpl","getRole","createRole","input","permissions","source","found","Error","description","descriptionOnCreate","result","role","created","CreateRoleToolHandler","AiSdkToolHandler","GetRoleUseCase","CreateRoleUseCase","CreateRoleToolImpl","CreateRoleTool","AiSdkToolDefinition"],"mappings":";;;;;AAQA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ,CAAC;IACjC,MAAMA,EAAAA,MACK,GACN,GAAG,CAAC,GACJ,QAAQ,CAAC;IACd,aAAaA,EAAAA,MACF,GACN,GAAG,CAAC,KACJ,QAAQ,GACR,QAAQ,CAAC;IACd,qBAAqBA,EAAAA,MACV,GACN,QAAQ,GACR,QAAQ,CACL;AAEZ;AAYA,MAAMC;IACF,YACYC,OAAiC,EACjCC,UAAuC,CACjD;aAFUD,OAAO,GAAPA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAwB;QAC9C,IAAIC,cAAoC,EAAE;QAC1C,IAAIC;QAEJ,IAAIF,MAAM,mBAAmB,EAAE;YAC3B,MAAMG,QAAQ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;gBAAE,IAAIH,MAAM,mBAAmB;YAAC;YAEzE,IAAIG,MAAM,MAAM,IACZ,MAAM,IAAIC,MACN,CAAC,MAAM,EAAEJ,MAAM,mBAAmB,CAAC,aAAa,EAAEG,MAAM,KAAK,CAAC,OAAO,CAAC,+BAA+B,CAAC;YAI9GF,cAAcE,MAAM,KAAK,CAAC,WAAW;YACrCD,SAASC,MAAM,KAAK,CAAC,IAAI;QAC7B;QAEA,MAAME,cAAcC,oBAAoBN,MAAM,WAAW;QACzD,MAAMO,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACzC,MAAMP,MAAM,IAAI;YAChB,MAAMA,MAAM,IAAI;YAChBK;YACAJ;QACJ;QAEA,IAAIM,OAAO,MAAM,IACb,MAAM,IAAIH,MAAM,CAAC,2BAA2B,EAAEG,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,MAAMC,OAAOD,OAAO,KAAK;QACzB,MAAME,UAAuB;YAAE,IAAID,KAAK,EAAE;YAAE,MAAMA,KAAK,IAAI;YAAE,MAAMA,KAAK,IAAI;QAAC;QAE7E,IAAIN,QACAO,QAAQ,qBAAqB,GAAGP;QAGpC,OAAOO;IACX;AACJ;AAEA,MAAMC,wBAAwBC,iBAAiB,oBAAoB,CAAC;IAChE,gBAAgBd;IAChB,cAAc;QAACe;QAAgBC;KAAkB;AACrD;AAUA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGnB;aACd,WAAW,GAAG;YAAE,cAAc;QAAM;aACpC,OAAO,GAAGe;;AACvB;AAEO,MAAMK,iBAAiBC,oBAAoB,oBAAoB,CAAC;IACnE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
4
|
+
import { GetRoleUseCase } from "@webiny/api-core/features/security/roles/GetRole/index.js";
|
|
5
|
+
import { DeleteRoleUseCase } from "@webiny/api-core/features/security/roles/DeleteRole/index.js";
|
|
6
|
+
import { ListTeamsUseCase } from "@webiny/api-core/features/security/teams/ListTeams/index.js";
|
|
7
|
+
import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
|
|
8
|
+
declare const inputSchema: z.ZodObject<{
|
|
9
|
+
roleId: z.ZodString;
|
|
10
|
+
name: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
type Input = z.infer<typeof inputSchema>;
|
|
13
|
+
interface DeletedRole {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
}
|
|
18
|
+
declare class DeleteRoleToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
|
|
19
|
+
private getRole;
|
|
20
|
+
private listTeams;
|
|
21
|
+
private listUsers;
|
|
22
|
+
private deleteRole;
|
|
23
|
+
constructor(getRole: GetRoleUseCase.Interface, listTeams: ListTeamsUseCase.Interface, listUsers: ListUsersUseCase.Interface, deleteRole: DeleteRoleUseCase.Interface);
|
|
24
|
+
execute(input: Input): Promise<DeletedRole>;
|
|
25
|
+
private findHolders;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Deletes one role that nothing uses.
|
|
29
|
+
*
|
|
30
|
+
* Destructive, so the approval says it cannot be undone. Refuses system roles, roles defined in
|
|
31
|
+
* code, and roles still given to a team or a user.
|
|
32
|
+
*/
|
|
33
|
+
declare class DeleteRoleToolImpl implements AiSdkToolDefinition.Interface<Input> {
|
|
34
|
+
readonly name = "deleteRole";
|
|
35
|
+
readonly title = "Delete role";
|
|
36
|
+
readonly description = "Deletes one role. Refused for system roles, roles defined in code, and roles still given to a team or user (the error names them). Call listRoles first for the id and exact name. Requires user approval.";
|
|
37
|
+
readonly inputSchema: z.ZodObject<{
|
|
38
|
+
roleId: z.ZodString;
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
readonly annotations: {
|
|
42
|
+
readOnlyHint: boolean;
|
|
43
|
+
destructiveHint: boolean;
|
|
44
|
+
};
|
|
45
|
+
readonly handler: typeof DeleteRoleToolHandlerImpl & {
|
|
46
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export declare const DeleteRoleTool: typeof DeleteRoleToolImpl & {
|
|
50
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { GetRoleUseCase } from "@webiny/api-core/features/security/roles/GetRole/index.js";
|
|
4
|
+
import { DeleteRoleUseCase } from "@webiny/api-core/features/security/roles/DeleteRole/index.js";
|
|
5
|
+
import { ListTeamsUseCase } from "@webiny/api-core/features/security/teams/ListTeams/index.js";
|
|
6
|
+
import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
|
|
7
|
+
const inputSchema = z.object({
|
|
8
|
+
roleId: z.string().describe("Role id as returned by listRoles."),
|
|
9
|
+
name: z.string().describe("The role's current name, exactly as listRoles returned it. The delete is refused if it does not match.")
|
|
10
|
+
});
|
|
11
|
+
class DeleteRoleToolHandlerImpl {
|
|
12
|
+
constructor(getRole, listTeams, listUsers, deleteRole){
|
|
13
|
+
this.getRole = getRole;
|
|
14
|
+
this.listTeams = listTeams;
|
|
15
|
+
this.listUsers = listUsers;
|
|
16
|
+
this.deleteRole = deleteRole;
|
|
17
|
+
}
|
|
18
|
+
async execute(input) {
|
|
19
|
+
const found = await this.getRole.execute({
|
|
20
|
+
id: input.roleId
|
|
21
|
+
});
|
|
22
|
+
if (found.isFail()) throw new Error(`Role "${input.roleId}" not found: ${found.error.message}. Call listRoles for valid ids.`);
|
|
23
|
+
const role = found.value;
|
|
24
|
+
if (role.name !== input.name) throw new Error(`Role "${input.roleId}" is named "${role.name}", not "${input.name}", so nothing was deleted. Check the role with listRoles.`);
|
|
25
|
+
if (role.system) throw new Error(`"${role.name}" is a system role and cannot be deleted.`);
|
|
26
|
+
const holders = await this.findHolders([
|
|
27
|
+
role.id,
|
|
28
|
+
role.slug
|
|
29
|
+
]);
|
|
30
|
+
if (holders.length > 0) throw new Error(`"${role.name}" is still given to ${holders.join(", ")}, so nothing was deleted. Remove it from them first.`);
|
|
31
|
+
const result = await this.deleteRole.execute(role.id);
|
|
32
|
+
if (result.isFail()) throw new Error(`Could not delete the role: ${result.error.message}`);
|
|
33
|
+
return {
|
|
34
|
+
id: role.id,
|
|
35
|
+
name: role.name,
|
|
36
|
+
slug: role.slug
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async findHolders(identifiers) {
|
|
40
|
+
const holds = (roles)=>(roles ?? []).some((role)=>identifiers.includes(role));
|
|
41
|
+
const teams = await this.listTeams.execute();
|
|
42
|
+
if (teams.isFail()) throw new Error(`Could not check which teams still have the role, so nothing was deleted. Deleting a role here also needs permission to list teams: ${teams.error.message}`);
|
|
43
|
+
const users = await this.listUsers.execute();
|
|
44
|
+
if (users.isFail()) throw new Error(`Could not check which users still have the role, so nothing was deleted. Deleting a role here also needs permission to list users: ${users.error.message}`);
|
|
45
|
+
return [
|
|
46
|
+
...teams.value.filter((team)=>holds(team.roles)).map((team)=>`team "${team.name}"`),
|
|
47
|
+
...users.value.filter((user)=>holds(user.roles)).map((user)=>`user "${user.displayName || user.email}"`)
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const DeleteRoleToolHandler = AiSdkToolHandler.createImplementation({
|
|
52
|
+
implementation: DeleteRoleToolHandlerImpl,
|
|
53
|
+
dependencies: [
|
|
54
|
+
GetRoleUseCase,
|
|
55
|
+
ListTeamsUseCase,
|
|
56
|
+
ListUsersUseCase,
|
|
57
|
+
DeleteRoleUseCase
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
class DeleteRoleToolImpl {
|
|
61
|
+
constructor(){
|
|
62
|
+
this.name = "deleteRole";
|
|
63
|
+
this.title = "Delete role";
|
|
64
|
+
this.description = "Deletes one role. Refused for system roles, roles defined in code, and roles still given to a team or user (the error names them). Call listRoles first for the id and exact name. Requires user approval.";
|
|
65
|
+
this.inputSchema = inputSchema;
|
|
66
|
+
this.annotations = {
|
|
67
|
+
readOnlyHint: false,
|
|
68
|
+
destructiveHint: true
|
|
69
|
+
};
|
|
70
|
+
this.handler = DeleteRoleToolHandler;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const DeleteRoleTool = AiSdkToolDefinition.createImplementation({
|
|
74
|
+
implementation: DeleteRoleToolImpl,
|
|
75
|
+
dependencies: []
|
|
76
|
+
});
|
|
77
|
+
export { DeleteRoleTool };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=DeleteRoleTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/DeleteRoleTool.js","sources":["../../../src/features/ai/DeleteRoleTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"@webiny/api-core/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetRoleUseCase } from \"@webiny/api-core/features/security/roles/GetRole/index.js\";\nimport { DeleteRoleUseCase } from \"@webiny/api-core/features/security/roles/DeleteRole/index.js\";\nimport { ListTeamsUseCase } from \"@webiny/api-core/features/security/teams/ListTeams/index.js\";\nimport { ListUsersUseCase } from \"@webiny/api-core/features/users/ListUsers/index.js\";\n\nconst inputSchema = z.object({\n roleId: z.string().describe(\"Role id as returned by listRoles.\"),\n name: z\n .string()\n .describe(\n \"The role's current name, exactly as listRoles returned it. The delete is refused if it does not match.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface DeletedRole {\n id: string;\n name: string;\n slug: string;\n}\n\n/*\n * The checks run before anything is deleted, in this order:\n *\n * - The name is in the input so the approval shows which role goes; it is checked against the\n * stored role, so what the user approved by name is what is removed.\n * - System roles (the Full Access role the installer creates) are refused. `DeleteRoleUseCase`\n * cannot refuse them itself: `RolesInstaller.uninstall()` uses it to roll back that same role.\n * - A role still given to a team or a user is refused, with their names. `DeleteRoleUseCase` would\n * delete it and leave them holding the id of a role that no longer exists. Both the id and the\n * slug are matched, since a record written before roles were resolved to ids can hold the slug.\n * The check goes through the list use cases, so it needs the caller's permission to list teams\n * and users. Without it the delete is refused and the error says why.\n */\nclass DeleteRoleToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getRole: GetRoleUseCase.Interface,\n private listTeams: ListTeamsUseCase.Interface,\n private listUsers: ListUsersUseCase.Interface,\n private deleteRole: DeleteRoleUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<DeletedRole> {\n const found = await this.getRole.execute({ id: input.roleId });\n\n if (found.isFail()) {\n throw new Error(\n `Role \"${input.roleId}\" not found: ${found.error.message}. Call listRoles for valid ids.`\n );\n }\n\n const role = found.value;\n\n if (role.name !== input.name) {\n throw new Error(\n `Role \"${input.roleId}\" is named \"${role.name}\", not \"${input.name}\", so nothing was deleted. Check the role with listRoles.`\n );\n }\n\n if (role.system) {\n throw new Error(`\"${role.name}\" is a system role and cannot be deleted.`);\n }\n\n const holders = await this.findHolders([role.id, role.slug]);\n\n if (holders.length > 0) {\n throw new Error(\n `\"${role.name}\" is still given to ${holders.join(\", \")}, so nothing was deleted. Remove it from them first.`\n );\n }\n\n const result = await this.deleteRole.execute(role.id);\n\n if (result.isFail()) {\n throw new Error(`Could not delete the role: ${result.error.message}`);\n }\n\n return { id: role.id, name: role.name, slug: role.slug };\n }\n\n private async findHolders(identifiers: string[]): Promise<string[]> {\n const holds = (roles: string[] | undefined) =>\n (roles ?? []).some(role => identifiers.includes(role));\n\n const teams = await this.listTeams.execute();\n if (teams.isFail()) {\n throw new Error(\n `Could not check which teams still have the role, so nothing was deleted. Deleting a role here also needs permission to list teams: ${teams.error.message}`\n );\n }\n\n const users = await this.listUsers.execute();\n if (users.isFail()) {\n throw new Error(\n `Could not check which users still have the role, so nothing was deleted. Deleting a role here also needs permission to list users: ${users.error.message}`\n );\n }\n\n return [\n ...teams.value.filter(team => holds(team.roles)).map(team => `team \"${team.name}\"`),\n ...users.value\n .filter(user => holds(user.roles))\n .map(user => `user \"${user.displayName || user.email}\"`)\n ];\n }\n}\n\nconst DeleteRoleToolHandler = AiSdkToolHandler.createImplementation({\n implementation: DeleteRoleToolHandlerImpl,\n dependencies: [GetRoleUseCase, ListTeamsUseCase, ListUsersUseCase, DeleteRoleUseCase]\n});\n\n/**\n * Deletes one role that nothing uses.\n *\n * Destructive, so the approval says it cannot be undone. Refuses system roles, roles defined in\n * code, and roles still given to a team or a user.\n */\nclass DeleteRoleToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"deleteRole\";\n readonly title = \"Delete role\";\n readonly description =\n \"Deletes one role. Refused for system roles, roles defined in code, and roles still given to a team or user (the error names them). Call listRoles first for the id and exact name. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, destructiveHint: true };\n readonly handler = DeleteRoleToolHandler;\n}\n\nexport const DeleteRoleTool = AiSdkToolDefinition.createImplementation({\n implementation: DeleteRoleToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","DeleteRoleToolHandlerImpl","getRole","listTeams","listUsers","deleteRole","input","found","Error","role","holders","result","identifiers","holds","roles","teams","users","team","user","DeleteRoleToolHandler","AiSdkToolHandler","GetRoleUseCase","ListTeamsUseCase","ListUsersUseCase","DeleteRoleUseCase","DeleteRoleToolImpl","DeleteRoleTool","AiSdkToolDefinition"],"mappings":";;;;;;AAQA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,QAAQA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAMA,EAAAA,MACK,GACN,QAAQ,CACL;AAEZ;AAuBA,MAAMC;IACF,YACYC,OAAiC,EACjCC,SAAqC,EACrCC,SAAqC,EACrCC,UAAuC,CACjD;aAJUH,OAAO,GAAPA;aACAC,SAAS,GAATA;aACAC,SAAS,GAATA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAwB;QAC9C,MAAMC,QAAQ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,IAAID,MAAM,MAAM;QAAC;QAE5D,IAAIC,MAAM,MAAM,IACZ,MAAM,IAAIC,MACN,CAAC,MAAM,EAAEF,MAAM,MAAM,CAAC,aAAa,EAAEC,MAAM,KAAK,CAAC,OAAO,CAAC,+BAA+B,CAAC;QAIjG,MAAME,OAAOF,MAAM,KAAK;QAExB,IAAIE,KAAK,IAAI,KAAKH,MAAM,IAAI,EACxB,MAAM,IAAIE,MACN,CAAC,MAAM,EAAEF,MAAM,MAAM,CAAC,YAAY,EAAEG,KAAK,IAAI,CAAC,QAAQ,EAAEH,MAAM,IAAI,CAAC,yDAAyD,CAAC;QAIrI,IAAIG,KAAK,MAAM,EACX,MAAM,IAAID,MAAM,CAAC,CAAC,EAAEC,KAAK,IAAI,CAAC,yCAAyC,CAAC;QAG5E,MAAMC,UAAU,MAAM,IAAI,CAAC,WAAW,CAAC;YAACD,KAAK,EAAE;YAAEA,KAAK,IAAI;SAAC;QAE3D,IAAIC,QAAQ,MAAM,GAAG,GACjB,MAAM,IAAIF,MACN,CAAC,CAAC,EAAEC,KAAK,IAAI,CAAC,oBAAoB,EAAEC,QAAQ,IAAI,CAAC,MAAM,oDAAoD,CAAC;QAIpH,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACF,KAAK,EAAE;QAEpD,IAAIE,OAAO,MAAM,IACb,MAAM,IAAIH,MAAM,CAAC,2BAA2B,EAAEG,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,OAAO;YAAE,IAAIF,KAAK,EAAE;YAAE,MAAMA,KAAK,IAAI;YAAE,MAAMA,KAAK,IAAI;QAAC;IAC3D;IAEA,MAAc,YAAYG,WAAqB,EAAqB;QAChE,MAAMC,QAAQ,CAACC,QACVA,AAAAA,CAAAA,SAAS,EAAC,EAAG,IAAI,CAACL,CAAAA,OAAQG,YAAY,QAAQ,CAACH;QAEpD,MAAMM,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO;QAC1C,IAAIA,MAAM,MAAM,IACZ,MAAM,IAAIP,MACN,CAAC,mIAAmI,EAAEO,MAAM,KAAK,CAAC,OAAO,EAAE;QAInK,MAAMC,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO;QAC1C,IAAIA,MAAM,MAAM,IACZ,MAAM,IAAIR,MACN,CAAC,mIAAmI,EAAEQ,MAAM,KAAK,CAAC,OAAO,EAAE;QAInK,OAAO;eACAD,MAAM,KAAK,CAAC,MAAM,CAACE,CAAAA,OAAQJ,MAAMI,KAAK,KAAK,GAAG,GAAG,CAACA,CAAAA,OAAQ,CAAC,MAAM,EAAEA,KAAK,IAAI,CAAC,CAAC,CAAC;eAC/ED,MAAM,KAAK,CACT,MAAM,CAACE,CAAAA,OAAQL,MAAMK,KAAK,KAAK,GAC/B,GAAG,CAACA,CAAAA,OAAQ,CAAC,MAAM,EAAEA,KAAK,WAAW,IAAIA,KAAK,KAAK,CAAC,CAAC,CAAC;SAC9D;IACL;AACJ;AAEA,MAAMC,wBAAwBC,iBAAiB,oBAAoB,CAAC;IAChE,gBAAgBnB;IAChB,cAAc;QAACoB;QAAgBC;QAAkBC;QAAkBC;KAAkB;AACzF;AAQA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAG1B;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,iBAAiB;QAAK;aAC3D,OAAO,GAAGoB;;AACvB;AAEO,MAAMO,iBAAiBC,oBAAoB,oBAAoB,CAAC;IACnE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { GetTeamUseCase } from "@webiny/api-core/features/security/teams/GetTeam/index.js";
|
|
4
|
+
import { DeleteTeam } from "@webiny/api-core/features/security/teams/DeleteTeam/index.js";
|
|
5
|
+
declare const inputSchema: z.ZodObject<{
|
|
6
|
+
teamId: z.ZodString;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type Input = z.infer<typeof inputSchema>;
|
|
10
|
+
interface DeletedTeam {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
}
|
|
15
|
+
declare class DeleteTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
|
|
16
|
+
private getTeam;
|
|
17
|
+
private deleteTeam;
|
|
18
|
+
constructor(getTeam: GetTeamUseCase.Interface, deleteTeam: DeleteTeam.Interface);
|
|
19
|
+
execute(input: Input): Promise<DeletedTeam>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Deletes one team.
|
|
23
|
+
*
|
|
24
|
+
* Destructive, so the approval says it cannot be undone. System teams and teams defined in code are
|
|
25
|
+
* refused by `DeleteTeam`, and that error reaches the model as-is.
|
|
26
|
+
*/
|
|
27
|
+
declare class DeleteTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {
|
|
28
|
+
readonly name = "deleteTeam";
|
|
29
|
+
readonly title = "Delete team";
|
|
30
|
+
readonly description = "Deletes one team. System teams and teams defined in code are refused. Call listTeams first for the id and exact name. Requires user approval.";
|
|
31
|
+
readonly inputSchema: z.ZodObject<{
|
|
32
|
+
teamId: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
readonly annotations: {
|
|
36
|
+
readOnlyHint: boolean;
|
|
37
|
+
destructiveHint: boolean;
|
|
38
|
+
};
|
|
39
|
+
readonly handler: typeof DeleteTeamToolHandlerImpl & {
|
|
40
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export declare const DeleteTeamTool: typeof DeleteTeamToolImpl & {
|
|
44
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { GetTeamUseCase } from "@webiny/api-core/features/security/teams/GetTeam/index.js";
|
|
4
|
+
import { DeleteTeam } from "@webiny/api-core/features/security/teams/DeleteTeam/index.js";
|
|
5
|
+
const inputSchema = z.object({
|
|
6
|
+
teamId: z.string().describe("Team id as returned by listTeams."),
|
|
7
|
+
name: z.string().describe("The team's current name, exactly as listTeams returned it. The delete is refused if it does not match.")
|
|
8
|
+
});
|
|
9
|
+
class DeleteTeamToolHandlerImpl {
|
|
10
|
+
constructor(getTeam, deleteTeam){
|
|
11
|
+
this.getTeam = getTeam;
|
|
12
|
+
this.deleteTeam = deleteTeam;
|
|
13
|
+
}
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const found = await this.getTeam.execute({
|
|
16
|
+
id: input.teamId
|
|
17
|
+
});
|
|
18
|
+
if (found.isFail()) throw new Error(`Team "${input.teamId}" not found: ${found.error.message}. Call listTeams for valid ids.`);
|
|
19
|
+
const team = found.value;
|
|
20
|
+
if (team.name !== input.name) throw new Error(`Team "${input.teamId}" is named "${team.name}", not "${input.name}", so nothing was deleted. Check the team with listTeams.`);
|
|
21
|
+
const result = await this.deleteTeam.execute(team.id);
|
|
22
|
+
if (result.isFail()) throw new Error(`Could not delete the team: ${result.error.message}`);
|
|
23
|
+
return {
|
|
24
|
+
id: team.id,
|
|
25
|
+
name: team.name,
|
|
26
|
+
slug: team.slug
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const DeleteTeamToolHandler = AiSdkToolHandler.createImplementation({
|
|
31
|
+
implementation: DeleteTeamToolHandlerImpl,
|
|
32
|
+
dependencies: [
|
|
33
|
+
GetTeamUseCase,
|
|
34
|
+
DeleteTeam
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
class DeleteTeamToolImpl {
|
|
38
|
+
constructor(){
|
|
39
|
+
this.name = "deleteTeam";
|
|
40
|
+
this.title = "Delete team";
|
|
41
|
+
this.description = "Deletes one team. System teams and teams defined in code are refused. Call listTeams first for the id and exact name. Requires user approval.";
|
|
42
|
+
this.inputSchema = inputSchema;
|
|
43
|
+
this.annotations = {
|
|
44
|
+
readOnlyHint: false,
|
|
45
|
+
destructiveHint: true
|
|
46
|
+
};
|
|
47
|
+
this.handler = DeleteTeamToolHandler;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const DeleteTeamTool = AiSdkToolDefinition.createImplementation({
|
|
51
|
+
implementation: DeleteTeamToolImpl,
|
|
52
|
+
dependencies: []
|
|
53
|
+
});
|
|
54
|
+
export { DeleteTeamTool };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=DeleteTeamTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/DeleteTeamTool.js","sources":["../../../src/features/ai/DeleteTeamTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetTeamUseCase } from \"@webiny/api-core/features/security/teams/GetTeam/index.js\";\nimport { DeleteTeam } from \"@webiny/api-core/features/security/teams/DeleteTeam/index.js\";\n\nconst inputSchema = z.object({\n teamId: z.string().describe(\"Team id as returned by listTeams.\"),\n name: z\n .string()\n .describe(\n \"The team's current name, exactly as listTeams returned it. The delete is refused if it does not match.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface DeletedTeam {\n id: string;\n name: string;\n slug: string;\n}\n\n/*\n * The name is part of the input so the approval shows the user which team goes, rather than only an\n * id. The model supplies it, so it is checked against the stored team before anything is deleted:\n * what the user approved by name has to be the team that is removed.\n */\nclass DeleteTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getTeam: GetTeamUseCase.Interface,\n private deleteTeam: DeleteTeam.Interface\n ) {}\n\n async execute(input: Input): Promise<DeletedTeam> {\n const found = await this.getTeam.execute({ id: input.teamId });\n\n if (found.isFail()) {\n throw new Error(\n `Team \"${input.teamId}\" not found: ${found.error.message}. Call listTeams for valid ids.`\n );\n }\n\n const team = found.value;\n\n if (team.name !== input.name) {\n throw new Error(\n `Team \"${input.teamId}\" is named \"${team.name}\", not \"${input.name}\", so nothing was deleted. Check the team with listTeams.`\n );\n }\n\n const result = await this.deleteTeam.execute(team.id);\n\n if (result.isFail()) {\n throw new Error(`Could not delete the team: ${result.error.message}`);\n }\n\n return { id: team.id, name: team.name, slug: team.slug };\n }\n}\n\nconst DeleteTeamToolHandler = AiSdkToolHandler.createImplementation({\n implementation: DeleteTeamToolHandlerImpl,\n dependencies: [GetTeamUseCase, DeleteTeam]\n});\n\n/**\n * Deletes one team.\n *\n * Destructive, so the approval says it cannot be undone. System teams and teams defined in code are\n * refused by `DeleteTeam`, and that error reaches the model as-is.\n */\nclass DeleteTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"deleteTeam\";\n readonly title = \"Delete team\";\n readonly description =\n \"Deletes one team. System teams and teams defined in code are refused. Call listTeams first for the id and exact name. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, destructiveHint: true };\n readonly handler = DeleteTeamToolHandler;\n}\n\nexport const DeleteTeamTool = AiSdkToolDefinition.createImplementation({\n implementation: DeleteTeamToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","DeleteTeamToolHandlerImpl","getTeam","deleteTeam","input","found","Error","team","result","DeleteTeamToolHandler","AiSdkToolHandler","GetTeamUseCase","DeleteTeam","DeleteTeamToolImpl","DeleteTeamTool","AiSdkToolDefinition"],"mappings":";;;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,QAAQA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAMA,EAAAA,MACK,GACN,QAAQ,CACL;AAEZ;AAeA,MAAMC;IACF,YACYC,OAAiC,EACjCC,UAAgC,CAC1C;aAFUD,OAAO,GAAPA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAwB;QAC9C,MAAMC,QAAQ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,IAAID,MAAM,MAAM;QAAC;QAE5D,IAAIC,MAAM,MAAM,IACZ,MAAM,IAAIC,MACN,CAAC,MAAM,EAAEF,MAAM,MAAM,CAAC,aAAa,EAAEC,MAAM,KAAK,CAAC,OAAO,CAAC,+BAA+B,CAAC;QAIjG,MAAME,OAAOF,MAAM,KAAK;QAExB,IAAIE,KAAK,IAAI,KAAKH,MAAM,IAAI,EACxB,MAAM,IAAIE,MACN,CAAC,MAAM,EAAEF,MAAM,MAAM,CAAC,YAAY,EAAEG,KAAK,IAAI,CAAC,QAAQ,EAAEH,MAAM,IAAI,CAAC,yDAAyD,CAAC;QAIrI,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD,KAAK,EAAE;QAEpD,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIF,MAAM,CAAC,2BAA2B,EAAEE,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,OAAO;YAAE,IAAID,KAAK,EAAE;YAAE,MAAMA,KAAK,IAAI;YAAE,MAAMA,KAAK,IAAI;QAAC;IAC3D;AACJ;AAEA,MAAME,wBAAwBC,iBAAiB,oBAAoB,CAAC;IAChE,gBAAgBT;IAChB,cAAc;QAACU;QAAgBC;KAAW;AAC9C;AAQA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGd;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,iBAAiB;QAAK;aAC3D,OAAO,GAAGU;;AACvB;AAEO,MAAMK,iBAAiBC,oBAAoB,oBAAoB,CAAC;IACnE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -23,7 +23,7 @@ declare class ListRolesToolHandlerImpl implements AiSdkToolHandler.Interface<Rec
|
|
|
23
23
|
declare class ListRolesToolImpl implements AiSdkToolDefinition.Interface<Record<string, never>> {
|
|
24
24
|
readonly name = "listRoles";
|
|
25
25
|
readonly title = "List roles";
|
|
26
|
-
readonly description = "Lists the security roles in this project
|
|
26
|
+
readonly description = "Lists the security roles in this project with their ids, names and slugs. createTeam and updateTeam take role ids (a slug also works; anything else is rejected). updateRole and deleteRole take the id, and deleteRole also the exact name.";
|
|
27
27
|
readonly inputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
28
28
|
readonly annotations: {
|
|
29
29
|
readOnlyHint: boolean;
|
|
@@ -30,7 +30,7 @@ class ListRolesToolImpl {
|
|
|
30
30
|
constructor(){
|
|
31
31
|
this.name = "listRoles";
|
|
32
32
|
this.title = "List roles";
|
|
33
|
-
this.description = "Lists the security roles in this project
|
|
33
|
+
this.description = "Lists the security roles in this project with their ids, names and slugs. createTeam and updateTeam take role ids (a slug also works; anything else is rejected). updateRole and deleteRole take the id, and deleteRole also the exact name.";
|
|
34
34
|
this.inputSchema = inputSchema;
|
|
35
35
|
this.annotations = {
|
|
36
36
|
readOnlyHint: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/ListRolesTool.js","sources":["../../../src/features/ai/ListRolesTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } 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\nclass ListRolesToolHandlerImpl implements AiSdkToolHandler.Interface<Record<string, never>> {\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\nconst ListRolesToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListRolesToolHandlerImpl,\n dependencies: [ListRolesUseCase]\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 AiSdkToolDefinition.Interface<Record<string, never>> {\n readonly name = \"listRoles\";\n readonly title = \"List roles\";\n readonly description =\n \"Lists the security roles in this project
|
|
1
|
+
{"version":3,"file":"features/ai/ListRolesTool.js","sources":["../../../src/features/ai/ListRolesTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } 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\nclass ListRolesToolHandlerImpl implements AiSdkToolHandler.Interface<Record<string, never>> {\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\nconst ListRolesToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListRolesToolHandlerImpl,\n dependencies: [ListRolesUseCase]\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 AiSdkToolDefinition.Interface<Record<string, never>> {\n readonly name = \"listRoles\";\n readonly title = \"List roles\";\n readonly description =\n \"Lists the security roles in this project with their ids, names and slugs. createTeam and updateTeam take role ids (a slug also works; anything else is rejected). updateRole and deleteRole take the id, and deleteRole also the exact name.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListRolesToolHandler;\n}\n\nexport const ListRolesTool = AiSdkToolDefinition.createImplementation({\n implementation: ListRolesToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListRolesToolHandlerImpl","listRoles","result","Error","role","summary","ListRolesToolHandler","AiSdkToolHandler","ListRolesUseCase","ListRolesToolImpl","ListRolesTool","AiSdkToolDefinition"],"mappings":";;;AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC,CAAC;AAS9B,MAAMC;IACF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;IAAwC;IAE5D,MAAM,UAAkC;QACpC,MAAMC,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;AAEA,MAAMC,uBAAuBC,iBAAiB,oBAAoB,CAAC;IAC/D,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC;AAUA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,gBAAgBC,oBAAoB,oBAAoB,CAAC;IAClE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -8,6 +8,8 @@ interface TeamSummary {
|
|
|
8
8
|
name: string;
|
|
9
9
|
slug: string;
|
|
10
10
|
description?: string;
|
|
11
|
+
/** Role ids, so `updateTeam` can be given the full list with one role added or removed. */
|
|
12
|
+
roles: string[];
|
|
11
13
|
}
|
|
12
14
|
declare class ListTeamsToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
|
|
13
15
|
private listTeams;
|
|
@@ -23,7 +25,7 @@ declare class ListTeamsToolHandlerImpl implements AiSdkToolHandler.Interface<Inp
|
|
|
23
25
|
declare class ListTeamsToolImpl implements AiSdkToolDefinition.Interface<Input> {
|
|
24
26
|
readonly name = "listTeams";
|
|
25
27
|
readonly title = "List teams";
|
|
26
|
-
readonly description = "Lists the teams in this project with their ids, names and
|
|
28
|
+
readonly description = "Lists the teams in this project with their ids, names, slugs and role ids. Folder permission targets use the SLUG (`team:<slug>`), not the id; updateTeam and deleteTeam take the id.";
|
|
27
29
|
readonly inputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
28
30
|
readonly annotations: {
|
|
29
31
|
readOnlyHint: boolean;
|
|
@@ -13,7 +13,8 @@ class ListTeamsToolHandlerImpl {
|
|
|
13
13
|
const summary = {
|
|
14
14
|
id: team.id,
|
|
15
15
|
name: team.name,
|
|
16
|
-
slug: team.slug
|
|
16
|
+
slug: team.slug,
|
|
17
|
+
roles: team.roles
|
|
17
18
|
};
|
|
18
19
|
if (team.description) summary.description = team.description;
|
|
19
20
|
return summary;
|
|
@@ -30,7 +31,7 @@ class ListTeamsToolImpl {
|
|
|
30
31
|
constructor(){
|
|
31
32
|
this.name = "listTeams";
|
|
32
33
|
this.title = "List teams";
|
|
33
|
-
this.description = "Lists the teams in this project with their ids, names and
|
|
34
|
+
this.description = "Lists the teams in this project with their ids, names, slugs and role ids. Folder permission targets use the SLUG (`team:<slug>`), not the id; updateTeam and deleteTeam take the id.";
|
|
34
35
|
this.inputSchema = inputSchema;
|
|
35
36
|
this.annotations = {
|
|
36
37
|
readOnlyHint: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/ListTeamsTool.js","sources":["../../../src/features/ai/ListTeamsTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } 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\nclass ListTeamsToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\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\nconst ListTeamsToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListTeamsToolHandlerImpl,\n dependencies: [ListTeamsUseCase]\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 AiSdkToolDefinition.Interface<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
|
|
1
|
+
{"version":3,"file":"features/ai/ListTeamsTool.js","sources":["../../../src/features/ai/ListTeamsTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } 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 /** Role ids, so `updateTeam` can be given the full list with one role added or removed. */\n roles: string[];\n}\n\nclass ListTeamsToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\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 roles: team.roles\n };\n\n if (team.description) {\n summary.description = team.description;\n }\n\n return summary;\n });\n }\n}\n\nconst ListTeamsToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListTeamsToolHandlerImpl,\n dependencies: [ListTeamsUseCase]\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 AiSdkToolDefinition.Interface<Input> {\n readonly name = \"listTeams\";\n readonly title = \"List teams\";\n readonly description =\n \"Lists the teams in this project with their ids, names, slugs and role ids. Folder permission targets use the SLUG (`team:<slug>`), not the id; updateTeam and deleteTeam take the id.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListTeamsToolHandler;\n}\n\nexport const ListTeamsTool = AiSdkToolDefinition.createImplementation({\n implementation: ListTeamsToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListTeamsToolHandlerImpl","listTeams","result","Error","team","summary","ListTeamsToolHandler","AiSdkToolHandler","ListTeamsUseCase","ListTeamsToolImpl","ListTeamsTool","AiSdkToolDefinition"],"mappings":";;;AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC,CAAC;AAa9B,MAAMC;IACF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;IAAwC;IAE5D,MAAM,UAAkC;QACpC,MAAMC,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;gBACf,OAAOA,KAAK,KAAK;YACrB;YAEA,IAAIA,KAAK,WAAW,EAChBC,QAAQ,WAAW,GAAGD,KAAK,WAAW;YAG1C,OAAOC;QACX;IACJ;AACJ;AAEA,MAAMC,uBAAuBC,iBAAiB,oBAAoB,CAAC;IAC/D,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC;AAQA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,gBAAgBC,oBAAoB,oBAAoB,CAAC;IAClE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AiSdkToolDefinition } from "@webiny/api-core/features/ai/index.js";
|
|
3
|
+
import { AiSdkToolHandler } from "@webiny/api-core/features/ai/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
|
+
currentTitle: z.ZodString;
|
|
9
|
+
title: z.ZodOptional<z.ZodString>;
|
|
10
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
11
|
+
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
type Input = z.infer<typeof inputSchema>;
|
|
14
|
+
interface UpdatedFolder {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
slug: string;
|
|
18
|
+
path: string;
|
|
19
|
+
parentId: string | null;
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
declare class UpdateFolderToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
|
|
23
|
+
private getFolder;
|
|
24
|
+
private updateFolder;
|
|
25
|
+
constructor(getFolder: GetFolderUseCase.Interface, updateFolder: UpdateFolderUseCase.Interface);
|
|
26
|
+
execute(input: Input): Promise<UpdatedFolder>;
|
|
27
|
+
private ensureSameType;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Renames or moves one folder.
|
|
31
|
+
*
|
|
32
|
+
* Not destructive: the old title, slug and parent can be set again. A new slug or parent changes the
|
|
33
|
+
* folder's path and its subfolders' paths, and with them which code-defined access rules apply, so
|
|
34
|
+
* it still waits for the user to approve the exact arguments.
|
|
35
|
+
*/
|
|
36
|
+
declare class UpdateFolderToolImpl implements AiSdkToolDefinition.Interface<Input> {
|
|
37
|
+
readonly name = "updateFolder";
|
|
38
|
+
readonly title = "Update folder";
|
|
39
|
+
readonly description = "Renames a folder, changes its slug, or moves it under another folder of the same type (parentId null moves it to the root). Call listFolders first for the id, the exact current title and the new parent. Access rules are changed with grantFolderAccess and revokeFolderAccess, not here. Requires user approval.";
|
|
40
|
+
readonly inputSchema: z.ZodObject<{
|
|
41
|
+
folderId: z.ZodString;
|
|
42
|
+
currentTitle: z.ZodString;
|
|
43
|
+
title: z.ZodOptional<z.ZodString>;
|
|
44
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
45
|
+
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
readonly annotations: {
|
|
48
|
+
readOnlyHint: boolean;
|
|
49
|
+
};
|
|
50
|
+
readonly handler: typeof UpdateFolderToolHandlerImpl & {
|
|
51
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export declare const UpdateFolderTool: typeof UpdateFolderToolImpl & {
|
|
55
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
|
|
56
|
+
};
|
|
57
|
+
export {};
|