modifywithai 1.9.0 → 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.
- package/README.md +145 -0
- package/dist/assistant/index.d.ts +3 -0
- package/dist/assistant/index.js +1 -0
- package/dist/assistant-NY2A-1_6.js +2 -0
- package/dist/assistant-nextjs/api.d.ts +42 -0
- package/dist/assistant-nextjs/api.js +1 -0
- package/dist/assistant-remix/api.d.ts +46 -0
- package/dist/assistant-remix/api.js +1 -0
- package/dist/assistant-tanstack-start/api.d.ts +56 -0
- package/dist/assistant-tanstack-start/api.js +1 -0
- package/dist/index-BiZCpmdI.d.ts +1227 -0
- package/dist/index.d.ts +3 -70
- package/dist/index.js +1 -1
- package/dist/types-CzieyGF2.d.ts +344 -0
- package/dist/utils-DQD-DMi0.js +1 -0
- package/package.json +115 -35
- package/dist/nextjs/api.d.ts +0 -67
- package/dist/nextjs/api.js +0 -1
- package/dist/nextjs/shims.d.ts +0 -13
- package/dist/nextjs/shims.js +0 -78
- package/dist/react/index.d.ts +0 -403
- package/dist/react/index.js +0 -1
- package/dist/types-BgiWGYKC.js +0 -1
- package/dist/types-DjksF7DU.d.ts +0 -135
package/dist/index.d.ts
CHANGED
|
@@ -1,70 +1,3 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Fetch the list of modifications for a given MWAI instance
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const modifications = await listModifications({ id: "your-mwai-id" })
|
|
11
|
-
* console.log(modifications)
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
declare function listModifications({
|
|
15
|
-
id
|
|
16
|
-
}: ListModificationsArgs): Promise<Modification[]>;
|
|
17
|
-
/**
|
|
18
|
-
* Submit a modification request to ModifyWithAI
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const result = await modifyWithAI({
|
|
23
|
-
* id: "your-mwai-id",
|
|
24
|
-
* prompt: "Change the button color to blue"
|
|
25
|
-
* })
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare function modifyWithAI({
|
|
29
|
-
id,
|
|
30
|
-
prompt
|
|
31
|
-
}: ModifyWithAIArgs, options?: ModifyWithAIOptions): Promise<{
|
|
32
|
-
modificationId?: string;
|
|
33
|
-
error?: Error;
|
|
34
|
-
}>;
|
|
35
|
-
/**
|
|
36
|
-
* Enable a modification for the current user
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* const result = await enableModification({
|
|
41
|
-
* modificationId: "mod-123"
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
declare function enableModification({
|
|
46
|
-
modificationId
|
|
47
|
-
}: EnableModificationArgs, options?: ModificationToggleOptions): Promise<{
|
|
48
|
-
success: boolean;
|
|
49
|
-
data?: EnableResponse;
|
|
50
|
-
error?: Error;
|
|
51
|
-
}>;
|
|
52
|
-
/**
|
|
53
|
-
* Disable a modification for the current user
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* const result = await disableModification({
|
|
58
|
-
* modificationId: "mod-123"
|
|
59
|
-
* })
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function disableModification({
|
|
63
|
-
modificationId
|
|
64
|
-
}: DisableModificationArgs, options?: ModificationToggleOptions): Promise<{
|
|
65
|
-
success: boolean;
|
|
66
|
-
data?: DisableResponse;
|
|
67
|
-
error?: Error;
|
|
68
|
-
}>;
|
|
69
|
-
//#endregion
|
|
70
|
-
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-CzieyGF2.js";
|
|
2
|
+
import { $ as MessageContentProps, A as PromptInputFooterProps, At as ConfirmationActions, B as DrawerContentProps, 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, 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-BiZCpmdI.js";
|
|
3
|
+
export { ActionDefinition, ActionDefinitionSchema, ActionOption, ActionOptionSchema, AssistantConfig, AssistantContextValue, AssistantFormRenderer, AssistantFormRendererProps, 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{
|
|
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,m as U,n as W,nt as G,o as K,ot as q,p as J,q as Y,r as X,rt as Z,s as Q,st as $,t as ee,tt as te,u as ne,v as re,w as ie,x as ae,y as oe,z as se}from"./assistant-NY2A-1_6.js";export{ee as ActionDefinitionSchema,W as ActionOptionSchema,s as AssistantFormRenderer,se as AssistantProvider,K as AssistantRoot,i as Collapsible,h as CollapsibleContent,V as CollapsibleTrigger,te as Confirmation,G as ConfirmationAccepted,Z as ConfirmationAction,z as ConfirmationActions,k as ConfirmationRejected,q as ConfirmationRequest,$ as ConfirmationTitle,E as Conversation,_ as ConversationContent,e as ConversationEmptyState,P as ConversationScrollButton,d as DateFieldRenderer,D as Drawer,re as DrawerClose,oe as DrawerContent,A as DrawerDescription,ae as DrawerFooter,y as DrawerHeader,r as DrawerOverlay,ie as DrawerPortal,b as DrawerTitle,a as DrawerTrigger,C as DynamicActionModal,g as DynamicButtonGroupRenderer,o as DynamicButtonRenderer,m as DynamicUI,Y as FormRenderer,t as Message,B as MessageContent,p as MessageResponse,F as PromptInput,J as PromptInputButton,U as PromptInputFooter,L as PromptInputSubmit,I as PromptInputTextarea,Q as Task,j as TaskContent,H as TaskItem,ne as TaskItemFile,N as TaskTrigger,u as TextAreaRenderer,T as TextFieldRenderer,X as TokenRequestSchema,R as TokenResponseSchema,O as ToolActionSchema,M as cn,w as defaultFormRegistry,l as dynamicUIRegistry,S as useAssistant,n as useAssistantContext,x as useAssistantToken,v as useDynamicUI,f as useDynamicUIToolExecution,c as useToolExecution};
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import * as ai0 from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
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,37 +1,117 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
"name": "modifywithai",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./src/assistant/index.tsx",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/index.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",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"AGENTS.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build:css": "bun run scripts/build-shadow-css.ts",
|
|
20
|
+
"build": "bun run build:css && bun run --bun tsdown",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@bosh-code/tsdown-plugin-tailwindcss": "^1.0.1",
|
|
25
|
+
"@tailwindcss/node": "^4.1.18",
|
|
26
|
+
"@tailwindcss/oxide": "^4.1.18",
|
|
27
|
+
"@types/bun": "^1.3.6",
|
|
28
|
+
"@types/react": "^19.2.9",
|
|
29
|
+
"@types/react-dom": "^19.2.3",
|
|
30
|
+
"tailwindcss": "^4.1.18",
|
|
31
|
+
"tsdown": "0.20.0",
|
|
32
|
+
"typescript": "^5.9.2"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
36
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
37
|
+
"next": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
38
|
+
"@remix-run/node": "^2.0.0",
|
|
39
|
+
"@remix-run/react": "^2.0.0",
|
|
40
|
+
"react-router": "^7.0.0",
|
|
41
|
+
"react-router-dom": "^6.0.0 || ^7.0.0",
|
|
42
|
+
"@tanstack/react-router": "^1.0.0",
|
|
43
|
+
"@tanstack/react-start": "^1.0.0",
|
|
44
|
+
"@ai-sdk/react": "^3.0.44",
|
|
45
|
+
"ai": "^6.0.42",
|
|
46
|
+
"streamdown": "^2.1.0",
|
|
47
|
+
"@radix-ui/react-collapsible": "^1.1.12",
|
|
48
|
+
"vaul-base": "^1.0.0",
|
|
49
|
+
"clsx": "^2.1.1",
|
|
50
|
+
"tailwind-merge": "^3.4.0",
|
|
51
|
+
"@json-render/react": "^0.2.0",
|
|
52
|
+
"@json-render/core": "^0.2.0",
|
|
53
|
+
"lucide-react": "^0.562.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"react-dom": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"next": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"@remix-run/node": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"@remix-run/react": {
|
|
66
|
+
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"react-router": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"react-router-dom": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@tanstack/react-router": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@tanstack/react-start": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"@ai-sdk/react": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"ai": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"streamdown": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@radix-ui/react-collapsible": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"vaul-base": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"clsx": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"tailwind-merge": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@json-render/react": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"@json-render/core": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"lucide-react": {
|
|
108
|
+
"optional": true
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"dependencies": {
|
|
112
|
+
"@tanstack/react-query": "^5.90.20",
|
|
113
|
+
"nanoid": "^5.1.6",
|
|
114
|
+
"rou3": "^0.7.12",
|
|
115
|
+
"zod": "^4.3.6"
|
|
116
|
+
}
|
|
37
117
|
}
|
package/dist/nextjs/api.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from "next/server";
|
|
2
|
-
|
|
3
|
-
//#region src/nextjs/api.d.ts
|
|
4
|
-
type CreateApiProxyHandlerOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* The app ID for this MWAI application
|
|
7
|
-
* This identifies your app in the modifywithai system
|
|
8
|
-
*/
|
|
9
|
-
appId: string;
|
|
10
|
-
/**
|
|
11
|
-
* Base URL of the modifywithai service
|
|
12
|
-
* @default "https://modifywithai.com"
|
|
13
|
-
*/
|
|
14
|
-
baseUrl?: string;
|
|
15
|
-
/**
|
|
16
|
-
* API key for authenticating with the modifywithai service
|
|
17
|
-
* @default process.env.MWAI_API_KEY
|
|
18
|
-
*/
|
|
19
|
-
apiKey?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Function to get the end user's ID from the request
|
|
22
|
-
* This will be injected into API calls that require endUserId
|
|
23
|
-
*/
|
|
24
|
-
getEndUserId: (request: NextRequest) => Promise<string | null>;
|
|
25
|
-
};
|
|
26
|
-
declare function generateStaticParams(): Promise<{
|
|
27
|
-
path: "list" | "enable" | "disable" | "modify" | "status";
|
|
28
|
-
}[]>;
|
|
29
|
-
declare function createNextjsHandler(options: CreateApiProxyHandlerOptions): {
|
|
30
|
-
GET: (request: NextRequest, {
|
|
31
|
-
params
|
|
32
|
-
}: {
|
|
33
|
-
params: Promise<{
|
|
34
|
-
path: string;
|
|
35
|
-
}>;
|
|
36
|
-
}) => Promise<Response>;
|
|
37
|
-
POST: (request: NextRequest, {
|
|
38
|
-
params
|
|
39
|
-
}: {
|
|
40
|
-
params: Promise<{
|
|
41
|
-
path: string;
|
|
42
|
-
}>;
|
|
43
|
-
}) => Promise<Response>;
|
|
44
|
-
PUT: (request: NextRequest, {
|
|
45
|
-
params
|
|
46
|
-
}: {
|
|
47
|
-
params: Promise<{
|
|
48
|
-
path: string;
|
|
49
|
-
}>;
|
|
50
|
-
}) => Promise<Response>;
|
|
51
|
-
PATCH: (request: NextRequest, {
|
|
52
|
-
params
|
|
53
|
-
}: {
|
|
54
|
-
params: Promise<{
|
|
55
|
-
path: string;
|
|
56
|
-
}>;
|
|
57
|
-
}) => Promise<Response>;
|
|
58
|
-
DELETE: (request: NextRequest, {
|
|
59
|
-
params
|
|
60
|
-
}: {
|
|
61
|
-
params: Promise<{
|
|
62
|
-
path: string;
|
|
63
|
-
}>;
|
|
64
|
-
}) => Promise<Response>;
|
|
65
|
-
};
|
|
66
|
-
//#endregion
|
|
67
|
-
export { createNextjsHandler, generateStaticParams };
|
package/dist/nextjs/api.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";const t=[`list`,`enable`,`disable`,`modify`,`status`],n={modify:{method:`POST`,inBody:!0,needsEndUserId:!0},disable:{method:`POST`,inBody:!0,needsEndUserId:!0},enable:{method:`POST`,inBody:!0,needsEndUserId:!0},list:{method:`GET`,inBody:!1,needsEndUserId:!1},status:{method:`GET`,inBody:!1,needsEndUserId:!1}};async function r(){return t.map(e=>({path:e}))}function i(r){let{appId:i,baseUrl:a=`https://modifywithai.com`,apiKey:o=process.env.MWAI_API_KEY,getEndUserId:s}=r;if(!o)throw Error(`MWAI API key is required. Provide it via the apiKey option or set the MWAI_API_KEY environment variable.`);async function c(r,{params:c}){let l=(await c).path;if(!t.includes(l))return e.json({error:`Not found`},{status:404});let u=n[l],d=await s(r);if(u.needsEndUserId&&!d)return e.json({error:`Unauthorized - end user ID required`},{status:401});let f=new URL(`/api/${l}`,a);r.nextUrl.searchParams.forEach((e,t)=>{f.searchParams.set(t,e)});let p=new Headers({"Content-Type":`application/json`,"x-api-key":o}),m;if(r.method===`POST`||r.method===`PUT`||r.method===`PATCH`)try{let e=await r.json();e.appId=i,u.needsEndUserId&&d&&(e.endUserId=d),m=JSON.stringify(e)}catch{let e={appId:i};u.needsEndUserId&&d&&(e.endUserId=d),m=JSON.stringify(e)}r.method===`GET`&&(f.searchParams.set(`appId`,i),d&&f.searchParams.set(`endUserId`,d));let h=await fetch(f.toString(),{method:r.method,headers:p,body:m}),g=await h.text();return new Response(g,{status:h.status,statusText:h.statusText,headers:{"Content-Type":h.headers.get(`Content-Type`)||`application/json`}})}return{GET:c,POST:c,PUT:c,PATCH:c,DELETE:c}}export{i as createNextjsHandler,r as generateStaticParams};
|