@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 +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/.turbo/turbo-clean.log +4 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +13 -0
- package/README.md +7 -0
- package/dist/index.d.mts +128 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.js +544 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +519 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +64 -0
- package/src/index.ts +3 -0
- package/src/package.json +10 -0
- package/src/use-assistant.ts +251 -0
- package/src/use-chat.ts +376 -0
- package/src/use-completion.ts +171 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +13 -0
- package/turbo.json +8 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
> @ai-sdk/svelte@0.0.1 build /home/runner/work/ai/ai/packages/svelte
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v7.2.0
|
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/ai/ai/packages/svelte/tsup.config.ts
|
|
9
|
+
[34mCLI[39m Target: es2018
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m14.99 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m30.49 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 47ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m13.34 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m30.36 KB[39m
|
|
17
|
+
[32mESM[39m ⚡️ Build success in 48ms
|
|
18
|
+
[34mDTS[39m Build start
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 3834ms
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.22 KB[39m
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m5.22 KB[39m
|
package/CHANGELOG.md
ADDED
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
|
package/dist/index.d.mts
ADDED
|
@@ -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 };
|
package/dist/index.d.ts
ADDED
|
@@ -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 };
|