diff --git a/src/defaultSkills/article-image-edit.SKILL b/src/defaultSkills/article-image-edit.SKILL new file mode 100644 index 0000000..59c1206 --- /dev/null +++ b/src/defaultSkills/article-image-edit.SKILL @@ -0,0 +1,41 @@ +Artikelbild X von Artikel Y Änderung User Intent + +# Goal +Handle user requests to edit, replace, or remove the background of an article image (e.g. "Artikelbild X von Artikel Y ändern"). + +# Procedure +1. Use `search_articles` to get the full hash of that article image. +2. Directly call `edit_image` with the vfsfilename `image/`. +3. When the user is asking for background removal, do NOT try to make it transparent, white is good enough. + +# Upload pattern +Run this pattern in `javascript_execute` to backup the original image, delete the old image, and upload the updated image: + +```js +module.exports = (async () => { + const sku = "ARTICLE-SKU"; + const hash = "IMAGE-FULL-HASH"; + const photoNumber = 2; + const path = `images/backupimage${photoNumber}ofArticle_${sku}.avif`; + + const image = await fetch(`/image/${hash}`); + if (!image.ok) throw Error(`Download failed: ${image.status}`); + fs.writeFileSync(path, Buffer.from(await image.arrayBuffer())); + + const del = await fetch(`/article/${encodeURIComponent(sku)}/image/${hash}`, { + method: "DELETE" + }); + if (!del.ok) throw Error(`Delete failed: ${del.status}`); + + const upload = await fetch(`/article/${encodeURIComponent(sku)}/image`, { + method: "POST", + headers: { "Content-Type": "image/avif" }, + body: fs.readFileSync(path) + }); + + return { path, status: upload.status, body: await upload.text() }; +})(); +``` + +# Response +In your final response to the user, inline display the backup image and the final image.