@ai-sdk/svelte 0.0.1

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/.eslintrc.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['vercel-ai'],
4
+ };
@@ -0,0 +1,21 @@
1
+
2
+ > @ai-sdk/svelte@0.0.1 build /home/runner/work/ai/ai/packages/svelte
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v7.2.0
8
+ CLI Using tsup config: /home/runner/work/ai/ai/packages/svelte/tsup.config.ts
9
+ CLI Target: es2018
10
+ CJS Build start
11
+ ESM Build start
12
+ CJS dist/index.js 14.99 KB
13
+ CJS dist/index.js.map 30.49 KB
14
+ CJS ⚡️ Build success in 47ms
15
+ ESM dist/index.mjs 13.34 KB
16
+ ESM dist/index.mjs.map 30.36 KB
17
+ ESM ⚡️ Build success in 48ms
18
+ DTS Build start
19
+ DTS ⚡️ Build success in 3834ms
20
+ DTS dist/index.d.ts 5.22 KB
21
+ DTS dist/index.d.mts 5.22 KB
@@ -0,0 +1,4 @@
1
+
2
+ > @ai-sdk/svelte@0.0.1 clean /home/runner/work/ai/ai/packages/svelte
3
+ > rm -rf dist
4
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @ai-sdk/svelte
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 85f209a4: chore: extracted ui library support into separate modules
8
+ - Updated dependencies [85f209a4]
9
+ - @ai-sdk/ui-utils@0.0.1
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Vercel AI SDK: Svelte provider
2
+
3
+ [Svelte](https://svelte.dev/) UI components for the [Vercel AI SDK](https://sdk.vercel.ai/docs):
4
+
5
+ - [`useChat`](https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-chat) hook
6
+ - [`useCompletion`](https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-completion) hook
7
+ - [`useAssistant`](https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-assistant) hook
@@ -0,0 +1,128 @@
1
+ import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils';
2
+ export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
3
+ import { Readable, Writable } from 'svelte/store';
4
+
5
+ type UseChatHelpers = {
6
+ /** Current messages in the chat */
7
+ messages: Readable<Message[]>;
8
+ /** The error object of the API request */
9
+ error: Readable<undefined | Error>;
10
+ /**
11
+ * Append a user message to the chat list. This triggers the API call to fetch
12
+ * the assistant's response.
13
+ * @param message The message to append
14
+ * @param chatRequestOptions Additional options to pass to the API call
15
+ */
16
+ append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
17
+ /**
18
+ * Reload the last AI chat response for the given chat history. If the last
19
+ * message isn't from the assistant, it will request the API to generate a
20
+ * new response.
21
+ */
22
+ reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
23
+ /**
24
+ * Abort the current request immediately, keep the generated tokens if any.
25
+ */
26
+ stop: () => void;
27
+ /**
28
+ * Update the `messages` state locally. This is useful when you want to
29
+ * edit the messages on the client, and then trigger the `reload` method
30
+ * manually to regenerate the AI response.
31
+ */
32
+ setMessages: (messages: Message[]) => void;
33
+ /** The current value of the input */
34
+ input: Writable<string>;
35
+ /** Form submission handler to automatically reset input and append a user message */
36
+ handleSubmit: (e: any, chatRequestOptions?: ChatRequestOptions) => void;
37
+ metadata?: Object;
38
+ /** Whether the API request is in progress */
39
+ isLoading: Readable<boolean | undefined>;
40
+ /** Additional data added on the server via StreamData */
41
+ data: Readable<JSONValue[] | undefined>;
42
+ };
43
+ declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: UseChatOptions): UseChatHelpers;
44
+
45
+ type UseCompletionHelpers = {
46
+ /** The current completion result */
47
+ completion: Readable<string>;
48
+ /** The error object of the API request */
49
+ error: Readable<undefined | Error>;
50
+ /**
51
+ * Send a new prompt to the API endpoint and update the completion state.
52
+ */
53
+ complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
54
+ /**
55
+ * Abort the current API request but keep the generated tokens.
56
+ */
57
+ stop: () => void;
58
+ /**
59
+ * Update the `completion` state locally.
60
+ */
61
+ setCompletion: (completion: string) => void;
62
+ /** The current value of the input */
63
+ input: Writable<string>;
64
+ /**
65
+ * Form submission handler to automatically reset input and append a user message
66
+ * @example
67
+ * ```jsx
68
+ * <form onSubmit={handleSubmit}>
69
+ * <input onChange={handleInputChange} value={input} />
70
+ * </form>
71
+ * ```
72
+ */
73
+ handleSubmit: (e: any) => void;
74
+ /** Whether the API request is in progress */
75
+ isLoading: Readable<boolean | undefined>;
76
+ /** Additional data added on the server via StreamData */
77
+ data: Readable<JSONValue[] | undefined>;
78
+ };
79
+ declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
80
+
81
+ type UseAssistantHelpers = {
82
+ /**
83
+ * The current array of chat messages.
84
+ */
85
+ messages: Readable<Message[]>;
86
+ /**
87
+ * Update the message store with a new array of messages.
88
+ */
89
+ setMessages: (messages: Message[]) => void;
90
+ /**
91
+ * The current thread ID.
92
+ */
93
+ threadId: Readable<string | undefined>;
94
+ /**
95
+ * The current value of the input field.
96
+ */
97
+ input: Writable<string>;
98
+ /**
99
+ * Append a user message to the chat list. This triggers the API call to fetch
100
+ * the assistant's response.
101
+ * @param message The message to append
102
+ * @param requestOptions Additional options to pass to the API call
103
+ */
104
+ append: (message: Message | CreateMessage, requestOptions?: {
105
+ data?: Record<string, string>;
106
+ }) => Promise<void>;
107
+ /**
108
+ Abort the current request immediately, keep the generated tokens if any.
109
+ */
110
+ stop: () => void;
111
+ /**
112
+ * Form submission handler that automatically resets the input field and appends a user message.
113
+ */
114
+ submitMessage: (e: any, requestOptions?: {
115
+ data?: Record<string, string>;
116
+ }) => Promise<void>;
117
+ /**
118
+ * The current status of the assistant. This can be used to show a loading indicator.
119
+ */
120
+ status: Readable<AssistantStatus>;
121
+ /**
122
+ * The error thrown during the assistant message processing, if any.
123
+ */
124
+ error: Readable<undefined | Error>;
125
+ };
126
+ declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
127
+
128
+ export { UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, useAssistant, useChat, useCompletion };
@@ -0,0 +1,128 @@
1
+ import { Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils';
2
+ export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
3
+ import { Readable, Writable } from 'svelte/store';
4
+
5
+ type UseChatHelpers = {
6
+ /** Current messages in the chat */
7
+ messages: Readable<Message[]>;
8
+ /** The error object of the API request */
9
+ error: Readable<undefined | Error>;
10
+ /**
11
+ * Append a user message to the chat list. This triggers the API call to fetch
12
+ * the assistant's response.
13
+ * @param message The message to append
14
+ * @param chatRequestOptions Additional options to pass to the API call
15
+ */
16
+ append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
17
+ /**
18
+ * Reload the last AI chat response for the given chat history. If the last
19
+ * message isn't from the assistant, it will request the API to generate a
20
+ * new response.
21
+ */
22
+ reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
23
+ /**
24
+ * Abort the current request immediately, keep the generated tokens if any.
25
+ */
26
+ stop: () => void;
27
+ /**
28
+ * Update the `messages` state locally. This is useful when you want to
29
+ * edit the messages on the client, and then trigger the `reload` method
30
+ * manually to regenerate the AI response.
31
+ */
32
+ setMessages: (messages: Message[]) => void;
33
+ /** The current value of the input */
34
+ input: Writable<string>;
35
+ /** Form submission handler to automatically reset input and append a user message */
36
+ handleSubmit: (e: any, chatRequestOptions?: ChatRequestOptions) => void;
37
+ metadata?: Object;
38
+ /** Whether the API request is in progress */
39
+ isLoading: Readable<boolean | undefined>;
40
+ /** Additional data added on the server via StreamData */
41
+ data: Readable<JSONValue[] | undefined>;
42
+ };
43
+ declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: UseChatOptions): UseChatHelpers;
44
+
45
+ type UseCompletionHelpers = {
46
+ /** The current completion result */
47
+ completion: Readable<string>;
48
+ /** The error object of the API request */
49
+ error: Readable<undefined | Error>;
50
+ /**
51
+ * Send a new prompt to the API endpoint and update the completion state.
52
+ */
53
+ complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
54
+ /**
55
+ * Abort the current API request but keep the generated tokens.
56
+ */
57
+ stop: () => void;
58
+ /**
59
+ * Update the `completion` state locally.
60
+ */
61
+ setCompletion: (completion: string) => void;
62
+ /** The current value of the input */
63
+ input: Writable<string>;
64
+ /**
65
+ * Form submission handler to automatically reset input and append a user message
66
+ * @example
67
+ * ```jsx
68
+ * <form onSubmit={handleSubmit}>
69
+ * <input onChange={handleInputChange} value={input} />
70
+ * </form>
71
+ * ```
72
+ */
73
+ handleSubmit: (e: any) => void;
74
+ /** Whether the API request is in progress */
75
+ isLoading: Readable<boolean | undefined>;
76
+ /** Additional data added on the server via StreamData */
77
+ data: Readable<JSONValue[] | undefined>;
78
+ };
79
+ declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
80
+
81
+ type UseAssistantHelpers = {
82
+ /**
83
+ * The current array of chat messages.
84
+ */
85
+ messages: Readable<Message[]>;
86
+ /**
87
+ * Update the message store with a new array of messages.
88
+ */
89
+ setMessages: (messages: Message[]) => void;
90
+ /**
91
+ * The current thread ID.
92
+ */
93
+ threadId: Readable<string | undefined>;
94
+ /**
95
+ * The current value of the input field.
96
+ */
97
+ input: Writable<string>;
98
+ /**
99
+ * Append a user message to the chat list. This triggers the API call to fetch
100
+ * the assistant's response.
101
+ * @param message The message to append
102
+ * @param requestOptions Additional options to pass to the API call
103
+ */
104
+ append: (message: Message | CreateMessage, requestOptions?: {
105
+ data?: Record<string, string>;
106
+ }) => Promise<void>;
107
+ /**
108
+ Abort the current request immediately, keep the generated tokens if any.
109
+ */
110
+ stop: () => void;
111
+ /**
112
+ * Form submission handler that automatically resets the input field and appends a user message.
113
+ */
114
+ submitMessage: (e: any, requestOptions?: {
115
+ data?: Record<string, string>;
116
+ }) => Promise<void>;
117
+ /**
118
+ * The current status of the assistant. This can be used to show a loading indicator.
119
+ */
120
+ status: Readable<AssistantStatus>;
121
+ /**
122
+ * The error thrown during the assistant message processing, if any.
123
+ */
124
+ error: Readable<undefined | Error>;
125
+ };
126
+ declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
127
+
128
+ export { UseAssistantHelpers, UseChatHelpers, UseCompletionHelpers, useAssistant, useChat, useCompletion };