import { feature } from 'bun:bundle';
import React, { useCallback, useEffect, useRef } from 'react';
import { setMainLoopModelOverride } from '../bootstrap/state.js';
import { type BridgePermissionCallbacks, type BridgePermissionResponse, isBridgePermissionResponse } from '../bridge/bridgePermissionCallbacks.js';
import { buildBridgeConnectUrl } from '../bridge/bridgeStatusUtil.js';
import { extractInboundMessageFields } from '../bridge/inboundMessages.js';
import type { BridgeState, ReplBridgeHandle } from '../bridge/replBridge.js';
import { setReplBridgeHandle } from '../bridge/replBridgeHandle.js';
import type { Command } from '../commands.js';
import { getSlashCommandToolSkills, isBridgeSafeCommand } from '../commands.js';
import { getRemoteSessionUrl } from '../constants/product.js';
import { useNotifications } from '../context/notifications.js';
import type { PermissionMode, SDKMessage } from '../entrypoints/agentSdkTypes.js';
import type { SDKControlResponse } from '../entrypoints/sdk/controlTypes.js';
import { Text } from '../ink.js';
import { getFeatureValue_CACHED_MAY_BE_STALE } from '../services/analytics/growthbook.js';
import { useAppState, useAppStateStore, useSetAppState } from '../state/AppState.js';
import type { Message } from '../types/message.js';
import { getCwd } from '../utils/cwd.js';
import { logForDebugging } from '../utils/debug.js';
import { errorMessage } from '../utils/errors.js';
import { enqueue } from '../utils/messageQueueManager.js';
import { buildSystemInitMessage } from '../utils/messages/systemInit.js';
import { createBridgeStatusMessage, createSystemMessage } from '../utils/messages.js';
import { getAutoModeUnavailableNotification, getAutoModeUnavailableReason, isAutoModeGateEnabled, isBypassPermissionsModeDisabled, transitionPermissionMode } from '../utils/permissions/permissionSetup.js';
import { getLeaderToolUseConfirmQueue } from '../utils/swarm/leaderPermissionBridge.js';

/** How long after a failure before replBridgeEnabled is auto-cleared (stops retries). */
export const BRIDGE_FAILURE_DISMISS_MS = 10_000;

/**
 * Max consecutive initReplBridge failures before the hook stops re-attempting
 * for the session lifetime. Guards against paths that flip replBridgeEnabled
 * back on after auto-disable (settings sync, /remote-control, config tool)
 * when the underlying OAuth is unrecoverable — each re-attempt is another
 * guaranteed 401 against POST /v1/environments/bridge. Datadog 2026-03-08:
 * top stuck client generated 2,879 × 401/day alone (17% of all 401s on the
 * route).
 */
const MAX_CONSECUTIVE_INIT_FAILURES = 3;

/**
 * Hook that initializes an always-on bridge connection in the background
 * and writes new user/assistant messages to the bridge session.
 *
 * Silently skips if bridge is not enabled or user is not OAuth-authenticated.
 *
 * Watches AppState.replBridgeEnabled — when toggled off (via /config or footer),
 * the bridge is torn down. When toggled back on, it re-initializes.
 *
 * Inbound messages from claude.ai are injected into the REPL via queuedCommands.
 */
