From 81ed7477cb48135ed22a10516d9d057d078a3396 Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Thu, 17 Apr 2025 16:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9F=B3=E4=B9=90=E6=92=AD?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open_ai_service/MCPClient.kt | 2 +- .../open_ai_service/OpenAIServicePlugin.kt | 25 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt b/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt index 78e607ef2..45b5a8810 100644 --- a/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt +++ b/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt @@ -391,7 +391,7 @@ class MCPSubClient( else -> "" } } - JSONObject().apply { put("name",name);put("meta",result?._meta.toString()); put("context",context) } + JSONObject().apply { put("name",name);put("meta",result?._meta); put("context",context) } } catch (e: Exception) { Log.e(TAG, "调用MCP工具失败: ${e.message}", e) JSONObject().apply { put("context", "调用MCP工具失败: ${e.message}")} diff --git a/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIServicePlugin.kt b/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIServicePlugin.kt index a558fc6cf..185989ee5 100644 --- a/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIServicePlugin.kt +++ b/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIServicePlugin.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.serialization.json.JsonObject import kotlin.math.min /** OpenAIServicePlugin */ @@ -168,25 +169,17 @@ class OpenAIServicePlugin : FlutterPlugin, MethodCallHandler, StreamHandler { Log.e("OpenAIServicePlugin", "context:${functionCall.toString()}") val context = functionCall["context"] if (functionCall.has("meta")) { - Log.e("OpenAIServicePlugin", - """ - 工具调用结果 meta 类型: ${functionCall["meta"]?.javaClass?.canonicalName} - 值内容: ${functionCall["meta"]} - """.trimIndent() - ) - val meta = functionCall["meta"].toString() -// val meta = mapOf( -// "card_spotify" to mapOf( -// "name" to "泡沫", -// "image" to "https://i.scdn.co/image/ab67616d0000b2739f6a38e4bb9c2f824c215e58", -// "url" to "spotify:track:2IfSPLPDW6RGosdB5huwAA", -// "sgener" to "Xposed", -// ) -// ) + val meta = functionCall.get("meta") + val metaJsonObject:JsonObject = meta as JsonObject Log.e("OpenAIServicePlugin", "工具调用结果 context:${context} meta:${meta.toString()}") // 发送函数调用事件 mainHandler.post { - eventSink?.success(mapOf("type" to "functionCall", "content" to context,"meta" to meta)) + eventSink?.success(mapOf("type" to "functionCall", "content" to context,"meta" to meta.toString())) + } + if (metaJsonObject.containsKey("card_spotify")) { + mainHandler.post { + eventSink?.success(mapOf("type" to "complete")) + } } }