modifywithai 1.8.0 → 1.9.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/AGENTS.md +1 -1
- package/README.md +4 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +26 -25
- package/dist/react/index.js +1 -1
- package/dist/types-BgiWGYKC.js +1 -0
- package/dist/{types-DP2zKGqL.d.ts → types-DjksF7DU.d.ts} +1 -1
- package/package.json +35 -37
- package/dist/types-B-V0OtIq.js +0 -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/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-DjksF7DU.js";
|
|
2
2
|
|
|
3
3
|
//#region src/core.d.ts
|
|
4
4
|
|
|
@@ -29,7 +29,7 @@ declare function modifyWithAI({
|
|
|
29
29
|
id,
|
|
30
30
|
prompt
|
|
31
31
|
}: ModifyWithAIArgs, options?: ModifyWithAIOptions): Promise<{
|
|
32
|
-
|
|
32
|
+
modificationId?: string;
|
|
33
33
|
error?: Error;
|
|
34
34
|
}>;
|
|
35
35
|
/**
|
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-
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"./types-BgiWGYKC.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};
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
|
-
import { _ as ModifyWithAIOptions, a as DisableResponseSchema, c as EnableResponseSchema, d as ModificationSchema, f as ModificationToggleOptions, h as ModifyResponseSchema, i as DisableResponse, m as ModifyResponse, n as ApiErrorSchema, p as ModificationsListSchema, s as EnableResponse, t as ApiError, u as Modification } from "../types-
|
|
1
|
+
import { _ as ModifyWithAIOptions, a as DisableResponseSchema, c as EnableResponseSchema, d as ModificationSchema, f as ModificationToggleOptions, h as ModifyResponseSchema, i as DisableResponse, m as ModifyResponse, n as ApiErrorSchema, p as ModificationsListSchema, s as EnableResponse, t as ApiError, u as Modification } from "../types-DjksF7DU.js";
|
|
2
2
|
import * as react0 from "react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
|
+
import * as jsxRuntime from "react/jsx-runtime";
|
|
4
5
|
import * as _tanstack_react_query0 from "@tanstack/react-query";
|
|
5
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
6
|
|
|
7
|
-
//#region src/react/
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
id,
|
|
11
|
-
children
|
|
12
|
-
}: {
|
|
13
|
-
id: string;
|
|
14
|
-
children: ReactNode;
|
|
15
|
-
}) => react_jsx_runtime0.JSX.Element;
|
|
7
|
+
//#region src/react/components.d.ts
|
|
8
|
+
declare const useComponents: () => jsxRuntime.JSX.Element | null;
|
|
9
|
+
declare const MWAIComponents: () => jsxRuntime.JSX.Element | null;
|
|
16
10
|
//#endregion
|
|
17
11
|
//#region src/react/head.d.ts
|
|
18
12
|
declare const MWAIHead: ({
|
|
19
13
|
basePath
|
|
20
14
|
}?: {
|
|
21
15
|
basePath?: string;
|
|
22
|
-
}) =>
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/react/components.d.ts
|
|
25
|
-
declare const useComponents: () => react_jsx_runtime0.JSX.Element | null;
|
|
26
|
-
declare const MWAIComponents: () => react_jsx_runtime0.JSX.Element | null;
|
|
16
|
+
}) => jsxRuntime.JSX.Element;
|
|
27
17
|
//#endregion
|
|
28
18
|
//#region src/react/hooks.d.ts
|
|
29
19
|
/**
|
|
30
20
|
* React hook for fetching the list of modifications
|
|
31
21
|
* Polls every 10 seconds for updates
|
|
22
|
+
* Automatically reloads the page when enabled modifications change
|
|
32
23
|
*
|
|
33
24
|
* @example
|
|
34
25
|
* ```tsx
|
|
@@ -76,10 +67,10 @@ declare function useModify(options?: ModifyWithAIOptions): {
|
|
|
76
67
|
isPaused: boolean;
|
|
77
68
|
submittedAt: number;
|
|
78
69
|
mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
|
|
79
|
-
|
|
70
|
+
modificationId: string;
|
|
80
71
|
}, Error, string, unknown>;
|
|
81
72
|
modify: _tanstack_react_query0.UseMutateFunction<{
|
|
82
|
-
|
|
73
|
+
modificationId: string;
|
|
83
74
|
}, Error, string, unknown>;
|
|
84
75
|
} | {
|
|
85
76
|
data: undefined;
|
|
@@ -97,10 +88,10 @@ declare function useModify(options?: ModifyWithAIOptions): {
|
|
|
97
88
|
isPaused: boolean;
|
|
98
89
|
submittedAt: number;
|
|
99
90
|
mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
|
|
100
|
-
|
|
91
|
+
modificationId: string;
|
|
101
92
|
}, Error, string, unknown>;
|
|
102
93
|
modify: _tanstack_react_query0.UseMutateFunction<{
|
|
103
|
-
|
|
94
|
+
modificationId: string;
|
|
104
95
|
}, Error, string, unknown>;
|
|
105
96
|
} | {
|
|
106
97
|
data: undefined;
|
|
@@ -118,14 +109,14 @@ declare function useModify(options?: ModifyWithAIOptions): {
|
|
|
118
109
|
isPaused: boolean;
|
|
119
110
|
submittedAt: number;
|
|
120
111
|
mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
|
|
121
|
-
|
|
112
|
+
modificationId: string;
|
|
122
113
|
}, Error, string, unknown>;
|
|
123
114
|
modify: _tanstack_react_query0.UseMutateFunction<{
|
|
124
|
-
|
|
115
|
+
modificationId: string;
|
|
125
116
|
}, Error, string, unknown>;
|
|
126
117
|
} | {
|
|
127
118
|
data: {
|
|
128
|
-
|
|
119
|
+
modificationId: string;
|
|
129
120
|
};
|
|
130
121
|
error: null;
|
|
131
122
|
variables: string;
|
|
@@ -141,10 +132,10 @@ declare function useModify(options?: ModifyWithAIOptions): {
|
|
|
141
132
|
isPaused: boolean;
|
|
142
133
|
submittedAt: number;
|
|
143
134
|
mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
|
|
144
|
-
|
|
135
|
+
modificationId: string;
|
|
145
136
|
}, Error, string, unknown>;
|
|
146
137
|
modify: _tanstack_react_query0.UseMutateFunction<{
|
|
147
|
-
|
|
138
|
+
modificationId: string;
|
|
148
139
|
}, Error, string, unknown>;
|
|
149
140
|
};
|
|
150
141
|
/**
|
|
@@ -390,6 +381,16 @@ declare function useDisable(options?: ModificationToggleOptions): {
|
|
|
390
381
|
}, Error, string, unknown>;
|
|
391
382
|
};
|
|
392
383
|
//#endregion
|
|
384
|
+
//#region src/react/provider.d.ts
|
|
385
|
+
declare const MWAIContext: react0.Context<string | null>;
|
|
386
|
+
declare const MWAIProvider: ({
|
|
387
|
+
appId,
|
|
388
|
+
children
|
|
389
|
+
}: {
|
|
390
|
+
appId: string;
|
|
391
|
+
children: ReactNode;
|
|
392
|
+
}) => jsxRuntime.JSX.Element;
|
|
393
|
+
//#endregion
|
|
393
394
|
//#region src/react/query-keys.d.ts
|
|
394
395
|
/**
|
|
395
396
|
* Centralized query key factory for type-safe, consistent cache management
|
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-
|
|
1
|
+
"use client";import{a as e,i as t,n,o as r,r as i,t as a}from"../types-BgiWGYKC.js";import o from"next/image";import s from"next/link";import*as c from"next/navigation";import*as l from"react";import{createContext as u,useContext as d,useLayoutEffect as f,useRef as p,useState as m}from"react";import*as h from"react/jsx-runtime";import{Fragment as g,jsx as _}from"react/jsx-runtime";import*as v from"react-dom";import*as y from"react-dom/client";import{QueryClient as b,QueryClientProvider as x,useMutation as S,useQuery as C,useQueryClient as w}from"@tanstack/react-query";const T={all:[`mwai`],modifications:()=>[...T.all,`modifications`]};function E(){let t=p(null);return C({queryKey:T.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 D(e){let t=w(),{mutate:n,...i}=S({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:T.modifications()}),e?.onSuccess?.()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{modify:n,...i}}function O(e){let t=w(),{mutate:n,...r}=S({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:T.modifications()}),e?.onSuccess?.()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{enable:n,...r}}function k(e){let t=w(),{mutate:r,...i}=S({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:T.modifications()}),e?.onSuccess?.()},onError:t=>{let n=t instanceof Error?t:Error(`Unknown error`);e?.onError?.(n)}});return{disable:r,...i}}const A=u(null);function j(){return new b({defaultOptions:{queries:{staleTime:5e3,refetchOnWindowFocus:!1}}})}const M=({appId:e,children:t})=>{let[n]=m(j);return _(x,{client:n,children:_(A.Provider,{value:e,children:t})})},N=()=>{let e=d(A),[t,n]=m(null),{data:r}=E();return f(()=>{if(!e){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__=h,window.__REACT_DOM__=v,window.__REACT_DOM_CLIENT__=y,window.__NEXT_LINK__=s,window.__NEXT_IMAGE__=o,window.__NEXT_NAVIGATION__=c)},[e]),f(()=>{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,{children:t.map(e=>_(e,{},e.name))}):null},P=()=>N(),F=({basePath:e=`/api/mwai`}={})=>_(`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{a as ApiErrorSchema,n as DisableResponseSchema,i as EnableResponseSchema,P as MWAIComponents,A as MWAIContext,F as MWAIHead,M as MWAIProvider,t as ModificationSchema,e as ModificationsListSchema,r as ModifyResponseSchema,T as mwaiQueryKeys,N as useComponents,k as useDisable,O as useEnable,E as useList,D as useModify};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod";const t=e.object({id:e.string(),title:e.string().nullable(),description:e.string().nullable(),status:e.enum([`pending`,`success`,`error`]),createdAt:e.number(),updatedAt:e.number(),enabled:e.boolean().nullable()}),n=e.array(t),r=e.object({modificationId:e.string()}),i=e.object({message:e.string(),modificationId:e.string(),endUserId:e.string()}),a=e.object({message:e.string(),modificationId:e.string(),endUserId:e.string()}),o=e.object({message:e.string().optional(),error:e.string().optional()});export{n as a,t as i,a as n,r as o,i as r,o as t};
|
|
@@ -38,7 +38,7 @@ declare const ModificationsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
38
38
|
* Schema for the modify API response
|
|
39
39
|
*/
|
|
40
40
|
declare const ModifyResponseSchema: z.ZodObject<{
|
|
41
|
-
|
|
41
|
+
modificationId: z.ZodString;
|
|
42
42
|
}, z.core.$strip>;
|
|
43
43
|
/**
|
|
44
44
|
* Schema for the enable API response
|
package/package.json
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
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
|
-
|
|
37
|
-
"zod": "^4.2.0"
|
|
38
|
-
}
|
|
2
|
+
"name": "modifywithai",
|
|
3
|
+
"version": "1.9.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./nextjs/api": "./dist/nextjs/api.js",
|
|
11
|
+
"./nextjs/shims": "./dist/nextjs/shims.js",
|
|
12
|
+
"./react": "./dist/react/index.js",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"AGENTS.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "bun run --bun tsdown",
|
|
21
|
+
"typecheck": "bun run --bun tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/bun": "latest",
|
|
25
|
+
"@types/react": "^19.2.7",
|
|
26
|
+
"@types/react-dom": "^19.2.3",
|
|
27
|
+
"tsdown": "^0.18.2"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^19.2.1",
|
|
31
|
+
"next": "^16.1.1"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@tanstack/react-query": "^5.0.0",
|
|
35
|
+
"zod": "^4.2.0"
|
|
36
|
+
}
|
|
39
37
|
}
|
package/dist/types-B-V0OtIq.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{z as e}from"zod";const t=e.object({id:e.string(),title:e.string().nullable(),description:e.string().nullable(),status:e.enum([`pending`,`success`,`error`]),createdAt:e.number(),updatedAt:e.number(),enabled:e.boolean().nullable()}),n=e.array(t),r=e.object({success:e.boolean()}),i=e.object({message:e.string(),modificationId:e.string(),endUserId:e.string()}),a=e.object({message:e.string(),modificationId:e.string(),endUserId:e.string()}),o=e.object({message:e.string().optional(),error:e.string().optional()});export{n as a,t as i,a as n,r as o,i as r,o as t};
|