modifywithai 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +4 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ export default function RootLayout({ children }) {
|
|
|
33
33
|
</head>
|
|
34
34
|
<body>
|
|
35
35
|
{children}
|
|
36
|
-
<MWAIProvider
|
|
36
|
+
<MWAIProvider appId="your-mwai-id">
|
|
37
37
|
<MWAIComponents />
|
|
38
38
|
</MWAIProvider>
|
|
39
39
|
</body>
|
|
@@ -65,6 +65,9 @@ app/
|
|
|
65
65
|
import { createNextjsHandler } from "modifywithai/nextjs/api"
|
|
66
66
|
|
|
67
67
|
export const { GET, POST, PUT, PATCH, DELETE } = createNextjsHandler({
|
|
68
|
+
// Required: Your MWAI app ID
|
|
69
|
+
appId: "your-app-id",
|
|
70
|
+
|
|
68
71
|
// Optional: defaults to "https://modifywithai.com"
|
|
69
72
|
baseUrl: process.env.MWAI_BASE_URL,
|
|
70
73
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
|
7
7
|
//#region src/react/provider.d.ts
|
|
8
8
|
declare const MWAIContext: react0.Context<string | null>;
|
|
9
9
|
declare const MWAIProvider: ({
|
|
10
|
-
|
|
10
|
+
appId,
|
|
11
11
|
children
|
|
12
12
|
}: {
|
|
13
|
-
|
|
13
|
+
appId: string;
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
}) => react_jsx_runtime0.JSX.Element;
|
|
16
16
|
//#endregion
|
package/dist/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{a as e,i as t,n,o as r,r as i,t as a}from"../types-B-V0OtIq.js";import*as o from"react";import{createContext as s,useContext as c,useLayoutEffect as l,useRef as u,useState as d}from"react";import{QueryClient as f,QueryClientProvider as p,useMutation as m,useQuery as h,useQueryClient as g}from"@tanstack/react-query";import*as _ from"react/jsx-runtime";import{Fragment as v,jsx as y}from"react/jsx-runtime";import*as b from"react-dom";import*as x from"react-dom/client";import S from"next/link";import C from"next/image";import*as w from"next/navigation";const T=s(null);function E(){return new f({defaultOptions:{queries:{staleTime:5e3,refetchOnWindowFocus:!1}}})}const D=({
|
|
1
|
+
"use client";import{a as e,i as t,n,o as r,r as i,t as a}from"../types-B-V0OtIq.js";import*as o from"react";import{createContext as s,useContext as c,useLayoutEffect as l,useRef as u,useState as d}from"react";import{QueryClient as f,QueryClientProvider as p,useMutation as m,useQuery as h,useQueryClient as g}from"@tanstack/react-query";import*as _ from"react/jsx-runtime";import{Fragment as v,jsx as y}from"react/jsx-runtime";import*as b from"react-dom";import*as x from"react-dom/client";import S from"next/link";import C from"next/image";import*as w from"next/navigation";const T=s(null);function E(){return new f({defaultOptions:{queries:{staleTime:5e3,refetchOnWindowFocus:!1}}})}const D=({appId:e,children:t})=>{let[n]=d(E);return y(p,{client:n,children:y(T.Provider,{value:e,children:t})})},O=({basePath:e=`/api/mwai`}={})=>y(`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`}})}}),k={all:[`mwai`],modifications:()=>[...k.all,`modifications`]};function A(){return h({queryKey:k.modifications(),queryFn:async()=>{let t=await fetch(`/api/mwai/api/list`);if(!t.ok)throw Error(`Failed to fetch modifications`);let n=await t.json();return e.parse(n)},refetchInterval:1e4})}function j(e){let t=g(),{mutate:n,...i}=m({mutationFn:async e=>{let t=e.trim();if(!t)throw Error(`Prompt cannot be empty`);let n=await fetch(`/api/mwai/api/modify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:t})});if(!n.ok){let e=await n.json().catch(()=>({})),t=a.safeParse(e),r=t.success&&(t.data.message||t.data.error)||`Failed to submit modification`;throw Error(r)}let i=await n.json();return r.parse(i)},onSuccess:()=>{t.invalidateQueries({queryKey:k.modifications()}),e?.onSuccess?.(),typeof window<`u`&&window.location.reload()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{modify:n,...i}}function M(e){let t=g(),{mutate:n,...r}=m({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=a.safeParse(e),r=n.success&&(n.data.message||n.data.error)||`Failed to enable modification`;throw Error(r)}let n=await t.json();return i.parse(n)},onSuccess:()=>{t.invalidateQueries({queryKey:k.modifications()}),e?.onSuccess?.(),typeof window<`u`&&window.location.reload()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{enable:n,...r}}function N(e){let t=g(),{mutate:r,...i}=m({mutationFn:async e=>{let t=await fetch(`/api/mwai/api/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!t.ok){let e=await t.json().catch(()=>({})),n=a.safeParse(e),r=n.success&&(n.data.message||n.data.error)||`Failed to disable modification`;throw Error(r)}let r=await t.json();return n.parse(r)},onSuccess:()=>{t.invalidateQueries({queryKey:k.modifications()}),e?.onSuccess?.(),typeof window<`u`&&window.location.reload()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{disable:r,...i}}const P=()=>{let e=c(T),[t,n]=d(null),{data:r}=A(),i=u(null);return l(()=>{if(!e){console.error(`ModifyWithAI: No appId provided. Wrap your app with <MWAIProvider appId='your-app-id'>`);return}typeof window<`u`&&(window.__REACT__=o,window.__REACT_JSX_RUNTIME__=_,window.__REACT_DOM__=b,window.__REACT_DOM_CLIENT__=x,window.__NEXT_LINK__=S,window.__NEXT_IMAGE__=C,window.__NEXT_NAVIGATION__=w)},[e]),l(()=>{if(!e||!r)return;let t=Function(`url`,`return import(url)`),a=r.filter(e=>e.enabled&&e.status===`success`).map(e=>e.id),o=i.current;if(o!==null){let e=new Set(o),t=new Set(a);if(o.length!==a.length||a.some(t=>!e.has(t))||o.some(e=>!t.has(e))){typeof window<`u`&&window.location.reload();return}}i.current=a,n([]),a.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?y(v,{children:t.map(e=>y(e,{},e.name))}):null},F=()=>P();export{a as ApiErrorSchema,n as DisableResponseSchema,i as EnableResponseSchema,F as MWAIComponents,T as MWAIContext,O as MWAIHead,D as MWAIProvider,t as ModificationSchema,e as ModificationsListSchema,r as ModifyResponseSchema,k as mwaiQueryKeys,P as useComponents,N as useDisable,M as useEnable,A as useList,j as useModify};
|