Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ai-sdk/ui-utils

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/ui-utils - npm Package Compare versions

Comparing version 1.0.0-canary.1 to 1.0.0-canary.2

81

./dist/index.js

@@ -729,4 +729,4 @@ "use strict";

const createdAt = getCurrentDate();
let prefixMap = {};
let nextPrefixMap = void 0;
let currentMessage = {};
let nextMessage = void 0;
const previousMessages = [];

@@ -750,3 +750,3 @@ const data = [];

if (!value.isContinued) {
nextPrefixMap = {};
nextMessage = {};
}

@@ -767,17 +767,17 @@ continue;

}
if (nextPrefixMap != null && (type === "text" || type === "tool_call" || type === "tool_call_streaming_start" || type === "tool_call_delta" || type === "tool_result")) {
if (prefixMap.text) {
previousMessages.push(prefixMap.text);
if (nextMessage != null && (type === "text" || type === "tool_call" || type === "tool_call_streaming_start" || type === "tool_call_delta" || type === "tool_result")) {
if (currentMessage.message) {
previousMessages.push(currentMessage.message);
}
prefixMap = nextPrefixMap;
nextPrefixMap = void 0;
currentMessage = nextMessage;
nextMessage = void 0;
}
if (type === "text") {
if (prefixMap["text"]) {
prefixMap["text"] = {
...prefixMap["text"],
content: (prefixMap["text"].content || "") + value
if (currentMessage["message"]) {
currentMessage["message"] = {
...currentMessage["message"],
content: (currentMessage["message"].content || "") + value
};
} else {
prefixMap["text"] = {
currentMessage["message"] = {
id: generateId2(),

@@ -791,4 +791,4 @@ role: "assistant",

if (type === "tool_call_streaming_start") {
if (prefixMap.text == null) {
prefixMap.text = {
if (currentMessage.message == null) {
currentMessage.message = {
id: generateId2(),

@@ -800,4 +800,4 @@ role: "assistant",

}
if (prefixMap.text.toolInvocations == null) {
prefixMap.text.toolInvocations = [];
if (currentMessage.message.toolInvocations == null) {
currentMessage.message.toolInvocations = [];
}

@@ -807,5 +807,5 @@ partialToolCalls[value.toolCallId] = {

toolName: value.toolName,
prefixMapIndex: prefixMap.text.toolInvocations.length
prefixMapIndex: currentMessage.message.toolInvocations.length
};
prefixMap.text.toolInvocations.push({
currentMessage.message.toolInvocations.push({
state: "partial-call",

@@ -820,3 +820,3 @@ toolCallId: value.toolCallId,

const { value: partialArgs } = parsePartialJson(partialToolCall.text);
prefixMap.text.toolInvocations[partialToolCall.prefixMapIndex] = {
currentMessage.message.toolInvocations[partialToolCall.prefixMapIndex] = {
state: "partial-call",

@@ -827,9 +827,9 @@ toolCallId: value.toolCallId,

};
prefixMap.text.internalUpdateId = generateId2();
currentMessage.message.internalUpdateId = generateId2();
} else if (type === "tool_call") {
if (partialToolCalls[value.toolCallId] != null) {
prefixMap.text.toolInvocations[partialToolCalls[value.toolCallId].prefixMapIndex] = { state: "call", ...value };
currentMessage.message.toolInvocations[partialToolCalls[value.toolCallId].prefixMapIndex] = { state: "call", ...value };
} else {
if (prefixMap.text == null) {
prefixMap.text = {
if (currentMessage.message == null) {
currentMessage.message = {
id: generateId2(),

@@ -841,6 +841,6 @@ role: "assistant",

}
if (prefixMap.text.toolInvocations == null) {
prefixMap.text.toolInvocations = [];
if (currentMessage.message.toolInvocations == null) {
currentMessage.message.toolInvocations = [];
}
prefixMap.text.toolInvocations.push({
currentMessage.message.toolInvocations.push({
state: "call",

@@ -850,11 +850,11 @@ ...value

}
prefixMap.text.internalUpdateId = generateId2();
currentMessage.message.internalUpdateId = generateId2();
if (onToolCall) {
const result = await onToolCall({ toolCall: value });
if (result != null) {
prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { state: "result", ...value, result };
currentMessage.message.toolInvocations[currentMessage.message.toolInvocations.length - 1] = { state: "result", ...value, result };
}
}
} else if (type === "tool_result") {
const toolInvocations = (_a = prefixMap.text) == null ? void 0 : _a.toolInvocations;
const toolInvocations = (_a = currentMessage.message) == null ? void 0 : _a.toolInvocations;
if (toolInvocations == null) {

@@ -880,3 +880,2 @@ throw new Error("tool_result must be preceded by a tool_call");

}
let responseMessage = prefixMap["text"];
if (type === "message_annotations") {

@@ -888,16 +887,14 @@ if (!messageAnnotations) {

}
responseMessage = assignAnnotationsToMessage(
prefixMap["text"],
currentMessage.message = assignAnnotationsToMessage(
currentMessage.message,
messageAnnotations
);
if (prefixMap.text != null) {
prefixMap.text.internalUpdateId = generateId2();
if (currentMessage.message != null) {
currentMessage.message.internalUpdateId = generateId2();
}
}
if (messageAnnotations == null ? void 0 : messageAnnotations.length) {
if (prefixMap.text) {
prefixMap.text.annotations = [...messageAnnotations];
}
if ((messageAnnotations == null ? void 0 : messageAnnotations.length) && currentMessage.message) {
currentMessage.message.annotations = [...messageAnnotations];
}
const merged = [responseMessage].filter(Boolean).map((message) => ({
const merged = [currentMessage.message].filter(Boolean).map((message) => ({
...assignAnnotationsToMessage(message, messageAnnotations)

@@ -907,5 +904,5 @@ }));

}
onFinish == null ? void 0 : onFinish({ message: prefixMap.text, finishReason, usage });
onFinish == null ? void 0 : onFinish({ message: currentMessage.message, finishReason, usage });
return {
messages: [prefixMap.text].filter(Boolean),
messages: [currentMessage.message].filter(Boolean),
data

@@ -912,0 +909,0 @@ };

# @ai-sdk/ui-utils
## 1.0.0-canary.2
### Major Changes
- 7814c4b: chore (ui): remove streamMode setting from useChat & useCompletion
### Patch Changes
- Updated dependencies [b469a7e]
- Updated dependencies [c0ddc24]
- Updated dependencies [db46ce5]
- @ai-sdk/provider-utils@2.0.0-canary.0
- @ai-sdk/provider@1.0.0-canary.0
## 1.0.0-canary.1

@@ -4,0 +18,0 @@

@@ -269,8 +269,2 @@ import { LanguageModelV1FinishReason, JSONValue as JSONValue$1 } from '@ai-sdk/provider';

/**
* Stream mode (default to "stream-data")
*
* @deprecated Use `streamProtocol` instead.
*/
streamMode?: 'stream-data' | 'text';
/**
Streaming protocol that is used. Defaults to `data`.

@@ -341,8 +335,2 @@ */

/**
* Stream mode (default to "stream-data")
*
* @deprecated Use `streamProtocol` instead.
*/
streamMode?: 'stream-data' | 'text';
/**
Streaming protocol that is used. Defaults to `data`.

@@ -349,0 +337,0 @@ */

@@ -729,4 +729,4 @@ "use strict";

const createdAt = getCurrentDate();
let prefixMap = {};
let nextPrefixMap = void 0;
let currentMessage = {};
let nextMessage = void 0;
const previousMessages = [];

@@ -750,3 +750,3 @@ const data = [];

if (!value.isContinued) {
nextPrefixMap = {};
nextMessage = {};
}

@@ -767,17 +767,17 @@ continue;

}
if (nextPrefixMap != null && (type === "text" || type === "tool_call" || type === "tool_call_streaming_start" || type === "tool_call_delta" || type === "tool_result")) {
if (prefixMap.text) {
previousMessages.push(prefixMap.text);
if (nextMessage != null && (type === "text" || type === "tool_call" || type === "tool_call_streaming_start" || type === "tool_call_delta" || type === "tool_result")) {
if (currentMessage.message) {
previousMessages.push(currentMessage.message);
}
prefixMap = nextPrefixMap;
nextPrefixMap = void 0;
currentMessage = nextMessage;
nextMessage = void 0;
}
if (type === "text") {
if (prefixMap["text"]) {
prefixMap["text"] = {
...prefixMap["text"],
content: (prefixMap["text"].content || "") + value
if (currentMessage["message"]) {
currentMessage["message"] = {
...currentMessage["message"],
content: (currentMessage["message"].content || "") + value
};
} else {
prefixMap["text"] = {
currentMessage["message"] = {
id: generateId2(),

@@ -791,4 +791,4 @@ role: "assistant",

if (type === "tool_call_streaming_start") {
if (prefixMap.text == null) {
prefixMap.text = {
if (currentMessage.message == null) {
currentMessage.message = {
id: generateId2(),

@@ -800,4 +800,4 @@ role: "assistant",

}
if (prefixMap.text.toolInvocations == null) {
prefixMap.text.toolInvocations = [];
if (currentMessage.message.toolInvocations == null) {
currentMessage.message.toolInvocations = [];
}

@@ -807,5 +807,5 @@ partialToolCalls[value.toolCallId] = {

toolName: value.toolName,
prefixMapIndex: prefixMap.text.toolInvocations.length
prefixMapIndex: currentMessage.message.toolInvocations.length
};
prefixMap.text.toolInvocations.push({
currentMessage.message.toolInvocations.push({
state: "partial-call",

@@ -820,3 +820,3 @@ toolCallId: value.toolCallId,

const { value: partialArgs } = parsePartialJson(partialToolCall.text);
prefixMap.text.toolInvocations[partialToolCall.prefixMapIndex] = {
currentMessage.message.toolInvocations[partialToolCall.prefixMapIndex] = {
state: "partial-call",

@@ -827,9 +827,9 @@ toolCallId: value.toolCallId,

};
prefixMap.text.internalUpdateId = generateId2();
currentMessage.message.internalUpdateId = generateId2();
} else if (type === "tool_call") {
if (partialToolCalls[value.toolCallId] != null) {
prefixMap.text.toolInvocations[partialToolCalls[value.toolCallId].prefixMapIndex] = { state: "call", ...value };
currentMessage.message.toolInvocations[partialToolCalls[value.toolCallId].prefixMapIndex] = { state: "call", ...value };
} else {
if (prefixMap.text == null) {
prefixMap.text = {
if (currentMessage.message == null) {
currentMessage.message = {
id: generateId2(),

@@ -841,6 +841,6 @@ role: "assistant",

}
if (prefixMap.text.toolInvocations == null) {
prefixMap.text.toolInvocations = [];
if (currentMessage.message.toolInvocations == null) {
currentMessage.message.toolInvocations = [];
}
prefixMap.text.toolInvocations.push({
currentMessage.message.toolInvocations.push({
state: "call",

@@ -850,11 +850,11 @@ ...value

}
prefixMap.text.internalUpdateId = generateId2();
currentMessage.message.internalUpdateId = generateId2();
if (onToolCall) {
const result = await onToolCall({ toolCall: value });
if (result != null) {
prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { state: "result", ...value, result };
currentMessage.message.toolInvocations[currentMessage.message.toolInvocations.length - 1] = { state: "result", ...value, result };
}
}
} else if (type === "tool_result") {
const toolInvocations = (_a = prefixMap.text) == null ? void 0 : _a.toolInvocations;
const toolInvocations = (_a = currentMessage.message) == null ? void 0 : _a.toolInvocations;
if (toolInvocations == null) {

@@ -880,3 +880,2 @@ throw new Error("tool_result must be preceded by a tool_call");

}
let responseMessage = prefixMap["text"];
if (type === "message_annotations") {

@@ -888,16 +887,14 @@ if (!messageAnnotations) {

}
responseMessage = assignAnnotationsToMessage(
prefixMap["text"],
currentMessage.message = assignAnnotationsToMessage(
currentMessage.message,
messageAnnotations
);
if (prefixMap.text != null) {
prefixMap.text.internalUpdateId = generateId2();
if (currentMessage.message != null) {
currentMessage.message.internalUpdateId = generateId2();
}
}
if (messageAnnotations == null ? void 0 : messageAnnotations.length) {
if (prefixMap.text) {
prefixMap.text.annotations = [...messageAnnotations];
}
if ((messageAnnotations == null ? void 0 : messageAnnotations.length) && currentMessage.message) {
currentMessage.message.annotations = [...messageAnnotations];
}
const merged = [responseMessage].filter(Boolean).map((message) => ({
const merged = [currentMessage.message].filter(Boolean).map((message) => ({
...assignAnnotationsToMessage(message, messageAnnotations)

@@ -907,5 +904,5 @@ }));

}
onFinish == null ? void 0 : onFinish({ message: prefixMap.text, finishReason, usage });
onFinish == null ? void 0 : onFinish({ message: currentMessage.message, finishReason, usage });
return {
messages: [prefixMap.text].filter(Boolean),
messages: [currentMessage.message].filter(Boolean),
data

@@ -912,0 +909,0 @@ };

{
"name": "@ai-sdk/ui-utils",
"version": "1.0.0-canary.1",
"version": "1.0.0-canary.2",
"license": "Apache-2.0",

@@ -29,4 +29,4 @@ "sideEffects": false,

"dependencies": {
"@ai-sdk/provider": "0.0.26",
"@ai-sdk/provider-utils": "1.0.22",
"@ai-sdk/provider": "1.0.0-canary.0",
"@ai-sdk/provider-utils": "2.0.0-canary.0",
"json-schema": "^0.4.0",

@@ -33,0 +33,0 @@ "secure-json-parse": "^2.7.0",

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

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