export function useReplBridge(messages: Message[], setMessages: (action: React.SetStateAction<Message[]>) => void, abortControllerRef: React.RefObject<AbortController | null>, commands: readonly Command[], mainLoopModel: string): {
  sendBridgeResult: () => void;
} {
  const handleRef = useRef<ReplBridgeHandle | null>(null);
  const teardownPromiseRef = useRef<Promise<void> | undefined>(undefined);
  const lastWrittenIndexRef = useRef(0);
  // Tracks UUIDs already flushed as initial messages. Persists across
  // bridge reconnections so Bridge #2+ only sends new messages — sending
  // duplicate UUIDs causes the server to kill the WebSocket.
  const flushedUUIDsRef = useRef(new Set<string>());
  const failureTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
  // Persists across effect re-runs (unlike the effect's local state). Reset
  // only on successful init. Hits MAX_CONSECUTIVE_INIT_FAILURES → fuse blown
  // for the session, regardless of replBridgeEnabled re-toggling.
  const consecutiveFailuresRef = useRef(0);
  const setAppState = useSetAppState();
  const commandsRef = useRef(commands);
  commandsRef.current = commands;
  const mainLoopModelRef = useRef(mainLoopModel);
  mainLoopModelRef.current = mainLoopModel;
  const messagesRef = useRef(messages);
  messagesRef.current = messages;
  const store = useAppStateStore();
  const {
    addNotification
  } = useNotifications();
  const replBridgeEnabled = feature('BRIDGE_MODE') ?
  // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
  useAppState(s => s.replBridgeEnabled) : false;
  const replBridgeConnected = feature('BRIDGE_MODE') ?
  // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
  useAppState(s_0 => s_0.replBridgeConnected) : false;
  const replBridgeOutboundOnly = feature('BRIDGE_MODE') ?
  // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
  useAppState(s_1 => s_1.replBridgeOutboundOnly) : false;
  const replBridgeInitialName = feature('BRIDGE_MODE') ?
  // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
  useAppState(s_2 => s_2.replBridgeInitialName) : undefined;

  // Initialize/teardown bridge when enabled state changes.
  // Passes current messages as initialMessages so the remote session
  // starts with the existing conversation context (e.g. from /bridge).
  useEffect(() => {
    // feature() check must use positive pattern for dead code elimination —
    // negative pattern (if (!feature(...)) return) does NOT eliminate
    // dynamic imports below.
    if (feature('BRIDGE_MODE')) {
      if (!replBridgeEnabled) return;
      const outboundOnly = replBridgeOutboundOnly;
      function notifyBridgeFailed(detail?: string): void {
        if (outboundOnly) return;
        addNotification({
          key: 'bridge-failed',
          jsx: <>
              <Text color="error">Remote Control failed</Text>
              {detail && <Text dimColor> · {detail}</Text>}
            </>,
          priority: 'immediate'
        });
      }
      if (consecutiveFailuresRef.current >= MAX_CONSECUTIVE_INIT_FAILURES) {
        logForDebugging(`[bridge:repl] Hook: ${consecutiveFailuresRef.current} consecutive init failures, not retrying this session`);
        // Clear replBridgeEnabled so /remote-control doesn't mistakenly show
        // BridgeDisconnectDialog for a bridge that never connected.
        const fuseHint = 'disabled after repeated failures · restart to retry';
        notifyBridgeFailed(fuseHint);
        setAppState(prev => {
          if (prev.replBridgeError === fuseHint && !prev.replBridgeEnabled) return prev;
          return {
            ...prev,
            replBridgeError: fuseHint,
            replBridgeEnabled: false
          };
        });
        return;
      }
      let cancelled = false;
      // Capture messages.length now so we don't re-send initial messages
      // through writeMessages after the bridge connects.
      const initialMessageCount = messages.length;
      void (async () => {
        try {
          // Wait for any in-progress teardown to complete before registering
          // a new environment. Without this, the deregister HTTP call from
          // the previous teardown races with the new register call, and the
          // server may tear down the freshly-created environment.
          if (teardownPromiseRef.current) {
            logForDebugging('[bridge:repl] Hook: waiting for previous teardown to complete before re-init');
            await teardownPromiseRef.current;
            teardownPromiseRef.current = undefined;
            logForDebugging('[bridge:repl] Hook: previous teardown complete, proceeding with re-init');
          }
          if (cancelled) return;

          // Dynamic import so the module is tree-shaken in external builds
          const {
            initReplBridge
          } = await import('../bridge/initReplBridge.js');
          const {
            shouldShowAppUpgradeMessage
          } = await import('../bridge/envLessBridgeConfig.js');

          // Assistant mode: perpetual bridge session — claude.ai shows one
          // continuous conversation across CLI restarts instead of a new
          // session per invocation. initBridgeCore reads bridge-pointer.json
          // (the same crash-recovery file #20735 added) and reuses its
          // {environmentId, sessionId} via reuseEnvironmentId +
          // api.reconnectSession(). Teardown skips archive/deregister/
          // pointer-clear so the session survives clean exits, not just
          // crashes. Non-assistant bridges clear the pointer on teardown
          // (crash-recovery only).
          let perpetual = false;
          if (feature('KAIROS')) {
            const {
              isAssistantMode
            } = await import('../assistant/index.js');
            perpetual = isAssistantMode();
          }

          // When a user message arrives from claude.ai, inject it into the REPL.
          // Preserves the original UUID so that when the message is forwarded
          // back to CCR, it matches the original — avoiding duplicate messages.
          //
          // Async because file_attachments (if present) need a network fetch +
          // disk write before we enqueue with the @path prefix. Caller doesn't
          // await — messages with attachments just land in the queue slightly
          // later, which is fine (web messages aren't rapid-fire).
          async function handleInboundMessage(msg: SDKMessage): Promise<void> {
            try {
              const fields = extractInboundMessageFields(msg);
              if (!fields) return;
              const {
                uuid
              } = fields;

              // Dynamic import keeps the bridge code out of non-BRIDGE_MODE builds.
              const {
                resolveAndPrepend
              } = await import('../bridge/inboundAttachments.js');
              let sanitized = fields.content;
              if (feature('KAIROS_GITHUB_WEBHOOKS')) {
                /* eslint-disable @typescript-eslint/no-require-imports */
                const {
                  sanitizeInboundWebhookContent
                } = require('../bridge/webhookSanitizer.js') as typeof import('../bridge/webhookSanitizer.js');
                /* eslint-enable @typescript-eslint/no-require-imports */
                sanitized = sanitizeInboundWebhookContent(fields.content);
              }
              const content = await resolveAndPrepend(msg, sanitized);
              const preview = typeof content === 'string' ? content.slice(0, 80) : `[${content.length} content blocks]`;
              logForDebugging(`[bridge:repl] Injecting inbound user message: ${preview}${uuid ? ` uuid=${uuid}` : ''}`);
              enqueue({
                value: content,
                mode: 'prompt' as const,
                uuid,
                // skipSlashCommands stays true as defense-in-depth —
                // processUserInputBase overrides it internally when bridgeOrigin
                // is set AND the resolved command passes isBridgeSafeCommand.
                // This keeps exit-word suppression and immediate-command blocks
                // intact for any code path that checks skipSlashCommands directly.
                skipSlashCommands: true,
                bridgeOrigin: true
              });
            } catch (e) {
              logForDebugging(`[bridge:repl] handleInboundMessage failed: ${e}`, {
                level: 'error'
              });
            }
          }

          // State change callback — maps bridge lifecycle events to AppState.
          function handleStateChange(state: BridgeState, detail_0?: string): void {
            if (cancelled) return;
            if (outboundOnly) {
              logForDebugging(`[bridge:repl] Mirror state=${state}${detail_0 ? ` detail=${detail_0}` : ''}`);
              // Sync replBridgeConnected so the forwarding effect starts/stops
              // writing as the transport comes up or dies.
              if (state === 'failed') {
                setAppState(prev_3 => {
                  if (!prev_3.replBridgeConnected) return prev_3;
                  return {
                    ...prev_3,
                    replBridgeConnected: false
                  };
                });
              } else if (state === 'ready' || state === 'connected') {
                setAppState(prev_4 => {
                  if (prev_4.replBridgeConnected) return prev_4;
                  return {
                    ...prev_4,
                    replBridgeConnected: true
                  };
                });
              }
              return;
            }
            const handle = handleRef.current;
            switch (state) {
              case 'ready':
                setAppState(prev_9 => {
                  const connectUrl = handle && handle.environmentId !== '' ? buildBridgeConnectUrl(handle.environmentId, handle.sessionIngressUrl) : prev_9.replBridgeConnectUrl;
                  const sessionUrl = handle ? getRemoteSessionUrl(handle.bridgeSessionId, handle.sessionIngressUrl) : prev_9.replBridgeSessionUrl;
                  const envId = handle?.environmentId;
                  const sessionId = handle?.bridgeSessionId;
                  if (prev_9.replBridgeConnected && !prev_9.replBridgeSessionActive && !prev_9.replBridgeReconnecting && prev_9.replBridgeConnectUrl === connectUrl && prev_9.replBridgeSessionUrl === sessionUrl && prev_9.replBridgeEnvironmentId === envId && prev_9.replBridgeSessionId === sessionId) {
                    return prev_9;
                  }
                  return {
                    ...prev_9,
                    replBridgeConnected: true,
                    replBridgeSessionActive: false,
                    replBridgeReconnecting: false,
                    replBridgeConnectUrl: connectUrl,
                    replBridgeSessionUrl: sessionUrl,
                    replBridgeEnvironmentId: envId,
                    replBridgeSessionId: sessionId,
                    replBridgeError: undefined
                  };
                });
                break;
              case 'connected':
                {
                  setAppState(prev_8 => {
                    if (prev_8.replBridgeSessionActive) return prev_8;
                    return {
                      ...prev_8,
                      replBridgeConnected: true,
                      replBridgeSessionActive: true,
                      replBridgeReconnecting: false,
                      replBridgeError: undefined
                    };
                  });
                  // Send system/init so remote clients (web/iOS/Android) get
                  // session metadata. REPL uses query() directly — never hits
                  // QueryEngine's SDKMessage layer — so this is the only path
                  // to put system/init on the REPL-bridge wire. Skills load is
                  // async (memoized, cheap after REPL startup); fire-and-forget
                  // so the connected-state transition isn't blocked.
                  if (getFeatureValue_CACHED_MAY_BE_STALE('tengu_bridge_system_init', false)) {
                    void (async () => {
                      try {
                        const skills = await getSlashCommandToolSkills(getCwd());
                        if (cancelled) return;
                        const state_0 = store.getState();
                        handleRef.current?.writeSdkMessages([buildSystemInitMessage({
                          // tools/mcpClients/plugins redacted for REPL-bridge:
                          // MCP-prefixed tool names and server names leak which
                          // integrations the user has wired up; plugin paths leak
                          // raw filesystem paths (username, project structure).
                          // CCR v2 persists SDK messages to Spanner — users who
                          // tap "Connect from phone" may not expect these on
                          // Anthropic's servers. QueryEngine (SDK) still emits
                          // full lists — SDK consumers expect full telemetry.
                          tools: [],
                          mcpClients: [],
                          model: mainLoopModelRef.current,
                          permissionMode: state_0.toolPermissionContext.mode as PermissionMode,
                          // TODO: avoid the cast
                          // Remote clients can only invoke bridge-safe commands —
                          // advertising unsafe ones (local-jsx, unallowed local)
                          // would let mobile/web attempt them and hit errors.
                          commands: commandsRef.current.filter(isBridgeSafeCommand),
                          agents: state_0.agentDefinitions.activeAgents,
                          skills,
                          plugins: [],
                          fastMode: state_0.fastMode
                        })]);
                      } catch (err_0) {
                        logForDebugging(`[bridge:repl] Failed to send system/init: ${errorMessage(err_0)}`, {
                          level: 'error'
                        });
                      }
                    })();
                  }
                  break;
                }
              case 'reconnecting':
                setAppState(prev_7 => {
                  if (prev_7.replBridgeReconnecting) return prev_7;
                  return {
                    ...prev_7,
                    replBridgeReconnecting: true,
                    replBridgeSessionActive: false
                  };
                });
                break;
              case 'failed':
                // Clear any previous failure dismiss timer
                clearTimeout(failureTimeoutRef.current);
                notifyBridgeFailed(detail_0);
                setAppState(prev_5 => ({
                  ...prev_5,
                  replBridgeError: detail_0,
                  replBridgeReconnecting: false,
                  replBridgeSessionActive: false,
                  replBridgeConnected: false
                }));
                // Auto-disable after timeout so the hook stops retrying.
                failureTimeoutRef.current = setTimeout(() => {
                  if (cancelled) return;
                  failureTimeoutRef.current = undefined;
                  setAppState(prev_6 => {
                    if (!prev_6.replBridgeError) return prev_6;
                    return {
                      ...prev_6,
                      replBridgeEnabled: false,
                      replBridgeError: undefined
                    };
                  });
                }, BRIDGE_FAILURE_DISMISS_MS);
                break;
            }
          }

          // Map of pending bridge permission response handlers, keyed by request_id.
          // Each entry is an onResponse handler waiting for CCR to reply.
          const pendingPermissionHandlers = new Map<string, (response: BridgePermissionResponse) => void>();

          // Dispatch incoming control_response messages to registered handlers
          function handlePermissionResponse(msg_0: SDKControlResponse): void {
            const requestId = msg_0.response?.request_id;
            if (!requestId) return;
            const handler = pendingPermissionHandlers.get(requestId);
            if (!handler) {
              logForDebugging(`[bridge:repl] No handler for control_response request_id=${requestId}`);
              return;
            }
            pendingPermissionHandlers.delete(requestId);
            // Extract the permission decision from the control_response payload
            const inner = msg_0.response;
            if (inner.subtype === 'success' && inner.response && isBridgePermissionResponse(inner.response)) {
              handler(inner.response);
            }
          }
          const handle_0 = await initReplBridge({
            outboundOnly,
            tags: outboundOnly ? ['ccr-mirror'] : undefined,
            onInboundMessage: handleInboundMessage,
            onPermissionResponse: handlePermissionResponse,
            onInterrupt() {
              abortControllerRef.current?.abort();
            },
            onSetModel(model) {
              const resolved = model === 'default' ? null : model ?? null;
              setMainLoopModelOverride(resolved);
              setAppState(prev_10 => {
                if (prev_10.mainLoopModelForSession === resolved) return prev_10;
                return {
                  ...prev_10,
                  mainLoopModelForSession: resolved
                };
              });
            },
            onSetMaxThinkingTokens(maxTokens) {
              const enabled = maxTokens !== null;
              setAppState(prev_11 => {
                if (prev_11.thinkingEnabled === enabled) return prev_11;
                return {
                  ...prev_11,
                  thinkingEnabled: enabled
                };
              });
            },
            onSetPermissionMode(mode) {
              // Policy guards MUST fire before transitionPermissionMode —
              // its internal auto-gate check is a defensive throw (with a
              // setAutoModeActive(true) side-effect BEFORE the throw) rather
              // than a graceful reject. Letting that throw escape would:
              // (1) leave STATE.autoModeActive=true while the mode is
              //     unchanged (3-way invariant violation per src/CLAUDE.md)
              // (2) fail to send a control_response → server kills WS
              // These mirror print.ts handleSetPermissionMode; the bridge
              // can't import the checks directly (bootstrap-isolation), so
              // it relies on this verdict to emit the error response.
              if (mode === 'bypassPermissions') {
                if (isBypassPermissionsModeDisabled()) {
                  return {
                    ok: false,
                    error: 'Cannot set permission mode to bypassPermissions because it is disabled by settings or configuration'
                  };
                }
                if (!store.getState().toolPermissionContext.isBypassPermissionsModeAvailable) {
                  return {
                    ok: false,
                    error: 'Cannot set permission mode to bypassPermissions because the session was not launched with --dangerously-skip-permissions'
                  };
                }
              }
              if (feature('TRANSCRIPT_CLASSIFIER') && mode === 'auto' && !isAutoModeGateEnabled()) {
                const reason = getAutoModeUnavailableReason();
                return {
                  ok: false,
                  error: reason ? `Cannot set permission mode to auto: ${getAutoModeUnavailableNotification(reason)}` : 'Cannot set permission mode to auto'
                };
              }
              // Guards passed — apply via the centralized transition so
              // prePlanMode stashing and auto-mode state sync all fire.
              setAppState(prev_12 => {
                const current = prev_12.toolPermissionContext.mode;
                if (current === mode) return prev_12;
                const next = transitionPermissionMode(current, mode, prev_12.toolPermissionContext);
                return {
                  ...prev_12,
                  toolPermissionContext: {
                    ...next,
                    mode
                  }
                };
              });
              // Recheck queued permission prompts now that mode changed.
              setImmediate(() => {
                getLeaderToolUseConfirmQueue()?.(currentQueue => {
                  currentQueue.forEach(item => {
                    void item.recheckPermission();
                  });
                  return currentQueue;
                });
              });
              return {
                ok: true
              };
            },
            onStateChange: handleStateChange,
            initialMessages: messages.length > 0 ? messages : undefined,
            getMessages: () => messagesRef.current,
            previouslyFlushedUUIDs: flushedUUIDsRef.current,
            initialName: replBridgeInitialName,
            perpetual
          });
          if (cancelled) {
            // Effect was cancelled while initReplBridge was in flight.
            // Tear down the handle to avoid leaking resources (poll loop,
            // WebSocket, registered environment, cleanup callback).
            logForDebugging(`[bridge:repl] Hook: init cancelled during flight, tearing down${handle_0 ? ` env=${handle_0.environmentId}` : ''}`);
            if (handle_0) {
              void handle_0.teardown();
            }
            return;
          }
          if (!handle_0) {
            // initReplBridge returned null — a precondition failed. For most
            // cases (no_oauth, policy_denied, etc.) onStateChange('failed')
            // already fired with a specific hint. The GrowthBook-gate-off case
            // is intentionally silent — not a failure, just not rolled out.
            consecutiveFailuresRef.current++;
            logForDebugging(`[bridge:repl] Init returned null (precondition or session creation failed); consecutive failures: ${consecutiveFailuresRef.current}`);
            clearTimeout(failureTimeoutRef.current);
            setAppState(prev_13 => ({
              ...prev_13,
              replBridgeError: prev_13.replBridgeError ?? 'check debug logs for details'
            }));
            failureTimeoutRef.current = setTimeout(() => {
              if (cancelled) return;
              failureTimeoutRef.current = undefined;
              setAppState(prev_14 => {
                if (!prev_14.replBridgeError) return prev_14;
                return {
                  ...prev_14,
                  replBridgeEnabled: false,
                  replBridgeError: undefined
                };
              });
            }, BRIDGE_FAILURE_DISMISS_MS);
            return;
          }
          handleRef.current = handle_0;
          setReplBridgeHandle(handle_0);
          consecutiveFailuresRef.current = 0;
          // Skip initial messages in the forwarding effect — they were
          // already loaded as session events during creation.
          lastWrittenIndexRef.current = initialMessageCount;
          if (outboundOnly) {
            setAppState(prev_15 => {
              if (prev_15.replBridgeConnected && prev_15.replBridgeSessionId === handle_0.bridgeSessionId) return prev_15;
              return {
                ...prev_15,
                replBridgeConnected: true,
                replBridgeSessionId: handle_0.bridgeSessionId,
                replBridgeSessionUrl: undefined,
                replBridgeConnectUrl: undefined,
                replBridgeError: undefined
              };
            });
            logForDebugging(`[bridge:repl] Mirror initialized, session=${handle_0.bridgeSessionId}`);
          } else {
            // Build bridge permission callbacks so the interactive permission
            // handler can race bridge responses against local user interaction.
            const permissionCallbacks: BridgePermissionCallbacks = {
              sendRequest(requestId_0, toolName, input, toolUseId, description, permissionSuggestions, blockedPath) {
                handle_0.sendControlRequest({
                  type: 'control_request',
                  request_id: requestId_0,
                  request: {
                    subtype: 'can_use_tool',
                    tool_name: toolName,
                    input,
                    tool_use_id: toolUseId,
                    description,
                    ...(permissionSuggestions ? {
                      permission_suggestions: permissionSuggestions
                    } : {}),
                    ...(blockedPath ? {
                      blocked_path: blockedPath
                    } : {})
                  }
                });
              },
              sendResponse(requestId_1, response) {
                const payload: Record<string, unknown> = {
                  ...response
                };
                handle_0.sendControlResponse({
                  type: 'control_response',
                  response: {
                    subtype: 'success',
                    request_id: requestId_1,
                    response: payload
                  }
                });
              },
              cancelRequest(requestId_2) {
                handle_0.sendControlCancelRequest(requestId_2);
              },
              onResponse(requestId_3, handler_0) {
                pendingPermissionHandlers.set(requestId_3, handler_0);
                return () => {
                  pendingPermissionHandlers.delete(requestId_3);
                };
              }
            };
            setAppState(prev_16 => ({
              ...prev_16,
              replBridgePermissionCallbacks: permissionCallbacks
            }));
            const url = getRemoteSessionUrl(handle_0.bridgeSessionId, handle_0.sessionIngressUrl);
            // environmentId === '' signals the v2 env-less path. buildBridgeConnectUrl
            // builds an env-specific connect URL, which doesn't exist without an env.
            const hasEnv = handle_0.environmentId !== '';
            const connectUrl_0 = hasEnv ? buildBridgeConnectUrl(handle_0.environmentId, handle_0.sessionIngressUrl) : undefined;
            setAppState(prev_17 => {
              if (prev_17.replBridgeConnected && prev_17.replBridgeSessionUrl === url) {
                return prev_17;
              }
              return {
                ...prev_17,
                replBridgeConnected: true,
                replBridgeSessionUrl: url,
                replBridgeConnectUrl: connectUrl_0 ?? prev_17.replBridgeConnectUrl,
                replBridgeEnvironmentId: handle_0.environmentId,
                replBridgeSessionId: handle_0.bridgeSessionId,
                replBridgeError: undefined
              };
            });

            // Show bridge status with URL in the transcript. perpetual (KAIROS
            // assistant mode) falls back to v1 at initReplBridge.ts — skip the
            // v2-only upgrade nudge for them. Own try/catch so a cosmetic
            // GrowthBook hiccup doesn't hit the outer init-failure handler.
            const upgradeNudge = !perpetual ? await shouldShowAppUpgradeMessage().catch(() => false) : false;
            if (cancelled) return;
            setMessages(prev_18 => [...prev_18, createBridgeStatusMessage(url, upgradeNudge ? 'Please upgrade to the latest version of the Claude mobile app to see your Remote Control sessions.' : undefined)]);
            logForDebugging(`[bridge:repl] Hook initialized, session=${handle_0.bridgeSessionId}`);
          }
        } catch (err) {
          // Never crash the REPL — surface the error in the UI.
          // Check cancelled first (symmetry with the !handle path at line ~386):
          // if initReplBridge threw during rapid toggle-off (in-flight network
          // error), don't count that toward the fuse or spam a stale error
          // into the UI. Also fixes pre-existing spurious setAppState/
          // setMessages on cancelled throws.
          if (cancelled) return;
          consecutiveFailuresRef.current++;
          const errMsg = errorMessage(err);
          logForDebugging(`[bridge:repl] Init failed: ${errMsg}; consecutive failures: ${consecutiveFailuresRef.current}`);
          clearTimeout(failureTimeoutRef.current);
          notifyBridgeFailed(errMsg);
          setAppState(prev_0 => ({
            ...prev_0,
            replBridgeError: errMsg
          }));
          failureTimeoutRef.current = setTimeout(() => {
            if (cancelled) return;
            failureTimeoutRef.current = undefined;
            setAppState(prev_1 => {
              if (!prev_1.replBridgeError) return prev_1;
              return {
                ...prev_1,
                replBridgeEnabled: false,
                replBridgeError: undefined
              };
            });
          }, BRIDGE_FAILURE_DISMISS_MS);
          if (!outboundOnly) {
            setMessages(prev_2 => [...prev_2, createSystemMessage(`Remote Control failed to connect: ${errMsg}`, 'warning')]);
          }
        }
      })();
      return () => {
        cancelled = true;
        clearTimeout(failureTimeoutRef.current);
        failureTimeoutRef.current = undefined;
        if (handleRef.current) {
          logForDebugging(`[bridge:repl] Hook cleanup: starting teardown for env=${handleRef.current.environmentId} session=${handleRef.current.bridgeSessionId}`);
          teardownPromiseRef.current = handleRef.current.teardown();
          handleRef.current = null;
          setReplBridgeHandle(null);
        }
        setAppState(prev_19 => {
          if (!prev_19.replBridgeConnected && !prev_19.replBridgeSessionActive && !prev_19.replBridgeError) {
            return prev_19;
          }
          return {
            ...prev_19,
            replBridgeConnected: false,
            replBridgeSessionActive: false,
            replBridgeReconnecting: false,
            replBridgeConnectUrl: undefined,
            replBridgeSessionUrl: undefined,
            replBridgeEnvironmentId: undefined,
            replBridgeSessionId: undefined,
            replBridgeError: undefined,
            replBridgePermissionCallbacks: undefined
          };
        });
        lastWrittenIndexRef.current = 0;
      };
    }
  }, [replBridgeEnabled, replBridgeOutboundOnly, setAppState, setMessages, addNotification]);

  // Write new messages as they appear.
  // Also re-runs when replBridgeConnected changes (bridge finishes init),
  // so any messages that arrived before the bridge was ready get written.
  useEffect(() => {
    // Positive feature() guard — see first useEffect comment
    if (feature('BRIDGE_MODE')) {
      if (!replBridgeConnected) return;
      const handle_1 = handleRef.current;
      if (!handle_1) return;

      // Clamp the index in case messages were compacted (array shortened).
      // After compaction the ref could exceed messages.length, and without
      // clamping no new messages would be forwarded.
      if (lastWrittenIndexRef.current > messages.length) {
        logForDebugging(`[bridge:repl] Compaction detected: lastWrittenIndex=${lastWrittenIndexRef.current} > messages.length=${messages.length}, clamping`);
      }
      const startIndex = Math.min(lastWrittenIndexRef.current, messages.length);

      // Collect new messages since last write
      const newMessages: Message[] = [];
      for (let i = startIndex; i < messages.length; i++) {
        const msg_1 = messages[i];
        if (msg_1 && (msg_1.type === 'user' || msg_1.type === 'assistant' || msg_1.type === 'system' && msg_1.subtype === 'local_command')) {
          newMessages.push(msg_1);
        }
      }
      lastWrittenIndexRef.current = messages.length;
      if (newMessages.length > 0) {
        handle_1.writeMessages(newMessages);
      }
    }
  }, [messages, replBridgeConnected]);
  const sendBridgeResult = useCallback(() => {
    if (feature('BRIDGE_MODE')) {
      handleRef.current?.sendResult();
    }
  }, []);
  return {
    sendBridgeResult
  };
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJmZWF0dXJlIiwiUmVhY3QiLCJ1c2VDYWxsYmFjayIsInVzZUVmZmVjdCIsInVzZVJlZiIsInNldE1haW5Mb29wTW9kZWxPdmVycmlkZSIsIkJyaWRnZVBlcm1pc3Npb25DYWxsYmFja3MiLCJCcmlkZ2VQZXJtaXNzaW9uUmVzcG9uc2UiLCJpc0JyaWRnZVBlcm1pc3Npb25SZXNwb25zZSIsImJ1aWxkQnJpZGdlQ29ubmVjdFVybCIsImV4dHJhY3RJbmJvdW5kTWVzc2FnZUZpZWxkcyIsIkJyaWRnZVN0YXRlIiwiUmVwbEJyaWRnZUhhbmRsZSIsInNldFJlcGxCcmlkZ2VIYW5kbGUiLCJDb21tYW5kIiwiZ2V0U2xhc2hDb21tYW5kVG9vbFNraWxscyIsImlzQnJpZGdlU2FmZUNvbW1hbmQiLCJnZXRSZW1vdGVTZXNzaW9uVXJsIiwidXNlTm90aWZpY2F0aW9ucyIsIlBlcm1pc3Npb25Nb2RlIiwiU0RLTWVzc2FnZSIsIlNES0NvbnRyb2xSZXNwb25zZSIsIlRleHQiLCJnZXRGZWF0dXJlVmFsdWVfQ0FDSEVEX01BWV9CRV9TVEFMRSIsInVzZUFwcFN0YXRlIiwidXNlQXBwU3RhdGVTdG9yZSIsInVzZVNldEFwcFN0YXRlIiwiTWVzc2FnZSIsImdldEN3ZCIsImxvZ0ZvckRlYnVnZ2luZyIsImVycm9yTWVzc2FnZSIsImVucXVldWUi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6ZUluYm91bmRXZWJob29rQ29udGVudChmaWVsZHMuY29udGVudClcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBjb25zdCBjb250ZW50ID0gYXdhaXQgcmVzb2x2ZUFuZFByZXBlbmQobXNnLCBzYW5pdGl6ZWQpXG5cbiAgICAgICAgICAgICAgY29uc3QgcHJldmlldyA9XG4gICAgICAgICAgICAgICAgdHlwZW9mIGNvbnRlbnQgPT09ICdzdHJpbmcnXG4gICAgICAgICAgICAgICAgICA/IGNvbnRlbnQuc2xpY2UoMCwgODApXG4gICAgICAgICAgICAgICAgICA6IGBbJHtjb250ZW50Lmxlbmd0aH0gY29udGVudCBibG9ja3NdYFxuICAgICAgICAgICAgICBsb2dGb3JEZWJ1Z2dpbmcoXG4gICAgICAgICAgICAgICAgYFticmlkZ2U6cmVwbF0gSW5qZWN0aW5nIGluYm91bmQgdXNlciBtZXNzYWdlOiAke3ByZXZpZXd9JHt1dWlkID8gYCB1dWlkPSR7dXVpZH1gIDogJyd9YCxcbiAgICAgICAgICAgICAgKVxuICAgICAgICAgICAgICBlbnF1ZXVlKHtcbiAgICAgICAgICAgICAgICB2YWx1ZTogY29udGVudCxcbiAgICAgICAgICAgICAgICBtb2RlOiAncHJvbXB0JyBhcyBjb25zdCxcbiAgICAgICAgICAgICAgICB1dWlkLFxuICAgICAgICAgICAgICAgIC8vIHNraXBTbGFzaENvbW1hbmRzIHN0YXlzIHRydWUgYXMgZGVmZW5zZS1pbi1kZXB0aCDigJRcbiAgICAgICAgICAgICAgICAvLyBwcm9jZXNzVXNlcklucHV0QmFzZSBvdmVycmlkZXMgaXQgaW50ZXJuYWxseSB3aGVuIGJyaWRnZU9yaWdpblxuICAgICAgICAgICAgICAgIC8vIGlzIHNldCBBTkQgdGhlIHJlc29sdmVkIGNvbW1hbmQgcGFzc2VzIGlzQnJpZGdlU2FmZUNvbW1hbmQuXG4gICAgICAgICAgICAgICAgLy8gVGhpcyBrZWVwcyBleGl0LXdvcmQgc3VwcHJlc3Npb24gYW5kIGltbWVkaWF0ZS1jb21tYW5kIGJsb2Nrc1xuICAgICAgICAgICAgICAgIC8vIGludGFjdCBmb3IgYW55IGNvZGUgcGF0aCB0aGF0IGNoZWNrcyBza2lwU2xhc2hDb21tYW5kcyBkaXJlY3RseS5cbiAgICAgICAgICAgICAgICBza2lwU2xhc2hDb21tYW5kczogdHJ1ZSxcbiAgICAgICAgICAgICAgICBicmlkZ2VPcmlnaW46IHRydWUsXG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9IGNhdGNoIChlKSB7XG4gICAgICAgICAgICAgIGxvZ0ZvckRlYnVnZ2luZyhcbiAgICAgICAgICAgICAgICBgW2JyaWRnZTpyZXBsXSBoYW5kbGVJbmJvdW5kTWVzc2FnZSBmYWlsZWQ6ICR7ZX1gLFxuICAgICAgICAgICAgICAgIHsgbGV2ZWw6ICdlcnJvcicgfSxcbiAgICAgICAgICAgICAgKVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIC8vIFN0YXRlIGNoYW5nZSBjYWxsYmFjayDigJQgbWFwcyBicmlkZ2UgbGlmZWN5Y2xlIGV2ZW50cyB0byBBcHBTdGF0ZS5cbiAgICAgICAgICBmdW5jdGlvbiBoYW5kbGVTdGF0ZUNoYW5nZShcbiAgICAgICAgICAgIHN0YXRlOiBCcmlkZ2VTdGF0ZSxcbiAgICAgICAgICAgIGRldGFpbD86IHN0cmluZyxcbiAgICAgICAgICApOiB2b2lkIHtcbiAgICAgICAgICAgIGlmIChjYW5jZWxsZWQpIHJldHVyblxuICAgICAgICAgICAgaWYgKG91dGJvdW5kT25seSkge1xuICAgICAgICAgICAgICBsb2dGb3JEZWJ1Z2dpbmcoXG4gICAgICAgICAgICAgICAgYFticmlkZ2U6cmVwbF0gTWlycm9yIHN0YXRlPSR7c3RhdGV9JHtkZXRhaWwgPyBgIGRldGFpbD0ke2RldGFpbH1gIDogJyd9YCxcbiAgICAgICAgICAgICAgKVxuICAgICAgICAgICAgICAvLyBTeW5jIHJlcGxCcmlkZ2VDb25uZWN0ZWQgc28gdGhlIGZvcndhcmRpbmcgZWZmZWN0IHN0YXJ0cy9zdG9wc1xuICAgICAgICAgICAgICAvLyB3cml0aW5nIGFzIHRoZSB0cmFuc3BvcnQgY29tZXMgdXAgb3IgZGllcy5cbiAgICAgICAgICAgICAgaWYgKHN0YXRlID09PSAnZmFpbGVkJykge1xuICAgICAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICAgICAgaWYgKCFwcmV2LnJlcGxCcmlkZ2VDb25uZWN0ZWQpIHJldHVybiBwcmV2XG4gICAgICAgICAgICAgICAgICByZXR1cm4geyAuLi5wcmV2LCByZXBsQnJpZGdlQ29ubmVjdGVkOiBmYWxzZSB9XG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZSA9PT0gJ3JlYWR5JyB8fCBzdGF0ZSA9PT0gJ2Nvbm5lY3RlZCcpIHtcbiAgICAgICAgICAgICAgICBzZXRBcHBTdGF0ZShwcmV2ID0+IHtcbiAgICAgICAgICAgICAgICAgIGlmIChwcmV2LnJlcGxCcmlkZ2VDb25uZWN0ZWQpIHJldHVybiBwcmV2XG4gICAgICAgICAgICAgICAgICByZXR1cm4geyAuLi5wcmV2LCByZXBsQnJpZGdlQ29ubmVjdGVkOiB0cnVlIH1cbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHJldHVyblxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29uc3QgaGFuZGxlID0gaGFuZGxlUmVmLmN1cnJlbnRcbiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUpIHtcbiAgICAgICAgICAgICAgY2FzZSAncmVhZHknOlxuICAgICAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICAgICAgY29uc3QgY29ubmVjdFVybCA9XG4gICAgICAgICAgICAgICAgICAgIGhhbmRsZSAmJiBoYW5kbGUuZW52aXJvbm1lbnRJZCAhPT0gJydcbiAgICAgICAgICAgICAgICAgICAgICA/IGJ1aWxkQnJpZGdlQ29ubmVjdFVybChcbiAgICAgICAgICAgICAgICAgICAgICAgICAgaGFuZGxlLmVudmlyb25tZW50SWQsXG4gICAgICAgICAgICAgICAgICAgICAgICAgIGhhbmRsZS5zZXNzaW9uSW5ncmVzc1VybCxcbiAgICAgICAgICAgICAgICAgICAgICAgIClcbiAgICAgICAgICAgICAgICAgICAgICA6IHByZXYucmVwbEJyaWRnZUNvbm5lY3RVcmxcbiAgICAgICAgICAgICAgICAgIGNvbnN0IHNlc3Npb25VcmwgPSBoYW5kbGVcbiAgICAgICAgICAgICAgICAgICAgPyBnZXRSZW1vdGVTZXNzaW9uVXJsKFxuICAgICAgICAgICAgICAgICAgICAgICAgaGFuZGxlLmJyaWRnZVNlc3Npb25JZCxcbiAgICAgICAgICAgICAgICAgICAgICAgIGhhbmRsZS5zZXNzaW9uSW5ncmVzc1VybCxcbiAgICAgICAgICAgICAgICAgICAgICApXG4gICAgICAgICAgICAgICAgICAgIDogcHJldi5yZXBsQnJpZGdlU2Vzc2lvblVybFxuICAgICAgICAgICAgICAgICAgY29uc3QgZW52SWQgPSBoYW5kbGU/LmVudmlyb25tZW50SWRcbiAgICAgICAgICAgICAgICAgIGNvbnN0IHNlc3Npb25JZCA9IGhhbmRsZT8uYnJpZGdlU2Vzc2lvbklkXG4gICAgICAgICAgICAgICAgICBpZiAoXG4gICAgICAgICAgICAgICAgICAgIHByZXYucmVwbEJyaWRnZUNvbm5lY3RlZCAmJlxuICAgICAgICAgICAgICAgICAgICAhcHJldi5yZXBsQnJpZGdlU2Vzc2lvbkFjdGl2ZSAmJlxuICAgICAgICAgICAgICAgICAgICAhcHJldi5yZXBsQnJpZGdlUmVjb25uZWN0aW5nICYmXG4gICAgICAgICAgICAgICAgICAgIHByZXYucmVwbEJyaWRnZUNvbm5lY3RVcmwgPT09IGNvbm5lY3RVcmwgJiZcbiAgICAgICAgICAgICAgICAgICAgcHJldi5yZXBsQnJpZGdlU2Vzc2lvblVybCA9PT0gc2Vzc2lvblVybCAmJlxuICAgICAgICAgICAgICAgICAgICBwcmV2LnJlcGxCcmlkZ2VFbnZpcm9ubWVudElkID09PSBlbnZJZCAmJlxuICAgICAgICAgICAgICAgICAgICBwcmV2LnJlcGxCcmlkZ2VTZXNzaW9uSWQgPT09IHNlc3Npb25JZFxuICAgICAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybiBwcmV2XG4gICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgICAgICAuLi5wcmV2LFxuICAgICAgICAgICAgICAgICAgICByZXBsQnJpZGdlQ29ubmVjdGVkOiB0cnVlLFxuICAgICAgICAgICAgICAgICAgICByZXBsQnJpZGdlU2Vzc2lvbkFjdGl2ZTogZmFsc2UsXG4gICAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VSZWNvbm5lY3Rpbmc6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICByZXBsQnJpZGdlQ29ubmVjdFVybDogY29ubmVjdFVybCxcbiAgICAgICAgICAgICAgICAgICAgcmVwbEJyaWRnZVNlc3Npb25Vcmw6IHNlc3Npb25VcmwsXG4gICAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VFbnZpcm9ubWVudElkOiBlbnZJZCxcbiAgICAgICAgICAgICAgICAgICAgcmVwbEJyaWRnZVNlc3Npb25JZDogc2Vzc2lvbklkLFxuICAgICAgICAgICAgICAgICAgICByZXBsQnJpZGdlRXJyb3I6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgIGJyZWFrXG4gICAgICAgICAgICAgIGNhc2UgJ2Nvbm5lY3RlZCc6IHtcbiAgICA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dGUgdHJhbnNpdGlvbiBpc24ndCBibG9ja2VkLlxuICAgICAgICAgICAgICAgIGlmIChcbiAgICAgICAgICAgICAgICAgIGdldEZlYXR1cmVWYWx1ZV9DQUNIRURfTUFZX0JFX1NUQUxFKFxuICAgICAgICAgICAgICAgICAgICAndGVuZ3VfYnJpZGdlX3N5c3RlbV9pbml0JyxcbiAgICAgICAgICAgICAgICAgICAgZmFsc2UsXG4gICAgICAgICAgICAgICAgICApXG4gICAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgICB2b2lkIChhc3luYyAoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc2tpbGxzID0gYXdhaXQgZ2V0U2xhc2hDb21tYW5kVG9vbFNraWxscyhnZXRDd2QoKSlcbiAgICAgICAgICAgICAgICAgICAgICBpZiAoY2FuY2VsbGVkKSByZXR1cm5cbiAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGF0ZSA9IHN0b3JlLmdldFN0YXRlKClcbiAgICAgICAgICAgICAgICAgICAgICBoYW5kbGVSZWYuY3VycmVudD8ud3JpdGVTZGtNZXNzYWdlcyhbXG4gICAgICAgICAgICAgICAgICAgICAgICBidWlsZFN5c3RlbUluaXRNZXNzYWdlKHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gdG9vbHMvbWNwQ2xpZW50cy9wbHVnaW5zIHJlZGFjdGVkIGZvciBSRVBMLWJyaWRnZTpcbiAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gTUNQLXByZWZpeGVkIHRvb2wgbmFtZXMgYW5kIHNlcnZlciBuYW1lcyBsZWFrIHdoaWNoXG4gICAgICAgICAgICAgICAgICAgICAgICAgIC8vIGludGVncmF0aW9ucyB0aGUgdXNlciBoYXMgd2lyZWQgdXA7IHBsdWdpbiBwYXRocyBsZWFrXG4gICAgICAgICAgICAgICAgICAgICAgICAgIC8vIHJhdyBmaWxlc3lzdGVtIHBhdGhzICh1c2VybmFtZSwgcHJvamVjdCBzdHJ1Y3R1cmUpLlxuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBDQ1IgdjIgcGVyc2lzdHMgU0RLIG1lc3NhZ2VzIHRvIFNwYW5uZXIg4oCUIHVzZXJzIHdob1xuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyB0YXAgXCJDb25uZWN0IGZyb20gcGhvbmVcIiBtYXkgbm90IGV4cGVjdCB0aGVzZSBvblxuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBBbnRocm9waWMncyBzZXJ2ZXJzLiBRdWVyeUVuZ2luZSAoU0RLKSBzdGlsbCBlbWl0c1xuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBmdWxsIGxpc3RzIOKAlCBTREsgY29uc3VtZXJzIGV4cGVjdCBmdWxsIHRlbGVtZXRyeS5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgdG9vbHM6IFtdLFxuICAgICAgICAgICAgICAgICAgICAgICAgICBtY3BDbGllbnRzOiBbXSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgbW9kZWw6IG1haW5Mb29wTW9kZWxSZWYuY3VycmVudCxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVybWlzc2lvbk1vZGU6IHN0YXRlLnRvb2xQZXJtaXNzaW9uQ29udGV4dFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC5tb2RlIGFzIFBlcm1pc3Npb25Nb2RlLCAvLyBUT0RPOiBhdm9pZCB0aGUgY2FzdFxuICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBSZW1vdGUgY2xpZW50cyBjYW4gb25seSBpbnZva2UgYnJpZGdlLXNhZmUgY29tbWFuZHMg4oCUXG4gICAgICAgICAgICAgICAgICAgICAgICAgIC8vIGFkdmVydGlzaW5nIHVuc2FmZSBvbmVzIChsb2NhbC1qc3gsIHVuYWxsb3dlZCBsb2NhbClcbiAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gd291bGQgbGV0IG1vYmlsZS93ZWIgYXR0ZW1wdCB0aGVtIGFuZCBoaXQgZXJyb3JzLlxuICAgICAgICAgICAgICAgICAgICAgICAgICBjb21tYW5kczpcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb21tYW5kc1JlZi5jdXJyZW50LmZpbHRlcihpc0JyaWRnZVNhZmVDb21tYW5kKSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgYWdlbnRzOiBzdGF0ZS5hZ2VudERlZmluaXRpb25zLmFjdGl2ZUFnZW50cyxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgc2tpbGxzLFxuICAgICAgICAgICAgICAgICAgICAgICAgICBwbHVnaW5zOiBbXSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgZmFzdE1vZGU6IHN0YXRlLmZhc3RNb2RlLFxuICAgICAgICAgICAgICAgICAgICAgICAgfSksXG4gICAgICAgICAgICAgICAgICAgICAgXSlcbiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgbG9nRm9yRGVidWdnaW5nKFxuICAgICAgICAgICAgICAgICAgICAgICAgYFticmlkZ2U6cmVwbF0gRmFpbGVkIHRvIHNlbmQgc3lzdGVtL2luaXQ6ICR7ZXJyb3JNZXNzYWdlKGVycil9YCxcbiAgICAgICAgICAgICAgICAgICAgICAgIHsgbGV2ZWw6ICdlcnJvcicgfSxcbiAgICAgICAgICAgICAgICAgICAgICApXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgIH0pKClcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgYnJlYWtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICBjYXNlICdyZWNvbm5lY3RpbmcnOlxuICAgICAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICAgICAgaWYgKHByZXYucmVwbEJyaWRnZVJlY29ubmVjdGluZykgcmV0dXJuIHByZXZcbiAgICAgICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VSZWNvbm5lY3Rpbmc6IHRydWUsXG4gICAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VTZXNzaW9uQWN0aXZlOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgIGJyZWFrXG4gICAgICAgICAgICAgIGNhc2UgJ2ZhaWxlZCc6XG4gICAgICAgICAgICAgICAgLy8gQ2xlYXIgYW55IHByZXZpb3VzIGZhaWx1cmUgZGlzbWlzcyB0aW1lclxuICAgICAgICAgICAgICAgIGNsZWFyVGltZW91dChmYWlsdXJlVGltZW91dFJlZi5jdXJyZW50KVxuICAgICAgICAgICAgICAgIG5vdGlmeUJyaWRnZUZhaWxlZChkZXRhaWwpXG4gICAgICAgICAgICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiAoe1xuICAgICAgICAgICAgICAgICAgLi4ucHJldixcbiAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VFcnJvcjogZGV0YWlsLFxuICAgICAgICAgICAgICAgICAgcmVwbEJyaWRnZVJlY29ubmVjdGluZzogZmFsc2UsXG4gICAgICAgICAgICAgICAgICByZXBsQnJpZGdlU2Vzc2lvbkFjdGl2ZTogZmFsc2UsXG4gICAgICAgICAgICAgICAgICByZXBsQnJpZGdlQ29ubmVjdGVkOiBmYWxzZSxcbiAgICAgICAgICAgICAgICB9KSlcbiAgICAgICAgICAgICAgICAvLyBBdXRvLWRpc2FibGUgYWZ0ZXIgdGltZW91dCBzbyB0aGUgaG9vayBzdG9wcyByZXRyeWluZy5cbiAgICAgICAgICAgICAgICBmYWlsdXJlVGltZW91dFJlZi5jdXJyZW50ID0gc2V0VGltZW91dCgoKSA9PiB7XG4gICAgICAgICAgICAgICAgICBpZiAoY2FuY2VsbGVkKSByZXR1cm5cbiAgICAgICAgICAgICAgICAgIGZhaWx1cmVUaW1lb3V0UmVmLmN1cnJlbnQgPSB1bmRlZmluZWRcbiAgICAgICAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoIXByZXYucmVwbEJyaWRnZUVycm9yKSByZXR1cm4gcHJldlxuICAgICAgICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgICAgICAgICAgICAgcmVwbEJyaWRnZUVuYWJsZWQ6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VFcnJvcjogdW5kZWZpbmVkLFxuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgIH0sIEJSSURHRV9GQUlMVVJFX0RJU01JU1NfTVMpXG4gICAgICAgICAgICAgICAgYnJlYWtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG5cbiAgICAgICAgICAvLyBNYXAgb2YgcGVuZGluZyBicmlkZ2UgcGVybWlzc2lvbiByZXNwb25zZSBoYW5kbGVycywga2V5ZWQgYnkgcmVxdWVzdF9pZC5cbiAgICAgICAgICAvLyBFYWNoIGVudHJ5IGlzIGFuIG9uUmVzcG9uc2UgaGFuZGxlciB3YWl0aW5nIGZvciBDQ1IgdG8gcmVwbHkuXG4gICAgICAgICAgY29uc3QgcGVuZGluZ1Blcm1pc3Npb25IYW5kbGVycyA9IG5ldyBNYXA8XG4gICAgICAgICAgICBzdHJpbmcsXG4gICAgICAgICAgICAocmVzcG9uc2U6IEJyaWRnZVBlcm1pc3Npb25SZXNwb25zZSkgPT4gdm9pZFxuICAgICAgICAgID4oKVxuXG4gICAgICAgICAgLy8gRGlzcGF0Y2ggaW5jb21pbmcgY29udHJvbF9yZXNwb25zZSBtZXNzYWdlcyB0byByZWdpc3RlcmVkIGhhbmRsZXJzXG4gICAgICAgICAgZnVuY3Rpb24gaGFuZGxlUGVybWlzc2lvblJlc3BvbnNlKG1zZzogU0RLQ29udHJvbFJlc3BvbnNlKTogdm9pZCB7XG4gICAgICAgICAgICBjb25zdCByZXF1ZXN0SWQgPSBtc2cucmVzcG9uc2U/LnJlcXVlc3RfaWRcbiAgICAgICAgICAgIGlmICghcmVxdWVzdElkKSByZXR1cm5cbiAgICAgICAgICAgIGNvbnN0IGhhbmRsZXIgPSBwZW5kaW5nUGVybWlzc2lvbkhhbmRsZXJzLmdldChyZXF1ZXN0SWQpXG4gICAgICAgICAgICBpZiAoIWhhbmRsZXIpIHtcbiAgICAgICAgICAgICAgbG9nRm9yRGVidWdnaW5nKFxuICAgICAgICAgICAgICAgIGBbYnJpZGdlOnJlcGxdIE5vIGhhbmRsZXIgZm9yIGNvbnRyb2xfcmVzcG9uc2UgcmVxdWVzdF9pZD0ke3JlcXVlc3RJZH1gLFxuICAgICAgICAgICAgICApXG4gICAgICAgICAgICAgIHJldHVyblxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcGVuZGluZ1Blcm1pc3Npb25IYW5kbGVycy5kZWxldGUocmVxdWVzdElkKVxuICAgICAgICAgICAgLy8gRXh0cmFjdCB0aGUgcGVybWlzc2lvbiBkZWNpc2lvbiBmcm9tIHRoZSBjb250cm9sX3Jlc3BvbnNlIHBheWxvYWRcbiAgICAgICAgICAgIGNvbnN0IGlubmVyID0gbXNnLnJlc3BvbnNlXG4gICAgICAgICAgICBpZiAoXG4gICAgICAgICAgICAgIGlubmVyLnN1YnR5cGUgPT09ICdzdWNjZXNzJyAmJlxuICAgICAgICAgICAgICBpbm5lci5yZXNwb25zZSAmJlxuICAgICAgICAgICAgICBpc0JyaWRnZVBlcm1pc3Npb25SZXNwb25zZShpbm5lci5yZXNwb25zZSlcbiAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICBoYW5kbGVyKGlubmVyLnJlc3BvbnNlKVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cblxuICAgICAgICAgIGNvbnN0IGhhbmRsZSA9IGF3YWl0IGluaXRSZXBsQnJpZGdlKHtcbiAgICAgICAgICAgIG91dGJvdW5kT25seSxcbiAgICAgICAgICAgIHRhZ3M6IG91dGJvdW5kT25seSA/IFsnY2NyLW1pcnJvciddIDogdW5kZWZpbmVkLFxuICAgICAgICAgICAgb25JbmJvdW5kTWVzc2FnZTogaGFuZGxlSW5ib3VuZE1lc3NhZ2UsXG4gICAgICAgICAgICBvblBlcm1pc3Npb25SZXNwb25zZTogaGFuZGxlUGVybWlzc2lvblJlc3BvbnNlLFxuICAgICAgICAgICAgb25JbnRlcnJ1cHQoKSB7XG4gICAgICAgICAgICAgIGFib3J0Q29udHJvbGxlclJlZi5jdXJyZW50Py5hYm9ydCgpXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgb25TZXRNb2RlbChtb2RlbCkge1xuICAgICAgICAgICAgICBjb25zdCByZXNvbHZlZCA9IG1vZGVsID09PSAnZGVmYXVsdCcgPyBudWxsIDogKG1vZGVsID8/IG51bGwpXG4gICAgICAgICAgICAgIHNldE1haW5Mb29wTW9kZWxPdmVycmlkZShyZXNvbHZlZClcbiAgICAgICAgICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKHByZXYubWFpbkxvb3BNb2RlbEZvclNlc3Npb24gPT09IHJlc29sdmVkKSByZXR1cm4gcHJldlxuICAgICAgICAgICAgICAgIHJldHVybiB7IC4uLnByZXYsIG1haW5Mb29wTW9kZWxGb3JTZXNzaW9uOiByZXNvbHZlZCB9XG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgb25TZXRNYXhUaGlua2luZ1Rva2VucyhtYXhUb2tlbnMpIHtcbiAgICAgICAgICAgICAgY29uc3QgZW5hYmxlZCA9IG1heFRva2VucyAhPT0gbnVsbFxuICAgICAgICAgICAgICBzZXRBcHBTdGF0ZShwcmV2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4ndCBpbXBvcnQgdGhlIGNoZWNrcyBkaXJlY3RseSAoYm9vdHN0cmFwLWlzb2xhdGlvbiksIHNvXG4gICAgICAgICAgICAgIC8vIGl0IHJlbGllcyBvbiB0aGlzIHZlcmRpY3QgdG8gZW1pdCB0aGUgZXJyb3IgcmVzcG9uc2UuXG4gICAgICAgICAgICAgIGlmIChtb2RlID09PSAnYnlwYXNzUGVybWlzc2lvbnMnKSB7XG4gICAgICAgICAgICAgICAgaWYgKGlzQnlwYXNzUGVybWlzc2lvbnNNb2RlRGlzYWJsZWQoKSkge1xuICAgICAgICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgICAgICAgb2s6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICBlcnJvcjpcbiAgICAgICAgICAgICAgICAgICAgICAnQ2Fubm90IHNldCBwZXJtaXNzaW9uIG1vZGUgdG8gYnlwYXNzUGVybWlzc2lvbnMgYmVjYXVzZSBpdCBpcyBkaXNhYmxlZCBieSBzZXR0aW5ncyBvciBjb25maWd1cmF0aW9uJyxcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaWYgKFxuICAgICAgICAgICAgICAgICAgIXN0b3JlLmdldFN0YXRlKCkudG9vbFBlcm1pc3Npb25Db250ZXh0XG4gICAgICAgICAgICAgICAgICAgIC5pc0J5cGFzc1Blcm1pc3Npb25zTW9kZUF2YWlsYWJsZVxuICAgICAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgICAgICAgb2s6IGZhbHNlLFxuICAgICAgICAgICAgICAgICAgICBlcnJvcjpcbiAgICAgICAgICAgICAgICAgICAgICAnQ2Fubm90IHNldCBwZXJtaXNzaW9uIG1vZGUgdG8gYnlwYXNzUGVybWlzc2lvbnMgYmVjYXVzZSB0aGUgc2Vzc2lvbiB3YXMgbm90IGxhdW5jaGVkIHdpdGggLS1kYW5nZXJvdXNseS1za2lwLXBlcm1pc3Npb25zJyxcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgaWYgKFxuICAgICAgICAgICAgICAgIGZlYXR1cmUoJ1RSQU5TQ1JJUFRfQ0xBU1NJRklFUicpICYmXG4gICAgICAgICAgICAgICAgbW9kZSA9PT0gJ2F1dG8nICYmXG4gICAgICAgICAgICAgICAgIWlzQXV0b01vZGVHYXRlRW5hYmxlZCgpXG4gICAgICAgICAgICAgICkge1xuICAgICAgICAgICAgICAgIGNvbnN0IHJlYXNvbiA9IGdldEF1dG9Nb2RlVW5hdmFpbGFibGVSZWFzb24oKVxuICAgICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgICBvazogZmFsc2UsXG4gICAgICAgICAgICAgICAgICBlcnJvcjogcmVhc29uXG4gICAgICAgICAgICAgICAgICAgID8gYENhbm5vdCBzZXQgcGVybWlzc2lvbiBtb2RlIHRvIGF1dG86ICR7Z2V0QXV0b01vZGVVbmF2YWlsYWJsZU5vdGlmaWNhdGlvbihyZWFzb24pfWBcbiAgICAgICAgICAgICAgICAgICAgOiAnQ2Fubm90IHNldCBwZXJtaXNzaW9uIG1vZGUgdG8gYXV0bycsXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIC8vIEd1YXJkcyBwYXNzZWQg4oCUIGFwcGx5IHZpYSB0aGUgY2VudHJhbGl6ZWQgdHJhbnNpdGlvbiBzb1xuICAgICAgICAgICAgICAvLyBwcmVQbGFuTW9kZSBzdGFzaGluZyBhbmQgYXV0by1tb2RlIHN0YXRlIHN5bmMgYWxsIGZpcmUuXG4gICAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICAgIGNvbnN0IGN1cnJlbnQgPSBwcmV2LnRvb2xQZXJtaXNzaW9uQ29udGV4dC5tb2RlXG4gICAgICAgICAgICAgICAgaWYgKGN1cnJlbnQgPT09IG1vZGUpIHJldHVybiBwcmV2XG4gICAgICAgICAgICAgICAgY29uc3QgbmV4dCA9IHRyYW5zaXRpb25QZXJtaXNzaW9uTW9kZShcbiAgICAgICAgICAgICAgICAgIGN1cnJlbnQsXG4gICAgICAgICAgICAgICAgICBtb2RlLFxuICAgICAgICAgICAgICAgICAgcHJldi50b29sUGVybWlzc2lvbkNvbnRleHQsXG4gICAgICAgICAgICAgICAgKVxuICAgICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgICAuLi5wcmV2LFxuICAgICAgICAgICAgICAgICAgdG9vbFBlcm1pc3Npb25Db250ZXh0OiB7IC4uLm5leHQsIG1vZGUgfSxcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0pXG4gICAgICAgICAgICAgIC8vIFJlY2hlY2sgcXVldWVkIHBlcm1pc3Npb24gcHJvbXB0cyBub3cgdGhhdCBtb2RlIGNoYW5nZWQuXG4gICAgICAgICAgICAgIHNldEltbWVkaWF0ZSgoKSA9PiB7XG4gICAgICAgICAgICAgICAgZ2V0TGVhZGVyVG9vbFVzZUNvbmZpcm1RdWV1ZSgpPy4oY3VycmVudFF1ZXVlID0+IHtcbiAgICAgICAgICAgICAgICAgIGN1cnJlbnRRdWV1ZS5mb3JFYWNoKGl0ZW0gPT4ge1xuICAgICAgICAgICAgICAgICAgICB2b2lkIGl0ZW0ucmVjaGVja1Blcm1pc3Npb24oKVxuICAgICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgICAgIHJldHVybiBjdXJyZW50UXVldWVcbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICByZXR1cm4geyBvazogdHJ1ZSB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgb25TdGF0ZUNoYW5nZTogaGFuZGxlU3RhdGVDaGFuZ2UsXG4gICAgICAgICAgICBpbml0aWFsTWVzc2FnZ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gICAgICAgICAgICAgaWYgKGNhbmNlbGxlZCkgcmV0dXJuXG4gICAgICAgICAgICAgIGZhaWx1cmVUaW1lb3V0UmVmLmN1cnJlbnQgPSB1bmRlZmluZWRcbiAgICAgICAgICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCFwcmV2LnJlcGxCcmlkZ2VFcnJvcikgcmV0dXJuIHByZXZcbiAgICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgICAgLi4ucHJldixcbiAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VFbmFibGVkOiBmYWxzZSxcbiAgICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VFcnJvcjogdW5kZWZpbmVkLFxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0sIEJSSURHRV9GQUlMVVJFX0RJU01JU1NfTVMpXG4gICAgICAgICAgICByZXR1cm5cbiAgICAgICAgICB9XG4gICAgICAgICAgaGFuZGxlUmVmLmN1cnJlbnQgPSBoYW5kbGVcbiAgICAgICAgICBzZXRSZXBsQnJpZGdlSGFuZGxlKGhhbmRsZSlcbiAgICAgICAgICBjb25zZWN1dGl2ZUZhaWx1cmVzUmVmLmN1cnJlbnQgPSAwXG4gICAgICAgICAgLy8gU2tpcCBpbml0aWFsIG1lc3NhZ2VzIGluIHRoZSBmb3J3YXJkaW5nIGVmZmVjdCDigJQgdGhleSB3ZXJlXG4gICAgICAgICAgLy8gYWxyZWFkeSBsb2FkZWQgYXMgc2Vzc2lvbiBldmVudHMgZHVyaW5nIGNyZWF0aW9uLlxuICAgICAgICAgIGxhc3RXcml0dGVuSW5kZXhSZWYuY3VycmVudCA9IGluaXRpYWxNZXNzYWdlQ291bnRcblxuICAgICAgICAgIGlmIChvdXRib3VuZE9ubHkpIHtcbiAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICBpZiAoXG4gICAgICAgICAgICAgICAgcHJldi5yZXBsQnJpZGdlQ29ubmVjdGVkICYmXG4gICAgICAgICAgICAgICAgcHJldi5yZXBsQnJpZGdlU2Vzc2lvbklkID09PSBoYW5kbGUuYnJpZGdlU2Vzc2lvbklkXG4gICAgICAgICAgICAgIClcbiAgICAgICAgICAgICAgICByZXR1cm4gcHJldlxuICAgICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgICAgICAgcmVwbEJyaWRnZUNvbm5lY3RlZDogdHJ1ZSxcbiAgICAgICAgICAgICAgICByZXBsQnJpZGdlU2Vzc2lvbklkOiBoYW5kbGUuYnJpZGdlU2Vzc2lvbklkLFxuICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VTZXNzaW9uVXJsOiB1bmRlZmluZWQsXG4gICAgICAgICAgICAgICAgcmVwbEJyaWRnZUNvbm5lY3RVcmw6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgICAgICByZXBsQnJpZGdlRXJyb3I6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIGxvZ0ZvckRlYnVnZ2luZyhcbiAgICAgICAgICAgICAgYFticmlkZ2U6cmVwbF0gTWlycm9yIGluaXRpYWxpemVkLCBzZXNzaW9uPSR7aGFuZGxlLmJyaWRnZVNlc3Npb25JZH1gLFxuICAgICAgICAgICAgKVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAvLyBCdWlsZCBicmlkZ2UgcGVybWlzc2lvbiBjYWxsYmFja3Mgc28gdGhlIGludGVyYWN0aXZlIHBlcm1pc3Npb25cbiAgICAgICAgICAgIC8vIGhhbmRsZXIgY2FuIHJhY2UgYnJpZGdlIHJlc3BvbnNlcyBhZ2FpbnN0IGxvY2FsIHVzZXIgaW50ZXJhY3Rpb24uXG4gICAgICAgICAgICBjb25zdCBwZXJtaXNzaW9uQ2FsbGJhY2tzOiBCcmlkZ2VQZXJtaXNzaW9uQ2FsbGJhY2tzID0ge1xuICAgICAgICAgICAgICBzZW5kUmVxdWVzdChcbiAgICAgICAgICAgICAgICByZXF1ZXN0SWQsXG4gICAgICAgICAgICAgICAgdG9vbE5hbWUsXG4gICAgICAgICAgICAgICAgaW5wdXQsXG4gICAgICAgICAgICAgICAgdG9vbFVzZUlkLFxuICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uLFxuICAgICAgICAgICAgICAgIHBlcm1pc3Npb25TdWdnZXN0aW9ucyxcbiAgICAgICAgICAgICAgICBibG9ja2VkUGF0aCxcbiAgICAgICAgICAgICAgKSB7XG4gICAgICAgICAgICAgICAgaGFuZGxlLnNlbmRDb250cm9sUmVxdWVzdCh7XG4gICAgICAgICAgICAgICAgICB0eXBlOiAnY29udHJvbF9yZXF1ZXN0JyxcbiAgICAgICAgICAgICAgICAgIHJlcXVlc3RfaWQ6IHJlcXVlc3RJZCxcbiAgICAgICAgICAgICAgICAgIHJlcXVlc3Q6IHtcbiAgICAgICAgICAgICAgICAgICAgc3VidHlwZTogJ2Nhbl91c2VfdG9vbCcsXG4gICAgICAgICAgICAgICAgICAgIHRvb2xfbmFtZTogdG9vbE5hbWUsXG4gICAgICAgICAgICAgICAgICAgIGlucHV0LFxuICAgICAgICAgICAgICAgICAgICB0b29sX3VzZV9pZDogdG9vbFVzZUlkLFxuICAgICAgICAgICAgICAgICAgICBkZXNjcmlwdGlvbixcbiAgICAgICAgICAgICAgICAgICAgLi4uKHBlcm1pc3Npb25TdWdnZXN0aW9uc1xuICAgICAgICAgICAgICAgICAgICAgID8geyBwZXJtaXNzaW9uX3N1Z2dlc3Rpb25zOiBwZXJtaXNzaW9uU3VnZ2VzdGlvbnMgfVxuICAgICAgICAgICAgICAgICAgICAgIDoge30pLFxuICAgICAgICAgICAgICAgICAgICAuLi4oYmxvY2tlZFBhdGggPyB7IGJsb2NrZWRfcGF0aDogYmxvY2tlZFBhdGggfSA6IHt9KSxcbiAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgc2VuZFJlc3BvbnNlKHJlcXVlc3RJZCwgcmVzcG9uc2UpIHtcbiAgICAgICAgICAgICAgICBjb25zdCBwYXlsb2FkOiBSZWNvcmQ8c3RyaW5nLCB1bmtub3duPiA9IHsgLi4ucmVzcG9uc2UgfVxuICAgICAgICAgICAgICAgIGhhbmRsZS5zZW5kQ29udHJvbFJlc3BvbnNlKHtcbiAgICAgICAgICAgICAgICAgIHR5cGU6ICdjb250cm9sX3Jlc3BvbnNlJyxcbiAgICAgICAgICAgICAgICAgIHJlc3BvbnNlOiB7XG4gICAgICAgICAgICAgICAgICAgIHN1YnR5cGU6ICdzdWNjZXNzJyxcbiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdF9pZDogcmVxdWVzdElkLFxuICAgICAgICAgICAgICAgICAgICByZXNwb25zZTogcGF5bG9hZCxcbiAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgY2FuY2VsUmVxdWVzdChyZXF1ZXN0SWQpIHtcbiAgICAgICAgICAgICAgICBoYW5kbGUuc2VuZENvbnRyb2xDYW5jZWxSZXF1ZXN0KHJlcXVlc3RJZClcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgb25SZXNwb25zZShyZXF1ZXN0SWQsIGhhbmRsZXIpIHtcbiAgICAgICAgICAgICAgICBwZW5kaW5nUGVybWlzc2lvbkhhbmRsZXJzLnNldChyZXF1ZXN0SWQsIGhhbmRsZXIpXG4gICAgICAgICAgICAgICAgcmV0dXJuICgpID0+IHtcbiAgICAgICAgICAgICAgICAgIHBlbmRpbmdQZXJtaXNzaW9uSGFuZGxlcnMuZGVsZXRlKHJlcXVlc3RJZClcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgIC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ICAgIHByZXYucmVwbEJyaWRnZVNlc3Npb25VcmwgPT09IHVybFxuICAgICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gcHJldlxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgLi4ucHJldixcbiAgICAgICAgICAgICAgICByZXBsQnJpZGdlQ29ubmVjdGVkOiB0cnVlLFxuICAgICAgICAgICAgICAgIHJlcGxCcmlkZ2VTZXNzaW9uVXJsOiB1cmwsXG4gICAgICAgICAgICAgICAgcmVwbEJyaWRnZUNvbm5lY3RVcmw6IGNvbm5lY3RVcmwgPz8gcHJldi5yZXBsQnJpZGdlQ29ubmVjdFVybCxcbiAgICAgICAgICAgICAgICByZXBsQnJpZGdlRW52aXJvbm1lbnRJZDogaGFuZGxlLmVudmlyb25tZW50SWQsXG4gICAgICAgICAgICAgICAgcmVwbEJyaWRnZVNlc3Npb25JZDogaGFuZGxlLmJyaWRnZVNlc3Npb25JZCxcbiAgICAgICAgICAgICAgICByZXBsQnJpZGdlRXJyb3I6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSlcblxuICAgICAgICAgICAgLy8gU2hvdyBicmlkZ2Ugc3RhdHVzIHdpdGggVVJMIGluIHRoZSB0cmFuc2NyaXB0LiBwZXJwZXR1YWwgKEtBSVJPU1xuICAgICAgICAgICAgLy8gYXNzaXN0YW50IG1vZGUpIGZhbGxzIGJhY2sgdG8gdjEgYXQgaW5pdFJlcGxCcmlkZ2UudHMg4oCUIHNraXAgdGhlXG4gICAgICAgICAgICAvLyB2Mi1vbmx5IHVwZ3JhZGUgbnVkZ2UgZm9yIHRoZW0uIE93biB0cnkvY2F0Y2ggc28gYSBjb3NtZXRpY1xuICAgICAgICAgICAgLy8gR3Jvd3RoQm9vayBoaWNjdXAgZG9lc24ndCBoaXQgdGhlIG91dGVyIGluaXQtZmFpbHVyZSBoYW5kbGVyLlxuICAgICA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yblxuICAgICAgICAgICAgZmFpbHVyZVRpbWVvdXRSZWYuY3VycmVudCA9IHVuZGVmaW5lZFxuICAgICAgICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiB7XG4gICAgICAgICAgICAgIGlmICghcHJldi5yZXBsQnJpZGdlRXJyb3IpIHJldHVybiBwcmV2XG4gICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgLi4ucHJldixcbiAgICAgICAgICAgICAgICByZXBsQnJpZGdlRW5hYmxlZDogZmFsc2UsXG4gICAgICAgICAgICAgICAgcmVwbEJyaWRnZUVycm9yOiB1bmRlZmluZWQsXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgICAgICAgfSwgQlJJREdFX0ZBSUxVUkVfRElTTUlTU19NUylcbiAgICAgICAgICBpZiAoIW91dGJvdW5kT25seSkge1xuICAgICAgICAgICAgc2V0TWVzc2FnZXMocHJldiA9PiBbXG4gICAgICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgICAgIGNyZWF0ZVN5c3RlbU1lc3NhZ2UoXG4gICAgICAgICAgICAgICAgYFJlbW90ZSBDb250cm9sIGZhaWxlZCB0byBjb25uZWN0OiAke2Vyck1zZ31gLFxuICAgICAgICAgICAgICAgICd3YXJuaW5nJyxcbiAgICAgICAgICAgICAgKSxcbiAgICAgICAgICAgIF0pXG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9KSgpXG5cbiAgICAgIHJldHVybiAoKSA9PiB7XG4gICAgICAgIGNhbmNlbGxlZCA9IHRydWVcbiAgICAgICAgY2xlYXJUaW1lb3V0KGZhaWx1cmVUaW1lb3V0UmVmLmN1cnJlbnQpXG4gICAgICAgIGZhaWx1cmVUaW1lb3V0UmVmLmN1cnJlbnQgPSB1bmRlZmluZWRcbiAgICAgICAgaWYgKGhhbmRsZVJlZi5jdXJyZW50KSB7XG4gICAgICAgICAgbG9nRm9yRGVidWdnaW5nKFxuICAgICAgICAgICAgYFticmlkZ2U6cmVwbF0gSG9vayBjbGVhbnVwOiBzdGFydGluZyB0ZWFyZG93biBmb3IgZW52PSR7aGFuZGxlUmVmLmN1cnJlbnQuZW52aXJvbm1lbnRJZH0gc2Vzc2lvbj0ke2hhbmRsZVJlZi5jdXJyZW50LmJyaWRnZVNlc3Npb25JZH1gLFxuICAgICAgICAgIClcbiAgICAgICAgICB0ZWFyZG93blByb21pc2VSZWYuY3VycmVudCA9IGhhbmRsZVJlZi5jdXJyZW50LnRlYXJkb3duKClcbiAgICAgICAgICBoYW5kbGVSZWYuY3VycmVudCA9IG51bGxcbiAgICAgICAgICBzZXRSZXBsQnJpZGdlSGFuZGxlKG51bGwpXG4gICAgICAgIH1cbiAgICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiB7XG4gICAgICAgICAgaWYgKFxuICAgICAgICAgICAgIXByZXYucmVwbEJyaWRnZUNvbm5lY3RlZCAmJlxuICAgICAgICAgICAgIXByZXYucmVwbEJyaWRnZVNlc3Npb25BY3RpdmUgJiZcbiAgICAgICAgICAgICFwcmV2LnJlcGxCcmlkZ2VFcnJvclxuICAgICAgICAgICkge1xuICAgICAgICAgICAgcmV0dXJuIHByZXZcbiAgICAgICAgICB9XG4gICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgICByZXBsQnJpZGdlQ29ubmVjdGVkOiBmYWxzZSxcbiAgICAgICAgICAgIHJlcGxCcmlkZ2VTZXNzaW9uQWN0aXZlOiBmYWxzZSxcbiAgICAgICAgICAgIHJlcGxCcmlkZ2VSZWNvbm5lY3Rpbmc6IGZhbHNlLFxuICAgICAgICAgICAgcmVwbEJyaWRnZUNvbm5lY3RVcmw6IHVuZGVmaW5lZCxcbiAgICAgICAgICAgIHJlcGxCcmlkZ2VTZXNzaW9uVXJsOiB1bmRlZmluZWQsXG4gICAgICAgICAgICByZXBsQnJpZGdlRW52aXJvbm1lbnRJZDogdW5kZWZpbmVkLFxuICAgICAgICAgICA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