🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

ai

Package Overview
Dependencies
Maintainers
5
Versions
1283
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai - npm Package Compare versions

Comparing version
7.0.0-beta.181
to
7.0.0-beta.182
+32
src/ui-message-stream/ui-message-stream-on-end-callback.ts
import type { FinishReason } from '../types/language-model';
import type { UIMessage } from '../ui/ui-messages';
export type UIMessageStreamOnEndCallback<UI_MESSAGE extends UIMessage> =
(event: {
/**
* The updated list of UI messages.
*/
messages: UI_MESSAGE[];
/**
* Indicates whether the response message is a continuation of the last original message,
* or if a new message was created.
*/
isContinuation: boolean;
/**
* Indicates whether the stream was aborted.
*/
isAborted: boolean;
/**
* The message that was sent to the client as a response
* (including the original message if it was extended).
*/
responseMessage: UI_MESSAGE;
/**
* The reason why the generation finished.
*/
finishReason?: FinishReason;
}) => PromiseLike<void> | void;
+1
-1
{
"name": "ai",
"version": "7.0.0-beta.181",
"version": "7.0.0-beta.182",
"type": "module",

@@ -5,0 +5,0 @@ "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",

@@ -14,3 +14,3 @@ import type { JSONObject } from '@ai-sdk/provider';

import type { InferUIMessageChunk } from '../ui-message-stream/ui-message-chunks';
import type { UIMessageStreamOnFinishCallback } from '../ui-message-stream/ui-message-stream-on-finish-callback';
import type { UIMessageStreamOnEndCallback } from '../ui-message-stream/ui-message-stream-on-end-callback';
import type { UIMessageStreamResponseInit } from '../ui-message-stream/ui-message-stream-response-init';

@@ -61,6 +61,11 @@ import type { InferUIMessageMetadata, UIMessage } from '../ui/ui-messages';

onFinish?: UIMessageStreamOnFinishCallback<UI_MESSAGE>;
onEnd?: UIMessageStreamOnEndCallback<UI_MESSAGE>;
/**
* Extracts message metadata that will be send to the client.
* @deprecated Use `onEnd` instead.
*/
onFinish?: UIMessageStreamOnEndCallback<UI_MESSAGE>;
/**
* Extracts message metadata that will be sent to the client.
*

@@ -67,0 +72,0 @@ * Called on `start` and `finish` events.

@@ -8,3 +8,3 @@ import {

import type { InferUIMessageChunk } from './ui-message-chunks';
import type { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';
import type { UIMessageStreamOnEndCallback } from './ui-message-stream-on-end-callback';
import type { UIMessageStreamOnStepEndCallback } from './ui-message-stream-on-step-end-callback';

@@ -23,3 +23,4 @@ import type { UIMessageStreamOnStepFinishCallback } from './ui-message-stream-on-step-finish-callback';

* @param options.onStepFinish - Deprecated alias for `onStepEnd`.
* @param options.onFinish - A callback that is called when the stream finishes.
* @param options.onEnd - A callback that is called when the stream ends.
* @param options.onFinish - Deprecated alias for `onEnd`.
* @param options.generateId - A function that generates a unique ID. Defaults to the built-in ID generator.

@@ -35,2 +36,3 @@ *

onStepFinish,
onEnd,
onFinish,

@@ -62,4 +64,9 @@ generateId = generateIdFunc,

onFinish?: UIMessageStreamOnFinishCallback<UI_MESSAGE>;
onEnd?: UIMessageStreamOnEndCallback<UI_MESSAGE>;
/**
* @deprecated Use `onEnd` instead.
*/
onFinish?: UIMessageStreamOnEndCallback<UI_MESSAGE>;
generateId?: IdGenerator;

@@ -155,5 +162,5 @@ }): ReadableStream<InferUIMessageChunk<UI_MESSAGE>> {

onStepEnd: onStepEnd ?? onStepFinish,
onFinish,
onEnd: onEnd ?? onFinish,
onError,
});
}

