@sanity/assist 1.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 +21 -0
- package/README.md +205 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.esm.js +2341 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2341 -0
- package/dist/index.js.map +1 -0
- package/package.json +98 -0
- package/sanity.json +8 -0
- package/src/_lib/connector/ConnectFromRegion.tsx +24 -0
- package/src/_lib/connector/ConnectToRegion.tsx +22 -0
- package/src/_lib/connector/ConnectorRegion.tsx +23 -0
- package/src/_lib/connector/ConnectorsProvider.tsx +19 -0
- package/src/_lib/connector/ConnectorsStore.ts +122 -0
- package/src/_lib/connector/ConnectorsStoreContext.ts +4 -0
- package/src/_lib/connector/helpers.ts +5 -0
- package/src/_lib/connector/index.ts +9 -0
- package/src/_lib/connector/mapConnectorToLine.ts +83 -0
- package/src/_lib/connector/types.ts +56 -0
- package/src/_lib/connector/useConnectorsStore.ts +13 -0
- package/src/_lib/connector/useRegionRects.ts +141 -0
- package/src/_lib/fixedListenQuery.ts +101 -0
- package/src/_lib/form/DocumentForm.tsx +197 -0
- package/src/_lib/form/helpers.ts +31 -0
- package/src/_lib/form/index.ts +1 -0
- package/src/_lib/randomKey.ts +29 -0
- package/src/_lib/useListeningQuery.ts +61 -0
- package/src/_lib/usePrevious.ts +9 -0
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +132 -0
- package/src/assistConnectors/ConnectorPath.tsx +62 -0
- package/src/assistConnectors/draw/arrowPath.ts +9 -0
- package/src/assistConnectors/draw/connectorPath.ts +142 -0
- package/src/assistConnectors/index.ts +1 -0
- package/src/assistDocument/AssistDocumentContext.tsx +31 -0
- package/src/assistDocument/AssistDocumentContextProvider.tsx +17 -0
- package/src/assistDocument/AssistDocumentInput.tsx +46 -0
- package/src/assistDocument/RequestRunInstructionProvider.tsx +50 -0
- package/src/assistDocument/components/AssistDocumentForm.tsx +188 -0
- package/src/assistDocument/components/FieldRefPreview.tsx +27 -0
- package/src/assistDocument/components/InstructionsArrayField.tsx +8 -0
- package/src/assistDocument/components/InstructionsArrayInput.tsx +26 -0
- package/src/assistDocument/components/SelectedFieldContext.tsx +10 -0
- package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +5 -0
- package/src/assistDocument/components/helpers.ts +21 -0
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +31 -0
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +33 -0
- package/src/assistDocument/components/instruction/InstructionInput.tsx +87 -0
- package/src/assistDocument/components/instruction/PromptInput.tsx +52 -0
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +46 -0
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +37 -0
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +68 -0
- package/src/assistDocument/hooks/useDocumentState.ts +6 -0
- package/src/assistDocument/hooks/useInstructionToaster.tsx +74 -0
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +119 -0
- package/src/assistDocument/index.ts +1 -0
- package/src/assistFormComponents/AssistField.tsx +51 -0
- package/src/assistFormComponents/AssistFormBlock.tsx +31 -0
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +14 -0
- package/src/assistFormComponents/AssistItem.tsx +20 -0
- package/src/assistFormComponents/validation/listItem.tsx +63 -0
- package/src/assistFormComponents/validation/validationList.tsx +89 -0
- package/src/assistInspector/AssistInspector.tsx +379 -0
- package/src/assistInspector/FieldAutocomplete.tsx +119 -0
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +261 -0
- package/src/assistInspector/constants.ts +1 -0
- package/src/assistInspector/helpers.ts +125 -0
- package/src/assistInspector/index.ts +26 -0
- package/src/assistLayout/AiAssistanceConfigContext.tsx +81 -0
- package/src/assistLayout/AlphaMigration.tsx +311 -0
- package/src/assistLayout/AssistLayout.tsx +38 -0
- package/src/assistLayout/RunInstructionProvider.tsx +222 -0
- package/src/components/AssistFeatureBadge.tsx +9 -0
- package/src/components/Delay.tsx +25 -0
- package/src/components/HideReferenceChangedBannerInput.tsx +25 -0
- package/src/components/SafeValueInput.tsx +73 -0
- package/src/components/TimeAgo.tsx +18 -0
- package/src/constants.ts +20 -0
- package/src/fieldActions/PrivateIcon.tsx +20 -0
- package/src/fieldActions/assistFieldActions.tsx +230 -0
- package/src/globals.d.ts +4 -0
- package/src/helpers/assistSupported.ts +44 -0
- package/src/helpers/ids.ts +19 -0
- package/src/helpers/misc.ts +16 -0
- package/src/helpers/typeUtils.ts +15 -0
- package/src/helpers/useAssistSupported.ts +10 -0
- package/src/index.ts +6 -0
- package/src/legacy-types.ts +72 -0
- package/src/onboarding/FieldActionsOnboarding.tsx +90 -0
- package/src/onboarding/FirstAssistedPathProvider.tsx +29 -0
- package/src/onboarding/InspectorOnboarding.tsx +46 -0
- package/src/onboarding/onboardingStore.ts +33 -0
- package/src/plugin.tsx +80 -0
- package/src/presence/AiFieldPresence.tsx +28 -0
- package/src/presence/AssistAvatar.tsx +96 -0
- package/src/presence/AssistDocumentPresence.tsx +58 -0
- package/src/presence/useAssistPresence.ts +61 -0
- package/src/schemas/assistDocumentSchema.tsx +450 -0
- package/src/schemas/contextDocumentSchema.tsx +56 -0
- package/src/schemas/index.ts +25 -0
- package/src/schemas/serialize/SchemTypeTool.tsx +102 -0
- package/src/schemas/serialize/schemaUtils.ts +37 -0
- package/src/schemas/serialize/serializeSchema.test.ts +382 -0
- package/src/schemas/serialize/serializeSchema.ts +162 -0
- package/src/schemas/serializedSchemaTypeSchema.ts +59 -0
- package/src/schemas/typeDefExtensions.ts +30 -0
- package/src/types.ts +167 -0
- package/src/useApiClient.ts +140 -0
- package/src/vite.config.ts +9 -0
- package/v2-incompatible.js +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Sanity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# @sanity/assist
|
|
2
|
+
|
|
3
|
+
> This is a **Sanity Studio v3** plugin.
|
|
4
|
+
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
- [Table of contents](#table-of-contents)
|
|
8
|
+
- [About Sanity AI Assist](#about-sanity-ai-assist)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Setup](#setup)
|
|
11
|
+
- [Add the plugin](#add-the-plugin)
|
|
12
|
+
- [Enabling the AI Assist API](#enabling-the-ai-assist-api)
|
|
13
|
+
- [Schema configuration](#schema-configuration)
|
|
14
|
+
- [Disable AI Assist for a schema type](#disable-ai-assist-for-a-schema-type)
|
|
15
|
+
- [Disable for a field](#disable-for-a-field)
|
|
16
|
+
- [Disable for an array type](#disable-for-an-array-type)
|
|
17
|
+
- [Unsupported types](#unsupported-types)
|
|
18
|
+
- [Troubleshooting](#troubleshooting)
|
|
19
|
+
- [Included document types](#included-document-types)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
- [Develop \& test](#develop--test)
|
|
22
|
+
- [Release new version](#release-new-version)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## About Sanity AI Assist
|
|
26
|
+
|
|
27
|
+
Free your team to do more of what they’re great at (and less busy work) with the AI assistant that works with structured content. Attach reusable AI instructions to fields and documents to supercharge your editorial workflow.
|
|
28
|
+
|
|
29
|
+
You create the instructions; Sanity AI Assist does the rest. [Learn more about writing instructions in the Sanity documentation](https://www.sanity.io/guides/getting-started-with-ai-assist-instructions?utm_source=github.com&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=).
|
|
30
|
+
|
|
31
|
+
<img width="1019" alt="Screenshot showing Sanity AI Assist instructions for a title field in the Sanity Studio document editor" src="https://github.com/sanity-io/sanity/assets/835514/4d895477-c6d7-4da0-be25-c73e109edbdb">
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
In your Studio project folder, install the following plugin dependency:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install @sanity/assist
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Setup
|
|
42
|
+
|
|
43
|
+
> **Note:** Before using the plugin, your project must have Sanity AI Assist enabled at the API level.
|
|
44
|
+
>
|
|
45
|
+
> Contact your Sanity enterprise representative to get started, or [contact the sales team](https://www.sanity.io/contact/sales?utm_source=github.com&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=).
|
|
46
|
+
|
|
47
|
+
### Add the plugin
|
|
48
|
+
|
|
49
|
+
In `sanity.config.ts`, add `assist` to the `plugins` array:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { assist } from '@sanity/assist'
|
|
53
|
+
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
/* other config */
|
|
56
|
+
plugins: [
|
|
57
|
+
/* other plugins */
|
|
58
|
+
assist()
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Enabling the AI Assist API
|
|
64
|
+
|
|
65
|
+
After installing and adding the plugin and having the AI Assist feature enabled for your project and its datasets, you need to create a token for the plugin to access the AI Assist API. This needs to be done by a member of the project with token creation permissions (typically someone with an admin or developer role).
|
|
66
|
+
|
|
67
|
+
* Start the studio and open any document
|
|
68
|
+
* Click *the sparkle icon** (✨) in the document header near the close document X-button
|
|
69
|
+
* Then select **Manage instructions**
|
|
70
|
+
|
|
71
|
+
<img width="210" alt="The AI Assist document menu showing 'Manage instructions' highlighted" src="https://github.com/sanity-io/sanity/assets/835514/58c177ca-4530-4f44-abe0-4adcd9e11c8b">
|
|
72
|
+
|
|
73
|
+
* Selecting **Manage instructions** will open an inspector panel
|
|
74
|
+
* Click the **Enable AI assistance** button to create a token and enable AI Assist for everyone with access to the project
|
|
75
|
+
|
|
76
|
+
<img width="339" alt="The 'Enable Sanity AI Assist' button" src="https://github.com/sanity-io/sanity/assets/835514/38b81861-6a7c-49a2-a7c5-f46816d0c0a8">
|
|
77
|
+
|
|
78
|
+
You will find a new API token entry for your project named “Sanity AI” in your project's API settings on [sanity.io/manage](https://sanity.io/manage).
|
|
79
|
+
|
|
80
|
+
<img alt="The Sanity AI Assist API token entry on sanity.io/manage" src="https://github.com/sanity-io/sanity/assets/835514/3b2f549b-926c-4d85-b5fa-dd7f8f58e667" />
|
|
81
|
+
|
|
82
|
+
The plugin will now work for any dataset in your project.
|
|
83
|
+
|
|
84
|
+
**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.
|
|
85
|
+
|
|
86
|
+
## Schema configuration
|
|
87
|
+
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
The assistant can also create array items, including Portable Text blocks, when the type has been imported to the Studio's schema as a custom type ([learn more about strict schemas](https://www.sanity.io/docs/graphql#33ec7103289a)).
|
|
91
|
+
|
|
92
|
+
### Disable AI Assist for a schema type
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
// this will disable AI assistance wherever it is used,
|
|
96
|
+
// ie: as field, document, array types
|
|
97
|
+
defineType({
|
|
98
|
+
name: 'policy',
|
|
99
|
+
type: 'document',
|
|
100
|
+
options: {
|
|
101
|
+
aiWritingAssistance: {exclude: true}
|
|
102
|
+
},
|
|
103
|
+
fields: [
|
|
104
|
+
// ...
|
|
105
|
+
]
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Disable for a field
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
// this disables AI assistance only for the specific field
|
|
113
|
+
defineType({
|
|
114
|
+
name: 'product',
|
|
115
|
+
type: 'object',
|
|
116
|
+
fields: [
|
|
117
|
+
defineField({
|
|
118
|
+
name: 'sku',
|
|
119
|
+
type: 'string',
|
|
120
|
+
options: {
|
|
121
|
+
aiWritingAssistance: {exclude: true}
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Disable for an array type
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
// this disables AI assistance for the specific array member
|
|
132
|
+
// if all types in the `of` array are excluded, the array type is also considered excluded
|
|
133
|
+
defineType({
|
|
134
|
+
name: 'product',
|
|
135
|
+
type: 'array',
|
|
136
|
+
of: [
|
|
137
|
+
defineArrayMember({
|
|
138
|
+
type: 'customProduct',
|
|
139
|
+
options: {
|
|
140
|
+
aiWritingAssistance: {exclude: true}
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Unsupported types
|
|
148
|
+
|
|
149
|
+
The following types are not supported, and behave as excluded types:
|
|
150
|
+
* [Number](https://www.sanity.io/docs/number-type)
|
|
151
|
+
* [Reference](https://www.sanity.io/docs/reference-type)
|
|
152
|
+
* [Slug](https://www.sanity.io/docs/slug-type)
|
|
153
|
+
* [Url](https://www.sanity.io/docs/url-type)
|
|
154
|
+
* [Date](https://www.sanity.io/docs/date-type)
|
|
155
|
+
* [Datetime](https://www.sanity.io/docs/datetime-type)
|
|
156
|
+
* [Image](https://www.sanity.io/docs/image-type) (supported when image has custom fields)
|
|
157
|
+
* [File](https://www.sanity.io/docs/file-type) (never supported, even when file has custom fields)
|
|
158
|
+
|
|
159
|
+
Fields with these types will not be changed by the assistant, do not have AI Assist actions, and cannot be referenced in instructions.
|
|
160
|
+
|
|
161
|
+
Objects where all fields are excluded or unsupported and arrays where all member types are excluded or unsupported
|
|
162
|
+
will also be excluded.
|
|
163
|
+
|
|
164
|
+
### Troubleshooting
|
|
165
|
+
|
|
166
|
+
There are limits to how much text the AI can process when processing an instruction. Under the hood, the AI Assist will add information about your schema, which adds to what's commonly referred to as “the context window.”
|
|
167
|
+
|
|
168
|
+
If you have a very large schema (that is, many document and field types), it can be necessary to exclude types to limit how much of the context window is used for the schema itself.
|
|
169
|
+
|
|
170
|
+
We recommend excluding any and all types which rarely would benefit from automated workflows. A quick win is typically to exclude array types. It can be a good idea to exclude most non-block types from Portable Text arrays. This will ensure that the Sanity Assist outputs mostly formatted text.
|
|
171
|
+
|
|
172
|
+
## Included document types
|
|
173
|
+
|
|
174
|
+
This plugin adds an `AI Context` document type.
|
|
175
|
+
|
|
176
|
+
If your Studio uses [Structure Builder](https://www.sanity.io/docs/structure-builder-introduction) to configure the studio structure,
|
|
177
|
+
you might have to add this document type to your structure.
|
|
178
|
+
|
|
179
|
+
The document type name can be imported from the plugin:
|
|
180
|
+
```ts
|
|
181
|
+
import {contextDocumentTypeName} from '@sanity/assist'
|
|
182
|
+
|
|
183
|
+
// put into structure in structure
|
|
184
|
+
S.documentTypeListItem(contextDocumentTypeName)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
[MIT](LICENSE) © Sanity
|
|
190
|
+
|
|
191
|
+
## Develop & test
|
|
192
|
+
|
|
193
|
+
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
194
|
+
with default configuration for build & watch scripts.
|
|
195
|
+
|
|
196
|
+
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
|
|
197
|
+
on how to run this plugin with hotreload in the studio.
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
### Release new version
|
|
201
|
+
|
|
202
|
+
Run ["CI & Release" workflow](https://github.com/sanity-io/sanity/actions/workflows/main.yml).
|
|
203
|
+
Make sure to select the main branch and check "Release new version".
|
|
204
|
+
|
|
205
|
+
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {JSX as JSX_2} from 'react/jsx-runtime'
|
|
2
|
+
import {Plugin as Plugin_2} from 'sanity'
|
|
3
|
+
import {SanityClient} from '@sanity/client'
|
|
4
|
+
|
|
5
|
+
export declare const assist: Plugin_2<void | AssistPluginConfig>
|
|
6
|
+
|
|
7
|
+
export declare interface AssistOptions {
|
|
8
|
+
aiWritingAssistance?: {
|
|
9
|
+
/** Set to true to disable assistance for this field or type */
|
|
10
|
+
exclude?: boolean
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare interface AssistPluginConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Set this to false to disable model migration from the alpha version of this plugin
|
|
17
|
+
*/
|
|
18
|
+
alphaMigration?: boolean
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
__customApiClient?: (defaultClient: SanityClient) => SanityClient
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare const contextDocumentTypeName: 'assist.instruction.context'
|
|
26
|
+
|
|
27
|
+
export declare function SchemaTypeTool(): JSX_2.Element
|
|
28
|
+
|
|
29
|
+
export {}
|
|
30
|
+
|
|
31
|
+
declare module 'sanity' {
|
|
32
|
+
interface ArrayOptions extends AssistOptions {}
|
|
33
|
+
interface BlockOptions extends AssistOptions {}
|
|
34
|
+
interface BooleanOptions extends AssistOptions {}
|
|
35
|
+
interface CrossDatasetReferenceOptions extends AssistOptions {}
|
|
36
|
+
interface DateOptions extends AssistOptions {}
|
|
37
|
+
interface DatetimeOptions extends AssistOptions {}
|
|
38
|
+
interface DocumentOptions extends AssistOptions {}
|
|
39
|
+
interface FileOptions extends AssistOptions {}
|
|
40
|
+
interface GeopointOptions extends AssistOptions {}
|
|
41
|
+
interface ImageOptions extends AssistOptions {
|
|
42
|
+
imagePromptField?: string
|
|
43
|
+
}
|
|
44
|
+
interface NumberOptions extends AssistOptions {}
|
|
45
|
+
interface ObjectOptions extends AssistOptions {}
|
|
46
|
+
interface ReferenceBaseOptions extends AssistOptions {}
|
|
47
|
+
interface SlugOptions extends AssistOptions {}
|
|
48
|
+
interface StringOptions extends AssistOptions {}
|
|
49
|
+
interface TextOptions extends AssistOptions {}
|
|
50
|
+
interface UrlOptions extends AssistOptions {}
|
|
51
|
+
interface EmailOptions extends AssistOptions {}
|
|
52
|
+
}
|