@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.
Files changed (126) hide show
  1. package/dist/components/action-toast/ActionToast.d.ts +1 -14
  2. package/dist/components/action-toast/ActionToast.js +1 -1
  3. package/dist/components/ai-input/AIInput.js +1 -1
  4. package/dist/components/audit-log-list/AuditLogList.d.ts +2 -3
  5. package/dist/components/diff-dialog/DiffDialog.d.ts +2 -6
  6. package/dist/components/diff-dialog/DiffDialog.js +1 -1
  7. package/dist/components/generate-field/GenerateField.js +2 -0
  8. package/dist/components/hooks/useAIChatStream.d.ts +1 -1
  9. package/dist/components/hooks/useAISettings.d.ts +1 -1
  10. package/dist/components/hooks/useAISettings.js +1 -1
  11. package/dist/components/hooks/useDocumentMentionSuggestions.js +1 -1
  12. package/dist/components/hooks/useMentions.js +1 -1
  13. package/dist/components/hooks/usePluginConfig.d.ts +6 -6
  14. package/dist/components/hooks/usePluginConfig.js +1 -1
  15. package/dist/{payload → features}/collectionPermissions.js +1 -1
  16. package/dist/{payload/textFieldGeneration.d.ts → features/content/fieldGeneration.d.ts} +4 -0
  17. package/dist/{payload/textFieldGeneration.js → features/content/fieldGeneration.js} +19 -3
  18. package/dist/{ai → features}/promptCaching.d.ts +2 -2
  19. package/dist/features/proposals/containerNormalization.d.ts +8 -0
  20. package/dist/features/proposals/containerNormalization.js +112 -0
  21. package/dist/{payload/proposalData.d.ts → features/proposals/data.d.ts} +5 -10
  22. package/dist/features/proposals/data.js +113 -0
  23. package/dist/features/proposals/fieldNormalization.d.ts +2 -0
  24. package/dist/features/proposals/fieldNormalization.js +69 -0
  25. package/dist/features/proposals/normalizationTypes.d.ts +31 -0
  26. package/dist/features/proposals/normalizationTypes.js +1 -0
  27. package/dist/features/proposals/optionInference.d.ts +13 -0
  28. package/dist/features/proposals/optionInference.js +46 -0
  29. package/dist/features/proposals/recordNormalization.d.ts +6 -0
  30. package/dist/features/proposals/recordNormalization.js +78 -0
  31. package/dist/features/proposals/relationshipNormalization.d.ts +8 -0
  32. package/dist/features/proposals/relationshipNormalization.js +71 -0
  33. package/dist/{ai/proposalRepair.d.ts → features/proposals/repair.d.ts} +1 -1
  34. package/dist/{ai/proposalSigning.d.ts → features/proposals/signing.d.ts} +2 -5
  35. package/dist/{ai/proposalSigning.js → features/proposals/signing.js} +1 -1
  36. package/dist/features/proposals/target.d.ts +52 -0
  37. package/dist/features/proposals/target.js +125 -0
  38. package/dist/features/proposals/types.d.ts +49 -0
  39. package/dist/features/proposals/types.js +1 -0
  40. package/dist/features/proposals/validation.d.ts +12 -0
  41. package/dist/features/proposals/validation.js +26 -0
  42. package/dist/features/providers/requestContext.d.ts +53 -0
  43. package/dist/features/providers/requestContext.js +90 -0
  44. package/dist/{ai/providerRuntime.d.ts → features/providers/runtime.d.ts} +1 -1
  45. package/dist/{ai/providerRuntime.js → features/providers/runtime.js} +1 -1
  46. package/dist/features/schema/context.d.ts +7 -0
  47. package/dist/features/schema/context.js +11 -0
  48. package/dist/{payload/schemaContext.d.ts → features/schema/description.d.ts} +6 -33
  49. package/dist/{payload/schemaContext.js → features/schema/description.js} +3 -207
  50. package/dist/{payload/toolFieldSelection.d.ts → features/schema/fieldSelection.d.ts} +1 -1
  51. package/dist/{payload/toolFieldSelection.js → features/schema/fieldSelection.js} +2 -2
  52. package/dist/features/schema/mentionDocuments.d.ts +15 -0
  53. package/dist/features/schema/mentionDocuments.js +50 -0
  54. package/dist/features/schema/mentions.d.ts +18 -0
  55. package/dist/features/schema/mentions.js +100 -0
  56. package/dist/{payload/normalizeData.js → features/schema/normalize.js} +1 -1
  57. package/dist/features/schema/registry.d.ts +30 -0
  58. package/dist/features/schema/registry.js +73 -0
  59. package/dist/{payload → features/schema}/toolSchemas.d.ts +1 -1
  60. package/dist/{payload → features/schema}/toolSchemas.js +1 -1
  61. package/dist/{ai → features}/sensitiveData.js +1 -1
  62. package/dist/{ai → features}/tokenUsage.d.ts +1 -2
  63. package/dist/handlers/apply/audit.d.ts +42 -0
  64. package/dist/handlers/apply/audit.js +150 -0
  65. package/dist/handlers/apply/operations.d.ts +18 -0
  66. package/dist/handlers/apply/operations.js +377 -0
  67. package/dist/handlers/apply/types.d.ts +33 -0
  68. package/dist/handlers/apply/types.js +1 -0
  69. package/dist/handlers/apply/validation.d.ts +45 -0
  70. package/dist/handlers/apply/validation.js +125 -0
  71. package/dist/handlers/applyActionHandler.d.ts +1 -6
  72. package/dist/handlers/applyActionHandler.js +13 -757
  73. package/dist/handlers/auditLogHandler.js +4 -8
  74. package/dist/handlers/chat/intent.d.ts +32 -0
  75. package/dist/handlers/chat/intent.js +155 -0
  76. package/dist/handlers/chat/prompt.d.ts +20 -0
  77. package/dist/handlers/chat/prompt.js +55 -0
  78. package/dist/handlers/chat/proposalTools.d.ts +96 -0
  79. package/dist/handlers/chat/proposalTools.js +451 -0
  80. package/dist/handlers/chat/streaming.d.ts +38 -0
  81. package/dist/handlers/chat/streaming.js +136 -0
  82. package/dist/handlers/chat/toolFactory.d.ts +79 -0
  83. package/dist/handlers/chat/toolFactory.js +156 -0
  84. package/dist/handlers/chat/types.d.ts +57 -0
  85. package/dist/handlers/chat/types.js +1 -0
  86. package/dist/handlers/chatHandler.d.ts +1 -44
  87. package/dist/handlers/chatHandler.js +186 -1162
  88. package/dist/handlers/generateFieldHandler.d.ts +3 -8
  89. package/dist/handlers/generateFieldHandler.js +71 -99
  90. package/dist/handlers/http.d.ts +17 -0
  91. package/dist/handlers/http.js +21 -0
  92. package/dist/handlers/mediaUploadHandler.js +12 -34
  93. package/dist/handlers/mentionSuggestionHandler.d.ts +1 -1
  94. package/dist/handlers/mentionSuggestionHandler.js +6 -10
  95. package/dist/handlers/proposalDiffHandler.d.ts +1 -1
  96. package/dist/handlers/proposalDiffHandler.js +72 -195
  97. package/dist/handlers/translateDocumentHandler.d.ts +3 -8
  98. package/dist/handlers/translateDocumentHandler.js +26 -82
  99. package/dist/index.d.ts +4 -30
  100. package/dist/index.js +31 -421
  101. package/dist/plugin/admin.d.ts +30 -0
  102. package/dist/plugin/admin.js +155 -0
  103. package/dist/plugin/collections.d.ts +3 -0
  104. package/dist/plugin/collections.js +169 -0
  105. package/dist/plugin/endpoints.d.ts +23 -0
  106. package/dist/plugin/endpoints.js +84 -0
  107. package/dist/plugin/options.d.ts +4 -0
  108. package/dist/plugin/options.js +13 -0
  109. package/dist/plugin/types.d.ts +28 -0
  110. package/dist/plugin/types.js +1 -0
  111. package/dist/{payload/shared.d.ts → utils/data.d.ts} +2 -12
  112. package/package.json +1 -1
  113. package/dist/payload/proposalData.js +0 -578
  114. /package/dist/{payload → features}/collectionPermissions.d.ts +0 -0
  115. /package/dist/{payload → features/content}/documentTranslation.d.ts +0 -0
  116. /package/dist/{payload → features/content}/documentTranslation.js +0 -0
  117. /package/dist/{ai → features}/promptCaching.js +0 -0
  118. /package/dist/{ai/proposalRepair.js → features/proposals/repair.js} +0 -0
  119. /package/dist/{ai/providerOptions.d.ts → features/providers/options.d.ts} +0 -0
  120. /package/dist/{ai/providerOptions.js → features/providers/options.js} +0 -0
  121. /package/dist/{payload/normalizeData.d.ts → features/schema/normalize.d.ts} +0 -0
  122. /package/dist/{ai → features}/sensitiveData.d.ts +0 -0
  123. /package/dist/{ai → features}/tokenUsage.js +0 -0
  124. /package/dist/{payload/shared.js → utils/data.js} +0 -0
  125. /package/dist/{payload → utils}/logging.d.ts +0 -0
  126. /package/dist/{payload → utils}/logging.js +0 -0
