#!/usr/bin/env python3 # -*- coding: utf-8 -*- """专题四 · 步骤 4 · 修改后:替换 chat.py 的 _ensure_system_first 为合并逻辑。""" from __future__ import annotations import sys import _bootstrap # noqa: F401 import _config as C import _plugin_patch as P from dify_api import Dify def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: d.login() chat_path = P.find_plugin_file(d, "chat.py") print("chat.py:", chat_path) content = P.read_remote_file(d, chat_path) new_content = P.replace_function(content, "_ensure_system_first", P.ENSURE_SYSTEM_FIRST) P.deploy_plugin_file(d, chat_path, new_content) print("已应用合并 system 补丁并重启 plugin_daemon") return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())