@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.js
CHANGED
|
@@ -675,7 +675,8 @@ const maxHistoryVisibilityMs = dateFns.minutesToMilliseconds(30);
|
|
|
675
675
|
function useStudioAssistDocument(_ref2) {
|
|
676
676
|
let {
|
|
677
677
|
documentId,
|
|
678
|
-
schemaType
|
|
678
|
+
schemaType,
|
|
679
|
+
initDoc
|
|
679
680
|
} = _ref2;
|
|
680
681
|
const documentTypeName = schemaType.name;
|
|
681
682
|
const currentUser = sanity.useCurrentUser();
|
|
@@ -686,13 +687,13 @@ function useStudioAssistDocument(_ref2) {
|
|
|
686
687
|
apiVersion: "2023-01-01"
|
|
687
688
|
});
|
|
688
689
|
react.useEffect(() => {
|
|
689
|
-
if (!assistDocument) {
|
|
690
|
+
if (!assistDocument && initDoc) {
|
|
690
691
|
client.createIfNotExists({
|
|
691
692
|
_id: assistDocumentId(documentTypeName),
|
|
692
693
|
_type: assistDocumentTypeName
|
|
693
|
-
});
|
|
694
|
+
}).catch(e => {});
|
|
694
695
|
}
|
|
695
|
-
}, [client, assistDocument, documentTypeName]);
|
|
696
|
+
}, [client, assistDocument, documentTypeName, initDoc]);
|
|
696
697
|
return react.useMemo(() => {
|
|
697
698
|
var _a, _b;
|
|
698
699
|
if (!assistDocument) {
|
|
@@ -972,7 +973,6 @@ function TaskItem(props) {
|
|
|
972
973
|
});
|
|
973
974
|
}
|
|
974
975
|
const basePath = "/assist/tasks/instruction";
|
|
975
|
-
const editorialAiFieldActionFeature = "editorialAiFieldActions";
|
|
976
976
|
function useApiClient(customApiClient) {
|
|
977
977
|
const client = sanity.useClient({
|
|
978
978
|
apiVersion: "2023-06-05"
|
|
@@ -1023,30 +1023,19 @@ function useGenerateCaption(apiClient) {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
function useGetInstructStatus(apiClient) {
|
|
1025
1025
|
const [loading, setLoading] = react.useState(true);
|
|
1026
|
-
const projectClient = sanity.useClient({
|
|
1027
|
-
apiVersion: "2023-06-05"
|
|
1028
|
-
});
|
|
1029
1026
|
const getInstructStatus = react.useCallback(async () => {
|
|
1030
1027
|
setLoading(true);
|
|
1031
1028
|
const projectId = apiClient.config().projectId;
|
|
1032
1029
|
try {
|
|
1033
|
-
const features = await projectClient.request({
|
|
1034
|
-
method: "GET",
|
|
1035
|
-
url: "/projects/".concat(projectId, "/features")
|
|
1036
|
-
});
|
|
1037
|
-
const enabled = features.some(f => f === editorialAiFieldActionFeature);
|
|
1038
1030
|
const status = await apiClient.request({
|
|
1039
1031
|
method: "GET",
|
|
1040
1032
|
url: "".concat(basePath, "/").concat(apiClient.config().dataset, "/status?projectId=").concat(projectId)
|
|
1041
1033
|
});
|
|
1042
|
-
return
|
|
1043
|
-
...status,
|
|
1044
|
-
enabled
|
|
1045
|
-
};
|
|
1034
|
+
return status;
|
|
1046
1035
|
} finally {
|
|
1047
1036
|
setLoading(false);
|
|
1048
1037
|
}
|
|
1049
|
-
}, [setLoading, apiClient
|
|
1038
|
+
}, [setLoading, apiClient]);
|
|
1050
1039
|
return {
|
|
1051
1040
|
loading,
|
|
1052
1041
|
getInstructStatus
|
|
@@ -1472,6 +1461,22 @@ function BackToInstructionListLink() {
|
|
|
1472
1461
|
const EMPTY_FIELDS = [];
|
|
1473
1462
|
const TypePathContext = react.createContext(void 0);
|
|
1474
1463
|
function AssistDocumentForm(props) {
|
|
1464
|
+
if (props.readOnly) {
|
|
1465
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
1466
|
+
border: true,
|
|
1467
|
+
tone: "caution",
|
|
1468
|
+
padding: 2,
|
|
1469
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
1470
|
+
size: 1,
|
|
1471
|
+
children: " You do not have sufficient permissions to manage instructions."
|
|
1472
|
+
})
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
return /* @__PURE__ */jsxRuntime.jsx(AssistDocumentFormEditable, {
|
|
1476
|
+
...props
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
function AssistDocumentFormEditable(props) {
|
|
1475
1480
|
const {
|
|
1476
1481
|
onChange
|
|
1477
1482
|
} = props;
|
|
@@ -1912,7 +1917,8 @@ function AssistInspector(props) {
|
|
|
1912
1917
|
const aiDocId = assistDocumentId(documentType);
|
|
1913
1918
|
const assistDocument = useStudioAssistDocument({
|
|
1914
1919
|
documentId,
|
|
1915
|
-
schemaType
|
|
1920
|
+
schemaType,
|
|
1921
|
+
initDoc: true
|
|
1916
1922
|
});
|
|
1917
1923
|
const assistField = (_a2 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a2.find(f => f.path === typePath);
|
|
1918
1924
|
const instruction = (_b2 = assistField == null ? void 0 : assistField.instructions) == null ? void 0 : _b2.find(i => i._key === instructionKey);
|