Commit b7402ca
authored
fix: emit content_part.done and populate output_text.done.text per Responses API spec (#49)
The /v1/responses streaming handler violates the OpenAI Responses API
SSE lifecycle spec in two ways:
1. response.content_part.done is never emitted. Per the spec
(https://platform.openai.com/docs/api-reference/responses-streaming),
the event sequence for a text content part should be:
content_part.added -> output_text.delta* -> output_text.done
-> content_part.done -> output_item.done
2. response.output_text.done is emitted with text: "" instead of the
accumulated output text. The spec requires the final content.
Accumulate delta tokens in a local variable at the streaming call
site, emit the missing response.content_part.done event with the
accumulated text in part.text, and populate output_text.done.text
with the same accumulated content. Gate the new content_part.done
event on at least one delta having been received, keeping the
content-part added/done lifecycle symmetric.
Adds one regression test in index.test.js that asserts:
- output_text.done.text equals the accumulated deltas
- content_part.done event is present with part.text populated
- correct ordering (output_text.done < content_part.done < output_item.done)
Closes #481 parent 2eb182f commit b7402ca
2 files changed
Lines changed: 95 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
926 | 929 | | |
927 | 930 | | |
928 | 931 | | |
| |||
941 | 944 | | |
942 | 945 | | |
943 | 946 | | |
| 947 | + | |
944 | 948 | | |
945 | 949 | | |
946 | 950 | | |
| |||
959 | 963 | | |
960 | 964 | | |
961 | 965 | | |
962 | | - | |
| 966 | + | |
963 | 967 | | |
964 | 968 | | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
965 | 982 | | |
966 | 983 | | |
967 | 984 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
83 | 98 | | |
84 | 99 | | |
85 | 100 | | |
| |||
1108 | 1123 | | |
1109 | 1124 | | |
1110 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1111 | 1188 | | |
1112 | 1189 | | |
1113 | 1190 | | |
| |||
0 commit comments