payload-forgeai 0.2.0 → 0.3.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.
|
@@ -16,7 +16,7 @@ export const ForgeAIField = (props)=>{
|
|
|
16
16
|
const endpoint = useMemo(()=>{
|
|
17
17
|
if (!collectionSlug) return null;
|
|
18
18
|
const base = config?.serverURL || '';
|
|
19
|
-
return `${base}/api/
|
|
19
|
+
return `${base}/api/forgeai/${collectionSlug}/${path}`;
|
|
20
20
|
}, [
|
|
21
21
|
collectionSlug,
|
|
22
22
|
config?.serverURL,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/ForgeAIField.tsx"],"sourcesContent":["'use client'\n\nimport React, { useCallback, useMemo, useState } from 'react'\nimport { type TextFieldClientComponent } from 'payload'\nimport { useConfig, useDocumentInfo, useField, FieldLabel, useFormFields } from '@payloadcms/ui'\n\nexport const ForgeAIField: TextFieldClientComponent = (props) => {\n const { path, field, readOnly } = props\n\n const { setValue, value, errorMessage, showError, formProcessing } = useField<string>({ path })\n const { collectionSlug, id: docId } = useDocumentInfo()\n const { config } = useConfig()\n
|
|
1
|
+
{"version":3,"sources":["../../src/components/ForgeAIField.tsx"],"sourcesContent":["'use client'\n\nimport React, { useCallback, useMemo, useState } from 'react'\nimport { type TextFieldClientComponent } from 'payload'\nimport { useConfig, useDocumentInfo, useField, FieldLabel, useFormFields } from '@payloadcms/ui'\n\nexport const ForgeAIField: TextFieldClientComponent = (props) => {\n const { path, field, readOnly } = props\n\n const { setValue, value, errorMessage, showError, formProcessing } = useField<string>({ path })\n const { collectionSlug, id: docId } = useDocumentInfo()\n const { config } = useConfig()\n\n // Access all form fields for context\n const allFields = useFormFields(([fields]) => fields)\n\n const [isGenerating, setIsGenerating] = useState(false)\n const [genError, setGenError] = useState<string | null>(null)\n\n const endpoint = useMemo(() => {\n if (!collectionSlug) return null\n const base = config?.serverURL || ''\n return `${base}/api/forgeai/${collectionSlug}/${path}`\n }, [collectionSlug, config?.serverURL, path])\n\n const generate = useCallback(async () => {\n if (!endpoint) return\n setIsGenerating(true)\n setGenError(null)\n try {\n // Gather context from form fields\n const contextData: Record<string, any> = {}\n if (allFields) {\n Object.entries(allFields).forEach(([fieldPath, fieldState]) => {\n contextData[fieldPath] = fieldState.value\n })\n }\n\n const res = await fetch(endpoint, {\n method: 'POST',\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n context: contextData,\n documentId: docId,\n currentValue: value, // Include current value so AI can generate something different\n }),\n })\n\n if (!res.ok) throw new Error(await res.text())\n\n const generated = await res.json()\n setValue(generated)\n } catch (e) {\n setGenError(e instanceof Error ? e.message : String(e))\n } finally {\n setIsGenerating(false)\n }\n }, [endpoint, setValue, allFields, docId])\n\n return (\n <div className=\"field-type\">\n <FieldLabel htmlFor={path} label={field.label ?? field.name} required={field.required} />\n\n <div>\n <input\n id={path}\n style={{ width: '100%' }}\n disabled={readOnly || formProcessing}\n value={value ?? ''}\n onChange={(e) => setValue(e.target.value)}\n />\n\n <button\n type=\"button\"\n onClick={generate}\n disabled={readOnly || formProcessing || isGenerating || !endpoint}\n style={{\n marginTop: 8,\n padding: '6px 12px',\n border: '1px solid var(--theme-elevation-400)',\n borderRadius: 4,\n background: 'var(--theme-elevation-50)',\n cursor:\n readOnly || formProcessing || isGenerating || !endpoint ? 'not-allowed' : 'pointer',\n display: 'inline-flex',\n alignItems: 'center',\n gap: 6,\n fontSize: 13,\n color: 'var(--theme-elevation-800)',\n transition: 'all 0.2s ease',\n opacity: readOnly || formProcessing || !endpoint ? 0.5 : 1,\n }}\n onMouseEnter={(e) => {\n if (!readOnly && !formProcessing && !isGenerating && endpoint) {\n e.currentTarget.style.background = 'var(--theme-elevation-100)'\n e.currentTarget.style.borderColor = 'var(--theme-elevation-500)'\n }\n }}\n onMouseLeave={(e) => {\n e.currentTarget.style.background = 'var(--theme-elevation-50)'\n e.currentTarget.style.borderColor = 'var(--theme-elevation-400)'\n }}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n style={{\n animation: isGenerating ? 'spin 1s linear infinite' : 'none',\n }}\n >\n <path d=\"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.2\" />\n </svg>\n {isGenerating ? 'Generating…' : 'Generate with AI'}\n </button>\n\n <style>{`\n @keyframes spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n }\n `}</style>\n </div>\n\n {genError ? (\n <div style={{ marginTop: 6, color: 'var(--theme-error-500)' }}>{genError}</div>\n ) : null}\n {showError && errorMessage ? (\n <div style={{ marginTop: 6, color: 'var(--theme-error-500)' }}>{errorMessage}</div>\n ) : null}\n </div>\n )\n}\n"],"names":["React","useCallback","useMemo","useState","useConfig","useDocumentInfo","useField","FieldLabel","useFormFields","ForgeAIField","props","path","field","readOnly","setValue","value","errorMessage","showError","formProcessing","collectionSlug","id","docId","config","allFields","fields","isGenerating","setIsGenerating","genError","setGenError","endpoint","base","serverURL","generate","contextData","Object","entries","forEach","fieldPath","fieldState","res","fetch","method","credentials","headers","body","JSON","stringify","context","documentId","currentValue","ok","Error","text","generated","json","e","message","String","div","className","htmlFor","label","name","required","input","style","width","disabled","onChange","target","button","type","onClick","marginTop","padding","border","borderRadius","background","cursor","display","alignItems","gap","fontSize","color","transition","opacity","onMouseEnter","currentTarget","borderColor","onMouseLeave","svg","xmlns","height","viewBox","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","animation","d"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAE7D,SAASC,SAAS,EAAEC,eAAe,EAAEC,QAAQ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Ac,CAAClC;4BACbA,EAAEgC,aAAa,CAACtB,KAAK,CAACY,UAAU,GAAG;4BACnCtB,EAAEgC,aAAa,CAACtB,KAAK,CAACuB,WAAW,GAAG;wBACtC;;0CAEA,KAACE;gCACCC,OAAM;gCACNzB,OAAM;gCACN0B,QAAO;gCACPC,SAAQ;gCACRC,MAAK;gCACLC,QAAO;gCACPC,aAAY;gCACZC,eAAc;gCACdC,gBAAe;gCACfjC,OAAO;oCACLkC,WAAW1E,eAAe,4BAA4B;gCACxD;0CAEA,cAAA,KAACd;oCAAKyF,GAAE;;;4BAET3E,eAAe,gBAAgB;;;kCAGlC,KAACwC;kCAAO,CAAC;;;;;;;;;QAST,CAAC;;;;YAGFtC,yBACC,KAAC+B;gBAAIO,OAAO;oBAAEQ,WAAW;oBAAGU,OAAO;gBAAyB;0BAAIxD;iBAC9D;YACHV,aAAaD,6BACZ,KAAC0C;gBAAIO,OAAO;oBAAEQ,WAAW;oBAAGU,OAAO;gBAAyB;0BAAInE;iBAC9D;;;AAGV,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ForgeAIField } from '../components/ForgeAIField.
|
|
1
|
+
export { ForgeAIField } from '../components/ForgeAIField.jsx';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/ForgeAIField.ts"],"sourcesContent":["export { ForgeAIField } from '../components/ForgeAIField.
|
|
1
|
+
{"version":3,"sources":["../../src/exports/ForgeAIField.ts"],"sourcesContent":["export { ForgeAIField } from '../components/ForgeAIField.jsx'\n"],"names":["ForgeAIField"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iCAAgC"}
|