@ai-sdk/svelte 1.1.23 → 2.0.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +5 -3
  3. package/dist/chat-context.svelte.d.ts +14 -0
  4. package/dist/chat-context.svelte.d.ts.map +1 -0
  5. package/dist/chat-context.svelte.js +13 -0
  6. package/dist/chat.svelte.d.ts +75 -0
  7. package/dist/chat.svelte.d.ts.map +1 -0
  8. package/dist/chat.svelte.js +244 -0
  9. package/dist/completion-context.svelte.d.ts +15 -0
  10. package/dist/completion-context.svelte.d.ts.map +1 -0
  11. package/dist/completion-context.svelte.js +14 -0
  12. package/dist/completion.svelte.d.ts +37 -0
  13. package/dist/completion.svelte.d.ts.map +1 -0
  14. package/dist/completion.svelte.js +111 -0
  15. package/dist/context-provider.d.ts +2 -0
  16. package/dist/context-provider.d.ts.map +1 -0
  17. package/dist/context-provider.js +11 -0
  18. package/dist/index.d.ts +5 -166
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +4 -551
  21. package/dist/structured-object-context.svelte.d.ts +12 -0
  22. package/dist/structured-object-context.svelte.d.ts.map +1 -0
  23. package/dist/structured-object-context.svelte.js +12 -0
  24. package/dist/structured-object.svelte.d.ts +73 -0
  25. package/dist/structured-object.svelte.d.ts.map +1 -0
  26. package/dist/structured-object.svelte.js +123 -0
  27. package/dist/tests/chat-synchronization.svelte +12 -0
  28. package/dist/tests/chat-synchronization.svelte.d.ts +11 -0
  29. package/dist/tests/chat-synchronization.svelte.d.ts.map +1 -0
  30. package/dist/tests/completion-synchronization.svelte +12 -0
  31. package/dist/tests/completion-synchronization.svelte.d.ts +11 -0
  32. package/dist/tests/completion-synchronization.svelte.d.ts.map +1 -0
  33. package/dist/tests/structured-object-synchronization.svelte +22 -0
  34. package/dist/tests/structured-object-synchronization.svelte.d.ts +28 -0
  35. package/dist/tests/structured-object-synchronization.svelte.d.ts.map +1 -0
  36. package/dist/utils.svelte.d.ts +17 -0
  37. package/dist/utils.svelte.d.ts.map +1 -0
  38. package/dist/utils.svelte.js +50 -0
  39. package/package.json +56 -35
  40. package/src/chat-context.svelte.ts +23 -0
  41. package/src/chat.svelte.ts +341 -0
  42. package/src/completion-context.svelte.ts +24 -0
  43. package/src/completion.svelte.ts +133 -0
  44. package/src/context-provider.ts +20 -0
  45. package/src/index.ts +16 -0
  46. package/src/structured-object-context.svelte.ts +27 -0
  47. package/src/structured-object.svelte.ts +222 -0
  48. package/src/tests/chat-synchronization.svelte +12 -0
  49. package/src/tests/completion-synchronization.svelte +12 -0
  50. package/src/tests/structured-object-synchronization.svelte +22 -0
  51. package/src/utils.svelte.ts +66 -0
  52. package/dist/index.d.mts +0 -166
  53. package/dist/index.js.map +0 -1
  54. package/dist/index.mjs +0 -532
  55. package/dist/index.mjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,166 +1,5 @@
