@ai-sdk/ui-utils
Advanced tools
Comparing version 1.0.0-canary.8 to 1.0.0-canary.9
# @ai-sdk/ui-utils | ||
## 1.0.0-canary.9 | ||
### Patch Changes | ||
- 04d3747: chore (ui-utils): restructure processAssistantMessage | ||
## 1.0.0-canary.8 | ||
@@ -4,0 +10,0 @@ |
@@ -565,5 +565,19 @@ import { LanguageModelV1FinishReason, JSONValue as JSONValue$1 } from '@ai-sdk/provider'; | ||
declare function processAssistantStream({ stream, onStreamPart, }: { | ||
declare function processAssistantStream({ stream, onTextPart, onErrorPart, onAssistantMessagePart, onAssistantControlDataPart, onDataMessagePart, }: { | ||
stream: ReadableStream<Uint8Array>; | ||
onStreamPart: (streamPart: AssistantStreamPartType) => Promise<void> | void; | ||
onTextPart?: (streamPart: (AssistantStreamPartType & { | ||
type: 'text'; | ||
})['value']) => Promise<void> | void; | ||
onErrorPart?: (streamPart: (AssistantStreamPartType & { | ||
type: 'error'; | ||
})['value']) => Promise<void> | void; | ||
onAssistantMessagePart?: (streamPart: (AssistantStreamPartType & { | ||
type: 'assistant_message'; | ||
})['value']) => Promise<void> | void; | ||
onAssistantControlDataPart?: (streamPart: (AssistantStreamPartType & { | ||
type: 'assistant_control_data'; | ||
})['value']) => Promise<void> | void; | ||
onDataMessagePart?: (streamPart: (AssistantStreamPartType & { | ||
type: 'data_message'; | ||
})['value']) => Promise<void> | void; | ||
}): Promise<void>; | ||
@@ -570,0 +584,0 @@ |
@@ -1259,3 +1259,7 @@ "use strict"; | ||
stream, | ||
onStreamPart | ||
onTextPart, | ||
onErrorPart, | ||
onAssistantMessagePart, | ||
onAssistantControlDataPart, | ||
onDataMessagePart | ||
}) { | ||
@@ -1281,4 +1285,24 @@ const reader = stream.getReader(); | ||
const streamParts = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseAssistantStreamPart); | ||
for (const streamPart of streamParts) { | ||
await onStreamPart(streamPart); | ||
for (const { type, value: value2 } of streamParts) { | ||
switch (type) { | ||
case "text": | ||
await (onTextPart == null ? void 0 : onTextPart(value2)); | ||
break; | ||
case "error": | ||
await (onErrorPart == null ? void 0 : onErrorPart(value2)); | ||
break; | ||
case "assistant_message": | ||
await (onAssistantMessagePart == null ? void 0 : onAssistantMessagePart(value2)); | ||
break; | ||
case "assistant_control_data": | ||
await (onAssistantControlDataPart == null ? void 0 : onAssistantControlDataPart(value2)); | ||
break; | ||
case "data_message": | ||
await (onDataMessagePart == null ? void 0 : onDataMessagePart(value2)); | ||
break; | ||
default: { | ||
const exhaustiveCheck = type; | ||
throw new Error(`Unknown stream part type: ${exhaustiveCheck}`); | ||
} | ||
} | ||
} | ||
@@ -1285,0 +1309,0 @@ } |
{ | ||
"name": "@ai-sdk/ui-utils", | ||
"version": "1.0.0-canary.8", | ||
"version": "1.0.0-canary.9", | ||
"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
322078
3575