@sanity/assist 1.2.2 → 1.2.3
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/index.esm.js +25 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +25 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/assistDocument/components/AssistDocumentForm.tsx +11 -1
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +12 -6
- package/src/assistInspector/AssistInspector.tsx +1 -1
- package/src/useApiClient.ts +3 -15
package/dist/index.esm.js
CHANGED
|
@@ -662,7 +662,8 @@ const maxHistoryVisibilityMs = minutesToMilliseconds(30);
|
|
|
662
662
|
function useStudioAssistDocument(_ref2) {
|
|
663
663
|
let {
|
|
664
664
|
documentId,
|
|
665
|
-
schemaType
|
|
665
|
+
schemaType,
|
|
666
|
+
initDoc
|
|
666
667
|
} = _ref2;
|
|
667
668
|
const documentTypeName = schemaType.name;
|
|
668
669
|
const currentUser = useCurrentUser();
|
|
@@ -673,13 +674,13 @@ function useStudioAssistDocument(_ref2) {
|
|
|
673
674
|
apiVersion: "2023-01-01"
|
|
674
675
|
});
|
|
675
676
|
useEffect(() => {
|
|
676
|
-
if (!assistDocument) {
|
|
677
|
+
if (!assistDocument && initDoc) {
|
|
677
678
|
client.createIfNotExists({
|
|
678
679
|
_id: assistDocumentId(documentTypeName),
|
|
679
680
|
_type: assistDocumentTypeName
|
|
680
|
-
});
|
|
681
|
+
}).catch(e => {});
|
|
681
682
|
}
|
|
682
|
-
}, [client, assistDocument, documentTypeName]);
|
|
683
|
+
}, [client, assistDocument, documentTypeName, initDoc]);
|
|
683
684
|
return useMemo(() => {
|
|
684
685
|
var _a, _b;
|
|
685
686
|
if (!assistDocument) {
|
|
@@ -959,7 +960,6 @@ function TaskItem(props) {
|
|
|
959
960
|
});
|
|
960
961
|
}
|
|
961
962
|
const basePath = "/assist/tasks/instruction";
|
|
962
|
-
const editorialAiFieldActionFeature = "editorialAiFieldActions";
|
|
963
963
|
function useApiClient(customApiClient) {
|
|
964
964
|
const client = useClient({
|
|
965
965
|
apiVersion: "2023-06-05"
|
|
@@ -1010,30 +1010,19 @@ function useGenerateCaption(apiClient) {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
function useGetInstructStatus(apiClient) {
|
|
1012
1012
|
const [loading, setLoading] = useState(true);
|
|
1013
|
-
const projectClient = useClient({
|
|
1014
|
-
apiVersion: "2023-06-05"
|
|
1015
|
-
});
|
|
1016
1013
|
const getInstructStatus = useCallback(async () => {
|
|
1017
1014
|
setLoading(true);
|
|
1018
1015
|
const projectId = apiClient.config().projectId;
|
|
1019
1016
|
try {
|
|
1020
|
-
const features = await projectClient.request({
|
|
1021
|
-
method: "GET",
|
|
1022
|
-
url: "/projects/".concat(projectId, "/features")
|
|
1023
|
-
});
|
|
1024
|
-
const enabled = features.some(f => f === editorialAiFieldActionFeature);
|
|
1025
1017
|
const status = await apiClient.request({
|
|
1026
1018
|
method: "GET",
|
|
1027
1019
|
url: "".concat(basePath, "/").concat(apiClient.config().dataset, "/status?projectId=").concat(projectId)
|
|
1028
1020
|
});
|
|
1029
|
-
return
|
|
1030
|
-
...status,
|
|
1031
|
-
enabled
|
|
1032
|
-
};
|
|
1021
|
+
return status;
|
|
1033
1022
|
} finally {
|
|
1034
1023
|
setLoading(false);
|
|
1035
1024
|
}
|
|
1036
|
-
}, [setLoading, apiClient
|
|
1025
|
+
}, [setLoading, apiClient]);
|
|
1037
1026
|
return {
|
|
1038
1027
|
loading,
|
|
1039
1028
|
getInstructStatus
|
|
@@ -1459,6 +1448,22 @@ function BackToInstructionListLink() {
|
|
|
1459
1448
|
const EMPTY_FIELDS = [];
|
|
1460
1449
|
const TypePathContext = createContext(void 0);
|
|
1461
1450
|
function AssistDocumentForm(props) {
|
|
1451
|
+
if (props.readOnly) {
|
|
1452
|
+
return /* @__PURE__ */jsx(Card, {
|
|
1453
|
+
border: true,
|
|
1454
|
+
tone: "caution",
|
|
1455
|
+
padding: 2,
|
|
1456
|
+
children: /* @__PURE__ */jsx(Text, {
|
|
1457
|
+
size: 1,
|
|
1458
|
+
children: " You do not have sufficient permissions to manage instructions."
|
|
1459
|
+
})
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
return /* @__PURE__ */jsx(AssistDocumentFormEditable, {
|
|
1463
|
+
...props
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
function AssistDocumentFormEditable(props) {
|
|
1462
1467
|
const {
|
|
1463
1468
|
onChange
|
|
1464
1469
|
} = props;
|
|
@@ -1899,7 +1904,8 @@ function AssistInspector(props) {
|
|
|
1899
1904
|
const aiDocId = assistDocumentId(documentType);
|
|
1900
1905
|
const assistDocument = useStudioAssistDocument({
|
|
1901
1906
|
documentId,
|
|
1902
|
-
schemaType
|
|
1907
|
+
schemaType,
|
|
1908
|
+
initDoc: true
|
|
1903
1909
|
});
|
|
1904
1910
|
const assistField = (_a2 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a2.find(f => f.path === typePath);
|
|
1905
1911
|
const instruction = (_b2 = assistField == null ? void 0 : assistField.instructions) == null ? void 0 : _b2.find(i => i._key === instructionKey);
|