An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Handle qualified Gemini model IDs in signature transport https://github.com/siyuan-note/siyuan/issues/18817
Danielb4a9e0832e51
diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex 9bba80c332..bfae493a72 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -1026,6 +1026,8 @@ func AgentChat(ctx context.Context, client *openai.Client, protocol, model, imag}if tcd.ID != "" {aggregatedToolCalls[idx].ID = tcd.ID+ }+ if tcd.Type != "" {aggregatedToolCalls[idx].Type = tcd.Type}if tcd.Function.Name != "" {@@ -1068,6 +1070,9 @@ func AgentChat(ctx context.Context, client *openai.Client, protocol, model, imagfiltered := make([]openai.ToolCall, 0, len(aggregatedToolCalls))for _, tc := range aggregatedToolCalls {if tc.Function.Name != "" {+ if tc.Type == "" {+ tc.Type = openai.ToolTypeFunction+ }filtered = append(filtered, tc)}}diff --git a/kernel/agent/assistant_context_test.go b/kernel/agent/assistant_context_test.goindex 0985abf04b..9ef5ad35a3 100644--- a/kernel/agent/assistant_context_test.go+++ b/kernel/agent/assistant_context_test.go@@ -380,7 +380,7 @@ func TestAgentChatRestoresCompleteAssistantContextAfterCommit(t *testing.T) {case 1:flusher := prepareTestStream(t, w)chunk := fmt.Sprintf(- `data: {"id":"chatcmpl-tool","object":"chat.completion.chunk","created":1,"model":"test-model","choices":[{"index":0,"delta":{"reasoning_content":%q,"tool_calls":[{"index":0,"id":%q,"type":"function","function":{"name":%q,"arguments":%q},"extra_content":{"google":{"thought_signature":%q}}}]},"finish_reason":"tool_calls"}]}`+"\n\n",+ `data: {"id":"chatcmpl-tool","object":"chat.completion.chunk","created":1,"model":"test-model","choices":[{"index":0,"delta":{"reasoning_content":%q,"tool_calls":[{"index":0,"id":%q,"function":{"name":%q,"arguments":%q},"extra_content":{"google":{"thought_signature":%q}}}]},"finish_reason":"tool_calls"}]}`+"\n\n",toolReasoning, toolCallID, toolName, argumentsJSON, thoughtSignature,)if _, err = io.WriteString(w, chunk); err != nil {diff --git a/kernel/util/openai_gemini.go b/kernel/util/openai_gemini.goindex 3704b14855..108c2ea852 100644--- a/kernel/util/openai_gemini.go+++ b/kernel/util/openai_gemini.go@@ -91,7 +91,11 @@ func isGoogleGeminiOpenAICompatibleEndpoint(apiBaseURL, model string) bool {if !strings.Contains(strings.ToLower(parsed.Path), "/openai") {return false}- return strings.HasPrefix(strings.ToLower(strings.TrimSpace(model)), "gemini-")+ normalizedModel := strings.ToLower(strings.TrimSpace(model))+ if slash := strings.LastIndex(normalizedModel, "/"); slash >= 0 {+ normalizedModel = normalizedModel[slash+1:]+ }+ return strings.HasPrefix(normalizedModel, "gemini-")}// WrapGeminiThoughtSignatureTransport 为 Google OpenAI 兼容端点补充工具调用签名往返支持。@@ -152,7 +156,7 @@ func injectGeminiThoughtSignatures(req *http.Request, state *GeminiThoughtSignattoolCalls, _ := message["tool_calls"].([]any)for _, rawToolCall := range toolCalls {toolCall, _ := rawToolCall.(map[string]any)- if toolCall["type"] != string(openai.ToolTypeFunction) {+ if !isGeminiFunctionToolCall(toolCall) {continue}if geminiThoughtSignatureFromToolCall(toolCall) != "" {@@ -179,6 +183,15 @@ func injectGeminiThoughtSignatures(req *http.Request, state *GeminiThoughtSignatrestoreOpenAIRequestBody(req, merged)}+func isGeminiFunctionToolCall(toolCall map[string]any) bool {+ toolType, _ := toolCall["type"].(string)+ if toolType != "" && toolType != string(openai.ToolTypeFunction) {+ return false+ }+ _, hasFunction := toolCall["function"].(map[string]any)+ return hasFunction+}+func restoreOpenAIRequestBody(req *http.Request, body []byte) {req.Body = io.NopCloser(bytes.NewReader(body))req.ContentLength = int64(len(body))diff --git a/kernel/util/openai_gemini_test.go b/kernel/util/openai_gemini_test.goindex 63aa949f53..488c68c3a7 100644--- a/kernel/util/openai_gemini_test.go+++ b/kernel/util/openai_gemini_test.go@@ -33,6 +33,7 @@ func TestIsGoogleGeminiOpenAICompatibleEndpoint(t *testing.T) {want bool}{{"https://generativelanguage.googleapis.com/v1beta/openai", "gemini-3.5-flash", true},+ {"https://generativelanguage.googleapis.com/v1beta/openai", "models/gemini-3.5-flash", true},{"https://GENERATIVELANGUAGE.GOOGLEAPIS.COM/v1beta/openai/", "GEMINI-3-pro", true},{"https://generativelanguage.googleapis.com/v1beta", "gemini-3.5-flash", false},{"https://example.com/v1beta/openai", "gemini-3.5-flash", false},@@ -84,7 +85,7 @@ func TestGeminiThoughtSignatureTransportRoundTrip(t *testing.T) {body := `{"model":"gemini-3.5-flash","messages":[` +`{"role":"assistant","tool_calls":[` +`{"id":"` + existingCallID + `","type":"function","function":{"name":"document","arguments":"{}"}},` +- `{"id":"` + legacyCallID + `","type":"function","function":{"name":"block","arguments":"{}"}}]},` ++ `{"id":"` + legacyCallID + `","type":"","function":{"name":"block","arguments":"{}"}}]},` +`{"role":"tool","tool_call_id":"` + existingCallID + `","content":"ok"}]}`req, err := http.NewRequestWithContext(ctx, http.MethodPost, server.URL+"/v1/chat/completions", strings.NewReader(body))if err != nil {