Socket
Socket
Sign inDemoInstall

ai

Package Overview
Dependencies
Maintainers
11
Versions
246
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 3.3.6 to 3.3.7

16

package.json
{
"name": "ai",
"version": "3.3.6",
"version": "3.3.7",
"description": "Vercel AI SDK - The AI Toolkit for TypeScript and JavaScript",

@@ -61,9 +61,9 @@ "license": "Apache-2.0",

"dependencies": {
"@ai-sdk/provider": "0.0.18",
"@ai-sdk/provider-utils": "1.0.10",
"@ai-sdk/react": "0.0.42",
"@ai-sdk/solid": "0.0.33",
"@ai-sdk/svelte": "0.0.35",
"@ai-sdk/ui-utils": "0.0.30",
"@ai-sdk/vue": "0.0.34",
"@ai-sdk/provider": "0.0.19",
"@ai-sdk/provider-utils": "1.0.11",
"@ai-sdk/react": "0.0.43",
"@ai-sdk/solid": "0.0.34",
"@ai-sdk/svelte": "0.0.36",
"@ai-sdk/ui-utils": "0.0.31",
"@ai-sdk/vue": "0.0.35",
"@opentelemetry/api": "1.9.0",

@@ -70,0 +70,0 @@ "eventsource-parser": "1.1.2",

@@ -1,5 +0,5 @@

import OpenAI from 'openai';
import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1 } from '@ai-sdk/provider';
import { ReactNode } from 'react';
import { z } from 'zod';
import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1 } from '@ai-sdk/provider';
import OpenAI from 'openai';

@@ -31,12 +31,2 @@ type AIAction<T = any, R = any> = (...args: T[]) => Promise<R>;

};
declare const __internal_curr: unique symbol;
declare const __internal_error: unique symbol;
/**
* StreamableValue is a value that can be streamed over the network via AI Actions.
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
*/
type StreamableValue<T = any, E = any> = {
[__internal_curr]?: T;
[__internal_error]?: E;
};

