@axflow/models
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -56,2 +56,13 @@ import { MessageType, JSONValueType } from '@axflow/models/shared'; | ||
onError?: (error: Error) => void; | ||
/** | ||
* Callback that is invoked when the list of messages change. | ||
* | ||
* Specifically, it is invoked when: | ||
* | ||
* 1. `onSubmit` is invoked and a new user message is added. | ||
* 2. A new message is received from the server. If streaming, this will | ||
* be called each time the message is updated from a streaming event. | ||
* 3. Any time a client of the hook calls `setMessages` | ||
*/ | ||
onMessagesChange?: (updatedMessages: MessageType[]) => void; | ||
}; | ||
@@ -58,0 +69,0 @@ /** |
@@ -124,10 +124,20 @@ "use strict"; | ||
}; | ||
var DEFAULT_ON_MESSAGES_CHANGE = (_messages) => { | ||
}; | ||
function useChat(options) { | ||
options ??= {}; | ||
const [input, setInput] = (0, import_react.useState)(options.initialInput ?? ""); | ||
const [messages, _setMessages] = (0, import_react.useState)(options.initialMessages ?? []); | ||
const initialInput = options.initialInput ?? ""; | ||
const [input, setInput] = (0, import_react.useState)(initialInput); | ||
const initialMessages = options.initialMessages ?? []; | ||
const [messages, _setMessages] = (0, import_react.useState)(initialMessages); | ||
const messagesRef = (0, import_react.useRef)(initialMessages); | ||
const [loading, _setLoading] = (0, import_react.useState)(false); | ||
const loadingRef = (0, import_react.useRef)(false); | ||
const [error, setError] = (0, import_react.useState)(null); | ||
const loadingRef = (0, import_react.useRef)(false); | ||
const messagesRef = (0, import_react.useRef)([]); | ||
const url = options.url ?? DEFAULT_URL; | ||
const accessor = options.accessor ?? DEFAULT_ACCESSOR; | ||
const body = options.body ?? DEFAULT_BODY; | ||
const headers = options.headers ?? DEFAULT_HEADERS; | ||
const onError = options.onError ?? DEFAULT_ON_ERROR; | ||
const onMessagesChange = options.onMessagesChange ?? DEFAULT_ON_MESSAGES_CHANGE; | ||
const setMessages = (0, import_react.useCallback)( | ||
@@ -137,4 +147,5 @@ (messages2) => { | ||
messagesRef.current = messages2; | ||
onMessagesChange(messages2); | ||
}, | ||
[messagesRef, _setMessages] | ||
[messagesRef, _setMessages, onMessagesChange] | ||
); | ||
@@ -148,7 +159,2 @@ const setLoading = (0, import_react.useCallback)( | ||
); | ||
const url = options.url ?? DEFAULT_URL; | ||
const accessor = options.accessor ?? DEFAULT_ACCESSOR; | ||
const body = options.body ?? DEFAULT_BODY; | ||
const headers = options.headers ?? DEFAULT_HEADERS; | ||
const onError = options.onError ?? DEFAULT_ON_ERROR; | ||
function append(message) { | ||
@@ -155,0 +161,0 @@ stableAppend( |
{ | ||
"name": "@axflow/models", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Zero-dependency, modular SDK for building robust natural language applications", | ||
@@ -199,3 +199,3 @@ "author": "Axflow (https://axflow.dev)", | ||
}, | ||
"gitHead": "8b514a72b14adbc11b81b26b9d4bfd2735afb07a" | ||
"gitHead": "4305adbfd2e4ef5c4158d07326626e8c871b0b72" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
221022
4170