@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.js
CHANGED
|
@@ -417,10 +417,10 @@ function getFieldRefs(schemaType, parent, depth = 0) {
|
|
|
417
417
|
}
|
|
418
418
|
function getSyntheticFields(schemaType, parent, depth = 0) {
|
|
419
419
|
return depth >= maxDepth ? [] : schemaType.of.filter((itemType) => !isType(itemType, "block")).flatMap((itemType) => {
|
|
420
|
-
const segment = { _key: itemType.name }, title = itemType.title ?? itemType.name, path = [...parent.path, segment], fieldRef = {
|
|
420
|
+
const segment = { _key: itemType.name }, title = itemType.title ?? itemType.name, path = parent ? [...parent.path, segment] : [segment], fieldRef = {
|
|
421
421
|
key: patchableKey(sanity.pathToString(path)),
|
|
422
422
|
path,
|
|
423
|
-
title: [parent.title, title].join(" / "),
|
|
423
|
+
title: parent ? [parent.title, title].join(" / ") : title,
|
|
424
424
|
schemaType: itemType,
|
|
425
425
|
icon: getTypeIcon(itemType),
|
|
426
426
|
synthetic: !0
|
|
@@ -601,7 +601,6 @@ function serializeInlineOf(blockSchemaType, schema, options2) {
|
|
|
601
601
|
if (!(!childrenType || !sanity.isArraySchemaType(childrenType)))
|
|
602
602
|
return arrayOf(
|
|
603
603
|
{
|
|
604
|
-
...childrenType,
|
|
605
604
|
of: childrenType.of.filter((t) => !isType(t, "span"))
|
|
606
605
|
},
|
|
607
606
|
schema,
|
|
@@ -825,6 +824,8 @@ function useRunInstructionApi(apiClient) {
|
|
|
825
824
|
const NO_INPUT = {}, RunInstructionContext = react.createContext({
|
|
826
825
|
runInstruction: () => {
|
|
827
826
|
},
|
|
827
|
+
getUserInput: async () => {
|
|
828
|
+
},
|
|
828
829
|
instructionLoading: !1
|
|
829
830
|
});
|
|
830
831
|
function useRunInstruction() {
|
|
@@ -834,7 +835,18 @@ function isUserInputBlock(block) {
|
|
|
834
835
|
return block._type === userInputTypeName;
|
|
835
836
|
}
|
|
836
837
|
function RunInstructionProvider(props) {
|
|
837
|
-
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(),
|
|
838
|
+
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 }) => {
|
|
839
|
+
const userInputBlocks = inputs2.map((input, i) => ({
|
|
840
|
+
_type: userInputTypeName,
|
|
841
|
+
_key: input.id ?? `${i}`,
|
|
842
|
+
message: input.title,
|
|
843
|
+
description: input.description
|
|
844
|
+
}));
|
|
845
|
+
if (userInputBlocks.length)
|
|
846
|
+
return setRunRequest({ dialogTitle: title, userInputBlocks }), new Promise((resolve) => {
|
|
847
|
+
setResolveUserInput(() => resolve);
|
|
848
|
+
});
|
|
849
|
+
}, []), runInstruction = react.useCallback(
|
|
838
850
|
(req) => {
|
|
839
851
|
if (loading)
|
|
840
852
|
return;
|
|
@@ -856,21 +868,35 @@ function RunInstructionProvider(props) {
|
|
|
856
868
|
},
|
|
857
869
|
[runInstructionRequest, loading]
|
|
858
870
|
), close = react.useCallback(() => {
|
|
859
|
-
setRunRequest(void 0), setInputs(NO_INPUT);
|
|
860
|
-
}, []), runWithInput = react.useCallback(() => {
|
|
861
|
-
if (runRequest)
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
871
|
+
setRunRequest(void 0), setInputs(NO_INPUT), resolveUserInput && resolveUserInput(void 0), setResolveUserInput(void 0);
|
|
872
|
+
}, [resolveUserInput]), runWithInput = react.useCallback(() => {
|
|
873
|
+
if (runRequest)
|
|
874
|
+
if ("instruction" in runRequest) {
|
|
875
|
+
const { instruction: instruction2, userTexts, ...request } = runRequest;
|
|
876
|
+
runInstructionRequest({
|
|
877
|
+
...request,
|
|
878
|
+
instructionKey: instruction2._key,
|
|
879
|
+
userTexts: Object.entries(inputs).map(([key, value]) => ({
|
|
880
|
+
blockKey: key,
|
|
881
|
+
userInput: value
|
|
882
|
+
}))
|
|
883
|
+
});
|
|
884
|
+
} else {
|
|
885
|
+
const userInputs = Object.values(inputs).map((input, i) => {
|
|
886
|
+
const userInputBlock = runRequest.userInputBlocks[i];
|
|
887
|
+
return {
|
|
888
|
+
input: {
|
|
889
|
+
id: userInputBlock._key,
|
|
890
|
+
title: userInputBlock.message ?? "",
|
|
891
|
+
description: userInputBlock.description
|
|
892
|
+
},
|
|
893
|
+
result: input
|
|
894
|
+
};
|
|
895
|
+
});
|
|
896
|
+
resolveUserInput?.(userInputs), setResolveUserInput(void 0);
|
|
897
|
+
}
|
|
872
898
|
close();
|
|
873
|
-
}, [close, runInstructionRequest, runRequest, inputs]), open = !!runRequest, runDisabled = react.useMemo(
|
|
899
|
+
}, [close, runInstructionRequest, runRequest, inputs, resolveUserInput]), open = !!runRequest, runDisabled = react.useMemo(
|
|
874
900
|
() => (runRequest?.userInputBlocks?.length ?? 0) > Object.entries(inputs).filter(([, value]) => !!value).length,
|
|
875
901
|
[runRequest?.userInputBlocks, inputs]
|
|
876
902
|
), runButton = /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -884,7 +910,7 @@ function RunInstructionProvider(props) {
|
|
|
884
910
|
disabled: runDisabled
|
|
885
911
|
}
|
|
886
912
|
), contextValue = react.useMemo(
|
|
887
|
-
() => ({ runInstruction, instructionLoading: loading }),
|
|
913
|
+
() => ({ runInstruction, getUserInput, instructionLoading: loading }),
|
|
888
914
|
[runInstruction, loading]
|
|
889
915
|
);
|
|
890
916
|
return /* @__PURE__ */ jsxRuntime.jsxs(RunInstructionContext.Provider, { value: contextValue, children: [
|
|
@@ -895,7 +921,7 @@ function RunInstructionProvider(props) {
|
|
|
895
921
|
open,
|
|
896
922
|
onClose: close,
|
|
897
923
|
width: 1,
|
|
898
|
-
header: getInstructionTitle(runRequest?.instruction),
|
|
924
|
+
header: "dialogTitle" in runRequest ? runRequest.dialogTitle : getInstructionTitle(runRequest?.instruction),
|
|
899
925
|
footer: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { justify: "space-between", padding: 2, flex: 1, children: runDisabled ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
900
926
|
ui.Tooltip,
|
|
901
927
|
{
|
|
@@ -993,7 +1019,7 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
993
1019
|
} = 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({
|
|
994
1020
|
documentId: assistableDocumentId,
|
|
995
1021
|
schemaType: documentSchemaType
|
|
996
|
-
});
|
|
1022
|
+
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
997
1023
|
return react.useMemo(() => {
|
|
998
1024
|
const base = {
|
|
999
1025
|
assistableDocumentId,
|
|
@@ -1004,7 +1030,10 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1004
1030
|
closeInspector,
|
|
1005
1031
|
inspector,
|
|
1006
1032
|
documentOnChange,
|
|
1007
|
-
selectedPath
|
|
1033
|
+
selectedPath,
|
|
1034
|
+
syntheticTasks,
|
|
1035
|
+
addSyntheticTask,
|
|
1036
|
+
removeSyntheticTask
|
|
1008
1037
|
};
|
|
1009
1038
|
return assistDocument ? {
|
|
1010
1039
|
...base,
|
|
@@ -1021,9 +1050,26 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
1021
1050
|
closeInspector,
|
|
1022
1051
|
inspector,
|
|
1023
1052
|
documentOnChange,
|
|
1024
|
-
selectedPath
|
|
1053
|
+
selectedPath,
|
|
1054
|
+
syntheticTasks,
|
|
1055
|
+
addSyntheticTask,
|
|
1056
|
+
removeSyntheticTask
|
|
1025
1057
|
]);
|
|
1026
1058
|
}
|
|
1059
|
+
function useSyntheticTasks(assistableDocumentId) {
|
|
1060
|
+
const [syntheticTasks, setSyntheticTasks] = react.useState(() => []), addSyntheticTask = react.useCallback((task) => {
|
|
1061
|
+
setSyntheticTasks((current) => [...current, task]);
|
|
1062
|
+
}, []), removeSyntheticTask = react.useCallback((task) => {
|
|
1063
|
+
setSyntheticTasks((current) => current.filter((t) => task._key !== t._key));
|
|
1064
|
+
}, []);
|
|
1065
|
+
return react.useEffect(() => {
|
|
1066
|
+
setSyntheticTasks([]);
|
|
1067
|
+
}, [assistableDocumentId]), {
|
|
1068
|
+
syntheticTasks,
|
|
1069
|
+
addSyntheticTask,
|
|
1070
|
+
removeSyntheticTask
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1027
1073
|
function AssistDocumentContextProvider(props) {
|
|
1028
1074
|
const { documentId, documentType } = props, value = useAssistDocumentContextValue(documentId, documentType);
|
|
1029
1075
|
return /* @__PURE__ */ jsxRuntime.jsx(AssistDocumentContext.Provider, { value, children: props.children });
|
|
@@ -1118,49 +1164,14 @@ const fadeIn = styledComponents.keyframes`
|
|
|
1118
1164
|
}, ref) {
|
|
1119
1165
|
return /* @__PURE__ */ jsxRuntime.jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
|
|
1120
1166
|
}), purple = {
|
|
1121
|
-
50: {
|
|
1122
|
-
title: "Purple 50",
|
|
1123
|
-
hex: "#f8f5ff"
|
|
1124
|
-
},
|
|
1125
|
-
100: {
|
|
1126
|
-
title: "Purple 100",
|
|
1127
|
-
hex: "#f1ebff"
|
|
1128
|
-
},
|
|
1129
|
-
200: {
|
|
1130
|
-
title: "Purple 200",
|
|
1131
|
-
hex: "#ece1fe"
|
|
1132
|
-
},
|
|
1133
|
-
300: {
|
|
1134
|
-
title: "Purple 300",
|
|
1135
|
-
hex: "#ccb1fc"
|
|
1136
|
-
},
|
|
1137
1167
|
400: {
|
|
1138
|
-
title: "Purple 400",
|
|
1139
1168
|
hex: "#b087f7"
|
|
1140
1169
|
},
|
|
1141
1170
|
500: {
|
|
1142
|
-
title: "Purple 500",
|
|
1143
1171
|
hex: "#8f57ef"
|
|
1144
1172
|
},
|
|
1145
1173
|
600: {
|
|
1146
|
-
title: "Purple 600",
|
|
1147
1174
|
hex: "#721fe5"
|
|
1148
|
-
},
|
|
1149
|
-
700: {
|
|
1150
|
-
title: "Purple 700",
|
|
1151
|
-
hex: "#4c1a9e"
|
|
1152
|
-
},
|
|
1153
|
-
800: {
|
|
1154
|
-
title: "Purple 800",
|
|
1155
|
-
hex: "#2f1862"
|
|
1156
|
-
},
|
|
1157
|
-
900: {
|
|
1158
|
-
title: "Purple 900",
|
|
1159
|
-
hex: "#23173f"
|
|
1160
|
-
},
|
|
1161
|
-
950: {
|
|
1162
|
-
title: "Purple 950",
|
|
1163
|
-
hex: "#181128"
|
|
1164
1175
|
}
|
|
1165
1176
|
}, Root = styledComponents.styled.span`
|
|
1166
1177
|
display: block;
|
|
@@ -2801,6 +2812,129 @@ function PrivateIcon() {
|
|
|
2801
2812
|
}
|
|
2802
2813
|
);
|
|
2803
2814
|
}
|
|
2815
|
+
function getRandomValues(typedArray) {
|
|
2816
|
+
const crypto = typeof window < "u" && "crypto" in window ? window.crypto : globalThis.crypto;
|
|
2817
|
+
if (!crypto || !crypto.getRandomValues)
|
|
2818
|
+
throw new Error("WebCrypto not available in this environment");
|
|
2819
|
+
return crypto.getRandomValues(typedArray);
|
|
2820
|
+
}
|
|
2821
|
+
function whatwgRNG(length = 16) {
|
|
2822
|
+
const rnds8 = new Uint8Array(length);
|
|
2823
|
+
return getRandomValues(rnds8), rnds8;
|
|
2824
|
+
}
|
|
2825
|
+
const getByteHexTable = /* @__PURE__ */ (() => {
|
|
2826
|
+
let table;
|
|
2827
|
+
return () => {
|
|
2828
|
+
if (table)
|
|
2829
|
+
return table;
|
|
2830
|
+
table = [];
|
|
2831
|
+
for (let i = 0; i < 256; ++i)
|
|
2832
|
+
table[i] = (i + 256).toString(16).substring(1);
|
|
2833
|
+
return table;
|
|
2834
|
+
};
|
|
2835
|
+
})();
|
|
2836
|
+
function randomKey(length) {
|
|
2837
|
+
const table = getByteHexTable();
|
|
2838
|
+
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
2839
|
+
}
|
|
2840
|
+
function defineAssistFieldAction(action) {
|
|
2841
|
+
return {
|
|
2842
|
+
...action,
|
|
2843
|
+
type: "action"
|
|
2844
|
+
};
|
|
2845
|
+
}
|
|
2846
|
+
function defineFieldActionDivider() {
|
|
2847
|
+
return {
|
|
2848
|
+
type: "divider"
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2851
|
+
function defineAssistFieldActionGroup(group) {
|
|
2852
|
+
return {
|
|
2853
|
+
...group,
|
|
2854
|
+
type: "group"
|
|
2855
|
+
};
|
|
2856
|
+
}
|
|
2857
|
+
function useCustomFieldActions(props) {
|
|
2858
|
+
const {
|
|
2859
|
+
config: { fieldActions }
|
|
2860
|
+
} = useAiAssistanceConfig(), { addSyntheticTask, removeSyntheticTask } = useAssistDocumentContext(), schemaId = sanity.useWorkspaceSchemaId(), { push: pushToast } = ui.useToast(), configActions = fieldActions?.useFieldActions?.({
|
|
2861
|
+
...props,
|
|
2862
|
+
schemaId,
|
|
2863
|
+
path: props.path
|
|
2864
|
+
});
|
|
2865
|
+
return react.useMemo(() => {
|
|
2866
|
+
const title = fieldActions?.title, customActions = configActions?.map((node) => createSafeNode({
|
|
2867
|
+
node,
|
|
2868
|
+
pushToast,
|
|
2869
|
+
addSyntheticTask,
|
|
2870
|
+
removeSyntheticTask
|
|
2871
|
+
})), onlyGroups = customActions?.length && customActions?.every((node) => node.type === "group");
|
|
2872
|
+
return (customActions?.length ? onlyGroups ? customActions : [
|
|
2873
|
+
{
|
|
2874
|
+
type: "group",
|
|
2875
|
+
title: title || "Custom actions",
|
|
2876
|
+
children: customActions,
|
|
2877
|
+
expanded: !0
|
|
2878
|
+
}
|
|
2879
|
+
] : []) ?? [];
|
|
2880
|
+
}, [configActions, fieldActions, pushToast]);
|
|
2881
|
+
}
|
|
2882
|
+
function createSafeNode(args) {
|
|
2883
|
+
const { node } = args;
|
|
2884
|
+
switch (node.type) {
|
|
2885
|
+
case "action":
|
|
2886
|
+
return createSafeAction({ ...args, action: node });
|
|
2887
|
+
case "group":
|
|
2888
|
+
return {
|
|
2889
|
+
...node,
|
|
2890
|
+
renderAsButton: !1,
|
|
2891
|
+
expanded: !0,
|
|
2892
|
+
children: node.children?.map((child) => createSafeNode({ ...args, node: child }))
|
|
2893
|
+
};
|
|
2894
|
+
case "divider":
|
|
2895
|
+
default:
|
|
2896
|
+
return node;
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
function createSafeAction(args) {
|
|
2900
|
+
const { action, pushToast, addSyntheticTask, removeSyntheticTask } = args;
|
|
2901
|
+
return {
|
|
2902
|
+
...action,
|
|
2903
|
+
onAction: () => {
|
|
2904
|
+
async function runAction() {
|
|
2905
|
+
const task = {
|
|
2906
|
+
_type: instructionTaskTypeName,
|
|
2907
|
+
_key: randomKey(12),
|
|
2908
|
+
started: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2909
|
+
presence: [
|
|
2910
|
+
{
|
|
2911
|
+
_type: fieldPresenceTypeName,
|
|
2912
|
+
_key: randomKey(12),
|
|
2913
|
+
path: documentRootKey,
|
|
2914
|
+
started: (/* @__PURE__ */ new Date()).toISOString()
|
|
2915
|
+
}
|
|
2916
|
+
]
|
|
2917
|
+
};
|
|
2918
|
+
try {
|
|
2919
|
+
addSyntheticTask(task);
|
|
2920
|
+
const actionResult = action.onAction?.();
|
|
2921
|
+
actionResult instanceof Promise && await actionResult;
|
|
2922
|
+
} catch (err) {
|
|
2923
|
+
console.error("Failed to execute action", action, err), pushToast({
|
|
2924
|
+
title: "Failed to execute action",
|
|
2925
|
+
description: err?.message,
|
|
2926
|
+
status: "error"
|
|
2927
|
+
});
|
|
2928
|
+
} finally {
|
|
2929
|
+
removeSyntheticTask(task);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
runAction();
|
|
2933
|
+
},
|
|
2934
|
+
renderAsButton: !1,
|
|
2935
|
+
selected: !1
|
|
2936
|
+
};
|
|
2937
|
+
}
|
|
2804
2938
|
const assistFieldActions = {
|
|
2805
2939
|
name: "sanity-assist-actions",
|
|
2806
2940
|
useAction(props) {
|
|
@@ -2815,7 +2949,7 @@ const assistFieldActions = {
|
|
|
2815
2949
|
documentSchemaType,
|
|
2816
2950
|
selectedPath,
|
|
2817
2951
|
assistableDocumentId
|
|
2818
|
-
} = useAssistDocumentContext(), { value: docValue, formState } = structure.useDocumentPane(), formStateRef = react.useRef(formState);
|
|
2952
|
+
} = useAssistDocumentContext(), { value: docValue, formState } = structure.useDocumentPane(), docValueRef = react.useRef(docValue), formStateRef = react.useRef(formState);
|
|
2819
2953
|
formStateRef.current = formState;
|
|
2820
2954
|
const currentUser = sanity.useCurrentUser(), isHidden = !assistDocument, pathKey = usePathKey(props.path), typePath = useTypePath(docValue, pathKey), assistDocumentId2 = assistDocument?._id, { requestRunInstruction } = useRequestRunInstruction({
|
|
2821
2955
|
documentOnChange,
|
|
@@ -2877,7 +3011,6 @@ const assistFieldActions = {
|
|
|
2877
3011
|
isPrivate: !!(instruction2.userId && instruction2.userId === currentUser?.id),
|
|
2878
3012
|
onInstructionAction,
|
|
2879
3013
|
hidden: isHidden,
|
|
2880
|
-
documentIsNew: !!documentIsNew,
|
|
2881
3014
|
assistSupported
|
|
2882
3015
|
})
|
|
2883
3016
|
) || [],
|
|
@@ -2895,7 +3028,23 @@ const assistFieldActions = {
|
|
|
2895
3028
|
imageCaptionAction,
|
|
2896
3029
|
translateAction,
|
|
2897
3030
|
imageGenAction
|
|
2898
|
-
]),
|
|
3031
|
+
]), getDocumentValue = react.useCallback(() => docValueRef.current, []), getConditionalPaths = react.useCallback(() => (formStateRef.current ? getConditionalMembers(formStateRef.current) : []).flatMap(
|
|
3032
|
+
(cm) => {
|
|
3033
|
+
const path = sanity.stringToPath(cm.path);
|
|
3034
|
+
return path.some((s) => typeof s == "number") ? [] : {
|
|
3035
|
+
...cm,
|
|
3036
|
+
path
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
), []), customActions = useCustomFieldActions({
|
|
3040
|
+
actionType: props.path.length ? "field" : "document",
|
|
3041
|
+
documentIdForAction: assistableDocumentId,
|
|
3042
|
+
schemaType,
|
|
3043
|
+
documentSchemaType,
|
|
3044
|
+
path: props.path,
|
|
3045
|
+
getDocumentValue,
|
|
3046
|
+
getConditionalPaths
|
|
3047
|
+
}), manageInstructionsItem = react.useMemo(
|
|
2899
3048
|
() => ({
|
|
2900
3049
|
type: "action",
|
|
2901
3050
|
icon: icons.ControlsIcon,
|
|
@@ -2912,6 +3061,7 @@ const assistFieldActions = {
|
|
|
2912
3061
|
children: [
|
|
2913
3062
|
runInstructionsGroup,
|
|
2914
3063
|
translateAction,
|
|
3064
|
+
...customActions,
|
|
2915
3065
|
assistSupported && manageInstructionsItem
|
|
2916
3066
|
].filter((c) => !!c).filter((c) => c.type === "group" ? c.children.length : !0),
|
|
2917
3067
|
expanded: !1,
|
|
@@ -2925,7 +3075,8 @@ const assistFieldActions = {
|
|
|
2925
3075
|
assistSupported,
|
|
2926
3076
|
imageCaptionAction,
|
|
2927
3077
|
translateAction,
|
|
2928
|
-
imageGenAction
|
|
3078
|
+
imageGenAction,
|
|
3079
|
+
customActions
|
|
2929
3080
|
]
|
|
2930
3081
|
), emptyAction = react.useMemo(
|
|
2931
3082
|
() => ({
|
|
@@ -2939,7 +3090,7 @@ const assistFieldActions = {
|
|
|
2939
3090
|
}),
|
|
2940
3091
|
[assistSupported, manageInstructions, isSelected]
|
|
2941
3092
|
);
|
|
2942
|
-
return
|
|
3093
|
+
return !instructions?.length && !imageCaptionAction && !translateAction && !imageGenAction && !customActions.length ? emptyAction : group;
|
|
2943
3094
|
}
|
|
2944
3095
|
};
|
|
2945
3096
|
function instructionItem(props) {
|
|
@@ -2960,21 +3111,19 @@ function createAssistDocumentPresence(documentId) {
|
|
|
2960
3111
|
};
|
|
2961
3112
|
}
|
|
2962
3113
|
function AssistDocumentPresence() {
|
|
2963
|
-
const { assistDocument } = useAssistDocumentContext(), anyPresence = react.useMemo(() => {
|
|
2964
|
-
const anyPresence2 = assistDocument?.tasks
|
|
3114
|
+
const { assistDocument, syntheticTasks } = useAssistDocumentContext(), anyPresence = react.useMemo(() => {
|
|
3115
|
+
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);
|
|
2965
3116
|
if (anyPresence2)
|
|
2966
3117
|
return aiPresence(anyPresence2, []);
|
|
2967
3118
|
const anyRun = assistDocument?.tasks?.filter((run) => !run.ended && !run.reason)?.find((f) => f.started && (/* @__PURE__ */ new Date()).getTime() - new Date(f.started).getTime() < 3e4);
|
|
2968
3119
|
return anyRun ? aiPresence(
|
|
2969
3120
|
{
|
|
2970
3121
|
started: anyRun.started,
|
|
2971
|
-
|
|
2972
|
-
_key: anyRun._key,
|
|
2973
|
-
_type: fieldPresenceTypeName
|
|
3122
|
+
_key: anyRun._key
|
|
2974
3123
|
},
|
|
2975
3124
|
[]
|
|
2976
3125
|
) : void 0;
|
|
2977
|
-
}, [assistDocument?.tasks]);
|
|
3126
|
+
}, [assistDocument?.tasks, syntheticTasks]);
|
|
2978
3127
|
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 }) }) }) });
|
|
2979
3128
|
}
|
|
2980
3129
|
function BackToInstructionListLink() {
|
|
@@ -3368,31 +3517,6 @@ function Selectable({
|
|
|
3368
3517
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Card, { marginTop: 1, onClick: handleChange, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { style: { cursor: "default" }, size: 1, children: title }) })
|
|
3369
3518
|
] });
|
|
3370
3519
|
}
|
|
3371
|
-
function getRandomValues(typedArray) {
|
|
3372
|
-
const crypto = typeof window < "u" && "crypto" in window ? window.crypto : globalThis.crypto;
|
|
3373
|
-
if (!crypto || !crypto.getRandomValues)
|
|
3374
|
-
throw new Error("WebCrypto not available in this environment");
|
|
3375
|
-
return crypto.getRandomValues(typedArray);
|
|
3376
|
-
}
|
|
3377
|
-
function whatwgRNG(length = 16) {
|
|
3378
|
-
const rnds8 = new Uint8Array(length);
|
|
3379
|
-
return getRandomValues(rnds8), rnds8;
|
|
3380
|
-
}
|
|
3381
|
-
const getByteHexTable = /* @__PURE__ */ (() => {
|
|
3382
|
-
let table;
|
|
3383
|
-
return () => {
|
|
3384
|
-
if (table)
|
|
3385
|
-
return table;
|
|
3386
|
-
table = [];
|
|
3387
|
-
for (let i = 0; i < 256; ++i)
|
|
3388
|
-
table[i] = (i + 256).toString(16).substring(1);
|
|
3389
|
-
return table;
|
|
3390
|
-
};
|
|
3391
|
-
})();
|
|
3392
|
-
function randomKey(length) {
|
|
3393
|
-
const table = getByteHexTable();
|
|
3394
|
-
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
3395
|
-
}
|
|
3396
3520
|
const PteMods = styledComponents.styled(ui.Box)`
|
|
3397
3521
|
& [data-testid='pt-editor__toolbar-card'] > div > div:last-child {
|
|
3398
3522
|
display: none;
|
|
@@ -4093,8 +4217,16 @@ function SchemaEntry({ schemaStub }) {
|
|
|
4093
4217
|
const out = react.useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub]);
|
|
4094
4218
|
return /* @__PURE__ */ jsxRuntime.jsx("pre", { children: out });
|
|
4095
4219
|
}
|
|
4220
|
+
function useUserInput() {
|
|
4221
|
+
const { getUserInput } = useRunInstruction();
|
|
4222
|
+
return getUserInput;
|
|
4223
|
+
}
|
|
4096
4224
|
exports.SchemaTypeTool = SchemaTypeTool;
|
|
4097
4225
|
exports.assist = assist;
|
|
4098
4226
|
exports.contextDocumentTypeName = contextDocumentTypeName;
|
|
4099
4227
|
exports.defaultLanguageOutputs = defaultLanguageOutputs;
|
|
4228
|
+
exports.defineAssistFieldAction = defineAssistFieldAction;
|
|
4229
|
+
exports.defineAssistFieldActionGroup = defineAssistFieldActionGroup;
|
|
4230
|
+
exports.defineFieldActionDivider = defineFieldActionDivider;
|
|
4231
|
+
exports.useUserInput = useUserInput;
|
|
4100
4232
|
//# sourceMappingURL=index.js.map
|