• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / BotFramework-Composer / 9010285116

28 Mar 2024 01:12PM UTC coverage: 54.424% (-0.06%) from 54.482%
9010285116

push

github

web-flow
Merge pull request #9713 from OEvgeny/chore/update-electron-26

chore: update dependencies

7577 of 18338 branches covered (41.32%)

Branch coverage included in aggregate %.

939 of 1507 new or added lines in 170 files covered. (62.31%)

8 existing lines in 8 files now uncovered.

19745 of 31864 relevant lines covered (61.97%)

26.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.54
/Composer/packages/client/src/components/BotRuntimeController/useBotOperations.ts
1
// Copyright (c) Microsoft Corporation.
2
// Licensed under the MIT License.
3

4
import { IPublishConfig } from '@bfc/shared';
5
import { useState } from 'react';
18✔
6
import { useRecoilValue } from 'recoil';
18✔
7

8
import { BotStatus } from '../../constants';
18✔
9
import { dispatcherState, rootBotProjectIdSelector } from '../../recoilModel';
18✔
10
import { botRuntimeOperationsSelector, buildConfigurationSelector } from '../../recoilModel/selectors';
18✔
11

12
import { useStartedRuntimesTracker } from './useStartedRuntimesTracker';
59✔
13

14
export function useBotOperations() {
18✔
15
  const builderEssentials = useRecoilValue(buildConfigurationSelector);
59✔
16
  const botRuntimeOperations = useRecoilValue(botRuntimeOperationsSelector);
59✔
17
  const rootBotId = useRecoilValue(rootBotProjectIdSelector);
59✔
18
  const [trackedProjectIds, setProjectsToTrack] = useState<string[]>([]);
59✔
19
  const { updateSettingsForSkillsWithoutManifest, resetBotRuntimeLog, setBotStatus } = useRecoilValue(dispatcherState);
59✔
20

21
  const handleBotStart = async (
59✔
22
    projectId: string,
23
    config: IPublishConfig,
24
    sensitiveSettings,
25
    botBuildRequired: boolean,
26
  ) => {
27
    resetBotRuntimeLog(projectId);
1✔
28
    setBotStatus(projectId, BotStatus.pending);
1✔
29
    if (botBuildRequired) {
1!
30
      // Default recognizer
31
      const matchedBuilder = builderEssentials.find(
NEW
32
        ({ projectId: currentProjectId }) => projectId === currentProjectId,
×
33
      );
34
      if (matchedBuilder?.dialogs) {
×
35
        await botRuntimeOperations?.buildWithDefaultRecognizer(projectId, {
×
36
          dialogs: matchedBuilder.dialogs,
37
          config,
38
        });
39
      }
40
    } else {
41
      // Regex recognizer
42
      await botRuntimeOperations?.startBot(projectId, sensitiveSettings);
1!
43
    }
44
  };
45

46
  const startRootBot = async (skipBuild?: boolean) => {
59✔
47
    setProjectsToTrack([]);
×
48
    await updateSettingsForSkillsWithoutManifest();
×
49
    if (builderEssentials.length) {
×
50
      const { projectId, configuration, buildRequired, status, sensitiveSettings } = builderEssentials[0];
×
51
      if (status !== BotStatus.connected) {
×
52
        let isBuildRequired = buildRequired;
×
53
        if (skipBuild) {
×
54
          isBuildRequired = false;
×
55
        }
56
        handleBotStart(projectId, configuration, sensitiveSettings, isBuildRequired);
×
57
      }
58
    }
59
  };
60

61
  // Custom hook to make sure root bot is started after all skills have been started.
62
  useStartedRuntimesTracker(() => {
63
    startRootBot();
×
64
  }, trackedProjectIds);
65

66
  const startAllBots = async () => {
59✔
67
    builderEssentials.forEach((bot) => {
×
68
      setBotStatus(bot.projectId, BotStatus.queued);
×
69
    });
70
    const [, ...skillsBots] = builderEssentials;
×
71
    if (skillsBots.length === 0) {
×
72
      startRootBot();
×
73
      return;
×
74
    }
75

76
    const trackProjects: string[] = skillsBots.map((skillBot) => skillBot.projectId);
×
77
    setProjectsToTrack(trackProjects);
×
78
    for (const botBuildConfig of skillsBots) {
×
79
      if (botBuildConfig.status !== BotStatus.connected) {
×
80
        const { projectId, configuration, buildRequired, sensitiveSettings } = botBuildConfig;
×
81
        await handleBotStart(projectId, configuration, sensitiveSettings, buildRequired);
×
82
      }
83
    }
84
  };
85

86
  const stopAllBots = async (): Promise<void> => {
59✔
87
    setProjectsToTrack([]);
×
88
    for (const projectBuilder of builderEssentials) {
×
89
      await botRuntimeOperations?.stopBot(projectBuilder.projectId);
×
90
    }
91
  };
92

93
  const startSingleBot = (projectId: string, skipBuild: boolean | undefined = undefined) => {
59✔
94
    if (projectId === rootBotId) {
1!
95
      startRootBot(skipBuild);
×
96
    } else {
97
      const botData = builderEssentials.find((builder) => builder.projectId === projectId);
2✔
98
      if (botData) {
1✔
99
        let isBuildRequired = botData?.buildRequired;
1!
100
        if (skipBuild) {
1!
101
          isBuildRequired = false;
×
102
        }
103
        handleBotStart(projectId, botData?.configuration, botData.sensitiveSettings, isBuildRequired);
1!
104
      }
105
    }
106
  };
107

108
  const stopSingleBot = (projectId: string) => {
59✔
109
    botRuntimeOperations?.stopBot(projectId);
1!
110
  };
111

112
  return {
59✔
113
    stopAllBots,
114
    startAllBots,
115
    startSingleBot,
116
    stopSingleBot,
117
  };
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc