ai 3.0.0 → 3.0.1
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/README.md +1 -60
- package/dist/index.d.ts +14 -3
- package/dist/index.js +35 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/rsc/dist/rsc-server.mjs +64 -27
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -245,10 +245,14 @@ function createCallbacksTransformer(cb) {
|
|
245
245
|
await callbacks.onStart();
|
246
246
|
},
|
247
247
|
async transform(message, controller) {
|
248
|
-
|
249
|
-
|
248
|
+
const content = typeof message === "string" ? message : message.content;
|
249
|
+
controller.enqueue(textEncoder.encode(content));
|
250
|
+
aggregatedResponse += content;
|
250
251
|
if (callbacks.onToken)
|
251
|
-
await callbacks.onToken(
|
252
|
+
await callbacks.onToken(content);
|
253
|
+
if (callbacks.onText && typeof message === "string") {
|
254
|
+
await callbacks.onText(message);
|
255
|
+
}
|
252
256
|
},
|
253
257
|
async flush() {
|
254
258
|
const isOpenAICallbacks = isOfTypeOpenAIStreamCallbacks(callbacks);
|
@@ -848,25 +852,46 @@ function chunkToText() {
|
|
848
852
|
const delta = (_a = json.choices[0]) == null ? void 0 : _a.delta;
|
849
853
|
if ((_b = delta.function_call) == null ? void 0 : _b.name) {
|
850
854
|
isFunctionStreamingIn = true;
|
851
|
-
return
|
855
|
+
return {
|
856
|
+
isText: false,
|
857
|
+
content: `{"function_call": {"name": "${delta.function_call.name}", "arguments": "`
|
858
|
+
};
|
852
859
|
} else if ((_e = (_d = (_c = delta.tool_calls) == null ? void 0 : _c[0]) == null ? void 0 : _d.function) == null ? void 0 : _e.name) {
|
853
860
|
isFunctionStreamingIn = true;
|
854
861
|
const toolCall = delta.tool_calls[0];
|
855
862
|
if (toolCall.index === 0) {
|
856
|
-
return
|
863
|
+
return {
|
864
|
+
isText: false,
|
865
|
+
content: `{"tool_calls":[ {"id": "${toolCall.id}", "type": "function", "function": {"name": "${(_f = toolCall.function) == null ? void 0 : _f.name}", "arguments": "`
|
866
|
+
};
|
857
867
|
} else {
|
858
|
-
return
|
868
|
+
return {
|
869
|
+
isText: false,
|
870
|
+
content: `"}}, {"id": "${toolCall.id}", "type": "function", "function": {"name": "${(_g = toolCall.function) == null ? void 0 : _g.name}", "arguments": "`
|
871
|
+
};
|
859
872
|
}
|
860
873
|
} else if ((_h = delta.function_call) == null ? void 0 : _h.arguments) {
|
861
|
-
return
|
874
|
+
return {
|
875
|
+
isText: false,
|
876
|
+
content: cleanupArguments((_i = delta.function_call) == null ? void 0 : _i.arguments)
|
877
|
+
};
|
862
878
|
} else if ((_l = (_k = (_j = delta.tool_calls) == null ? void 0 : _j[0]) == null ? void 0 : _k.function) == null ? void 0 : _l.arguments) {
|
863
|
-
return
|
879
|
+
return {
|
880
|
+
isText: false,
|
881
|
+
content: cleanupArguments((_o = (_n = (_m = delta.tool_calls) == null ? void 0 : _m[0]) == null ? void 0 : _n.function) == null ? void 0 : _o.arguments)
|
882
|
+
};
|
864
883
|
} else if (isFunctionStreamingIn && (((_p = json.choices[0]) == null ? void 0 : _p.finish_reason) === "function_call" || ((_q = json.choices[0]) == null ? void 0 : _q.finish_reason) === "stop")) {
|
865
884
|
isFunctionStreamingIn = false;
|
866
|
-
return
|
885
|
+
return {
|
886
|
+
isText: false,
|
887
|
+
content: '"}}'
|
888
|
+
};
|
867
889
|
} else if (isFunctionStreamingIn && ((_r = json.choices[0]) == null ? void 0 : _r.finish_reason) === "tool_calls") {
|
868
890
|
isFunctionStreamingIn = false;
|
869
|
-
return
|
891
|
+
return {
|
892
|
+
isText: false,
|
893
|
+
content: '"}}]}'
|
894
|
+
};
|
870
895
|
}
|
871
896
|
}
|
872
897
|
const text = trimStartOfStream(
|