1233 lines
44 KiB
Python
1233 lines
44 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
AI 工具定义
|
||
将 PS 操作注册为 function calling 的 tool schema
|
||
前端收到 tool_calls 后执行 JSX,把结果回传
|
||
"""
|
||
|
||
# ==================== 工具 Schema(OpenAI function calling 格式)====================
|
||
|
||
PS_TOOLS = [
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_document_info",
|
||
"description": "获取当前 Photoshop 文档信息(名称、尺寸、分辨率)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_layer_structure",
|
||
"description": "获取当前文档的图层结构树(所有顶层组和子图层)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "create_layer",
|
||
"description": "在 Photoshop 中创建新图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "新图层的名称"}
|
||
},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "rename_layer",
|
||
"description": "重命名当前选中的图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"new_name": {"type": "string", "description": "新名称"}},
|
||
"required": ["new_name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "delete_layer",
|
||
"description": "删除当前选中的图层",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "duplicate_layer",
|
||
"description": "复制当前选中的图层",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "align_layers",
|
||
"description": "对齐当前选中的图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"type": {
|
||
"type": "string",
|
||
"enum": [
|
||
"left",
|
||
"right",
|
||
"centerH",
|
||
"top",
|
||
"bottom",
|
||
"centerV",
|
||
],
|
||
"description": "对齐方式:left=左对齐, right=右对齐, centerH=水平居中, top=顶对齐, bottom=底对齐, centerV=垂直居中",
|
||
}
|
||
},
|
||
"required": ["type"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "merge_layers",
|
||
"description": "合并当前选中的图层",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "create_layer_group",
|
||
"description": "创建图层组(如果不存在)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层组名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "move_layer_to_group",
|
||
"description": "将当前图层移入指定图层组",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"group_name": {"type": "string", "description": "目标图层组名称"}
|
||
},
|
||
"required": ["group_name"],
|
||
},
|
||
},
|
||
},
|
||
# ==================== 套图工具 ====================
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "identify_pieces",
|
||
"description": "识别裁片部位。截取当前PS画布并分析每个裁片图层的形状和位置,用视觉AI识别哪个图层是前片、后片、袖子等。应在套图前先调用,以建立图层名到裁片部位的对应关系。",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "generate_garment_preview",
|
||
"description": "【阶段1-生成预览】将用户上传的成衣照片中的花样,填充到 PS 文档的裁片轮廓上,生成一张带轮廓的花样预览图。预览图会显示在聊天中,供用户确认效果。需要用户已上传成衣图片。",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "generate_design_images",
|
||
"description": "通用豆包出图。按提示词生成设计图、方向图、概念图、背景图或海报素材。支持纯文生图;如果当前聊天里已上传参考图,可设置 use_reference_image=true 基于该图继续出图。count 大于 1 时会返回 1 到 4 张连贯方案图。",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"prompt": {
|
||
"type": "string",
|
||
"description": "生成要求。尽量写清主体、风格、构图、配色、材质、光线、氛围和用途。",
|
||
},
|
||
"count": {
|
||
"type": "integer",
|
||
"description": "生成数量,1 到 4,默认 1。",
|
||
},
|
||
"use_reference_image": {
|
||
"type": "boolean",
|
||
"description": "是否使用当前聊天最近上传的图片作为参考图。",
|
||
},
|
||
"size": {
|
||
"type": "string",
|
||
"description": "输出尺寸,默认 2K。",
|
||
},
|
||
},
|
||
"required": ["prompt"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "extract_and_apply_all_pieces",
|
||
"description": "【阶段2-正式套图】用户确认预览OK后调用。自动根据 pattern_mode 选择策略:all_over模式=生成一张面料图覆盖所有裁片(最快);placement模式=逐片处理。all_over模式下不需要先生成预览图(generate_garment_preview),直接调用即可。",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"pieces": {
|
||
"type": "array",
|
||
"items": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {
|
||
"type": "string",
|
||
"description": "裁片图层名称(使用实际图层名)",
|
||
},
|
||
"type": {
|
||
"type": "string",
|
||
"enum": [
|
||
"solid",
|
||
"all_over",
|
||
"fill_pattern",
|
||
"theme_pattern",
|
||
"mixed_pattern",
|
||
],
|
||
"description": "图案类型",
|
||
},
|
||
"color": {
|
||
"type": "string",
|
||
"description": "颜色 hex(solid/theme_pattern 必填)",
|
||
},
|
||
"description": {
|
||
"type": "string",
|
||
"description": "图案描述",
|
||
},
|
||
},
|
||
"required": ["name", "type"],
|
||
},
|
||
"description": "裁片列表,type/color 来自 identify_pieces 的分析结果",
|
||
}
|
||
},
|
||
"required": ["pieces"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "verify_pattern_result",
|
||
"description": "验证套图效果。自动截取当前 PS 画布与原始成衣对比,由视觉 AI 评分(1-10)并给出改进建议。应在套图完成后调用。",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
# ==================== PS 通用操作工具 ====================
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "move_layer",
|
||
"description": "移动图层。dx 正值向右,dy 正值向下(单位像素)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"dx": {"type": "number", "description": "水平位移(像素,正=右)"},
|
||
"dy": {"type": "number", "description": "垂直位移(像素,正=下)"},
|
||
},
|
||
"required": ["name", "dx", "dy"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "resize_layer",
|
||
"description": "缩放图层(百分比)。100=不变,200=放大2倍,50=缩小一半",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"scale_x": {"type": "number", "description": "水平缩放百分比"},
|
||
"scale_y": {
|
||
"type": "number",
|
||
"description": "垂直缩放百分比(省略则与 scale_x 相同)",
|
||
},
|
||
},
|
||
"required": ["name", "scale_x"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "rotate_layer",
|
||
"description": "旋转图层(角度,正值=顺时针)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"angle": {"type": "number", "description": "旋转角度(正=顺时针)"},
|
||
},
|
||
"required": ["name", "angle"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "flip_layer",
|
||
"description": "翻转图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"direction": {
|
||
"type": "string",
|
||
"enum": ["horizontal", "vertical"],
|
||
"description": "翻转方向",
|
||
},
|
||
},
|
||
"required": ["name", "direction"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_layer_opacity",
|
||
"description": "设置图层透明度(0=完全透明,100=完全不透明)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"opacity": {"type": "number", "description": "透明度 0-100"},
|
||
},
|
||
"required": ["name", "opacity"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_layer_blend_mode",
|
||
"description": "设置图层混合模式",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"mode": {
|
||
"type": "string",
|
||
"enum": [
|
||
"normal",
|
||
"multiply",
|
||
"screen",
|
||
"overlay",
|
||
"darken",
|
||
"lighten",
|
||
"color_dodge",
|
||
"color_burn",
|
||
"soft_light",
|
||
"hard_light",
|
||
"difference",
|
||
"exclusion",
|
||
"hue",
|
||
"saturation",
|
||
"color",
|
||
"luminosity",
|
||
],
|
||
"description": "混合模式",
|
||
},
|
||
},
|
||
"required": ["name", "mode"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_layer_visible",
|
||
"description": "显示或隐藏图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"visible": {
|
||
"type": "boolean",
|
||
"description": "true=显示,false=隐藏",
|
||
},
|
||
},
|
||
"required": ["name", "visible"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_text_content",
|
||
"description": "修改文字图层的文本内容",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "文字图层名称"},
|
||
"text": {"type": "string", "description": "新的文本内容"},
|
||
},
|
||
"required": ["name", "text"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_text_color",
|
||
"description": "修改文字图层的颜色",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "文字图层名称"},
|
||
"color": {
|
||
"type": "string",
|
||
"description": "颜色 hex 值,如 #FF0000",
|
||
},
|
||
},
|
||
"required": ["name", "color"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_text_size",
|
||
"description": "修改文字图层的字号(像素)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "文字图层名称"},
|
||
"size": {"type": "number", "description": "字号(像素)"},
|
||
},
|
||
"required": ["name", "size"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "group_layers",
|
||
"description": "将多个图层编组",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"layer_names": {
|
||
"type": "array",
|
||
"items": {"type": "string"},
|
||
"description": "要编组的图层名称列表",
|
||
},
|
||
"group_name": {"type": "string", "description": "组名称"},
|
||
},
|
||
"required": ["layer_names", "group_name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "merge_visible",
|
||
"description": "合并所有可见图层",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "flatten_image",
|
||
"description": "拼合图像(所有图层合并为背景层)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "resize_canvas",
|
||
"description": "调整画布大小(像素)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"width": {"type": "number", "description": "画布宽度(像素)"},
|
||
"height": {"type": "number", "description": "画布高度(像素)"},
|
||
"anchor": {
|
||
"type": "string",
|
||
"enum": [
|
||
"top-left",
|
||
"top",
|
||
"top-right",
|
||
"left",
|
||
"center",
|
||
"right",
|
||
"bottom-left",
|
||
"bottom",
|
||
"bottom-right",
|
||
],
|
||
"description": "锚点位置(默认 center)",
|
||
},
|
||
},
|
||
"required": ["width", "height"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "adjust_brightness_contrast",
|
||
"description": "调整当前图层的亮度和对比度",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"brightness": {"type": "number", "description": "亮度 -150 到 150"},
|
||
"contrast": {"type": "number", "description": "对比度 -50 到 100"},
|
||
},
|
||
"required": ["brightness", "contrast"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "desaturate",
|
||
"description": "将当前图层去色(变为灰度)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "rasterize_layer",
|
||
"description": "栅格化图层(将智能对象/文字/形状转为像素图层)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "align_layers_tool",
|
||
"description": "对齐多个图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"layer_names": {
|
||
"type": "array",
|
||
"items": {"type": "string"},
|
||
"description": "要对齐的图层名",
|
||
},
|
||
"alignment": {
|
||
"type": "string",
|
||
"enum": [
|
||
"left",
|
||
"center_h",
|
||
"right",
|
||
"top",
|
||
"center_v",
|
||
"bottom",
|
||
],
|
||
"description": "对齐方式",
|
||
},
|
||
},
|
||
"required": ["layer_names", "alignment"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "distribute_layers",
|
||
"description": "等距分布多个图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"layer_names": {
|
||
"type": "array",
|
||
"items": {"type": "string"},
|
||
"description": "要分布的图层名",
|
||
},
|
||
"direction": {
|
||
"type": "string",
|
||
"enum": ["horizontal", "vertical"],
|
||
"description": "分布方向",
|
||
},
|
||
},
|
||
"required": ["layer_names", "direction"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "add_stroke",
|
||
"description": "给图层添加描边效果",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"size": {"type": "number", "description": "描边宽度(像素)"},
|
||
"color": {
|
||
"type": "string",
|
||
"description": "描边颜色 hex,如 #FF0000",
|
||
},
|
||
"position": {
|
||
"type": "string",
|
||
"enum": ["outside", "inside", "center"],
|
||
"description": "描边位置(默认 outside)",
|
||
},
|
||
},
|
||
"required": ["name", "size", "color"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "create_clipping_mask",
|
||
"description": "为图层创建剪贴蒙版(裁切到下方图层形状)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "release_clipping_mask",
|
||
"description": "释放图层的剪贴蒙版",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "undo",
|
||
"description": "撤销操作(Ctrl+Z),可指定步数",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"steps": {"type": "number", "description": "撤销步数(默认 1)"}
|
||
},
|
||
"required": [],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_layer_bounds",
|
||
"description": "获取图层的位置和尺寸信息(left/top/width/height/center)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "create_document",
|
||
"description": "新建 Photoshop 文档",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"width": {"type": "number", "description": "宽度(像素)"},
|
||
"height": {"type": "number", "description": "高度(像素)"},
|
||
"resolution": {
|
||
"type": "number",
|
||
"description": "分辨率 DPI(默认 150)",
|
||
},
|
||
"name": {"type": "string", "description": "文档名称"},
|
||
},
|
||
"required": ["width", "height"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "save_document",
|
||
"description": "保存当前文档(Ctrl+S)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "resize_image",
|
||
"description": "调整图像大小(像素/分辨率)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"width": {"type": "number", "description": "新宽度(像素)"},
|
||
"height": {"type": "number", "description": "新高度(像素)"},
|
||
"resolution": {
|
||
"type": "number",
|
||
"description": "新分辨率 DPI(可选)",
|
||
},
|
||
},
|
||
"required": ["width", "height"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "gaussian_blur",
|
||
"description": "对当前图层应用高斯模糊",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"radius": {"type": "number", "description": "模糊半径(像素)"}
|
||
},
|
||
"required": ["radius"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "auto_levels",
|
||
"description": "自动色阶(快速修正色调范围)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "auto_contrast",
|
||
"description": "自动对比度",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "invert_colors",
|
||
"description": "反相(颜色取反)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "convert_to_rgb",
|
||
"description": "转换为 RGB 色彩模式",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "convert_to_cmyk",
|
||
"description": "转换为 CMYK 色彩模式(印刷用)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "add_drop_shadow",
|
||
"description": "给图层添加投影效果",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"distance": {"type": "number", "description": "投影距离(像素)"},
|
||
"size": {"type": "number", "description": "投影大小/模糊(像素)"},
|
||
"opacity": {
|
||
"type": "number",
|
||
"description": "投影不透明度 0-100(默认 75)",
|
||
},
|
||
"angle": {"type": "number", "description": "光照角度(默认 120)"},
|
||
},
|
||
"required": ["name", "distance", "size"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "clear_layer_effects",
|
||
"description": "清除图层的所有图层样式(投影/描边/发光等)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "bring_to_front",
|
||
"description": "将图层移到最顶层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "send_to_back",
|
||
"description": "将图层移到最底层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "crop_document",
|
||
"description": "裁切画布到指定区域(像素坐标)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"left": {"type": "number"},
|
||
"top": {"type": "number"},
|
||
"right": {"type": "number"},
|
||
"bottom": {"type": "number"},
|
||
},
|
||
"required": ["left", "top", "right", "bottom"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "trim_document",
|
||
"description": "自动裁切(去除透明或纯色边缘)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"type": {
|
||
"type": "string",
|
||
"enum": ["transparent", "topleft"],
|
||
"description": "裁切依据(默认 topleft 即左上角颜色)",
|
||
}
|
||
},
|
||
"required": [],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "add_guide",
|
||
"description": "添加参考线",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"position": {"type": "number", "description": "位置(像素)"},
|
||
"direction": {
|
||
"type": "string",
|
||
"enum": ["horizontal", "vertical"],
|
||
"description": "方向",
|
||
},
|
||
},
|
||
"required": ["position", "direction"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "clear_guides",
|
||
"description": "清除所有参考线",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "fill_selection",
|
||
"description": "用颜色填充当前选区",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"color": {"type": "string", "description": "填充颜色 hex"},
|
||
"opacity": {
|
||
"type": "number",
|
||
"description": "填充不透明度 0-100(默认 100)",
|
||
},
|
||
},
|
||
"required": ["color"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "inverse_selection",
|
||
"description": "反选(选中未选区域)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "feather_selection",
|
||
"description": "羽化选区边缘",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"radius": {"type": "number", "description": "羽化半径(像素)"}
|
||
},
|
||
"required": ["radius"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "adjust_levels",
|
||
"description": "调整色阶(输入黑点/灰度系数/白点)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"black": {
|
||
"type": "number",
|
||
"description": "输入黑点 0-253(默认 0)",
|
||
},
|
||
"gamma": {
|
||
"type": "number",
|
||
"description": "灰度系数 0.1-9.99(默认 1.0,<1变暗 >1变亮)",
|
||
},
|
||
"white": {
|
||
"type": "number",
|
||
"description": "输入白点 2-255(默认 255)",
|
||
},
|
||
},
|
||
"required": ["black", "gamma", "white"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "copy_merged_to_new_layer",
|
||
"description": "复制合并所有可见内容到新图层(Ctrl+Shift+C + 粘贴)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "lock_layer",
|
||
"description": "锁定或解锁图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"locked": {
|
||
"type": "boolean",
|
||
"description": "true=锁定,false=解锁",
|
||
},
|
||
},
|
||
"required": ["name", "locked"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "set_foreground_color",
|
||
"description": "设置前景色",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"color": {"type": "string", "description": "颜色 hex 值"}
|
||
},
|
||
"required": ["color"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "save_document_as",
|
||
"description": "文件另存为(支持 PSD/PNG/JPG)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"path": {"type": "string", "description": "保存路径"},
|
||
"format": {
|
||
"type": "string",
|
||
"enum": ["psd", "png", "jpg"],
|
||
"description": "文件格式",
|
||
},
|
||
},
|
||
"required": ["path"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "add_layer_mask",
|
||
"description": "为图层添加蒙版(全白=全显示 / 全黑=全隐藏 / 基于当前选区)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"hide_all": {
|
||
"type": "boolean",
|
||
"description": "true=全黑蒙版(隐藏),false=全白蒙版(显示,默认)",
|
||
},
|
||
},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "delete_layer_mask",
|
||
"description": "删除图层蒙版",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"apply": {
|
||
"type": "boolean",
|
||
"description": "true=应用蒙版后删除,false=直接丢弃(默认)",
|
||
},
|
||
},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "convert_to_smart_object",
|
||
"description": "将图层转为智能对象",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {"name": {"type": "string", "description": "图层名称"}},
|
||
"required": ["name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "adjust_hsl",
|
||
"description": "调整色相/饱和度/明度(H=-180~180, S=-100~100, L=-100~100)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"hue": {"type": "number", "description": "色相偏移 -180到180"},
|
||
"saturation": {"type": "number", "description": "饱和度 -100到100"},
|
||
"lightness": {"type": "number", "description": "明度 -100到100"},
|
||
},
|
||
"required": ["hue", "saturation", "lightness"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "create_text_layer",
|
||
"description": "创建文字图层",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"text": {"type": "string", "description": "文字内容"},
|
||
"x": {"type": "number", "description": "X 坐标(像素)"},
|
||
"y": {"type": "number", "description": "Y 坐标(像素)"},
|
||
"font_size": {"type": "number", "description": "字号(像素)"},
|
||
"color": {"type": "string", "description": "颜色 hex(默认黑色)"},
|
||
"font_name": {"type": "string", "description": "字体名称(可选)"},
|
||
},
|
||
"required": ["text", "x", "y", "font_size"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_active_layer_info",
|
||
"description": "获取当前选中图层的详细信息(名称/类型/尺寸/位置/透明度/混合模式等)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "list_all_layer_names",
|
||
"description": "列出文档中所有图层名称(扁平列表,含类型和可见性)",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "duplicate_layer_to_document",
|
||
"description": "复制图层到另一个已打开的文档",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"name": {"type": "string", "description": "图层名称"},
|
||
"target_doc": {"type": "string", "description": "目标文档名称"},
|
||
},
|
||
"required": ["name", "target_doc"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "switch_document",
|
||
"description": "切换到另一个已打开的文档",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"doc_name": {"type": "string", "description": "文档名称"}
|
||
},
|
||
"required": ["doc_name"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "list_documents",
|
||
"description": "列出所有已打开的文档",
|
||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_pixel_color",
|
||
"description": "获取画布上指定坐标的像素颜色(取色器)",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"x": {"type": "number", "description": "X 坐标"},
|
||
"y": {"type": "number", "description": "Y 坐标"},
|
||
},
|
||
"required": ["x", "y"],
|
||
},
|
||
},
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "close_document",
|
||
"description": "关闭当前文档",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"save": {"type": "boolean", "description": "是否保存(默认不保存)"}
|
||
},
|
||
"required": [],
|
||
},
|
||
},
|
||
},
|
||
]
|
||
|
||
# 工具名称映射(中文显示用)
|
||
TOOL_DISPLAY_NAMES = {
|
||
"get_document_info": "查看文档信息",
|
||
"get_layer_structure": "查看图层结构",
|
||
"create_layer": "新建图层",
|
||
"rename_layer": "重命名图层",
|
||
"delete_layer": "删除图层",
|
||
"duplicate_layer": "复制图层",
|
||
"align_layers": "对齐图层",
|
||
"merge_layers": "合并图层",
|
||
"create_layer_group": "创建图层组",
|
||
"move_layer_to_group": "移入图层组",
|
||
"identify_pieces": "识别裁片部位",
|
||
"generate_garment_preview": "生成花样预览",
|
||
"generate_design_images": "豆包出图",
|
||
"extract_and_apply_all_pieces": "提取并套图",
|
||
"verify_pattern_result": "验证套图效果",
|
||
# PS 通用操作
|
||
"move_layer": "移动图层",
|
||
"resize_layer": "缩放图层",
|
||
"rotate_layer": "旋转图层",
|
||
"flip_layer": "翻转图层",
|
||
"set_layer_opacity": "设置透明度",
|
||
"set_layer_blend_mode": "设置混合模式",
|
||
"set_layer_visible": "显示/隐藏图层",
|
||
"set_text_content": "修改文字",
|
||
"set_text_color": "修改文字颜色",
|
||
"set_text_size": "修改字号",
|
||
"group_layers": "编组图层",
|
||
"merge_visible": "合并可见",
|
||
"flatten_image": "拼合图像",
|
||
"resize_canvas": "调整画布",
|
||
"adjust_brightness_contrast": "亮度/对比度",
|
||
"desaturate": "去色",
|
||
"rasterize_layer": "栅格化",
|
||
"align_layers_tool": "对齐图层",
|
||
"distribute_layers": "分布图层",
|
||
"add_stroke": "添加描边",
|
||
"create_clipping_mask": "创建剪贴蒙版",
|
||
"release_clipping_mask": "释放剪贴蒙版",
|
||
"undo": "撤销",
|
||
"get_layer_bounds": "获取图层位置",
|
||
"create_document": "新建文档",
|
||
"save_document": "保存文档",
|
||
"resize_image": "调整图像大小",
|
||
"gaussian_blur": "高斯模糊",
|
||
"auto_levels": "自动色阶",
|
||
"auto_contrast": "自动对比度",
|
||
"invert_colors": "反相",
|
||
"convert_to_rgb": "转RGB",
|
||
"convert_to_cmyk": "转CMYK",
|
||
"add_drop_shadow": "添加投影",
|
||
"clear_layer_effects": "清除图层样式",
|
||
"bring_to_front": "置顶图层",
|
||
"send_to_back": "置底图层",
|
||
"crop_document": "裁切画布",
|
||
"trim_document": "自动裁切",
|
||
"add_guide": "添加参考线",
|
||
"clear_guides": "清除参考线",
|
||
"fill_selection": "填充选区",
|
||
"inverse_selection": "反选",
|
||
"feather_selection": "羽化选区",
|
||
"adjust_levels": "色阶",
|
||
"copy_merged_to_new_layer": "复制合并",
|
||
"lock_layer": "锁定图层",
|
||
"set_foreground_color": "设置前景色",
|
||
"save_document_as": "另存为",
|
||
"add_layer_mask": "添加蒙版",
|
||
"delete_layer_mask": "删除蒙版",
|
||
"convert_to_smart_object": "转智能对象",
|
||
"adjust_hsl": "色相/饱和度",
|
||
"create_text_layer": "创建文字",
|
||
"get_active_layer_info": "查看当前图层",
|
||
"list_all_layer_names": "列出所有图层",
|
||
"duplicate_layer_to_document": "复制到文档",
|
||
"switch_document": "切换文档",
|
||
"list_documents": "列出文档",
|
||
"get_pixel_color": "取色",
|
||
"close_document": "关闭文档",
|
||
}
|