Parcourir la source

企业agent配置兼容

jackson il y a 3 semaines
Parent
commit
8a690d3474

+ 1 - 1
README.md

@@ -50,7 +50,7 @@ Gateway 保持“薄网关”边界:
 | `list_order_abnormal_filter_options` | 查询头程问题件六个中文页签 | `/mcp/tools/listOrderAbnormalFilterOptions` | 安全筛选项 |
 | `query_receive_volume_list` | 按入库时间查询收货量已入库订单明细 | `/mcp/tools/queryReceiveVolumeList` | 固定 9 列安全表格 |
 | `query_goods_info` | 按 SKU 或中文品名查询已审核商品资料 | `/mcp/tools/queryGoodsInfo` | 固定 24 列安全表格 |
-| `query_pending_goods_list` | 查询待审核商品 | `/mcp/tools/queryPendingGoodsList` | 固定 22 列安全表格,第一列商品编号 |
+| `query_pending_goods_list` | 查询待审核商品 | `/mcp/tools/queryPendingGoodsList` | 固定 21 列安全表格,第一列商品编号 |
 | `list_pending_goods_filter_options` | 取得待审核商品的客户、起运国、目的国 | `/mcp/tools/listPendingGoodsFilterOptions` | 安全筛选项 |
 | `open_goods_audit` | 打开一条商品审核单 | `/mcp/tools/openGoodsAudit` | 审核单、可选项和参考 |
 | `submit_goods_audit` | 提交一条商品审核 | `/mcp/tools/submitGoodsAudit` | 审核结果 |

+ 7 - 5
app.py

@@ -944,11 +944,13 @@ class GatewayApp:
             elif args.tool in ('open_goods_audit', 'submit_goods_audit'):
                 tool_args.pop('page', None)
                 tool_args.pop('limit', None)
-                if not args.goods_id:
-                    raise ValueError(
-                        '--goods-id is required for ' + args.tool
-                    )
-                tool_args['goods_id'] = args.goods_id
+                if not args.sku:
+                    raise ValueError('--sku is required for ' + args.tool)
+                tool_args['sku'] = args.sku
+                if args.departure_country:
+                    tool_args['departure_country'] = args.departure_country
+                if args.destination_country:
+                    tool_args['destination_country'] = args.destination_country
                 if args.tool == 'submit_goods_audit':
                     if not args.audit_status:
                         raise ValueError(

+ 34 - 2
services/output_presenter.py

@@ -673,8 +673,8 @@ class OutputPresenter:
         ('product_name', '物流产品'),
     )
     PENDING_GOODS_COLUMNS = (
-        ('goods_id', '商品编号'),
-        ('sku', 'SKU'), ('customer_name', '客户名称'),
+        ('sku', '商品编号'),
+        ('customer_name', '客户名称'),
         ('departure_country', '起运国'), ('destination_country', '目的国'),
         ('cn_name', '中文名称'), ('en_name', '英文名称'),
         ('image_url', '产品图片'), ('material_cn', '材质(CN)'),
@@ -3062,6 +3062,20 @@ class OutputPresenter:
             if not self._fuel_rate_message(message):
                 message = self._parameter_message('')
             return self._error_result(code, message, False, meta)
+        elif code == 'MCP_1401' and tool_name in (
+            self.GOODS_AUDIT_OPEN_TOOLS | self.GOODS_AUDIT_SUBMIT_TOOLS
+        ):
+            if self._goods_audit_message(message):
+                return self._error_result(code, message, False, meta)
+            message = self._parameter_message('')
+            return self._error_result(code, message, False, meta)
+        elif code == 'MCP_1501' and tool_name in (
+            self.GOODS_AUDIT_OPEN_TOOLS | self.GOODS_AUDIT_SUBMIT_TOOLS
+        ):
+            if message == '商品不存在':
+                return self._error_result(code, message, False, meta)
+            message = self.ERROR_MESSAGES['MCP_1501']
+            return self._error_result(code, message, False, meta)
         elif code == 'MCP_1401':
             label = self._find_field_label(tool_name, raw_message)
             message = self._parameter_message(label)
@@ -3140,6 +3154,24 @@ class OutputPresenter:
             return True
         return message.startswith('请填写订单') and message.endswith('的重量和体积')
 
+    def _goods_audit_message(self, message):
+        if message in (
+            '请填写商品编号',
+            '只能是待审核或预审通过状态的商品才能审核',
+            '这条商品不能预审通过',
+            '不能把这次审核记成系统审核或改写操作日志',
+            '清关记录编号不是这条商品的',
+            '这条商品不能同步订单',
+            '驳回原因不能为空',
+            '驳回类型不能为空',
+            '驳回类型不正确',
+            '请选择商品标记',
+            '商品标记不在可选项里',
+            '加拿大商品这几项申报只能为否',
+        ):
+            return True
+        return message.startswith('这个商品编号有多条,请补充起运国和目的国')
+
     def _find_field_label(self, tool_name, raw_message):
         message = str(raw_message or '')
         fields = self.FIELD_LABELS.get(tool_name, {})

+ 70 - 14
tests/test_pending_goods_tools.py

@@ -50,9 +50,9 @@ class PendingGoodsToolsTest(unittest.TestCase):
             'meta': {'page': 1, 'limit': 20, 'has_more': False, 'request_id': 'rq'},
         })
         self.assertFalse(result['is_error'])
