@sanity/assist 1.2.2 → 1.2.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.
- package/README.md +14 -1
- package/dist/index.esm.js +26 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -20
- 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/schemas/serialize/serializeSchema.test.ts +30 -0
- package/src/schemas/serialize/serializeSchema.ts +5 -4
- package/src/useApiClient.ts +3 -15
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
- [Setup](#setup)
|
|
11
11
|
- [Add the plugin](#add-the-plugin)
|
|
12
12
|
- [Enabling the AI Assist API](#enabling-the-ai-assist-api)
|
|
13
|
+
- [Permissions](#permissions)
|
|
13
14
|
- [Schema configuration](#schema-configuration)
|
|
14
15
|
- [Disable AI Assist for a schema type](#disable-ai-assist-for-a-schema-type)
|
|
15
16
|
- [Disable for a field](#disable-for-a-field)
|
|
@@ -89,6 +90,18 @@ The plugin will now work for any dataset in your project.
|
|
|
89
90
|
|
|
90
91
|
**Note:** You can revoke this token at any time to disable Sanity AI Assist service. A new token has to be generated via the plugin UI for it to work again.
|
|
91
92
|
|
|
93
|
+
### Permissions
|
|
94
|
+
|
|
95
|
+
If your project is using custom roles (Enterprise), there are some additional considerations.
|
|
96
|
+
|
|
97
|
+
To see AI Assist presence when running instructions, users will need read access to
|
|
98
|
+
documents of `_type=="sanity.assist.task.status"`.
|
|
99
|
+
|
|
100
|
+
To edit instructions, users will need read and write access to documents of `_type=="sanity.assist.schemaType.annotations"`.
|
|
101
|
+
|
|
102
|
+
Note that instructions run using the permissions of the user invoking it, so only fields that the user
|
|
103
|
+
themselves can edit can be changed by the instruction instance.
|
|
104
|
+
|
|
92
105
|
## Schema configuration
|
|
93
106
|
|
|
94
107
|
By default, most object, array, and string field types have AI writing assistance enabled. Your assistant can write to all compatible fields that it detects.
|
|
@@ -224,7 +237,7 @@ defineField({
|
|
|
224
237
|
options: {
|
|
225
238
|
captionField: 'caption',
|
|
226
239
|
},
|
|
227
|
-
})
|
|
240
|
+
})
|
|
228
241
|
```
|
|
229
242
|
This will add a "Generate caption" action to the configured field.
|
|
230
243
|
"Generate caption" action will automatically run whenever the image changes.
|
package/dist/index.esm.js
CHANGED
|
@@ -210,7 +210,7 @@ function getBaseFields(schema, type, typeName, options) {
|
|
|
210
210
|
options: imagePromptField ? {
|
|
211
211
|
imagePromptField
|
|
212
212
|
} : void 0,
|
|
213
|
-
values:
|
|
213
|
+
values: ((_b = type == null ? void 0 : type.options) == null ? void 0 : _b.list) ? (_c = type == null ? void 0 : type.options) == null ? void 0 : _c.list.map(v => {
|
|
214
214
|
var _a2;
|
|
215
215
|
return typeof v === "string" ? v : (_a2 = v.value) != null ? _a2 : "".concat(v.title);
|
|
216
216
|
}) : void 0,
|
|
@@ -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);
|