          (map :candidate)
          (into []))))
 
-(defn execute-request-handler [shell-socket iopub-socket nrepl-client]
+(defn execute-request-handler [shell-socket stdin-socket iopub-socket nrepl-client]
   (let [execution-count (atom 0N)]
     (fn [message signer]
       (let [session-id (get-in message [:header :session])


(defn comm-info-reply
  [message socket signer]
  (let [parent_header (:header message)
        metadata {}
        content  {:comms
                  {:comm_id {:target_name ""}}}
        session-id (get-in message [:header :session])]
    (send-message socket "comm_info_reply" content parent_header metadata session-id signer)))

(defn comm-msg-reply
  [message socket signer]
  (let [parent_header (:header message)
        metadata {}
        content  {}
        session-id (get-in message [:header :session])]
    (send-message socket "comm_msg_reply" content parent_header metadata session-id signer)))

(defn is-complete-reply [message socket signer]
  (let [parent_header (:header message)
        metadata {}
        content  (is-complete-reply-content message)
        session-id (get-in message [:header :session])
        ident (:idents message)]
    (send-router-message socket
                         "is_complete_reply"
                         content parent_header session-id metadata signer ident)))

(defn complete-reply
  [message socket signer transport]
  (let [parent_header (:header message)
        metadata {}
        content  (complete-reply-content message transport)
        session-id (get-in message [:header :session])
        ident (:idents message)]
    (send-router-message socket
                         "complete_reply"
                         content parent_header session-id metadata signer ident)))

(defn configure-shell-handler [shell-socket iopub-socket signer nrepl-client]
  (let [execute-request (execute-request-handler shell-socket iopub-socket nrepl-client)]
    (fn [message]
      (let [msg-type (get-in message [:header :msg_type])]
        (case msg-type

                      :session @nrepl-session})))

(defn nrepl-eval
  [code parent-header session-id signer ident
   shell-socket stdin-socket iopub-socket
   nrepl-client]
  (let [pending (atom #{})
        command-id (nrepl.misc/uuid)
        result (atom {:nrepl-result "nil"})
        io-sleep   5
        get-input (fn []
                    (input-request stdin-socket
                                   parent-header session-id signer ident))
        send-input (fn  [nrepl-client session pending]
                     (get-input)
                     (let [message (read-raw-message @stdin-socket)
                           parsed-message (parse-message message)
                           input (get-in parsed-message [:content :value])
                           command-id (nrepl.misc/uuid)]
                       (swap! pending conj command-id)
                       (nrepl/message nrepl-client {:id command-id
                                                    :op "stdin"
                                                    :stdin (str input "\n")
                                                   :session session})))
        done?      (fn [{:keys [id status] :as msg} pending]
                     (let [pending? (@pending id)]
