@webiny/api-headless-cms 6.6.0-alpha.10 → 6.6.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/features/ai/CreateEntryTool.d.ts +43 -0
  2. package/features/ai/CreateEntryTool.js +67 -0
  3. package/features/ai/CreateEntryTool.js.map +1 -0
  4. package/features/ai/DeleteEntryTool.d.ts +46 -0
  5. package/features/ai/DeleteEntryTool.js +68 -0
  6. package/features/ai/DeleteEntryTool.js.map +1 -0
  7. package/features/ai/ListContentModelsTool.d.ts +2 -2
  8. package/features/ai/ListContentModelsTool.js +1 -2
  9. package/features/ai/ListContentModelsTool.js.map +1 -1
  10. package/features/ai/PublishEntryTool.d.ts +42 -0
  11. package/features/ai/PublishEntryTool.js +65 -0
  12. package/features/ai/PublishEntryTool.js.map +1 -0
  13. package/features/ai/UnpublishEntryTool.d.ts +42 -0
  14. package/features/ai/UnpublishEntryTool.js +67 -0
  15. package/features/ai/UnpublishEntryTool.js.map +1 -0
  16. package/features/ai/UpdateEntryTool.d.ts +47 -0
  17. package/features/ai/UpdateEntryTool.js +78 -0
  18. package/features/ai/UpdateEntryTool.js.map +1 -0
  19. package/features/ai/assertKnownFields.d.ts +7 -0
  20. package/features/ai/assertKnownFields.js +11 -0
  21. package/features/ai/assertKnownFields.js.map +1 -0
  22. package/features/ai/entrySummary.d.ts +9 -0
  23. package/features/ai/entrySummary.js +9 -0
  24. package/features/ai/entrySummary.js.map +1 -0
  25. package/features/ai/feature.d.ts +6 -2
  26. package/features/ai/feature.js +10 -0
  27. package/features/ai/feature.js.map +1 -1
  28. package/features/ai/index.d.ts +5 -0
  29. package/features/ai/index.js +5 -0
  30. package/features/ai/models.d.ts +18 -0
  31. package/features/ai/models.js +21 -0
  32. package/features/ai/models.js.map +1 -0
  33. package/features/contentEntry/NotifyEntryChange/index.d.ts +1 -0
  34. package/features/contentEntry/NotifyEntryChange/index.js +1 -0
  35. package/features/contentEntry/NotifyEntryChange/recordType.d.ts +11 -0
  36. package/features/contentEntry/NotifyEntryChange/recordType.js +4 -0
  37. package/features/contentEntry/NotifyEntryChange/recordType.js.map +1 -0
  38. package/features/contentModelGroup/GetGroup/GetGroupRepository.js +1 -1
  39. package/features/contentModelGroup/GetGroup/GetGroupRepository.js.map +1 -1
  40. package/features/contentModelGroup/ListGroups/ListGroupsRepository.js +1 -1
  41. package/features/contentModelGroup/ListGroups/ListGroupsRepository.js.map +1 -1
  42. package/features/contentModelGroup/shared/PluginGroupsProvider.js +1 -1
  43. package/features/contentModelGroup/shared/PluginGroupsProvider.js.map +1 -1
  44. package/features/modelStorageSync/SyncStorageOnModelUpdate.js +5 -1
  45. package/features/modelStorageSync/SyncStorageOnModelUpdate.js.map +1 -1
  46. package/package.json +16 -16
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../../features/contentModel/GetModel/index.js";
4
+ import { CreateEntryUseCase } from "../../features/contentEntry/CreateEntry/index.js";
5
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
6
+ import { type EntrySummary } from "./entrySummary.js";
7
+ declare const inputSchema: z.ZodObject<{
8
+ modelId: z.ZodString;
9
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
10
+ folderId: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strip>;
12
+ type Input = z.infer<typeof inputSchema>;
13
+ declare class CreateEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
14
+ private getModel;
15
+ private createEntry;
16
+ private notifyRecordChange;
17
+ constructor(getModel: GetModelUseCase.Interface, createEntry: CreateEntryUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
18
+ execute(input: Input): Promise<EntrySummary>;
19
+ }
20
+ /**
21
+ * Creates one entry as a draft. Publishing is a separate call, so the user approves the content and
22
+ * the publish on their own.
23
+ */
24
+ declare class CreateEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {
25
+ readonly name = "createEntry";
26
+ readonly title = "Create entry";
27
+ readonly description = "Creates one content entry as an unpublished draft. Call describeContentModel first so `values` uses real field IDs and fills the required fields. Publish it afterwards with publishEntry if the user asked for that. Requires user approval.";
28
+ readonly inputSchema: z.ZodObject<{
29
+ modelId: z.ZodString;
30
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
31
+ folderId: z.ZodOptional<z.ZodString>;
32
+ }, z.core.$strip>;
33
+ readonly annotations: {
34
+ readOnlyHint: boolean;
35
+ };
36
+ readonly handler: typeof CreateEntryToolHandlerImpl & {
37
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolHandler<any>>;
38
+ };
39
+ }
40
+ export declare const CreateEntryTool: typeof CreateEntryToolImpl & {
41
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolDefinition<any>>;
42
+ };
43
+ export {};
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../contentModel/GetModel/index.js";
4
+ import { CreateEntryUseCase } from "../contentEntry/CreateEntry/index.js";
5
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
6
+ import { ENTRY_RECORD_TYPE } from "../contentEntry/NotifyEntryChange/index.js";
7
+ import { assertKnownFields } from "./assertKnownFields.js";
8
+ import { getWritableModel } from "./models.js";
9
+ import { toEntrySummary } from "./entrySummary.js";
10
+ const inputSchema = z.object({
11
+ modelId: z.string().describe("Model ID as returned by listContentModels."),
12
+ values: z.record(z.string(), z.unknown()).describe("Field values keyed by field ID from describeContentModel, e.g. { title: 'Desk lamp', price: 49 }. Fields left out stay empty."),
13
+ folderId: z.string().optional().describe("Folder to create the entry in, as returned by listFolders. Omit it for the root.")
14
+ });
15
+ class CreateEntryToolHandlerImpl {
16
+ constructor(getModel, createEntry, notifyRecordChange){
17
+ this.getModel = getModel;
18
+ this.createEntry = createEntry;
19
+ this.notifyRecordChange = notifyRecordChange;
20
+ }
21
+ async execute(input) {
22
+ const model = await getWritableModel(this.getModel, input.modelId);
23
+ assertKnownFields(model, input.values);
24
+ const result = await this.createEntry.execute(model, {
25
+ values: input.values,
26
+ location: input.folderId ? {
27
+ folderId: input.folderId
28
+ } : void 0
29
+ });
30
+ if (result.isFail()) throw new Error(`Could not create the entry: ${result.error.message}`);
31
+ const entry = result.value;
32
+ await this.notifyRecordChange.execute({
33
+ type: ENTRY_RECORD_TYPE,
34
+ id: entry.entryId,
35
+ scope: model.modelId,
36
+ change: "created"
37
+ });
38
+ return toEntrySummary(entry);
39
+ }
40
+ }
41
+ const CreateEntryToolHandler = AiSdkToolHandler.createImplementation({
42
+ implementation: CreateEntryToolHandlerImpl,
43
+ dependencies: [
44
+ GetModelUseCase,
45
+ CreateEntryUseCase,
46
+ NotifyRecordChangeUseCase
47
+ ]
48
+ });
49
+ class CreateEntryToolImpl {
50
+ constructor(){
51
+ this.name = "createEntry";
52
+ this.title = "Create entry";
53
+ this.description = "Creates one content entry as an unpublished draft. Call describeContentModel first so `values` uses real field IDs and fills the required fields. Publish it afterwards with publishEntry if the user asked for that. Requires user approval.";
54
+ this.inputSchema = inputSchema;
55
+ this.annotations = {
56
+ readOnlyHint: false
57
+ };
58
+ this.handler = CreateEntryToolHandler;
59
+ }
60
+ }
61
+ const CreateEntryTool = AiSdkToolDefinition.createImplementation({
62
+ implementation: CreateEntryToolImpl,
63
+ dependencies: []
64
+ });
65
+ export { CreateEntryTool };
66
+
67
+ //# sourceMappingURL=CreateEntryTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/CreateEntryTool.js","sources":["../../../src/features/ai/CreateEntryTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { CreateEntryUseCase } from \"~/features/contentEntry/CreateEntry/index.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { ENTRY_RECORD_TYPE } from \"~/features/contentEntry/NotifyEntryChange/index.js\";\nimport { assertKnownFields } from \"./assertKnownFields.js\";\nimport { getWritableModel } from \"./models.js\";\nimport { toEntrySummary, type EntrySummary } from \"./entrySummary.js\";\n\nconst inputSchema = z.object({\n modelId: z.string().describe(\"Model ID as returned by listContentModels.\"),\n values: z\n .record(z.string(), z.unknown())\n .describe(\n \"Field values keyed by field ID from describeContentModel, e.g. { title: 'Desk lamp', price: 49 }. Fields left out stay empty.\"\n ),\n folderId: z\n .string()\n .optional()\n .describe(\n \"Folder to create the entry in, as returned by listFolders. Omit it for the root.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\nclass CreateEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getModel: GetModelUseCase.Interface,\n private createEntry: CreateEntryUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<EntrySummary> {\n const model = await getWritableModel(this.getModel, input.modelId);\n assertKnownFields(model, input.values);\n\n const result = await this.createEntry.execute(model, {\n values: input.values,\n location: input.folderId ? { folderId: input.folderId } : undefined\n });\n\n if (result.isFail()) {\n throw new Error(`Could not create the entry: ${result.error.message}`);\n }\n\n const entry = result.value;\n await this.notifyRecordChange.execute({\n type: ENTRY_RECORD_TYPE,\n id: entry.entryId,\n scope: model.modelId,\n change: \"created\"\n });\n\n return toEntrySummary(entry);\n }\n}\n\nconst CreateEntryToolHandler = AiSdkToolHandler.createImplementation({\n implementation: CreateEntryToolHandlerImpl,\n dependencies: [GetModelUseCase, CreateEntryUseCase, NotifyRecordChangeUseCase]\n});\n\n/**\n * Creates one entry as a draft. Publishing is a separate call, so the user approves the content and\n * the publish on their own.\n */\nclass CreateEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"createEntry\";\n readonly title = \"Create entry\";\n readonly description =\n \"Creates one content entry as an unpublished draft. Call describeContentModel first so `values` uses real field IDs and fills the required fields. Publish it afterwards with publishEntry if the user asked for that. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n readonly handler = CreateEntryToolHandler;\n}\n\nexport const CreateEntryTool = AiSdkToolDefinition.createImplementation({\n implementation: CreateEntryToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","CreateEntryToolHandlerImpl","getModel","createEntry","notifyRecordChange","input","model","getWritableModel","assertKnownFields","result","undefined","Error","entry","ENTRY_RECORD_TYPE","toEntrySummary","CreateEntryToolHandler","AiSdkToolHandler","GetModelUseCase","CreateEntryUseCase","NotifyRecordChangeUseCase","CreateEntryToolImpl","CreateEntryTool","AiSdkToolDefinition"],"mappings":";;;;;;;;;AAUA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,QAAQA,EAAAA,MACG,CAACA,EAAE,MAAM,IAAIA,EAAE,OAAO,IAC5B,QAAQ,CACL;IAER,UAAUA,EAAAA,MACC,GACN,QAAQ,GACR,QAAQ,CACL;AAEZ;AAIA,MAAMC;IACF,YACYC,QAAmC,EACnCC,WAAyC,EACzCC,kBAAuD,CACjE;aAHUF,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAyB;QAC/C,MAAMC,QAAQ,MAAMC,iBAAiB,IAAI,CAAC,QAAQ,EAAEF,MAAM,OAAO;QACjEG,kBAAkBF,OAAOD,MAAM,MAAM;QAErC,MAAMI,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACH,OAAO;YACjD,QAAQD,MAAM,MAAM;YACpB,UAAUA,MAAM,QAAQ,GAAG;gBAAE,UAAUA,MAAM,QAAQ;YAAC,IAAIK;QAC9D;QAEA,IAAID,OAAO,MAAM,IACb,MAAM,IAAIE,MAAM,CAAC,4BAA4B,EAAEF,OAAO,KAAK,CAAC,OAAO,EAAE;QAGzE,MAAMG,QAAQH,OAAO,KAAK;QAC1B,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMI;YACN,IAAID,MAAM,OAAO;YACjB,OAAON,MAAM,OAAO;YACpB,QAAQ;QACZ;QAEA,OAAOQ,eAAeF;IAC1B;AACJ;AAEA,MAAMG,yBAAyBC,iBAAiB,oBAAoB,CAAC;IACjE,gBAAgBf;IAChB,cAAc;QAACgB;QAAiBC;QAAoBC;KAA0B;AAClF;AAMA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGrB;aACd,WAAW,GAAG;YAAE,cAAc;QAAM;aACpC,OAAO,GAAGgB;;AACvB;AAEO,MAAMM,kBAAkBC,oBAAoB,oBAAoB,CAAC;IACpE,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 { GetModelUseCase } from "../../features/contentModel/GetModel/index.js";
4
+ import { GetLatestRevisionByEntryIdUseCase } from "../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
5
+ import { MoveEntryToBinUseCase } from "../../features/contentEntry/DeleteEntry/index.js";
6
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ declare const inputSchema: z.ZodObject<{
8
+ modelId: z.ZodString;
9
+ entryId: z.ZodString;
10
+ title: z.ZodString;
11
+ }, z.core.$strip>;
12
+ type Input = z.infer<typeof inputSchema>;
13
+ interface DeletedEntry {
14
+ entryId: string;
15
+ title: string;
16
+ }
17
+ declare class DeleteEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
18
+ private getModel;
19
+ private getLatestRevision;
20
+ private moveEntryToBin;
21
+ private notifyRecordChange;
22
+ constructor(getModel: GetModelUseCase.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface, moveEntryToBin: MoveEntryToBinUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
23
+ execute(input: Input): Promise<DeletedEntry>;
24
+ }
25
+ /** Moves one entry to the trash bin. Needs approval; it can be restored from the bin. */
26
+ declare class DeleteEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {
27
+ readonly name = "deleteEntry";
28
+ readonly title = "Delete entry";
29
+ readonly description = "Moves one content entry, with all its revisions, to the trash bin. It can be restored from the bin in the admin. Pass the entry's exact current title from queryEntries. Requires user approval.";
30
+ readonly inputSchema: z.ZodObject<{
31
+ modelId: z.ZodString;
32
+ entryId: z.ZodString;
33
+ title: z.ZodString;
34
+ }, z.core.$strip>;
35
+ readonly annotations: {
36
+ readOnlyHint: boolean;
37
+ destructiveHint: boolean;
38
+ };
39
+ readonly handler: typeof DeleteEntryToolHandlerImpl & {
40
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolHandler<any>>;
41
+ };
42
+ }
43
+ export declare const DeleteEntryTool: typeof DeleteEntryToolImpl & {
44
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolDefinition<any>>;
45
+ };
46
+ export {};
@@ -0,0 +1,68 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../contentModel/GetModel/index.js";
4
+ import { GetLatestRevisionByEntryIdUseCase } from "../contentEntry/GetLatestRevisionByEntryId/index.js";
5
+ import { MoveEntryToBinUseCase } from "../contentEntry/DeleteEntry/index.js";
6
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { ENTRY_RECORD_TYPE } from "../contentEntry/NotifyEntryChange/index.js";
8
+ import { getLatestEntryRevision, getWritableModel } from "./models.js";
9
+ const inputSchema = z.object({
10
+ modelId: z.string().describe("Model ID as returned by listContentModels."),
11
+ entryId: z.string().describe("The entry's `entryId` as returned by queryEntries."),
12
+ title: z.string().describe("The entry's current title (the value of the model's title field), exactly as queryEntries returned it. The delete is refused if it does not match.")
13
+ });
14
+ class DeleteEntryToolHandlerImpl {
15
+ constructor(getModel, getLatestRevision, moveEntryToBin, notifyRecordChange){
16
+ this.getModel = getModel;
17
+ this.getLatestRevision = getLatestRevision;
18
+ this.moveEntryToBin = moveEntryToBin;
19
+ this.notifyRecordChange = notifyRecordChange;
20
+ }
21
+ async execute(input) {
22
+ const model = await getWritableModel(this.getModel, input.modelId);
23
+ const entry = await getLatestEntryRevision(this.getLatestRevision, model, input.entryId);
24
+ const title = String(entry.values[model.titleFieldId] ?? entry.id);
25
+ if (title !== input.title) throw new Error(`Entry "${input.entryId}" is titled "${title}", not "${input.title}", so nothing was deleted. Check the entry with queryEntries.`);
26
+ const result = await this.moveEntryToBin.execute(model, entry.entryId);
27
+ if (result.isFail()) throw new Error(`Could not delete the entry: ${result.error.message}`);
28
+ await this.notifyRecordChange.execute({
29
+ type: ENTRY_RECORD_TYPE,
30
+ id: entry.entryId,
31
+ scope: model.modelId,
32
+ change: "deleted"
33
+ });
34
+ return {
35
+ entryId: entry.entryId,
36
+ title
37
+ };
38
+ }
39
+ }
40
+ const DeleteEntryToolHandler = AiSdkToolHandler.createImplementation({
41
+ implementation: DeleteEntryToolHandlerImpl,
42
+ dependencies: [
43
+ GetModelUseCase,
44
+ GetLatestRevisionByEntryIdUseCase,
45
+ MoveEntryToBinUseCase,
46
+ NotifyRecordChangeUseCase
47
+ ]
48
+ });
49
+ class DeleteEntryToolImpl {
50
+ constructor(){
51
+ this.name = "deleteEntry";
52
+ this.title = "Delete entry";
53
+ this.description = "Moves one content entry, with all its revisions, to the trash bin. It can be restored from the bin in the admin. Pass the entry's exact current title from queryEntries. Requires user approval.";
54
+ this.inputSchema = inputSchema;
55
+ this.annotations = {
56
+ readOnlyHint: false,
57
+ destructiveHint: true
58
+ };
59
+ this.handler = DeleteEntryToolHandler;
60
+ }
61
+ }
62
+ const DeleteEntryTool = AiSdkToolDefinition.createImplementation({
63
+ implementation: DeleteEntryToolImpl,
64
+ dependencies: []
65
+ });
66
+ export { DeleteEntryTool };
67
+
68
+ //# sourceMappingURL=DeleteEntryTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/DeleteEntryTool.js","sources":["../../../src/features/ai/DeleteEntryTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { MoveEntryToBinUseCase } from \"~/features/contentEntry/DeleteEntry/index.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { ENTRY_RECORD_TYPE } from \"~/features/contentEntry/NotifyEntryChange/index.js\";\nimport { getLatestEntryRevision } from \"./models.js\";\nimport { getWritableModel } from \"./models.js\";\n\nconst inputSchema = z.object({\n modelId: z.string().describe(\"Model ID as returned by listContentModels.\"),\n entryId: z.string().describe(\"The entry's `entryId` as returned by queryEntries.\"),\n title: z\n .string()\n .describe(\n \"The entry's current title (the value of the model's title field), exactly as queryEntries returned it. The delete is refused if it does not match.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface DeletedEntry {\n entryId: string;\n title: string;\n}\n\n/*\n * Moves the entry to the trash bin, never deletes it permanently, so it can be restored from the\n * admin. The title is in the input so the approval shows which entry goes rather than an id; it is\n * checked against the stored entry, so what the user approved by name is what is removed.\n */\nclass DeleteEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getModel: GetModelUseCase.Interface,\n private getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface,\n private moveEntryToBin: MoveEntryToBinUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<DeletedEntry> {\n const model = await getWritableModel(this.getModel, input.modelId);\n\n const entry = await getLatestEntryRevision(this.getLatestRevision, model, input.entryId);\n\n const title = String(entry.values[model.titleFieldId] ?? entry.id);\n\n if (title !== input.title) {\n throw new Error(\n `Entry \"${input.entryId}\" is titled \"${title}\", not \"${input.title}\", so nothing was deleted. Check the entry with queryEntries.`\n );\n }\n\n const result = await this.moveEntryToBin.execute(model, entry.entryId);\n if (result.isFail()) {\n throw new Error(`Could not delete the entry: ${result.error.message}`);\n }\n\n await this.notifyRecordChange.execute({\n type: ENTRY_RECORD_TYPE,\n id: entry.entryId,\n scope: model.modelId,\n change: \"deleted\"\n });\n\n return { entryId: entry.entryId, title };\n }\n}\n\nconst DeleteEntryToolHandler = AiSdkToolHandler.createImplementation({\n implementation: DeleteEntryToolHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetLatestRevisionByEntryIdUseCase,\n MoveEntryToBinUseCase,\n NotifyRecordChangeUseCase\n ]\n});\n\n/** Moves one entry to the trash bin. Needs approval; it can be restored from the bin. */\nclass DeleteEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"deleteEntry\";\n readonly title = \"Delete entry\";\n readonly description =\n \"Moves one content entry, with all its revisions, to the trash bin. It can be restored from the bin in the admin. Pass the entry's exact current title from queryEntries. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, destructiveHint: true };\n readonly handler = DeleteEntryToolHandler;\n}\n\nexport const DeleteEntryTool = AiSdkToolDefinition.createImplementation({\n implementation: DeleteEntryToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","DeleteEntryToolHandlerImpl","getModel","getLatestRevision","moveEntryToBin","notifyRecordChange","input","model","getWritableModel","entry","getLatestEntryRevision","title","String","Error","result","ENTRY_RECORD_TYPE","DeleteEntryToolHandler","AiSdkToolHandler","GetModelUseCase","GetLatestRevisionByEntryIdUseCase","MoveEntryToBinUseCase","NotifyRecordChangeUseCase","DeleteEntryToolImpl","DeleteEntryTool","AiSdkToolDefinition"],"mappings":";;;;;;;;AAUA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,OAAOA,EAAAA,MACI,GACN,QAAQ,CACL;AAEZ;AAcA,MAAMC;IACF,YACYC,QAAmC,EACnCC,iBAA8D,EAC9DC,cAA+C,EAC/CC,kBAAuD,CACjE;aAJUH,QAAQ,GAARA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAyB;QAC/C,MAAMC,QAAQ,MAAMC,iBAAiB,IAAI,CAAC,QAAQ,EAAEF,MAAM,OAAO;QAEjE,MAAMG,QAAQ,MAAMC,uBAAuB,IAAI,CAAC,iBAAiB,EAAEH,OAAOD,MAAM,OAAO;QAEvF,MAAMK,QAAQC,OAAOH,MAAM,MAAM,CAACF,MAAM,YAAY,CAAC,IAAIE,MAAM,EAAE;QAEjE,IAAIE,UAAUL,MAAM,KAAK,EACrB,MAAM,IAAIO,MACN,CAAC,OAAO,EAAEP,MAAM,OAAO,CAAC,aAAa,EAAEK,MAAM,QAAQ,EAAEL,MAAM,KAAK,CAAC,6DAA6D,CAAC;QAIzI,MAAMQ,SAAS,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACP,OAAOE,MAAM,OAAO;QACrE,IAAIK,OAAO,MAAM,IACb,MAAM,IAAID,MAAM,CAAC,4BAA4B,EAAEC,OAAO,KAAK,CAAC,OAAO,EAAE;QAGzE,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMC;YACN,IAAIN,MAAM,OAAO;YACjB,OAAOF,MAAM,OAAO;YACpB,QAAQ;QACZ;QAEA,OAAO;YAAE,SAASE,MAAM,OAAO;YAAEE;QAAM;IAC3C;AACJ;AAEA,MAAMK,yBAAyBC,iBAAiB,oBAAoB,CAAC;IACjE,gBAAgBhB;IAChB,cAAc;QACViB;QACAC;QACAC;QACAC;KACH;AACL;AAGA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGvB;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,iBAAiB;QAAK;aAC3D,OAAO,GAAGiB;;AACvB;AAEO,MAAMO,kBAAkBC,oBAAoB,oBAAoB,CAAC;IACpE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -37,10 +37,10 @@ declare class ListContentModelsToolImpl implements AiSdkToolDefinition.Interface
37
37
  idempotentHint: boolean;
38
38
  };
