@mvriu5/payload-ai 0.5.10 → 1.1.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/dist/components/AIInput.js +166 -109
- package/dist/components/APIKeyField.js +41 -24
- package/dist/components/ActionToast.js +200 -101
- package/dist/components/AuditLogList.js +90 -53
- package/dist/components/DiffDialog.js +222 -121
- package/dist/components/Icons.js +390 -274
- package/dist/components/MentionPopover.js +33 -22
- package/dist/handlers/chatHandler.js +89 -2
- package/dist/index.js +2 -2
- package/package.json +40 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { useConfig } from "@payloadcms/ui";
|
|
3
4
|
import { formatAdminURL } from "payload/shared";
|
|
4
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -44,15 +45,25 @@ const getProviderIcon = (provider)=>{
|
|
|
44
45
|
};
|
|
45
46
|
switch(provider){
|
|
46
47
|
case "claude":
|
|
47
|
-
return /*#__PURE__*/
|
|
48
|
+
return /*#__PURE__*/ _jsx(ClaudeIcon, {
|
|
49
|
+
...iconProps
|
|
50
|
+
});
|
|
48
51
|
case "google":
|
|
49
|
-
return /*#__PURE__*/
|
|
52
|
+
return /*#__PURE__*/ _jsx(GoogleGeminiIcon, {
|
|
53
|
+
...iconProps
|
|
54
|
+
});
|
|
50
55
|
case "mistral":
|
|
51
|
-
return /*#__PURE__*/
|
|
56
|
+
return /*#__PURE__*/ _jsx(MistralAiIcon, {
|
|
57
|
+
...iconProps
|
|
58
|
+
});
|
|
52
59
|
case "openai":
|
|
53
|
-
return /*#__PURE__*/
|
|
60
|
+
return /*#__PURE__*/ _jsx(OpenaiIcon, {
|
|
61
|
+
...iconProps
|
|
62
|
+
});
|
|
54
63
|
case "openrouter":
|
|
55
|
-
return /*#__PURE__*/
|
|
64
|
+
return /*#__PURE__*/ _jsx(OpenrouterIcon, {
|
|
65
|
+
...iconProps
|
|
66
|
+
});
|
|
56
67
|
default:
|
|
57
68
|
return null;
|
|
58
69
|
}
|
|
@@ -582,109 +593,155 @@ const AIInput = ()=>{
|
|
|
582
593
|
setIsApplying(false);
|
|
583
594
|
}
|
|
584
595
|
};
|
|
585
|
-
return /*#__PURE__*/
|
|
586
|
-
className: styles.chatLayout
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
596
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
597
|
+
className: styles.chatLayout,
|
|
598
|
+
children: [
|
|
599
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
600
|
+
className: styles.chat,
|
|
601
|
+
children: [
|
|
602
|
+
/*#__PURE__*/ _jsx("div", {
|
|
603
|
+
className: styles.chatHeader,
|
|
604
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
605
|
+
children: [
|
|
606
|
+
/*#__PURE__*/ _jsx("h2", {
|
|
607
|
+
className: styles.chatTitle,
|
|
608
|
+
children: "AI Assistant"
|
|
609
|
+
}),
|
|
610
|
+
/*#__PURE__*/ _jsx("p", {
|
|
611
|
+
className: styles.chatDescription,
|
|
612
|
+
children: "Ask AI to draft, improve, or analyze content."
|
|
613
|
+
})
|
|
614
|
+
]
|
|
615
|
+
})
|
|
616
|
+
}),
|
|
617
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
618
|
+
className: styles.chatInputRow,
|
|
619
|
+
children: [
|
|
620
|
+
/*#__PURE__*/ _jsx("div", {
|
|
621
|
+
className: styles.chatInputSurface,
|
|
622
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
623
|
+
className: styles.chatInput,
|
|
624
|
+
contentEditable: true,
|
|
625
|
+
"data-placeholder": "Ask AI...",
|
|
626
|
+
onInput: (event)=>{
|
|
627
|
+
const value = event.currentTarget.innerText;
|
|
628
|
+
setPrompt(value);
|
|
629
|
+
if (!value.trim()) {
|
|
630
|
+
setMentions([]);
|
|
631
|
+
}
|
|
632
|
+
updateMentionState(getTextBeforeCaret(event.currentTarget));
|
|
633
|
+
},
|
|
634
|
+
onKeyDown: (event)=>{
|
|
635
|
+
if (event.key === "ArrowDown" && mentionRange && mentionSuggestions.length > 0) {
|
|
636
|
+
const firstOption = mentionPopoverRef.current?.querySelector("button");
|
|
637
|
+
if (firstOption) {
|
|
638
|
+
event.preventDefault();
|
|
639
|
+
firstOption.focus();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
644
|
+
event.preventDefault();
|
|
645
|
+
void handleSubmit();
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
ref: editorRef,
|
|
649
|
+
role: "textbox",
|
|
650
|
+
suppressContentEditableWarning: true
|
|
651
|
+
})
|
|
652
|
+
}),
|
|
653
|
+
mentionRange && /*#__PURE__*/ _jsx(MentionPopover, {
|
|
654
|
+
containerRef: mentionPopoverRef,
|
|
655
|
+
onSelect: insertMention,
|
|
656
|
+
style: mentionPopoverPosition ? {
|
|
657
|
+
left: `${mentionPopoverPosition.left}px`,
|
|
658
|
+
top: `${mentionPopoverPosition.top}px`
|
|
659
|
+
} : undefined,
|
|
660
|
+
suggestions: mentionSuggestions
|
|
661
|
+
})
|
|
662
|
+
]
|
|
663
|
+
}),
|
|
664
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
665
|
+
className: styles.chatActionsRow,
|
|
666
|
+
children: [
|
|
667
|
+
/*#__PURE__*/ _jsx("div", {
|
|
668
|
+
className: styles.settings,
|
|
669
|
+
children: /*#__PURE__*/ _jsxs("label", {
|
|
670
|
+
className: styles.setting,
|
|
671
|
+
children: [
|
|
672
|
+
/*#__PURE__*/ _jsx("span", {
|
|
673
|
+
className: styles.settingLabel,
|
|
674
|
+
children: "Model"
|
|
675
|
+
}),
|
|
676
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
677
|
+
className: styles.selectWrapper,
|
|
678
|
+
children: [
|
|
679
|
+
getProviderIcon(settingsProvider),
|
|
680
|
+
/*#__PURE__*/ _jsxs("select", {
|
|
681
|
+
className: styles.select,
|
|
682
|
+
disabled: !settingsProvider,
|
|
683
|
+
onChange: (event)=>setSelectedModel(event.target.value),
|
|
684
|
+
value: selectedModel,
|
|
685
|
+
children: [
|
|
686
|
+
!settingsProvider && /*#__PURE__*/ _jsx("option", {
|
|
687
|
+
value: "",
|
|
688
|
+
children: "Select provider in account settings"
|
|
689
|
+
}),
|
|
690
|
+
settingsProvider && aiModelConfig.providers[settingsProvider].map((model)=>/*#__PURE__*/ _jsx("option", {
|
|
691
|
+
value: model.value,
|
|
692
|
+
children: model.label
|
|
693
|
+
}, model.value))
|
|
694
|
+
]
|
|
695
|
+
})
|
|
696
|
+
]
|
|
697
|
+
})
|
|
698
|
+
]
|
|
699
|
+
})
|
|
700
|
+
}),
|
|
701
|
+
/*#__PURE__*/ _jsxs("button", {
|
|
702
|
+
className: styles.chatButton,
|
|
703
|
+
disabled: !prompt.trim() || !settingsProvider || !selectedModel || isLoading,
|
|
704
|
+
onClick: ()=>void handleSubmit(),
|
|
705
|
+
type: "button",
|
|
706
|
+
children: [
|
|
707
|
+
/*#__PURE__*/ _jsx(Send, {
|
|
708
|
+
width: 14,
|
|
709
|
+
height: 14
|
|
710
|
+
}),
|
|
711
|
+
isLoading ? "Sending..." : "Send"
|
|
712
|
+
]
|
|
713
|
+
})
|
|
714
|
+
]
|
|
715
|
+
}),
|
|
716
|
+
/*#__PURE__*/ _jsx(ActionToast, {
|
|
717
|
+
apiRoute: config.routes.api,
|
|
718
|
+
appliedProposalIndexes: appliedProposalIndexes,
|
|
719
|
+
description: response,
|
|
720
|
+
error: error,
|
|
721
|
+
getViewURL: getProposalViewURL,
|
|
722
|
+
isApplying: isApplying,
|
|
723
|
+
onDismiss: ()=>{
|
|
724
|
+
setAppliedProposalIndexes([]);
|
|
725
|
+
setError("");
|
|
726
|
+
setProposals([]);
|
|
727
|
+
setResponse("");
|
|
728
|
+
setTokenUsage(null);
|
|
729
|
+
clearInput();
|
|
730
|
+
},
|
|
731
|
+
onDismissError: ()=>{
|
|
732
|
+
setError("");
|
|
733
|
+
},
|
|
734
|
+
onApply: (proposal, _index)=>void handleApplyProposal(proposal),
|
|
735
|
+
proposals: proposals,
|
|
736
|
+
tokenUsage: tokenUsage
|
|
737
|
+
})
|
|
738
|
+
]
|
|
739
|
+
}),
|
|
740
|
+
/*#__PURE__*/ _jsx(RecentChangesList, {
|
|
741
|
+
allChangesURL: allChangesURL,
|
|
742
|
+
changes: appliedChanges
|
|
743
|
+
})
|
|
744
|
+
]
|
|
745
|
+
});
|
|
689
746
|
};
|
|
690
747
|
export default AIInput;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { useField } from "@payloadcms/ui";
|
|
3
4
|
const getFieldClassName = ({ className, isReadOnly, showError })=>[
|
|
4
5
|
"field-type",
|
|
@@ -14,33 +15,49 @@ const APIKeyField = ({ field, inputRef, path, readOnly })=>{
|
|
|
14
15
|
const fieldID = `field-${path.replace(/\./g, "__")}`;
|
|
15
16
|
const isReadOnly = readOnly || disabled || field.admin?.disabled;
|
|
16
17
|
const handleChange = (event)=>setValue(event.target.value);
|
|
17
|
-
return /*#__PURE__*/
|
|
18
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
18
19
|
className: getFieldClassName({
|
|
19
20
|
className: field.admin?.className,
|
|
20
21
|
isReadOnly,
|
|
21
22
|
showError
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
}),
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ _jsxs("label", {
|
|
26
|
+
className: "field-label",
|
|
27
|
+
htmlFor: fieldID,
|
|
28
|
+
children: [
|
|
29
|
+
field?.label?.toString(),
|
|
30
|
+
field.required ? /*#__PURE__*/ _jsx("span", {
|
|
31
|
+
className: "required",
|
|
32
|
+
children: "*"
|
|
33
|
+
}) : null
|
|
34
|
+
]
|
|
35
|
+
}),
|
|
36
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
37
|
+
className: "field-type__wrap",
|
|
38
|
+
children: [
|
|
39
|
+
showError && errorMessage ? /*#__PURE__*/ _jsx("div", {
|
|
40
|
+
className: "field-error",
|
|
41
|
+
children: errorMessage
|
|
42
|
+
}) : null,
|
|
43
|
+
/*#__PURE__*/ _jsx("input", {
|
|
44
|
+
autoComplete: "new-password",
|
|
45
|
+
disabled: isReadOnly,
|
|
46
|
+
id: fieldID,
|
|
47
|
+
name: path,
|
|
48
|
+
onChange: handleChange,
|
|
49
|
+
placeholder: field.admin?.placeholder?.toString(),
|
|
50
|
+
ref: inputRef,
|
|
51
|
+
type: "password",
|
|
52
|
+
value: value || ""
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ _jsx("div", {
|
|
55
|
+
className: "field-description",
|
|
56
|
+
children: field.admin?.description?.toString()
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
});
|
|
45
62
|
};
|
|
46
63
|
export default APIKeyField;
|