@ykurilov/agent-chat-flows 0.62.0 → 0.63.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @ykurilov/agent-chat-flows
2
2
 
3
+ ## 0.63.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8bcee93]
8
+ - @ykurilov/agent-chat-react@0.63.1
9
+ - @ykurilov/agent-chat-core@0.63.1
10
+
11
+ ## 0.63.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 8a9e399: Доска сценария больше не показывает «Сохранено» для несохранённых правок после возвращения на вкладку: новое необязательное `savedValue` у `FlowEditor` и функция `sameFlow` из `@ykurilov/agent-chat-flows/react`.
16
+
17
+ ### Как обновить приложение
18
+
19
+ Если `FlowEditor` стоит на отдельной вкладке и размонтируется при уходе, передайте `savedValue={сценарий, как он лежит на сервере}`. Без него поведение прежнее.
20
+
21
+ ### Patch Changes
22
+
23
+ - @ykurilov/agent-chat-core@0.63.0
24
+ - @ykurilov/agent-chat-react@0.63.0
25
+
3
26
  ## 0.62.0
4
27
 
5
28
  ### Minor Changes
package/dist/react.js CHANGED
@@ -825,6 +825,21 @@ function flowToJson(flow) {
825
825
  return `${JSON.stringify(keepJudgeText(compactFlow(flow)), null, 2)}
826
826
  `;
827
827
  }
828
+ function sortKeys(value) {
829
+ if (Array.isArray(value)) return value.map(sortKeys);
830
+ if (value && typeof value === "object") {
831
+ return Object.fromEntries(
832
+ Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, inner]) => [key, sortKeys(inner)])
833
+ );
834
+ }
835
+ return value;
836
+ }
837
+ function flowFingerprint(flow) {
838
+ return JSON.stringify(sortKeys(keepJudgeText(compactFlow(flow))));
839
+ }
840
+ function sameFlow(a, b) {
841
+ return flowFingerprint(a) === flowFingerprint(b);
842
+ }
828
843
  function keepJudgeText(json) {
829
844
  const fix = (exits) => exits?.forEach((exit) => {
830
845
  if (exit.when?.type === "judge" && exit.when.text === void 0) exit.when.text = "";
@@ -1729,7 +1744,10 @@ function useFlowEditor(options) {
1729
1744
  const [jsonErrors, setJsonErrors] = useState3([]);
1730
1745
  const [simulation, setSimulation] = useState3(null);
1731
1746
  const [saving, setSaving] = useState3(false);
1732
- const [savedJson, setSavedJson] = useState3(() => flowToJson(flow));
1747
+ const [mountedPrint] = useState3(() => flowFingerprint(flow));
1748
+ const savedPrint = useMemo3(() => options.savedValue ? flowFingerprint(options.savedValue) : void 0, [options.savedValue]);
1749
+ const [sent, setSent] = useState3(null);
1750
+ const savedJson = sent && sent.base === savedPrint ? sent.print : savedPrint ?? mountedPrint;
1733
1751
  const [rejection, setRejection] = useState3(null);
1734
1752
  const readOnly = options.readOnly === true;
1735
1753
  const checks = options.checks;
@@ -1741,7 +1759,8 @@ function useFlowEditor(options) {
1741
1759
  );
1742
1760
  const issueCount = useMemo3(() => countIssues(issues), [issues]);
1743
1761
  const json = useMemo3(() => flowToJson(flow), [flow]);
1744
- const dirty = json !== savedJson;
1762
+ const print = useMemo3(() => flowFingerprint(flow), [flow]);
1763
+ const dirty = print !== savedJson;
1745
1764
  const visibleSelection = selection.kind === "state" && !flow.states.some((state) => state.id === selection.stateId) ? { kind: "overview" } : selection;
1746
1765
  const edit = useCallback3((change) => {
1747
1766
  if (latest.current.readOnly) return;
@@ -1862,7 +1881,7 @@ function useFlowEditor(options) {
1862
1881
  return;
1863
1882
  }
1864
1883
  setRejection(null);
1865
- setSavedJson(flowToJson(value));
1884
+ setSent({ print: flowFingerprint(value), base: latest.current.savedValue ? flowFingerprint(latest.current.savedValue) : void 0 });
1866
1885
  } catch (error) {
1867
1886
  console.warn("[flow] onSave failed", error);
1868
1887
  setRejection({ flow: value, issues: [] });
@@ -2640,6 +2659,7 @@ export {
2640
2659
  formatDuration,
2641
2660
  nextQuestionField,
2642
2661
  russianFlowLabels,
2662
+ sameFlow,
2643
2663
  setKnownValue,
2644
2664
  simulationChoices,
2645
2665
  startSimulation,