39
39
  readonly handler: typeof ListContentModelsToolHandlerImpl & {
40
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
40
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolHandler<any>>;
41
41
  };
42
42
  }
43
43
  export declare const ListContentModelsTool: typeof ListContentModelsToolImpl & {
44
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
44
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolDefinition<any>>;
45
45
  };
46
46
  export {};
@@ -1,11 +1,10 @@
1
1
  import { z } from "zod";
2
2
  import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
3
  import { ListModelsUseCase } from "../contentModel/ListModels/index.js";
4
- const HIDDEN_MODEL_GROUP = "hidden";
4
+ import { isSystemModel } from "./models.js";
5
5
  const inputSchema = z.object({
6
6
  includeSystem: z.boolean().optional().describe("Include system models that back Webiny itself (languages, tenants, task settings) and internal models belonging to other apps. Off by default — these are never what a user means by 'content'.")
7
7
  });
8
- const isSystemModel = (model)=>Boolean(model.isPrivate) || model.group === HIDDEN_MODEL_GROUP;
9
8
  class ListContentModelsToolHandlerImpl {
10
9
  constructor(listModels){
11
10
  this.listModels = listModels;
@@ -1 +1 @@
1
- {"version":3,"file":"features/ai/ListContentModelsTool.js","sources":["../../../src/features/ai/ListContentModelsTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\nconst HIDDEN_MODEL_GROUP = \"hidden\";\n\nconst inputSchema = z.object({\n includeSystem: z\n .boolean()\n .optional()\n .describe(\n \"Include system models that back Webiny itself (languages, tenants, task settings) and internal models belonging to other apps. Off by default — these are never what a user means by 'content'.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface ModelSummary {\n modelId: string;\n name: string;\n description: string | null;\n group: string;\n singularApiName: string;\n pluralApiName: string;\n titleFieldId: string;\n fieldCount: number;\n}\n\n/**\n * Models Webiny itself owns. Two separate markers, both needed:\n * - `group: \"hidden\"` — the convention system models use (languages, tenants, background-task\n * settings). The admin UI filters the same way, see app-headless-cms useCmsData.\n * - `isPrivate` — models another app owns and manages through its own UI (e.g. Website Builder).\n */\nconst isSystemModel = (model: CmsModel): boolean =>\n Boolean(model.isPrivate) || model.group === HIDDEN_MODEL_GROUP;\n\nclass ListContentModelsToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private listModels: ListModelsUseCase.Interface) {}\n\n async execute(input: Input): Promise<ModelSummary[]> {\n const result = await this.listModels.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not list content models: ${result.error.message}`);\n }\n\n return result.value\n .filter(model => (input.includeSystem ? true : !isSystemModel(model)))\n .map(model => ({\n modelId: model.modelId,\n name: model.name,\n description: model.description,\n group: model.group,\n singularApiName: model.singularApiName,\n pluralApiName: model.pluralApiName,\n titleFieldId: model.titleFieldId,\n fieldCount: model.fields.length\n }));\n }\n}\n\nconst ListContentModelsToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListContentModelsToolHandlerImpl,\n dependencies: [ListModelsUseCase]\n});\n\n/**\n * Entry point for any content question. The CMS schema is defined per project (and per tenant), so a\n * model list cannot be baked into a system prompt — it has to be discovered at call time. Returns a\n * summary only; `describeContentModel` supplies the field detail needed to actually build a query.\n */\nclass ListContentModelsToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"listContentModels\";\n readonly title = \"List content models\";\n readonly description =\n \"Lists the content models available in this project. Call this first when you need to find content — model IDs are project-specific and cannot be guessed. Returns a summary per model; use describeContentModel for field details.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListContentModelsToolHandler;\n}\n\nexport const ListContentModelsTool = AiSdkToolDefinition.createImplementation({\n implementation: ListContentModelsToolImpl,\n dependencies: []\n});\n"],"names":["HIDDEN_MODEL_GROUP","inputSchema","z","isSystemModel","model","Boolean","ListContentModelsToolHandlerImpl","listModels","input","result","Error","ListContentModelsToolHandler","AiSdkToolHandler","ListModelsUseCase","ListContentModelsToolImpl","ListContentModelsTool","AiSdkToolDefinition"],"mappings":";;;AAKA,MAAMA,qBAAqB;AAE3B,MAAMC,cAAcC,EAAE,MAAM,CAAC;IACzB,eAAeA,EAAAA,OACH,GACP,QAAQ,GACR,QAAQ,CACL;AAEZ;AAqBA,MAAMC,gBAAgB,CAACC,QACnBC,QAAQD,MAAM,SAAS,KAAKA,MAAM,KAAK,KAAKJ;AAEhD,MAAMM;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,KAAY,EAA2B;QACjD,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO;QAE5C,IAAIA,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,+BAA+B,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAG5E,OAAOA,OAAO,KAAK,CACd,MAAM,CAACL,CAAAA,QAAUI,MAAM,aAAa,GAAG,OAAO,CAACL,cAAcC,QAC7D,GAAG,CAACA,CAAAA,QAAU;gBACX,SAASA,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;gBAChB,aAAaA,MAAM,WAAW;gBAC9B,OAAOA,MAAM,KAAK;gBAClB,iBAAiBA,MAAM,eAAe;gBACtC,eAAeA,MAAM,aAAa;gBAClC,cAAcA,MAAM,YAAY;gBAChC,YAAYA,MAAM,MAAM,CAAC,MAAM;YACnC;IACR;AACJ;AAEA,MAAMO,+BAA+BC,iBAAiB,oBAAoB,CAAC;IACvE,gBAAgBN;IAChB,cAAc;QAACO;KAAkB;AACrC;AAOA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGb;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGU;;AACvB;AAEO,MAAMI,wBAAwBC,oBAAoB,oBAAoB,CAAC;IAC1E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/ai/ListContentModelsTool.js","sources":["../../../src/features/ai/ListContentModelsTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\nimport { isSystemModel } from \"./models.js\";\n\nconst inputSchema = z.object({\n includeSystem: z\n .boolean()\n .optional()\n .describe(\n \"Include system models that back Webiny itself (languages, tenants, task settings) and internal models belonging to other apps. Off by default — these are never what a user means by 'content'.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface ModelSummary {\n modelId: string;\n name: string;\n description: string | null;\n group: string;\n singularApiName: string;\n pluralApiName: string;\n titleFieldId: string;\n fieldCount: number;\n}\n\nclass ListContentModelsToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private listModels: ListModelsUseCase.Interface) {}\n\n async execute(input: Input): Promise<ModelSummary[]> {\n const result = await this.listModels.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not list content models: ${result.error.message}`);\n }\n\n return result.value\n .filter(model => (input.includeSystem ? true : !isSystemModel(model)))\n .map(model => ({\n modelId: model.modelId,\n name: model.name,\n description: model.description,\n group: model.group,\n singularApiName: model.singularApiName,\n pluralApiName: model.pluralApiName,\n titleFieldId: model.titleFieldId,\n fieldCount: model.fields.length\n }));\n }\n}\n\nconst ListContentModelsToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListContentModelsToolHandlerImpl,\n dependencies: [ListModelsUseCase]\n});\n\n/**\n * Entry point for any content question. The CMS schema is defined per project (and per tenant), so a\n * model list cannot be baked into a system prompt — it has to be discovered at call time. Returns a\n * summary only; `describeContentModel` supplies the field detail needed to actually build a query.\n */\nclass ListContentModelsToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"listContentModels\";\n readonly title = \"List content models\";\n readonly description =\n \"Lists the content models available in this project. Call this first when you need to find content — model IDs are project-specific and cannot be guessed. Returns a summary per model; use describeContentModel for field details.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListContentModelsToolHandler;\n}\n\nexport const ListContentModelsTool = AiSdkToolDefinition.createImplementation({\n implementation: ListContentModelsToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListContentModelsToolHandlerImpl","listModels","input","result","Error","model","isSystemModel","ListContentModelsToolHandler","AiSdkToolHandler","ListModelsUseCase","ListContentModelsToolImpl","ListContentModelsTool","AiSdkToolDefinition"],"mappings":";;;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,eAAeA,EAAAA,OACH,GACP,QAAQ,GACR,QAAQ,CACL;AAEZ;AAeA,MAAMC;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,KAAY,EAA2B;QACjD,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO;QAE5C,IAAIA,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,+BAA+B,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAG5E,OAAOA,OAAO,KAAK,CACd,MAAM,CAACE,CAAAA,QAAUH,MAAM,aAAa,GAAG,OAAO,CAACI,cAAcD,QAC7D,GAAG,CAACA,CAAAA,QAAU;gBACX,SAASA,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;gBAChB,aAAaA,MAAM,WAAW;gBAC9B,OAAOA,MAAM,KAAK;gBAClB,iBAAiBA,MAAM,eAAe;gBACtC,eAAeA,MAAM,aAAa;gBAClC,cAAcA,MAAM,YAAY;gBAChC,YAAYA,MAAM,MAAM,CAAC,MAAM;YACnC;IACR;AACJ;AAEA,MAAME,+BAA+BC,iBAAiB,oBAAoB,CAAC;IACvE,gBAAgBR;IAChB,cAAc;QAACS;KAAkB;AACrC;AAOA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGZ;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGS;;AACvB;AAEO,MAAMI,wBAAwBC,oBAAoB,oBAAoB,CAAC;IAC1E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../../features/contentModel/GetModel/index.js";
4
+ import { GetLatestRevisionByEntryIdUseCase } from "../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
5
+ import { PublishEntryUseCase } from "../../features/contentEntry/PublishEntry/index.js";
6
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { type EntrySummary } from "./entrySummary.js";
8
+ declare const inputSchema: z.ZodObject<{
9
+ modelId: z.ZodString;
10
+ entryId: z.ZodString;
11
+ }, z.core.$strip>;
12
+ type Input = z.infer<typeof inputSchema>;
13
+ /** Publishes the latest revision, which is what the admin's Publish button does. */
14
+ declare class PublishEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
15
+ private getModel;
16
+ private getLatestRevision;
17
+ private publishEntry;
18
+ private notifyRecordChange;
19
+ constructor(getModel: GetModelUseCase.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface, publishEntry: PublishEntryUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
20
+ execute(input: Input): Promise<EntrySummary>;
21
+ }
22
+ /** Makes the entry's latest revision live. Needs approval: it changes what the website shows. */
23
+ declare class PublishEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {
24
+ readonly name = "publishEntry";
25
+ readonly title = "Publish entry";
26
+ readonly description = "Publishes the latest revision of one content entry, making it live. Requires user approval.";
27
+ readonly inputSchema: z.ZodObject<{
28
+ modelId: z.ZodString;
29
+ entryId: z.ZodString;
30
+ }, z.core.$strip>;
31
+ readonly annotations: {
32
+ readOnlyHint: boolean;
33
+ idempotentHint: boolean;
34
+ };
35
+ readonly handler: typeof PublishEntryToolHandlerImpl & {
36
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolHandler<any>>;
37
+ };
38
+ }
39
+ export declare const PublishEntryTool: typeof PublishEntryToolImpl & {
40
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolDefinition<any>>;
41
+ };
42
+ export {};
@@ -0,0 +1,65 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../contentModel/GetModel/index.js";
4
+ import { GetLatestRevisionByEntryIdUseCase } from "../contentEntry/GetLatestRevisionByEntryId/index.js";
5
+ import { PublishEntryUseCase } from "../contentEntry/PublishEntry/index.js";
6
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { ENTRY_RECORD_TYPE } from "../contentEntry/NotifyEntryChange/index.js";
8
+ import { getLatestEntryRevision, getWritableModel } from "./models.js";
9
+ import { toEntrySummary } from "./entrySummary.js";
10
+ const inputSchema = z.object({
11
+ modelId: z.string().describe("Model ID as returned by listContentModels."),
12
+ entryId: z.string().describe("The entry's `entryId` as returned by queryEntries.")
13
+ });
14
+ class PublishEntryToolHandlerImpl {
15
+ constructor(getModel, getLatestRevision, publishEntry, notifyRecordChange){
16
+ this.getModel = getModel;
17
+ this.getLatestRevision = getLatestRevision;
18
+ this.publishEntry = publishEntry;
19
+ this.notifyRecordChange = notifyRecordChange;
20
+ }
21
+ async execute(input) {
22
+ const model = await getWritableModel(this.getModel, input.modelId);
23
+ const latest = await getLatestEntryRevision(this.getLatestRevision, model, input.entryId);
24
+ if ("published" === latest.status) throw new Error(`Entry "${input.entryId}" is already published. Nothing was changed.`);
25
+ const result = await this.publishEntry.execute(model, latest.id);
26
+ if (result.isFail()) throw new Error(`Could not publish the entry: ${result.error.message}`);
27
+ const entry = result.value;
28
+ await this.notifyRecordChange.execute({
29
+ type: ENTRY_RECORD_TYPE,
30
+ id: entry.entryId,
31
+ scope: model.modelId,
32
+ change: "updated"
33
+ });
34
+ return toEntrySummary(entry);
35
+ }
36
+ }
37
+ const PublishEntryToolHandler = AiSdkToolHandler.createImplementation({
38
+ implementation: PublishEntryToolHandlerImpl,
39
+ dependencies: [
40
+ GetModelUseCase,
41
+ GetLatestRevisionByEntryIdUseCase,
42
+ PublishEntryUseCase,
43
+ NotifyRecordChangeUseCase
44
+ ]
45
+ });
46
+ class PublishEntryToolImpl {
47
+ constructor(){
48
+ this.name = "publishEntry";
49
+ this.title = "Publish entry";
50
+ this.description = "Publishes the latest revision of one content entry, making it live. Requires user approval.";
51
+ this.inputSchema = inputSchema;
52
+ this.annotations = {
53
+ readOnlyHint: false,
54
+ idempotentHint: true
55
+ };
56
+ this.handler = PublishEntryToolHandler;
57
+ }
58
+ }
59
+ const PublishEntryTool = AiSdkToolDefinition.createImplementation({
60
+ implementation: PublishEntryToolImpl,
61
+ dependencies: []
62
+ });
63
+ export { PublishEntryTool };
64
+
65
+ //# sourceMappingURL=PublishEntryTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/PublishEntryTool.js","sources":["../../../src/features/ai/PublishEntryTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { PublishEntryUseCase } from \"~/features/contentEntry/PublishEntry/index.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { ENTRY_RECORD_TYPE } from \"~/features/contentEntry/NotifyEntryChange/index.js\";\nimport { getLatestEntryRevision } from \"./models.js\";\nimport { getWritableModel } from \"./models.js\";\nimport { toEntrySummary, type EntrySummary } from \"./entrySummary.js\";\n\nconst inputSchema = z.object({\n modelId: z.string().describe(\"Model ID as returned by listContentModels.\"),\n entryId: z.string().describe(\"The entry's `entryId` as returned by queryEntries.\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\n/** Publishes the latest revision, which is what the admin's Publish button does. */\nclass PublishEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getModel: GetModelUseCase.Interface,\n private getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface,\n private publishEntry: PublishEntryUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<EntrySummary> {\n const model = await getWritableModel(this.getModel, input.modelId);\n\n const latest = await getLatestEntryRevision(this.getLatestRevision, model, input.entryId);\n\n if (latest.status === \"published\") {\n throw new Error(`Entry \"${input.entryId}\" is already published. Nothing was changed.`);\n }\n\n const result = await this.publishEntry.execute(model, latest.id);\n if (result.isFail()) {\n throw new Error(`Could not publish the entry: ${result.error.message}`);\n }\n\n const entry = result.value;\n await this.notifyRecordChange.execute({\n type: ENTRY_RECORD_TYPE,\n id: entry.entryId,\n scope: model.modelId,\n change: \"updated\"\n });\n\n return toEntrySummary(entry);\n }\n}\n\nconst PublishEntryToolHandler = AiSdkToolHandler.createImplementation({\n implementation: PublishEntryToolHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetLatestRevisionByEntryIdUseCase,\n PublishEntryUseCase,\n NotifyRecordChangeUseCase\n ]\n});\n\n/** Makes the entry's latest revision live. Needs approval: it changes what the website shows. */\nclass PublishEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"publishEntry\";\n readonly title = \"Publish entry\";\n readonly description =\n \"Publishes the latest revision of one content entry, making it live. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, idempotentHint: true };\n readonly handler = PublishEntryToolHandler;\n}\n\nexport const PublishEntryTool = AiSdkToolDefinition.createImplementation({\n implementation: PublishEntryToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","PublishEntryToolHandlerImpl","getModel","getLatestRevision","publishEntry","notifyRecordChange","input","model","getWritableModel","latest","getLatestEntryRevision","Error","result","entry","ENTRY_RECORD_TYPE","toEntrySummary","PublishEntryToolHandler","AiSdkToolHandler","GetModelUseCase","GetLatestRevisionByEntryIdUseCase","PublishEntryUseCase","NotifyRecordChangeUseCase","PublishEntryToolImpl","PublishEntryTool","AiSdkToolDefinition"],"mappings":";;;;;;;;;AAWA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;AACjC;AAKA,MAAMC;IACF,YACYC,QAAmC,EACnCC,iBAA8D,EAC9DC,YAA2C,EAC3CC,kBAAuD,CACjE;aAJUH,QAAQ,GAARA;aACAC,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAyB;QAC/C,MAAMC,QAAQ,MAAMC,iBAAiB,IAAI,CAAC,QAAQ,EAAEF,MAAM,OAAO;QAEjE,MAAMG,SAAS,MAAMC,uBAAuB,IAAI,CAAC,iBAAiB,EAAEH,OAAOD,MAAM,OAAO;QAExF,IAAIG,AAAkB,gBAAlBA,OAAO,MAAM,EACb,MAAM,IAAIE,MAAM,CAAC,OAAO,EAAEL,MAAM,OAAO,CAAC,4CAA4C,CAAC;QAGzF,MAAMM,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACL,OAAOE,OAAO,EAAE;QAC/D,IAAIG,OAAO,MAAM,IACb,MAAM,IAAID,MAAM,CAAC,6BAA6B,EAAEC,OAAO,KAAK,CAAC,OAAO,EAAE;QAG1E,MAAMC,QAAQD,OAAO,KAAK;QAC1B,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAME;YACN,IAAID,MAAM,OAAO;YACjB,OAAON,MAAM,OAAO;YACpB,QAAQ;QACZ;QAEA,OAAOQ,eAAeF;IAC1B;AACJ;AAEA,MAAMG,0BAA0BC,iBAAiB,oBAAoB,CAAC;IAClE,gBAAgBhB;IAChB,cAAc;QACViB;QACAC;QACAC;QACAC;KACH;AACL;AAGA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGvB;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,gBAAgB;QAAK;aAC1D,OAAO,GAAGiB;;AACvB;AAEO,MAAMO,mBAAmBC,oBAAoB,oBAAoB,CAAC;IACrE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../../features/contentModel/GetModel/index.js";
4
+ import { GetPublishedRevisionByEntryIdUseCase } from "../../features/contentEntry/GetPublishedRevisionByEntryId/index.js";
5
+ import { UnpublishEntryUseCase } from "../../features/contentEntry/UnpublishEntry/index.js";
6
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { type EntrySummary } from "./entrySummary.js";
8
+ declare const inputSchema: z.ZodObject<{
9
+ modelId: z.ZodString;
10
+ entryId: z.ZodString;
11
+ }, z.core.$strip>;
12
+ type Input = z.infer<typeof inputSchema>;
13
+ /** Takes the published revision offline. The entry and its revisions stay. */
14
+ declare class UnpublishEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
15
+ private getModel;
16
+ private getPublishedRevision;
17
+ private unpublishEntry;
18
+ private notifyRecordChange;
19
+ constructor(getModel: GetModelUseCase.Interface, getPublishedRevision: GetPublishedRevisionByEntryIdUseCase.Interface, unpublishEntry: UnpublishEntryUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
20
+ execute(input: Input): Promise<EntrySummary>;
21
+ }
22
+ /** Takes an entry offline. Needs approval: it changes what the website shows. */
23
+ declare class UnpublishEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {
24
+ readonly name = "unpublishEntry";
25
+ readonly title = "Unpublish entry";
26
+ readonly description = "Unpublishes one content entry, taking it offline. The entry and its content stay and can be published again. Requires user approval.";
27
+ readonly inputSchema: z.ZodObject<{
28
+ modelId: z.ZodString;
29
+ entryId: z.ZodString;
30
+ }, z.core.$strip>;
31
+ readonly annotations: {
32
+ readOnlyHint: boolean;
33
+ idempotentHint: boolean;
34
+ };
35
+ readonly handler: typeof UnpublishEntryToolHandlerImpl & {
36
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolHandler<any>>;
37
+ };
38
+ }
39
+ export declare const UnpublishEntryTool: typeof UnpublishEntryToolImpl & {
40
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolDefinition<any>>;
41
+ };
42
+ export {};
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../contentModel/GetModel/index.js";
4
+ import { GetPublishedRevisionByEntryIdUseCase } from "../contentEntry/GetPublishedRevisionByEntryId/index.js";
5
+ import { UnpublishEntryUseCase } from "../contentEntry/UnpublishEntry/index.js";
6
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { ENTRY_RECORD_TYPE } from "../contentEntry/NotifyEntryChange/index.js";
8
+ import { getWritableModel } from "./models.js";
9
+ import { toEntrySummary } from "./entrySummary.js";
10
+ const inputSchema = z.object({
11
+ modelId: z.string().describe("Model ID as returned by listContentModels."),
12
+ entryId: z.string().describe("The entry's `entryId` as returned by queryEntries.")
13
+ });
14
+ class UnpublishEntryToolHandlerImpl {
15
+ constructor(getModel, getPublishedRevision, unpublishEntry, notifyRecordChange){
16
+ this.getModel = getModel;
17
+ this.getPublishedRevision = getPublishedRevision;
18
+ this.unpublishEntry = unpublishEntry;
19
+ this.notifyRecordChange = notifyRecordChange;
20
+ }
21
+ async execute(input) {
22
+ const model = await getWritableModel(this.getModel, input.modelId);
23
+ const published = await this.getPublishedRevision.execute(model, input.entryId);
24
+ if (published.isFail() && "Cms/Entry/NotFound" !== published.error.code) throw new Error(`Could not read entry "${input.entryId}": ${published.error.message}`);
25
+ const revision = published.isOk() ? published.value : null;
26
+ if (!revision) throw new Error(`Entry "${input.entryId}" is not published. Nothing was changed.`);
27
+ const result = await this.unpublishEntry.execute(model, revision.id);
28
+ if (result.isFail()) throw new Error(`Could not unpublish the entry: ${result.error.message}`);
29
+ const entry = result.value;
30
+ await this.notifyRecordChange.execute({
31
+ type: ENTRY_RECORD_TYPE,
32
+ id: entry.entryId,
33
+ scope: model.modelId,
34
+ change: "updated"
35
+ });
36
+ return toEntrySummary(entry);
37
+ }
38
+ }
39
+ const UnpublishEntryToolHandler = AiSdkToolHandler.createImplementation({
40
+ implementation: UnpublishEntryToolHandlerImpl,
41
+ dependencies: [
42
+ GetModelUseCase,
43
+ GetPublishedRevisionByEntryIdUseCase,
44
+ UnpublishEntryUseCase,
45
+ NotifyRecordChangeUseCase
46
+ ]
47
+ });
48
+ class UnpublishEntryToolImpl {
49
+ constructor(){
50
+ this.name = "unpublishEntry";
51
+ this.title = "Unpublish entry";
52
+ this.description = "Unpublishes one content entry, taking it offline. The entry and its content stay and can be published again. Requires user approval.";
53
+ this.inputSchema = inputSchema;
54
+ this.annotations = {
55
+ readOnlyHint: false,
56
+ idempotentHint: true
57
+ };
58
+ this.handler = UnpublishEntryToolHandler;
59
+ }
60
+ }
61
+ const UnpublishEntryTool = AiSdkToolDefinition.createImplementation({
62
+ implementation: UnpublishEntryToolImpl,
63
+ dependencies: []
64
+ });
65
+ export { UnpublishEntryTool };
66
+
67
+ //# sourceMappingURL=UnpublishEntryTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/UnpublishEntryTool.js","sources":["../../../src/features/ai/UnpublishEntryTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetPublishedRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetPublishedRevisionByEntryId/index.js\";\nimport { UnpublishEntryUseCase } from \"~/features/contentEntry/UnpublishEntry/index.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { ENTRY_RECORD_TYPE } from \"~/features/contentEntry/NotifyEntryChange/index.js\";\nimport { getWritableModel } from \"./models.js\";\nimport { toEntrySummary, type EntrySummary } from \"./entrySummary.js\";\n\nconst inputSchema = z.object({\n modelId: z.string().describe(\"Model ID as returned by listContentModels.\"),\n entryId: z.string().describe(\"The entry's `entryId` as returned by queryEntries.\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\n/** Takes the published revision offline. The entry and its revisions stay. */\nclass UnpublishEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getModel: GetModelUseCase.Interface,\n private getPublishedRevision: GetPublishedRevisionByEntryIdUseCase.Interface,\n private unpublishEntry: UnpublishEntryUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<EntrySummary> {\n const model = await getWritableModel(this.getModel, input.modelId);\n\n const published = await this.getPublishedRevision.execute(model, input.entryId);\n\n // An entry with no published revision reads as not found, or as `null`.\n if (published.isFail() && published.error.code !== \"Cms/Entry/NotFound\") {\n throw new Error(`Could not read entry \"${input.entryId}\": ${published.error.message}`);\n }\n\n const revision = published.isOk() ? published.value : null;\n if (!revision) {\n throw new Error(`Entry \"${input.entryId}\" is not published. Nothing was changed.`);\n }\n\n const result = await this.unpublishEntry.execute(model, revision.id);\n if (result.isFail()) {\n throw new Error(`Could not unpublish the entry: ${result.error.message}`);\n }\n\n const entry = result.value;\n await this.notifyRecordChange.execute({\n type: ENTRY_RECORD_TYPE,\n id: entry.entryId,\n scope: model.modelId,\n change: \"updated\"\n });\n\n return toEntrySummary(entry);\n }\n}\n\nconst UnpublishEntryToolHandler = AiSdkToolHandler.createImplementation({\n implementation: UnpublishEntryToolHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetPublishedRevisionByEntryIdUseCase,\n UnpublishEntryUseCase,\n NotifyRecordChangeUseCase\n ]\n});\n\n/** Takes an entry offline. Needs approval: it changes what the website shows. */\nclass UnpublishEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"unpublishEntry\";\n readonly title = \"Unpublish entry\";\n readonly description =\n \"Unpublishes one content entry, taking it offline. The entry and its content stay and can be published again. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, idempotentHint: true };\n readonly handler = UnpublishEntryToolHandler;\n}\n\nexport const UnpublishEntryTool = AiSdkToolDefinition.createImplementation({\n implementation: UnpublishEntryToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","UnpublishEntryToolHandlerImpl","getModel","getPublishedRevision","unpublishEntry","notifyRecordChange","input","model","getWritableModel","published","Error","revision","result","entry","ENTRY_RECORD_TYPE","toEntrySummary","UnpublishEntryToolHandler","AiSdkToolHandler","GetModelUseCase","GetPublishedRevisionByEntryIdUseCase","UnpublishEntryUseCase","NotifyRecordChangeUseCase","UnpublishEntryToolImpl","UnpublishEntryTool","AiSdkToolDefinition"],"mappings":";;;;;;;;;AAUA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;AACjC;AAKA,MAAMC;IACF,YACYC,QAAmC,EACnCC,oBAAoE,EACpEC,cAA+C,EAC/CC,kBAAuD,CACjE;aAJUH,QAAQ,GAARA;aACAC,oBAAoB,GAApBA;aACAC,cAAc,GAAdA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAyB;QAC/C,MAAMC,QAAQ,MAAMC,iBAAiB,IAAI,CAAC,QAAQ,EAAEF,MAAM,OAAO;QAEjE,MAAMG,YAAY,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACF,OAAOD,MAAM,OAAO;QAG9E,IAAIG,UAAU,MAAM,MAAMA,AAAyB,yBAAzBA,UAAU,KAAK,CAAC,IAAI,EAC1C,MAAM,IAAIC,MAAM,CAAC,sBAAsB,EAAEJ,MAAM,OAAO,CAAC,GAAG,EAAEG,UAAU,KAAK,CAAC,OAAO,EAAE;QAGzF,MAAME,WAAWF,UAAU,IAAI,KAAKA,UAAU,KAAK,GAAG;QACtD,IAAI,CAACE,UACD,MAAM,IAAID,MAAM,CAAC,OAAO,EAAEJ,MAAM,OAAO,CAAC,wCAAwC,CAAC;QAGrF,MAAMM,SAAS,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACL,OAAOI,SAAS,EAAE;QACnE,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIF,MAAM,CAAC,+BAA+B,EAAEE,OAAO,KAAK,CAAC,OAAO,EAAE;QAG5E,MAAMC,QAAQD,OAAO,KAAK;QAC1B,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAME;YACN,IAAID,MAAM,OAAO;YACjB,OAAON,MAAM,OAAO;YACpB,QAAQ;QACZ;QAEA,OAAOQ,eAAeF;IAC1B;AACJ;AAEA,MAAMG,4BAA4BC,iBAAiB,oBAAoB,CAAC;IACpE,gBAAgBhB;IAChB,cAAc;QACViB;QACAC;QACAC;QACAC;KACH;AACL;AAGA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGvB;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,gBAAgB;QAAK;aAC1D,OAAO,GAAGiB;;AACvB;AAEO,MAAMO,qBAAqBC,oBAAoB,oBAAoB,CAAC;IACvE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../../features/contentModel/GetModel/index.js";
4
+ import { GetLatestRevisionByEntryIdUseCase } from "../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
5
+ import { UpdateEntryUseCase } from "../../features/contentEntry/UpdateEntry/index.js";
6
+ import { CreateEntryRevisionFromUseCase } from "../../features/contentEntry/CreateEntryRevisionFrom/index.js";
7
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
8
+ import { type EntrySummary } from "./entrySummary.js";
9
+ declare const inputSchema: z.ZodObject<{
10
+ modelId: z.ZodString;
11
+ entryId: z.ZodString;
12
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
13
+ }, z.core.$strip>;
14
+ type Input = z.infer<typeof inputSchema>;
15
+ declare class UpdateEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
16
+ private getModel;
17
+ private getLatestRevision;
18
+ private updateEntry;
19
+ private createRevisionFrom;
20
+ private notifyRecordChange;
21
+ constructor(getModel: GetModelUseCase.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface, updateEntry: UpdateEntryUseCase.Interface, createRevisionFrom: CreateEntryRevisionFromUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
22
+ execute(input: Input): Promise<EntrySummary & {
23
+ newRevision: boolean;
24
+ }>;
25
+ }
26
+ /** Changes some fields of one entry. Needs approval; the approval shows exactly which fields. */
27
+ declare class UpdateEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {
28
+ readonly name = "updateEntry";
29
+ readonly title = "Update entry";
30
+ readonly description = "Changes some field values of one content entry, leaving the other fields as they are. If the entry is published, the change goes into a new draft revision and the published version stays live until publishEntry is called. Call describeContentModel for field IDs and queryEntries for the entryId. Requires user approval.";
31
+ readonly inputSchema: z.ZodObject<{
32
+ modelId: z.ZodString;
33
+ entryId: z.ZodString;
34
+ values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
35
+ }, z.core.$strip>;
36
+ readonly annotations: {
37
+ readOnlyHint: boolean;
38
+ idempotentHint: boolean;
39
+ };
40
+ readonly handler: typeof UpdateEntryToolHandlerImpl & {
41
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolHandler<any>>;
42
+ };
43
+ }
44
+ export declare const UpdateEntryTool: typeof UpdateEntryToolImpl & {
45
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions.js").IAiSdkToolDefinition<any>>;
46
+ };
47
+ export {};
@@ -0,0 +1,78 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetModelUseCase } from "../contentModel/GetModel/index.js";
4
+ import { GetLatestRevisionByEntryIdUseCase } from "../contentEntry/GetLatestRevisionByEntryId/index.js";
5
+ import { UpdateEntryUseCase } from "../contentEntry/UpdateEntry/index.js";
6
+ import { CreateEntryRevisionFromUseCase } from "../contentEntry/CreateEntryRevisionFrom/index.js";
7
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
8
+ import { ENTRY_RECORD_TYPE } from "../contentEntry/NotifyEntryChange/index.js";
9
+ import { assertKnownFields } from "./assertKnownFields.js";
10
+ import { getLatestEntryRevision, getWritableModel } from "./models.js";
11
+ import { toEntrySummary } from "./entrySummary.js";
12
+ const inputSchema = z.object({
13
+ modelId: z.string().describe("Model ID as returned by listContentModels."),
14
+ entryId: z.string().describe("The entry's `entryId` as returned by queryEntries."),
15
+ values: z.record(z.string(), z.unknown()).describe("Only the fields to change, keyed by field ID from describeContentModel. Fields left out keep their current values.")
16
+ });
17
+ class UpdateEntryToolHandlerImpl {
18
+ constructor(getModel, getLatestRevision, updateEntry, createRevisionFrom, notifyRecordChange){
19
+ this.getModel = getModel;
20
+ this.getLatestRevision = getLatestRevision;
21
+ this.updateEntry = updateEntry;
22
+ this.createRevisionFrom = createRevisionFrom;
23
+ this.notifyRecordChange = notifyRecordChange;
24
+ }
25
+ async execute(input) {
26
+ const model = await getWritableModel(this.getModel, input.modelId);
27
+ assertKnownFields(model, input.values);
28
+ const revision = await getLatestEntryRevision(this.getLatestRevision, model, input.entryId);
29
+ const newRevision = Boolean(revision.locked);
30
+ const result = newRevision ? await this.createRevisionFrom.execute(model, revision.id, {
31
+ values: input.values
32
+ }) : await this.updateEntry.execute(model, revision.id, {
33
+ values: input.values
34
+ });
35
+ if (result.isFail()) throw new Error(`Could not update the entry: ${result.error.message}`);
36
+ const entry = result.value;
37
+ await this.notifyRecordChange.execute({
38
+ type: ENTRY_RECORD_TYPE,
39
+ id: entry.entryId,
40
+ scope: model.modelId,
41
+ change: "updated"
42
+ });
43
+ return {
44
+ ...toEntrySummary(entry),
45
+ newRevision
46
+ };
47
+ }
48
+ }
49
+ const UpdateEntryToolHandler = AiSdkToolHandler.createImplementation({
50
+ implementation: UpdateEntryToolHandlerImpl,
51
+ dependencies: [
52
+ GetModelUseCase,
53
+ GetLatestRevisionByEntryIdUseCase,
54
+ UpdateEntryUseCase,
55
+ CreateEntryRevisionFromUseCase,
56
+ NotifyRecordChangeUseCase
57
+ ]
58
+ });
59
+ class UpdateEntryToolImpl {
60
+ constructor(){
61
+ this.name = "updateEntry";
62
+ this.title = "Update entry";
63
+ this.description = "Changes some field values of one content entry, leaving the other fields as they are. If the entry is published, the change goes into a new draft revision and the published version stays live until publishEntry is called. Call describeContentModel for field IDs and queryEntries for the entryId. Requires user approval.";
64
+ this.inputSchema = inputSchema;
65
+ this.annotations = {
66
+ readOnlyHint: false,
67
+ idempotentHint: true
68
+ };
69
+ this.handler = UpdateEntryToolHandler;
70
+ }
71
+ }
72
+ const UpdateEntryTool = AiSdkToolDefinition.createImplementation({
73
+ implementation: UpdateEntryToolImpl,
74
+ dependencies: []
75
+ });
76
+ export { UpdateEntryTool };
77
+
78
+ //# sourceMappingURL=UpdateEntryTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/UpdateEntryTool.js","sources":["../../../src/features/ai/UpdateEntryTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { UpdateEntryUseCase } from \"~/features/contentEntry/UpdateEntry/index.js\";\nimport { CreateEntryRevisionFromUseCase } from \"~/features/contentEntry/CreateEntryRevisionFrom/index.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { ENTRY_RECORD_TYPE } from \"~/features/contentEntry/NotifyEntryChange/index.js\";\nimport { assertKnownFields } from \"./assertKnownFields.js\";\nimport { getLatestEntryRevision } from \"./models.js\";\nimport { getWritableModel } from \"./models.js\";\nimport { toEntrySummary, type EntrySummary } from \"./entrySummary.js\";\n\nconst inputSchema = z.object({\n modelId: z.string().describe(\"Model ID as returned by listContentModels.\"),\n entryId: z.string().describe(\"The entry's `entryId` as returned by queryEntries.\"),\n values: z\n .record(z.string(), z.unknown())\n .describe(\n \"Only the fields to change, keyed by field ID from describeContentModel. Fields left out keep their current values.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\n/*\n * Changes the latest revision. A published (locked) revision cannot be changed, so in that case a\n * new draft revision is created from it with the new values, which is what the admin's editor does\n * when you save a published entry. The published content stays live until that draft is published.\n */\nclass UpdateEntryToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getModel: GetModelUseCase.Interface,\n private getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface,\n private updateEntry: UpdateEntryUseCase.Interface,\n private createRevisionFrom: CreateEntryRevisionFromUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<EntrySummary & { newRevision: boolean }> {\n const model = await getWritableModel(this.getModel, input.modelId);\n assertKnownFields(model, input.values);\n\n const revision = await getLatestEntryRevision(this.getLatestRevision, model, input.entryId);\n\n const newRevision = Boolean(revision.locked);\n\n const result = newRevision\n ? await this.createRevisionFrom.execute(model, revision.id, { values: input.values })\n : await this.updateEntry.execute(model, revision.id, { values: input.values });\n\n if (result.isFail()) {\n throw new Error(`Could not update the entry: ${result.error.message}`);\n }\n\n const entry = result.value;\n await this.notifyRecordChange.execute({\n type: ENTRY_RECORD_TYPE,\n id: entry.entryId,\n scope: model.modelId,\n change: \"updated\"\n });\n\n return { ...toEntrySummary(entry), newRevision };\n }\n}\n\nconst UpdateEntryToolHandler = AiSdkToolHandler.createImplementation({\n implementation: UpdateEntryToolHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetLatestRevisionByEntryIdUseCase,\n UpdateEntryUseCase,\n CreateEntryRevisionFromUseCase,\n NotifyRecordChangeUseCase\n ]\n});\n\n/** Changes some fields of one entry. Needs approval; the approval shows exactly which fields. */\nclass UpdateEntryToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"updateEntry\";\n readonly title = \"Update entry\";\n readonly description =\n \"Changes some field values of one content entry, leaving the other fields as they are. If the entry is published, the change goes into a new draft revision and the published version stays live until publishEntry is called. Call describeContentModel for field IDs and queryEntries for the entryId. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, idempotentHint: true };\n readonly handler = UpdateEntryToolHandler;\n}\n\nexport const UpdateEntryTool = AiSdkToolDefinition.createImplementation({\n implementation: UpdateEntryToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","UpdateEntryToolHandlerImpl","getModel","getLatestRevision","updateEntry","createRevisionFrom","notifyRecordChange","input","model","getWritableModel","assertKnownFields","revision","getLatestEntryRevision","newRevision","Boolean","result","Error","entry","ENTRY_RECORD_TYPE","toEntrySummary","UpdateEntryToolHandler","AiSdkToolHandler","GetModelUseCase","GetLatestRevisionByEntryIdUseCase","UpdateEntryUseCase","CreateEntryRevisionFromUseCase","NotifyRecordChangeUseCase","UpdateEntryToolImpl","UpdateEntryTool","AiSdkToolDefinition"],"mappings":";;;;;;;;;;;AAaA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAASA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,QAAQA,EAAAA,MACG,CAACA,EAAE,MAAM,IAAIA,EAAE,OAAO,IAC5B,QAAQ,CACL;AAEZ;AASA,MAAMC;IACF,YACYC,QAAmC,EACnCC,iBAA8D,EAC9DC,WAAyC,EACzCC,kBAA4D,EAC5DC,kBAAuD,CACjE;aALUJ,QAAQ,GAARA;aACAC,iBAAiB,GAAjBA;aACAC,WAAW,GAAXA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,KAAY,EAAoD;QAC1E,MAAMC,QAAQ,MAAMC,iBAAiB,IAAI,CAAC,QAAQ,EAAEF,MAAM,OAAO;QACjEG,kBAAkBF,OAAOD,MAAM,MAAM;QAErC,MAAMI,WAAW,MAAMC,uBAAuB,IAAI,CAAC,iBAAiB,EAAEJ,OAAOD,MAAM,OAAO;QAE1F,MAAMM,cAAcC,QAAQH,SAAS,MAAM;QAE3C,MAAMI,SAASF,cACT,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACL,OAAOG,SAAS,EAAE,EAAE;YAAE,QAAQJ,MAAM,MAAM;QAAC,KACjF,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACC,OAAOG,SAAS,EAAE,EAAE;YAAE,QAAQJ,MAAM,MAAM;QAAC;QAEhF,IAAIQ,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,4BAA4B,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGzE,MAAME,QAAQF,OAAO,KAAK;QAC1B,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMG;YACN,IAAID,MAAM,OAAO;YACjB,OAAOT,MAAM,OAAO;YACpB,QAAQ;QACZ;QAEA,OAAO;YAAE,GAAGW,eAAeF,MAAM;YAAEJ;QAAY;IACnD;AACJ;AAEA,MAAMO,yBAAyBC,iBAAiB,oBAAoB,CAAC;IACjE,gBAAgBpB;IAChB,cAAc;QACVqB;QACAC;QACAC;QACAC;QACAC;KACH;AACL;AAGA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAG5B;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,gBAAgB;QAAK;aAC1D,OAAO,GAAGqB;;AACvB;AAEO,MAAMQ,kBAAkBC,oBAAoB,oBAAoB,CAAC;IACpE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,7 @@
1
+ import type { CmsModel } from "../../types/index.js";
2
+ /**
3
+ * Refuses values keyed by a field the model does not have. The entry write would drop them without
4
+ * a word and report success, so the assistant would tell the user it set a field that was never
5
+ * saved. Checks the top level only; nested object fields go through the same drop.
6
+ */
7
+ export declare const assertKnownFields: (model: CmsModel, values: Record<string, unknown>) => void;
@@ -0,0 +1,11 @@
1
+ const assertKnownFields = (model, values)=>{
2
+ const knownFieldIds = model.fields.map((field)=>field.fieldId);
3
+ const fieldIds = new Set(knownFieldIds);
4
+ const unknown = Object.keys(values).filter((fieldId)=>!fieldIds.has(fieldId));
5
+ if (!unknown.length) return;
6
+ const names = unknown.map((fieldId)=>`"${fieldId}"`).join(", ");
7
+ throw new Error(`Unknown ${1 === unknown.length ? "field" : "fields"} ${names} in "${model.modelId}". Call describeContentModel for valid field IDs.`);
8
+ };
9
+ export { assertKnownFields };
10
+
11
+ //# sourceMappingURL=assertKnownFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/assertKnownFields.js","sources":["../../../src/features/ai/assertKnownFields.ts"],"sourcesContent":["import type { CmsModel } from \"~/types/index.js\";\n\n/**\n * Refuses values keyed by a field the model does not have. The entry write would drop them without\n * a word and report success, so the assistant would tell the user it set a field that was never\n * saved. Checks the top level only; nested object fields go through the same drop.\n */\nexport const assertKnownFields = (model: CmsModel, values: Record<string, unknown>): void => {\n const knownFieldIds = model.fields.map(field => field.fieldId);\n const fieldIds = new Set(knownFieldIds);\n const unknown = Object.keys(values).filter(fieldId => !fieldIds.has(fieldId));\n\n if (!unknown.length) {\n return;\n }\n\n const names = unknown.map(fieldId => `\"${fieldId}\"`).join(\", \");\n throw new Error(\n `Unknown ${unknown.length === 1 ? \"field\" : \"fields\"} ${names} in \"${model.modelId}\". Call describeContentModel for valid field IDs.`\n );\n};\n"],"names":["assertKnownFields","model","values","knownFieldIds","field","fieldIds","Set","unknown","Object","fieldId","names","Error"],"mappings":"AAOO,MAAMA,oBAAoB,CAACC,OAAiBC;IAC/C,MAAMC,gBAAgBF,MAAM,MAAM,CAAC,GAAG,CAACG,CAAAA,QAASA,MAAM,OAAO;IAC7D,MAAMC,WAAW,IAAIC,IAAIH;IACzB,MAAMI,UAAUC,OAAO,IAAI,CAACN,QAAQ,MAAM,CAACO,CAAAA,UAAW,CAACJ,SAAS,GAAG,CAACI;IAEpE,IAAI,CAACF,QAAQ,MAAM,EACf;IAGJ,MAAMG,QAAQH,QAAQ,GAAG,CAACE,CAAAA,UAAW,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC;IAC1D,MAAM,IAAIE,MACN,CAAC,QAAQ,EAAEJ,AAAmB,MAAnBA,QAAQ,MAAM,GAAS,UAAU,SAAS,CAAC,EAAEG,MAAM,KAAK,EAAET,MAAM,OAAO,CAAC,iDAAiD,CAAC;AAE7I"}
@@ -0,0 +1,9 @@
1
+ import type { CmsEntry } from "../../types/index.js";
2
+ export interface EntrySummary {
3
+ id: string;
4
+ entryId: string;
5
+ status: string;
6
+ values: Record<string, unknown>;
7
+ }
8
+ /** What an entry write tool reports back: enough to refer to the entry and to see what was stored. */
9
+ export declare const toEntrySummary: (entry: CmsEntry) => EntrySummary;
@@ -0,0 +1,9 @@
1
+ const toEntrySummary = (entry)=>({
2
+ id: entry.id,
3
+ entryId: entry.entryId,
4
+ status: entry.status,
5
+ values: entry.values
6
+ });
7
+ export { toEntrySummary };
8
+
9
+ //# sourceMappingURL=entrySummary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/entrySummary.js","sources":["../../../src/features/ai/entrySummary.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface EntrySummary {\n id: string;\n entryId: string;\n status: string;\n values: Record<string, unknown>;\n}\n\n/** What an entry write tool reports back: enough to refer to the entry and to see what was stored. */\nexport const toEntrySummary = (entry: CmsEntry): EntrySummary => ({\n id: entry.id,\n entryId: entry.entryId,\n status: entry.status,\n values: entry.values\n});\n"],"names":["toEntrySummary","entry"],"mappings":"AAUO,MAAMA,iBAAiB,CAACC,QAAmC;QAC9D,IAAIA,MAAM,EAAE;QACZ,SAASA,MAAM,OAAO;QACtB,QAAQA,MAAM,MAAM;QACpB,QAAQA,MAAM,MAAM;IACxB"}
@@ -1,6 +1,10 @@
1
1
  /**
2
- * Read-only CMS tools for AI callers. Registered as `AiSdkToolDefinition` implementations, so any
3
- * caller that builds a tool set from that abstraction picks them up without naming them.
2
+ * CMS tools for AI callers. Registered as `AiSdkToolDefinition` implementations, so any caller that
3
+ * builds a tool set from that abstraction picks them up without naming them.
4
+ *
5
+ * The model and query tools are read-only and run unattended. The entry tools write, so each pauses
6
+ * for the user to approve the exact arguments. None of them deletes permanently: `deleteEntry` moves
7
+ * the entry to the trash bin.
4
8
  */
5
9
  export declare const CmsAiToolsFeature: {
6
10
  name: string;
@@ -2,12 +2,22 @@ import { createFeature } from "@webiny/feature/api";
2
2
  import { ListContentModelsTool } from "./ListContentModelsTool.js";
3
3
  import { DescribeContentModelTool } from "./DescribeContentModelTool.js";
4
4
  import { QueryEntriesTool } from "./QueryEntriesTool.js";
5
+ import { CreateEntryTool } from "./CreateEntryTool.js";
6
+ import { UpdateEntryTool } from "./UpdateEntryTool.js";
7
+ import { PublishEntryTool } from "./PublishEntryTool.js";
8
+ import { UnpublishEntryTool } from "./UnpublishEntryTool.js";
9
+ import { DeleteEntryTool } from "./DeleteEntryTool.js";
5
10
  const CmsAiToolsFeature = createFeature({
6
11
  name: "HeadlessCms/AiTools",
7
12
  register (container) {
8
13
  container.register(ListContentModelsTool);
9
14
  container.register(DescribeContentModelTool);
10
15
  container.register(QueryEntriesTool);
16
+ container.register(CreateEntryTool);
17
+ container.register(UpdateEntryTool);
18
+ container.register(PublishEntryTool);
19
+ container.register(UnpublishEntryTool);
20
+ container.register(DeleteEntryTool);
11
21
  }
12
22
  });
13
23
  export { CmsAiToolsFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListContentModelsTool } from \"./ListContentModelsTool.js\";\nimport { DescribeContentModelTool } from \"./DescribeContentModelTool.js\";\nimport { QueryEntriesTool } from \"./QueryEntriesTool.js\";\n\n/**\n * Read-only CMS tools for AI callers. Registered as `AiSdkToolDefinition` implementations, so any\n * caller that builds a tool set from that abstraction picks them up without naming them.\n */\nexport const CmsAiToolsFeature = createFeature({\n name: \"HeadlessCms/AiTools\",\n register(container) {\n container.register(ListContentModelsTool);\n container.register(DescribeContentModelTool);\n container.register(QueryEntriesTool);\n }\n});\n"],"names":["CmsAiToolsFeature","createFeature","container","ListContentModelsTool","DescribeContentModelTool","QueryEntriesTool"],"mappings":";;;;AASO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
1
+ {"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListContentModelsTool } from \"./ListContentModelsTool.js\";\nimport { DescribeContentModelTool } from \"./DescribeContentModelTool.js\";\nimport { QueryEntriesTool } from \"./QueryEntriesTool.js\";\nimport { CreateEntryTool } from \"./CreateEntryTool.js\";\nimport { UpdateEntryTool } from \"./UpdateEntryTool.js\";\nimport { PublishEntryTool } from \"./PublishEntryTool.js\";\nimport { UnpublishEntryTool } from \"./UnpublishEntryTool.js\";\nimport { DeleteEntryTool } from \"./DeleteEntryTool.js\";\n\n/**\n * CMS tools for AI callers. Registered as `AiSdkToolDefinition` implementations, so any caller that\n * builds a tool set from that abstraction picks them up without naming them.\n *\n * The model and query tools are read-only and run unattended. The entry tools write, so each pauses\n * for the user to approve the exact arguments. None of them deletes permanently: `deleteEntry` moves\n * the entry to the trash bin.\n */\nexport const CmsAiToolsFeature = createFeature({\n name: \"HeadlessCms/AiTools\",\n register(container) {\n container.register(ListContentModelsTool);\n container.register(DescribeContentModelTool);\n container.register(QueryEntriesTool);\n container.register(CreateEntryTool);\n container.register(UpdateEntryTool);\n container.register(PublishEntryTool);\n container.register(UnpublishEntryTool);\n container.register(DeleteEntryTool);\n }\n});\n"],"names":["CmsAiToolsFeature","createFeature","container","ListContentModelsTool","DescribeContentModelTool","QueryEntriesTool","CreateEntryTool","UpdateEntryTool","PublishEntryTool","UnpublishEntryTool","DeleteEntryTool"],"mappings":";;;;;;;;;AAkBO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;IACvB;AACJ"}
@@ -2,3 +2,8 @@ export { CmsAiToolsFeature } from "./feature.js";
2
2
  export { ListContentModelsTool } from "./ListContentModelsTool.js";
3
3
  export { DescribeContentModelTool } from "./DescribeContentModelTool.js";
4
4
  export { QueryEntriesTool } from "./QueryEntriesTool.js";
5
+ export { CreateEntryTool } from "./CreateEntryTool.js";
6
+ export { UpdateEntryTool } from "./UpdateEntryTool.js";
7
+ export { PublishEntryTool } from "./PublishEntryTool.js";
8
+ export { UnpublishEntryTool } from "./UnpublishEntryTool.js";
9
+ export { DeleteEntryTool } from "./DeleteEntryTool.js";
@@ -2,3 +2,8 @@ export { CmsAiToolsFeature } from "./feature.js";
2
2
  export { ListContentModelsTool } from "./ListContentModelsTool.js";
3
3
  export { DescribeContentModelTool } from "./DescribeContentModelTool.js";
4
4
  export { QueryEntriesTool } from "./QueryEntriesTool.js";
5
+ export { CreateEntryTool } from "./CreateEntryTool.js";
6
+ export { UpdateEntryTool } from "./UpdateEntryTool.js";
7
+ export { PublishEntryTool } from "./PublishEntryTool.js";
8
+ export { UnpublishEntryTool } from "./UnpublishEntryTool.js";
9
+ export { DeleteEntryTool } from "./DeleteEntryTool.js";
@@ -0,0 +1,18 @@
1
+ import type { GetModelUseCase } from "../../features/contentModel/GetModel/index.js";
2
+ import type { GetLatestRevisionByEntryIdUseCase } from "../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
3
+ import type { CmsEntry, CmsModel } from "../../types/index.js";
4
+ /**
5
+ * Models Webiny itself owns. Two separate markers, both needed:
6
+ * - `group: "hidden"` — the convention system models use (languages, tenants, background-task
7
+ * settings). The admin UI filters the same way, see app-headless-cms useCmsData.
8
+ * - `isPrivate` — models another app owns and manages through its own UI (e.g. Website Builder).
9
+ */
10
+ export declare const isSystemModel: (model: CmsModel) => boolean;
11
+ /**
12
+ * Loads a model the entry write tools may change. System models are refused: their entries back
13
+ * Webiny itself or another app, which keeps rules the CMS does not know about. Singleton models are
14
+ * refused too: they hold one entry, edited on its own screen, not created or deleted.
15
+ */
16
+ export declare const getWritableModel: (getModel: GetModelUseCase.Interface, modelId: string) => Promise<CmsModel>;
17
+ /** Loads an entry's latest revision, with the error the entry write tools give for a wrong id. */
18
+ export declare const getLatestEntryRevision: (getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface, model: CmsModel, entryId: string) => Promise<CmsEntry>;
@@ -0,0 +1,21 @@
1
+ import { CMS_MODEL_SINGLETON_TAG } from "../../constants.js";
2
+ const HIDDEN_MODEL_GROUP = "hidden";
3
+ const isSystemModel = (model)=>Boolean(model.isPrivate) || model.group === HIDDEN_MODEL_GROUP;
4
+ const getWritableModel = async (getModel, modelId)=>{
5
+ const result = await getModel.execute(modelId);
6
+ if (result.isFail()) throw new Error(`Unknown model "${modelId}": ${result.error.message}. Call listContentModels for valid model IDs.`);
7
+ const model = result.value;
8
+ if (isSystemModel(model)) throw new Error(`"${modelId}" is a system model; its entries cannot be changed here.`);
9
+ if (model.tags?.includes(CMS_MODEL_SINGLETON_TAG)) throw new Error(`"${modelId}" is a single-entry model; edit it on its own screen in the admin.`);
10
+ return model;
11
+ };
12
+ const getLatestEntryRevision = async (getLatestRevision, model, entryId)=>{
13
+ const result = await getLatestRevision.execute(model, {
14
+ id: entryId
15
+ });
16
+ if (result.isFail()) throw new Error(`Entry "${entryId}" not found in "${model.modelId}": ${result.error.message}. Call queryEntries for valid entry IDs.`);
17
+ return result.value;
18
+ };
19
+ export { getLatestEntryRevision, getWritableModel, isSystemModel };
20
+
21
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/models.js","sources":["../../../src/features/ai/models.ts"],"sourcesContent":["import { CMS_MODEL_SINGLETON_TAG } from \"~/constants.js\";\nimport type { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport type { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport type { CmsEntry, CmsModel } from \"~/types/index.js\";\n\nconst HIDDEN_MODEL_GROUP = \"hidden\";\n\n/**\n * Models Webiny itself owns. Two separate markers, both needed:\n * - `group: \"hidden\"` — the convention system models use (languages, tenants, background-task\n * settings). The admin UI filters the same way, see app-headless-cms useCmsData.\n * - `isPrivate` — models another app owns and manages through its own UI (e.g. Website Builder).\n */\nexport const isSystemModel = (model: CmsModel): boolean =>\n Boolean(model.isPrivate) || model.group === HIDDEN_MODEL_GROUP;\n\n/**\n * Loads a model the entry write tools may change. System models are refused: their entries back\n * Webiny itself or another app, which keeps rules the CMS does not know about. Singleton models are\n * refused too: they hold one entry, edited on its own screen, not created or deleted.\n */\nexport const getWritableModel = async (\n getModel: GetModelUseCase.Interface,\n modelId: string\n): Promise<CmsModel> => {\n const result = await getModel.execute(modelId);\n\n if (result.isFail()) {\n throw new Error(\n `Unknown model \"${modelId}\": ${result.error.message}. Call listContentModels for valid model IDs.`\n );\n }\n\n const model = result.value;\n\n if (isSystemModel(model)) {\n throw new Error(`\"${modelId}\" is a system model; its entries cannot be changed here.`);\n }\n\n if (model.tags?.includes(CMS_MODEL_SINGLETON_TAG)) {\n throw new Error(\n `\"${modelId}\" is a single-entry model; edit it on its own screen in the admin.`\n );\n }\n\n return model;\n};\n\n/** Loads an entry's latest revision, with the error the entry write tools give for a wrong id. */\nexport const getLatestEntryRevision = async (\n getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface,\n model: CmsModel,\n entryId: string\n): Promise<CmsEntry> => {\n const result = await getLatestRevision.execute(model, { id: entryId });\n\n if (result.isFail()) {\n throw new Error(\n `Entry \"${entryId}\" not found in \"${model.modelId}\": ${result.error.message}. Call queryEntries for valid entry IDs.`\n );\n }\n\n return result.value;\n};\n"],"names":["HIDDEN_MODEL_GROUP","isSystemModel","model","Boolean","getWritableModel","getModel","modelId","result","Error","CMS_MODEL_SINGLETON_TAG","getLatestEntryRevision","getLatestRevision","entryId"],"mappings":";AAKA,MAAMA,qBAAqB;AAQpB,MAAMC,gBAAgB,CAACC,QAC1BC,QAAQD,MAAM,SAAS,KAAKA,MAAM,KAAK,KAAKF;AAOzC,MAAMI,mBAAmB,OAC5BC,UACAC;IAEA,MAAMC,SAAS,MAAMF,SAAS,OAAO,CAACC;IAEtC,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MACN,CAAC,eAAe,EAAEF,QAAQ,GAAG,EAAEC,OAAO,KAAK,CAAC,OAAO,CAAC,6CAA6C,CAAC;IAI1G,MAAML,QAAQK,OAAO,KAAK;IAE1B,IAAIN,cAAcC,QACd,MAAM,IAAIM,MAAM,CAAC,CAAC,EAAEF,QAAQ,wDAAwD,CAAC;IAGzF,IAAIJ,MAAM,IAAI,EAAE,SAASO,0BACrB,MAAM,IAAID,MACN,CAAC,CAAC,EAAEF,QAAQ,kEAAkE,CAAC;IAIvF,OAAOJ;AACX;AAGO,MAAMQ,yBAAyB,OAClCC,mBACAT,OACAU;IAEA,MAAML,SAAS,MAAMI,kBAAkB,OAAO,CAACT,OAAO;QAAE,IAAIU;IAAQ;IAEpE,IAAIL,OAAO,MAAM,IACb,MAAM,IAAIC,MACN,CAAC,OAAO,EAAEI,QAAQ,gBAAgB,EAAEV,MAAM,OAAO,CAAC,GAAG,EAAEK,OAAO,KAAK,CAAC,OAAO,CAAC,wCAAwC,CAAC;IAI7H,OAAOA,OAAO,KAAK;AACvB"}
@@ -0,0 +1 @@
1
+ export { ENTRY_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1 @@
1
+ export { ENTRY_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The `type` of the record-changed message sent when an entry changes. The message's `id` is the
3
+ * `entryId` and its `scope` the model id. The admin's `ApplyEntryChangeToCache` filters on the same
4
+ * string.
5
+ *
6
+ * Sent explicitly (today by the assistant's entry tools), not from the entry lifecycle events the
7
+ * way team, role and user changes are announced. Entries are written in bulk (imports, bulk
8
+ * actions, scheduled publishing), and a message per write would mean a websocket send per entry and
9
+ * an admin read-back per message.
10
+ */
11
+ export declare const ENTRY_RECORD_TYPE = "cms.entry";
@@ -0,0 +1,4 @@
1
+ const ENTRY_RECORD_TYPE = "cms.entry";
2
+ export { ENTRY_RECORD_TYPE };
3
+
4
+ //# sourceMappingURL=recordType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/contentEntry/NotifyEntryChange/recordType.js","sources":["../../../../src/features/contentEntry/NotifyEntryChange/recordType.ts"],"sourcesContent":["/**\n * The `type` of the record-changed message sent when an entry changes. The message's `id` is the\n * `entryId` and its `scope` the model id. The admin's `ApplyEntryChangeToCache` filters on the same\n * string.\n *\n * Sent explicitly (today by the assistant's entry tools), not from the entry lifecycle events the\n * way team, role and user changes are announced. Entries are written in bulk (imports, bulk\n * actions, scheduled publishing), and a message per write would mean a websocket send per entry and\n * an admin read-back per message.\n */\nexport const ENTRY_RECORD_TYPE = \"cms.entry\";\n"],"names":["ENTRY_RECORD_TYPE"],"mappings":"AAUO,MAAMA,oBAAoB"}
@@ -41,7 +41,7 @@ class GetGroupRepositoryImpl {
41
41
  }));
42
42
  const filteredCacheKey = createCacheKey({
43
43
  dbCacheKey: dbCacheKey.get(),
44
- identity: this.identityContext.isAuthorizationEnabled() ? this.identityContext.getIdentity()?.id : void 0
44
+ identity: this.identityContext.isAuthorizationEnabled() ? this.identityContext.getIdentity().id : void 0
45
45
  });
46
46
  const filteredDatabaseGroups = await this.groupCache.getOrSet(filteredCacheKey, async ()=>filterAsync(databaseGroups, async (group)=>{
47
47
  if (!group) return false;
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModelGroup/GetGroup/GetGroupRepository.js","sources":["../../../../src/features/contentModelGroup/GetGroup/GetGroupRepository.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { GetGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupNotFoundError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { ListGroupsStorageOperation } from \"~/features/shared/storageOperations/group/ListGroupsStorageOperation.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { filterAsync } from \"~/utils/filterAsync.js\";\nimport { createCacheKey } from \"~/utils/index.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * GetGroupRepository - Fetches a single group by ID.\n *\n * Responsibilities:\n * - Create cache keys based on tenant + identity\n * - Provide data loader functions to GroupCache\n * - Fetch from plugin groups + database groups\n * - Apply access control filtering\n * - Return the group or NotFoundError\n */\nclass GetGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private listGroups: ListGroupsStorageOperation.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private cmsContext: CmsContext.Interface\n ) {}\n\n async execute(groupId: string): Promise<Result<CmsGroup, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Fetch all groups (plugin + database) with access control filtering\n const groups = await this.fetchAllGroups(tenant.id);\n\n const group = groups.find(g => g.id === groupId);\n\n if (!group) {\n return Result.fail(new GroupNotFoundError(groupId));\n }\n\n return Result.ok(group);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n\n private async fetchAllGroups(tenant: string): Promise<CmsGroup[]> {\n // 1. Fetch plugin groups (with caching and access control)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n\n // 2. Fetch database groups (with caching)\n const dbCacheKey = createCacheKey({ tenant });\n const databaseGroups = await this.groupCache.getOrSet(dbCacheKey, async () => {\n return await this.listGroups.execute({\n where: { tenant }\n });\n });\n\n // 3. Apply access control to database groups (with caching)\n const filteredCacheKey = createCacheKey({\n dbCacheKey: dbCacheKey.get(),\n identity: this.identityContext.isAuthorizationEnabled()\n ? this.identityContext.getIdentity()?.id\n : undefined\n });\n\n const filteredDatabaseGroups = await this.groupCache.getOrSet(\n filteredCacheKey,\n async () => {\n return filterAsync(databaseGroups, async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n return this.accessControl.canAccessGroup({ group });\n });\n }\n );\n\n // 4. Merge plugin + database groups\n return [...pluginGroups, ...filteredDatabaseGroups];\n }\n}\n\nexport const GetGroupRepository = RepositoryAbstraction.createImplementation({\n implementation: GetGroupRepositoryImpl,\n dependencies: [\n GroupCache,\n PluginGroupsProvider,\n ListGroupsStorageOperation,\n AccessControl,\n TenantContext,\n IdentityContext,\n CmsContext\n ]\n});\n"],"names":["GetGroupRepositoryImpl","groupCache","pluginGroupsProvider","listGroups","accessControl","tenantContext","identityContext","cmsContext","groupId","tenant","groups","group","g","Result","GroupNotFoundError","error","GroupPersistenceError","pluginGroups","dbCacheKey","createCacheKey","databaseGroups","filteredCacheKey","undefined","filteredDatabaseGroups","filterAsync","GetGroupRepository","RepositoryAbstraction","GroupCache","PluginGroupsProvider","ListGroupsStorageOperation","AccessControl","TenantContext","IdentityContext","CmsContext"],"mappings":";;;;;;;;;;AAyBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,UAAgD,EAChDC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,EAC1CC,UAAgC,CAC1C;aAPUN,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,OAAe,EAA0D;QACnF,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,MAAMC,SAAS,MAAM,IAAI,CAAC,cAAc,CAACD,OAAO,EAAE;YAElD,MAAME,QAAQD,OAAO,IAAI,CAACE,CAAAA,IAAKA,EAAE,EAAE,KAAKJ;YAExC,IAAI,CAACG,OACD,OAAOE,OAAO,IAAI,CAAC,IAAIC,mBAAmBN;YAG9C,OAAOK,OAAO,EAAE,CAACF;QACrB,EAAE,OAAOI,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD;QACjD;IACJ;IAEA,MAAc,eAAeN,MAAc,EAAuB;QAE9D,MAAMQ,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;QAG9D,MAAMC,aAAaC,eAAe;YAAEV;QAAO;QAC3C,MAAMW,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAACF,YAAY,UACvD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBACjC,OAAO;oBAAET;gBAAO;YACpB;QAIJ,MAAMY,mBAAmBF,eAAe;YACpC,YAAYD,WAAW,GAAG;YAC1B,UAAU,IAAI,CAAC,eAAe,CAAC,sBAAsB,KAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,KACpCI;QACV;QAEA,MAAMC,yBAAyB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CACzDF,kBACA,UACWG,YAAYJ,gBAAgB,OAAOT;gBACtC,IAAI,CAACA,OACD,OAAO;gBAEX,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAAEA;gBAAM;YACrD;QAKR,OAAO;eAAIM;eAAiBM;SAAuB;IACvD;AACJ;AAEO,MAAME,wCAAqBC,mBAAAA,oBAA0C,CAAC;IACzE,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/contentModelGroup/GetGroup/GetGroupRepository.js","sources":["../../../../src/features/contentModelGroup/GetGroup/GetGroupRepository.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { GetGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupNotFoundError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { ListGroupsStorageOperation } from \"~/features/shared/storageOperations/group/ListGroupsStorageOperation.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { filterAsync } from \"~/utils/filterAsync.js\";\nimport { createCacheKey } from \"~/utils/index.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * GetGroupRepository - Fetches a single group by ID.\n *\n * Responsibilities:\n * - Create cache keys based on tenant + identity\n * - Provide data loader functions to GroupCache\n * - Fetch from plugin groups + database groups\n * - Apply access control filtering\n * - Return the group or NotFoundError\n */\nclass GetGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private listGroups: ListGroupsStorageOperation.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private cmsContext: CmsContext.Interface\n ) {}\n\n async execute(groupId: string): Promise<Result<CmsGroup, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Fetch all groups (plugin + database) with access control filtering\n const groups = await this.fetchAllGroups(tenant.id);\n\n const group = groups.find(g => g.id === groupId);\n\n if (!group) {\n return Result.fail(new GroupNotFoundError(groupId));\n }\n\n return Result.ok(group);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n\n private async fetchAllGroups(tenant: string): Promise<CmsGroup[]> {\n // 1. Fetch plugin groups (with caching and access control)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n\n // 2. Fetch database groups (with caching)\n const dbCacheKey = createCacheKey({ tenant });\n const databaseGroups = await this.groupCache.getOrSet(dbCacheKey, async () => {\n return await this.listGroups.execute({\n where: { tenant }\n });\n });\n\n // 3. Apply access control to database groups (with caching)\n const filteredCacheKey = createCacheKey({\n dbCacheKey: dbCacheKey.get(),\n identity: this.identityContext.isAuthorizationEnabled()\n ? this.identityContext.getIdentity().id\n : undefined\n });\n\n const filteredDatabaseGroups = await this.groupCache.getOrSet(\n filteredCacheKey,\n async () => {\n return filterAsync(databaseGroups, async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n return this.accessControl.canAccessGroup({ group });\n });\n }\n );\n\n // 4. Merge plugin + database groups\n return [...pluginGroups, ...filteredDatabaseGroups];\n }\n}\n\nexport const GetGroupRepository = RepositoryAbstraction.createImplementation({\n implementation: GetGroupRepositoryImpl,\n dependencies: [\n GroupCache,\n PluginGroupsProvider,\n ListGroupsStorageOperation,\n AccessControl,\n TenantContext,\n IdentityContext,\n CmsContext\n ]\n});\n"],"names":["GetGroupRepositoryImpl","groupCache","pluginGroupsProvider","listGroups","accessControl","tenantContext","identityContext","cmsContext","groupId","tenant","groups","group","g","Result","GroupNotFoundError","error","GroupPersistenceError","pluginGroups","dbCacheKey","createCacheKey","databaseGroups","filteredCacheKey","undefined","filteredDatabaseGroups","filterAsync","GetGroupRepository","RepositoryAbstraction","GroupCache","PluginGroupsProvider","ListGroupsStorageOperation","AccessControl","TenantContext","IdentityContext","CmsContext"],"mappings":";;;;;;;;;;AAyBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,UAAgD,EAChDC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,EAC1CC,UAAgC,CAC1C;aAPUN,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,OAAe,EAA0D;QACnF,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,MAAMC,SAAS,MAAM,IAAI,CAAC,cAAc,CAACD,OAAO,EAAE;YAElD,MAAME,QAAQD,OAAO,IAAI,CAACE,CAAAA,IAAKA,EAAE,EAAE,KAAKJ;YAExC,IAAI,CAACG,OACD,OAAOE,OAAO,IAAI,CAAC,IAAIC,mBAAmBN;YAG9C,OAAOK,OAAO,EAAE,CAACF;QACrB,EAAE,OAAOI,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD;QACjD;IACJ;IAEA,MAAc,eAAeN,MAAc,EAAuB;QAE9D,MAAMQ,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;QAG9D,MAAMC,aAAaC,eAAe;YAAEV;QAAO;QAC3C,MAAMW,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAACF,YAAY,UACvD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBACjC,OAAO;oBAAET;gBAAO;YACpB;QAIJ,MAAMY,mBAAmBF,eAAe;YACpC,YAAYD,WAAW,GAAG;YAC1B,UAAU,IAAI,CAAC,eAAe,CAAC,sBAAsB,KAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,GACrCI;QACV;QAEA,MAAMC,yBAAyB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CACzDF,kBACA,UACWG,YAAYJ,gBAAgB,OAAOT;gBACtC,IAAI,CAACA,OACD,OAAO;gBAEX,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAAEA;gBAAM;YACrD;QAKR,OAAO;eAAIM;eAAiBM;SAAuB;IACvD;AACJ;AAEO,MAAME,wCAAqBC,mBAAAA,oBAA0C,CAAC;IACzE,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -39,7 +39,7 @@ class ListGroupsRepositoryImpl {
39
39
  }));
40
40
  const filteredCacheKey = createCacheKey({
41
41
  dbCacheKey: dbCacheKey.get(),
42
- identity: this.identityContext.isAuthorizationEnabled() ? this.identityContext.getIdentity()?.id : void 0
42
+ identity: this.identityContext.isAuthorizationEnabled() ? this.identityContext.getIdentity().id : void 0
43
43
  });
44
44
  const filteredDatabaseGroups = await this.groupCache.getOrSet(filteredCacheKey, async ()=>filterAsync(databaseGroups, async (group)=>{
45
45
  if (!group) return false;
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModelGroup/ListGroups/ListGroupsRepository.js","sources":["../../../../src/features/contentModelGroup/ListGroups/ListGroupsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListGroupsRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { ListGroupsStorageOperation } from \"~/features/shared/storageOperations/group/ListGroupsStorageOperation.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { filterAsync } from \"~/utils/filterAsync.js\";\nimport { createCacheKey } from \"~/utils/index.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * ListGroupsRepository - Fetches all groups (plugin + database).\n *\n * Responsibilities:\n * - Create cache keys based on tenant + identity\n * - Provide data loader functions to GroupCache\n * - Fetch from plugin groups + database groups\n * - Apply access control filtering\n * - Return all accessible groups\n */\nclass ListGroupsRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private listGroups: ListGroupsStorageOperation.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private cmsContext: CmsContext.Interface\n ) {}\n\n async execute(): Promise<Result<CmsGroup[], RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Fetch all groups (plugin + database) with access control filtering\n const groups = await this.fetchAllGroups(tenant.id);\n\n return Result.ok(groups);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n\n private async fetchAllGroups(tenant: string): Promise<CmsGroup[]> {\n // 1. Fetch plugin groups (with caching and access control)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n\n // 2. Fetch database groups (with caching)\n const dbCacheKey = createCacheKey({ tenant });\n const databaseGroups = await this.groupCache.getOrSet(dbCacheKey, async () => {\n return await this.listGroups.execute({\n where: { tenant }\n });\n });\n\n // 3. Apply access control to database groups (with caching)\n const filteredCacheKey = createCacheKey({\n dbCacheKey: dbCacheKey.get(),\n identity: this.identityContext.isAuthorizationEnabled()\n ? this.identityContext.getIdentity()?.id\n : undefined\n });\n\n const filteredDatabaseGroups = await this.groupCache.getOrSet(\n filteredCacheKey,\n async () => {\n return filterAsync(databaseGroups, async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n return this.accessControl.canAccessGroup({ group });\n });\n }\n );\n\n // 4. Merge groups\n return [...filteredDatabaseGroups, ...pluginGroups];\n }\n}\n\nexport const ListGroupsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListGroupsRepositoryImpl,\n dependencies: [\n GroupCache,\n PluginGroupsProvider,\n ListGroupsStorageOperation,\n AccessControl,\n TenantContext,\n IdentityContext,\n CmsContext\n ]\n});\n"],"names":["ListGroupsRepositoryImpl","groupCache","pluginGroupsProvider","listGroups","accessControl","tenantContext","identityContext","cmsContext","tenant","groups","Result","error","GroupPersistenceError","pluginGroups","dbCacheKey","createCacheKey","databaseGroups","filteredCacheKey","undefined","filteredDatabaseGroups","filterAsync","group","ListGroupsRepository","RepositoryAbstraction","GroupCache","PluginGroupsProvider","ListGroupsStorageOperation","AccessControl","TenantContext","IdentityContext","CmsContext"],"mappings":";;;;;;;;;;AAwBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,UAAgD,EAChDC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,EAC1CC,UAAgC,CAC1C;aAPUN,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,UAAoE;QACtE,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,MAAMC,SAAS,MAAM,IAAI,CAAC,cAAc,CAACD,OAAO,EAAE;YAElD,OAAOE,OAAO,EAAE,CAACD;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAOD,OAAO,IAAI,CAAC,IAAIE,sBAAsBD;QACjD;IACJ;IAEA,MAAc,eAAeH,MAAc,EAAuB;QAE9D,MAAMK,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;QAG9D,MAAMC,aAAaC,eAAe;YAAEP;QAAO;QAC3C,MAAMQ,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAACF,YAAY,UACvD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBACjC,OAAO;oBAAEN;gBAAO;YACpB;QAIJ,MAAMS,mBAAmBF,eAAe;YACpC,YAAYD,WAAW,GAAG;YAC1B,UAAU,IAAI,CAAC,eAAe,CAAC,sBAAsB,KAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,KACpCI;QACV;QAEA,MAAMC,yBAAyB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CACzDF,kBACA,UACWG,YAAYJ,gBAAgB,OAAOK;gBACtC,IAAI,CAACA,OACD,OAAO;gBAEX,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAAEA;gBAAM;YACrD;QAKR,OAAO;eAAIF;eAA2BN;SAAa;IACvD;AACJ;AAEO,MAAMS,4CAAuBC,qBAAAA,oBAA0C,CAAC;IAC3E,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/contentModelGroup/ListGroups/ListGroupsRepository.js","sources":["../../../../src/features/contentModelGroup/ListGroups/ListGroupsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListGroupsRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { ListGroupsStorageOperation } from \"~/features/shared/storageOperations/group/ListGroupsStorageOperation.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { filterAsync } from \"~/utils/filterAsync.js\";\nimport { createCacheKey } from \"~/utils/index.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * ListGroupsRepository - Fetches all groups (plugin + database).\n *\n * Responsibilities:\n * - Create cache keys based on tenant + identity\n * - Provide data loader functions to GroupCache\n * - Fetch from plugin groups + database groups\n * - Apply access control filtering\n * - Return all accessible groups\n */\nclass ListGroupsRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private listGroups: ListGroupsStorageOperation.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private cmsContext: CmsContext.Interface\n ) {}\n\n async execute(): Promise<Result<CmsGroup[], RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Fetch all groups (plugin + database) with access control filtering\n const groups = await this.fetchAllGroups(tenant.id);\n\n return Result.ok(groups);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n\n private async fetchAllGroups(tenant: string): Promise<CmsGroup[]> {\n // 1. Fetch plugin groups (with caching and access control)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n\n // 2. Fetch database groups (with caching)\n const dbCacheKey = createCacheKey({ tenant });\n const databaseGroups = await this.groupCache.getOrSet(dbCacheKey, async () => {\n return await this.listGroups.execute({\n where: { tenant }\n });\n });\n\n // 3. Apply access control to database groups (with caching)\n const filteredCacheKey = createCacheKey({\n dbCacheKey: dbCacheKey.get(),\n identity: this.identityContext.isAuthorizationEnabled()\n ? this.identityContext.getIdentity().id\n : undefined\n });\n\n const filteredDatabaseGroups = await this.groupCache.getOrSet(\n filteredCacheKey,\n async () => {\n return filterAsync(databaseGroups, async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n return this.accessControl.canAccessGroup({ group });\n });\n }\n );\n\n // 4. Merge groups\n return [...filteredDatabaseGroups, ...pluginGroups];\n }\n}\n\nexport const ListGroupsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListGroupsRepositoryImpl,\n dependencies: [\n GroupCache,\n PluginGroupsProvider,\n ListGroupsStorageOperation,\n AccessControl,\n TenantContext,\n IdentityContext,\n CmsContext\n ]\n});\n"],"names":["ListGroupsRepositoryImpl","groupCache","pluginGroupsProvider","listGroups","accessControl","tenantContext","identityContext","cmsContext","tenant","groups","Result","error","GroupPersistenceError","pluginGroups","dbCacheKey","createCacheKey","databaseGroups","filteredCacheKey","undefined","filteredDatabaseGroups","filterAsync","group","ListGroupsRepository","RepositoryAbstraction","GroupCache","PluginGroupsProvider","ListGroupsStorageOperation","AccessControl","TenantContext","IdentityContext","CmsContext"],"mappings":";;;;;;;;;;AAwBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,UAAgD,EAChDC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,EAC1CC,UAAgC,CAC1C;aAPUN,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,UAAoE;QACtE,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,MAAMC,SAAS,MAAM,IAAI,CAAC,cAAc,CAACD,OAAO,EAAE;YAElD,OAAOE,OAAO,EAAE,CAACD;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAOD,OAAO,IAAI,CAAC,IAAIE,sBAAsBD;QACjD;IACJ;IAEA,MAAc,eAAeH,MAAc,EAAuB;QAE9D,MAAMK,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;QAG9D,MAAMC,aAAaC,eAAe;YAAEP;QAAO;QAC3C,MAAMQ,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAACF,YAAY,UACvD,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBACjC,OAAO;oBAAEN;gBAAO;YACpB;QAIJ,MAAMS,mBAAmBF,eAAe;YACpC,YAAYD,WAAW,GAAG;YAC1B,UAAU,IAAI,CAAC,eAAe,CAAC,sBAAsB,KAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,GACrCI;QACV;QAEA,MAAMC,yBAAyB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CACzDF,kBACA,UACWG,YAAYJ,gBAAgB,OAAOK;gBACtC,IAAI,CAACA,OACD,OAAO;gBAEX,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAAEA;gBAAM;YACrD;QAKR,OAAO;eAAIF;eAA2BN;SAAa;IACvD;AACJ;AAEO,MAAMS,4CAAuBC,qBAAAA,oBAA0C,CAAC;IAC3E,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -18,7 +18,7 @@ class PluginGroupsProviderImpl {
18
18
  const pluginGroups = this.pluginGroups;
19
19
  const cacheKey = createCacheKey({
20
20
  tenant: tenant.id,
21
- identity: this.identityContext.isAuthorizationEnabled() ? this.identityContext.getIdentity()?.id : void 0,
21
+ identity: this.identityContext.isAuthorizationEnabled() ? this.identityContext.getIdentity().id : void 0,
22
22
  groups: pluginGroups.map(({ contentModelGroup: group })=>`${group.id}#${group.slug}#${group.savedOn || "unknown"}`).join("/"),
23
23
  codeGroups: this.groupFactories.length
24
24
  });
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModelGroup/shared/PluginGroupsProvider.js","sources":["../../../../src/features/contentModelGroup/shared/PluginGroupsProvider.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {\n CmsGroupPluginInstance,\n ModelGroupFactory,\n PluginGroupsProvider as ProviderAbstraction\n} from \"./abstractions.js\";\nimport type { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin.js\";\nimport { filterAsync } from \"~/utils/filterAsync.js\";\nimport { createCacheKey } from \"~/utils/index.js\";\nimport { createMemoryCache } from \"~/utils/index.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * PluginGroupsProvider implementation\n *\n * Fetches groups from CmsGroupPlugin instances.\n * Filters by tenant and applies access control.\n * Results are cached based on tenant + identity + plugin signatures.\n */\nclass PluginGroupsProviderImpl implements ProviderAbstraction.Interface {\n private cache = createMemoryCache<Promise<CmsGroup[]>>();\n\n public constructor(\n private tenantContext: TenantContext.Interface,\n private pluginGroups: CmsGroupPlugin[],\n private accessControl: AccessControl.Interface,\n private identityContext: IdentityContext.Interface,\n private groupFactories: ModelGroupFactory.Interface[]\n ) {}\n\n async getGroups(): Promise<CmsGroup[]> {\n const tenant = this.tenantContext.getTenant();\n const pluginGroups = this.pluginGroups;\n\n const cacheKey = createCacheKey({\n tenant: tenant.id,\n identity: this.identityContext.isAuthorizationEnabled()\n ? this.identityContext.getIdentity()?.id\n : undefined,\n groups: pluginGroups\n .map(({ contentModelGroup: group }) => {\n return `${group.id}#${group.slug}#${group.savedOn || \"unknown\"}`;\n })\n .join(\"/\"),\n codeGroups: this.groupFactories.length\n });\n\n return this.cache.getOrSet(cacheKey, async (): Promise<CmsGroup[]> => {\n // TODO: once the legacy code plugins are removed, clean this up.\n // Currently, this code makes the new group compatible with the legacy one.\n const codeGroups: CmsGroup[] = await Promise.all(\n this.groupFactories.map(factory => factory.execute())\n ).then(result => {\n return result.flat().map<CmsGroup>(group => ({\n ...group,\n id: group.slug,\n tenant: tenant.id,\n description: \"\"\n }));\n });\n\n const groups = pluginGroups\n // Filter by tenant if specified in plugin\n // If not specified, plugin group is available for all tenants\n .filter(plugin => {\n const { tenant: t } = plugin.contentModelGroup;\n if (t && t !== tenant.id) {\n return false;\n }\n return true;\n })\n .map(plugin => {\n return {\n ...plugin.contentModelGroup,\n tenant: tenant.id\n };\n });\n\n // Apply access control filtering\n return filterAsync([...codeGroups, ...groups], async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n return this.accessControl.canAccessGroup({ group });\n });\n });\n }\n}\n\nexport const PluginGroupsProvider = ProviderAbstraction.createImplementation({\n implementation: PluginGroupsProviderImpl,\n dependencies: [\n TenantContext,\n [CmsGroupPluginInstance, { multiple: true }],\n AccessControl,\n IdentityContext,\n [ModelGroupFactory, { multiple: true }]\n ]\n});\n"],"names":["PluginGroupsProviderImpl","tenantContext","pluginGroups","accessControl","identityContext","groupFactories","createMemoryCache","tenant","cacheKey","createCacheKey","undefined","group","codeGroups","Promise","factory","result","groups","plugin","t","filterAsync","PluginGroupsProvider","ProviderAbstraction","TenantContext","CmsGroupPluginInstance","AccessControl","IdentityContext","ModelGroupFactory"],"mappings":";;;;;;AAqBA,MAAMA;IAGF,YACYC,aAAsC,EACtCC,YAA8B,EAC9BC,aAAsC,EACtCC,eAA0C,EAC1CC,cAA6C,CACvD;aALUJ,aAAa,GAAbA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;aAPJ,KAAK,GAAGC;IAQb;IAEH,MAAM,YAAiC;QACnC,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAML,eAAe,IAAI,CAAC,YAAY;QAEtC,MAAMM,WAAWC,eAAe;YAC5B,QAAQF,OAAO,EAAE;YACjB,UAAU,IAAI,CAAC,eAAe,CAAC,sBAAsB,KAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,KACpCG;YACN,QAAQR,aACH,GAAG,CAAC,CAAC,EAAE,mBAAmBS,KAAK,EAAE,GACvB,GAAGA,MAAM,EAAE,CAAC,CAAC,EAAEA,MAAM,IAAI,CAAC,CAAC,EAAEA,MAAM,OAAO,IAAI,WAAW,EAEnE,IAAI,CAAC;YACV,YAAY,IAAI,CAAC,cAAc,CAAC,MAAM;QAC1C;QAEA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAACH,UAAU;YAGjC,MAAMI,aAAyB,MAAMC,QAAQ,GAAG,CAC5C,IAAI,CAAC,cAAc,CAAC,GAAG,CAACC,CAAAA,UAAWA,QAAQ,OAAO,KACpD,IAAI,CAACC,CAAAA,SACIA,OAAO,IAAI,GAAG,GAAG,CAAWJ,CAAAA,QAAU;wBACzC,GAAGA,KAAK;wBACR,IAAIA,MAAM,IAAI;wBACd,QAAQJ,OAAO,EAAE;wBACjB,aAAa;oBACjB;YAGJ,MAAMS,SAASd,aAGV,MAAM,CAACe,CAAAA;gBACJ,MAAM,EAAE,QAAQC,CAAC,EAAE,GAAGD,OAAO,iBAAiB;gBAC9C,IAAIC,KAAKA,MAAMX,OAAO,EAAE,EACpB,OAAO;gBAEX,OAAO;YACX,GACC,GAAG,CAACU,CAAAA,SACM;oBACH,GAAGA,OAAO,iBAAiB;oBAC3B,QAAQV,OAAO,EAAE;gBACrB;YAIR,OAAOY,YAAY;mBAAIP;mBAAeI;aAAO,EAAE,OAAOL;gBAClD,IAAI,CAACA,OACD,OAAO;gBAEX,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAAEA;gBAAM;YACrD;QACJ;IACJ;AACJ;AAEO,MAAMS,4CAAuBC,qBAAAA,oBAAwC,CAAC;IACzE,gBAAgBrB;IAChB,cAAc;QACVsB;QACA;YAACC;YAAwB;gBAAE,UAAU;YAAK;SAAE;QAC5CC;QACAC;QACA;YAACC;YAAmB;gBAAE,UAAU;YAAK;SAAE;KAC1C;AACL"}
1
+ {"version":3,"file":"features/contentModelGroup/shared/PluginGroupsProvider.js","sources":["../../../../src/features/contentModelGroup/shared/PluginGroupsProvider.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {\n CmsGroupPluginInstance,\n ModelGroupFactory,\n PluginGroupsProvider as ProviderAbstraction\n} from \"./abstractions.js\";\nimport type { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin.js\";\nimport { filterAsync } from \"~/utils/filterAsync.js\";\nimport { createCacheKey } from \"~/utils/index.js\";\nimport { createMemoryCache } from \"~/utils/index.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * PluginGroupsProvider implementation\n *\n * Fetches groups from CmsGroupPlugin instances.\n * Filters by tenant and applies access control.\n * Results are cached based on tenant + identity + plugin signatures.\n */\nclass PluginGroupsProviderImpl implements ProviderAbstraction.Interface {\n private cache = createMemoryCache<Promise<CmsGroup[]>>();\n\n public constructor(\n private tenantContext: TenantContext.Interface,\n private pluginGroups: CmsGroupPlugin[],\n private accessControl: AccessControl.Interface,\n private identityContext: IdentityContext.Interface,\n private groupFactories: ModelGroupFactory.Interface[]\n ) {}\n\n async getGroups(): Promise<CmsGroup[]> {\n const tenant = this.tenantContext.getTenant();\n const pluginGroups = this.pluginGroups;\n\n const cacheKey = createCacheKey({\n tenant: tenant.id,\n identity: this.identityContext.isAuthorizationEnabled()\n ? this.identityContext.getIdentity().id\n : undefined,\n groups: pluginGroups\n .map(({ contentModelGroup: group }) => {\n return `${group.id}#${group.slug}#${group.savedOn || \"unknown\"}`;\n })\n .join(\"/\"),\n codeGroups: this.groupFactories.length\n });\n\n return this.cache.getOrSet(cacheKey, async (): Promise<CmsGroup[]> => {\n // TODO: once the legacy code plugins are removed, clean this up.\n // Currently, this code makes the new group compatible with the legacy one.\n const codeGroups: CmsGroup[] = await Promise.all(\n this.groupFactories.map(factory => factory.execute())\n ).then(result => {\n return result.flat().map<CmsGroup>(group => ({\n ...group,\n id: group.slug,\n tenant: tenant.id,\n description: \"\"\n }));\n });\n\n const groups = pluginGroups\n // Filter by tenant if specified in plugin\n // If not specified, plugin group is available for all tenants\n .filter(plugin => {\n const { tenant: t } = plugin.contentModelGroup;\n if (t && t !== tenant.id) {\n return false;\n }\n return true;\n })\n .map(plugin => {\n return {\n ...plugin.contentModelGroup,\n tenant: tenant.id\n };\n });\n\n // Apply access control filtering\n return filterAsync([...codeGroups, ...groups], async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n return this.accessControl.canAccessGroup({ group });\n });\n });\n }\n}\n\nexport const PluginGroupsProvider = ProviderAbstraction.createImplementation({\n implementation: PluginGroupsProviderImpl,\n dependencies: [\n TenantContext,\n [CmsGroupPluginInstance, { multiple: true }],\n AccessControl,\n IdentityContext,\n [ModelGroupFactory, { multiple: true }]\n ]\n});\n"],"names":["PluginGroupsProviderImpl","tenantContext","pluginGroups","accessControl","identityContext","groupFactories","createMemoryCache","tenant","cacheKey","createCacheKey","undefined","group","codeGroups","Promise","factory","result","groups","plugin","t","filterAsync","PluginGroupsProvider","ProviderAbstraction","TenantContext","CmsGroupPluginInstance","AccessControl","IdentityContext","ModelGroupFactory"],"mappings":";;;;;;AAqBA,MAAMA;IAGF,YACYC,aAAsC,EACtCC,YAA8B,EAC9BC,aAAsC,EACtCC,eAA0C,EAC1CC,cAA6C,CACvD;aALUJ,aAAa,GAAbA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;aAPJ,KAAK,GAAGC;IAQb;IAEH,MAAM,YAAiC;QACnC,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAML,eAAe,IAAI,CAAC,YAAY;QAEtC,MAAMM,WAAWC,eAAe;YAC5B,QAAQF,OAAO,EAAE;YACjB,UAAU,IAAI,CAAC,eAAe,CAAC,sBAAsB,KAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,GACrCG;YACN,QAAQR,aACH,GAAG,CAAC,CAAC,EAAE,mBAAmBS,KAAK,EAAE,GACvB,GAAGA,MAAM,EAAE,CAAC,CAAC,EAAEA,MAAM,IAAI,CAAC,CAAC,EAAEA,MAAM,OAAO,IAAI,WAAW,EAEnE,IAAI,CAAC;YACV,YAAY,IAAI,CAAC,cAAc,CAAC,MAAM;QAC1C;QAEA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAACH,UAAU;YAGjC,MAAMI,aAAyB,MAAMC,QAAQ,GAAG,CAC5C,IAAI,CAAC,cAAc,CAAC,GAAG,CAACC,CAAAA,UAAWA,QAAQ,OAAO,KACpD,IAAI,CAACC,CAAAA,SACIA,OAAO,IAAI,GAAG,GAAG,CAAWJ,CAAAA,QAAU;wBACzC,GAAGA,KAAK;wBACR,IAAIA,MAAM,IAAI;wBACd,QAAQJ,OAAO,EAAE;wBACjB,aAAa;oBACjB;YAGJ,MAAMS,SAASd,aAGV,MAAM,CAACe,CAAAA;gBACJ,MAAM,EAAE,QAAQC,CAAC,EAAE,GAAGD,OAAO,iBAAiB;gBAC9C,IAAIC,KAAKA,MAAMX,OAAO,EAAE,EACpB,OAAO;gBAEX,OAAO;YACX,GACC,GAAG,CAACU,CAAAA,SACM;oBACH,GAAGA,OAAO,iBAAiB;oBAC3B,QAAQV,OAAO,EAAE;gBACrB;YAIR,OAAOY,YAAY;mBAAIP;mBAAeI;aAAO,EAAE,OAAOL;gBAClD,IAAI,CAACA,OACD,OAAO;gBAEX,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAAEA;gBAAM;YACrD;QACJ;IACJ;AACJ;AAEO,MAAMS,4CAAuBC,qBAAAA,oBAAwC,CAAC;IACzE,gBAAgBrB;IAChB,cAAc;QACVsB;QACA;YAACC;YAAwB;gBAAE,UAAU;YAAK;SAAE;QAC5CC;QACAC;QACA;YAACC;YAAmB;gBAAE,UAAU;YAAK;SAAE;KAC1C;AACL"}
@@ -13,13 +13,17 @@ class SyncStorageOnModelUpdateImpl {
13
13
  if (!this.sync || !this.taskService || model.isPlugin) return;
14
14
  try {
15
15
  if (!await this.sync.needsSync(model)) return;
16
- await this.taskService.trigger({
16
+ const result = await this.taskService.trigger({
17
17
  definition: MODEL_STORAGE_SYNC_TASK,
18
18
  name: `Sync storage of model "${model.modelId}"`,
19
19
  input: {
20
20
  modelId: model.modelId
21
21
  }
22
22
  });
23
+ if (result.isFail()) this.logger.error({
24
+ error: result.error,
25
+ modelId: model.modelId
26
+ }, "Could not start the storage sync of a changed model.");
23
27
  } catch (error) {
24
28
  this.logger.error({
25
29
  error,
@@ -1 +1 @@
1
- {"version":3,"file":"features/modelStorageSync/SyncStorageOnModelUpdate.js","sources":["../../../src/features/modelStorageSync/SyncStorageOnModelUpdate.ts"],"sourcesContent":["import { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { ModelAfterUpdateEventHandler } from \"~/features/contentModel/UpdateModel/index.js\";\nimport {\n MODEL_STORAGE_SYNC_TASK,\n ModelStorageSync,\n type IModelStorageSyncTaskInput\n} from \"./abstractions.js\";\n\n/**\n * After a model edited in the admin UI is saved, starts the background sync if its storage has work\n * to do. Code models are skipped: there is no event for a changed code definition, so their sync is\n * triggered after a deploy (the background tasks `triggerTask` mutation, or `TaskService`).\n *\n * Never fails the update: the model is already stored, and pending work only makes some queries\n * slower until a sync runs.\n */\nclass SyncStorageOnModelUpdateImpl implements ModelAfterUpdateEventHandler.Interface {\n public constructor(\n private readonly logger: Logger.Interface,\n private readonly sync?: ModelStorageSync.Interface,\n private readonly taskService?: TaskService.Interface\n ) {}\n\n public async handle(event: ModelAfterUpdateEventHandler.Event): Promise<void> {\n const { model } = event.payload;\n if (!this.sync || !this.taskService || model.isPlugin) {\n return;\n }\n try {\n if (!(await this.sync.needsSync(model))) {\n return;\n }\n await this.taskService.trigger<IModelStorageSyncTaskInput>({\n definition: MODEL_STORAGE_SYNC_TASK,\n name: `Sync storage of model \"${model.modelId}\"`,\n input: { modelId: model.modelId }\n });\n } catch (error) {\n this.logger.error(\n { error, modelId: model.modelId },\n \"Could not start the storage sync of a changed model.\"\n );\n }\n }\n}\n\nexport const SyncStorageOnModelUpdate = ModelAfterUpdateEventHandler.createImplementation({\n implementation: SyncStorageOnModelUpdateImpl,\n dependencies: [\n Logger,\n [ModelStorageSync, { optional: true }],\n [TaskService, { optional: true }]\n ]\n});\n"],"names":["SyncStorageOnModelUpdateImpl","logger","sync","taskService","event","model","MODEL_STORAGE_SYNC_TASK","error","SyncStorageOnModelUpdate","ModelAfterUpdateEventHandler","Logger","ModelStorageSync","TaskService"],"mappings":";;;;AAiBA,MAAMA;IACF,YACqBC,MAAwB,EACxBC,IAAiC,EACjCC,WAAmC,CACtD;aAHmBF,MAAM,GAANA;aACAC,IAAI,GAAJA;aACAC,WAAW,GAAXA;IAClB;IAEH,MAAa,OAAOC,KAAyC,EAAiB;QAC1E,MAAM,EAAEC,KAAK,EAAE,GAAGD,MAAM,OAAO;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,IAAIC,MAAM,QAAQ,EACjD;QAEJ,IAAI;YACA,IAAI,CAAE,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAACA,QAC5B;YAEJ,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAA6B;gBACvD,YAAYC;gBACZ,MAAM,CAAC,uBAAuB,EAAED,MAAM,OAAO,CAAC,CAAC,CAAC;gBAChD,OAAO;oBAAE,SAASA,MAAM,OAAO;gBAAC;YACpC;QACJ,EAAE,OAAOE,OAAO;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;gBAAEA;gBAAO,SAASF,MAAM,OAAO;YAAC,GAChC;QAER;IACJ;AACJ;AAEO,MAAMG,2BAA2BC,6BAA6B,oBAAoB,CAAC;IACtF,gBAAgBT;IAChB,cAAc;QACVU;QACA;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;QACtC;YAACC;YAAa;gBAAE,UAAU;YAAK;SAAE;KACpC;AACL"}
1
+ {"version":3,"file":"features/modelStorageSync/SyncStorageOnModelUpdate.js","sources":["../../../src/features/modelStorageSync/SyncStorageOnModelUpdate.ts"],"sourcesContent":["import { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { ModelAfterUpdateEventHandler } from \"~/features/contentModel/UpdateModel/index.js\";\nimport {\n MODEL_STORAGE_SYNC_TASK,\n ModelStorageSync,\n type IModelStorageSyncTaskInput\n} from \"./abstractions.js\";\n\n/**\n * After a model edited in the admin UI is saved, starts the background sync if its storage has work\n * to do. Code models are skipped: there is no event for a changed code definition, so their sync is\n * triggered after a deploy (the background tasks `triggerTask` mutation, or `TaskService`).\n *\n * Never fails the update: the model is already stored, and pending work only makes some queries\n * slower until a sync runs.\n */\nclass SyncStorageOnModelUpdateImpl implements ModelAfterUpdateEventHandler.Interface {\n public constructor(\n private readonly logger: Logger.Interface,\n private readonly sync?: ModelStorageSync.Interface,\n private readonly taskService?: TaskService.Interface\n ) {}\n\n public async handle(event: ModelAfterUpdateEventHandler.Event): Promise<void> {\n const { model } = event.payload;\n if (!this.sync || !this.taskService || model.isPlugin) {\n return;\n }\n try {\n if (!(await this.sync.needsSync(model))) {\n return;\n }\n const result = await this.taskService.trigger<IModelStorageSyncTaskInput>({\n definition: MODEL_STORAGE_SYNC_TASK,\n name: `Sync storage of model \"${model.modelId}\"`,\n input: { modelId: model.modelId }\n });\n if (result.isFail()) {\n this.logger.error(\n { error: result.error, modelId: model.modelId },\n \"Could not start the storage sync of a changed model.\"\n );\n }\n } catch (error) {\n this.logger.error(\n { error, modelId: model.modelId },\n \"Could not start the storage sync of a changed model.\"\n );\n }\n }\n}\n\nexport const SyncStorageOnModelUpdate = ModelAfterUpdateEventHandler.createImplementation({\n implementation: SyncStorageOnModelUpdateImpl,\n dependencies: [\n Logger,\n [ModelStorageSync, { optional: true }],\n [TaskService, { optional: true }]\n ]\n});\n"],"names":["SyncStorageOnModelUpdateImpl","logger","sync","taskService","event","model","result","MODEL_STORAGE_SYNC_TASK","error","SyncStorageOnModelUpdate","ModelAfterUpdateEventHandler","Logger","ModelStorageSync","TaskService"],"mappings":";;;;AAiBA,MAAMA;IACF,YACqBC,MAAwB,EACxBC,IAAiC,EACjCC,WAAmC,CACtD;aAHmBF,MAAM,GAANA;aACAC,IAAI,GAAJA;aACAC,WAAW,GAAXA;IAClB;IAEH,MAAa,OAAOC,KAAyC,EAAiB;QAC1E,MAAM,EAAEC,KAAK,EAAE,GAAGD,MAAM,OAAO;QAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,IAAIC,MAAM,QAAQ,EACjD;QAEJ,IAAI;YACA,IAAI,CAAE,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAACA,QAC5B;YAEJ,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAA6B;gBACtE,YAAYC;gBACZ,MAAM,CAAC,uBAAuB,EAAEF,MAAM,OAAO,CAAC,CAAC,CAAC;gBAChD,OAAO;oBAAE,SAASA,MAAM,OAAO;gBAAC;YACpC;YACA,IAAIC,OAAO,MAAM,IACb,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;gBAAE,OAAOA,OAAO,KAAK;gBAAE,SAASD,MAAM,OAAO;YAAC,GAC9C;QAGZ,EAAE,OAAOG,OAAO;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;gBAAEA;gBAAO,SAASH,MAAM,OAAO;YAAC,GAChC;QAER;IACJ;AACJ;AAEO,MAAMI,2BAA2BC,6BAA6B,oBAAoB,CAAC;IACtF,gBAAgBV;IAChB,cAAc;QACVW;QACA;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;QACtC;YAACC;YAAa;gBAAE,UAAU;YAAK;SAAE;KACpC;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "6.6.0-alpha.10",
3
+ "version": "6.6.0-alpha.12",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -25,18 +25,18 @@
25
25
  "@babel/code-frame": "8.0.6",
26
26
  "@graphql-tools/merge": "10.0.8",
27
27
  "@graphql-tools/schema": "11.0.8",
28
- "@webiny/api": "6.6.0-alpha.10",
29
- "@webiny/api-core": "6.6.0-alpha.10",
30
- "@webiny/api-core-testing": "6.6.0-alpha.10",
31
- "@webiny/api-graphql": "6.6.0-alpha.10",
28
+ "@webiny/api": "6.6.0-alpha.12",
29
+ "@webiny/api-core": "6.6.0-alpha.12",
30
+ "@webiny/api-core-testing": "6.6.0-alpha.12",
31
+ "@webiny/api-graphql": "6.6.0-alpha.12",
32
32
  "@webiny/di": "2.0.0",
33
- "@webiny/error": "6.6.0-alpha.10",
34
- "@webiny/event-handler-core": "6.6.0-alpha.10",
35
- "@webiny/feature": "6.6.0-alpha.10",
36
- "@webiny/handler": "6.6.0-alpha.10",
37
- "@webiny/plugins": "6.6.0-alpha.10",
38
- "@webiny/utils": "6.6.0-alpha.10",
39
- "@webiny/validation": "6.6.0-alpha.10",
33
+ "@webiny/error": "6.6.0-alpha.12",
34
+ "@webiny/event-handler-core": "6.6.0-alpha.12",
35
+ "@webiny/feature": "6.6.0-alpha.12",
36
+ "@webiny/handler": "6.6.0-alpha.12",
37
+ "@webiny/plugins": "6.6.0-alpha.12",
38
+ "@webiny/utils": "6.6.0-alpha.12",
39
+ "@webiny/validation": "6.6.0-alpha.12",
40
40
  "dot-prop-immutable": "2.1.1",
41
41
  "graphql": "16.14.2",
42
42
  "graphql-tag": "2.12.7",
@@ -49,10 +49,10 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/pluralize": "0.0.33",
52
- "@webiny/build-tools": "6.6.0-alpha.10",
53
- "@webiny/db-dynamodb": "6.6.0-alpha.10",
54
- "@webiny/sdk": "6.6.0-alpha.10",
55
- "@webiny/wcp": "6.6.0-alpha.10",
52
+ "@webiny/build-tools": "6.6.0-alpha.12",
53
+ "@webiny/db-dynamodb": "6.6.0-alpha.12",
54
+ "@webiny/sdk": "6.6.0-alpha.12",
55
+ "@webiny/wcp": "6.6.0-alpha.12",
56
56
  "graphql": "16.14.2",
57
57
  "oxfmt": "0.75.0",
58
58
  "rimraf": "6.1.3",