


























@@ -797,8 +797,11 @@ function createGoogleTransportStreamFn(kind: GoogleTransportApi): StreamFn {
797797const candidate = chunk.candidates?.[0];
798798if (candidate?.content?.parts) {
799799for (const part of candidate.content.parts) {
800-if (typeof part.text === "string") {
801-const isThinking = part.thought === true;
800+const hasThoughtSignature =
801+typeof part.thoughtSignature === "string" && part.thoughtSignature.length > 0;
802+const hasText = typeof part.text === "string";
803+if (hasText || (hasThoughtSignature && !part.functionCall)) {
804+const isThinking = part.thought === true || !hasText;
802805const currentBlock = output.content[currentBlockIndex];
803806if (
804807currentBlockIndex < 0 ||
@@ -829,15 +832,16 @@ function createGoogleTransportStreamFn(kind: GoogleTransportApi): StreamFn {
829832}
830833const activeBlock = output.content[currentBlockIndex];
831834if (activeBlock?.type === "thinking") {
832-activeBlock.thinking += part.text;
835+const delta = hasText ? part.text : "";
836+activeBlock.thinking += delta;
833837activeBlock.thinkingSignature = retainThoughtSignature(
834838activeBlock.thinkingSignature,
835839part.thoughtSignature,
836840);
837841stream.push({
838842type: "thinking_delta",
839843contentIndex: currentBlockIndex,
840-delta: part.text,
844+ delta,
841845partial: output as never,
842846});
843847} else if (activeBlock?.type === "text") {
@@ -894,45 +898,6 @@ function createGoogleTransportStreamFn(kind: GoogleTransportApi): StreamFn {
894898partial: output as never,
895899});
896900}
897-// Gemini 3+ models can emit thoughtSignature-only parts during the
898-// thinking phase before user-visible text arrives. Emit a stream event
899-// so that idle-timeout wrappers detect model activity and don't kill
900-// the stream prematurely.
901-if (
902-typeof part.thoughtSignature === "string" &&
903-part.thoughtSignature.length > 0 &&
904-typeof part.text !== "string" &&
905-!part.functionCall
906-) {
907-if (
908-currentBlockIndex < 0 ||
909-output.content[currentBlockIndex]?.type !== "thinking"
910-) {
911-if (currentBlockIndex >= 0) {
912-pushTextBlockEnd(stream, output, currentBlockIndex);
913-}
914-output.content.push({ type: "thinking", thinking: "" });
915-currentBlockIndex = output.content.length - 1;
916-stream.push({
917-type: "thinking_start",
918-contentIndex: currentBlockIndex,
919-partial: output as never,
920-});
921-}
922-const activeBlock = output.content[currentBlockIndex];
923-if (activeBlock?.type === "thinking") {
924-activeBlock.thinkingSignature = retainThoughtSignature(
925-activeBlock.thinkingSignature,
926-part.thoughtSignature,
927-);
928-}
929-stream.push({
930-type: "thinking_signature",
931-contentIndex: currentBlockIndex,
932-signature: part.thoughtSignature,
933-partial: output as never,
934-});
935-}
936901}
937902}
938903if (typeof candidate?.finishReason === "string") {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。