@sanity/assist 5.0.0 → 5.0.2

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/dist/index.js CHANGED
@@ -1,17 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), ui = require("@sanity/ui"), react = require("react"), structure = require("sanity/structure"), dateFns = require("date-fns"), icons = require("@sanity/icons"), mutator = require("@sanity/mutator"), styledComponents = require("styled-components"), operators = require("rxjs/operators"), get = require("lodash/get.js"), isEqual = require("react-fast-compare"), rxjs = require("rxjs"), rxjsExhaustmapWithTrailing = require("rxjs-exhaustmap-with-trailing");
4
- function _interopDefaultCompat(e) {
5
- return e && typeof e == "object" && "default" in e ? e : { default: e };
6
- }
7
- var get__default = /* @__PURE__ */ _interopDefaultCompat(get), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual);
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { pathToString, getVersionFromId, getPublishedId, isVersionId, useEditState, useCurrentUser, useClient, typed, FormFieldHeaderText, PatchEvent, unset, isObjectSchemaType, stringToPath, isKeySegment, useSchema, getVersionId, getDraftId, useColorSchemeValue, isArraySchemaType, useFormCallbacks, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, StatusButton, PresenceOverlay, VirtualizerScrollInstanceProvider, isDocumentSchemaType, useSyncState, set, useWorkspaceSchemaId, MemberFieldError, FormCallbacksProvider, FormInput, setIfMissing, insert, ObjectInputMember, isArrayOfObjectsSchemaType, defineType, defineField, defineArrayMember, definePlugin } from "sanity";
3
+ import { useToast, useLayer, Dialog, Stack, Flex, Tooltip, Text, TextArea, Button, Card, Box, ErrorBoundary, focusFirstDescendant, Spinner, Container, Autocomplete, Breadcrumbs, useClickOutside, Popover, useGlobalKeyDown, useTheme, rgba, Radio, Checkbox, ThemeProvider, MenuButton, Menu, MenuItem, Switch, Label } from "@sanity/ui";
4
+ import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, useId, forwardRef, createElement, useReducer } from "react";
5
+ import { useDocumentPane, usePaneRouter, DocumentInspectorHeader, DocumentPaneProvider } from "sanity/structure";
6
+ import { minutesToMilliseconds, isAfter, addSeconds, formatDistanceToNow } from "date-fns";
7
+ import { PlayIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, SparklesIcon, SearchIcon, SyncIcon, ErrorOutlineIcon, CheckmarkCircleIcon, ClockIcon, CloseCircleIcon, RetryIcon, ArrowRightIcon, CloseIcon, icons, TranslateIcon, LockIcon, ControlsIcon, ArrowLeftIcon, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon } from "@sanity/icons";
8
+ import { extractWithPath } from "@sanity/mutator";
9
+ import { keyframes, styled } from "styled-components";
10
+ import { tap, mergeMap, share, take, filter, distinctUntilChanged, catchError } from "rxjs/operators";
11
+ import { get } from "lodash-es";
12
+ import isEqual from "react-fast-compare";
13
+ import { defer, throwError, of, partition, merge, switchMap, delay } from "rxjs";
14
+ import { exhaustMapToWithTrailing } from "rxjs-exhaustmap-with-trailing";
8
15
  function hasOverflowScroll(el) {
9
16
  const overflow = getComputedStyle(el).overflow;
10
17
  return overflow.includes("auto") || overflow.includes("hidden") || overflow.includes("scroll");
11
18
  }