@@ -74,153 +64,42 @@ /**

type StreamableUIWrapper = {
declare function createAI<AIState = any, UIState = any, Actions extends AIActions = {}>({ actions, initialAIState, initialUIState, onSetAIState, onGetUIState, }: {
actions: Actions;
initialAIState?: AIState;
initialUIState?: UIState;
/**
* The value of the streamable UI. This can be returned from a Server Action and received by the client.
* This function is called whenever the AI state is updated by an Action.
* You can use this to persist the AI state to a database, or to send it to a
* logging service.
*/
readonly value: React.ReactNode;
onSetAIState?: OnSetAIState<AIState>;
/**
* This method updates the current UI node. It takes a new UI node and replaces the old one.
*/
update(value: React.ReactNode): StreamableUIWrapper;
/**
* This method is used to append a new UI node to the end of the old one.
* Once appended a new UI node, the previous UI node cannot be updated anymore.
* This function is used to retrieve the UI state based on the AI state.
* For example, to render the initial UI state based on a given AI state, or
* to sync the UI state when the application is already loaded.
*
* If returning `undefined`, the client side UI state will not be updated.
*
* This function must be annotated with the `"use server"` directive.
*
* @example
* ```jsx
* const ui = createStreamableUI(<div>hello</div>)
* ui.append(<div>world</div>)
* ```tsx
* onGetUIState: async () => {
* 'use server';
*
* // The UI node will be:
* // <>
* // <div>hello</div>
* // <div>world</div>
* // </>
* ```
*/
append(value: React.ReactNode): StreamableUIWrapper;
/**
* This method is used to signal that there is an error in the UI stream.
* It will be thrown on the client side and caught by the nearest error boundary component.
*/
error(error: any): StreamableUIWrapper;
/**
* This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
* Once called, the UI node cannot be updated or appended anymore.
* const currentAIState = getAIState();
* const externalAIState = await loadAIStateFromDatabase();
*
* This method is always **required** to be called, otherwise the response will be stuck in a loading state.
*/
done(...args: [React.ReactNode] | []): StreamableUIWrapper;
};
/**
* Create a piece of changeable UI that can be streamed to the client.
* On the client side, it can be rendered as a normal React node.
*/
declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
/**
* Create a wrapped, changeable value that can be streamed to the client.
* On the client side, the value can be accessed via the readStreamableValue() API.
*/
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
type StreamableValueWrapper<T, E> = {
/**
* The value of the streamable. This can be returned from a Server Action and
* received by the client. To read the streamed values, use the
* `readStreamableValue` or `useStreamableValue` APIs.
*/
readonly value: StreamableValue<T, E>;
/**
* This method updates the current value with a new one.
*/
update(value: T): StreamableValueWrapper<T, E>;
/**
* This method is used to append a delta string to the current value. It
* requires the current value of the streamable to be a string.
* if (currentAIState === externalAIState) return undefined;
*
* @example
* ```jsx
* const streamable = createStreamableValue('hello');
* streamable.append(' world');
* // Update current AI state and return the new UI state
* const state = getMutableAIState()
* state.done(externalAIState)
*
* // The value will be 'hello world'
* return <div>...</div>;
* }
* ```
*/
append(value: T): StreamableValueWrapper<T, E>;
/**
* This method is used to signal that there is an error in the value stream.
* It will be thrown on the client side when consumed via
* `readStreamableValue` or `useStreamableValue`.
*/
error(error: any): StreamableValueWrapper<T, E>;
/**
* This method marks the value as finalized. You can either call it without
* any parameters or with a new value as the final state.
* Once called, the value cannot be updated or appended anymore.
*
* This method is always **required** to be called, otherwise the response
* will be stuck in a loading state.
*/
done(...args: [T] | []): StreamableValueWrapper<T, E>;
};
onGetUIState?: OnGetUIState<UIState>;
}): AIProvider<AIState, UIState, Actions>;
type Streamable$1 = ReactNode | Promise<ReactNode>;
type Renderer$1<T> = (props: T) => Streamable$1 | Generator<Streamable$1, Streamable$1, void> | AsyncGenerator<Streamable$1, Streamable$1, void>;
/**
* `render` is a helper function to create a streamable UI from some LLMs.
* This API only supports OpenAI's GPT models with Function Calling and Assistants Tools,
* please use `streamUI` for compatibility with other providers.
*
* @deprecated It's recommended to use the `streamUI` API for compatibility with AI SDK Core APIs
* and future features. This API will be removed in a future release.
*/
declare function render<TS extends {
[name: string]: z.Schema;
} = {}, FS extends {
[name: string]: z.Schema;
} = {}>(options: {
/**
* The model name to use. Must be OpenAI SDK compatible. Tools and Functions are only supported
* GPT models (3.5/4), OpenAI Assistants, Mistral small and large, and Fireworks firefunction-v1.
*
* @example "gpt-3.5-turbo"
*/
model: string;
/**
* The provider instance to use. Currently the only provider available is OpenAI.
* This needs to match the model name.
*/
provider: OpenAI;
messages: Parameters<typeof OpenAI.prototype.chat.completions.create>[0]['messages'];
text?: Renderer$1<{
/**
* The full text content from the model so far.
*/
content: string;
/**
* The new appended text content from the model since the last `text` call.
*/
delta: string;
/**
* Whether the model is done generating text.
* If `true`, the `content` will be the final output and this call will be the last.
*/
done: boolean;
}>;
tools?: {
[name in keyof TS]: {
description?: string;
parameters: TS[name];
render: Renderer$1<z.infer<TS[name]>>;
};
};
functions?: {
[name in keyof FS]: {
description?: string;
parameters: FS[name];
render: Renderer$1<z.infer<FS[name]>>;
};
};
initial?: ReactNode;
temperature?: number;
}): ReactNode;
type CallSettings = {

@@ -493,8 +372,8 @@ /**

type Streamable = ReactNode | Promise<ReactNode>;
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
type Streamable$1 = ReactNode | Promise<ReactNode>;
type Renderer$1<T extends Array<any>> = (...args: T) => Streamable$1 | Generator<Streamable$1, Streamable$1, void> | AsyncGenerator<Streamable$1, Streamable$1, void>;
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
description?: string;
parameters: PARAMETERS;
generate?: Renderer<[
generate?: Renderer$1<[
z.infer<PARAMETERS>,

@@ -507,3 +386,3 @@ {

};
type RenderText = Renderer<[
type RenderText = Renderer$1<[
{

@@ -582,41 +461,164 @@ /**

declare function createAI<AIState = any, UIState = any, Actions extends AIActions = {}>({ actions, initialAIState, initialUIState, onSetAIState, onGetUIState, }: {
actions: Actions;
initialAIState?: AIState;
initialUIState?: UIState;
type Streamable = ReactNode | Promise<ReactNode>;
type Renderer<T> = (props: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
/**
* `render` is a helper function to create a streamable UI from some LLMs.
* This API only supports OpenAI's GPT models with Function Calling and Assistants Tools,
* please use `streamUI` for compatibility with other providers.
*
* @deprecated It's recommended to use the `streamUI` API for compatibility with AI SDK Core APIs
* and future features. This API will be removed in a future release.
*/
declare function render<TS extends {
[name: string]: z.Schema;
} = {}, FS extends {
[name: string]: z.Schema;
} = {}>(options: {
/**
* This function is called whenever the AI state is updated by an Action.
* You can use this to persist the AI state to a database, or to send it to a
* logging service.
* The model name to use. Must be OpenAI SDK compatible. Tools and Functions are only supported
* GPT models (3.5/4), OpenAI Assistants, Mistral small and large, and Fireworks firefunction-v1.
*
* @example "gpt-3.5-turbo"
*/
onSetAIState?: OnSetAIState<AIState>;
model: string;
/**
* This function is used to retrieve the UI state based on the AI state.
* For example, to render the initial UI state based on a given AI state, or
* to sync the UI state when the application is already loaded.
* The provider instance to use. Currently the only provider available is OpenAI.
* This needs to match the model name.
*/
provider: OpenAI;
messages: Parameters<typeof OpenAI.prototype.chat.completions.create>[0]['messages'];
text?: Renderer<{
/**
* The full text content from the model so far.
*/
content: string;
/**
* The new appended text content from the model since the last `text` call.
*/
delta: string;
/**
* Whether the model is done generating text.
* If `true`, the `content` will be the final output and this call will be the last.
*/
done: boolean;
}>;
tools?: {
[name in keyof TS]: {
description?: string;
parameters: TS[name];
render: Renderer<z.infer<TS[name]>>;
};
};
functions?: {
[name in keyof FS]: {
description?: string;
parameters: FS[name];
render: Renderer<z.infer<FS[name]>>;
};
};
initial?: ReactNode;
temperature?: number;
}): ReactNode;
type StreamableUIWrapper = {
/**
* The value of the streamable UI. This can be returned from a Server Action and received by the client.
*/
readonly value: React.ReactNode;
/**
* This method updates the current UI node. It takes a new UI node and replaces the old one.
*/
update(value: React.ReactNode): StreamableUIWrapper;
/**
* This method is used to append a new UI node to the end of the old one.
* Once appended a new UI node, the previous UI node cannot be updated anymore.
*
* If returning `undefined`, the client side UI state will not be updated.
*
* This function must be annotated with the `"use server"` directive.
*
* @example
* ```tsx
* onGetUIState: async () => {
* 'use server';
* ```jsx
* const ui = createStreamableUI(<div>hello</div>)
* ui.append(<div>world</div>)
*
* const currentAIState = getAIState();
* const externalAIState = await loadAIStateFromDatabase();
* // The UI node will be:
* // <>
* // <div>hello</div>
* // <div>world</div>
* // </>
* ```
*/
append(value: React.ReactNode): StreamableUIWrapper;
/**
* This method is used to signal that there is an error in the UI stream.
* It will be thrown on the client side and caught by the nearest error boundary component.
*/
error(error: any): StreamableUIWrapper;
/**
* This method marks the UI node as finalized. You can either call it without any parameters or with a new UI node as the final state.
* Once called, the UI node cannot be updated or appended anymore.
*
* if (currentAIState === externalAIState) return undefined;
* This method is always **required** to be called, otherwise the response will be stuck in a loading state.
*/
done(...args: [React.ReactNode] | []): StreamableUIWrapper;
};
/**
* Create a piece of changeable UI that can be streamed to the client.
* On the client side, it can be rendered as a normal React node.
*/
declare function createStreamableUI(initialValue?: React.ReactNode): StreamableUIWrapper;
declare const __internal_curr: unique symbol;
declare const __internal_error: unique symbol;
/**
* StreamableValue is a value that can be streamed over the network via AI Actions.
* To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs.
*/
type StreamableValue<T = any, E = any> = {
[__internal_curr]?: T;
[__internal_error]?: E;
};
/**
* Create a wrapped, changeable value that can be streamed to the client.
* On the client side, the value can be accessed via the readStreamableValue() API.
*/
declare function createStreamableValue<T = any, E = any>(initialValue?: T | ReadableStream<T>): StreamableValueWrapper<T, E>;
type StreamableValueWrapper<T, E> = {
/**
* The value of the streamable. This can be returned from a Server Action and
* received by the client. To read the streamed values, use the
* `readStreamableValue` or `useStreamableValue` APIs.
*/
readonly value: StreamableValue<T, E>;
/**
* This method updates the current value with a new one.
*/
update(value: T): StreamableValueWrapper<T, E>;
/**
* This method is used to append a delta string to the current value. It
* requires the current value of the streamable to be a string.
*
* // Update current AI state and return the new UI state
* const state = getMutableAIState()
* state.done(externalAIState)
* @example
* ```jsx
* const streamable = createStreamableValue('hello');
* streamable.append(' world');
*
* return <div>...</div>;
* }
* // The value will be 'hello world'
* ```
*/
onGetUIState?: OnGetUIState<UIState>;
}): AIProvider<AIState, UIState, Actions>;
append(value: T): StreamableValueWrapper<T, E>;
/**
* This method is used to signal that there is an error in the value stream.
* It will be thrown on the client side when consumed via
* `readStreamableValue` or `useStreamableValue`.
*/
error(error: any): StreamableValueWrapper<T, E>;
/**
* This method marks the value as finalized. You can either call it without
* any parameters or with a new value as the final state.
* Once called, the value cannot be updated or appended anymore.
*
* This method is always **required** to be called, otherwise the response
* will be stuck in a loading state.
*/
done(...args: [T] | []): StreamableValueWrapper<T, E>;
};

@@ -654,2 +656,3 @@ /**

declare function readStreamableValue<T = unknown>(streamableValue: StreamableValue<T>): AsyncIterable<T | undefined>;
/**

@@ -656,0 +659,0 @@ * `useStreamableValue` is a React hook that takes a streamable value created via the `createStreamableValue().value` API,

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 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 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