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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"SlicesManager.cjs","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":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","mockSlice","SharedSlice","SliceComparator","UnauthenticatedError","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","bufferCodec","SharedSliceContent","DEFAULT_SLICE_SCREENSHOT_URL","createContentDigest","ConverseCommand","BedrockRuntimeClient"],"mappings":";;;;;;;;;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AW,aAAa,MAAM;AAElC,gBAAM,cAAc,MAAM,eACzB,GAAG,4BAA4B;AAEhC,gBAAM,cAAc,MAAM,2BACzB,YACA,UACA,YAAY;AAGb,kBAAQ,IACP,8CACA,GAAG,WAAW,aAAa,MAAM;AAElC,0BAAgB,MAAM,qCACrB,YACA,UACA,aACA,WAAW;AAAA,iBAEJ;AACR,kBAAQ,MACP,+BAA+B,WAAW,aAAa,SACvD,KAAK;AAAA,QAEP;AAEO,eAAA,EAAE,cAAc,eAAe;MACtC,CAAA,CAAC;AAIG,YAAA,QAAQ,IACb,cAAc,IACb,OAAO,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;;"}
1
+ {"version":3,"file":"SlicesManager.cjs","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\tMessage,\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\tsliceImages: Uint8Array[];\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, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } =\n\t\t\tprocess.env;\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\t\tconst AWS_REGION = \"us-east-1\";\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\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: 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\tlet retry: {\n\t\t\t[key in \"MODEL\" | \"MOCKS\" | \"CODE\" | \"APPEARANCE\"]: number;\n\t\t}[] = args.sliceImages.map((_) => ({\n\t\t\tMODEL: 0,\n\t\t\tMOCKS: 0,\n\t\t\tCODE: 0,\n\t\t\tAPPEARANCE: 0,\n\t\t}));\n\n\t\tasync function callAI<ReturnType extends Record<string, unknown>>({\n\t\t\tai,\n\t\t\tsliceIndex,\n\t\t\tstepName,\n\t\t\tsystemPrompt,\n\t\t\timageFile,\n\t\t\ttextContent,\n\t\t}: {\n\t\t\tai: \"OPENAI\" | \"AWS\";\n\t\t\tsliceIndex: number;\n\t\t\tstepName: \"MODEL\" | \"MOCKS\" | \"CODE\" | \"APPEARANCE\";\n\t\t\tsystemPrompt: string;\n\t\t\timageFile?: Uint8Array;\n\t\t\ttextContent?: string;\n\t\t}): Promise<ReturnType> {\n\t\t\tlet resultText: string | undefined;\n\n\t\t\tif (ai === \"OPENAI\") {\n\t\t\t\tconst messages: Array<ChatCompletionMessageParam> = [\n\t\t\t\t\t{ role: \"system\", content: systemPrompt },\n\t\t\t\t];\n\n\t\t\t\tconst userContent: Array<\n\t\t\t\t\t| {\n\t\t\t\t\t\t\ttype: \"text\";\n\t\t\t\t\t\t\ttext: string;\n\t\t\t\t\t }\n\t\t\t\t\t| {\n\t\t\t\t\t\t\ttype: \"image_url\";\n\t\t\t\t\t\t\timage_url: { url: string };\n\t\t\t\t\t }\n\t\t\t\t> = [];\n\n\t\t\t\tif (imageFile) {\n\t\t\t\t\tuserContent.push({\n\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\timage_url: {\n\t\t\t\t\t\t\turl:\n\t\t\t\t\t\t\t\t\"data:image/png;base64,\" +\n\t\t\t\t\t\t\t\tBuffer.from(imageFile).toString(\"base64\"),\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (textContent) {\n\t\t\t\t\tuserContent.push({ type: \"text\", text: textContent });\n\t\t\t\t}\n\n\t\t\t\tif (userContent.length > 0) {\n\t\t\t\t\tmessages.push({\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: userContent,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst response = await openai.chat.completions.create({\n\t\t\t\t\tmodel: \"gpt-4o\",\n\t\t\t\t\tmessages,\n\t\t\t\t\tresponse_format: { type: \"json_object\" },\n\t\t\t\t});\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Generated response for ${stepName} - ${sliceIndex}:`,\n\t\t\t\t\tJSON.stringify(response),\n\t\t\t\t);\n\n\t\t\t\tresultText = response.choices[0]?.message?.content?.trim();\n\t\t\t} else if (ai === \"AWS\") {\n\t\t\t\tconst messages: Array<Message> = [];\n\n\t\t\t\tif (imageFile) {\n\t\t\t\t\tmessages.push({\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\n\t\t\t\tif (textContent) {\n\t\t\t\t\tmessages.push({\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\ttext: textContent,\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\tconst command = new ConverseCommand({\n\t\t\t\t\tmodelId: \"us.anthropic.claude-3-7-sonnet-20250219-v1:0\",\n\t\t\t\t\tsystem: [{ text: systemPrompt }],\n\t\t\t\t\tmessages: messages,\n\t\t\t\t});\n\n\t\t\t\tconst response = await bedrockClient.send(command);\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Generated response for ${stepName} - ${sliceIndex}:`,\n\t\t\t\t\tJSON.stringify(response),\n\t\t\t\t);\n\n\t\t\t\tresultText = response.output?.message?.content?.[0]?.text?.trim();\n\t\t\t}\n\n\t\t\tasync function retryCall(error: string): Promise<ReturnType> {\n\t\t\t\tif (retry[sliceIndex][stepName] < 3) {\n\t\t\t\t\tretry[sliceIndex][stepName]++;\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Retrying ${retry[sliceIndex][stepName]} ${stepName} for slice ${sliceIndex}.`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn await callAI({\n\t\t\t\t\t\tai,\n\t\t\t\t\t\tsliceIndex,\n\t\t\t\t\t\tstepName,\n\t\t\t\t\t\tsystemPrompt,\n\t\t\t\t\t\timageFile,\n\t\t\t\t\t\ttextContent,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthrow new Error(error);\n\t\t\t}\n\n\t\t\tif (!resultText) {\n\t\t\t\treturn await retryCall(\n\t\t\t\t\t`No valid response was generated for ${stepName}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(resultText);\n\t\t\t} catch (error) {\n\t\t\t\treturn await retryCall(\n\t\t\t\t\t`Failed to parse AI response for ${stepName}: ` + error,\n\t\t\t\t);\n\t\t\t}\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\tsliceIndex: number,\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 and code provided**, generate a **valid Prismic JSON model** for the slice described below.\n\n\t\t\t\t**STRICT MODELING RULES (NO EXCEPTIONS):**\n\t\t\t\t\t- **Use the TypeScript schema provided as your reference**.\n\t\t\t\t\t- **Absolutely all fields must be placed under the \"primary\" object**.\n\t\t\t\t\t- **Do not create groups or collections for single-image content** (background images must be a single image field).\n\t\t\t\t\t- **Ensure each field has appropriate placeholders, labels, and configurations**.\n\t\t\t\t\t- **Never generate a Link/Button text field—only the Link/Button field itself** with \\`\"allowText\": true\\`.\n\t\t\t\t\t- **Include all fields visible in the provided image**, do not forget any field and everything should be covered.\n\t\t\t\t\t- **Repeated fields must always be grouped**:\n\t\t\t\t\t\t- **Identify when field are part of a group**, when there is a repetition of a field or multiple fields together use a Group field.\n\t\t\t\t\t\t- **DO NOT** create individually numbered fields like \\`feature1\\`, \\`feature2\\`, \\`feature3\\`. Instead, define a single **Group field** (e.g., \\`features\\`) and move all repeated items inside it.\n\t\t\t\t\t- **Differentiate Prismic fields from decorative elements:**\n\t\t\t\t\t\t- If an element in the image is purely visual/decorative, **do not include it in the model**.\n\t\t\t\t\t\t- Use the **code as the source of truth** to determine what should be a field.\n\t\t\t\t\t\t- If an element is an image in the code, it **must also be an image field in Prismic** (strict 1:1 mapping).\n\t\t\t\t\t- **Handle repeated content correctly:**\n\t\t\t\t\t\t- **If an image, text, or link is repeated, always use a Group field**—do not create individual fields.\n\t\t\t\t\t\t- **If multiple fields are repeated together, they must be inside a single Group field**.\n\t\t\t\t\t- **Strictly forbid nesting of groups:**\n\t\t\t\t\t\t- **NEVER put a Group inside another Group field**.\n\t\t\t\t\t\t- **Group fields CANNOT be nested for any reason**—this is **strictly prohibited** even for navigation structures like headers or footers.\n\t\t\t\t\t- **Do not use the \"items\" field**:\n\t\t\t\t\t\t- **All repeatable fields must be defined as Group fields under \"primary\"**.\n\t\t\t\t\t\t- **\"items\" must never appear in the final JSON output**.\n\t\t\t\t\t- **Do not create more than one SliceVariation**, only one variation is enough to create the model.\n\n\t\t\t\t**STRICT FIELD NAMING & CONTENT RULES:**\n\t\t\t\t\t- **Replace placeholders in the existing slice template** (\\`<ID_TO_CHANGE>\\`, \\`<NAME_TO_CHANGE>\\`, etc.).\n\t\t\t\t\t- **Field placeholders must be very short**—do **not** put actual image content inside placeholders.\n\t\t\t\t\t- **Field labels and IDs must define the field's purpose, not its content**.\n\t\t\t\t\t- **Slice name, ID, and description must describe the slice's function, not its content**.\n\t\t\t\t\t- The slice name and ID must be **generic and reusable**, defining what the slice **does**, not what it is used for.\n\t\t\t\t\t- **DO NOT name the slice after a specific topic, content type, or industry. Instead, name it based on its structure and function.\n\n\t\t\t\t**STRICT JSON OUTPUT FORMAT (NO MARKDOWN OR EXTRA TEXT):**\n\t\t\t\t\t- **Return ONLY a valid JSON object**—no extra text, comments, or formatting.\n\t\t\t\t\t- **The response must be directly parseable** using \\`JSON.parse(output)\\`.\n\t\t\t\t\t- **Do not wrap the output in markdown (\\`\\`\\`\\`json\\`) or any other formatting.**\n\n\t\t\t\t**VALIDATION REQUIREMENT:**\n\t\t\t\t\t- Before returning, **validate that \\`JSON.parse(output)\\` runs without errors**.\n\t\t\t\t\t- If there is **any extra text, markdown, or incorrect structure**, **rewrite the response before returning**.\n\n\t\t\t\t**REFERENCE SCHEMA (Follow this exactly):**\n\t\t\t\t${SHARED_SLICE_SCHEMA}\n\t\t\t\t\n\t\t\t\t**EXISTING SLICE TO UPDATE (Modify strictly according to the rules above):**\n\t\t\t\t${JSON.stringify(DEFAULT_SLICE_MODEL)}\n\t\t\t`.trim();\n\n\t\t\tconst generatedModel = await callAI<SharedSlice>({\n\t\t\t\tai: \"OPENAI\",\n\t\t\t\tsliceIndex,\n\t\t\t\tstepName: \"MODEL\",\n\t\t\t\tsystemPrompt,\n\t\t\t\timageFile,\n\t\t\t});\n\n\t\t\treturn generatedModel;\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\tsliceIndex: number,\n\t\t\timageFile: Uint8Array,\n\t\t\texistingMocks: SharedSliceContent[],\n\t\t): Promise<SharedSliceContent[]> {\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 **only** on the visible text content in the provided image.\n\n\t\t\t\t**STRICT UPDATE GUIDELINES:**\n\t\t\t\t\t- **Do no create content, only take visible text from the image.**\n\t\t\t\t\t- **Do not modify the overall structure of the mocks template.**\n\t\t\t\t\t- **Strictly update text content only.**\n\t\t\t\t\t- **Do not touch images or image-related fields.**\n\t\t\t\t\t- **If a repeated item appears in a group, match the exact number of group items seen in the image.**\n\t\t\t\t\t- **Do not modify metadata, field properties, or structure.** This includes:\n\t\t\t\t\t\t- Do **not** change the \\`\"key\"\\` property of links.\n\t\t\t\t\t\t- Do **not** modify \\`StructuredText\\` properties such as \\`\"direction\"\\`, \\`\"spans\"\\`, or \\`\"type\"\\`.\n\t\t\t\t\t\t- Do **not** alter field nesting or object structure.\n\t\t\t\t\t- **For StructuredText fields, maintain all existing structure and properties**—**only replace text content**.\n\t\t\t\t\t- **Ensure that only visible text in the image is updated**—do not generate or assume content.\n\t\t\t\t\t- **Never modify image fields**—image references and properties must remain unchanged.\n\n\t\t\t\t**STRICT JSON OUTPUT FORMAT:**\n\t\t\t\t\t- **Return ONLY a valid JSON object**—no extra text, explanations, or formatting.\n\t\t\t\t\t- **The response must be directly parseable** using \\`JSON.parse(output)\\`.\n\t\t\t\t\t- **Do not wrap the output in markdown (\\`\\`\\`\\`json\\`) or any other formatting.**\n\n\t\t\t\t**VALIDATION REQUIREMENT:**\n\t\t\t\t\t- Before returning, **validate that \\`JSON.parse(output)\\` runs without errors**.\n\t\t\t\t\t- If there is **any extra text, markdown, or incorrect structure**, **rewrite the response before returning**.\n\n\t\t\t\t**EXISTING MOCKS TEMPLATE (To be updated with the visible text from the image only):**\n\t\t\t\t${JSON.stringify(existingMocks)}\n\t\t\t`.trim();\n\n\t\t\tconst updatedMock = await callAI<SharedSliceContent>({\n\t\t\t\tai: \"OPENAI\",\n\t\t\t\tsliceIndex,\n\t\t\t\tstepName: \"MOCKS\",\n\t\t\t\tsystemPrompt,\n\t\t\t\timageFile,\n\t\t\t});\n\n\t\t\treturn [updatedMock];\n\t\t}\n\n\t\tconst SLICE_CODE_EXAMPLE = `\n-----------------------------------------------------------\nimport { FC } from \"react\";\nimport { Content } from \"@prismicio/client\";\nimport { SliceComponentProps, PrismicRichText } from \"@prismicio/react\";\nimport { PrismicNextImage, PrismicNextLink } from \"@prismicio/next\";\n\nexport type PascalNameToReplaceProps =\n\tSliceComponentProps<Content.PascalNameToReplaceSlice>;\n\nconst PascalNameToReplace: FC<PascalNameToReplaceProps> = ({ slice }) => {\n\treturn (\n\t\t<section\n\t\t\tdata-slice-type={slice.slice_type}\n\t\t\tdata-slice-variation={slice.variation}\n\t\t\tclassName=\"es-bounded es-alternate-grid\"\n\t\t>\n\t\t\t<PrismicNextLink\n\t\t\t\tclassName=\"es-alternate-grid__button\"\n\t\t\t\tfield={slice.primary.buttonLink}\n\t\t\t/>\n\t\t\t<div className=\"es-alternate-grid__content\">\n\t\t\t\t<PrismicNextImage\n\t\t\t\t\tfield={slice.primary.image}\n\t\t\t\t\tclassName=\"es-alternate-grid__image\"\n\t\t\t\t/>\n\t\t\t\t<div className=\"es-alternate-grid__primary-content\">\n\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__intro\">\n\t\t\t\t\t\t<p className=\"es-alternate-grid__primary-content__intro__eyebrow\">\n\t\t\t\t\t\t\t{slice.primary.eyebrowHeadline}\n\t\t\t\t\t\t</p>\n\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__intro__headline\">\n\t\t\t\t\t\t\t<PrismicRichText field={slice.primary.title} />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__intro__description\">\n\t\t\t\t\t\t\t<PrismicRichText field={slice.primary.description} />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<div className=\"es-alternate-grid__primary-content__stats\">\n\t\t\t\t\t\t{slice.primary.stats.map((stat, i) => (\n\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<div className=\"es-alternate-grid__stat__heading\">\n\t\t\t\t\t\t\t\t\t<PrismicRichText field={stat.title} />\n\t\t\t\t\t\t\t\t</div>\n\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<PrismicRichText field={stat.description} />\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))}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</section>\n\t);\n};\n\nexport default PascalNameToReplace;\n-----------------------------------------------------------\n`.trim();\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\tsliceIndex: number,\n\t\t\timageFile: Uint8Array,\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** for a Prismic slice, **focusing ONLY on structure (HTML) without styling**.\n\n\t\t\t\t**STRICT STRUCTURAL GUIDELINES:**\n\t\t\t\t\t- **Do not include styling.** Focus **100% on correct structure**.\n\t\t\t\t\t- **Be self-contained.** The component must work in isolation.\n\t\t\t\t\t- **Follow the structure provided in the example.** Do not introduce **any variations**.\n\t\t\t\t\t- **Use all fields provided in the model**—do not omit or invent fields.\n\t\t\t\t\t- **Never access a field using** \\`<field>.value\\`. Always follow the example pattern with just \\`<field>\\`.\n\t\t\t\t\t- **Ensure correct mapping of field types:**\n\t\t\t\t\t\t- **StructuredText** → \\`PrismicRichText\\`\n\t\t\t\t\t\t- **Image field** → \\`PrismicNextImage\\`\n\t\t\t\t\t\t- **Text field** → Standard \\`<p>\\` element\n\t\t\t\t\t\t- **Link field** → \\`PrismicNextLink\\`\n\t\t\t\t\t\t- **Group field** → Map to the correct structure based on the example.\n\t\t\t\t\t- **Maintain W3C-compliant HTML.** Do not place \\`PrismicRichText\\` inside \\`<h1>\\`, \\`<p>\\`, or other invalid elements.\n\n\t\t\t\t**PRISMIC COMPONENT USAGE RULES:**\n\t\t\t\t\t- **Links must use \\`PrismicNextLink\\`**, passing only the \\`field\\` (no manual text extraction).\n\t\t\t\t\t- **\\`PrismicNextLink\\` must never be opened manually**—pass the field directly as in the example.\n\t\t\t\t\t- **\\`PrismicRichText\\` cannot have a \\`style\\` prop**.\n\t\t\t\t\t- **Imports must be identical to the provided example**.\n\n\t\t\t\t**STRICT JSON OUTPUT FORMAT**\n\t\t\t\t\t- **Return ONLY a valid JSON object** with **one key**: \\`\"componentCode\"\\`.\n\t\t\t\t\t- **No markdown (\\`\\`\\`\\`json\\`), no comments, no text before or after—ONLY pure JSON**.\n\t\t\t\t\t- **The response MUST start with \\`{\\` and end with \\`}\\` exactly, do not start with a sentence explaining what you will do.**\n\t\t\t\t\t- **Ensure the output is directly parseable** with \\`JSON.parse(output)\\`.\n\t\t\t\t\t- **All strings must use double quotes (\\`\"\\`).** Do not use single quotes or template literals.\n\t\t\t\t\t- **Escape all embedded double quotes (\\`\\\"\\`) and backslashes (\\`\\\\\\`).**\n\t\t\t\t\t- **The output must not contain raw control characters** (newline, tab, etc.); use escape sequences instead.\n\n\t\t\t\t**Before returning, VALIDATE that \\`JSON.parse(output)\\` runs without errors.**\n\n\t\t\t\t**EXAMPLE OF A FULLY ISOLATED SLICE COMPONENT (Follow this strictly):**\n\t\t\t\t${SLICE_CODE_EXAMPLE}\n\n\t\t\t\t**SLICE MODEL (Use this as the exact reference):**\n\t\t\t\t${JSON.stringify(updatedSlice)}\n\t\t\t`.trim();\n\n\t\t\tconst parsed = await callAI<{ componentCode: string }>({\n\t\t\t\tai: \"AWS\",\n\t\t\t\tsliceIndex,\n\t\t\t\tstepName: \"CODE\",\n\t\t\t\tsystemPrompt,\n\t\t\t\timageFile,\n\t\t\t});\n\n\t\t\tif (!parsed.componentCode) {\n\t\t\t\tthrow new Error(\"Missing key 'componentCode' in AI response.\");\n\t\t\t}\n\n\t\t\treturn parsed.componentCode;\n\t\t}\n\n\t\tasync function generateSliceComponentCodeAppearance(\n\t\t\tsliceIndex: number,\n\t\t\timageFile: Uint8Array,\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 branding (appearance) strictly based on the provided image and code input**.\n\t\t\t\tThe **branding is CRITICAL**—the slice you create **must perfectly match the visual appearance** of the provided slice image.\n\t\t\t\n\t\t\t\t**STRICT GUIDELINES TO FOLLOW (NO EXCEPTIONS):**\n\t\t\t\t\t- **DO NOT** modify the structure of the code—**ONLY apply styling**. Your role is **purely styling-related**.\n\t\t\t\t\t- **NO external dependencies**—use **only inline** styling.\n\t\t\t\t\t- **VISUAL ACCURACY IS MANDATORY**—your goal is to make the output **visually identical** to the provided image.\n\t\t\t\t\t\n\t\t\t\t**MUST strictly respect the following:**\n\t\t\t\t\t- **Background color** → Must **exactly match** the image. If unsure, **do not apply** any background color.\n\t\t\t\t\t- **Padding & margin** → Must be **pixel-perfect** per the provided image.\n\t\t\t\t\t- **Font size, color, and type** → Must match exactly. If the exact font is unavailable, choose the **closest possible match**.\n\t\t\t\t\t- **Typography precision** → If the font-family does not match, **the output is incorrect**.\n\t\t\t\t\t- **Color accuracy** → Use **ONLY the colors visible** in the provided image.\n\t\t\t\t\t- **Element positioning** → Elements **must be placed exactly** as seen in the provided image.\n\t\t\t\t\t- **Element sizes** → Every element **must match** the provided image in width, height, and proportions.\n\t\t\t\t\t- **Overall proportions** → The slice must maintain **identical proportions** to the provided image.\n\t\t\t\t\t- **Image constraints** → Images **must** maintain their **original aspect ratio**. Use explicit \\`width\\` and \\`height\\` constraints with an explicit pixels value. Avoid \\`width: auto\\`, \\`height: auto\\`, \\`width: 100%\\` or \\`height: 100%\\`.\n\t\t\t\t\t- **Repetitions & layout** → Ensure **consistent styling** across repeated items. The **layout direction (horizontal/vertical)** must match the image.\n\t\t\t\t\t- **Animations** → Handle animations as seen in the image, but **keep them fast and subtle** (avoid long animations).\n\t\t\t\t\n\t\t\t\t**IMPORTANT RULES:**\n\t\t\t\t\t1. **DO NOT modify any non-styling code**.\n\t\t\t\t\t\t- **Everything from the first import to the last export must remain unchanged**.\n\t\t\t\t\t\t- **Only add styling** on top of the existing structure.\n\t\t\t\t\n\t\t\t\t\t2. **STRICT JSON OUTPUT FORMAT**\n\t\t\t\t\t\t- Return a **valid JSON object** with **one key only**: \\`\"componentCode\"\\`.\n\t\t\t\t\t\t- **NO markdown, NO code blocks, NO text before or after**—only **pure JSON**.\n\t\t\t\t\t\t- The response **must start and end directly with \\`{ \"componentCode\": ... }\\`**.\n\t\t\t\t\t\t- Ensure the output is **directly parseable** using \\`JSON.parse(output)\\`.\n\t\t\t\t\n\t\t\t\t\t3. **INLINE \\`<style>\\` RULES**\n\t\t\t\t\t\t- Use **only inline** \\`<style>\\` tags (not \\`<style jsx>\\`).\n\t\t\t\t\t\t- Ensure **all CSS is valid** and matches the image precisely.\n\t\t\t\t\t\t- **Use backtick inside the \\`<style>\\` tag like this: <style>{\\`...\\`}</style>**.\n\t\t\t\t\t\t- **Do NOT escape the backtick (\\`\\`\\`) inside the \\`<style>\\` tag**.\n\t\t\t\t\n\t\t\t\t**Before returning, VALIDATE that \\`JSON.parse(output)\\` runs without errors.**\n\t\t\t\t\n\t\t\t\t**EXISTING CODE (to apply branding on):**\n\t\t\t\t${componentCode}\n\t\t \t`.trim();\n\n\t\t\tconst parsed = await callAI<{ componentCode: string }>({\n\t\t\t\tai: \"AWS\",\n\t\t\t\tsliceIndex,\n\t\t\t\tstepName: \"APPEARANCE\",\n\t\t\t\tsystemPrompt,\n\t\t\t\timageFile,\n\t\t\t});\n\n\t\t\tif (!parsed.componentCode) {\n\t\t\t\tthrow new Error(\"Missing key 'componentCode' in AI response.\");\n\t\t\t}\n\n\t\t\treturn parsed.componentCode;\n\t\t}\n\n\t\ttry {\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\targs.sliceImages.map(async (sliceImage, 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 1: 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(index, sliceImage);\n\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"STEP 2: 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 3: 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 4: 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(\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tsliceImage,\n\t\t\t\t\t\t\texistingMocks,\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 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 5: 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 initialCode = await generateSliceComponentCode(\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tsliceImage,\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 6: 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\tindex,\n\t\t\t\t\t\t\tsliceImage,\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 updatedSlices.forEach(\n\t\t\t\tasync ({ updatedSlice, componentCode, updatedMock }, index) => {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"STEP 7: Update the slice code for:\",\n\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t);\n\t\t\t\t\tif (componentCode) {\n\t\t\t\t\t\tconst { errors } = await this.createSlice({\n\t\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\t\tmodel: updatedSlice,\n\t\t\t\t\t\t\tcomponentContents: componentCode,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t`Errors while updating the slice code for ${index} - ${updatedSlice.name}:`,\n\t\t\t\t\t\t\t\terrors,\n\t\t\t\t\t\t\t);\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\t\t\t\t\t} else {\n\t\t\t\t\t\tawait this.createSlice({\n\t\t\t\t\t\t\tlibraryID: DEFAULT_LIBRARY_ID,\n\t\t\t\t\t\t\tmodel: updatedSlice,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"STEP 8: Persist the generated mocks for:\",\n\t\t\t\t\t\t`${index} - ${updatedSlice.name}`,\n\t\t\t\t\t);\n\t\t\t\t\tawait this.updateSliceMocks({\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\tmocks: updatedMock,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconsole.log(\"STEP 9: 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":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","mockSlice","SharedSlice","SliceComparator","UnauthenticatedError","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","bufferCodec","SharedSliceContent","DEFAULT_SLICE_SCREENSHOT_URL","createContentDigest","ConverseCommand","BedrockRuntimeClient"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4OM,MAAO,sBAAsBA,YAAAA,YAAW;AAAA,EAC7C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