Socket
Socket
Sign inDemoInstall

@ai-sdk/react

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/react - npm Package Compare versions

Comparing version 0.0.55 to 0.0.56

82

./dist/index.js

@@ -452,3 +452,4 @@ "use strict";

headers: headers2,
body: body2
body: body2,
experimental_attachments
} = {}) => {

@@ -458,2 +459,5 @@ if (!message.id) {

}
const attachmentsForRequest = await prepareAttachmentsForRequest(
experimental_attachments
);
const requestOptions = {

@@ -463,4 +467,11 @@ headers: headers2 != null ? headers2 : options == null ? void 0 : options.headers,

};
const messages2 = messagesRef.current.concat({
id: generateId2(),
createdAt: /* @__PURE__ */ new Date(),
role: "user",
content: message.content,
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : void 0
});
const chatRequest = {
messages: messagesRef.current.concat(message),
messages: messages2,
options: requestOptions,

@@ -555,36 +566,5 @@ headers: requestOptions.headers,

}
const attachmentsForRequest = [];
const attachmentsFromOptions = options.experimental_attachments;
if (attachmentsFromOptions) {
if (attachmentsFromOptions instanceof FileList) {
for (const attachment of Array.from(attachmentsFromOptions)) {
const { name, type } = attachment;
const dataUrl = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (readerEvent) => {
var _a2;
resolve((_a2 = readerEvent.target) == null ? void 0 : _a2.result);
};
reader.onerror = (error2) => reject(error2);
reader.readAsDataURL(attachment);
});
attachmentsForRequest.push({
name,
contentType: type,
url: dataUrl
});
}
} else if (Array.isArray(attachmentsFromOptions)) {
for (const file of attachmentsFromOptions) {
const { name, url, contentType } = file;
attachmentsForRequest.push({
name,
contentType,
url
});
}
} else {
throw new Error("Invalid attachments type");
}
}
const attachmentsForRequest = await prepareAttachmentsForRequest(
options.experimental_attachments
);
const requestOptions = {

@@ -668,2 +648,32 @@ headers: (_c = options.headers) != null ? _c : (_b = options.options) == null ? void 0 : _b.headers,

}
async function prepareAttachmentsForRequest(attachmentsFromOptions) {
if (attachmentsFromOptions == null) {
return [];
}
if (attachmentsFromOptions instanceof FileList) {
return Promise.all(
Array.from(attachmentsFromOptions).map(async (attachment) => {
const { name, type } = attachment;
const dataUrl = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (readerEvent) => {
var _a;
resolve((_a = readerEvent.target) == null ? void 0 : _a.result);
};
reader.onerror = (error) => reject(error);
reader.readAsDataURL(attachment);
});
return {
name,
contentType: type,
url: dataUrl
};
})
);
}
if (Array.isArray(attachmentsFromOptions)) {
return attachmentsFromOptions;
}
throw new Error("Invalid attachments type");
}

@@ -670,0 +680,0 @@ // src/use-completion.ts

# @ai-sdk/react
## 0.0.56
### Patch Changes
- a0403d6: feat (react): support sending attachments using append
## 0.0.55

@@ -4,0 +10,0 @@

@@ -452,3 +452,4 @@ "use strict";

headers: headers2,
body: body2
body: body2,
experimental_attachments
} = {}) => {

@@ -458,2 +459,5 @@ if (!message.id) {

}
const attachmentsForRequest = await prepareAttachmentsForRequest(
experimental_attachments
);
const requestOptions = {

@@ -463,4 +467,11 @@ headers: headers2 != null ? headers2 : options == null ? void 0 : options.headers,

};
const messages2 = messagesRef.current.concat({
id: generateId2(),
createdAt: /* @__PURE__ */ new Date(),
role: "user",
content: message.content,
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : void 0
});
const chatRequest = {
messages: messagesRef.current.concat(message),
messages: messages2,
options: requestOptions,

@@ -555,36 +566,5 @@ headers: requestOptions.headers,

}
const attachmentsForRequest = [];
const attachmentsFromOptions = options.experimental_attachments;
if (attachmentsFromOptions) {
if (attachmentsFromOptions instanceof FileList) {
for (const attachment of Array.from(attachmentsFromOptions)) {
const { name, type } = attachment;
const dataUrl = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (readerEvent) => {
var _a2;
resolve((_a2 = readerEvent.target) == null ? void 0 : _a2.result);
};
reader.onerror = (error2) => reject(error2);
reader.readAsDataURL(attachment);
});
attachmentsForRequest.push({
name,
contentType: type,
url: dataUrl
});
}
} else if (Array.isArray(attachmentsFromOptions)) {
for (const file of attachmentsFromOptions) {
const { name, url, contentType } = file;
attachmentsForRequest.push({
name,
contentType,
url
});
}
} else {
throw new Error("Invalid attachments type");
}
}
const attachmentsForRequest = await prepareAttachmentsForRequest(
options.experimental_attachments
);
const requestOptions = {

@@ -668,2 +648,32 @@ headers: (_c = options.headers) != null ? _c : (_b = options.options) == null ? void 0 : _b.headers,

}
async function prepareAttachmentsForRequest(attachmentsFromOptions) {
if (attachmentsFromOptions == null) {
return [];
}
if (attachmentsFromOptions instanceof FileList) {
return Promise.all(
Array.from(attachmentsFromOptions).map(async (attachment) => {
const { name, type } = attachment;
const dataUrl = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (readerEvent) => {
var _a;
resolve((_a = readerEvent.target) == null ? void 0 : _a.result);
};
reader.onerror = (error) => reject(error);
reader.readAsDataURL(attachment);
});
return {
name,
contentType: type,
url: dataUrl
};
})
);
}
if (Array.isArray(attachmentsFromOptions)) {
return attachmentsFromOptions;
}
throw new Error("Invalid attachments type");
}

@@ -670,0 +680,0 @@ // src/use-completion.ts

{
"name": "@ai-sdk/react",
"version": "0.0.55",
"version": "0.0.56",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "sideEffects": false,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc