@sanity/assist 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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, Badge, Popover, Card, Box, ErrorBoundary, focusFirstDescendant, Spinner, Container, Autocomplete, Breadcrumbs, useClickOutside, 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, ArrowRightIcon, CheckmarkIcon, SearchIcon, SyncIcon, ErrorOutlineIcon, CheckmarkCircleIcon, ClockIcon, CloseCircleIcon, RetryIcon, 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,52 +947,52 @@ 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) });
954
+ return /* @__PURE__ */ jsx(AssistDocumentContextProvider, { documentType, documentId, children: props.renderDefault(props) });
948
955
  }
949
956
  function AssistFeatureBadge() {
950
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { fontSize: 0, style: { margin: "-2px 0" }, tone: "primary", children: "Beta" });
957
+ return /* @__PURE__ */ jsx(Badge, { fontSize: 0, style: { margin: "-2px 0" }, tone: "primary", children: "Beta" });
951
958
  }
952
959
  function AssistOnboardingPopover(props) {
953
960
  const { dismiss } = props;
954
- return /* @__PURE__ */ jsxRuntime.jsx(
955
- ui.Popover,
961
+ return /* @__PURE__ */ jsx(
962
+ Popover,
956
963
  {
957
- content: /* @__PURE__ */ jsxRuntime.jsx(AssistIntroCard, { dismiss }),
964
+ content: /* @__PURE__ */ jsx(AssistIntroCard, { dismiss }),
958
965
  open: !0,
959
966
  portal: !0,
960
967
  placeholder: "bottom",
961
968
  tone: "default",
962
969
  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 }) })
970
+ children: /* @__PURE__ */ jsx(Card, { radius: 2, shadow: 2, style: { padding: 2, lineHeight: 0 }, children: /* @__PURE__ */ jsx(Button, { disabled: !0, fontSize: 1, icon: SparklesIcon, mode: "bleed", padding: 2 }) })
964
971
  }
965
972
  );
966
973
  }
967
974
  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, {}) })
975
+ const buttonRef = useRef(null);
976
+ return /* @__PURE__ */ jsxs(Stack, { as: "section", padding: 3, space: 3, children: [
977
+ /* @__PURE__ */ jsxs(Stack, { padding: 2, space: 4, children: [
978
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
979
+ /* @__PURE__ */ jsx(Text, { as: "h1", size: 1, weight: "semibold", children: pluginTitle }),
980
+ /* @__PURE__ */ jsx("div", { "aria-hidden": !0, style: { margin: "-3px 0", lineHeight: 0 }, children: /* @__PURE__ */ jsx(AssistFeatureBadge, {}) })
974
981
  ] }),
975
- /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 3, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { as: "p", muted: !0, size: 1, children: [
982
+ /* @__PURE__ */ jsx(Stack, { space: 3, children: /* @__PURE__ */ jsxs(Text, { as: "p", muted: !0, size: 1, children: [
976
983
  "Manage reusable AI instructions to boost your content creation and reduce amount of repetitive chores.",
977
984
  " ",
978
- /* @__PURE__ */ jsxRuntime.jsxs("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: [
985
+ /* @__PURE__ */ jsxs("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: [
979
986
  "Learn more ",
980
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRightIcon, {})
987
+ /* @__PURE__ */ jsx(ArrowRightIcon, {})
981
988
  ] })
982
989
  ] }) })
983
990
  ] }),
984
- /* @__PURE__ */ jsxRuntime.jsx(
985
- ui.Button,
991
+ /* @__PURE__ */ jsx(
992
+ Button,
986
993
  {
987
994
  fontSize: 1,
988
- icon: icons.CheckmarkIcon,
995
+ icon: CheckmarkIcon,
989
996
  onClick: props.dismiss,
990
997
  padding: 3,
991
998
  ref: buttonRef,
@@ -1003,14 +1010,14 @@ function dismissFeatureOnboarding(featureKey) {
1003
1010
  typeof localStorage > "u" || localStorage.setItem(featureKey, "true");
1004
1011
  }
1005
1012
  function useOnboardingFeature(featureKey) {
1006
- const [showOnboarding, setShowOnboarding] = react.useState(
1013
+ const [showOnboarding, setShowOnboarding] = useState(
1007
1014
  () => !isFeatureOnboardingDismissed(featureKey)
1008
- ), dismissOnboarding = react.useCallback(() => {
1015
+ ), dismissOnboarding = useCallback(() => {
1009
1016
  setShowOnboarding(!1), dismissFeatureOnboarding(featureKey);
1010
1017
  }, [setShowOnboarding, featureKey]);
1011
1018
  return { showOnboarding, dismissOnboarding };
1012
1019
  }
1013
- const fadeIn = styledComponents.keyframes`
1020
+ const fadeIn = keyframes`
1014
1021
  0% {
1015
1022
  opacity: 0;
1016
1023
  transform: scale(0.75);
@@ -1023,14 +1030,14 @@ const fadeIn = styledComponents.keyframes`
1023
1030
  opacity: 1;
1024
1031
  transform: scale(1);
1025
1032
  }
1026
- `, FadeInDiv = styledComponents.styled.div`
1033
+ `, FadeInDiv = styled.div`
1027
1034
  animation-name: ${fadeIn};
1028
1035
  animation-timing-function: ease-in-out;
1029
- `, FadeInContent = react.forwardRef(function({
1036
+ `, FadeInContent = forwardRef(function({
1030
1037
  children,
1031
1038
  durationMs = 250
1032
1039
  }, ref) {
1033
- return /* @__PURE__ */ jsxRuntime.jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
1040
+ return /* @__PURE__ */ jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
1034
1041
  }), purple = {
1035
1042
  400: {
1036
1043
  hex: "#b087f7"
@@ -1041,19 +1048,19 @@ const fadeIn = styledComponents.keyframes`
1041
1048
  600: {
1042
1049
  hex: "#721fe5"
1043
1050
  }
1044
- }, Root = styledComponents.styled.span`
1051
+ }, Root = styled.span`
1045
1052
  display: block;
1046
1053
  width: 25px;
1047
1054
  height: 25px;
1048
1055
  position: relative;
1049
- `, dash = styledComponents.keyframes`
1056
+ `, dash = keyframes`
1050
1057
  0% {
1051
1058
  transform: rotate(0);
1052
1059
  }
1053
1060
  100% {
1054
1061
  transform: rotate(43deg);
1055
1062
  }
1056
- `, Outline = styledComponents.styled.svg`
1063
+ `, Outline = styled.svg`
1057
1064
  display: block;
1058
1065
  position: absolute;
1059
1066
  top: 0;
@@ -1073,7 +1080,7 @@ const fadeIn = styledComponents.keyframes`
1073
1080
  stroke-dasharray: 2px 2.34px;
1074
1081
  }
1075
1082
  }
1076
- `, IconDisc = styledComponents.styled.span`
1083
+ `, IconDisc = styled.span`
1077
1084
  background: var(--ai-avatar-disc-color);
1078
1085
  color: white;
1079
1086
  width: 21px;
@@ -1087,15 +1094,15 @@ const fadeIn = styledComponents.keyframes`
1087
1094
  left: 2px;
1088
1095
  `;
1089
1096
  function AssistAvatar(props) {
1090
- const { state = "present" } = props, scheme = sanity.useColorSchemeValue(), style = react.useMemo(() => scheme === "dark" ? {
1097
+ const { state = "present" } = props, scheme = useColorSchemeValue(), style = useMemo(() => scheme === "dark" ? {
1091
1098
  "--ai-avatar-stroke-color": purple[400].hex,
1092
1099
  "--ai-avatar-disc-color": purple[600].hex
1093
1100
  } : {
1094
1101
  "--ai-avatar-stroke-color": purple[500].hex,
1095
1102
  "--ai-avatar-disc-color": purple[600].hex
1096
1103
  }, [scheme]);
1097
- return /* @__PURE__ */ jsxRuntime.jsxs(Root, { "data-state": state, style, children: [
1098
- /* @__PURE__ */ jsxRuntime.jsx(
1104
+ return /* @__PURE__ */ jsxs(Root, { "data-state": state, style, children: [
1105
+ /* @__PURE__ */ jsx(
1099
1106
  Outline,
1100
1107
  {
1101
1108
  width: "25",
@@ -1103,35 +1110,35 @@ function AssistAvatar(props) {
1103
1110
  viewBox: "0 0 25 25",
1104
1111
  fill: "none",
1105
1112
  xmlns: "http://www.w3.org/2000/svg",
1106
- children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12.5", cy: "12.5", r: "11.75" })
1113
+ children: /* @__PURE__ */ jsx("circle", { cx: "12.5", cy: "12.5", r: "11.75" })
1107
1114
  }
1108
1115
  ),
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" } }) }) })
1116
+ /* @__PURE__ */ jsx(IconDisc, { children: /* @__PURE__ */ jsx(Text, { as: "span", size: 0, style: { color: "inherit" }, children: /* @__PURE__ */ jsx(SparklesIcon, { style: { color: "inherit" } }) }) })
1110
1117
  ] });
1111
1118
  }
1112
1119
  function AiFieldPresence(props) {
1113
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { style: { position: "relative", background: "transparent" }, contentEditable: !1, children: /* @__PURE__ */ jsxRuntime.jsx(
1114
- ui.Tooltip,
1120
+ return /* @__PURE__ */ jsx(Card, { style: { position: "relative", background: "transparent" }, contentEditable: !1, children: /* @__PURE__ */ jsx(
1121
+ Tooltip,
1115
1122
  {
1116
1123
  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" }) })
1124
+ content: /* @__PURE__ */ jsx(Card, { padding: 3, border: !0, children: /* @__PURE__ */ jsx(Flex, { align: "center", children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Running instruction..." }) }) }),
1125
+ children: /* @__PURE__ */ jsx(FadeInContent, { durationMs: 300, children: /* @__PURE__ */ jsx(AssistAvatar, { state: "active" }) })
1119
1126
  }
1120
1127
  ) });
1121
1128
  }
1122
1129
  const NO_PRESENCE = [];
1123
1130
  function useAssistPresence(path, showFocusWithin) {
1124
1131
  const context = useAssistDocumentContext(), tasks = (context && "assistDocument" in context ? context.assistDocument : void 0)?.tasks;
1125
- return react.useMemo(() => {
1132
+ return useMemo(() => {
1126
1133
  const activePresence = tasks?.filter((task) => !task.ended)?.flatMap((task) => task.presence ?? [])?.filter(
1127
1134
  (p) => p.started && (/* @__PURE__ */ new Date()).getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs
1128
1135
  ).filter((presence) => {
1129
1136
  if (!presence.path || !path.length)
1130
1137
  return !1;
1131
- const statusPath = sanity.stringToPath(presence.path);
1138
+ const statusPath = stringToPath(presence.path);
1132
1139
  return !showFocusWithin && statusPath.length !== path.length ? !1 : path.every((pathSegment, i) => {
1133
1140
  const statusSegment = statusPath[i];
1134
- return typeof pathSegment == "string" ? pathSegment === statusSegment : sanity.isKeySegment(pathSegment) && sanity.isKeySegment(statusSegment) ? pathSegment._key === statusSegment._key : !1;
1141
+ return typeof pathSegment == "string" ? pathSegment === statusSegment : isKeySegment(pathSegment) && isKeySegment(statusSegment) ? pathSegment._key === statusSegment._key : !1;
1135
1142
  });
1136
1143
  });
1137
1144
  return activePresence?.length ? activePresence.map((status) => aiPresence(status, path)) : NO_PRESENCE;
@@ -1150,18 +1157,18 @@ function aiPresence(presence, path, title) {
1150
1157
  }
1151
1158
  function AssistFieldWrapper(props) {
1152
1159
  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);
1160
+ 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
1161
  }
1155
1162
  function AssistField(props) {
1156
- const { path } = props, isPortableText = react.useMemo(
1157
- () => !!(sanity.isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
1163
+ const { path } = props, isPortableText = useMemo(
1164
+ () => !!(isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
1158
1165
  [props.schemaType]
1159
- ), presence = useAssistPresence(props.path, isPortableText), firstAssistedPath = react.useContext(FirstAssistedPathContext), isFirstAssisted = react.useMemo(
1160
- () => sanity.pathToString(path) === firstAssistedPath,
1166
+ ), presence = useAssistPresence(props.path, isPortableText), firstAssistedPath = useContext(FirstAssistedPathContext), isFirstAssisted = useMemo(
1167
+ () => pathToString(path) === firstAssistedPath,
1161
1168
  [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 })
1169
+ ), { showOnboarding, dismissOnboarding } = useOnboardingFeature(fieldOnboardingKey), singlePresence = presence[0], actions = /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", justify: "space-between", children: [
1170
+ singlePresence && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(AiFieldPresence, { presence: singlePresence }) }),
1171
+ isFirstAssisted && showOnboarding && /* @__PURE__ */ jsx(AssistOnboardingPopover, { dismiss: dismissOnboarding })
1165
1172
  ] });
1166
1173
  return props.renderDefault({
1167
1174
  ...props,
@@ -1172,57 +1179,57 @@ function AssistField(props) {
1172
1179
  __internal_slot: actions
1173
1180
  });
1174
1181
  }
1175
- const WrapPreCard = styledComponents.styled(ui.Card)`
1182
+ const WrapPreCard = styled(Card)`
1176
1183
  & pre {
1177
1184
  white-space: pre-wrap !important;
1178
1185
  }
1179
1186
  `;
1180
1187
  function SafeValueInput(props) {
1181
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorWrapper, { onChange: props.onChange, children: /* @__PURE__ */ jsxRuntime.jsx(PteValueFixer, { ...props }) });
1188
+ return /* @__PURE__ */ jsx(ErrorWrapper, { onChange: props.onChange, children: /* @__PURE__ */ jsx(PteValueFixer, { ...props }) });
1182
1189
  }
1183
1190
  function ErrorWrapper(props) {
1184
- const { onChange } = props, [error, setError] = react.useState(), catchError = react.useCallback((params) => {
1191
+ const { onChange } = props, [error, setError] = useState(), catchError2 = useCallback((params) => {
1185
1192
  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" })
1193
+ }, []), unsetValue = useCallback(() => {
1194
+ onChange(PatchEvent.from(unset())), setError(void 0);
1195
+ }, [onChange]), dismiss = useCallback(() => setError(void 0), []), catcher = /* @__PURE__ */ jsx(ErrorBoundary, { onCatch: catchError2, children: props.children });
1196
+ return error ? /* @__PURE__ */ jsx(Card, { border: !0, tone: "critical", padding: 2, contentEditable: !1, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
1197
+ /* @__PURE__ */ jsx(Text, { muted: !0, weight: "semibold", children: "An error occurred." }),
1198
+ /* @__PURE__ */ jsx(WrapPreCard, { flex: 1, padding: 2, tone: "critical", border: !0, children: catcher }),
1199
+ /* @__PURE__ */ jsxs(Flex, { width: "fill", flex: 1, gap: 3, children: [
1200
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Button, { text: "Dismiss", onClick: dismiss, tone: "primary" }) }),
1201
+ /* @__PURE__ */ jsx(Button, { text: "Unset value", onClick: unsetValue, tone: "critical" })
1195
1202
  ] })
1196
1203
  ] }) }) : catcher;
1197
1204
  }
1198
1205
  function PteValueFixer(props) {
1199
- const isPortableText = react.useMemo(
1200
- () => sanity.isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType),
1206
+ const isPortableText = useMemo(
1207
+ () => isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType),
1201
1208
  [props.schemaType]
1202
1209
  ), value = props.value;
1203
1210
  return isPortableText && value && !value.length ? props.renderDefault({ ...props, value: void 0 }) : props.renderDefault(props);
1204
1211
  }
1205
1212
  function AssistFormBlock(props) {
1206
- const presence = useAssistPresence(props.path, !0), { onChange } = sanity.useFormCallbacks(), key = props.value._key, localOnChange = react.useCallback(
1213
+ const presence = useAssistPresence(props.path, !0), { onChange } = useFormCallbacks(), key = props.value._key, localOnChange = useCallback(
1207
1214
  (patchEvent) => {
1208
- key && onChange(sanity.PatchEvent.from(patchEvent).prefixAll({ _key: key }));
1215
+ key && onChange(PatchEvent.from(patchEvent).prefixAll({ _key: key }));
1209
1216
  },
1210
1217
  [onChange, key]
1211
1218
  ), 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 })
1219
+ return /* @__PURE__ */ jsx(ErrorWrapper, { onChange: localOnChange, children: /* @__PURE__ */ jsxs(Flex, { align: "center", justify: "space-between", children: [
1220
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: props.renderDefault(props) }),
1221
+ singlePresence && /* @__PURE__ */ jsx(AiFieldPresence, { presence: singlePresence })
1215
1222
  ] }) });
1216
1223
  }
1217
- const InlineBlockValueContext = react.createContext(void 0);
1224
+ const InlineBlockValueContext = createContext(void 0);
1218
1225
  function AssistInlineFormBlock(props) {
1219
- return /* @__PURE__ */ jsxRuntime.jsx(InlineBlockValueContext.Provider, { value: props.value, children: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.renderDefault(props) }) });
1226
+ return /* @__PURE__ */ jsx(InlineBlockValueContext.Provider, { value: props.value, children: /* @__PURE__ */ jsx(Fragment, { children: props.renderDefault(props) }) });
1220
1227
  }
1221
1228
  function AssistItem(props) {
1222
1229
  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))
1230
+ return /* @__PURE__ */ jsxs(Flex, { align: "center", width: "fill", style: { position: "relative" }, children: [
1231
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: props.renderDefault({ ...props }) }),
1232
+ presence.map((pre) => /* @__PURE__ */ jsx(Box, { style: { position: "absolute", right: 35 }, children: /* @__PURE__ */ jsx(AiFieldPresence, { presence: pre }) }, pre.user.id))
1226
1233
  ] });
1227
1234
  }
1228
1235
  const preventDefault = (ev) => ev.preventDefault();
