| 927 | } |
| 928 | |
| 929 | func retrieveTaskPluginResponse(c *gin.Context, deps pluginProtocolBridgeDeps) { |
| 930 | deps = deps.withDefaults() |
| 931 | responseID := strings.TrimSpace(c.Param("response_id")) |
| 932 | if !strings.HasPrefix(responseID, "resp_") { |
| 933 | writeTaskPluginResponseNotFound(c, responseID, "bad_prefix") |
| 934 | return |
| 935 | } |
| 936 | taskID := "task_" + strings.TrimPrefix(responseID, "resp_") |
| 937 | userID := common.GetContextKeyInt(c, constant.ContextKeyUserId) |
| 938 | logger.LogDebug(c, "task_plugin subsystem=protocol event=retrieve_start response_id=%q public_task_id=%q", responseID, taskID) |
| 939 | |
| 940 | task, exists, err := deps.getByTaskId(userID, taskID) |
| 941 | if err != nil { |
| 942 | logger.LogError(c, "task protocol retrieve lookup failed") |
| 943 | logger.LogDebug(c, "task_plugin subsystem=protocol event=retrieve_failed reason=lookup_error public_task_id=%q", taskID) |
| 944 | respondPluginProtocolError(c, http.StatusInternalServerError, "task_protocol_error", "Task protocol request failed") |
| 945 | return |
| 946 | } |
| 947 | if !exists || task == nil { |
| 948 | writeTaskPluginResponseNotFound(c, responseID, "missing") |
| 949 | return |
| 950 | } |
| 951 | |
| 952 | plugin, generation, ok := deps.resolvePlugin(task.Platform) |
| 953 | if !ok || plugin == nil { |
| 954 | writeTaskPluginResponseNotFound(c, responseID, "no_plugin") |
| 955 | return |
| 956 | } |
| 957 | claimsProtocol := false |
| 958 | for _, claim := range plugin.Meta.Protocols { |
| 959 | if claim.Name == "openai_responses" { |
| 960 | claimsProtocol = true |
| 961 | break |
| 962 | } |
| 963 | } |
| 964 | if !claimsProtocol { |
| 965 | writeTaskPluginResponseNotFound(c, responseID, "no_claim") |
| 966 | return |
| 967 | } |
| 968 | |
| 969 | generationNumber := uint64(0) |
| 970 | if generation != nil { |
| 971 | generationNumber = generation.Number |
| 972 | } |
| 973 | createdAt := task.CreatedAt |
| 974 | if createdAt == 0 { |
| 975 | createdAt = task.SubmitTime |
| 976 | } |
| 977 | if createdAt == 0 { |
| 978 | createdAt = deps.now().Unix() |
| 979 | } |
| 980 | machine := relay.NewPluginResponsesMachine( |
| 981 | task.TaskID, |
| 982 | task.Properties.OriginModelName, |
| 983 | createdAt, |
| 984 | deps.protocolLimits, |
| 985 | ) |
| 986 | machine.SetBackground(task.PrivateData.ResponsesBackground) |