modifywithai 1.7.1 → 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 +3 -1
- package/README.md +4 -1
- package/dist/nextjs/api.d.ts +5 -0
- package/dist/nextjs/api.js +1 -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
|
@@ -49,7 +49,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
49
49
|
<head>
|
|
50
50
|
<MWAIHead />
|
|
51
51
|
</head>
|
|
52
|
-
<MWAIProvider
|
|
52
|
+
<MWAIProvider appId="{{MWAI_ID}}">
|
|
53
53
|
<body>
|
|
54
54
|
{children}
|
|
55
55
|
<MWAIComponents />
|
|
@@ -77,6 +77,7 @@ export { generateStaticParams } from "modifywithai/nextjs/api"
|
|
|
77
77
|
export const dynamicParams = false
|
|
78
78
|
|
|
79
79
|
export const { GET, POST, PUT, PATCH, DELETE } = createNextjsHandler({
|
|
80
|
+
appId: "{{MWAI_APP_ID}}", // Your MWAI app ID from the dashboard
|
|
80
81
|
getEndUserId: async (request) => {
|
|
81
82
|
// TODO: Implement user ID retrieval based on the project's auth system
|
|
82
83
|
// Return the current user's ID as a string
|
|
@@ -97,6 +98,7 @@ export { generateStaticParams } from "modifywithai/nextjs/api"
|
|
|
97
98
|
export const dynamicParams = false
|
|
98
99
|
|
|
99
100
|
export const { GET, POST, PUT, PATCH, DELETE } = createNextjsHandler({
|
|
101
|
+
appId: "{{MWAI_APP_ID}}", // Your MWAI app ID from the dashboard
|
|
100
102
|
getEndUserId: async (request) => {
|
|
101
103
|
const session = await auth.api.getSession({
|
|
102
104
|
headers: request.headers,
|
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/nextjs/api.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { NextRequest } from "next/server";
|
|
|
2
2
|
|
|
3
3
|
//#region src/nextjs/api.d.ts
|
|
4
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;
|
|
5
10
|
/**
|
|
6
11
|
* Base URL of the modifywithai service
|
|
7
12
|
* @default "https://modifywithai.com"
|
package/dist/nextjs/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";const t=[`list`,`enable`,`disable`,`modify`,`status`],n={modify:{method:`POST`,inBody:!0},disable:{method:`POST`,inBody:!0},enable:{method:`POST`,inBody:!0},list:{method:`GET`,inBody:!1}};async function r(){return t.map(e=>({path:e}))}function i(r){let{baseUrl:
|
|
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};
|
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};
|