12
19
  function useRegionRects() {
13
- const ref = react.useRef(null), [relativeBoundsRect, setRelativeBoundsRect] = react.useState(null), [relativeElementRect, setRelativeElementRect] = react.useState(null), [boundsScroll, setBoundsScroll] = react.useState({ x: 0, y: 0 }), [scroll, setScroll] = react.useState({ x: 0, y: 0 }), boundsScrollXRef = react.useRef(0), boundsScrollYRef = react.useRef(0), elementScrollXRef = react.useRef(0), elementScrollYRef = react.useRef(0);
14
- react.useEffect(() => {
20
+ const ref = useRef(null), [relativeBoundsRect, setRelativeBoundsRect] = useState(null), [relativeElementRect, setRelativeElementRect] = useState(null), [boundsScroll, setBoundsScroll] = useState({ x: 0, y: 0 }), [scroll, setScroll] = useState({ x: 0, y: 0 }), boundsScrollXRef = useRef(0), boundsScrollYRef = useRef(0), elementScrollXRef = useRef(0), elementScrollYRef = useRef(0);
21
+ useEffect(() => {
15
22
  const el = ref.current;
16
23
  if (!el) return;
17
24
  const scrollParents = [];
@@ -59,7 +66,7 @@ function useRegionRects() {
59
66
  ro.disconnect(), window.removeEventListener("scroll", handleScroll);
60
67
  };
61
68
  }, []);
62
- const bounds = react.useMemo(
69
+ const bounds = useMemo(
63
70
  () => relativeBoundsRect && {
64
71
  x: relativeBoundsRect.x - boundsScroll.x,
65
72
  y: relativeBoundsRect.y - boundsScroll.y,
@@ -67,7 +74,7 @@ function useRegionRects() {
67
74
  h: relativeBoundsRect.h
68
75
  },
69
76
  [relativeBoundsRect, boundsScroll]
70
- ), element = react.useMemo(
77
+ ), element = useMemo(
71
78
  () => relativeElementRect && {
72
79
  x: relativeElementRect.x - scroll.x,
73
80
  y: relativeElementRect.y - scroll.y,
@@ -80,22 +87,22 @@ function useRegionRects() {
80
87
  }
81
88
  function ConnectorRegion(props) {
82
89
  const { children, onRectsChange, ...restProps } = props, { bounds, element, ref } = useRegionRects();
83
- return react.useEffect(() => {
90
+ return useEffect(() => {
84
91
  onRectsChange?.(bounds && element ? { bounds, element } : null);
85
- }, [bounds, element, onRectsChange]), /* @__PURE__ */ jsxRuntime.jsx("div", { ...restProps, ref, children });
92
+ }, [bounds, element, onRectsChange]), /* @__PURE__ */ jsx("div", { ...restProps, ref, children });
86
93
  }
87
- const ConnectorsStoreContext = react.createContext(null);
94
+ const ConnectorsStoreContext = createContext(null);
88
95
  function useConnectorsStore() {
89
- const store = react.useContext(ConnectorsStoreContext);
96
+ const store = useContext(ConnectorsStoreContext);
90
97
  if (!store)
91
98
  throw new Error("Missing connectors store context");
92
99
  return store;
93
100
  }
94
101
  function ConnectFromRegion(props) {
95
- const { children, _key: key, zIndex, ...restProps } = props, store = useConnectorsStore(), [rects, setRects] = react.useState(null);
96
- return react.useEffect(() => store.from.subscribe(key, { zIndex }), [key, store, zIndex]), react.useEffect(() => {
102
+ const { children, _key: key, zIndex, ...restProps } = props, store = useConnectorsStore(), [rects, setRects] = useState(null);
103
+ return useEffect(() => store.from.subscribe(key, { zIndex }), [key, store, zIndex]), useEffect(() => {
97
104
  rects && store.from.next(key, rects);
98
- }, [key, rects, store]), /* @__PURE__ */ jsxRuntime.jsx(ConnectorRegion, { ...restProps, onRectsChange: setRects, children });
105
+ }, [key, rects, store]), /* @__PURE__ */ jsx(ConnectorRegion, { ...restProps, onRectsChange: setRects, children });
99
106
  }
100
107
  function createConnectorsStore() {
101
108
  const configKeys = [], fieldKeys = [], channels = {
@@ -154,11 +161,11 @@ function createConnectorsStore() {
154
161
  };
155
162
  }
156
163
  function ConnectorsProvider(props) {
157
- const { children, onConnectorsChange } = props, store = react.useMemo(() => createConnectorsStore(), []);
158
- return react.useEffect(
164
+ const { children, onConnectorsChange } = props, store = useMemo(() => createConnectorsStore(), []);
165
+ return useEffect(
159
166
  () => onConnectorsChange && store.connectors.subscribe(onConnectorsChange),
160
167
  [onConnectorsChange, store]
161
- ), /* @__PURE__ */ jsxRuntime.jsx(ConnectorsStoreContext.Provider, { value: store, children });
168
+ ), /* @__PURE__ */ jsx(ConnectorsStoreContext.Provider, { value: store, children });
162
169
  }
163
170
  function getConnectorLinePoint(options2, rect, bounds) {
164
171
  const centerY = rect.y + rect.h / 2, isAbove = rect.y + rect.h < bounds.y + options2.arrow.marginY, isBelow = rect.y > bounds.y + bounds.h - options2.arrow.marginY;
@@ -196,10 +203,10 @@ function mapConnectorToLine(options2, connector) {
196
203
  }
197
204
  const assistFormId = "assist", assistDocumentIdPrefix = "sanity.assist.schemaType.", assistDocumentStatusIdPrefix = "sanity.assist.status.", assistSchemaIdPrefix = "sanity.assist.schema.", assistDocumentTypeName = "sanity.assist.schemaType.annotations", assistFieldTypeName = "sanity.assist.schemaType.field", instructionTypeName = "sanity.assist.instruction", promptTypeName = "sanity.assist.instruction.prompt", userInputTypeName = "sanity.assist.instruction.userInput", instructionContextTypeName = "sanity.assist.instruction.context", fieldReferenceTypeName = "sanity.assist.instruction.fieldRef", contextDocumentTypeName = "assist.instruction.context", assistTasksStatusTypeName = "sanity.assist.task.status", instructionTaskTypeName = "sanity.assist.instructionTask", fieldPresenceTypeName = "sanity.assist.instructionTask.presence", assistSerializedTypeName = "sanity.assist.serialized.type", assistSerializedFieldTypeName = "sanity.assist.serialized.field", outputFieldTypeName = "sanity.assist.output.field", outputTypeTypeName = "sanity.assist.output.type", fieldPathParam = "pathKey", instructionParam = "instruction", documentRootKey = "<document>";
198
205
  function usePathKey(path) {
199
- return react.useMemo(() => getPathKey(path), [path]);
206
+ return useMemo(() => getPathKey(path), [path]);
200
207
  }
201
208
  function getPathKey(path) {
202
- return path.length ? Array.isArray(path) ? sanity.pathToString(path) : path : documentRootKey;
209
+ return path.length ? Array.isArray(path) ? pathToString(path) : path : documentRootKey;
203
210
  }
204
211
  function getInstructionTitle(instruction2) {
205
212
  return instruction2?.title ?? "Untitled";
@@ -244,25 +251,25 @@ function isDisabled(type) {
244
251
  function isUnsupportedType(type) {
245
252
  return type.name === "sanity.imageCrop" || type.name === "sanity.imageHotspot" || isType(type, "globalDocumentReference") || isType(type, "reference") && !type?.options?.aiAssist?.embeddingsIndex || isType(type, "crossDatasetReference") || isType(type, "file");
246
253
  }
247
- const FirstAssistedPathContext = react.createContext(void 0);
254
+ const FirstAssistedPathContext = createContext(void 0);
248
255
  function FirstAssistedPathProvider(props) {
249
- const { members } = props, firstAssistedPath = react.useMemo(() => {
256
+ const { members } = props, firstAssistedPath = useMemo(() => {
250
257
  const firstAssisted = members.find(
251
258
  (member) => member.kind === "field" && isAssistSupported(member.field.schemaType)
252
259
  );
253
- return firstAssisted?.field.path ? sanity.pathToString(firstAssisted?.field.path) : void 0;
260
+ return firstAssisted?.field.path ? pathToString(firstAssisted?.field.path) : void 0;
254
261
  }, [members]);
255
- return /* @__PURE__ */ jsxRuntime.jsx(FirstAssistedPathContext.Provider, { value: firstAssistedPath, children: props.children });
262
+ return /* @__PURE__ */ jsx(FirstAssistedPathContext.Provider, { value: firstAssistedPath, children: props.children });
256
263
  }
257
- const releaseAnnouncementUrl = "https://www.sanity.io/blog/sanity-ai-assist-announcement?utm_source=sanity-assist-plugin&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=", instructionGuideUrl = "https://sanity.io/guides/getting-started-with-ai-assist-instructions?utm_source=sanity-assist-plugin&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=", giveFeedbackUrl = "https://forms.gle/Kwz7CThxGeA2GiEU8", salesUrl = "https://www.sanity.io/contact/sales?utm_source=sanity-assist-plugin&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=", packageName = "@sanity/assist", pluginTitle = "Sanity AI Assist", pluginTitleShort = "AI Assist", maxHistoryVisibilityMs = dateFns.minutesToMilliseconds(30), illegalIdChars = /[^a-zA-Z0-9._-]/g;
264
+ const releaseAnnouncementUrl = "https://www.sanity.io/blog/sanity-ai-assist-announcement?utm_source=sanity-assist-plugin&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=", instructionGuideUrl = "https://sanity.io/guides/getting-started-with-ai-assist-instructions?utm_source=sanity-assist-plugin&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=", giveFeedbackUrl = "https://forms.gle/Kwz7CThxGeA2GiEU8", salesUrl = "https://www.sanity.io/contact/sales?utm_source=sanity-assist-plugin&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=", packageName = "@sanity/assist", pluginTitle = "Sanity AI Assist", pluginTitleShort = "AI Assist", maxHistoryVisibilityMs = minutesToMilliseconds(30), illegalIdChars = /[^a-zA-Z0-9._-]/g;
258
265
  function assistDocumentId(documentType) {
259
266
  return `${assistDocumentIdPrefix}${documentType}`.replace(illegalIdChars, "_");
260
267
  }
261
268
  function assistTasksStatusId(documentId) {
262
- return sanity.isVersionId(documentId) ? `${assistDocumentStatusIdPrefix}${sanity.getVersionFromId(documentId)}.${sanity.getPublishedId(documentId)}` : `${assistDocumentStatusIdPrefix}${sanity.getPublishedId(documentId)}`;
269
+ return isVersionId(documentId) ? `${assistDocumentStatusIdPrefix}${getVersionFromId(documentId)}.${getPublishedId(documentId)}` : `${assistDocumentStatusIdPrefix}${getPublishedId(documentId)}`;
263
270
  }
264
271
  function useDocumentState(id, docType) {
265
- const state = sanity.useEditState(id, docType);
272
+ const state = useEditState(id, docType);
266
273
  return state.draft || state.published;
267
274
  }
268
275
  function useStudioAssistDocument({
@@ -270,20 +277,20 @@ function useStudioAssistDocument({
270
277
  schemaType,
271
278
  initDoc
272
279
  }) {
273
- const documentTypeName = schemaType.name, currentUser = sanity.useCurrentUser(), assistDocument = useDocumentState(
280
+ const documentTypeName = schemaType.name, currentUser = useCurrentUser(), assistDocument = useDocumentState(
274
281
  assistDocumentId(documentTypeName),
275
282
  assistDocumentTypeName
276
283
  ), assistTasksStatus = useDocumentState(
277
284
  assistTasksStatusId(documentId ?? ""),
278
285
  assistTasksStatusTypeName
279
- ), client = sanity.useClient({ apiVersion: "2023-01-01" });
280
- return react.useEffect(() => {
286
+ ), client = useClient({ apiVersion: "2023-01-01" });
287
+ return useEffect(() => {
281
288
  !assistDocument && initDoc && client.createIfNotExists({
282
289
  _id: assistDocumentId(documentTypeName),
283
290
  _type: assistDocumentTypeName
284
291
  }).catch(() => {
285
292
  });
286
- }, [client, assistDocument, documentTypeName, initDoc]), react.useMemo(() => {
293
+ }, [client, assistDocument, documentTypeName, initDoc]), useMemo(() => {
287
294
  if (!assistDocument)
288
295
  return;
289
296
  const tasks = assistTasksStatus?.tasks ?? [], fields = (assistDocument?.fields ?? []).map((assistField) => ({
@@ -291,7 +298,7 @@ function useStudioAssistDocument({
291
298
  tasks: tasks.filter((task) => task.path === assistField.path),
292
299
  instructions: assistField.instructions?.filter((p) => !p.userId || p.userId === currentUser?.id).map((instruction2) => asStudioInstruction(instruction2, tasks))
293
300
  }));
294
- return sanity.typed({
301
+ return typed({
295
302
  ...assistDocument,
296
303
  tasks: tasks?.map((task) => {
297
304
  const instruction2 = fields.find((f) => f.path === task.path)?.instructions?.find((i) => i._key === task.instructionKey);
@@ -314,8 +321,8 @@ function asStudioInstruction(instruction2, run) {
314
321
  }
315
322
  const NO_TASKS = [];
316
323
  function useInstructionToaster(documentId, documentSchemaType) {
317
- const assistDocument = useStudioAssistDocument({ documentId, schemaType: documentSchemaType }), assistDocLoaded = !!assistDocument, currentUser = sanity.useCurrentUser(), toast = ui.useToast(), tasks = assistDocument?.tasks, previousTasks = react.useRef("initial");
318
- react.useEffect(() => {
324
+ const assistDocument = useStudioAssistDocument({ documentId, schemaType: documentSchemaType }), assistDocLoaded = !!assistDocument, currentUser = useCurrentUser(), toast = useToast(), tasks = assistDocument?.tasks, previousTasks = useRef("initial");
325
+ useEffect(() => {
319
326
  if (assistDocLoaded) {
320
327
  if (previousTasks.current !== "initial") {
321
328
  const prevTaskByKey = Object.fromEntries(
@@ -324,7 +331,7 @@ function useInstructionToaster(documentId, documentSchemaType) {
324
331
  tasks?.filter((task) => task.startedByUserId === currentUser?.id).filter((task) => {
325
332
  const prevTask = prevTaskByKey[task._key];
326
333
  return !prevTask && task.ended || !prevTask?.ended && task.ended;
327
- }).filter((task) => task.ended && dateFns.isAfter(dateFns.addSeconds(new Date(task.ended), 30), /* @__PURE__ */ new Date()))?.forEach((task) => {
334
+ }).filter((task) => task.ended && isAfter(addSeconds(new Date(task.ended), 30), /* @__PURE__ */ new Date()))?.forEach((task) => {
328
335
  const title = task.title ?? getInstructionTitle(task.instruction);
329
336
  task.reason === "error" ? toast.push({
330
337
  title: `Failed: ${title}`,
@@ -356,13 +363,13 @@ function useInstructionToaster(documentId, documentSchemaType) {
356
363
  }
357
364
  function AssistDocumentInputWrapper(props) {
358
365
  if (!isType(props.schemaType, "document") && props.id !== "root" && props.id !== assistFormId)
359
- return /* @__PURE__ */ jsxRuntime.jsx(AssistInput, { ...props });
366
+ return /* @__PURE__ */ jsx(AssistInput, { ...props });
360
367
  const documentId = props.value?._id;
361
- return documentId ? /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentInput, { ...props, documentId }) : props.renderDefault(props);
368
+ return documentId ? /* @__PURE__ */ jsx(AssistDocumentInput, { ...props, documentId }) : props.renderDefault(props);
362
369
  }
363
370
  function AssistDocumentInput({ documentId, ...props }) {
364
371
  useInstructionToaster(documentId, props.schemaType);
365
- const schemaType = react.useMemo(() => props.schemaType.name !== assistDocumentTypeName ? props.schemaType : {
372
+ const schemaType = useMemo(() => props.schemaType.name !== assistDocumentTypeName ? props.schemaType : {
366
373
  ...props.schemaType,
367
374
  type: {
368
375
  ...props.schemaType.type,
@@ -370,24 +377,24 @@ function AssistDocumentInput({ documentId, ...props }) {
370
377
  name: "document"
371
378
  }
372
379
  }, [props.schemaType]);
373
- return /* @__PURE__ */ jsxRuntime.jsx(FirstAssistedPathProvider, { members: props.members, children: props.renderDefault({ ...props, schemaType }) });
380
+ return /* @__PURE__ */ jsx(FirstAssistedPathProvider, { members: props.members, children: props.renderDefault({ ...props, schemaType }) });
374
381
  }
375
382
  function AssistInput(props) {
376
- const { zIndex } = ui.useLayer(), { paneKey } = structure.useDocumentPane(), pathKey = usePathKey(props.path);
377
- return /* @__PURE__ */ jsxRuntime.jsx(ConnectFromRegion, { _key: `${paneKey}_${pathKey}`, zIndex, style: { minWidth: 0 }, children: props.renderDefault(props) });
383
+ const { zIndex } = useLayer(), { paneKey } = useDocumentPane(), pathKey = usePathKey(props.path);
384
+ return /* @__PURE__ */ jsx(ConnectFromRegion, { _key: `${paneKey}_${pathKey}`, zIndex, style: { minWidth: 0 }, children: props.renderDefault(props) });
378
385
  }
379
- const AssistDocumentContext = react.createContext(
386
+ const AssistDocumentContext = createContext(
380
387
  void 0
381
388
  );
382
389
  function useAssistDocumentContext() {
383
- const context = react.useContext(AssistDocumentContext);
390
+ const context = useContext(AssistDocumentContext);
384
391
  if (!context)
385
392
  throw new Error("AssistDocumentContext value is missing");
386
393
  return context;
387
394
  }
388
- const AiAssistanceConfigContext = react.createContext({});
395
+ const AiAssistanceConfigContext = createContext({});
389
396
  function useAiAssistanceConfig() {
390
- const context = react.useContext(AiAssistanceConfigContext);
397
+ const context = useContext(AiAssistanceConfigContext);
391
398
  if (!context)
392
399
  throw new Error("Missing AiAssistanceConfigContext");
393
400
  return context;
@@ -400,14 +407,14 @@ function canUseAssist(status) {
400
407
  return status?.enabled && status.initialized && status.validToken;
401
408
  }
402
409
  function useApiClient(customApiClient) {
403
- const client = sanity.useClient({ apiVersion: API_VERSION_WITH_EXTENDED_TYPES });
404
- return react.useMemo(
410
+ const client = useClient({ apiVersion: API_VERSION_WITH_EXTENDED_TYPES });
411
+ return useMemo(
405
412
  () => customApiClient ? customApiClient(client) : client,
406
413
  [client, customApiClient]
407
414
  );
408
415
  }
409
416
  function useTranslate(apiClient) {
410
- const [loading, setLoading] = react.useState(!1), user = sanity.useCurrentUser(), types = useSerializedTypes(), toast = ui.useToast(), translate = react.useCallback(
417
+ const [loading, setLoading] = useState(!1), user = useCurrentUser(), types = useSerializedTypes(), toast = useToast(), translate = useCallback(
411
418
  ({
412
419
  documentId,
413
420
  languagePath,
@@ -428,7 +435,7 @@ function useTranslate(apiClient) {
428
435
  userStyleguide: await styleguide(),
429
436
  fieldLanguageMap,
430
437
  conditionalMembers,
431
- translatePath: translatePath.length === 0 ? documentRootKey : sanity.pathToString(translatePath),
438
+ translatePath: translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
432
439
  userId: user?.id
433
440
  }
434
441
  });
@@ -447,7 +454,7 @@ function useTranslate(apiClient) {
447
454
  },
448
455
  [setLoading, apiClient, toast, user, types]
449
456
  );
450
- return react.useMemo(
457
+ return useMemo(
451
458
  () => ({
452
459
  translate,
453
460
  loading
@@ -456,7 +463,7 @@ function useTranslate(apiClient) {
456
463
  );
457
464
  }
458
465
  function useGenerateCaption(apiClient) {
459
- const [loading, setLoading] = react.useState(!1), user = sanity.useCurrentUser(), types = useSerializedTypes(), toast = ui.useToast(), generateCaption = react.useCallback(
466
+ const [loading, setLoading] = useState(!1), user = useCurrentUser(), types = useSerializedTypes(), toast = useToast(), generateCaption = useCallback(
460
467
  ({ path, documentId }) => (setLoading(!0), apiClient.request({
461
468
  method: "POST",
462
469
  url: `/assist/tasks/generate-caption/${apiClient.config().dataset}?projectId=${apiClient.config().projectId}`,
@@ -479,7 +486,7 @@ function useGenerateCaption(apiClient) {
479
486
  })),
480
487
  [setLoading, apiClient, toast, user, types]
481
488
  );
482
- return react.useMemo(
489
+ return useMemo(
483
490
  () => ({
484
491
  generateCaption,
485
492
  loading
@@ -488,7 +495,7 @@ function useGenerateCaption(apiClient) {
488
495
  );
489
496
  }
490
497
  function useGenerateImage(apiClient) {
491
- const [loading, setLoading] = react.useState(!1), user = sanity.useCurrentUser(), types = useSerializedTypes(), toast = ui.useToast(), generateImage = react.useCallback(
498
+ const [loading, setLoading] = useState(!1), user = useCurrentUser(), types = useSerializedTypes(), toast = useToast(), generateImage = useCallback(
492
499
  ({ path, documentId }) => (setLoading(!0), apiClient.request({
493
500
  method: "POST",
494
501
  url: `/assist/tasks/generate-image/${apiClient.config().dataset}?projectId=${apiClient.config().projectId}`,
@@ -511,7 +518,7 @@ function useGenerateImage(apiClient) {
511
518
  })),
512
519
  [setLoading, apiClient, toast, user, types]
513
520
  );
514
- return react.useMemo(
521
+ return useMemo(
515
522
  () => ({
516
523
  generateImage,
517
524
  loading
@@ -520,7 +527,7 @@ function useGenerateImage(apiClient) {
520
527
  );
521
528
  }
522
529
  function useGetInstructStatus(apiClient) {
523
- const [loading, setLoading] = react.useState(!0), getInstructStatus = react.useCallback(async () => {
530
+ const [loading, setLoading] = useState(!0), getInstructStatus = useCallback(async () => {
524
531
  setLoading(!0);
525
532
  const projectId = apiClient.config().projectId;
526
533
  try {
@@ -538,7 +545,7 @@ function useGetInstructStatus(apiClient) {
538
545
  };
539
546
  }
540
547
  function useInitInstruct(apiClient) {
541
- const [loading, setLoading] = react.useState(!1), initInstruct = react.useCallback(() => (setLoading(!0), apiClient.request({
548
+ const [loading, setLoading] = useState(!1), initInstruct = useCallback(() => (setLoading(!0), apiClient.request({
542
549
  method: "GET",
543
550
  url: `${basePath}/${apiClient.config().dataset}/init?projectId=${apiClient.config().projectId}`
544
551
  }).finally(() => {
@@ -550,9 +557,9 @@ function useInitInstruct(apiClient) {
550
557
  };
551
558
  }
552
559
  function useRunInstructionApi(apiClient) {
553
- const toast = ui.useToast(), [loading, setLoading] = react.useState(!1), user = sanity.useCurrentUser(), types = useSerializedTypes(), {
560
+ const toast = useToast(), [loading, setLoading] = useState(!1), user = useCurrentUser(), types = useSerializedTypes(), {
554
561
  config: { assist: assistConfig }
555
- } = useAiAssistanceConfig(), runInstruction = react.useCallback(
562
+ } = useAiAssistanceConfig(), runInstruction = useCallback(
556
563
  (request) => {
557
564
  if (!user) {
558
565
  toast.push({
@@ -585,7 +592,7 @@ function useRunInstructionApi(apiClient) {
585
592
  },
586
593
  [apiClient, types, user, toast, assistConfig]
587
594
  );
588
- return react.useMemo(
595
+ return useMemo(
589
596
  () => ({
590
597
  runInstruction,
591
598
  loading
@@ -593,7 +600,7 @@ function useRunInstructionApi(apiClient) {
593
600
  [runInstruction, loading]
594
601
  );
595
602
  }
596
- const NO_INPUT = {}, RunInstructionContext = react.createContext({
603
+ const NO_INPUT = {}, RunInstructionContext = createContext({
597
604
  runInstruction: () => {
598
605
  },
599
606
  getUserInput: async () => {
@@ -601,13 +608,13 @@ const NO_INPUT = {}, RunInstructionContext = react.createContext({
601
608
  instructionLoading: !1
602
609
  });
603
610
  function useRunInstruction() {
604
- return react.useContext(RunInstructionContext);
611
+ return useContext(RunInstructionContext);
605
612
  }
606
613
  function isUserInputBlock(block) {
607
614
  return block._type === userInputTypeName;
608
615
  }
609
616
  function RunInstructionProvider(props) {
610
- const { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { runInstruction: runInstructionRequest, loading } = useRunInstructionApi(apiClient), id = react.useId(), [inputs, setInputs] = react.useState(NO_INPUT), [runRequest, setRunRequest] = react.useState(), [resolveUserInput, setResolveUserInput] = react.useState(), getUserInput = react.useCallback(async ({ title, inputs: inputs2 }) => {
617
+ const { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { runInstruction: runInstructionRequest, loading } = useRunInstructionApi(apiClient), id = useId(), [inputs, setInputs] = useState(NO_INPUT), [runRequest, setRunRequest] = useState(), [resolveUserInput, setResolveUserInput] = useState(), getUserInput = useCallback(async ({ title, inputs: inputs2 }) => {
611
618
  const userInputBlocks = inputs2.map((input, i) => ({
612
619
  _type: userInputTypeName,
613
620
  _key: input.id ?? `${i}`,
@@ -618,7 +625,7 @@ function RunInstructionProvider(props) {
618
625
  return setRunRequest({ dialogTitle: title, userInputBlocks }), new Promise((resolve) => {
619
626
  setResolveUserInput(() => resolve);
620
627
  });
621
- }, []), runInstruction = react.useCallback(
628
+ }, []), runInstruction = useCallback(
622
629
  (req) => {
623
630
  if (loading)
624
631
  return;
@@ -639,9 +646,9 @@ function RunInstructionProvider(props) {
639
646
  });
640
647
  },
641
648
  [runInstructionRequest, loading]
642
- ), close = react.useCallback(() => {
649
+ ), close = useCallback(() => {
643
650
  setRunRequest(void 0), setInputs(NO_INPUT), resolveUserInput && resolveUserInput(void 0), setResolveUserInput(void 0);
644
- }, [resolveUserInput]), runWithInput = react.useCallback(() => {
651
+ }, [resolveUserInput]), runWithInput = useCallback(() => {
645
652
  if (runRequest)
646
653
  if ("instruction" in runRequest) {
647
654
  const { instruction: instruction2, userTexts, ...request } = runRequest;
@@ -668,41 +675,41 @@ function RunInstructionProvider(props) {
668
675
  resolveUserInput?.(userInputs), setResolveUserInput(void 0);
669
676
  }
670
677
  close();
671
- }, [close, runInstructionRequest, runRequest, inputs, resolveUserInput]), open = !!runRequest, runDisabled = react.useMemo(
678
+ }, [close, runInstructionRequest, runRequest, inputs, resolveUserInput]), open = !!runRequest, runDisabled = useMemo(
672
679
  () => (runRequest?.userInputBlocks?.length ?? 0) > Object.entries(inputs).filter(([, value]) => !!value).length,
673
680
  [runRequest?.userInputBlocks, inputs]
674
- ), runButton = /* @__PURE__ */ jsxRuntime.jsx(
675
- ui.Button,
681
+ ), runButton = /* @__PURE__ */ jsx(
682
+ Button,
676
683
  {
677
684
  text: "Run instruction",
678
685
  onClick: runWithInput,
679
686
  tone: "primary",
680
- icon: icons.PlayIcon,
687
+ icon: PlayIcon,
681
688
  style: { width: "100%" },
682
689
  disabled: runDisabled
683
690
  }
684
- ), contextValue = react.useMemo(
691
+ ), contextValue = useMemo(
685
692
  () => ({ runInstruction, getUserInput, instructionLoading: loading }),
686
693
  [runInstruction, loading]
687
694
  );
688
- return /* @__PURE__ */ jsxRuntime.jsxs(RunInstructionContext.Provider, { value: contextValue, children: [
689
- open ? /* @__PURE__ */ jsxRuntime.jsx(
690
- ui.Dialog,
695
+ return /* @__PURE__ */ jsxs(RunInstructionContext.Provider, { value: contextValue, children: [
696
+ open ? /* @__PURE__ */ jsx(
697
+ Dialog,
691
698
  {
692
699
  id,
693
700
  open,
694
701
  onClose: close,
695
702
  width: 1,
696
703
  header: "dialogTitle" in runRequest ? runRequest.dialogTitle : getInstructionTitle(runRequest?.instruction),
697
- footer: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsxRuntime.jsx(
698
- ui.Tooltip,
704
+ footer: /* @__PURE__ */ jsx(Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsx(
705
+ Tooltip,
699
706
  {
700
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Unable to run instruction. All fields must have a value." }) }),
707
+ content: /* @__PURE__ */ jsx(Flex, { padding: 2, children: /* @__PURE__ */ jsx(Text, { children: "Unable to run instruction. All fields must have a value." }) }),
701
708
  placement: "top",
702
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, children: runButton })
709
+ children: /* @__PURE__ */ jsx(Flex, { flex: 1, children: runButton })
703
710
  }
704
711
  ) : runButton }),
705
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { padding: 4, space: 2, children: runRequest?.userInputBlocks?.map((block, i) => /* @__PURE__ */ jsxRuntime.jsx(
712
+ children: /* @__PURE__ */ jsx(Stack, { padding: 4, space: 2, children: runRequest?.userInputBlocks?.map((block, i) => /* @__PURE__ */ jsx(
706
713
  UserInput,
707
714
  {
708
715
  block,
@@ -718,7 +725,7 @@ function RunInstructionProvider(props) {
718
725
  ] });
719
726
  }
720
727
  function UserInput(props) {
721
- const { block, autoFocus, setInputs, inputs } = props, key = block._key, textAreaRef = react.useRef(null), onChange = react.useCallback(
728
+ const { block, autoFocus, setInputs, inputs } = props, key = block._key, textAreaRef = useRef(null), onChange = useCallback(
722
729
  (e) => {
723
730
  setInputs((current) => ({
724
731
  ...current,
@@ -726,19 +733,19 @@ function UserInput(props) {
726
733
  }));
727
734
  },
728
735
  [key, setInputs]
729
- ), value = react.useMemo(() => inputs[key], [inputs, key]);
730
- return react.useEffect(() => {
736
+ ), value = useMemo(() => inputs[key], [inputs, key]);
737
+ return useEffect(() => {
731
738
  autoFocus && setTimeout(() => textAreaRef.current?.focus(), 0);
732
- }, [autoFocus]), /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { padding: 2, space: 3, children: [
733
- /* @__PURE__ */ jsxRuntime.jsx(
734
- sanity.FormFieldHeaderText,
739
+ }, [autoFocus]), /* @__PURE__ */ jsxs(Stack, { padding: 2, space: 3, children: [
740
+ /* @__PURE__ */ jsx(
741
+ FormFieldHeaderText,
735
742
  {
736
743
  title: block?.message ?? "Provide more context",
737
744
  description: block.description
738
745
  }
739
746
  ),
740
- /* @__PURE__ */ jsxRuntime.jsx(
741
- ui.TextArea,
747
+ /* @__PURE__ */ jsx(
748
+ TextArea,
742
749
  {
743
750
  ref: textAreaRef,
744
751
  rows: 4,
@@ -763,12 +770,12 @@ function useRequestRunInstruction(args) {
763
770
  };
764
771
  }
765
772
  function useDraftDelayedTask(args) {
766
- const { documentOnChange, isDocAssistable: isDocAssistable2, task } = args, [queuedArgs, setQueuedArgs] = react.useState(void 0);
767
- return react.useEffect(() => {
773
+ const { documentOnChange, isDocAssistable: isDocAssistable2, task } = args, [queuedArgs, setQueuedArgs] = useState(void 0);
774
+ return useEffect(() => {
768
775
  queuedArgs && isDocAssistable2 && (task(queuedArgs), setQueuedArgs(void 0));
769
- }, [queuedArgs, isDocAssistable2, task]), react.useCallback(
776
+ }, [queuedArgs, isDocAssistable2, task]), useCallback(
770
777
  (taskArgs) => {
771
- documentOnChange(sanity.PatchEvent.from([sanity.unset(["_force_document_creation"])])), setQueuedArgs(taskArgs);
778
+ documentOnChange(PatchEvent.from([unset(["_force_document_creation"])])), setQueuedArgs(taskArgs);
772
779
  },
773
780
  [setQueuedArgs, documentOnChange]
774
781
  );
@@ -780,7 +787,7 @@ function getTypeIcon(schemaType) {
780
787
  if (t.icon) return t.icon;
781
788
  t = t.type;
782
789
  }
783
- return isType(schemaType, "slug") ? icons.LinkIcon : isType(schemaType, "image") ? icons.ImageIcon : schemaType.jsonType === "array" && isPortableTextArray(schemaType) ? icons.BlockContentIcon : schemaType.jsonType === "array" ? icons.OlistIcon : schemaType.jsonType === "object" ? icons.BlockquoteIcon : schemaType.jsonType === "string" ? icons.StringIcon : icons.DocumentIcon;
790
+ return isType(schemaType, "slug") ? LinkIcon : isType(schemaType, "image") ? ImageIcon : schemaType.jsonType === "array" && isPortableTextArray(schemaType) ? BlockContentIcon : schemaType.jsonType === "array" ? OlistIcon : schemaType.jsonType === "object" ? BlockquoteIcon : schemaType.jsonType === "string" ? StringIcon : DocumentIcon;
784
791
  }
785
792
  function asFieldRefsByTypePath(fieldRefs) {
786
793
  return fieldRefs.reduce(
@@ -791,7 +798,7 @@ function asFieldRefsByTypePath(fieldRefs) {
791
798
  function getDocumentFieldRef(schemaType) {
792
799
  return {
793
800
  key: documentRootKey,
794
- icon: schemaType.icon ?? icons.DocumentIcon,
801
+ icon: schemaType.icon ?? DocumentIcon,
795
802
  title: "The entire document",
796
803
  path: [],
797
804
  schemaType
@@ -800,7 +807,7 @@ function getDocumentFieldRef(schemaType) {
800
807
  function getFieldRefs(schemaType, parent, depth = 0) {
801
808
  return depth >= maxDepth ? [] : schemaType.fields.filter((f) => !f.name.startsWith("_")).flatMap((field) => {
802
809
  const path = parent ? [...parent.path, field.name] : [field.name], title = field.type.title ?? field.name, fieldRef = {
803
- key: patchableKey(sanity.pathToString(path)),
810
+ key: patchableKey(pathToString(path)),
804
811
  path,
805
812
  title: parent ? [parent.title, title].join(" / ") : title,
806
813
  schemaType: field.type,
@@ -812,7 +819,7 @@ function getFieldRefs(schemaType, parent, depth = 0) {
812
819
  function getSyntheticFields(schemaType, parent, depth = 0) {
813
820
  return depth >= maxDepth ? [] : schemaType.of.filter((itemType) => !isType(itemType, "block")).flatMap((itemType) => {
814
821
  const segment = { _key: itemType.name }, title = itemType.title ?? itemType.name, path = parent ? [...parent.path, segment] : [segment], fieldRef = {
815
- key: patchableKey(sanity.pathToString(path)),
822
+ key: patchableKey(pathToString(path)),
816
823
  path,
817
824
  title: parent ? [parent.title, title].join(" / ") : title,
818
825
  schemaType: itemType,
@@ -825,50 +832,50 @@ function getSyntheticFields(schemaType, parent, depth = 0) {
825
832
  function getTypePath(doc, pathString) {
826
833
  if (!pathString)
827
834
  return;
828
- const path = sanity.stringToPath(pathString), currentPath = [];
835
+ const path = stringToPath(pathString), currentPath = [];
829
836
  let valid = !0;
830
837
  const syntheticPath = path.map((segment) => {
831
- if (currentPath.push(segment), sanity.isKeySegment(segment)) {
832
- const match = mutator.extractWithPath(sanity.pathToString(currentPath), doc)[0], value = match?.value;
838
+ if (currentPath.push(segment), isKeySegment(segment)) {
839
+ const match = extractWithPath(pathToString(currentPath), doc)[0], value = match?.value;
833
840
  if (match && value && typeof value == "object" && "_type" in value)
834
841
  return { _key: value._type };
835
842
  valid = !1;
836
843
  }
837
844
  return segment;
838
845
  });
839
- return valid ? patchableKey(sanity.pathToString(syntheticPath)) : void 0;
846
+ return valid ? patchableKey(pathToString(syntheticPath)) : void 0;
840
847
  }
841
848
  function patchableKey(pathKey) {
842
849
  return pathKey.replace(/[=]=/g, ":").replace(/[[\]]/g, "|").replace(/"/g, "");
843
850
  }
844
851
  function useTypePath(doc, pathString) {
845
- return react.useMemo(() => getTypePath(doc, pathString), [doc, pathString]);
852
+ return useMemo(() => getTypePath(doc, pathString), [doc, pathString]);
846
853
  }
847
854
  function useSelectedField(documentSchemaType, path) {
848
- const { getFieldRefs: getFieldRefs2 } = useAiAssistanceConfig(), selectableFields = react.useMemo(
849
- () => documentSchemaType && sanity.isObjectSchemaType(documentSchemaType) ? [getDocumentFieldRef(documentSchemaType), ...getFieldRefs2(documentSchemaType.name)] : [],
855
+ const { getFieldRefs: getFieldRefs2 } = useAiAssistanceConfig(), selectableFields = useMemo(
856
+ () => documentSchemaType && isObjectSchemaType(documentSchemaType) ? [getDocumentFieldRef(documentSchemaType), ...getFieldRefs2(documentSchemaType.name)] : [],
850
857
  [documentSchemaType, getFieldRefs2]
851
858
  );
852
- return react.useMemo(() => path ? selectableFields?.find((f) => f.key === path) : void 0, [selectableFields, path]);
859
+ return useMemo(() => path ? selectableFields?.find((f) => f.key === path) : void 0, [selectableFields, path]);
853
860
  }
854
861
  function getFieldTitle(field) {
855
862
  const schemaType = field?.schemaType;
856
863
  return field?.title ?? schemaType?.title ?? schemaType?.name ?? "Untitled";
857
864
  }
858
865
  function useAiPaneRouter() {
859
- const paneRouter = structure.usePaneRouter();
860
- return react.useMemo(
866
+ const paneRouter = usePaneRouter();
867
+ return useMemo(
861
868
  () => ({ ...paneRouter, params: paneRouter.params ?? {} }),
862
869
  [paneRouter]
863
870
  );
864
871
  }
865
872
  function useAssistDocumentContextValue(documentId, documentType) {
866
- const schema = sanity.useSchema(), { getFieldRefs: getFieldRefs2, getFieldRefsByTypePath } = useAiAssistanceConfig(), documentSchemaType = react.useMemo(() => {
873
+ const schema = useSchema(), { getFieldRefs: getFieldRefs2, getFieldRefsByTypePath } = useAiAssistanceConfig(), documentSchemaType = useMemo(() => {
867
874
  const schemaType = schema.get(documentType);
868
875
  if (!schemaType)
869
876
  throw new Error(`Schema type "${documentType}" not found`);
870
877
  return schemaType;
871
- }, [documentType, schema]), { fieldRefs, fieldRefsByTypePath } = react.useMemo(() => ({
878
+ }, [documentType, schema]), { fieldRefs, fieldRefsByTypePath } = useMemo(() => ({
872
879
  fieldRefs: getFieldRefs2(documentType),
873
880
  fieldRefsByTypePath: getFieldRefsByTypePath(documentType)
874
881
  }), [getFieldRefs2, getFieldRefsByTypePath, documentType]), {
@@ -880,11 +887,11 @@ function useAssistDocumentContextValue(documentId, documentType) {
880
887
  // @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
881
888
  selectedReleaseId,
882
889
  editState
883
- } = structure.useDocumentPane(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? sanity.getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : sanity.getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
890
+ } = useDocumentPane(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
884
891
  documentId: assistableDocumentId,
885
892
  schemaType: documentSchemaType
886
893
  }), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
887
- return react.useMemo(() => {
894
+ return useMemo(() => {
888
895
  const base = {
889
896
  assistableDocumentId,
890
897
  documentSchemaType,
@@ -925,12 +932,12 @@ function useAssistDocumentContextValue(documentId, documentType) {
925
932
  ]);
926
933
  }
927
934
  function useSyntheticTasks(assistableDocumentId) {
928
- const [syntheticTasks, setSyntheticTasks] = react.useState(() => []), addSyntheticTask = react.useCallback((task) => {
935
+ const [syntheticTasks, setSyntheticTasks] = useState(() => []), addSyntheticTask = useCallback((task) => {
929
936
  setSyntheticTasks((current) => [...current, task]);
930
- }, []), removeSyntheticTask = react.useCallback((task) => {
937
+ }, []), removeSyntheticTask = useCallback((task) => {
931
938
  setSyntheticTasks((current) => current.filter((t) => task._key !== t._key));
932
939
  }, []);
933
- return react.useEffect(() => {
940
+ return useEffect(() => {
934
941
  setSyntheticTasks([]);
935
942
  }, [assistableDocumentId]), {
936
943
  syntheticTasks,
@@ -940,77 +947,13 @@ function useSyntheticTasks(assistableDocumentId) {
940
947
  }
941
948
  function AssistDocumentContextProvider(props) {
942
949
  const { documentId, documentType } = props, value = useAssistDocumentContextValue(documentId, documentType);
943
- return /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentContext.Provider, { value, children: props.children });
950
+ return /* @__PURE__ */ jsx(AssistDocumentContext.Provider, { value, children: props.children });
944
951
  }
945
952
  function AssistDocumentLayout(props) {
946
953
  const { documentId, documentType } = props;
947
- return /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentContextProvider, { documentType, documentId, children: props.renderDefault(props) });
948
- }
949
- function AssistFeatureBadge() {
950
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { fontSize: 0, style: { margin: "-2px 0" }, tone: "primary", children: "Beta" });
951
- }
952
- function AssistOnboardingPopover(props) {
953
- const { dismiss } = props;
954
- return /* @__PURE__ */ jsxRuntime.jsx(
955
- ui.Popover,
956
- {
957
- content: /* @__PURE__ */ jsxRuntime.jsx(AssistIntroCard, { dismiss }),
958
- open: !0,
959
- portal: !0,
960
- placeholder: "bottom",
961
- tone: "default",
962
- width: 0,
963
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { radius: 2, shadow: 2, style: { padding: 2, lineHeight: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: !0, fontSize: 1, icon: icons.SparklesIcon, mode: "bleed", padding: 2 }) })
964
- }
965
- );
966
- }
967
- function AssistIntroCard(props) {
968
- const buttonRef = react.useRef(null);
969
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { as: "section", padding: 3, space: 3, children: [
970
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { padding: 2, space: 4, children: [
971
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", children: [
972
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { as: "h1", size: 1, weight: "semibold", children: pluginTitle }),
973
- /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-hidden": !0, style: { margin: "-3px 0", lineHeight: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(AssistFeatureBadge, {}) })
974
- ] }),
975
- /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 3, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { as: "p", muted: !0, size: 1, children: [
976
- "Manage reusable AI instructions to boost your content creation and reduce amount of repetitive chores.",
977
- " ",
978
- /* @__PURE__ */ jsxRuntime.jsxs("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: [
979
- "Learn more ",
980
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRightIcon, {})
981
- ] })
982
- ] }) })
983
- ] }),
984
- /* @__PURE__ */ jsxRuntime.jsx(
985
- ui.Button,
986
- {
987
- fontSize: 1,
988
- icon: icons.CheckmarkIcon,
989
- onClick: props.dismiss,
990
- padding: 3,
991
- ref: buttonRef,
992
- text: "Ok, good to know!",
993
- tone: "primary"
994
- }
995
- )
996
- ] });
997
- }
998
- const inspectorOnboardingKey = "sanityStudio:assist:inspector:onboarding:dismissed", fieldOnboardingKey = "sanityStudio:assist:field:onboarding:dismissed";
999
- function isFeatureOnboardingDismissed(featureKey) {
1000
- return typeof localStorage > "u" ? !1 : localStorage.getItem(featureKey) === "true";
1001
- }
1002
- function dismissFeatureOnboarding(featureKey) {
1003
- typeof localStorage > "u" || localStorage.setItem(featureKey, "true");
954
+ return /* @__PURE__ */ jsx(AssistDocumentContextProvider, { documentType, documentId, children: props.renderDefault(props) });
1004
955
  }
1005
- function useOnboardingFeature(featureKey) {
1006
- const [showOnboarding, setShowOnboarding] = react.useState(
1007
- () => !isFeatureOnboardingDismissed(featureKey)
1008
- ), dismissOnboarding = react.useCallback(() => {
1009
- setShowOnboarding(!1), dismissFeatureOnboarding(featureKey);
1010
- }, [setShowOnboarding, featureKey]);
1011
- return { showOnboarding, dismissOnboarding };
1012
- }
1013
- const fadeIn = styledComponents.keyframes`
956
+ const fadeIn = keyframes`
1014
957
  0% {
1015
958
  opacity: 0;
1016
959
  transform: scale(0.75);
@@ -1023,14 +966,14 @@ const fadeIn = styledComponents.keyframes`
1023
966
  opacity: 1;
1024
967
  transform: scale(1);
1025
968
  }
1026
- `, FadeInDiv = styledComponents.styled.div`
969
+ `, FadeInDiv = styled.div`
1027
970
  animation-name: ${fadeIn};
1028
971
  animation-timing-function: ease-in-out;
1029
- `, FadeInContent = react.forwardRef(function({
972
+ `, FadeInContent = forwardRef(function({
1030
973
  children,
1031
974
  durationMs = 250
1032
975
  }, ref) {
1033
- return /* @__PURE__ */ jsxRuntime.jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
976
+ return /* @__PURE__ */ jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
1034
977
  }), purple = {
1035
978
  400: {
1036
979
  hex: "#b087f7"
@@ -1041,19 +984,19 @@ const fadeIn = styledComponents.keyframes`
1041
984
  600: {
1042
985
  hex: "#721fe5"
1043
986
  }
1044
- }, Root = styledComponents.styled.span`
987
+ }, Root = styled.span`
1045
988
  display: block;
1046
989
  width: 25px;
1047
990
  height: 25px;
1048
991
  position: relative;
1049
- `, dash = styledComponents.keyframes`
992
+ `, dash = keyframes`
1050
993
  0% {
1051
994
  transform: rotate(0);
1052
995
  }
1053
996
  100% {
1054
997
  transform: rotate(43deg);
1055
998
  }
1056
- `, Outline = styledComponents.styled.svg`
999
+ `, Outline = styled.svg`
1057
1000
  display: block;
1058
1001
  position: absolute;
1059
1002
  top: 0;
@@ -1073,7 +1016,7 @@ const fadeIn = styledComponents.keyframes`
1073
1016
  stroke-dasharray: 2px 2.34px;
1074
1017
  }
1075
1018
  }
1076
- `, IconDisc = styledComponents.styled.span`
1019
+ `, IconDisc = styled.span`
1077
1020
  background: var(--ai-avatar-disc-color);
1078
1021
  color: white;
1079
1022
  width: 21px;
@@ -1087,15 +1030,15 @@ const fadeIn = styledComponents.keyframes`
1087
1030
  left: 2px;
1088
1031
  `;
1089
1032
  function AssistAvatar(props) {
1090
- const { state = "present" } = props, scheme = sanity.useColorSchemeValue(), style = react.useMemo(() => scheme === "dark" ? {
1033
+ const { state = "present" } = props, scheme = useColorSchemeValue(), style = useMemo(() => scheme === "dark" ? {
1091
1034
  "--ai-avatar-stroke-color": purple[400].hex,
1092
1035
  "--ai-avatar-disc-color": purple[600].hex
1093
1036
  } : {
1094
1037
  "--ai-avatar-stroke-color": purple[500].hex,
1095
1038
  "--ai-avatar-disc-color": purple[600].hex
1096
1039
  }, [scheme]);
1097
- return /* @__PURE__ */ jsxRuntime.jsxs(Root, { "data-state": state, style, children: [
1098
- /* @__PURE__ */ jsxRuntime.jsx(
1040
+ return /* @__PURE__ */ jsxs(Root, { "data-state": state, style, children: [
1041
+ /* @__PURE__ */ jsx(
1099
1042
  Outline,
1100
1043
  {
1101
1044
  width: "25",
@@ -1103,35 +1046,35 @@ function AssistAvatar(props) {
1103
1046
  viewBox: "0 0 25 25",
1104
1047
  fill: "none",
1105
1048
  xmlns: "http://www.w3.org/2000/svg",
1106
- children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12.5", cy: "12.5", r: "11.75" })
1049
+ children: /* @__PURE__ */ jsx("circle", { cx: "12.5", cy: "12.5", r: "11.75" })
1107
1050
  }
1108
1051
  ),
1109
- /* @__PURE__ */ jsxRuntime.jsx(IconDisc, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { as: "span", size: 0, style: { color: "inherit" }, children: /* @__PURE__ */ jsxRuntime.jsx(icons.SparklesIcon, { style: { color: "inherit" } }) }) })
1052
+ /* @__PURE__ */ jsx(IconDisc, { children: /* @__PURE__ */ jsx(Text, { as: "span", size: 0, style: { color: "inherit" }, children: /* @__PURE__ */ jsx(SparklesIcon, { style: { color: "inherit" } }) }) })
1110
1053
  ] });
1111
1054
  }
1112
1055
  function AiFieldPresence(props) {
1113
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { style: { position: "relative", background: "transparent" }, contentEditable: !1, children: /* @__PURE__ */ jsxRuntime.jsx(
1114
- ui.Tooltip,
1056
+ return /* @__PURE__ */ jsx(Card, { style: { position: "relative", background: "transparent" }, contentEditable: !1, children: /* @__PURE__ */ jsx(
1057
+ Tooltip,
1115
1058
  {
1116
1059
  placement: "left",
1117
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, border: !0, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Running instruction..." }) }) }),
1118
- children: /* @__PURE__ */ jsxRuntime.jsx(FadeInContent, { durationMs: 300, children: /* @__PURE__ */ jsxRuntime.jsx(AssistAvatar, { state: "active" }) })
1060
+ content: /* @__PURE__ */ jsx(Card, { padding: 3, border: !0, children: /* @__PURE__ */ jsx(Flex, { align: "center", children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Running instruction..." }) }) }),
1061
+ children: /* @__PURE__ */ jsx(FadeInContent, { durationMs: 300, children: /* @__PURE__ */ jsx(AssistAvatar, { state: "active" }) })
1119
1062
  }
1120
1063
  ) });
1121
1064
  }
1122
1065
  const NO_PRESENCE = [];
1123
1066
  function useAssistPresence(path, showFocusWithin) {
1124
1067
  const context = useAssistDocumentContext(), tasks = (context && "assistDocument" in context ? context.assistDocument : void 0)?.tasks;
1125
- return react.useMemo(() => {
1068
+ return useMemo(() => {
1126
1069
  const activePresence = tasks?.filter((task) => !task.ended)?.flatMap((task) => task.presence ?? [])?.filter(
1127
1070
  (p) => p.started && (/* @__PURE__ */ new Date()).getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs
1128
1071
  ).filter((presence) => {
1129
1072
  if (!presence.path || !path.length)
1130
1073
  return !1;
1131
- const statusPath = sanity.stringToPath(presence.path);
1074
+ const statusPath = stringToPath(presence.path);
1132
1075
  return !showFocusWithin && statusPath.length !== path.length ? !1 : path.every((pathSegment, i) => {
1133
1076
  const statusSegment = statusPath[i];
1134
- return typeof pathSegment == "string" ? pathSegment === statusSegment : sanity.isKeySegment(pathSegment) && sanity.isKeySegment(statusSegment) ? pathSegment._key === statusSegment._key : !1;
1077
+ return typeof pathSegment == "string" ? pathSegment === statusSegment : isKeySegment(pathSegment) && isKeySegment(statusSegment) ? pathSegment._key === statusSegment._key : !1;
1135
1078
  });
1136
1079
  });
1137
1080
  return activePresence?.length ? activePresence.map((status) => aiPresence(status, path)) : NO_PRESENCE;
@@ -1150,79 +1093,72 @@ function aiPresence(presence, path, title) {
1150
1093
  }
1151
1094
  function AssistFieldWrapper(props) {
1152
1095
  const { schemaType } = props;
1153
- return !react.useMemo(() => isAssistSupported(schemaType), [schemaType]) || schemaType.name.startsWith("sanity.") || schemaType.name === contextDocumentTypeName ? props.renderDefault(props) : !isType(props.schemaType, "document") && props.inputId !== "root" && props.inputId !== assistFormId ? /* @__PURE__ */ jsxRuntime.jsx(AssistField, { ...props, children: props.children }) : props.renderDefault(props);
1096
+ return !useMemo(() => isAssistSupported(schemaType), [schemaType]) || schemaType.name.startsWith("sanity.") || schemaType.name === contextDocumentTypeName ? props.renderDefault(props) : !isType(props.schemaType, "document") && props.inputId !== "root" && props.inputId !== assistFormId ? /* @__PURE__ */ jsx(AssistField, { ...props, children: props.children }) : props.renderDefault(props);
1154
1097
  }
1155
1098
  function AssistField(props) {
1156
- const { path } = props, isPortableText = react.useMemo(
1157
- () => !!(sanity.isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
1099
+ const isPortableText = useMemo(
1100
+ () => !!(isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
1158
1101
  [props.schemaType]
1159
- ), presence = useAssistPresence(props.path, isPortableText), firstAssistedPath = react.useContext(FirstAssistedPathContext), isFirstAssisted = react.useMemo(
1160
- () => sanity.pathToString(path) === firstAssistedPath,
1161
- [path, firstAssistedPath]
1162
- ), { showOnboarding, dismissOnboarding } = useOnboardingFeature(fieldOnboardingKey), singlePresence = presence[0], actions = /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", justify: "space-between", children: [
1163
- singlePresence && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(AiFieldPresence, { presence: singlePresence }) }),
1164
- isFirstAssisted && showOnboarding && /* @__PURE__ */ jsxRuntime.jsx(AssistOnboardingPopover, { dismiss: dismissOnboarding })
1165
- ] });
1102
+ ), singlePresence = useAssistPresence(props.path, isPortableText)[0], actions = /* @__PURE__ */ jsx(Flex, { gap: 2, align: "center", justify: "space-between", children: singlePresence && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(AiFieldPresence, { presence: singlePresence }) }) });
1166
1103
  return props.renderDefault({
1167
1104
  ...props,
1168
- // When showing the onboarding, prevent default field actions from being rendered
1169
- actions: isFirstAssisted && showOnboarding ? [] : props.actions,
1170
- // Render presence (and possibly onboarding) in the internal slot (between presence and the field actions)
1105
+ actions: props.actions,
1106
+ // Render presence in the internal slot (between presence and the field actions)
1171
1107
  // eslint-disable-next-line camelcase
1172
1108
  __internal_slot: actions
1173
1109
  });
1174
1110
  }
1175
- const WrapPreCard = styledComponents.styled(ui.Card)`
1111
+ const WrapPreCard = styled(Card)`
1176
1112
  & pre {
1177
1113
  white-space: pre-wrap !important;
1178
1114
  }
1179
1115
  `;
1180
1116
  function SafeValueInput(props) {
1181
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorWrapper, { onChange: props.onChange, children: /* @__PURE__ */ jsxRuntime.jsx(PteValueFixer, { ...props }) });
1117
+ return /* @__PURE__ */ jsx(ErrorWrapper, { onChange: props.onChange, children: /* @__PURE__ */ jsx(PteValueFixer, { ...props }) });
1182
1118
  }
1183
1119
  function ErrorWrapper(props) {
1184
- const { onChange } = props, [error, setError] = react.useState(), catchError = react.useCallback((params) => {
1120
+ const { onChange } = props, [error, setError] = useState(), catchError2 = useCallback((params) => {
1185
1121
  setError(params.error);
1186
- }, []), unsetValue = react.useCallback(() => {
1187
- onChange(sanity.PatchEvent.from(sanity.unset())), setError(void 0);
1188
- }, [onChange]), dismiss = react.useCallback(() => setError(void 0), []), catcher = /* @__PURE__ */ jsxRuntime.jsx(ui.ErrorBoundary, { onCatch: catchError, children: props.children });
1189
- return error ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { border: !0, tone: "critical", padding: 2, contentEditable: !1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
1190
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, weight: "semibold", children: "An error occurred." }),
1191
- /* @__PURE__ */ jsxRuntime.jsx(WrapPreCard, { flex: 1, padding: 2, tone: "critical", border: !0, children: catcher }),
1192
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "fill", flex: 1, gap: 3, children: [
1193
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { text: "Dismiss", onClick: dismiss, tone: "primary" }) }),
1194
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { text: "Unset value", onClick: unsetValue, tone: "critical" })
1122
+ }, []), unsetValue = useCallback(() => {
1123
+ onChange(PatchEvent.from(unset())), setError(void 0);
1124
+ }, [onChange]), dismiss = useCallback(() => setError(void 0), []), catcher = /* @__PURE__ */ jsx(ErrorBoundary, { onCatch: catchError2, children: props.children });
1125
+ return error ? /* @__PURE__ */ jsx(Card, { border: !0, tone: "critical", padding: 2, contentEditable: !1, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
1126
+ /* @__PURE__ */ jsx(Text, { muted: !0, weight: "semibold", children: "An error occurred." }),
1127
+ /* @__PURE__ */ jsx(WrapPreCard, { flex: 1, padding: 2, tone: "critical", border: !0, children: catcher }),
1128
+ /* @__PURE__ */ jsxs(Flex, { width: "fill", flex: 1, gap: 3, children: [
1129
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Button, { text: "Dismiss", onClick: dismiss, tone: "primary" }) }),
1130
+ /* @__PURE__ */ jsx(Button, { text: "Unset value", onClick: unsetValue, tone: "critical" })
1195
1131
  ] })
1196
1132
  ] }) }) : catcher;
1197
1133
  }
1198
1134
  function PteValueFixer(props) {
1199
- const isPortableText = react.useMemo(
1200
- () => sanity.isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType),
1135
+ const isPortableText = useMemo(
1136
+ () => isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType),
1201
1137
  [props.schemaType]
1202
1138
  ), value = props.value;
1203
1139
  return isPortableText && value && !value.length ? props.renderDefault({ ...props, value: void 0 }) : props.renderDefault(props);
1204
1140
  }
1205
1141
  function AssistFormBlock(props) {
1206
- const presence = useAssistPresence(props.path, !0), { onChange } = sanity.useFormCallbacks(), key = props.value._key, localOnChange = react.useCallback(
1142
+ const presence = useAssistPresence(props.path, !0), { onChange } = useFormCallbacks(), key = props.value._key, localOnChange = useCallback(
1207
1143
  (patchEvent) => {
1208
- key && onChange(sanity.PatchEvent.from(patchEvent).prefixAll({ _key: key }));
1144
+ key && onChange(PatchEvent.from(patchEvent).prefixAll({ _key: key }));
1209
1145
  },
1210
1146
  [onChange, key]
1211
1147
  ), singlePresence = presence[0];
1212
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorWrapper, { onChange: localOnChange, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", justify: "space-between", children: [
1213
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: props.renderDefault(props) }),
1214
- singlePresence && /* @__PURE__ */ jsxRuntime.jsx(AiFieldPresence, { presence: singlePresence })
1148
+ return /* @__PURE__ */ jsx(ErrorWrapper, { onChange: localOnChange, children: /* @__PURE__ */ jsxs(Flex, { align: "center", justify: "space-between", children: [
1149
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: props.renderDefault(props) }),
1150
+ singlePresence && /* @__PURE__ */ jsx(AiFieldPresence, { presence: singlePresence })
1215
1151
  ] }) });
1216
1152
  }
1217
- const InlineBlockValueContext = react.createContext(void 0);
1153
+ const InlineBlockValueContext = createContext(void 0);
1218
1154
  function AssistInlineFormBlock(props) {
1219
- return /* @__PURE__ */ jsxRuntime.jsx(InlineBlockValueContext.Provider, { value: props.value, children: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.renderDefault(props) }) });
1155
+ return /* @__PURE__ */ jsx(InlineBlockValueContext.Provider, { value: props.value, children: /* @__PURE__ */ jsx(Fragment, { children: props.renderDefault(props) }) });
1220
1156
  }
1221
1157
  function AssistItem(props) {
1222
1158
  const { path } = props, presence = useAssistPresence(path, !0);
1223
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", width: "fill", style: { position: "relative" }, children: [
1224
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: props.renderDefault({ ...props }) }),
1225
- presence.map((pre) => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { position: "absolute", right: 35 }, children: /* @__PURE__ */ jsxRuntime.jsx(AiFieldPresence, { presence: pre }) }, pre.user.id))
1159
+ return /* @__PURE__ */ jsxs(Flex, { align: "center", width: "fill", style: { position: "relative" }, children: [
1160
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: props.renderDefault({ ...props }) }),
1161
+ presence.map((pre) => /* @__PURE__ */ jsx(Box, { style: { position: "absolute", right: 35 }, children: /* @__PURE__ */ jsx(AiFieldPresence, { presence: pre }) }, pre.user.id))
1226
1162
  ] });
1227
1163
  }
1228
1164
  const preventDefault = (ev) => ev.preventDefault();
@@ -1244,10 +1180,10 @@ function DocumentForm(props) {
1244
1180
  onSetCollapsedPath,
1245
1181
  ready,
1246
1182
  validation
1247
- } = structure.useDocumentPane(), documentStore = sanity.useDocumentStore(), presence = sanity.useDocumentPresence(documentId), patchChannel = react.useMemo(() => sanity.createPatchChannel(), []), isLocked = editState?.transactionSyncLock?.enabled;
1248
- react.useEffect(() => {
1183
+ } = useDocumentPane(), documentStore = useDocumentStore(), presence = useDocumentPresence(documentId), patchChannel = useMemo(() => createPatchChannel(), []), isLocked = editState?.transactionSyncLock?.enabled;
1184
+ useEffect(() => {
1249
1185
  const sub = documentStore.pair.documentEvents(documentId, documentType).pipe(
1250
- operators.tap((event) => {
1186
+ tap((event) => {
1251
1187
  event.type === "mutation" && patchChannel.publish(prepareMutationEvent(event)), event.type === "rebase" && patchChannel.publish(prepareRebaseEvent(event));
1252
1188
  })
1253
1189
  ).subscribe();
@@ -1256,18 +1192,18 @@ function DocumentForm(props) {
1256
1192
  };
1257
1193
  }, [documentId, documentStore, documentType, patchChannel]);
1258
1194
  const hasRev = !!value?._rev;
1259
- react.useEffect(() => {
1195
+ useEffect(() => {
1260
1196
  hasRev && patchChannel.publish({
1261
1197
  type: "mutation",
1262
1198
  patches: [],
1263
1199
  snapshot: value
1264
1200
  });
1265
1201
  }, [hasRev]);
1266
- const formRef = react.useRef(null);
1267
- return react.useEffect(() => {
1268
- ui.focusFirstDescendant(formRef.current);
1269
- }, []), isLocked ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { as: "form", ...props, ref: formRef, children: /* @__PURE__ */ jsxRuntime.jsx(
1270
- ui.Flex,
1202
+ const formRef = useRef(null);
1203
+ return useEffect(() => {
1204
+ focusFirstDescendant(formRef.current);
1205
+ }, []), isLocked ? /* @__PURE__ */ jsx(Box, { as: "form", ...props, ref: formRef, children: /* @__PURE__ */ jsx(
1206
+ Flex,
1271
1207
  {
1272
1208
  align: "center",
1273
1209
  direction: "column",
@@ -1275,10 +1211,10 @@ function DocumentForm(props) {
1275
1211
  justify: "center",
1276
1212
  padding: 3,
1277
1213
  sizing: "border",
1278
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Please hold tight while the document is synced. This usually happens right after the document has been published, and it shouldn\u2019t take more than a few seconds" })
1214
+ children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Please hold tight while the document is synced. This usually happens right after the document has been published, and it shouldn\u2019t take more than a few seconds" })
1279
1215
  }
1280
- ) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { as: "form", ...props, onSubmit: preventDefault, ref: formRef, children: ready ? formState === null ? /* @__PURE__ */ jsxRuntime.jsx(
1281
- ui.Flex,
1216
+ ) }) : /* @__PURE__ */ jsx(Box, { as: "form", ...props, onSubmit: preventDefault, ref: formRef, children: ready ? formState === null ? /* @__PURE__ */ jsx(
1217
+ Flex,
1282
1218
  {
1283
1219
  align: "center",
1284
1220
  direction: "column",
@@ -1286,10 +1222,10 @@ function DocumentForm(props) {
1286
1222
  justify: "center",
1287
1223
  padding: 3,
1288
1224
  sizing: "border",
1289
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "This form is hidden" })
1225
+ children: /* @__PURE__ */ jsx(Text, { size: 1, children: "This form is hidden" })
1290
1226
  }
1291
- ) : /* @__PURE__ */ jsxRuntime.jsx(
1292
- sanity.FormBuilder,
1227
+ ) : /* @__PURE__ */ jsx(
1228
+ FormBuilder,
1293
1229
  {
1294
1230
  __internal_patchChannel: patchChannel,
1295
1231
  collapsedFieldSets,
@@ -1311,10 +1247,11 @@ function DocumentForm(props) {
1311
1247
  readOnly: formState.readOnly,
1312
1248
  schemaType: formState.schemaType,
1313
1249
  validation,
1314
- value: formState.value
1250
+ value: formState.value,
1251
+ hasUpstreamVersion: !1
1315
1252
  }
1316
- ) : /* @__PURE__ */ jsxRuntime.jsxs(
1317
- ui.Flex,
1253
+ ) : /* @__PURE__ */ jsxs(
1254
+ Flex,
1318
1255
  {
1319
1256
  align: "center",
1320
1257
  direction: "column",
@@ -1323,8 +1260,8 @@ function DocumentForm(props) {
1323
1260
  padding: 3,
1324
1261
  sizing: "border",
1325
1262
  children: [
1326
- /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { muted: !0 }),
1327
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 3, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { align: "center", muted: !0, size: 1, children: "Loading document" }) })
1263
+ /* @__PURE__ */ jsx(Spinner, { muted: !0 }),
1264
+ /* @__PURE__ */ jsx(Box, { marginTop: 3, children: /* @__PURE__ */ jsx(Text, { align: "center", muted: !0, size: 1, children: "Loading document" }) })
1328
1265
  ]
1329
1266
  }
1330
1267
  ) });
@@ -1334,7 +1271,7 @@ function prepareMutationEvent(event) {
1334
1271
  return {
1335
1272
  type: "mutation",
1336
1273
  snapshot: event.document,
1337
- patches: sanity.fromMutationPatches(event.origin, patches)
1274
+ patches: fromMutationPatches(event.origin, patches)
1338
1275
  };
1339
1276
  }
1340
1277
  function prepareRebaseEvent(event) {
@@ -1342,12 +1279,12 @@ function prepareRebaseEvent(event) {
1342
1279
  return {
1343
1280
  type: "rebase",
1344
1281
  snapshot: event.document,
1345
- patches: sanity.fromMutationPatches("remote", remotePatches).concat(
1346
- sanity.fromMutationPatches("local", localPatches)
1282
+ patches: fromMutationPatches("remote", remotePatches).concat(
1283
+ fromMutationPatches("local", localPatches)
1347
1284
  )
1348
1285
  };
1349
1286
  }
1350
- const AssistTypeContext = react.createContext({}), DEFAULT_MAX_DEPTH$1 = 8, ABSOLUTE_MAX_DEPTH$1 = 50;
1287
+ const AssistTypeContext = createContext({}), DEFAULT_MAX_DEPTH$1 = 8, ABSOLUTE_MAX_DEPTH$1 = 50;
1351
1288
  function getConditionalMembers(docState, maxDepth2 = DEFAULT_MAX_DEPTH$1) {
1352
1289
  return [{
1353
1290
  path: "",
@@ -1361,7 +1298,7 @@ function isConditional(schemaType) {
1361
1298
  }
1362
1299
  function conditionalState(memberState) {
1363
1300
  return {
1364
- path: sanity.pathToString(memberState.path),
1301
+ path: pathToString(memberState.path),
1365
1302
  readOnly: !!memberState.readOnly,
1366
1303
  // Use actual form state readOnly value
1367
1304
  hidden: !1,
@@ -1382,7 +1319,7 @@ function extractConditionalPaths(node, maxDepth2) {
1382
1319
  const array = member.field;
1383
1320
  let arrayPaths = [];
1384
1321
  const isObjectsArray = array.members.some(
1385
- (m) => m.kind === "item" && sanity.isObjectSchemaType(m.item.schemaType)
1322
+ (m) => m.kind === "item" && isObjectSchemaType(m.item.schemaType)
1386
1323
  );
1387
1324
  if (!array.readOnly)
1388
1325
  for (const arrayMember of array.members) {
@@ -1407,7 +1344,7 @@ function extractConditionalPaths(node, maxDepth2) {
1407
1344
  return acc;
1408
1345
  }, []);
1409
1346
  }
1410
- const SparklesIllustration = styledComponents.styled(icons.SparklesIcon)({
1347
+ const SparklesIllustration = styled(SparklesIcon)({
1411
1348
  fontSize: "3.125em",
1412
1349
  "& path": {
1413
1350
  strokeWidth: "0.6px !important"
@@ -1415,12 +1352,12 @@ const SparklesIllustration = styledComponents.styled(icons.SparklesIcon)({
1415
1352
  });
1416
1353
  function InspectorOnboarding(props) {
1417
1354
  const { onDismiss } = props;
1418
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { width: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
1419
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(SparklesIllustration, {}) }),
1420
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { align: "center", size: 1, children: "Create reusable AI instructions that can be applied across all documents of a certain type." }),
1421
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 2, justify: "center", children: [
1422
- /* @__PURE__ */ jsxRuntime.jsx(
1423
- ui.Button,
1355
+ return /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsx(Container, { width: 0, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
1356
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(SparklesIllustration, {}) }),
1357
+ /* @__PURE__ */ jsx(Text, { align: "center", size: 1, children: "Create reusable AI instructions that can be applied across all documents of a certain type." }),
1358
+ /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, justify: "center", children: [
1359
+ /* @__PURE__ */ jsx(
1360
+ Button,
1424
1361
  {
1425
1362
  as: "a",
1426
1363
  href: releaseAnnouncementUrl,
@@ -1434,35 +1371,35 @@ function InspectorOnboarding(props) {
1434
1371
  tone: "primary"
1435
1372
  }
1436
1373
  ),
1437
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, mode: "bleed", onClick: onDismiss, padding: 2, text: "Dismiss" })
1374
+ /* @__PURE__ */ jsx(Button, { fontSize: 1, mode: "bleed", onClick: onDismiss, padding: 2, text: "Dismiss" })
1438
1375
  ] })
1439
1376
  ] }) }) });
1440
1377
  }
1441
1378
  function FieldAutocomplete(props) {
1442
- const { id, schemaType, fieldPath, onSelect, includeDocument, filter } = props, { getFieldRefs: getFieldRefs2 } = useAiAssistanceConfig(), fieldRefs = react.useMemo(() => {
1379
+ const { id, schemaType, fieldPath, onSelect, includeDocument, filter: filter2 } = props, { getFieldRefs: getFieldRefs2 } = useAiAssistanceConfig(), fieldRefs = useMemo(() => {
1443
1380
  const refs = getFieldRefs2(schemaType.name);
1444
1381
  return includeDocument ? [getDocumentFieldRef(schemaType), ...refs] : refs;
1445
- }, [schemaType, includeDocument, getFieldRefs2]), currentField = react.useMemo(
1382
+ }, [schemaType, includeDocument, getFieldRefs2]), currentField = useMemo(
1446
1383
  () => fieldRefs.find((f) => f.key === fieldPath),
1447
1384
  [fieldPath, fieldRefs]
1448
- ), autocompleteOptions = react.useMemo(
1449
- () => fieldRefs.filter((field) => filter ? filter(field) : !0).filter((f) => !isType(f.schemaType, "reference")).map((field) => ({ value: field.key, field })),
1450
- [fieldRefs, filter]
1451
- ), renderOption = react.useCallback((option) => {
1385
+ ), autocompleteOptions = useMemo(
1386
+ () => fieldRefs.filter((field) => filter2 ? filter2(field) : !0).filter((f) => !isType(f.schemaType, "reference")).map((field) => ({ value: field.key, field })),
1387
+ [fieldRefs, filter2]
1388
+ ), renderOption = useCallback((option) => {
1452
1389
  const { value, field } = option;
1453
- return value ? isType(field.schemaType, "document") ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "The entire document" }) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 3, children: [
1454
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: react.createElement(field.icon) }),
1455
- /* @__PURE__ */ jsxRuntime.jsx(FieldTitle, { field })
1456
- ] }) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { accent: !0, size: 1, children: option.value }) });
1457
- }, []), renderValue = react.useCallback((value, option) => option?.field.title ?? value, []), filterOption = react.useCallback((query, option) => {
1390
+ return value ? isType(field.schemaType, "document") ? /* @__PURE__ */ jsx(Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "The entire document" }) }) : /* @__PURE__ */ jsx(Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, children: [
1391
+ /* @__PURE__ */ jsx(Text, { size: 1, children: createElement(field.icon) }),
1392
+ /* @__PURE__ */ jsx(FieldTitle, { field })
1393
+ ] }) }) : /* @__PURE__ */ jsx(Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsx(Text, { accent: !0, size: 1, children: option.value }) });
1394
+ }, []), renderValue = useCallback((value, option) => option?.field.title ?? value, []), filterOption = useCallback((query, option) => {
1458
1395
  const lQuery = query.toLowerCase();
1459
1396
  return option?.value?.toLowerCase().includes(lQuery) || option?.field?.title?.toLowerCase().includes(lQuery);
1460
1397
  }, []);
1461
- return /* @__PURE__ */ jsxRuntime.jsx(
1462
- ui.Autocomplete,
1398
+ return /* @__PURE__ */ jsx(
1399
+ Autocomplete,
1463
1400
  {
1464
1401
  fontSize: 1,
1465
- icon: currentField ? currentField.icon : icons.SearchIcon,
1402
+ icon: currentField ? currentField.icon : SearchIcon,
1466
1403
  onChange: onSelect,
1467
1404
  openButton: !0,
1468
1405
  id,
@@ -1478,8 +1415,8 @@ function FieldAutocomplete(props) {
1478
1415
  }
1479
1416
  function FieldTitle(props) {
1480
1417
  const splitTitle = props.field.title.split("/");
1481
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsxs(
1482
- ui.Breadcrumbs,
1418
+ return /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxs(
1419
+ Breadcrumbs,
1483
1420
  {
1484
1421
  style: {
1485
1422
  display: "flex",
@@ -1487,77 +1424,77 @@ function FieldTitle(props) {
1487
1424
  alignItems: "center",
1488
1425
  marginTop: "-4px"
1489
1426
  },
1490
- separator: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "/" }) }),
1427
+ separator: /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "/" }) }),
1491
1428
  space: 1,
1492
1429
  children: [
1493
1430
  splitTitle.slice(0, splitTitle.length - 1).map((pt, i) => (
1494
1431
  // eslint-disable-next-line react/no-array-index-key
1495
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: pt.trim() }) }, i)
1432
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: pt.trim() }) }, i)
1496
1433
  )),
1497
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "medium", children: splitTitle[splitTitle.length - 1] }) })
1434
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "medium", children: splitTitle[splitTitle.length - 1] }) })
1498
1435
  ]
1499
1436
  }
1500
1437
  ) });
1501
1438
  }
1502
1439
  function useInterval(ms) {
1503
- const [tick, update] = react.useReducer((n) => n + 1, 0);
1504
- return react.useEffect(() => {
1440
+ const [tick, update] = useReducer((n) => n + 1, 0);
1441
+ return useEffect(() => {
1505
1442
  const i = setInterval(update, ms);
1506
1443
  return () => clearInterval(i);
1507
1444
  }, [ms]), tick;
1508
1445
  }
1509
1446
  function TimeAgo({ date }) {
1510
1447
  useInterval(1e3);
1511
- const timeSince = dateFns.formatDistanceToNow(date ? new Date(date) : /* @__PURE__ */ new Date());
1512
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { title: timeSince, children: [
1448
+ const timeSince = formatDistanceToNow(date ? new Date(date) : /* @__PURE__ */ new Date());
1449
+ return /* @__PURE__ */ jsxs("span", { title: timeSince, children: [
1513
1450
  timeSince,
1514
1451
  " ago"
1515
1452
  ] });
1516
1453
  }
1517
- const rotate = styledComponents.keyframes`
1454
+ const rotate = keyframes`
1518
1455
  0% {
1519
1456
  transform: rotate(0);
1520
1457
  }
1521
1458
  100% {
1522
1459
  transform: rotate(360deg);
1523
1460
  }
1524
- `, SyncSpinningIcon = styledComponents.styled(icons.SyncIcon)`
1461
+ `, SyncSpinningIcon = styled(SyncIcon)`
1525
1462
  animation: ${rotate} 1s linear infinite;
1526
1463
  `, TASK_CONFIG = {
1527
1464
  aborted: {
1528
1465
  title: "Canceled",
1529
- icon: icons.CloseCircleIcon,
1466
+ icon: CloseCircleIcon,
1530
1467
  tone: "transparent"
1531
1468
  },
1532
1469
  error: {
1533
1470
  title: "Error",
1534
- icon: icons.ErrorOutlineIcon,
1471
+ icon: ErrorOutlineIcon,
1535
1472
  tone: "critical"
1536
1473
  },
1537
1474
  success: {
1538
1475
  title: "Completed",
1539
- icon: icons.CheckmarkCircleIcon,
1476
+ icon: CheckmarkCircleIcon,
1540
1477
  tone: "positive"
1541
1478
  },
1542
1479
  timeout: {
1543
1480
  title: "Timeout",
1544
- icon: icons.ClockIcon,
1481
+ icon: ClockIcon,
1545
1482
  tone: "caution"
1546
1483
  }
1547
1484
  };
1548
1485
  function InstructionTaskHistoryButton(props) {
1549
- const { tasks, instructions, documentId, showTitles } = props, client = sanity.useClient({ apiVersion: "2023-01-01" }), cancelRun = react.useCallback(
1486
+ const { tasks, instructions, documentId, showTitles } = props, client = useClient({ apiVersion: "2023-01-01" }), cancelRun = useCallback(
1550
1487
  (taskKey) => {
1551
1488
  if (!documentId)
1552
1489
  return;
1553
- const statusDocId = assistTasksStatusId(documentId), basePath2 = `${sanity.typed("tasks")}[_key=="${taskKey}"]`;
1490
+ const statusDocId = assistTasksStatusId(documentId), basePath2 = `${typed("tasks")}[_key=="${taskKey}"]`;
1554
1491
  client.patch(statusDocId).set({
1555
- [`${basePath2}.${sanity.typed("ended")}`]: (/* @__PURE__ */ new Date()).toISOString(),
1556
- [`${basePath2}.${sanity.typed("reason")}`]: sanity.typed("aborted")
1492
+ [`${basePath2}.${typed("ended")}`]: (/* @__PURE__ */ new Date()).toISOString(),
1493
+ [`${basePath2}.${typed("reason")}`]: typed("aborted")
1557
1494
  }).commit().catch(console.error);
1558
1495
  },
1559
1496
  [client, documentId]
1560
- ), titledTasks = react.useMemo(() => {
1497
+ ), titledTasks = useMemo(() => {
1561
1498
  const t = tasks?.filter(
1562
1499
  (task) => task.started && (/* @__PURE__ */ new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs
1563
1500
  ).map((task) => {
@@ -1569,27 +1506,27 @@ function InstructionTaskHistoryButton(props) {
1569
1506
  };
1570
1507
  }) ?? [];
1571
1508
  return t.sort((a, b) => new Date(b.started ?? "").getTime() - new Date(a.started ?? "").getTime()), t;
1572
- }, [tasks, instructions, cancelRun, showTitles]), isRunning = react.useMemo(() => titledTasks.some((r) => !r.ended), [titledTasks]), hasErrors = react.useMemo(
1509
+ }, [tasks, instructions, cancelRun, showTitles]), isRunning = useMemo(() => titledTasks.some((r) => !r.ended), [titledTasks]), hasErrors = useMemo(
1573
1510
  () => titledTasks.some((r) => r.reason === "error" || r.reason === "timeout"),
1574
1511
  [titledTasks]
1575
- ), [open, setOpen] = react.useState(!1), toggleOpen = react.useCallback(() => setOpen((v) => !v), []), [button, setButton] = react.useState(null), [popover, setPopover] = react.useState(null), handleClickOutside = react.useCallback(() => {
1512
+ ), [open, setOpen] = useState(!1), toggleOpen = useCallback(() => setOpen((v) => !v), []), [button, setButton] = useState(null), [popover, setPopover] = useState(null), handleClickOutside = useCallback(() => {
1576
1513
  setOpen(!1);
1577
1514
  }, []);
1578
- ui.useClickOutside(handleClickOutside, [button, popover]);
1579
- const handleEscape = react.useCallback(() => {
1515
+ useClickOutside(handleClickOutside, [button, popover]);
1516
+ const handleEscape = useCallback(() => {
1580
1517
  setOpen(!1), button?.focus();
1581
1518
  }, [button]);
1582
- return /* @__PURE__ */ jsxRuntime.jsx(
1583
- ui.Popover,
1519
+ return /* @__PURE__ */ jsx(
1520
+ Popover,
1584
1521
  {
1585
1522
  constrainSize: !0,
1586
- content: /* @__PURE__ */ jsxRuntime.jsx(TaskList, { onEscape: handleEscape, tasks: titledTasks }),
1523
+ content: /* @__PURE__ */ jsx(TaskList, { onEscape: handleEscape, tasks: titledTasks }),
1587
1524
  open: open && !!titledTasks?.length,
1588
1525
  placement: "top",
1589
1526
  portal: !0,
1590
1527
  ref: setPopover,
1591
1528
  width: 0,
1592
- children: /* @__PURE__ */ jsxRuntime.jsx(
1529
+ children: /* @__PURE__ */ jsx(
1593
1530
  TaskStatusButton,
1594
1531
  {
1595
1532
  disabled: !titledTasks?.length,
@@ -1605,14 +1542,14 @@ function InstructionTaskHistoryButton(props) {
1605
1542
  }
1606
1543
  const TASK_STATUS_BUTTON_TOOLTIP_PROPS = {
1607
1544
  placement: "top"
1608
- }, TaskStatusButton = react.forwardRef(function(props, ref) {
1545
+ }, TaskStatusButton = forwardRef(function(props, ref) {
1609
1546
  const { disabled, hasErrors, isRunning, onClick, selected } = props;
1610
- return /* @__PURE__ */ jsxRuntime.jsx(
1611
- sanity.StatusButton,
1547
+ return /* @__PURE__ */ jsx(
1548
+ StatusButton,
1612
1549
  {
1613
1550
  label: `${pluginTitle} status`,
1614
1551
  "aria-label": `${pluginTitle} status`,
1615
- icon: isRunning ? SyncSpinningIcon : hasErrors ? icons.ErrorOutlineIcon : icons.CheckmarkCircleIcon,
1552
+ icon: isRunning ? SyncSpinningIcon : hasErrors ? ErrorOutlineIcon : CheckmarkCircleIcon,
1616
1553
  mode: "bleed",
1617
1554
  onClick,
1618
1555
  tone: hasErrors ? "critical" : void 0,
@@ -1624,40 +1561,55 @@ const TASK_STATUS_BUTTON_TOOLTIP_PROPS = {
1624
1561
  );
1625
1562
  });
1626
1563
  function TaskList(props) {
1627
- const { onEscape, tasks } = props, { isTopLayer } = ui.useLayer();
1628
- return ui.useGlobalKeyDown(
1629
- react.useCallback(
1564
+ const { onEscape, tasks } = props, { isTopLayer } = useLayer();
1565
+ return useGlobalKeyDown(
1566
+ useCallback(
1630
1567
  (event) => {
1631
1568
  isTopLayer && event.key === "Escape" && onEscape();
1632
1569
  },
1633
1570
  [isTopLayer, onEscape]
1634
1571
  )
1635
- ), /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { padding: 1, space: 1, children: tasks.map((task) => /* @__PURE__ */ jsxRuntime.jsx(TaskItem, { task }, task._key)) });
1572
+ ), /* @__PURE__ */ jsx(Stack, { padding: 1, space: 1, children: tasks.map((task) => /* @__PURE__ */ jsx(TaskItem, { task }, task._key)) });
1636
1573
  }
1637
1574
  function TaskItem(props) {
1638
1575
  const { task } = props, taskType = task.reason && TASK_CONFIG[task.reason];
1639
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { radius: 2, tone: taskType && taskType?.tone, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 1, children: [
1640
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "flex-start", flex: 1, gap: 3, padding: 3, children: [
1641
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
1642
- taskType && react.createElement(taskType.icon),
1643
- !task.reason && /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {})
1576
+ return /* @__PURE__ */ jsx(Card, { radius: 2, tone: taskType && taskType?.tone, children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 1, children: [
1577
+ /* @__PURE__ */ jsxs(Flex, { align: "flex-start", flex: 1, gap: 3, padding: 3, children: [
1578
+ /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
1579
+ taskType && createElement(taskType.icon),
1580
+ !task.reason && /* @__PURE__ */ jsx(Spinner, {})
1644
1581
  ] }) }),
1645
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { flex: 1, space: 2, children: [
1646
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "medium", children: [
1582
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, space: 2, children: [
1583
+ /* @__PURE__ */ jsxs(Text, { size: 1, weight: "medium", children: [
1647
1584
  taskType ? taskType.title : "Running",
1648
- task.title && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1585
+ task.title && /* @__PURE__ */ jsxs(Fragment, { children: [
1649
1586
  ": ",
1650
1587
  task.title
1651
1588
  ] })
1652
1589
  ] }),
1653
- task.message ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: task.message }) : null,
1654
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: /* @__PURE__ */ jsxRuntime.jsx(TimeAgo, { date: task.ended ?? task.started }) })
1590
+ task.message ? /* @__PURE__ */ jsx(Text, { size: 1, children: task.message }) : null,
1591
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: /* @__PURE__ */ jsx(TimeAgo, { date: task.ended ?? task.started }) })
1655
1592
  ] })
1656
1593
  ] }),
1657
- !task.ended && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", padding: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, mode: "bleed", onClick: task.cancel, text: "Cancel" }) })
1594
+ !task.ended && /* @__PURE__ */ jsx(Box, { flex: "none", padding: 1, children: /* @__PURE__ */ jsx(Button, { fontSize: 1, mode: "bleed", onClick: task.cancel, text: "Cancel" }) })
1658
1595
  ] }) });
1659
1596
  }
1660
- const CardWithShadowBelow = styledComponents.styled(ui.Card)`
1597
+ const inspectorOnboardingKey = "sanityStudio:assist:inspector:onboarding:dismissed";
1598
+ function isFeatureOnboardingDismissed(featureKey) {
1599
+ return typeof localStorage > "u" ? !1 : localStorage.getItem(featureKey) === "true";
1600
+ }
1601
+ function dismissFeatureOnboarding(featureKey) {
1602
+ typeof localStorage > "u" || localStorage.setItem(featureKey, "true");
1603
+ }
1604
+ function useOnboardingFeature(featureKey) {
1605
+ const [showOnboarding, setShowOnboarding] = useState(
1606
+ () => !isFeatureOnboardingDismissed(featureKey)
1607
+ ), dismissOnboarding = useCallback(() => {
1608
+ setShowOnboarding(!1), dismissFeatureOnboarding(featureKey);
1609
+ }, [setShowOnboarding, featureKey]);
1610
+ return { showOnboarding, dismissOnboarding };
1611
+ }
1612
+ const CardWithShadowBelow = styled(Card)`
1661
1613
  position: relative;
1662
1614
 
1663
1615
  &:after {
@@ -1671,7 +1623,7 @@ const CardWithShadowBelow = styledComponents.styled(ui.Card)`
1671
1623
  opacity: 0.5;
1672
1624
  z-index: 100;
1673
1625
  }
1674
- `, CardWithShadowAbove = styledComponents.styled(ui.Card)`
1626
+ `, CardWithShadowAbove = styled(Card)`
1675
1627
  position: relative;
1676
1628
 
1677
1629
  &:after {
@@ -1689,48 +1641,48 @@ const CardWithShadowBelow = styledComponents.styled(ui.Card)`
1689
1641
  function AssistInspectorWrapper(props) {
1690
1642
  const context = useAiAssistanceConfig();
1691
1643
  if (context.statusLoading)
1692
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", height: "fill", justify: "center", padding: 4, sizing: "border", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, style: { textAlign: "center" }, children: [
1693
- /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { muted: !0 }),
1694
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { muted: !0, size: 1, children: [
1644
+ return /* @__PURE__ */ jsx(Flex, { align: "center", height: "fill", justify: "center", padding: 4, sizing: "border", children: /* @__PURE__ */ jsxs(Stack, { space: 3, style: { textAlign: "center" }, children: [
1645
+ /* @__PURE__ */ jsx(Spinner, { muted: !0 }),
1646
+ /* @__PURE__ */ jsxs(Text, { muted: !0, size: 1, children: [
1695
1647
  "Loading ",
1696
1648
  pluginTitle,
1697
1649
  "..."
1698
1650
  ] })
1699
1651
  ] }) });
1700
1652
  const status = context.status;
1701
- return status?.enabled ? !status?.initialized || !status.validToken ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", height: "fill", children: [
1702
- /* @__PURE__ */ jsxRuntime.jsx(
1703
- structure.DocumentInspectorHeader,
1653
+ return status?.enabled ? !status?.initialized || !status.validToken ? /* @__PURE__ */ jsxs(Flex, { direction: "column", height: "fill", children: [
1654
+ /* @__PURE__ */ jsx(
1655
+ DocumentInspectorHeader,
1704
1656
  {
1705
1657
  closeButtonLabel: "Close",
1706
1658
  onClose: props.onClose,
1707
1659
  title: pluginTitle
1708
1660
  }
1709
1661
  ),
1710
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { padding: 4, space: 3, children: [
1711
- context.error ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "semibold", children: [
1662
+ /* @__PURE__ */ jsxs(Stack, { padding: 4, space: 3, children: [
1663
+ context.error ? /* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
1712
1664
  "Failed to start ",
1713
1665
  pluginTitle
1714
1666
  ] }) : null,
1715
- !context.error && !status?.initialized ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "semibold", children: [
1667
+ !context.error && !status?.initialized ? /* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
1716
1668
  pluginTitle,
1717
1669
  " is not enabled"
1718
1670
  ] }) : null,
1719
- !context.error && status?.initialized && !status.validToken ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1720
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "Invalid token" }),
1721
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "The token used by the AI Assistant is not valid and has to be regenerated." })
1671
+ !context.error && status?.initialized && !status.validToken ? /* @__PURE__ */ jsxs(Fragment, { children: [
1672
+ /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Invalid token" }),
1673
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "The token used by the AI Assistant is not valid and has to be regenerated." })
1722
1674
  ] }) : null,
1723
- context.error && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "Something went wrong. See console for details." }),
1724
- !context.error && !status?.initialized && /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, muted: !0, children: [
1675
+ context.error && /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Something went wrong. See console for details." }),
1676
+ !context.error && !status?.initialized && /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
1725
1677
  "Please enable ",
1726
1678
  pluginTitle,
1727
1679
  "."
1728
1680
  ] }),
1729
- /* @__PURE__ */ jsxRuntime.jsx(
1730
- ui.Button,
1681
+ /* @__PURE__ */ jsx(
1682
+ Button,
1731
1683
  {
1732
1684
  fontSize: 1,
1733
- icon: context.initLoading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }) : context.error ? icons.RetryIcon : void 0,
1685
+ icon: context.initLoading ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Spinner, {}) }) : context.error ? RetryIcon : void 0,
1734
1686
  text: context.error ? "Retry" : status?.initialized && !status.validToken ? `Restore ${pluginTitle}` : `Enable ${pluginTitle} now`,
1735
1687
  tone: "primary",
1736
1688
  onClick: context.init,
@@ -1738,59 +1690,59 @@ function AssistInspectorWrapper(props) {
1738
1690
  }
1739
1691
  )
1740
1692
  ] })
1741
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(AssistInspector, { ...props }) : /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", height: "fill", children: [
1742
- /* @__PURE__ */ jsxRuntime.jsx(
1743
- structure.DocumentInspectorHeader,
1693
+ ] }) : /* @__PURE__ */ jsx(AssistInspector, { ...props }) : /* @__PURE__ */ jsxs(Flex, { direction: "column", height: "fill", children: [
1694
+ /* @__PURE__ */ jsx(
1695
+ DocumentInspectorHeader,
1744
1696
  {
1745
1697
  closeButtonLabel: "Close",
1746
1698
  onClose: props.onClose,
1747
1699
  title: pluginTitle
1748
1700
  }
1749
1701
  ),
1750
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { flex: 1, overflow: "auto", padding: 4, space: 3, children: [
1751
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { as: "p", size: 1, weight: "semibold", children: [
1702
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, overflow: "auto", padding: 4, space: 3, children: [
1703
+ /* @__PURE__ */ jsxs(Text, { as: "p", size: 1, weight: "semibold", children: [
1752
1704
  pluginTitle,
1753
1705
  " is not available"
1754
1706
  ] }),
1755
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { as: "p", muted: !0, size: 1, children: [
1707
+ /* @__PURE__ */ jsxs(Text, { as: "p", muted: !0, size: 1, children: [
1756
1708
  "Please get in touch with a Sanity account manager or",
1757
1709
  " ",
1758
- /* @__PURE__ */ jsxRuntime.jsx("a", { href: salesUrl, target: "_blank", rel: "noreferrer", children: "contact our sales team" }),
1710
+ /* @__PURE__ */ jsx("a", { href: salesUrl, target: "_blank", rel: "noreferrer", children: "contact our sales team" }),
1759
1711
  " ",
1760
1712
  "to get started with ",
1761
1713
  pluginTitle,
1762
1714
  ".",
1763
1715
  " ",
1764
- /* @__PURE__ */ jsxRuntime.jsx("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: "Learn more \u2192" })
1716
+ /* @__PURE__ */ jsx("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: "Learn more \u2192" })
1765
1717
  ] })
1766
1718
  ] })
1767
1719
  ] });
1768
1720
  }
1769
1721
  function AssistInspector(props) {
1770
- const { params } = useAiPaneRouter(), boundary = react.useRef(null), pathKey = params?.[fieldPathParam], instructionKey = params?.[instructionParam], documentPane = structure.useDocumentPane(), {
1722
+ const { params } = useAiPaneRouter(), boundary = useRef(null), pathKey = params?.[fieldPathParam], instructionKey = params?.[instructionParam], documentPane = useDocumentPane(), {
1771
1723
  documentId,
1772
1724
  documentType,
1773
1725
  value: docValue,
1774
1726
  schemaType,
1775
1727
  onChange: documentOnChange,
1776
1728
  formState
1777
- } = documentPane, { assistableDocumentId, documentIsAssistable } = useAssistDocumentContext(), formStateRef = react.useRef(formState);
1729
+ } = documentPane, { assistableDocumentId, documentIsAssistable } = useAssistDocumentContext(), formStateRef = useRef(formState);
1778
1730
  formStateRef.current = formState;
1779
1731
  const { instructionLoading, requestRunInstruction } = useRequestRunInstruction({
1780
1732
  documentOnChange,
1781
1733
  isDocAssistable: documentIsAssistable
1782
- }), typePath = useTypePath(docValue, pathKey ?? ""), selectedField = useSelectedField(schemaType, typePath), aiDocId = assistDocumentId(documentType), assistDocument = useStudioAssistDocument({ documentId, schemaType, initDoc: !0 }), instruction2 = assistDocument?.fields?.find((f) => f.path === typePath)?.instructions?.find((i) => i._key === instructionKey), tasks = react.useMemo(
1734
+ }), typePath = useTypePath(docValue, pathKey ?? ""), selectedField = useSelectedField(schemaType, typePath), aiDocId = assistDocumentId(documentType), assistDocument = useStudioAssistDocument({ documentId, schemaType, initDoc: !0 }), instruction2 = assistDocument?.fields?.find((f) => f.path === typePath)?.instructions?.find((i) => i._key === instructionKey), tasks = useMemo(
1783
1735
  () => assistDocument?.tasks?.filter((i) => !instructionKey || i.instructionKey === instructionKey),
1784
1736
  [assistDocument?.tasks, instructionKey]
1785
- ), instructions = react.useMemo(
1737
+ ), instructions = useMemo(
1786
1738
  () => assistDocument?.fields?.flatMap((f) => f.instructions ?? []),
1787
1739
  [assistDocument?.fields]
1788
- ), promptValue = instruction2?.prompt, isEmptyPrompt = react.useMemo(() => {
1740
+ ), promptValue = instruction2?.prompt, isEmptyPrompt = useMemo(() => {
1789
1741
  if (!promptValue?.length)
1790
1742
  return !0;
1791
1743
  const children = promptValue[0]?.children;
1792
1744
  return promptValue.length == 1 && children?.length === 1 && !children?.[0]?.text?.length;
1793
- }, [promptValue]), paneNode = react.useMemo(
1745
+ }, [promptValue]), paneNode = useMemo(
1794
1746
  () => ({
1795
1747
  type: "document",
1796
1748
  id: aiDocId,
@@ -1801,7 +1753,7 @@ function AssistInspector(props) {
1801
1753
  }
1802
1754
  }),
1803
1755
  [aiDocId]
1804
- ), runCurrentInstruction = react.useCallback(
1756
+ ), runCurrentInstruction = useCallback(
1805
1757
  () => instruction2 && pathKey && typePath && requestRunInstruction({
1806
1758
  documentId: assistableDocumentId,
1807
1759
  path: pathKey,
@@ -1811,9 +1763,9 @@ function AssistInspector(props) {
1811
1763
  conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : []
1812
1764
  }),
1813
1765
  [pathKey, instruction2, typePath, documentType, assistableDocumentId, requestRunInstruction]
1814
- ), Region = react.useCallback((_props) => /* @__PURE__ */ jsxRuntime.jsx("div", { ..._props, style: { height: "100%", flex: 1, overflow: "auto" } }), []), assistTypeContext = react.useMemo(() => ({ typePath, documentType }), [typePath, documentType]);
1815
- return !documentId || !schemaType || schemaType.jsonType !== "object" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { flex: 1, padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Document not ready yet." }) }) : /* @__PURE__ */ jsxRuntime.jsxs(
1816
- ui.Flex,
1766
+ ), Region = useCallback((_props) => /* @__PURE__ */ jsx("div", { ..._props, style: { height: "100%", flex: 1, overflow: "auto" } }), []), assistTypeContext = useMemo(() => ({ typePath, documentType }), [typePath, documentType]);
1767
+ return !documentId || !schemaType || schemaType.jsonType !== "object" ? /* @__PURE__ */ jsx(Card, { flex: 1, padding: 4, children: /* @__PURE__ */ jsx(Text, { children: "Document not ready yet." }) }) : /* @__PURE__ */ jsxs(
1768
+ Flex,
1817
1769
  {
1818
1770
  ref: boundary,
1819
1771
  direction: "column",
@@ -1822,7 +1774,7 @@ function AssistInspector(props) {
1822
1774
  sizing: "border",
1823
1775
  style: { lineHeight: 0 },
1824
1776
  children: [
1825
- /* @__PURE__ */ jsxRuntime.jsx(
1777
+ /* @__PURE__ */ jsx(
1826
1778
  AiInspectorHeader,
1827
1779
  {
1828
1780
  onClose: props.onClose,
@@ -1830,14 +1782,14 @@ function AssistInspector(props) {
1830
1782
  fieldTitle: getFieldTitle(selectedField)
1831
1783
  }
1832
1784
  ),
1833
- /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { as: Region, flex: 1, overflow: "auto", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", style: { minHeight: "100%" }, children: [
1834
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(sanity.PresenceOverlay, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 4, children: selectedField && /* @__PURE__ */ jsxRuntime.jsx(AssistTypeContext.Provider, { value: assistTypeContext, children: /* @__PURE__ */ jsxRuntime.jsx(
1835
- sanity.VirtualizerScrollInstanceProvider,
1785
+ /* @__PURE__ */ jsx(Card, { as: Region, flex: 1, overflow: "auto", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", style: { minHeight: "100%" }, children: [
1786
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(PresenceOverlay, { children: /* @__PURE__ */ jsx(Box, { padding: 4, children: selectedField && /* @__PURE__ */ jsx(AssistTypeContext.Provider, { value: assistTypeContext, children: /* @__PURE__ */ jsx(
1787
+ VirtualizerScrollInstanceProvider,
1836
1788
  {
1837
1789
  scrollElement: boundary.current,
1838
1790
  containerElement: boundary,
1839
- children: /* @__PURE__ */ jsxRuntime.jsx(
1840
- structure.DocumentPaneProvider,
1791
+ children: /* @__PURE__ */ jsx(
1792
+ DocumentPaneProvider,
1841
1793
  {
1842
1794
  paneKey: documentPane.paneKey,
1843
1795
  index: documentPane.index,
@@ -1848,15 +1800,15 @@ function AssistInspector(props) {
1848
1800
  selectedPerspectiveName: "published",
1849
1801
  selectedReleaseId: void 0
1850
1802
  },
1851
- children: /* @__PURE__ */ jsxRuntime.jsx(DocumentForm, {})
1803
+ children: /* @__PURE__ */ jsx(DocumentForm, {})
1852
1804
  }
1853
1805
  )
1854
1806
  }
1855
1807
  ) }) }) }) }),
1856
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { muted: !0, size: 1, children: [
1808
+ /* @__PURE__ */ jsx(Box, { flex: "none", padding: 4, children: /* @__PURE__ */ jsxs(Text, { muted: !0, size: 1, children: [
1857
1809
  "How is Sanity AI Assist working for you?",
1858
1810
  " ",
1859
- /* @__PURE__ */ jsxRuntime.jsxs(
1811
+ /* @__PURE__ */ jsxs(
1860
1812
  "a",
1861
1813
  {
1862
1814
  href: giveFeedbackUrl,
@@ -1865,26 +1817,26 @@ function AssistInspector(props) {
1865
1817
  style: { whiteSpace: "nowrap" },
1866
1818
  children: [
1867
1819
  "Let us know ",
1868
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRightIcon, {})
1820
+ /* @__PURE__ */ jsx(ArrowRightIcon, {})
1869
1821
  ]
1870
1822
  }
1871
1823
  )
1872
1824
  ] }) })
1873
1825
  ] }) }),
1874
- /* @__PURE__ */ jsxRuntime.jsx(CardWithShadowAbove, { flex: "none", paddingX: 4, paddingY: 3, style: { justifySelf: "flex-end" }, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, flex: 1, justify: "flex-end", children: [
1875
- schemaType?.name && pathKey && instructionKey && /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
1876
- ui.Button,
1826
+ /* @__PURE__ */ jsx(CardWithShadowAbove, { flex: "none", paddingX: 4, paddingY: 3, style: { justifySelf: "flex-end" }, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, flex: 1, justify: "flex-end", children: [
1827
+ schemaType?.name && pathKey && instructionKey && /* @__PURE__ */ jsx(Stack, { flex: 1, children: /* @__PURE__ */ jsx(
1828
+ Button,
1877
1829
  {
1878
1830
  mode: "ghost",
1879
1831
  disabled: isEmptyPrompt || instructionLoading,
1880
1832
  fontSize: 1,
1881
- icon: instructionLoading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { marginTop: 3 } }) : icons.PlayIcon,
1833
+ icon: instructionLoading ? /* @__PURE__ */ jsx(Spinner, { style: { marginTop: 3 } }) : PlayIcon,
1882
1834
  onClick: runCurrentInstruction,
1883
1835
  padding: 3,
1884
1836
  text: "Run instruction"
1885
1837
  }
1886
1838
  ) }),
1887
- /* @__PURE__ */ jsxRuntime.jsx(
1839
+ /* @__PURE__ */ jsx(
1888
1840
  InstructionTaskHistoryButton,
1889
1841
  {
1890
1842
  documentId: assistableDocumentId,
@@ -1900,21 +1852,21 @@ function AssistInspector(props) {
1900
1852
  }
1901
1853
  function AiInspectorHeader(props) {
1902
1854
  const { onClose, field, fieldTitle } = props, { showOnboarding, dismissOnboarding } = useOnboardingFeature(inspectorOnboardingKey);
1903
- return /* @__PURE__ */ jsxRuntime.jsxs(CardWithShadowBelow, { flex: "none", padding: 2, children: [
1904
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { flex: 1, align: "center", children: [
1905
- /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, padding: 3, gap: 2, align: "center", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, align: "center", wrap: "wrap", style: { marginTop: "-4px" }, children: [
1906
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "AI instructions for" }) }),
1907
- /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { radius: 2, border: !0, padding: 1, marginTop: 1, children: field ? /* @__PURE__ */ jsxRuntime.jsx(FieldTitle, { field }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: fieldTitle }) })
1855
+ return /* @__PURE__ */ jsxs(CardWithShadowBelow, { flex: "none", padding: 2, children: [
1856
+ /* @__PURE__ */ jsxs(Flex, { flex: 1, align: "center", children: [
1857
+ /* @__PURE__ */ jsx(Flex, { flex: 1, padding: 3, gap: 2, align: "center", children: /* @__PURE__ */ jsxs(Flex, { gap: 1, align: "center", wrap: "wrap", style: { marginTop: "-4px" }, children: [
1858
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "AI instructions for" }) }),
1859
+ /* @__PURE__ */ jsx(Card, { radius: 2, border: !0, padding: 1, marginTop: 1, children: field ? /* @__PURE__ */ jsx(FieldTitle, { field }) : /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: fieldTitle }) })
1908
1860
  ] }) }),
1909
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, icon: icons.CloseIcon, mode: "bleed", onClick: onClose }) })
1861
+ /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(Button, { fontSize: 1, icon: CloseIcon, mode: "bleed", onClick: onClose }) })
1910
1862
  ] }),
1911
- showOnboarding && /* @__PURE__ */ jsxRuntime.jsx(InspectorOnboarding, { onDismiss: dismissOnboarding })
1863
+ showOnboarding && /* @__PURE__ */ jsx(InspectorOnboarding, { onDismiss: dismissOnboarding })
1912
1864
  ] });
1913
1865
  }
1914
1866
  const aiInspectorId = "ai-assistance", assistInspector = {
1915
1867
  name: aiInspectorId,
1916
1868
  useMenuItem: () => ({
1917
- icon: icons.SparklesIcon,
1869
+ icon: SparklesIcon,
1918
1870
  title: pluginTitle,
1919
1871
  hidden: !0,
1920
1872
  showAsAction: !1
@@ -1922,7 +1874,7 @@ const aiInspectorId = "ai-assistance", assistInspector = {
1922
1874
  component: AssistInspectorWrapper,
1923
1875
  onClose({ params }) {
1924
1876
  return {
1925
- params: sanity.typed({
1877
+ params: typed({
1926
1878
  ...params,
1927
1879
  [fieldPathParam]: void 0,
1928
1880
  [instructionParam]: void 0
@@ -2014,9 +1966,9 @@ function drawConnectorPath(options2, line) {
2014
1966
  ), join(cmds);
2015
1967
  }
2016
1968
  function ConnectorPath(props) {
2017
- const { from, options: options2, to } = props, { strokeWidth } = options2.path, theme = ui.useTheme(), line = react.useMemo(() => mapConnectorToLine(options2, { from, to }), [from, options2, to]);
2018
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2019
- /* @__PURE__ */ jsxRuntime.jsx(
1969
+ const { from, options: options2, to } = props, { strokeWidth } = options2.path, theme = useTheme(), line = useMemo(() => mapConnectorToLine(options2, { from, to }), [from, options2, to]);
1970
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1971
+ /* @__PURE__ */ jsx(
2020
1972
  "path",
2021
1973
  {
2022
1974
  d: drawConnectorPath(options2, line),
@@ -2024,15 +1976,15 @@ function ConnectorPath(props) {
2024
1976
  strokeWidth: strokeWidth + 4
2025
1977
  }
2026
1978
  ),
2027
- /* @__PURE__ */ jsxRuntime.jsx(
1979
+ /* @__PURE__ */ jsx(
2028
1980
  "path",
2029
1981
  {
2030
1982
  d: drawConnectorPath(options2, line),
2031
- stroke: ui.rgba(theme.sanity.color.base.border, 0.5),
1983
+ stroke: rgba(theme.sanity.color.base.border, 0.5),
2032
1984
  strokeWidth
2033
1985
  }
2034
1986
  ),
2035
- line.from.isAbove && /* @__PURE__ */ jsxRuntime.jsx(
1987
+ line.from.isAbove && /* @__PURE__ */ jsx(
2036
1988
  "path",
2037
1989
  {
2038
1990
  d: arrowPath(
@@ -2045,7 +1997,7 @@ function ConnectorPath(props) {
2045
1997
  strokeWidth
2046
1998
  }
2047
1999
  ),
2048
- line.from.isBelow && /* @__PURE__ */ jsxRuntime.jsx(
2000
+ line.from.isBelow && /* @__PURE__ */ jsx(
2049
2001
  "path",
2050
2002
  {
2051
2003
  d: arrowPath(
@@ -2077,11 +2029,11 @@ const DEBUG = !1, options = {
2077
2029
  }
2078
2030
  };
2079
2031
  function AssistConnectorsOverlay(props) {
2080
- const { connectors } = props, [, setRedraw] = react.useState(!1);
2081
- return react.useEffect(() => {
2032
+ const { connectors } = props, [, setRedraw] = useState(!1);
2033
+ return useEffect(() => {
2082
2034
  setRedraw(!0);
2083
- }, []), /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2084
- /* @__PURE__ */ jsxRuntime.jsx(
2035
+ }, []), /* @__PURE__ */ jsxs(Fragment, { children: [
2036
+ /* @__PURE__ */ jsx(
2085
2037
  "svg",
2086
2038
  {
2087
2039
  fill: "none",
@@ -2097,7 +2049,7 @@ function AssistConnectorsOverlay(props) {
2097
2049
  zIndex: 150
2098
2050
  // zIndex,
2099
2051
  },
2100
- children: connectors.map((connector) => /* @__PURE__ */ jsxRuntime.jsx(
2052
+ children: connectors.map((connector) => /* @__PURE__ */ jsx(
2101
2053
  ConnectorPath,
2102
2054
  {
2103
2055
  from: connector.from,
@@ -2131,7 +2083,7 @@ const getLanguageParams = (select, document2) => {
2131
2083
  return {};
2132
2084
  const selection = select || {}, selectedValue = {};
2133
2085
  for (const [key, path] of Object.entries(selection)) {
2134
- let value = get__default.default(document2, path);
2086
+ let value = get(document2, path);
2135
2087
  Array.isArray(value) && (value = value.filter(
2136
2088
  (item) => typeof item == "object" ? item?._type !== "reference" || "_ref" in item : !0
2137
2089
  )), selectedValue[key] = value;
@@ -2149,11 +2101,11 @@ function setPreferredToFieldLanguages(fromLanguageId, languageIds) {
2149
2101
  }
2150
2102
  const DEFAULT_MAX_DEPTH = 6, ABSOLUTE_MAX_DEPTH = 50;
2151
2103
  function getDocumentMembersFlat(doc, schemaType, maxDepth2 = DEFAULT_MAX_DEPTH) {
2152
- return sanity.isDocumentSchemaType(schemaType) ? extractPaths(doc, schemaType, [], Math.min(maxDepth2, ABSOLUTE_MAX_DEPTH)) : (console.error("Schema type is not a document"), []);
2104
+ return isDocumentSchemaType(schemaType) ? extractPaths(doc, schemaType, [], Math.min(maxDepth2, ABSOLUTE_MAX_DEPTH)) : (console.error("Schema type is not a document"), []);
2153
2105
  }
2154
2106
  function extractPaths(doc, schemaType, path, maxDepth2) {
2155
2107
  return path.length >= maxDepth2 ? [] : schemaType.fields.reduce((acc, field) => {
2156
- const fieldPath = [...path, field.name], fieldSchema = field.type, { value } = mutator.extractWithPath(sanity.pathToString(fieldPath), doc)[0] ?? {};
2108
+ const fieldPath = [...path, field.name], fieldSchema = field.type, { value } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
2157
2109
  if (!value)
2158
2110
  return acc;
2159
2111
  const thisFieldWithPath = {
@@ -2167,7 +2119,7 @@ function extractPaths(doc, schemaType, path, maxDepth2) {
2167
2119
  return [...acc, thisFieldWithPath, ...innerFields];
2168
2120
  } else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some((item) => "fields" in item) && // no reason to drill into arrays if the item fields will be culled by maxDepth, ie we need 1 extra path headroom
2169
2121
  path.length + 1 < maxDepth2) {
2170
- const { value: arrayValue } = mutator.extractWithPath(sanity.pathToString(fieldPath), doc)[0] ?? {};
2122
+ const { value: arrayValue } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
2171
2123
  let arrayPaths = [];
2172
2124
  if (arrayValue?.length)
2173
2125
  for (const item of arrayValue) {
@@ -2203,7 +2155,7 @@ function extractPaths(doc, schemaType, path, maxDepth2) {
2203
2155
  const defaultLanguageOutputs = function(member, enclosingType, translateFromLanguageId, translateToLanguageIds) {
2204
2156
  if (member.schemaType.jsonType === "object" && member.schemaType.name.startsWith("internationalizedArray")) {
2205
2157
  const pathEnd = member.path.slice(-1);
2206
- return (sanity.isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null) === translateFromLanguageId ? translateToLanguageIds.map((translateToId) => ({
2158
+ return (isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null) === translateFromLanguageId ? translateToLanguageIds.map((translateToId) => ({
2207
2159
  id: translateToId,
2208
2160
  outputPath: [...member.path.slice(0, -1), { _key: translateToId }]
2209
2161
  })) : void 0;
@@ -2217,7 +2169,7 @@ const defaultLanguageOutputs = function(member, enclosingType, translateFromLang
2217
2169
  function getFieldLanguageMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
2218
2170
  const translationMaps = [];
2219
2171
  for (const member of documentMembers) {
2220
- const parentPath = member.path.slice(0, -1), enclosingType = documentMembers.find((m) => sanity.pathToString(m.path) === sanity.pathToString(parentPath))?.schemaType ?? documentSchema, translations = langFn(
2172
+ const parentPath = member.path.slice(0, -1), enclosingType = documentMembers.find((m) => pathToString(m.path) === pathToString(parentPath))?.schemaType ?? documentSchema, translations = langFn(
2221
2173
  member,
2222
2174
  enclosingType,
2223
2175
  translateFromLanguageId,
@@ -2231,25 +2183,25 @@ function getFieldLanguageMap(documentSchema, documentMembers, translateFromLangu
2231
2183
  }
2232
2184
  return translationMaps;
2233
2185
  }
2234
- const FieldTranslationContext = react.createContext({
2186
+ const FieldTranslationContext = createContext({
2235
2187
  openFieldTranslation: () => {
2236
2188
  },
2237
2189
  translationLoading: !1
2238
2190
  });
2239
2191
  function useFieldTranslation() {
2240
- return react.useContext(FieldTranslationContext);
2192
+ return useContext(FieldTranslationContext);
2241
2193
  }
2242
2194
  function hasValuesToTranslate(fieldLanguageMaps, fromLanguage, basePath2) {
2243
2195
  return fieldLanguageMaps?.some(
2244
- (map) => map.inputLanguageId === fromLanguage?.id && map.inputPath && sanity.pathToString(map.inputPath).startsWith(sanity.pathToString(basePath2))
2196
+ (map) => map.inputLanguageId === fromLanguage?.id && map.inputPath && pathToString(map.inputPath).startsWith(pathToString(basePath2))
2245
2197
  );
2246
2198
  }
2247
2199
  function FieldTranslationProvider(props) {
2248
- const { config: assistConfig } = useAiAssistanceConfig(), apiClient = useApiClient(assistConfig.__customApiClient), styleguide = assistConfig.translate?.styleguide, config = assistConfig.translate?.field, { translate: runTranslate } = useTranslate(apiClient), [dialogOpen, setDialogOpen] = react.useState(!1), [fieldTranslationParams, setFieldTranslationParams] = react.useState(), [languages, setLanguages] = react.useState(), [fromLanguage, setFromLanguage] = react.useState(void 0), [toLanguages, setToLanguages] = react.useState(void 0), [fieldLanguageMaps, setFieldLanguageMaps] = react.useState(), close = react.useCallback(() => {
2200
+ const { config: assistConfig } = useAiAssistanceConfig(), apiClient = useApiClient(assistConfig.__customApiClient), styleguide = assistConfig.translate?.styleguide, config = assistConfig.translate?.field, { translate: runTranslate } = useTranslate(apiClient), [dialogOpen, setDialogOpen] = useState(!1), [fieldTranslationParams, setFieldTranslationParams] = useState(), [languages, setLanguages] = useState(), [fromLanguage, setFromLanguage] = useState(void 0), [toLanguages, setToLanguages] = useState(void 0), [fieldLanguageMaps, setFieldLanguageMaps] = useState(), close = useCallback(() => {
2249
2201
  setDialogOpen(!1), setLanguages(void 0), setFieldTranslationParams(void 0);
2250
- }, []), languageClient = sanity.useClient({
2202
+ }, []), languageClient = useClient({
2251
2203
  apiVersion: config?.apiVersion ?? API_VERSION_WITH_EXTENDED_TYPES
2252
- }), documentId = fieldTranslationParams?.document?._id, id = react.useId(), selectFromLanguage = react.useCallback(
2204
+ }), documentId = fieldTranslationParams?.document?._id, id = useId(), selectFromLanguage = useCallback(
2253
2205
  (from, languages2, params) => {
2254
2206
  const { document: document2, documentSchema } = params ?? {};
2255
2207
  if (setFromLanguage(from), !document2 || !documentSchema || !params || !languages2) {
@@ -2274,7 +2226,7 @@ function FieldTranslationProvider(props) {
2274
2226
  setFieldLanguageMaps(void 0);
2275
2227
  },
2276
2228
  [config]
2277
- ), toggleToLanguage = react.useCallback(
2229
+ ), toggleToLanguage = useCallback(
2278
2230
  (toggledLang, toLanguages2, languages2) => {
2279
2231
  if (!languages2 || !fromLanguage)
2280
2232
  return;
@@ -2289,7 +2241,7 @@ function FieldTranslationProvider(props) {
2289
2241
  );
2290
2242
  },
2291
2243
  [fromLanguage]
2292
- ), openFieldTranslation = react.useCallback(
2244
+ ), openFieldTranslation = useCallback(
2293
2245
  async (params) => {
2294
2246
  setDialogOpen(!0);
2295
2247
  const languageParams = getLanguageParams(config?.selectLanguageParams, params.document), languages2 = await (typeof config?.languages == "function" ? config?.languages(languageClient, languageParams) : Promise.resolve(config?.languages));
@@ -2298,10 +2250,10 @@ function FieldTranslationProvider(props) {
2298
2250
  fromLanguage2 ? selectFromLanguage(fromLanguage2, languages2, params) : console.error("No languages available for selected language params", languageParams);
2299
2251
  },
2300
2252
  [selectFromLanguage, config, languageClient]
2301
- ), contextValue = react.useMemo(() => ({
2253
+ ), contextValue = useMemo(() => ({
2302
2254
  openFieldTranslation,
2303
2255
  translationLoading: !1
2304
- }), [openFieldTranslation]), runDisabled = !fromLanguage || !toLanguages?.length || !fieldLanguageMaps?.length || !documentId || !hasValuesToTranslate(fieldLanguageMaps, fromLanguage, fieldTranslationParams.translatePath), onRunTranslation = react.useCallback(() => {
2256
+ }), [openFieldTranslation]), runDisabled = !fromLanguage || !toLanguages?.length || !fieldLanguageMaps?.length || !documentId || !hasValuesToTranslate(fieldLanguageMaps, fromLanguage, fieldTranslationParams.translatePath), onRunTranslation = useCallback(() => {
2305
2257
  const translatePath = fieldTranslationParams?.translatePath;
2306
2258
  fieldLanguageMaps && documentId && translatePath && runTranslate({
2307
2259
  documentId,
@@ -2330,38 +2282,38 @@ function FieldTranslationProvider(props) {
2330
2282
  fieldTranslationParams?.conditionalMembers,
2331
2283
  fieldTranslationParams?.documentSchema,
2332
2284
  languageClient
2333
- ]), runButton = /* @__PURE__ */ jsxRuntime.jsx(
2334
- ui.Button,
2285
+ ]), runButton = /* @__PURE__ */ jsx(
2286
+ Button,
2335
2287
  {
2336
2288
  text: "Translate",
2337
2289
  tone: "primary",
2338
- icon: icons.PlayIcon,
2290
+ icon: PlayIcon,
2339
2291
  style: { width: "100%" },
2340
2292
  disabled: runDisabled,
2341
2293
  onClick: onRunTranslation
2342
2294
  }
2343
2295
  );
2344
- return /* @__PURE__ */ jsxRuntime.jsxs(FieldTranslationContext.Provider, { value: contextValue, children: [
2345
- dialogOpen ? /* @__PURE__ */ jsxRuntime.jsx(
2346
- ui.Dialog,
2296
+ return /* @__PURE__ */ jsxs(FieldTranslationContext.Provider, { value: contextValue, children: [
2297
+ dialogOpen ? /* @__PURE__ */ jsx(
2298
+ Dialog,
2347
2299
  {
2348
2300
  id,
2349
2301
  width: 1,
2350
2302
  open: dialogOpen,
2351
2303
  onClose: close,
2352
2304
  header: "Translate fields",
2353
- footer: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsxRuntime.jsx(
2354
- ui.Tooltip,
2305
+ footer: /* @__PURE__ */ jsx(Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsx(
2306
+ Tooltip,
2355
2307
  {
2356
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "There is nothing to translate in the selected from-language." }) }),
2308
+ content: /* @__PURE__ */ jsx(Flex, { padding: 2, children: /* @__PURE__ */ jsx(Text, { children: "There is nothing to translate in the selected from-language." }) }),
2357
2309
  placement: "top",
2358
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, children: runButton })
2310
+ children: /* @__PURE__ */ jsx(Flex, { flex: 1, children: runButton })
2359
2311
  }
2360
2312
  ) : runButton }),
2361
- children: languages ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { padding: 4, gap: 5, align: "flex-start", justify: "center", children: [
2362
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
2363
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginBottom: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "semibold", children: "From" }) }),
2364
- languages?.map((radioLanguage) => /* @__PURE__ */ jsxRuntime.jsx(
2313
+ children: languages ? /* @__PURE__ */ jsxs(Flex, { padding: 4, gap: 5, align: "flex-start", justify: "center", children: [
2314
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
2315
+ /* @__PURE__ */ jsx(Box, { marginBottom: 2, children: /* @__PURE__ */ jsx(Text, { weight: "semibold", children: "From" }) }),
2316
+ languages?.map((radioLanguage) => /* @__PURE__ */ jsx(
2365
2317
  FromLanguageRadio,
2366
2318
  {
2367
2319
  radioLanguage,
@@ -2373,9 +2325,9 @@ function FieldTranslationProvider(props) {
2373
2325
  radioLanguage.id
2374
2326
  ))
2375
2327
  ] }),
2376
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
2377
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginBottom: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "semibold", children: "To" }) }),
2378
- languages.map((checkboxLanguage) => /* @__PURE__ */ jsxRuntime.jsx(
2328
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
2329
+ /* @__PURE__ */ jsx(Box, { marginBottom: 2, children: /* @__PURE__ */ jsx(Text, { weight: "semibold", children: "To" }) }),
2330
+ languages.map((checkboxLanguage) => /* @__PURE__ */ jsx(
2379
2331
  ToLanguageCheckbox,
2380
2332
  {
2381
2333
  checkboxLanguage,
@@ -2387,9 +2339,9 @@ function FieldTranslationProvider(props) {
2387
2339
  checkboxLanguage.id
2388
2340
  ))
2389
2341
  ] })
2390
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { padding: 4, gap: 2, align: "flex-start", justify: "center", children: [
2391
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }),
2392
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading languages..." })
2342
+ ] }) : /* @__PURE__ */ jsxs(Flex, { padding: 4, gap: 2, align: "flex-start", justify: "center", children: [
2343
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Spinner, {}) }),
2344
+ /* @__PURE__ */ jsx(Text, { children: "Loading languages..." })
2393
2345
  ] })
2394
2346
  }
2395
2347
  ) : null,
@@ -2397,20 +2349,20 @@ function FieldTranslationProvider(props) {
2397
2349
  ] });
2398
2350
  }
2399
2351
  function ToLanguageCheckbox(props) {
2400
- const { checkboxLanguage, fromLanguage, toLanguages, toggleToLanguage, languages } = props, langId = checkboxLanguage.id, onChange = react.useCallback(
2352
+ const { checkboxLanguage, fromLanguage, toLanguages, toggleToLanguage, languages } = props, langId = checkboxLanguage.id, onChange = useCallback(
2401
2353
  () => toggleToLanguage(checkboxLanguage, toLanguages, languages),
2402
2354
  [toggleToLanguage, checkboxLanguage, toLanguages, languages]
2403
2355
  );
2404
- return /* @__PURE__ */ jsxRuntime.jsxs(
2405
- ui.Flex,
2356
+ return /* @__PURE__ */ jsxs(
2357
+ Flex,
2406
2358
  {
2407
2359
  gap: 3,
2408
2360
  align: "center",
2409
2361
  as: "label",
2410
2362
  style: langId === fromLanguage?.id ? { opacity: 0.5 } : void 0,
2411
2363
  children: [
2412
- /* @__PURE__ */ jsxRuntime.jsx(
2413
- ui.Checkbox,
2364
+ /* @__PURE__ */ jsx(
2365
+ Checkbox,
2414
2366
  {
2415
2367
  name: "toLang",
2416
2368
  value: langId,
@@ -2419,20 +2371,20 @@ function ToLanguageCheckbox(props) {
2419
2371
  disabled: langId === fromLanguage?.id
2420
2372
  }
2421
2373
  ),
2422
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: langId === fromLanguage?.id, children: checkboxLanguage.title ?? langId })
2374
+ /* @__PURE__ */ jsx(Text, { muted: langId === fromLanguage?.id, children: checkboxLanguage.title ?? langId })
2423
2375
  ]
2424
2376
  },
2425
2377
  langId
2426
2378
  );
2427
2379
  }
2428
2380
  function FromLanguageRadio(props) {
2429
- const { languages, radioLanguage, selectFromLanguage, fromLanguage, fieldTranslationParams } = props, langId = radioLanguage.id, onChange = react.useCallback(
2381
+ const { languages, radioLanguage, selectFromLanguage, fromLanguage, fieldTranslationParams } = props, langId = radioLanguage.id, onChange = useCallback(
2430
2382
  () => selectFromLanguage(radioLanguage, languages, fieldTranslationParams),
2431
2383
  [selectFromLanguage, radioLanguage, languages, fieldTranslationParams]
2432
2384
  );
2433
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 3, align: "center", as: "label", children: [
2434
- /* @__PURE__ */ jsxRuntime.jsx(
2435
- ui.Radio,
2385
+ return /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", as: "label", children: [
2386
+ /* @__PURE__ */ jsx(
2387
+ Radio,
2436
2388
  {
2437
2389
  name: "fromLang",
2438
2390
  value: langId,
@@ -2440,7 +2392,7 @@ function FromLanguageRadio(props) {
2440
2392
  onChange
2441
2393
  }
2442
2394
  ),
2443
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: radioLanguage.title ?? radioLanguage.id })
2395
+ /* @__PURE__ */ jsx(Text, { children: radioLanguage.title ?? radioLanguage.id })
2444
2396
  ] }, langId);
2445
2397
  }
2446
2398
  const hiddenTypes = [
@@ -2540,7 +2492,7 @@ function serializeMember(schema, type, name, options2) {
2540
2492
  }
2541
2493
  function serializeInlineOf(blockSchemaType, schema, options2) {
2542
2494
  const childrenType = blockSchemaType.fields.find((f) => f.name === "children")?.type;
2543
- if (!(!childrenType || !sanity.isArraySchemaType(childrenType)))
2495
+ if (!(!childrenType || !isArraySchemaType(childrenType)))
2544
2496
  return arrayOf(
2545
2497
  {
2546
2498
  of: childrenType.of.filter((t) => !isType(t, "span"))
@@ -2551,7 +2503,7 @@ function serializeInlineOf(blockSchemaType, schema, options2) {
2551
2503
  }
2552
2504
  function serializeAnnotations(blockSchemaType, schema, options2) {
2553
2505
  const marksType = blockSchemaType.fields.find((f) => f.name === "markDefs")?.type;
2554
- if (!(!marksType || !sanity.isArraySchemaType(marksType)))
2506
+ if (!(!marksType || !isArraySchemaType(marksType)))
2555
2507
  return arrayOf(marksType, schema, options2);
2556
2508
  }
2557
2509
  function arrayOf(arrayType, schema, options2) {
@@ -2559,7 +2511,7 @@ function arrayOf(arrayType, schema, options2) {
2559
2511
  }
2560
2512
  function refToTypeNames(type) {
2561
2513
  return type.to.map((t) => ({
2562
- type: sanity.typed(t.name)
2514
+ type: typed(t.name)
2563
2515
  }));
2564
2516
  }
2565
2517
  function removeUndef(obj) {
@@ -2579,13 +2531,13 @@ function createFieldRefCache() {
2579
2531
  return getRefsForType;
2580
2532
  }
2581
2533
  function AiAssistanceConfigProvider(props) {
2582
- const [status, setStatus] = react.useState(), [error, setError] = react.useState(), apiClient = useApiClient(props.config?.__customApiClient), { getInstructStatus, loading: statusLoading } = useGetInstructStatus(apiClient), { initInstruct, loading: initLoading } = useInitInstruct(apiClient), schema = sanity.useSchema(), serializedTypes = react.useMemo(() => serializeSchema(schema, { leanFormat: !0 }), [schema]), { getFieldRefs: getFieldRefs2, getFieldRefsByTypePath } = useFieldRefGetters(schema);
2583
- react.useEffect(() => {
2534
+ const [status, setStatus] = useState(), [error, setError] = useState(), apiClient = useApiClient(props.config?.__customApiClient), { getInstructStatus, loading: statusLoading } = useGetInstructStatus(apiClient), { initInstruct, loading: initLoading } = useInitInstruct(apiClient), schema = useSchema(), serializedTypes = useMemo(() => serializeSchema(schema, { leanFormat: !0 }), [schema]), { getFieldRefs: getFieldRefs2, getFieldRefsByTypePath } = useFieldRefGetters(schema);
2535
+ useEffect(() => {
2584
2536
  getInstructStatus().then((s) => setStatus(s)).catch((e) => {
2585
2537
  console.error(e), setError(e);
2586
2538
  });
2587
2539
  }, [getInstructStatus]);
2588
- const init = react.useCallback(async () => {
2540
+ const init = useCallback(async () => {
2589
2541
  setError(void 0);
2590
2542
  try {
2591
2543
  await initInstruct();
@@ -2594,7 +2546,7 @@ function AiAssistanceConfigProvider(props) {
2594
2546
  } catch (e) {
2595
2547
  console.error("Failed to init ai assistance", e), setError(e);
2596
2548
  }
2597
- }, [initInstruct, getInstructStatus, setStatus]), { config, children } = props, context = react.useMemo(() => ({
2549
+ }, [initInstruct, getInstructStatus, setStatus]), { config, children } = props, context = useMemo(() => ({
2598
2550
  config,
2599
2551
  status,
2600
2552
  statusLoading,
@@ -2615,10 +2567,10 @@ function AiAssistanceConfigProvider(props) {
2615
2567
  getFieldRefs2,
2616
2568
  getFieldRefsByTypePath
2617
2569
  ]);
2618
- return /* @__PURE__ */ jsxRuntime.jsx(AiAssistanceConfigContext.Provider, { value: context, children });
2570
+ return /* @__PURE__ */ jsx(AiAssistanceConfigContext.Provider, { value: context, children });
2619
2571
  }
2620
2572
  function useFieldRefGetters(schema) {
2621
- return react.useMemo(() => {
2573
+ return useMemo(() => {
2622
2574
  const getForSchemaType = createFieldRefCache();
2623
2575
  function getRefsForType(documentType) {
2624
2576
  const schemaType = schema.get(documentType);
@@ -2633,23 +2585,23 @@ function useFieldRefGetters(schema) {
2633
2585
  }, [schema]);
2634
2586
  }
2635
2587
  function AssistLayout(props) {
2636
- const [connectors, setConnectors] = react.useState([]);
2637
- return /* @__PURE__ */ jsxRuntime.jsx(AiAssistanceConfigProvider, { config: props.config, children: /* @__PURE__ */ jsxRuntime.jsx(RunInstructionProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(FieldTranslationProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(ConnectorsProvider, { onConnectorsChange: setConnectors, children: [
2588
+ const [connectors, setConnectors] = useState([]);
2589
+ return /* @__PURE__ */ jsx(AiAssistanceConfigProvider, { config: props.config, children: /* @__PURE__ */ jsx(RunInstructionProvider, { children: /* @__PURE__ */ jsx(FieldTranslationProvider, { children: /* @__PURE__ */ jsxs(ConnectorsProvider, { onConnectorsChange: setConnectors, children: [
2638
2590
  props.renderDefault(props),
2639
- /* @__PURE__ */ jsxRuntime.jsx(ui.ThemeProvider, { tone: "default", children: /* @__PURE__ */ jsxRuntime.jsx(AssistConnectorsOverlay, { connectors }) })
2591
+ /* @__PURE__ */ jsx(ThemeProvider, { tone: "default", children: /* @__PURE__ */ jsx(AssistConnectorsOverlay, { connectors }) })
2640
2592
  ] }) }) }) });
2641
2593
  }
2642
- const ImageContext = react.createContext({});
2594
+ const ImageContext = createContext({});
2643
2595
  function ImageContextProvider(props) {
2644
- const { schemaType, path, value, readOnly } = props, assetRef = value?.asset?._ref, { selectedReleaseId } = structure.useDocumentPane(), [assetRefState, setAssetRefState] = react.useState(assetRef), { assistableDocumentId, documentSchemaType } = useAssistDocumentContext(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption } = useGenerateCaption(apiClient), { isSyncing } = sanity.useSyncState(
2645
- sanity.getPublishedId(assistableDocumentId),
2596
+ const { schemaType, path, value, readOnly } = props, assetRef = value?.asset?._ref, { selectedReleaseId } = useDocumentPane(), [assetRefState, setAssetRefState] = useState(assetRef), { assistableDocumentId, documentSchemaType } = useAssistDocumentContext(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption } = useGenerateCaption(apiClient), { isSyncing } = useSyncState(
2597
+ getPublishedId(assistableDocumentId),
2646
2598
  documentSchemaType.name,
2647
2599
  selectedReleaseId
2648
- ), isShowingOlderRevision = !!structure.usePaneRouter().params?.rev;
2649
- react.useEffect(() => {
2600
+ ), isShowingOlderRevision = !!usePaneRouter().params?.rev;
2601
+ useEffect(() => {
2650
2602
  const descriptionField = getDescriptionFieldOption(schemaType);
2651
2603
  assetRef && assistableDocumentId && descriptionField?.updateOnImageChange && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly && (setAssetRefState(assetRef), canUseAssist(status) && generateCaption({
2652
- path: sanity.pathToString([...path, descriptionField.path]),
2604
+ path: pathToString([...path, descriptionField.path]),
2653
2605
  documentId: assistableDocumentId
2654
2606
  }));
2655
2607
  }, [
@@ -2664,27 +2616,27 @@ function ImageContextProvider(props) {
2664
2616
  readOnly,
2665
2617
  isShowingOlderRevision
2666
2618
  ]);
2667
- const context = react.useMemo(() => {
2619
+ const context = useMemo(() => {
2668
2620
  const descriptionField = getDescriptionFieldOption(schemaType), imageInstructionField = getImageInstructionFieldOption(schemaType);
2669
2621
  return {
2670
- imageDescriptionPath: descriptionField?.path ? sanity.pathToString([...path, descriptionField.path]) : void 0,
2671
- imageInstructionPath: imageInstructionField ? sanity.pathToString([...path, imageInstructionField]) : void 0,
2622
+ imageDescriptionPath: descriptionField?.path ? pathToString([...path, descriptionField.path]) : void 0,
2623
+ imageInstructionPath: imageInstructionField ? pathToString([...path, imageInstructionField]) : void 0,
2672
2624
  assetRef
2673
2625
  };
2674
2626
  }, [schemaType, path, assetRef]);
2675
- return /* @__PURE__ */ jsxRuntime.jsx(ImageContext.Provider, { value: context, children: props.renderDefault(props) });
2627
+ return /* @__PURE__ */ jsx(ImageContext.Provider, { value: context, children: props.renderDefault(props) });
2676
2628
  }
2677
2629
  function IconInput(props) {
2678
- const { value, onChange } = props, id = react.useId(), items = react.useMemo(
2679
- () => Object.entries(icons.icons).map(([key, icon]) => /* @__PURE__ */ jsxRuntime.jsx(IconItem, { iconKey: key, icon, onChange }, key)),
2630
+ const { value, onChange } = props, id = useId(), items = useMemo(
2631
+ () => Object.entries(icons).map(([key, icon]) => /* @__PURE__ */ jsx(IconItem, { iconKey: key, icon, onChange }, key)),
2680
2632
  [onChange]
2681
- ), selectedIcon = react.useMemo(() => getIcon(value), [value]);
2682
- return /* @__PURE__ */ jsxRuntime.jsx(
2683
- ui.MenuButton,
2633
+ ), selectedIcon = useMemo(() => getIcon(value), [value]);
2634
+ return /* @__PURE__ */ jsx(
2635
+ MenuButton,
2684
2636
  {
2685
- button: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { icon: selectedIcon, title: "Select icon", padding: 3, mode: "ghost", radius: 1 }),
2637
+ button: /* @__PURE__ */ jsx(Button, { icon: selectedIcon, title: "Select icon", padding: 3, mode: "ghost", radius: 1 }),
2686
2638
  id,
2687
- menu: /* @__PURE__ */ jsxRuntime.jsx(ui.Menu, { style: { maxHeight: 300 }, children: items }),
2639
+ menu: /* @__PURE__ */ jsx(Menu, { style: { maxHeight: 300 }, children: items }),
2688
2640
  popover: { portal: !0 }
2689
2641
  }
2690
2642
  );
@@ -2694,19 +2646,19 @@ function IconItem({
2694
2646
  iconKey: key,
2695
2647
  onChange
2696
2648
  }) {
2697
- const onClick = react.useCallback(() => onChange(sanity.set(key)), [onChange, key]);
2698
- return /* @__PURE__ */ jsxRuntime.jsx(ui.MenuItem, { icon, title: key, text: key, onClick });
2649
+ const onClick = useCallback(() => onChange(set(key)), [onChange, key]);
2650
+ return /* @__PURE__ */ jsx(MenuItem, { icon, title: key, text: key, onClick });
2699
2651
  }
2700
2652
  function getIcon(iconName) {
2701
- return Object.entries(icons.icons).find(([key]) => key === iconName)?.[1] ?? icons.icons.sparkles;
2653
+ return Object.entries(icons).find(([key]) => key === iconName)?.[1] ?? icons.sparkles;
2702
2654
  }
2703
2655
  function useAssistSupported(path, schemaType) {
2704
- return react.useMemo(() => isAssistSupported(schemaType), [schemaType]);
2656
+ return useMemo(() => isAssistSupported(schemaType), [schemaType]);
2705
2657
  }
2706
2658
  const translateActions = {
2707
2659
  name: "sanity-assist-translate",
2708
2660
  useAction(props) {
2709
- const { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), client = sanity.useClient({ apiVersion: API_VERSION_WITH_EXTENDED_TYPES }), {
2661
+ const { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), client = useClient({ apiVersion: API_VERSION_WITH_EXTENDED_TYPES }), {
2710
2662
  schemaType: fieldSchemaType,
2711
2663
  path,
2712
2664
  documentId,
@@ -2714,21 +2666,21 @@ const translateActions = {
2714
2666
  documentIsAssistable
2715
2667
  } = props, isDocumentLevel = path.length === 0, readOnly = fieldSchemaType.readOnly === !0, docTransTypes = config.translate?.document?.documentTypes, options2 = fieldSchemaType?.options, addFieldAction = isDocumentLevel || options2?.aiAssist?.translateAction, fieldTransEnabled = addFieldAction && documentSchemaType && config.translate?.field?.documentTypes?.includes(documentSchemaType.name), documentTranslationEnabled = addFieldAction && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || docTransTypes?.includes(documentSchemaType.name));
2716
2668
  if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
2717
- const { value: documentValue, onChange: documentOnChange, formState } = structure.useDocumentPane(), docRef = react.useRef(documentValue);
2669
+ const { value: documentValue, onChange: documentOnChange, formState } = useDocumentPane(), docRef = useRef(documentValue);
2718
2670
  docRef.current = documentValue;
2719
- const formStateRef = react.useRef(formState);
2671
+ const formStateRef = useRef(formState);
2720
2672
  formStateRef.current = formState;
2721
2673
  const translationApi = useTranslate(apiClient), translate = useDraftDelayedTask({
2722
2674
  documentOnChange,
2723
2675
  isDocAssistable: documentIsAssistable ?? !1,
2724
2676
  task: translationApi.translate
2725
- }), styleguide = config.translate?.styleguide, languagePath = config.translate?.document?.languageField, translateDocumentAction = react.useMemo(() => {
2677
+ }), styleguide = config.translate?.styleguide, languagePath = config.translate?.document?.languageField, translateDocumentAction = useMemo(() => {
2726
2678
  if (!languagePath || !documentTranslationEnabled)
2727
2679
  return;
2728
2680
  const title = path.length ? "Translate" : "Translate document";
2729
2681
  return {
2730
2682
  type: "action",
2731
- icon: translationApi.loading ? () => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { height: 17 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { transform: "translateY(6px)" } }) }) : icons.TranslateIcon,
2683
+ icon: translationApi.loading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : TranslateIcon,
2732
2684
  title,
2733
2685
  onAction: () => {
2734
2686
  translationApi.loading || !languagePath || !documentId || translate({
@@ -2761,10 +2713,10 @@ const translateActions = {
2761
2713
  documentOnChange,
2762
2714
  isDocAssistable: documentIsAssistable ?? !1,
2763
2715
  task: fieldTranslate.openFieldTranslation
2764
- }), maxDepth2 = config.translate?.field?.maxPathDepth, translateFieldsAction = react.useMemo(
2716
+ }), maxDepth2 = config.translate?.field?.maxPathDepth, translateFieldsAction = useMemo(
2765
2717
  () => fieldTransEnabled ? {
2766
2718
  type: "action",
2767
- icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { height: 17 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { transform: "translateY(6px)" } }) }) : icons.TranslateIcon,
2719
+ icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : TranslateIcon,
2768
2720
  title: "Translate fields...",
2769
2721
  onAction: () => {
2770
2722
  fieldTranslate.translationLoading || !documentId || (formStateRef.current && getConditionalMembers(formStateRef.current), openFieldTranslation({
@@ -2791,7 +2743,7 @@ const translateActions = {
2791
2743
  maxDepth2
2792
2744
  ]
2793
2745
  );
2794
- return react.useMemo(() => {
2746
+ return useMemo(() => {
2795
2747
  if (status?.initialized)
2796
2748
  return {
2797
2749
  type: "group",
@@ -2808,12 +2760,12 @@ const translateActions = {
2808
2760
  }, generateCaptionsActions = {
2809
2761
  name: "sanity-assist-generate-captions",
2810
2762
  useAction(props) {
2811
- const pathKey = usePathKey(props.path), { openInspector } = structure.useDocumentPane(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption, loading } = useGenerateCaption(apiClient), imageContext = react.useContext(ImageContext);
2763
+ const pathKey = usePathKey(props.path), { openInspector } = useDocumentPane(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption, loading } = useGenerateCaption(apiClient), imageContext = useContext(ImageContext);
2812
2764
  if (imageContext && pathKey === imageContext?.imageDescriptionPath) {
2813
2765
  const { assistableDocumentId } = useAssistDocumentContext();
2814
- return react.useMemo(() => ({
2766
+ return useMemo(() => ({
2815
2767
  type: "action",
2816
- icon: loading ? () => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { height: 17 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { transform: "translateY(6px)" } }) }) : icons.ImageIcon,
2768
+ icon: loading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : ImageIcon,
2817
2769
  title: "Generate image description",
2818
2770
  onAction: () => {
2819
2771
  if (!loading) {
@@ -2844,12 +2796,12 @@ const translateActions = {
2844
2796
  }, generateImagActions = {
2845
2797
  name: "sanity-assist-generate-image",
2846
2798
  useAction(props) {
2847
- const pathKey = usePathKey(props.path), { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateImage, loading } = useGenerateImage(apiClient), imageContext = react.useContext(ImageContext);
2799
+ const pathKey = usePathKey(props.path), { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateImage, loading } = useGenerateImage(apiClient), imageContext = useContext(ImageContext);
2848
2800
  if (imageContext && pathKey === imageContext?.imageInstructionPath) {
2849
2801
  const { assistableDocumentId } = useAssistDocumentContext();
2850
- return react.useMemo(() => ({
2802
+ return useMemo(() => ({
2851
2803
  type: "action",
2852
- icon: loading ? () => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { height: 17 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { transform: "translateY(6px)" } }) }) : icons.ImageIcon,
2804
+ icon: loading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : ImageIcon,
2853
2805
  title: "Generate image from prompt",
2854
2806
  onAction: () => {
2855
2807
  loading || generateImage({ path: pathKey, documentId: assistableDocumentId });
@@ -2861,15 +2813,15 @@ const translateActions = {
2861
2813
  }
2862
2814
  };
2863
2815
  function PrivateIcon() {
2864
- return /* @__PURE__ */ jsxRuntime.jsx(
2865
- ui.Tooltip,
2816
+ return /* @__PURE__ */ jsx(
2817
+ Tooltip,
2866
2818
  {
2867
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Only visible to you" }),
2819
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Only visible to you" }),
2868
2820
  fallbackPlacements: ["bottom"],
2869
2821
  padding: 2,
2870
2822
  placement: "top",
2871
2823
  portal: !0,
2872
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.LockIcon, {})
2824
+ children: /* @__PURE__ */ jsx(LockIcon, {})
2873
2825
  }
2874
2826
  );
2875
2827
  }
@@ -2918,12 +2870,12 @@ function defineAssistFieldActionGroup(group) {
2918
2870
  function useCustomFieldActions(props) {
2919
2871
  const {
2920
2872
  config: { fieldActions }
2921
- } = useAiAssistanceConfig(), { addSyntheticTask, removeSyntheticTask } = useAssistDocumentContext(), schemaId = sanity.useWorkspaceSchemaId(), { push: pushToast } = ui.useToast(), configActions = fieldActions?.useFieldActions?.({
2873
+ } = useAiAssistanceConfig(), { addSyntheticTask, removeSyntheticTask } = useAssistDocumentContext(), schemaId = useWorkspaceSchemaId(), { push: pushToast } = useToast(), configActions = fieldActions?.useFieldActions?.({
2922
2874
  ...props,
2923
2875
  schemaId,
2924
2876
  path: props.path
2925
2877
  });
2926
- return react.useMemo(() => {
2878
+ return useMemo(() => {
2927
2879
  const title = fieldActions?.title, customActions = configActions?.filter(isDefined).map((node) => createSafeNode({
2928
2880
  node,
2929
2881
  pushToast,
@@ -3012,30 +2964,30 @@ const assistFieldActions = {
3012
2964
  selectedPath,
3013
2965
  assistableDocumentId,
3014
2966
  fieldRefsByTypePath
3015
- } = useAssistDocumentContext(), { value: docValue, formState } = structure.useDocumentPane(), docValueRef = react.useRef(docValue), formStateRef = react.useRef(formState);
2967
+ } = useAssistDocumentContext(), { value: docValue, formState } = useDocumentPane(), docValueRef = useRef(docValue), formStateRef = useRef(formState);
3016
2968
  formStateRef.current = formState;
3017
- const currentUser = sanity.useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
2969
+ const currentUser = useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
3018
2970
  documentOnChange,
3019
2971
  isDocAssistable: documentIsAssistable ?? !1
3020
- }), isSelectable = !!useSelectedField(documentSchemaType, typePath), assistSupported = useAssistSupported(props.path, schemaType) && isSelectable && isSchemaAssistEnabled(documentSchemaType) && schemaType.readOnly !== !0, fieldAssist = react.useMemo(
2972
+ }), isSelectable = !!useSelectedField(documentSchemaType, typePath), assistSupported = useAssistSupported(props.path, schemaType) && isSelectable && isSchemaAssistEnabled(documentSchemaType) && schemaType.readOnly !== !0, fieldAssist = useMemo(
3021
2973
  () => (assistDocument?.fields ?? []).find(
3022
2974
  (f) => f.path === typePath || pathKey === documentRootKey && f.path === pathKey
3023
2975
  ),
3024
2976
  [assistDocument?.fields, pathKey, typePath]
3025
2977
  ), fieldAssistKey = fieldAssist?._key, isSelected = inspector?.name === aiInspectorId && pathKey === selectedPath, imageCaptionAction = generateCaptionsActions.useAction(props), imageGenAction = generateImagActions.useAction(props), translateAction = translateActions.useAction(
3026
- sanity.typed({
2978
+ typed({
3027
2979
  ...props,
3028
2980
  documentId: assistableDocumentId,
3029
2981
  documentIsAssistable,
3030
2982
  documentSchemaType
3031
2983
  })
3032
- ), manageInstructions = react.useCallback(
2984
+ ), manageInstructions = useCallback(
3033
2985
  () => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
3034
2986
  [fieldPathParam]: pathKey,
3035
2987
  [instructionParam]: void 0
3036
2988
  }),
3037
2989
  [openInspector, closeInspector, isSelected, pathKey]
3038
- ), onInstructionAction = react.useCallback(
2990
+ ), onInstructionAction = useCallback(
3039
2991
  (instruction2) => {
3040
2992
  !pathKey || !fieldAssistKey || !assistDocumentId2 || !assistableDocumentId || requestRunInstruction({
3041
2993
  documentId: assistableDocumentId,
@@ -3054,16 +3006,16 @@ const assistFieldActions = {
3054
3006
  assistDocumentId2,
3055
3007
  fieldAssistKey
3056
3008
  ]
3057
- ), privateInstructions = react.useMemo(
3009
+ ), privateInstructions = useMemo(
3058
3010
  () => fieldAssist?.instructions?.filter((i) => i.userId && i.userId === currentUser?.id) || [],
3059
3011
  [fieldAssist?.instructions, currentUser]
3060
- ), sharedInstructions = react.useMemo(
3012
+ ), sharedInstructions = useMemo(
3061
3013
  () => fieldAssist?.instructions?.filter((i) => !i.userId) || [],
3062
3014
  [fieldAssist?.instructions]
3063
- ), instructions = react.useMemo(
3015
+ ), instructions = useMemo(
3064
3016
  () => [...privateInstructions, ...sharedInstructions],
3065
3017
  [privateInstructions, sharedInstructions]
3066
- ), runInstructionsGroup = react.useMemo(() => instructions?.length || imageCaptionAction || translateAction || imageGenAction ? {
3018
+ ), runInstructionsGroup = useMemo(() => instructions?.length || imageCaptionAction || translateAction || imageGenAction ? {
3067
3019
  type: "group",
3068
3020
  icon: () => null,
3069
3021
  title: "Run instructions",
@@ -3091,20 +3043,20 @@ const assistFieldActions = {
3091
3043
  imageCaptionAction,
3092
3044
  translateAction,
3093
3045
  imageGenAction
3094
- ]), getDocumentValue = react.useCallback(() => docValueRef.current, []), getConditionalPaths = react.useCallback(() => (formStateRef.current ? getConditionalMembers(formStateRef.current) : []).flatMap(
3046
+ ]), getDocumentValue = useCallback(() => docValueRef.current, []), getConditionalPaths = useCallback(() => (formStateRef.current ? getConditionalMembers(formStateRef.current) : []).flatMap(
3095
3047
  (cm) => {
3096
- const path = sanity.stringToPath(cm.path);
3048
+ const path = stringToPath(cm.path);
3097
3049
  return path.some((s) => typeof s == "number") ? [] : {
3098
3050
  ...cm,
3099
3051
  path
3100
3052
  };
3101
3053
  }
3102
- ), []), parentSchemaType = react.useMemo(() => {
3054
+ ), []), parentSchemaType = useMemo(() => {
3103
3055
  if (props.path.length) {
3104
3056
  if (props.path.length === 1)
3105
3057
  return documentSchemaType;
3106
3058
  } else return;
3107
- const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, sanity.pathToString(parentPath));
3059
+ const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, pathToString(parentPath));
3108
3060
  return typePath2 ? fieldRefsByTypePath[typePath2]?.schemaType : void 0;
3109
3061
  }, [fieldRefsByTypePath, props.path, documentSchemaType]), customActions = useCustomFieldActions({
3110
3062
  actionType: props.path.length ? "field" : "document",
@@ -3115,19 +3067,19 @@ const assistFieldActions = {
3115
3067
  getDocumentValue,
3116
3068
  getConditionalPaths,
3117
3069
  parentSchemaType
3118
- }), manageInstructionsItem = react.useMemo(
3070
+ }), manageInstructionsItem = useMemo(
3119
3071
  () => ({
3120
3072
  type: "action",
3121
- icon: icons.ControlsIcon,
3073
+ icon: ControlsIcon,
3122
3074
  title: "Manage instructions",
3123
3075
  onAction: manageInstructions,
3124
3076
  selected: isSelected
3125
3077
  }),
3126
3078
  [manageInstructions, isSelected]
3127
- ), group = react.useMemo(
3079
+ ), group = useMemo(
3128
3080
  () => ({
3129
3081
  type: "group",
3130
- icon: icons.SparklesIcon,
3082
+ icon: SparklesIcon,
3131
3083
  title: pluginTitleShort,
3132
3084
  children: [
3133
3085
  runInstructionsGroup,
@@ -3149,11 +3101,11 @@ const assistFieldActions = {
3149
3101
  imageGenAction,
3150
3102
  customActions
3151
3103
  ]
3152
- ), emptyAction = react.useMemo(
3104
+ ), emptyAction = useMemo(
3153
3105
  () => ({
3154
3106
  type: "action",
3155
3107
  hidden: !assistSupported,
3156
- icon: icons.SparklesIcon,
3108
+ icon: SparklesIcon,
3157
3109
  onAction: manageInstructions,
3158
3110
  renderAsButton: !0,
3159
3111
  title: pluginTitleShort,
@@ -3178,11 +3130,11 @@ function instructionItem(props) {
3178
3130
  }
3179
3131
  function createAssistDocumentPresence(documentId) {
3180
3132
  return function() {
3181
- return documentId ? /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentPresence, {}) : null;
3133
+ return documentId ? /* @__PURE__ */ jsx(AssistDocumentPresence, {}) : null;
3182
3134
  };
3183
3135
  }
3184
3136
  function AssistDocumentPresence() {
3185
- const { assistDocument, syntheticTasks } = useAssistDocumentContext(), anyPresence = react.useMemo(() => {
3137
+ const { assistDocument, syntheticTasks } = useAssistDocumentContext(), anyPresence = useMemo(() => {
3186
3138
  const anyPresence2 = [...assistDocument?.tasks ?? [], ...syntheticTasks ?? []].filter((run) => !run.ended && !run.reason)?.flatMap((run) => run.presence ?? []).find((f) => f.started && (/* @__PURE__ */ new Date()).getTime() - new Date(f.started).getTime() < 3e4);
3187
3139
  if (anyPresence2)
3188
3140
  return aiPresence(anyPresence2, []);
@@ -3195,19 +3147,19 @@ function AssistDocumentPresence() {
3195
3147
  []
3196
3148
  ) : void 0;
3197
3149
  }, [assistDocument?.tasks, syntheticTasks]);
3198
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, justify: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { gap: 2, align: "center", children: anyPresence && /* @__PURE__ */ jsxRuntime.jsx(AiFieldPresence, { presence: anyPresence }) }) }) });
3150
+ return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(Flex, { flex: 1, justify: "flex-end", children: /* @__PURE__ */ jsx(Flex, { gap: 2, align: "center", children: anyPresence && /* @__PURE__ */ jsx(AiFieldPresence, { presence: anyPresence }) }) }) });
3199
3151
  }
3200
3152
  function BackToInstructionListLink() {
3201
- const { openInspector } = structure.useDocumentPane(), goBack = react.useCallback(
3153
+ const { openInspector } = useDocumentPane(), goBack = useCallback(
3202
3154
  () => openInspector(aiInspectorId, { [instructionParam]: void 0 }),
3203
3155
  [openInspector]
3204
3156
  );
3205
- return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
3206
- ui.Button,
3157
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
3158
+ Button,
3207
3159
  {
3208
3160
  as: "a",
3209
3161
  fontSize: 1,
3210
- icon: icons.ArrowLeftIcon,
3162
+ icon: ArrowLeftIcon,
3211
3163
  mode: "bleed",
3212
3164
  padding: 1,
3213
3165
  space: 2,
@@ -3217,38 +3169,38 @@ function BackToInstructionListLink() {
3217
3169
  }
3218
3170
  ) });
3219
3171
  }
3220
- const SelectedFieldContext = react.createContext(void 0), SelectedFieldContextProvider = SelectedFieldContext.Provider, EMPTY_FIELDS = [];
3172
+ const SelectedFieldContext = createContext(void 0), SelectedFieldContextProvider = SelectedFieldContext.Provider, EMPTY_FIELDS = [];
3221
3173
  function AssistDocumentForm(props) {
3222
- return props.readOnly ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { border: !0, tone: "caution", padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: " You do not have sufficient permissions to manage instructions." }) }) : /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentFormEditable, { ...props });
3174
+ return props.readOnly ? /* @__PURE__ */ jsx(Card, { border: !0, tone: "caution", padding: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, children: " You do not have sufficient permissions to manage instructions." }) }) : /* @__PURE__ */ jsx(AssistDocumentFormEditable, { ...props });
3223
3175
  }
3224
3176
  function AssistDocumentFormEditable(props) {
3225
- const { onChange } = props, value = props.value, id = value?._id, fields = value?.fields, { params, setParams } = useAiPaneRouter(), pathKey = params[fieldPathParam], { typePath, documentType: targetDocumentType } = react.useContext(AssistTypeContext), instruction2 = params[instructionParam], activeKey = react.useMemo(() => {
3177
+ const { onChange } = props, value = props.value, id = value?._id, fields = value?.fields, { params, setParams } = useAiPaneRouter(), pathKey = params[fieldPathParam], { typePath, documentType: targetDocumentType } = useContext(AssistTypeContext), instruction2 = params[instructionParam], activeKey = useMemo(() => {
3226
3178
  if (typePath)
3227
3179
  return (fields ?? EMPTY_FIELDS).find((f) => f.path === typePath)?._key;
3228
- }, [fields, typePath]), activePath = react.useMemo(() => {
3180
+ }, [fields, typePath]), activePath = useMemo(() => {
3229
3181
  if (!activeKey)
3230
3182
  return;
3231
3183
  const base = ["fields", { _key: activeKey }];
3232
3184
  return instruction2 ? [...base, "instructions", { _key: instruction2 }] : base;
3233
- }, [activeKey, instruction2]), schema = sanity.useSchema(), documentSchema = react.useMemo(() => {
3185
+ }, [activeKey, instruction2]), schema = useSchema(), documentSchema = useMemo(() => {
3234
3186
  if (targetDocumentType)
3235
3187
  return schema.get(targetDocumentType);
3236
- }, [schema, targetDocumentType]), fieldSchema = useSelectedSchema(pathKey, documentSchema), context = react.useMemo(
3188
+ }, [schema, targetDocumentType]), fieldSchema = useSelectedSchema(pathKey, documentSchema), context = useMemo(
3237
3189
  () => ({
3238
3190
  documentSchema,
3239
3191
  fieldSchema: fieldSchema ?? documentSchema
3240
3192
  }),
3241
3193
  [fieldSchema, documentSchema]
3242
3194
  ), title = value?.title;
3243
- react.useEffect(() => {
3244
- !title && documentSchema && !id?.startsWith("drafts.") && onChange(sanity.set(documentSchema.title ?? documentSchema.name, ["title"]));
3195
+ useEffect(() => {
3196
+ !title && documentSchema && !id?.startsWith("drafts.") && onChange(set(documentSchema.title ?? documentSchema.name, ["title"]));
3245
3197
  }, [title, documentSchema, onChange, id]);
3246
- const { onPathOpen, ...formCallbacks } = sanity.useFormCallbacks(), newCallbacks = react.useMemo(
3198
+ const { onPathOpen, ...formCallbacks } = useFormCallbacks(), newCallbacks = useMemo(
3247
3199
  () => ({
3248
3200
  ...formCallbacks,
3249
3201
  onPathOpen: (path) => {
3250
3202
  !instruction2 && path.length === 4 && path[2] === "instructions" ? (setParams(
3251
- sanity.typed({
3203
+ typed({
3252
3204
  ...params,
3253
3205
  [instructionParam]: path[3]?._key
3254
3206
  })
@@ -3257,18 +3209,18 @@ function AssistDocumentFormEditable(props) {
3257
3209
  }),
3258
3210
  [formCallbacks, onPathOpen, params, setParams, instruction2]
3259
3211
  );
3260
- react.useEffect(() => {
3212
+ useEffect(() => {
3261
3213
  activePath && !instruction2 && onPathOpen([]);
3262
3214
  }, [activePath, instruction2, onPathOpen]);
3263
- const fieldError = react.useMemo(() => {
3215
+ const fieldError = useMemo(() => {
3264
3216
  const fieldError2 = props.members.find(
3265
3217
  (m) => m.kind === "error" && m.fieldName === "fields"
3266
3218
  );
3267
3219
  if (fieldError2)
3268
- return /* @__PURE__ */ jsxRuntime.jsx(sanity.MemberFieldError, { member: fieldError2 });
3220
+ return /* @__PURE__ */ jsx(MemberFieldError, { member: fieldError2 });
3269
3221
  }, [props.members]);
3270
- return /* @__PURE__ */ jsxRuntime.jsx(SelectedFieldContextProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 5, children: [
3271
- /* @__PURE__ */ jsxRuntime.jsx(
3222
+ return /* @__PURE__ */ jsx(SelectedFieldContextProvider, { value: context, children: /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
3223
+ /* @__PURE__ */ jsx(
3272
3224
  FieldsInitializer,
3273
3225
  {
3274
3226
  pathKey: typePath,
@@ -3279,19 +3231,19 @@ function AssistDocumentFormEditable(props) {
3279
3231
  },
3280
3232
  typePath
3281
3233
  ),
3282
- instruction2 && /* @__PURE__ */ jsxRuntime.jsx(BackToInstructionListLink, {}),
3283
- activePath && !fieldError && /* @__PURE__ */ jsxRuntime.jsx(sanity.FormCallbacksProvider, { ...newCallbacks, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { lineHeight: "1.25em" }, children: /* @__PURE__ */ jsxRuntime.jsx(sanity.FormInput, { ...props, absolutePath: activePath }) }) }),
3234
+ instruction2 && /* @__PURE__ */ jsx(BackToInstructionListLink, {}),
3235
+ activePath && !fieldError && /* @__PURE__ */ jsx(FormCallbacksProvider, { ...newCallbacks, children: /* @__PURE__ */ jsx("div", { style: { lineHeight: "1.25em" }, children: /* @__PURE__ */ jsx(FormInput, { ...props, absolutePath: activePath }) }) }),
3284
3236
  fieldError,
3285
3237
  !activePath && props.renderDefault(props)
3286
3238
  ] }) });
3287
3239
  }
3288
3240
  function useSelectedSchema(fieldPath, documentSchema) {
3289
- return react.useMemo(() => {
3241
+ return useMemo(() => {
3290
3242
  if (!fieldPath)
3291
3243
  return;
3292
3244
  if (fieldPath === documentRootKey)
3293
3245
  return documentSchema;
3294
- const path = sanity.stringToPath(fieldPath);
3246
+ const path = stringToPath(fieldPath);
3295
3247
  let currentSchema = documentSchema;
3296
3248
  for (let i = 0; i < path.length; i++) {
3297
3249
  const segment = path[i], field = currentSchema?.fields.find((f) => f.name === segment);
@@ -3315,22 +3267,22 @@ function FieldsInitializer({
3315
3267
  }) {
3316
3268
  const {
3317
3269
  config: { __presets: presets }
3318
- } = useAiAssistanceConfig(), existingField = fields?.find((f) => f._key === pathKey), documentPresets = !!documentSchema?.name && presets?.[documentSchema?.name], missingPresetInstructions = react.useMemo(() => {
3270
+ } = useAiAssistanceConfig(), existingField = fields?.find((f) => f._key === pathKey), documentPresets = !!documentSchema?.name && presets?.[documentSchema?.name], missingPresetInstructions = useMemo(() => {
3319
3271
  if (!documentPresets || !pathKey)
3320
3272
  return;
3321
3273
  const existingInstructions = existingField?.instructions;
3322
3274
  return documentPresets.fields?.find((f) => f.path === pathKey)?.instructions?.filter(
3323
3275
  (i) => !existingInstructions?.some((ei) => ei._key === i._key)
3324
3276
  );
3325
- }, [documentPresets, pathKey, existingField]), initialized = react.useRef(!1);
3326
- return react.useEffect(() => {
3277
+ }, [documentPresets, pathKey, existingField]), initialized = useRef(!1);
3278
+ return useEffect(() => {
3327
3279
  if (initialized.current || !pathKey || existingField && !missingPresetInstructions?.length)
3328
3280
  return;
3329
- let event = sanity.PatchEvent.from([sanity.setIfMissing([], ["fields"])]);
3281
+ let event = PatchEvent.from([setIfMissing([], ["fields"])]);
3330
3282
  existingField || (event = event.append(
3331
- sanity.insert(
3283
+ insert(
3332
3284
  [
3333
- sanity.typed({
3285
+ typed({
3334
3286
  _key: pathKey,
3335
3287
  _type: assistFieldTypeName,
3336
3288
  path: pathKey,
@@ -3340,8 +3292,8 @@ function FieldsInitializer({
3340
3292
  "after",
3341
3293
  ["fields", -1]
3342
3294
  )
3343
- )), existingField?.instructions?.length || (event = event.append([sanity.setIfMissing([], ["fields", { _key: pathKey }, "instructions"])])), missingPresetInstructions?.length && (event = event.append(
3344
- sanity.insert(
3295
+ )), existingField?.instructions?.length || (event = event.append([setIfMissing([], ["fields", { _key: pathKey }, "instructions"])])), missingPresetInstructions?.length && (event = event.append(
3296
+ insert(
3345
3297
  missingPresetInstructions.map(
3346
3298
  (preset) => ({
3347
3299
  ...preset,
@@ -3356,9 +3308,9 @@ function FieldsInitializer({
3356
3308
  }, [activePath, onChange, pathKey, existingField, missingPresetInstructions]), null;
3357
3309
  }
3358
3310
  function FieldRefPreview(props) {
3359
- const { actions } = props, documentSchema = react.useContext(SelectedFieldContext)?.documentSchema, path = react.useContext(InlineBlockValueContext)?.path ?? props.path, selectedField = useSelectedField(documentSchema, path);
3360
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", style: { width: "100%" }, children: [
3361
- /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, gap: 2, align: "center", paddingY: 3, paddingX: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, textOverflow: "ellipsis", children: selectedField?.title ?? "Select field" }) }) }),
3311
+ const { actions } = props, documentSchema = useContext(SelectedFieldContext)?.documentSchema, path = useContext(InlineBlockValueContext)?.path ?? props.path, selectedField = useSelectedField(documentSchema, path);
3312
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", style: { width: "100%" }, children: [
3313
+ /* @__PURE__ */ jsx(Flex, { flex: 1, gap: 2, align: "center", paddingY: 3, paddingX: 1, children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, textOverflow: "ellipsis", children: selectedField?.title ?? "Select field" }) }) }),
3362
3314
  actions
3363
3315
  ] });
3364
3316
  }
@@ -3366,13 +3318,13 @@ function HiddenFieldTitle(props) {
3366
3318
  return props.renderDefault({ ...props, title: "", level: props.level - 2, changed: !1 });
3367
3319
  }
3368
3320
  function InstructionVisibility(props) {
3369
- const { value, onChange } = props, user = sanity.useCurrentUser(), handleChange = react.useCallback(() => {
3321
+ const { value, onChange } = props, user = useCurrentUser(), handleChange = useCallback(() => {
3370
3322
  const newValue = value ? "" : user?.id ?? "";
3371
- onChange(newValue ? sanity.set(newValue) : sanity.unset());
3372
- }, [onChange, user, value]), id = react.useId();
3373
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "flex-start", children: [
3374
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { margin: "-3px 0" }, children: /* @__PURE__ */ jsxRuntime.jsx(
3375
- ui.Switch,
3323
+ onChange(newValue ? set(newValue) : unset());
3324
+ }, [onChange, user, value]), id = useId();
3325
+ return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "flex-start", children: [
3326
+ /* @__PURE__ */ jsx("div", { style: { margin: "-3px 0" }, children: /* @__PURE__ */ jsx(
3327
+ Switch,
3376
3328
  {
3377
3329
  ...props.elementProps,
3378
3330
  id,
@@ -3382,15 +3334,15 @@ function InstructionVisibility(props) {
3382
3334
  disabled: props.elementProps.readOnly
3383
3335
  }
3384
3336
  ) }),
3385
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, weight: "medium", children: /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, children: "Make visible to all Studio members" }) })
3337
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, weight: "medium", children: /* @__PURE__ */ jsx("label", { htmlFor: id, children: "Make visible to all Studio members" }) })
3386
3338
  ] }) });
3387
3339
  }
3388
3340
  function FieldRefPathInput(props) {
3389
- const documentSchema = react.useContext(SelectedFieldContext)?.documentSchema, { typePath } = react.useContext(AssistTypeContext), ref = react.useRef(null), id = react.useId(), { onChange } = props;
3390
- react.useEffect(() => {
3341
+ const documentSchema = useContext(SelectedFieldContext)?.documentSchema, { typePath } = useContext(AssistTypeContext), ref = useRef(null), id = useId(), { onChange } = props;
3342
+ useEffect(() => {
3391
3343
  ref.current?.querySelector("input")?.focus();
3392
3344
  }, []);
3393
- const onSelect = react.useCallback((path) => onChange(sanity.set(path)), [onChange]), filter = react.useCallback(
3345
+ const onSelect = useCallback((path) => onChange(set(path)), [onChange]), filter2 = useCallback(
3394
3346
  (field) => {
3395
3347
  if (!field.key.includes("|") || !typePath)
3396
3348
  return !0;
@@ -3401,14 +3353,14 @@ function FieldRefPathInput(props) {
3401
3353
  },
3402
3354
  [typePath]
3403
3355
  );
3404
- return documentSchema ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, style: { minWidth: 300 }, ref, children: /* @__PURE__ */ jsxRuntime.jsx(
3356
+ return documentSchema ? /* @__PURE__ */ jsx(Box, { flex: 1, style: { minWidth: 300 }, ref, children: /* @__PURE__ */ jsx(
3405
3357
  FieldAutocomplete,
3406
3358
  {
3407
3359
  id,
3408
3360
  schemaType: documentSchema,
3409
3361
  onSelect,
3410
3362
  fieldPath: props.value,
3411
- filter
3363
+ filter: filter2
3412
3364
  }
3413
3365
  ) }) : props.renderDefault(props);
3414
3366
  }
@@ -3423,20 +3375,20 @@ function findFieldsetMember(members, fieldsetName) {
3423
3375
  );
3424
3376
  }
3425
3377
  function InstructionInput(props) {
3426
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: [4, 4, 4, 5], children: [
3427
- /* @__PURE__ */ jsxRuntime.jsx(NameField, { ...props }),
3428
- /* @__PURE__ */ jsxRuntime.jsx(ShareField, { ...props }),
3429
- /* @__PURE__ */ jsxRuntime.jsx(ObjectMember, { fieldName: "prompt", ...props }),
3430
- /* @__PURE__ */ jsxRuntime.jsx(ObjectMember, { fieldName: "output", ...props })
3378
+ return /* @__PURE__ */ jsxs(Stack, { space: [4, 4, 4, 5], children: [
3379
+ /* @__PURE__ */ jsx(NameField, { ...props }),
3380
+ /* @__PURE__ */ jsx(ShareField, { ...props }),
3381
+ /* @__PURE__ */ jsx(ObjectMember, { fieldName: "prompt", ...props }),
3382
+ /* @__PURE__ */ jsx(ObjectMember, { fieldName: "output", ...props })
3431
3383
  ] });
3432
3384
  }
3433
3385
  function ObjectMember({ fieldName, ...props }) {
3434
3386
  const member = findFieldMember(props.members, fieldName);
3435
- return member ? /* @__PURE__ */ jsxRuntime.jsx(sanity.ObjectInputMember, { ...props, member }) : null;
3387
+ return member ? /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member }) : null;
3436
3388
  }
3437
3389
  const NONE = [];
3438
3390
  function NameField(props) {
3439
- const fieldsetMember = findFieldsetMember(props.members, "appearance"), titleId = react.useId(), members = fieldsetMember?.fieldSet.members ?? NONE, iconMember = findFieldMember(members, "icon"), titleMember = findFieldMember(members, "title"), titlePlaceholder = "Untitled", moddedTitleMember = react.useMemo(() => {
3391
+ const fieldsetMember = findFieldsetMember(props.members, "appearance"), titleId = useId(), members = fieldsetMember?.fieldSet.members ?? NONE, iconMember = findFieldMember(members, "icon"), titleMember = findFieldMember(members, "title"), titlePlaceholder = "Untitled", moddedTitleMember = useMemo(() => {
3440
3392
  if (titleMember)
3441
3393
  return titleMember.kind === "error" ? titleMember : {
3442
3394
  ...titleMember,
@@ -3449,28 +3401,28 @@ function NameField(props) {
3449
3401
  }
3450
3402
  };
3451
3403
  }, [titleMember, titlePlaceholder]);
3452
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 5, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
3453
- /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { gap: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { as: "label", weight: "semibold", size: 1, htmlFor: titleId, children: "Name" }) }),
3454
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "How this instruction appears in menus" }),
3455
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [
3456
- iconMember && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(sanity.ObjectInputMember, { ...props, member: iconMember }) }),
3457
- moddedTitleMember && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, style: { marginLeft: -1 }, children: /* @__PURE__ */ jsxRuntime.jsx(sanity.ObjectInputMember, { ...props, member: moddedTitleMember }) })
3404
+ return /* @__PURE__ */ jsx(Stack, { space: 5, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
3405
+ /* @__PURE__ */ jsx(Flex, { gap: 1, children: /* @__PURE__ */ jsx(Text, { as: "label", weight: "semibold", size: 1, htmlFor: titleId, children: "Name" }) }),
3406
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "How this instruction appears in menus" }),
3407
+ /* @__PURE__ */ jsxs(Flex, { align: "center", children: [
3408
+ iconMember && /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: iconMember }) }),
3409
+ moddedTitleMember && /* @__PURE__ */ jsx(Box, { flex: 1, style: { marginLeft: -1 }, children: /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: moddedTitleMember }) })
3458
3410
  ] })
3459
3411
  ] }) });
3460
3412
  }
3461
3413
  function ShareField(props) {
3462
3414
  const members = findFieldsetMember(props.members, "appearance")?.fieldSet.members ?? NONE, visibilityMember = findFieldMember(members, "userId");
3463
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: visibilityMember && /* @__PURE__ */ jsxRuntime.jsx(sanity.ObjectInputMember, { ...props, member: visibilityMember }) });
3415
+ return /* @__PURE__ */ jsx(Fragment, { children: visibilityMember && /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: visibilityMember }) });
3464
3416
  }
3465
3417
  function InstructionOutputField(props) {
3466
- const { fieldSchema } = react.useContext(SelectedFieldContext) ?? {};
3467
- return !fieldSchema || !(sanity.isObjectSchemaType(fieldSchema) || sanity.isArrayOfObjectsSchemaType(fieldSchema)) ? null : /* @__PURE__ */ jsxRuntime.jsx(EnabledOutputField, { ...props, fieldSchema, children: props.children });
3418
+ const { fieldSchema } = useContext(SelectedFieldContext) ?? {};
3419
+ return !fieldSchema || !(isObjectSchemaType(fieldSchema) || isArrayOfObjectsSchemaType(fieldSchema)) ? null : /* @__PURE__ */ jsx(EnabledOutputField, { ...props, fieldSchema, children: props.children });
3468
3420
  }
3469
3421
  function EnabledOutputField({
3470
3422
  fieldSchema,
3471
3423
  ...props
3472
3424
  }) {
3473
- const [open, setOpen] = react.useState(!!props.value?.length), onExpand = react.useCallback(() => setOpen(!0), []), onCollapse = react.useCallback(() => setOpen(!1), []);
3425
+ const [open, setOpen] = useState(!!props.value?.length), onExpand = useCallback(() => setOpen(!0), []), onCollapse = useCallback(() => setOpen(!1), []);
3474
3426
  return props.renderDefault({
3475
3427
  ...props,
3476
3428
  collapsible: !0,
@@ -3478,46 +3430,46 @@ function EnabledOutputField({
3478
3430
  onCollapse,
3479
3431
  collapsed: !open,
3480
3432
  level: 1,
3481
- title: sanity.isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
3433
+ title: isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
3482
3434
  });
3483
3435
  }
3484
3436
  function InstructionOutputInput(props) {
3485
- const { fieldSchema } = react.useContext(SelectedFieldContext) ?? {};
3486
- return fieldSchema ? sanity.isObjectSchemaType(fieldSchema) ? /* @__PURE__ */ jsxRuntime.jsx(ObjectOutputInput, { ...props, fieldSchema }) : sanity.isArrayOfObjectsSchemaType(fieldSchema) ? /* @__PURE__ */ jsxRuntime.jsx(ArrayOutputInput, { ...props, fieldSchema }) : null : null;
3437
+ const { fieldSchema } = useContext(SelectedFieldContext) ?? {};
3438
+ return fieldSchema ? isObjectSchemaType(fieldSchema) ? /* @__PURE__ */ jsx(ObjectOutputInput, { ...props, fieldSchema }) : isArrayOfObjectsSchemaType(fieldSchema) ? /* @__PURE__ */ jsx(ArrayOutputInput, { ...props, fieldSchema }) : null : null;
3487
3439
  }
3488
3440
  function useEmptySelectAllValue(value, allowedValues, onChange) {
3489
- react.useEffect(() => {
3441
+ useEffect(() => {
3490
3442
  const validValues = value?.filter(
3491
3443
  (v) => allowedValues.find(
3492
3444
  (f) => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)
3493
3445
  )
3494
3446
  ), valueLength = value?.length ?? 0, validLength = validValues?.length ?? 0;
3495
- (!validLength && valueLength || validLength >= allowedValues.length) && onChange(sanity.PatchEvent.from([sanity.unset()]));
3447
+ (!validLength && valueLength || validLength >= allowedValues.length) && onChange(PatchEvent.from([unset()]));
3496
3448
  }, [allowedValues, value, onChange]);
3497
3449
  }
3498
3450
  function ObjectOutputInput({
3499
3451
  fieldSchema,
3500
3452
  ...props
3501
3453
  }) {
3502
- const { value, onChange } = props, fields = react.useMemo(
3454
+ const { value, onChange } = props, fields = useMemo(
3503
3455
  () => fieldSchema.fields.filter((field) => isAssistSupported(field.type)),
3504
3456
  [fieldSchema.fields]
3505
3457
  );
3506
3458
  useEmptySelectAllValue(value, fields, onChange);
3507
- const onSelectChange = react.useCallback(
3459
+ const onSelectChange = useCallback(
3508
3460
  (checked, selectedValue) => {
3509
3461
  if (checked)
3510
3462
  if (value?.length)
3511
- onChange(sanity.PatchEvent.from(sanity.unset([{ _key: selectedValue }])));
3463
+ onChange(PatchEvent.from(unset([{ _key: selectedValue }])));
3512
3464
  else {
3513
3465
  const items = fields.filter((f) => f.name !== selectedValue).map(
3514
- (field) => sanity.typed({
3466
+ (field) => typed({
3515
3467
  _key: field.name,
3516
3468
  _type: "sanity.assist.output.field",
3517
3469
  relativePath: field.name
3518
3470
  })
3519
3471
  );
3520
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert(items, "after", [-1])]));
3472
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
3521
3473
  }
3522
3474
  else {
3523
3475
  const patchValue = {
@@ -3525,12 +3477,12 @@ function ObjectOutputInput({
3525
3477
  _type: "sanity.assist.output.field",
3526
3478
  relativePath: selectedValue
3527
3479
  };
3528
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([patchValue], "after", [-1])]));
3480
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
3529
3481
  }
3530
3482
  },
3531
3483
  [onChange, value, fields]
3532
3484
  );
3533
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: fields.map((field) => /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
3485
+ return /* @__PURE__ */ jsx(Stack, { space: 2, children: fields.map((field) => /* @__PURE__ */ jsx(Flex, { align: "center", gap: 2, children: /* @__PURE__ */ jsx(
3534
3486
  Selectable,
3535
3487
  {
3536
3488
  value: field.name,
@@ -3544,25 +3496,25 @@ function ArrayOutputInput({
3544
3496
  fieldSchema,
3545
3497
  ...props
3546
3498
  }) {
3547
- const { value, onChange } = props, ofItems = react.useMemo(
3499
+ const { value, onChange } = props, ofItems = useMemo(
3548
3500
  () => fieldSchema.of.filter((itemType) => isAssistSupported(itemType)),
3549
3501
  [fieldSchema.of]
3550
3502
  );
3551
3503
  useEmptySelectAllValue(value, ofItems, onChange);
3552
- const onSelectChange = react.useCallback(
3504
+ const onSelectChange = useCallback(
3553
3505
  (checked, selectedValue) => {
3554
3506
  if (checked)
3555
3507
  if (value?.length)
3556
- onChange(sanity.PatchEvent.from(sanity.unset([{ _key: selectedValue }])));
3508
+ onChange(PatchEvent.from(unset([{ _key: selectedValue }])));
3557
3509
  else {
3558
3510
  const items = ofItems.filter((f) => f.name !== selectedValue).map(
3559
- (field) => sanity.typed({
3511
+ (field) => typed({
3560
3512
  _key: field.name,
3561
3513
  _type: "sanity.assist.output.type",
3562
3514
  type: field.name
3563
3515
  })
3564
3516
  );
3565
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert(items, "after", [-1])]));
3517
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
3566
3518
  }
3567
3519
  else {
3568
3520
  const patchValue = {
@@ -3570,12 +3522,12 @@ function ArrayOutputInput({
3570
3522
  _type: "sanity.assist.output.type",
3571
3523
  type: selectedValue
3572
3524
  };
3573
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([patchValue], "after", [-1])]));
3525
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
3574
3526
  }
3575
3527
  },
3576
3528
  [onChange, value, ofItems]
3577
3529
  );
3578
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: ofItems.map((itemType) => /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(
3530
+ return /* @__PURE__ */ jsx(Stack, { space: 2, children: ofItems.map((itemType) => /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3579
3531
  Selectable,
3580
3532
  {
3581
3533
  value: itemType.name,
@@ -3591,13 +3543,13 @@ function Selectable({
3591
3543
  value,
3592
3544
  onChange
3593
3545
  }) {
3594
- const checked = !arrayValue?.length || !!arrayValue?.find((v) => v._key === value), handleChange = react.useCallback(() => onChange(checked, value), [onChange, checked, value]);
3595
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "flex-start", children: [
3596
- /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { checked, onChange: handleChange }),
3597
- /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { marginTop: 1, onClick: handleChange, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { style: { cursor: "default" }, size: 1, children: title }) })
3546
+ const checked = !arrayValue?.length || !!arrayValue?.find((v) => v._key === value), handleChange = useCallback(() => onChange(checked, value), [onChange, checked, value]);
3547
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "flex-start", children: [
3548
+ /* @__PURE__ */ jsx(Checkbox, { checked, onChange: handleChange }),
3549
+ /* @__PURE__ */ jsx(Card, { marginTop: 1, onClick: handleChange, children: /* @__PURE__ */ jsx(Text, { style: { cursor: "default" }, size: 1, children: title }) })
3598
3550
  ] });
3599
3551
  }
3600
- const PteMods = styledComponents.styled(ui.Box)`
3552
+ const PteMods = styled(Box)`
3601
3553
  & [data-testid='pt-editor__toolbar-card'] > div > div:last-child {
3602
3554
  display: none;
3603
3555
  }
@@ -3609,12 +3561,12 @@ const PteMods = styledComponents.styled(ui.Box)`
3609
3561
  }
3610
3562
  `;
3611
3563
  function PromptInput(props) {
3612
- return useOnlyInlineBlocks(props), /* @__PURE__ */ jsxRuntime.jsx(PteMods, { children: props.renderDefault(props) });
3564
+ return useOnlyInlineBlocks(props), /* @__PURE__ */ jsx(PteMods, { children: props.renderDefault(props) });
3613
3565
  }
3614
3566
  function useOnlyInlineBlocks(props) {
3615
- react.useEffect(() => {
3567
+ useEffect(() => {
3616
3568
  let needsFix = !1;
3617
- const val = (props.value ?? []).map((block) => block._type === "block" ? block : (needsFix = !0, sanity.typed({
3569
+ const val = (props.value ?? []).map((block) => block._type === "block" ? block : (needsFix = !0, typed({
3618
3570
  _key: randomKey(12),
3619
3571
  _type: "block",
3620
3572
  level: 0,
@@ -3622,7 +3574,7 @@ function useOnlyInlineBlocks(props) {
3622
3574
  style: "normal",
3623
3575
  children: [block]
3624
3576
  })));
3625
- needsFix && props.onChange(sanity.set(val));
3577
+ needsFix && props.onChange(set(val));
3626
3578
  }, []);
3627
3579
  }
3628
3580
  function InstructionsArrayField(props) {
@@ -3632,10 +3584,10 @@ function InstructionsArrayField(props) {
3632
3584
  });
3633
3585
  }
3634
3586
  function InstructionsArrayInput(props) {
3635
- const user = sanity.useCurrentUser(), originalValue = props.value, originalMembers = props.members, value = react.useMemo(
3587
+ const user = useCurrentUser(), originalValue = props.value, originalMembers = props.members, value = useMemo(
3636
3588
  () => (originalValue ?? []).filter((v) => !v.userId || v.userId === user?.id),
3637
3589
  [originalValue, user]
3638
- ), members = react.useMemo(
3590
+ ), members = useMemo(
3639
3591
  () => (originalMembers ?? []).filter((v) => {
3640
3592
  if (v.kind === "error")
3641
3593
  return !0;
@@ -3647,8 +3599,8 @@ function InstructionsArrayInput(props) {
3647
3599
  return props.renderDefault({ ...props, value, members });
3648
3600
  }
3649
3601
  function HideReferenceChangedBannerInput(props) {
3650
- const ref = react.useRef(null);
3651
- return react.useEffect(() => {
3602
+ const ref = useRef(null);
3603
+ return useEffect(() => {
3652
3604
  const parent = ref.current?.closest('[data-testid="pane-content"]');
3653
3605
  if (!parent)
3654
3606
  return;
@@ -3656,29 +3608,29 @@ function HideReferenceChangedBannerInput(props) {
3656
3608
  parent.id = parentId, style.innerText = `
3657
3609
  #${parentId} [data-testid="reference-changed-banner"] { display: none; }
3658
3610
  `, parent.prepend(style);
3659
- }, [ref]), /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { ref, children: props.renderDefault(props) });
3611
+ }, [ref]), /* @__PURE__ */ jsx(Box, { ref, children: props.renderDefault(props) });
3660
3612
  }
3661
- const contextDocumentSchema = sanity.defineType({
3613
+ const contextDocumentSchema = defineType({
3662
3614
  type: "document",
3663
3615
  name: contextDocumentTypeName,
3664
3616
  title: "AI context",
3665
3617
  liveEdit: !0,
3666
- icon: icons.TokenIcon,
3618
+ icon: TokenIcon,
3667
3619
  components: {
3668
3620
  input: HideReferenceChangedBannerInput
3669
3621
  },
3670
3622
  fields: [
3671
- sanity.defineField({
3623
+ defineField({
3672
3624
  type: "string",
3673
3625
  name: "title",
3674
3626
  title: "Title"
3675
3627
  }),
3676
- sanity.defineField({
3628
+ defineField({
3677
3629
  name: "context",
3678
3630
  type: "array",
3679
3631
  title: "Context",
3680
3632
  of: [
3681
- sanity.defineArrayMember({
3633
+ defineArrayMember({
3682
3634
  type: "block",
3683
3635
  styles: [{ title: "Normal", value: "normal" }],
3684
3636
  lists: [],
@@ -3700,17 +3652,17 @@ const contextDocumentSchema = sanity.defineType({
3700
3652
  return {
3701
3653
  title,
3702
3654
  subtitle: `Words: ${words}`,
3703
- media: icons.DocumentTextIcon
3655
+ media: DocumentTextIcon
3704
3656
  };
3705
3657
  }
3706
3658
  }
3707
- }), fieldReference = sanity.defineType({
3659
+ }), fieldReference = defineType({
3708
3660
  type: "object",
3709
3661
  name: fieldReferenceTypeName,
3710
3662
  title: "Field",
3711
- icon: icons.ThListIcon,
3663
+ icon: ThListIcon,
3712
3664
  fields: [
3713
- sanity.defineField({
3665
+ defineField({
3714
3666
  type: "string",
3715
3667
  name: "path",
3716
3668
  title: "Field",
@@ -3746,7 +3698,7 @@ const contextDocumentSchema = sanity.defineType({
3746
3698
  return {
3747
3699
  title: path,
3748
3700
  path,
3749
- icon: icons.CodeIcon
3701
+ icon: CodeIcon
3750
3702
  };
3751
3703
  }
3752
3704
  },
@@ -3758,13 +3710,13 @@ const contextDocumentSchema = sanity.defineType({
3758
3710
  type: "popover"
3759
3711
  }
3760
3712
  }
3761
- }), userInput = sanity.defineType({
3713
+ }), userInput = defineType({
3762
3714
  type: "object",
3763
3715
  name: userInputTypeName,
3764
3716
  title: "User input",
3765
- icon: icons.ComposeIcon,
3717
+ icon: ComposeIcon,
3766
3718
  fields: [
3767
- sanity.defineField({
3719
+ defineField({
3768
3720
  type: "string",
3769
3721
  name: "message",
3770
3722
  title: "User input title",
@@ -3772,7 +3724,7 @@ const contextDocumentSchema = sanity.defineType({
3772
3724
  description: "The header above the user input text field",
3773
3725
  validation: (rule) => rule.required()
3774
3726
  }),
3775
- sanity.defineField({
3727
+ defineField({
3776
3728
  type: "text",
3777
3729
  rows: 3,
3778
3730
  name: "description",
@@ -3791,13 +3743,13 @@ const contextDocumentSchema = sanity.defineType({
3791
3743
  width: 1
3792
3744
  }
3793
3745
  }
3794
- }), promptContext = sanity.defineType({
3746
+ }), promptContext = defineType({
3795
3747
  type: "object",
3796
3748
  name: instructionContextTypeName,
3797
3749
  title: contextDocumentSchema.title,
3798
3750
  icon: contextDocumentSchema.icon,
3799
3751
  fields: [
3800
- sanity.defineField({
3752
+ defineField({
3801
3753
  type: "reference",
3802
3754
  name: "reference",
3803
3755
  to: [{ type: contextDocumentSchema.name }],
@@ -3806,14 +3758,14 @@ const contextDocumentSchema = sanity.defineType({
3806
3758
  validation: (rule) => rule.required(),
3807
3759
  components: {
3808
3760
  input: function(props) {
3809
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { maxWidth: 300 }, children: props.renderDefault(props) });
3761
+ return /* @__PURE__ */ jsx(Box, { style: { maxWidth: 300 }, children: props.renderDefault(props) });
3810
3762
  }
3811
3763
  }
3812
3764
  })
3813
3765
  ],
3814
3766
  preview: {
3815
3767
  select: {
3816
- ref: "reference._ref",
3768
+ ref: "reference._id",
3817
3769
  title: "reference.title",
3818
3770
  context: "reference.context"
3819
3771
  },
@@ -3827,12 +3779,12 @@ const contextDocumentSchema = sanity.defineType({
3827
3779
  width: "auto"
3828
3780
  }
3829
3781
  }
3830
- }), prompt = sanity.defineType({
3782
+ }), prompt = defineType({
3831
3783
  type: "array",
3832
3784
  name: promptTypeName,
3833
3785
  title: "Prompt",
3834
3786
  of: [
3835
- sanity.defineArrayMember({
3787
+ defineArrayMember({
3836
3788
  type: "block",
3837
3789
  styles: [{ title: "Normal", value: "normal" }],
3838
3790
  lists: [],
@@ -3841,13 +3793,13 @@ const contextDocumentSchema = sanity.defineType({
3841
3793
  annotations: []
3842
3794
  },
3843
3795
  of: [
3844
- sanity.defineArrayMember({
3796
+ defineArrayMember({
3845
3797
  type: fieldReference.name
3846
3798
  }),
3847
- sanity.defineArrayMember({
3799
+ defineArrayMember({
3848
3800
  type: promptContext.name
3849
3801
  }),
3850
- sanity.defineArrayMember({
3802
+ defineArrayMember({
3851
3803
  type: userInput.name
3852
3804
  })
3853
3805
  ]
@@ -3862,29 +3814,29 @@ const contextDocumentSchema = sanity.defineType({
3862
3814
  type: userInput.name,
3863
3815
  }),*/
3864
3816
  ]
3865
- }), outputFieldType = sanity.defineType({
3817
+ }), outputFieldType = defineType({
3866
3818
  type: "object",
3867
3819
  name: outputFieldTypeName,
3868
3820
  title: "Output field",
3869
3821
  fields: [
3870
- sanity.defineField({
3822
+ defineField({
3871
3823
  type: "string",
3872
3824
  name: "path",
3873
3825
  title: "Path"
3874
3826
  })
3875
3827
  ]
3876
- }), outputTypeType = sanity.defineType({
3828
+ }), outputTypeType = defineType({
3877
3829
  type: "object",
3878
3830
  name: outputTypeTypeName,
3879
3831
  title: "Output type",
3880
3832
  fields: [
3881
- sanity.defineField({
3833
+ defineField({
3882
3834
  type: "string",
3883
3835
  name: "type",
3884
3836
  title: "Type"
3885
3837
  })
3886
3838
  ]
3887
- }), instruction = sanity.defineType({
3839
+ }), instruction = defineType({
3888
3840
  type: "object",
3889
3841
  name: instructionTypeName,
3890
3842
  title: "Instruction",
@@ -3899,45 +3851,45 @@ const contextDocumentSchema = sanity.defineType({
3899
3851
  },
3900
3852
  prepare: ({ icon, title, userId }) => ({
3901
3853
  title,
3902
- icon: icon ? icons.icons[icon] : icons.SparklesIcon,
3854
+ icon: icon ? icons[icon] : SparklesIcon,
3903
3855
  userId
3904
3856
  })
3905
3857
  },
3906
3858
  components: {
3907
3859
  input: InstructionInput,
3908
- preview: (props) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 3, align: "center", padding: 2, children: [
3909
- props.icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: react.createElement(props.icon) }) }),
3910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { flex: 1, space: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, textOverflow: "ellipsis", weight: "medium", children: getInstructionTitle(props) }) }),
3911
- props.userId && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
3912
- ui.Tooltip,
3860
+ preview: (props) => /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", padding: 2, children: [
3861
+ props.icon && /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(Text, { size: 1, children: createElement(props.icon) }) }),
3862
+ /* @__PURE__ */ jsx(Stack, { flex: 1, space: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, textOverflow: "ellipsis", weight: "medium", children: getInstructionTitle(props) }) }),
3863
+ props.userId && /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(
3864
+ Tooltip,
3913
3865
  {
3914
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Only visible to you" }),
3866
+ content: /* @__PURE__ */ jsx(Text, { size: 1, children: "Only visible to you" }),
3915
3867
  padding: 2,
3916
3868
  placement: "top",
3917
3869
  portal: !0,
3918
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.LockIcon, {})
3870
+ children: /* @__PURE__ */ jsx(LockIcon, {})
3919
3871
  }
3920
3872
  ) })
3921
3873
  ] })
3922
3874
  },
3923
3875
  fields: [
3924
- sanity.defineField({
3876
+ defineField({
3925
3877
  type: prompt.name,
3926
3878
  name: "prompt",
3927
3879
  title: "Instruction",
3928
- description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3880
+ description: /* @__PURE__ */ jsxs(Fragment, { children: [
3929
3881
  "Learn from",
3930
3882
  " ",
3931
- /* @__PURE__ */ jsxRuntime.jsxs("a", { href: instructionGuideUrl, target: "_blank", rel: "noreferrer", children: [
3883
+ /* @__PURE__ */ jsxs("a", { href: instructionGuideUrl, target: "_blank", rel: "noreferrer", children: [
3932
3884
  "our instruction guide ",
3933
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRightIcon, {})
3885
+ /* @__PURE__ */ jsx(ArrowRightIcon, {})
3934
3886
  ] })
3935
3887
  ] }),
3936
3888
  components: {
3937
3889
  input: PromptInput
3938
3890
  }
3939
3891
  }),
3940
- sanity.defineField({
3892
+ defineField({
3941
3893
  type: "string",
3942
3894
  name: "icon",
3943
3895
  title: "Icon",
@@ -3947,7 +3899,7 @@ const contextDocumentSchema = sanity.defineType({
3947
3899
  input: IconInput
3948
3900
  }
3949
3901
  }),
3950
- sanity.defineField({
3902
+ defineField({
3951
3903
  type: "string",
3952
3904
  name: "title",
3953
3905
  title: "Title",
@@ -3956,7 +3908,7 @@ const contextDocumentSchema = sanity.defineType({
3956
3908
  field: HiddenFieldTitle
3957
3909
  }
3958
3910
  }),
3959
- sanity.defineField({
3911
+ defineField({
3960
3912
  type: "string",
3961
3913
  name: "userId",
3962
3914
  title: "Visibility",
@@ -3968,7 +3920,7 @@ const contextDocumentSchema = sanity.defineType({
3968
3920
  initialValue: (params, context) => context.currentUser?.id ?? "",
3969
3921
  readOnly: (context) => !!(context.parent?.createdById && context.parent?.createdById !== context.currentUser?.id)
3970
3922
  }),
3971
- sanity.defineField({
3923
+ defineField({
3972
3924
  type: "string",
3973
3925
  name: "createdById",
3974
3926
  title: "Created by",
@@ -3976,7 +3928,7 @@ const contextDocumentSchema = sanity.defineType({
3976
3928
  fieldset: "appearance",
3977
3929
  initialValue: (params, context) => context.currentUser?.id ?? ""
3978
3930
  }),
3979
- sanity.defineField({
3931
+ defineField({
3980
3932
  type: "array",
3981
3933
  name: "output",
3982
3934
  title: "Output filter",
@@ -3985,12 +3937,12 @@ const contextDocumentSchema = sanity.defineType({
3985
3937
  field: InstructionOutputField
3986
3938
  },
3987
3939
  of: [
3988
- sanity.defineArrayMember({ type: outputFieldType.name }),
3989
- sanity.defineArrayMember({ type: outputTypeType.name })
3940
+ defineArrayMember({ type: outputFieldType.name }),
3941
+ defineArrayMember({ type: outputTypeType.name })
3990
3942
  ]
3991
3943
  })
3992
3944
  ]
3993
- }), fieldInstructions = sanity.defineType({
3945
+ }), fieldInstructions = defineType({
3994
3946
  type: "object",
3995
3947
  name: assistFieldTypeName,
3996
3948
  title: "Field prompt",
@@ -3998,14 +3950,14 @@ const contextDocumentSchema = sanity.defineType({
3998
3950
  input: FieldPromptInput,
3999
3951
  },*/
4000
3952
  fields: [
4001
- sanity.defineField({
3953
+ defineField({
4002
3954
  type: "string",
4003
3955
  name: "path",
4004
3956
  title: "Path",
4005
3957
  readOnly: !0,
4006
3958
  hidden: !0
4007
3959
  }),
4008
- sanity.defineField({
3960
+ defineField({
4009
3961
  type: "array",
4010
3962
  name: "instructions",
4011
3963
  title: "Instructions",
@@ -4021,7 +3973,7 @@ const contextDocumentSchema = sanity.defineType({
4021
3973
  title: "path"
4022
3974
  }
4023
3975
  }
4024
- }), assistDocumentSchema = sanity.defineType({
3976
+ }), assistDocumentSchema = defineType({
4025
3977
  //NOTE: this is a document type. Using object here ensures it does not appear in structure menus
4026
3978
  type: "object",
4027
3979
  liveEdit: !0,
@@ -4032,12 +3984,12 @@ const contextDocumentSchema = sanity.defineType({
4032
3984
  field: (props) => props.renderDefault({ ...props, title: "" })
4033
3985
  },
4034
3986
  fields: [
4035
- sanity.defineField({
3987
+ defineField({
4036
3988
  type: "string",
4037
3989
  name: "title",
4038
3990
  title: "Title"
4039
3991
  }),
4040
- sanity.defineField({
3992
+ defineField({
4041
3993
  type: "array",
4042
3994
  name: "fields",
4043
3995
  title: "Fields",
@@ -4049,45 +4001,45 @@ const contextDocumentSchema = sanity.defineType({
4049
4001
  title: "title"
4050
4002
  }
4051
4003
  }
4052
- }), instructionTask = sanity.defineType({
4004
+ }), instructionTask = defineType({
4053
4005
  type: "object",
4054
4006
  name: instructionTaskTypeName,
4055
4007
  title: "Instruction task",
4056
4008
  fields: [
4057
- sanity.defineField({
4009
+ defineField({
4058
4010
  type: "string",
4059
4011
  name: "path",
4060
4012
  title: "Path"
4061
4013
  }),
4062
- sanity.defineField({
4014
+ defineField({
4063
4015
  type: "string",
4064
4016
  name: "instructionKey",
4065
4017
  title: "Instruction key"
4066
4018
  }),
4067
- sanity.defineField({
4019
+ defineField({
4068
4020
  type: "datetime",
4069
4021
  name: "started",
4070
4022
  title: "Started"
4071
4023
  }),
4072
- sanity.defineField({
4024
+ defineField({
4073
4025
  type: "datetime",
4074
4026
  name: "updated",
4075
4027
  title: "Updated"
4076
4028
  }),
4077
- sanity.defineField({
4029
+ defineField({
4078
4030
  type: "string",
4079
4031
  name: "info",
4080
4032
  title: "Info"
4081
4033
  })
4082
4034
  ]
4083
- }), documentInstructionStatus = sanity.defineType({
4035
+ }), documentInstructionStatus = defineType({
4084
4036
  //NOTE: this is a document type. Using object here ensures it does not appear in structure menus
4085
4037
  type: "object",
4086
4038
  liveEdit: !0,
4087
4039
  name: assistTasksStatusTypeName,
4088
4040
  title: "Document instruction status",
4089
4041
  fields: [
4090
- sanity.defineField({
4042
+ defineField({
4091
4043
  type: "array",
4092
4044
  name: "tasks",
4093
4045
  title: "Tasks",
@@ -4133,7 +4085,7 @@ const instructionForm = [
4133
4085
  documentInstructionStatus,
4134
4086
  instructionTask,
4135
4087
  contextDocumentSchema
4136
- ], assist = sanity.definePlugin((config) => {
4088
+ ], assist = definePlugin((config) => {
4137
4089
  const configWithDefaults = config ?? {}, styleguide = configWithDefaults.translate?.styleguide || "", maxPathDepth = configWithDefaults.assist?.maxPathDepth, temperature = configWithDefaults.assist?.temperature;
4138
4090
  if (typeof styleguide == "string" && validateStyleguide(styleguide), maxPathDepth !== void 0 && (maxPathDepth < 1 || maxPathDepth > 12))
4139
4091
  throw new Error(
@@ -4167,7 +4119,7 @@ const instructionForm = [
4167
4119
  if (schemaType === assistDocumentTypeName)
4168
4120
  return [];
4169
4121
  const docSchema = schema.get(schemaType);
4170
- return docSchema && sanity.isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema) ? [...prev, createAssistDocumentPresence(documentId)] : prev;
4122
+ return docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema) ? [...prev, createAssistDocumentPresence(documentId)] : prev;
4171
4123
  },
4172
4124
  components: {
4173
4125
  unstable_layout: AssistDocumentLayout
@@ -4176,7 +4128,7 @@ const instructionForm = [
4176
4128
  studio: {
4177
4129
  components: {
4178
4130
  layout: function(props) {
4179
- return /* @__PURE__ */ jsxRuntime.jsx(AssistLayout, { ...props, config: configWithDefaults });
4131
+ return /* @__PURE__ */ jsx(AssistLayout, { ...props, config: configWithDefaults });
4180
4132
  }
4181
4133
  }
4182
4134
  },
@@ -4190,24 +4142,24 @@ const instructionForm = [
4190
4142
  }
4191
4143
  },
4192
4144
  plugins: [
4193
- sanity.definePlugin({
4145
+ definePlugin({
4194
4146
  name: `${packageName}/safe-value-input`,
4195
4147
  form: { components: { input: SafeValueInput } }
4196
4148
  })(),
4197
- sanity.definePlugin({
4149
+ definePlugin({
4198
4150
  name: `${packageName}/generate-caption`,
4199
4151
  form: {
4200
4152
  components: {
4201
4153
  input: (props) => {
4202
4154
  const { schemaType } = props;
4203
- return isImage(schemaType) ? /* @__PURE__ */ jsxRuntime.jsx(ImageContextProvider, { ...props }) : props.renderDefault(props);
4155
+ return isImage(schemaType) ? /* @__PURE__ */ jsx(ImageContextProvider, { ...props }) : props.renderDefault(props);
4204
4156
  }
4205
4157
  }
4206
4158
  }
4207
4159
  })()
4208
4160
  ]
4209
4161
  };
4210
- }), fetch = (client, query, params, options2) => rxjs.defer(
4162
+ }), fetch = (client, query, params, options2) => defer(
4211
4163
  () => (
4212
4164
  // getVersionedClient(options.apiVersion)
4213
4165
  client.observable.fetch(query, params, {
@@ -4215,7 +4167,7 @@ const instructionForm = [
4215
4167
  filterResponse: !0
4216
4168
  })
4217
4169
  )
4218
- ), listen = (client, query, params, options2) => rxjs.defer(
4170
+ ), listen = (client, query, params, options2) => defer(
4219
4171
  () => (
4220
4172
  // getVersionedClient(options.apiVersion)
4221
4173
  client.listen(query, params, {
@@ -4231,35 +4183,35 @@ function isWelcomeEvent(event) {
4231
4183
  }
4232
4184
  const listenQuery = (client, query, params = {}, options2 = {}) => {
4233
4185
  const fetchQuery = query, listenerQuery = query, fetchOnce$ = fetch(client, fetchQuery, params, options2), events$ = listen(client, listenerQuery, params, options2).pipe(
4234
- operators.mergeMap((ev, i) => i === 0 && !isWelcomeEvent(ev) ? rxjs.throwError(
4186
+ mergeMap((ev, i) => i === 0 && !isWelcomeEvent(ev) ? throwError(
4235
4187
  new Error(
4236
4188
  ev.type === "reconnect" ? "Could not establish EventSource connection" : `Received unexpected type of first event "${ev.type}"`
4237
4189
  )
4238
- ) : rxjs.of(ev)),
4239
- operators.share()
4240
- ), [welcome$, mutationAndReconnect$] = rxjs.partition(events$, isWelcomeEvent), isRelevantEvent = (event) => !options2.transitions || event.type !== "mutation" ? !0 : options2.transitions.includes(event.transition);
4241
- return rxjs.merge(
4242
- welcome$.pipe(operators.take(1)),
4190
+ ) : of(ev)),
4191
+ share()
4192
+ ), [welcome$, mutationAndReconnect$] = partition(events$, isWelcomeEvent), isRelevantEvent = (event) => !options2.transitions || event.type !== "mutation" ? !0 : options2.transitions.includes(event.transition);
4193
+ return merge(
4194
+ welcome$.pipe(take(1)),
4243
4195
  mutationAndReconnect$.pipe(
4244
- operators.filter(isRelevantEvent),
4245
- rxjs.switchMap((event) => rxjs.merge(rxjs.of(event), rxjs.of(event).pipe(rxjs.delay(options2.throttleTime || 1e3))))
4196
+ filter(isRelevantEvent),
4197
+ switchMap((event) => merge(of(event), of(event).pipe(delay(options2.throttleTime || 1e3))))
4246
4198
  )
4247
- ).pipe(rxjsExhaustmapWithTrailing.exhaustMapToWithTrailing(fetchOnce$));
4199
+ ).pipe(exhaustMapToWithTrailing(fetchOnce$));
4248
4200
  }, DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2022-05-09" };
4249
4201
  function useListeningQuery(query, params = DEFAULT_PARAMS, options2 = DEFAULT_OPTIONS) {
4250
- const [loading, setLoading] = react.useState(!0), [error, setError] = react.useState(!1), [data, setData] = react.useState(null), subscription = react.useRef(null), client = sanity.useClient({ apiVersion: "v2022-05-09" });
4251
- return react.useEffect(() => (subscription.current = listenQuery(client, query, params, options2).pipe(
4252
- operators.distinctUntilChanged(isEqual__default.default),
4253
- operators.catchError((err) => (console.error(err), setError(err), setLoading(!1), setData(null), err))
4202
+ const [loading, setLoading] = useState(!0), [error, setError] = useState(!1), [data, setData] = useState(null), subscription = useRef(null), client = useClient({ apiVersion: "v2022-05-09" });
4203
+ return useEffect(() => (subscription.current = listenQuery(client, query, params, options2).pipe(
4204
+ distinctUntilChanged(isEqual),
4205
+ catchError((err) => (console.error(err), setError(err), setLoading(!1), setData(null), err))
4254
4206
  ).subscribe((documents) => {
4255
- setData((current) => isEqual__default.default(current, documents) ? current : documents), setLoading(!1), setError(!1);
4207
+ setData((current) => isEqual(current, documents) ? current : documents), setLoading(!1), setError(!1);
4256
4208
  }), () => subscription.current ? subscription.current.unsubscribe() : void 0), [query, params, options2, client]), { loading, error, data };
4257
4209
  }
4258
4210
  const NO_DATA = [], defaultTitle = "Sync schema";
4259
4211
  function SchemaTypeTool() {
4260
- const schema = sanity.useSchema(), client = sanity.useClient({ apiVersion: "2023-01-01" }), [saving, setSaving] = react.useState(!1), [syncTitle, setSyncTitle] = react.useState(defaultTitle), { data } = useListeningQuery("*[_type==$type] | order(_type)", {
4212
+ const schema = useSchema(), client = useClient({ apiVersion: "2023-01-01" }), [saving, setSaving] = useState(!1), [syncTitle, setSyncTitle] = useState(defaultTitle), { data } = useListeningQuery("*[_type==$type] | order(_type)", {
4261
4213
  type: assistSerializedTypeName
4262
- }), types = react.useMemo(() => serializeSchema(schema), [schema]), storeTypes = react.useCallback(() => {
4214
+ }), types = useMemo(() => serializeSchema(schema), [schema]), storeTypes = useCallback(() => {
4263
4215
  setSaving(!0);
4264
4216
  let canSave = !0;
4265
4217
  async function store() {
@@ -4277,43 +4229,45 @@ function SchemaTypeTool() {
4277
4229
  canSave = !1, setSaving(!1), setSyncTitle(defaultTitle);
4278
4230
  };
4279
4231
  }, [types, client, setSaving, setSyncTitle]);
4280
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 4, overflow: "auto", style: { height: "calc(100vh - 81px)" }, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
4281
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
4282
- ui.Button,
4232
+ return /* @__PURE__ */ jsx(Card, { padding: 4, overflow: "auto", style: { height: "calc(100vh - 81px)" }, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
4233
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
4234
+ Button,
4283
4235
  {
4284
- icon: saving ? /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { marginTop: 5 } }) : icons.SyncIcon,
4236
+ icon: saving ? /* @__PURE__ */ jsx(Spinner, { style: { marginTop: 5 } }) : SyncIcon,
4285
4237
  text: syncTitle,
4286
4238
  disabled: saving,
4287
4239
  onClick: storeTypes
4288
4240
  }
4289
4241
  ) }),
4290
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, children: [
4291
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
4292
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Studio schema" }),
4293
- /* @__PURE__ */ jsxRuntime.jsx("ul", { children: types.map((type) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(SchemaEntry, { schemaStub: type }) }, type.name)) })
4242
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
4243
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
4244
+ /* @__PURE__ */ jsx(Label, { children: "Studio schema" }),
4245
+ /* @__PURE__ */ jsx("ul", { children: types.map((type) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(SchemaEntry, { schemaStub: type }) }, type.name)) })
4294
4246
  ] }),
4295
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
4296
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Stored schema" }),
4297
- /* @__PURE__ */ jsxRuntime.jsx("ul", { children: (data ?? NO_DATA).map((type) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(SchemaEntry, { schemaStub: type }) }, type.name)) })
4247
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
4248
+ /* @__PURE__ */ jsx(Label, { children: "Stored schema" }),
4249
+ /* @__PURE__ */ jsx("ul", { children: (data ?? NO_DATA).map((type) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(SchemaEntry, { schemaStub: type }) }, type.name)) })
4298
4250
  ] })
4299
4251
  ] })
4300
4252
  ] }) });
4301
4253
  }
4302
4254
  function SchemaEntry({ schemaStub }) {
4303
- const out = react.useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub]);
4304
- return /* @__PURE__ */ jsxRuntime.jsx("pre", { children: out });
4255
+ const out = useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub]);
4256
+ return /* @__PURE__ */ jsx("pre", { children: out });
4305
4257
  }
4306
4258
  function useUserInput() {
4307
4259
  const { getUserInput } = useRunInstruction();
4308
4260
  return getUserInput;
4309
4261
  }
4310
- exports.SchemaTypeTool = SchemaTypeTool;
4311
- exports.assist = assist;
4312
- exports.contextDocumentTypeName = contextDocumentTypeName;
4313
- exports.defaultLanguageOutputs = defaultLanguageOutputs;
4314
- exports.defineAssistFieldAction = defineAssistFieldAction;
4315
- exports.defineAssistFieldActionGroup = defineAssistFieldActionGroup;
4316
- exports.defineFieldActionDivider = defineFieldActionDivider;
4317
- exports.isType = isType;
4318
- exports.useUserInput = useUserInput;
4262
+ export {
4263
+ SchemaTypeTool,
4264
+ assist,
4265
+ contextDocumentTypeName,
4266
+ defaultLanguageOutputs,
4267
+ defineAssistFieldAction,
4268
+ defineAssistFieldActionGroup,
4269
+ defineFieldActionDivider,
4270
+ isType,
4271
+ useUserInput
4272
+ };
4319
4273
  //# sourceMappingURL=index.js.map