@ai-sdk/svelte
Advanced tools
Comparing version 0.0.10 to 0.0.11
# @ai-sdk/svelte | ||
## 0.0.11 | ||
### Patch Changes | ||
- d3100b9c: feat (ai/ui): support custom fetch function in useChat, useCompletion, useAssistant, useObject | ||
- Updated dependencies [d3100b9c] | ||
- @ai-sdk/ui-utils@0.0.8 | ||
## 0.0.10 | ||
@@ -4,0 +12,0 @@ |
@@ -45,3 +45,3 @@ import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils'; | ||
}; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: UseChatOptions): UseChatHelpers; | ||
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, fetch, }?: UseChatOptions): UseChatHelpers; | ||
@@ -84,3 +84,3 @@ type UseCompletionHelpers = { | ||
}; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers; | ||
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, fetch, }?: UseCompletionOptions): UseCompletionHelpers; | ||
@@ -134,4 +134,4 @@ type UseAssistantHelpers = { | ||
}; | ||
declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers; | ||
declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, fetch, }: UseAssistantOptions): UseAssistantHelpers; | ||
export { UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, useAssistant, useChat, useCompletion }; |
@@ -33,3 +33,3 @@ "use strict"; | ||
var import_store = require("svelte/store"); | ||
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadata, previousMessages, abortControllerRef, generateId2, streamMode, onFinish, onResponse, sendExtraMessageFields) => { | ||
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadata, previousMessages, abortControllerRef, generateId2, streamMode, onFinish, onResponse, sendExtraMessageFields, fetch2) => { | ||
var _a, _b; | ||
@@ -61,3 +61,2 @@ mutate(chatRequest.messages); | ||
api, | ||
messages: constructedMessagesPayload, | ||
body: { | ||
@@ -97,3 +96,6 @@ messages: constructedMessagesPayload, | ||
onFinish, | ||
generateId: generateId2 | ||
generateId: generateId2, | ||
onToolCall: void 0, | ||
// not implemented yet | ||
fetch: fetch2 | ||
}); | ||
@@ -118,3 +120,4 @@ }; | ||
body, | ||
generateId: generateId2 = import_ui_utils.generateId | ||
generateId: generateId2 = import_ui_utils.generateId, | ||
fetch: fetch2 | ||
} = {}) { | ||
@@ -167,3 +170,4 @@ const chatId = id || `chat-${uniqueId++}`; | ||
onResponse, | ||
sendExtraMessageFields | ||
sendExtraMessageFields, | ||
fetch2 | ||
), | ||
@@ -309,3 +313,4 @@ experimental_onFunctionCall, | ||
onFinish, | ||
onError | ||
onError, | ||
fetch: fetch2 | ||
} = {}) { | ||
@@ -358,3 +363,4 @@ const completionId = id || `completion-${uniqueId2++}`; | ||
streamData.set([...existingData || [], ...data2 || []]); | ||
} | ||
}, | ||
fetch: fetch2 | ||
}); | ||
@@ -401,2 +407,3 @@ }; | ||
var import_store3 = require("svelte/store"); | ||
var getOriginalFetch = () => fetch; | ||
var uniqueId3 = 0; | ||
@@ -410,3 +417,4 @@ var store3 = {}; | ||
body, | ||
onError | ||
onError, | ||
fetch: fetch2 | ||
}) { | ||
@@ -434,3 +442,4 @@ const threadIdStore = (0, import_store3.writable)(threadIdParam); | ||
try { | ||
const response = await fetch(api, { | ||
const actualFetch = fetch2 != null ? fetch2 : getOriginalFetch(); | ||
const response = await actualFetch(api, { | ||
method: "POST", | ||
@@ -437,0 +446,0 @@ credentials, |
{ | ||
"name": "@ai-sdk/svelte", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"license": "Apache-2.0", | ||
@@ -19,3 +19,3 @@ "sideEffects": false, | ||
"@ai-sdk/provider-utils": "1.0.0", | ||
"@ai-sdk/ui-utils": "0.0.7", | ||
"@ai-sdk/ui-utils": "0.0.8", | ||
"sswr": "2.1.0" | ||
@@ -22,0 +22,0 @@ }, |
@@ -11,2 +11,5 @@ import { isAbortError } from '@ai-sdk/provider-utils'; | ||
// use function to allow for mocking in tests: | ||
const getOriginalFetch = () => fetch; | ||
let uniqueId = 0; | ||
@@ -79,2 +82,3 @@ | ||
onError, | ||
fetch, | ||
}: UseAssistantOptions): UseAssistantHelpers { | ||
@@ -117,3 +121,4 @@ // Generate a unique thread ID | ||
try { | ||
const response = await fetch(api, { | ||
const actualFetch = fetch ?? getOriginalFetch(); | ||
const response = await actualFetch(api, { | ||
method: 'POST', | ||
@@ -120,0 +125,0 @@ credentials, |
@@ -5,2 +5,3 @@ import type { | ||
CreateMessage, | ||
FetchFunction, | ||
IdGenerator, | ||
@@ -81,6 +82,7 @@ JSONValue, | ||
generateId: IdGenerator, | ||
streamMode?: 'stream-data' | 'text', | ||
onFinish?: (message: Message) => void, | ||
onResponse?: (response: Response) => void | Promise<void>, | ||
sendExtraMessageFields?: boolean, | ||
streamMode: 'stream-data' | 'text' | undefined, | ||
onFinish: ((message: Message) => void) | undefined, | ||
onResponse: ((response: Response) => void | Promise<void>) | undefined, | ||
sendExtraMessageFields: boolean | undefined, | ||
fetch: FetchFunction | undefined, | ||
) => { | ||
@@ -118,3 +120,2 @@ // Do an optimistic update to the chat state to show the updated messages | ||
api, | ||
messages: constructedMessagesPayload, | ||
body: { | ||
@@ -155,2 +156,4 @@ messages: constructedMessagesPayload, | ||
generateId, | ||
onToolCall: undefined, // not implemented yet | ||
fetch, | ||
}); | ||
@@ -179,2 +182,3 @@ }; | ||
generateId = generateIdFunc, | ||
fetch, | ||
}: UseChatOptions = {}): UseChatHelpers { | ||
@@ -246,2 +250,3 @@ // Generate a unique id for the chat if not provided. | ||
sendExtraMessageFields, | ||
fetch, | ||
), | ||
@@ -248,0 +253,0 @@ experimental_onFunctionCall, |
@@ -67,2 +67,3 @@ import type { | ||
onError, | ||
fetch, | ||
}: UseCompletionOptions = {}): UseCompletionHelpers { | ||
@@ -131,2 +132,3 @@ // Generate an unique id for the completion if not provided. | ||
}, | ||
fetch, | ||
}); | ||
@@ -133,0 +135,0 @@ }; |
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
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
133278
1985
62
11
16
6
62
+ Added@ai-sdk/ui-utils@0.0.8(transitive)
- Removed@ai-sdk/ui-utils@0.0.7(transitive)
Updated@ai-sdk/ui-utils@0.0.8