@@ -9,3 +9,3 @@ import {

import type { InferUIMessageChunk, UIMessageChunk } from './ui-message-chunks';
import type { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';
import type { UIMessageStreamOnEndCallback } from './ui-message-stream-on-end-callback';
import type { UIMessageStreamOnStepEndCallback } from './ui-message-stream-on-step-end-callback';

@@ -19,2 +19,3 @@ import type { UIMessageStreamOnStepFinishCallback } from './ui-message-stream-on-step-finish-callback';

onStepFinish,
onEnd,
onFinish,

@@ -51,3 +52,8 @@ onError,

onFinish?: UIMessageStreamOnFinishCallback<UI_MESSAGE>;
onEnd?: UIMessageStreamOnEndCallback<UI_MESSAGE>;
/**
* @deprecated Use `onEnd` instead.
*/
onFinish?: UIMessageStreamOnEndCallback<UI_MESSAGE>;
}): ReadableStream<InferUIMessageChunk<UI_MESSAGE>> {

@@ -93,4 +99,5 @@ // last message is only relevant for assistant messages

const resolvedOnStepEnd = onStepEnd ?? onStepFinish;
const resolvedOnEnd = onEnd ?? onFinish;
if (onFinish == null && resolvedOnStepEnd == null) {
if (resolvedOnEnd == null && resolvedOnStepEnd == null) {
return idInjectedStream;

@@ -117,4 +124,4 @@ }

const callOnFinish = async () => {
if (finishCalled || !onFinish) {
const callOnEnd = async () => {
if (finishCalled || !resolvedOnEnd) {
return;

@@ -125,3 +132,3 @@ }

const isContinuation = state.message.id === lastMessage?.id;
await onFinish({
await resolvedOnEnd({
isAborted,

@@ -179,7 +186,7 @@ isContinuation,

async cancel() {
await callOnFinish();
await callOnEnd();
},
async flush() {
await callOnFinish();
await callOnEnd();
},

@@ -186,0 +193,0 @@ }),

@@ -17,2 +17,3 @@ export { createUIMessageStream } from './create-ui-message-stream';

export { UI_MESSAGE_STREAM_HEADERS } from './ui-message-stream-headers';
export type { UIMessageStreamOnEndCallback } from './ui-message-stream-on-end-callback';
export type { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';

@@ -19,0 +20,0 @@ export type { UIMessageStreamOnStepEndCallback } from './ui-message-stream-on-step-end-callback';

@@ -16,3 +16,3 @@ import type { ToolSet } from '@ai-sdk/provider-utils';

* UI message streaming, including response message ID injection and
* `onFinish` handling.
* `onEnd` handling.
*/

@@ -33,2 +33,3 @@ export function toUIMessageStream<

generateMessageId,
onEnd,
onFinish,

@@ -89,5 +90,5 @@ }: {

originalMessages,
onFinish,
onEnd: onEnd ?? onFinish,
onError,
});
}

@@ -1,32 +0,8 @@

import type { FinishReason } from '../types/language-model';
import type { UIMessage } from '../ui/ui-messages';
import type { UIMessageStreamOnEndCallback } from './ui-message-stream-on-end-callback';
/**
* @deprecated Use `UIMessageStreamOnEndCallback` instead.
*/
export type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> =
(event: {
/**
* The updated list of UI messages.
*/
messages: UI_MESSAGE[];
/**
* Indicates whether the response message is a continuation of the last original message,
* or if a new message was created.
*/
isContinuation: boolean;
/**
* Indicates whether the stream was aborted.
*/
isAborted: boolean;
/**
* The message that was sent to the client as a response
* (including the original message if it was extended).
*/
responseMessage: UI_MESSAGE;
/**
* The reason why the generation finished.
*/
finishReason?: FinishReason;
}) => PromiseLike<void> | void;
UIMessageStreamOnEndCallback<UI_MESSAGE>;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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

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

Sorry, the diff of this file is too big to display