@xsai/text-responses 1.0.0-beta.2 → 1.0.0-beta.3
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/index.js +17 -12
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -300,8 +300,8 @@ const normalizeFinishReason = (response) => {
|
|
|
300
300
|
return reason;
|
|
301
301
|
}
|
|
302
302
|
};
|
|
303
|
-
const normalizeStatus = (
|
|
304
|
-
switch (
|
|
303
|
+
const normalizeStatus = (status) => {
|
|
304
|
+
switch (status) {
|
|
305
305
|
case "cancelled":
|
|
306
306
|
return "cancelled";
|
|
307
307
|
case "completed":
|
|
@@ -310,8 +310,9 @@ const normalizeStatus = (response) => {
|
|
|
310
310
|
return "failed";
|
|
311
311
|
case "incomplete":
|
|
312
312
|
return "incomplete";
|
|
313
|
+
case void 0:
|
|
313
314
|
default:
|
|
314
|
-
throw new Error(`unknown response status: ${
|
|
315
|
+
throw new Error(`unknown response status: ${status}`);
|
|
315
316
|
}
|
|
316
317
|
};
|
|
317
318
|
class ResponsesEventStream extends WireEventStream {
|
|
@@ -343,6 +344,7 @@ class ResponsesEventStream extends WireEventStream {
|
|
|
343
344
|
};
|
|
344
345
|
const onItemDone = (builder, item, index) => {
|
|
345
346
|
const normalized = normalizeOutputItem(item, index);
|
|
347
|
+
builder.meta({ messageId: normalized.messageId });
|
|
346
348
|
for (const part of normalized.parts) {
|
|
347
349
|
const key = part.key ?? index;
|
|
348
350
|
builder.start(key, part.content.type, part.init);
|
|
@@ -350,12 +352,12 @@ class ResponsesEventStream extends WireEventStream {
|
|
|
350
352
|
}
|
|
351
353
|
return normalized;
|
|
352
354
|
};
|
|
353
|
-
const finishResponse = (builder, response) => {
|
|
354
|
-
const status = normalizeStatus(response);
|
|
355
|
+
const finishResponse = (builder, response, defaultStatus) => {
|
|
356
|
+
const status = normalizeStatus(response.status ?? defaultStatus);
|
|
355
357
|
if (response.usage != null)
|
|
356
358
|
builder.meta({ usage: normalizeUsage(response.usage) });
|
|
357
|
-
const output = response.output
|
|
358
|
-
const message = {
|
|
359
|
+
const output = response.output?.map((item, index) => onItemDone(builder, item, index));
|
|
360
|
+
const message = output && {
|
|
359
361
|
content: output.flatMap((item) => item.parts.map((part) => part.content)),
|
|
360
362
|
id: output.findLast((item) => item.messageId != null)?.messageId,
|
|
361
363
|
role: "assistant"
|
|
@@ -367,20 +369,23 @@ class ResponsesEventStream extends WireEventStream {
|
|
|
367
369
|
builder.fail(error, message);
|
|
368
370
|
return;
|
|
369
371
|
}
|
|
370
|
-
const reason = normalizeFinishReason(response) ?? (status === "completed" && message
|
|
372
|
+
const reason = normalizeFinishReason(response) ?? (status === "completed" && message?.content.some((part) => part.type === "refusal") ? "refusal" : void 0);
|
|
371
373
|
builder.done(status, reason, message);
|
|
372
374
|
};
|
|
373
375
|
super((event, builder) => {
|
|
374
376
|
switch (event.type) {
|
|
375
|
-
case "error":
|
|
376
|
-
|
|
377
|
-
|
|
377
|
+
case "error": {
|
|
378
|
+
const error = "error" in event ? event.error : event;
|
|
379
|
+
builder.fail(new XSAIError("model-error", error.message, {
|
|
380
|
+
cause: error
|
|
378
381
|
}));
|
|
379
382
|
break;
|
|
383
|
+
}
|
|
380
384
|
case "response.completed":
|
|
385
|
+
case "response.done":
|
|
381
386
|
case "response.failed":
|
|
382
387
|
case "response.incomplete":
|
|
383
|
-
finishResponse(builder, event.response);
|
|
388
|
+
finishResponse(builder, event.response, event.type === "response.done" ? "completed" : void 0);
|
|
384
389
|
break;
|
|
385
390
|
case "response.content_part.added": {
|
|
386
391
|
const content = normalizeContentPart(event.part);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/text-responses",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.3",
|
|
5
5
|
"description": "extra-small AI SDK: OpenAI Responses API model for @xsai/text.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"node": ">=26"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@xsai/text": "1.0.0-beta.
|
|
37
|
+
"@xsai/text": "1.0.0-beta.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@xsai/shared": "1.0.0-beta.
|
|
40
|
+
"@xsai/shared": "1.0.0-beta.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@xsai/text": "1.0.0-beta.
|
|
43
|
+
"@xsai/text": "1.0.0-beta.3",
|
|
44
44
|
"zod": "^4.3.6"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|