@slicemachine/manager 0.24.4-alpha.xru-poc-ai.1 → 0.24.4-alpha.xru-slice-generation-ai-poc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"SlicesManager.js","sources":["../../../../src/managers/slices/SlicesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport { SliceComparator } from \"@prismicio/types-internal/lib/customtypes/diff\";\nimport {\n\tCompositeSlice,\n\tLegacySlice,\n\tSharedSlice,\n\tVariation,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tHookError,\n\tSliceAssetUpdateHook,\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceLibraryReadHookData,\n\tSliceReadHookData,\n\tSliceRenameHook,\n\tSliceRenameHookData,\n\tSliceUpdateHook,\n} from \"@slicemachine/plugin-kit\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { bufferCodec } from \"../../lib/bufferCodec\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { mockSlice } from \"../../lib/mockSlice\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { DEFAULT_SLICE_SCREENSHOT_URL } from \"../../constants/DEFAULT_SLICE_SCREENSHOT_URL\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { UnauthenticatedError, UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport {\n\tBedrockRuntimeClient,\n\tConverseCommand,\n} from \"@aws-sdk/client-bedrock-runtime\";\n\ntype SlicesManagerReadSliceLibraryReturnType = {\n\tsliceIDs: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SlicesManagerReadAllSliceLibrariesReturnType = {\n\tlibraries: {\n\t\tlibraryID: string;\n\t\tsliceIDs: string[] | undefined;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryArgs = {\n\tlibraryID: string;\n};\n\ntype SliceMachineManagerUpdateSliceArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\tmocks?: SharedSliceContent[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\tmodels: { model: SharedSlice }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesReturnType = {\n\tmodels: {\n\t\tlibraryID: string;\n\t\tmodel: SharedSlice;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceReturnType = {\n\tmodel: SharedSlice | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tuserAgent?: string;\n};\n\nexport type SliceMachineManagerPushSliceReturnType = {\n\t/**\n\t * A record of Slice variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tscreenshotURLs: Record<string, string> | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceScreenshotReturnType = {\n\tdata: Buffer | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerUpdateSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tdata: Buffer;\n};\n\ntype SliceMachineManagerDeleteSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksReturnType = {\n\tmocks?: SharedSliceContent[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tmocks: SharedSliceContent[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype SlicesManagerUpsertHostedSliceScrenshotsArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n};\n\ntype SliceMachineManagerDeleteSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerDeleteSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerRenameSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\t/**\n\t * Current ID of the variation to rename.\n\t */\n\tvariationID: string;\n\tmodel: Variation;\n};\n\ntype SliceMachineManagerRenameSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerDeleteSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerDeleteSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {\n\tmodel: CompositeSlice | LegacySlice;\n\tsrc: {\n\t\tcustomTypeID: string;\n\t\ttabID: string;\n\t\tsliceZoneID: string;\n\t\tsliceID: string;\n\t};\n\tdest: {\n\t\tlibraryID: string;\n\t\tsliceID: string;\n\t\tvariationName: string;\n\t\tvariationID: string;\n\t};\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerGenerateSliceArgs = {\n\tuserPrompt: string;\n\tlibraryID: string;\n\tslice: SharedSlice;\n\timageFile?: Buffer;\n};\n\ntype SliceMachineManagerGenerateSliceReturnType = {\n\tslice?: SharedSlice;\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class SlicesManager extends BaseManager {\n\tasync readSliceLibrary(\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SlicesManagerReadSliceLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Should validation happen at the `callHook` level?\n\t\t// Including validation at the hook level would ensure\n\t\t// hook-based actions are validated.\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tsliceIDs: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tsliceIDs: data[0]?.sliceIDs ?? [],\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync readAllSliceLibraries(): Promise<SlicesManagerReadAllSliceLibrariesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SlicesManagerReadAllSliceLibrariesReturnType = {\n\t\t\tlibraries: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\tres.libraries.push({\n\t\t\t\tlibraryID,\n\t\t\t\tsliceIDs,\n\t\t\t});\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlicesForLibrary(\n\t\targs: SliceMachineManagerReadAllSlicesForLibraryArgs,\n\t): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\t\tres.errors.push(...errors);\n\n\t\tif (sliceIDs) {\n\t\t\tfor (const sliceID of sliceIDs) {\n\t\t\t\tconst { model, errors } = await this.readSlice({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t\tres.errors.push(...errors);\n\n\t\t\t\tif (model) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SliceMachineManagerReadAllSlicesReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { models, errors } = await this.readAllSlicesForLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors.push(...errors);\n\n\t\t\tfor (const model of models) {\n\t\t\t\tres.models.push({\n\t\t\t\t\tlibraryID,\n\t\t\t\t\tmodel: model.model,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createSlice(\n\t\targs: SliceCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:create\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: mockSlice({ model: args.model }),\n\t\t};\n\n\t\tconst { errors: updateSliceHookErrors } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceHookErrors],\n\t\t};\n\t}\n\n\tasync readSlice(\n\t\targs: SliceReadHookData,\n\t): Promise<SliceMachineManagerReadSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: SharedSlice,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors: errors.map((error) => {\n\t\t\t\terror.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;\n\n\t\t\t\treturn error;\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync updateSlice(\n\t\targs: SliceMachineManagerUpdateSliceArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { mocks: previousMocks } = await this.readSliceMocks({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst { model: previousModel } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updatedMocks = mockSlice({\n\t\t\tmodel: args.model,\n\t\t\tmocks: previousMocks,\n\t\t\tdiff: SliceComparator.compare(previousModel, args.model),\n\t\t});\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: updatedMocks,\n\t\t};\n\n\t\tconst { errors: updateSliceMocksHookResult } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceMocksHookResult],\n\t\t};\n\t}\n\n\tasync renameSlice(\n\t\targs: SliceRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSlice(\n\t\targs: SliceMachineManagerDeleteSliceArgs,\n\t): Promise<SliceMachineManagerDeleteSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst { errors: deleteSliceErrors } =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:delete\", {\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t});\n\n\t\t\t// Do not update custom types if slice deletion failed\n\t\t\tif (deleteSliceErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: deleteSliceErrors,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: updateCustomTypeErrors } =\n\t\t\t\tawait this._removeSliceFromCustomTypes(args.sliceID);\n\n\t\t\treturn {\n\t\t\t\terrors: updateCustomTypeErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync renameSliceVariation(\n\t\targs: SliceMachineManagerRenameSliceVariationArgs,\n\t): Promise<SliceMachineManagerRenameSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Remove when we support renaming variation ID, see: DT-1708\n\t\tif (args.variationID !== args.model.id) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Find and rename the variation\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.map((variation) => {\n\t\t\t\t\tif (variation.id === args.variationID) {\n\t\t\t\t\t\t// Matches the slice we want to rename\n\t\t\t\t\t\treturn args.model;\n\t\t\t\t\t} else if (variation.id === args.model.id) {\n\t\t\t\t\t\t// Matches any other slice that has the ID of the renamed variation and throw.\n\t\t\t\t\t\t// This should be validated on the frontend first for better UX, this is only backend validation.\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot rename variation \\`${args.variationID}\\` to \\`${args.model.id}\\`. A variation already exists with that ID in slice \\`${args.sliceID}\\` from library \\`${args.libraryID}\\`, try deleting it first or choose another variation ID to rename that slice.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn variation;\n\t\t\t\t}),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// If variation ID has changed, we need to rename assets accordingly\n\t\t\tconst assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];\n\t\t\tif (args.variationID !== args.model.id) {\n\t\t\t\t// Renaming screenshot\n\t\t\t\tconst { data: screenshot, errors: readSliceScreenshotErrors } =\n\t\t\t\t\tawait this.readSliceScreenshot({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceScreenshotErrors);\n\n\t\t\t\tif (screenshot) {\n\t\t\t\t\t// Delete old ID screenshot\n\t\t\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.deleteSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...deleteSliceScreenshotErrors);\n\n\t\t\t\t\t// Create new ID screenshot\n\t\t\t\t\tconst { errors: updateSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.model.id,\n\t\t\t\t\t\t\tdata: screenshot,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceScreenshotErrors);\n\t\t\t\t}\n\n\t\t\t\t// Renaming mocks\n\t\t\t\tconst { mocks, errors: readSliceMocksErrors } =\n\t\t\t\t\tawait this.readSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceMocksErrors);\n\n\t\t\t\tif (mocks?.length) {\n\t\t\t\t\tconst { errors: updateSliceMocksErrors } =\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tmocks: mocks.map((mock) => {\n\t\t\t\t\t\t\t\tif (mock.variation === args.variationID) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...mock,\n\t\t\t\t\t\t\t\t\t\tvariation: args.model.id,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn mock;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceMocksErrors);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync deleteSliceVariation(\n\t\targs: SliceMachineManagerDeleteSliceVariationArgs,\n\t): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Remove variation from model and update it\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.filter(\n\t\t\t\t\t(variation) => variation.id !== args.variationID,\n\t\t\t\t),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// Cleanup deleted variation screenshot\n\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\tawait this.deleteSliceScreenshot(args);\n\n\t\t\t// Cleanup deleted variation mocks\n\t\t\tconst { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(\n\t\t\t\t{\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t},\n\t\t\t);\n\t\t\tlet updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType[\"errors\"] =\n\t\t\t\t[];\n\t\t\tif (mocks?.length) {\n\t\t\t\tupdateSliceMocksErrors = (\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tmocks: mocks.filter((mock) => mock.variation !== args.variationID),\n\t\t\t\t\t})\n\t\t\t\t).errors;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors: [\n\t\t\t\t\t...deleteSliceScreenshotErrors,\n\t\t\t\t\t...readSliceMocksErrors,\n\t\t\t\t\t...updateSliceMocksErrors,\n\t\t\t\t],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync convertLegacySliceToSharedSlice(\n\t\targs: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,\n\t): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {\n\t\tconst errors: (DecodeError | HookError)[] = [];\n\n\t\tconst { model: maybeExistingSlice } = await this.readSlice({\n\t\t\tlibraryID: args.dest.libraryID,\n\t\t\tsliceID: args.dest.sliceID,\n\t\t});\n\n\t\tconst legacySliceAsVariation: Variation = {\n\t\t\tid: args.dest.variationID,\n\t\t\tname: args.dest.variationName,\n\t\t\tdescription: args.dest.variationName,\n\t\t\timageUrl: \"\",\n\t\t\tdocURL: \"\",\n\t\t\tversion: \"initial\",\n\t\t\tprimary: {},\n\t\t\titems: {},\n\t\t};\n\n\t\tswitch (args.model.type) {\n\t\t\tcase \"Slice\":\n\t\t\t\tlegacySliceAsVariation.primary = args.model[\"non-repeat\"];\n\t\t\t\tlegacySliceAsVariation.items = args.model.repeat;\n\t\t\t\tbreak;\n\n\t\t\tcase \"Group\":\n\t\t\t\tlegacySliceAsVariation.items = args.model.config?.fields ?? {};\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tlegacySliceAsVariation.primary = { [args.src.sliceID]: args.model };\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Convert as a slice variation, or merge against an existing slice variation\n\t\tif (maybeExistingSlice) {\n\t\t\tconst maybeVariation = maybeExistingSlice.variations.find(\n\t\t\t\t(variation) => variation.id === args.dest.variationID,\n\t\t\t);\n\n\t\t\t// If we're not merging against an existing slice variation, then we need to insert the new variation\n\t\t\tif (!maybeVariation) {\n\t\t\t\tmaybeExistingSlice.variations = [\n\t\t\t\t\t...maybeExistingSlice.variations,\n\t\t\t\t\tlegacySliceAsVariation,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tmaybeExistingSlice.legacyPaths ||= {};\n\t\t\tmaybeExistingSlice.legacyPaths[\n\t\t\t\t`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`\n\t\t\t] = args.dest.variationID;\n\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: maybeExistingSlice,\n\t\t\t});\n\t\t} else {\n\t\t\t// Convert to new shared slice\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: {\n\t\t\t\t\tid: args.dest.sliceID,\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t\tname: args.dest.sliceID,\n\t\t\t\t\tlegacyPaths: {\n\t\t\t\t\t\t[`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`]:\n\t\t\t\t\t\t\targs.dest.variationID,\n\t\t\t\t\t},\n\t\t\t\t\tvariations: [legacySliceAsVariation],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Update source custom type\n\t\tconst { model: customType, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readCustomType({\n\t\t\t\tid: args.src.customTypeID,\n\t\t\t});\n\t\terrors.push(...customTypeReadErrors);\n\n\t\tif (customType) {\n\t\t\tconst field = customType.json[args.src.tabID][args.src.sliceZoneID];\n\n\t\t\t// Convert legacy slice definition in slice zone to shared slice reference\n\t\t\tif (field.type === \"Slices\" && field.config?.choices) {\n\t\t\t\tdelete field.config.choices[args.src.sliceID];\n\t\t\t\tfield.config.choices[args.dest.sliceID] = {\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: customTypeUpdateErrors } =\n\t\t\t\tawait this.customTypes.updateCustomType({ model: customType });\n\t\t\terrors.push(...customTypeUpdateErrors);\n\t\t}\n\n\t\treturn { errors };\n\t}\n\n\t/**\n\t * @returns Record of variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tasync pushSlice(\n\t\targs: SliceMachineManagerPushSliceArgs,\n\t): Promise<SliceMachineManagerPushSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst modelWithScreenshots =\n\t\t\t\tawait this.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel,\n\t\t\t\t});\n\n\t\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Slice already exists on the repository.\n\t\t\t\tawait client.getSharedSliceByID(args.sliceID);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateSharedSlice(modelWithScreenshots);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If the Slice doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertSharedSlice(modelWithScreenshots);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push Slices to this Prismic repository.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Pass the error through if it isn't the one we were expecting.\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst screenshotURLs: Record<string, string> = {};\n\t\t\tfor (const variation of modelWithScreenshots.variations) {\n\t\t\t\tscreenshotURLs[variation.id] = variation.imageUrl;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tscreenshotURLs,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tscreenshotURLs: undefined,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync readSliceScreenshot(\n\t\targs: SliceMachineManagerReadSliceScreenshotArgs,\n\t): Promise<SliceMachineManagerReadSliceScreenshotReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: bufferCodec,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tdata: data[0]?.data,\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync updateSliceScreenshot(\n\t\targs: SliceMachineManagerUpdateSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: `screenshot-${args.variationID}.png`,\n\t\t\t\t\tdata: args.data,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSliceScreenshot(\n\t\targs: SliceMachineManagerDeleteSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:delete\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readSliceMocks(\n\t\targs: SliceMachineManagerReadSliceMocksArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `mocks.json`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: t.array(SharedSliceContent),\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...hookResult,\n\t\t\t\t// Convert the asset data from a Buffer to JSON\n\t\t\t\t// to prepare it for validation.\n\t\t\t\tdata: hookResult.data.map((result) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tdata: JSON.parse(result.data.toString()),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocks: data[0]?.data,\n\t\t\t\terrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocks: [],\n\t\t\t\terrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync updateSliceMocks(\n\t\targs: SliceMachineManagerUpdateSliceMocksArgs,\n\t): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocks, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\t// TODO: Remove\n\tasync readSliceMocksConfig(\n\t\targs: SliceMachineManagerReadSliceMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync fetchRemoteSlices(): Promise<SharedSlice[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllSharedSlices();\n\t}\n\n\tasync updateSliceModelScreenshotsInPlace(\n\t\targs: SlicesManagerUpsertHostedSliceScrenshotsArgs,\n\t): Promise<SharedSlice> {\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst variations = await Promise.all(\n\t\t\targs.model.variations.map(async (variation) => {\n\t\t\t\tconst screenshot = await this.readSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.model.id,\n\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t});\n\n\t\t\t\t// If there's no screenshot, delete it by replacing it with the default screenshot\n\t\t\t\tif (!screenshot.data) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\timageUrl: DEFAULT_SLICE_SCREENSHOT_URL,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst hasScreenshotChanged = !variation.imageUrl?.includes(\n\t\t\t\t\tcreateContentDigest(screenshot.data),\n\t\t\t\t);\n\n\t\t\t\t// If screenshot hasn't changed, do nothing\n\t\t\t\tif (!hasScreenshotChanged) {\n\t\t\t\t\treturn variation;\n\t\t\t\t}\n\n\t\t\t\tconst keyPrefix = [\n\t\t\t\t\trepositoryName,\n\t\t\t\t\t\"shared-slices\",\n\t\t\t\t\targs.model.id,\n\t\t\t\t\tvariation.id,\n\t\t\t\t].join(\"/\");\n\n\t\t\t\tconst uploadedScreenshot = await this.screenshots.uploadScreenshot({\n\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\tkeyPrefix,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\t...variation,\n\t\t\t\t\timageUrl: uploadedScreenshot.url,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\t...args.model,\n\t\t\tvariations,\n\t\t};\n\t}\n\n\tprivate async _removeSliceFromCustomTypes(sliceID: string) {\n\t\tconst { models, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readAllCustomTypes();\n\n\t\t// Successfully update all custom types or throw\n\t\tawait Promise.all(\n\t\t\tmodels.map(async (customType) => {\n\t\t\t\tconst updatedJsonModel = Object.entries(customType.model.json).reduce(\n\t\t\t\t\t(tabAccumulator, [tabKey, tab]) => {\n\t\t\t\t\t\tconst updatedTabFields = Object.entries(tab).reduce(\n\t\t\t\t\t\t\t(fieldAccumulator, [fieldKey, field]) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tfield.config === undefined ||\n\t\t\t\t\t\t\t\t\tfield.type !== \"Slices\" ||\n\t\t\t\t\t\t\t\t\tfield.config.choices === undefined\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn { ...fieldAccumulator, [fieldKey]: field };\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filteredChoices = Object.entries(\n\t\t\t\t\t\t\t\t\tfield.config.choices,\n\t\t\t\t\t\t\t\t).reduce((choiceAccumulator, [choiceKey, choice]) => {\n\t\t\t\t\t\t\t\t\tif (choiceKey === sliceID) {\n\t\t\t\t\t\t\t\t\t\treturn choiceAccumulator;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn { ...choiceAccumulator, [choiceKey]: choice };\n\t\t\t\t\t\t\t\t}, {});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...fieldAccumulator,\n\t\t\t\t\t\t\t\t\t[fieldKey]: {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tconfig: { ...field.config, choices: filteredChoices },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn { ...tabAccumulator, [tabKey]: updatedTabFields };\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t);\n\n\t\t\t\tawait this.customTypes.updateCustomType({\n\t\t\t\t\tmodel: { ...customType.model, json: updatedJsonModel },\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\n\t\treturn { errors: customTypeReadErrors };\n\t}\n\n\tasync generateSlice(\n\t\targs: SliceMachineManagerGenerateSliceArgs,\n\t): Promise<SliceMachineManagerGenerateSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst AWS_REGION = \"us-east-1\";\n\t\tconst AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;\n\t\tconst AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;\n\n\t\tif (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY) {\n\t\t\tthrow new Error(\"AWS credentials are not set.\");\n\t\t}\n\n\t\t// Initialize AWS Bedrock client\n\t\tconst bedrockClient = new BedrockRuntimeClient({\n\t\t\tregion: AWS_REGION,\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: AWS_ACCESS_KEY_ID,\n\t\t\t\tsecretAccessKey: AWS_SECRET_ACCESS_KEY,\n\t\t\t},\n\t\t});\n\n\t\t/**\n\t\t * Generates the JSON schema for the SharedSlice TypeScript type.\n\t\t */\n\t\tconst getSharedSliceSchema = (): string => {\n\t\t\treturn `\n\n\t\t\t/**\n\t\t\t * Represents a Prismic Slice.\n\t\t\t * @property {string} type - Should always be \"SharedSlice\".\n\t\t\t * @property {string} id - Unique identifier for the slice in snake_case.\n\t\t\t * @property {string} name - Human-readable name in PascalCase.\n\t\t\t * @property {string} description - Brief explanation of the slice's purpose.\n\t\t\t * @property {SliceVariation[]} variations - Array of variations for the slice.\n\t\t\t */\n\t\t\ttype PrismicSlice = {\n\t\t\t type: \"SharedSlice\";\n\t\t\t id: string;\n\t\t\t name: string;\n\t\t\t description: string;\n\t\t\t variations: SliceVariation[];\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a variation of a Prismic Slice.\n\t\t\t * @property {string} id - Unique identifier for the variation in snake_case.\n\t\t\t * @property {string} name - Human-readable name in PascalCase.\n\t\t\t * @property {string} description - Brief explanation of the variation's purpose.\n\t\t\t * @property {string} docURL - Legacy property, required with an empty string.\n\t\t\t * @property {string} version - Legacy property, required with the name property value.\n\t\t\t * @property {Record<string, PrismicField>} [primary] - Primary fields defining the main content of the slice.\n\t\t\t */\n\t\t\ttype SliceVariation = {\n\t\t\t id: string;\n\t\t\t name: string;\n\t\t\t description: string;\n\t\t\t primary: Record<string, PrismicField>;\n\t\t\t docURL: string;\n\t\t\t version: string;\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Union type representing all possible Prismic fields.\n\t\t\t */\n\t\t\ttype PrismicField =\n\t\t\t | UIDField\n\t\t\t | BooleanField\n\t\t\t | ColorField\n\t\t\t | DateField\n\t\t\t | TimestampField\n\t\t\t | NumberField\n\t\t\t | KeyTextField\n\t\t\t | SelectField\n\t\t\t | StructuredTextField\n\t\t\t | ImageField\n\t\t\t | LinkField\n\t\t\t | GeoPointField\n\t\t\t | EmbedField\n\t\t\t | GroupField;\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a UID Field in Prismic.\n\t\t\t * @property {\"UID\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {string} [config.placeholder] - Placeholder text.\n\t\t\t * @property {string} [config.customregex] - Custom regex for validation.\n\t\t\t * @property {string} [config.errorMessage] - Error message for invalid input.\n\t\t\t */\n\t\t\ttype UIDField = {\n\t\t\t type: \"UID\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tplaceholder?: string;\n\t\t\t\tcustomregex?: string;\n\t\t\t\terrorMessage?: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Boolean Field in Prismic.\n\t\t\t * @property {\"Boolean\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {boolean} [config.default_value] - Default value (true or false).\n\t\t\t */\n\t\t\ttype BooleanField = {\n\t\t\t type: \"Boolean\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tdefault_value?: boolean;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Color Field in Prismic.\n\t\t\t * @property {\"Color\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t */\n\t\t\ttype ColorField = {\n\t\t\t type: \"Color\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Date Field in Prismic.\n\t\t\t * @property {\"Date\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t */\n\t\t\ttype DateField = {\n\t\t\t type: \"Date\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Timestamp Field in Prismic.\n\t\t\t * @property {\"Timestamp\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t */\n\t\t\ttype TimestampField = {\n\t\t\t type: \"Timestamp\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Number Field in Prismic.\n\t\t\t * @property {\"Number\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {string} [config.placeholder] - Placeholder text.\n\t\t\t * @property {number} [config.min] - Minimum allowable value.\n\t\t\t * @property {number} [config.max] - Maximum allowable value.\n\t\t\t */\n\t\t\ttype NumberField = {\n\t\t\t type: \"Number\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tplaceholder?: string;\n\t\t\t\tmin?: number;\n\t\t\t\tmax?: number;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Key Text Field in Prismic.\n\t\t\t * @property {\"Text\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {string} [config.placeholder] - Placeholder text.\n\t\t\t */\n\t\t\ttype KeyTextField = {\n\t\t\t type: \"Text\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tplaceholder?: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Select Field in Prismic.\n\t\t\t * @property {\"Select\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {string[]} config.options - Array of options for the select dropdown.\n\t\t\t */\n\t\t\ttype SelectField = {\n\t\t\t type: \"Select\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\toptions: string[];\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Structured Text Field in Prismic.\n\t\t\t * @property {\"StructuredText\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {string} [config.placeholder] - Placeholder text.\n\t\t\t * @property {string} [config.single] - A comma-separated list of formatting options that does not allow line breaks. Options: paragraph | preformatted | heading1 | heading2 | heading3 | heading4 | heading5 | heading6 | strong | em | hyperlink | image | embed | list-item | o-list-item | rtl.\n\t\t\t * @property {string} [config.multi] - A comma-separated list of formatting options, with paragraph breaks allowed. Options: paragraph | preformatted | heading1 | heading2 | heading3 | heading4 | heading5 | heading6 | strong | em | hyperlink | image | embed | list-item | o-list-item | rtl.\n\t\t\t * @property {boolean} [config.allowTargetBlank] - Allows links to open in a new tab.\n\t\t\t * @property {string[]} [config.labels] - An array of strings to define labels for custom formatting.\n\t\t\t * @property {ImageConstraint} [config.imageConstraint] - Constraints for images within the rich text field.\n\t\t\t */\n\t\t\ttype StructuredTextField = {\n\t\t\t type: \"StructuredText\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tplaceholder?: string;\n\t\t\t\tsingle?: string;\n\t\t\t\tmulti?: string;\n\t\t\t\tallowTargetBlank?: boolean;\n\t\t\t\tlabels?: string[];\n\t\t\t\timageConstraint?: ImageConstraint;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents constraints for images within a rich text field.\n\t\t\t * @property {number} [width] - Width constraint in pixels.\n\t\t\t * @property {number\n\t\t\t * @property {number} [height] - Height constraint in pixels.\n\t\t\t */\n\t\t\ttype ImageConstraint = {\n\t\t\t width?: number;\n\t\t\t height?: number;\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents an Image Field in Prismic.\n\t\t\t * @property {\"Image\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {Object} [config.constraint] - Constraints for the image dimensions.\n\t\t\t * @property {number} [config.constraint.width] - Width constraint.\n\t\t\t * @property {number} [config.constraint.height] - Height constraint.\n\t\t\t * @property {Thumbnail[]} [config.thumbnails] - Array of thumbnail configurations.\n\t\t\t */\n\t\t\ttype ImageField = {\n\t\t\t type: \"Image\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tconstraint?: {\n\t\t\t\t width?: number;\n\t\t\t\t height?: number;\n\t\t\t\t};\n\t\t\t\tthumbnails?: Thumbnail[];\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Thumbnail configuration for an Image field.\n\t\t\t * @property {string} name - Name of the thumbnail.\n\t\t\t * @property {number} [width] - Width of the thumbnail in pixels.\n\t\t\t * @property {number} [height] - Height of the thumbnail in pixels.\n\t\t\t */\n\t\t\ttype Thumbnail = {\n\t\t\t name: string;\n\t\t\t width?: number;\n\t\t\t height?: number;\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Link Field in Prismic.\n\t\t\t * @property {\"Link\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {\"web\" | \"document\" | \"media\"} config.select - Defines the type of link allowed.\n\t\t\t * @property {string[]} [config.customtypes] - Defines which Prismic document types are allowed if select is \"document\".\n\t\t\t */\n\t\t\ttype LinkField = {\n\t\t\t type: \"Link\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tselect: \"web\" | \"document\" | \"media\";\n\t\t\t\tcustomtypes?: string[];\n\t\t\t\tallowText: boolean;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents an Embed Field in Prismic.\n\t\t\t * @property {\"Embed\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t */\n\t\t\ttype EmbedField = {\n\t\t\t type: \"Embed\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a GeoPoint Field in Prismic.\n\t\t\t * @property {\"GeoPoint\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t */\n\t\t\ttype GeoPointField = {\n\t\t\t type: \"GeoPoint\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t };\n\t\t\t};\n\t\t\t\n\t\t\t/**\n\t\t\t * Represents a Group Field (Repeatable Fields) in Prismic.\n\t\t\t * @property {\"Group\"} type - Field type.\n\t\t\t * @property {Object} config - Configuration object.\n\t\t\t * @property {string} config.label - Label displayed in the editor.\n\t\t\t * @property {Record<string, PrismicField>} config.fields - Defines the fields inside the group.\n\t\t\t */\n\t\t\ttype GroupField = {\n\t\t\t type: \"Group\";\n\t\t\t config: {\n\t\t\t\tlabel: string;\n\t\t\t\tfields: Record<string, PrismicField>;\n\t\t\t };\n\t\t\t};\n`;\n\t\t};\n\n\t\t/**\n\t\t * Builds the system prompt message using the generated TypeScript schema.\n\t\t */\n\t\tconst buildSystemMessage = (\n\t\t\tschema: string,\n\t\t\texistingSlice: SharedSlice,\n\t\t): string => {\n\t\t\treturn `\nYou are a world-class expert in creating Prismic Custom Type models for slices.\nYour task is to generate a valid Prismic JSON model based solely on the provided description and the TypeScript schema below.\nThe JSON model must adhere strictly to these rules:\n1. Include all necessary fields as described.\n2. Use the \"primary\" object for all main content fields.\n3. Do NOT use an \"items\" field. If a field represents a collection, it must be defined inside a Group field within the \"primary\" object.\n4. Ensure that each field has appropriate placeholders, labels, and configurations.\n5. If the existing slices contain fields, ensure to understand the user prompt to update the existing slice instead of creating something from scratch.\n6. If you detect the user wants to add a variation, always ensure the new variation is not exactly the same as another existing one\n7. Always return the full valid slice, as given in existing it should be returned in a valid format.\n8. If you detect the user prompt is about creating a totally different slice, do it and discard what was given in the existing slice, BUT only if you detect if nothing related.\n9. NEVER generate a Link / Button text field, ONLY the Link / Button field itself is enough. So ONE field just for the Link / Button. ENABLE \"allowText\" when doing that.\n10. AND THE MOST ULTRA IMPORTANT THING! Output ONLY a valid JSON object without any additional commentary or formatting! ONLY JSON, I need to parse it after with JSON.parse!\n\n### TypeScript Schema for reference:\n${schema}\n\n### Existing slice\n${JSON.stringify(existingSlice)}\n`.trim();\n\t\t};\n\n\t\t/**\n\t\t * Sends the prompt to AWS Bedrock and returns the generated Prismic JSON\n\t\t * model.\n\t\t */\n\t\tconst generatePrismicModel = async (\n\t\t\tuserPrompt: string,\n\t\t): Promise<string> => {\n\t\t\tconst schema = getSharedSliceSchema();\n\n\t\t\tconst systemMessage = buildSystemMessage(schema, args.slice);\n\n\t\t\tconst command = new ConverseCommand({\n\t\t\t\tmodelId: \"anthropic.claude-3-5-sonnet-20240620-v1:0\",\n\t\t\t\tsystem: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\tsystemMessage +\n\t\t\t\t\t\t\t(args.imageFile\n\t\t\t\t\t\t\t\t? `\n\t\t\t\t\t\t\t\t### Additional important rules\n\t\t\t\t\tA. SUPER IMPORTANT, you have to check and read the image and generate the model according to what is visible.\n\t\t\t\t\tB. You MUST understand that background image are just a simple image field. Don't try to do anything fancy with it, just a simple image field. \n\t\t\t\t\tC. Even if the background image looks like two image, be smart and detect if it's actually just one simple background that don't need a GROUP!\n\t\t\t\t\tD. NEVER EVER ADD decorative elements as detailled fields\n\t\t\t\t\t`\n\t\t\t\t\t\t\t\t: ``),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tmessages: [\n\t\t\t\t\targs.imageFile\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\timage: {\n\t\t\t\t\t\t\t\t\t\t\tformat: \"png\",\n\t\t\t\t\t\t\t\t\t\t\tsource: { bytes: args.imageFile } as any,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttext: `Generate a valid Prismic JSON model based on the following description:\\n\\n${userPrompt}`,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t },\n\t\t\t\t],\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tconsole.log(\"Before sending command\");\n\t\t\t\tconst response = await bedrockClient.send(command);\n\t\t\t\tconsole.log(\"After response\", JSON.stringify(response));\n\n\t\t\t\tconst result = response.output?.message?.content?.[0]?.text?.trim();\n\t\t\t\tconsole.log(\"After sending command\");\n\t\t\t\tif (!result) {\n\t\t\t\t\tthrow new Error(\"No valid response received.\");\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\"Error generating Prismic model:\", error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t};\n\n\t\tconst prismicModel = await generatePrismicModel(args.userPrompt);\n\n\t\tconsole.log(\"After saving slice\", prismicModel);\n\n\t\tconst newSlice = {\n\t\t\t...args.slice,\n\t\t\tvariations: JSON.parse(prismicModel).variations,\n\t\t};\n\n\t\tconst response = await this.updateSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tmodel: newSlice,\n\t\t});\n\n\t\tif (response.errors.length) {\n\t\t\treturn {\n\t\t\t\terrors: response.errors,\n\t\t\t};\n\t\t}\n\n\t\ttry {\n\t\t\tif (args.imageFile) {\n\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: newSlice.id,\n\t\t\t\t\tvariationID: newSlice.variations[0].id,\n\t\t\t\t\tdata: args.imageFile,\n\t\t\t\t});\n\n\t\t\t\tconst extMocks = mockSlice({ model: newSlice });\n\t\t\t\tconsole.log(\"extMocks\", extMocks);\n\n\t\t\t\tconst command = new ConverseCommand({\n\t\t\t\t\tmodelId: \"anthropic.claude-3-5-sonnet-20240620-v1:0\",\n\t\t\t\t\tsystem: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttext: `\n# Task 1\nYou are a world-class expert in creating Prismic Mocks for slices.\nYour task is to generate a valid Prismic JSON mocks based solely on the provided existing mocks.\nThe goal is for you to take the image from the user input, detect the text and fill ensure the existing mock data is aligned with what is visible.\nDon't handle images.\nOnly handle text.\nIf you see a repetition with a group, you must create the same number of group items that are visible on the image.\nKEEP THE EXACT SAME STRUCTURE FOR THE MOCKS DATA, ONLY FILL IN THE TEXT FIELDS!\nAND ULTRA IMPORTANT! Output ONLY a valid JSON object without any additional commentary or formatting! ONLY JSON with the same existing mock format, I need to parse it after with JSON.parse!\n\n### Existing mocks\n${JSON.stringify(extMocks)}\n\nTHAT was your FIRST task!\n# Task 2\n\nNow you also have a second task, generating the slice code!\nGenerate fully isolated slice mock that don't require any package. The code is in React.\nYou have to ensure the mocks data will be the input of your code.\nUse the example of a slice fully isolated from bellow to help you know how to code a slice. But use the mocks data as input and the slice name etc.\nNEVER USE <style jsx> in the final code, just <style> is enough! It's important to not use <style jsx>!\nEnsure that the color used for the background is the same as the image provide in the user prompt! It's better no background color than a wrong one.\nYour goal is to make the code visually looks as close as possible to the image from the user input.\nAND ULTRA IMPORTANT! Output ONLY a valid React code without any additional commentary or formatting! Give me the code so I can just copy paste it into a React component file.\n\n### Tips\nFor links just use PrismicNextLink just pass the field, PrismicNextLink will handle the display of the link text.\nDO NOT TRY TO MANUALLY GO INSIDE THE LINK TO WRITE THE TEXT IT\"S DONE AUTOMATICALLY.\n\n### Example of a slice fully isolated \nimport { type Content } from \"@prismicio/client\";\nimport { PrismicNextLink, PrismicNextImage } from \"@prismicio/next\";\nimport { SliceComponentProps, PrismicRichText } from \"@prismicio/react\";\n\nexport type HeroProps = SliceComponentProps<Content.HeroSlice>;\n\nconst Hero = ({ slice }: HeroProps): JSX.Element => {\n return (\n <section\n data-slice-type={slice.slice_type}\n data-slice-variation={slice.variation}\n className=\"es-bounded es-fullpage-hero\"\n >\n <div\n className=\"es-fullpage-hero__content\"\n >\n <div>\n <PrismicNextImage\n field={slice.primary.image}\n className=\"es-fullpage-hero__image\"\n />\n </div>\n\n <div className=\"es-fullpage-hero__content-right\">\n <div className=\"es-fullpage-hero__content__intro\">\n <p className=\"es-fullpage-hero__content__intro__eyebrow\">\n {slice.primary.eyebrowHeadline}\n </p>\n \n <div className=\"es-fullpage-hero__content__intro__headline\">\n <PrismicRichText field={slice.primary.title} />\n </div>\n\n \n <div className=\"es-fullpage-hero__content__intro__description\">\n <PrismicRichText field={slice.primary.description} />\n </div>\n \n <PrismicNextLink\n className=\"es-call-to-action__link\"\n field={slice.primary.callToActionLink}\n />\n </div>\n </div>\n </div>\n <style>\n {\\`\n .es-bounded {\n margin: 0px;\n min-width: 0px;\n position: relative;\n }\n \n .es-fullpage-hero {\n font-family: system-ui, sans-serif;\n background-color: #fff;\n color: #333;\n }\n \n .es-fullpage-hero__image {\n max-width: 100%;\n height: auto;\n align-self: center;\n\t\t}\n \n .es-fullpage-hero__content {\n display: flex;\n flex-direction: column;\n gap: 2rem;\n }\n \n .es-fullpage-hero__content-right {\n display: flex;\n flex-direction: column;\n justify-content: space-around;\n padding: 1.5rem;\n }\n \n @media (min-width: 1080px) {\n .es-fullpage-hero__content {\n flex-direction: row;\n }\n \n .es-fullpage-hero__content > div {\n width: 50%;\n }\n }\n \n .es-fullpage-hero__content__intro {\n display: grid;\n gap: 1rem;\n }\n \n .es-fullpage-hero__content__intro__eyebrow {\n color: #47C1AF;\n font-size: 1.15rem;\n font-weight: 500;\n margin: 0;\n }\n \n .es-fullpage-hero__content__intro__headline {\n font-size: 1.625rem;\n font-weight: 700;\n }\n \n .es-fullpage-hero__content__intro__headline * {\n margin: 0;\n }\n \n @media (min-width: 640px) {\n .es-fullpage-hero__content__intro__headline {\n font-size: 2rem;\n }\n }\n \n @media (min-width: 1024px) {\n .es-fullpage-hero__content__intro__headline {\n font-size: 2.5rem;\n }\n }\n \n @media (min-width: 1200px) {\n .es-fullpage-hero__content__intro__headline {\n font-size: 2.75rem;\n }\n }\n \n .es-fullpage-hero__content__intro__description {\n font-size: 1.15rem;\n max-width: 38rem;\n }\n \n .es-fullpage-hero__content__intro__description > p {\n margin: 0;\n }\n \n @media (min-width: 1200px) {\n .es-fullpage-hero__content__intro__description {\n font-size: 1.4rem;\n }\n }\n\n .es-call-to-action__link {\n justify-self: flex-start;\n border-radius: 0.25rem;\n font-size: 0.875rem;\n line-height: 1.3;\n padding: 1rem 2.625rem;\n transition: background-color 100ms linear;\n background-color: #16745f;\n color: #fff;\n }\n \n .es-call-to-action__link:hover {\n background-color: #0d5e4c;\n }\n \\`}\n </style>\n </section>\n );\n};\n\nexport default Hero;\n\n\n# Final output of task 1 and 2\nReturn the task 1 and 2 output in a an object:\n{\n task1: <JSON of task 1 for the mocks>,\n task2: <plain string of the slice code for task 2>\n}\nTHIS IS THE MOST IMPORTANT THING, YOU NEED A VALID JSON, with task1 and task2 property. And the correct format for each of the two property.\n\t\t\t\t\t\t`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tmessages: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\timage: {\n\t\t\t\t\t\t\t\t\t\tformat: \"png\",\n\t\t\t\t\t\t\t\t\t\tsource: { bytes: args.imageFile } as any,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\tconsole.log(\"Before sending mock command\");\n\t\t\t\tconst response = await bedrockClient.send(command);\n\t\t\t\tconsole.log(\"After response\", JSON.stringify(response));\n\n\t\t\t\tconst result = response.output?.message?.content?.[0]?.text?.trim();\n\t\t\t\tconsole.log(\"After sending mock command\");\n\n\t\t\t\tif (result) {\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: newSlice.id,\n\t\t\t\t\t\tmocks: JSON.parse(result).task1,\n\t\t\t\t\t});\n\n\t\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update-code\", {\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tmodel: newSlice,\n\t\t\t\t\t\tcomponentContents: JSON.parse(result).task2,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.log(\"Error\", e);\n\t\t}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AAAA,YAChB,SAAS,SAAS;AAAA,YAClB,OAAO,KAAK,MAAM,MAAM,EAAE;AAAA,UAAA,CAC1B;AAEK,gBAAA,KAAK,yBAAyB,SAAS,qBAAqB;AAAA,YACjE,WAAW,KAAK;AAAA,YAChB,OAAO;AAAA,YACP,mBAAmB,KAAK,MAAM,MAAM,EAAE;AAAA,UAAA,CACtC;AAAA,QACF;AAAA,MACD;AAAA,aACQ;AACA,cAAA,IAAI,SAAS,CAAC;AAAA,IACvB;AAEO,WAAA;AAAA,MACN,QAAQ,CAAE;AAAA,MACV,OAAO;AAAA,IAAA;AAAA,EAET;AACA;"}
1
+ {"version":3,"file":"SlicesManager.js","sources":["../../../../src/managers/slices/SlicesManager.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport * as t from \"io-ts\";\nimport OpenAI from \"openai\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport { SliceComparator } from \"@prismicio/types-internal/lib/customtypes/diff\";\nimport {\n\tCompositeSlice,\n\tLegacySlice,\n\tSharedSlice,\n\tVariation,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tHookError,\n\tSliceAssetUpdateHook,\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceLibraryReadHookData,\n\tSliceReadHookData,\n\tSliceRenameHook,\n\tSliceRenameHookData,\n\tSliceUpdateHook,\n} from \"@slicemachine/plugin-kit\";\nimport path from \"node:path\";\nimport { ChatCompletionMessageParam } from \"openai/resources\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { bufferCodec } from \"../../lib/bufferCodec\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { mockSlice } from \"../../lib/mockSlice\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { DEFAULT_SLICE_SCREENSHOT_URL } from \"../../constants/DEFAULT_SLICE_SCREENSHOT_URL\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { UnauthenticatedError, UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport {\n\tBedrockRuntimeClient,\n\tConverseCommand,\n} from \"@aws-sdk/client-bedrock-runtime\";\n\ntype SlicesManagerReadSliceLibraryReturnType = {\n\tsliceIDs: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SlicesManagerReadAllSliceLibrariesReturnType = {\n\tlibraries: {\n\t\tlibraryID: string;\n\t\tsliceIDs: string[] | undefined;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryArgs = {\n\tlibraryID: string;\n};\n\ntype SliceMachineManagerUpdateSliceArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\tmocks?: SharedSliceContent[];\n};\n\ntype SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\tmodels: { model: SharedSlice }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadAllSlicesReturnType = {\n\tmodels: {\n\t\tlibraryID: string;\n\t\tmodel: SharedSlice;\n\t}[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceReturnType = {\n\tmodel: SharedSlice | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tuserAgent?: string;\n};\n\nexport type SliceMachineManagerPushSliceReturnType = {\n\t/**\n\t * A record of Slice variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tscreenshotURLs: Record<string, string> | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceScreenshotReturnType = {\n\tdata: Buffer | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerUpdateSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tdata: Buffer;\n};\n\ntype SliceMachineManagerDeleteSliceScreenshotArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksReturnType = {\n\tmocks?: SharedSliceContent[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerReadSliceMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tmocks: SharedSliceContent[];\n};\n\ntype SliceMachineManagerUpdateSliceMocksArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype SlicesManagerUpsertHostedSliceScrenshotsArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n};\n\ntype SliceMachineManagerDeleteSliceArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n};\n\ntype SliceMachineManagerDeleteSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerRenameSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\t/**\n\t * Current ID of the variation to rename.\n\t */\n\tvariationID: string;\n\tmodel: Variation;\n};\n\ntype SliceMachineManagerRenameSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerDeleteSliceVariationArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n};\n\ntype SliceMachineManagerDeleteSliceVariationReturnType = {\n\terrors: (DecodeError | HookError)[];\n\tassetsErrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceArgs = {\n\tmodel: CompositeSlice | LegacySlice;\n\tsrc: {\n\t\tcustomTypeID: string;\n\t\ttabID: string;\n\t\tsliceZoneID: string;\n\t\tsliceID: string;\n\t};\n\tdest: {\n\t\tlibraryID: string;\n\t\tsliceID: string;\n\t\tvariationName: string;\n\t\tvariationID: string;\n\t};\n};\n\ntype SliceMachineManagerConvertLegacySliceToSharedSliceReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerGenerateSliceArgs = {\n\tlibraryID: string;\n\tslice: SharedSlice;\n\timageFile: Uint8Array;\n};\n\ntype SliceMachineManagerGenerateSliceReturnType = {\n\tslice?: SharedSlice;\n};\n\ntype SliceMachineManagerGenerateSlicesFromUrlArgs = {\n\twebsiteUrl: string;\n};\n\ntype SliceMachineManagerGenerateSlicesFromUrlReturnType = {\n\tslices: SharedSlice[];\n};\n\nexport class SlicesManager extends BaseManager {\n\tasync readSliceLibrary(\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SlicesManagerReadSliceLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Should validation happen at the `callHook` level?\n\t\t// Including validation at the hook level would ensure\n\t\t// hook-based actions are validated.\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice-library:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tsliceIDs: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tsliceIDs: data[0]?.sliceIDs ?? [],\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync readAllSliceLibraries(): Promise<SlicesManagerReadAllSliceLibrariesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SlicesManagerReadAllSliceLibrariesReturnType = {\n\t\t\tlibraries: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\tres.libraries.push({\n\t\t\t\tlibraryID,\n\t\t\t\tsliceIDs,\n\t\t\t});\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlicesForLibrary(\n\t\targs: SliceMachineManagerReadAllSlicesForLibraryArgs,\n\t): Promise<SliceMachineManagerReadAllSlicesForLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllSlicesForLibraryReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { sliceIDs, errors } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\t\tres.errors.push(...errors);\n\n\t\tif (sliceIDs) {\n\t\t\tfor (const sliceID of sliceIDs) {\n\t\t\t\tconst { model, errors } = await this.readSlice({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t\tres.errors.push(...errors);\n\n\t\t\t\tif (model) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync readAllSlices(): Promise<SliceMachineManagerReadAllSlicesReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\n\t\tconst res: SliceMachineManagerReadAllSlicesReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tfor (const libraryID of libraryIDs) {\n\t\t\tconst { models, errors } = await this.readAllSlicesForLibrary({\n\t\t\t\tlibraryID,\n\t\t\t});\n\t\t\tres.errors.push(...errors);\n\n\t\t\tfor (const model of models) {\n\t\t\t\tres.models.push({\n\t\t\t\t\tlibraryID,\n\t\t\t\t\tmodel: model.model,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createSlice(\n\t\targs: SliceCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconsole.log(\n\t\t\t`component code to create NOW for ${args.model.name}:`,\n\t\t\tJSON.stringify(args),\n\t\t);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:create\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: mockSlice({ model: args.model }),\n\t\t};\n\n\t\tconst { errors: updateSliceHookErrors } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceHookErrors],\n\t\t};\n\t}\n\n\tasync readSlice(\n\t\targs: SliceReadHookData,\n\t): Promise<SliceMachineManagerReadSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: SharedSlice,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors: errors.map((error) => {\n\t\t\t\terror.message = `Failed to decode slice model with id '${args.sliceID}': ${error.message}`;\n\n\t\t\t\treturn error;\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync updateSlice(\n\t\targs: SliceMachineManagerUpdateSliceArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { mocks: previousMocks } = await this.readSliceMocks({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst { model: previousModel } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t});\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:update\",\n\t\t\targs,\n\t\t);\n\n\t\tconst updatedMocks = mockSlice({\n\t\t\tmodel: args.model,\n\t\t\tmocks: previousMocks,\n\t\t\tdiff: SliceComparator.compare(previousModel, args.model),\n\t\t});\n\t\tconst updateSliceMocksArgs: SliceMachineManagerUpdateSliceMocksArgs = {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.model.id,\n\t\t\tmocks: updatedMocks,\n\t\t};\n\n\t\tconst { errors: updateSliceMocksHookResult } =\n\t\t\tawait this.updateSliceMocks(updateSliceMocksArgs);\n\n\t\treturn {\n\t\t\terrors: [...hookResult.errors, ...updateSliceMocksHookResult],\n\t\t};\n\t}\n\n\tasync renameSlice(\n\t\targs: SliceRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSlice(\n\t\targs: SliceMachineManagerDeleteSliceArgs,\n\t): Promise<SliceMachineManagerDeleteSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst { errors: deleteSliceErrors } =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:delete\", {\n\t\t\t\t\tmodel,\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t});\n\n\t\t\t// Do not update custom types if slice deletion failed\n\t\t\tif (deleteSliceErrors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: deleteSliceErrors,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: updateCustomTypeErrors } =\n\t\t\t\tawait this._removeSliceFromCustomTypes(args.sliceID);\n\n\t\t\treturn {\n\t\t\t\terrors: updateCustomTypeErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync renameSliceVariation(\n\t\targs: SliceMachineManagerRenameSliceVariationArgs,\n\t): Promise<SliceMachineManagerRenameSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// TODO: Remove when we support renaming variation ID, see: DT-1708\n\t\tif (args.variationID !== args.model.id) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Renaming variation ID is not supported yet by the backend, only rename its name! For more information, see: https://linear.app/prismic/issue/DT-1708\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Find and rename the variation\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.map((variation) => {\n\t\t\t\t\tif (variation.id === args.variationID) {\n\t\t\t\t\t\t// Matches the slice we want to rename\n\t\t\t\t\t\treturn args.model;\n\t\t\t\t\t} else if (variation.id === args.model.id) {\n\t\t\t\t\t\t// Matches any other slice that has the ID of the renamed variation and throw.\n\t\t\t\t\t\t// This should be validated on the frontend first for better UX, this is only backend validation.\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot rename variation \\`${args.variationID}\\` to \\`${args.model.id}\\`. A variation already exists with that ID in slice \\`${args.sliceID}\\` from library \\`${args.libraryID}\\`, try deleting it first or choose another variation ID to rename that slice.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn variation;\n\t\t\t\t}),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// If variation ID has changed, we need to rename assets accordingly\n\t\t\tconst assetsErrors: (DecodeError<unknown> | HookError<unknown>)[] = [];\n\t\t\tif (args.variationID !== args.model.id) {\n\t\t\t\t// Renaming screenshot\n\t\t\t\tconst { data: screenshot, errors: readSliceScreenshotErrors } =\n\t\t\t\t\tawait this.readSliceScreenshot({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceScreenshotErrors);\n\n\t\t\t\tif (screenshot) {\n\t\t\t\t\t// Delete old ID screenshot\n\t\t\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.deleteSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.variationID,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...deleteSliceScreenshotErrors);\n\n\t\t\t\t\t// Create new ID screenshot\n\t\t\t\t\tconst { errors: updateSliceScreenshotErrors } =\n\t\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tvariationID: args.model.id,\n\t\t\t\t\t\t\tdata: screenshot,\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceScreenshotErrors);\n\t\t\t\t}\n\n\t\t\t\t// Renaming mocks\n\t\t\t\tconst { mocks, errors: readSliceMocksErrors } =\n\t\t\t\t\tawait this.readSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t});\n\t\t\t\tassetsErrors.push(...readSliceMocksErrors);\n\n\t\t\t\tif (mocks?.length) {\n\t\t\t\t\tconst { errors: updateSliceMocksErrors } =\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\t\tmocks: mocks.map((mock) => {\n\t\t\t\t\t\t\t\tif (mock.variation === args.variationID) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t...mock,\n\t\t\t\t\t\t\t\t\t\tvariation: args.model.id,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn mock;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t});\n\t\t\t\t\tassetsErrors.push(...updateSliceMocksErrors);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync deleteSliceVariation(\n\t\targs: SliceMachineManagerDeleteSliceVariationArgs,\n\t): Promise<SliceMachineManagerDeleteSliceVariationReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\t// Remove variation from model and update it\n\t\t\tconst updatedModel = {\n\t\t\t\t...model,\n\t\t\t\tvariations: model.variations.filter(\n\t\t\t\t\t(variation) => variation.id !== args.variationID,\n\t\t\t\t),\n\t\t\t};\n\t\t\tconst updateSliceHookResult =\n\t\t\t\tawait this.sliceMachinePluginRunner.callHook(\"slice:update\", {\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel: updatedModel,\n\t\t\t\t});\n\n\t\t\t// Cleanup deleted variation screenshot\n\t\t\tconst { errors: deleteSliceScreenshotErrors } =\n\t\t\t\tawait this.deleteSliceScreenshot(args);\n\n\t\t\t// Cleanup deleted variation mocks\n\t\t\tconst { mocks, errors: readSliceMocksErrors } = await this.readSliceMocks(\n\t\t\t\t{\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t},\n\t\t\t);\n\t\t\tlet updateSliceMocksErrors: SliceMachineManagerUpdateSliceMocksArgsReturnType[\"errors\"] =\n\t\t\t\t[];\n\t\t\tif (mocks?.length) {\n\t\t\t\tupdateSliceMocksErrors = (\n\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\tsliceID: args.sliceID,\n\t\t\t\t\t\tmocks: mocks.filter((mock) => mock.variation !== args.variationID),\n\t\t\t\t\t})\n\t\t\t\t).errors;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\terrors: updateSliceHookResult.errors,\n\t\t\t\tassetsErrors: [\n\t\t\t\t\t...deleteSliceScreenshotErrors,\n\t\t\t\t\t...readSliceMocksErrors,\n\t\t\t\t\t...updateSliceMocksErrors,\n\t\t\t\t],\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readSliceErrors,\n\t\t\t\tassetsErrors: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync convertLegacySliceToSharedSlice(\n\t\targs: SliceMachineManagerConvertLegacySliceToSharedSliceArgs,\n\t): Promise<SliceMachineManagerConvertLegacySliceToSharedSliceReturnType> {\n\t\tconst errors: (DecodeError | HookError)[] = [];\n\n\t\tconst { model: maybeExistingSlice } = await this.readSlice({\n\t\t\tlibraryID: args.dest.libraryID,\n\t\t\tsliceID: args.dest.sliceID,\n\t\t});\n\n\t\tconst legacySliceAsVariation: Variation = {\n\t\t\tid: args.dest.variationID,\n\t\t\tname: args.dest.variationName,\n\t\t\tdescription: args.dest.variationName,\n\t\t\timageUrl: \"\",\n\t\t\tdocURL: \"\",\n\t\t\tversion: \"initial\",\n\t\t\tprimary: {},\n\t\t\titems: {},\n\t\t};\n\n\t\tswitch (args.model.type) {\n\t\t\tcase \"Slice\":\n\t\t\t\tlegacySliceAsVariation.primary = args.model[\"non-repeat\"];\n\t\t\t\tlegacySliceAsVariation.items = args.model.repeat;\n\t\t\t\tbreak;\n\n\t\t\tcase \"Group\":\n\t\t\t\tlegacySliceAsVariation.items = args.model.config?.fields ?? {};\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tlegacySliceAsVariation.primary = { [args.src.sliceID]: args.model };\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// Convert as a slice variation, or merge against an existing slice variation\n\t\tif (maybeExistingSlice) {\n\t\t\tconst maybeVariation = maybeExistingSlice.variations.find(\n\t\t\t\t(variation) => variation.id === args.dest.variationID,\n\t\t\t);\n\n\t\t\t// If we're not merging against an existing slice variation, then we need to insert the new variation\n\t\t\tif (!maybeVariation) {\n\t\t\t\tmaybeExistingSlice.variations = [\n\t\t\t\t\t...maybeExistingSlice.variations,\n\t\t\t\t\tlegacySliceAsVariation,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tmaybeExistingSlice.legacyPaths ||= {};\n\t\t\tmaybeExistingSlice.legacyPaths[\n\t\t\t\t`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`\n\t\t\t] = args.dest.variationID;\n\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: maybeExistingSlice,\n\t\t\t});\n\t\t} else {\n\t\t\t// Convert to new shared slice\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.dest.libraryID,\n\t\t\t\tmodel: {\n\t\t\t\t\tid: args.dest.sliceID,\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t\tname: args.dest.sliceID,\n\t\t\t\t\tlegacyPaths: {\n\t\t\t\t\t\t[`${args.src.customTypeID}::${args.src.sliceZoneID}::${args.src.sliceID}`]:\n\t\t\t\t\t\t\targs.dest.variationID,\n\t\t\t\t\t},\n\t\t\t\t\tvariations: [legacySliceAsVariation],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Update source custom type\n\t\tconst { model: customType, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readCustomType({\n\t\t\t\tid: args.src.customTypeID,\n\t\t\t});\n\t\terrors.push(...customTypeReadErrors);\n\n\t\tif (customType) {\n\t\t\tconst field = customType.json[args.src.tabID][args.src.sliceZoneID];\n\n\t\t\t// Convert legacy slice definition in slice zone to shared slice reference\n\t\t\tif (field.type === \"Slices\" && field.config?.choices) {\n\t\t\t\tdelete field.config.choices[args.src.sliceID];\n\t\t\t\tfield.config.choices[args.dest.sliceID] = {\n\t\t\t\t\ttype: \"SharedSlice\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { errors: customTypeUpdateErrors } =\n\t\t\t\tawait this.customTypes.updateCustomType({ model: customType });\n\t\t\terrors.push(...customTypeUpdateErrors);\n\t\t}\n\n\t\treturn { errors };\n\t}\n\n\t/**\n\t * @returns Record of variation IDs mapped to uploaded screenshot URLs.\n\t */\n\tasync pushSlice(\n\t\targs: SliceMachineManagerPushSliceArgs,\n\t): Promise<SliceMachineManagerPushSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\tconst { model, errors: readSliceErrors } = await this.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst modelWithScreenshots =\n\t\t\t\tawait this.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tmodel,\n\t\t\t\t});\n\n\t\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Slice already exists on the repository.\n\t\t\t\tawait client.getSharedSliceByID(args.sliceID);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateSharedSlice(modelWithScreenshots);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If the Slice doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertSharedSlice(modelWithScreenshots);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push Slices to this Prismic repository.\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Pass the error through if it isn't the one we were expecting.\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst screenshotURLs: Record<string, string> = {};\n\t\t\tfor (const variation of modelWithScreenshots.variations) {\n\t\t\t\tscreenshotURLs[variation.id] = variation.imageUrl;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tscreenshotURLs,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tscreenshotURLs: undefined,\n\t\t\t\terrors: readSliceErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync readSliceScreenshot(\n\t\targs: SliceMachineManagerReadSliceScreenshotArgs,\n\t): Promise<SliceMachineManagerReadSliceScreenshotReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: bufferCodec,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tdata: data[0]?.data,\n\t\t\terrors: errors,\n\t\t};\n\t}\n\n\tasync updateSliceScreenshot(\n\t\targs: SliceMachineManagerUpdateSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: `screenshot-${args.variationID}.png`,\n\t\t\t\t\tdata: args.data,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteSliceScreenshot(\n\t\targs: SliceMachineManagerDeleteSliceScreenshotArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<SliceAssetUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:delete\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `screenshot-${args.variationID}.png`,\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readSliceMocks(\n\t\targs: SliceMachineManagerReadSliceMocksArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: `mocks.json`,\n\t\t\t},\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tdata: t.array(SharedSliceContent),\n\t\t\t}),\n\t\t\t{\n\t\t\t\t...hookResult,\n\t\t\t\t// Convert the asset data from a Buffer to JSON\n\t\t\t\t// to prepare it for validation.\n\t\t\t\tdata: hookResult.data.map((result) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tdata: JSON.parse(result.data.toString()),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocks: data[0]?.data,\n\t\t\t\terrors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocks: [],\n\t\t\t\terrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync updateSliceMocks(\n\t\targs: SliceMachineManagerUpdateSliceMocksArgs,\n\t): Promise<SliceMachineManagerUpdateSliceMocksArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:update\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocks, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\t// TODO: Remove\n\tasync readSliceMocksConfig(\n\t\targs: SliceMachineManagerReadSliceMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadSliceMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"slice:asset:read\",\n\t\t\t{\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.sliceID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync fetchRemoteSlices(): Promise<SharedSlice[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllSharedSlices();\n\t}\n\n\tasync updateSliceModelScreenshotsInPlace(\n\t\targs: SlicesManagerUpsertHostedSliceScrenshotsArgs,\n\t): Promise<SharedSlice> {\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst variations = await Promise.all(\n\t\t\targs.model.variations.map(async (variation) => {\n\t\t\t\tconst screenshot = await this.readSliceScreenshot({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID: args.model.id,\n\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t});\n\n\t\t\t\t// If there's no screenshot, delete it by replacing it with the default screenshot\n\t\t\t\tif (!screenshot.data) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...variation,\n\t\t\t\t\t\timageUrl: DEFAULT_SLICE_SCREENSHOT_URL,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst hasScreenshotChanged = !variation.imageUrl?.includes(\n\t\t\t\t\tcreateContentDigest(screenshot.data),\n\t\t\t\t);\n\n\t\t\t\t// If screenshot hasn't changed, do nothing\n\t\t\t\tif (!hasScreenshotChanged) {\n\t\t\t\t\treturn variation;\n\t\t\t\t}\n\n\t\t\t\tconst keyPrefix = [\n\t\t\t\t\trepositoryName,\n\t\t\t\t\t\"shared-slices\",\n\t\t\t\t\targs.model.id,\n\t\t\t\t\tvariation.id,\n\t\t\t\t].join(\"/\");\n\n\t\t\t\tconst uploadedScreenshot = await this.screenshots.uploadScreenshot({\n\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\tkeyPrefix,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\t...variation,\n\t\t\t\t\timageUrl: uploadedScreenshot.url,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\t...args.model,\n\t\t\tvariations,\n\t\t};\n\t}\n\n\tprivate async _removeSliceFromCustomTypes(sliceID: string) {\n\t\tconst { models, errors: customTypeReadErrors } =\n\t\t\tawait this.customTypes.readAllCustomTypes();\n\n\t\t// Successfully update all custom types or throw\n\t\tawait Promise.all(\n\t\t\tmodels.map(async (customType) => {\n\t\t\t\tconst updatedJsonModel = Object.entries(customType.model.json).reduce(\n\t\t\t\t\t(tabAccumulator, [tabKey, tab]) => {\n\t\t\t\t\t\tconst updatedTabFields = Object.entries(tab).reduce(\n\t\t\t\t\t\t\t(fieldAccumulator, [fieldKey, field]) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tfield.config === undefined ||\n\t\t\t\t\t\t\t\t\tfield.type !== \"Slices\" ||\n\t\t\t\t\t\t\t\t\tfield.config.choices === undefined\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\treturn { ...fieldAccumulator, [fieldKey]: field };\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst filteredChoices = Object.entries(\n\t\t\t\t\t\t\t\t\tfield.config.choices,\n\t\t\t\t\t\t\t\t).reduce((choiceAccumulator, [choiceKey, choice]) => {\n\t\t\t\t\t\t\t\t\tif (choiceKey === sliceID) {\n\t\t\t\t\t\t\t\t\t\treturn choiceAccumulator;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn { ...choiceAccumulator, [choiceKey]: choice };\n\t\t\t\t\t\t\t\t}, {});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...fieldAccumulator,\n\t\t\t\t\t\t\t\t\t[fieldKey]: {\n\t\t\t\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\t\t\t\tconfig: { ...field.config, choices: filteredChoices },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn { ...tabAccumulator, [tabKey]: updatedTabFields };\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t);\n\n\t\t\t\tawait this.customTypes.updateCustomType({\n\t\t\t\t\tmodel: { ...customType.model, json: updatedJsonModel },\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\n\t\treturn { errors: customTypeReadErrors };\n\t}\n\n\tasync generateSlice(\n\t\targs: SliceMachineManagerGenerateSliceArgs,\n\t): Promise<SliceMachineManagerGenerateSliceReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst INPUT_TOKEN_PRICE = 0.000003;\n\t\tconst OUTPUT_TOKEN_PRICE = 0.000015;\n\n\t\tlet totalTokens = {\n\t\t\tmodelGeneration: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\ttotal: 0,\n\t\t\t\tprice: 0,\n\t\t\t},\n\t\t\tmocksGeneration: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\ttotal: 0,\n\t\t\t\tprice: 0,\n\t\t\t},\n\t\t\tcodeGeneration: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\ttotal: 0,\n\t\t\t\tprice: 0,\n\t\t\t},\n\t\t};\n\n\t\t// Validate AWS credentials\n\t\tconst AWS_REGION = \"us-east-1\";\n\t\tconst { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } = process.env;\n\t\tif (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY) {\n\t\t\tthrow new Error(\"AWS credentials are not set.\");\n\t\t}\n\n\t\t/**\n\t\t * TypeScript schema for the Shared Slice definition.\n\t\t */\n\t\tconst SHARED_SLICE_SCHEMA = `\n/**\n * Represents a Prismic Slice.\n * @property {string} type - Should always be \"SharedSlice\".\n * @property {string} id - Unique identifier for the slice in snake_case.\n * @property {string} name - Human-readable name in PascalCase.\n * @property {string} description - Brief explanation of the slice's purpose.\n * @property {SliceVariation[]} variations - Array of variations for the slice.\n */\ntype PrismicSlice = {\n type: \"SharedSlice\";\n id: string;\n name: string;\n description: string;\n variations: SliceVariation[];\n};\n\n/**\n * Represents a variation of a Prismic Slice.\n */\ntype SliceVariation = {\n id: string;\n name: string;\n description: string;\n primary: Record<string, PrismicField>;\n docURL: string;\n version: string;\n};\n\n/**\n * Union type representing all possible Prismic fields.\n */\ntype PrismicField =\n | UIDField\n | BooleanField\n | ColorField\n | DateField\n | TimestampField\n | NumberField\n | KeyTextField\n | SelectField\n | StructuredTextField\n | ImageField\n | LinkField\n | GeoPointField\n | EmbedField\n | GroupField;\n\n/* Definitions for each field type follow... */\n\n/**\n * Represents a UID Field in Prismic.\n * @property {\"UID\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n * @property {string} [config.customregex] - Custom regex for validation.\n * @property {string} [config.errorMessage] - Error message for invalid input.\n */\ntype UIDField = {\n\ttype: \"UID\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t\tcustomregex?: string;\n\t\terrorMessage?: string;\n\t};\n};\n\n/**\n * Represents a Boolean Field in Prismic.\n * @property {\"Boolean\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {boolean} [config.default_value] - Default value (true or false).\n */\ntype BooleanField = {\n\ttype: \"Boolean\";\n\tconfig: {\n\t\tlabel: string;\n\t\tdefault_value?: boolean;\n\t};\n};\n\n/**\n * Represents a Color Field in Prismic.\n * @property {\"Color\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype ColorField = {\n\ttype: \"Color\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Date Field in Prismic.\n * @property {\"Date\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype DateField = {\n\ttype: \"Date\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Timestamp Field in Prismic.\n * @property {\"Timestamp\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype TimestampField = {\n\ttype: \"Timestamp\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Number Field in Prismic.\n * @property {\"Number\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n * @property {number} [config.min] - Minimum allowable value.\n * @property {number} [config.max] - Maximum allowable value.\n */\ntype NumberField = {\n\ttype: \"Number\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t\tmin?: number;\n\t\tmax?: number;\n\t};\n};\n\n/**\n * Represents a Key Text Field in Prismic.\n * @property {\"Text\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n */\ntype KeyTextField = {\n\ttype: \"Text\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t};\n};\n\n/**\n * Represents a Select Field in Prismic.\n * @property {\"Select\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string[]} config.options - Array of options for the select dropdown.\n */\ntype SelectField = {\n\ttype: \"Select\";\n\tconfig: {\n\t\tlabel: string;\n\t\toptions: string[];\n\t};\n};\n\n/**\n * Represents a Structured Text Field in Prismic.\n * @property {\"StructuredText\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n * @property {string} [config.single] - A comma-separated list of formatting options that does not allow line breaks. Options: paragraph | preformatted | heading1 | heading2 | heading3 | heading4 | heading5 | heading6 | strong | em | hyperlink | image | embed | list-item | o-list-item | rtl.\n * @property {string} [config.multi] - A comma-separated list of formatting options, with paragraph breaks allowed. Options: paragraph | preformatted | heading1 | heading2 | heading3 | heading4 | heading5 | heading6 | strong | em | hyperlink | image | embed | list-item | o-list-item | rtl.\n * @property {boolean} [config.allowTargetBlank] - Allows links to open in a new tab.\n * @property {string[]} [config.labels] - An array of strings to define labels for custom formatting.\n * @property {ImageConstraint} [config.imageConstraint] - Constraints for images within the rich text field.\n */\ntype StructuredTextField = {\n\ttype: \"StructuredText\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t\tsingle?: string;\n\t\tmulti?: string;\n\t\tallowTargetBlank?: boolean;\n\t\tlabels?: string[];\n\t\timageConstraint?: ImageConstraint;\n\t};\n};\n\n/**\n * Represents constraints for images within a rich text field.\n * @property {number} [width] - Width constraint in pixels.\n * @property {number\n * @property {number} [height] - Height constraint in pixels.\n */\ntype ImageConstraint = {\n\twidth?: number;\n\theight?: number;\n};\n\n/**\n * Represents an Image Field in Prismic.\n * @property {\"Image\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {Object} [config.constraint] - Constraints for the image dimensions.\n * @property {number} [config.constraint.width] - Width constraint.\n * @property {number} [config.constraint.height] - Height constraint.\n * @property {Thumbnail[]} [config.thumbnails] - Array of thumbnail configurations.\n */\ntype ImageField = {\n\ttype: \"Image\";\n\tconfig: {\n\t\tlabel: string;\n\t\tconstraint?: {\n\t\t\twidth?: number;\n\t\t\theight?: number;\n\t\t};\n\t\tthumbnails?: Thumbnail[];\n\t};\n};\n\n/**\n * Represents a Thumbnail configuration for an Image field.\n * @property {string} name - Name of the thumbnail.\n * @property {number} [width] - Width of the thumbnail in pixels.\n * @property {number} [height] - Height of the thumbnail in pixels.\n */\ntype Thumbnail = {\n\tname: string;\n\twidth?: number;\n\theight?: number;\n};\n\n/**\n * Represents a Link Field in Prismic.\n * @property {\"Link\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n* @property {boolean} config.allowText - Enable the text field for the link.\n */\ntype LinkField = {\n\ttype: \"Link\";\n\tconfig: {\n\t\tlabel: string;\n\t\tallowText: boolean;\n\t};\n};\n\n/**\n * Represents an Embed Field in Prismic.\n * @property {\"Embed\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype EmbedField = {\n\ttype: \"Embed\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a GeoPoint Field in Prismic.\n * @property {\"GeoPoint\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype GeoPointField = {\n\ttype: \"GeoPoint\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Group Field (Repeatable Fields) in Prismic.\n * @property {\"Group\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {Record<string, PrismicField>} config.fields - Defines the fields inside the group.\n */\ntype GroupField = {\n\ttype: \"Group\";\n\tconfig: {\n\t\tlabel: string;\n\t\tfields: Record<string, PrismicField>;\n\t};\n};\n`;\n\n\t\t/**\n\t\t * Calls the AI to generate the slice model.\n\t\t */\n\t\tasync function generateSliceModel(\n\t\t\tclient: BedrockRuntimeClient,\n\t\t\texistingSlice: SharedSlice,\n\t\t\timageFile: Uint8Array,\n\t\t): Promise<SharedSlice> {\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are an expert in Prismic content modeling. Using the image provided, generate a valid Prismic JSON model for the slice described below. Follow these rules precisely:\n\t\t\t\t- Use the TypeScript schema provided as your reference.\n\t\t\t\t- Place all main content fields under the \"primary\" object.\n\t\t\t\t- Do not create any collections or groups for single-image content (background images should be a single image field).\n\t\t\t\t- Ensure that each field has appropriate placeholders, labels, and configurations.\n\t\t\t\t- Never generate a Link / Button text field, only the Link / Button field itself is enough. Just enable \"allowText\" when doing that.\n\t\t\t\t- Do not forget any field visible from the image provide in the user prompt.\n\t\t\t\t- Ensure to differentiate Prismic fields from just an image with visual inside the image. When that's the case, just add a Prismic image field.\n\t\t\t\t- Do not include any decorative fields.\n\t\t\t\t- Do not include any extra commentary or formatting.\n\t\n\t\t\t\t!IMPORTANT!: \n\t\t\t\t\t- Only return a valid JSON object representing the full slice model, nothing else before. JSON.parse on your response should not throw an error.\n\t\t\t\t\t- All your response should fit in a single return response.\n\n\t\t\t\tReference Schema:\n\t\t\t\t${SHARED_SLICE_SCHEMA}\n\t\t\t\t\n\t\t\t\tExisting Slice:\n\t\t\t\t${JSON.stringify(existingSlice)}\n\t\t\t`.trim();\n\t\t\tconst command = new ConverseCommand({\n\t\t\t\tmodelId: \"us.anthropic.claude-3-5-sonnet-20241022-v2:0\",\n\t\t\t\tsystem: [{ text: systemPrompt }],\n\t\t\t\tmessages: [\n\t\t\t\t\t{\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\timage: { format: \"png\", source: { bytes: imageFile } },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tconst response = await client.send(command);\n\t\t\tconsole.log(\"Generated model response:\", JSON.stringify(response));\n\n\t\t\tif (\n\t\t\t\t!response.usage ||\n\t\t\t\t!response.usage.inputTokens ||\n\t\t\t\t!response.usage.outputTokens ||\n\t\t\t\t!response.usage.totalTokens\n\t\t\t) {\n\t\t\t\tthrow new Error(\"No usage data was returned.\");\n\t\t\t}\n\t\t\ttotalTokens.modelGeneration = {\n\t\t\t\tinput: response.usage.inputTokens,\n\t\t\t\toutput: response.usage.outputTokens,\n\t\t\t\ttotal: response.usage.totalTokens,\n\t\t\t\tprice:\n\t\t\t\t\tresponse.usage.inputTokens * INPUT_TOKEN_PRICE +\n\t\t\t\t\tresponse.usage.outputTokens * OUTPUT_TOKEN_PRICE,\n\t\t\t};\n\n\t\t\tconst resultText = response.output?.message?.content?.[0]?.text?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid slice model was generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst generatedModel = JSON.parse(resultText);\n\t\t\t\tconst updatedSlice: SharedSlice = {\n\t\t\t\t\t...args.slice,\n\t\t\t\t\tvariations: generatedModel.variations,\n\t\t\t\t};\n\n\t\t\t\treturn updatedSlice;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\"Failed to parse AI response for model: \" + error);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Calls the AI endpoint to generate mocks.\n\t\t */\n\t\tasync function generateSliceMocks(\n\t\t\tclient: BedrockRuntimeClient,\n\t\t\timageFile: Uint8Array,\n\t\t\texistingMocks: SharedSliceContent[],\n\t\t): Promise<SharedSliceContent[]> {\n\t\t\t// Build a prompt focused solely on updating the mocks.\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are a seasoned frontend engineer with deep expertise in Prismic slices.\n\t\t\t\tYour task is to update the provided mocks template based solely on the visible content in the image.\n\t\t\t\tFollow these guidelines strictly:\n\t\t\t\t\t- Do not modify the overall structure of the mocks template.\n\t\t\t\t\t- Strictly only update text content.\n\t\t\t\t\t- Do not touch images.\n\t\t\t\t\t- If you see a repetition with a group, you must create the same number of group items that are visible on the image.\n\n\t\t\t\t!IMPORTANT!: \n\t\t\t\t\t- Only return a valid JSON object for mocks, nothing else before. JSON.parse on your response should not throw an error.\n\t\t\t\t\t- All your response should fit in a single return response.\n\t\t\t\t\n\t\t\t\tExisting Mocks Template:\n\t\t\t\t${JSON.stringify(existingMocks, null, 2)}\n\t\t\t`.trim();\n\n\t\t\tconst command = new ConverseCommand({\n\t\t\t\tmodelId: \"us.anthropic.claude-3-5-sonnet-20241022-v2:0\",\n\t\t\t\tsystem: [{ text: systemPrompt }],\n\t\t\t\tmessages: [\n\t\t\t\t\t{\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ image: { format: \"png\", source: { bytes: imageFile } } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tconst response = await client.send(command);\n\t\t\tconsole.log(\"Generated mocks response:\", JSON.stringify(response));\n\n\t\t\tif (\n\t\t\t\t!response.usage ||\n\t\t\t\t!response.usage.inputTokens ||\n\t\t\t\t!response.usage.outputTokens ||\n\t\t\t\t!response.usage.totalTokens\n\t\t\t) {\n\t\t\t\tthrow new Error(\"No usage data was returned.\");\n\t\t\t}\n\t\t\ttotalTokens.mocksGeneration = {\n\t\t\t\tinput: response.usage.inputTokens,\n\t\t\t\toutput: response.usage.outputTokens,\n\t\t\t\ttotal: response.usage.totalTokens,\n\t\t\t\tprice:\n\t\t\t\t\tresponse.usage.inputTokens * INPUT_TOKEN_PRICE +\n\t\t\t\t\tresponse.usage.outputTokens * OUTPUT_TOKEN_PRICE,\n\t\t\t};\n\n\t\t\tconst resultText = response.output?.message?.content?.[0]?.text?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid mocks were generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst updatedMocks = JSON.parse(resultText);\n\n\t\t\t\treturn updatedMocks;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\"Failed to parse AI response for mocks: \" + error);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Calls the AI endpoint to generate the slice React component.\n\t\t */\n\t\tasync function generateSliceComponentCode(\n\t\t\tclient: BedrockRuntimeClient,\n\t\t\timageFile: Uint8Array,\n\t\t\texistingMocks: any,\n\t\t): Promise<string> {\n\t\t\t// Build a prompt focused solely on generating the React component code.\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are a seasoned frontend engineer with deep expertise in Prismic slices.\n\t\t\t\tYour task is to generate a fully isolated React component code for a slice based on the provided image input.\n\t\t\t\tFollow these guidelines strictly:\n\t\t\t\t\t- Be self-contained.\n\t\t\t\t\t- Your goal is to make the code visually looks as close as possible to the image from the user input.\n\t\t\t\t\t- Ensure that the color used for the background is the same as the image provide in the user prompt! It's better no background color than a wrong one.\n\t\t\t\t\t- For links, you must use PrismicNextLink and you must just pass the field, PrismicNextLink will handle the display of the link text, don't do it manually.\n\t\t\t\t\t- Respect the padding and margin visible in the image provide in the user prompt.\n\t\t\t\t\t- Respect the fonts size, color, type visible in the image provide in the user prompt.\n\t\t\t\t\t- Respect the colors visible in the image provide in the user prompt.\n\t\t\t\t\t- Respect the position of elements visible in the image provide in the user prompt.\n\t\t\t\t\t- Respect the size of each elements visible in the image provide in the user prompt.\n\t\t\t\t\t- Respect the overall proportions of the slice from the image provide in the user prompt.\n\t\t\t\t\t- Ensure to strictly respect what is defined on the mocks for each fields ID, do not invent or use something not in the mocks.\n\t\t\t\t\t- Ensure to use all fields provided in the mocks.\n\t\t\t\t\t- Use inline <style> (do not use <style jsx>).\n\t\t\t\t\t- Follow the structure provided in the code example below.\n\n\t\t\t\t!IMPORTANT!: \n\t\t\t\t\t- Only return a valid JSON object with two keys: \"mocks\" and \"componentCode\", nothing else before. JSON.parse on your response should not throw an error.\n\t\t\t\t\t- All your response should fit in a single return response.\n\t\t\t\t\n\t\t\t\t## Example of a Fully Isolated Slice Component:\n\t\t\t\t-----------------------------------------------------------\n\t\t\t\timport { type Content } from \"@prismicio/client\";\n\t\t\t\timport { PrismicNextLink, PrismicNextImage } from \"@prismicio/next\";\n\t\t\t\timport { SliceComponentProps, PrismicRichText } from \"@prismicio/react\";\n\t\t\t\t\n\t\t\t\texport type HeroProps = SliceComponentProps<Content.HeroSlice>;\n\t\t\t\t\n\t\t\t\tconst Hero = ({ slice }: HeroProps): JSX.Element => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t\tclassName=\"hero\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t<div className=\"hero__content\">\n\t\t\t\t\t\t\t<div className=\"hero__image-wrapper\">\n\t\t\t\t\t\t\t\t<PrismicNextImage field={slice.primary.image} className=\"hero__image\" />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div className=\"hero__text\">\n\t\t\t\t\t\t\t\t<PrismicRichText field={slice.primary.title} />\n\t\t\t\t\t\t\t\t<PrismicRichText field={slice.primary.description} />\n\t\t\t\t\t\t\t\t<PrismicNextLink field={slice.primary.link} />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t{\\`\n\t\t\t\t\t\t\t\t.hero { display: flex; flex-direction: row; padding: 20px; }\n\t\t\t\t\t\t\t\t.hero__content { width: 100%; }\n\t\t\t\t\t\t\t\t.hero__image-wrapper { flex: 1; }\n\t\t\t\t\t\t\t\t.hero__text { flex: 1; padding-left: 20px; }\n\t\t\t\t\t\t\t\\`}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t\t</section>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\texport default Hero;\n\t\t\t\t-----------------------------------------------------------\n\t\t\t\tExisting Mocks Template:\n\t\t\t\t${JSON.stringify(existingMocks, null, 2)}\n\t\t\t`.trim();\n\n\t\t\tconst command = new ConverseCommand({\n\t\t\t\tmodelId: \"us.anthropic.claude-3-5-sonnet-20241022-v2:0\",\n\t\t\t\tsystem: [{ text: systemPrompt }],\n\t\t\t\tmessages: [\n\t\t\t\t\t{\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ image: { format: \"png\", source: { bytes: imageFile } } },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tconst response = await client.send(command);\n\t\t\tconsole.log(\n\t\t\t\t\"Generated component code response:\",\n\t\t\t\tJSON.stringify(response),\n\t\t\t);\n\n\t\t\tif (\n\t\t\t\t!response.usage ||\n\t\t\t\t!response.usage.inputTokens ||\n\t\t\t\t!response.usage.outputTokens ||\n\t\t\t\t!response.usage.totalTokens\n\t\t\t) {\n\t\t\t\tthrow new Error(\"No usage data was returned.\");\n\t\t\t}\n\t\t\ttotalTokens.codeGeneration = {\n\t\t\t\tinput: response.usage.inputTokens,\n\t\t\t\toutput: response.usage.outputTokens,\n\t\t\t\ttotal: response.usage.totalTokens,\n\t\t\t\tprice:\n\t\t\t\t\tresponse.usage.inputTokens * INPUT_TOKEN_PRICE +\n\t\t\t\t\tresponse.usage.outputTokens * OUTPUT_TOKEN_PRICE,\n\t\t\t};\n\n\t\t\tconst resultText = response.output?.message?.content?.[0]?.text?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid slice component code was generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(resultText);\n\t\t\t\tif (!parsed.componentCode) {\n\t\t\t\t\tthrow new Error(\"Missing key 'componentCode' in AI response.\");\n\t\t\t\t}\n\t\t\t\treturn parsed.componentCode;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Failed to parse AI response for component code: \" + error,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Initialize AWS Bedrock client.\n\t\tconst bedrockClient = new BedrockRuntimeClient({\n\t\t\tregion: AWS_REGION,\n\t\t\tcredentials: {\n\t\t\t\taccessKeyId: AWS_ACCESS_KEY_ID,\n\t\t\t\tsecretAccessKey: AWS_SECRET_ACCESS_KEY,\n\t\t\t},\n\t\t});\n\n\t\ttry {\n\t\t\t// ----- Q1 scope -----\n\n\t\t\t// STEP 1: Generate the slice model using the image.\n\t\t\tconsole.log(\"STEP 1: Generate the slice model using the image.\");\n\t\t\tconst updatedSlice = await generateSliceModel(\n\t\t\t\tbedrockClient,\n\t\t\t\targs.slice,\n\t\t\t\targs.imageFile,\n\t\t\t);\n\n\t\t\t// STEP 2: Persist the updated slice model.\n\t\t\tconsole.log(\"STEP 2: Persist the updated slice model.\");\n\t\t\tawait this.updateSlice({\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tmodel: updatedSlice,\n\t\t\t});\n\n\t\t\t// STEP 3: Update the slice screenshot.\n\t\t\tconsole.log(\"STEP 3: Update the slice screenshot.\");\n\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: updatedSlice.id,\n\t\t\t\tvariationID: updatedSlice.variations[0].id,\n\t\t\t\tdata: Buffer.from(args.imageFile),\n\t\t\t});\n\n\t\t\t// ----- Q1 scope -----\n\n\t\t\t// STEP 4: Generate updated mocks.\n\t\t\tconsole.log(\"STEP 4: Generate updated mocks.\");\n\t\t\tconst existingMocks = mockSlice({ model: updatedSlice });\n\t\t\tconst updatedMocks = await generateSliceMocks(\n\t\t\t\tbedrockClient,\n\t\t\t\targs.imageFile,\n\t\t\t\texistingMocks,\n\t\t\t);\n\n\t\t\t// STEP 5: Generate the isolated slice component code.\n\t\t\tconsole.log(\"STEP 5: Generate updated component code.\");\n\t\t\tconst componentCode = await generateSliceComponentCode(\n\t\t\t\tbedrockClient,\n\t\t\t\targs.imageFile,\n\t\t\t\texistingMocks,\n\t\t\t);\n\n\t\t\t// STEP 6: Update the slice code.\n\t\t\tconsole.log(\"STEP 6: Update the slice code.\");\n\t\t\tawait this.createSlice({\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tmodel: updatedSlice,\n\t\t\t\tcomponentContents: componentCode,\n\t\t\t});\n\n\t\t\t// STEP 7: Persist the generated mocks.\n\t\t\tconsole.log(\"STEP 7: Persist the generated mocks.\");\n\t\t\tawait this.updateSliceMocks({\n\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\tsliceID: args.slice.id,\n\t\t\t\tmocks: updatedMocks,\n\t\t\t});\n\n\t\t\t// Usage\n\t\t\tconsole.log(\"Tokens used:\", totalTokens);\n\t\t\tconst totalPrice = Object.values(totalTokens).reduce(\n\t\t\t\t(acc, { price }) => acc + price,\n\t\t\t\t0,\n\t\t\t);\n\t\t\tconsole.log(\"Total price:\", totalPrice);\n\n\t\t\treturn { slice: updatedSlice };\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Failed to generate slice:\", error);\n\t\t\tthrow new Error(\"Failed to generate slice: \" + error);\n\t\t}\n\t}\n\n\tasync generateSlicesFromUrl(\n\t\targs: SliceMachineManagerGenerateSlicesFromUrlArgs,\n\t): Promise<SliceMachineManagerGenerateSlicesFromUrlReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { OPENAI_API_KEY } = process.env;\n\t\tif (!OPENAI_API_KEY) {\n\t\t\tthrow new Error(\"OPENAI_API_KEY is not set.\");\n\t\t}\n\t\tconst openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\t\tconst libraryIDs = sliceMachineConfig.libraries || [];\n\t\tconst DEFAULT_LIBRARY_ID = libraryIDs[0];\n\n\t\tconst KNOWNED_WEBSITE_URLS: { [url: string]: string } = {\n\t\t\t\"https://www.criteo.com/\": \"./resources/criteo/homepage\",\n\t\t\t\"https://www.brevo.com/landing/email-marketing-service/\":\n\t\t\t\t\"./resources/brevo/mail\",\n\t\t};\n\n\t\tasync function readImagesFromFolder(\n\t\t\tfolderPath: string,\n\t\t): Promise<Uint8Array[]> {\n\t\t\tconsole.log(process.cwd());\n\n\t\t\tconst files = await fs.promises.readdir(folderPath);\n\t\t\tconst images = await Promise.all(\n\t\t\t\tfiles.map(async (file) => {\n\t\t\t\t\tconst buffer = await fs.promises.readFile(\n\t\t\t\t\t\tpath.join(folderPath, file),\n\t\t\t\t\t);\n\t\t\t\t\treturn new Uint8Array(buffer);\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\treturn images;\n\t\t}\n\n\t\tasync function readCodeFromFolder(folderPath: string): Promise<string[]> {\n\t\t\tconst files = await fs.promises.readdir(folderPath);\n\t\t\tconst codes = await Promise.all(\n\t\t\t\tfiles.map(async (file) => {\n\t\t\t\t\tconst buffer = await fs.promises.readFile(\n\t\t\t\t\t\tpath.join(folderPath, file),\n\t\t\t\t\t\t\"utf-8\",\n\t\t\t\t\t);\n\t\t\t\t\treturn buffer.toString();\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\treturn codes;\n\t\t}\n\n\t\tasync function getGlobalStyle(filePath: string): Promise<string> {\n\t\t\tconst buffer = await fs.promises\n\t\t\t\t.readFile(filePath)\n\t\t\t\t.catch(() => Buffer.from(\"\"));\n\n\t\t\treturn buffer.toString();\n\t\t}\n\n\t\t/**\n\t\t * TypeScript schema for the Shared Slice definition.\n\t\t */\n\t\tconst SHARED_SLICE_SCHEMA = `\n/**\n * Represents a Prismic Slice.\n * @property {string} type - Should always be \"SharedSlice\".\n * @property {string} id - Unique identifier for the slice in snake_case.\n * @property {string} name - Human-readable name in PascalCase.\n * @property {string} description - Brief explanation of the slice's purpose.\n * @property {SliceVariation[]} variations - Array of variations for the slice.\n */\ntype PrismicSlice = {\n type: \"SharedSlice\";\n id: string;\n name: string;\n description: string;\n variations: SliceVariation[];\n};\n\n/**\n * Represents a variation of a Prismic Slice.\n * TIPS: Never use \"items\" property, you can see it doesn't exist here!\n */\ntype SliceVariation = {\n id: string;\n name: string;\n description: string;\n primary: Record<string, PrismicField>;\n docURL: string;\n version: string;\n};\n\n/**\n * Union type representing all possible Prismic fields.\n */\ntype PrismicField =\n | UIDField\n | BooleanField\n | ColorField\n | DateField\n | TimestampField\n | NumberField\n | TextField\n | SelectField\n | StructuredTextField\n | ImageField\n | LinkField\n | GeoPointField\n | EmbedField\n | GroupField;\n\n/* Definitions for each field type follow... */\n\n/**\n * Represents a UID Field in Prismic.\n * @property {\"UID\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n * @property {string} [config.customregex] - Custom regex for validation.\n * @property {string} [config.errorMessage] - Error message for invalid input.\n */\ntype UIDField = {\n\ttype: \"UID\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t\tcustomregex?: string;\n\t\terrorMessage?: string;\n\t};\n};\n\n/**\n * Represents a Boolean Field in Prismic.\n * @property {\"Boolean\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {boolean} [config.default_value] - Default value (true or false).\n */\ntype BooleanField = {\n\ttype: \"Boolean\";\n\tconfig: {\n\t\tlabel: string;\n\t\tdefault_value?: boolean;\n\t};\n};\n\n/**\n * Represents a Color Field in Prismic.\n * @property {\"Color\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype ColorField = {\n\ttype: \"Color\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Date Field in Prismic.\n * @property {\"Date\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype DateField = {\n\ttype: \"Date\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Timestamp Field in Prismic.\n * @property {\"Timestamp\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype TimestampField = {\n\ttype: \"Timestamp\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Number Field in Prismic.\n * @property {\"Number\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n * @property {number} [config.min] - Minimum allowable value.\n * @property {number} [config.max] - Maximum allowable value.\n */\ntype NumberField = {\n\ttype: \"Number\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t\tmin?: number;\n\t\tmax?: number;\n\t};\n};\n\n/**\n * Represents a Text Field in Prismic.\n * @property {\"Text\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n */\ntype TextField = {\n\ttype: \"Text\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t};\n};\n\n/**\n * Represents a Select Field in Prismic.\n * @property {\"Select\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string[]} config.options - Array of options for the select dropdown.\n */\ntype SelectField = {\n\ttype: \"Select\";\n\tconfig: {\n\t\tlabel: string;\n\t\toptions: string[];\n\t};\n};\n\n/**\n * Represents a Structured Text Field in Prismic.\n * @property {\"StructuredText\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {string} [config.placeholder] - Placeholder text.\n * @property {string} [config.single] - A comma-separated list of formatting options that does not allow line breaks. Options: paragraph | preformatted | heading1 | heading2 | heading3 | heading4 | heading5 | heading6 | strong | em | hyperlink | image | embed | list-item | o-list-item | rtl.\n * @property {string} [config.multi] - A comma-separated list of formatting options, with paragraph breaks allowed. Options: paragraph | preformatted | heading1 | heading2 | heading3 | heading4 | heading5 | heading6 | strong | em | hyperlink | image | embed | list-item | o-list-item | rtl.\n * @property {boolean} [config.allowTargetBlank] - Allows links to open in a new tab.\n * @property {string[]} [config.labels] - An array of strings to define labels for custom formatting.\n * @property {ImageConstraint} [config.imageConstraint] - Constraints for images within the rich text field.\n */\ntype StructuredTextField = {\n\ttype: \"StructuredText\";\n\tconfig: {\n\t\tlabel: string;\n\t\tplaceholder?: string;\n\t\tsingle?: string;\n\t\tmulti?: string;\n\t\tallowTargetBlank?: boolean;\n\t\tlabels?: string[];\n\t\timageConstraint?: ImageConstraint;\n\t};\n};\n\n/**\n * Represents constraints for images within a rich text field.\n * @property {number} [width] - Width constraint in pixels.\n * @property {number\n * @property {number} [height] - Height constraint in pixels.\n */\ntype ImageConstraint = {\n\twidth?: number;\n\theight?: number;\n};\n\n/**\n * Represents an Image Field in Prismic.\n * @property {\"Image\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {Object} [config.constraint] - Constraints for the image dimensions.\n * @property {number} [config.constraint.width] - Width constraint.\n * @property {number} [config.constraint.height] - Height constraint.\n * @property {Thumbnail[]} [config.thumbnails] - Array of thumbnail configurations.\n */\ntype ImageField = {\n\ttype: \"Image\";\n\tconfig: {\n\t\tlabel: string;\n\t\tconstraint?: {\n\t\t\twidth?: number;\n\t\t\theight?: number;\n\t\t};\n\t\tthumbnails?: Thumbnail[];\n\t};\n};\n\n/**\n * Represents a Thumbnail configuration for an Image field.\n * @property {string} name - Name of the thumbnail.\n * @property {number} [width] - Width of the thumbnail in pixels.\n * @property {number} [height] - Height of the thumbnail in pixels.\n */\ntype Thumbnail = {\n\tname: string;\n\twidth?: number;\n\theight?: number;\n};\n\n/**\n * Represents a Link Field in Prismic.\n * @property {\"Link\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n* @property {boolean} config.allowText - Enable the text field for the link.\n */\ntype LinkField = {\n\ttype: \"Link\";\n\tconfig: {\n\t\tlabel: string;\n\t\tallowText: boolean;\n\t};\n};\n\n/**\n * Represents an Embed Field in Prismic.\n * @property {\"Embed\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype EmbedField = {\n\ttype: \"Embed\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a GeoPoint Field in Prismic.\n * @property {\"GeoPoint\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n */\ntype GeoPointField = {\n\ttype: \"GeoPoint\";\n\tconfig: {\n\t\tlabel: string;\n\t};\n};\n\n/**\n * Represents a Group Field (Repeatable Fields) in Prismic.\n * It CAN NEVER BE PUT INSIDE ANOTHER FIELD.\n * @property {\"Group\"} type - Field type.\n * @property {Object} config - Configuration object.\n * @property {string} config.label - Label displayed in the editor.\n * @property {Record<string, PrismicField>} config.fields - Defines the fields inside the group.\n */\ntype GroupField = {\n\ttype: \"Group\";\n\tconfig: {\n\t\tlabel: string;\n\t\tfields: Record<string, PrismicField>;\n\t};\n};\n`;\n\n\t\t/**\n\t\t * Default slice model for the SharedSlice.\n\t\t */\n\t\tconst DEFAULT_SLICE_MODEL: SharedSlice = {\n\t\t\tid: \"<ID_TO_CHANGE>\",\n\t\t\ttype: \"SharedSlice\",\n\t\t\tname: \"<NAME_TO_CHANGE>\",\n\t\t\tdescription: \"<DESCRIPTION_TO_CHANGE>\",\n\t\t\tvariations: [\n\t\t\t\t{\n\t\t\t\t\tid: \"<VARIATION_ID_TO_CHANGE>\",\n\t\t\t\t\tname: \"<NAME_TO_CHANGE>\",\n\t\t\t\t\tdocURL: \"...\",\n\t\t\t\t\tversion: \"initial\",\n\t\t\t\t\tdescription: \"<DESCRIPTION_TO_CHANGE>\",\n\t\t\t\t\timageUrl: \"\",\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\t/**\n\t\t * Calls the AI to generate the slice model.\n\t\t */\n\t\tasync function generateSliceModel(\n\t\t\timageFile: Uint8Array,\n\t\t\tcodeFile: string,\n\t\t): Promise<SharedSlice> {\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are an expert in Prismic content modeling. Using the image and the code provided, generate a valid Prismic JSON model for the slice described below. Follow these rules precisely:\n\t\t\t\t- Use the TypeScript schema provided as your reference.\n\t\t\t\t- Place all main content fields under the \"primary\" object.\n\t\t\t\t- Do not create any collections or groups for single-image content (background images should be a single image field).\n\t\t\t\t- Ensure that each field has appropriate placeholders, labels, and configurations.\n\t\t\t\t- Never generate a Link / Button text field, only the Link / Button field itself is enough. Just enable \"allowText\" when doing that.\n\t\t\t\t- Do not forget any field visible from the image provide in the user prompt.\n\t\t\t\t- Ensure to differentiate Prismic fields from just an image with visual inside the image. When that's the case, just add a Prismic image field.\n\t\t\t\t- Use the code to know exactly what is a real field and not an image. If in the code it's an image, then the field should also be an image, do a 1-1 mapping thanks to the code.\n\t\t\t\t- Do not include any decorative fields. When an element is purely visual, decorative, don't include it att all in the slice model.\n\t\t\t\t- Do not include any extra commentary or formatting.\n\t\t\t\t- When you see a repetition of an image, a text, a link, etc, NEVER create one field per repeated item, you HAVE to use a group for that.\n\t\t\t\t- When you see multiple fields repeated, you MUST use a group for that.\n\t\t\t\t- NEVER put a group inside another group field, this is not allowed. In the final JSON a group CANNOT be within another group field. YOU CANNOT NEST GROUP FIELDS! Not for any reason you are allowed to do that! Even for navigation, in header or footer you cannot nest group fields.\n\t\t\t\t- The \"items\" field must not be used under any circumstances. All repeatable fields should be defined using a Group field inside the primary object. If a field represents a collection of items, it must be part of a Group field, and items must never appear in the JSON output.\n\t\t\t\t- Don't forget to replace the temporary text in the \"Existing Slice to update\", like <ID_TO_CHANGE>, <NAME_TO_CHANGE>, <DESCRIPTION_TO_CHANGE>, <VARIATION_ID_TO_CHANGE>, etc.\n\t\t\t\t- Field placeholder should be super short, do not put the content from the image inside the placeholder.\n\t\t\t\t- Field label and id should define the field's purpose, not its content.\n\t\t\t\t- Slice name and id should define the slice's purpose, not its content.\n\t\t\t\t- Slice description should be a brief explanation of the slice's purpose not its content.\n\t\t\t\n\t\t\t\t!IMPORTANT!: \n\t\t\t\t\t- Only return a valid JSON object representing the full slice model, nothing else before. JSON.parse on your response should not throw an error.\n\t\t\t\t\t- All your response should fit in a single return response.\n\t\t\t\t\t- Never stop the response until you totally finish the full JSON response you wanted.\n\n\t\t\t\tReference Schema:\n\t\t\t\t${SHARED_SLICE_SCHEMA}\n\t\t\t\t\n\t\t\t\tExisting Slice to update:\n\t\t\t\t${JSON.stringify(DEFAULT_SLICE_MODEL)}\n\t\t\t`.trim();\n\n\t\t\tconst messages: Array<ChatCompletionMessageParam> = [\n\t\t\t\t{ role: \"system\", content: systemPrompt },\n\t\t\t\t{\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\t\turl:\n\t\t\t\t\t\t\t\t\t\"data:image/png;base64,\" +\n\t\t\t\t\t\t\t\t\tBuffer.from(imageFile).toString(\"base64\"),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ type: \"text\", text: codeFile },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst response: OpenAI.Chat.Completions.ChatCompletion & {\n\t\t\t\t_request_id?: string | null;\n\t\t\t} = await openai.chat.completions.create({\n\t\t\t\tmodel: \"gpt-4o\",\n\t\t\t\tmessages,\n\t\t\t\tresponse_format: {\n\t\t\t\t\ttype: \"json_object\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.log(\"Generated model response:\", JSON.stringify(response));\n\n\t\t\tconst resultText = response.choices[0]?.message?.content?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid slice model was generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst generatedModel = JSON.parse(resultText);\n\n\t\t\t\treturn generatedModel;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\"Failed to parse AI response for model: \" + error);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Calls the AI endpoint to generate mocks.\n\t\t */\n\t\tasync function generateSliceMocks(\n\t\t\timageFile: Uint8Array,\n\t\t\texistingMocks: SharedSliceContent[],\n\t\t): Promise<SharedSliceContent[]> {\n\t\t\t// Build a prompt focused solely on updating the mocks.\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are a seasoned frontend engineer with deep expertise in Prismic slices.\n\t\t\t\tYour task is to update the provided mocks template based solely on the visible content in the image.\n\t\t\t\tFollow these guidelines strictly:\n\t\t\t\t\t- Do not modify the overall structure of the mocks template.\n\t\t\t\t\t- Strictly only update text content.\n\t\t\t\t\t- Do not touch images.\n\t\t\t\t\t- If you see a repetition with a group, you must create the same number of group items that are visible on the image.\n\t\t\t\t\t- Absolutely do not touch what is not necessary to be changed, like link \"key\" property, or the StructureText \"direction\", spans\", etc or the structure, this is really important that you just do a replace of the text.\n\t\t\t\t\t- For structure text content you must alway keep the same structure and properties, even if empty, ONLY replace text content.\n\t\t\t\t\t- Only and strictly update the text content of the fields, nothing else. You should only and strictly update the text that is visible in the image.\n\t\t\t\t\t- Never touch the image fields, nothing should be changed for image fields.\n\n\t\t\t\t!IMPORTANT!:\n\t\t\t\t\t- Only return a valid JSON object for mocks, nothing else before. JSON.parse on your response should not throw an error.\n\t\t\t\t\t- All your response should fit in a single return response.\n\t\t\t\t\t- Never stop the response until you totally finish the full JSON response you wanted.\n\n\t\t\t\tExisting Mocks Template:\n\t\t\t\t${JSON.stringify(existingMocks)}\n\t\t\t`.trim();\n\n\t\t\tconst messages: Array<ChatCompletionMessageParam> = [\n\t\t\t\t{ role: \"system\", content: systemPrompt },\n\t\t\t\t{\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\t\turl:\n\t\t\t\t\t\t\t\t\t\"data:image/png;base64,\" +\n\t\t\t\t\t\t\t\t\tBuffer.from(imageFile).toString(\"base64\"),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst response: OpenAI.Chat.Completions.ChatCompletion & {\n\t\t\t\t_request_id?: string | null;\n\t\t\t} = await openai.chat.completions.create({\n\t\t\t\tmodel: \"gpt-4o\",\n\t\t\t\tmessages,\n\t\t\t\tresponse_format: {\n\t\t\t\t\ttype: \"json_object\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.log(\"Generated mocks response:\", JSON.stringify(response));\n\n\t\t\tconst resultText = response.choices[0]?.message?.content?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid mocks were generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst updatedMock: SharedSliceContent = JSON.parse(resultText);\n\n\t\t\t\treturn [updatedMock];\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\"Failed to parse AI response for mocks: \" + error);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Calls the AI endpoint to generate the slice React component.\n\t\t */\n\t\tasync function generateSliceComponentCode(\n\t\t\timageFile: Uint8Array,\n\t\t\tcodeFile: string,\n\t\t\tupdatedSlice: SharedSlice,\n\t\t): Promise<string> {\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are a seasoned frontend engineer with deep expertise in Prismic slices.\n\t\t\t\tYour task is to generate a fully isolated React component code for a slice based on the provided image and code input.\n\t\t\t\tThe goal is to create the React (HTML) structure of the slice, NO STYLING! Concentrate 100% on the perfect structure of each component.\n\n\t\t\t\tFollow these guidelines strictly:\n\t\t\t\t\t- Be self-contained.\n\t\t\t\t\t- For links, you must use PrismicNextLink and you must just pass the field, PrismicNextLink will handle the display of the link text, don't do it manually.\n\t\t\t\t\t- PrismicNextLink should never be open, just passing the field is enough like in the code example below. You can use className or inline style directly on the PrismicNextLink component.\n\t\t\t\t\t- Ensure to strictly respect what is defined on the model for each fields ID, do not invent or use something not in the model.\n\t\t\t\t\t- Ensure to use all fields provided in the model.\n\t\t\t\t\t- Follow the structure provided in the code example below.\n\t\t\t\t\t- Use the provided code to help yourself to create the structure.\n\t\t\t\t\t- As you can see in the example of the code you MUST never access the data with \"<field>.value\".\n\t\t\t\t\t- You need to really inspire yourself from the code example bellow in order to understand how to access field, write field etc. Do not try to invent something that you didn't see.\n\t\t\t\t\t- You cannot add a style prop to \"PrismicRichText\" component, it's not allowed.\n\t\t\t\t\t- It's important to respect the same imports as done in the code example bellow, import exactly from the same package.\n\t\t\t\t\t- Never do wrong W3C HTML structure, always respect a correct HTML structure, for example you cannot put a PrismicRichText component inside a <h1>, or a <p>, etc.\n\t\t\t\t\t- Ensure to map the field type to the correct Prismic component, for example, a StructuredText field should be mapped to PrismicRichText, an image field should be mapped to PrismicNextImage, a Text field should just be map to a classic <p> component\n\t\t\t\t\n\t\t\t\t!IMPORTANT!:\n\t\t\t\t\t- Return a valid JSON object containing only one key: \"componentCode\". No additional keys, text, or formatting are allowed before, after, or within the JSON object.\n\t\t\t\t\t- Return a valid JSON, meaning you should NEVER start with a sentence, directly the JSON so that I can JSON.parse your response.\n\t\t\t\t\t- All strings must be enclosed in double quotes (\"). Do not use single quotes or template literals.\n\t\t\t\t\t- Within the string value for \"componentCode\", every embedded double quote must be escaped as \\\". Similarly, every backslash must be escaped as \\\\.\n\t\t\t\t\t- Ensure that the string value does not contain any raw control characters (such as literal newline, tab, or carriage return characters). Instead, use their escape sequences.\n\t\t\t\t\t- Before finalizing the output, validate that JSON.parse(output) works without throwing an error. No unescaped characters should cause the parser to crash.\n\t\t\t\t\t- The output must not include any markdown formatting, code block fences, or extra text. It should be a single, clean JSON object.\n\n\t\t\t\t## Example of a Fully Isolated Slice Component:\n\t\t\t\t-----------------------------------------------------------\n\t\t\t\timport { FC } from \"react\";\n\t\t\t\timport { Content } from \"@prismicio/client\";\n\t\t\t\timport { SliceComponentProps, PrismicRichText } from \"@prismicio/react\";\n\t\t\t\timport { PrismicNextImage, PrismicNextLink } from \"@prismicio/next\";\n\n\t\t\t\texport type PascalNameToReplaceProps =\n\t\t\t\t\tSliceComponentProps<Content.PascalNameToReplaceSlice>;\n\n\t\t\t\tconst PascalNameToReplace: FC<PascalNameToReplaceProps> = ({ slice }) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<section\n\t\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t\t\tclassName=\"es-bounded es-alternate-grid\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<PrismicNextLink\n\t\t\t\t\t\t\t\tclassName=\"es-alternate-grid__button\"\n\t\t\t\t\t\t\t\tfield={slice.primary.buttonLink}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<div className=\"es-alternate-grid__content\">\n\t\t\t\t\t\t\t\t<PrismicNextImage\n\t\t\t\t\t\t\t\t\tfield={slice.primary.image}\n\t\t\t\t\t\t\t\t\tclassName=\"es-alternate-grid__image\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content\">\n\t\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__intro\">\n\t\t\t\t\t\t\t\t\t\t<p className=\"es-alternate-grid__primary-content__intro__eyebrow\">\n\t\t\t\t\t\t\t\t\t\t\t{slice.primary.eyebrowHeadline}\n\t\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__intro__headline\">\n\t\t\t\t\t\t\t\t\t\t\t<PrismicRichText field={slice.primary.title} />\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__intro__description\">\n\t\t\t\t\t\t\t\t\t\t\t<PrismicRichText field={slice.primary.description} />\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__stats\">\n\t\t\t\t\t\t\t\t\t\t{slice.primary.stats.map((stat, i) => (\n\t\t\t\t\t\t\t\t\t\t\t<div key={\\`stat-$\\{i + 1\\}\\`} className=\"es-alternate-grid__stat\">\n\t\t\t\t\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__stat__heading\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<PrismicRichText field={stat.title} />\n\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t<div className=\"es-alternate-grid__stat__description\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<PrismicRichText field={stat.description} />\n\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</section>\n\t\t\t\t\t);\n\t\t\t\t};\n\n\t\t\t\texport default PascalNameToReplace;\n\t\t\t\t-----------------------------------------------------------\n\n\t\t\t\tModel of the slice:\n\t\t\t\t${JSON.stringify(updatedSlice)}\n\t\t\t`.trim();\n\n\t\t\tconst messages: Array<ChatCompletionMessageParam> = [\n\t\t\t\t{ role: \"system\", content: systemPrompt },\n\t\t\t\t{\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\t\turl:\n\t\t\t\t\t\t\t\t\t\"data:image/png;base64,\" +\n\t\t\t\t\t\t\t\t\tBuffer.from(imageFile).toString(\"base64\"),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ type: \"text\", text: codeFile },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst response: OpenAI.Chat.Completions.ChatCompletion & {\n\t\t\t\t_request_id?: string | null;\n\t\t\t} = await openai.chat.completions.create({\n\t\t\t\tmodel: \"gpt-4o\",\n\t\t\t\tmessages,\n\t\t\t\tresponse_format: {\n\t\t\t\t\ttype: \"json_object\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.log(\n\t\t\t\t\"Generated component code response:\",\n\t\t\t\tJSON.stringify(response),\n\t\t\t);\n\n\t\t\tconst resultText = response.choices[0]?.message?.content?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid slice component code was generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(resultText);\n\t\t\t\tif (!parsed.componentCode) {\n\t\t\t\t\tthrow new Error(\"Missing key 'componentCode' in AI response.\");\n\t\t\t\t}\n\t\t\t\treturn parsed.componentCode;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Failed to parse AI response for component code: \" + error,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tasync function generateSliceComponentCodeAppearance(\n\t\t\timageFile: Uint8Array,\n\t\t\tcodeFile: string,\n\t\t\tglobalStyle: string,\n\t\t\tcomponentCode: string,\n\t\t): Promise<string> {\n\t\t\tconst systemPrompt = `\n\t\t\t\tYou are a seasoned frontend engineer with deep expertise in Prismic slices.\n\t\t\t\tYour task is to apply the branding (appearance) based on the provided image and code input.\n\t\t\t\tThe branding is SUPER important, and the slice you create should PERFECTLY match the branding (appearance) of the provided slice image and code.\n\n\t\t\t\tFollow these guidelines strictly:\n\t\t\t\t\t- Don't change anything related to the structure of the code, ONLY apply styling, PURELY styling is your ONLY task.\n\t\t\t\t\t- Be self-contained, no dependency should be use to do the styling, do inline style.\n\t\t\t\t\t- Your goal is to make the code visually looks as close as possible to the image from the user input.\n\t\t\t\t\t- Ensure that the color used for the background is the same as the image provide in the user prompt! It's better no background color than a wrong one.\n\t\t\t\t\t- Strictly respect the padding and margin visible in the image provide in the user prompt.\n\t\t\t\t\t- Strictly respect the fonts size, color, type visible in the image provide in the user prompt.\n\t\t\t\t\t- Strictly respect the colors visible in the image provide in the user prompt.\n\t\t\t\t\t- Strictly respect the position of elements visible in the image provide in the user prompt.\n\t\t\t\t\t- Strictly respect the size of each elements visible in the image provide in the user prompt.\n\t\t\t\t\t- Strictly respect the overall proportions of the slice from the image provide in the user prompt.\n\t\t\t\t\t- Ensure image are always displayed with the same aspect ratio as the image provide in the user prompt, put constraints on the image with / height to make sure it's the same.\n\t\t\t\t\t- Handle animations, but never make them too long, it should be fast enough to be nice to read.\n\t\t\t\t\t- Use inline <style> (do not use <style jsx>).\n\t\t\t\t\t- Items repetitions should be styled in the same way as the image provided, the direction of the flex should be the same so that the items are vertical or horizontal as in the image.\n\n\t\t\t\t!IMPORTANT!:\n\t\t\t\t\t- DO NOT CHANGE anything else than the style BUT return everything as before for the rest, like from the import to the last export line, everything should stay the same BUT you add the styling on top.\n\t\t\t\t\t- Return a valid JSON object containing only one key: \"componentCode\". No additional keys, text, or formatting are allowed before, after, or within the JSON object.\n\t\t\t\t\t- Return a valid JSON, meaning you should NEVER start with a sentence, directly the JSON so that I can JSON.parse your response.\n\t\t\t\t\t- All strings must be enclosed in double quotes (\"). Do not use single quotes or template literals.\n\t\t\t\t\t- Within the string value for \"componentCode\", every embedded double quote must be escaped as \\\". Similarly, every backslash must be escaped as \\\\.\n\t\t\t\t\t- Ensure that the string value does not contain any raw control characters (such as literal newline, tab, or carriage return characters). Instead, use their escape sequences.\n\t\t\t\t\t- Before finalizing the output, validate that JSON.parse(output) works without throwing an error. No unescaped characters should cause the parser to crash.\n\t\t\t\t\t- The output must not include any markdown formatting, code block fences, or extra text. It should be a single, clean JSON object.\n\n\t\t\t\tExisting code to apply branding on it:\n\t\t\t\t${componentCode}\n\t\t\t`.trim();\n\n\t\t\t// INFO: globalStyle is way too big as of today to be included in the prompt.\n\t\t\t// As the user is providing a slice image and code you miss the global style to help you build the best slice that match the branding, so here is the global style:\n\t\t\t// ${globalStyle}\n\n\t\t\tconst messages: Array<ChatCompletionMessageParam> = [\n\t\t\t\t{ role: \"system\", content: systemPrompt },\n\t\t\t\t{\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\t\turl:\n\t\t\t\t\t\t\t\t\t\"data:image/png;base64,\" +\n\t\t\t\t\t\t\t\t\tBuffer.from(imageFile).toString(\"base64\"),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ type: \"text\", text: codeFile },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst response: OpenAI.Chat.Completions.ChatCompletion & {\n\t\t\t\t_request_id?: string | null;\n\t\t\t} = await openai.chat.completions.create({\n\t\t\t\tmodel: \"gpt-4o\",\n\t\t\t\tmessages,\n\t\t\t\tresponse_format: {\n\t\t\t\t\ttype: \"json_object\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.log(\n\t\t\t\t\"Generated component code appearance response:\",\n\t\t\t\tJSON.stringify(response),\n\t\t\t);\n\n\t\t\tconst resultText = response.choices[0]?.message?.content?.trim();\n\t\t\tif (!resultText) {\n\t\t\t\tthrow new Error(\"No valid slice component code was generated.\");\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(resultText);\n\t\t\t\tif (!parsed.componentCode) {\n\t\t\t\t\tthrow new Error(\"Missing key 'componentCode' in AI response.\");\n\t\t\t\t}\n\t\t\t\treturn parsed.componentCode;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Failed to parse AI response for component code appearance: \" + error,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\tlet slices: {\n\t\t\t\tsliceImage: Uint8Array;\n\t\t\t\tcodeFile: string;\n\t\t\t}[] = [];\n\n\t\t\tconst folderPath = KNOWNED_WEBSITE_URLS[args.websiteUrl];\n\n\t\t\tconsole.log(\"STEP 1: Get the slices images from the folder.\");\n\t\t\tconst sliceImages = await readImagesFromFolder(`${folderPath}/images`);\n\n\t\t\tconsole.log(\"STEP 2: Get the slices codes from the folder.\");\n\t\t\tconst sliceCodes = await readCodeFromFolder(`${folderPath}/code`);\n\n\t\t\tslices = sliceImages.map((sliceImage, index) => ({\n\t\t\t\tsliceImage,\n\t\t\t\tcodeFile: sliceCodes[index],\n\t\t\t}));\n\n\t\t\t// Loop in parallel over each slice image and html code and generate the slice model, mocks and code.\n\t\t\tconst updatedSlices = await Promise.all(\n\t\t\t\tslices.map(async ({ sliceImage, codeFile }, index) => {\n\t\t\t\t\t// ----- Q1 scope -----\n\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"STEP 3: Generate the slice model using the image for slice:\",\n\t\t\t\t\t\tindex,\n\t\t\t\t\t);\n\t\t\t\t\tconst updatedSlice = await generateSliceModel(sliceImage, codeFile);\n\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"STEP 4: Persist the updated slice model for:\",\n\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t);\n\t\t\t\t\tawait this.updateSlice({\n\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\tmodel: updatedSlice,\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"STEP 5: Update the slice screenshot for:\",\n\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t);\n\t\t\t\t\tawait this.updateSliceScreenshot({\n\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\tsliceID: updatedSlice.id,\n\t\t\t\t\t\tvariationID: updatedSlice.variations[0].id,\n\t\t\t\t\t\tdata: Buffer.from(sliceImage),\n\t\t\t\t\t});\n\n\t\t\t\t\t// ----- END Q1 scope -----\n\n\t\t\t\t\tlet updatedMock: SharedSliceContent[];\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\"STEP 6: Generate updated mocks for:\",\n\t\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst existingMocks = mockSlice({ model: updatedSlice });\n\t\t\t\t\t\tupdatedMock = await generateSliceMocks(sliceImage, existingMocks);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`Failed to generate mocks for ${index} - ${updatedSlice.name}:`,\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tupdatedMock = mockSlice({ model: updatedSlice });\n\t\t\t\t\t}\n\n\t\t\t\t\tlet componentCode: string | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\"STEP 7: Generate the isolated slice component code for:\",\n\t\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst globalStyle = await getGlobalStyle(\n\t\t\t\t\t\t\t`${folderPath}/globalStyle.css`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst initialCode = await generateSliceComponentCode(\n\t\t\t\t\t\t\tsliceImage,\n\t\t\t\t\t\t\tcodeFile,\n\t\t\t\t\t\t\tupdatedSlice,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\"STEP 8: Generate the branding on the code:\",\n\t\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcomponentCode = await generateSliceComponentCodeAppearance(\n\t\t\t\t\t\t\tsliceImage,\n\t\t\t\t\t\t\tcodeFile,\n\t\t\t\t\t\t\tglobalStyle,\n\t\t\t\t\t\t\tinitialCode,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`Failed to generate code for ${index} - ${updatedSlice.name}:`,\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn { updatedSlice, componentCode, updatedMock };\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Ensure to wait to have all slices code and mocks before writing on the disk\n\t\t\tawait Promise.all(\n\t\t\t\tupdatedSlices.map(\n\t\t\t\t\tasync ({ updatedSlice, componentCode, updatedMock }, index) => {\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\"STEP 9: Update the slice code for:\",\n\t\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (componentCode) {\n\t\t\t\t\t\t\tawait this.createSlice({\n\t\t\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\t\t\tmodel: updatedSlice,\n\t\t\t\t\t\t\t\tcomponentContents: componentCode,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tawait this.createSlice({\n\t\t\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\t\t\tmodel: updatedSlice,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\"STEP 10: Persist the generated mocks for:\",\n\t\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait this.updateSliceMocks({\n\t\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\t\tsliceID: updatedSlice.id,\n\t\t\t\t\t\t\tmocks: updatedMock,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tconsole.log(\"STEP 11: THE END\");\n\n\t\t\treturn {\n\t\t\t\tslices: updatedSlices.map(({ updatedSlice }) => updatedSlice),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Failed to generate slice:\", error);\n\t\t\tthrow new Error(\"Failed to generate slice: \" + error);\n\t\t}\n\t}\n}\n"],"names":["errors","path"],"mappings":";;;;;;;;;;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AO,EAAE,cAAc,eAAe,eAAe,UAAS;AAC7D,gBAAQ,IACP,sCACA,GAAG,WAAW,aAAa,MAAM;AAElC,YAAI,eAAe;AAClB,gBAAM,KAAK,YAAY;AAAA,YACtB,WAAW;AAAA,YACX,OAAO;AAAA,YACP,mBAAmB;AAAA,UAAA,CACnB;AAAA,QAAA,OACK;AACN,gBAAM,KAAK,YAAY;AAAA,YACtB,WAAW;AAAA,YACX,OAAO;AAAA,UAAA,CACP;AAAA,QACF;AAEA,gBAAQ,IACP,6CACA,GAAG,WAAW,aAAa,MAAM;AAElC,cAAM,KAAK,iBAAiB;AAAA,UAC3B,WAAW;AAAA,UACX,SAAS,aAAa;AAAA,UACtB,OAAO;AAAA,QAAA,CACP;AAAA,MACD,CAAA,CACD;AAGF,cAAQ,IAAI,kBAAkB;AAEvB,aAAA;AAAA,QACN,QAAQ,cAAc,IAAI,CAAC,EAAE,aAAA,MAAmB,YAAY;AAAA,MAAA;AAAA,aAErD;AACA,cAAA,MAAM,6BAA6B,KAAK;AAC1C,YAAA,IAAI,MAAM,+BAA+B,KAAK;AAAA,IACrD;AAAA,EACD;AACA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/manager",
3
- "version": "0.24.4-alpha.xru-poc-ai.1",
3
+ "version": "0.24.4-alpha.xru-slice-generation-ai-poc.1",
4
4
  "description": "Manage all aspects of a Slice Machine project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -65,13 +65,13 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@antfu/ni": "^0.20.0",
68
- "@aws-sdk/client-bedrock-runtime": "3.744.0",
68
+ "@aws-sdk/client-bedrock-runtime": "^3.744.0",
69
69
  "@prismicio/client": "^7.11.0",
70
70
  "@prismicio/custom-types-client": "2.1.0",
71
71
  "@prismicio/mocks": "2.8.0",
72
72
  "@prismicio/types-internal": "3.3.0",
73
73
  "@segment/analytics-node": "^2.1.2",
74
- "@slicemachine/plugin-kit": "0.4.66-alpha.xru-poc-ai.1",
74
+ "@slicemachine/plugin-kit": "0.4.66-alpha.xru-slice-generation-ai-poc.1",
75
75
  "cookie": "^1.0.1",
76
76
  "cors": "^2.8.5",
77
77
  "execa": "^7.1.1",
@@ -85,13 +85,16 @@
85
85
  "monocle-ts": "^2.3.13",
86
86
  "newtype-ts": "^0.3.5",
87
87
  "node-fetch": "^3.3.1",
88
+ "openai": "^4.85.3",
88
89
  "p-limit": "^4.0.0",
90
+ "playwright": "^1.50.1",
89
91
  "prettier": "^3.0.3",
92
+ "puppeteer": "^24.2.1",
90
93
  "r19": "0.1.8",
91
94
  "rc9": "^2.0.1",
92
95
  "readable-web-to-node-stream": "^3.0.2",
93
96
  "semver": "^7.3.8",
94
- "typescript-json-schema": "0.65.1"
97
+ "sharp": "^0.33.5"
95
98
  },
96
99
  "devDependencies": {
97
100
  "@amplitude/experiment-node-server": "1.8.1",