@ai-sdk/ui-utils
Advanced tools
Comparing version 1.0.2 to 1.0.3
# @ai-sdk/ui-utils | ||
## 1.0.3 | ||
### Patch Changes | ||
- 953469c: chore (ui): extract prepareAttachmentsForRequest | ||
- a3dd2ed: fix (ui): preserve createdAt as Date object | ||
## 1.0.2 | ||
@@ -4,0 +11,0 @@ |
@@ -565,2 +565,4 @@ import { LanguageModelV1FinishReason, JSONValue as JSONValue$1 } from '@ai-sdk/provider'; | ||
declare function prepareAttachmentsForRequest(attachmentsFromOptions: FileList | Array<Attachment> | undefined): Promise<Attachment[]>; | ||
declare function processAssistantStream({ stream, onTextPart, onErrorPart, onAssistantMessagePart, onAssistantControlDataPart, onDataMessagePart, }: { | ||
@@ -660,2 +662,2 @@ stream: ReadableStream<Uint8Array>; | ||
export { type AssistantMessage, type AssistantStatus, type AssistantStreamPart, type AssistantStreamString, type Attachment, type ChatRequest, type ChatRequestOptions, type CreateMessage, type DataMessage, type DataStreamPart, type DataStreamString, type DeepPartial, type IdGenerator, type JSONValue, type Message, type RequestOptions, type Schema, type ToolInvocation, type UseAssistantOptions, type UseChatOptions, type UseCompletionOptions, asSchema, callChatApi, callCompletionApi, formatAssistantStreamPart, formatDataStreamPart, getTextFromDataUrl, isDeepEqualData, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, parsePartialJson, processAssistantStream, processDataStream, processTextStream, zodSchema }; | ||
export { type AssistantMessage, type AssistantStatus, type AssistantStreamPart, type AssistantStreamString, type Attachment, type ChatRequest, type ChatRequestOptions, type CreateMessage, type DataMessage, type DataStreamPart, type DataStreamString, type DeepPartial, type IdGenerator, type JSONValue, type Message, type RequestOptions, type Schema, type ToolInvocation, type UseAssistantOptions, type UseChatOptions, type UseCompletionOptions, asSchema, callChatApi, callCompletionApi, formatAssistantStreamPart, formatDataStreamPart, getTextFromDataUrl, isDeepEqualData, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, parsePartialJson, prepareAttachmentsForRequest, processAssistantStream, processDataStream, processTextStream, zodSchema }; |
@@ -45,2 +45,3 @@ "use strict"; | ||
parsePartialJson: () => parsePartialJson, | ||
prepareAttachmentsForRequest: () => prepareAttachmentsForRequest, | ||
processAssistantStream: () => processAssistantStream, | ||
@@ -860,3 +861,5 @@ processDataStream: () => processDataStream, | ||
// forwarded to rendering): | ||
revisionId: generateId2() | ||
revisionId: generateId2(), | ||
// Fill in createdAt to retain Date object (lost in JSON.parse): | ||
createdAt: currentMessage.createdAt | ||
}; | ||
@@ -1254,2 +1257,34 @@ update([...previousMessages, copiedMessage], copiedData); | ||
// src/prepare-attachments-for-request.ts | ||
async function prepareAttachmentsForRequest(attachmentsFromOptions) { | ||
if (!attachmentsFromOptions) { | ||
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"); | ||
} | ||
// src/process-assistant-stream.ts | ||
@@ -1368,2 +1403,3 @@ var NEWLINE2 = "\n".charCodeAt(0); | ||
parsePartialJson, | ||
prepareAttachmentsForRequest, | ||
processAssistantStream, | ||
@@ -1370,0 +1406,0 @@ processDataStream, |
{ | ||
"name": "@ai-sdk/ui-utils", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
331808
3659