modifywithai 1.10.0 → 2.2.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.
Files changed (39) hide show
  1. package/README.md +145 -0
  2. package/dist/assistant/index.d.ts +3 -0
  3. package/dist/assistant/index.js +1 -0
  4. package/dist/assistant-7f9B_gWg.js +2 -0
  5. package/dist/assistant-nextjs/api.d.ts +42 -0
  6. package/dist/assistant-nextjs/api.js +1 -0
  7. package/dist/assistant-remix/api.d.ts +46 -0
  8. package/dist/assistant-remix/api.js +1 -0
  9. package/dist/assistant-tanstack-start/api.d.ts +56 -0
  10. package/dist/assistant-tanstack-start/api.js +1 -0
  11. package/dist/index-B2dmSvFt.d.ts +1272 -0
  12. package/dist/index.d.ts +3 -69
  13. package/dist/index.js +1 -1
  14. package/dist/types-C7I0JuqF.d.ts +344 -0
  15. package/dist/utils-DQD-DMi0.js +1 -0
  16. package/package.json +67 -20
  17. package/dist/index-Dp00MJvS.d.ts +0 -391
  18. package/dist/nextjs/api.d.ts +0 -67
  19. package/dist/nextjs/api.js +0 -1
  20. package/dist/nextjs/shims.d.ts +0 -13
  21. package/dist/nextjs/shims.js +0 -1
  22. package/dist/react/index.d.ts +0 -3
  23. package/dist/react/index.js +0 -1
  24. package/dist/react-CREl6aTM.js +0 -1
  25. package/dist/remix/api.d.ts +0 -45
  26. package/dist/remix/api.js +0 -1
  27. package/dist/remix/index.d.ts +0 -38
  28. package/dist/remix/index.js +0 -1
  29. package/dist/remix/shims.d.ts +0 -14
  30. package/dist/remix/shims.js +0 -1
  31. package/dist/shims-C5D8K0uz.js +0 -191
  32. package/dist/tanstack-start/api.d.ts +0 -43
  33. package/dist/tanstack-start/api.js +0 -1
  34. package/dist/tanstack-start/index.d.ts +0 -33
  35. package/dist/tanstack-start/index.js +0 -1
  36. package/dist/tanstack-start/shims.d.ts +0 -15
  37. package/dist/tanstack-start/shims.js +0 -1
  38. package/dist/types-D83LZSks.d.ts +0 -190
  39. package/dist/types-V6wytIkL.js +0 -1
