| 948 | } |
| 949 | |
| 950 | func retrieveTaskPluginResponse(c *gin.Context, deps pluginProtocolBridgeDeps) { |
| 951 | deps = deps.withDefaults() |
| 952 | responseID := strings.TrimSpace(c.Param("response_id")) |
| 953 | if !strings.HasPrefix(responseID, "resp_") { |
| 954 | writeTaskPluginResponseNotFound(c, responseID, "bad_prefix") |
| 955 | return |
| 956 | } |
| 957 | taskID := "task_" + strings.TrimPrefix(responseID, "resp_") |
| 958 | userID := common.GetContextKeyInt(c, constant.ContextKeyUserId) |
| 959 | logger.LogDebug(c, "task_plugin subsystem=protocol event=retrieve_start response_id=%q public_task_id=%q", responseID, taskID) |
| 960 | |
| 961 | task, exists, err := deps.getByTaskId(userID, taskID) |
| 962 | if err != nil { |
| 963 | logger.LogError(c, common.LogText("task protocol retrieve lookup failed")) |
| 964 | logger.LogDebug(c, "task_plugin subsystem=protocol event=retrieve_failed reason=lookup_error public_task_id=%q", taskID) |
| 965 | respondPluginProtocolError(c, http.StatusInternalServerError, "task_protocol_error", "Task protocol request failed") |
| 966 | return |
| 967 | } |
| 968 | if !exists || task == nil { |
| 969 | writeTaskPluginResponseNotFound(c, responseID, "missing") |
| 970 | return |
| 971 | } |
| 972 | if !task.ResultRetrievable() { |
| 973 | writeTaskPluginResponseNotFound(c, responseID, "result_discarded") |
| 974 | return |
| 975 | } |
| 976 | |
| 977 | plugin, generation, ok := deps.resolvePlugin(task.Platform) |
| 978 | if !ok || plugin == nil { |
| 979 | writeTaskPluginResponseNotFound(c, responseID, "no_plugin") |
| 980 | return |
| 981 | } |
| 982 | claimsProtocol := false |
| 983 | for _, claim := range plugin.Meta.Protocols { |
| 984 | if claim.Name == "openai_responses" { |
| 985 | claimsProtocol = true |
| 986 | break |
| 987 | } |
| 988 | } |
| 989 | if !claimsProtocol { |
| 990 | writeTaskPluginResponseNotFound(c, responseID, "no_claim") |
| 991 | return |
| 992 | } |
| 993 | |
| 994 | generationNumber := uint64(0) |
| 995 | if generation != nil { |
| 996 | generationNumber = generation.Number |
| 997 | } |
| 998 | createdAt := task.CreatedAt |
| 999 | if createdAt == 0 { |
| 1000 | createdAt = task.SubmitTime |
| 1001 | } |
| 1002 | if createdAt == 0 { |
| 1003 | createdAt = deps.now().Unix() |
| 1004 | } |
| 1005 | machine := relay.NewPluginResponsesMachine( |
| 1006 | task.TaskID, |
| 1007 | task.Properties.OriginModelName, |