@sanity/assist 1.2.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "sanity",
@@ -28,7 +28,7 @@ import {
28
28
  import {BackToInstructionListLink} from './instruction/BackToInstructionsLink'
29
29
  import {useAiPaneRouter} from '../../assistInspector/helpers'
30
30
  import {SelectedFieldContextProvider, SelectedFieldContextValue} from './SelectedFieldContext'
31
- import {Stack} from '@sanity/ui'
31
+ import {Card, Stack, Text} from '@sanity/ui'
32
32
  import {documentTypeFromAiDocumentId} from '../../helpers/ids'
33
33
 
34
34
  const EMPTY_FIELDS: AssistField[] = []
@@ -36,6 +36,16 @@ const EMPTY_FIELDS: AssistField[] = []
36
36
  export const TypePathContext = createContext<string | undefined>(undefined)
37
37
 
38
38
  export function AssistDocumentForm(props: ObjectInputProps) {
39
+ if (props.readOnly) {
40
+ return (
41
+ <Card border tone="caution" padding={2}>
42
+ <Text size={1}> You do not have sufficient permissions to manage instructions.</Text>
43
+ </Card>
44
+ )
45
+ }
46
+ return <AssistDocumentFormEditable {...props} />
47
+ }
48
+ function AssistDocumentFormEditable(props: ObjectInputProps) {
39
49
  const {onChange} = props
40
50
  const value = props.value as AssistDocument | undefined
41
51
  const id = value?._id
@@ -26,11 +26,13 @@ import {maxHistoryVisibilityMs} from '../../constants'
26
26
  interface UseAssistDocumentProps {
27
27
  documentId: string
28
28
  schemaType: ObjectSchemaType
29
+ initDoc?: boolean
29
30
  }
30
31
 
31
32
  export function useStudioAssistDocument({
32
33
  documentId,
33
34
  schemaType,
35
+ initDoc,
34
36
  }: UseAssistDocumentProps): StudioAssistDocument | undefined {
35
37
  const documentTypeName = schemaType.name
36
38
  const currentUser = useCurrentUser()
@@ -48,13 +50,17 @@ export function useStudioAssistDocument({
48
50
  const client = useClient({apiVersion: '2023-01-01'})
49
51
 
50
52
  useEffect(() => {
51
- if (!assistDocument) {
52
- client.createIfNotExists({
53
- _id: assistDocumentId(documentTypeName),
54
- _type: assistDocumentTypeName,
55
- })
53
+ if (!assistDocument && initDoc) {
54
+ client
55
+ .createIfNotExists({
56
+ _id: assistDocumentId(documentTypeName),
57
+ _type: assistDocumentTypeName,
58
+ })
59
+ .catch((e) => {
60
+ // best effort
61
+ })
56
62
  }
57
- }, [client, assistDocument, documentTypeName])
63
+ }, [client, assistDocument, documentTypeName, initDoc])
58
64
 
59
65
  return useMemo(() => {
60
66
  if (!assistDocument) {
@@ -213,7 +213,7 @@ export function AssistInspector(props: DocumentInspectorProps) {
213
213
 
214
214
  const aiDocId = assistDocumentId(documentType)
215
215
 
216
- const assistDocument = useStudioAssistDocument({documentId, schemaType})
216
+ const assistDocument = useStudioAssistDocument({documentId, schemaType, initDoc: true})
217
217
  const assistField = assistDocument?.fields?.find((f) => f.path === typePath)
218
218
  const instruction = assistField?.instructions?.find((i) => i._key === instructionKey)
219
219
  const tasks = useMemo(
@@ -367,7 +367,7 @@ export const fieldInstructions = defineType({
367
367
 
368
368
  export const assistDocumentSchema = defineType({
369
369
  //NOTE: this is a document type. Using object here ensures it does not appear in structure menus
370
- type: 'document',
370
+ type: 'object',
371
371
  //workaround for using object and not document
372
372
  ...({liveEdit: true} as any),
373
373
  name: assistDocumentTypeName,
@@ -26,7 +26,6 @@ export interface InstructStatus {
26
26
  }
27
27
 
28
28
  const basePath = '/assist/tasks/instruction'
29
- const editorialAiFieldActionFeature = 'editorialAiFieldActions'
30
29
 
31
30
  export function useApiClient(customApiClient?: (defaultClient: SanityClient) => SanityClient) {
32
31
  const client = useClient({apiVersion: '2023-06-05'})
@@ -91,33 +90,22 @@ export function useGenerateCaption(apiClient: SanityClient) {
91
90
 
92
91
  export function useGetInstructStatus(apiClient: SanityClient) {
93
92
  const [loading, setLoading] = useState(true)
94
- const projectClient = useClient({apiVersion: '2023-06-05'})
95
93
 
96
94
  const getInstructStatus = useCallback(async () => {
97
95
  setLoading(true)
98
96
 
99
97
  const projectId = apiClient.config().projectId
100
98
  try {
101
- const features = await projectClient.request<string[]>({
102
- method: 'GET',
103
- url: `/projects/${projectId}/features`,
104
- })
105
-
106
- const enabled = features.some((f) => f === editorialAiFieldActionFeature)
107
-
108
- const status = await apiClient.request<Omit<InstructStatus, 'enabled'>>({
99
+ const status = await apiClient.request<InstructStatus>({
109
100
  method: 'GET',
110
101
  url: `${basePath}/${apiClient.config().dataset}/status?projectId=${projectId}`,
111
102
  })
112
103
 
113
- return {
114
- ...status,
115
- enabled,
116
- }
104
+ return status
117
105
  } finally {
118
106
  setLoading(false)
119
107
  }
120
- }, [setLoading, apiClient, projectClient])
108
+ }, [setLoading, apiClient])
121
109
 
122
110
  return {
123
111
  loading,