-        self.assertEqual(22, len(result['structured_content']['headers']))
+        self.assertEqual(21, len(result['structured_content']['headers']))
         self.assertEqual('商品编号', result['structured_content']['headers'][0]['label'])
-        self.assertEqual('经过预审', result['structured_content']['headers'][21]['label'])
+        self.assertEqual('经过预审', result['structured_content']['headers'][20]['label'])
         broken = dict(record)
         broken['extra'] = 'x'
         failed = presenter.present('query_pending_goods_list', {
@@ -229,7 +229,7 @@ class PendingGoodsToolsTest(unittest.TestCase):
 
         opened = OpenGoodsAuditTool().metadata()
         submitted = SubmitGoodsAuditTool().metadata()
-        self.assertEqual(['goods_id'], opened['input_schema']['required'])
+        self.assertEqual(['sku'], opened['input_schema']['required'])
         self.assertFalse(opened['input_schema']['additionalProperties'])
         self.assertFalse(submitted['input_schema']['additionalProperties'])
         self.assertIn('status', submitted['input_schema']['required'])
@@ -244,24 +244,44 @@ class PendingGoodsToolsTest(unittest.TestCase):
 
         client = Client()
         self.assertEqual(
-            2683,
-            OpenGoodsAuditTool(client).call(2683) and client.payload['goods_id'],
+            'CUP-1',
+            OpenGoodsAuditTool(client).call('CUP-1') and client.payload['sku'],
         )
+        OpenGoodsAuditTool(client).call(
+            ' CUP-1 ',
+            departure_country='中国',
+            destination_country='美国',
+        )
+        self.assertEqual('中国', client.payload['departure_country'])
+        self.assertEqual('美国', client.payload['destination_country'])
         with self.assertRaises(RuntimeError):
-            OpenGoodsAuditTool().call(2683)
+            OpenGoodsAuditTool().call('CUP-1')
+        with self.assertRaises(ValueError):
+            OpenGoodsAuditTool(client).call('')
         with self.assertRaises(ValueError):
             OpenGoodsAuditTool(client).call(True)
+        with self.assertRaises(ValueError):
+            OpenGoodsAuditTool(client).call('x' * 201)
+        with self.assertRaises(ValueError):
+            SubmitGoodsAuditTool(client).call('x' * 201, '30')
         SubmitGoodsAuditTool(client).call(
-            2683, '30', audit_result='备注', options={'results': []},
+            'CUP-1', '30',
+            departure_country='中国',
+            destination_country='美国',
+            audit_result='备注',
+            options={'results': []},
         )
         self.assertEqual('30', client.payload['status'])
+        self.assertEqual('CUP-1', client.payload['sku'])
         self.assertEqual('备注', client.payload['audit_result'])
         with self.assertRaises(ValueError):
-            SubmitGoodsAuditTool(client).call(0, '30')
+            SubmitGoodsAuditTool(client).call('', '30')
         with self.assertRaises(ValueError):
-            SubmitGoodsAuditTool(client).call(2683, '10')
+            SubmitGoodsAuditTool(client).call(True, '30')
+        with self.assertRaises(ValueError):
+            SubmitGoodsAuditTool(client).call('CUP-1', '10')
         with self.assertRaises(RuntimeError):
-            SubmitGoodsAuditTool().call(2683, '30')
+            SubmitGoodsAuditTool().call('CUP-1', '30')
 
         presenter = OutputPresenter()
         payload = self._audit_payload()
@@ -392,18 +412,54 @@ class PendingGoodsToolsTest(unittest.TestCase):
         with self.assertRaises(ValueError):
             app.run_cli(['call', '--tool', 'open_goods_audit'], stdout=io.StringIO())
         app.run_cli([
-            'call', '--tool', 'open_goods_audit', '--goods-id', '2683',
+            'call', '--tool', 'open_goods_audit', '--sku', 'CUP-1',
+            '--departure-country', '中国', '--destination-country', '美国',
         ], stdout=io.StringIO())
         with self.assertRaises(ValueError):
             app.run_cli([
-                'call', '--tool', 'submit_goods_audit', '--goods-id', '2683',
+                'call', '--tool', 'submit_goods_audit', '--sku', 'CUP-1',
             ], stdout=io.StringIO())
         app.run_cli([
             'call', '--tool', 'submit_goods_audit',
-            '--goods-id', '2683', '--audit-status', '25',
+            '--sku', 'CUP-1', '--audit-status', '25',
         ], stdout=io.StringIO())
-        self.assertEqual(2683, cli.calls[0]['goods_id'])
+        self.assertEqual('CUP-1', cli.calls[0]['sku'])
         self.assertEqual('25', cli.calls[1]['status'])
+        many = presenter.present('open_goods_audit', {
+            'code': 'MCP_1401',
+            'msg': '请填写商品编号',
+            'data': {},
+            'meta': {'request_id': 'rq'},
+        })
+        self.assertIn('商品编号', many['text'])
+        many = presenter.present('open_goods_audit', {
+            'code': 'MCP_1401',
+            'msg': '这个商品编号有多条,请补充起运国和目的国:客户甲,中国到美国',
+            'data': {},
+            'meta': {'request_id': 'rq'},
+        })
+        self.assertIn('多条', many['text'])
+        missing = presenter.present('open_goods_audit', {
+            'code': 'MCP_1501',
+            'msg': '商品不存在',
+            'data': {},
+            'meta': {'request_id': 'rq'},
+        })
+        self.assertIn('商品不存在', missing['text'])
+        unknown = presenter.present('open_goods_audit', {
+            'code': 'MCP_1401',
+            'msg': '别的参数错了',
+            'data': {},
+            'meta': {'request_id': 'rq'},
+        })
+        self.assertTrue(unknown['is_error'])
+        other = presenter.present('submit_goods_audit', {
+            'code': 'MCP_1501',
+            'msg': '别的不可用',
+            'data': {},
+            'meta': {'request_id': 'rq'},
+        })
+        self.assertIn('目标数据不可用', other['text'])
 
     def _open_error(self, presenter, data):
         return presenter.present('open_goods_audit', {

+ 41 - 10
tools/open_goods_audit.py

@@ -10,7 +10,8 @@ class OpenGoodsAuditTool:
             'name': self.name,
             'description': (
                 '使用场景:用户要打开一条商品的审核单时调用。'
-                '必须使用待审核列表第一列的商品编号,或用户给出的商品编号。'
+                '商品编号就是审核页上的 SKU,不是内部商品 ID。'
+                '同一个商品编号有多条时,先补充起运国和目的国,可以写国家名或国家代码。'
                 '返回审核单、可选项和只看不提交的参考。'
                 '禁止使用:在本工具里提交审核结果,不得改走后台商品审核页。'
                 '参数只用于工具内部调用;最终回答只能展示中文业务名称。'
@@ -18,22 +19,52 @@ class OpenGoodsAuditTool:
             'input_schema': {
                 'type': 'object',
                 'properties': {
-                    'goods_id': {
-                        'type': 'integer',
-                        'minimum': 1,
-                        'description': '商品编号,来自待审核列表或用户给出的审核页编号。',
+                    'sku': {
+                        'type': 'string',
+                        'minLength': 1,
+                        'maxLength': 200,
+                        'description': '商品编号,即审核页上的 SKU。',
+                    },
+                    'departure_country': {
+                        'type': 'string',
+                        'maxLength': 100,
+                        'description': '起运国,国家名或国家代码。同一个商品编号有多条时填写。',
+                    },
+                    'destination_country': {
+                        'type': 'string',
+                        'maxLength': 100,
+                        'description': '目的国,国家名或国家代码。同一个商品编号有多条时填写。',
                     },
                 },
-                'required': ['goods_id'],
+                'required': ['sku'],
                 'additionalProperties': False,
             },
         }
 
-    def call(self, goods_id, request_id='rq_open_goods_audit'):
+    def call(
+        self,
+        sku='',
+        departure_country='',
+        destination_country='',
+        request_id='rq_open_goods_audit',
+        **_ignored,
+    ):
         if self.api_client is None:
             raise RuntimeError('api client is required for open_goods_audit')
-        if not isinstance(goods_id, int) or isinstance(goods_id, bool) or goods_id < 1:
-            raise ValueError('goods_id is invalid')
+        payload = {'sku': self._text(sku)}
+        if departure_country:
+            payload['departure_country'] = self._text(departure_country)
+        if destination_country:
+            payload['destination_country'] = self._text(destination_country)
         return self.api_client.call_tool(
-            self.name, self.route_path, {'goods_id': goods_id}, request_id,
+            self.name, self.route_path, payload, request_id,
         )
+
+    @staticmethod
+    def _text(value):
+        if not isinstance(value, str):
+            raise ValueError('sku is invalid')
+        text = value.strip()
+        if not text or len(text) > 200:
+            raise ValueError('sku is invalid')
+        return text

+ 1 - 1
tools/query_pending_goods_list.py

@@ -17,7 +17,7 @@ class QueryPendingGoodsListTool:
                 '使用场景:用户要看待审核商品时调用。只查商品审核页待审核页签,'
                 '可以不带筛选直接看第一页。客户、起运国、目的国必须先调用'
                 'list_pending_goods_filter_options取得可传值;同名先让用户选定。'
-                '第一列是商品编号。要审核时先用这个编号调用 open_goods_audit。'
+                '第一列是商品编号,也就是审核页上的 SKU。要审核时用这个编号调用 open_goods_audit。'
                 '禁止使用:在本工具里审核、驳回或导出,不得改走query_goods_info。'
                 '参数只用于工具内部调用;最终回答只能展示中文业务名称;'
                 '描述筛选条件时不得展示筛选字段的英文参数名。'

+ 44 - 7
tools/submit_goods_audit.py

@@ -11,7 +11,9 @@ class SubmitGoodsAuditTool:
             'name': self.name,
             'description': (
                 '使用场景:用户已经看过 open_goods_audit 返回的审核单,并确认结果后调用。'
-                '一次只提交一条。字段名和嵌套与打开时的审核单相同。'
+                '用商品编号定位,商品编号就是审核页上的 SKU,不是内部商品 ID。'
+                '同一个商品编号有多条时,带上和打开时相同的起运国、目的国。'
+                '一次只提交一条。审核单字段名和嵌套与打开时相同。'
                 '审核通过交齐清关信息;审核驳回交驳回类型和驳回原因;'
                 '预审通过交备注和商品标记。'
                 '参考、可选项名单和编码旁边的税率提示可以原样带上,服务端会丢掉。'
@@ -21,21 +23,40 @@ class SubmitGoodsAuditTool:
             'input_schema': self._schema(),
         }
 
-    def call(self, goods_id, status, request_id='rq_submit_goods_audit', **extra):
+    def call(
+        self,
+        sku='',
+        status=None,
+        departure_country='',
+        destination_country='',
+        request_id='rq_submit_goods_audit',
+        **extra,
+    ):
         if self.api_client is None:
             raise RuntimeError('api client is required for submit_goods_audit')
-        if not isinstance(goods_id, int) or isinstance(goods_id, bool) or goods_id < 1:
-            raise ValueError('goods_id is invalid')
         status_text = str(status)
         if status_text not in self.STATUSES:
             raise ValueError('status is invalid')
         payload = dict(extra)
-        payload['goods_id'] = goods_id
+        payload['sku'] = self._text(sku)
         payload['status'] = status_text
+        if departure_country:
+            payload['departure_country'] = self._text(departure_country)
+        if destination_country:
+            payload['destination_country'] = self._text(destination_country)
         return self.api_client.call_tool(
             self.name, self.route_path, payload, request_id,
         )
 
+    @staticmethod
+    def _text(value):
+        if not isinstance(value, str):
+            raise ValueError('sku is invalid')
+        text = value.strip()
+        if not text or len(text) > 200:
+            raise ValueError('sku is invalid')
+        return text
+
     def _schema(self):
         text = {'type': 'string'}
         row = {
@@ -78,10 +99,26 @@ class SubmitGoodsAuditTool:
         return {
             'type': 'object',
             'properties': {
+                'sku': {
+                    'type': 'string',
+                    'minLength': 1,
+                    'maxLength': 200,
+                    'description': '商品编号,即审核页上的 SKU。',
+                },
+                'departure_country': {
+                    'type': 'string',
+                    'maxLength': 100,
+                    'description': '起运国,与打开审核单时相同。',
+                },
+                'destination_country': {
+                    'type': 'string',
+                    'maxLength': 100,
+                    'description': '目的国,与打开审核单时相同。',
+                },
                 'goods_id': {
                     'type': 'integer',
                     'minimum': 1,
-                    'description': '商品编号。',
+                    'description': '打开审核单后带出的内部编号。不要向用户索取。',
                 },
                 'goods_clearance_id': {
                     'type': 'string',
@@ -117,6 +154,6 @@ class SubmitGoodsAuditTool:
                 'options': {'type': 'object'},
                 'reference': {'type': 'object'},
             },
-            'required': ['goods_id', 'status'],
+            'required': ['sku', 'status'],
             'additionalProperties': False,
         }