@ynhcj/xiaoyi-channel 0.0.184-next → 0.0.185-next
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/provider.js +8 -6
- package/package.json +1 -1
package/dist/src/provider.js
CHANGED
|
@@ -128,7 +128,7 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
128
128
|
let hasContent = false;
|
|
129
129
|
const buffer = [];
|
|
130
130
|
let errorResult = null;
|
|
131
|
-
|
|
131
|
+
const fullResponseEvents = [];
|
|
132
132
|
for await (const event of stream) {
|
|
133
133
|
const isContent = CONTENT_EVENT_TYPES.has(event.type);
|
|
134
134
|
if (!hasContent && !isContent) {
|
|
@@ -151,18 +151,20 @@ function createRetryingStream(createStream, cronJob) {
|
|
|
151
151
|
if (!hasContent) {
|
|
152
152
|
logger.log("[xiaoyiprovider] first content event received, switching to streaming mode");
|
|
153
153
|
hasContent = true;
|
|
154
|
-
for (const b of buffer)
|
|
154
|
+
for (const b of buffer) {
|
|
155
|
+
if (CONTENT_EVENT_TYPES.has(b.type))
|
|
156
|
+
fullResponseEvents.push(b);
|
|
155
157
|
yield b;
|
|
158
|
+
}
|
|
156
159
|
}
|
|
160
|
+
if (isContent)
|
|
161
|
+
fullResponseEvents.push(event);
|
|
157
162
|
// IMPORTANT: resolve result() BEFORE yielding terminal events to avoid deadlock.
|
|
158
163
|
// The SDK calls result() when it sees done/error — if we yield first, the generator
|
|
159
164
|
// suspends and can never reach resolve, causing a permanent deadlock.
|
|
160
|
-
if (event.type === "text_delta") {
|
|
161
|
-
fullResponseText += event.delta ?? "";
|
|
162
|
-
}
|
|
163
165
|
if (event.type === "done") {
|
|
164
166
|
logger.log(`[xiaoyiprovider] stream completed, usage: input=${event.message?.usage?.input} output=${event.message?.usage?.output}`);
|
|
165
|
-
logger.log(`[xiaoyiprovider] full model response: ${
|
|
167
|
+
logger.log(`[xiaoyiprovider] full model response: ${JSON.stringify(fullResponseEvents)}`);
|
|
166
168
|
resultResolve(event.message);
|
|
167
169
|
yield event;
|
|
168
170
|
return;
|