@mvriu5/payload-ai 1.6.1 → 1.6.2

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.
@@ -1,3 +1,4 @@
1
+ import { isDeepStrictEqual } from "node:util";
1
2
  import { generateText } from "ai";
2
3
  import { isAIProvider } from "../ai/providerOptions.js";
3
4
  import { getModel, getProviderConfig } from "../ai/providerRuntime.js";
@@ -70,17 +71,25 @@ export const createTranslateDocumentHandler = (options)=>async (req)=>{
70
71
  locale: defaultLocale,
71
72
  req
72
73
  });
74
+ const sourceValues = getTranslationValues(pageContext.fields, sourceDocument);
75
+ if (sourceValues.length === 0) return Response.json({
76
+ available: false
77
+ });
73
78
  const targetDocument = await loadDocument({
74
79
  context: pageContext,
75
80
  id: body.id,
76
81
  locale,
77
82
  req
78
83
  });
79
- const sourceValues = getTranslationValues(pageContext.fields, sourceDocument);
80
- const targetValues = getTranslationValues(pageContext.fields, targetDocument);
81
- const populatedTargetPaths = new Set(targetValues.map((entry)=>entry.path));
82
- const missingSourceValues = sourceValues.filter((entry)=>!populatedTargetPaths.has(entry.path));
83
- const available = missingSourceValues.length > 0;
84
+ const targetValuesByPath = new Map(getTranslationValues(pageContext.fields, targetDocument).map((entry)=>[
85
+ entry.path,
86
+ entry.value
87
+ ]));
88
+ const translationSourceValues = sourceValues.filter((entry)=>{
89
+ const targetValue = targetValuesByPath.get(entry.path);
90
+ return targetValue === undefined || isDeepStrictEqual(targetValue, entry.value);
91
+ });
92
+ const available = translationSourceValues.length > 0;
84
93
  if (body.action === "status" || !available) return Response.json({
85
94
  available
86
95
  });
@@ -139,7 +148,7 @@ export const createTranslateDocumentHandler = (options)=>async (req)=>{
139
148
  prompt: JSON.stringify({
140
149
  sourceLocale: defaultLocale,
141
150
  targetLocale: locale,
142
- values: missingSourceValues.map((entry, index)=>({
151
+ values: translationSourceValues.map((entry, index)=>({
143
152
  id: String(index),
144
153
  value: entry.value
145
154
  }))
@@ -151,7 +160,7 @@ export const createTranslateDocumentHandler = (options)=>async (req)=>{
151
160
  "Return no Markdown or explanation."
152
161
  ].join(" ")
153
162
  });
154
- const translatedValues = parseTranslations(result.text, missingSourceValues.length);
163
+ const translatedValues = parseTranslations(result.text, translationSourceValues.length);
155
164
  if (translatedValues.some((value)=>value === undefined)) throw new Error("Translation response is incomplete.");
156
165
  if (result.usage && options.maxTokenUsage) {
157
166
  await recordTokenUsage({
@@ -164,7 +173,7 @@ export const createTranslateDocumentHandler = (options)=>async (req)=>{
164
173
  }
165
174
  return Response.json({
166
175
  available: true,
167
- values: missingSourceValues.map((entry, index)=>({
176
+ values: translationSourceValues.map((entry, index)=>({
168
177
  fieldType: entry.fieldType,
169
178
  path: entry.path,
170
179
  value: translatedValues[index]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mvriu5/payload-ai",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "AI assistant plugin for Payload CMS with provider selection, CMS mentions, and signed action proposals.",
5
5
  "keywords": [
6
6
  "payload",
@@ -66,10 +66,10 @@
66
66
  "knip": "knip"
67
67
  },
68
68
  "devDependencies": {
69
- "@ai-sdk/anthropic": "^3.0.81",
69
+ "@ai-sdk/anthropic": "^4.0.21",
70
70
  "@ai-sdk/google": "^3.0.80",
71
71
  "@ai-sdk/mistral": "^4.0.13",
72
- "@ai-sdk/openai": "^3.0.67",
72
+ "@ai-sdk/openai": "^4.0.20",
73
73
  "@floating-ui/react": "0.27.20",
74
74
  "@openrouter/ai-sdk-provider": "^3.0.0",
75
75
  "@payloadcms/db-postgres": "3.86.0",
@@ -85,7 +85,7 @@
85
85
  "cross-env": "^10.1.0",
86
86
  "eslint": "^10.5.0",
87
87
  "graphql": "^16.8.1",
88
- "jsdom": "^29.1.1",
88
+ "jsdom": "^30.0.0",
89
89
  "knip": "^6.18.0",
90
90
  "next": "16.2.11",
91
91
  "payload": "3.86.0",
@@ -98,10 +98,10 @@
98
98
  "vitest": "4.1.10"
99
99
  },
100
100
  "peerDependencies": {
101
- "@ai-sdk/anthropic": "^3.0.81",
101
+ "@ai-sdk/anthropic": "^4.0.21",
102
102
  "@ai-sdk/google": "^3.0.80",
103
103
  "@ai-sdk/mistral": "^4.0.13",
104
- "@ai-sdk/openai": "^3.0.67",
104
+ "@ai-sdk/openai": "^4.0.20",
105
105
  "@openrouter/ai-sdk-provider": "^3.0.0",
106
106
  "@payloadcms/ui": "^3.84.1",
107
107
  "payload": "^3.84.1"