@sanity/assist 1.2.15-lang.8 → 1.2.15-lang.9

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/README.md CHANGED
@@ -192,7 +192,7 @@ Fields with these types will not be changed by the assistant, do not have AI Ass
192
192
  Objects where all fields are excluded or unsupported and arrays where all member types are excluded or unsupported
193
193
  will also be excluded.
194
194
 
195
- ### Hidden adn readOnly fields
195
+ ### Hidden and readOnly fields
196
196
 
197
197
  In AI Assist 2.0 and later, conditionally `hidden` and `readOnly` fields can have instructions.
198
198
  These fields can be written to by an instruction, as long as the field is non-hidden and writable when the instruction is started.
package/dist/index.esm.js CHANGED
@@ -441,16 +441,24 @@ function extractPaths(doc, schemaType, path, maxDepth) {
441
441
  let arrayPaths = [];
442
442
  if (arrayValue == null ? void 0 : arrayValue.length) {
443
443
  for (const item of arrayValue) {
444
- const arrayItemSchema = fieldSchema.of.find(t => t.name === item._type);
445
- if (item._key && arrayItemSchema) {
446
- const itemPath = [...fieldPath, {
447
- _key: item._key
448
- }];
449
- const innerFields = extractPaths(doc, arrayItemSchema, itemPath, maxDepth);
444
+ const itemPath = [...fieldPath, {
445
+ _key: item._key
446
+ }];
447
+ let itemSchema = fieldSchema.of.find(t => t.name === item._type);
448
+ if (!item._type) {
449
+ itemSchema = fieldSchema.of[0];
450
+ console.warn("Array item is missing _type - using the first defined type in the array.of schema", {
451
+ itemPath,
452
+ item,
453
+ itemSchema
454
+ });
455
+ }
456
+ if (item._key && itemSchema) {
457
+ const innerFields = extractPaths(doc, itemSchema, itemPath, maxDepth);
450
458
  const arrayMember = {
451
459
  path: itemPath,
452
460
  name: item._key,
453
- schemaType: arrayItemSchema,
461
+ schemaType: itemSchema,
454
462
  value: item
455
463
  };
456
464
  arrayPaths = [...arrayPaths, arrayMember, ...innerFields];
@@ -6178,7 +6186,8 @@ const translateActions = {
6178
6186
  useAction(props) {
6179
6187
  var _a, _b, _c, _d, _e, _f, _g, _h;
6180
6188
  const {
6181
- config
6189
+ config,
6190
+ status
6182
6191
  } = useAiAssistanceConfig();
6183
6192
  const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
6184
6193
  const {
@@ -6193,8 +6202,8 @@ const translateActions = {
6193
6202
  const docTransTypes = (_b = (_a = config.translate) == null ? void 0 : _a.document) == null ? void 0 : _b.documentTypes;
6194
6203
  const options = fieldSchemaType == null ? void 0 : fieldSchemaType.options;
6195
6204
  const addFieldAction = isDocumentLevel || ((_c = options == null ? void 0 : options.aiWritingAssistance) == null ? void 0 : _c.translateAction);
6196
- const fieldTransEnabled = addFieldAction && documentSchemaType && ((_f = (_e = (_d = config.translate) == null ? void 0 : _d.field) == null ? void 0 : _e.documentTypes) == null ? void 0 : _f.includes(documentSchemaType.name));
6197
- const documentTranslationEnabled = addFieldAction && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(documentSchemaType.name)));
6205
+ const fieldTransEnabled = addFieldAction && (status == null ? void 0 : status.initialized) && documentSchemaType && ((_f = (_e = (_d = config.translate) == null ? void 0 : _d.field) == null ? void 0 : _e.documentTypes) == null ? void 0 : _f.includes(documentSchemaType.name));
6206
+ const documentTranslationEnabled = addFieldAction && (status == null ? void 0 : status.initialized) && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(documentSchemaType.name)));
6198
6207
  if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
6199
6208
  const {
6200
6209
  value: documentValue,