Files
MaaAssistantArknights/docs/en-us/protocol/callback-schema.md
Lucien Shaw e461208bf9 chore: 完善容器配置及依赖安装 (#14208)
格式化工具部分:
1. pre-commit 引入 python 的格式化工具,包括 black(代码格式化)和 isort(对“包导入顺序”的规范)
2. 允许 prettier 对文档站的 markdown 文件格式化
3. 不允许 prettier 对 markdown 文件中的代码块的代码本身进行格式化
4. 升级了 pre-commit 的各个 hook 的版本
5. 优化了 pre-commit 的日志文本显示

容器总览部分:
1. 由原来的单一轻量环境转为区分空环境、轻量环境和全量环境
2. 空环境是裸 Linux 镜像(Ubuntu),为默认环境
3. 轻量环境适合开发文档站前端
4. 全量环境适合开发 MaaCore
5. 目前,全量环境完整包含了轻量环境,轻量环境完整包含了空环境
6. 在仓库 README.md 中更新了三个环境的描述,并将链接分别设置为对应环境的创建链接
   **注意:没有修改文档站中的对应文件**
7. 在各个语言的开发指南的最后,移除了 Codespace 部分的“安装额外依赖”相关描述,且将链接设置为全量环境的创建链接
   **注意:没有添加“开发文档站”的指南和对应 codespace 的使用方式**

容器的轻量环境和全量环境共有部分:
1. 安装 black 和 isort 包
2. 调整 VS Code 设置,取消先前(对 markdown 文件单独指定 markdownlint 扩展作为格式化工具)的错误设置,现在 markdown 文件仍然使用默认的 prettier 扩展作为格式化工具
3. 引入 markdown-all-in-one 扩展作为语法提示工具
4. 将 node_modules 和 3rdparty 排除在 VS Code 的文本的搜索路径之外

容器的全量环境部分:
1. 为 tools 下的所有 python 脚本安装依赖
2. 使用 tools/maadeps-download.py 下载 maadeps,且将必要二进制文件软链接到 /usr/local/bin/
3. 使用 apt 安装 cmake 和 clangd-20,将后者通过 update-alternatives 设置为系统 clangd 的默认版本
4. 使用 cmake tools 扩展,并按照 Linux 编译方法进行配置
5. 使用 clang-format 作为 c/cpp 的格式化工具,clang-format 程序主体来自 maadeps(已经软链接到 /usr/local/bin/)
6. 使用 clangd 作为 c/cpp 的语法提示工具
7. 将 MaaDeps、install 和 build 排除在 VS Code 的文本搜索路径之外

其它手动调整:
1. 更新文档站的 package.json,指定 pnpm 包管理器的版本
2. 手动保证 markdown 文件中的列表前后有空行(注意到 MarkdownLint 官方规则不一定能精准定位所有“列表前后空行”的问题,详见:https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md032---lists-should-be-surrounded-by-blank-lines )
3. 修改了部分 markdown 文件中的 json 代码块的语法问题
   **注意:相同的问题并未全部发现,仅修改了两处**
4. 在 tools 目录中,一处 python 脚本的包名误用(本地包名和某个 pip 包重名),这里修改了相应代码
5. 在 tools 目录中,一处 python 脚本使用了弃用的包 cchardet 的问题,这里更换了推荐使用的功能相近的包并修改了相应代码

自动化脚本提交的修改:
1. 自动格式化了大量 tools 中的 python 脚本
2. 自动格式化了大量 docs 中的 markdown 文件

Commits:

* chore: pre-commit引入black和isort规范py文件

* chore: Auto update by pre-commit hooks [skip changelog]

* chore: devcontainer添加isort扩展,排序python导入

* chore: pre-commit任务命名及更名

* style: isort fix

* chore: Auto update by pre-commit hooks [skip changelog]

* chore: 更新pre-commit的hook版本

* fix: 模块名与第三方库重名,大忌

* chore: 容器构建时额外安装isort

* docs: md -> markdown

* chore: 容器安装python包和maadeps

* fix: 修复过时python包

* chore: 指定pnpm版本

* chore: container支持选择轻量环境

* chore: 去掉rust

* chore: add plain env

* chore: 使用clangd语言服务器

* chore: 无需单独设置markdown的格式化工具

* chore: 更新安装的clangd版本

* docs: 简易文档适配

* docs: 在仓库README中重新编排codespaces相关指引

* chore: Auto update by pre-commit hooks [skip changelog]

* style: 调整缩进

* chore: 格式化工具不用特意排除被gitignore忽略的文件

* chore: sh文件在gitattributes中单列一类

* chore: 格式化docs下的markdown文件

* chore: 暂时不修改md文件中的代码块

* style: 人为明确markdown中的部分列表相关格式

* docs: 补上部分markdown的json代码块中缺失的逗号

* chore: Auto update by pre-commit hooks [skip changelog]

* chore: Auto update by pre-commit hooks [skip changelog]

* fix: 补上tools的服务器排序相关代码中缺失的逗号

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: 使用maadeps的clangd

* build: 更新maadeps工具链版本

* style: prettier fix

* revert: 还原maadeps版本

* revert: 取消使用maadeps的clangd依赖,改用系统apt安装

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-30 19:39:48 +08:00

16 KiB

order, icon
order icon
2 material-symbols:u-turn-left

Callback Message Protocol

::: info Note Callback messages are rapidly evolving with each version update, so this document may become outdated. For the latest information, please refer to the C# Integration Source Code :::

Callback Function Prototype

typedef void(ASST_CALL* AsstCallback)(int msg, const char* details, void* custom_arg);

Parameter Overview

  • int msg
    Message type

    enum class AsstMsg
    {
        /* Global Info */
        InternalError     = 0,           // Internal error
        InitFailed        = 1,           // Initialization failed
        ConnectionInfo    = 2,           // Connection-related information
        AllTasksCompleted = 3,           // All tasks completed
        AsyncCallInfo     = 4,           // External asynchronous call information
        Destroyed         = 5,           // Instance destroyed
    
        /* TaskChain Info */
        TaskChainError     = 10000,      // Task chain execution/recognition error
        TaskChainStart     = 10001,      // Task chain started
        TaskChainCompleted = 10002,      // Task chain completed
        TaskChainExtraInfo = 10003,      // Task chain extra information
        TaskChainStopped   = 10004,      // Task chain manually stopped
    
        /* SubTask Info */
        SubTaskError      = 20000,       // Atomic task execution/recognition error
        SubTaskStart      = 20001,       // Atomic task started
        SubTaskCompleted  = 20002,       // Atomic task completed
        SubTaskExtraInfo  = 20003,       // Atomic task extra information
        SubTaskStopped    = 20004,       // Atomic task manually stopped
    
        /* Web Request */
        ReportRequest     = 30000,       // Report request
    };
    
  • const char* details
    Message details, JSON string, see Field Explanations

  • void* custom_arg
    Custom parameter from the caller, returns the custom_arg parameter from the AsstCreateEx interface unchanged. C-like languages can use this parameter to pass this pointers

Field Explanations

InternalError

Todo

InitFailed

{
    "what": string,     // Error type
    "why": string,      // Error reason
    "details": object   // Error details
}

ConnectionInfo

{
    "what": string,     // Information type
    "why": string,      // Information reason
    "uuid": string,     // Device unique ID (empty when connection fails)
    "details": {
        "adb": string,     // AsstConnect interface adb_path parameter
        "address": string, // AsstConnect interface address parameter
        "config": string   // AsstConnect interface config parameter
    }
}

Common What Field Values

  • ConnectFailed
    Connection failed
  • Connected
    Connected, note that the uuid field is empty at this point (next step will retrieve it)
  • UuidGot
    Device unique ID retrieved
  • UnsupportedResolution
    Resolution not supported
  • ResolutionError
    Resolution retrieval error
  • Reconnecting
    Connection lost (adb/emulator crashed), attempting reconnection
  • Reconnected
    Connection lost (adb/emulator crashed), reconnection successful
  • Disconnect
    Connection lost (adb/emulator crashed), and reconnection failed
  • ScreencapFailed
    Screenshot failed (adb/emulator crashed), and retry failed
  • TouchModeNotAvailable
    Unsupported touch mode

AsyncCallInfo

{
    "uuid": string,             // Device unique ID
    "what": string,             // Callback type, "Connect" | "Click" | "Screencap" | ...
    "async_call_id": int,       // Asynchronous request ID, i.e., return value when calling AsstAsyncXXX
    "details": {
        "ret": bool,            // Actual call return value
        "cost": int64,          // Time cost, in milliseconds
    }
}

AllTasksCompleted

{
    "taskchain": string,            // Last task chain
    "uuid": string,                 // Device unique ID
    "finished_tasks": [             // IDs of tasks that have been run
        int,
        ...
    ]
}

Common taskchain Field Values

  • StartUp
    Start up
  • CloseDown
    Close down
  • Fight
    Sanity farming
  • Mall
    Credit store and shopping
  • Recruit
    Auto recruitment
  • Infrast
    Base management
  • Award
    Collect daily rewards
  • Roguelike
    Integrated Strategy
  • Copilot
    Auto combat
  • SSSCopilot
    Auto Stationary Security Service
  • Depot
    Depot recognition
  • OperBox
    Operator box recognition
  • Reclamation
    Reclamation Algorithm
  • Custom
    Custom task
  • SingleStep
    Single step task
  • VideoRecognition
    Video recognition task
  • Debug
    Debug
{
    "taskchain": string,            // Current task chain
    "taskid": int,                  // Current task TaskId
    "uuid": string                  // Device unique ID
}

TaskChainExtraInfo

Todo

{
    "subtask": string,             // Subtask name
    "class": string,               // Subtask symbol name
    "taskchain": string,           // Current task chain
    "taskid": int,                 // Current task TaskId
    "details": object,             // Details
    "uuid": string                 // Device unique ID
}

Common subtask Field Values

  • ProcessTask

    // Corresponding details field example
    {
      "task": "StartButton2", // Task name
      "action": 512,
      "exec_times": 1, // Execution times
      "max_times": 999, // Maximum execution times
      "algorithm": 0
    }
    
  • Todo others

Common task Field Values
  • StartButton2
    Start battle
  • MedicineConfirm
    Use sanity potion
  • ExpiringMedicineConfirm
    Use sanity potion expiring within 48 hours
  • StoneConfirm
    Use Originium Prime
  • RecruitRefreshConfirm
    Refresh recruitment tags
  • RecruitConfirm
    Confirm recruitment
  • RecruitNowConfirm
    Use Expedited Plan
  • ReportToPenguinStats
    Report to Penguin Statistics
  • ReportToYituliu
    Report to Yituliu big data
  • InfrastDormDoubleConfirmButton
    Base dormitory double confirmation button, appears only when operators conflict, please notify users
  • StartExplore
    Start Integrated Strategy exploration
  • StageTraderInvestConfirm
    Integrated Strategy invested Originium Ingots
  • StageTraderInvestSystemFull
    Integrated Strategy investment reached game limit
  • ExitThenAbandon
    Integrated Strategy abandoned current exploration
  • MissionCompletedFlag
    Integrated Strategy battle completed
  • MissionFailedFlag
    Integrated Strategy battle failed
  • StageTraderEnter
    Integrated Strategy stage: Merchant
  • StageSafeHouseEnter
    Integrated Strategy stage: Safe House
  • StageEncounterEnter
    Integrated Strategy stage: Encounter/Castle Gift
  • StageCombatDpsEnter
    Integrated Strategy stage: Combat
  • StageEmergencyDps
    Integrated Strategy stage: Emergency Combat
  • StageDreadfulFoe
    Integrated Strategy stage: Dreadful Foe
  • StartGameTask Failed to open client (config file does not match passed client_type)
  • Todo others

SubTaskExtraInfo

{
    "taskchain": string,           // Current task chain
    "class": string,               // Subtask type
    "what": string,                // Information type
    "details": object,             // Information details
    "uuid": string,                // Device unique ID
}

Common what and details Field Values

  • StageDrops
    Stage material drop information

    // Corresponding details field example
    {
      "drops": [
        // Materials dropped in this recognition
        {
          "itemId": "3301",
          "quantity": 2,
          "itemName": "技巧概要·卷1" // "Skill Summary - 1"
        },
        {
          "itemId": "3302",
          "quantity": 1,
          "itemName": "技巧概要·卷2" // "Skill Summary - 2"
        },
        {
          "itemId": "3303",
          "quantity": 2,
          "itemName": "技巧概要·卷3" // "Skill Summary - 3"
        }
      ],
      "stage": {
        // Stage information
        "stageCode": "CA-5",
        "stageId": "wk_fly_5"
      },
      "stars": 3, // Operation completion stars
      "stats": [
        // Total material drops during this execution
        {
          "itemId": "3301",
          "itemName": "技巧概要·卷1", // "Skill Summary - 1"
          "quantity": 4,
          "addQuantity": 2 // New drop quantity this time
        },
        {
          "itemId": "3302",
          "itemName": "技巧概要·卷2", // "Skill Summary - 2"
          "quantity": 3,
          "addQuantity": 1
        },
        {
          "itemId": "3303",
          "itemName": "技巧概要·卷3", // "Skill Summary - 3"
          "quantity": 4,
          "addQuantity": 2
        }
      ]
    }
    
  • RecruitTagsDetected
    Recruitment tags detected

    // Corresponding details field example
    {
      "tags": ["费用回复", "防护", "先锋干员", "辅助干员", "近战位"] // ["DP-Recovery", "Defense", "Vanguard", "Support", "Melee"]
    }
    
  • RecruitSpecialTag
    Recruitment special tag detected

    // Corresponding details field example
    {
      "tag": "高级资深干员" // "Top Operator"
    }
    
  • RecruitResult
    Recruitment recognition result

    // Corresponding details field example
    {
      "tags": [
        // All detected tags, currently always 5
        "削弱", // "Debuff"
        "减速", // "Slow"
        "术师干员", // "Caster"
        "辅助干员", // "Supporter"
        "近战位" // "Melee"
      ],
      "level": 4, // Overall rarity
      "result": [
        {
          "tags": ["削弱"], // ["Debuff"]
          "level": 4, // This tag combination's rarity
          "opers": [
            {
              "name": "初雪", // "Pramanix"
              "level": 5 // Operator rarity
            },
            {
              "name": "陨星", // "Meteorite"
              "level": 5
            },
            {
              "name": "槐琥", // "Waai Fu"
              "level": 5
            },
            {
              "name": "夜烟", // "Haze"
              "level": 4
            },
            {
              "name": "流星", // "Meteor"
              "level": 4
            }
          ]
        },
        {
          "tags": ["减速", "术师干员"], // ["Slow", "Caster"]
          "level": 4,
          "opers": [
            {
              "name": "夜魔", // "Nightmare"
              "level": 5
            },
            {
              "name": "格雷伊", // "Greyy"
              "level": 4
            }
          ]
        },
        {
          "tags": ["削弱", "术师干员"], // ["Debuff", "Caster"]
          "level": 4,
          "opers": [
            {
              "name": "夜烟", // "Haze"
              "level": 4
            }
          ]
        }
      ]
    }
    
  • RecruitTagsRefreshed
    Recruitment tags refreshed

    // Corresponding details field example
    {
      "count": 1, // Current slot refresh count
      "refresh_limit": 3 // Current slot refresh limit
    }
    
  • RecruitNoPermit
    No recruitment permits available

    // Corresponding details field example
    {
      "continue": true // Whether to continue refreshing
    }
    
  • RecruitTagsSelected
    Recruitment tags selected

    // Corresponding details field example
    {
      "tags": ["减速", "术师干员"] // ["Slow", "Caster"]
    }
    
  • RecruitSlotCompleted
    Current recruitment slot task completed

  • RecruitError
    Recruitment recognition error

  • EnterFacility
    Base entered facility

    // Corresponding details field example
    {
      "facility": "Mfg", // Facility name
      "index": 0 // Facility index
    }
    
  • NotEnoughStaff
    Base available operators insufficient

    // Corresponding details field example
    {
      "facility": "Mfg", // Facility name
      "index": 0 // Facility index
    }
    
  • ProductOfFacility
    Base facility product

    // Corresponding details field example
    {
      "product": "Money", // Product name
      "facility": "Mfg", // Facility name
      "index": 0 // Facility index
    }
    
  • StageInfo
    Auto combat stage information

    // Corresponding details field example
    {
        "name": string  // Stage name
    }
    
  • StageInfoError
    Auto combat stage recognition error

  • PenguinId
    Penguin Statistics ID

    // Corresponding details field example
    {
        "id": string
    }
    
  • Depot
    Depot recognition result

    // Corresponding details field example
    "done": bool,       // Whether recognition is complete, false means still in progress (data during process)
    "arkplanner": {     // https://penguin-stats.cn/planner
        "object": {
            "items": [
                {
                    "id": "2004",
                    "have": 4,
                    "name": "高级作战记录" // "Advanced Battle Record"
                },
                {
                    "id": "mod_unlock_token",
                    "have": 25,
                    "name": "模组数据块" // "Module Data Block"
                },
                {
                    "id": "2003",
                    "have": 20,
                    "name": "中级作战记录" // "Tactical Battle Record"
                }
            ],
            "@type": "@penguin-statistics/depot"
        },
        "data": "{\"@type\":\"@penguin-statistics/depot\",\"items\":[{\"id\":\"2004\",\"have\":4,\"name\":\"高级作战记录\"},{\"id\":\"mod_unlock_token\",\"have\":25,\"name\":\"模组数据块\"},{\"id\":\"2003\",\"have\":20,\"name\":\"中级作战记录\"}]}"
    },
    "lolicon": {     // https://arkntools.app/#/material
        "object": {
            "2004" : 4,
            "mod_unlock_token": 25,
            "2003": 20
        },
        "data": "{\"2003\":20,\"2004\": 4,\"mod_unlock_token\": 25}"
    }
    // Currently only supports ArkPlanner and Lolicon (Arkntools) formats, may support more websites in the future
    
  • OperBox
    Operator recognition result

    // Corresponding details field example
    "done": bool,       // Whether recognition is complete, false means still in progress (data during process)
    "all_oper": [
        {
            "id": "char_002_amiya",
            "name": "阿米娅", // "Amiya"
            "own": true,
            "rarity": 5
        },
        {
            "id": "char_003_kalts",
            "name": "凯尔希", // "Kal'tsit"
            "own": true,
            "rarity": 6
        },
        {
            "id": "char_1020_reed2",
            "name": "焰影苇草", // "Reed the Flame Shadow"
            "own": false,
            "rarity": 6
        },
    ]
    "own_opers": [
        {
            "id": "char_002_amiya", // Operator ID
            "name": "阿米娅", // "Amiya" - Operator name
            "own": true, // Whether owned
            "elite": 2, // Elite level 0,1,2
            "level": 50, // Operator level
            "potential": 6, // Operator potential [1, 6]
            "rarity": 5 // Operator rarity [1, 6]
        },
        {
            "id": "char_003_kalts",
            "name": "凯尔希", // "Kal'tsit"
            "own": true,
            "elite": 2,
            "level": 50,
            "potential": 1,
            "rarity": 6
        }
    ]
    
  • UnsupportedLevel
    Auto combat, unsupported stage name

ReportRequest

This field is mainly used by the core module to pass network request information to the UI layer, which is responsible for performing the actual HTTP reporting operations.

{
  "url": "string",            // The full request URL, e.g., https://penguin-stats.io/PenguinStats/api/v2/report
  "headers": {                // Request headers key-value pairs (excluding Content-Type, which is added by the UI)
    "authorization": "PenguinID 1234567890",
    "User-Agent": "MaaAssistantArknights/1.2.3 cpr/4.5.6"
  },
  "body": "string",           // Request body content (usually a JSON-formatted string)
  "subtask": "string"         // Subtask name identifying the specific reporting task, e.g., "ReportToPenguinStats", "ReportToYituliu"
}