@ai-sdk/vue 4.0.122 → 4.0.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/index.d.ts +113 -109
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +423 -523
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/use-object.ts","../src/use-completion.ts","../src/chat.vue.ts","../src/use-chat.ts","../src/index.ts"],"sourcesContent":["import {\n isAbortError,\n safeValidateTypes,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n asSchema,\n isDeepEqualData,\n parsePartialJson,\n type DeepPartial,\n type FlexibleSchema,\n type InferSchema,\n} from 'ai';\nimport type * as SwrvModule from 'swrv';\nimport swrv from 'swrv';\nimport { ref, type Ref } from 'vue';\n// use function to allow for mocking in tests\nconst getOriginalFetch = () => fetch;\n\nexport type UseObjectOptions<SCHEMA extends FlexibleSchema, RESULT> = {\n /** API endpoint that streams JSON chunks matching the schema */\n api: string;\n\n /** Schema that defines the final object shape */\n schema: SCHEMA;\n\n /** Shared state key. If omitted a random one is generated */\n id?: string;\n\n /** Initial partial value */\n initialValue?: DeepPartial<RESULT>;\n\n /** Optional custom fetch implementation */\n fetch?: FetchFunction;\n\n /** Called when stream ends */\n onFinish?: (event: {\n object: RESULT | undefined;\n error: Error | undefined;\n }) => Promise<void> | void;\n\n /** Called on error */\n onError?: (error: Error) => void;\n\n /** Extra request headers */\n headers?: Record<string, string> | Headers;\n\n /** Request credentials mode. Defaults to 'same-origin' if omitted */\n credentials?: RequestCredentials;\n};\n\nexport type UseObjectHelpers<RESULT, INPUT> = {\n /** POST the input and start streaming */\n submit: (input: INPUT) => void;\n\n /** Current partial object, updated as chunks arrive */\n object: Ref<DeepPartial<RESULT> | undefined>;\n\n /** Latest error if any */\n error: Ref<Error | undefined>;\n\n /** Loading flag for the in-flight request */\n isLoading: Ref<boolean | undefined>;\n\n /** Abort the current request. Keeps current partial object. */\n stop: () => void;\n\n /** Abort and clear all state */\n clear: () => void;\n};\n\nlet uniqueId = 0;\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof SwrvModule)['default']) || swrv;\nconst store: Record<string, any> = {};\n\nexport function useObject<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n INPUT = any,\n>({\n api,\n id,\n schema,\n initialValue,\n fetch,\n onError,\n onFinish,\n headers,\n credentials,\n}: UseObjectOptions<SCHEMA, RESULT>): UseObjectHelpers<RESULT, INPUT> {\n // Generate an unique id for the object if not provided.\n const completionId = id || `completion-${uniqueId++}`;\n\n const key = `${api}|${completionId}`;\n const { data, mutate: originalMutate } = useSWRV<\n DeepPartial<RESULT> | undefined\n >(key, () => (key in store ? store[key] : initialValue));\n\n const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(\n `${completionId}-loading`,\n null,\n );\n\n isLoading.value ??= false;\n data.value ||= initialValue as DeepPartial<RESULT> | undefined;\n\n const mutateObject = (value: DeepPartial<RESULT> | undefined) => {\n store[key] = value;\n return originalMutate();\n };\n\n const error = ref<Error | undefined>(undefined);\n let abortController: AbortController | null = null;\n\n const stop = async () => {\n if (abortController) {\n try {\n abortController.abort();\n } catch {\n // ignore\n } finally {\n abortController = null;\n }\n }\n await mutateLoading(() => false);\n };\n\n const clearObject = async () => {\n error.value = undefined;\n await mutateLoading(() => false);\n await mutateObject(undefined);\n // Need to explicitly set the value to undefined to trigger a re-render\n data.value = undefined;\n };\n\n const clear = async () => {\n await stop();\n await clearObject();\n };\n\n const submit = async (input: INPUT) => {\n try {\n await clearObject();\n await mutateLoading(() => true);\n\n abortController = new AbortController();\n\n const actualFetch = fetch ?? getOriginalFetch();\n const response = await actualFetch(api, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...(headers as any),\n },\n credentials: credentials ?? 'same-origin',\n signal: abortController.signal,\n body: JSON.stringify(input),\n });\n\n if (!response.ok) {\n throw new Error(\n (await response.text()) || 'Failed to fetch the response.',\n );\n }\n\n if (!response.body) {\n throw new Error('The response body is empty.');\n }\n\n let accumulatedText = '';\n let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n new WritableStream<string>({\n async write(chunk) {\n accumulatedText += chunk;\n const { value } = await parsePartialJson(accumulatedText);\n const currentObject = value as DeepPartial<RESULT>;\n if (!isDeepEqualData(latestObject, currentObject)) {\n latestObject = currentObject;\n await mutateObject(currentObject);\n }\n },\n async close() {\n await mutateLoading(() => false);\n abortController = null;\n\n if (onFinish) {\n const validationResult = await safeValidateTypes({\n value: latestObject,\n schema: asSchema(schema),\n });\n\n onFinish(\n validationResult.success\n ? {\n object: validationResult.value as RESULT,\n error: undefined,\n }\n : { object: undefined, error: validationResult.error },\n );\n }\n },\n }),\n );\n } catch (err: unknown) {\n if (isAbortError(err)) return;\n\n if (onError && err instanceof Error) onError(err);\n\n await mutateLoading(() => false);\n error.value = err instanceof Error ? err : new Error(String(err));\n }\n };\n\n return {\n submit,\n object: data,\n error,\n isLoading,\n stop,\n clear,\n };\n}\n","import {\n callCompletionApi,\n type CompletionRequestOptions,\n type UseCompletionOptions,\n} from 'ai';\nimport type * as SwrvModule from 'swrv';\nimport swrv from 'swrv';\nimport { ref, unref, type Ref } from 'vue';\nexport type { UseCompletionOptions };\n\nexport type UseCompletionHelpers<BODY extends object = object> = {\n /** The current completion result */\n completion: Ref<string>;\n /** The error object of the API request */\n error: Ref<undefined | Error>;\n /**\n * Send a new prompt to the API endpoint and update the completion state.\n */\n complete: (\n prompt: string,\n options?: CompletionRequestOptions<BODY>,\n ) => Promise<string | null | undefined>;\n /**\n * Abort the current API request but keep the generated tokens.\n */\n stop: () => void;\n /**\n * Update the `completion` state locally.\n */\n setCompletion: (completion: string) => void;\n /** The current value of the input */\n input: Ref<string>;\n /**\n * Form submission handler to automatically reset input and append a user message\n * @example\n * ```jsx\n * <form @submit=\"handleSubmit\">\n * <input @change=\"handleInputChange\" v-model=\"input\" />\n * </form>\n * ```\n */\n handleSubmit: (event?: { preventDefault?: () => void }) => void;\n /** Whether the API request is in progress */\n isLoading: Ref<boolean | undefined>;\n};\n\nlet uniqueId = 0;\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof SwrvModule)['default']) || swrv;\nconst store: Record<string, any> = {};\n\nexport function useCompletion<BODY extends object = object>({\n api = '/api/completion',\n id,\n initialCompletion = '',\n initialInput = '',\n credentials,\n headers,\n body,\n streamProtocol,\n onFinish,\n onError,\n fetch,\n}: UseCompletionOptions<NoInfer<BODY>> = {}): UseCompletionHelpers<BODY> {\n // Generate an unique id for the completion if not provided.\n const completionId = id || `completion-${uniqueId++}`;\n\n const key = `${api}|${completionId}`;\n const { data, mutate: originalMutate } = useSWRV<string>(\n key,\n () => store[key] ?? initialCompletion,\n );\n\n const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(\n `${completionId}-loading`,\n null,\n );\n\n isLoading.value ??= false;\n\n // Force the `data` to be `initialCompletion` if it's `undefined`.\n data.value ??= initialCompletion;\n\n const mutate = (data: string) => {\n store[key] = data;\n return originalMutate();\n };\n\n // Because of the `initialData` option, the `data` will never be `undefined`.\n const completion = data as Ref<string>;\n\n const error = ref<undefined | Error>(undefined);\n\n let abortController: AbortController | null = null;\n\n async function triggerRequest(\n prompt: string,\n options?: CompletionRequestOptions<BODY>,\n ) {\n return callCompletionApi({\n api,\n prompt,\n credentials,\n headers: {\n ...headers,\n ...options?.headers,\n },\n body: {\n ...unref(body),\n ...options?.body,\n },\n streamProtocol,\n setCompletion: mutate,\n setLoading: loading => mutateLoading(() => loading),\n setError: err => {\n error.value = err;\n },\n setAbortController: controller => {\n abortController = controller;\n },\n getAbortController: () => abortController,\n onFinish,\n onError,\n fetch,\n });\n }\n\n const complete: UseCompletionHelpers<BODY>['complete'] = async (\n prompt,\n options,\n ) => {\n return triggerRequest(prompt, options);\n };\n\n const stop = () => {\n if (abortController) {\n abortController.abort();\n }\n };\n\n const setCompletion = (completion: string) => {\n mutate(completion);\n };\n\n const input = ref(initialInput);\n\n const handleSubmit = (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n const inputValue = input.value;\n return inputValue ? complete(inputValue) : undefined;\n };\n\n return {\n completion,\n complete,\n error,\n stop,\n setCompletion,\n input,\n handleSubmit,\n isLoading,\n };\n}\n","import {\n AbstractChat,\n type ChatInit,\n type ChatState,\n type ChatStatus,\n type UIMessage,\n} from 'ai';\nimport { ref, type Ref } from 'vue';\nclass VueChatState<\n UI_MESSAGE extends UIMessage,\n> implements ChatState<UI_MESSAGE> {\n private messagesRef: Ref<UI_MESSAGE[]>;\n private statusRef = ref<ChatStatus>('ready');\n private errorRef = ref<Error | undefined>(undefined);\n\n constructor(messages?: UI_MESSAGE[]) {\n this.messagesRef = ref(messages ?? []) as Ref<UI_MESSAGE[]>;\n }\n\n get messages(): UI_MESSAGE[] {\n return this.messagesRef.value;\n }\n\n set messages(messages: UI_MESSAGE[]) {\n this.messagesRef.value = messages;\n }\n\n get status(): ChatStatus {\n return this.statusRef.value;\n }\n\n set status(status: ChatStatus) {\n this.statusRef.value = status;\n }\n\n get error(): Error | undefined {\n return this.errorRef.value;\n }\n\n set error(error: Error | undefined) {\n this.errorRef.value = error;\n }\n\n pushMessage = (message: UI_MESSAGE) => {\n this.messagesRef.value = [...this.messagesRef.value, message];\n };\n\n popMessage = () => {\n this.messagesRef.value = this.messagesRef.value.slice(0, -1);\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n // message is cloned here because vue's deep reactivity shows unexpected behavior, particularly when updating tool invocation parts\n this.messagesRef.value[index] = { ...message };\n };\n\n snapshot = <T>(value: T): T => value;\n}\n\n/**\n * @deprecated Use the {@link useChat} composable instead. It exposes reactive\n * refs and automatically recreates the chat when its init object changes.\n */\nexport class Chat<\n UI_MESSAGE extends UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor({ messages, ...init }: ChatInit<UI_MESSAGE>) {\n super({\n ...init,\n state: new VueChatState(messages),\n });\n }\n}\n","import {\n AbstractChat,\n type ChatInit as BaseChatInit,\n type ChatInit,\n type ChatState,\n type ChatStatus,\n type UIMessage,\n} from 'ai';\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowRef,\n toValue,\n watch,\n type ComputedRef,\n type MaybeRefOrGetter,\n type ShallowRef,\n} from 'vue';\n\nfunction cloneMetadata<METADATA>(metadata: METADATA): METADATA {\n if (Array.isArray(metadata)) {\n return [...metadata] as METADATA;\n }\n\n if (\n metadata != null &&\n typeof metadata === 'object' &&\n (Object.getPrototypeOf(metadata) === Object.prototype ||\n Object.getPrototypeOf(metadata) === null)\n ) {\n return { ...metadata } as METADATA;\n }\n\n return metadata;\n}\n\nfunction snapshotValue<T>(value: T): T {\n if (\n value == null ||\n typeof value !== 'object' ||\n !('parts' in value) ||\n !Array.isArray(value.parts)\n ) {\n return value;\n }\n\n const message = value as unknown as UIMessage;\n const snapshot = {\n ...message,\n parts: message.parts.map(part => ({ ...part })),\n };\n\n if ('metadata' in message) {\n snapshot.metadata = cloneMetadata(message.metadata);\n }\n\n return snapshot as T;\n}\n\nclass VueChatState<\n UI_MESSAGE extends UIMessage,\n> implements ChatState<UI_MESSAGE> {\n private messagesValue: UI_MESSAGE[];\n private publishedMessages: UI_MESSAGE[] = [];\n private publishedMessageSources: UI_MESSAGE[] = [];\n private readonly dirtyMessageIndices = new Set<number>();\n private statusValue: ChatStatus = 'ready';\n private errorValue: Error | undefined;\n private readonly throttleWaitMs: number | undefined;\n private timeout: ReturnType<typeof setTimeout> | undefined;\n private hasPendingPublication = false;\n private isActive = true;\n\n isPublishing = false;\n\n constructor({\n initialMessages,\n messagesRef,\n statusRef,\n errorRef,\n throttleWaitMs,\n }: {\n initialMessages: UI_MESSAGE[];\n messagesRef: ShallowRef<UI_MESSAGE[]>;\n statusRef: ShallowRef<ChatStatus>;\n errorRef: ShallowRef<Error | undefined>;\n throttleWaitMs?: number;\n }) {\n this.messagesValue = initialMessages;\n this.messagesRef = messagesRef;\n this.statusRef = statusRef;\n this.errorRef = errorRef;\n this.throttleWaitMs =\n throttleWaitMs != null &&\n Number.isFinite(throttleWaitMs) &&\n throttleWaitMs > 0\n ? throttleWaitMs\n : undefined;\n }\n\n private readonly messagesRef: ShallowRef<UI_MESSAGE[]>;\n private readonly statusRef: ShallowRef<ChatStatus>;\n private readonly errorRef: ShallowRef<Error | undefined>;\n\n get messages(): UI_MESSAGE[] {\n return this.messagesValue;\n }\n\n set messages(messages: UI_MESSAGE[]) {\n const previousMessages = this.messagesValue;\n this.messagesValue = messages;\n\n for (let index = 0; index < messages.length; index++) {\n if (messages[index] !== previousMessages[index]) {\n this.dirtyMessageIndices.add(index);\n }\n }\n\n this.schedulePublication();\n }\n\n get status(): ChatStatus {\n return this.statusValue;\n }\n\n set status(status: ChatStatus) {\n this.statusValue = status;\n\n if (!this.isActive) {\n return;\n }\n\n if (status === 'ready' || status === 'error') {\n // Terminal states must never become observable before the final message.\n this.flushPublication();\n }\n\n this.statusRef.value = status;\n }\n\n get error(): Error | undefined {\n return this.errorValue;\n }\n\n set error(error: Error | undefined) {\n this.errorValue = error;\n\n if (this.isActive) {\n this.errorRef.value = error;\n }\n }\n\n pushMessage = (message: UI_MESSAGE) => {\n this.messagesValue.push(message);\n this.dirtyMessageIndices.add(this.messagesValue.length - 1);\n this.schedulePublication();\n };\n\n popMessage = () => {\n this.messagesValue.pop();\n this.schedulePublication();\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n this.messagesValue[index] = message;\n this.dirtyMessageIndices.add(index);\n this.schedulePublication();\n };\n\n snapshot = snapshotValue;\n\n publishInitialState() {\n this.publishMessages();\n this.statusRef.value = this.statusValue;\n this.errorRef.value = this.errorValue;\n }\n\n setMessagesFromConsumer(messages: UI_MESSAGE[]) {\n this.messagesValue = messages;\n this.publishedMessages = messages;\n this.publishedMessageSources = messages;\n this.dirtyMessageIndices.clear();\n }\n\n dispose() {\n this.isActive = false;\n this.hasPendingPublication = false;\n this.dirtyMessageIndices.clear();\n this.publishedMessages = [];\n this.publishedMessageSources = [];\n\n if (this.timeout != null) {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n }\n }\n\n private schedulePublication() {\n if (!this.isActive) {\n return;\n }\n\n if (this.throttleWaitMs == null) {\n this.publishMessages();\n return;\n }\n\n if (this.timeout == null) {\n // Publish the leading update immediately, then coalesce updates until\n // the next interval boundary.\n this.publishMessages();\n this.timeout = setTimeout(this.handleIntervalEnd, this.throttleWaitMs);\n } else {\n this.hasPendingPublication = true;\n }\n }\n\n private readonly handleIntervalEnd = () => {\n this.timeout = undefined;\n\n if (!this.isActive || !this.hasPendingPublication) {\n return;\n }\n\n this.hasPendingPublication = false;\n this.publishMessages();\n this.timeout = setTimeout(this.handleIntervalEnd, this.throttleWaitMs);\n };\n\n private flushPublication() {\n if (this.timeout != null) {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n }\n\n this.hasPendingPublication = false;\n this.publishMessages();\n }\n\n private publishMessages() {\n if (!this.isActive) {\n return;\n }\n\n const publishedMessages = this.messagesValue.map((message, index) =>\n this.dirtyMessageIndices.has(index) ||\n this.publishedMessageSources[index] !== message\n ? snapshotValue(message)\n : this.publishedMessages[index],\n );\n\n this.publishedMessages = publishedMessages;\n this.publishedMessageSources = [...this.messagesValue];\n this.dirtyMessageIndices.clear();\n\n this.isPublishing = true;\n try {\n this.messagesRef.value = publishedMessages;\n } finally {\n this.isPublishing = false;\n }\n }\n}\n\n/**\n * @internal\n */\nexport class VueChat<\n UI_MESSAGE extends UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor({\n state,\n ...init\n }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {\n state: ChatState<UI_MESSAGE>;\n }) {\n super({\n ...init,\n state,\n });\n }\n}\n\n/**\n * Return type of the {@link useChat} composable, which includes the chat\n * instance methods and reactive properties for messages, status, and error.\n */\nexport interface UseChatHelpers<UI_MESSAGE extends UIMessage> extends Pick<\n AbstractChat<UI_MESSAGE>,\n | 'sendMessage'\n | 'regenerate'\n | 'stop'\n | 'resumeStream'\n | 'addToolOutput'\n | 'addToolApprovalResponse'\n | 'clearError'\n> {\n /**\n * The id of the chat.\n */\n id: ComputedRef<string>;\n\n /**\n * The current error state of the chat, if any.\n */\n error: ShallowRef<Error | undefined>;\n\n /**\n * The current status of the chat, which can be 'ready', 'generating', 'streaming', or 'error'.\n */\n status: ShallowRef<ChatStatus>;\n\n /**\n * The list of messages in the chat, which can be updated by the chat instance methods or directly by setting this property.\n */\n messages: ShallowRef<UI_MESSAGE[]>;\n}\n\nexport type UseChatOptions<UI_MESSAGE extends UIMessage> =\n BaseChatInit<UI_MESSAGE> & {\n /**\n * Custom throttle wait time in milliseconds for reactive message updates.\n * Positive values enable throttling. Defaults to undefined, which disables\n * throttling.\n */\n throttle?: number;\n };\n\n/**\n * Composable to access messages, status, and other chat properties and\n * methods. Accepts an optional reactive initial configuration object\n *\n * @example\n *\n * ```ts\n * // passing a getter if any reactive properties are used within\n * // the init object\n * const { messages, sendMessage } = useChat(() => ({\n * // ...\n * })\n * ```\n *\n * @see BaseChatInit\n */\nexport function useChat<UI_MESSAGE extends UIMessage = UIMessage>(\n init?: MaybeRefOrGetter<UseChatOptions<UI_MESSAGE>>,\n): UseChatHelpers<UI_MESSAGE> {\n const messages = shallowRef<UI_MESSAGE[]>([]);\n const status = shallowRef<ChatStatus>('ready');\n const error = shallowRef<Error | undefined>();\n\n // the instance is created right away thanks to immediate: true. We do it this\n // way instead of a computed to ensure all changes to reactive state happen\n // in the same tick\n const chatInstance = shallowRef<VueChat<UI_MESSAGE>>() as ShallowRef<\n VueChat<UI_MESSAGE>\n >;\n let chatState: VueChatState<UI_MESSAGE> | undefined;\n\n watch(\n messages,\n messageList => {\n if (chatState != null && !chatState.isPublishing) {\n chatState.setMessagesFromConsumer(messageList);\n }\n },\n { flush: 'sync' },\n );\n\n watch(\n () => toValue(init),\n opts => {\n chatState?.dispose();\n\n const { throttle, ...chatInit } = opts ?? {};\n const nextChatState = new VueChatState<UI_MESSAGE>({\n initialMessages: chatInit.messages ?? [],\n messagesRef: messages,\n statusRef: status,\n errorRef: error,\n throttleWaitMs: throttle,\n });\n\n chatState = nextChatState;\n nextChatState.publishInitialState();\n\n chatInstance.value = new VueChat<UI_MESSAGE>({\n ...chatInit,\n state: nextChatState,\n });\n },\n { immediate: true },\n );\n\n if (getCurrentScope() != null) {\n onScopeDispose(() => {\n chatState?.dispose();\n });\n }\n\n return {\n id: computed(() => chatInstance.value.id),\n status,\n messages,\n error,\n addToolApprovalResponse: opts =>\n chatInstance.value.addToolApprovalResponse(opts),\n addToolOutput: opts => chatInstance.value.addToolOutput(opts),\n clearError: () => chatInstance.value.clearError(),\n regenerate: opts => chatInstance.value.regenerate(opts),\n sendMessage: (...args) => chatInstance.value.sendMessage(...args),\n stop: () => chatInstance.value.stop(),\n resumeStream: opts => chatInstance.value.resumeStream(opts),\n };\n}\n","import type { FlexibleSchema } from '@ai-sdk/provider-utils';\nimport {\n useObject,\n type UseObjectHelpers,\n type UseObjectOptions,\n} from './use-object';\n\nexport * from './use-completion';\nexport { Chat } from './chat.vue';\nexport { useChat, type UseChatHelpers, type UseChatOptions } from './use-chat';\nexport * from './use-object';\n\n// deprecated aliases\n// note: declared here (instead of export aliases) so that the `@deprecated`\n// tags are preserved in the bundled type declarations\n\n/**\n * @deprecated Use `useObject` instead.\n */\nexport const experimental_useObject = useObject;\n\n/**\n * @deprecated Use `UseObjectOptions` instead.\n */\nexport type Experimental_UseObjectOptions<\n SCHEMA extends FlexibleSchema,\n RESULT,\n> = UseObjectOptions<SCHEMA, RESULT>;\n\n/**\n * @deprecated Use `UseObjectHelpers` instead.\n */\nexport type Experimental_UseObjectHelpers<RESULT, INPUT> = UseObjectHelpers<\n RESULT,\n INPUT\n>;\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;AAAA,IAC5D,YAAY,MAAM,aAAa,MAAM,WAAW;AAAA,IAChD,YAAY,UAAQ,aAAa,MAAM,WAAW,IAAI;AAAA,IACtD,aAAa,IAAI,SAAS,aAAa,MAAM,YAAY,GAAG,IAAI;AAAA,IAChE,MAAM,MAAM,aAAa,MAAM,KAAK;AAAA,IACpC,cAAc,UAAQ,aAAa,MAAM,aAAa,IAAI;AAAA,EAC5D;AACF;;;AC5YO,IAAM,yBAAyB;","names":["fetch","swrv","ref","uniqueId","useSWRV","store","fetch","data","completion","ref","AbstractChat","VueChatState"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["uniqueId","useSWRV","store","VueChatState"],"sources":["../src/use-object.ts","../src/use-completion.ts","../src/chat.vue.ts","../src/use-chat.ts","../src/index.ts"],"sourcesContent":["import {\n isAbortError,\n safeValidateTypes,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n asSchema,\n isDeepEqualData,\n parsePartialJson,\n type DeepPartial,\n type FlexibleSchema,\n type InferSchema,\n} from 'ai';\nimport type * as SwrvModule from 'swrv';\nimport swrv from 'swrv';\nimport { ref, type Ref } from 'vue';\n// use function to allow for mocking in tests\nconst getOriginalFetch = () => fetch;\n\nexport type UseObjectOptions<SCHEMA extends FlexibleSchema, RESULT> = {\n /** API endpoint that streams JSON chunks matching the schema */\n api: string;\n\n /** Schema that defines the final object shape */\n schema: SCHEMA;\n\n /** Shared state key. If omitted a random one is generated */\n id?: string;\n\n /** Initial partial value */\n initialValue?: DeepPartial<RESULT>;\n\n /** Optional custom fetch implementation */\n fetch?: FetchFunction;\n\n /** Called when stream ends */\n onFinish?: (event: {\n object: RESULT | undefined;\n error: Error | undefined;\n }) => Promise<void> | void;\n\n /** Called on error */\n onError?: (error: Error) => void;\n\n /** Extra request headers */\n headers?: Record<string, string> | Headers;\n\n /** Request credentials mode. Defaults to 'same-origin' if omitted */\n credentials?: RequestCredentials;\n};\n\nexport type UseObjectHelpers<RESULT, INPUT> = {\n /** POST the input and start streaming */\n submit: (input: INPUT) => void;\n\n /** Current partial object, updated as chunks arrive */\n object: Ref<DeepPartial<RESULT> | undefined>;\n\n /** Latest error if any */\n error: Ref<Error | undefined>;\n\n /** Loading flag for the in-flight request */\n isLoading: Ref<boolean | undefined>;\n\n /** Abort the current request. Keeps current partial object. */\n stop: () => void;\n\n /** Abort and clear all state */\n clear: () => void;\n};\n\nlet uniqueId = 0;\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof SwrvModule)['default']) || swrv;\nconst store: Record<string, any> = {};\n\nexport function useObject<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n INPUT = any,\n>({\n api,\n id,\n schema,\n initialValue,\n fetch,\n onError,\n onFinish,\n headers,\n credentials,\n}: UseObjectOptions<SCHEMA, RESULT>): UseObjectHelpers<RESULT, INPUT> {\n // Generate an unique id for the object if not provided.\n const completionId = id || `completion-${uniqueId++}`;\n\n const key = `${api}|${completionId}`;\n const { data, mutate: originalMutate } = useSWRV<\n DeepPartial<RESULT> | undefined\n >(key, () => (key in store ? store[key] : initialValue));\n\n const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(\n `${completionId}-loading`,\n null,\n );\n\n isLoading.value ??= false;\n data.value ||= initialValue as DeepPartial<RESULT> | undefined;\n\n const mutateObject = (value: DeepPartial<RESULT> | undefined) => {\n store[key] = value;\n return originalMutate();\n };\n\n const error = ref<Error | undefined>(undefined);\n let abortController: AbortController | null = null;\n\n const stop = async () => {\n if (abortController) {\n try {\n abortController.abort();\n } catch {\n // ignore\n } finally {\n abortController = null;\n }\n }\n await mutateLoading(() => false);\n };\n\n const clearObject = async () => {\n error.value = undefined;\n await mutateLoading(() => false);\n await mutateObject(undefined);\n // Need to explicitly set the value to undefined to trigger a re-render\n data.value = undefined;\n };\n\n const clear = async () => {\n await stop();\n await clearObject();\n };\n\n const submit = async (input: INPUT) => {\n try {\n await clearObject();\n await mutateLoading(() => true);\n\n abortController = new AbortController();\n\n const actualFetch = fetch ?? getOriginalFetch();\n const response = await actualFetch(api, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...(headers as any),\n },\n credentials: credentials ?? 'same-origin',\n signal: abortController.signal,\n body: JSON.stringify(input),\n });\n\n if (!response.ok) {\n throw new Error(\n (await response.text()) || 'Failed to fetch the response.',\n );\n }\n\n if (!response.body) {\n throw new Error('The response body is empty.');\n }\n\n let accumulatedText = '';\n let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n new WritableStream<string>({\n async write(chunk) {\n accumulatedText += chunk;\n const { value } = await parsePartialJson(accumulatedText);\n const currentObject = value as DeepPartial<RESULT>;\n if (!isDeepEqualData(latestObject, currentObject)) {\n latestObject = currentObject;\n await mutateObject(currentObject);\n }\n },\n async close() {\n await mutateLoading(() => false);\n abortController = null;\n\n if (onFinish) {\n const validationResult = await safeValidateTypes({\n value: latestObject,\n schema: asSchema(schema),\n });\n\n onFinish(\n validationResult.success\n ? {\n object: validationResult.value as RESULT,\n error: undefined,\n }\n : { object: undefined, error: validationResult.error },\n );\n }\n },\n }),\n );\n } catch (err: unknown) {\n if (isAbortError(err)) return;\n\n if (onError && err instanceof Error) onError(err);\n\n await mutateLoading(() => false);\n error.value = err instanceof Error ? err : new Error(String(err));\n }\n };\n\n return {\n submit,\n object: data,\n error,\n isLoading,\n stop,\n clear,\n };\n}\n","import {\n callCompletionApi,\n type CompletionRequestOptions,\n type UseCompletionOptions,\n} from 'ai';\nimport type * as SwrvModule from 'swrv';\nimport swrv from 'swrv';\nimport { ref, unref, type Ref } from 'vue';\nexport type { UseCompletionOptions };\n\nexport type UseCompletionHelpers<BODY extends object = object> = {\n /** The current completion result */\n completion: Ref<string>;\n /** The error object of the API request */\n error: Ref<undefined | Error>;\n /**\n * Send a new prompt to the API endpoint and update the completion state.\n */\n complete: (\n prompt: string,\n options?: CompletionRequestOptions<BODY>,\n ) => Promise<string | null | undefined>;\n /**\n * Abort the current API request but keep the generated tokens.\n */\n stop: () => void;\n /**\n * Update the `completion` state locally.\n */\n setCompletion: (completion: string) => void;\n /** The current value of the input */\n input: Ref<string>;\n /**\n * Form submission handler to automatically reset input and append a user message\n * @example\n * ```jsx\n * <form @submit=\"handleSubmit\">\n * <input @change=\"handleInputChange\" v-model=\"input\" />\n * </form>\n * ```\n */\n handleSubmit: (event?: { preventDefault?: () => void }) => void;\n /** Whether the API request is in progress */\n isLoading: Ref<boolean | undefined>;\n};\n\nlet uniqueId = 0;\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof SwrvModule)['default']) || swrv;\nconst store: Record<string, any> = {};\n\nexport function useCompletion<BODY extends object = object>({\n api = '/api/completion',\n id,\n initialCompletion = '',\n initialInput = '',\n credentials,\n headers,\n body,\n streamProtocol,\n onFinish,\n onError,\n fetch,\n}: UseCompletionOptions<NoInfer<BODY>> = {}): UseCompletionHelpers<BODY> {\n // Generate an unique id for the completion if not provided.\n const completionId = id || `completion-${uniqueId++}`;\n\n const key = `${api}|${completionId}`;\n const { data, mutate: originalMutate } = useSWRV<string>(\n key,\n () => store[key] ?? initialCompletion,\n );\n\n const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(\n `${completionId}-loading`,\n null,\n );\n\n isLoading.value ??= false;\n\n // Force the `data` to be `initialCompletion` if it's `undefined`.\n data.value ??= initialCompletion;\n\n const mutate = (data: string) => {\n store[key] = data;\n return originalMutate();\n };\n\n // Because of the `initialData` option, the `data` will never be `undefined`.\n const completion = data as Ref<string>;\n\n const error = ref<undefined | Error>(undefined);\n\n let abortController: AbortController | null = null;\n\n async function triggerRequest(\n prompt: string,\n options?: CompletionRequestOptions<BODY>,\n ) {\n return callCompletionApi({\n api,\n prompt,\n credentials,\n headers: {\n ...headers,\n ...options?.headers,\n },\n body: {\n ...unref(body),\n ...options?.body,\n },\n streamProtocol,\n setCompletion: mutate,\n setLoading: loading => mutateLoading(() => loading),\n setError: err => {\n error.value = err;\n },\n setAbortController: controller => {\n abortController = controller;\n },\n getAbortController: () => abortController,\n onFinish,\n onError,\n fetch,\n });\n }\n\n const complete: UseCompletionHelpers<BODY>['complete'] = async (\n prompt,\n options,\n ) => {\n return triggerRequest(prompt, options);\n };\n\n const stop = () => {\n if (abortController) {\n abortController.abort();\n }\n };\n\n const setCompletion = (completion: string) => {\n mutate(completion);\n };\n\n const input = ref(initialInput);\n\n const handleSubmit = (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n const inputValue = input.value;\n return inputValue ? complete(inputValue) : undefined;\n };\n\n return {\n completion,\n complete,\n error,\n stop,\n setCompletion,\n input,\n handleSubmit,\n isLoading,\n };\n}\n","import {\n AbstractChat,\n type ChatInit,\n type ChatState,\n type ChatStatus,\n type UIMessage,\n} from 'ai';\nimport { ref, type Ref } from 'vue';\nclass VueChatState<\n UI_MESSAGE extends UIMessage,\n> implements ChatState<UI_MESSAGE> {\n private messagesRef: Ref<UI_MESSAGE[]>;\n private statusRef = ref<ChatStatus>('ready');\n private errorRef = ref<Error | undefined>(undefined);\n\n constructor(messages?: UI_MESSAGE[]) {\n this.messagesRef = ref(messages ?? []) as Ref<UI_MESSAGE[]>;\n }\n\n get messages(): UI_MESSAGE[] {\n return this.messagesRef.value;\n }\n\n set messages(messages: UI_MESSAGE[]) {\n this.messagesRef.value = messages;\n }\n\n get status(): ChatStatus {\n return this.statusRef.value;\n }\n\n set status(status: ChatStatus) {\n this.statusRef.value = status;\n }\n\n get error(): Error | undefined {\n return this.errorRef.value;\n }\n\n set error(error: Error | undefined) {\n this.errorRef.value = error;\n }\n\n pushMessage = (message: UI_MESSAGE) => {\n this.messagesRef.value = [...this.messagesRef.value, message];\n };\n\n popMessage = () => {\n this.messagesRef.value = this.messagesRef.value.slice(0, -1);\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n // message is cloned here because vue's deep reactivity shows unexpected behavior, particularly when updating tool invocation parts\n this.messagesRef.value[index] = { ...message };\n };\n\n snapshot = <T>(value: T): T => value;\n}\n\n/**\n * @deprecated Use the {@link useChat} composable instead. It exposes reactive\n * refs and automatically recreates the chat when its init object changes.\n */\nexport class Chat<\n UI_MESSAGE extends UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor({ messages, ...init }: ChatInit<UI_MESSAGE>) {\n super({\n ...init,\n state: new VueChatState(messages),\n });\n }\n}\n","import {\n AbstractChat,\n type ChatInit as BaseChatInit,\n type ChatInit,\n type ChatState,\n type ChatStatus,\n type UIMessage,\n} from 'ai';\nimport {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowRef,\n toValue,\n watch,\n type ComputedRef,\n type MaybeRefOrGetter,\n type ShallowRef,\n} from 'vue';\n\nfunction cloneMetadata<METADATA>(metadata: METADATA): METADATA {\n if (Array.isArray(metadata)) {\n return [...metadata] as METADATA;\n }\n\n if (\n metadata != null &&\n typeof metadata === 'object' &&\n (Object.getPrototypeOf(metadata) === Object.prototype ||\n Object.getPrototypeOf(metadata) === null)\n ) {\n return { ...metadata } as METADATA;\n }\n\n return metadata;\n}\n\nfunction snapshotValue<T>(value: T): T {\n if (\n value == null ||\n typeof value !== 'object' ||\n !('parts' in value) ||\n !Array.isArray(value.parts)\n ) {\n return value;\n }\n\n const message = value as unknown as UIMessage;\n const snapshot = {\n ...message,\n parts: message.parts.map(part => ({ ...part })),\n };\n\n if ('metadata' in message) {\n snapshot.metadata = cloneMetadata(message.metadata);\n }\n\n return snapshot as T;\n}\n\nclass VueChatState<\n UI_MESSAGE extends UIMessage,\n> implements ChatState<UI_MESSAGE> {\n private messagesValue: UI_MESSAGE[];\n private publishedMessages: UI_MESSAGE[] = [];\n private publishedMessageSources: UI_MESSAGE[] = [];\n private readonly dirtyMessageIndices = new Set<number>();\n private statusValue: ChatStatus = 'ready';\n private errorValue: Error | undefined;\n private readonly throttleWaitMs: number | undefined;\n private timeout: ReturnType<typeof setTimeout> | undefined;\n private hasPendingPublication = false;\n private isActive = true;\n\n isPublishing = false;\n\n constructor({\n initialMessages,\n messagesRef,\n statusRef,\n errorRef,\n throttleWaitMs,\n }: {\n initialMessages: UI_MESSAGE[];\n messagesRef: ShallowRef<UI_MESSAGE[]>;\n statusRef: ShallowRef<ChatStatus>;\n errorRef: ShallowRef<Error | undefined>;\n throttleWaitMs?: number;\n }) {\n this.messagesValue = initialMessages;\n this.messagesRef = messagesRef;\n this.statusRef = statusRef;\n this.errorRef = errorRef;\n this.throttleWaitMs =\n throttleWaitMs != null &&\n Number.isFinite(throttleWaitMs) &&\n throttleWaitMs > 0\n ? throttleWaitMs\n : undefined;\n }\n\n private readonly messagesRef: ShallowRef<UI_MESSAGE[]>;\n private readonly statusRef: ShallowRef<ChatStatus>;\n private readonly errorRef: ShallowRef<Error | undefined>;\n\n get messages(): UI_MESSAGE[] {\n return this.messagesValue;\n }\n\n set messages(messages: UI_MESSAGE[]) {\n const previousMessages = this.messagesValue;\n this.messagesValue = messages;\n\n for (let index = 0; index < messages.length; index++) {\n if (messages[index] !== previousMessages[index]) {\n this.dirtyMessageIndices.add(index);\n }\n }\n\n this.schedulePublication();\n }\n\n get status(): ChatStatus {\n return this.statusValue;\n }\n\n set status(status: ChatStatus) {\n this.statusValue = status;\n\n if (!this.isActive) {\n return;\n }\n\n if (status === 'ready' || status === 'error') {\n // Terminal states must never become observable before the final message.\n this.flushPublication();\n }\n\n this.statusRef.value = status;\n }\n\n get error(): Error | undefined {\n return this.errorValue;\n }\n\n set error(error: Error | undefined) {\n this.errorValue = error;\n\n if (this.isActive) {\n this.errorRef.value = error;\n }\n }\n\n pushMessage = (message: UI_MESSAGE) => {\n this.messagesValue.push(message);\n this.dirtyMessageIndices.add(this.messagesValue.length - 1);\n this.schedulePublication();\n };\n\n popMessage = () => {\n this.messagesValue.pop();\n this.schedulePublication();\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n this.messagesValue[index] = message;\n this.dirtyMessageIndices.add(index);\n this.schedulePublication();\n };\n\n snapshot = snapshotValue;\n\n publishInitialState() {\n this.publishMessages();\n this.statusRef.value = this.statusValue;\n this.errorRef.value = this.errorValue;\n }\n\n setMessagesFromConsumer(messages: UI_MESSAGE[]) {\n this.messagesValue = messages;\n this.publishedMessages = messages;\n this.publishedMessageSources = messages;\n this.dirtyMessageIndices.clear();\n }\n\n dispose() {\n this.isActive = false;\n this.hasPendingPublication = false;\n this.dirtyMessageIndices.clear();\n this.publishedMessages = [];\n this.publishedMessageSources = [];\n\n if (this.timeout != null) {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n }\n }\n\n private schedulePublication() {\n if (!this.isActive) {\n return;\n }\n\n if (this.throttleWaitMs == null) {\n this.publishMessages();\n return;\n }\n\n if (this.timeout == null) {\n // Publish the leading update immediately, then coalesce updates until\n // the next interval boundary.\n this.publishMessages();\n this.timeout = setTimeout(this.handleIntervalEnd, this.throttleWaitMs);\n } else {\n this.hasPendingPublication = true;\n }\n }\n\n private readonly handleIntervalEnd = () => {\n this.timeout = undefined;\n\n if (!this.isActive || !this.hasPendingPublication) {\n return;\n }\n\n this.hasPendingPublication = false;\n this.publishMessages();\n this.timeout = setTimeout(this.handleIntervalEnd, this.throttleWaitMs);\n };\n\n private flushPublication() {\n if (this.timeout != null) {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n }\n\n this.hasPendingPublication = false;\n this.publishMessages();\n }\n\n private publishMessages() {\n if (!this.isActive) {\n return;\n }\n\n const publishedMessages = this.messagesValue.map((message, index) =>\n this.dirtyMessageIndices.has(index) ||\n this.publishedMessageSources[index] !== message\n ? snapshotValue(message)\n : this.publishedMessages[index],\n );\n\n this.publishedMessages = publishedMessages;\n this.publishedMessageSources = [...this.messagesValue];\n this.dirtyMessageIndices.clear();\n\n this.isPublishing = true;\n try {\n this.messagesRef.value = publishedMessages;\n } finally {\n this.isPublishing = false;\n }\n }\n}\n\n/**\n * @internal\n */\nexport class VueChat<\n UI_MESSAGE extends UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor({\n state,\n ...init\n }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {\n state: ChatState<UI_MESSAGE>;\n }) {\n super({\n ...init,\n state,\n });\n }\n}\n\n/**\n * Return type of the {@link useChat} composable, which includes the chat\n * instance methods and reactive properties for messages, status, and error.\n */\nexport interface UseChatHelpers<UI_MESSAGE extends UIMessage> extends Pick<\n AbstractChat<UI_MESSAGE>,\n | 'sendMessage'\n | 'regenerate'\n | 'stop'\n | 'resumeStream'\n | 'addToolOutput'\n | 'addToolApprovalResponse'\n | 'clearError'\n> {\n /**\n * The id of the chat.\n */\n id: ComputedRef<string>;\n\n /**\n * The current error state of the chat, if any.\n */\n error: ShallowRef<Error | undefined>;\n\n /**\n * The current status of the chat, which can be 'ready', 'generating', 'streaming', or 'error'.\n */\n status: ShallowRef<ChatStatus>;\n\n /**\n * The list of messages in the chat, which can be updated by the chat instance methods or directly by setting this property.\n */\n messages: ShallowRef<UI_MESSAGE[]>;\n}\n\nexport type UseChatOptions<UI_MESSAGE extends UIMessage> =\n BaseChatInit<UI_MESSAGE> & {\n /**\n * Custom throttle wait time in milliseconds for reactive message updates.\n * Positive values enable throttling. Defaults to undefined, which disables\n * throttling.\n */\n throttle?: number;\n };\n\n/**\n * Composable to access messages, status, and other chat properties and\n * methods. Accepts an optional reactive initial configuration object\n *\n * @example\n *\n * ```ts\n * // passing a getter if any reactive properties are used within\n * // the init object\n * const { messages, sendMessage } = useChat(() => ({\n * // ...\n * })\n * ```\n *\n * @see BaseChatInit\n */\nexport function useChat<UI_MESSAGE extends UIMessage = UIMessage>(\n init?: MaybeRefOrGetter<UseChatOptions<UI_MESSAGE>>,\n): UseChatHelpers<UI_MESSAGE> {\n const messages = shallowRef<UI_MESSAGE[]>([]);\n const status = shallowRef<ChatStatus>('ready');\n const error = shallowRef<Error | undefined>();\n\n // the instance is created right away thanks to immediate: true. We do it this\n // way instead of a computed to ensure all changes to reactive state happen\n // in the same tick\n const chatInstance = shallowRef<VueChat<UI_MESSAGE>>() as ShallowRef<\n VueChat<UI_MESSAGE>\n >;\n let chatState: VueChatState<UI_MESSAGE> | undefined;\n\n watch(\n messages,\n messageList => {\n if (chatState != null && !chatState.isPublishing) {\n chatState.setMessagesFromConsumer(messageList);\n }\n },\n { flush: 'sync' },\n );\n\n watch(\n () => toValue(init),\n opts => {\n chatState?.dispose();\n\n const { throttle, ...chatInit } = opts ?? {};\n const nextChatState = new VueChatState<UI_MESSAGE>({\n initialMessages: chatInit.messages ?? [],\n messagesRef: messages,\n statusRef: status,\n errorRef: error,\n throttleWaitMs: throttle,\n });\n\n chatState = nextChatState;\n nextChatState.publishInitialState();\n\n chatInstance.value = new VueChat<UI_MESSAGE>({\n ...chatInit,\n state: nextChatState,\n });\n },\n { immediate: true },\n );\n\n if (getCurrentScope() != null) {\n onScopeDispose(() => {\n chatState?.dispose();\n });\n }\n\n return {\n id: computed(() => chatInstance.value.id),\n status,\n messages,\n error,\n addToolApprovalResponse: opts =>\n chatInstance.value.addToolApprovalResponse(opts),\n addToolOutput: opts => chatInstance.value.addToolOutput(opts),\n clearError: () => chatInstance.value.clearError(),\n regenerate: opts => chatInstance.value.regenerate(opts),\n sendMessage: (...args) => chatInstance.value.sendMessage(...args),\n stop: () => chatInstance.value.stop(),\n resumeStream: opts => chatInstance.value.resumeStream(opts),\n };\n}\n","import type { FlexibleSchema } from '@ai-sdk/provider-utils';\nimport {\n useObject,\n type UseObjectHelpers,\n type UseObjectOptions,\n} from './use-object';\n\nexport * from './use-completion';\nexport { Chat } from './chat.vue';\nexport { useChat, type UseChatHelpers, type UseChatOptions } from './use-chat';\nexport * from './use-object';\n\n// deprecated aliases\n// note: declared here (instead of export aliases) so that the `@deprecated`\n// tags are preserved in the bundled type declarations\n\n/**\n * @deprecated Use `useObject` instead.\n */\nexport const experimental_useObject = useObject;\n\n/**\n * @deprecated Use `UseObjectOptions` instead.\n */\nexport type Experimental_UseObjectOptions<\n SCHEMA extends FlexibleSchema,\n RESULT,\n> = UseObjectOptions<SCHEMA, RESULT>;\n\n/**\n * @deprecated Use `UseObjectHelpers` instead.\n */\nexport type Experimental_UseObjectHelpers<RESULT, INPUT> = UseObjectHelpers<\n RESULT,\n INPUT\n>;\n"],"mappings":";;;;;AAiBA,MAAM,yBAAyB;AAsD/B,IAAIA,aAAW;AAGf,MAAMC,YAAW,KAAK,WAA8C;AACpE,MAAMC,UAA6B,CAAC;AAEpC,SAAgB,UAId,EACA,KACA,IACA,QACA,cACA,OACA,SACA,UACA,SACA,eACoE;CAEpE,MAAM,eAAe,MAAM,cAAc;CAEzC,MAAM,MAAM,GAAG,IAAI,GAAG;CACtB,MAAM,EAAE,MAAM,QAAQ,mBAAmBD,UAEvC,WAAY,OAAOC,UAAQA,QAAM,OAAO,YAAa;CAEvD,MAAM,EAAE,MAAM,WAAW,QAAQ,kBAAkBD,UACjD,GAAG,aAAa,WAChB,IACF;CAEA,UAAU,UAAU;CACpB,KAAK,UAAU;CAEf,MAAM,gBAAgB,UAA2C;EAC/D,QAAM,OAAO;EACb,OAAO,eAAe;CACxB;CAEA,MAAM,QAAQ,IAAuB,KAAA,CAAS;CAC9C,IAAI,kBAA0C;CAE9C,MAAM,OAAO,YAAY;EACvB,IAAI,iBACF,IAAI;GACF,gBAAgB,MAAM;EACxB,QAAQ,CAER,UAAU;GACR,kBAAkB;EACpB;EAEF,MAAM,oBAAoB,KAAK;CACjC;CAEA,MAAM,cAAc,YAAY;EAC9B,MAAM,QAAQ,KAAA;EACd,MAAM,oBAAoB,KAAK;EAC/B,MAAM,aAAa,KAAA,CAAS;EAE5B,KAAK,QAAQ,KAAA;CACf;CAEA,MAAM,QAAQ,YAAY;EACxB,MAAM,KAAK;EACX,MAAM,YAAY;CACpB;CAEA,MAAM,SAAS,OAAO,UAAiB;EACrC,IAAI;GACF,MAAM,YAAY;GAClB,MAAM,oBAAoB,IAAI;GAE9B,kBAAkB,IAAI,gBAAgB;GAGtC,MAAM,WAAW,OADG,SAAS,iBAAiB,EAAA,CACX,KAAK;IACtC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GACV,gBAAgB;EAClB,CAAC;EAED,YAAY;EACZ,cAAc,oBAAoB;EAElC,aAAa,QAAQ,IAAI,QAAoB;GAC3C,GAAG;GACH,OAAO;EACT,CAAC;CACH,GACA,EAAE,WAAW,KAAK,CACpB;CAEA,IAAI,gBAAgB,KAAK,MACvB,qBAAqB;EACnB,WAAW,QAAQ;CACrB,CAAC;CAGH,OAAO;EACL,IAAI,eAAe,aAAa,MAAM,EAAE;EACxC;EACA;EACA;EACA,0BAAyB,SACvB,aAAa,MAAM,wBAAwB,IAAI;EACjD,gBAAe,SAAQ,aAAa,MAAM,cAAc,IAAI;EAC5D,kBAAkB,aAAa,MAAM,WAAW;EAChD,aAAY,SAAQ,aAAa,MAAM,WAAW,IAAI;EACtD,cAAc,GAAG,SAAS,aAAa,MAAM,YAAY,GAAG,IAAI;EAChE,YAAY,aAAa,MAAM,KAAK;EACpC,eAAc,SAAQ,aAAa,MAAM,aAAa,IAAI;CAC5D;AACF;;;;;;AC5YA,MAAa,yBAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/vue",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.124",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
30
|
-
"ai": "7.0.
|
|
29
|
+
"@ai-sdk/provider-utils": "5.0.53",
|
|
30
|
+
"ai": "7.0.124",
|
|
31
31
|
"swrv": "^1.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@ai-sdk/test-server": "2.0.
|
|
34
|
+
"@ai-sdk/test-server": "2.0.3",
|
|
35
35
|
"@testing-library/jest-dom": "^6.9.1",
|
|
36
36
|
"@testing-library/user-event": "^14.6.1",
|
|
37
37
|
"@testing-library/vue": "^8.1.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@vitejs/plugin-vue": "5.2.0",
|
|
41
41
|
"jsdom": "^24.1.3",
|
|
42
42
|
"msw": "2.6.4",
|
|
43
|
-
"
|
|
43
|
+
"tsdown": "^0.23.0",
|
|
44
44
|
"typescript": "5.8.3",
|
|
45
45
|
"vitest": "4.1.6",
|
|
46
46
|
"zod": "3.25.76"
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"vue"
|
|
70
70
|
],
|
|
71
71
|
"scripts": {
|
|
72
|
-
"build": "pnpm clean &&
|
|
73
|
-
"build:watch": "pnpm clean &&
|
|
74
|
-
"clean": "del-cli
|
|
72
|
+
"build": "pnpm clean && tsdown",
|
|
73
|
+
"build:watch": "pnpm clean && tsdown --watch",
|
|
74
|
+
"clean": "del-cli *.tsbuildinfo",
|
|
75
75
|
"type-check": "tsc --build",
|
|
76
76
|
"test": "vitest --config vitest.config.js --run",
|
|
77
77
|
"test:update": "vitest --config vitest.config.js --run -u",
|