Comparing version 2.1.8 to 2.1.9
@@ -62,2 +62,3 @@ "use strict"; | ||
AnthropicStream: () => AnthropicStream, | ||
CohereStream: () => CohereStream, | ||
HuggingFaceStream: () => HuggingFaceStream, | ||
@@ -235,2 +236,26 @@ LangChainStream: () => LangChainStream, | ||
// streams/cohere-stream.ts | ||
function createParser3(res) { | ||
return new ReadableStream({ | ||
pull(controller) { | ||
return __async(this, null, function* () { | ||
const { value, done } = yield res.next(); | ||
if (done) { | ||
controller.close(); | ||
return; | ||
} | ||
const { text, is_finished } = JSON.parse(value); | ||
if (is_finished === true) { | ||
controller.close(); | ||
} else { | ||
controller.enqueue(text); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
function CohereStream(res, callbacks) { | ||
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)); | ||
} | ||
// streams/anthropic-stream.ts | ||
@@ -277,2 +302,3 @@ function parseAnthropicStream() { | ||
AnthropicStream, | ||
CohereStream, | ||
HuggingFaceStream, | ||
@@ -279,0 +305,0 @@ LangChainStream, |
@@ -92,2 +92,4 @@ import { ServerResponse } from 'node:http'; | ||
declare function CohereStream(res: AsyncGenerator<any>, callbacks?: AIStreamCallbacks): ReadableStream; | ||
declare function AnthropicStream(res: Response, cb?: AIStreamCallbacks): ReadableStream; | ||
@@ -107,3 +109,3 @@ | ||
*/ | ||
declare type Message = { | ||
type Message = { | ||
id: string; | ||
@@ -114,3 +116,3 @@ createdAt?: Date; | ||
}; | ||
declare type CreateMessage = { | ||
type CreateMessage = { | ||
id?: string; | ||
@@ -121,7 +123,7 @@ createdAt?: Date; | ||
}; | ||
declare type RequestOptions = { | ||
type RequestOptions = { | ||
headers?: Record<string, string> | Headers; | ||
body?: object; | ||
}; | ||
declare type UseChatOptions = { | ||
type UseChatOptions = { | ||
/** | ||
@@ -182,3 +184,3 @@ * The API endpoint that accepts a `{ messages: Message[] }` object and returns | ||
}; | ||
declare type UseCompletionOptions = { | ||
type UseCompletionOptions = { | ||
/** | ||
@@ -234,2 +236,2 @@ * The API endpoint that accepts a `{ prompt: string }` object and returns | ||
export { AIStream, AIStreamCallbacks, AIStreamParser, AnthropicStream, CreateMessage, HuggingFaceStream, LangChainStream, Message, OpenAIStream, RequestOptions, StreamingTextResponse, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createEventStreamTransformer, streamToResponse, trimStartOfStreamHelper }; | ||
export { AIStream, AIStreamCallbacks, AIStreamParser, AnthropicStream, CohereStream, CreateMessage, HuggingFaceStream, LangChainStream, Message, OpenAIStream, RequestOptions, StreamingTextResponse, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createEventStreamTransformer, streamToResponse, trimStartOfStreamHelper }; |
@@ -62,2 +62,3 @@ "use strict"; | ||
AnthropicStream: () => AnthropicStream, | ||
CohereStream: () => CohereStream, | ||
HuggingFaceStream: () => HuggingFaceStream, | ||
@@ -235,2 +236,26 @@ LangChainStream: () => LangChainStream, | ||
// streams/cohere-stream.ts | ||
function createParser3(res) { | ||
return new ReadableStream({ | ||
pull(controller) { | ||
return __async(this, null, function* () { | ||
const { value, done } = yield res.next(); | ||
if (done) { | ||
controller.close(); | ||
return; | ||
} | ||
const { text, is_finished } = JSON.parse(value); | ||
if (is_finished === true) { | ||
controller.close(); | ||
} else { | ||
controller.enqueue(text); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
function CohereStream(res, callbacks) { | ||
return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)); | ||
} | ||
// streams/anthropic-stream.ts | ||
@@ -277,2 +302,3 @@ function parseAnthropicStream() { | ||
AnthropicStream, | ||
CohereStream, | ||
HuggingFaceStream, | ||
@@ -279,0 +305,0 @@ LangChainStream, |
{ | ||
"name": "ai", | ||
"version": "2.1.8", | ||
"version": "2.1.9", | ||
"license": "Apache-2.0", | ||
@@ -57,3 +57,3 @@ "sideEffects": false, | ||
"@types/node": "^17.0.12", | ||
"@types/react": "^18.2.0", | ||
"@types/react": "^18.2.8", | ||
"@types/react-dom": "^18.2.0", | ||
@@ -64,3 +64,3 @@ "eslint": "^7.32.0", | ||
"tsup": "^6.7.0", | ||
"typescript": "^4.5.3", | ||
"typescript": "5.1.3", | ||
"@vercel/ai-tsconfig": "0.0.0", | ||
@@ -70,3 +70,3 @@ "eslint-config-vercel-ai": "0.0.0" | ||
"peerDependencies": { | ||
"react": "^18.0.0", | ||
"react": "^18.2.0", | ||
"svelte": "^3.29.0", | ||
@@ -73,0 +73,0 @@ "vue": "^3.3.4" |
@@ -0,5 +1,7 @@ | ||
import * as react_jsx_runtime from 'react/jsx-runtime'; | ||
/** | ||
* Shared types between the API and UI packages. | ||
*/ | ||
declare type Message = { | ||
type Message = { | ||
id: string; | ||
@@ -10,3 +12,3 @@ createdAt?: Date; | ||
}; | ||
declare type CreateMessage = { | ||
type CreateMessage = { | ||
id?: string; | ||
@@ -17,7 +19,7 @@ createdAt?: Date; | ||
}; | ||
declare type RequestOptions = { | ||
type RequestOptions = { | ||
headers?: Record<string, string> | Headers; | ||
body?: object; | ||
}; | ||
declare type UseChatOptions = { | ||
type UseChatOptions = { | ||
/** | ||
@@ -78,3 +80,3 @@ * The API endpoint that accepts a `{ messages: Message[] }` object and returns | ||
}; | ||
declare type UseCompletionOptions = { | ||
type UseCompletionOptions = { | ||
/** | ||
@@ -130,3 +132,3 @@ * The API endpoint that accepts a `{ prompt: string }` object and returns | ||
declare type UseChatHelpers = { | ||
type UseChatHelpers = { | ||
/** Current messages in the chat */ | ||
@@ -172,3 +174,3 @@ messages: Message[]; | ||
declare type UseCompletionHelpers = { | ||
type UseCompletionHelpers = { | ||
/** The current completion result */ | ||
@@ -217,2 +219,13 @@ completion: string; | ||
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion }; | ||
type Props = { | ||
/** | ||
* A ReadableStream produced by the AI SDK. | ||
*/ | ||
stream: ReadableStream; | ||
}; | ||
/** | ||
* A React Server Component that recursively renders a stream of tokens. | ||
*/ | ||
declare function Tokens(props: Props): Promise<react_jsx_runtime.JSX.Element>; | ||
export { CreateMessage, Message, Tokens, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion }; |
@@ -68,2 +68,3 @@ 'use client' | ||
__export(react_exports, { | ||
Tokens: () => Tokens, | ||
useChat: () => useChat, | ||
@@ -448,6 +449,31 @@ useCompletion: () => useCompletion | ||
} | ||
// react/tokens.tsx | ||
var import_react3 = require("react"); | ||
var import_jsx_runtime = require("react/jsx-runtime"); | ||
function Tokens(props) { | ||
return __async(this, null, function* () { | ||
const { stream } = props; | ||
const reader = stream.getReader(); | ||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) }); | ||
}); | ||
} | ||
function RecursiveTokens(_0) { | ||
return __async(this, arguments, function* ({ reader }) { | ||
const { done, value } = yield reader.read(); | ||
if (done) { | ||
return null; | ||
} | ||
const text = new TextDecoder().decode(value); | ||
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ | ||
text, | ||
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react3.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) }) | ||
] }); | ||
}); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Tokens, | ||
useChat, | ||
useCompletion | ||
}); |
@@ -6,3 +6,3 @@ import { Readable, Writable } from 'svelte/store'; | ||
*/ | ||
declare type Message = { | ||
type Message = { | ||
id: string; | ||
@@ -13,3 +13,3 @@ createdAt?: Date; | ||
}; | ||
declare type CreateMessage = { | ||
type CreateMessage = { | ||
id?: string; | ||
@@ -20,7 +20,7 @@ createdAt?: Date; | ||
}; | ||
declare type RequestOptions = { | ||
type RequestOptions = { | ||
headers?: Record<string, string> | Headers; | ||
body?: object; | ||
}; | ||
declare type UseChatOptions = { | ||
type UseChatOptions = { | ||
/** | ||
@@ -81,3 +81,3 @@ * The API endpoint that accepts a `{ messages: Message[] }` object and returns | ||
}; | ||
declare type UseCompletionOptions = { | ||
type UseCompletionOptions = { | ||
/** | ||
@@ -133,3 +133,3 @@ * The API endpoint that accepts a `{ prompt: string }` object and returns | ||
declare type UseChatHelpers = { | ||
type UseChatHelpers = { | ||
/** Current messages in the chat */ | ||
@@ -169,3 +169,3 @@ messages: Readable<Message[]>; | ||
declare type UseCompletionHelpers = { | ||
type UseCompletionHelpers = { | ||
/** The current completion result */ | ||
@@ -172,0 +172,0 @@ completion: Readable<string>; |
@@ -6,3 +6,3 @@ import { Ref } from 'vue'; | ||
*/ | ||
declare type Message = { | ||
type Message = { | ||
id: string; | ||
@@ -13,3 +13,3 @@ createdAt?: Date; | ||
}; | ||
declare type CreateMessage = { | ||
type CreateMessage = { | ||
id?: string; | ||
@@ -20,7 +20,7 @@ createdAt?: Date; | ||
}; | ||
declare type RequestOptions = { | ||
type RequestOptions = { | ||
headers?: Record<string, string> | Headers; | ||
body?: object; | ||
}; | ||
declare type UseChatOptions = { | ||
type UseChatOptions = { | ||
/** | ||
@@ -81,3 +81,3 @@ * The API endpoint that accepts a `{ messages: Message[] }` object and returns | ||
}; | ||
declare type UseCompletionOptions = { | ||
type UseCompletionOptions = { | ||
/** | ||
@@ -133,3 +133,3 @@ * The API endpoint that accepts a `{ prompt: string }` object and returns | ||
declare type UseChatHelpers = { | ||
type UseChatHelpers = { | ||
/** Current messages in the chat */ | ||
@@ -169,3 +169,3 @@ messages: Ref<Message[]>; | ||
declare type UseCompletionHelpers = { | ||
type UseCompletionHelpers = { | ||
/** The current completion result */ | ||
@@ -172,0 +172,0 @@ completion: Ref<string>; |
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
155272
4938