mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:49:19 +08:00
fix: 发布助手去掉读表单空转并修正工具状态卡住
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
"""发布场景前端工具:读快照用请求体注入;写工具由 streamer 推 client_tool 事件。"""
|
||||
"""发布场景前端写工具:读快照注入 system;写工具由 streamer 推 client_tool 事件。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.tools import StructuredTool
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class _EmptyArgs(BaseModel):
|
||||
pass
|
||||
|
||||
|
||||
class SetGoodsNameArgs(BaseModel):
|
||||
goodsName: str = Field(description="商品标题,建议 60 字内")
|
||||
|
||||
@@ -28,16 +23,19 @@ class SpecAxis(BaseModel):
|
||||
|
||||
class SetSpecAxesArgs(BaseModel):
|
||||
axes: list[SpecAxis] = Field(
|
||||
description="完整规格轴;将替换表单现有规格轴并重建 SKU 行"
|
||||
description=(
|
||||
"完整规格轴;同维改文案会保留已有 SKU 编码,"
|
||||
"新增取值才新建空编码行"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def build_publish_client_tools(
|
||||
*,
|
||||
form_snapshot: dict[str, Any] | None,
|
||||
form_snapshot: dict[str, Any] | None = None,
|
||||
) -> list[Any]:
|
||||
def get_snapshot() -> str:
|
||||
return json.dumps(form_snapshot or {}, ensure_ascii=False, default=str)
|
||||
"""仅注册写工具;读快照已注入 system,避免再占一轮「读取发布表单」。"""
|
||||
del form_snapshot # 快照由 system 注入,工具闭包不再依赖
|
||||
|
||||
def set_goods_name(goodsName: str) -> str:
|
||||
return f"已请求写入标题:{goodsName}"
|
||||
@@ -50,12 +48,6 @@ def build_publish_client_tools(
|
||||
return f"已请求写入 {n} 个规格维,页面将重建 SKU 行"
|
||||
|
||||
return [
|
||||
StructuredTool.from_function(
|
||||
func=get_snapshot,
|
||||
name="ui_get_publish_snapshot",
|
||||
description="读取当前发布表单快照:标题、描述、类目、规格轴、SKU 行(含商家编码)等。改表前应先调用。",
|
||||
args_schema=_EmptyArgs,
|
||||
),
|
||||
StructuredTool.from_function(
|
||||
func=set_goods_name,
|
||||
name="ui_set_goods_name",
|
||||
@@ -71,11 +63,12 @@ def build_publish_client_tools(
|
||||
StructuredTool.from_function(
|
||||
func=set_spec_axes,
|
||||
name="ui_set_spec_axes",
|
||||
description="设置规格轴(维名+值列表)。页面会按笛卡尔积重建 SKU 行。",
|
||||
description="设置规格轴(维名+值列表)。同维相同/改名的取值会保留已有 SKU 商家编码;新增取值才新建空编码行。",
|
||||
args_schema=SetSpecAxesArgs,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def is_client_tool_name(name: str) -> bool:
|
||||
return (name or "").startswith("ui_")
|
||||
"""需前端执行的写工具(ui_set_*);读类工具不走 client_tool。"""
|
||||
return (name or "").startswith("ui_set_")
|
||||
|
||||
Reference in New Issue
Block a user