@sanity/assist 5.0.4 → 6.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/LICENSE +1 -1
- package/README.md +28 -254
- package/dist/index.d.ts +322 -410
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3181 -2649
- package/dist/index.js.map +1 -1
- package/package.json +38 -78
- package/dist/index.cjs +0 -4239
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -791
- package/sanity.json +0 -8
- package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
- package/src/_lib/connector/ConnectToRegion.tsx +0 -23
- package/src/_lib/connector/ConnectorRegion.tsx +0 -24
- package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
- package/src/_lib/connector/ConnectorsStore.ts +0 -122
- package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
- package/src/_lib/connector/helpers.ts +0 -5
- package/src/_lib/connector/index.ts +0 -9
- package/src/_lib/connector/mapConnectorToLine.ts +0 -83
- package/src/_lib/connector/types.ts +0 -56
- package/src/_lib/connector/useConnectorsStore.ts +0 -14
- package/src/_lib/connector/useRegionRects.ts +0 -142
- package/src/_lib/fixedListenQuery.ts +0 -101
- package/src/_lib/form/DocumentForm.tsx +0 -201
- package/src/_lib/form/constants.ts +0 -1
- package/src/_lib/form/helpers.ts +0 -32
- package/src/_lib/form/index.ts +0 -1
- package/src/_lib/randomKey.ts +0 -29
- package/src/_lib/useListeningQuery.ts +0 -62
- package/src/_lib/usePrevious.ts +0 -9
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
- package/src/assistConnectors/ConnectorPath.tsx +0 -63
- package/src/assistConnectors/draw/arrowPath.ts +0 -9
- package/src/assistConnectors/draw/connectorPath.ts +0 -142
- package/src/assistConnectors/index.ts +0 -1
- package/src/assistDocument/AssistDocumentContext.tsx +0 -51
- package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
- package/src/assistDocument/AssistDocumentInput.tsx +0 -61
- package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
- package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
- package/src/assistDocument/components/AssistDocumentForm.tsx +0 -287
- package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
- package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
- package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
- package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
- package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
- package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
- package/src/assistDocument/components/helpers.ts +0 -21
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
- package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
- package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -127
- package/src/assistDocument/hooks/useDocumentState.ts +0 -6
- package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
- package/src/assistDocument/index.ts +0 -1
- package/src/assistFormComponents/AssistField.tsx +0 -63
- package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
- package/src/assistFormComponents/AssistItem.tsx +0 -21
- package/src/assistFormComponents/validation/listItem.tsx +0 -63
- package/src/assistFormComponents/validation/validationList.tsx +0 -90
- package/src/assistInspector/AssistInspector.tsx +0 -419
- package/src/assistInspector/FieldAutocomplete.tsx +0 -146
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
- package/src/assistInspector/constants.ts +0 -1
- package/src/assistInspector/helpers.ts +0 -211
- package/src/assistInspector/index.ts +0 -27
- package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
- package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
- package/src/assistLayout/AssistLayout.tsx +0 -39
- package/src/assistLayout/RunInstructionProvider.tsx +0 -278
- package/src/assistLayout/fieldRefCache.tsx +0 -34
- package/src/assistTypes.ts +0 -83
- package/src/components/AssistFeatureBadge.tsx +0 -9
- package/src/components/FadeInContent.tsx +0 -40
- package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
- package/src/components/ImageContext.tsx +0 -85
- package/src/components/SafeValueInput.tsx +0 -74
- package/src/components/TimeAgo.tsx +0 -18
- package/src/constants.ts +0 -20
- package/src/fieldActions/PrivateIcon.tsx +0 -20
- package/src/fieldActions/assistFieldActions.tsx +0 -320
- package/src/fieldActions/customFieldActions.tsx +0 -333
- package/src/fieldActions/generateCaptionActions.tsx +0 -77
- package/src/fieldActions/generateImageActions.tsx +0 -58
- package/src/fieldActions/useUserInput.ts +0 -107
- package/src/globals.d.ts +0 -4
- package/src/helpers/assistSupported.ts +0 -49
- package/src/helpers/conditionalMembers.test.ts +0 -319
- package/src/helpers/conditionalMembers.ts +0 -134
- package/src/helpers/ids.test.ts +0 -28
- package/src/helpers/ids.ts +0 -23
- package/src/helpers/misc.ts +0 -25
- package/src/helpers/styleguide.ts +0 -24
- package/src/helpers/typeUtils.ts +0 -60
- package/src/helpers/useAssistSupported.ts +0 -8
- package/src/index.ts +0 -26
- package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
- package/src/onboarding/InspectorOnboarding.tsx +0 -47
- package/src/onboarding/onboardingStore.ts +0 -32
- package/src/plugin.tsx +0 -162
- package/src/presence/AiFieldPresence.tsx +0 -28
- package/src/presence/AssistAvatar.tsx +0 -96
- package/src/presence/AssistDocumentPresence.tsx +0 -50
- package/src/presence/useAssistPresence.ts +0 -64
- package/src/schemas/assistDocumentSchema.tsx +0 -497
- package/src/schemas/contextDocumentSchema.tsx +0 -57
- package/src/schemas/index.ts +0 -69
- package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
- package/src/schemas/serialize/schemaUtils.ts +0 -38
- package/src/schemas/serialize/serializeSchema.test.ts +0 -819
- package/src/schemas/serialize/serializeSchema.ts +0 -224
- package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
- package/src/schemas/typeDefExtensions.ts +0 -127
- package/src/translate/FieldTranslationProvider.tsx +0 -382
- package/src/translate/getLanguageParams.ts +0 -26
- package/src/translate/languageStore.ts +0 -18
- package/src/translate/paths.test.ts +0 -181
- package/src/translate/paths.ts +0 -183
- package/src/translate/translateActions.tsx +0 -205
- package/src/translate/types.ts +0 -197
- package/src/types.ts +0 -220
- package/src/useApiClient.ts +0 -338
- package/v2-incompatible.js +0 -11
package/src/types.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import {PortableTextBlock, PortableTextMarkDefinition, PortableTextSpan} from '@portabletext/types'
|
|
2
|
-
import {SanityDocument} from 'sanity'
|
|
3
|
-
|
|
4
|
-
//id prefixes
|
|
5
|
-
export const assistDocumentIdPrefix = 'sanity.assist.schemaType.'
|
|
6
|
-
export const assistDocumentStatusIdPrefix = 'sanity.assist.status.'
|
|
7
|
-
export const assistSchemaIdPrefix = 'sanity.assist.schema.'
|
|
8
|
-
|
|
9
|
-
// type names
|
|
10
|
-
export const assistDocumentTypeName = 'sanity.assist.schemaType.annotations' as const
|
|
11
|
-
export const assistFieldTypeName = 'sanity.assist.schemaType.field' as const
|
|
12
|
-
export const instructionTypeName = 'sanity.assist.instruction' as const
|
|
13
|
-
export const promptTypeName = 'sanity.assist.instruction.prompt' as const
|
|
14
|
-
|
|
15
|
-
export const userInputTypeName = 'sanity.assist.instruction.userInput' as const
|
|
16
|
-
export const instructionContextTypeName = 'sanity.assist.instruction.context' as const
|
|
17
|
-
export const fieldReferenceTypeName = 'sanity.assist.instruction.fieldRef' as const
|
|
18
|
-
|
|
19
|
-
// user-facing type. Intentionally does not have sanity. prefix
|
|
20
|
-
export const contextDocumentTypeName = 'assist.instruction.context' as const
|
|
21
|
-
|
|
22
|
-
export const assistTasksStatusTypeName = 'sanity.assist.task.status' as const
|
|
23
|
-
export const instructionTaskTypeName = 'sanity.assist.instructionTask' as const
|
|
24
|
-
export const fieldPresenceTypeName = 'sanity.assist.instructionTask.presence' as const
|
|
25
|
-
|
|
26
|
-
export const assistSerializedTypeName = 'sanity.assist.serialized.type' as const
|
|
27
|
-
export const assistSerializedFieldTypeName = 'sanity.assist.serialized.field' as const
|
|
28
|
-
|
|
29
|
-
export const outputFieldTypeName = 'sanity.assist.output.field' as const
|
|
30
|
-
export const outputTypeTypeName = 'sanity.assist.output.type' as const
|
|
31
|
-
|
|
32
|
-
//url params
|
|
33
|
-
export const inspectParam = 'inspect' as const
|
|
34
|
-
export const fieldPathParam = 'pathKey' as const
|
|
35
|
-
export const instructionParam = 'instruction' as const
|
|
36
|
-
|
|
37
|
-
// other constants
|
|
38
|
-
export const documentRootKey = '<document>'
|
|
39
|
-
|
|
40
|
-
export type SerializedSchemaMember = Omit<SerializedSchemaType, 'name' | '_type'> & {
|
|
41
|
-
_type?: typeof assistSerializedFieldTypeName
|
|
42
|
-
name?: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface SerializedSchemaType {
|
|
46
|
-
_type?: typeof assistSerializedTypeName
|
|
47
|
-
_id?: string
|
|
48
|
-
type: string
|
|
49
|
-
name: string
|
|
50
|
-
title?: string
|
|
51
|
-
fields?: SerializedSchemaMember[]
|
|
52
|
-
of?: SerializedSchemaMember[]
|
|
53
|
-
to?: SerializedSchemaMember[]
|
|
54
|
-
annotations?: SerializedSchemaMember[]
|
|
55
|
-
inlineOf?: SerializedSchemaMember[]
|
|
56
|
-
values?: string[] | {value: string; title?: string}[]
|
|
57
|
-
hidden?: boolean | 'function'
|
|
58
|
-
readOnly?: boolean | 'function'
|
|
59
|
-
options?: {
|
|
60
|
-
/** equivalent to options.aiAssist.imageDescriptionField - not renamed in the api for backwards compatability */
|
|
61
|
-
imagePromptField?: string
|
|
62
|
-
embeddingsIndex?: string
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface AssistDocument extends SanityDocument {
|
|
67
|
-
fields?: AssistField[]
|
|
68
|
-
instructions?: StudioInstruction[]
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface PresetInstruction {
|
|
72
|
-
_key: string
|
|
73
|
-
prompt?: PromptTextBlock[]
|
|
74
|
-
|
|
75
|
-
title?: string
|
|
76
|
-
/**
|
|
77
|
-
* String key from `@sanity/icons` IconMap
|
|
78
|
-
*/
|
|
79
|
-
icon?: string
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Type/field filter
|
|
83
|
-
*/
|
|
84
|
-
output?: (OutputFieldItem | OutputTypeItem)[]
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface PresetField {
|
|
88
|
-
path?: string
|
|
89
|
-
instructions?: PresetInstruction[]
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface AssistPreset {
|
|
93
|
-
fields?: PresetField[]
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface SanityAssistDocument {
|
|
97
|
-
_id: string
|
|
98
|
-
_type: typeof assistDocumentTypeName
|
|
99
|
-
fields?: StudioAssistField[]
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface StudioAssistDocument extends SanityAssistDocument {
|
|
103
|
-
// added after loading
|
|
104
|
-
tasks?: InstructionTask[]
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface AssistField {
|
|
108
|
-
_key: string
|
|
109
|
-
_type: typeof assistFieldTypeName
|
|
110
|
-
path?: string
|
|
111
|
-
instructions?: StudioInstruction[]
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface StudioAssistField {
|
|
115
|
-
_key: string
|
|
116
|
-
path?: string
|
|
117
|
-
instructions?: StudioInstruction[]
|
|
118
|
-
|
|
119
|
-
// added
|
|
120
|
-
tasks?: InstructionTask[]
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface FieldRef extends PortableTextMarkDefinition {
|
|
124
|
-
_type: typeof fieldReferenceTypeName
|
|
125
|
-
path?: string
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface ContextBlock {
|
|
129
|
-
_type: typeof instructionContextTypeName
|
|
130
|
-
reference?: {
|
|
131
|
-
_type: 'reference'
|
|
132
|
-
_ref?: string
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface UserInputBlock {
|
|
137
|
-
_type: typeof userInputTypeName
|
|
138
|
-
_key: string
|
|
139
|
-
message?: string
|
|
140
|
-
description?: string
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export type InlinePromptBlock = PortableTextSpan | FieldRef | UserInputBlock | ContextBlock
|
|
144
|
-
export type PromptTextBlock = Omit<
|
|
145
|
-
PortableTextBlock<never, InlinePromptBlock, 'normal', never>,
|
|
146
|
-
'_type'
|
|
147
|
-
> & {_type: 'block'}
|
|
148
|
-
|
|
149
|
-
export type PromptBlock = PromptTextBlock | FieldRef | ContextBlock | UserInputBlock
|
|
150
|
-
|
|
151
|
-
export interface AiPresence {
|
|
152
|
-
_key: string
|
|
153
|
-
_type: typeof fieldPresenceTypeName
|
|
154
|
-
path?: string
|
|
155
|
-
started?: string
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export type TaskEndedReason = 'success' | 'error' | 'aborted' | 'timeout'
|
|
159
|
-
|
|
160
|
-
export interface InstructionTask {
|
|
161
|
-
_key: string
|
|
162
|
-
_type: typeof instructionTaskTypeName
|
|
163
|
-
instructionKey?: string
|
|
164
|
-
title?: string
|
|
165
|
-
path?: string
|
|
166
|
-
started?: string
|
|
167
|
-
updated?: string
|
|
168
|
-
ended?: string
|
|
169
|
-
message?: string
|
|
170
|
-
reason?: TaskEndedReason
|
|
171
|
-
presence?: AiPresence[]
|
|
172
|
-
startedByUserId?: string
|
|
173
|
-
|
|
174
|
-
//added by studio
|
|
175
|
-
// eslint-disable-next-line no-use-before-define
|
|
176
|
-
instruction?: StudioInstruction
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export interface StudioInstruction {
|
|
180
|
-
_key: string
|
|
181
|
-
_type: typeof instructionTypeName
|
|
182
|
-
prompt?: PromptBlock[]
|
|
183
|
-
|
|
184
|
-
icon?: string
|
|
185
|
-
userId?: string
|
|
186
|
-
title?: string
|
|
187
|
-
placeholder?: string
|
|
188
|
-
output?: (OutputFieldItem | OutputTypeItem)[]
|
|
189
|
-
|
|
190
|
-
//added after query / synthetic fields
|
|
191
|
-
tasks?: InstructionTask[]
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export interface AssistTasksStatus {
|
|
195
|
-
_id: string
|
|
196
|
-
_type: typeof assistTasksStatusTypeName
|
|
197
|
-
tasks?: InstructionTask[]
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export interface AssistInspectorRouteParams {
|
|
201
|
-
[inspectParam]?: string
|
|
202
|
-
[fieldPathParam]?: string
|
|
203
|
-
[instructionParam]?: string
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface OutputFieldItem {
|
|
207
|
-
_type: typeof outputFieldTypeName
|
|
208
|
-
_key: string
|
|
209
|
-
//path relative to the field the instruction is for (same as _key)
|
|
210
|
-
relativePath?: string
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export interface OutputTypeItem {
|
|
214
|
-
_type: typeof outputTypeTypeName
|
|
215
|
-
_key: string
|
|
216
|
-
/* array item type name */
|
|
217
|
-
type?: string
|
|
218
|
-
//path relative to the array-field the instruction is for, can be empty string (the array itself, same as _key)
|
|
219
|
-
relativePath?: string
|
|
220
|
-
}
|
package/src/useApiClient.ts
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import type {SanityClient} from '@sanity/client'
|
|
2
|
-
import {useToast} from '@sanity/ui'
|
|
3
|
-
import {useCallback, useMemo, useState} from 'react'
|
|
4
|
-
import {Path, pathToString, useClient, useCurrentUser} from 'sanity'
|
|
5
|
-
|
|
6
|
-
import {useAiAssistanceConfig, useSerializedTypes} from './assistLayout/AiAssistanceConfigContext'
|
|
7
|
-
import {ConditionalMemberState} from './helpers/conditionalMembers'
|
|
8
|
-
import {FieldLanguageMap} from './translate/paths'
|
|
9
|
-
import {documentRootKey} from './types'
|
|
10
|
-
|
|
11
|
-
export interface UserTextInstance {
|
|
12
|
-
blockKey: string
|
|
13
|
-
userInput: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface RunInstructionRequest {
|
|
17
|
-
documentId: string
|
|
18
|
-
assistDocumentId: string
|
|
19
|
-
path: string
|
|
20
|
-
typePath?: string
|
|
21
|
-
instructionKey: string
|
|
22
|
-
userId?: string
|
|
23
|
-
userTexts?: UserTextInstance[]
|
|
24
|
-
conditionalMembers?: ConditionalMemberState[]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface InstructStatus {
|
|
28
|
-
enabled: boolean
|
|
29
|
-
initialized: boolean
|
|
30
|
-
validToken: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface TranslateRequest {
|
|
34
|
-
documentId: string
|
|
35
|
-
translatePath: Path
|
|
36
|
-
languagePath?: string
|
|
37
|
-
styleguide: () => Promise<string | undefined>
|
|
38
|
-
fieldLanguageMap?: FieldLanguageMap[]
|
|
39
|
-
conditionalMembers?: ConditionalMemberState[]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const basePath = '/assist/tasks/instruction'
|
|
43
|
-
export const API_VERSION_WITH_EXTENDED_TYPES = '2025-04-01'
|
|
44
|
-
|
|
45
|
-
export function canUseAssist(status: InstructStatus | undefined) {
|
|
46
|
-
return status?.enabled && status.initialized && status.validToken
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function useApiClient(customApiClient?: (defaultClient: SanityClient) => SanityClient) {
|
|
50
|
-
const client = useClient({apiVersion: API_VERSION_WITH_EXTENDED_TYPES})
|
|
51
|
-
return useMemo(
|
|
52
|
-
() => (customApiClient ? customApiClient(client) : client),
|
|
53
|
-
[client, customApiClient],
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function useTranslate(apiClient: SanityClient) {
|
|
58
|
-
const [loading, setLoading] = useState(false)
|
|
59
|
-
const user = useCurrentUser()
|
|
60
|
-
const types = useSerializedTypes()
|
|
61
|
-
const toast = useToast()
|
|
62
|
-
|
|
63
|
-
const translate = useCallback(
|
|
64
|
-
({
|
|
65
|
-
documentId,
|
|
66
|
-
languagePath,
|
|
67
|
-
styleguide,
|
|
68
|
-
translatePath,
|
|
69
|
-
fieldLanguageMap,
|
|
70
|
-
conditionalMembers,
|
|
71
|
-
}: TranslateRequest) => {
|
|
72
|
-
setLoading(true)
|
|
73
|
-
|
|
74
|
-
async function run() {
|
|
75
|
-
return apiClient.request({
|
|
76
|
-
method: 'POST',
|
|
77
|
-
url: `/assist/tasks/translate/${apiClient.config().dataset}?projectId=${
|
|
78
|
-
apiClient.config().projectId
|
|
79
|
-
}`,
|
|
80
|
-
body: {
|
|
81
|
-
documentId,
|
|
82
|
-
types,
|
|
83
|
-
languagePath,
|
|
84
|
-
userStyleguide: await styleguide(),
|
|
85
|
-
fieldLanguageMap,
|
|
86
|
-
conditionalMembers,
|
|
87
|
-
translatePath:
|
|
88
|
-
translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
|
|
89
|
-
userId: user?.id,
|
|
90
|
-
},
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return run()
|
|
95
|
-
.catch((e) => {
|
|
96
|
-
toast.push({
|
|
97
|
-
status: 'error',
|
|
98
|
-
title: 'Translate failed',
|
|
99
|
-
description: e.message,
|
|
100
|
-
})
|
|
101
|
-
setLoading(false)
|
|
102
|
-
throw e
|
|
103
|
-
})
|
|
104
|
-
.finally(() => {
|
|
105
|
-
// adding some artificial delay here
|
|
106
|
-
// server responds with 201 then proceeds; we dont need to allow spamming the button
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
setLoading(false)
|
|
109
|
-
}, 2000)
|
|
110
|
-
})
|
|
111
|
-
},
|
|
112
|
-
[setLoading, apiClient, toast, user, types],
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
return useMemo(
|
|
116
|
-
() => ({
|
|
117
|
-
translate,
|
|
118
|
-
loading,
|
|
119
|
-
}),
|
|
120
|
-
[translate, loading],
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function useGenerateCaption(apiClient: SanityClient) {
|
|
125
|
-
const [loading, setLoading] = useState(false)
|
|
126
|
-
const user = useCurrentUser()
|
|
127
|
-
const types = useSerializedTypes()
|
|
128
|
-
const toast = useToast()
|
|
129
|
-
|
|
130
|
-
const generateCaption = useCallback(
|
|
131
|
-
({path, documentId}: {path: string; documentId: string}) => {
|
|
132
|
-
setLoading(true)
|
|
133
|
-
|
|
134
|
-
return apiClient
|
|
135
|
-
.request({
|
|
136
|
-
method: 'POST',
|
|
137
|
-
url: `/assist/tasks/generate-caption/${apiClient.config().dataset}?projectId=${
|
|
138
|
-
apiClient.config().projectId
|
|
139
|
-
}`,
|
|
140
|
-
body: {
|
|
141
|
-
path,
|
|
142
|
-
documentId,
|
|
143
|
-
types,
|
|
144
|
-
userId: user?.id,
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
.catch((e) => {
|
|
148
|
-
toast.push({
|
|
149
|
-
status: 'error',
|
|
150
|
-
title: 'Generate image description failed',
|
|
151
|
-
description: e.message,
|
|
152
|
-
})
|
|
153
|
-
setLoading(false)
|
|
154
|
-
throw e
|
|
155
|
-
})
|
|
156
|
-
.finally(() => {
|
|
157
|
-
// adding some artificial delay here
|
|
158
|
-
// server responds with 201 then proceeds; we dont need to allow spamming the button
|
|
159
|
-
setTimeout(() => {
|
|
160
|
-
setLoading(false)
|
|
161
|
-
}, 2000)
|
|
162
|
-
})
|
|
163
|
-
},
|
|
164
|
-
[setLoading, apiClient, toast, user, types],
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
return useMemo(
|
|
168
|
-
() => ({
|
|
169
|
-
generateCaption,
|
|
170
|
-
loading,
|
|
171
|
-
}),
|
|
172
|
-
[generateCaption, loading],
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function useGenerateImage(apiClient: SanityClient) {
|
|
177
|
-
const [loading, setLoading] = useState(false)
|
|
178
|
-
const user = useCurrentUser()
|
|
179
|
-
const types = useSerializedTypes()
|
|
180
|
-
const toast = useToast()
|
|
181
|
-
|
|
182
|
-
const generateImage = useCallback(
|
|
183
|
-
({path, documentId}: {path: string; documentId: string}) => {
|
|
184
|
-
setLoading(true)
|
|
185
|
-
|
|
186
|
-
return apiClient
|
|
187
|
-
.request({
|
|
188
|
-
method: 'POST',
|
|
189
|
-
url: `/assist/tasks/generate-image/${apiClient.config().dataset}?projectId=${
|
|
190
|
-
apiClient.config().projectId
|
|
191
|
-
}`,
|
|
192
|
-
body: {
|
|
193
|
-
path,
|
|
194
|
-
documentId,
|
|
195
|
-
types,
|
|
196
|
-
userId: user?.id,
|
|
197
|
-
},
|
|
198
|
-
})
|
|
199
|
-
.catch((e) => {
|
|
200
|
-
toast.push({
|
|
201
|
-
status: 'error',
|
|
202
|
-
title: 'Generate image from prompt failed',
|
|
203
|
-
description: e.message,
|
|
204
|
-
})
|
|
205
|
-
setLoading(false)
|
|
206
|
-
throw e
|
|
207
|
-
})
|
|
208
|
-
.finally(() => {
|
|
209
|
-
// adding some artificial delay here
|
|
210
|
-
// server responds with 201 then proceeds; we dont need to allow spamming the button
|
|
211
|
-
setTimeout(() => {
|
|
212
|
-
setLoading(false)
|
|
213
|
-
}, 2000)
|
|
214
|
-
})
|
|
215
|
-
},
|
|
216
|
-
[setLoading, apiClient, toast, user, types],
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
return useMemo(
|
|
220
|
-
() => ({
|
|
221
|
-
generateImage,
|
|
222
|
-
loading,
|
|
223
|
-
}),
|
|
224
|
-
[generateImage, loading],
|
|
225
|
-
)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export function useGetInstructStatus(apiClient: SanityClient) {
|
|
229
|
-
const [loading, setLoading] = useState(true)
|
|
230
|
-
|
|
231
|
-
const getInstructStatus = useCallback(async () => {
|
|
232
|
-
setLoading(true)
|
|
233
|
-
|
|
234
|
-
const projectId = apiClient.config().projectId
|
|
235
|
-
try {
|
|
236
|
-
const status = await apiClient.request<InstructStatus>({
|
|
237
|
-
method: 'GET',
|
|
238
|
-
url: `${basePath}/${apiClient.config().dataset}/status?projectId=${projectId}`,
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
return status
|
|
242
|
-
} finally {
|
|
243
|
-
setLoading(false)
|
|
244
|
-
}
|
|
245
|
-
}, [setLoading, apiClient])
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
loading,
|
|
249
|
-
getInstructStatus,
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export function useInitInstruct(apiClient: SanityClient) {
|
|
254
|
-
const [loading, setLoading] = useState(false)
|
|
255
|
-
const initInstruct = useCallback(() => {
|
|
256
|
-
setLoading(true)
|
|
257
|
-
return apiClient
|
|
258
|
-
.request({
|
|
259
|
-
method: 'GET',
|
|
260
|
-
url: `${basePath}/${apiClient.config().dataset}/init?projectId=${
|
|
261
|
-
apiClient.config().projectId
|
|
262
|
-
}`,
|
|
263
|
-
})
|
|
264
|
-
.finally(() => {
|
|
265
|
-
setLoading(false)
|
|
266
|
-
})
|
|
267
|
-
}, [setLoading, apiClient])
|
|
268
|
-
|
|
269
|
-
return {
|
|
270
|
-
loading,
|
|
271
|
-
initInstruct,
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function useRunInstructionApi(apiClient: SanityClient) {
|
|
276
|
-
const toast = useToast()
|
|
277
|
-
const [loading, setLoading] = useState(false)
|
|
278
|
-
const user = useCurrentUser()
|
|
279
|
-
const types = useSerializedTypes()
|
|
280
|
-
|
|
281
|
-
const {
|
|
282
|
-
config: {assist: assistConfig},
|
|
283
|
-
} = useAiAssistanceConfig()
|
|
284
|
-
|
|
285
|
-
const runInstruction = useCallback(
|
|
286
|
-
(request: RunInstructionRequest) => {
|
|
287
|
-
if (!user) {
|
|
288
|
-
toast.push({
|
|
289
|
-
status: 'error',
|
|
290
|
-
title: 'Unable to get user for instruction.',
|
|
291
|
-
})
|
|
292
|
-
return undefined
|
|
293
|
-
}
|
|
294
|
-
setLoading(true)
|
|
295
|
-
|
|
296
|
-
const {timeZone, locale} = Intl.DateTimeFormat().resolvedOptions()
|
|
297
|
-
const defaultLocaleSettings = {timeZone, locale}
|
|
298
|
-
const localeSettings =
|
|
299
|
-
assistConfig?.localeSettings?.({user, defaultSettings: defaultLocaleSettings}) ??
|
|
300
|
-
defaultLocaleSettings
|
|
301
|
-
|
|
302
|
-
return apiClient
|
|
303
|
-
.request({
|
|
304
|
-
method: 'POST',
|
|
305
|
-
url: `${basePath}/${apiClient.config().dataset}?projectId=${
|
|
306
|
-
apiClient.config().projectId
|
|
307
|
-
}`,
|
|
308
|
-
body: {
|
|
309
|
-
...request,
|
|
310
|
-
types,
|
|
311
|
-
userId: user?.id,
|
|
312
|
-
localeSettings,
|
|
313
|
-
maxPathDepth: assistConfig?.maxPathDepth,
|
|
314
|
-
},
|
|
315
|
-
})
|
|
316
|
-
.catch((e) => {
|
|
317
|
-
toast.push({
|
|
318
|
-
status: 'error',
|
|
319
|
-
title: 'Instruction failed',
|
|
320
|
-
description: e.message,
|
|
321
|
-
})
|
|
322
|
-
throw e
|
|
323
|
-
})
|
|
324
|
-
.finally(() => {
|
|
325
|
-
setLoading(false)
|
|
326
|
-
})
|
|
327
|
-
},
|
|
328
|
-
[apiClient, types, user, toast, assistConfig],
|
|
329
|
-
)
|
|
330
|
-
|
|
331
|
-
return useMemo(
|
|
332
|
-
() => ({
|
|
333
|
-
runInstruction,
|
|
334
|
-
loading,
|
|
335
|
-
}),
|
|
336
|
-
[runInstruction, loading],
|
|
337
|
-
)
|
|
338
|
-
}
|
package/v2-incompatible.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
|
|
2
|
-
const {name, version, sanityExchangeUrl} = require('./package.json')
|
|
3
|
-
|
|
4
|
-
export default showIncompatiblePluginDialog({
|
|
5
|
-
name: name,
|
|
6
|
-
versions: {
|
|
7
|
-
v3: version,
|
|
8
|
-
v2: undefined,
|
|
9
|
-
},
|
|
10
|
-
sanityExchangeUrl,
|
|
11
|
-
})
|