@@ -1244,10 +1251,10 @@ function DocumentForm(props) {
1244
1251
  onSetCollapsedPath,
1245
1252
  ready,
1246
1253
  validation
1247
- } = structure.useDocumentPane(), documentStore = sanity.useDocumentStore(), presence = sanity.useDocumentPresence(documentId), patchChannel = react.useMemo(() => sanity.createPatchChannel(), []), isLocked = editState?.transactionSyncLock?.enabled;
1248
- react.useEffect(() => {
1254
+ } = useDocumentPane(), documentStore = useDocumentStore(), presence = useDocumentPresence(documentId), patchChannel = useMemo(() => createPatchChannel(), []), isLocked = editState?.transactionSyncLock?.enabled;
1255
+ useEffect(() => {
1249
1256
  const sub = documentStore.pair.documentEvents(documentId, documentType).pipe(
1250
- operators.tap((event) => {
1257
+ tap((event) => {
1251
1258
  event.type === "mutation" && patchChannel.publish(prepareMutationEvent(event)), event.type === "rebase" && patchChannel.publish(prepareRebaseEvent(event));
1252
1259
  })
1253
1260
  ).subscribe();
@@ -1256,18 +1263,18 @@ function DocumentForm(props) {
1256
1263
  };
1257
1264
  }, [documentId, documentStore, documentType, patchChannel]);
1258
1265
  const hasRev = !!value?._rev;
1259
- react.useEffect(() => {
1266
+ useEffect(() => {
1260
1267
  hasRev && patchChannel.publish({
1261
1268
  type: "mutation",
1262
1269
  patches: [],
1263
1270
  snapshot: value
1264
1271
  });
1265
1272
  }, [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,
1273
+ const formRef = useRef(null);
1274
+ return useEffect(() => {
1275
+ focusFirstDescendant(formRef.current);
1276
+ }, []), isLocked ? /* @__PURE__ */ jsx(Box, { as: "form", ...props, ref: formRef, children: /* @__PURE__ */ jsx(
1277
+ Flex,
1271
1278
  {
1272
1279
  align: "center",
1273
1280
  direction: "column",
@@ -1275,10 +1282,10 @@ function DocumentForm(props) {
1275
1282
  justify: "center",
1276
1283
  padding: 3,
1277
1284
  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" })
1285
+ 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
1286
  }
1280
- ) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { as: "form", ...props, onSubmit: preventDefault, ref: formRef, children: ready ? formState === null ? /* @__PURE__ */ jsxRuntime.jsx(
1281
- ui.Flex,
1287
+ ) }) : /* @__PURE__ */ jsx(Box, { as: "form", ...props, onSubmit: preventDefault, ref: formRef, children: ready ? formState === null ? /* @__PURE__ */ jsx(
1288
+ Flex,
1282
1289
  {
1283
1290
  align: "center",
1284
1291
  direction: "column",
@@ -1286,10 +1293,10 @@ function DocumentForm(props) {
1286
1293
  justify: "center",
1287
1294
  padding: 3,
1288
1295
  sizing: "border",
1289
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "This form is hidden" })
1296
+ children: /* @__PURE__ */ jsx(Text, { size: 1, children: "This form is hidden" })
1290
1297
  }
1291
- ) : /* @__PURE__ */ jsxRuntime.jsx(
1292
- sanity.FormBuilder,
1298
+ ) : /* @__PURE__ */ jsx(
1299
+ FormBuilder,
1293
1300
  {
1294
1301
  __internal_patchChannel: patchChannel,
1295
1302
  collapsedFieldSets,
@@ -1311,10 +1318,11 @@ function DocumentForm(props) {
1311
1318
  readOnly: formState.readOnly,
1312
1319
  schemaType: formState.schemaType,
1313
1320
  validation,
1314
- value: formState.value
1321
+ value: formState.value,
1322
+ hasUpstreamVersion: !1
1315
1323
  }
1316
- ) : /* @__PURE__ */ jsxRuntime.jsxs(
1317
- ui.Flex,
1324
+ ) : /* @__PURE__ */ jsxs(
1325
+ Flex,
1318
1326
  {
1319
1327
  align: "center",
1320
1328
  direction: "column",
@@ -1323,8 +1331,8 @@ function DocumentForm(props) {
1323
1331
  padding: 3,
1324
1332
  sizing: "border",
1325
1333
  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" }) })
1334
+ /* @__PURE__ */ jsx(Spinner, { muted: !0 }),
1335
+ /* @__PURE__ */ jsx(Box, { marginTop: 3, children: /* @__PURE__ */ jsx(Text, { align: "center", muted: !0, size: 1, children: "Loading document" }) })
1328
1336
  ]
1329
1337
  }
1330
1338
  ) });
@@ -1334,7 +1342,7 @@ function prepareMutationEvent(event) {
1334
1342
  return {
1335
1343
  type: "mutation",
1336
1344
  snapshot: event.document,
1337
- patches: sanity.fromMutationPatches(event.origin, patches)
1345
+ patches: fromMutationPatches(event.origin, patches)
1338
1346
  };
1339
1347
  }
1340
1348
  function prepareRebaseEvent(event) {
@@ -1342,12 +1350,12 @@ function prepareRebaseEvent(event) {
1342
1350
  return {
1343
1351
  type: "rebase",
1344
1352
  snapshot: event.document,
1345
- patches: sanity.fromMutationPatches("remote", remotePatches).concat(
1346
- sanity.fromMutationPatches("local", localPatches)
1353
+ patches: fromMutationPatches("remote", remotePatches).concat(
1354
+ fromMutationPatches("local", localPatches)
1347
1355
  )
1348
1356
  };
1349
1357
  }
1350
- const AssistTypeContext = react.createContext({}), DEFAULT_MAX_DEPTH$1 = 8, ABSOLUTE_MAX_DEPTH$1 = 50;
1358
+ const AssistTypeContext = createContext({}), DEFAULT_MAX_DEPTH$1 = 8, ABSOLUTE_MAX_DEPTH$1 = 50;
1351
1359
  function getConditionalMembers(docState, maxDepth2 = DEFAULT_MAX_DEPTH$1) {
1352
1360
  return [{
1353
1361
  path: "",
@@ -1361,7 +1369,7 @@ function isConditional(schemaType) {
1361
1369
  }
1362
1370
  function conditionalState(memberState) {
1363
1371
  return {
1364
- path: sanity.pathToString(memberState.path),
1372
+ path: pathToString(memberState.path),
1365
1373
  readOnly: !!memberState.readOnly,
1366
1374
  // Use actual form state readOnly value
1367
1375
  hidden: !1,
@@ -1382,7 +1390,7 @@ function extractConditionalPaths(node, maxDepth2) {
1382
1390
  const array = member.field;
1383
1391
  let arrayPaths = [];
1384
1392
  const isObjectsArray = array.members.some(
1385
- (m) => m.kind === "item" && sanity.isObjectSchemaType(m.item.schemaType)
1393
+ (m) => m.kind === "item" && isObjectSchemaType(m.item.schemaType)
1386
1394
  );
1387
1395
  if (!array.readOnly)
1388
1396
  for (const arrayMember of array.members) {
@@ -1407,7 +1415,7 @@ function extractConditionalPaths(node, maxDepth2) {
1407
1415
  return acc;
1408
1416
  }, []);
1409
1417
  }
1410
- const SparklesIllustration = styledComponents.styled(icons.SparklesIcon)({
1418
+ const SparklesIllustration = styled(SparklesIcon)({
1411
1419
  fontSize: "3.125em",
1412
1420
  "& path": {
1413
1421
  strokeWidth: "0.6px !important"
@@ -1415,12 +1423,12 @@ const SparklesIllustration = styledComponents.styled(icons.SparklesIcon)({
1415
1423
  });
1416
1424
  function InspectorOnboarding(props) {
1417
1425
  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,
1426
+ return /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsx(Container, { width: 0, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
1427
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(SparklesIllustration, {}) }),
1428
+ /* @__PURE__ */ jsx(Text, { align: "center", size: 1, children: "Create reusable AI instructions that can be applied across all documents of a certain type." }),
1429
+ /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, justify: "center", children: [
1430
+ /* @__PURE__ */ jsx(
1431
+ Button,
1424
1432
  {
1425
1433
  as: "a",
1426
1434
  href: releaseAnnouncementUrl,
@@ -1434,35 +1442,35 @@ function InspectorOnboarding(props) {
1434
1442
  tone: "primary"
1435
1443
  }
1436
1444
  ),
1437
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, mode: "bleed", onClick: onDismiss, padding: 2, text: "Dismiss" })
1445
+ /* @__PURE__ */ jsx(Button, { fontSize: 1, mode: "bleed", onClick: onDismiss, padding: 2, text: "Dismiss" })
1438
1446
  ] })
1439
1447
  ] }) }) });
1440
1448
  }
1441
1449
  function FieldAutocomplete(props) {
1442
- const { id, schemaType, fieldPath, onSelect, includeDocument, filter } = props, { getFieldRefs: getFieldRefs2 } = useAiAssistanceConfig(), fieldRefs = react.useMemo(() => {
1450
+ const { id, schemaType, fieldPath, onSelect, includeDocument, filter: filter2 } = props, { getFieldRefs: getFieldRefs2 } = useAiAssistanceConfig(), fieldRefs = useMemo(() => {
1443
1451
  const refs = getFieldRefs2(schemaType.name);
1444
1452
  return includeDocument ? [getDocumentFieldRef(schemaType), ...refs] : refs;
1445
- }, [schemaType, includeDocument, getFieldRefs2]), currentField = react.useMemo(
1453
+ }, [schemaType, includeDocument, getFieldRefs2]), currentField = useMemo(
1446
1454
  () => fieldRefs.find((f) => f.key === fieldPath),
1447
1455
  [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) => {
1456
+ ), autocompleteOptions = useMemo(
1457
+ () => fieldRefs.filter((field) => filter2 ? filter2(field) : !0).filter((f) => !isType(f.schemaType, "reference")).map((field) => ({ value: field.key, field })),
1458
+ [fieldRefs, filter2]
1459
+ ), renderOption = useCallback((option) => {
1452
1460
  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) => {
1461
+ 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: [
1462
+ /* @__PURE__ */ jsx(Text, { size: 1, children: createElement(field.icon) }),
1463
+ /* @__PURE__ */ jsx(FieldTitle, { field })
1464
+ ] }) }) : /* @__PURE__ */ jsx(Card, { as: "button", padding: 3, radius: 1, children: /* @__PURE__ */ jsx(Text, { accent: !0, size: 1, children: option.value }) });
1465
+ }, []), renderValue = useCallback((value, option) => option?.field.title ?? value, []), filterOption = useCallback((query, option) => {
1458
1466
  const lQuery = query.toLowerCase();
1459
1467
  return option?.value?.toLowerCase().includes(lQuery) || option?.field?.title?.toLowerCase().includes(lQuery);
1460
1468
  }, []);
1461
- return /* @__PURE__ */ jsxRuntime.jsx(
1462
- ui.Autocomplete,
1469
+ return /* @__PURE__ */ jsx(
1470
+ Autocomplete,
1463
1471
  {
1464
1472
  fontSize: 1,
1465
- icon: currentField ? currentField.icon : icons.SearchIcon,
1473
+ icon: currentField ? currentField.icon : SearchIcon,
1466
1474
  onChange: onSelect,
1467
1475
  openButton: !0,
1468
1476
  id,
@@ -1478,8 +1486,8 @@ function FieldAutocomplete(props) {
1478
1486
  }
1479
1487
  function FieldTitle(props) {
1480
1488
  const splitTitle = props.field.title.split("/");
1481
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsxs(
1482
- ui.Breadcrumbs,
1489
+ return /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxs(
1490
+ Breadcrumbs,
1483
1491
  {
1484
1492
  style: {
1485
1493
  display: "flex",
@@ -1487,77 +1495,77 @@ function FieldTitle(props) {
1487
1495
  alignItems: "center",
1488
1496
  marginTop: "-4px"
1489
1497
  },
1490
- separator: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "/" }) }),
1498
+ separator: /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "/" }) }),
1491
1499
  space: 1,
1492
1500
  children: [
1493
1501
  splitTitle.slice(0, splitTitle.length - 1).map((pt, i) => (
1494
1502
  // 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)
1503
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: pt.trim() }) }, i)
1496
1504
  )),
1497
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "medium", children: splitTitle[splitTitle.length - 1] }) })
1505
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "medium", children: splitTitle[splitTitle.length - 1] }) })
1498
1506
  ]
1499
1507
  }
1500
1508
  ) });
1501
1509
  }