@@ -1,10 +1,6 @@
1
- import { getNumber, getString } from "../payload/shared.js";
2
- export const createAuditLogHandler = (options)=>async (req)=>{
3
- if (!req.user) return Response.json({
4
- error: "Unauthorized"
5
- }, {
6
- status: 401
7
- });
1
+ import { getNumber, getString } from "../utils/data.js";
2
+ import { withAuthenticatedHandler } from "./http.js";
3
+ export const createAuditLogHandler = (options)=>withAuthenticatedHandler(async (req)=>{
8
4
  const result = await req.payload.find({
9
5
  collection: options.changeLogCollection,
10
6
  depth: 0,
@@ -36,4 +32,4 @@ export const createAuditLogHandler = (options)=>async (req)=>{
36
32
  url: getString(doc.targetURL)
37
33
  }))
38
34
  });
39
- };
35
+ });
@@ -0,0 +1,32 @@
1
+ import type { ChatIntent, ToolChoice } from "./types.js";
2
+ export declare const createCollectionAliasMap: (collections: Array<{
3
+ labels?: {
4
+ plural?: unknown;
5
+ singular?: unknown;
6
+ };
7
+ slug: string;
8
+ }>) => {
9
+ [k: string]: string;
10
+ };
11
+ export declare const getLikelyCollectionMatches: ({ aliasMap, prompt }: {
12
+ aliasMap: Record<string, string>;
13
+ prompt: string;
14
+ }) => string[];
15
+ export declare const getChatIntent: ({ hasCurrentDocument, hasCurrentGlobal, prompt, }: {
16
+ hasCurrentDocument: boolean;
17
+ hasCurrentGlobal: boolean;
18
+ prompt: string;
19
+ }) => ChatIntent;
20
+ export declare const getIntentToolChoice: ({ hasKnownCollection, hasKnownDocument, hasKnownGlobal, intent, }: {
21
+ hasKnownCollection: boolean;
22
+ hasKnownDocument: boolean;
23
+ hasKnownGlobal: boolean;
24
+ intent: ChatIntent;
25
+ }) => ToolChoice | undefined;
26
+ export declare const getToolNamesForIntent: ({ hasAttachments, hasKnownCollection, hasCurrentDocument, hasCurrentGlobal, intent, }: {
27
+ hasAttachments: boolean;
28
+ hasKnownCollection: boolean;
29
+ hasCurrentDocument: boolean;
30
+ hasCurrentGlobal: boolean;
31
+ intent: ChatIntent;
32
+ }) => Set<string>;
@@ -0,0 +1,155 @@
1
+ const regexSpecialCharactersPattern = /[.*+?^${}()|[\]\\]/g;
2
+ export const createCollectionAliasMap = (collections)=>{
3
+ const aliasMap = new Map();
4
+ const addAlias = (alias, slug)=>{
5
+ const normalizedAlias = alias?.trim().toLowerCase();
6
+ if (!normalizedAlias) return;
7
+ if (!aliasMap.has(normalizedAlias)) aliasMap.set(normalizedAlias, slug);
8
+ };
9
+ for (const collection of collections){
10
+ addAlias(collection.slug, collection.slug);
11
+ addAlias(collection.slug.replace(/-/g, " "), collection.slug);
12
+ const singular = typeof collection.labels?.singular === "string" ? collection.labels.singular : undefined;
13
+ const plural = typeof collection.labels?.plural === "string" ? collection.labels.plural : undefined;
14
+ addAlias(singular, collection.slug);
15
+ addAlias(plural, collection.slug);
16
+ if (singular?.endsWith("s")) addAlias(singular.slice(0, -1), collection.slug);
17
+ if (plural?.endsWith("s")) addAlias(plural.slice(0, -1), collection.slug);
18
+ }
19
+ return Object.fromEntries(aliasMap.entries());
20
+ };
21
+ export const getLikelyCollectionMatches = ({ aliasMap, prompt })=>{
22
+ const normalizedPrompt = prompt.toLowerCase();
23
+ const matches = new Set();
24
+ const aliases = Object.keys(aliasMap).sort((a, b)=>b.length - a.length);
25
+ const aliasPattern = aliases.length > 0 ? new RegExp(aliases.map((alias)=>alias.replace(regexSpecialCharactersPattern, "\\$&")).join("|"), "g") : null;
26
+ if (!aliasPattern) return [];
27
+ for (const match of normalizedPrompt.matchAll(aliasPattern)){
28
+ const slug = aliasMap[match[0]];
29
+ if (slug) matches.add(slug);
30
+ }
31
+ return [
32
+ ...matches
33
+ ];
34
+ };
35
+ const normalizeIntentText = (prompt)=>prompt.toLowerCase().replace(/ä/g, "ae").replace(/ö/g, "oe").replace(/ü/g, "ue").replace(/ß/g, "ss").normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
36
+ const deleteIntentPattern = /\b(?:delete|remove|erase|destroy|discard|purge|loesch\w*|losch\w*|entfern\w*|rausnehm\w*|wegnehm\w*|verwerf\w*)\b/;
37
+ const createIntentPattern = /\b(?:create|build|generate|draft|compose|author|write|make|new|erstell\w*|anleg\w*|erzeug\w*|generier\w*|entwerf\w*|verfass\w*|schreib\w*|neu)\b/;
38
+ const updateIntentPattern = /\b(?:update|edit|change|modify|revise|refine|rewrite|translate|replace|rename|correct|fix|set|publish|unpublish|aktualisier\w*|aender\w*|bearbeit\w*|anpass\w*|ueberarbeit\w*|uberarbeit\w*|umschreib\w*|uebersetz\w*|ubersetz\w*|ersetz\w*|umbenenn\w*|korrigier\w*|reparier\w*|setz\w*|veroeffentlich\w*|veroffentlich\w*|zurueckzieh\w*|zuruckzieh\w*)\b/;
39
+ const additiveIntentPattern = /\b(?:add|insert|append|attach|assign|link|include|extend|ergaenz\w*|erganz\w*|hinzufueg\w*|hinzufug\w*|einfueg\w*|einfug\w*|anhaeng\w*|anhang\w*|zuweis\w*|verknuepf\w*|verknupf\w*)\b/;
40
+ const searchIntentPattern = /\b(?:search|find|lookup|locate|list|show|fetch|browse|query|such\w*|find\w*|nachschlag\w*|auflist\w*|anzeig\w*|zeig\w*|hol\w*|durchsuch\w*)\b/;
41
+ const separableDeleteIntentPattern = /\b(?:nimm|nehm\w*)\b(?:\s+\w+){0,8}\s+(?:raus|weg)\b/;
42
+ const separableUpdateIntentPattern = /\b(?:pass(?:e|t|en|st)?\b(?:\s+\w+){0,8}\s+an|fueg\w*\b(?:\s+\w+){0,8}\s+(?:ein|hinzu)|haeng\w*\b(?:\s+\w+){0,8}\s+an|weis\w*\b(?:\s+\w+){0,8}\s+zu)\b/;
43
+ export const getChatIntent = ({ hasCurrentDocument, hasCurrentGlobal, prompt })=>{
44
+ const normalizedPrompt = normalizeIntentText(prompt);
45
+ if (deleteIntentPattern.test(normalizedPrompt) || separableDeleteIntentPattern.test(normalizedPrompt)) {
46
+ return hasCurrentGlobal ? "read" : "delete";
47
+ }
48
+ if (createIntentPattern.test(normalizedPrompt)) {
49
+ if (hasCurrentGlobal) return "updateGlobal";
50
+ if (hasCurrentDocument) return "update";
51
+ return "create";
52
+ }
53
+ if (updateIntentPattern.test(normalizedPrompt) || additiveIntentPattern.test(normalizedPrompt) || separableUpdateIntentPattern.test(normalizedPrompt)) {
54
+ return hasCurrentGlobal ? "updateGlobal" : "update";
55
+ }
56
+ if (searchIntentPattern.test(normalizedPrompt)) return "search";
57
+ return "read";
58
+ };
59
+ export const getIntentToolChoice = ({ hasKnownCollection, hasKnownDocument, hasKnownGlobal, intent })=>{
60
+ if (intent === "create" && hasKnownCollection) return {
61
+ toolName: "proposeCreateDoc",
62
+ type: "tool"
63
+ };
64
+ if (intent === "update" && hasKnownDocument) return {
65
+ toolName: "proposeUpdateDoc",
66
+ type: "tool"
67
+ };
68
+ if (intent === "delete" && hasKnownDocument) return {
69
+ toolName: "proposeDeleteDoc",
70
+ type: "tool"
71
+ };
72
+ if (intent === "updateGlobal" && hasKnownGlobal) return {
73
+ toolName: "proposeUpdateGlobal",
74
+ type: "tool"
75
+ };
76
+ return undefined;
77
+ };
78
+ export const getToolNamesForIntent = ({ hasAttachments, hasKnownCollection, hasCurrentDocument, hasCurrentGlobal, intent })=>{
79
+ if (hasCurrentGlobal) {
80
+ return new Set(intent === "updateGlobal" ? [
81
+ "getGlobal",
82
+ "listGlobals",
83
+ "proposeUpdateGlobal"
84
+ ] : [
85
+ "getGlobal",
86
+ "listGlobals"
87
+ ]);
88
+ }
89
+ if (hasCurrentDocument) {
90
+ if (intent === "delete") return new Set([
91
+ "getDoc",
92
+ "proposeDeleteDoc"
93
+ ]);
94
+ if (intent === "update" || intent === "create") return new Set([
95
+ "getDoc",
96
+ "listCollections",
97
+ "proposeUpdateDoc"
98
+ ]);
99
+ return new Set([
100
+ "getDoc",
101
+ "listCollections"
102
+ ]);
103
+ }
104
+ if (hasKnownCollection) {
105
+ if (intent === "create") return new Set([
106
+ "getDoc",
107
+ "listCollections",
108
+ "proposeCreateDoc",
109
+ "searchDocs"
110
+ ]);
111
+ if (intent === "update") return new Set([
112
+ "getDoc",
113
+ "listCollections",
114
+ "proposeUpdateDoc",
115
+ "searchDocs"
116
+ ]);
117
+ if (intent === "delete") return new Set([
118
+ "getDoc",
119
+ "proposeDeleteDoc",
120
+ "searchDocs"
121
+ ]);
122
+ return new Set([
123
+ "getDoc",
124
+ "listCollections",
125
+ "searchDocs"
126
+ ]);
127
+ }
128
+ const toolNames = intent === "create" ? new Set([
129
+ "getDoc",
130
+ "listCollections",
131
+ "proposeCreateDoc",
132
+ "searchDocs"
133
+ ]) : intent === "update" ? new Set([
134
+ "getDoc",
135
+ "getGlobal",
136
+ "listCollections",
137
+ "listGlobals",
138
+ "proposeUpdateDoc",
139
+ "proposeUpdateGlobal",
140
+ "searchDocs"
141
+ ]) : intent === "delete" ? new Set([
142
+ "getDoc",
143
+ "listCollections",
144
+ "proposeDeleteDoc",
145
+ "searchDocs"
146
+ ]) : new Set([
147
+ "getDoc",
148
+ "getGlobal",
149
+ "listCollections",
150
+ "listGlobals",
151
+ "searchDocs"
152
+ ]);
153
+ if (hasAttachments && (intent === "create" || intent === "update")) toolNames.add("proposeUpdateDoc");
154
+ return toolNames;
155
+ };
@@ -0,0 +1,20 @@
1
+ import type { SystemModelMessage } from "ai";
2
+ import type { AIProvider } from "../../features/providers/options.js";
3
+ import { type PromptCacheProviderOptions } from "../../features/promptCaching.js";
4
+ export declare const createChatPromptContext: ({ chatIntent, collectionAliasMap, focusedRequiredFieldsByCollection, focusedTitleFieldByCollection, intentToolName, likelyCollectionMatches, mentionContext, modelID, promptCaching, provider, scopedToolNames, }: {
5
+ chatIntent: string;
6
+ collectionAliasMap: Record<string, string>;
7
+ focusedRequiredFieldsByCollection: Record<string, unknown>;
8
+ focusedTitleFieldByCollection: Record<string, unknown>;
9
+ intentToolName?: string;
10
+ likelyCollectionMatches: string[];
11
+ mentionContext: unknown;
12
+ modelID: string;
13
+ promptCaching: boolean;
14
+ provider: AIProvider;
15
+ scopedToolNames: Set<string>;
16
+ }) => {
17
+ dynamicMentionContext: Record<string, unknown>[];
18
+ promptCacheProviderOptions: PromptCacheProviderOptions | undefined;
19
+ system: SystemModelMessage[];
20
+ };
@@ -0,0 +1,55 @@
1
+ import { createCachedSystemMessages, createPromptCacheProviderOptions, splitPromptCacheContext } from "../../features/promptCaching.js";
2
+ import { redactSensitiveData } from "../../features/sensitiveData.js";
3
+ export const createChatPromptContext = ({ chatIntent, collectionAliasMap, focusedRequiredFieldsByCollection, focusedTitleFieldByCollection, intentToolName, likelyCollectionMatches, mentionContext, modelID, promptCaching, provider, scopedToolNames })=>{
4
+ const sanitizedMentionContext = redactSensitiveData(mentionContext);
5
+ const { cacheable: cacheableMentionContext, dynamic: dynamicMentionContext } = splitPromptCacheContext(sanitizedMentionContext);
6
+ const staticSystemInstructions = [
7
+ "You are a Payload CMS assistant. Inspect schema/content with tools before proposing writes.",
8
+ "Mentions define the active CMS scope. Locale mentions define active locale; multiple locales require localizedData keyed by locale.",
9
+ "Writes are proposals only. Never claim changes were applied before user confirmation.",
10
+ "Uploaded media attachments appear in context as mediaAttachment entries. Use their exact IDs for upload fields.",
11
+ "If an uploaded media document has editable descriptive fields, propose an update to that media document with suitable values.",
12
+ "If a collection has a required `slug` field and the user does not provide it, generate a URL-friendly slug from the title or from the first meaningful word of the prompt.",
13
+ "For create/update/delete requests, you must use proposal tools. Do not end with plain text if the user asked for a content change.",
14
+ "If the user asks to create, update, refine, translate, remove, or delete content, produce at least one proposal tool call unless blocked by missing schema information or permissions.",
15
+ "Put concrete field values only in tool data, not visible text.",
16
+ "For blocks fields: use exact blockType values from schema, exact field names, and complete objects for required block fields.",
17
+ "For arrays: every item must be an object matching the child field schema, not free text.",
18
+ "If schema details are missing, call listCollections/listGlobals with a slug before proposing. If an inferred collection schema is already present in context, use it directly.",
19
+ "Read tools return compact identity fields by default. Request only the additional fields needed for the current task; full schemas remain available separately.",
20
+ "If a proposal tool returns retryable=true, correct only repair.issues and call the same proposal tool once more. If retryable=false, do not retry that tool target."
21
+ ];
22
+ const cacheableSystemInstructions = [
23
+ `Collection aliases: ${JSON.stringify(collectionAliasMap)}.`,
24
+ `Focused required create fields: ${JSON.stringify(focusedRequiredFieldsByCollection)}.`,
25
+ `Focused title fields: ${JSON.stringify(focusedTitleFieldByCollection)}. Infer concise titles when needed.`
26
+ ];
27
+ const dynamicSystemInstructions = [
28
+ `Likely collection matches for this prompt: ${JSON.stringify(likelyCollectionMatches)}.`,
29
+ `Request intent: ${chatIntent}. Preferred proposal tool: ${intentToolName || "none"}.`,
30
+ "Visible response: plain text, under 40 words, no Markdown, no proposed content."
31
+ ];
32
+ return {
33
+ dynamicMentionContext,
34
+ promptCacheProviderOptions: createPromptCacheProviderOptions({
35
+ cacheKeyParts: [
36
+ cacheableMentionContext,
37
+ cacheableSystemInstructions,
38
+ [
39
+ ...scopedToolNames
40
+ ].sort()
41
+ ],
42
+ enabled: promptCaching,
43
+ model: modelID,
44
+ provider
45
+ }),
46
+ system: createCachedSystemMessages({
47
+ cacheableContext: cacheableMentionContext,
48
+ cacheableInstructions: cacheableSystemInstructions,
49
+ dynamicInstructions: dynamicSystemInstructions,
50
+ enabled: promptCaching,
51
+ provider,
52
+ staticInstructions: staticSystemInstructions
53
+ })
54
+ };
55
+ };
@@ -0,0 +1,96 @@
1
+ import type { PayloadHandler } from "payload";
2
+ import type { ActionProposal, LocalizedDataInput } from "../../features/proposals/types.js";
3
+ import type { FieldConfig as ProposalFieldConfig } from "../../features/schema/normalize.js";
4
+ import type { ChatMention, FieldConfig } from "../../features/schema/context.js";
5
+ type RequiredFieldInfo = {
6
+ defaultValue?: unknown;
7
+ isTitleField?: boolean;
8
+ localized: boolean;
9
+ options?: (string | {
10
+ label?: unknown;
11
+ value?: string;
12
+ })[];
13
+ path: string;
14
+ type?: string;
15
+ };
16
+ export type BlockFieldConfig = ProposalFieldConfig & {
17
+ blocks?: Array<{
18
+ fields?: ProposalFieldConfig[];
19
+ slug: string;
20
+ }>;
21
+ fields?: ProposalFieldConfig[];
22
+ name?: string;
23
+ type?: string;
24
+ };
25
+ type RelationshipTargetReference = {
26
+ collection: string;
27
+ id: number | string;
28
+ path: string;
29
+ };
30
+ export declare const getRequiredFieldInfos: (fields: FieldConfig[], titleFieldName?: string, path?: string) => RequiredFieldInfo[];
31
+ export declare const fillMissingCreateFields: ({ data, label, localizedData, requiredFields, }: {
32
+ data?: Record<string, unknown>;
33
+ label: string;
34
+ localizedData?: LocalizedDataInput;
35
+ requiredFields: RequiredFieldInfo[];
36
+ }) => {
37
+ localizedData: {
38
+ [k: string]: {
39
+ [x: string]: unknown;
40
+ };
41
+ };
42
+ data?: undefined;
43
+ } | {
44
+ data: {
45
+ [x: string]: unknown;
46
+ };
47
+ localizedData?: undefined;
48
+ };
49
+ export declare const getMissingCreateFields: ({ data, localizedData, requiredFields, }: {
50
+ data?: Record<string, unknown>;
51
+ localizedData?: LocalizedDataInput;
52
+ requiredFields: RequiredFieldInfo[];
53
+ }) => string[];
54
+ export declare const getProposalSummary: (proposal: ActionProposal) => {
55
+ action: "create" | "delete" | "update" | "updateGlobal";
56
+ collection: string | undefined;
57
+ hasData: boolean;
58
+ hasLocalizedData: boolean;
59
+ id: string | undefined;
60
+ label: string;
61
+ locale: string | undefined;
62
+ locales: string[] | undefined;
63
+ slug: string | undefined;
64
+ };
65
+ export declare const getCollectionBlockTypes: (fields: readonly BlockFieldConfig[]) => string[];
66
+ export declare const getRequestedBlockTypes: ({ availableBlockTypes, mentions, prompt }: {
67
+ availableBlockTypes: string[];
68
+ mentions?: ChatMention[];
69
+ prompt: string;
70
+ }) => string[];
71
+ export declare const collectProposalBlockTypes: ({ data, fields }: {
72
+ data: Record<string, unknown>;
73
+ fields: readonly BlockFieldConfig[];
74
+ }) => Set<string>;
75
+ export declare const validateRelationshipTargetsExist: ({ data, fields, req, }: {
76
+ data: Record<string, unknown>;
77
+ fields: readonly BlockFieldConfig[];
78
+ req: Parameters<PayloadHandler>[0];
79
+ }) => Promise<RelationshipTargetReference[]>;
80
+ export declare const getUploadTargetsOutsideAttachments: ({ allowedAttachmentKeys, data, fields, }: {
81
+ allowedAttachmentKeys: Set<string>;
82
+ data: Record<string, unknown>;
83
+ fields: readonly BlockFieldConfig[];
84
+ }) => RelationshipTargetReference[];
85
+ export declare const validateProposalReferences: ({ allowedAttachmentKeys, data, fields, localizedData, priority, req, }: {
86
+ allowedAttachmentKeys: Set<string>;
87
+ data?: Record<string, unknown>;
88
+ fields: readonly BlockFieldConfig[];
89
+ localizedData?: LocalizedDataInput;
90
+ priority: "attachments" | "relationships";
91
+ req: Parameters<PayloadHandler>[0];
92
+ }) => Promise<{
93
+ invalidRelationshipTargets: RelationshipTargetReference[];
94
+ uploadTargetsOutsideAttachments: RelationshipTargetReference[];
95
+ }>;
96
+ export {};