<commit_before>import Service from '@ember/service';
import config from 'nomad-ui/config/environment';
import { getOwner } from '@ember/application';

export default Service.extend({
  getTaskStateSocket(taskState, command) {
    const mirageEnabled =
      config['ember-cli-mirage'] && config['ember-cli-mirage'].enabled !== false;

    if (mirageEnabled) {
      return new Object({
        messageDisplayed: false,

        send(e) {
          if (!this.messageDisplayed) {
            this.messageDisplayed = true;
            this.onmessage({ data: `{"stdout":{"data":"${btoa('unsupported in Mirage\n\r')}"}}` });
          } else {
            this.onmessage({ data: e.replace('stdin', 'stdout') });
          }
        },
      });
    } else {
      const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
      const applicationAdapter = getOwner(this).lookup('adapter:application');
      const prefix = `${applicationAdapter.host ||
        window.location.host}/${applicationAdapter.urlPrefix()}`;

      return new WebSocket(
        `${protocol}//${prefix}/client/allocation/${taskState.allocation.id}` +
          `/exec?task=${taskState.name}&tty=true` +
          `&command=${encodeURIComponent(`["${command}"]`)}`
      );<commit_msg>UI: Fix check for Mirage presence setting up sockets (#7497)<commit_after>import Service from '@ember/service';
import config from 'nomad-ui/config/environment';
import { getOwner } from '@ember/application';

export default Service.extend({
  getTaskStateSocket(taskState, command) {
    const mirageEnabled =
      config.environment !== 'production' &&
      config['ember-cli-mirage'] &&
      config['ember-cli-mirage'].enabled !== false;

    if (mirageEnabled) {
      return new Object({
        messageDisplayed: false,

        send(e) {
          if (!this.messageDisplayed) {
            this.messageDisplayed = true;
            this.onmessage({ data: `{"stdout":{"data":"${btoa('unsupported in Mirage\n\r')}"}}` });
          } else {
            this.onmessage({ data: e.replace('stdin', 'stdout') });
          }
        },
      });
    } else {
      const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
      const applicationAdapter = getOwner(this).lookup('adapter:application');
      const prefix = `${applicationAdapter.host ||
        window.location.host}/${applicationAdapter.urlPrefix()}`;

      return new WebSocket(
        `${protocol}//${prefix}/client/allocation/${taskState.allocation.id}` +
          `/exec?task=${taskState.name}&tty=true` +
          `&command=${encodeURIComponent(`["${command}"]`)}`
      );
{'fraction_non_alphanumeric': 0.17134192570128887, 'fraction_numerical': 0.001516300227445034, 'mean_word_length': 2.968421052631579, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3714258', 'n_tokens_mistral': 753, 'n_tokens_neox': 755, 'n_words': 139}