From 2aee80d0d35449d72f717e0af7f07072a5c9ffb0 Mon Sep 17 00:00:00 2001 From: CJACK Date: Mon, 13 Apr 2026 03:49:06 +0800 Subject: [PATCH] fix: update URL decoding method and refine file ID extraction logic to exclude text-based inputs --- internal/adapter/openai/file_inline_upload.go | 2 +- internal/adapter/openai/file_refs.go | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/adapter/openai/file_inline_upload.go b/internal/adapter/openai/file_inline_upload.go index c199498..dd73dec 100644 --- a/internal/adapter/openai/file_inline_upload.go +++ b/internal/adapter/openai/file_inline_upload.go @@ -292,7 +292,7 @@ func decodeDataURL(raw string, explicitContentType string) ([]byte, string, erro } return decoded, contentType, nil } - decoded, err := url.QueryUnescape(payload) + decoded, err := url.PathUnescape(payload) if err != nil { return nil, "", err } diff --git a/internal/adapter/openai/file_refs.go b/internal/adapter/openai/file_refs.go index adf49e1..d1cef34 100644 --- a/internal/adapter/openai/file_refs.go +++ b/internal/adapter/openai/file_refs.go @@ -8,13 +8,24 @@ func collectOpenAIRefFileIDs(req map[string]any) []string { } out := make([]string, 0, 4) seen := map[string]struct{}{} - for _, raw := range []any{ - req["ref_file_ids"], - req["file_ids"], - req["attachments"], - req["messages"], - req["input"], + for _, key := range []string{ + "ref_file_ids", + "file_ids", + "attachments", + "messages", + "input", } { + raw := req[key] + if raw == nil { + continue + } + // Skip top-level strings for 'messages' and 'input' as they are likely plain text content, + // not file IDs. String file IDs are expected in 'ref_file_ids' or 'file_ids'. + if key == "messages" || key == "input" { + if _, ok := raw.(string); ok { + continue + } + } appendOpenAIRefFileIDs(&out, seen, raw) } if len(out) == 0 {