@mvriu5/payload-ai 1.6.2 → 1.6.4
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/action-toast/ActionToast.d.ts +1 -14
- package/dist/components/action-toast/ActionToast.js +1 -1
- package/dist/components/ai-input/AIInput.js +1 -1
- package/dist/components/audit-log-list/AuditLogList.d.ts +2 -3
- package/dist/components/diff-dialog/DiffDialog.d.ts +2 -6
- package/dist/components/diff-dialog/DiffDialog.js +1 -1
- package/dist/components/generate-field/GenerateField.js +2 -0
- package/dist/components/hooks/useAIChatStream.d.ts +1 -1
- package/dist/components/hooks/useAISettings.d.ts +1 -1
- package/dist/components/hooks/useAISettings.js +1 -1
- package/dist/components/hooks/useDocumentMentionSuggestions.js +1 -1
- package/dist/components/hooks/useMentions.js +1 -1
- package/dist/components/hooks/usePluginConfig.d.ts +6 -6
- package/dist/components/hooks/usePluginConfig.js +1 -1
- package/dist/{payload → features}/collectionPermissions.js +1 -1
- package/dist/{payload/textFieldGeneration.d.ts → features/content/fieldGeneration.d.ts} +4 -0
- package/dist/{payload/textFieldGeneration.js → features/content/fieldGeneration.js} +19 -3
- package/dist/{ai → features}/promptCaching.d.ts +2 -2
- package/dist/features/proposals/containerNormalization.d.ts +8 -0
- package/dist/features/proposals/containerNormalization.js +112 -0
- package/dist/{payload/proposalData.d.ts → features/proposals/data.d.ts} +5 -10
- package/dist/features/proposals/data.js +113 -0
- package/dist/features/proposals/fieldNormalization.d.ts +2 -0
- package/dist/features/proposals/fieldNormalization.js +69 -0
- package/dist/features/proposals/normalizationTypes.d.ts +31 -0
- package/dist/features/proposals/normalizationTypes.js +1 -0
- package/dist/features/proposals/optionInference.d.ts +13 -0
- package/dist/features/proposals/optionInference.js +46 -0
- package/dist/features/proposals/recordNormalization.d.ts +6 -0
- package/dist/features/proposals/recordNormalization.js +78 -0
- package/dist/features/proposals/relationshipNormalization.d.ts +8 -0
- package/dist/features/proposals/relationshipNormalization.js +71 -0
- package/dist/{ai/proposalRepair.d.ts → features/proposals/repair.d.ts} +1 -1
- package/dist/{ai/proposalSigning.d.ts → features/proposals/signing.d.ts} +2 -5
- package/dist/{ai/proposalSigning.js → features/proposals/signing.js} +1 -1
- package/dist/features/proposals/target.d.ts +52 -0
- package/dist/features/proposals/target.js +125 -0
- package/dist/features/proposals/types.d.ts +49 -0
- package/dist/features/proposals/types.js +1 -0
- package/dist/features/proposals/validation.d.ts +12 -0
- package/dist/features/proposals/validation.js +26 -0
- package/dist/features/providers/requestContext.d.ts +53 -0
- package/dist/features/providers/requestContext.js +90 -0
- package/dist/{ai/providerRuntime.d.ts → features/providers/runtime.d.ts} +1 -1
- package/dist/{ai/providerRuntime.js → features/providers/runtime.js} +1 -1
- package/dist/features/schema/context.d.ts +7 -0
- package/dist/features/schema/context.js +11 -0
- package/dist/{payload/schemaContext.d.ts → features/schema/description.d.ts} +6 -33
- package/dist/{payload/schemaContext.js → features/schema/description.js} +3 -207
- package/dist/{payload/toolFieldSelection.d.ts → features/schema/fieldSelection.d.ts} +1 -1
- package/dist/{payload/toolFieldSelection.js → features/schema/fieldSelection.js} +2 -2
- package/dist/features/schema/mentionDocuments.d.ts +15 -0
- package/dist/features/schema/mentionDocuments.js +50 -0
- package/dist/features/schema/mentions.d.ts +18 -0
- package/dist/features/schema/mentions.js +100 -0
- package/dist/{payload/normalizeData.js → features/schema/normalize.js} +1 -1
- package/dist/features/schema/registry.d.ts +30 -0
- package/dist/features/schema/registry.js +73 -0
- package/dist/{payload → features/schema}/toolSchemas.d.ts +1 -1
- package/dist/{payload → features/schema}/toolSchemas.js +1 -1
- package/dist/{ai → features}/sensitiveData.js +1 -1
- package/dist/{ai → features}/tokenUsage.d.ts +1 -2
- package/dist/handlers/apply/audit.d.ts +42 -0
- package/dist/handlers/apply/audit.js +150 -0
- package/dist/handlers/apply/operations.d.ts +18 -0
- package/dist/handlers/apply/operations.js +377 -0
- package/dist/handlers/apply/types.d.ts +33 -0
- package/dist/handlers/apply/types.js +1 -0
- package/dist/handlers/apply/validation.d.ts +45 -0
- package/dist/handlers/apply/validation.js +125 -0
- package/dist/handlers/applyActionHandler.d.ts +1 -6
- package/dist/handlers/applyActionHandler.js +13 -757
- package/dist/handlers/auditLogHandler.js +4 -8
- package/dist/handlers/chat/intent.d.ts +32 -0
- package/dist/handlers/chat/intent.js +155 -0
- package/dist/handlers/chat/prompt.d.ts +20 -0
- package/dist/handlers/chat/prompt.js +55 -0
- package/dist/handlers/chat/proposalTools.d.ts +96 -0
- package/dist/handlers/chat/proposalTools.js +451 -0
- package/dist/handlers/chat/streaming.d.ts +38 -0
- package/dist/handlers/chat/streaming.js +136 -0
- package/dist/handlers/chat/toolFactory.d.ts +79 -0
- package/dist/handlers/chat/toolFactory.js +156 -0
- package/dist/handlers/chat/types.d.ts +57 -0
- package/dist/handlers/chat/types.js +1 -0
- package/dist/handlers/chatHandler.d.ts +1 -44
- package/dist/handlers/chatHandler.js +186 -1162
- package/dist/handlers/generateFieldHandler.d.ts +3 -8
- package/dist/handlers/generateFieldHandler.js +71 -99
- package/dist/handlers/http.d.ts +17 -0
- package/dist/handlers/http.js +21 -0
- package/dist/handlers/mediaUploadHandler.js +12 -34
- package/dist/handlers/mentionSuggestionHandler.d.ts +1 -1
- package/dist/handlers/mentionSuggestionHandler.js +6 -10
- package/dist/handlers/proposalDiffHandler.d.ts +1 -1
- package/dist/handlers/proposalDiffHandler.js +72 -195
- package/dist/handlers/translateDocumentHandler.d.ts +3 -8
- package/dist/handlers/translateDocumentHandler.js +26 -82
- package/dist/index.d.ts +4 -30
- package/dist/index.js +31 -421
- package/dist/plugin/admin.d.ts +30 -0
- package/dist/plugin/admin.js +155 -0
- package/dist/plugin/collections.d.ts +3 -0
- package/dist/plugin/collections.js +169 -0
- package/dist/plugin/endpoints.d.ts +23 -0
- package/dist/plugin/endpoints.js +84 -0
- package/dist/plugin/options.d.ts +4 -0
- package/dist/plugin/options.js +13 -0
- package/dist/plugin/types.d.ts +28 -0
- package/dist/plugin/types.js +1 -0
- package/dist/{payload/shared.d.ts → utils/data.d.ts} +2 -12
- package/package.json +1 -1
- package/dist/payload/proposalData.js +0 -578
- /package/dist/{payload → features}/collectionPermissions.d.ts +0 -0
- /package/dist/{payload → features/content}/documentTranslation.d.ts +0 -0
- /package/dist/{payload → features/content}/documentTranslation.js +0 -0
- /package/dist/{ai → features}/promptCaching.js +0 -0
- /package/dist/{ai/proposalRepair.js → features/proposals/repair.js} +0 -0
- /package/dist/{ai/providerOptions.d.ts → features/providers/options.d.ts} +0 -0
- /package/dist/{ai/providerOptions.js → features/providers/options.js} +0 -0
- /package/dist/{payload/normalizeData.d.ts → features/schema/normalize.d.ts} +0 -0
- /package/dist/{ai → features}/sensitiveData.d.ts +0 -0
- /package/dist/{ai → features}/tokenUsage.js +0 -0
- /package/dist/{payload/shared.js → utils/data.js} +0 -0
- /package/dist/{payload → utils}/logging.d.ts +0 -0
- /package/dist/{payload → utils}/logging.js +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { containsSensitiveData } from "../../features/sensitiveData.js";
|
|
2
|
+
import { validateSignedProposal } from "../../features/proposals/validation.js";
|
|
3
|
+
import { getOptionalNumber, hasLocalizedData } from "../../utils/data.js";
|
|
4
|
+
import { logHandlerEvent } from "../../utils/logging.js";
|
|
5
|
+
import { readJSONBody } from "../http.js";
|
|
6
|
+
export const getProposalLogSummary = (proposal)=>({
|
|
7
|
+
action: proposal.action,
|
|
8
|
+
collection: "collection" in proposal ? proposal.collection : undefined,
|
|
9
|
+
hasData: "data" in proposal && Boolean(proposal.data),
|
|
10
|
+
hasLocalizedData: "localizedData" in proposal && Boolean(proposal.localizedData),
|
|
11
|
+
id: "id" in proposal ? proposal.id : undefined,
|
|
12
|
+
label: proposal.label,
|
|
13
|
+
locale: proposal.locale,
|
|
14
|
+
locales: "localizedData" in proposal && proposal.localizedData ? Object.keys(proposal.localizedData) : undefined,
|
|
15
|
+
slug: "slug" in proposal ? proposal.slug : undefined
|
|
16
|
+
});
|
|
17
|
+
export const getProposalMeta = (proposal)=>{
|
|
18
|
+
if (!proposal) return {};
|
|
19
|
+
return {
|
|
20
|
+
action: proposal.action,
|
|
21
|
+
collection: "collection" in proposal ? proposal.collection : undefined,
|
|
22
|
+
id: "id" in proposal ? proposal.id : undefined,
|
|
23
|
+
slug: "slug" in proposal ? proposal.slug : undefined
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const createApplyDebugPayload = ({ details, phase, proposal, reason })=>({
|
|
27
|
+
...getProposalMeta(proposal),
|
|
28
|
+
details,
|
|
29
|
+
phase,
|
|
30
|
+
reason
|
|
31
|
+
});
|
|
32
|
+
const failure = ({ details, error, logMessage, phase = "apply_validation", proposal, reason, status })=>({
|
|
33
|
+
failure: {
|
|
34
|
+
debug: createApplyDebugPayload({
|
|
35
|
+
details,
|
|
36
|
+
phase,
|
|
37
|
+
proposal,
|
|
38
|
+
reason
|
|
39
|
+
}),
|
|
40
|
+
error,
|
|
41
|
+
logMessage,
|
|
42
|
+
proposal,
|
|
43
|
+
status
|
|
44
|
+
},
|
|
45
|
+
ok: false
|
|
46
|
+
});
|
|
47
|
+
export const resolveApplyRequest = async (req)=>{
|
|
48
|
+
if (!req.user) {
|
|
49
|
+
return failure({
|
|
50
|
+
error: "Unauthorized",
|
|
51
|
+
logMessage: "AI apply blocked: unauthorized request",
|
|
52
|
+
phase: "authorization",
|
|
53
|
+
reason: "unauthorized",
|
|
54
|
+
status: 401
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const body = await readJSONBody(req);
|
|
58
|
+
const proposalValidation = validateSignedProposal(body?.proposal);
|
|
59
|
+
if (!proposalValidation.ok && proposalValidation.error === "missing") {
|
|
60
|
+
return failure({
|
|
61
|
+
error: "Proposal is required",
|
|
62
|
+
logMessage: "AI apply blocked: missing proposal payload",
|
|
63
|
+
reason: "missing_proposal"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!proposalValidation.ok && proposalValidation.error === "invalid_signature") {
|
|
67
|
+
return failure({
|
|
68
|
+
error: "Proposal signature is invalid or expired.",
|
|
69
|
+
logMessage: "AI apply blocked: invalid proposal signature",
|
|
70
|
+
proposal: proposalValidation.proposal,
|
|
71
|
+
reason: "invalid_signature"
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (!proposalValidation.ok) {
|
|
75
|
+
return failure({
|
|
76
|
+
error: "Proposal is invalid.",
|
|
77
|
+
logMessage: "AI apply blocked: invalid proposal shape",
|
|
78
|
+
proposal: proposalValidation.proposal,
|
|
79
|
+
reason: "invalid_proposal_shape"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const proposal = proposalValidation.proposal;
|
|
83
|
+
if ("data" in proposal && proposal.data && containsSensitiveData(proposal.data)) {
|
|
84
|
+
return failure({
|
|
85
|
+
error: "Proposal contains sensitive fields and cannot be applied.",
|
|
86
|
+
logMessage: "AI apply blocked: sensitive data detected in proposal data",
|
|
87
|
+
proposal,
|
|
88
|
+
reason: "sensitive_data_in_data"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (hasLocalizedData(proposal) && Object.values(proposal.localizedData).some((value)=>containsSensitiveData(value))) {
|
|
92
|
+
return failure({
|
|
93
|
+
error: "Proposal contains sensitive fields and cannot be applied.",
|
|
94
|
+
logMessage: "AI apply blocked: sensitive data detected in localized proposal data",
|
|
95
|
+
proposal,
|
|
96
|
+
reason: "sensitive_data_in_localized_data"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
context: {
|
|
101
|
+
aiResponse: typeof body?.aiResponse === "string" && body.aiResponse.trim() ? body.aiResponse.trim() : undefined,
|
|
102
|
+
prompt: typeof body?.prompt === "string" && body.prompt.trim() ? body.prompt.trim() : undefined,
|
|
103
|
+
tokenUsage: body?.tokenUsage ? {
|
|
104
|
+
inputTokens: getOptionalNumber(body.tokenUsage.inputTokens),
|
|
105
|
+
outputTokens: getOptionalNumber(body.tokenUsage.outputTokens),
|
|
106
|
+
totalTokens: getOptionalNumber(body.tokenUsage.totalTokens)
|
|
107
|
+
} : undefined
|
|
108
|
+
},
|
|
109
|
+
ok: true,
|
|
110
|
+
proposal
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export const createApplyFailureResponse = (req, applyFailure)=>{
|
|
114
|
+
logHandlerEvent(req, "warn", {
|
|
115
|
+
debug: applyFailure.debug,
|
|
116
|
+
msg: applyFailure.logMessage,
|
|
117
|
+
proposal: getProposalMeta(applyFailure.proposal)
|
|
118
|
+
});
|
|
119
|
+
return Response.json({
|
|
120
|
+
debug: applyFailure.debug,
|
|
121
|
+
error: applyFailure.error
|
|
122
|
+
}, {
|
|
123
|
+
status: applyFailure.status || 400
|
|
124
|
+
});
|
|
125
|
+
};
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { PayloadHandler } from "payload";
|
|
2
|
-
import {
|
|
3
|
-
type ApplyActionOptions = {
|
|
4
|
-
changeLogCollection?: string;
|
|
5
|
-
collections?: ResolvedCollectionPermissionMap;
|
|
6
|
-
};
|
|
2
|
+
import type { ApplyActionOptions } from "./apply/types.js";
|
|
7
3
|
export declare const createApplyActionHandler: (options?: ApplyActionOptions) => PayloadHandler;
|
|
8
|
-
export {};
|