@sanity/assist 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +292 -0
- package/dist/index.d.mts +257 -0
- package/dist/index.d.ts +257 -0
- package/dist/index.esm.js +231 -99
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +226 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +231 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
- package/src/assistDocument/AssistDocumentContext.tsx +14 -1
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +30 -3
- package/src/assistLayout/RunInstructionProvider.tsx +75 -23
- package/src/fieldActions/assistFieldActions.tsx +42 -2
- package/src/fieldActions/customFieldActions.tsx +304 -0
- package/src/fieldActions/useUserInput.ts +107 -0
- package/src/index.ts +17 -0
- package/src/plugin.tsx +6 -0
- package/src/presence/AssistDocumentPresence.tsx +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { pathToString,
|
|
3
|
-
import { useToast, useLayer, Dialog, Flex, Tooltip, Text,
|
|
2
|
+
import { pathToString, getVersionFromId, getPublishedId, isVersionId, useEditState, useCurrentUser, useClient, typed, isObjectSchemaType, stringToPath, isKeySegment, isArraySchemaType, useSchema, FormFieldHeaderText, PatchEvent, unset, getVersionId, getDraftId, useColorSchemeValue, useFormCallbacks, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, StatusButton, PresenceOverlay, VirtualizerScrollInstanceProvider, isDocumentSchemaType, useSyncState, set, useWorkspaceSchemaId, 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
4
|
import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, useId, forwardRef, createElement, useReducer } from "react";
|
|
5
5
|
import { useDocumentPane, usePaneRouter, DocumentInspectorHeader, DocumentPaneProvider } from "sanity/structure";
|
|
6
6
|
import { minutesToMilliseconds, isAfter, addSeconds, formatDistanceToNow } from "date-fns";
|
|
7
|
-
import { DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, PlayIcon, SparklesIcon, ArrowRightIcon, CheckmarkIcon, SearchIcon, SyncIcon, ErrorOutlineIcon, CheckmarkCircleIcon,
|
|
7
|
+
import { DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, PlayIcon, 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
8
|
import { extractWithPath } from "@sanity/mutator";
|
|
9
9
|
import { keyframes, styled } from "styled-components";
|
|
10
10
|
import { tap, mergeMap, share, take, filter, distinctUntilChanged, catchError } from "rxjs/operators";
|
|
11
11
|
import { get } from "lodash-es";
|
|
12
12
|
import isEqual from "react-fast-compare";
|
|
13
|
-
import { throwError, of, partition, merge, switchMap, delay
|
|
13
|
+
import { defer, throwError, of, partition, merge, switchMap, delay } from "rxjs";
|
|
14
14
|
import { exhaustMapToWithTrailing } from "rxjs-exhaustmap-with-trailing";
|
|
15
15
|
function hasOverflowScroll(el) {
|
|
16
16
|
const overflow = getComputedStyle(el).overflow;
|
|
@@ -424,10 +424,10 @@ function getFieldRefs(schemaType, parent, depth = 0) {
|
|
|
424
424
|
}
|
|
425
425
|
function getSyntheticFields(schemaType, parent, depth = 0) {
|
|
426
426
|
return depth >= maxDepth ? [] : schemaType.of.filter((itemType) => !isType(itemType, "block")).flatMap((itemType) => {
|
|
427
|
-
const segment = { _key: itemType.name }, title = itemType.title ?? itemType.name, path = [...parent.path, segment], fieldRef = {
|
|
427
|
+
const segment = { _key: itemType.name }, title = itemType.title ?? itemType.name, path = parent ? [...parent.path, segment] : [segment], fieldRef = {
|
|
428
428
|
key: patchableKey(pathToString(path)),
|
|
429
429
|
path,
|
|
430
|
-
title: [parent.title, title].join(" / "),
|
|
430
|
+
title: parent ? [parent.title, title].join(" / ") : title,
|
|
431
431
|
schemaType: itemType,
|
|
432
432
|
icon: getTypeIcon(itemType),
|
|
433
433
|
synthetic: !0
|
|
@@ -608,7 +608,6 @@ function serializeInlineOf(blockSchemaType, schema, options2) {
|
|
|
608
608
|
if (!(!childrenType || !isArraySchemaType(childrenType)))
|
|
609
609
|
return arrayOf(
|
|
610
610
|
{
|
|
611
|
-
...childrenType,
|
|
612
611
|
of: childrenType.of.filter((t) => !isType(t, "span"))
|
|
613
612
|
},
|
|
614
613
|
schema,
|
|
@@ -832,6 +831,8 @@ function useRunInstructionApi(apiClient) {
|
|
|
832
831
|
const NO_INPUT = {}, RunInstructionContext = createContext({
|
|
833
832
|
runInstruction: () => {
|
|
834
833
|
},
|
|
834
|
+
getUserInput: async () => {
|
|
835
|
+
},
|
|
835
836
|
instructionLoading: !1
|
|
836
837
|
});
|
|
837
838
|
function useRunInstruction() {
|
|
@@ -841,7 +842,18 @@ function isUserInputBlock(block) {
|
|
|
841
842
|
return block._type === userInputTypeName;
|
|
842
843
|
}
|
|
843
844
|
function RunInstructionProvider(props) {
|
|
844
|
-
const { config } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { runInstruction: runInstructionRequest, loading } = useRunInstructionApi(apiClient), id = useId(), [inputs, setInputs] = useState(NO_INPUT), [runRequest, setRunRequest] = useState(),
|
|
845
|
+
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 }) => {
|
|
846
|
+
const userInputBlocks = inputs2.map((input, i) => ({
|
|
847
|
+
_type: userInputTypeName,
|
|
848
|
+
_key: input.id ?? `${i}`,
|
|
849
|
+
message: input.title,
|
|
850
|
+
description: input.description
|
|
851
|
+
}));
|
|
852
|
+
if (userInputBlocks.length)
|
|
853
|
+
return setRunRequest({ dialogTitle: title, userInputBlocks }), new Promise((resolve) => {
|
|
854
|
+
setResolveUserInput(() => resolve);
|
|
855
|
+
});
|
|
856
|
+
}, []), runInstruction = useCallback(
|
|
845
857
|
(req) => {
|
|
846
858
|
if (loading)
|
|
847
859
|
return;
|
|
@@ -863,21 +875,35 @@ function RunInstructionProvider(props) {
|
|
|
863
875
|
},
|
|
864
876
|
[runInstructionRequest, loading]
|
|
865
877
|
), close = useCallback(() => {
|
|
866
|
-
setRunRequest(void 0), setInputs(NO_INPUT);
|
|
867
|
-
}, []), runWithInput = useCallback(() => {
|
|
868
|
-
if (runRequest)
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
878
|
+
setRunRequest(void 0), setInputs(NO_INPUT), resolveUserInput && resolveUserInput(void 0), setResolveUserInput(void 0);
|
|
879
|
+
}, [resolveUserInput]), runWithInput = useCallback(() => {
|
|
880
|
+
if (runRequest)
|
|
881
|
+
if ("instruction" in runRequest) {
|
|
882
|
+
const { instruction: instruction2, userTexts, ...request } = runRequest;
|
|
883
|
+
runInstructionRequest({
|
|
884
|
+
...request,
|
|
885
|
+
instructionKey: instruction2._key,
|
|
886
|
+
userTexts: Object.entries(inputs).map(([key, value]) => ({
|
|
887
|
+
blockKey: key,
|
|
888
|
+
userInput: value
|
|
889
|
+
}))
|
|
890
|
+
});
|
|
891
|
+
} else {
|
|
892
|
+
const userInputs = Object.values(inputs).map((input, i) => {
|
|
893
|
+
const userInputBlock = runRequest.userInputBlocks[i];
|
|
894
|
+
return {
|
|
895
|
+
input: {
|
|
896
|
+
id: userInputBlock._key,
|
|
897
|
+
title: userInputBlock.message ?? "",
|
|
898
|
+
description: userInputBlock.description
|
|
899
|
+
},
|
|
900
|
+
result: input
|
|
901
|
+
};
|
|
902
|
+
});
|
|
903
|
+
resolveUserInput?.(userInputs), setResolveUserInput(void 0);
|
|
904
|
+
}
|
|
879
905
|
close();
|
|
880
|
-
}, [close, runInstructionRequest, runRequest, inputs]), open = !!runRequest, runDisabled = useMemo(
|
|
906
|
+
}, [close, runInstructionRequest, runRequest, inputs, resolveUserInput]), open = !!runRequest, runDisabled = useMemo(
|
|
881
907
|
() => (runRequest?.userInputBlocks?.length ?? 0) > Object.entries(inputs).filter(([, value]) => !!value).length,
|
|
882
908
|
[runRequest?.userInputBlocks, inputs]
|
|
883
909
|
), runButton = /* @__PURE__ */ jsx(
|
|
@@ -891,7 +917,7 @@ function RunInstructionProvider(props) {
|
|
|
891
917
|
disabled: runDisabled
|
|
892
918
|
}
|
|
893
919
|
), contextValue = useMemo(
|
|
894
|
-
() => ({ runInstruction, instructionLoading: loading }),
|
|
920
|
+
() => ({ runInstruction, getUserInput, instructionLoading: loading }),
|
|
895
921
|
[runInstruction, loading]
|
|
896
922
|
);
|
|
897
923
|
return /* @__PURE__ */ jsxs(RunInstructionContext.Provider, { value: contextValue, children: [
|
|
@@ -902,7 +928,7 @@ function RunInstructionProvider(props) {
|
|
|
902
928
|
open,
|
|
903
929
|
onClose: close,
|
|
904
930
|
width: 1,
|
|
905
|
-
header: getInstructionTitle(runRequest?.instruction),
|
|
931
|
+
header: "dialogTitle" in runRequest ? runRequest.dialogTitle : getInstructionTitle(runRequest?.instruction),
|
|
906
932
|
footer: /* @__PURE__ */ jsx(Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsx(
|
|
907
933
|
Tooltip,
|
|
908
934
|
{
|
|
@@ -1000,7 +1026,7 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1000
1026
|
} = 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({
|
|
1001
1027
|
documentId: assistableDocumentId,
|
|
1002
1028
|
schemaType: documentSchemaType
|
|
1003
|
-
});
|
|
1029
|
+
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
1004
1030
|
return useMemo(() => {
|
|
1005
1031
|
const base = {
|
|
1006
1032
|
assistableDocumentId,
|
|
@@ -1011,7 +1037,10 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1011
1037
|
closeInspector,
|
|
1012
1038
|
inspector,
|
|
1013
1039
|
documentOnChange,
|
|
1014
|
-
selectedPath
|
|
1040
|
+
selectedPath,
|
|
1041
|
+
syntheticTasks,
|
|
1042
|
+
addSyntheticTask,
|
|
1043
|
+
removeSyntheticTask
|
|
1015
1044
|
};
|
|
1016
1045
|
return assistDocument ? {
|
|
1017
1046
|
...base,
|
|
@@ -1028,9 +1057,26 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1028
1057
|
closeInspector,
|
|
1029
1058
|
inspector,
|
|
1030
1059
|
documentOnChange,
|
|
1031
|
-
selectedPath
|
|
1060
|
+
selectedPath,
|
|
1061
|
+
syntheticTasks,
|
|
1062
|
+
addSyntheticTask,
|
|
1063
|
+
removeSyntheticTask
|
|
1032
1064
|
]);
|
|
1033
1065
|
}
|
|
1066
|
+
function useSyntheticTasks(assistableDocumentId) {
|
|
1067
|
+
const [syntheticTasks, setSyntheticTasks] = useState(() => []), addSyntheticTask = useCallback((task) => {
|
|
1068
|
+
setSyntheticTasks((current) => [...current, task]);
|
|
1069
|
+
}, []), removeSyntheticTask = useCallback((task) => {
|
|
1070
|
+
setSyntheticTasks((current) => current.filter((t) => task._key !== t._key));
|
|
1071
|
+
}, []);
|
|
1072
|
+
return useEffect(() => {
|
|
1073
|
+
setSyntheticTasks([]);
|
|
1074
|
+
}, [assistableDocumentId]), {
|
|
1075
|
+
syntheticTasks,
|
|
1076
|
+
addSyntheticTask,
|
|
1077
|
+
removeSyntheticTask
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1034
1080
|
function AssistDocumentContextProvider(props) {
|
|
1035
1081
|
const { documentId, documentType } = props, value = useAssistDocumentContextValue(documentId, documentType);
|
|
1036
1082
|
return /* @__PURE__ */ jsx(AssistDocumentContext.Provider, { value, children: props.children });
|
|
@@ -1125,49 +1171,14 @@ const fadeIn = keyframes`
|
|
|
1125
1171
|
}, ref) {
|
|
1126
1172
|
return /* @__PURE__ */ jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
|
|
1127
1173
|
}), purple = {
|
|
1128
|
-
50: {
|
|
1129
|
-
title: "Purple 50",
|
|
1130
|
-
hex: "#f8f5ff"
|
|
1131
|
-
},
|
|
1132
|
-
100: {
|
|
1133
|
-
title: "Purple 100",
|
|
1134
|
-
hex: "#f1ebff"
|
|
1135
|
-
},
|
|
1136
|
-
200: {
|
|
1137
|
-
title: "Purple 200",
|
|
1138
|
-
hex: "#ece1fe"
|
|
1139
|
-
},
|
|
1140
|
-
300: {
|
|
1141
|
-
title: "Purple 300",
|
|
1142
|
-
hex: "#ccb1fc"
|
|
1143
|
-
},
|
|
1144
1174
|
400: {
|
|
1145
|
-
title: "Purple 400",
|
|
1146
1175
|
hex: "#b087f7"
|
|
1147
1176
|
},
|
|
1148
1177
|
500: {
|
|
1149
|
-
title: "Purple 500",
|
|
1150
1178
|
hex: "#8f57ef"
|
|
1151
1179
|
},
|
|
1152
1180
|
600: {
|
|
1153
|
-
title: "Purple 600",
|
|
1154
1181
|
hex: "#721fe5"
|
|
1155
|
-
},
|
|
1156
|
-
700: {
|
|
1157
|
-
title: "Purple 700",
|
|
1158
|
-
hex: "#4c1a9e"
|
|
1159
|
-
},
|
|
1160
|
-
800: {
|
|
1161
|
-
title: "Purple 800",
|
|
1162
|
-
hex: "#2f1862"
|
|
1163
|
-
},
|
|
1164
|
-
900: {
|
|
1165
|
-
title: "Purple 900",
|
|
1166
|
-
hex: "#23173f"
|
|
1167
|
-
},
|
|
1168
|
-
950: {
|
|
1169
|
-
title: "Purple 950",
|
|
1170
|
-
hex: "#181128"
|
|
1171
1182
|
}
|
|
1172
1183
|
}, Root = styled.span`
|
|
1173
1184
|
display: block;
|
|
@@ -2808,6 +2819,129 @@ function PrivateIcon() {
|
|
|
2808
2819
|
}
|
|
2809
2820
|
);
|
|
2810
2821
|
}
|
|
2822
|
+
function getRandomValues(typedArray) {
|
|
2823
|
+
const crypto = typeof window < "u" && "crypto" in window ? window.crypto : globalThis.crypto;
|
|
2824
|
+
if (!crypto || !crypto.getRandomValues)
|
|
2825
|
+
throw new Error("WebCrypto not available in this environment");
|
|
2826
|
+
return crypto.getRandomValues(typedArray);
|
|
2827
|
+
}
|
|
2828
|
+
function whatwgRNG(length = 16) {
|
|
2829
|
+
const rnds8 = new Uint8Array(length);
|
|
2830
|
+
return getRandomValues(rnds8), rnds8;
|
|
2831
|
+
}
|
|
2832
|
+
const getByteHexTable = /* @__PURE__ */ (() => {
|
|
2833
|
+
let table;
|
|
2834
|
+
return () => {
|
|
2835
|
+
if (table)
|
|
2836
|
+
return table;
|
|
2837
|
+
table = [];
|
|
2838
|
+
for (let i = 0; i < 256; ++i)
|
|
2839
|
+
table[i] = (i + 256).toString(16).substring(1);
|
|
2840
|
+
return table;
|
|
2841
|
+
};
|
|
2842
|
+
})();
|
|
2843
|
+
function randomKey(length) {
|
|
2844
|
+
const table = getByteHexTable();
|
|
2845
|
+
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
2846
|
+
}
|
|
2847
|
+
function defineAssistFieldAction(action) {
|
|
2848
|
+
return {
|
|
2849
|
+
...action,
|
|
2850
|
+
type: "action"
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2853
|
+
function defineFieldActionDivider() {
|
|
2854
|
+
return {
|
|
2855
|
+
type: "divider"
|
|
2856
|
+
};
|
|
2857
|
+
}
|
|
2858
|
+
function defineAssistFieldActionGroup(group) {
|
|
2859
|
+
return {
|
|
2860
|
+
...group,
|
|
2861
|
+
type: "group"
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
2864
|
+
function useCustomFieldActions(props) {
|
|
2865
|
+
const {
|
|
2866
|
+
config: { fieldActions }
|
|
2867
|
+
} = useAiAssistanceConfig(), { addSyntheticTask, removeSyntheticTask } = useAssistDocumentContext(), schemaId = useWorkspaceSchemaId(), { push: pushToast } = useToast(), configActions = fieldActions?.useFieldActions?.({
|
|
2868
|
+
...props,
|
|
2869
|
+
schemaId,
|
|
2870
|
+
path: props.path
|
|
2871
|
+
});
|
|
2872
|
+
return useMemo(() => {
|
|
2873
|
+
const title = fieldActions?.title, customActions = configActions?.map((node) => createSafeNode({
|
|
2874
|
+
node,
|
|
2875
|
+
pushToast,
|
|
2876
|
+
addSyntheticTask,
|
|
2877
|
+
removeSyntheticTask
|
|
2878
|
+
})), onlyGroups = customActions?.length && customActions?.every((node) => node.type === "group");
|
|
2879
|
+
return (customActions?.length ? onlyGroups ? customActions : [
|
|
2880
|
+
{
|
|
2881
|
+
type: "group",
|
|
2882
|
+
title: title || "Custom actions",
|
|
2883
|
+
children: customActions,
|
|
2884
|
+
expanded: !0
|
|
2885
|
+
}
|
|
2886
|
+
] : []) ?? [];
|
|
2887
|
+
}, [configActions, fieldActions, pushToast]);
|
|
2888
|
+
}
|
|
2889
|
+
function createSafeNode(args) {
|
|
2890
|
+
const { node } = args;
|
|
2891
|
+
switch (node.type) {
|
|
2892
|
+
case "action":
|
|
2893
|
+
return createSafeAction({ ...args, action: node });
|
|
2894
|
+
case "group":
|
|
2895
|
+
return {
|
|
2896
|
+
...node,
|
|
2897
|
+
renderAsButton: !1,
|
|
2898
|
+
expanded: !0,
|
|
2899
|
+
children: node.children?.map((child) => createSafeNode({ ...args, node: child }))
|
|
2900
|
+
};
|
|
2901
|
+
case "divider":
|
|
2902
|
+
default:
|
|
2903
|
+
return node;
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
function createSafeAction(args) {
|
|
2907
|
+
const { action, pushToast, addSyntheticTask, removeSyntheticTask } = args;
|
|
2908
|
+
return {
|
|
2909
|
+
...action,
|
|
2910
|
+
onAction: () => {
|
|
2911
|
+
async function runAction() {
|
|
2912
|
+
const task = {
|
|
2913
|
+
_type: instructionTaskTypeName,
|
|
2914
|
+
_key: randomKey(12),
|
|
2915
|
+
started: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2916
|
+
presence: [
|
|
2917
|
+
{
|
|
2918
|
+
_type: fieldPresenceTypeName,
|
|
2919
|
+
_key: randomKey(12),
|
|
2920
|
+
path: documentRootKey,
|
|
2921
|
+
started: (/* @__PURE__ */ new Date()).toISOString()
|
|
2922
|
+
}
|
|
2923
|
+
]
|
|
2924
|
+
};
|
|
2925
|
+
try {
|
|
2926
|
+
addSyntheticTask(task);
|
|
2927
|
+
const actionResult = action.onAction?.();
|
|
2928
|
+
actionResult instanceof Promise && await actionResult;
|
|
2929
|
+
} catch (err) {
|
|
2930
|
+
console.error("Failed to execute action", action, err), pushToast({
|
|
2931
|
+
title: "Failed to execute action",
|
|
2932
|
+
description: err?.message,
|
|
2933
|
+
status: "error"
|
|
2934
|
+
});
|
|
2935
|
+
} finally {
|
|
2936
|
+
removeSyntheticTask(task);
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
runAction();
|
|
2940
|
+
},
|
|
2941
|
+
renderAsButton: !1,
|
|
2942
|
+
selected: !1
|
|
2943
|
+
};
|
|
2944
|
+
}
|
|
2811
2945
|
const assistFieldActions = {
|
|
2812
2946
|
name: "sanity-assist-actions",
|
|
2813
2947
|
useAction(props) {
|
|
@@ -2822,7 +2956,7 @@ const assistFieldActions = {
|
|
|
2822
2956
|
documentSchemaType,
|
|
2823
2957
|
selectedPath,
|
|
2824
2958
|
assistableDocumentId
|
|
2825
|
-
} = useAssistDocumentContext(), { value: docValue, formState } = useDocumentPane(), formStateRef = useRef(formState);
|
|
2959
|
+
} = useAssistDocumentContext(), { value: docValue, formState } = useDocumentPane(), docValueRef = useRef(docValue), formStateRef = useRef(formState);
|
|
2826
2960
|
formStateRef.current = formState;
|
|
2827
2961
|
const currentUser = useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
|
|
2828
2962
|
documentOnChange,
|
|
@@ -2884,7 +3018,6 @@ const assistFieldActions = {
|
|
|
2884
3018
|
isPrivate: !!(instruction2.userId && instruction2.userId === currentUser?.id),
|
|
2885
3019
|
onInstructionAction,
|
|
2886
3020
|
hidden: isHidden,
|
|
2887
|
-
documentIsNew: !!documentIsNew,
|
|
2888
3021
|
assistSupported
|
|
2889
3022
|
})
|
|
2890
3023
|
) || [],
|
|
@@ -2902,7 +3035,23 @@ const assistFieldActions = {
|
|
|
2902
3035
|
imageCaptionAction,
|
|
2903
3036
|
translateAction,
|
|
2904
3037
|
imageGenAction
|
|
2905
|
-
]),
|
|
3038
|
+
]), getDocumentValue = useCallback(() => docValueRef.current, []), getConditionalPaths = useCallback(() => (formStateRef.current ? getConditionalMembers(formStateRef.current) : []).flatMap(
|
|
3039
|
+
(cm) => {
|
|
3040
|
+
const path = stringToPath(cm.path);
|
|
3041
|
+
return path.some((s) => typeof s == "number") ? [] : {
|
|
3042
|
+
...cm,
|
|
3043
|
+
path
|
|
3044
|
+
};
|
|
3045
|
+
}
|
|
3046
|
+
), []), customActions = useCustomFieldActions({
|
|
3047
|
+
actionType: props.path.length ? "field" : "document",
|
|
3048
|
+
documentIdForAction: assistableDocumentId,
|
|
3049
|
+
schemaType,
|
|
3050
|
+
documentSchemaType,
|
|
3051
|
+
path: props.path,
|
|
3052
|
+
getDocumentValue,
|
|
3053
|
+
getConditionalPaths
|
|
3054
|
+
}), manageInstructionsItem = useMemo(
|
|
2906
3055
|
() => ({
|
|
2907
3056
|
type: "action",
|
|
2908
3057
|
icon: ControlsIcon,
|
|
@@ -2919,6 +3068,7 @@ const assistFieldActions = {
|
|
|
2919
3068
|
children: [
|
|
2920
3069
|
runInstructionsGroup,
|
|
2921
3070
|
translateAction,
|
|
3071
|
+
...customActions,
|
|
2922
3072
|
assistSupported && manageInstructionsItem
|
|
2923
3073
|
].filter((c) => !!c).filter((c) => c.type === "group" ? c.children.length : !0),
|
|
2924
3074
|
expanded: !1,
|
|
@@ -2932,7 +3082,8 @@ const assistFieldActions = {
|
|
|
2932
3082
|
assistSupported,
|
|
2933
3083
|
imageCaptionAction,
|
|
2934
3084
|
translateAction,
|
|
2935
|
-
imageGenAction
|
|
3085
|
+
imageGenAction,
|
|
3086
|
+
customActions
|
|
2936
3087
|
]
|
|
2937
3088
|
), emptyAction = useMemo(
|
|
2938
3089
|
() => ({
|
|
@@ -2946,7 +3097,7 @@ const assistFieldActions = {
|
|
|
2946
3097
|
}),
|
|
2947
3098
|
[assistSupported, manageInstructions, isSelected]
|
|
2948
3099
|
);
|
|
2949
|
-
return
|
|
3100
|
+
return !instructions?.length && !imageCaptionAction && !translateAction && !imageGenAction && !customActions.length ? emptyAction : group;
|
|
2950
3101
|
}
|
|
2951
3102
|
};
|
|
2952
3103
|
function instructionItem(props) {
|
|
@@ -2967,21 +3118,19 @@ function createAssistDocumentPresence(documentId) {
|
|
|
2967
3118
|
};
|
|
2968
3119
|
}
|
|
2969
3120
|
function AssistDocumentPresence() {
|
|
2970
|
-
const { assistDocument } = useAssistDocumentContext(), anyPresence = useMemo(() => {
|
|
2971
|
-
const anyPresence2 = assistDocument?.tasks
|
|
3121
|
+
const { assistDocument, syntheticTasks } = useAssistDocumentContext(), anyPresence = useMemo(() => {
|
|
3122
|
+
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);
|
|
2972
3123
|
if (anyPresence2)
|
|
2973
3124
|
return aiPresence(anyPresence2, []);
|
|
2974
3125
|
const anyRun = assistDocument?.tasks?.filter((run) => !run.ended && !run.reason)?.find((f) => f.started && (/* @__PURE__ */ new Date()).getTime() - new Date(f.started).getTime() < 3e4);
|
|
2975
3126
|
return anyRun ? aiPresence(
|
|
2976
3127
|
{
|
|
2977
3128
|
started: anyRun.started,
|
|
2978
|
-
|
|
2979
|
-
_key: anyRun._key,
|
|
2980
|
-
_type: fieldPresenceTypeName
|
|
3129
|
+
_key: anyRun._key
|
|
2981
3130
|
},
|
|
2982
3131
|
[]
|
|
2983
3132
|
) : void 0;
|
|
2984
|
-
}, [assistDocument?.tasks]);
|
|
3133
|
+
}, [assistDocument?.tasks, syntheticTasks]);
|
|
2985
3134
|
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 }) }) }) });
|
|
2986
3135
|
}
|
|
2987
3136
|
function BackToInstructionListLink() {
|
|
@@ -3375,31 +3524,6 @@ function Selectable({
|
|
|
3375
3524
|
/* @__PURE__ */ jsx(Card, { marginTop: 1, onClick: handleChange, children: /* @__PURE__ */ jsx(Text, { style: { cursor: "default" }, size: 1, children: title }) })
|
|
3376
3525
|
] });
|
|
3377
3526
|
}
|
|
3378
|
-
function getRandomValues(typedArray) {
|
|
3379
|
-
const crypto = typeof window < "u" && "crypto" in window ? window.crypto : globalThis.crypto;
|
|
3380
|
-
if (!crypto || !crypto.getRandomValues)
|
|
3381
|
-
throw new Error("WebCrypto not available in this environment");
|
|
3382
|
-
return crypto.getRandomValues(typedArray);
|
|
3383
|
-
}
|
|
3384
|
-
function whatwgRNG(length = 16) {
|
|
3385
|
-
const rnds8 = new Uint8Array(length);
|
|
3386
|
-
return getRandomValues(rnds8), rnds8;
|
|
3387
|
-
}
|
|
3388
|
-
const getByteHexTable = /* @__PURE__ */ (() => {
|
|
3389
|
-
let table;
|
|
3390
|
-
return () => {
|
|
3391
|
-
if (table)
|
|
3392
|
-
return table;
|
|
3393
|
-
table = [];
|
|
3394
|
-
for (let i = 0; i < 256; ++i)
|
|
3395
|
-
table[i] = (i + 256).toString(16).substring(1);
|
|
3396
|
-
return table;
|
|
3397
|
-
};
|
|
3398
|
-
})();
|
|
3399
|
-
function randomKey(length) {
|
|
3400
|
-
const table = getByteHexTable();
|
|
3401
|
-
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
3402
|
-
}
|
|
3403
3527
|
const PteMods = styled(Box)`
|
|
3404
3528
|
& [data-testid='pt-editor__toolbar-card'] > div > div:last-child {
|
|
3405
3529
|
display: none;
|
|
@@ -4100,10 +4224,18 @@ function SchemaEntry({ schemaStub }) {
|
|
|
4100
4224
|
const out = useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub]);
|
|
4101
4225
|
return /* @__PURE__ */ jsx("pre", { children: out });
|
|
4102
4226
|
}
|
|
4227
|
+
function useUserInput() {
|
|
4228
|
+
const { getUserInput } = useRunInstruction();
|
|
4229
|
+
return getUserInput;
|
|
4230
|
+
}
|
|
4103
4231
|
export {
|
|
4104
4232
|
SchemaTypeTool,
|
|
4105
4233
|
assist,
|
|
4106
4234
|
contextDocumentTypeName,
|
|
4107
|
-
defaultLanguageOutputs
|
|
4235
|
+
defaultLanguageOutputs,
|
|
4236
|
+
defineAssistFieldAction,
|
|
4237
|
+
defineAssistFieldActionGroup,
|
|
4238
|
+
defineFieldActionDivider,
|
|
4239
|
+
useUserInput
|
|
4108
4240
|
};
|
|
4109
4241
|
//# sourceMappingURL=index.mjs.map
|