Feature: Support remote chat on Android hosts
The chat tools were Windows-only because the Android client had no COMMAND_CHAT handler: the server asked for a chat sub-connection and the command was silently dropped, leaving chat_open to time out. This adds the full path on the client and the matching server gating. Client: COMMAND_CHAT on the main connection spawns a chat thread that opens an authenticated sub-connection, sends TOKEN_CHAT_START and waits for the server to bind it. Incoming GBK lines are decoded and dispatched to ChatSession, which drives an in-app chat activity; when accessibility is available the activity is pulled to the front, otherwise a tappable notification is posted. Outgoing text is strictly GBK encoded so emoji and unmappable characters are rejected instead of becoming '?'. When the server ends the session the activity closes itself, matching the Windows client's DestroyWindow, and a new session starts from an empty log. Server: a new CLIENT_CAP_REMOTE_CHAT bit lets the server tell new APKs from old ones. ResolveHost now accepts Windows and Android hosts and rejects older APKs up front with -32005 rather than waiting for the command to expire. Tool platform masks, instructions, the docs matrix and mcp/tools.json follow the same change. Verified end to end on the Android 15 emulator: chat_open pops the activity, Chinese text from the server renders, a device reply reaches chat_wait, and ending the session from the master closes the activity instead of leaving a dead window. The committed ghost.apk is stale and must be rebuilt before release. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
f33a205fd9
commit
915c587964
14 files changed
+695
-29
No files matched your search
@@ -85,7 +85,7 @@ struct HostTool {
|
||||
};
|
||||
|
||||
bool ResolveHost(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent,
|
||||
HostTool& ht, bool requireWindows_, std::string& errJson) {
|
||||
HostTool& ht, bool requireChatSupported_, std::string& errJson) {
|
||||
uint64_t dev = 0;
|
||||
std::string err;
|
||||
if (!ParseHostIdArg(args, dev, err)) {
|
||||
@@ -97,10 +97,21 @@ bool ResolveHost(const Json::Value& id, const Json::Value& args, CMy2015RemoteDl
|
||||
errJson = BuildError(id, kErrOffline, "Host not found or offline: " + std::to_string(dev));
|
||||
return false;
|
||||
}
|
||||
if (requireWindows_ && !IsWindowsClient(ctx)) {
|
||||
errJson = BuildError(id, kErrUnsupported,
|
||||
"Remote chat is only supported on Windows hosts");
|
||||
return false;
|
||||
// Windows 客户端一直有 COMMAND_CHAT 分支;Android 从支持 CLIENT_CAP_REMOTE_CHAT 的版本
|
||||
// 才开始弹应用内聊天窗口,老 APK 收到会静默丢弃,提前拒绝比等 15s 超时友好。
|
||||
if (requireChatSupported_) {
|
||||
const CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
if (clientType == "LNX" || clientType == "MAC") {
|
||||
errJson = BuildError(id, kErrUnsupported,
|
||||
"Remote chat is only supported on Windows and Android hosts");
|
||||
return false;
|
||||
}
|
||||
if (clientType == "APK" && !ctx->SupportsChat()) {
|
||||
errJson = BuildError(id, kErrUnsupported,
|
||||
"Android client is too old for remote chat: "
|
||||
"the APK has no COMMAND_CHAT handler, upgrade the client first");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ht.dev = dev;
|
||||
ht.mainCtx = ctx;
|
||||
@@ -237,7 +248,7 @@ void AppendTools(Json::Value& tools) {
|
||||
props["id"] = HostIdProp();
|
||||
props["timeout_ms"] = PropInt(u8"等待客户端弹出聊天窗口的超时,默认 15000,范围 2000-60000");
|
||||
AddTool(tools, "chat_open",
|
||||
u8"在指定在线 Windows 主机上弹出「远程交谈」窗口,建立一次多轮文字对话。返回 session_id,后续 chat_send / chat_wait / chat_close 都要带上。客户端使用者会直接看到聊天窗口(无确认框)。同一主机同一时刻只允许一个会话;会话在客户端断开或空闲 10 分钟后自动失效。会话建立后应先用 chat_send 发送问候,再用 chat_wait 等待对方回复。",
|
||||
u8"在指定在线 Windows / Android 主机上弹出「远程交谈」窗口,建立一次多轮文字对话。返回 session_id,后续 chat_send / chat_wait / chat_close 都要带上。客户端使用者会直接看到聊天窗口(无确认框;Android 上是应用内聊天界面,无障碍服务可用时会自动拉到前台,否则发一条可点开的通知)。同一主机同一时刻只允许一个会话;会话在客户端断开或空闲 10 分钟后自动失效。会话建立后应先用 chat_send 发送问候,再用 chat_wait 等待对方回复。",
|
||||
MakeSchema(props, { "id" }),
|
||||
OutputSchema([] {
|
||||
Json::Value p(Json::objectValue);
|
||||
@@ -255,7 +266,7 @@ void AppendTools(Json::Value& tools) {
|
||||
props["session_id"] = SessionIdProp();
|
||||
props["message"] = PropStr(u8"要发给客户端使用者的纯文本(UTF-8)。不能为空、不能含换行/控制字符、不能超过 4000 个 GBK 字节(约 2000 个汉字);emoji 等 GBK 无法表示的字符会被拒绝");
|
||||
AddTool(tools, "chat_send",
|
||||
u8"向会话对端发送一条文本。消息以客户端本地代码页(简体中文为 GBK/CP936)显示;客户端不保证非中文系统能正确显示。发送成功只代表已写入子连接,不代表对方已读。请勿在同一条消息里塞入多段对话;需要等待回复时调用 chat_wait。",
|
||||
u8"向会话对端发送一条文本。消息以客户端本地代码页(简体中文为 GBK/CP936)显示(Windows 客户端按 UTF-16 渲染,Android 客户端按 GBK 解码);客户端不保证非中文系统能正确显示。发送成功只代表已写入子连接,不代表对方已读。请勿在同一条消息里塞入多段对话;需要等待回复时调用 chat_wait。",
|
||||
MakeSchema(props, { "id", "session_id", "message" }),
|
||||
OutputSchema([] {
|
||||
Json::Value p(Json::objectValue);
|
||||
@@ -322,7 +333,7 @@ static std::string BuildChatOpen(const Json::Value& id, const Json::Value& args,
|
||||
CMy2015RemoteDlg* parent) {
|
||||
HostTool ht;
|
||||
std::string errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireWindows_=*/true, errJson)) return errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireChatSupported_=*/true, errJson)) return errJson;
|
||||
|
||||
int timeoutMs = kOpenDefaultMs;
|
||||
if (!GetOptIntArg(id, args, "timeout_ms", kOpenMinMs, kOpenMaxMs, timeoutMs, errJson))
|
||||
@@ -383,7 +394,7 @@ static std::string BuildChatSend(const Json::Value& id, const Json::Value& args,
|
||||
CMy2015RemoteDlg* parent) {
|
||||
HostTool ht;
|
||||
std::string errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireWindows_=*/true, errJson)) return errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireChatSupported_=*/true, errJson)) return errJson;
|
||||
|
||||
const std::string sessionId = OptStr(args, "session_id");
|
||||
if (sessionId.empty())
|
||||
@@ -457,7 +468,7 @@ static std::string BuildChatWait(const Json::Value& id, const Json::Value& args,
|
||||
CMy2015RemoteDlg* parent) {
|
||||
HostTool ht;
|
||||
std::string errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireWindows_=*/true, errJson)) return errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireChatSupported_=*/true, errJson)) return errJson;
|
||||
|
||||
const std::string sessionId = OptStr(args, "session_id");
|
||||
if (sessionId.empty())
|
||||
@@ -535,7 +546,7 @@ static std::string BuildChatClose(const Json::Value& id, const Json::Value& args
|
||||
CMy2015RemoteDlg* parent) {
|
||||
HostTool ht;
|
||||
std::string errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireWindows_=*/true, errJson)) return errJson;
|
||||
if (!ResolveHost(id, args, parent, ht, /*requireChatSupported_=*/true, errJson)) return errJson;
|
||||
|
||||
const std::string sessionId = OptStr(args, "session_id");
|
||||
if (sessionId.empty())
|
||||
|
||||
Reference in new issue
Block a user