@whyshu/argent-engine 0.8.0-rc.12 → 0.8.0-rc.14
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.
- package/MANIFEST.json +2 -2
- package/engine/VERSION +1 -1
- package/engine/scripts/appointment_grab.py +62 -0
- package/engine/version.mjs +1 -1
- package/package.json +1 -1
package/MANIFEST.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"package": "@whyshu/argent-engine",
|
|
4
4
|
"files": {
|
|
5
|
-
"VERSION": "
|
|
5
|
+
"VERSION": "f6b29e1320531f7ce9ba32cbb9aef8e5f91bb375427b79c58e8eac8d784a324f",
|
|
6
6
|
"agents/catalog.json": "5356a812f2554dfd3115370363d4c3f787a82c9e5928a85d05b2a07c9e4b324d",
|
|
7
7
|
"configs/_aliases.proposed.json": "3a59edf80563bcc20d410d488decad6fd787bd3de9489321367b0783904cd3e5",
|
|
8
8
|
"configs/_migration-plan.proposed.json": "dd9f90b0b9b2f217dd23367a618402e57997d44f7fddcfa88a7cadf52e056c0d",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"scripts/appointment-create.mjs": "3448966cebc767160cb151a27ccf2b6f6439c80f970f769621058871f95433cc",
|
|
58
58
|
"scripts/appointment-stop.mjs": "2e0a965346d33ef8683da5473c48df7f4e66ee8a3167526ee6b568e1adf5c91d",
|
|
59
59
|
"scripts/appointment-worker.mjs": "e79486eab2b902d351a75885258f2a74b871b29c0e83fccedd9eccc6029b2bdd",
|
|
60
|
-
"scripts/appointment_grab.py": "
|
|
60
|
+
"scripts/appointment_grab.py": "592baf4599a55f801393166253fe4fcde63e0393fc41b5a0bc7888b0749593a7",
|
|
61
61
|
"scripts/archive/feishu-bridge.js": "e6714c72022892d0c527d1fc9ae0f8ff99f9ab3bd0363329979b423246684885",
|
|
62
62
|
"scripts/argent-agents.mjs": "73f4a058df2cd6d62b285ea48a5e32881db678b63007d1ac2f218005cb28c18d",
|
|
63
63
|
"scripts/argent-capabilities.mjs": "7186d7c19f733d987a7afe2355dd7d788333a15c0f80811c4cde4e7a32584c4e",
|
package/engine/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.8.0-rc.
|
|
1
|
+
0.8.0-rc.14
|
|
@@ -10,6 +10,7 @@ import argparse
|
|
|
10
10
|
import asyncio
|
|
11
11
|
import time
|
|
12
12
|
import json
|
|
13
|
+
import urllib.request
|
|
13
14
|
import os
|
|
14
15
|
import signal
|
|
15
16
|
import sys
|
|
@@ -292,6 +293,8 @@ async def run_task(task: dict) -> dict:
|
|
|
292
293
|
args = SimpleNamespace(record_id='', sku=task.get('sku', ''), qty=task.get('quantity'), box=task.get('boxCount'),
|
|
293
294
|
shipment_id=task.get('shipmentNo') or '', store_name=store, no_lock=True)
|
|
294
295
|
orch = O.Orchestrator(cfg, sel, args)
|
|
296
|
+
global _ORCH
|
|
297
|
+
_ORCH = orch
|
|
295
298
|
orch.state.store_name = store
|
|
296
299
|
orch.state.record_id = ''
|
|
297
300
|
orch.state.sku = str(task.get('sku') or '')
|
|
@@ -445,6 +448,62 @@ async def run_task(task: dict) -> dict:
|
|
|
445
448
|
_APPT_CLOSE_LAST = {'closed': 0}
|
|
446
449
|
|
|
447
450
|
|
|
451
|
+
_ORCH = None
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def _http_sync(url: str, method: str = 'GET', timeout: float = 2.0):
|
|
455
|
+
req = urllib.request.Request(url, method=method)
|
|
456
|
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
|
457
|
+
return r.read()
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def _close_appointment_tab_via_cdp(orch) -> int:
|
|
461
|
+
"""同步 CDP 关闭(2026-11-07 第二轮修复)。
|
|
462
|
+
|
|
463
|
+
停止信号会让事件循环提前关闭,``await page.close()`` 会报 ``no running event loop``
|
|
464
|
+
(客户机日志实证)⇒ 清理必须在**事件循环之外**用 CDP HTTP 同步完成。
|
|
465
|
+
"""
|
|
466
|
+
closed = 0
|
|
467
|
+
try:
|
|
468
|
+
browser = getattr(orch, 'browser', None) if orch is not None else None
|
|
469
|
+
endpoint = str(getattr(browser, 'cdp_url', '') or '').rstrip('/')
|
|
470
|
+
if not endpoint:
|
|
471
|
+
return 0
|
|
472
|
+
targets = json.loads(_http_sync(f'{endpoint}/json/list').decode('utf-8', 'replace') or '[]')
|
|
473
|
+
appt = [t for t in targets if 'appointment-v2' in str(t.get('url') or '')]
|
|
474
|
+
if not appt:
|
|
475
|
+
try: orch._log(' ⚠️ 同步清理:未发现 appointment-v2 标签页')
|
|
476
|
+
except Exception: pass
|
|
477
|
+
return 0
|
|
478
|
+
# 只有预约页是窗口里最后一个页面时才开占位页;用户/店铺已有其它标签 → 直接关(不制造空页)
|
|
479
|
+
others = [
|
|
480
|
+
t for t in targets
|
|
481
|
+
if t not in appt and str(t.get('type') or '') == 'page'
|
|
482
|
+
and not str(t.get('url') or '').startswith('about:')
|
|
483
|
+
and 'chrome-extension://' not in str(t.get('url') or '')
|
|
484
|
+
]
|
|
485
|
+
if not others:
|
|
486
|
+
try: _http_sync(f'{endpoint}/json/new?about:blank', method='PUT')
|
|
487
|
+
except Exception:
|
|
488
|
+
try: _http_sync(f'{endpoint}/json/new?about:blank')
|
|
489
|
+
except Exception: pass
|
|
490
|
+
for t in appt:
|
|
491
|
+
tid = str(t.get('id') or '')
|
|
492
|
+
if not tid: continue
|
|
493
|
+
try:
|
|
494
|
+
_http_sync(f'{endpoint}/json/close/{tid}')
|
|
495
|
+
closed += 1
|
|
496
|
+
try: orch._log(f' 🗂️ 同步 CDP 已关闭预约标签页({str(t.get("url"))[:100]})')
|
|
497
|
+
except Exception: pass
|
|
498
|
+
except Exception as e:
|
|
499
|
+
try: orch._log(f' ⚠️ 同步 CDP 关闭失败:{str(e)[:120]}')
|
|
500
|
+
except Exception: pass
|
|
501
|
+
except Exception as e:
|
|
502
|
+
try: orch._log(f' ⚠️ 同步 CDP 清理异常:{str(e)[:120]}')
|
|
503
|
+
except Exception: pass
|
|
504
|
+
return closed
|
|
505
|
+
|
|
506
|
+
|
|
448
507
|
def _on_term(signum, frame):
|
|
449
508
|
# SIGTERM 默认直接退出,不会执行 run_task 的 finally ⇒ 预约标签页残留。
|
|
450
509
|
# 抛 KeyboardInterrupt 交给 asyncio.run 取消主任务,确保 finally 里的标签页清理执行。
|
|
@@ -459,6 +518,9 @@ def main():
|
|
|
459
518
|
out = asyncio.run(run_task(task))
|
|
460
519
|
except KeyboardInterrupt:
|
|
461
520
|
closed = int(_APPT_CLOSE_LAST.get('closed') or 0)
|
|
521
|
+
# 事件循环已关闭 ⇒ await 清理不可用;用 CDP HTTP 同步兜底(2026-11-07 客户机实证)
|
|
522
|
+
if _ORCH is not None:
|
|
523
|
+
closed = max(closed, _close_appointment_tab_via_cdp(_ORCH))
|
|
462
524
|
out = {
|
|
463
525
|
'status': 'stopped',
|
|
464
526
|
'summary': ('收到停止请求,已关闭预约标签页' if closed > 0
|
package/engine/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.8.0-rc.
|
|
1
|
+
export const VERSION = "0.8.0-rc.14"
|