modifywithai 1.10.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.
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-NY2A-1_6.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-BiZCpmdI.d.ts +1227 -0
  12. package/dist/index.d.ts +3 -69
  13. package/dist/index.js +1 -1
  14. package/dist/types-CzieyGF2.d.ts +344 -0
  15. package/dist/utils-DQD-DMi0.js +1 -0
  16. package/package.json +65 -19
  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
@@ -1,391 +0,0 @@
1
- import { f as ModificationToggleOptions, w as UseRouterOptions, x as RouterResponse } from "./types-D83LZSks.js";
2
- import * as react0 from "react";
3
- import { ReactNode } from "react";
4
- import * as jsxRuntime from "react/jsx-runtime";
5
- import * as _tanstack_react_query0 from "@tanstack/react-query";
6
-
7
- //#region src/react/components.d.ts
8
- declare const useComponents: () => jsxRuntime.JSX.Element | null;
9
- declare const MWAIComponents: () => jsxRuntime.JSX.Element | null;
10
- //#endregion
11
- //#region src/react/head.d.ts
12
- declare const MWAIHead: ({
13
- basePath
14
- }?: {
15
- basePath?: string;
16
- }) => jsxRuntime.JSX.Element;
17
- //#endregion
18
- //#region src/react/hooks.d.ts
19
- /**
20
- * React hook for fetching the list of modifications
21
- * Polls every 10 seconds for updates
22
- * Automatically reloads the page when enabled modifications change
23
- *
24
- * @example
25
- * ```tsx
26
- * const { data, isLoading, error } = useList()
27
- * ```
28
- */
29
- declare function useList(): _tanstack_react_query0.UseQueryResult<{
30
- id: string;
31
- title: string | null;
32
- description: string | null;
33
- status: "error" | "pending" | "success";
34
- createdAt: number;
35
- updatedAt: number;
36
- enabled: boolean | null;
37
- }[], Error>;
38
- /**
39
- * React hook for routing modification requests to ModifyWithAI
40
- * Returns the router response, pending state, and a `submit` function
41
- *
42
- * @example
43
- * ```tsx
44
- * const { submit, routerResponse, reply, isPending } = useRouter()
45
- *
46
- * const handleSubmit = () => {
47
- * submit("Change the button color to blue")
48
- * }
49
- *
50
- * // Display the response
51
- * if (routerResponse?.route === "matched") {
52
- * console.log("Matched:", routerResponse.title)
53
- * }
54
- * ```
55
- */
56
- declare function useRouter(options?: UseRouterOptions): {
57
- variables: undefined;
58
- error: null;
59
- isError: false;
60
- isIdle: true;
61
- isSuccess: false;
62
- status: "idle";
63
- context: unknown;
64
- failureCount: number;
65
- failureReason: Error | null;
66
- isPaused: boolean;
67
- submittedAt: number;
68
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
69
- submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
70
- reset: () => void; /** The parsed router response */
71
- routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
72
- reply: string | null; /** Whether the router request is pending */
73
- isPending: boolean;
74
- } | {
75
- variables: string;
76
- error: null;
77
- isError: false;
78
- isIdle: false;
79
- isSuccess: false;
80
- status: "pending";
81
- context: unknown;
82
- failureCount: number;
83
- failureReason: Error | null;
84
- isPaused: boolean;
85
- submittedAt: number;
86
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
87
- submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
88
- reset: () => void; /** The parsed router response */
89
- routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
90
- reply: string | null; /** Whether the router request is pending */
91
- isPending: boolean;
92
- } | {
93
- error: Error;
94
- variables: string;
95
- isError: true;
96
- isIdle: false;
97
- isSuccess: false;
98
- status: "error";
99
- context: unknown;
100
- failureCount: number;
101
- failureReason: Error | null;
102
- isPaused: boolean;
103
- submittedAt: number;
104
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
105
- submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
106
- reset: () => void; /** The parsed router response */
107
- routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
108
- reply: string | null; /** Whether the router request is pending */
109
- isPending: boolean;
110
- } | {
111
- error: null;
112
- variables: string;
113
- isError: false;
114
- isIdle: false;
115
- isSuccess: true;
116
- status: "success";
117
- context: unknown;
118
- failureCount: number;
119
- failureReason: Error | null;
120
- isPaused: boolean;
121
- submittedAt: number;
122
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
123
- submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
124
- reset: () => void; /** The parsed router response */
125
- routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
126
- reply: string | null; /** Whether the router request is pending */
127
- isPending: boolean;
128
- };
129
- /**
130
- * React hook for enabling a modification
131
- * Returns mutation state and an `enable` function for enabling modifications
132
- *
133
- * @example
134
- * ```tsx
135
- * const { enable, isPending, isError, error } = useEnable()
136
- *
137
- * const handleEnable = () => {
138
- * enable("modification-id", {
139
- * onSuccess: () => console.log("Enabled!"),
140
- * onError: (err) => console.error(err),
141
- * })
142
- * }
143
- * ```
144
- */
145
- declare function useEnable(options?: ModificationToggleOptions): {
146
- data: undefined;
147
- variables: undefined;
148
- error: null;
149
- isError: false;
150
- isIdle: true;
151
- isPending: false;
152
- isSuccess: false;
153
- status: "idle";
154
- reset: () => void;
155
- context: unknown;
156
- failureCount: number;
157
- failureReason: Error | null;
158
- isPaused: boolean;
159
- submittedAt: number;
160
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
161
- message: string;
162
- modificationId: string;
163
- endUserId: string;
164
- }, Error, string, unknown>;
165
- enable: _tanstack_react_query0.UseMutateFunction<{
166
- message: string;
167
- modificationId: string;
168
- endUserId: string;
169
- }, Error, string, unknown>;
170
- } | {
171
- data: undefined;
172
- variables: string;
173
- error: null;
174
- isError: false;
175
- isIdle: false;
176
- isPending: true;
177
- isSuccess: false;
178
- status: "pending";
179
- reset: () => void;
180
- context: unknown;
181
- failureCount: number;
182
- failureReason: Error | null;
183
- isPaused: boolean;
184
- submittedAt: number;
185
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
186
- message: string;
187
- modificationId: string;
188
- endUserId: string;
189
- }, Error, string, unknown>;
190
- enable: _tanstack_react_query0.UseMutateFunction<{
191
- message: string;
192
- modificationId: string;
193
- endUserId: string;
194
- }, Error, string, unknown>;
195
- } | {
196
- data: undefined;
197
- error: Error;
198
- variables: string;
199
- isError: true;
200
- isIdle: false;
201
- isPending: false;
202
- isSuccess: false;
203
- status: "error";
204
- reset: () => void;
205
- context: unknown;
206
- failureCount: number;
207
- failureReason: Error | null;
208
- isPaused: boolean;
209
- submittedAt: number;
210
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
211
- message: string;
212
- modificationId: string;
213
- endUserId: string;
214
- }, Error, string, unknown>;
215
- enable: _tanstack_react_query0.UseMutateFunction<{
216
- message: string;
217
- modificationId: string;
218
- endUserId: string;
219
- }, Error, string, unknown>;
220
- } | {
221
- data: {
222
- message: string;
223
- modificationId: string;
224
- endUserId: string;
225
- };
226
- error: null;
227
- variables: string;
228
- isError: false;
229
- isIdle: false;
230
- isPending: false;
231
- isSuccess: true;
232
- status: "success";
233
- reset: () => void;
234
- context: unknown;
235
- failureCount: number;
236
- failureReason: Error | null;
237
- isPaused: boolean;
238
- submittedAt: number;
239
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
240
- message: string;
241
- modificationId: string;
242
- endUserId: string;
243
- }, Error, string, unknown>;
244
- enable: _tanstack_react_query0.UseMutateFunction<{
245
- message: string;
246
- modificationId: string;
247
- endUserId: string;
248
- }, Error, string, unknown>;
249
- };
250
- /**
251
- * React hook for disabling a modification
252
- * Returns mutation state and a `disable` function for disabling modifications
253
- *
254
- * @example
255
- * ```tsx
256
- * const { disable, isPending, isError, error } = useDisable()
257
- *
258
- * const handleDisable = () => {
259
- * disable("modification-id", {
260
- * onSuccess: () => console.log("Disabled!"),
261
- * onError: (err) => console.error(err),
262
- * })
263
- * }
264
- * ```
265
- */
266
- declare function useDisable(options?: ModificationToggleOptions): {
267
- data: undefined;
268
- variables: undefined;
269
- error: null;
270
- isError: false;
271
- isIdle: true;
272
- isPending: false;
273
- isSuccess: false;
274
- status: "idle";
275
- reset: () => void;
276
- context: unknown;
277
- failureCount: number;
278
- failureReason: Error | null;
279
- isPaused: boolean;
280
- submittedAt: number;
281
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
282
- message: string;
283
- modificationId: string;
284
- endUserId: string;
285
- }, Error, string, unknown>;
286
- disable: _tanstack_react_query0.UseMutateFunction<{
287
- message: string;
288
- modificationId: string;
289
- endUserId: string;
290
- }, Error, string, unknown>;
291
- } | {
292
- data: undefined;
293
- variables: string;
294
- error: null;
295
- isError: false;
296
- isIdle: false;
297
- isPending: true;
298
- isSuccess: false;
299
- status: "pending";
300
- reset: () => void;
301
- context: unknown;
302
- failureCount: number;
303
- failureReason: Error | null;
304
- isPaused: boolean;
305
- submittedAt: number;
306
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
307
- message: string;
308
- modificationId: string;
309
- endUserId: string;
310
- }, Error, string, unknown>;
311
- disable: _tanstack_react_query0.UseMutateFunction<{
312
- message: string;
313
- modificationId: string;
314
- endUserId: string;
315
- }, Error, string, unknown>;
316
- } | {
317
- data: undefined;
318
- error: Error;
319
- variables: string;
320
- isError: true;
321
- isIdle: false;
322
- isPending: false;
323
- isSuccess: false;
324
- status: "error";
325
- reset: () => void;
326
- context: unknown;
327
- failureCount: number;
328
- failureReason: Error | null;
329
- isPaused: boolean;
330
- submittedAt: number;
331
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
332
- message: string;
333
- modificationId: string;
334
- endUserId: string;
335
- }, Error, string, unknown>;
336
- disable: _tanstack_react_query0.UseMutateFunction<{
337
- message: string;
338
- modificationId: string;
339
- endUserId: string;
340
- }, Error, string, unknown>;
341
- } | {
342
- data: {
343
- message: string;
344
- modificationId: string;
345
- endUserId: string;
346
- };
347
- error: null;
348
- variables: string;
349
- isError: false;
350
- isIdle: false;
351
- isPending: false;
352
- isSuccess: true;
353
- status: "success";
354
- reset: () => void;
355
- context: unknown;
356
- failureCount: number;
357
- failureReason: Error | null;
358
- isPaused: boolean;
359
- submittedAt: number;
360
- mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
361
- message: string;
362
- modificationId: string;
363
- endUserId: string;
364
- }, Error, string, unknown>;
365
- disable: _tanstack_react_query0.UseMutateFunction<{
366
- message: string;
367
- modificationId: string;
368
- endUserId: string;
369
- }, Error, string, unknown>;
370
- };
371
- //#endregion
372
- //#region src/react/provider.d.ts
373
- declare const MWAIContext: react0.Context<string | null>;
374
- declare const MWAIProvider: ({
375
- appId,
376
- children
377
- }: {
378
- appId: string;
379
- children: ReactNode;
380
- }) => jsxRuntime.JSX.Element;
381
- //#endregion
382
- //#region src/react/query-keys.d.ts
383
- /**
384
- * Centralized query key factory for type-safe, consistent cache management
385
- */
386
- declare const mwaiQueryKeys: {
387
- readonly all: readonly ["mwai"];
388
- readonly modifications: () => readonly ["mwai", "modifications"];
389
- };
390
- //#endregion
391
- export { useEnable as a, MWAIHead as c, useDisable as i, MWAIComponents as l, MWAIContext as n, useList as o, MWAIProvider as r, useRouter as s, mwaiQueryKeys as t, useComponents as u };
@@ -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: "status" | "list" | "enable" | "disable" | "router";
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 };
@@ -1 +0,0 @@
1
- import{NextResponse as e}from"next/server";const t=[`list`,`enable`,`disable`,`router`,`status`],n={router:{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};
@@ -1,13 +0,0 @@
1
- //#region src/nextjs/shims.d.ts
2
- declare function generateStaticParams(): Promise<{
3
- path: string;
4
- }[]>;
5
- declare const GET: (_request: Request, {
6
- params
7
- }: {
8
- params: Promise<{
9
- path: string;
10
- }>;
11
- }) => Promise<Response>;
12
- //#endregion
13
- export { GET, generateStaticParams };
@@ -1 +0,0 @@
1
- import{t as e}from"../shims-C5D8K0uz.js";async function t(){return Object.keys(e).map(e=>({path:e}))}const n=async(t,{params:n})=>{let r=(await n).path;return new Response(e[r],{headers:{"Content-Type":`application/javascript`,"Cache-Control":`public, max-age=31536000, immutable`}})};export{n as GET,t as generateStaticParams};
@@ -1,3 +0,0 @@
1
- import { C as RouterRoute, S as RouterResponseSchema, a as DisableResponseSchema, b as RouterMatchedResponse, c as EnableResponseSchema, d as ModificationSchema, f as ModificationToggleOptions, i as DisableResponse, n as ApiErrorSchema, p as ModificationsListSchema, s as EnableResponse, t as ApiError, u as Modification, v as RouterCannotCreateResponse, w as UseRouterOptions, x as RouterResponse, y as RouterCreatingResponse } from "../types-D83LZSks.js";
2
- import { a as useEnable, c as MWAIHead, i as useDisable, l as MWAIComponents, n as MWAIContext, o as useList, r as MWAIProvider, s as useRouter, t as mwaiQueryKeys, u as useComponents } from "../index-Dp00MJvS.js";
3
- export { ApiError, ApiErrorSchema, DisableResponse, DisableResponseSchema, EnableResponse, EnableResponseSchema, MWAIComponents, MWAIContext, MWAIHead, MWAIProvider, Modification, ModificationSchema, ModificationToggleOptions, ModificationsListSchema, RouterCannotCreateResponse, RouterCreatingResponse, RouterMatchedResponse, RouterResponse, RouterResponseSchema, RouterRoute, UseRouterOptions, mwaiQueryKeys, useComponents, useDisable, useEnable, useList, useRouter };
@@ -1 +0,0 @@
1
- "use client";import{a as e,i as t,n,r,s as i,t as a}from"../types-V6wytIkL.js";import{a as o,c as s,i as c,l,n as u,o as d,r as f,s as p,t as m,u as h}from"../react-CREl6aTM.js";export{a as ApiErrorSchema,n as DisableResponseSchema,r as EnableResponseSchema,u as MWAIComponents,c as MWAIContext,m as MWAIHead,o as MWAIProvider,t as ModificationSchema,e as ModificationsListSchema,i as RouterResponseSchema,h as mwaiQueryKeys,f as useComponents,d as useDisable,p as useEnable,s as useList,l as useRouter};
@@ -1 +0,0 @@
1
- import{a as e,n as t,r as n,s as r,t as i}from"./types-V6wytIkL.js";import a from"next/image";import o from"next/link";import*as s from"next/navigation";import*as c from"react";import{createContext as l,useContext as u,useLayoutEffect as d,useRef as f,useState as p}from"react";import*as m from"react/jsx-runtime";import{Fragment as h,jsx as g}from"react/jsx-runtime";import*as _ from"react-dom";import*as v from"react-dom/client";import{QueryClient as y,QueryClientProvider as b,useMutation as x,useQuery as S,useQueryClient as C}from"@tanstack/react-query";const w={all:[`mwai`],modifications:()=>[...w.all,`modifications`]};function T(){let t=f(null);return S({queryKey:w.modifications(),queryFn:async()=>{let n=await fetch(`/api/mwai/api/list`);if(!n.ok)throw Error(`Failed to fetch modifications`);let r=await n.json(),i=e.parse(r),a=i.filter(e=>e.enabled&&e.status===`success`).map(e=>e.id),o=t.current;if(o!==null){let e=new Set(o),t=new Set(a);(o.length!==a.length||a.some(t=>!e.has(t))||o.some(e=>!t.has(e)))&&typeof window<`u`&&window.location.reload()}return t.current=a,i},refetchInterval:1e4})}function E(e){let t=C(),{mutate:n,data:a,isPending:o,reset:s,...c}=x({mutationFn:async e=>{let t=e.trim();if(!t)throw Error(`Prompt cannot be empty`);let n=await fetch(`/api/mwai/api/router`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:t})});if(!n.ok){let e=await n.json().catch(()=>({})),t=i.safeParse(e),r=t.success&&(t.data.message||t.data.error)||`Failed to submit modification`;throw Error(r)}let a=await n.json();return r.parse(a)},onSuccess:n=>{t.invalidateQueries({queryKey:w.modifications()}),e?.onSuccess?.(n)},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{submit:n,reset:s,routerResponse:a??null,reply:a?.textMessage??null,isPending:o,...c}}function D(e){let t=C(),{mutate:r,...a}=x({mutationFn:async e=>{let t=await fetch(`/api/mwai/api/enable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!t.ok){let e=await t.json().catch(()=>({})),n=i.safeParse(e),r=n.success&&(n.data.message||n.data.error)||`Failed to enable modification`;throw Error(r)}let r=await t.json();return n.parse(r)},onSuccess:()=>{t.invalidateQueries({queryKey:w.modifications()}),e?.onSuccess?.()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{enable:r,...a}}function O(e){let n=C(),{mutate:r,...a}=x({mutationFn:async e=>{let n=await fetch(`/api/mwai/api/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!n.ok){let e=await n.json().catch(()=>({})),t=i.safeParse(e),r=t.success&&(t.data.message||t.data.error)||`Failed to disable modification`;throw Error(r)}let r=await n.json();return t.parse(r)},onSuccess:()=>{n.invalidateQueries({queryKey:w.modifications()}),e?.onSuccess?.()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{disable:r,...a}}const k=l(null);function A(){return new y({defaultOptions:{queries:{staleTime:5e3,refetchOnWindowFocus:!1}}})}const j=({appId:e,children:t})=>{let[n]=p(A);return g(b,{client:n,children:g(k.Provider,{value:e,children:t})})},M=()=>{let e=u(k),[t,n]=p(null),{data:r}=T();return d(()=>{if(!e){console.error(`ModifyWithAI: No appId provided. Wrap your app with <MWAIProvider appId='your-app-id'>`);return}typeof window<`u`&&(window.__REACT__=c,window.__REACT_JSX_RUNTIME__=m,window.__REACT_DOM__=_,window.__REACT_DOM_CLIENT__=v,window.__NEXT_LINK__=o,window.__NEXT_IMAGE__=a,window.__NEXT_NAVIGATION__=s)},[e]),d(()=>{if(!e||!r)return;let t=Function(`url`,`return import(url)`),i=r.filter(e=>e.enabled&&e.status===`success`).map(e=>e.id);n([]),i.forEach(r=>{t(`https://bucket.modifywithai.com/${e}/${r}.js`).then(e=>n(t=>[...t||[],e.default])).catch(e=>console.error(`Failed to load external module:`,e))})},[e,r]),t?g(h,{children:t.map(e=>g(e,{},e.name))}):null},N=()=>M(),P=({basePath:e=`/api/mwai`}={})=>g(`script`,{type:`importmap`,dangerouslySetInnerHTML:{__html:JSON.stringify({imports:{react:`${e}/shims/react-shim.js`,"react/jsx-runtime":`${e}/shims/react-jsx-shim.js`,"react-dom":`${e}/shims/react-dom-shim.js`,"react-dom/client":`${e}/shims/react-dom-client-shim.js`,"next/link":`${e}/shims/next-link-shim.js`,"next/image":`${e}/shims/next-image-shim.js`,"next/navigation":`${e}/shims/next-navigation-shim.js`}})}});export{j as a,T as c,k as i,E as l,N as n,O as o,M as r,D as s,P as t,w as u};
@@ -1,45 +0,0 @@
1
- //#region src/remix/api.d.ts
2
- /**
3
- * Generic loader/action function args that work with both:
4
- * - Remix v2 (@remix-run/node)
5
- * - React Router v7 framework mode (react-router)
6
- */
7
- type LoaderActionArgs = {
8
- request: Request;
9
- params: Record<string, string | undefined>;
10
- context?: unknown;
11
- };
12
- type CreateRemixHandlerOptions = {
13
- /**
14
- * The app ID for this MWAI application
15
- * This identifies your app in the modifywithai system
16
- */
17
- appId: string;
18
- /**
19
- * Base URL of the modifywithai service
20
- * @default "https://modifywithai.com"
21
- */
22
- baseUrl?: string;
23
- /**
24
- * API key for authenticating with the modifywithai service
25
- * @default process.env.MWAI_API_KEY
26
- */
27
- apiKey?: string;
28
- /**
29
- * Function to get the end user's ID from the request
30
- * This will be injected into API calls that require endUserId
31
- */
32
- getEndUserId: (request: Request) => Promise<string | null>;
33
- };
34
- declare function createRemixHandler(options: CreateRemixHandlerOptions): {
35
- loader: ({
36
- request,
37
- params
38
- }: LoaderActionArgs) => Promise<Response>;
39
- action: ({
40
- request,
41
- params
42
- }: LoaderActionArgs) => Promise<Response>;
43
- };
44
- //#endregion
45
- export { createRemixHandler };
package/dist/remix/api.js DELETED
@@ -1 +0,0 @@
1
- const e=[`list`,`enable`,`disable`,`router`,`status`],t={router:{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}};function n(n){let{appId:r,baseUrl:i=`https://modifywithai.com`,apiKey:a=process.env.MWAI_API_KEY,getEndUserId:o}=n;if(!a)throw Error(`MWAI API key is required. Provide it via the apiKey option or set the MWAI_API_KEY environment variable.`);async function s(n,s){let c=s[`*`]||``;if(!e.includes(c))return new Response(JSON.stringify({error:`Not found`}),{status:404,headers:{"Content-Type":`application/json`}});let l=t[c],u=await o(n);if(l.needsEndUserId&&!u)return new Response(JSON.stringify({error:`Unauthorized - end user ID required`}),{status:401,headers:{"Content-Type":`application/json`}});let d=new URL(`/api/${c}`,i);new URL(n.url).searchParams.forEach((e,t)=>{d.searchParams.set(t,e)});let f=new Headers({"Content-Type":`application/json`,"x-api-key":a}),p;if(n.method===`POST`||n.method===`PUT`||n.method===`PATCH`)try{let e=await n.json();e.appId=r,l.needsEndUserId&&u&&(e.endUserId=u),p=JSON.stringify(e)}catch{let e={appId:r};l.needsEndUserId&&u&&(e.endUserId=u),p=JSON.stringify(e)}n.method===`GET`&&(d.searchParams.set(`appId`,r),u&&d.searchParams.set(`endUserId`,u));let m=await fetch(d.toString(),{method:n.method,headers:f,body:p}),h=await m.text();return new Response(h,{status:m.status,statusText:m.statusText,headers:{"Content-Type":m.headers.get(`Content-Type`)||`application/json`}})}async function c({request:e,params:t}){return s(e,t)}async function l({request:e,params:t}){return s(e,t)}return{loader:c,action:l}}export{n as createRemixHandler};
@@ -1,38 +0,0 @@
1
- import { b as RouterMatchedResponse, f as ModificationToggleOptions, i as DisableResponse, s as EnableResponse, t as ApiError, u as Modification, v as RouterCannotCreateResponse, w as UseRouterOptions, x as RouterResponse, y as RouterCreatingResponse } from "../types-D83LZSks.js";
2
- import { a as useEnable, i as useDisable, n as MWAIContext, o as useList, r as MWAIProvider, s as useRouter, t as mwaiQueryKeys } from "../index-Dp00MJvS.js";
3
- import { createRemixHandler } from "./api.js";
4
- import { loader } from "./shims.js";
5
- import * as react_jsx_runtime0 from "react/jsx-runtime";
6
-
7
- //#region src/remix/head.d.ts
8
- /**
9
- * MWAIHeadRemix - Renders the import map for dynamically loaded components
10
- * Works with both Remix v2 (@remix-run/react) and React Router v7 (react-router)
11
- */
12
- declare const MWAIHeadRemix: ({
13
- basePath
14
- }?: {
15
- basePath?: string;
16
- }) => react_jsx_runtime0.JSX.Element;
17
- //#endregion
18
- //#region src/remix/components.d.ts
19
- /**
20
- * Props for MWAIRemixComponents to pass router modules
21
- * Users must pass their router imports since we support both:
22
- * - Remix v2 (@remix-run/react)
23
- * - React Router v7 (react-router)
24
- */
25
- type RouterModules = {
26
- /** Pass the @remix-run/react or react-router module */routerModule: Record<string, unknown>; /** Pass react-router-dom module (optional, for additional compatibility) */
27
- reactRouterDOM?: Record<string, unknown>;
28
- };
29
- declare const useRemixComponents: (routerModules?: RouterModules) => react_jsx_runtime0.JSX.Element | null;
30
- declare const MWAIRemixComponents: ({
31
- routerModule,
32
- reactRouterDOM
33
- }?: {
34
- /** Pass the @remix-run/react module (for Remix v2) or react-router (for RR v7) */routerModule?: Record<string, unknown>; /** Pass react-router-dom module (optional) */
35
- reactRouterDOM?: Record<string, unknown>;
36
- }) => react_jsx_runtime0.JSX.Element | null;
37
- //#endregion
38
- export { type ApiError, type DisableResponse, type EnableResponse, MWAIContext, MWAIHeadRemix, MWAIProvider, MWAIRemixComponents, type Modification, type ModificationToggleOptions, type RouterCannotCreateResponse, type RouterCreatingResponse, type RouterMatchedResponse, type RouterResponse, type UseRouterOptions, createRemixHandler, mwaiQueryKeys, loader as shimsLoader, useDisable, useEnable, useList, useRemixComponents, useRouter };
@@ -1 +0,0 @@
1
- "use client";import"../types-V6wytIkL.js";import{a as e,c as t,i as n,l as r,o as i,s as a,u as o}from"../react-CREl6aTM.js";import{createRemixHandler as s}from"./api.js";import{loader as c}from"./shims.js";import*as l from"react";import{useContext as u,useLayoutEffect as d,useState as f}from"react";import*as p from"react/jsx-runtime";import{Fragment as m,jsx as h}from"react/jsx-runtime";import*as g from"react-dom";import*as _ from"react-dom/client";const v=({basePath:e=`/api/mwai`}={})=>h(`script`,{type:`importmap`,dangerouslySetInnerHTML:{__html:JSON.stringify({imports:{react:`${e}/shims/react-shim.js`,"react/jsx-runtime":`${e}/shims/react-jsx-shim.js`,"react-dom":`${e}/shims/react-dom-shim.js`,"react-dom/client":`${e}/shims/react-dom-client-shim.js`,"@remix-run/react":`${e}/shims/remix-react-shim.js`,"react-router":`${e}/shims/react-router-shim.js`,"react-router-dom":`${e}/shims/react-router-dom-shim.js`}})}}),y=e=>{let r=u(n),[i,a]=f(null),{data:o}=t();return d(()=>{if(!r){console.error(`ModifyWithAI: No appId provided. Wrap your app with <MWAIProvider appId='your-app-id'>`);return}typeof window<`u`&&(window.__REACT__=l,window.__REACT_JSX_RUNTIME__=p,window.__REACT_DOM__=g,window.__REACT_DOM_CLIENT__=_,e?.routerModule&&(window.__REMIX_REACT__=e.routerModule),e?.reactRouterDOM&&(window.__REACT_ROUTER_DOM__=e.reactRouterDOM))},[r,e]),d(()=>{if(!r||!o)return;let e=Function(`url`,`return import(url)`),t=o.filter(e=>e.enabled&&e.status===`success`).map(e=>e.id);a([]),t.forEach(t=>{e(`https://bucket.modifywithai.com/${r}/${t}.js`).then(e=>a(t=>[...t||[],e.default])).catch(e=>console.error(`Failed to load external module:`,e))})},[r,o]),i?h(m,{children:i.map(e=>h(e,{},e.name))}):null},b=({routerModule:e,reactRouterDOM:t}={})=>y(e?{routerModule:e,reactRouterDOM:t}:void 0);export{n as MWAIContext,v as MWAIHeadRemix,e as MWAIProvider,b as MWAIRemixComponents,s as createRemixHandler,o as mwaiQueryKeys,c as shimsLoader,i as useDisable,a as useEnable,t as useList,y as useRemixComponents,r as useRouter};
@@ -1,14 +0,0 @@
1
- //#region src/remix/shims.d.ts
2
- /**
3
- * Generic loader args that work with both:
4
- * - Remix v2 (@remix-run/node)
5
- * - React Router v7 framework mode (react-router)
6
- */
7
- type LoaderArgs = {
8
- params: Record<string, string | undefined>;
9
- };
10
- declare function loader({
11
- params
12
- }: LoaderArgs): Promise<Response>;
13
- //#endregion
14
- export { loader };
@@ -1 +0,0 @@
1
- import{t as e}from"../shims-C5D8K0uz.js";async function t({params:t}){let n=t[`*`];return e[n]?new Response(e[n],{headers:{"Content-Type":`application/javascript`,"Cache-Control":`public, max-age=31536000, immutable`}}):new Response(`Not found`,{status:404})}export{t as loader};