@sanity/assist 5.0.4 → 6.0.1
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 +3205 -2670
- package/dist/index.js.map +1 -1
- package/package.json +41 -81
- 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
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {purple} from '@sanity/color'
|
|
2
|
-
import {SparklesIcon} from '@sanity/icons'
|
|
3
|
-
import {Text} from '@sanity/ui'
|
|
4
|
-
import {type CSSProperties, useMemo} from 'react'
|
|
5
|
-
import {useColorSchemeValue} from 'sanity'
|
|
6
|
-
import {keyframes, styled} from 'styled-components'
|
|
7
|
-
|
|
8
|
-
const Root = styled.span`
|
|
9
|
-
display: block;
|
|
10
|
-
width: 25px;
|
|
11
|
-
height: 25px;
|
|
12
|
-
position: relative;
|
|
13
|
-
`
|
|
14
|
-
|
|
15
|
-
const dash = keyframes`
|
|
16
|
-
0% {
|
|
17
|
-
transform: rotate(0);
|
|
18
|
-
}
|
|
19
|
-
100% {
|
|
20
|
-
transform: rotate(43deg);
|
|
21
|
-
}
|
|
22
|
-
`
|
|
23
|
-
|
|
24
|
-
const Outline = styled.svg`
|
|
25
|
-
display: block;
|
|
26
|
-
position: absolute;
|
|
27
|
-
top: 0;
|
|
28
|
-
left: 0;
|
|
29
|
-
|
|
30
|
-
& > circle {
|
|
31
|
-
stroke: var(--ai-avatar-stroke-color);
|
|
32
|
-
stroke-width: 1.5px;
|
|
33
|
-
stroke-linecap: round;
|
|
34
|
-
transform-origin: center;
|
|
35
|
-
animation: ${dash} 500ms ease-in-out infinite;
|
|
36
|
-
transition: stroke-dasharray 200ms ease-in-out;
|
|
37
|
-
|
|
38
|
-
stroke-dasharray: 2.34px 0;
|
|
39
|
-
|
|
40
|
-
[data-state='active'] > & {
|
|
41
|
-
stroke-dasharray: 2px 2.34px;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`
|
|
45
|
-
|
|
46
|
-
const IconDisc = styled.span`
|
|
47
|
-
background: var(--ai-avatar-disc-color);
|
|
48
|
-
color: white;
|
|
49
|
-
width: 21px;
|
|
50
|
-
height: 21px;
|
|
51
|
-
display: flex;
|
|
52
|
-
align-items: center;
|
|
53
|
-
justify-content: center;
|
|
54
|
-
border-radius: 10.5px;
|
|
55
|
-
position: absolute;
|
|
56
|
-
top: 2px;
|
|
57
|
-
left: 2px;
|
|
58
|
-
`
|
|
59
|
-
|
|
60
|
-
export function AssistAvatar(props: {state?: 'present' | 'active'}) {
|
|
61
|
-
const {state = 'present'} = props
|
|
62
|
-
const scheme = useColorSchemeValue()
|
|
63
|
-
|
|
64
|
-
const style = useMemo(() => {
|
|
65
|
-
if (scheme === 'dark') {
|
|
66
|
-
return {
|
|
67
|
-
[`--ai-avatar-stroke-color`]: purple[400].hex,
|
|
68
|
-
[`--ai-avatar-disc-color`]: purple[600].hex,
|
|
69
|
-
} as CSSProperties
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
[`--ai-avatar-stroke-color`]: purple[500].hex,
|
|
74
|
-
[`--ai-avatar-disc-color`]: purple[600].hex,
|
|
75
|
-
} as CSSProperties
|
|
76
|
-
}, [scheme])
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<Root data-state={state} style={style}>
|
|
80
|
-
<Outline
|
|
81
|
-
width="25"
|
|
82
|
-
height="25"
|
|
83
|
-
viewBox="0 0 25 25"
|
|
84
|
-
fill="none"
|
|
85
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
86
|
-
>
|
|
87
|
-
<circle cx="12.5" cy="12.5" r="11.75" />
|
|
88
|
-
</Outline>
|
|
89
|
-
<IconDisc>
|
|
90
|
-
<Text as="span" size={0} style={{color: 'inherit'}}>
|
|
91
|
-
<SparklesIcon style={{color: 'inherit'}} />
|
|
92
|
-
</Text>
|
|
93
|
-
</IconDisc>
|
|
94
|
-
</Root>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {Card, Flex} from '@sanity/ui'
|
|
2
|
-
import {useMemo} from 'react'
|
|
3
|
-
|
|
4
|
-
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
5
|
-
import {documentRootKey, fieldPresenceTypeName} from '../types'
|
|
6
|
-
import {AiFieldPresence} from './AiFieldPresence'
|
|
7
|
-
import {aiPresence} from './useAssistPresence'
|
|
8
|
-
|
|
9
|
-
export function createAssistDocumentPresence(documentId: string | undefined) {
|
|
10
|
-
return function AssistDocumentPresenceWrapper() {
|
|
11
|
-
return documentId ? <AssistDocumentPresence /> : null
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function AssistDocumentPresence() {
|
|
16
|
-
const {assistDocument, syntheticTasks} = useAssistDocumentContext()
|
|
17
|
-
const anyPresence = useMemo(() => {
|
|
18
|
-
const anyPresence = [...(assistDocument?.tasks ?? []), ...(syntheticTasks ?? [])]
|
|
19
|
-
?.filter((run) => !run.ended && !run.reason)
|
|
20
|
-
?.flatMap((run) => run.presence ?? [])
|
|
21
|
-
.find((f) => f.started && new Date().getTime() - new Date(f.started).getTime() < 30000)
|
|
22
|
-
if (anyPresence) {
|
|
23
|
-
return aiPresence(anyPresence, [])
|
|
24
|
-
}
|
|
25
|
-
const anyRun = assistDocument?.tasks
|
|
26
|
-
?.filter((run) => !run.ended && !run.reason)
|
|
27
|
-
?.find((f) => f.started && new Date().getTime() - new Date(f.started).getTime() < 30000)
|
|
28
|
-
return anyRun
|
|
29
|
-
? aiPresence(
|
|
30
|
-
{
|
|
31
|
-
started: anyRun.started,
|
|
32
|
-
path: documentRootKey,
|
|
33
|
-
_key: anyRun._key,
|
|
34
|
-
_type: fieldPresenceTypeName,
|
|
35
|
-
},
|
|
36
|
-
[],
|
|
37
|
-
)
|
|
38
|
-
: undefined
|
|
39
|
-
}, [assistDocument?.tasks, syntheticTasks])
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<Card>
|
|
43
|
-
<Flex flex={1} justify="flex-end">
|
|
44
|
-
<Flex gap={2} align={'center'}>
|
|
45
|
-
{anyPresence && <AiFieldPresence presence={anyPresence} />}
|
|
46
|
-
</Flex>
|
|
47
|
-
</Flex>
|
|
48
|
-
</Card>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {useMemo} from 'react'
|
|
2
|
-
import {type FormNodePresence, isKeySegment, type Path, stringToPath} from 'sanity'
|
|
3
|
-
|
|
4
|
-
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
5
|
-
import {maxHistoryVisibilityMs, pluginTitle} from '../constants'
|
|
6
|
-
import type {AiPresence} from '../types'
|
|
7
|
-
|
|
8
|
-
const NO_PRESENCE: FormNodePresence[] = []
|
|
9
|
-
|
|
10
|
-
export function useAssistPresence(path: Path, showFocusWithin?: boolean): FormNodePresence[] {
|
|
11
|
-
const context = useAssistDocumentContext()
|
|
12
|
-
const assistDocument = context && 'assistDocument' in context ? context.assistDocument : undefined
|
|
13
|
-
const tasks = assistDocument?.tasks
|
|
14
|
-
|
|
15
|
-
return useMemo(() => {
|
|
16
|
-
const activePresence = tasks
|
|
17
|
-
?.filter((task) => !task.ended)
|
|
18
|
-
?.flatMap((task) => task.presence ?? [])
|
|
19
|
-
?.filter(
|
|
20
|
-
(p) =>
|
|
21
|
-
p.started &&
|
|
22
|
-
new Date().getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs,
|
|
23
|
-
)
|
|
24
|
-
.filter((presence) => {
|
|
25
|
-
if (!presence.path || !path.length) {
|
|
26
|
-
return false
|
|
27
|
-
}
|
|
28
|
-
const statusPath = stringToPath(presence.path)
|
|
29
|
-
|
|
30
|
-
if (!showFocusWithin && statusPath.length !== path.length) {
|
|
31
|
-
return false
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return path.every((pathSegment, i) => {
|
|
35
|
-
const statusSegment = statusPath[i]
|
|
36
|
-
if (typeof pathSegment === 'string') {
|
|
37
|
-
return pathSegment === statusSegment
|
|
38
|
-
}
|
|
39
|
-
if (isKeySegment(pathSegment) && isKeySegment(statusSegment)) {
|
|
40
|
-
return pathSegment._key === statusSegment._key
|
|
41
|
-
}
|
|
42
|
-
return false
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
if (!activePresence?.length) {
|
|
46
|
-
return NO_PRESENCE
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return activePresence.map((status) => aiPresence(status, path))
|
|
50
|
-
}, [showFocusWithin, tasks, path])
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
-
export function aiPresence(presence: AiPresence, path: Path, title?: string): FormNodePresence {
|
|
55
|
-
return {
|
|
56
|
-
user: {
|
|
57
|
-
id: `sanity-assistant_${presence._key}`,
|
|
58
|
-
displayName: pluginTitle,
|
|
59
|
-
},
|
|
60
|
-
path: path,
|
|
61
|
-
sessionId: 'not-available',
|
|
62
|
-
lastActiveAt: presence?.started ?? new Date().toISOString(),
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ArrowRightIcon,
|
|
3
|
-
CodeIcon,
|
|
4
|
-
ComposeIcon,
|
|
5
|
-
icons,
|
|
6
|
-
IconSymbol,
|
|
7
|
-
LockIcon,
|
|
8
|
-
SparklesIcon,
|
|
9
|
-
ThListIcon,
|
|
10
|
-
} from '@sanity/icons'
|
|
11
|
-
import {Box, Flex, Stack, Text, Tooltip} from '@sanity/ui'
|
|
12
|
-
import {createElement} from 'react'
|
|
13
|
-
import {defineArrayMember, defineField, defineType, ObjectSchemaType} from 'sanity'
|
|
14
|
-
|
|
15
|
-
import {AssistDocumentForm} from '../assistDocument/components/AssistDocumentForm'
|
|
16
|
-
import {FieldRefPreview} from '../assistDocument/components/FieldRefPreview'
|
|
17
|
-
import {HiddenFieldTitle} from '../assistDocument/components/generic/HiddenFieldTitle'
|
|
18
|
-
import {IconInput} from '../assistDocument/components/instruction/appearance/IconInput'
|
|
19
|
-
import {InstructionVisibility} from '../assistDocument/components/instruction/appearance/InstructionVisibility'
|
|
20
|
-
import {FieldRefPathInput} from '../assistDocument/components/instruction/FieldRefInput'
|
|
21
|
-
import {InstructionInput} from '../assistDocument/components/instruction/InstructionInput'
|
|
22
|
-
import {InstructionOutputField} from '../assistDocument/components/instruction/InstructionOutputField'
|
|
23
|
-
import {InstructionOutputInput} from '../assistDocument/components/instruction/InstructionOutputInput'
|
|
24
|
-
import {PromptInput} from '../assistDocument/components/instruction/PromptInput'
|
|
25
|
-
import {InstructionsArrayField} from '../assistDocument/components/InstructionsArrayField'
|
|
26
|
-
import {InstructionsArrayInput} from '../assistDocument/components/InstructionsArrayInput'
|
|
27
|
-
import {instructionGuideUrl} from '../constants'
|
|
28
|
-
import {getInstructionTitle} from '../helpers/misc'
|
|
29
|
-
import {
|
|
30
|
-
assistDocumentIdPrefix,
|
|
31
|
-
assistDocumentTypeName,
|
|
32
|
-
assistFieldTypeName,
|
|
33
|
-
assistTasksStatusTypeName,
|
|
34
|
-
fieldReferenceTypeName,
|
|
35
|
-
instructionContextTypeName,
|
|
36
|
-
instructionTaskTypeName,
|
|
37
|
-
instructionTypeName,
|
|
38
|
-
outputFieldTypeName,
|
|
39
|
-
outputTypeTypeName,
|
|
40
|
-
promptTypeName,
|
|
41
|
-
userInputTypeName,
|
|
42
|
-
} from '../types'
|
|
43
|
-
import {contextDocumentSchema} from './contextDocumentSchema'
|
|
44
|
-
|
|
45
|
-
import {createFieldRefCache} from '../assistLayout/fieldRefCache'
|
|
46
|
-
|
|
47
|
-
export const fieldReference = defineType({
|
|
48
|
-
type: 'object',
|
|
49
|
-
name: fieldReferenceTypeName,
|
|
50
|
-
title: 'Field',
|
|
51
|
-
icon: ThListIcon,
|
|
52
|
-
|
|
53
|
-
fields: [
|
|
54
|
-
defineField({
|
|
55
|
-
type: 'string',
|
|
56
|
-
name: 'path',
|
|
57
|
-
title: 'Field',
|
|
58
|
-
components: {
|
|
59
|
-
input: FieldRefPathInput,
|
|
60
|
-
},
|
|
61
|
-
validation: (rule) => {
|
|
62
|
-
const getForSchemaType = createFieldRefCache()
|
|
63
|
-
return rule.custom((value, context) => {
|
|
64
|
-
if (!value) {
|
|
65
|
-
return 'Please select a field'
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const docId = context.document?._id
|
|
69
|
-
if (!docId) {
|
|
70
|
-
return `Field reference cannot be used outside document inspector context. Could not resolve document id.`
|
|
71
|
-
}
|
|
72
|
-
const targetDocType = docId.replace(new RegExp(`^${assistDocumentIdPrefix}`), '')
|
|
73
|
-
const schema = context.schema.get(targetDocType)
|
|
74
|
-
if (!schema) {
|
|
75
|
-
return `Field reference cannot be used outside document inspector context. Could not resolve schema: ${targetDocType}`
|
|
76
|
-
}
|
|
77
|
-
const {fieldRefs} = getForSchemaType(schema as ObjectSchemaType)
|
|
78
|
-
const fieldRef = fieldRefs.find((r) => r.key === value)
|
|
79
|
-
if (!fieldRef) {
|
|
80
|
-
return `Field with path "${value}" does not exist in the schema.`
|
|
81
|
-
}
|
|
82
|
-
return true
|
|
83
|
-
} catch (e) {
|
|
84
|
-
console.error('Failed to resolve field reference', e)
|
|
85
|
-
return 'Invalid field reference.'
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
},
|
|
89
|
-
}),
|
|
90
|
-
],
|
|
91
|
-
preview: {
|
|
92
|
-
select: {
|
|
93
|
-
path: 'path',
|
|
94
|
-
},
|
|
95
|
-
prepare({path}) {
|
|
96
|
-
return {
|
|
97
|
-
title: path,
|
|
98
|
-
path,
|
|
99
|
-
icon: CodeIcon,
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
components: {
|
|
104
|
-
preview: FieldRefPreview,
|
|
105
|
-
},
|
|
106
|
-
options: {
|
|
107
|
-
modal: {
|
|
108
|
-
type: 'popover',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
export const userInput = defineType({
|
|
114
|
-
type: 'object',
|
|
115
|
-
name: userInputTypeName,
|
|
116
|
-
title: 'User input',
|
|
117
|
-
icon: ComposeIcon,
|
|
118
|
-
fields: [
|
|
119
|
-
defineField({
|
|
120
|
-
type: 'string',
|
|
121
|
-
name: 'message',
|
|
122
|
-
title: 'User input title',
|
|
123
|
-
placeholder: 'Provide instruction text',
|
|
124
|
-
description: 'The header above the user input text field',
|
|
125
|
-
validation: (rule) => rule.required(),
|
|
126
|
-
}),
|
|
127
|
-
defineField({
|
|
128
|
-
type: 'text',
|
|
129
|
-
rows: 3,
|
|
130
|
-
name: 'description',
|
|
131
|
-
title: 'User input description',
|
|
132
|
-
description: 'The description above the user input text field',
|
|
133
|
-
}),
|
|
134
|
-
],
|
|
135
|
-
preview: {
|
|
136
|
-
select: {
|
|
137
|
-
title: 'message',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
options: {
|
|
141
|
-
modal: {
|
|
142
|
-
type: 'popover',
|
|
143
|
-
width: 1,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
export const promptContext = defineType({
|
|
149
|
-
type: 'object',
|
|
150
|
-
name: instructionContextTypeName,
|
|
151
|
-
title: contextDocumentSchema.title,
|
|
152
|
-
icon: contextDocumentSchema.icon,
|
|
153
|
-
fields: [
|
|
154
|
-
defineField({
|
|
155
|
-
type: 'reference',
|
|
156
|
-
name: 'reference',
|
|
157
|
-
to: [{type: contextDocumentSchema.name}],
|
|
158
|
-
title: 'Context',
|
|
159
|
-
description: 'The referenced context will be inserted into the instruction',
|
|
160
|
-
validation: (rule) => rule.required(),
|
|
161
|
-
components: {
|
|
162
|
-
input: function Fix(props) {
|
|
163
|
-
return <Box style={{maxWidth: 300}}>{props.renderDefault(props)}</Box>
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
}),
|
|
167
|
-
],
|
|
168
|
-
preview: {
|
|
169
|
-
select: {
|
|
170
|
-
ref: 'reference._id',
|
|
171
|
-
title: 'reference.title',
|
|
172
|
-
context: 'reference.context',
|
|
173
|
-
},
|
|
174
|
-
prepare(select) {
|
|
175
|
-
return select.ref
|
|
176
|
-
? (contextDocumentSchema?.preview?.prepare?.(select) ?? select)
|
|
177
|
-
: {title: 'No reference selected', media: contextDocumentSchema.icon}
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
options: {
|
|
181
|
-
modal: {
|
|
182
|
-
type: 'popover',
|
|
183
|
-
width: 'auto',
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
export const prompt = defineType({
|
|
189
|
-
type: 'array',
|
|
190
|
-
name: promptTypeName,
|
|
191
|
-
title: 'Prompt',
|
|
192
|
-
of: [
|
|
193
|
-
defineArrayMember({
|
|
194
|
-
type: 'block',
|
|
195
|
-
styles: [{title: 'Normal', value: 'normal'}],
|
|
196
|
-
lists: [],
|
|
197
|
-
marks: {
|
|
198
|
-
decorators: [],
|
|
199
|
-
annotations: [],
|
|
200
|
-
},
|
|
201
|
-
of: [
|
|
202
|
-
defineArrayMember({
|
|
203
|
-
type: fieldReference.name,
|
|
204
|
-
}),
|
|
205
|
-
defineArrayMember({
|
|
206
|
-
type: promptContext.name,
|
|
207
|
-
}),
|
|
208
|
-
defineArrayMember({
|
|
209
|
-
type: userInput.name,
|
|
210
|
-
}),
|
|
211
|
-
],
|
|
212
|
-
}),
|
|
213
|
-
/* defineArrayMember({
|
|
214
|
-
type: fieldReference.name,
|
|
215
|
-
}),
|
|
216
|
-
defineArrayMember({
|
|
217
|
-
type: promptContext.name,
|
|
218
|
-
}),
|
|
219
|
-
defineArrayMember({
|
|
220
|
-
type: userInput.name,
|
|
221
|
-
}),*/
|
|
222
|
-
],
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
export const outputFieldType = defineType({
|
|
226
|
-
type: 'object',
|
|
227
|
-
name: outputFieldTypeName,
|
|
228
|
-
title: 'Output field',
|
|
229
|
-
fields: [
|
|
230
|
-
defineField({
|
|
231
|
-
type: 'string',
|
|
232
|
-
name: 'path',
|
|
233
|
-
title: 'Path',
|
|
234
|
-
}),
|
|
235
|
-
],
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
export const outputTypeType = defineType({
|
|
239
|
-
type: 'object',
|
|
240
|
-
name: outputTypeTypeName,
|
|
241
|
-
title: 'Output type',
|
|
242
|
-
fields: [
|
|
243
|
-
defineField({
|
|
244
|
-
type: 'string',
|
|
245
|
-
name: 'type',
|
|
246
|
-
title: 'Type',
|
|
247
|
-
}),
|
|
248
|
-
],
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
export const instruction = defineType({
|
|
252
|
-
type: 'object',
|
|
253
|
-
name: instructionTypeName,
|
|
254
|
-
title: 'Instruction',
|
|
255
|
-
fieldsets: [
|
|
256
|
-
{name: 'appearance', title: 'Appearance', options: {collapsible: true, collapsed: true}},
|
|
257
|
-
],
|
|
258
|
-
preview: {
|
|
259
|
-
select: {
|
|
260
|
-
icon: 'icon',
|
|
261
|
-
title: 'title',
|
|
262
|
-
userId: 'userId',
|
|
263
|
-
},
|
|
264
|
-
prepare: ({icon, title, userId}) => {
|
|
265
|
-
return {
|
|
266
|
-
title,
|
|
267
|
-
icon: icon ? icons[icon as IconSymbol] : SparklesIcon,
|
|
268
|
-
userId,
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
components: {
|
|
273
|
-
input: InstructionInput,
|
|
274
|
-
preview: (props: any) => {
|
|
275
|
-
return (
|
|
276
|
-
<Flex gap={3} align="center" padding={2}>
|
|
277
|
-
{props.icon && (
|
|
278
|
-
<Box flex="none">
|
|
279
|
-
<Text size={1}>{createElement(props.icon)}</Text>
|
|
280
|
-
</Box>
|
|
281
|
-
)}
|
|
282
|
-
|
|
283
|
-
<Stack flex={1} space={2}>
|
|
284
|
-
<Text size={1} textOverflow="ellipsis" weight="medium">
|
|
285
|
-
{getInstructionTitle(props)}
|
|
286
|
-
</Text>
|
|
287
|
-
</Stack>
|
|
288
|
-
|
|
289
|
-
{props.userId && (
|
|
290
|
-
<Text size={1}>
|
|
291
|
-
<Tooltip
|
|
292
|
-
content={<Text size={1}>Only visible to you</Text>}
|
|
293
|
-
padding={2}
|
|
294
|
-
placement="top"
|
|
295
|
-
portal
|
|
296
|
-
>
|
|
297
|
-
<LockIcon />
|
|
298
|
-
</Tooltip>
|
|
299
|
-
</Text>
|
|
300
|
-
)}
|
|
301
|
-
</Flex>
|
|
302
|
-
)
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
fields: [
|
|
306
|
-
defineField({
|
|
307
|
-
type: prompt.name,
|
|
308
|
-
name: 'prompt',
|
|
309
|
-
title: 'Instruction',
|
|
310
|
-
description: (
|
|
311
|
-
<>
|
|
312
|
-
Learn from{' '}
|
|
313
|
-
<a href={instructionGuideUrl} target="_blank" rel="noreferrer">
|
|
314
|
-
our instruction guide <ArrowRightIcon />
|
|
315
|
-
</a>
|
|
316
|
-
</>
|
|
317
|
-
),
|
|
318
|
-
components: {
|
|
319
|
-
input: PromptInput,
|
|
320
|
-
},
|
|
321
|
-
}),
|
|
322
|
-
defineField({
|
|
323
|
-
type: 'string',
|
|
324
|
-
name: 'icon',
|
|
325
|
-
title: 'Icon',
|
|
326
|
-
fieldset: 'appearance',
|
|
327
|
-
components: {
|
|
328
|
-
field: HiddenFieldTitle,
|
|
329
|
-
input: IconInput,
|
|
330
|
-
},
|
|
331
|
-
}),
|
|
332
|
-
defineField({
|
|
333
|
-
type: 'string',
|
|
334
|
-
name: 'title',
|
|
335
|
-
title: 'Title',
|
|
336
|
-
fieldset: 'appearance',
|
|
337
|
-
components: {
|
|
338
|
-
field: HiddenFieldTitle,
|
|
339
|
-
},
|
|
340
|
-
}),
|
|
341
|
-
defineField({
|
|
342
|
-
type: 'string',
|
|
343
|
-
name: 'userId',
|
|
344
|
-
title: 'Visibility',
|
|
345
|
-
fieldset: 'appearance',
|
|
346
|
-
components: {
|
|
347
|
-
field: HiddenFieldTitle,
|
|
348
|
-
input: InstructionVisibility,
|
|
349
|
-
},
|
|
350
|
-
initialValue: (params, context) => context.currentUser?.id ?? '',
|
|
351
|
-
readOnly: (context) =>
|
|
352
|
-
Boolean(
|
|
353
|
-
context.parent?.createdById && context.parent?.createdById !== context.currentUser?.id,
|
|
354
|
-
),
|
|
355
|
-
}),
|
|
356
|
-
defineField({
|
|
357
|
-
type: 'string',
|
|
358
|
-
name: 'createdById',
|
|
359
|
-
title: 'Created by',
|
|
360
|
-
hidden: true,
|
|
361
|
-
fieldset: 'appearance',
|
|
362
|
-
initialValue: (params, context) => {
|
|
363
|
-
return context.currentUser?.id ?? ''
|
|
364
|
-
},
|
|
365
|
-
}),
|
|
366
|
-
defineField({
|
|
367
|
-
type: 'array',
|
|
368
|
-
name: 'output',
|
|
369
|
-
title: 'Output filter',
|
|
370
|
-
components: {
|
|
371
|
-
input: InstructionOutputInput,
|
|
372
|
-
field: InstructionOutputField,
|
|
373
|
-
},
|
|
374
|
-
of: [
|
|
375
|
-
defineArrayMember({type: outputFieldType.name}),
|
|
376
|
-
defineArrayMember({type: outputTypeType.name}),
|
|
377
|
-
],
|
|
378
|
-
}),
|
|
379
|
-
],
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
export const fieldInstructions = defineType({
|
|
383
|
-
type: 'object',
|
|
384
|
-
name: assistFieldTypeName,
|
|
385
|
-
title: 'Field prompt',
|
|
386
|
-
/* components: {
|
|
387
|
-
input: FieldPromptInput,
|
|
388
|
-
},*/
|
|
389
|
-
fields: [
|
|
390
|
-
defineField({
|
|
391
|
-
type: 'string',
|
|
392
|
-
name: 'path',
|
|
393
|
-
title: 'Path',
|
|
394
|
-
readOnly: true,
|
|
395
|
-
hidden: true,
|
|
396
|
-
}),
|
|
397
|
-
defineField({
|
|
398
|
-
type: 'array',
|
|
399
|
-
name: 'instructions',
|
|
400
|
-
title: 'Instructions',
|
|
401
|
-
of: [{type: instruction.name}],
|
|
402
|
-
components: {
|
|
403
|
-
field: InstructionsArrayField,
|
|
404
|
-
input: InstructionsArrayInput,
|
|
405
|
-
},
|
|
406
|
-
}),
|
|
407
|
-
],
|
|
408
|
-
preview: {
|
|
409
|
-
select: {
|
|
410
|
-
title: 'path',
|
|
411
|
-
},
|
|
412
|
-
},
|
|
413
|
-
})
|
|
414
|
-
|
|
415
|
-
export const assistDocumentSchema = defineType({
|
|
416
|
-
//NOTE: this is a document type. Using object here ensures it does not appear in structure menus
|
|
417
|
-
type: 'object',
|
|
418
|
-
//workaround for using object and not document
|
|
419
|
-
...({liveEdit: true} as any),
|
|
420
|
-
name: assistDocumentTypeName,
|
|
421
|
-
title: 'AI Document',
|
|
422
|
-
|
|
423
|
-
components: {
|
|
424
|
-
input: AssistDocumentForm,
|
|
425
|
-
field: (props: any) => {
|
|
426
|
-
return props.renderDefault({...props, title: ''})
|
|
427
|
-
},
|
|
428
|
-
},
|
|
429
|
-
fields: [
|
|
430
|
-
defineField({
|
|
431
|
-
type: 'string',
|
|
432
|
-
name: 'title',
|
|
433
|
-
title: 'Title',
|
|
434
|
-
}),
|
|
435
|
-
defineField({
|
|
436
|
-
type: 'array',
|
|
437
|
-
name: 'fields',
|
|
438
|
-
title: 'Fields',
|
|
439
|
-
of: [{type: fieldInstructions.name}],
|
|
440
|
-
}),
|
|
441
|
-
],
|
|
442
|
-
preview: {
|
|
443
|
-
select: {
|
|
444
|
-
title: 'title',
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
export const instructionTask = defineType({
|
|
450
|
-
type: 'object',
|
|
451
|
-
name: instructionTaskTypeName,
|
|
452
|
-
title: 'Instruction task',
|
|
453
|
-
fields: [
|
|
454
|
-
defineField({
|
|
455
|
-
type: 'string',
|
|
456
|
-
name: 'path',
|
|
457
|
-
title: 'Path',
|
|
458
|
-
}),
|
|
459
|
-
defineField({
|
|
460
|
-
type: 'string',
|
|
461
|
-
name: 'instructionKey',
|
|
462
|
-
title: 'Instruction key',
|
|
463
|
-
}),
|
|
464
|
-
defineField({
|
|
465
|
-
type: 'datetime',
|
|
466
|
-
name: 'started',
|
|
467
|
-
title: 'Started',
|
|
468
|
-
}),
|
|
469
|
-
defineField({
|
|
470
|
-
type: 'datetime',
|
|
471
|
-
name: 'updated',
|
|
472
|
-
title: 'Updated',
|
|
473
|
-
}),
|
|
474
|
-
defineField({
|
|
475
|
-
type: 'string',
|
|
476
|
-
name: 'info',
|
|
477
|
-
title: 'Info',
|
|
478
|
-
}),
|
|
479
|
-
],
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
export const documentInstructionStatus = defineType({
|
|
483
|
-
//NOTE: this is a document type. Using object here ensures it does not appear in structure menus
|
|
484
|
-
type: 'object',
|
|
485
|
-
//workaround for using object and not document
|
|
486
|
-
...({liveEdit: true} as any),
|
|
487
|
-
name: assistTasksStatusTypeName,
|
|
488
|
-
title: 'Document instruction status',
|
|
489
|
-
fields: [
|
|
490
|
-
defineField({
|
|
491
|
-
type: 'array',
|
|
492
|
-
name: 'tasks',
|
|
493
|
-
title: 'Tasks',
|
|
494
|
-
of: [{type: instructionTask.name}],
|
|
495
|
-
}),
|
|
496
|
-
],
|
|
497
|
-
})
|