@sanity/assist 2.0.4 → 3.0.0
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 +2 -2
- package/dist/index.d.mts +377 -0
- package/dist/index.esm.js +3132 -5883
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3109 -5886
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4159 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -37
- package/src/_lib/connector/ConnectFromRegion.tsx +4 -3
- package/src/_lib/connector/ConnectToRegion.tsx +1 -0
- package/src/_lib/connector/ConnectorRegion.tsx +2 -1
- package/src/_lib/connector/ConnectorsProvider.tsx +2 -1
- package/src/_lib/connector/ConnectorsStoreContext.ts +1 -0
- package/src/_lib/connector/index.ts +1 -1
- package/src/_lib/connector/mapConnectorToLine.ts +2 -2
- package/src/_lib/connector/useConnectorsStore.ts +2 -1
- package/src/_lib/connector/useRegionRects.ts +4 -3
- package/src/_lib/fixedListenQuery.ts +11 -11
- package/src/_lib/form/DocumentForm.tsx +11 -9
- package/src/_lib/form/helpers.ts +2 -1
- package/src/_lib/useListeningQuery.ts +4 -3
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +1 -0
- package/src/assistConnectors/ConnectorPath.tsx +3 -2
- package/src/assistConnectors/draw/connectorPath.ts +13 -13
- package/src/assistDocument/AssistDocumentContext.tsx +3 -2
- package/src/assistDocument/AssistDocumentContextProvider.tsx +2 -1
- package/src/assistDocument/AssistDocumentInput.tsx +10 -9
- package/src/assistDocument/RequestRunInstructionProvider.tsx +4 -3
- package/src/assistDocument/components/AssistDocumentForm.tsx +25 -24
- package/src/assistDocument/components/FieldRefPreview.tsx +4 -3
- package/src/assistDocument/components/InstructionsArrayInput.tsx +4 -3
- package/src/assistDocument/components/SelectedFieldContext.tsx +1 -1
- package/src/assistDocument/components/helpers.ts +4 -4
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +4 -3
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +5 -4
- package/src/assistDocument/components/instruction/InstructionInput.tsx +3 -2
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +2 -1
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +14 -13
- package/src/assistDocument/components/instruction/PromptInput.tsx +10 -3
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +2 -2
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +1 -1
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +8 -7
- package/src/assistDocument/hooks/useInstructionToaster.tsx +6 -5
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +14 -13
- package/src/assistFormComponents/AssistField.tsx +9 -8
- package/src/assistFormComponents/AssistFormBlock.tsx +5 -4
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +1 -1
- package/src/assistFormComponents/AssistItem.tsx +3 -2
- package/src/assistFormComponents/validation/listItem.tsx +3 -3
- package/src/assistFormComponents/validation/validationList.tsx +3 -2
- package/src/assistInspector/AssistInspector.tsx +25 -18
- package/src/assistInspector/FieldAutocomplete.tsx +4 -3
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +20 -19
- package/src/assistInspector/helpers.ts +16 -15
- package/src/assistInspector/index.ts +4 -3
- package/src/assistLayout/AiAssistanceConfigContext.tsx +1 -0
- package/src/assistLayout/AssistLayout.tsx +5 -4
- package/src/assistLayout/RunInstructionProvider.tsx +18 -15
- package/src/components/FadeInContent.tsx +3 -3
- package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
- package/src/components/ImageContext.tsx +5 -4
- package/src/components/SafeValueInput.tsx +9 -11
- package/src/components/TimeAgo.tsx +1 -1
- package/src/fieldActions/assistFieldActions.tsx +31 -30
- package/src/fieldActions/generateCaptionActions.tsx +8 -7
- package/src/fieldActions/generateImageActions.tsx +6 -5
- package/src/helpers/assistSupported.ts +1 -0
- package/src/helpers/conditionalMembers.test.ts +2 -1
- package/src/helpers/conditionalMembers.ts +17 -14
- package/src/helpers/misc.ts +3 -2
- package/src/helpers/typeUtils.ts +1 -1
- package/src/helpers/useAssistSupported.ts +2 -1
- package/src/onboarding/FieldActionsOnboarding.tsx +2 -1
- package/src/onboarding/FirstAssistedPathProvider.tsx +4 -3
- package/src/onboarding/InspectorOnboarding.tsx +3 -2
- package/src/onboarding/onboardingStore.ts +1 -1
- package/src/presence/AiFieldPresence.tsx +3 -1
- package/src/presence/AssistAvatar.tsx +2 -2
- package/src/presence/AssistDocumentPresence.tsx +7 -6
- package/src/presence/useAssistPresence.ts +6 -3
- package/src/schemas/assistDocumentSchema.tsx +21 -20
- package/src/schemas/contextDocumentSchema.tsx +3 -2
- package/src/schemas/index.ts +2 -1
- package/src/schemas/serialize/SchemTypeTool.tsx +4 -3
- package/src/schemas/serialize/serializeSchema.test.ts +3 -2
- package/src/schemas/serialize/serializeSchema.ts +15 -14
- package/src/schemas/serializedSchemaTypeSchema.ts +2 -1
- package/src/translate/FieldTranslationProvider.tsx +33 -25
- package/src/translate/getLanguageParams.ts +4 -4
- package/src/translate/paths.test.ts +11 -4
- package/src/translate/paths.ts +12 -11
- package/src/translate/translateActions.tsx +12 -11
- package/src/translate/types.ts +2 -2
- package/src/useApiClient.ts +9 -9
- package/dist/index.cjs.mjs +0 -7
|
@@ -2,36 +2,43 @@ import {ArrowRightIcon, CloseIcon, PlayIcon, RetryIcon} from '@sanity/icons'
|
|
|
2
2
|
import {Box, Button, Card, Flex, Spinner, Stack, Text} from '@sanity/ui'
|
|
3
3
|
import {useCallback, useMemo, useRef} from 'react'
|
|
4
4
|
import {
|
|
5
|
-
DocumentInspectorProps,
|
|
5
|
+
type DocumentInspectorProps,
|
|
6
6
|
PresenceOverlay,
|
|
7
7
|
useEditState,
|
|
8
8
|
VirtualizerScrollInstanceProvider,
|
|
9
9
|
} from 'sanity'
|
|
10
10
|
import {
|
|
11
11
|
DocumentInspectorHeader,
|
|
12
|
-
DocumentPaneNode,
|
|
12
|
+
type DocumentPaneNode,
|
|
13
13
|
DocumentPaneProvider,
|
|
14
14
|
useDocumentPane,
|
|
15
|
-
} from 'sanity/
|
|
15
|
+
} from 'sanity/structure'
|
|
16
|
+
import {styled} from 'styled-components'
|
|
17
|
+
|
|
16
18
|
import {DocumentForm} from '../_lib/form'
|
|
17
|
-
import {
|
|
18
|
-
import {FieldRef, getFieldTitle, useAiPaneRouter, useSelectedField, useTypePath} from './helpers'
|
|
19
|
-
import styled from 'styled-components'
|
|
19
|
+
import {TypePathContext} from '../assistDocument/components/AssistDocumentForm'
|
|
20
20
|
import {useStudioAssistDocument} from '../assistDocument/hooks/useStudioAssistDocument'
|
|
21
|
-
import {InstructionTaskHistoryButton} from './InstructionTaskHistoryButton'
|
|
22
|
-
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
23
|
-
import {giveFeedbackUrl, pluginTitle, releaseAnnouncementUrl, salesUrl} from '../constants'
|
|
24
|
-
import {assistDocumentId} from '../helpers/ids'
|
|
25
21
|
import {
|
|
26
22
|
getAssistableDocId,
|
|
27
23
|
isDocAssistable,
|
|
28
24
|
useRequestRunInstruction,
|
|
29
25
|
} from '../assistDocument/RequestRunInstructionProvider'
|
|
26
|
+
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
27
|
+
import {giveFeedbackUrl, pluginTitle, releaseAnnouncementUrl, salesUrl} from '../constants'
|
|
28
|
+
import {getConditionalMembers} from '../helpers/conditionalMembers'
|
|
29
|
+
import {assistDocumentId} from '../helpers/ids'
|
|
30
30
|
import {InspectorOnboarding} from '../onboarding/InspectorOnboarding'
|
|
31
31
|
import {inspectorOnboardingKey, useOnboardingFeature} from '../onboarding/onboardingStore'
|
|
32
|
-
import {
|
|
32
|
+
import {assistDocumentTypeName, fieldPathParam, instructionParam} from '../types'
|
|
33
33
|
import {FieldTitle} from './FieldAutocomplete'
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
type FieldRef,
|
|
36
|
+
getFieldTitle,
|
|
37
|
+
useAiPaneRouter,
|
|
38
|
+
useSelectedField,
|
|
39
|
+
useTypePath,
|
|
40
|
+
} from './helpers'
|
|
41
|
+
import {InstructionTaskHistoryButton} from './InstructionTaskHistoryButton'
|
|
35
42
|
|
|
36
43
|
const CardWithShadowBelow = styled(Card)`
|
|
37
44
|
position: relative;
|
|
@@ -172,8 +179,8 @@ export function AssistInspectorWrapper(props: DocumentInspectorProps) {
|
|
|
172
179
|
context.error
|
|
173
180
|
? 'Retry'
|
|
174
181
|
: status?.initialized && !status.validToken
|
|
175
|
-
|
|
176
|
-
|
|
182
|
+
? `Restore ${pluginTitle}`
|
|
183
|
+
: `Enable ${pluginTitle} now`
|
|
177
184
|
}
|
|
178
185
|
tone="primary"
|
|
179
186
|
onClick={context.init}
|
|
@@ -224,11 +231,11 @@ export function AssistInspector(props: DocumentInspectorProps) {
|
|
|
224
231
|
const tasks = useMemo(
|
|
225
232
|
() =>
|
|
226
233
|
assistDocument?.tasks?.filter((i) => !instructionKey || i.instructionKey === instructionKey),
|
|
227
|
-
[assistDocument?.tasks, instructionKey]
|
|
234
|
+
[assistDocument?.tasks, instructionKey],
|
|
228
235
|
)
|
|
229
236
|
const instructions = useMemo(
|
|
230
237
|
() => assistDocument?.fields?.flatMap((f) => f.instructions ?? []),
|
|
231
|
-
[assistDocument?.fields]
|
|
238
|
+
[assistDocument?.fields],
|
|
232
239
|
)
|
|
233
240
|
|
|
234
241
|
const promptValue = instruction?.prompt
|
|
@@ -252,7 +259,7 @@ export function AssistInspector(props: DocumentInspectorProps) {
|
|
|
252
259
|
type: assistDocumentTypeName,
|
|
253
260
|
},
|
|
254
261
|
}),
|
|
255
|
-
[aiDocId]
|
|
262
|
+
[aiDocId],
|
|
256
263
|
)
|
|
257
264
|
|
|
258
265
|
const runCurrentInstruction = useCallback(
|
|
@@ -268,7 +275,7 @@ export function AssistInspector(props: DocumentInspectorProps) {
|
|
|
268
275
|
instruction,
|
|
269
276
|
conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : [],
|
|
270
277
|
}),
|
|
271
|
-
[pathKey, instruction, typePath, documentType, assistableDocId, requestRunInstruction]
|
|
278
|
+
[pathKey, instruction, typePath, documentType, assistableDocId, requestRunInstruction],
|
|
272
279
|
)
|
|
273
280
|
|
|
274
281
|
const Region = useCallback((_props: any) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {SearchIcon} from '@sanity/icons'
|
|
2
2
|
import {Autocomplete, Box, Breadcrumbs, Card, Flex, Text} from '@sanity/ui'
|
|
3
3
|
import {createElement, useCallback, useMemo} from 'react'
|
|
4
|
-
import {FieldRef, getFieldRefs, getFieldRefsWithDocument} from './helpers'
|
|
5
4
|
import {ObjectSchemaType} from 'sanity'
|
|
5
|
+
|
|
6
6
|
import {isType} from '../helpers/typeUtils'
|
|
7
|
+
import {FieldRef, getFieldRefs, getFieldRefsWithDocument} from './helpers'
|
|
7
8
|
|
|
8
9
|
interface FieldSelectorProps {
|
|
9
10
|
id: string
|
|
@@ -25,7 +26,7 @@ export function FieldAutocomplete(props: FieldSelectorProps) {
|
|
|
25
26
|
}, [schemaType, includeDocument])
|
|
26
27
|
const currentField = useMemo(
|
|
27
28
|
() => fieldRefs.find((f) => f.key === fieldPath),
|
|
28
|
-
[fieldPath, fieldRefs]
|
|
29
|
+
[fieldPath, fieldRefs],
|
|
29
30
|
)
|
|
30
31
|
|
|
31
32
|
const autocompleteOptions = useMemo(
|
|
@@ -34,7 +35,7 @@ export function FieldAutocomplete(props: FieldSelectorProps) {
|
|
|
34
35
|
.filter((field) => (filter ? filter(field) : true))
|
|
35
36
|
.filter((f) => !isType(f.schemaType, 'reference'))
|
|
36
37
|
.map((field) => ({value: field.key, field})),
|
|
37
|
-
[fieldRefs, filter]
|
|
38
|
+
[fieldRefs, filter],
|
|
38
39
|
)
|
|
39
40
|
|
|
40
41
|
const renderOption = useCallback((option: {value: string; field: FieldRef}) => {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CheckmarkCircleIcon,
|
|
3
|
+
ClockIcon,
|
|
4
|
+
CloseCircleIcon,
|
|
5
|
+
ErrorOutlineIcon,
|
|
6
|
+
SyncIcon,
|
|
7
|
+
} from '@sanity/icons'
|
|
3
8
|
import {
|
|
4
9
|
Box,
|
|
5
10
|
Button,
|
|
@@ -13,19 +18,15 @@ import {
|
|
|
13
18
|
useGlobalKeyDown,
|
|
14
19
|
useLayer,
|
|
15
20
|
} from '@sanity/ui'
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ErrorOutlineIcon,
|
|
21
|
-
SyncIcon,
|
|
22
|
-
} from '@sanity/icons'
|
|
21
|
+
import {createElement, type ForwardedRef, forwardRef, useCallback, useMemo, useState} from 'react'
|
|
22
|
+
import {StatusButton, type StatusButtonProps, typed, useClient} from 'sanity'
|
|
23
|
+
import {keyframes, styled} from 'styled-components'
|
|
24
|
+
|
|
23
25
|
import {TimeAgo} from '../components/TimeAgo'
|
|
24
|
-
import {StatusButton, StatusButtonProps, typed, useClient} from 'sanity'
|
|
25
|
-
import {getInstructionTitle} from '../helpers/misc'
|
|
26
|
-
import styled, {keyframes} from 'styled-components'
|
|
27
|
-
import {assistTasksStatusId} from '../helpers/ids'
|
|
28
26
|
import {maxHistoryVisibilityMs, pluginTitle} from '../constants'
|
|
27
|
+
import {assistTasksStatusId} from '../helpers/ids'
|
|
28
|
+
import {getInstructionTitle} from '../helpers/misc'
|
|
29
|
+
import type {AssistTasksStatus, InstructionTask, StudioInstruction, TaskEndedReason} from '../types'
|
|
29
30
|
|
|
30
31
|
export interface InstructionTaskHistoryButtonProps {
|
|
31
32
|
documentId?: string
|
|
@@ -96,7 +97,7 @@ export function InstructionTaskHistoryButton(props: InstructionTaskHistoryButton
|
|
|
96
97
|
.commit()
|
|
97
98
|
.catch(console.error)
|
|
98
99
|
},
|
|
99
|
-
[client, documentId]
|
|
100
|
+
[client, documentId],
|
|
100
101
|
)
|
|
101
102
|
|
|
102
103
|
const titledTasks = useMemo(() => {
|
|
@@ -105,7 +106,7 @@ export function InstructionTaskHistoryButton(props: InstructionTaskHistoryButton
|
|
|
105
106
|
?.filter(
|
|
106
107
|
(task) =>
|
|
107
108
|
task.started &&
|
|
108
|
-
new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs
|
|
109
|
+
new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs,
|
|
109
110
|
)
|
|
110
111
|
.map((task): CancelableInstructionTask => {
|
|
111
112
|
const instruction = instructions?.find((i) => i._key === task.instructionKey)
|
|
@@ -124,7 +125,7 @@ export function InstructionTaskHistoryButton(props: InstructionTaskHistoryButton
|
|
|
124
125
|
const isRunning = useMemo(() => titledTasks.some((r) => !r.ended), [titledTasks])
|
|
125
126
|
const hasErrors = useMemo(
|
|
126
127
|
() => titledTasks.some((r) => r.reason === 'error' || r.reason === 'timeout'),
|
|
127
|
-
[titledTasks]
|
|
128
|
+
[titledTasks],
|
|
128
129
|
)
|
|
129
130
|
|
|
130
131
|
const [open, setOpen] = useState(false)
|
|
@@ -179,7 +180,7 @@ const TaskStatusButton = forwardRef(function TaskStatusButton(
|
|
|
179
180
|
onClick: () => void
|
|
180
181
|
selected: boolean
|
|
181
182
|
},
|
|
182
|
-
ref: ForwardedRef<HTMLButtonElement
|
|
183
|
+
ref: ForwardedRef<HTMLButtonElement>,
|
|
183
184
|
) {
|
|
184
185
|
const {disabled, hasErrors, isRunning, onClick, selected} = props
|
|
185
186
|
|
|
@@ -210,8 +211,8 @@ function TaskList(props: {onEscape: () => void; tasks: CancelableInstructionTask
|
|
|
210
211
|
onEscape()
|
|
211
212
|
}
|
|
212
213
|
},
|
|
213
|
-
[isTopLayer, onEscape]
|
|
214
|
-
)
|
|
214
|
+
[isTopLayer, onEscape],
|
|
215
|
+
),
|
|
215
216
|
)
|
|
216
217
|
|
|
217
218
|
return (
|
|
@@ -7,24 +7,25 @@ import {
|
|
|
7
7
|
OlistIcon,
|
|
8
8
|
StringIcon,
|
|
9
9
|
} from '@sanity/icons'
|
|
10
|
+
import {extractWithPath} from '@sanity/mutator'
|
|
11
|
+
import {type ComponentType, useContext, useMemo} from 'react'
|
|
10
12
|
import {
|
|
11
|
-
ArraySchemaType,
|
|
13
|
+
type ArraySchemaType,
|
|
12
14
|
isKeySegment,
|
|
13
15
|
isObjectSchemaType,
|
|
14
|
-
ObjectSchemaType,
|
|
15
|
-
Path,
|
|
16
|
+
type ObjectSchemaType,
|
|
17
|
+
type Path,
|
|
16
18
|
pathToString,
|
|
17
|
-
SanityDocumentLike,
|
|
18
|
-
SchemaType,
|
|
19
|
+
type SanityDocumentLike,
|
|
20
|
+
type SchemaType,
|
|
19
21
|
stringToPath,
|
|
20
22
|
} from 'sanity'
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
import {
|
|
23
|
+
import {type PaneRouterContextValue, usePaneRouter} from 'sanity/structure'
|
|
24
|
+
|
|
25
|
+
import {SelectedFieldContext} from '../assistDocument/components/SelectedFieldContext'
|
|
24
26
|
import {isAssistSupported} from '../helpers/assistSupported'
|
|
25
27
|
import {isPortableTextArray, isType} from '../helpers/typeUtils'
|
|
26
|
-
import {
|
|
27
|
-
import {extractWithPath} from '@sanity/mutator'
|
|
28
|
+
import {type AssistInspectorRouteParams, documentRootKey, fieldPathParam} from '../types'
|
|
28
29
|
|
|
29
30
|
export interface FieldRef {
|
|
30
31
|
key: string
|
|
@@ -74,7 +75,7 @@ export function getFieldRefsWithDocument(schemaType: ObjectSchemaType): FieldRef
|
|
|
74
75
|
export function getFieldRefs(
|
|
75
76
|
schemaType: ObjectSchemaType,
|
|
76
77
|
parent?: FieldRef,
|
|
77
|
-
depth = 0
|
|
78
|
+
depth = 0,
|
|
78
79
|
): FieldRef[] {
|
|
79
80
|
if (depth >= maxDepth) {
|
|
80
81
|
return []
|
|
@@ -171,14 +172,14 @@ export function useTypePath(doc: SanityDocumentLike, pathString: string) {
|
|
|
171
172
|
|
|
172
173
|
export function useSelectedField(
|
|
173
174
|
documentSchemaType?: SchemaType,
|
|
174
|
-
path?: string
|
|
175
|
+
path?: string,
|
|
175
176
|
): FieldRef | undefined {
|
|
176
177
|
const selectableFields = useMemo(
|
|
177
178
|
() =>
|
|
178
179
|
documentSchemaType && isObjectSchemaType(documentSchemaType)
|
|
179
180
|
? getFieldRefsWithDocument(documentSchemaType)
|
|
180
181
|
: [],
|
|
181
|
-
[documentSchemaType]
|
|
182
|
+
[documentSchemaType],
|
|
182
183
|
)
|
|
183
184
|
|
|
184
185
|
return useMemo(() => {
|
|
@@ -207,7 +208,7 @@ export function useAiPaneRouter() {
|
|
|
207
208
|
const paneRouter = usePaneRouter()
|
|
208
209
|
|
|
209
210
|
return useMemo(
|
|
210
|
-
() => ({...paneRouter, params: paneRouter.params ?? {}} as AiPaneRouter
|
|
211
|
-
[paneRouter]
|
|
211
|
+
() => ({...paneRouter, params: paneRouter.params ?? {}}) as AiPaneRouter,
|
|
212
|
+
[paneRouter],
|
|
212
213
|
)
|
|
213
214
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {SparklesIcon} from '@sanity/icons'
|
|
2
2
|
import {DocumentInspector, typed} from 'sanity'
|
|
3
|
-
|
|
4
|
-
import {AssistInspectorWrapper} from './AssistInspector'
|
|
5
|
-
import {AssistInspectorRouteParams, fieldPathParam, instructionParam} from '../types'
|
|
3
|
+
|
|
6
4
|
import {pluginTitle} from '../constants'
|
|
5
|
+
import {AssistInspectorRouteParams, fieldPathParam, instructionParam} from '../types'
|
|
6
|
+
import {AssistInspectorWrapper} from './AssistInspector'
|
|
7
|
+
import {aiInspectorId} from './constants'
|
|
7
8
|
|
|
8
9
|
export const assistInspector: DocumentInspector = {
|
|
9
10
|
name: aiInspectorId,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import {ThemeProvider} from '@sanity/ui'
|
|
1
2
|
import {useState} from 'react'
|
|
2
3
|
import {LayoutProps} from 'sanity'
|
|
4
|
+
|
|
3
5
|
import {Connector, ConnectorsProvider} from '../_lib/connector'
|
|
4
6
|
import {AssistConnectorsOverlay} from '../assistConnectors'
|
|
5
7
|
import {AssistPluginConfig} from '../plugin'
|
|
6
|
-
import {
|
|
7
|
-
import {RunInstructionRequest} from '../useApiClient'
|
|
8
|
+
import {FieldTranslationProvider} from '../translate/FieldTranslationProvider'
|
|
8
9
|
import {StudioInstruction} from '../types'
|
|
10
|
+
import {RunInstructionRequest} from '../useApiClient'
|
|
11
|
+
import {AiAssistanceConfigProvider} from './AiAssistanceConfigContext'
|
|
9
12
|
import {RunInstructionProvider} from './RunInstructionProvider'
|
|
10
|
-
import {ThemeProvider} from '@sanity/ui'
|
|
11
|
-
import {FieldTranslationProvider} from '../translate/FieldTranslationProvider'
|
|
12
13
|
|
|
13
14
|
export interface AIStudioLayoutProps extends LayoutProps {
|
|
14
15
|
config: AssistPluginConfig
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {Button, Dialog, Flex, Stack, Text, TextArea, Tooltip} from '@sanity/ui'
|
|
2
|
-
import {getInstructionTitle} from '../helpers/misc'
|
|
3
1
|
import {PlayIcon} from '@sanity/icons'
|
|
2
|
+
import {Button, Dialog, Flex, Stack, Text, TextArea, Tooltip} from '@sanity/ui'
|
|
4
3
|
import {
|
|
5
4
|
createContext,
|
|
6
|
-
Dispatch,
|
|
7
|
-
FormEvent,
|
|
8
|
-
PropsWithChildren,
|
|
9
|
-
SetStateAction,
|
|
5
|
+
type Dispatch,
|
|
6
|
+
type FormEvent,
|
|
7
|
+
type PropsWithChildren,
|
|
8
|
+
type SetStateAction,
|
|
10
9
|
useCallback,
|
|
11
10
|
useContext,
|
|
12
11
|
useEffect,
|
|
@@ -15,11 +14,13 @@ import {
|
|
|
15
14
|
useRef,
|
|
16
15
|
useState,
|
|
17
16
|
} from 'react'
|
|
18
|
-
import {
|
|
19
|
-
|
|
17
|
+
import {FormFieldHeaderText} from 'sanity'
|
|
18
|
+
|
|
19
|
+
import {getInstructionTitle} from '../helpers/misc'
|
|
20
|
+
import {type UserInputBlock, userInputTypeName} from '../types'
|
|
20
21
|
import {useApiClient, useRunInstructionApi} from '../useApiClient'
|
|
21
22
|
import {useAiAssistanceConfig} from './AiAssistanceConfigContext'
|
|
22
|
-
import {
|
|
23
|
+
import type {RunInstructionArgs} from './AssistLayout'
|
|
23
24
|
|
|
24
25
|
type BlockInputs = Record<string, string>
|
|
25
26
|
const NO_INPUT: BlockInputs = {}
|
|
@@ -42,6 +43,7 @@ function isUserInputBlock(block: {_type: string}): block is UserInputBlock {
|
|
|
42
43
|
return block._type === userInputTypeName
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
45
47
|
export function RunInstructionProvider(props: PropsWithChildren<{}>) {
|
|
46
48
|
const {config} = useAiAssistanceConfig()
|
|
47
49
|
const apiClient = useApiClient(config?.__customApiClient)
|
|
@@ -63,7 +65,7 @@ export function RunInstructionProvider(props: PropsWithChildren<{}>) {
|
|
|
63
65
|
const instructionKey = instruction._key
|
|
64
66
|
const userInputBlocks = instruction?.prompt
|
|
65
67
|
?.flatMap((block) =>
|
|
66
|
-
block._type === 'block' ? block.children.filter(isUserInputBlock) : [block]
|
|
68
|
+
block._type === 'block' ? block.children.filter(isUserInputBlock) : [block],
|
|
67
69
|
)
|
|
68
70
|
.filter(isUserInputBlock)
|
|
69
71
|
|
|
@@ -81,16 +83,17 @@ export function RunInstructionProvider(props: PropsWithChildren<{}>) {
|
|
|
81
83
|
userInputBlocks,
|
|
82
84
|
})
|
|
83
85
|
},
|
|
84
|
-
[
|
|
86
|
+
[runInstructionRequest, loading],
|
|
85
87
|
)
|
|
86
88
|
|
|
87
89
|
const close = useCallback(() => {
|
|
88
90
|
setRunRequest(undefined)
|
|
89
91
|
setInputs(NO_INPUT)
|
|
90
|
-
}, [
|
|
92
|
+
}, [])
|
|
91
93
|
|
|
92
94
|
const runWithInput = useCallback(() => {
|
|
93
95
|
if (runRequest) {
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
94
97
|
const {instruction, userTexts, ...request} = runRequest
|
|
95
98
|
runInstructionRequest({
|
|
96
99
|
...request,
|
|
@@ -110,7 +113,7 @@ export function RunInstructionProvider(props: PropsWithChildren<{}>) {
|
|
|
110
113
|
() =>
|
|
111
114
|
(runRequest?.userInputBlocks?.length ?? 0) >
|
|
112
115
|
Object.entries(inputs).filter(([, value]) => !!value).length,
|
|
113
|
-
[runRequest?.userInputBlocks, inputs]
|
|
116
|
+
[runRequest?.userInputBlocks, inputs],
|
|
114
117
|
)
|
|
115
118
|
|
|
116
119
|
const runButton = (
|
|
@@ -126,7 +129,7 @@ export function RunInstructionProvider(props: PropsWithChildren<{}>) {
|
|
|
126
129
|
|
|
127
130
|
const contextValue: RunInstructionContextValue = useMemo(
|
|
128
131
|
() => ({runInstruction, instructionLoading: loading}),
|
|
129
|
-
[runInstruction, loading]
|
|
132
|
+
[runInstruction, loading],
|
|
130
133
|
)
|
|
131
134
|
|
|
132
135
|
return (
|
|
@@ -192,7 +195,7 @@ function UserInput(props: {
|
|
|
192
195
|
[key]: (e.currentTarget ?? e.target).value,
|
|
193
196
|
}))
|
|
194
197
|
},
|
|
195
|
-
[key, setInputs]
|
|
198
|
+
[key, setInputs],
|
|
196
199
|
)
|
|
197
200
|
|
|
198
201
|
const value = useMemo(() => inputs[key], [inputs, key])
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {forwardRef, ReactElement, ReactNode} from 'react'
|
|
2
|
-
import
|
|
1
|
+
import {forwardRef, type ReactElement, type ReactNode} from 'react'
|
|
2
|
+
import {keyframes, styled} from 'styled-components'
|
|
3
3
|
|
|
4
4
|
const fadeIn = keyframes`
|
|
5
5
|
0% {
|
|
@@ -30,7 +30,7 @@ export const FadeInContent = forwardRef(function FadeInContent(
|
|
|
30
30
|
ms?: number
|
|
31
31
|
durationMs?: number
|
|
32
32
|
},
|
|
33
|
-
ref: any
|
|
33
|
+
ref: any,
|
|
34
34
|
): ReactElement {
|
|
35
35
|
return (
|
|
36
36
|
<FadeInDiv ref={ref} style={{animationDuration: `${durationMs}ms`}}>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {ObjectInputProps} from 'sanity'
|
|
2
1
|
import {Box} from '@sanity/ui'
|
|
3
2
|
import {useEffect, useRef} from 'react'
|
|
3
|
+
import {ObjectInputProps} from 'sanity'
|
|
4
4
|
|
|
5
5
|
export function HideReferenceChangedBannerInput(props: ObjectInputProps) {
|
|
6
6
|
const ref = useRef<HTMLDivElement>(null)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {createContext, useEffect, useMemo, useState} from 'react'
|
|
2
|
-
import {InputProps, pathToString, useSyncState} from 'sanity'
|
|
3
|
-
import {
|
|
2
|
+
import {type InputProps, pathToString, useSyncState} from 'sanity'
|
|
3
|
+
import {usePaneRouter} from 'sanity/structure'
|
|
4
|
+
|
|
4
5
|
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
5
|
-
import {canUseAssist, useApiClient, useGenerateCaption} from '../useApiClient'
|
|
6
6
|
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
7
7
|
import {publicId} from '../helpers/ids'
|
|
8
|
-
import {
|
|
8
|
+
import {getDescriptionFieldOption, getImageInstructionFieldOption} from '../helpers/typeUtils'
|
|
9
|
+
import {canUseAssist, useApiClient, useGenerateCaption} from '../useApiClient'
|
|
9
10
|
|
|
10
11
|
export interface ImageContextValue {
|
|
11
12
|
imageDescriptionPath?: string
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {InputProps, isArraySchemaType, PatchEvent, unset} from 'sanity'
|
|
2
|
-
import {ErrorInfo, PropsWithChildren, useCallback, useMemo, useState} from 'react'
|
|
3
1
|
import {Box, Button, Card, ErrorBoundary, Flex, Stack, Text} from '@sanity/ui'
|
|
2
|
+
import {type ErrorInfo, type PropsWithChildren, useCallback, useMemo, useState} from 'react'
|
|
3
|
+
import {type InputProps, isArraySchemaType, PatchEvent, unset} from 'sanity'
|
|
4
|
+
import {styled} from 'styled-components'
|
|
5
|
+
|
|
4
6
|
import {isPortableTextArray} from '../helpers/typeUtils'
|
|
5
|
-
import styled from 'styled-components'
|
|
6
7
|
|
|
7
8
|
const WrapPreCard = styled(Card)`
|
|
8
9
|
& pre {
|
|
@@ -19,17 +20,14 @@ export function SafeValueInput(props: InputProps) {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function ErrorWrapper(
|
|
22
|
-
props: PropsWithChildren<{onChange: (patchEvent: PatchEvent) => void}
|
|
23
|
+
props: PropsWithChildren<{onChange: (patchEvent: PatchEvent) => void}>,
|
|
23
24
|
) {
|
|
24
25
|
const {onChange} = props
|
|
25
26
|
const [error, setError] = useState<Error | undefined>()
|
|
26
27
|
|
|
27
|
-
const catchError = useCallback(
|
|
28
|
-
(params
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
[setError]
|
|
32
|
-
)
|
|
28
|
+
const catchError = useCallback((params: {error: Error; info: ErrorInfo}) => {
|
|
29
|
+
setError(params.error)
|
|
30
|
+
}, [])
|
|
33
31
|
|
|
34
32
|
const unsetValue = useCallback(() => {
|
|
35
33
|
onChange(PatchEvent.from(unset()))
|
|
@@ -65,7 +63,7 @@ export function ErrorWrapper(
|
|
|
65
63
|
function PteValueFixer(props: InputProps) {
|
|
66
64
|
const isPortableText = useMemo(
|
|
67
65
|
() => isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType),
|
|
68
|
-
[props.schemaType]
|
|
66
|
+
[props.schemaType],
|
|
69
67
|
)
|
|
70
68
|
const value = props.value
|
|
71
69
|
if (isPortableText && value && !(value as any[]).length) {
|