package/dist/index.d.ts CHANGED
@@ -1,69 +1,3 @@
1
- import { _ as ModifyWithAIOptions, a as DisableResponseSchema, c as EnableResponseSchema, d as ModificationSchema, f as ModificationToggleOptions, g as ModifyWithAIArgs, h as ModifyResponseSchema, i as DisableResponse, l as ListModificationsArgs, m as ModifyResponse, n as ApiErrorSchema, o as EnableModificationArgs, p as ModificationsListSchema, r as DisableModificationArgs, s as EnableResponse, t as ApiError, u as Modification } from "./types-D83LZSks.js";
2
-
3
- //#region src/core.d.ts
4
- /**
5
- * Fetch the list of modifications for a given MWAI instance
6
- *
7
- * @example
8
- * ```ts
9
- * const modifications = await listModifications({ id: "your-mwai-id" })
10
- * console.log(modifications)
11
- * ```
12
- */
13
- declare function listModifications({
14
- id
15
- }: ListModificationsArgs): Promise<Modification[]>;
16
- /**
17
- * Submit a modification request to ModifyWithAI
18
- *
19
- * @example
20
- * ```ts
21
- * const result = await modifyWithAI({
22
- * id: "your-mwai-id",
23
- * prompt: "Change the button color to blue"
24
- * })
25
- * ```
26
- */
27
- declare function modifyWithAI({
28
- id,
29
- prompt
30
- }: ModifyWithAIArgs, options?: ModifyWithAIOptions): Promise<{
31
- modificationId?: string;
32
- error?: Error;
33
- }>;
34
- /**
35
- * Enable a modification for the current user
36
- *
37
- * @example
38
- * ```ts
39
- * const result = await enableModification({
40
- * modificationId: "mod-123"
41
- * })
42
- * ```
43
- */
44
- declare function enableModification({
45
- modificationId
46
- }: EnableModificationArgs, options?: ModificationToggleOptions): Promise<{
47
- success: boolean;
48
- data?: EnableResponse;
49
- error?: Error;
50
- }>;
51
- /**
52
- * Disable a modification for the current user
53
- *
54
- * @example
55
- * ```ts
56
- * const result = await disableModification({
57
- * modificationId: "mod-123"
58
- * })
59
- * ```
60
- */
61
- declare function disableModification({
62
- modificationId
63
- }: DisableModificationArgs, options?: ModificationToggleOptions): Promise<{
64
- success: boolean;
65
- data?: DisableResponse;
66
- error?: Error;
67
- }>;
68
- //#endregion
69
- export { type ApiError, ApiErrorSchema, type DisableModificationArgs, type DisableResponse, DisableResponseSchema, type EnableModificationArgs, type EnableResponse, EnableResponseSchema, type ListModificationsArgs, type Modification, ModificationSchema, type ModificationToggleOptions, ModificationsListSchema, type ModifyResponse, ModifyResponseSchema, type ModifyWithAIArgs, type ModifyWithAIOptions, disableModification, enableModification, listModifications, modifyWithAI };
1
+ import { S as UseDynamicUIReturn, _ as ToolActionSchema, a as AssistantConfig, b as UseAssistantTokenOptions, c as DynamicButton, d as DynamicUITree, f as TokenRequest, g as ToolAction, h as TokenResponseSchema, i as ActionOptionSchema, l as DynamicButtonGroup, m as TokenResponse, n as ActionDefinitionSchema, o as ChatStatus, p as TokenRequestSchema, r as ActionOption, s as CreateAssistantTokenHandlerOptions, t as ActionDefinition, u as DynamicUIElement, v as UseAssistantOptions, x as UseAssistantTokenReturn, y as UseAssistantReturn } from "./types-C7I0JuqF.js";
2
+ import { $ as MessageContentProps, A as PromptInputFooterProps, At as ConfirmationActions, B as DrawerContentProps, Bt as AssistantMessages, C as TaskProps, Ct as ConversationScrollButton, D as PromptInputButton, Dt as ConfirmationAcceptedProps, E as PromptInput, Et as ConfirmationAccepted, F as PromptInputTextarea, Ft as ConfirmationRequest, G as DrawerPortal, H as DrawerFooter, I as PromptInputTextareaProps, It as ConfirmationRequestProps, J as Collapsible, K as DrawerTitle, L as Drawer, Lt as ConfirmationTitle, M as PromptInputProps, Mt as ConfirmationProps, N as PromptInputSubmit, Nt as ConfirmationRejected, O as PromptInputButtonProps, Ot as ConfirmationAction, P as PromptInputSubmitProps, Pt as ConfirmationRejectedProps, Q as MessageContent, R as DrawerClose, Rt as ConfirmationTitleProps, S as TaskItemProps, St as ConversationProps, T as TaskTriggerProps, Tt as Confirmation, U as DrawerHeader, V as DrawerDescription, Vt as AssistantMessagesProps, W as DrawerOverlay, X as CollapsibleTrigger, Y as CollapsibleContent, Z as Message, _ as TaskContent, _t as Conversation, a as useToolExecution, at as DateFieldRenderer, b as TaskItemFile, bt as ConversationEmptyState, c as useDynamicUIToolExecution, ct as TextFieldRenderer, d as useAssistant, dt as DynamicButtonRenderer, et as MessageProps, f as AssistantContextValue, ft as dynamicUIRegistry, g as Task, gt as DynamicActionModalProps, h as useAssistantContext, ht as DynamicActionModal, i as UseToolExecutionOptions, it as AssistantFormRendererProps, j as PromptInputMessage, jt as ConfirmationActionsProps, k as PromptInputFooter, kt as ConfirmationActionProps, l as UseDynamicUIOptions, lt as defaultFormRegistry, m as AssistantProviderProps, mt as DynamicUIProps, n as AssistantRoot, nt as MessageResponseProps, o as useAssistantToken, ot as FormRenderer, p as AssistantProvider, pt as DynamicUI, q as DrawerTrigger, r as AssistantRootProps, rt as AssistantFormRenderer, s as UseDynamicUIToolExecutionOptions, st as TextAreaRenderer, t as cn, tt as MessageResponse, u as useDynamicUI, ut as DynamicButtonGroupRenderer, v as TaskContentProps, vt as ConversationContent, w as TaskTrigger, wt as ConversationScrollButtonProps, x as TaskItemFileProps, xt as ConversationEmptyStateProps, y as TaskItem, yt as ConversationContentProps, z as DrawerContent, zt as ToolUIPartApproval } from "./index-B2dmSvFt.js";
3
+ export { ActionDefinition, ActionDefinitionSchema, ActionOption, ActionOptionSchema, AssistantConfig, AssistantContextValue, AssistantFormRenderer, AssistantFormRendererProps, AssistantMessages, AssistantMessagesProps, AssistantProvider, AssistantProviderProps, AssistantRoot, AssistantRootProps, ChatStatus, Collapsible, CollapsibleContent, CollapsibleTrigger, Confirmation, ConfirmationAccepted, ConfirmationAcceptedProps, ConfirmationAction, ConfirmationActionProps, ConfirmationActions, ConfirmationActionsProps, ConfirmationProps, ConfirmationRejected, ConfirmationRejectedProps, ConfirmationRequest, ConfirmationRequestProps, ConfirmationTitle, ConfirmationTitleProps, Conversation, ConversationContent, ConversationContentProps, ConversationEmptyState, ConversationEmptyStateProps, ConversationProps, ConversationScrollButton, ConversationScrollButtonProps, CreateAssistantTokenHandlerOptions, DateFieldRenderer, Drawer, DrawerClose, DrawerContent, DrawerContentProps, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DynamicActionModal, DynamicActionModalProps, DynamicButton, DynamicButtonGroup, DynamicButtonGroupRenderer, DynamicButtonRenderer, DynamicUI, DynamicUIElement, DynamicUIProps, DynamicUITree, FormRenderer, Message, MessageContent, MessageContentProps, MessageProps, MessageResponse, MessageResponseProps, PromptInput, PromptInputButton, PromptInputButtonProps, PromptInputFooter, PromptInputFooterProps, PromptInputMessage, PromptInputProps, PromptInputSubmit, PromptInputSubmitProps, PromptInputTextarea, PromptInputTextareaProps, Task, TaskContent, TaskContentProps, TaskItem, TaskItemFile, TaskItemFileProps, TaskItemProps, TaskProps, TaskTrigger, TaskTriggerProps, TextAreaRenderer, TextFieldRenderer, TokenRequest, TokenRequestSchema, TokenResponse, TokenResponseSchema, ToolAction, ToolActionSchema, ToolUIPartApproval, UseAssistantOptions, UseAssistantReturn, UseAssistantTokenOptions, UseAssistantTokenReturn, UseDynamicUIOptions, UseDynamicUIReturn, UseDynamicUIToolExecutionOptions, UseToolExecutionOptions, cn, defaultFormRegistry, dynamicUIRegistry, useAssistant, useAssistantContext, useAssistantToken, useDynamicUI, useDynamicUIToolExecution, useToolExecution };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,i as t,n,o as r,r as i,t as a}from"./types-V6wytIkL.js";async function o({id:t}){let n=await fetch(`/api/mwai/api/list`);if(!n.ok)throw Error(`Failed to fetch modifications`);let r=await n.json();return e.parse(r)}async function s({id:e,prompt:t},n){let i=t.trim();if(!i){let e=Error(`Prompt cannot be empty`);return n?.onError?.(e),{error:e}}try{let e=await fetch(`/api/mwai/api/modify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:i})});if(!e.ok){let t=await e.json().catch(()=>({})),n=a.safeParse(t),r=n.success&&(n.data.message||n.data.error)||`Failed to submit modification`;throw Error(r)}let t=await e.json(),o=r.parse(t);return n?.onSuccess?.(),{modificationId:o.modificationId}}catch(e){let t=e instanceof Error?e:Error(`Unknown error`);return n?.onError?.(t),{error:t}}}async function c({modificationId:e},t){try{let n=await fetch(`/api/mwai/api/enable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!n.ok){let e=await n.json().catch(()=>({})),t=a.safeParse(e),r=t.success&&(t.data.message||t.data.error)||`Failed to enable modification`;throw Error(r)}let r=await n.json(),o=i.parse(r);return t?.onSuccess?.(),{success:!0,data:o}}catch(e){let n=e instanceof Error?e:Error(`Unknown error`);return t?.onError?.(n),{success:!1,error:n}}}async function l({modificationId:e},t){try{let r=await fetch(`/api/mwai/api/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!r.ok){let e=await r.json().catch(()=>({})),t=a.safeParse(e),n=t.success&&(t.data.message||t.data.error)||`Failed to disable modification`;throw Error(n)}let i=await r.json(),o=n.parse(i);return t?.onSuccess?.(),{success:!0,data:o}}catch(e){let n=e instanceof Error?e:Error(`Unknown error`);return t?.onError?.(n),{success:!1,error:n}}}export{a as ApiErrorSchema,n as DisableResponseSchema,i as EnableResponseSchema,t as ModificationSchema,e as ModificationsListSchema,r as ModifyResponseSchema,l as disableModification,c as enableModification,o as listModifications,s as modifyWithAI};
1
+ import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as C,X as w,Y as T,Z as E,_ as D,a as O,at as k,b as A,c as j,ct as M,d as N,et as P,f as F,g as I,h as L,i as R,it as z,j as B,k as V,l as H,lt as U,m as W,n as G,nt as K,o as q,ot as J,p as Y,q as X,r as Z,rt as Q,s as $,st as ee,t as te,tt as ne,u as re,v as ie,w as ae,x as oe,y as se,z as ce}from"./assistant-7f9B_gWg.js";export{k as ActionDefinitionSchema,J as ActionOptionSchema,s as AssistantFormRenderer,m as AssistantMessages,r as AssistantProvider,te as AssistantRoot,ce as Collapsible,n as CollapsibleContent,S as CollapsibleTrigger,E as Confirmation,_ as ConfirmationAccepted,e as ConfirmationAction,P as ConfirmationActions,ne as ConfirmationRejected,K as ConfirmationRequest,Q as ConfirmationTitle,V as Conversation,t as ConversationContent,B as ConversationEmptyState,p as ConversationScrollButton,d as DateFieldRenderer,$ as Drawer,j as DrawerClose,H as DrawerContent,re as DrawerDescription,N as DrawerFooter,F as DrawerHeader,Y as DrawerOverlay,W as DrawerPortal,L as DrawerTitle,I as DrawerTrigger,h as DynamicActionModal,ie as DynamicButtonGroupRenderer,se as DynamicButtonRenderer,D as DynamicUI,X as FormRenderer,c as Message,x as MessageContent,C as MessageResponse,G as PromptInput,Z as PromptInputButton,R as PromptInputFooter,O as PromptInputSubmit,q as PromptInputTextarea,g as Task,o as TaskContent,l as TaskItem,f as TaskItemFile,v as TaskTrigger,u as TextAreaRenderer,T as TextFieldRenderer,ee as TokenRequestSchema,M as TokenResponseSchema,U as ToolActionSchema,z as cn,w as defaultFormRegistry,A as dynamicUIRegistry,b as useAssistant,ae as useAssistantContext,i as useAssistantToken,y as useDynamicUI,oe as useDynamicUIToolExecution,a as useToolExecution};
@@ -0,0 +1,344 @@
1
+ import { z } from "zod";
2
+ import * as ai0 from "ai";
3
+
4
+ //#region src/assistant/types.d.ts
5
+ /**
6
+ * Schema for action option definition
7
+ */
8
+ declare const ActionOptionSchema: z.ZodObject<{
9
+ type: z.ZodString;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ required: z.ZodOptional<z.ZodBoolean>;
12
+ }, z.core.$strip>;
13
+ /**
14
+ * Schema for action definition - describes an action the assistant can perform
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const addTodoAction: ActionDefinition = {
19
+ * name: "addTodo",
20
+ * description: "Add a new todo item",
21
+ * options: {
22
+ * text: { type: "string", description: "The todo title", required: true },
23
+ * dueDate: { type: "string", description: "Due date in ISO format" },
24
+ * },
25
+ * approvalRequired: false,
26
+ * }
27
+ * ```
28
+ */
29
+ declare const ActionDefinitionSchema: z.ZodObject<{
30
+ name: z.ZodString;
31
+ description: z.ZodString;
32
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
33
+ type: z.ZodString;
34
+ description: z.ZodOptional<z.ZodString>;
35
+ required: z.ZodOptional<z.ZodBoolean>;
36
+ }, z.core.$strip>>>;
37
+ approvalRequired: z.ZodOptional<z.ZodBoolean>;
38
+ }, z.core.$strip>;
39
+ /**
40
+ * Schema for a tool action - an action invoked by the assistant
41
+ */
42
+ declare const ToolActionSchema: z.ZodObject<{
43
+ name: z.ZodString;
44
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ }, z.core.$strip>;
46
+ /**
47
+ * Schema for token response from the server
48
+ */
49
+ declare const TokenResponseSchema: z.ZodObject<{
50
+ token: z.ZodString;
51
+ expiresAt: z.ZodNumber;
52
+ }, z.core.$strip>;
53
+ /**
54
+ * Schema for token request body
55
+ */
56
+ declare const TokenRequestSchema: z.ZodObject<{
57
+ endUserId: z.ZodString;
58
+ availableActions: z.ZodArray<z.ZodObject<{
59
+ name: z.ZodString;
60
+ description: z.ZodString;
61
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
62
+ type: z.ZodString;
63
+ description: z.ZodOptional<z.ZodString>;
64
+ required: z.ZodOptional<z.ZodBoolean>;
65
+ }, z.core.$strip>>>;
66
+ approvalRequired: z.ZodOptional<z.ZodBoolean>;
67
+ }, z.core.$strip>>;
68
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
69
+ }, z.core.$strip>;
70
+ /**
71
+ * Defines the schema for an action option
72
+ */
73
+ type ActionOption = z.infer<typeof ActionOptionSchema>;
74
+ /**
75
+ * Defines an action the assistant can perform
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const actions: ActionDefinition[] = [
80
+ * {
81
+ * name: "addTodo",
82
+ * description: "Add a new todo item",
83
+ * options: {
84
+ * text: { type: "string", description: "The todo title", required: true },
85
+ * },
86
+ * },
87
+ * {
88
+ * name: "deleteTodo",
89
+ * description: "Delete a todo by ID",
90
+ * options: { id: { type: "string", required: true } },
91
+ * approvalRequired: true, // Requires user confirmation
92
+ * },
93
+ * ]
94
+ * ```
95
+ */
96
+ type ActionDefinition = z.infer<typeof ActionDefinitionSchema>;
97
+ /**
98
+ * Represents an action invoked by the assistant
99
+ */
100
+ type ToolAction = z.infer<typeof ToolActionSchema>;
101
+ /**
102
+ * Response from the token endpoint
103
+ */
104
+ type TokenResponse = z.infer<typeof TokenResponseSchema>;
105
+ /**
106
+ * Request body for the token endpoint
107
+ */
108
+ type TokenRequest = z.infer<typeof TokenRequestSchema>;
109
+ /**
110
+ * Options for the useAssistantToken hook
111
+ *
112
+ * @example
113
+ * ```tsx
114
+ * const { token, isLoading, error } = useAssistantToken({
115
+ * tokenEndpoint: "/api/mwai/token",
116
+ * endUserId: "user-123",
117
+ * availableActions: myActions,
118
+ * autoFetch: true,
119
+ * refreshBuffer: 30000,
120
+ * })
121
+ * ```
122
+ */
123
+ interface UseAssistantTokenOptions {
124
+ /** The endpoint to fetch tokens from */
125
+ tokenEndpoint: string;
126
+ /** The end user identifier */
127
+ endUserId: string;
128
+ /** Available actions for the assistant */
129
+ availableActions: ActionDefinition[];
130
+ /** Whether to automatically fetch token on mount (default: true) */
131
+ autoFetch?: boolean;
132
+ /** Time in ms before expiration to refresh token (default: 30000) */
133
+ refreshBuffer?: number;
134
+ }
135
+ /**
136
+ * Return type for the useAssistantToken hook
137
+ */
138
+ interface UseAssistantTokenReturn {
139
+ /** The current token, or null if not yet fetched */
140
+ token: string | null;
141
+ /** When the token expires (Unix timestamp in ms) */
142
+ expiresAt: number | null;
143
+ /** Whether a token fetch is in progress */
144
+ isLoading: boolean;
145
+ /** Error message if token fetch failed */
146
+ error: string | null;
147
+ /** Manually trigger a token fetch */
148
+ fetchToken: () => Promise<void>;
149
+ }
150
+ /**
151
+ * Configuration for the assistant
152
+ *
153
+ * @example
154
+ * ```tsx
155
+ * const config: AssistantConfig = {
156
+ * tokenEndpoint: "/api/mwai/token",
157
+ * apiUrl: "https://api.modifywithai.com",
158
+ * endUserId: "user-123",
159
+ * availableActions: myActions,
160
+ * }
161
+ * ```
162
+ */
163
+ interface AssistantConfig {
164
+ /** The endpoint to fetch tokens from (default: "/api/mwai/token") */
165
+ tokenEndpoint?: string;
166
+ /** The ModifyWithAI API URL (default: "https://api.modifywithai.com") */
167
+ apiUrl?: string;
168
+ /** The end user identifier */
169
+ endUserId: string;
170
+ /** Available actions for the assistant */
171
+ availableActions: ActionDefinition[];
172
+ }
173
+ /**
174
+ * Options for the useAssistant hook
175
+ *
176
+ * @example
177
+ * ```tsx
178
+ * const assistant = useAssistant({
179
+ * endUserId: "user-123",
180
+ * availableActions: myActions,
181
+ * getContext: () => ({ todos: myTodos }),
182
+ * onAction: (action) => handleAction(action),
183
+ * onError: (error) => console.error(error),
184
+ * })
185
+ * ```
186
+ */
187
+ interface UseAssistantOptions {
188
+ /** The endpoint to fetch tokens from (default: "/api/mwai/token") */
189
+ tokenEndpoint?: string;
190
+ /** The ModifyWithAI API URL (default: "https://api.modifywithai.com") */
191
+ apiUrl?: string;
192
+ /** The end user identifier */
193
+ endUserId: string;
194
+ /** Available actions for the assistant */
195
+ availableActions: ActionDefinition[];
196
+ /** Function to get fresh context for each request */
197
+ getContext?: () => Record<string, unknown>;
198
+ /** Called when the assistant invokes an action */
199
+ onAction?: (action: ToolAction) => void;
200
+ /** Called when an error occurs */
201
+ onError?: (error: Error) => void;
202
+ }
203
+ /**
204
+ * Chat status type from ai-sdk
205
+ */
206
+ type ChatStatus$1 = "submitted" | "streaming" | "ready" | "error";
207
+ /**
208
+ * Return type for the useAssistant hook
209
+ */
210
+ interface UseAssistantReturn {
211
+ /** The chat messages */
212
+ messages: ai0.UIMessage[];
213
+ /** Send a new message */
214
+ sendMessage: (message: {
215
+ text: string;
216
+ }) => void;
217
+ /** Current chat status */
218
+ status: ChatStatus$1;
219
+ /** Error if any occurred */
220
+ error: Error | null;
221
+ /** Current input value */
222
+ input: string;
223
+ /** Set the input value */
224
+ setInput: (value: string) => void;
225
+ /** Handle form submission */
226
+ handleSubmit: (e?: React.FormEvent) => void;
227
+ /** Add a tool approval response */
228
+ addToolApprovalResponse: (response: {
229
+ id: string;
230
+ approved: boolean;
231
+ }) => void;
232
+ /** Whether the assistant is ready (has token) */
233
+ isReady: boolean;
234
+ /** Token error if any */
235
+ tokenError: string | null;
236
+ /** Manually refresh the token */
237
+ refreshToken: () => Promise<void>;
238
+ }
239
+ /**
240
+ * Options for creating the Next.js token handler
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * // app/api/mwai/token/route.ts
245
+ * import { createAssistantTokenHandler } from "modifywithai/nextjs"
246
+ *
247
+ * export const POST = createAssistantTokenHandler({
248
+ * appId: process.env.MWAI_APP_ID!,
249
+ * // apiKey defaults to process.env.MWAI_API_KEY
250
+ * // apiUrl defaults to https://api.modifywithai.com
251
+ * })
252
+ * ```
253
+ */
254
+ interface CreateAssistantTokenHandlerOptions {
255
+ /** The ModifyWithAI app ID */
256
+ appId: string;
257
+ /** The API key (default: process.env.MWAI_API_KEY) */
258
+ apiKey?: string;
259
+ /** The API URL (default: https://api.modifywithai.com) */
260
+ apiUrl?: string;
261
+ /**
262
+ * Custom function to extract the end user ID from the request.
263
+ * If not provided, endUserId must be included in the request body.
264
+ */
265
+ getEndUserId?: (request: Request) => Promise<string | null>;
266
+ }
267
+ /**
268
+ * Button definition for DynamicUI
269
+ */
270
+ interface DynamicButton {
271
+ /** Unique identifier for the button */
272
+ id: string;
273
+ /** Display label for the button */
274
+ label: string;
275
+ /** Button variant for styling */
276
+ variant?: "default" | "destructive" | "outline" | "secondary" | "ghost";
277
+ /** Lucide icon name to display */
278
+ icon?: string;
279
+ /** Actions to execute when clicked (same structure as performActions) */
280
+ actions: ToolAction[];
281
+ /** Index signature for Record compatibility */
282
+ [key: string]: unknown;
283
+ }
284
+ /**
285
+ * Button group definition for organizing buttons
286
+ */
287
+ interface DynamicButtonGroup {
288
+ /** Unique identifier for the group */
289
+ id: string;
290
+ /** Optional label for the group */
291
+ label?: string;
292
+ /** Direction to lay out buttons */
293
+ direction?: "horizontal" | "vertical";
294
+ /** Index signature for Record compatibility */
295
+ [key: string]: unknown;
296
+ }
297
+ /**
298
+ * Element in the DynamicUI tree
299
+ * Compatible with UIElement from @json-render/core
300
+ */
301
+ interface DynamicUIElement {
302
+ /** Unique key for this element */
303
+ key: string;
304
+ /** Element type */
305
+ type: "DynamicButton" | "DynamicButtonGroup";
306
+ /** Props for the element - uses Record for json-render compatibility */
307
+ props: Record<string, unknown>;
308
+ /** Child element keys (for groups) */
309
+ children?: string[];
310
+ /** Parent element key */
311
+ parentKey?: string;
312
+ }
313
+ /**
314
+ * Persisted tree structure for DynamicUI
315
+ */
316
+ interface DynamicUITree {
317
+ /** Key of the root element */
318
+ root: string;
319
+ /** Map of element keys to element definitions */
320
+ elements: Record<string, DynamicUIElement>;
321
+ }
322
+ /**
323
+ * Return type for the useDynamicUI hook
324
+ */
325
+ interface UseDynamicUIReturn {
326
+ /** The current UI tree */
327
+ tree: DynamicUITree | null;
328
+ /** Whether the tree is still loading from localStorage */
329
+ isLoading: boolean;
330
+ /** Add a new button to the tree */
331
+ addButton: (button: DynamicButton, parentKey?: string) => void;
332
+ /** Remove a button from the tree */
333
+ removeButton: (buttonId: string) => void;
334
+ /** Update an existing button */
335
+ updateButton: (buttonId: string, updates: Partial<DynamicButton>) => void;
336
+ /** Add a new button group */
337
+ addGroup: (group: DynamicButtonGroup) => void;
338
+ /** Remove a button group */
339
+ removeGroup: (groupId: string) => void;
340
+ /** Clear all buttons and groups */
341
+ clearAll: () => void;
342
+ }
343
+ //#endregion
344
+ export { UseDynamicUIReturn as S, ToolActionSchema as _, AssistantConfig as a, UseAssistantTokenOptions as b, DynamicButton as c, DynamicUITree as d, TokenRequest as f, ToolAction as g, TokenResponseSchema as h, ActionOptionSchema as i, DynamicButtonGroup as l, TokenResponse as m, ActionDefinitionSchema as n, ChatStatus$1 as o, TokenRequestSchema as p, ActionOption as r, CreateAssistantTokenHandlerOptions as s, ActionDefinition as t, DynamicUIElement as u, UseAssistantOptions as v, UseAssistantTokenReturn as x, UseAssistantReturn as y };
@@ -0,0 +1 @@
1
+ import{customAlphabet as e}from"nanoid";const t=e(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`,22),n=e=>{let n=t();return e?`${e}_${n}`:n};export{n as t};
package/package.json CHANGED
@@ -1,47 +1,62 @@
1
1
  {
2
2
  "name": "modifywithai",
3
- "version": "1.10.0",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
- "types": "./src/index.ts",
5
+ "types": "./src/assistant/index.tsx",
6
6
  "exports": {
7
7
  ".": "./dist/index.js",
8
- "./nextjs/api": "./dist/nextjs/api.js",
9
- "./nextjs/shims": "./dist/nextjs/shims.js",
10
- "./react": "./dist/react/index.js",
11
- "./remix": "./dist/remix/index.js",
12
- "./remix/api": "./dist/remix/api.js",
13
- "./remix/shims": "./dist/remix/shims.js",
14
- "./tanstack-start": "./dist/tanstack-start/index.js",
15
- "./tanstack-start/api": "./dist/tanstack-start/api.js",
16
- "./tanstack-start/shims": "./dist/tanstack-start/shims.js",
8
+ "./assistant": "./dist/assistant/index.js",
9
+ "./assistant-nextjs/api": "./dist/assistant-nextjs/api.js",
10
+ "./assistant-remix/api": "./dist/assistant-remix/api.js",
11
+ "./assistant-tanstack-start/api": "./dist/assistant-tanstack-start/api.js",
17
12
  "./package.json": "./package.json"
18
13
  },
19
14
  "files": [
20
15
  "dist",
21
16
  "AGENTS.md"
22
17
  ],
18
+ "sideEffects": false,
23
19
  "scripts": {
24
- "build": "bun run --bun tsdown",
20
+ "build:css": "bun run scripts/build-shadow-css.ts",
21
+ "build": "bun run build:css && bun run --bun tsdown",
25
22
  "typecheck": "tsc --noEmit"
26
23
  },
27
24
  "devDependencies": {
28
- "@types/bun": "1.3.6",
29
- "@types/react": "^19.2.8",
25
+ "@bosh-code/tsdown-plugin-tailwindcss": "^1.0.1",
26
+ "@tailwindcss/node": "^4.1.18",
27
+ "@tailwindcss/oxide": "^4.1.18",
28
+ "@types/bun": "^1.3.8",
29
+ "@types/react": "^19.2.10",
30
30
  "@types/react-dom": "^19.2.3",
31
- "typescript": "^5.8.3",
32
- "tsdown": "^0.20.0-beta.2"
31
+ "tailwindcss": "^4.1.18",
32
+ "tsdown": "0.20.0",
33
+ "typescript": "^5.9.2"
33
34
  },
34
35
  "peerDependencies": {
35
- "react": "^18.0.0 || ^19.0.0",
36
+ "react": "^19.2.4",
37
+ "react-dom": "^18.0.0 || ^19.0.0",
36
38
  "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
37
39
  "@remix-run/node": "^2.0.0",
38
40
  "@remix-run/react": "^2.0.0",
39
41
  "react-router": "^7.0.0",
40
42
  "react-router-dom": "^6.0.0 || ^7.0.0",
41
43
  "@tanstack/react-router": "^1.0.0",
42
- "@tanstack/react-start": "^1.0.0"
44
+ "@tanstack/react-start": "^1.0.0",
45
+ "@ai-sdk/react": "^3.0.44",
46
+ "ai": "^6.0.42",
47
+ "streamdown": "^2.1.0",
48
+ "@radix-ui/react-collapsible": "^1.1.12",
49
+ "vaul-base": "^1.0.0",
50
+ "clsx": "^2.1.1",
51
+ "tailwind-merge": "^3.4.0",
52
+ "@json-render/react": "^0.2.0",
53
+ "@json-render/core": "^0.2.0",
54
+ "lucide-react": "^0.562.0"
43
55
  },
44
56
  "peerDependenciesMeta": {
57
+ "react-dom": {
58
+ "optional": true
59
+ },
45
60
  "next": {
46
61
  "optional": true
47
62
  },
@@ -62,10 +77,42 @@
62
77
  },
63
78
  "@tanstack/react-start": {
64
79
  "optional": true
80
+ },
81
+ "@ai-sdk/react": {
82
+ "optional": true
83
+ },
84
+ "ai": {
85
+ "optional": true
86
+ },
87
+ "streamdown": {
88
+ "optional": true
89
+ },
90
+ "@radix-ui/react-collapsible": {
91
+ "optional": true
92
+ },
93
+ "vaul-base": {
94
+ "optional": true
95
+ },
96
+ "clsx": {
97
+ "optional": true
98
+ },
99
+ "tailwind-merge": {
100
+ "optional": true
101
+ },
102
+ "@json-render/react": {
103
+ "optional": true
104
+ },
105
+ "@json-render/core": {
106
+ "optional": true
107
+ },
108
+ "lucide-react": {
109
+ "optional": true
65
110
  }
66
111
  },
67
112
  "dependencies": {
68
- "@tanstack/react-query": "^5.0.0",
69
- "zod": "^4.2.0"
113
+ "@tanstack/react-query": "^5.90.20",
114
+ "nanoid": "^5.1.6",
115
+ "rou3": "^0.7.12",
116
+ "zod": "^4.3.6"
70
117
  }
71
118
  }