History

feat: 添加Kiro渠道图片支持功能,借鉴justlovemaki/AIClient-2-API实现

Your Name committed 11 months ago

Commit 68cbe201 parent 15353a61 file · +41 −2Browse files

Unified · Split

internal/runtime/executor/kiro_executor.go+41−2
@@ -604,10 +604,22 @@ type kiroHistoryMessage struct { · 603 unmodified lines
604604 AssistantResponseMessage *kiroAssistantResponseMessage `json:"assistantResponseMessage,omitempty"`
605605 }
606606
607+// kiroImage represents an image in Kiro API format
608+type kiroImage struct {
609+ Format string `json:"format"`
610+ Source kiroImageSource `json:"source"`
611+}
612+
613+// kiroImageSource contains the image data
614+type kiroImageSource struct {
615+ Bytes string `json:"bytes"` // base64 encoded image data
616+}
617+
607618 type kiroUserInputMessage struct {
608619 Content string `json:"content"`
609620 ModelID string `json:"modelId"`
610621 Origin string `json:"origin"`
622+ Images []kiroImage `json:"images,omitempty"`
611623 UserInputMessageContext *kiroUserInputMessageContext `json:"userInputMessageContext,omitempty"`
612624 }
613625
@@ -824,6 +836,7 @@ func (e *KiroExecutor) buildUserMessageStruct(msg gjson.Result, modelID, origin · 210 unmodified lines
824836 content := msg.Get("content")
825837 var contentBuilder strings.Builder
826838 var toolResults []kiroToolResult
839+ var images []kiroImage
827840
828841 if content.IsArray() {
829842 for _, part := range content.Array() {
@@ -831,6 +844,25 @@ func (e *KiroExecutor) buildUserMessageStruct(msg gjson.Result, modelID, origin · 1 unmodified line
831844 switch partType {
832845 case "text":
833846 contentBuilder.WriteString(part.Get("text").String())
847+ case "image":
848+ // Extract image data from Claude API format
849+ mediaType := part.Get("source.media_type").String()
850+ data := part.Get("source.data").String()
851+
852+ // Extract format from media_type (e.g., "image/png" -> "png")
853+ format := ""
854+ if idx := strings.LastIndex(mediaType, "/"); idx != -1 {
855+ format = mediaType[idx+1:]
856+ }
857+
858+ if format != "" && data != "" {
859+ images = append(images, kiroImage{
860+ Format: format,
861+ Source: kiroImageSource{
862+ Bytes: data,
863+ },
864+ })
865+ }
834866 case "tool_result":
835867 // Extract tool result for API
836868 toolUseID := part.Get("tool_use_id").String()
@@ -872,11 +904,18 @@ func (e *KiroExecutor) buildUserMessageStruct(msg gjson.Result, modelID, origin · 35 unmodified lines
872904 contentBuilder.WriteString(content.String())
873905 }
874906
875− return kiroUserInputMessage{
907+ userMsg := kiroUserInputMessage{
876908 Content: contentBuilder.String(),
877909 ModelID: modelID,
878910 Origin: origin,
879− }, toolResults
911+ }
912+
913+ // Add images to message if present
914+ if len(images) > 0 {
915+ userMsg.Images = images
916+ }
917+
918+ return userMsg, toolResults
880919 }
881920
882921 // buildAssistantMessageStruct builds an assistant message with tool uses

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t