1
- import { UseChatOptions as UseChatOptions$1, UIMessage, Message, CreateMessage, ChatRequestOptions, JSONValue, RequestOptions, UseCompletionOptions, AssistantStatus, UseAssistantOptions } from '@ai-sdk/ui-utils';
2
- export { CreateMessage, Message, UseCompletionOptions } from '@ai-sdk/ui-utils';
3
- import { Readable, Writable } from 'svelte/store';
4
-
5
- type UseChatOptions = UseChatOptions$1 & {
6
- /**
7
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
8
-
9
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
10
-
11
- By default, it's set to 1, which means that only a single LLM call is made.
12
- */
13
- maxSteps?: number;
14
- };
15
- type UseChatHelpers = {
16
- /** Current messages in the chat */
17
- messages: Readable<UIMessage[]>;
18
- /** The error object of the API request */
19
- error: Readable<undefined | Error>;
20
- /**
21
- * Append a user message to the chat list. This triggers the API call to fetch
22
- * the assistant's response.
23
- * @param message The message to append
24
- * @param chatRequestOptions Additional options to pass to the API call
25
- */
26
- append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
27
- /**
28
- * Reload the last AI chat response for the given chat history. If the last
29
- * message isn't from the assistant, it will request the API to generate a
30
- * new response.
31
- */
32
- reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
33
- /**
34
- * Abort the current request immediately, keep the generated tokens if any.
35
- */
36
- stop: () => void;
37
- /**
38
- * Update the `messages` state locally. This is useful when you want to
39
- * edit the messages on the client, and then trigger the `reload` method
40
- * manually to regenerate the AI response.
41
- */
42
- setMessages: (messages: Message[] | ((messages: Message[]) => Message[])) => void;
43
- /** The current value of the input */
44
- input: Writable<string>;
45
- /** Form submission handler to automatically reset input and append a user message */
46
- handleSubmit: (event?: {
47
- preventDefault?: () => void;
48
- }, chatRequestOptions?: ChatRequestOptions) => void;
49
- metadata?: Object;
50
- /**
51
- * Whether the API request is in progress
52
- *
53
- * @deprecated use `status` instead
54
- */
55
- isLoading: Readable<boolean | undefined>;
56
- /**
57
- * Hook status:
58
- *
59
- * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
60
- * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
61
- * - `ready`: The full response has been received and processed; a new user message can be submitted.
62
- * - `error`: An error occurred during the API request, preventing successful completion.
63
- */
64
- status: Readable<'submitted' | 'streaming' | 'ready' | 'error'>;
65
- /** Additional data added on the server via StreamData */
66
- data: Readable<JSONValue[] | undefined>;
67
- /** Set the data of the chat. You can use this to transform or clear the chat data. */
68
- setData: (data: JSONValue[] | undefined | ((data: JSONValue[] | undefined) => JSONValue[] | undefined)) => void;
69
- /** The id of the chat */
70
- id: string;
71
- };
72
- declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, streamProtocol, onResponse, onFinish, onError, onToolCall, credentials, headers, body, generateId, fetch, keepLastMessageOnError, maxSteps, }?: UseChatOptions): UseChatHelpers & {
73
- addToolResult: ({ toolCallId, result, }: {
74
- toolCallId: string;
75
- result: any;
76
- }) => void;
77
- };
78
-
79
- type UseCompletionHelpers = {
80
- /** The current completion result */
81
- completion: Readable<string>;
82
- /** The error object of the API request */
83
- error: Readable<undefined | Error>;
84
- /**
85
- * Send a new prompt to the API endpoint and update the completion state.
86
- */
87
- complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
88
- /**
89
- * Abort the current API request but keep the generated tokens.
90
- */
91
- stop: () => void;
92
- /**
93
- * Update the `completion` state locally.
94
- */
95
- setCompletion: (completion: string) => void;
96
- /** The current value of the input */
97
- input: Writable<string>;
98
- /**
99
- * Form submission handler to automatically reset input and append a user message
100
- * @example
101
- * ```jsx
102
- * <form onSubmit={handleSubmit}>
103
- * <input onChange={handleInputChange} value={input} />
104
- * </form>
105
- * ```
106
- */
107
- handleSubmit: (event?: {
108
- preventDefault?: () => void;
109
- }) => void;
110
- /** Whether the API request is in progress */
111
- isLoading: Readable<boolean | undefined>;
112
- /** Additional data added on the server via StreamData */
113
- data: Readable<JSONValue[] | undefined>;
114
- };
115
- declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamProtocol, onResponse, onFinish, onError, fetch, }?: UseCompletionOptions): UseCompletionHelpers;
116
-
117
- type UseAssistantHelpers = {
118
- /**
119
- * The current array of chat messages.
120
- */
121
- messages: Readable<Message[]>;
122
- /**
123
- * Update the message store with a new array of messages.
124
- */
125
- setMessages: (messages: Message[]) => void;
126
- /**
127
- * The current thread ID.
128
- */
129
- threadId: Readable<string | undefined>;
130
- /**
131
- * The current value of the input field.
132
- */
133
- input: Writable<string>;
134
- /**
135
- * Append a user message to the chat list. This triggers the API call to fetch
136
- * the assistant's response.
137
- * @param message The message to append
138
- * @param requestOptions Additional options to pass to the API call
139
- */
140
- append: (message: Message | CreateMessage, requestOptions?: {
141
- data?: Record<string, string>;
142
- }) => Promise<void>;
143
- /**
144
- Abort the current request immediately, keep the generated tokens if any.
145
- */
146
- stop: () => void;
147
- /**
148
- * Form submission handler that automatically resets the input field and appends a user message.
149
- */
150
- submitMessage: (event?: {
151
- preventDefault?: () => void;
152
- }, requestOptions?: {
153
- data?: Record<string, string>;
154
- }) => Promise<void>;
155
- /**
156
- * The current status of the assistant. This can be used to show a loading indicator.
157
- */
158
- status: Readable<AssistantStatus>;
159
- /**
160
- * The error thrown during the assistant message processing, if any.
161
- */
162
- error: Readable<undefined | Error>;
163
- };
164
- declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, fetch, }: UseAssistantOptions): UseAssistantHelpers;
165
-
166
- export { UseAssistantHelpers, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useAssistant, useChat, useCompletion };
1
+ export { Chat, type ChatOptions, type CreateMessage, type Message, type UIMessage, } from './chat.svelte.js';
2
+ export { StructuredObject as Experimental_StructuredObject, type Experimental_StructuredObjectOptions, } from './structured-object.svelte.js';
3
+ export { Completion, type CompletionOptions } from './completion.svelte.js';
4
+ export { createAIContext } from './context-provider.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,KAAK,SAAS,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,gBAAgB,IAAI,6BAA6B,EACjD,KAAK,oCAAoC,GAC1C,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}