1502
1510
  function useInterval(ms) {
1503
- const [tick, update] = react.useReducer((n) => n + 1, 0);
1504
- return react.useEffect(() => {
1511
+ const [tick, update] = useReducer((n) => n + 1, 0);
1512
+ return useEffect(() => {
1505
1513
  const i = setInterval(update, ms);
1506
1514
  return () => clearInterval(i);
1507
1515
  }, [ms]), tick;
1508
1516
  }
1509
1517
  function TimeAgo({ date }) {
1510
1518
  useInterval(1e3);
1511
- const timeSince = dateFns.formatDistanceToNow(date ? new Date(date) : /* @__PURE__ */ new Date());
1512
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { title: timeSince, children: [
1519
+ const timeSince = formatDistanceToNow(date ? new Date(date) : /* @__PURE__ */ new Date());
1520
+ return /* @__PURE__ */ jsxs("span", { title: timeSince, children: [
1513
1521
  timeSince,
1514
1522
  " ago"
1515
1523
  ] });
1516
1524
  }
1517
- const rotate = styledComponents.keyframes`
1525
+ const rotate = keyframes`
1518
1526
  0% {
1519
1527
  transform: rotate(0);
1520
1528
  }
1521
1529
  100% {
1522
1530
  transform: rotate(360deg);
1523
1531
  }
1524
- `, SyncSpinningIcon = styledComponents.styled(icons.SyncIcon)`
1532
+ `, SyncSpinningIcon = styled(SyncIcon)`
1525
1533
  animation: ${rotate} 1s linear infinite;
1526
1534
  `, TASK_CONFIG = {
1527
1535
  aborted: {
1528
1536
  title: "Canceled",
1529
- icon: icons.CloseCircleIcon,
1537
+ icon: CloseCircleIcon,
1530
1538
  tone: "transparent"
1531
1539
  },
1532
1540
  error: {
1533
1541
  title: "Error",
1534
- icon: icons.ErrorOutlineIcon,
1542
+ icon: ErrorOutlineIcon,
1535
1543
  tone: "critical"
1536
1544
  },
1537
1545
  success: {
1538
1546
  title: "Completed",
1539
- icon: icons.CheckmarkCircleIcon,
1547
+ icon: CheckmarkCircleIcon,
1540
1548
  tone: "positive"
1541
1549
  },
1542
1550
  timeout: {
1543
1551
  title: "Timeout",
1544
- icon: icons.ClockIcon,
1552
+ icon: ClockIcon,
1545
1553
  tone: "caution"
1546
1554
  }
1547
1555
  };
1548
1556
  function InstructionTaskHistoryButton(props) {
1549
- const { tasks, instructions, documentId, showTitles } = props, client = sanity.useClient({ apiVersion: "2023-01-01" }), cancelRun = react.useCallback(
1557
+ const { tasks, instructions, documentId, showTitles } = props, client = useClient({ apiVersion: "2023-01-01" }), cancelRun = useCallback(
1550
1558
  (taskKey) => {
1551
1559
  if (!documentId)
1552
1560
  return;
1553
- const statusDocId = assistTasksStatusId(documentId), basePath2 = `${sanity.typed("tasks")}[_key=="${taskKey}"]`;
1561
+ const statusDocId = assistTasksStatusId(documentId), basePath2 = `${typed("tasks")}[_key=="${taskKey}"]`;
1554
1562
  client.patch(statusDocId).set({
1555
- [`${basePath2}.${sanity.typed("ended")}`]: (/* @__PURE__ */ new Date()).toISOString(),
1556
- [`${basePath2}.${sanity.typed("reason")}`]: sanity.typed("aborted")
1563
+ [`${basePath2}.${typed("ended")}`]: (/* @__PURE__ */ new Date()).toISOString(),
1564
+ [`${basePath2}.${typed("reason")}`]: typed("aborted")
1557
1565
  }).commit().catch(console.error);
1558
1566
  },
1559
1567
  [client, documentId]
1560
- ), titledTasks = react.useMemo(() => {
1568
+ ), titledTasks = useMemo(() => {
1561
1569
  const t = tasks?.filter(
1562
1570
  (task) => task.started && (/* @__PURE__ */ new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs
1563
1571
  ).map((task) => {
@@ -1569,27 +1577,27 @@ function InstructionTaskHistoryButton(props) {
1569
1577
  };
1570
1578
  }) ?? [];
1571
1579
  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(
1580
+ }, [tasks, instructions, cancelRun, showTitles]), isRunning = useMemo(() => titledTasks.some((r) => !r.ended), [titledTasks]), hasErrors = useMemo(
1573
1581
  () => titledTasks.some((r) => r.reason === "error" || r.reason === "timeout"),
1574
1582
  [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(() => {
1583
+ ), [open, setOpen] = useState(!1), toggleOpen = useCallback(() => setOpen((v) => !v), []), [button, setButton] = useState(null), [popover, setPopover] = useState(null), handleClickOutside = useCallback(() => {
1576
1584
  setOpen(!1);
1577
1585
  }, []);
1578
- ui.useClickOutside(handleClickOutside, [button, popover]);
1579
- const handleEscape = react.useCallback(() => {
1586
+ useClickOutside(handleClickOutside, [button, popover]);
1587
+ const handleEscape = useCallback(() => {
1580
1588
  setOpen(!1), button?.focus();
1581
1589
  }, [button]);
1582
- return /* @__PURE__ */ jsxRuntime.jsx(
1583
- ui.Popover,
1590
+ return /* @__PURE__ */ jsx(
1591
+ Popover,
1584
1592
  {
1585
1593
  constrainSize: !0,
1586
- content: /* @__PURE__ */ jsxRuntime.jsx(TaskList, { onEscape: handleEscape, tasks: titledTasks }),
1594
+ content: /* @__PURE__ */ jsx(TaskList, { onEscape: handleEscape, tasks: titledTasks }),
1587
1595
  open: open && !!titledTasks?.length,
1588
1596
  placement: "top",
1589
1597
  portal: !0,
1590
1598
  ref: setPopover,
1591
1599
  width: 0,
1592
- children: /* @__PURE__ */ jsxRuntime.jsx(
1600
+ children: /* @__PURE__ */ jsx(
1593
1601
  TaskStatusButton,
1594
1602
  {
1595
1603
  disabled: !titledTasks?.length,
@@ -1605,14 +1613,14 @@ function InstructionTaskHistoryButton(props) {
1605
1613
  }
1606
1614
  const TASK_STATUS_BUTTON_TOOLTIP_PROPS = {
1607
1615
  placement: "top"
1608
- }, TaskStatusButton = react.forwardRef(function(props, ref) {
1616
+ }, TaskStatusButton = forwardRef(function(props, ref) {
1609
1617
  const { disabled, hasErrors, isRunning, onClick, selected } = props;
1610
- return /* @__PURE__ */ jsxRuntime.jsx(
1611
- sanity.StatusButton,
1618
+ return /* @__PURE__ */ jsx(
1619
+ StatusButton,
1612
1620
  {
1613
1621
  label: `${pluginTitle} status`,
1614
1622
  "aria-label": `${pluginTitle} status`,
1615
- icon: isRunning ? SyncSpinningIcon : hasErrors ? icons.ErrorOutlineIcon : icons.CheckmarkCircleIcon,
1623
+ icon: isRunning ? SyncSpinningIcon : hasErrors ? ErrorOutlineIcon : CheckmarkCircleIcon,
1616
1624
  mode: "bleed",
1617
1625
  onClick,
1618
1626
  tone: hasErrors ? "critical" : void 0,
@@ -1624,40 +1632,40 @@ const TASK_STATUS_BUTTON_TOOLTIP_PROPS = {
1624
1632
  );
1625
1633
  });
1626
1634
  function TaskList(props) {
1627
- const { onEscape, tasks } = props, { isTopLayer } = ui.useLayer();
1628
- return ui.useGlobalKeyDown(
1629
- react.useCallback(
1635
+ const { onEscape, tasks } = props, { isTopLayer } = useLayer();
1636
+ return useGlobalKeyDown(
1637
+ useCallback(
1630
1638
  (event) => {
1631
1639
  isTopLayer && event.key === "Escape" && onEscape();
1632
1640
  },
1633
1641
  [isTopLayer, onEscape]
1634
1642
  )
1635
- ), /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { padding: 1, space: 1, children: tasks.map((task) => /* @__PURE__ */ jsxRuntime.jsx(TaskItem, { task }, task._key)) });
1643
+ ), /* @__PURE__ */ jsx(Stack, { padding: 1, space: 1, children: tasks.map((task) => /* @__PURE__ */ jsx(TaskItem, { task }, task._key)) });
1636
1644
  }
1637
1645
  function TaskItem(props) {
1638
1646
  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, {})
1647
+ return /* @__PURE__ */ jsx(Card, { radius: 2, tone: taskType && taskType?.tone, children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 1, children: [
1648
+ /* @__PURE__ */ jsxs(Flex, { align: "flex-start", flex: 1, gap: 3, padding: 3, children: [
1649
+ /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsxs(Text, { size: 1, children: [
1650
+ taskType && createElement(taskType.icon),
1651
+ !task.reason && /* @__PURE__ */ jsx(Spinner, {})
1644
1652
  ] }) }),
1645
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { flex: 1, space: 2, children: [
1646
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "medium", children: [
1653
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, space: 2, children: [
1654
+ /* @__PURE__ */ jsxs(Text, { size: 1, weight: "medium", children: [
1647
1655
  taskType ? taskType.title : "Running",
1648
- task.title && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1656
+ task.title && /* @__PURE__ */ jsxs(Fragment, { children: [
1649
1657
  ": ",
1650
1658
  task.title
1651
1659
  ] })
1652
1660
  ] }),
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 }) })
1661
+ task.message ? /* @__PURE__ */ jsx(Text, { size: 1, children: task.message }) : null,
1662
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: /* @__PURE__ */ jsx(TimeAgo, { date: task.ended ?? task.started }) })
1655
1663
  ] })
1656
1664
  ] }),
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" }) })
1665
+ !task.ended && /* @__PURE__ */ jsx(Box, { flex: "none", padding: 1, children: /* @__PURE__ */ jsx(Button, { fontSize: 1, mode: "bleed", onClick: task.cancel, text: "Cancel" }) })
1658
1666
  ] }) });
1659
1667
  }
1660
- const CardWithShadowBelow = styledComponents.styled(ui.Card)`
1668
+ const CardWithShadowBelow = styled(Card)`
1661
1669
  position: relative;
1662
1670
 
1663
1671
  &:after {
@@ -1671,7 +1679,7 @@ const CardWithShadowBelow = styledComponents.styled(ui.Card)`
1671
1679
  opacity: 0.5;
1672
1680
  z-index: 100;
1673
1681
  }
1674
- `, CardWithShadowAbove = styledComponents.styled(ui.Card)`
1682
+ `, CardWithShadowAbove = styled(Card)`
1675
1683
  position: relative;
1676
1684
 
1677
1685
  &:after {
@@ -1689,48 +1697,48 @@ const CardWithShadowBelow = styledComponents.styled(ui.Card)`
1689
1697
  function AssistInspectorWrapper(props) {
1690
1698
  const context = useAiAssistanceConfig();
1691
1699
  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: [
1700
+ return /* @__PURE__ */ jsx(Flex, { align: "center", height: "fill", justify: "center", padding: 4, sizing: "border", children: /* @__PURE__ */ jsxs(Stack, { space: 3, style: { textAlign: "center" }, children: [
1701
+ /* @__PURE__ */ jsx(Spinner, { muted: !0 }),
1702
+ /* @__PURE__ */ jsxs(Text, { muted: !0, size: 1, children: [
1695
1703
  "Loading ",
1696
1704
  pluginTitle,
1697
1705
  "..."
1698
1706
  ] })
1699
1707
  ] }) });
1700
1708
  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,
1709
+ return status?.enabled ? !status?.initialized || !status.validToken ? /* @__PURE__ */ jsxs(Flex, { direction: "column", height: "fill", children: [
1710
+ /* @__PURE__ */ jsx(
1711
+ DocumentInspectorHeader,
1704
1712
  {
1705
1713
  closeButtonLabel: "Close",
1706
1714
  onClose: props.onClose,
1707
1715
  title: pluginTitle
1708
1716
  }
1709
1717
  ),
1710
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { padding: 4, space: 3, children: [
1711
- context.error ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "semibold", children: [
1718
+ /* @__PURE__ */ jsxs(Stack, { padding: 4, space: 3, children: [
1719
+ context.error ? /* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
1712
1720
  "Failed to start ",
1713
1721
  pluginTitle
1714
1722
  ] }) : null,
1715
- !context.error && !status?.initialized ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "semibold", children: [
1723
+ !context.error && !status?.initialized ? /* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
1716
1724
  pluginTitle,
1717
1725
  " is not enabled"
1718
1726
  ] }) : 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." })
1727
+ !context.error && status?.initialized && !status.validToken ? /* @__PURE__ */ jsxs(Fragment, { children: [
1728
+ /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Invalid token" }),
1729
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "The token used by the AI Assistant is not valid and has to be regenerated." })
1722
1730
  ] }) : 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: [
1731
+ context.error && /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Something went wrong. See console for details." }),
1732
+ !context.error && !status?.initialized && /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
1725
1733
  "Please enable ",
1726
1734
  pluginTitle,
1727
1735
  "."
1728
1736
  ] }),
1729
- /* @__PURE__ */ jsxRuntime.jsx(
1730
- ui.Button,
1737
+ /* @__PURE__ */ jsx(
1738
+ Button,
1731
1739
  {
1732
1740
  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,
1741
+ icon: context.initLoading ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Spinner, {}) }) : context.error ? RetryIcon : void 0,
1734
1742
  text: context.error ? "Retry" : status?.initialized && !status.validToken ? `Restore ${pluginTitle}` : `Enable ${pluginTitle} now`,
1735
1743
  tone: "primary",
1736
1744
  onClick: context.init,
@@ -1738,59 +1746,59 @@ function AssistInspectorWrapper(props) {
1738
1746
  }
1739
1747
  )
1740
1748
  ] })
1741
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(AssistInspector, { ...props }) : /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", height: "fill", children: [
1742
- /* @__PURE__ */ jsxRuntime.jsx(
1743
- structure.DocumentInspectorHeader,
1749
+ ] }) : /* @__PURE__ */ jsx(AssistInspector, { ...props }) : /* @__PURE__ */ jsxs(Flex, { direction: "column", height: "fill", children: [
1750
+ /* @__PURE__ */ jsx(
1751
+ DocumentInspectorHeader,
1744
1752
  {
1745
1753
  closeButtonLabel: "Close",
1746
1754
  onClose: props.onClose,
1747
1755
  title: pluginTitle
1748
1756
  }
1749
1757
  ),
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: [
1758
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, overflow: "auto", padding: 4, space: 3, children: [
1759
+ /* @__PURE__ */ jsxs(Text, { as: "p", size: 1, weight: "semibold", children: [
1752
1760
  pluginTitle,
1753
1761
  " is not available"
1754
1762
  ] }),
1755
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { as: "p", muted: !0, size: 1, children: [
1763
+ /* @__PURE__ */ jsxs(Text, { as: "p", muted: !0, size: 1, children: [
1756
1764
  "Please get in touch with a Sanity account manager or",
1757
1765
  " ",
1758
- /* @__PURE__ */ jsxRuntime.jsx("a", { href: salesUrl, target: "_blank", rel: "noreferrer", children: "contact our sales team" }),
1766
+ /* @__PURE__ */ jsx("a", { href: salesUrl, target: "_blank", rel: "noreferrer", children: "contact our sales team" }),
1759
1767
  " ",
1760
1768
  "to get started with ",
1761
1769
  pluginTitle,
1762
1770
  ".",
1763
1771
  " ",
1764
- /* @__PURE__ */ jsxRuntime.jsx("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: "Learn more \u2192" })
1772
+ /* @__PURE__ */ jsx("a", { href: releaseAnnouncementUrl, target: "_blank", rel: "noreferrer", children: "Learn more \u2192" })
1765
1773
  ] })
1766
1774
  ] })
1767
1775
  ] });
1768
1776
  }
1769
1777
  function AssistInspector(props) {
1770
- const { params } = useAiPaneRouter(), boundary = react.useRef(null), pathKey = params?.[fieldPathParam], instructionKey = params?.[instructionParam], documentPane = structure.useDocumentPane(), {
1778
+ const { params } = useAiPaneRouter(), boundary = useRef(null), pathKey = params?.[fieldPathParam], instructionKey = params?.[instructionParam], documentPane = useDocumentPane(), {
1771
1779
  documentId,
1772
1780
  documentType,
1773
1781
  value: docValue,
1774
1782
  schemaType,
1775
1783
  onChange: documentOnChange,
1776
1784
  formState
1777
- } = documentPane, { assistableDocumentId, documentIsAssistable } = useAssistDocumentContext(), formStateRef = react.useRef(formState);
1785
+ } = documentPane, { assistableDocumentId, documentIsAssistable } = useAssistDocumentContext(), formStateRef = useRef(formState);
1778
1786
  formStateRef.current = formState;
1779
1787
  const { instructionLoading, requestRunInstruction } = useRequestRunInstruction({
1780
1788
  documentOnChange,
1781
1789
  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(
1790
+ }), 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
1791
  () => assistDocument?.tasks?.filter((i) => !instructionKey || i.instructionKey === instructionKey),
1784
1792
  [assistDocument?.tasks, instructionKey]
1785
- ), instructions = react.useMemo(
1793
+ ), instructions = useMemo(
1786
1794
  () => assistDocument?.fields?.flatMap((f) => f.instructions ?? []),
1787
1795
  [assistDocument?.fields]
1788
- ), promptValue = instruction2?.prompt, isEmptyPrompt = react.useMemo(() => {
1796
+ ), promptValue = instruction2?.prompt, isEmptyPrompt = useMemo(() => {
1789
1797
  if (!promptValue?.length)
1790
1798
  return !0;
1791
1799
  const children = promptValue[0]?.children;
1792
1800
  return promptValue.length == 1 && children?.length === 1 && !children?.[0]?.text?.length;
1793
- }, [promptValue]), paneNode = react.useMemo(
1801
+ }, [promptValue]), paneNode = useMemo(
1794
1802
  () => ({
1795
1803
  type: "document",
1796
1804
  id: aiDocId,
@@ -1801,7 +1809,7 @@ function AssistInspector(props) {
1801
1809
  }
1802
1810
  }),
1803
1811
  [aiDocId]
1804
- ), runCurrentInstruction = react.useCallback(
1812
+ ), runCurrentInstruction = useCallback(
1805
1813
  () => instruction2 && pathKey && typePath && requestRunInstruction({
1806
1814
  documentId: assistableDocumentId,
1807
1815
  path: pathKey,
@@ -1811,9 +1819,9 @@ function AssistInspector(props) {
1811
1819
  conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : []
1812
1820
  }),
1813
1821
  [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,
1822
+ ), Region = useCallback((_props) => /* @__PURE__ */ jsx("div", { ..._props, style: { height: "100%", flex: 1, overflow: "auto" } }), []), assistTypeContext = useMemo(() => ({ typePath, documentType }), [typePath, documentType]);
1823
+ return !documentId || !schemaType || schemaType.jsonType !== "object" ? /* @__PURE__ */ jsx(Card, { flex: 1, padding: 4, children: /* @__PURE__ */ jsx(Text, { children: "Document not ready yet." }) }) : /* @__PURE__ */ jsxs(
1824
+ Flex,
1817
1825
  {
1818
1826
  ref: boundary,
1819
1827
  direction: "column",
@@ -1822,7 +1830,7 @@ function AssistInspector(props) {
1822
1830
  sizing: "border",
1823
1831
  style: { lineHeight: 0 },
1824
1832
  children: [
1825
- /* @__PURE__ */ jsxRuntime.jsx(
1833
+ /* @__PURE__ */ jsx(
1826
1834
  AiInspectorHeader,
1827
1835
  {
1828
1836
  onClose: props.onClose,
@@ -1830,14 +1838,14 @@ function AssistInspector(props) {
1830
1838
  fieldTitle: getFieldTitle(selectedField)
1831
1839
  }
1832
1840
  ),
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,
1841
+ /* @__PURE__ */ jsx(Card, { as: Region, flex: 1, overflow: "auto", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", style: { minHeight: "100%" }, children: [
1842
+ /* @__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(
1843
+ VirtualizerScrollInstanceProvider,
1836
1844
  {
1837
1845
  scrollElement: boundary.current,
1838
1846
  containerElement: boundary,
1839
- children: /* @__PURE__ */ jsxRuntime.jsx(
1840
- structure.DocumentPaneProvider,
1847
+ children: /* @__PURE__ */ jsx(
1848
+ DocumentPaneProvider,
1841
1849
  {
1842
1850
  paneKey: documentPane.paneKey,
1843
1851
  index: documentPane.index,
@@ -1848,15 +1856,15 @@ function AssistInspector(props) {
1848
1856
  selectedPerspectiveName: "published",
1849
1857
  selectedReleaseId: void 0
1850
1858
  },
1851
- children: /* @__PURE__ */ jsxRuntime.jsx(DocumentForm, {})
1859
+ children: /* @__PURE__ */ jsx(DocumentForm, {})
1852
1860
  }
1853
1861
  )
1854
1862
  }
1855
1863
  ) }) }) }) }),
1856
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { muted: !0, size: 1, children: [
1864
+ /* @__PURE__ */ jsx(Box, { flex: "none", padding: 4, children: /* @__PURE__ */ jsxs(Text, { muted: !0, size: 1, children: [
1857
1865
  "How is Sanity AI Assist working for you?",
1858
1866
  " ",
1859
- /* @__PURE__ */ jsxRuntime.jsxs(
1867
+ /* @__PURE__ */ jsxs(
1860
1868
  "a",
1861
1869
  {
1862
1870
  href: giveFeedbackUrl,
@@ -1865,26 +1873,26 @@ function AssistInspector(props) {
1865
1873
  style: { whiteSpace: "nowrap" },
1866
1874
  children: [
1867
1875
  "Let us know ",
1868
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRightIcon, {})
1876
+ /* @__PURE__ */ jsx(ArrowRightIcon, {})
1869
1877
  ]
1870
1878
  }
1871
1879
  )
1872
1880
  ] }) })
1873
1881
  ] }) }),
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,
1882
+ /* @__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: [
1883
+ schemaType?.name && pathKey && instructionKey && /* @__PURE__ */ jsx(Stack, { flex: 1, children: /* @__PURE__ */ jsx(
1884
+ Button,
1877
1885
  {
1878
1886
  mode: "ghost",
1879
1887
  disabled: isEmptyPrompt || instructionLoading,
1880
1888
  fontSize: 1,
1881
- icon: instructionLoading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { marginTop: 3 } }) : icons.PlayIcon,
1889
+ icon: instructionLoading ? /* @__PURE__ */ jsx(Spinner, { style: { marginTop: 3 } }) : PlayIcon,
1882
1890
  onClick: runCurrentInstruction,
1883
1891
  padding: 3,
1884
1892
  text: "Run instruction"
1885
1893
  }
1886
1894
  ) }),
1887
- /* @__PURE__ */ jsxRuntime.jsx(
1895
+ /* @__PURE__ */ jsx(
1888
1896
  InstructionTaskHistoryButton,
1889
1897
  {
1890
1898
  documentId: assistableDocumentId,
@@ -1900,21 +1908,21 @@ function AssistInspector(props) {
1900
1908
  }
1901
1909
  function AiInspectorHeader(props) {
1902
1910
  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 }) })
1911
+ return /* @__PURE__ */ jsxs(CardWithShadowBelow, { flex: "none", padding: 2, children: [
1912
+ /* @__PURE__ */ jsxs(Flex, { flex: 1, align: "center", children: [
1913
+ /* @__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: [
1914
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "AI instructions for" }) }),
1915
+ /* @__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
1916
  ] }) }),
1909
- /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { fontSize: 1, icon: icons.CloseIcon, mode: "bleed", onClick: onClose }) })
1917
+ /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(Button, { fontSize: 1, icon: CloseIcon, mode: "bleed", onClick: onClose }) })
1910
1918
  ] }),
1911
- showOnboarding && /* @__PURE__ */ jsxRuntime.jsx(InspectorOnboarding, { onDismiss: dismissOnboarding })
1919
+ showOnboarding && /* @__PURE__ */ jsx(InspectorOnboarding, { onDismiss: dismissOnboarding })
1912
1920
  ] });
1913
1921
  }
1914
1922
  const aiInspectorId = "ai-assistance", assistInspector = {
1915
1923
  name: aiInspectorId,
1916
1924
  useMenuItem: () => ({
1917
- icon: icons.SparklesIcon,
1925
+ icon: SparklesIcon,
1918
1926
  title: pluginTitle,
1919
1927
  hidden: !0,
1920
1928
  showAsAction: !1
@@ -1922,7 +1930,7 @@ const aiInspectorId = "ai-assistance", assistInspector = {
1922
1930
  component: AssistInspectorWrapper,
1923
1931
  onClose({ params }) {
1924
1932
  return {
1925
- params: sanity.typed({
1933
+ params: typed({
1926
1934
  ...params,
1927
1935
  [fieldPathParam]: void 0,
1928
1936
  [instructionParam]: void 0
@@ -2014,9 +2022,9 @@ function drawConnectorPath(options2, line) {
2014
2022
  ), join(cmds);
2015
2023
  }
2016
2024
  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(
2025
+ const { from, options: options2, to } = props, { strokeWidth } = options2.path, theme = useTheme(), line = useMemo(() => mapConnectorToLine(options2, { from, to }), [from, options2, to]);
2026
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2027
+ /* @__PURE__ */ jsx(
2020
2028
  "path",
2021
2029
  {
2022
2030
  d: drawConnectorPath(options2, line),
@@ -2024,15 +2032,15 @@ function ConnectorPath(props) {
2024
2032
  strokeWidth: strokeWidth + 4
2025
2033
  }
2026
2034
  ),
2027
- /* @__PURE__ */ jsxRuntime.jsx(
2035
+ /* @__PURE__ */ jsx(
2028
2036
  "path",
2029
2037
  {
2030
2038
  d: drawConnectorPath(options2, line),
2031
- stroke: ui.rgba(theme.sanity.color.base.border, 0.5),
2039
+ stroke: rgba(theme.sanity.color.base.border, 0.5),
2032
2040
  strokeWidth
2033
2041
  }
2034
2042
  ),
2035
- line.from.isAbove && /* @__PURE__ */ jsxRuntime.jsx(
2043
+ line.from.isAbove && /* @__PURE__ */ jsx(
2036
2044
  "path",
2037
2045
  {
2038
2046
  d: arrowPath(
@@ -2045,7 +2053,7 @@ function ConnectorPath(props) {
2045
2053
  strokeWidth
2046
2054
  }
2047
2055
  ),
2048
- line.from.isBelow && /* @__PURE__ */ jsxRuntime.jsx(
2056
+ line.from.isBelow && /* @__PURE__ */ jsx(
2049
2057
  "path",
2050
2058
  {
2051
2059
  d: arrowPath(
@@ -2077,11 +2085,11 @@ const DEBUG = !1, options = {
2077
2085
  }
2078
2086
  };
2079
2087
  function AssistConnectorsOverlay(props) {
2080
- const { connectors } = props, [, setRedraw] = react.useState(!1);
2081
- return react.useEffect(() => {
2088
+ const { connectors } = props, [, setRedraw] = useState(!1);
2089
+ return useEffect(() => {
2082
2090
  setRedraw(!0);
2083
- }, []), /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2084
- /* @__PURE__ */ jsxRuntime.jsx(
2091
+ }, []), /* @__PURE__ */ jsxs(Fragment, { children: [
2092
+ /* @__PURE__ */ jsx(
2085
2093
  "svg",
2086
2094
  {
2087
2095
  fill: "none",
@@ -2097,7 +2105,7 @@ function AssistConnectorsOverlay(props) {
2097
2105
  zIndex: 150
2098
2106
  // zIndex,
2099
2107
  },
2100
- children: connectors.map((connector) => /* @__PURE__ */ jsxRuntime.jsx(
2108
+ children: connectors.map((connector) => /* @__PURE__ */ jsx(
2101
2109
  ConnectorPath,
2102
2110
  {
2103
2111
  from: connector.from,
@@ -2131,7 +2139,7 @@ const getLanguageParams = (select, document2) => {
2131
2139
  return {};
2132
2140
  const selection = select || {}, selectedValue = {};
2133
2141
  for (const [key, path] of Object.entries(selection)) {
2134
- let value = get__default.default(document2, path);
2142
+ let value = get(document2, path);
2135
2143
  Array.isArray(value) && (value = value.filter(
2136
2144
  (item) => typeof item == "object" ? item?._type !== "reference" || "_ref" in item : !0
2137
2145
  )), selectedValue[key] = value;
@@ -2149,11 +2157,11 @@ function setPreferredToFieldLanguages(fromLanguageId, languageIds) {
2149
2157
  }
2150
2158
  const DEFAULT_MAX_DEPTH = 6, ABSOLUTE_MAX_DEPTH = 50;
2151
2159
  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"), []);
2160
+ return isDocumentSchemaType(schemaType) ? extractPaths(doc, schemaType, [], Math.min(maxDepth2, ABSOLUTE_MAX_DEPTH)) : (console.error("Schema type is not a document"), []);
2153
2161
  }
2154
2162
  function extractPaths(doc, schemaType, path, maxDepth2) {
2155
2163
  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] ?? {};
2164
+ const fieldPath = [...path, field.name], fieldSchema = field.type, { value } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
2157
2165
  if (!value)
2158
2166
  return acc;
2159
2167
  const thisFieldWithPath = {
@@ -2167,7 +2175,7 @@ function extractPaths(doc, schemaType, path, maxDepth2) {
2167
2175
  return [...acc, thisFieldWithPath, ...innerFields];
2168
2176
  } 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
2177
  path.length + 1 < maxDepth2) {
2170
- const { value: arrayValue } = mutator.extractWithPath(sanity.pathToString(fieldPath), doc)[0] ?? {};
2178
+ const { value: arrayValue } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {};
2171
2179
  let arrayPaths = [];
2172
2180
  if (arrayValue?.length)
2173
2181
  for (const item of arrayValue) {
@@ -2203,7 +2211,7 @@ function extractPaths(doc, schemaType, path, maxDepth2) {
2203
2211
  const defaultLanguageOutputs = function(member, enclosingType, translateFromLanguageId, translateToLanguageIds) {
2204
2212
  if (member.schemaType.jsonType === "object" && member.schemaType.name.startsWith("internationalizedArray")) {
2205
2213
  const pathEnd = member.path.slice(-1);
2206
- return (sanity.isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null) === translateFromLanguageId ? translateToLanguageIds.map((translateToId) => ({
2214
+ return (isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null) === translateFromLanguageId ? translateToLanguageIds.map((translateToId) => ({
2207
2215
  id: translateToId,
2208
2216
  outputPath: [...member.path.slice(0, -1), { _key: translateToId }]
2209
2217
  })) : void 0;
@@ -2217,7 +2225,7 @@ const defaultLanguageOutputs = function(member, enclosingType, translateFromLang
2217
2225
  function getFieldLanguageMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
2218
2226
  const translationMaps = [];
2219
2227
  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(
2228
+ const parentPath = member.path.slice(0, -1), enclosingType = documentMembers.find((m) => pathToString(m.path) === pathToString(parentPath))?.schemaType ?? documentSchema, translations = langFn(
2221
2229
  member,
2222
2230
  enclosingType,
2223
2231
  translateFromLanguageId,
@@ -2231,25 +2239,25 @@ function getFieldLanguageMap(documentSchema, documentMembers, translateFromLangu
2231
2239
  }
2232
2240
  return translationMaps;
2233
2241
  }
2234
- const FieldTranslationContext = react.createContext({
2242
+ const FieldTranslationContext = createContext({
2235
2243
  openFieldTranslation: () => {
2236
2244
  },
2237
2245
  translationLoading: !1
2238
2246
  });
2239
2247
  function useFieldTranslation() {
2240
- return react.useContext(FieldTranslationContext);
2248
+ return useContext(FieldTranslationContext);
2241
2249
  }
2242
2250
  function hasValuesToTranslate(fieldLanguageMaps, fromLanguage, basePath2) {
2243
2251
  return fieldLanguageMaps?.some(
2244
- (map) => map.inputLanguageId === fromLanguage?.id && map.inputPath && sanity.pathToString(map.inputPath).startsWith(sanity.pathToString(basePath2))
2252
+ (map) => map.inputLanguageId === fromLanguage?.id && map.inputPath && pathToString(map.inputPath).startsWith(pathToString(basePath2))
2245
2253
  );
2246
2254
  }
2247
2255
  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(() => {
2256
+ 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
2257
  setDialogOpen(!1), setLanguages(void 0), setFieldTranslationParams(void 0);
2250
- }, []), languageClient = sanity.useClient({
2258
+ }, []), languageClient = useClient({
2251
2259
  apiVersion: config?.apiVersion ?? API_VERSION_WITH_EXTENDED_TYPES
2252
- }), documentId = fieldTranslationParams?.document?._id, id = react.useId(), selectFromLanguage = react.useCallback(
2260
+ }), documentId = fieldTranslationParams?.document?._id, id = useId(), selectFromLanguage = useCallback(
2253
2261
  (from, languages2, params) => {
2254
2262
  const { document: document2, documentSchema } = params ?? {};
2255
2263
  if (setFromLanguage(from), !document2 || !documentSchema || !params || !languages2) {
@@ -2274,7 +2282,7 @@ function FieldTranslationProvider(props) {
2274
2282
  setFieldLanguageMaps(void 0);
2275
2283
  },
2276
2284
  [config]
2277
- ), toggleToLanguage = react.useCallback(
2285
+ ), toggleToLanguage = useCallback(
2278
2286
  (toggledLang, toLanguages2, languages2) => {
2279
2287
  if (!languages2 || !fromLanguage)
2280
2288
  return;
@@ -2289,7 +2297,7 @@ function FieldTranslationProvider(props) {
2289
2297
  );
2290
2298
  },
2291
2299
  [fromLanguage]
2292
- ), openFieldTranslation = react.useCallback(
2300
+ ), openFieldTranslation = useCallback(
2293
2301
  async (params) => {
2294
2302
  setDialogOpen(!0);
2295
2303
  const languageParams = getLanguageParams(config?.selectLanguageParams, params.document), languages2 = await (typeof config?.languages == "function" ? config?.languages(languageClient, languageParams) : Promise.resolve(config?.languages));
@@ -2298,10 +2306,10 @@ function FieldTranslationProvider(props) {
2298
2306
  fromLanguage2 ? selectFromLanguage(fromLanguage2, languages2, params) : console.error("No languages available for selected language params", languageParams);
2299
2307
  },
2300
2308
  [selectFromLanguage, config, languageClient]
2301
- ), contextValue = react.useMemo(() => ({
2309
+ ), contextValue = useMemo(() => ({
2302
2310
  openFieldTranslation,
2303
2311
  translationLoading: !1
2304
- }), [openFieldTranslation]), runDisabled = !fromLanguage || !toLanguages?.length || !fieldLanguageMaps?.length || !documentId || !hasValuesToTranslate(fieldLanguageMaps, fromLanguage, fieldTranslationParams.translatePath), onRunTranslation = react.useCallback(() => {
2312
+ }), [openFieldTranslation]), runDisabled = !fromLanguage || !toLanguages?.length || !fieldLanguageMaps?.length || !documentId || !hasValuesToTranslate(fieldLanguageMaps, fromLanguage, fieldTranslationParams.translatePath), onRunTranslation = useCallback(() => {
2305
2313
  const translatePath = fieldTranslationParams?.translatePath;
2306
2314
  fieldLanguageMaps && documentId && translatePath && runTranslate({
2307
2315
  documentId,
@@ -2330,38 +2338,38 @@ function FieldTranslationProvider(props) {
2330
2338
  fieldTranslationParams?.conditionalMembers,
2331
2339
  fieldTranslationParams?.documentSchema,
2332
2340
  languageClient
2333
- ]), runButton = /* @__PURE__ */ jsxRuntime.jsx(
2334
- ui.Button,
2341
+ ]), runButton = /* @__PURE__ */ jsx(
2342
+ Button,
2335
2343
  {
2336
2344
  text: "Translate",
2337
2345
  tone: "primary",
2338
- icon: icons.PlayIcon,
2346
+ icon: PlayIcon,
2339
2347
  style: { width: "100%" },
2340
2348
  disabled: runDisabled,
2341
2349
  onClick: onRunTranslation
2342
2350
  }
2343
2351
  );
2344
- return /* @__PURE__ */ jsxRuntime.jsxs(FieldTranslationContext.Provider, { value: contextValue, children: [
2345
- dialogOpen ? /* @__PURE__ */ jsxRuntime.jsx(
2346
- ui.Dialog,
2352
+ return /* @__PURE__ */ jsxs(FieldTranslationContext.Provider, { value: contextValue, children: [
2353
+ dialogOpen ? /* @__PURE__ */ jsx(
2354
+ Dialog,
2347
2355
  {
2348
2356
  id,
2349
2357
  width: 1,
2350
2358
  open: dialogOpen,
2351
2359
  onClose: close,
2352
2360
  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,
2361
+ footer: /* @__PURE__ */ jsx(Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsx(
2362
+ Tooltip,
2355
2363
  {
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." }) }),
2364
+ content: /* @__PURE__ */ jsx(Flex, { padding: 2, children: /* @__PURE__ */ jsx(Text, { children: "There is nothing to translate in the selected from-language." }) }),
2357
2365
  placement: "top",
2358
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, children: runButton })
2366
+ children: /* @__PURE__ */ jsx(Flex, { flex: 1, children: runButton })
2359
2367
  }
2360
2368
  ) : 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(
2369
+ children: languages ? /* @__PURE__ */ jsxs(Flex, { padding: 4, gap: 5, align: "flex-start", justify: "center", children: [
2370
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
2371
+ /* @__PURE__ */ jsx(Box, { marginBottom: 2, children: /* @__PURE__ */ jsx(Text, { weight: "semibold", children: "From" }) }),
2372
+ languages?.map((radioLanguage) => /* @__PURE__ */ jsx(
2365
2373
  FromLanguageRadio,
2366
2374
  {
2367
2375
  radioLanguage,
@@ -2373,9 +2381,9 @@ function FieldTranslationProvider(props) {
2373
2381
  radioLanguage.id
2374
2382
  ))
2375
2383
  ] }),
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(
2384
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
2385
+ /* @__PURE__ */ jsx(Box, { marginBottom: 2, children: /* @__PURE__ */ jsx(Text, { weight: "semibold", children: "To" }) }),
2386
+ languages.map((checkboxLanguage) => /* @__PURE__ */ jsx(
2379
2387
  ToLanguageCheckbox,
2380
2388
  {
2381
2389
  checkboxLanguage,
@@ -2387,9 +2395,9 @@ function FieldTranslationProvider(props) {
2387
2395
  checkboxLanguage.id
2388
2396
  ))
2389
2397
  ] })
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..." })
2398
+ ] }) : /* @__PURE__ */ jsxs(Flex, { padding: 4, gap: 2, align: "flex-start", justify: "center", children: [
2399
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Spinner, {}) }),
2400
+ /* @__PURE__ */ jsx(Text, { children: "Loading languages..." })
2393
2401
  ] })
2394
2402
  }
2395
2403
  ) : null,
@@ -2397,20 +2405,20 @@ function FieldTranslationProvider(props) {
2397
2405
  ] });
2398
2406
  }
2399
2407
  function ToLanguageCheckbox(props) {
2400
- const { checkboxLanguage, fromLanguage, toLanguages, toggleToLanguage, languages } = props, langId = checkboxLanguage.id, onChange = react.useCallback(
2408
+ const { checkboxLanguage, fromLanguage, toLanguages, toggleToLanguage, languages } = props, langId = checkboxLanguage.id, onChange = useCallback(
2401
2409
  () => toggleToLanguage(checkboxLanguage, toLanguages, languages),
2402
2410
  [toggleToLanguage, checkboxLanguage, toLanguages, languages]
2403
2411
  );
2404
- return /* @__PURE__ */ jsxRuntime.jsxs(
2405
- ui.Flex,
2412
+ return /* @__PURE__ */ jsxs(
2413
+ Flex,
2406
2414
  {
2407
2415
  gap: 3,
2408
2416
  align: "center",
2409
2417
  as: "label",
2410
2418
  style: langId === fromLanguage?.id ? { opacity: 0.5 } : void 0,
2411
2419
  children: [
2412
- /* @__PURE__ */ jsxRuntime.jsx(
2413
- ui.Checkbox,
2420
+ /* @__PURE__ */ jsx(
2421
+ Checkbox,
2414
2422
  {
2415
2423
  name: "toLang",
2416
2424
  value: langId,
@@ -2419,20 +2427,20 @@ function ToLanguageCheckbox(props) {
2419
2427
  disabled: langId === fromLanguage?.id
2420
2428
  }
2421
2429
  ),
2422
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: langId === fromLanguage?.id, children: checkboxLanguage.title ?? langId })
2430
+ /* @__PURE__ */ jsx(Text, { muted: langId === fromLanguage?.id, children: checkboxLanguage.title ?? langId })
2423
2431
  ]
2424
2432
  },
2425
2433
  langId
2426
2434
  );
2427
2435
  }
2428
2436
  function FromLanguageRadio(props) {
2429
- const { languages, radioLanguage, selectFromLanguage, fromLanguage, fieldTranslationParams } = props, langId = radioLanguage.id, onChange = react.useCallback(
2437
+ const { languages, radioLanguage, selectFromLanguage, fromLanguage, fieldTranslationParams } = props, langId = radioLanguage.id, onChange = useCallback(
2430
2438
  () => selectFromLanguage(radioLanguage, languages, fieldTranslationParams),
2431
2439
  [selectFromLanguage, radioLanguage, languages, fieldTranslationParams]
2432
2440
  );
2433
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 3, align: "center", as: "label", children: [
2434
- /* @__PURE__ */ jsxRuntime.jsx(
2435
- ui.Radio,
2441
+ return /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", as: "label", children: [
2442
+ /* @__PURE__ */ jsx(
2443
+ Radio,
2436
2444
  {
2437
2445
  name: "fromLang",
2438
2446
  value: langId,
@@ -2440,7 +2448,7 @@ function FromLanguageRadio(props) {
2440
2448
  onChange
2441
2449
  }
2442
2450
  ),
2443
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: radioLanguage.title ?? radioLanguage.id })
2451
+ /* @__PURE__ */ jsx(Text, { children: radioLanguage.title ?? radioLanguage.id })
2444
2452
  ] }, langId);
2445
2453
  }
2446
2454
  const hiddenTypes = [
@@ -2540,7 +2548,7 @@ function serializeMember(schema, type, name, options2) {
2540
2548
  }
2541
2549
  function serializeInlineOf(blockSchemaType, schema, options2) {
2542
2550
  const childrenType = blockSchemaType.fields.find((f) => f.name === "children")?.type;
2543
- if (!(!childrenType || !sanity.isArraySchemaType(childrenType)))
2551
+ if (!(!childrenType || !isArraySchemaType(childrenType)))
2544
2552
  return arrayOf(
2545
2553
  {
2546
2554
  of: childrenType.of.filter((t) => !isType(t, "span"))
@@ -2551,7 +2559,7 @@ function serializeInlineOf(blockSchemaType, schema, options2) {
2551
2559
  }
2552
2560
  function serializeAnnotations(blockSchemaType, schema, options2) {
2553
2561
  const marksType = blockSchemaType.fields.find((f) => f.name === "markDefs")?.type;
2554
- if (!(!marksType || !sanity.isArraySchemaType(marksType)))
2562
+ if (!(!marksType || !isArraySchemaType(marksType)))
2555
2563
  return arrayOf(marksType, schema, options2);
2556
2564
  }
2557
2565
  function arrayOf(arrayType, schema, options2) {
@@ -2559,7 +2567,7 @@ function arrayOf(arrayType, schema, options2) {
2559
2567
  }
2560
2568
  function refToTypeNames(type) {
2561
2569
  return type.to.map((t) => ({
2562
- type: sanity.typed(t.name)
2570
+ type: typed(t.name)
2563
2571
  }));
2564
2572
  }
2565
2573
  function removeUndef(obj) {
@@ -2579,13 +2587,13 @@ function createFieldRefCache() {
2579
2587
  return getRefsForType;
2580
2588
  }
2581
2589
  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(() => {
2590
+ 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);
2591
+ useEffect(() => {
2584
2592
  getInstructStatus().then((s) => setStatus(s)).catch((e) => {
2585
2593
  console.error(e), setError(e);
2586
2594
  });
2587
2595
  }, [getInstructStatus]);
2588
- const init = react.useCallback(async () => {
2596
+ const init = useCallback(async () => {
2589
2597
  setError(void 0);
2590
2598
  try {
2591
2599
  await initInstruct();
@@ -2594,7 +2602,7 @@ function AiAssistanceConfigProvider(props) {
2594
2602
  } catch (e) {
2595
2603
  console.error("Failed to init ai assistance", e), setError(e);
2596
2604
  }
2597
- }, [initInstruct, getInstructStatus, setStatus]), { config, children } = props, context = react.useMemo(() => ({
2605
+ }, [initInstruct, getInstructStatus, setStatus]), { config, children } = props, context = useMemo(() => ({
2598
2606
  config,
2599
2607
  status,
2600
2608
  statusLoading,
@@ -2615,10 +2623,10 @@ function AiAssistanceConfigProvider(props) {
2615
2623
  getFieldRefs2,
2616
2624
  getFieldRefsByTypePath
2617
2625
  ]);
2618
- return /* @__PURE__ */ jsxRuntime.jsx(AiAssistanceConfigContext.Provider, { value: context, children });
2626
+ return /* @__PURE__ */ jsx(AiAssistanceConfigContext.Provider, { value: context, children });
2619
2627
  }
2620
2628
  function useFieldRefGetters(schema) {
2621
- return react.useMemo(() => {
2629
+ return useMemo(() => {
2622
2630
  const getForSchemaType = createFieldRefCache();
2623
2631
  function getRefsForType(documentType) {
2624
2632
  const schemaType = schema.get(documentType);
@@ -2633,23 +2641,23 @@ function useFieldRefGetters(schema) {
2633
2641
  }, [schema]);
2634
2642
  }
2635
2643
  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: [
2644
+ const [connectors, setConnectors] = useState([]);
2645
+ return /* @__PURE__ */ jsx(AiAssistanceConfigProvider, { config: props.config, children: /* @__PURE__ */ jsx(RunInstructionProvider, { children: /* @__PURE__ */ jsx(FieldTranslationProvider, { children: /* @__PURE__ */ jsxs(ConnectorsProvider, { onConnectorsChange: setConnectors, children: [
2638
2646
  props.renderDefault(props),
2639
- /* @__PURE__ */ jsxRuntime.jsx(ui.ThemeProvider, { tone: "default", children: /* @__PURE__ */ jsxRuntime.jsx(AssistConnectorsOverlay, { connectors }) })
2647
+ /* @__PURE__ */ jsx(ThemeProvider, { tone: "default", children: /* @__PURE__ */ jsx(AssistConnectorsOverlay, { connectors }) })
2640
2648
  ] }) }) }) });
2641
2649
  }
2642
- const ImageContext = react.createContext({});
2650
+ const ImageContext = createContext({});
2643
2651
  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),
2652
+ 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(
2653
+ getPublishedId(assistableDocumentId),
2646
2654
  documentSchemaType.name,
2647
2655
  selectedReleaseId
2648
- ), isShowingOlderRevision = !!structure.usePaneRouter().params?.rev;
2649
- react.useEffect(() => {
2656
+ ), isShowingOlderRevision = !!usePaneRouter().params?.rev;
2657
+ useEffect(() => {
2650
2658
  const descriptionField = getDescriptionFieldOption(schemaType);
2651
2659
  assetRef && assistableDocumentId && descriptionField?.updateOnImageChange && assetRef !== assetRefState && !isSyncing && !isShowingOlderRevision && !readOnly && (setAssetRefState(assetRef), canUseAssist(status) && generateCaption({
2652
- path: sanity.pathToString([...path, descriptionField.path]),
2660
+ path: pathToString([...path, descriptionField.path]),
2653
2661
  documentId: assistableDocumentId
2654
2662
  }));
2655
2663
  }, [
@@ -2664,27 +2672,27 @@ function ImageContextProvider(props) {
2664
2672
  readOnly,
2665
2673
  isShowingOlderRevision
2666
2674
  ]);
2667
- const context = react.useMemo(() => {
2675
+ const context = useMemo(() => {
2668
2676
  const descriptionField = getDescriptionFieldOption(schemaType), imageInstructionField = getImageInstructionFieldOption(schemaType);
2669
2677
  return {
2670
- imageDescriptionPath: descriptionField?.path ? sanity.pathToString([...path, descriptionField.path]) : void 0,
2671
- imageInstructionPath: imageInstructionField ? sanity.pathToString([...path, imageInstructionField]) : void 0,
2678
+ imageDescriptionPath: descriptionField?.path ? pathToString([...path, descriptionField.path]) : void 0,
2679
+ imageInstructionPath: imageInstructionField ? pathToString([...path, imageInstructionField]) : void 0,
2672
2680
  assetRef
2673
2681
  };
2674
2682
  }, [schemaType, path, assetRef]);
2675
- return /* @__PURE__ */ jsxRuntime.jsx(ImageContext.Provider, { value: context, children: props.renderDefault(props) });
2683
+ return /* @__PURE__ */ jsx(ImageContext.Provider, { value: context, children: props.renderDefault(props) });
2676
2684
  }
2677
2685
  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)),
2686
+ const { value, onChange } = props, id = useId(), items = useMemo(
2687
+ () => Object.entries(icons).map(([key, icon]) => /* @__PURE__ */ jsx(IconItem, { iconKey: key, icon, onChange }, key)),
2680
2688
  [onChange]
2681
- ), selectedIcon = react.useMemo(() => getIcon(value), [value]);
2682
- return /* @__PURE__ */ jsxRuntime.jsx(
2683
- ui.MenuButton,
2689
+ ), selectedIcon = useMemo(() => getIcon(value), [value]);
2690
+ return /* @__PURE__ */ jsx(
2691
+ MenuButton,
2684
2692
  {
2685
- button: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { icon: selectedIcon, title: "Select icon", padding: 3, mode: "ghost", radius: 1 }),
2693
+ button: /* @__PURE__ */ jsx(Button, { icon: selectedIcon, title: "Select icon", padding: 3, mode: "ghost", radius: 1 }),
2686
2694
  id,
2687
- menu: /* @__PURE__ */ jsxRuntime.jsx(ui.Menu, { style: { maxHeight: 300 }, children: items }),
2695
+ menu: /* @__PURE__ */ jsx(Menu, { style: { maxHeight: 300 }, children: items }),
2688
2696
  popover: { portal: !0 }
2689
2697
  }
2690
2698
  );
@@ -2694,19 +2702,19 @@ function IconItem({
2694
2702
  iconKey: key,
2695
2703
  onChange
2696
2704
  }) {
2697
- const onClick = react.useCallback(() => onChange(sanity.set(key)), [onChange, key]);
2698
- return /* @__PURE__ */ jsxRuntime.jsx(ui.MenuItem, { icon, title: key, text: key, onClick });
2705
+ const onClick = useCallback(() => onChange(set(key)), [onChange, key]);
2706
+ return /* @__PURE__ */ jsx(MenuItem, { icon, title: key, text: key, onClick });
2699
2707
  }
2700
2708
  function getIcon(iconName) {
2701
- return Object.entries(icons.icons).find(([key]) => key === iconName)?.[1] ?? icons.icons.sparkles;
2709
+ return Object.entries(icons).find(([key]) => key === iconName)?.[1] ?? icons.sparkles;
2702
2710
  }
2703
2711
  function useAssistSupported(path, schemaType) {
2704
- return react.useMemo(() => isAssistSupported(schemaType), [schemaType]);
2712
+ return useMemo(() => isAssistSupported(schemaType), [schemaType]);
2705
2713
  }
2706
2714
  const translateActions = {
2707
2715
  name: "sanity-assist-translate",
2708
2716
  useAction(props) {
2709
- const { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), client = sanity.useClient({ apiVersion: API_VERSION_WITH_EXTENDED_TYPES }), {
2717
+ const { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), client = useClient({ apiVersion: API_VERSION_WITH_EXTENDED_TYPES }), {
2710
2718
  schemaType: fieldSchemaType,
2711
2719
  path,
2712
2720
  documentId,
@@ -2714,21 +2722,21 @@ const translateActions = {
2714
2722
  documentIsAssistable
2715
2723
  } = 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
2724
  if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
2717
- const { value: documentValue, onChange: documentOnChange, formState } = structure.useDocumentPane(), docRef = react.useRef(documentValue);
2725
+ const { value: documentValue, onChange: documentOnChange, formState } = useDocumentPane(), docRef = useRef(documentValue);
2718
2726
  docRef.current = documentValue;
2719
- const formStateRef = react.useRef(formState);
2727
+ const formStateRef = useRef(formState);
2720
2728
  formStateRef.current = formState;
2721
2729
  const translationApi = useTranslate(apiClient), translate = useDraftDelayedTask({
2722
2730
  documentOnChange,
2723
2731
  isDocAssistable: documentIsAssistable ?? !1,
2724
2732
  task: translationApi.translate
2725
- }), styleguide = config.translate?.styleguide, languagePath = config.translate?.document?.languageField, translateDocumentAction = react.useMemo(() => {
2733
+ }), styleguide = config.translate?.styleguide, languagePath = config.translate?.document?.languageField, translateDocumentAction = useMemo(() => {
2726
2734
  if (!languagePath || !documentTranslationEnabled)
2727
2735
  return;
2728
2736
  const title = path.length ? "Translate" : "Translate document";
2729
2737
  return {
2730
2738
  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,
2739
+ icon: translationApi.loading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : TranslateIcon,
2732
2740
  title,
2733
2741
  onAction: () => {
2734
2742
  translationApi.loading || !languagePath || !documentId || translate({
@@ -2761,10 +2769,10 @@ const translateActions = {
2761
2769
  documentOnChange,
2762
2770
  isDocAssistable: documentIsAssistable ?? !1,
2763
2771
  task: fieldTranslate.openFieldTranslation
2764
- }), maxDepth2 = config.translate?.field?.maxPathDepth, translateFieldsAction = react.useMemo(
2772
+ }), maxDepth2 = config.translate?.field?.maxPathDepth, translateFieldsAction = useMemo(
2765
2773
  () => fieldTransEnabled ? {
2766
2774
  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,
2775
+ icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : TranslateIcon,
2768
2776
  title: "Translate fields...",
2769
2777
  onAction: () => {
2770
2778
  fieldTranslate.translationLoading || !documentId || (formStateRef.current && getConditionalMembers(formStateRef.current), openFieldTranslation({
@@ -2791,7 +2799,7 @@ const translateActions = {
2791
2799
  maxDepth2
2792
2800
  ]
2793
2801
  );
2794
- return react.useMemo(() => {
2802
+ return useMemo(() => {
2795
2803
  if (status?.initialized)
2796
2804
  return {
2797
2805
  type: "group",
@@ -2808,12 +2816,12 @@ const translateActions = {
2808
2816
  }, generateCaptionsActions = {
2809
2817
  name: "sanity-assist-generate-captions",
2810
2818
  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);
2819
+ const pathKey = usePathKey(props.path), { openInspector } = useDocumentPane(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption, loading } = useGenerateCaption(apiClient), imageContext = useContext(ImageContext);
2812
2820
  if (imageContext && pathKey === imageContext?.imageDescriptionPath) {
2813
2821
  const { assistableDocumentId } = useAssistDocumentContext();
2814
- return react.useMemo(() => ({
2822
+ return useMemo(() => ({
2815
2823
  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,
2824
+ icon: loading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : ImageIcon,
2817
2825
  title: "Generate image description",
2818
2826
  onAction: () => {
2819
2827
  if (!loading) {
@@ -2844,12 +2852,12 @@ const translateActions = {
2844
2852
  }, generateImagActions = {
2845
2853
  name: "sanity-assist-generate-image",
2846
2854
  useAction(props) {
2847
- const pathKey = usePathKey(props.path), { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateImage, loading } = useGenerateImage(apiClient), imageContext = react.useContext(ImageContext);
2855
+ const pathKey = usePathKey(props.path), { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateImage, loading } = useGenerateImage(apiClient), imageContext = useContext(ImageContext);
2848
2856
  if (imageContext && pathKey === imageContext?.imageInstructionPath) {
2849
2857
  const { assistableDocumentId } = useAssistDocumentContext();
2850
- return react.useMemo(() => ({
2858
+ return useMemo(() => ({
2851
2859
  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,
2860
+ icon: loading ? () => /* @__PURE__ */ jsx(Box, { style: { height: 17 }, children: /* @__PURE__ */ jsx(Spinner, { style: { transform: "translateY(6px)" } }) }) : ImageIcon,
2853
2861
  title: "Generate image from prompt",
2854
2862
  onAction: () => {
2855
2863
  loading || generateImage({ path: pathKey, documentId: assistableDocumentId });
@@ -2861,15 +2869,15 @@ const translateActions = {
2861
2869
  }
2862
2870
  };
2863
2871
  function PrivateIcon() {
2864
- return /* @__PURE__ */ jsxRuntime.jsx(
2865
- ui.Tooltip,
2872
+ return /* @__PURE__ */ jsx(
2873
+ Tooltip,
2866
2874
  {
2867
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Only visible to you" }),
2875
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Only visible to you" }),
2868
2876
  fallbackPlacements: ["bottom"],
2869
2877
  padding: 2,
2870
2878
  placement: "top",
2871
2879
  portal: !0,
2872
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.LockIcon, {})
2880
+ children: /* @__PURE__ */ jsx(LockIcon, {})
2873
2881
  }
2874
2882
  );
2875
2883
  }
@@ -2918,12 +2926,12 @@ function defineAssistFieldActionGroup(group) {
2918
2926
  function useCustomFieldActions(props) {
2919
2927
  const {
2920
2928
  config: { fieldActions }
2921
- } = useAiAssistanceConfig(), { addSyntheticTask, removeSyntheticTask } = useAssistDocumentContext(), schemaId = sanity.useWorkspaceSchemaId(), { push: pushToast } = ui.useToast(), configActions = fieldActions?.useFieldActions?.({
2929
+ } = useAiAssistanceConfig(), { addSyntheticTask, removeSyntheticTask } = useAssistDocumentContext(), schemaId = useWorkspaceSchemaId(), { push: pushToast } = useToast(), configActions = fieldActions?.useFieldActions?.({
2922
2930
  ...props,
2923
2931
  schemaId,
2924
2932
  path: props.path
2925
2933
  });
2926
- return react.useMemo(() => {
2934
+ return useMemo(() => {
2927
2935
  const title = fieldActions?.title, customActions = configActions?.filter(isDefined).map((node) => createSafeNode({
2928
2936
  node,
2929
2937
  pushToast,
@@ -3012,30 +3020,30 @@ const assistFieldActions = {
3012
3020
  selectedPath,
3013
3021
  assistableDocumentId,
3014
3022
  fieldRefsByTypePath
3015
- } = useAssistDocumentContext(), { value: docValue, formState } = structure.useDocumentPane(), docValueRef = react.useRef(docValue), formStateRef = react.useRef(formState);
3023
+ } = useAssistDocumentContext(), { value: docValue, formState } = useDocumentPane(), docValueRef = useRef(docValue), formStateRef = useRef(formState);
3016
3024
  formStateRef.current = formState;
3017
- const currentUser = sanity.useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
3025
+ const currentUser = useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
3018
3026
  documentOnChange,
3019
3027
  isDocAssistable: documentIsAssistable ?? !1
3020
- }), isSelectable = !!useSelectedField(documentSchemaType, typePath), assistSupported = useAssistSupported(props.path, schemaType) && isSelectable && isSchemaAssistEnabled(documentSchemaType) && schemaType.readOnly !== !0, fieldAssist = react.useMemo(
3028
+ }), isSelectable = !!useSelectedField(documentSchemaType, typePath), assistSupported = useAssistSupported(props.path, schemaType) && isSelectable && isSchemaAssistEnabled(documentSchemaType) && schemaType.readOnly !== !0, fieldAssist = useMemo(
3021
3029
  () => (assistDocument?.fields ?? []).find(
3022
3030
  (f) => f.path === typePath || pathKey === documentRootKey && f.path === pathKey
3023
3031
  ),
3024
3032
  [assistDocument?.fields, pathKey, typePath]
3025
3033
  ), fieldAssistKey = fieldAssist?._key, isSelected = inspector?.name === aiInspectorId && pathKey === selectedPath, imageCaptionAction = generateCaptionsActions.useAction(props), imageGenAction = generateImagActions.useAction(props), translateAction = translateActions.useAction(
3026
- sanity.typed({
3034
+ typed({
3027
3035
  ...props,
3028
3036
  documentId: assistableDocumentId,
3029
3037
  documentIsAssistable,
3030
3038
  documentSchemaType
3031
3039
  })
3032
- ), manageInstructions = react.useCallback(
3040
+ ), manageInstructions = useCallback(
3033
3041
  () => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
3034
3042
  [fieldPathParam]: pathKey,
3035
3043
  [instructionParam]: void 0
3036
3044
  }),
3037
3045
  [openInspector, closeInspector, isSelected, pathKey]
3038
- ), onInstructionAction = react.useCallback(
3046
+ ), onInstructionAction = useCallback(
3039
3047
  (instruction2) => {
3040
3048
  !pathKey || !fieldAssistKey || !assistDocumentId2 || !assistableDocumentId || requestRunInstruction({
3041
3049
  documentId: assistableDocumentId,
@@ -3054,16 +3062,16 @@ const assistFieldActions = {
3054
3062
  assistDocumentId2,
3055
3063
  fieldAssistKey
3056
3064
  ]
3057
- ), privateInstructions = react.useMemo(
3065
+ ), privateInstructions = useMemo(
3058
3066
  () => fieldAssist?.instructions?.filter((i) => i.userId && i.userId === currentUser?.id) || [],
3059
3067
  [fieldAssist?.instructions, currentUser]
3060
- ), sharedInstructions = react.useMemo(
3068
+ ), sharedInstructions = useMemo(
3061
3069
  () => fieldAssist?.instructions?.filter((i) => !i.userId) || [],
3062
3070
  [fieldAssist?.instructions]
3063
- ), instructions = react.useMemo(
3071
+ ), instructions = useMemo(
3064
3072
  () => [...privateInstructions, ...sharedInstructions],
3065
3073
  [privateInstructions, sharedInstructions]
3066
- ), runInstructionsGroup = react.useMemo(() => instructions?.length || imageCaptionAction || translateAction || imageGenAction ? {
3074
+ ), runInstructionsGroup = useMemo(() => instructions?.length || imageCaptionAction || translateAction || imageGenAction ? {
3067
3075
  type: "group",
3068
3076
  icon: () => null,
3069
3077
  title: "Run instructions",
@@ -3091,20 +3099,20 @@ const assistFieldActions = {
3091
3099
  imageCaptionAction,
3092
3100
  translateAction,
3093
3101
  imageGenAction
3094
- ]), getDocumentValue = react.useCallback(() => docValueRef.current, []), getConditionalPaths = react.useCallback(() => (formStateRef.current ? getConditionalMembers(formStateRef.current) : []).flatMap(
3102
+ ]), getDocumentValue = useCallback(() => docValueRef.current, []), getConditionalPaths = useCallback(() => (formStateRef.current ? getConditionalMembers(formStateRef.current) : []).flatMap(
3095
3103
  (cm) => {
3096
- const path = sanity.stringToPath(cm.path);
3104
+ const path = stringToPath(cm.path);
3097
3105
  return path.some((s) => typeof s == "number") ? [] : {
3098
3106
  ...cm,
3099
3107
  path
3100
3108
  };
3101
3109
  }
3102
- ), []), parentSchemaType = react.useMemo(() => {
3110
+ ), []), parentSchemaType = useMemo(() => {
3103
3111
  if (props.path.length) {
3104
3112
  if (props.path.length === 1)
3105
3113
  return documentSchemaType;
3106
3114
  } else return;
3107
- const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, sanity.pathToString(parentPath));
3115
+ const parentPath = props.path.slice(0, -1), typePath2 = getTypePath(docValueRef.current, pathToString(parentPath));
3108
3116
  return typePath2 ? fieldRefsByTypePath[typePath2]?.schemaType : void 0;
3109
3117
  }, [fieldRefsByTypePath, props.path, documentSchemaType]), customActions = useCustomFieldActions({
3110
3118
  actionType: props.path.length ? "field" : "document",
@@ -3115,19 +3123,19 @@ const assistFieldActions = {
3115
3123
  getDocumentValue,
3116
3124
  getConditionalPaths,
3117
3125
  parentSchemaType
3118
- }), manageInstructionsItem = react.useMemo(
3126
+ }), manageInstructionsItem = useMemo(
3119
3127
  () => ({
3120
3128
  type: "action",
3121
- icon: icons.ControlsIcon,
3129
+ icon: ControlsIcon,
3122
3130
  title: "Manage instructions",
3123
3131
  onAction: manageInstructions,
3124
3132
  selected: isSelected
3125
3133
  }),
3126
3134
  [manageInstructions, isSelected]
3127
- ), group = react.useMemo(
3135
+ ), group = useMemo(
3128
3136
  () => ({
3129
3137
  type: "group",
3130
- icon: icons.SparklesIcon,
3138
+ icon: SparklesIcon,
3131
3139
  title: pluginTitleShort,
3132
3140
  children: [
3133
3141
  runInstructionsGroup,
@@ -3149,11 +3157,11 @@ const assistFieldActions = {
3149
3157
  imageGenAction,
3150
3158
  customActions
3151
3159
  ]
3152
- ), emptyAction = react.useMemo(
3160
+ ), emptyAction = useMemo(
3153
3161
  () => ({
3154
3162
  type: "action",
3155
3163
  hidden: !assistSupported,
3156
- icon: icons.SparklesIcon,
3164
+ icon: SparklesIcon,
3157
3165
  onAction: manageInstructions,
3158
3166
  renderAsButton: !0,
3159
3167
  title: pluginTitleShort,
@@ -3178,11 +3186,11 @@ function instructionItem(props) {
3178
3186
  }
3179
3187
  function createAssistDocumentPresence(documentId) {
3180
3188
  return function() {
3181
- return documentId ? /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentPresence, {}) : null;
3189
+ return documentId ? /* @__PURE__ */ jsx(AssistDocumentPresence, {}) : null;
3182
3190
  };
3183
3191
  }
3184
3192
  function AssistDocumentPresence() {
3185
- const { assistDocument, syntheticTasks } = useAssistDocumentContext(), anyPresence = react.useMemo(() => {
3193
+ const { assistDocument, syntheticTasks } = useAssistDocumentContext(), anyPresence = useMemo(() => {
3186
3194
  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
3195
  if (anyPresence2)
3188
3196
  return aiPresence(anyPresence2, []);
@@ -3195,19 +3203,19 @@ function AssistDocumentPresence() {
3195
3203
  []
3196
3204
  ) : void 0;
3197
3205
  }, [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 }) }) }) });
3206
+ 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
3207
  }
3200
3208
  function BackToInstructionListLink() {
3201
- const { openInspector } = structure.useDocumentPane(), goBack = react.useCallback(
3209
+ const { openInspector } = useDocumentPane(), goBack = useCallback(
3202
3210
  () => openInspector(aiInspectorId, { [instructionParam]: void 0 }),
3203
3211
  [openInspector]
3204
3212
  );
3205
- return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
3206
- ui.Button,
3213
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
3214
+ Button,
3207
3215
  {
3208
3216
  as: "a",
3209
3217
  fontSize: 1,
3210
- icon: icons.ArrowLeftIcon,
3218
+ icon: ArrowLeftIcon,
3211
3219
  mode: "bleed",
3212
3220
  padding: 1,
3213
3221
  space: 2,
@@ -3217,38 +3225,38 @@ function BackToInstructionListLink() {
3217
3225
  }
3218
3226
  ) });
3219
3227
  }
3220
- const SelectedFieldContext = react.createContext(void 0), SelectedFieldContextProvider = SelectedFieldContext.Provider, EMPTY_FIELDS = [];
3228
+ const SelectedFieldContext = createContext(void 0), SelectedFieldContextProvider = SelectedFieldContext.Provider, EMPTY_FIELDS = [];
3221
3229
  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 });
3230
+ 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
3231
  }
3224
3232
  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(() => {
3233
+ 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
3234
  if (typePath)
3227
3235
  return (fields ?? EMPTY_FIELDS).find((f) => f.path === typePath)?._key;
3228
- }, [fields, typePath]), activePath = react.useMemo(() => {
3236
+ }, [fields, typePath]), activePath = useMemo(() => {
3229
3237
  if (!activeKey)
3230
3238
  return;
3231
3239
  const base = ["fields", { _key: activeKey }];
3232
3240
  return instruction2 ? [...base, "instructions", { _key: instruction2 }] : base;
3233
- }, [activeKey, instruction2]), schema = sanity.useSchema(), documentSchema = react.useMemo(() => {
3241
+ }, [activeKey, instruction2]), schema = useSchema(), documentSchema = useMemo(() => {
3234
3242
  if (targetDocumentType)
3235
3243
  return schema.get(targetDocumentType);
3236
- }, [schema, targetDocumentType]), fieldSchema = useSelectedSchema(pathKey, documentSchema), context = react.useMemo(
3244
+ }, [schema, targetDocumentType]), fieldSchema = useSelectedSchema(pathKey, documentSchema), context = useMemo(
3237
3245
  () => ({
3238
3246
  documentSchema,
3239
3247
  fieldSchema: fieldSchema ?? documentSchema
3240
3248
  }),
3241
3249
  [fieldSchema, documentSchema]
3242
3250
  ), title = value?.title;
3243
- react.useEffect(() => {
3244
- !title && documentSchema && !id?.startsWith("drafts.") && onChange(sanity.set(documentSchema.title ?? documentSchema.name, ["title"]));
3251
+ useEffect(() => {
3252
+ !title && documentSchema && !id?.startsWith("drafts.") && onChange(set(documentSchema.title ?? documentSchema.name, ["title"]));
3245
3253
  }, [title, documentSchema, onChange, id]);
3246
- const { onPathOpen, ...formCallbacks } = sanity.useFormCallbacks(), newCallbacks = react.useMemo(
3254
+ const { onPathOpen, ...formCallbacks } = useFormCallbacks(), newCallbacks = useMemo(
3247
3255
  () => ({
3248
3256
  ...formCallbacks,
3249
3257
  onPathOpen: (path) => {
3250
3258
  !instruction2 && path.length === 4 && path[2] === "instructions" ? (setParams(
3251
- sanity.typed({
3259
+ typed({
3252
3260
  ...params,
3253
3261
  [instructionParam]: path[3]?._key
3254
3262
  })
@@ -3257,18 +3265,18 @@ function AssistDocumentFormEditable(props) {
3257
3265
  }),
3258
3266
  [formCallbacks, onPathOpen, params, setParams, instruction2]
3259
3267
  );
3260
- react.useEffect(() => {
3268
+ useEffect(() => {
3261
3269
  activePath && !instruction2 && onPathOpen([]);
3262
3270
  }, [activePath, instruction2, onPathOpen]);
3263
- const fieldError = react.useMemo(() => {
3271
+ const fieldError = useMemo(() => {
3264
3272
  const fieldError2 = props.members.find(
3265
3273
  (m) => m.kind === "error" && m.fieldName === "fields"
3266
3274
  );
3267
3275
  if (fieldError2)
3268
- return /* @__PURE__ */ jsxRuntime.jsx(sanity.MemberFieldError, { member: fieldError2 });
3276
+ return /* @__PURE__ */ jsx(MemberFieldError, { member: fieldError2 });
3269
3277
  }, [props.members]);
3270
- return /* @__PURE__ */ jsxRuntime.jsx(SelectedFieldContextProvider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 5, children: [
3271
- /* @__PURE__ */ jsxRuntime.jsx(
3278
+ return /* @__PURE__ */ jsx(SelectedFieldContextProvider, { value: context, children: /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
3279
+ /* @__PURE__ */ jsx(
3272
3280
  FieldsInitializer,
3273
3281
  {
3274
3282
  pathKey: typePath,
@@ -3279,19 +3287,19 @@ function AssistDocumentFormEditable(props) {
3279
3287
  },
3280
3288
  typePath
3281
3289
  ),
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 }) }) }),
3290
+ instruction2 && /* @__PURE__ */ jsx(BackToInstructionListLink, {}),
3291
+ activePath && !fieldError && /* @__PURE__ */ jsx(FormCallbacksProvider, { ...newCallbacks, children: /* @__PURE__ */ jsx("div", { style: { lineHeight: "1.25em" }, children: /* @__PURE__ */ jsx(FormInput, { ...props, absolutePath: activePath }) }) }),
3284
3292
  fieldError,
3285
3293
  !activePath && props.renderDefault(props)
3286
3294
  ] }) });
3287
3295
  }
3288
3296
  function useSelectedSchema(fieldPath, documentSchema) {
3289
- return react.useMemo(() => {
3297
+ return useMemo(() => {
3290
3298
  if (!fieldPath)
3291
3299
  return;
3292
3300
  if (fieldPath === documentRootKey)
3293
3301
  return documentSchema;
3294
- const path = sanity.stringToPath(fieldPath);
3302
+ const path = stringToPath(fieldPath);
3295
3303
  let currentSchema = documentSchema;
3296
3304
  for (let i = 0; i < path.length; i++) {
3297
3305
  const segment = path[i], field = currentSchema?.fields.find((f) => f.name === segment);
@@ -3315,22 +3323,22 @@ function FieldsInitializer({
3315
3323
  }) {
3316
3324
  const {
3317
3325
  config: { __presets: presets }
3318
- } = useAiAssistanceConfig(), existingField = fields?.find((f) => f._key === pathKey), documentPresets = !!documentSchema?.name && presets?.[documentSchema?.name], missingPresetInstructions = react.useMemo(() => {
3326
+ } = useAiAssistanceConfig(), existingField = fields?.find((f) => f._key === pathKey), documentPresets = !!documentSchema?.name && presets?.[documentSchema?.name], missingPresetInstructions = useMemo(() => {
3319
3327
  if (!documentPresets || !pathKey)
3320
3328
  return;
3321
3329
  const existingInstructions = existingField?.instructions;
3322
3330
  return documentPresets.fields?.find((f) => f.path === pathKey)?.instructions?.filter(
3323
3331
  (i) => !existingInstructions?.some((ei) => ei._key === i._key)
3324
3332
  );
3325
- }, [documentPresets, pathKey, existingField]), initialized = react.useRef(!1);
3326
- return react.useEffect(() => {
3333
+ }, [documentPresets, pathKey, existingField]), initialized = useRef(!1);
3334
+ return useEffect(() => {
3327
3335
  if (initialized.current || !pathKey || existingField && !missingPresetInstructions?.length)
3328
3336
  return;
3329
- let event = sanity.PatchEvent.from([sanity.setIfMissing([], ["fields"])]);
3337
+ let event = PatchEvent.from([setIfMissing([], ["fields"])]);
3330
3338
  existingField || (event = event.append(
3331
- sanity.insert(
3339
+ insert(
3332
3340
  [
3333
- sanity.typed({
3341
+ typed({
3334
3342
  _key: pathKey,
3335
3343
  _type: assistFieldTypeName,
3336
3344
  path: pathKey,
@@ -3340,8 +3348,8 @@ function FieldsInitializer({
3340
3348
  "after",
3341
3349
  ["fields", -1]
3342
3350
  )
3343
- )), existingField?.instructions?.length || (event = event.append([sanity.setIfMissing([], ["fields", { _key: pathKey }, "instructions"])])), missingPresetInstructions?.length && (event = event.append(
3344
- sanity.insert(
3351
+ )), existingField?.instructions?.length || (event = event.append([setIfMissing([], ["fields", { _key: pathKey }, "instructions"])])), missingPresetInstructions?.length && (event = event.append(
3352
+ insert(
3345
3353
  missingPresetInstructions.map(
3346
3354
  (preset) => ({
3347
3355
  ...preset,
@@ -3356,9 +3364,9 @@ function FieldsInitializer({
3356
3364
  }, [activePath, onChange, pathKey, existingField, missingPresetInstructions]), null;
3357
3365
  }
3358
3366
  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" }) }) }),
3367
+ const { actions } = props, documentSchema = useContext(SelectedFieldContext)?.documentSchema, path = useContext(InlineBlockValueContext)?.path ?? props.path, selectedField = useSelectedField(documentSchema, path);
3368
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", style: { width: "100%" }, children: [
3369
+ /* @__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
3370
  actions
3363
3371
  ] });
3364
3372
  }
@@ -3366,13 +3374,13 @@ function HiddenFieldTitle(props) {
3366
3374
  return props.renderDefault({ ...props, title: "", level: props.level - 2, changed: !1 });
3367
3375
  }
3368
3376
  function InstructionVisibility(props) {
3369
- const { value, onChange } = props, user = sanity.useCurrentUser(), handleChange = react.useCallback(() => {
3377
+ const { value, onChange } = props, user = useCurrentUser(), handleChange = useCallback(() => {
3370
3378
  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,
3379
+ onChange(newValue ? set(newValue) : unset());
3380
+ }, [onChange, user, value]), id = useId();
3381
+ return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "flex-start", children: [
3382
+ /* @__PURE__ */ jsx("div", { style: { margin: "-3px 0" }, children: /* @__PURE__ */ jsx(
3383
+ Switch,
3376
3384
  {
3377
3385
  ...props.elementProps,
3378
3386
  id,
@@ -3382,15 +3390,15 @@ function InstructionVisibility(props) {
3382
3390
  disabled: props.elementProps.readOnly
3383
3391
  }
3384
3392
  ) }),
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" }) })
3393
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, weight: "medium", children: /* @__PURE__ */ jsx("label", { htmlFor: id, children: "Make visible to all Studio members" }) })
3386
3394
  ] }) });
3387
3395
  }
3388
3396
  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(() => {
3397
+ const documentSchema = useContext(SelectedFieldContext)?.documentSchema, { typePath } = useContext(AssistTypeContext), ref = useRef(null), id = useId(), { onChange } = props;
3398
+ useEffect(() => {
3391
3399
  ref.current?.querySelector("input")?.focus();
3392
3400
  }, []);
3393
- const onSelect = react.useCallback((path) => onChange(sanity.set(path)), [onChange]), filter = react.useCallback(
3401
+ const onSelect = useCallback((path) => onChange(set(path)), [onChange]), filter2 = useCallback(
3394
3402
  (field) => {
3395
3403
  if (!field.key.includes("|") || !typePath)
3396
3404
  return !0;
@@ -3401,14 +3409,14 @@ function FieldRefPathInput(props) {
3401
3409
  },
3402
3410
  [typePath]
3403
3411
  );
3404
- return documentSchema ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, style: { minWidth: 300 }, ref, children: /* @__PURE__ */ jsxRuntime.jsx(
3412
+ return documentSchema ? /* @__PURE__ */ jsx(Box, { flex: 1, style: { minWidth: 300 }, ref, children: /* @__PURE__ */ jsx(
3405
3413
  FieldAutocomplete,
3406
3414
  {
3407
3415
  id,
3408
3416
  schemaType: documentSchema,
3409
3417
  onSelect,
3410
3418
  fieldPath: props.value,
3411
- filter
3419
+ filter: filter2
3412
3420
  }
3413
3421
  ) }) : props.renderDefault(props);
3414
3422
  }
@@ -3423,20 +3431,20 @@ function findFieldsetMember(members, fieldsetName) {
3423
3431
  );
3424
3432
  }
3425
3433
  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 })
3434
+ return /* @__PURE__ */ jsxs(Stack, { space: [4, 4, 4, 5], children: [
3435
+ /* @__PURE__ */ jsx(NameField, { ...props }),
3436
+ /* @__PURE__ */ jsx(ShareField, { ...props }),
3437
+ /* @__PURE__ */ jsx(ObjectMember, { fieldName: "prompt", ...props }),
3438
+ /* @__PURE__ */ jsx(ObjectMember, { fieldName: "output", ...props })
3431
3439
  ] });
3432
3440
  }
3433
3441
  function ObjectMember({ fieldName, ...props }) {
3434
3442
  const member = findFieldMember(props.members, fieldName);
3435
- return member ? /* @__PURE__ */ jsxRuntime.jsx(sanity.ObjectInputMember, { ...props, member }) : null;
3443
+ return member ? /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member }) : null;
3436
3444
  }
3437
3445
  const NONE = [];
3438
3446
  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(() => {
3447
+ 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
3448
  if (titleMember)
3441
3449
  return titleMember.kind === "error" ? titleMember : {
3442
3450
  ...titleMember,
@@ -3449,28 +3457,28 @@ function NameField(props) {
3449
3457
  }
3450
3458
  };
3451
3459
  }, [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 }) })
3460
+ return /* @__PURE__ */ jsx(Stack, { space: 5, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
3461
+ /* @__PURE__ */ jsx(Flex, { gap: 1, children: /* @__PURE__ */ jsx(Text, { as: "label", weight: "semibold", size: 1, htmlFor: titleId, children: "Name" }) }),
3462
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "How this instruction appears in menus" }),
3463
+ /* @__PURE__ */ jsxs(Flex, { align: "center", children: [
3464
+ iconMember && /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: iconMember }) }),
3465
+ moddedTitleMember && /* @__PURE__ */ jsx(Box, { flex: 1, style: { marginLeft: -1 }, children: /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: moddedTitleMember }) })
3458
3466
  ] })
3459
3467
  ] }) });
3460
3468
  }
3461
3469
  function ShareField(props) {
3462
3470
  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 }) });
3471
+ return /* @__PURE__ */ jsx(Fragment, { children: visibilityMember && /* @__PURE__ */ jsx(ObjectInputMember, { ...props, member: visibilityMember }) });
3464
3472
  }
3465
3473
  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 });
3474
+ const { fieldSchema } = useContext(SelectedFieldContext) ?? {};
3475
+ return !fieldSchema || !(isObjectSchemaType(fieldSchema) || isArrayOfObjectsSchemaType(fieldSchema)) ? null : /* @__PURE__ */ jsx(EnabledOutputField, { ...props, fieldSchema, children: props.children });
3468
3476
  }
3469
3477
  function EnabledOutputField({
3470
3478
  fieldSchema,
3471
3479
  ...props
3472
3480
  }) {
3473
- const [open, setOpen] = react.useState(!!props.value?.length), onExpand = react.useCallback(() => setOpen(!0), []), onCollapse = react.useCallback(() => setOpen(!1), []);
3481
+ const [open, setOpen] = useState(!!props.value?.length), onExpand = useCallback(() => setOpen(!0), []), onCollapse = useCallback(() => setOpen(!1), []);
3474
3482
  return props.renderDefault({
3475
3483
  ...props,
3476
3484
  collapsible: !0,
@@ -3478,46 +3486,46 @@ function EnabledOutputField({
3478
3486
  onCollapse,
3479
3487
  collapsed: !open,
3480
3488
  level: 1,
3481
- title: sanity.isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
3489
+ title: isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
3482
3490
  });
3483
3491
  }
3484
3492
  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;
3493
+ const { fieldSchema } = useContext(SelectedFieldContext) ?? {};
3494
+ return fieldSchema ? isObjectSchemaType(fieldSchema) ? /* @__PURE__ */ jsx(ObjectOutputInput, { ...props, fieldSchema }) : isArrayOfObjectsSchemaType(fieldSchema) ? /* @__PURE__ */ jsx(ArrayOutputInput, { ...props, fieldSchema }) : null : null;
3487
3495
  }
3488
3496
  function useEmptySelectAllValue(value, allowedValues, onChange) {
3489
- react.useEffect(() => {
3497
+ useEffect(() => {
3490
3498
  const validValues = value?.filter(
3491
3499
  (v) => allowedValues.find(
3492
3500
  (f) => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)
3493
3501
  )
3494
3502
  ), valueLength = value?.length ?? 0, validLength = validValues?.length ?? 0;
3495
- (!validLength && valueLength || validLength >= allowedValues.length) && onChange(sanity.PatchEvent.from([sanity.unset()]));
3503
+ (!validLength && valueLength || validLength >= allowedValues.length) && onChange(PatchEvent.from([unset()]));
3496
3504
  }, [allowedValues, value, onChange]);
3497
3505
  }
3498
3506
  function ObjectOutputInput({
3499
3507
  fieldSchema,
3500
3508
  ...props
3501
3509
  }) {
3502
- const { value, onChange } = props, fields = react.useMemo(
3510
+ const { value, onChange } = props, fields = useMemo(
3503
3511
  () => fieldSchema.fields.filter((field) => isAssistSupported(field.type)),
3504
3512
  [fieldSchema.fields]
3505
3513
  );
3506
3514
  useEmptySelectAllValue(value, fields, onChange);
3507
- const onSelectChange = react.useCallback(
3515
+ const onSelectChange = useCallback(
3508
3516
  (checked, selectedValue) => {
3509
3517
  if (checked)
3510
3518
  if (value?.length)
3511
- onChange(sanity.PatchEvent.from(sanity.unset([{ _key: selectedValue }])));
3519
+ onChange(PatchEvent.from(unset([{ _key: selectedValue }])));
3512
3520
  else {
3513
3521
  const items = fields.filter((f) => f.name !== selectedValue).map(
3514
- (field) => sanity.typed({
3522
+ (field) => typed({
3515
3523
  _key: field.name,
3516
3524
  _type: "sanity.assist.output.field",
3517
3525
  relativePath: field.name
3518
3526
  })
3519
3527
  );
3520
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert(items, "after", [-1])]));
3528
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
3521
3529
  }
3522
3530
  else {
3523
3531
  const patchValue = {
@@ -3525,12 +3533,12 @@ function ObjectOutputInput({
3525
3533
  _type: "sanity.assist.output.field",
3526
3534
  relativePath: selectedValue
3527
3535
  };
3528
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([patchValue], "after", [-1])]));
3536
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
3529
3537
  }
3530
3538
  },
3531
3539
  [onChange, value, fields]
3532
3540
  );
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(
3541
+ return /* @__PURE__ */ jsx(Stack, { space: 2, children: fields.map((field) => /* @__PURE__ */ jsx(Flex, { align: "center", gap: 2, children: /* @__PURE__ */ jsx(
3534
3542
  Selectable,
3535
3543
  {
3536
3544
  value: field.name,
@@ -3544,25 +3552,25 @@ function ArrayOutputInput({
3544
3552
  fieldSchema,
3545
3553
  ...props
3546
3554
  }) {
3547
- const { value, onChange } = props, ofItems = react.useMemo(
3555
+ const { value, onChange } = props, ofItems = useMemo(
3548
3556
  () => fieldSchema.of.filter((itemType) => isAssistSupported(itemType)),
3549
3557
  [fieldSchema.of]
3550
3558
  );
3551
3559
  useEmptySelectAllValue(value, ofItems, onChange);
3552
- const onSelectChange = react.useCallback(
3560
+ const onSelectChange = useCallback(
3553
3561
  (checked, selectedValue) => {
3554
3562
  if (checked)
3555
3563
  if (value?.length)
3556
- onChange(sanity.PatchEvent.from(sanity.unset([{ _key: selectedValue }])));
3564
+ onChange(PatchEvent.from(unset([{ _key: selectedValue }])));
3557
3565
  else {
3558
3566
  const items = ofItems.filter((f) => f.name !== selectedValue).map(
3559
- (field) => sanity.typed({
3567
+ (field) => typed({
3560
3568
  _key: field.name,
3561
3569
  _type: "sanity.assist.output.type",
3562
3570
  type: field.name
3563
3571
  })
3564
3572
  );
3565
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert(items, "after", [-1])]));
3573
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
3566
3574
  }
3567
3575
  else {
3568
3576
  const patchValue = {
@@ -3570,12 +3578,12 @@ function ArrayOutputInput({
3570
3578
  _type: "sanity.assist.output.type",
3571
3579
  type: selectedValue
3572
3580
  };
3573
- onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([patchValue], "after", [-1])]));
3581
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
3574
3582
  }
3575
3583
  },
3576
3584
  [onChange, value, ofItems]
3577
3585
  );
3578
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: ofItems.map((itemType) => /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(
3586
+ return /* @__PURE__ */ jsx(Stack, { space: 2, children: ofItems.map((itemType) => /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3579
3587
  Selectable,
3580
3588
  {
3581
3589
  value: itemType.name,
@@ -3591,13 +3599,13 @@ function Selectable({
3591
3599
  value,
3592
3600
  onChange
3593
3601
  }) {
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 }) })
3602
+ const checked = !arrayValue?.length || !!arrayValue?.find((v) => v._key === value), handleChange = useCallback(() => onChange(checked, value), [onChange, checked, value]);
3603
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "flex-start", children: [
3604
+ /* @__PURE__ */ jsx(Checkbox, { checked, onChange: handleChange }),
3605
+ /* @__PURE__ */ jsx(Card, { marginTop: 1, onClick: handleChange, children: /* @__PURE__ */ jsx(Text, { style: { cursor: "default" }, size: 1, children: title }) })
3598
3606
  ] });
3599
3607
  }
3600
- const PteMods = styledComponents.styled(ui.Box)`
3608
+ const PteMods = styled(Box)`
3601
3609
  & [data-testid='pt-editor__toolbar-card'] > div > div:last-child {
3602
3610
  display: none;
3603
3611
  }
@@ -3609,12 +3617,12 @@ const PteMods = styledComponents.styled(ui.Box)`
3609
3617
  }
3610
3618
  `;
3611
3619
  function PromptInput(props) {
3612
- return useOnlyInlineBlocks(props), /* @__PURE__ */ jsxRuntime.jsx(PteMods, { children: props.renderDefault(props) });
3620
+ return useOnlyInlineBlocks(props), /* @__PURE__ */ jsx(PteMods, { children: props.renderDefault(props) });
3613
3621
  }
3614
3622
  function useOnlyInlineBlocks(props) {
3615
- react.useEffect(() => {
3623
+ useEffect(() => {
3616
3624
  let needsFix = !1;
3617
- const val = (props.value ?? []).map((block) => block._type === "block" ? block : (needsFix = !0, sanity.typed({
3625
+ const val = (props.value ?? []).map((block) => block._type === "block" ? block : (needsFix = !0, typed({
3618
3626
  _key: randomKey(12),
3619
3627
  _type: "block",
3620
3628
  level: 0,
@@ -3622,7 +3630,7 @@ function useOnlyInlineBlocks(props) {
3622
3630
  style: "normal",
3623
3631
  children: [block]
3624
3632
  })));
3625
- needsFix && props.onChange(sanity.set(val));
3633
+ needsFix && props.onChange(set(val));
3626
3634
  }, []);
3627
3635
  }
3628
3636
  function InstructionsArrayField(props) {
@@ -3632,10 +3640,10 @@ function InstructionsArrayField(props) {
3632
3640
  });
3633
3641
  }
3634
3642
  function InstructionsArrayInput(props) {
3635
- const user = sanity.useCurrentUser(), originalValue = props.value, originalMembers = props.members, value = react.useMemo(
3643
+ const user = useCurrentUser(), originalValue = props.value, originalMembers = props.members, value = useMemo(
3636
3644
  () => (originalValue ?? []).filter((v) => !v.userId || v.userId === user?.id),
3637
3645
  [originalValue, user]
3638
- ), members = react.useMemo(
3646
+ ), members = useMemo(
3639
3647
  () => (originalMembers ?? []).filter((v) => {
3640
3648
  if (v.kind === "error")
3641
3649
  return !0;
@@ -3647,8 +3655,8 @@ function InstructionsArrayInput(props) {
3647
3655
  return props.renderDefault({ ...props, value, members });
3648
3656
  }
3649
3657
  function HideReferenceChangedBannerInput(props) {
3650
- const ref = react.useRef(null);
3651
- return react.useEffect(() => {
3658
+ const ref = useRef(null);
3659
+ return useEffect(() => {
3652
3660
  const parent = ref.current?.closest('[data-testid="pane-content"]');
3653
3661
  if (!parent)
3654
3662
  return;
@@ -3656,29 +3664,29 @@ function HideReferenceChangedBannerInput(props) {
3656
3664
  parent.id = parentId, style.innerText = `
3657
3665
  #${parentId} [data-testid="reference-changed-banner"] { display: none; }
3658
3666
  `, parent.prepend(style);
3659
- }, [ref]), /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { ref, children: props.renderDefault(props) });
3667
+ }, [ref]), /* @__PURE__ */ jsx(Box, { ref, children: props.renderDefault(props) });
3660
3668
  }
3661
- const contextDocumentSchema = sanity.defineType({
3669
+ const contextDocumentSchema = defineType({
3662
3670
  type: "document",
3663
3671
  name: contextDocumentTypeName,
3664
3672
  title: "AI context",
3665
3673
  liveEdit: !0,
3666
- icon: icons.TokenIcon,
3674
+ icon: TokenIcon,
3667
3675
  components: {
3668
3676
  input: HideReferenceChangedBannerInput
3669
3677
  },
3670
3678
  fields: [
3671
- sanity.defineField({
3679
+ defineField({
3672
3680
  type: "string",
3673
3681
  name: "title",
3674
3682
  title: "Title"
3675
3683
  }),
3676
- sanity.defineField({
3684
+ defineField({
3677
3685
  name: "context",
3678
3686
  type: "array",
3679
3687
  title: "Context",
3680
3688
  of: [
3681
- sanity.defineArrayMember({
3689
+ defineArrayMember({
3682
3690
  type: "block",
3683
3691
  styles: [{ title: "Normal", value: "normal" }],
3684
3692
  lists: [],
@@ -3700,17 +3708,17 @@ const contextDocumentSchema = sanity.defineType({
3700
3708
  return {
3701
3709
  title,
3702
3710
  subtitle: `Words: ${words}`,
3703
- media: icons.DocumentTextIcon
3711
+ media: DocumentTextIcon
3704
3712
  };
3705
3713
  }
3706
3714
  }
3707
- }), fieldReference = sanity.defineType({
3715
+ }), fieldReference = defineType({
3708
3716
  type: "object",
3709
3717
  name: fieldReferenceTypeName,
3710
3718
  title: "Field",
3711
- icon: icons.ThListIcon,
3719
+ icon: ThListIcon,
3712
3720
  fields: [
3713
- sanity.defineField({
3721
+ defineField({
3714
3722
  type: "string",
3715
3723
  name: "path",
3716
3724
  title: "Field",
@@ -3746,7 +3754,7 @@ const contextDocumentSchema = sanity.defineType({
3746
3754
  return {
3747
3755
  title: path,
3748
3756
  path,
3749
- icon: icons.CodeIcon
3757
+ icon: CodeIcon
3750
3758
  };
3751
3759
  }
3752
3760
  },
@@ -3758,13 +3766,13 @@ const contextDocumentSchema = sanity.defineType({
3758
3766
  type: "popover"
3759
3767
  }
3760
3768
  }
3761
- }), userInput = sanity.defineType({
3769
+ }), userInput = defineType({
3762
3770
  type: "object",
3763
3771
  name: userInputTypeName,
3764
3772
  title: "User input",
3765
- icon: icons.ComposeIcon,
3773
+ icon: ComposeIcon,
3766
3774
  fields: [
3767
- sanity.defineField({
3775
+ defineField({
3768
3776
  type: "string",
3769
3777
  name: "message",
3770
3778
  title: "User input title",
@@ -3772,7 +3780,7 @@ const contextDocumentSchema = sanity.defineType({
3772
3780
  description: "The header above the user input text field",
3773
3781
  validation: (rule) => rule.required()
3774
3782
  }),
3775
- sanity.defineField({
3783
+ defineField({
3776
3784
  type: "text",
3777
3785
  rows: 3,
3778
3786
  name: "description",
@@ -3791,13 +3799,13 @@ const contextDocumentSchema = sanity.defineType({
3791
3799
  width: 1
3792
3800
  }
3793
3801
  }
3794
- }), promptContext = sanity.defineType({
3802
+ }), promptContext = defineType({
3795
3803
  type: "object",
3796
3804
  name: instructionContextTypeName,
3797
3805
  title: contextDocumentSchema.title,
3798
3806
  icon: contextDocumentSchema.icon,
3799
3807
  fields: [
3800
- sanity.defineField({
3808
+ defineField({
3801
3809
  type: "reference",
3802
3810
  name: "reference",
3803
3811
  to: [{ type: contextDocumentSchema.name }],
@@ -3806,14 +3814,14 @@ const contextDocumentSchema = sanity.defineType({
3806
3814
  validation: (rule) => rule.required(),
3807
3815
  components: {
3808
3816
  input: function(props) {
3809
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { maxWidth: 300 }, children: props.renderDefault(props) });
3817
+ return /* @__PURE__ */ jsx(Box, { style: { maxWidth: 300 }, children: props.renderDefault(props) });
3810
3818
  }
3811
3819
  }
3812
3820
  })
3813
3821
  ],
3814
3822
  preview: {
3815
3823
  select: {
3816
- ref: "reference._ref",
3824
+ ref: "reference._id",
3817
3825
  title: "reference.title",
3818
3826
  context: "reference.context"
3819
3827
  },
@@ -3827,12 +3835,12 @@ const contextDocumentSchema = sanity.defineType({
3827
3835
  width: "auto"
3828
3836
  }
3829
3837
  }
3830
- }), prompt = sanity.defineType({
3838
+ }), prompt = defineType({
3831
3839
  type: "array",
3832
3840
  name: promptTypeName,
3833
3841
  title: "Prompt",
3834
3842
  of: [
3835
- sanity.defineArrayMember({
3843
+ defineArrayMember({
3836
3844
  type: "block",
3837
3845
  styles: [{ title: "Normal", value: "normal" }],
3838
3846
  lists: [],
@@ -3841,13 +3849,13 @@ const contextDocumentSchema = sanity.defineType({
3841
3849
  annotations: []
3842
3850
  },
3843
3851
  of: [
3844
- sanity.defineArrayMember({
3852
+ defineArrayMember({
3845
3853
  type: fieldReference.name
3846
3854
  }),
3847
- sanity.defineArrayMember({
3855
+ defineArrayMember({
3848
3856
  type: promptContext.name
3849
3857
  }),
3850
- sanity.defineArrayMember({
3858
+ defineArrayMember({
3851
3859
  type: userInput.name
3852
3860
  })
3853
3861
  ]
@@ -3862,29 +3870,29 @@ const contextDocumentSchema = sanity.defineType({
3862
3870
  type: userInput.name,
3863
3871
  }),*/
3864
3872
  ]
3865
- }), outputFieldType = sanity.defineType({
3873
+ }), outputFieldType = defineType({
3866
3874
  type: "object",
3867
3875
  name: outputFieldTypeName,
3868
3876
  title: "Output field",
3869
3877
  fields: [
3870
- sanity.defineField({
3878
+ defineField({
3871
3879
  type: "string",
3872
3880
  name: "path",
3873
3881
  title: "Path"
3874
3882
  })
3875
3883
  ]
3876
- }), outputTypeType = sanity.defineType({
3884
+ }), outputTypeType = defineType({
3877
3885
  type: "object",
3878
3886
  name: outputTypeTypeName,
3879
3887
  title: "Output type",
3880
3888
  fields: [
3881
- sanity.defineField({
3889
+ defineField({
3882
3890
  type: "string",
3883
3891
  name: "type",
3884
3892
  title: "Type"
3885
3893
  })
3886
3894
  ]
3887
- }), instruction = sanity.defineType({
3895
+ }), instruction = defineType({
3888
3896
  type: "object",
3889
3897
  name: instructionTypeName,
3890
3898
  title: "Instruction",
@@ -3899,45 +3907,45 @@ const contextDocumentSchema = sanity.defineType({
3899
3907
  },
3900
3908
  prepare: ({ icon, title, userId }) => ({
3901
3909
  title,
3902
- icon: icon ? icons.icons[icon] : icons.SparklesIcon,
3910
+ icon: icon ? icons[icon] : SparklesIcon,
3903
3911
  userId
3904
3912
  })
3905
3913
  },
3906
3914
  components: {
3907
3915
  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,
3916
+ preview: (props) => /* @__PURE__ */ jsxs(Flex, { gap: 3, align: "center", padding: 2, children: [
3917
+ props.icon && /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(Text, { size: 1, children: createElement(props.icon) }) }),
3918
+ /* @__PURE__ */ jsx(Stack, { flex: 1, space: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, textOverflow: "ellipsis", weight: "medium", children: getInstructionTitle(props) }) }),
3919
+ props.userId && /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(
3920
+ Tooltip,
3913
3921
  {
3914
- content: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: "Only visible to you" }),
3922
+ content: /* @__PURE__ */ jsx(Text, { size: 1, children: "Only visible to you" }),
3915
3923
  padding: 2,
3916
3924
  placement: "top",
3917
3925
  portal: !0,
3918
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.LockIcon, {})
3926
+ children: /* @__PURE__ */ jsx(LockIcon, {})
3919
3927
  }
3920
3928
  ) })
3921
3929
  ] })
3922
3930
  },
3923
3931
  fields: [
3924
- sanity.defineField({
3932
+ defineField({
3925
3933
  type: prompt.name,
3926
3934
  name: "prompt",
3927
3935
  title: "Instruction",
3928
- description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3936
+ description: /* @__PURE__ */ jsxs(Fragment, { children: [
3929
3937
  "Learn from",
3930
3938
  " ",
3931
- /* @__PURE__ */ jsxRuntime.jsxs("a", { href: instructionGuideUrl, target: "_blank", rel: "noreferrer", children: [
3939
+ /* @__PURE__ */ jsxs("a", { href: instructionGuideUrl, target: "_blank", rel: "noreferrer", children: [
3932
3940
  "our instruction guide ",
3933
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRightIcon, {})
3941
+ /* @__PURE__ */ jsx(ArrowRightIcon, {})
3934
3942
  ] })
3935
3943
  ] }),
3936
3944
  components: {
3937
3945
  input: PromptInput
3938
3946
  }
3939
3947
  }),
3940
- sanity.defineField({
3948
+ defineField({
3941
3949
  type: "string",
3942
3950
  name: "icon",
3943
3951
  title: "Icon",
@@ -3947,7 +3955,7 @@ const contextDocumentSchema = sanity.defineType({
3947
3955
  input: IconInput
3948
3956
  }
3949
3957
  }),
3950
- sanity.defineField({
3958
+ defineField({
3951
3959
  type: "string",
3952
3960
  name: "title",
3953
3961
  title: "Title",
@@ -3956,7 +3964,7 @@ const contextDocumentSchema = sanity.defineType({
3956
3964
  field: HiddenFieldTitle
3957
3965
  }
3958
3966
  }),
3959
- sanity.defineField({
3967
+ defineField({
3960
3968
  type: "string",
3961
3969
  name: "userId",
3962
3970
  title: "Visibility",
@@ -3968,7 +3976,7 @@ const contextDocumentSchema = sanity.defineType({
3968
3976
  initialValue: (params, context) => context.currentUser?.id ?? "",
3969
3977
  readOnly: (context) => !!(context.parent?.createdById && context.parent?.createdById !== context.currentUser?.id)
3970
3978
  }),
3971
- sanity.defineField({
3979
+ defineField({
3972
3980
  type: "string",
3973
3981
  name: "createdById",
3974
3982
  title: "Created by",
@@ -3976,7 +3984,7 @@ const contextDocumentSchema = sanity.defineType({
3976
3984
  fieldset: "appearance",
3977
3985
  initialValue: (params, context) => context.currentUser?.id ?? ""
3978
3986
  }),
3979
- sanity.defineField({
3987
+ defineField({
3980
3988
  type: "array",
3981
3989
  name: "output",
3982
3990
  title: "Output filter",
@@ -3985,12 +3993,12 @@ const contextDocumentSchema = sanity.defineType({
3985
3993
  field: InstructionOutputField
3986
3994
  },
3987
3995
  of: [
3988
- sanity.defineArrayMember({ type: outputFieldType.name }),
3989
- sanity.defineArrayMember({ type: outputTypeType.name })
3996
+ defineArrayMember({ type: outputFieldType.name }),
3997
+ defineArrayMember({ type: outputTypeType.name })
3990
3998
  ]
3991
3999
  })
3992
4000
  ]
3993
- }), fieldInstructions = sanity.defineType({
4001
+ }), fieldInstructions = defineType({
3994
4002
  type: "object",
3995
4003
  name: assistFieldTypeName,
3996
4004
  title: "Field prompt",
@@ -3998,14 +4006,14 @@ const contextDocumentSchema = sanity.defineType({
3998
4006
  input: FieldPromptInput,
3999
4007
  },*/
4000
4008
  fields: [
4001
- sanity.defineField({
4009
+ defineField({
4002
4010
  type: "string",
4003
4011
  name: "path",
4004
4012
  title: "Path",
4005
4013
  readOnly: !0,
4006
4014
  hidden: !0
4007
4015
  }),
4008
- sanity.defineField({
4016
+ defineField({
4009
4017
  type: "array",
4010
4018
  name: "instructions",
4011
4019
  title: "Instructions",
@@ -4021,7 +4029,7 @@ const contextDocumentSchema = sanity.defineType({
4021
4029
  title: "path"
4022
4030
  }
4023
4031
  }
4024
- }), assistDocumentSchema = sanity.defineType({
4032
+ }), assistDocumentSchema = defineType({
4025
4033
  //NOTE: this is a document type. Using object here ensures it does not appear in structure menus
4026
4034
  type: "object",
4027
4035
  liveEdit: !0,
@@ -4032,12 +4040,12 @@ const contextDocumentSchema = sanity.defineType({
4032
4040
  field: (props) => props.renderDefault({ ...props, title: "" })
4033
4041
  },
4034
4042
  fields: [
4035
- sanity.defineField({
4043
+ defineField({
4036
4044
  type: "string",
4037
4045
  name: "title",
4038
4046
  title: "Title"
4039
4047
  }),
4040
- sanity.defineField({
4048
+ defineField({
4041
4049
  type: "array",
4042
4050
  name: "fields",
4043
4051
  title: "Fields",
@@ -4049,45 +4057,45 @@ const contextDocumentSchema = sanity.defineType({
4049
4057
  title: "title"
4050
4058
  }
4051
4059
  }
4052
- }), instructionTask = sanity.defineType({
4060
+ }), instructionTask = defineType({
4053
4061
  type: "object",
4054
4062
  name: instructionTaskTypeName,
4055
4063
  title: "Instruction task",
4056
4064
  fields: [
4057
- sanity.defineField({
4065
+ defineField({
4058
4066
  type: "string",
4059
4067
  name: "path",
4060
4068
  title: "Path"
4061
4069
  }),
4062
- sanity.defineField({
4070
+ defineField({
4063
4071
  type: "string",
4064
4072
  name: "instructionKey",
4065
4073
  title: "Instruction key"
4066
4074
  }),
4067
- sanity.defineField({
4075
+ defineField({
4068
4076
  type: "datetime",
4069
4077
  name: "started",
4070
4078
  title: "Started"
4071
4079
  }),
4072
- sanity.defineField({
4080
+ defineField({
4073
4081
  type: "datetime",
4074
4082
  name: "updated",
4075
4083
  title: "Updated"
4076
4084
  }),
4077
- sanity.defineField({
4085
+ defineField({
4078
4086
  type: "string",
4079
4087
  name: "info",
4080
4088
  title: "Info"
4081
4089
  })
4082
4090
  ]
4083
- }), documentInstructionStatus = sanity.defineType({
4091
+ }), documentInstructionStatus = defineType({
4084
4092
  //NOTE: this is a document type. Using object here ensures it does not appear in structure menus
4085
4093
  type: "object",
4086
4094
  liveEdit: !0,
4087
4095
  name: assistTasksStatusTypeName,
4088
4096
  title: "Document instruction status",
4089
4097
  fields: [
4090
- sanity.defineField({
4098
+ defineField({
4091
4099
  type: "array",
4092
4100
  name: "tasks",
4093
4101
  title: "Tasks",
@@ -4133,7 +4141,7 @@ const instructionForm = [
4133
4141
  documentInstructionStatus,
4134
4142
  instructionTask,
4135
4143
  contextDocumentSchema
4136
- ], assist = sanity.definePlugin((config) => {
4144
+ ], assist = definePlugin((config) => {
4137
4145
  const configWithDefaults = config ?? {}, styleguide = configWithDefaults.translate?.styleguide || "", maxPathDepth = configWithDefaults.assist?.maxPathDepth, temperature = configWithDefaults.assist?.temperature;
4138
4146
  if (typeof styleguide == "string" && validateStyleguide(styleguide), maxPathDepth !== void 0 && (maxPathDepth < 1 || maxPathDepth > 12))
4139
4147
  throw new Error(
@@ -4167,7 +4175,7 @@ const instructionForm = [
4167
4175
  if (schemaType === assistDocumentTypeName)
4168
4176
  return [];
4169
4177
  const docSchema = schema.get(schemaType);
4170
- return docSchema && sanity.isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema) ? [...prev, createAssistDocumentPresence(documentId)] : prev;
4178
+ return docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema) ? [...prev, createAssistDocumentPresence(documentId)] : prev;
4171
4179
  },
4172
4180
  components: {
4173
4181
  unstable_layout: AssistDocumentLayout
@@ -4176,7 +4184,7 @@ const instructionForm = [
4176
4184
  studio: {
4177
4185
  components: {
4178
4186
  layout: function(props) {
4179
- return /* @__PURE__ */ jsxRuntime.jsx(AssistLayout, { ...props, config: configWithDefaults });
4187
+ return /* @__PURE__ */ jsx(AssistLayout, { ...props, config: configWithDefaults });
4180
4188
  }
4181
4189
  }
4182
4190
  },
@@ -4190,24 +4198,24 @@ const instructionForm = [
4190
4198
  }
4191
4199
  },
4192
4200
  plugins: [
4193
- sanity.definePlugin({
4201
+ definePlugin({
4194
4202
  name: `${packageName}/safe-value-input`,
4195
4203
  form: { components: { input: SafeValueInput } }
4196
4204
  })(),
4197
- sanity.definePlugin({
4205
+ definePlugin({
4198
4206
  name: `${packageName}/generate-caption`,
4199
4207
  form: {
4200
4208
  components: {
4201
4209
  input: (props) => {
4202
4210
  const { schemaType } = props;
4203
- return isImage(schemaType) ? /* @__PURE__ */ jsxRuntime.jsx(ImageContextProvider, { ...props }) : props.renderDefault(props);
4211
+ return isImage(schemaType) ? /* @__PURE__ */ jsx(ImageContextProvider, { ...props }) : props.renderDefault(props);
4204
4212
  }
4205
4213
  }
4206
4214
  }
4207
4215
  })()
4208
4216
  ]
4209
4217
  };
4210
- }), fetch = (client, query, params, options2) => rxjs.defer(
4218
+ }), fetch = (client, query, params, options2) => defer(
4211
4219
  () => (
4212
4220
  // getVersionedClient(options.apiVersion)
4213
4221
  client.observable.fetch(query, params, {
@@ -4215,7 +4223,7 @@ const instructionForm = [
4215
4223
  filterResponse: !0
4216
4224
  })
4217
4225
  )
4218
- ), listen = (client, query, params, options2) => rxjs.defer(
4226
+ ), listen = (client, query, params, options2) => defer(
4219
4227
  () => (
4220
4228
  // getVersionedClient(options.apiVersion)
4221
4229
  client.listen(query, params, {
@@ -4231,35 +4239,35 @@ function isWelcomeEvent(event) {
4231
4239
  }
4232
4240
  const listenQuery = (client, query, params = {}, options2 = {}) => {
4233
4241
  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(
4242
+ mergeMap((ev, i) => i === 0 && !isWelcomeEvent(ev) ? throwError(
4235
4243
  new Error(
4236
4244
  ev.type === "reconnect" ? "Could not establish EventSource connection" : `Received unexpected type of first event "${ev.type}"`
4237
4245
  )
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)),
4246
+ ) : of(ev)),
4247
+ share()
4248
+ ), [welcome$, mutationAndReconnect$] = partition(events$, isWelcomeEvent), isRelevantEvent = (event) => !options2.transitions || event.type !== "mutation" ? !0 : options2.transitions.includes(event.transition);
4249
+ return merge(
4250
+ welcome$.pipe(take(1)),
4243
4251
  mutationAndReconnect$.pipe(
4244
- operators.filter(isRelevantEvent),
4245
- rxjs.switchMap((event) => rxjs.merge(rxjs.of(event), rxjs.of(event).pipe(rxjs.delay(options2.throttleTime || 1e3))))
4252
+ filter(isRelevantEvent),
4253
+ switchMap((event) => merge(of(event), of(event).pipe(delay(options2.throttleTime || 1e3))))
4246
4254
  )
4247
- ).pipe(rxjsExhaustmapWithTrailing.exhaustMapToWithTrailing(fetchOnce$));
4255
+ ).pipe(exhaustMapToWithTrailing(fetchOnce$));
4248
4256
  }, DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2022-05-09" };
4249
4257
  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))
4258
+ const [loading, setLoading] = useState(!0), [error, setError] = useState(!1), [data, setData] = useState(null), subscription = useRef(null), client = useClient({ apiVersion: "v2022-05-09" });
4259
+ return useEffect(() => (subscription.current = listenQuery(client, query, params, options2).pipe(
4260
+ distinctUntilChanged(isEqual),
4261
+ catchError((err) => (console.error(err), setError(err), setLoading(!1), setData(null), err))
4254
4262
  ).subscribe((documents) => {
4255
- setData((current) => isEqual__default.default(current, documents) ? current : documents), setLoading(!1), setError(!1);
4263
+ setData((current) => isEqual(current, documents) ? current : documents), setLoading(!1), setError(!1);
4256
4264
  }), () => subscription.current ? subscription.current.unsubscribe() : void 0), [query, params, options2, client]), { loading, error, data };
4257
4265
  }
4258
4266
  const NO_DATA = [], defaultTitle = "Sync schema";
4259
4267
  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)", {
4268
+ const schema = useSchema(), client = useClient({ apiVersion: "2023-01-01" }), [saving, setSaving] = useState(!1), [syncTitle, setSyncTitle] = useState(defaultTitle), { data } = useListeningQuery("*[_type==$type] | order(_type)", {
4261
4269
  type: assistSerializedTypeName
4262
- }), types = react.useMemo(() => serializeSchema(schema), [schema]), storeTypes = react.useCallback(() => {
4270
+ }), types = useMemo(() => serializeSchema(schema), [schema]), storeTypes = useCallback(() => {
4263
4271
  setSaving(!0);
4264
4272
  let canSave = !0;
4265
4273
  async function store() {
@@ -4277,43 +4285,45 @@ function SchemaTypeTool() {
4277
4285
  canSave = !1, setSaving(!1), setSyncTitle(defaultTitle);
4278
4286
  };
4279
4287
  }, [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,
4288
+ return /* @__PURE__ */ jsx(Card, { padding: 4, overflow: "auto", style: { height: "calc(100vh - 81px)" }, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
4289
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
4290
+ Button,
4283
4291
  {
4284
- icon: saving ? /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { style: { marginTop: 5 } }) : icons.SyncIcon,
4292
+ icon: saving ? /* @__PURE__ */ jsx(Spinner, { style: { marginTop: 5 } }) : SyncIcon,
4285
4293
  text: syncTitle,
4286
4294
  disabled: saving,
4287
4295
  onClick: storeTypes
4288
4296
  }
4289
4297
  ) }),
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)) })
4298
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
4299
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
4300
+ /* @__PURE__ */ jsx(Label, { children: "Studio schema" }),
4301
+ /* @__PURE__ */ jsx("ul", { children: types.map((type) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(SchemaEntry, { schemaStub: type }) }, type.name)) })
4294
4302
  ] }),
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)) })
4303
+ /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
4304
+ /* @__PURE__ */ jsx(Label, { children: "Stored schema" }),
4305
+ /* @__PURE__ */ jsx("ul", { children: (data ?? NO_DATA).map((type) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(SchemaEntry, { schemaStub: type }) }, type.name)) })
4298
4306
  ] })
4299
4307
  ] })
4300
4308
  ] }) });
4301
4309
  }
4302
4310
  function SchemaEntry({ schemaStub }) {
4303
- const out = react.useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub]);
4304
- return /* @__PURE__ */ jsxRuntime.jsx("pre", { children: out });
4311
+ const out = useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub]);
4312
+ return /* @__PURE__ */ jsx("pre", { children: out });
4305
4313
  }
4306
4314
  function useUserInput() {
4307
4315
  const { getUserInput } = useRunInstruction();
4308
4316
  return getUserInput;
4309
4317
  }
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;
4318
+ export {
4319
+ SchemaTypeTool,
4320
+ assist,
4321
+ contextDocumentTypeName,
4322
+ defaultLanguageOutputs,
4323
+ defineAssistFieldAction,
4324
+ defineAssistFieldActionGroup,
4325
+ defineFieldActionDivider,
4326
+ isType,
4327
+ useUserInput
4328
+ };
4319
4329
  //# sourceMappingURL=index.js.map