ai 2.2.31 → 2.2.33
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.d.ts +59 -5
- package/dist/index.js +83 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/prompts/dist/index.d.ts +4 -0
- package/react/dist/index.d.ts +11 -1
- package/react/dist/index.js +39 -5
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +39 -5
- package/react/dist/index.mjs.map +1 -1
- package/solid/dist/index.d.ts +4 -0
- package/solid/dist/index.js +32 -3
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +32 -3
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.ts +4 -0
- package/svelte/dist/index.js +32 -3
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +32 -3
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.ts +4 -0
- package/vue/dist/index.js +32 -3
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +32 -3
- package/vue/dist/index.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -114,6 +114,16 @@ var toolCallStreamPart = {
|
|
114
114
|
};
|
115
115
|
}
|
116
116
|
};
|
117
|
+
var messageAnnotationsStreamPart = {
|
118
|
+
code: "8",
|
119
|
+
name: "message_annotations",
|
120
|
+
parse: (value) => {
|
121
|
+
if (!Array.isArray(value)) {
|
122
|
+
throw new Error('"message_annotations" parts expect an array value.');
|
123
|
+
}
|
124
|
+
return { type: "message_annotations", value };
|
125
|
+
}
|
126
|
+
};
|
117
127
|
var streamParts = [
|
118
128
|
textStreamPart,
|
119
129
|
functionCallStreamPart,
|
@@ -122,7 +132,8 @@ var streamParts = [
|
|
122
132
|
assistantMessageStreamPart,
|
123
133
|
assistantControlDataStreamPart,
|
124
134
|
dataMessageStreamPart,
|
125
|
-
toolCallStreamPart
|
135
|
+
toolCallStreamPart,
|
136
|
+
messageAnnotationsStreamPart
|
126
137
|
];
|
127
138
|
var streamPartsByCode = {
|
128
139
|
[textStreamPart.code]: textStreamPart,
|
@@ -132,7 +143,8 @@ var streamPartsByCode = {
|
|
132
143
|
[assistantMessageStreamPart.code]: assistantMessageStreamPart,
|
133
144
|
[assistantControlDataStreamPart.code]: assistantControlDataStreamPart,
|
134
145
|
[dataMessageStreamPart.code]: dataMessageStreamPart,
|
135
|
-
[toolCallStreamPart.code]: toolCallStreamPart
|
146
|
+
[toolCallStreamPart.code]: toolCallStreamPart,
|
147
|
+
[messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart
|
136
148
|
};
|
137
149
|
var StreamStringPrefixes = {
|
138
150
|
[textStreamPart.name]: textStreamPart.code,
|
@@ -142,7 +154,8 @@ var StreamStringPrefixes = {
|
|
142
154
|
[assistantMessageStreamPart.name]: assistantMessageStreamPart.code,
|
143
155
|
[assistantControlDataStreamPart.name]: assistantControlDataStreamPart.code,
|
144
156
|
[dataMessageStreamPart.name]: dataMessageStreamPart.code,
|
145
|
-
[toolCallStreamPart.name]: toolCallStreamPart.code
|
157
|
+
[toolCallStreamPart.name]: toolCallStreamPart.code,
|
158
|
+
[messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code
|
146
159
|
};
|
147
160
|
var validCodes = streamParts.map((part) => part.code);
|
148
161
|
var parseStreamPart = (line) => {
|
@@ -208,7 +221,9 @@ function createEventStreamTransformer(customParser) {
|
|
208
221
|
return;
|
209
222
|
}
|
210
223
|
if ("data" in event) {
|
211
|
-
const parsedMessage = customParser ? customParser(event.data
|
224
|
+
const parsedMessage = customParser ? customParser(event.data, {
|
225
|
+
event: event.event
|
226
|
+
}) : event.data;
|
212
227
|
if (parsedMessage)
|
213
228
|
controller.enqueue(parsedMessage);
|
214
229
|
}
|
@@ -320,6 +335,7 @@ var experimental_StreamData = class {
|
|
320
335
|
this.isClosed = false;
|
321
336
|
// array to store appended data
|
322
337
|
this.data = [];
|
338
|
+
this.messageAnnotations = [];
|
323
339
|
this.isClosedPromise = new Promise((resolve) => {
|
324
340
|
this.isClosedPromiseResolver = resolve;
|
325
341
|
});
|
@@ -336,6 +352,12 @@ var experimental_StreamData = class {
|
|
336
352
|
self.data = [];
|
337
353
|
controller.enqueue(encodedData);
|
338
354
|
}
|
355
|
+
if (self.messageAnnotations.length) {
|
356
|
+
const encodedmessageAnnotations = self.encoder.encode(
|
357
|
+
formatStreamPart("message_annotations", self.messageAnnotations)
|
358
|
+
);
|
359
|
+
controller.enqueue(encodedmessageAnnotations);
|
360
|
+
}
|
339
361
|
controller.enqueue(chunk);
|
340
362
|
},
|
341
363
|
async flush(controller) {
|
@@ -354,6 +376,12 @@ var experimental_StreamData = class {
|
|
354
376
|
);
|
355
377
|
controller.enqueue(encodedData);
|
356
378
|
}
|
379
|
+
if (self.messageAnnotations.length) {
|
380
|
+
const encodedData = self.encoder.encode(
|
381
|
+
formatStreamPart("message_annotations", self.messageAnnotations)
|
382
|
+
);
|
383
|
+
controller.enqueue(encodedData);
|
384
|
+
}
|
357
385
|
}
|
358
386
|
});
|
359
387
|
}
|
@@ -374,6 +402,12 @@ var experimental_StreamData = class {
|
|
374
402
|
}
|
375
403
|
this.data.push(value);
|
376
404
|
}
|
405
|
+
appendMessageAnnotation(value) {
|
406
|
+
if (this.isClosed) {
|
407
|
+
throw new Error("Data Stream has already been closed.");
|
408
|
+
}
|
409
|
+
this.messageAnnotations.push(value);
|
410
|
+
}
|
377
411
|
};
|
378
412
|
function createStreamDataTransformer(experimental_streamData) {
|
379
413
|
if (!experimental_streamData) {
|
@@ -699,7 +733,35 @@ function parseOpenAIStream() {
|
|
699
733
|
}
|
700
734
|
async function* streamable3(stream) {
|
701
735
|
const extract = chunkToText();
|
702
|
-
for await (
|
736
|
+
for await (let chunk of stream) {
|
737
|
+
if ("promptFilterResults" in chunk) {
|
738
|
+
chunk = {
|
739
|
+
id: chunk.id,
|
740
|
+
created: chunk.created.getDate(),
|
741
|
+
object: chunk.object,
|
742
|
+
// not exposed by Azure API
|
743
|
+
model: chunk.model,
|
744
|
+
// not exposed by Azure API
|
745
|
+
choices: chunk.choices.map((choice) => {
|
746
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
747
|
+
return {
|
748
|
+
delta: {
|
749
|
+
content: (_a = choice.delta) == null ? void 0 : _a.content,
|
750
|
+
function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
|
751
|
+
role: (_c = choice.delta) == null ? void 0 : _c.role,
|
752
|
+
tool_calls: ((_e = (_d = choice.delta) == null ? void 0 : _d.toolCalls) == null ? void 0 : _e.length) ? (_g = (_f = choice.delta) == null ? void 0 : _f.toolCalls) == null ? void 0 : _g.map((toolCall, index) => ({
|
753
|
+
index,
|
754
|
+
id: toolCall.id,
|
755
|
+
function: toolCall.function,
|
756
|
+
type: toolCall.type
|
757
|
+
})) : void 0
|
758
|
+
},
|
759
|
+
finish_reason: choice.finishReason,
|
760
|
+
index: choice.index
|
761
|
+
};
|
762
|
+
})
|
763
|
+
};
|
764
|
+
}
|
703
765
|
const text = extract(chunk);
|
704
766
|
if (text)
|
705
767
|
yield text;
|
@@ -1059,6 +1121,22 @@ async function parseComplexResponse({
|
|
1059
1121
|
};
|
1060
1122
|
}
|
1061
1123
|
}
|
1124
|
+
if (type == "message_annotations") {
|
1125
|
+
if (prefixMap["text"]) {
|
1126
|
+
prefixMap["text"] = {
|
1127
|
+
...prefixMap["text"],
|
1128
|
+
annotations: [...prefixMap["text"].annotations || [], ...value]
|
1129
|
+
};
|
1130
|
+
} else {
|
1131
|
+
prefixMap["text"] = {
|
1132
|
+
id: generateId(),
|
1133
|
+
role: "assistant",
|
1134
|
+
content: "",
|
1135
|
+
annotations: [...value],
|
1136
|
+
createdAt
|
1137
|
+
};
|
1138
|
+
}
|
1139
|
+
}
|
1062
1140
|
let functionCallMessage = null;
|
1063
1141
|
if (type === "function_call") {
|
1064
1142
|
prefixMap["function_call"] = {
|