MCPcopy Create free account
hub / github.com/dot-agent/nextpy / _build_html

Method _build_html

nextpy/ai/engine/_program.py:686–1042  ·  view source on GitHub ↗
(self, text, last=False)

Source from the content-addressed store, hash-verified

684 return self._text
685
686 def _build_html(self, text, last=False):
687 output = text
688
689 def undo_html_encode(x):
690 return (
691 x.replace("{", "{")
692 .replace("}", "}")
693 .replace("$", "$")
694 )
695
696 def start_generate_or_select(x):
697 no_echo = "echo=False" in x.group(1)
698 alpha = 1.0 if no_echo else 1.0
699
700 # script that toggles the viisibility of the next element
701 click_script = 'var e = this.nextElementSibling; if (e.style.display == "inline") { e.style.display = "none"; this.style.borderRight = "1px solid rgba(0, 165, 0, 0.25)"; } else { e.style.display = "inline"; this.style.borderRight = "0px";}'
702
703 if no_echo:
704 out = f"""<div style='background-color: rgba(0, 165, 0, 0.25); border-radius: 4px 0px 0px 4px; border: 1px solid rgba(0, 165, 0, 1); padding-left: 3px; padding-right: 3px; user-select: none; color: rgb(0, 165, 0, 1.0); display: inline; font-weight: normal; cursor: pointer' onClick='{click_script}'>no echo</div>"""
705 out += "<span style='background-color: rgba(0, 165, 0, 0.25); opacity: {}; display: none;' title='{}'>".format(
706 alpha, undo_html_encode(x.group(1))
707 )
708 else:
709 out = "<span style='background-color: rgba(0, 165, 0, 0.25); opacity: {}; display: inline;' title='{}'>".format(
710 alpha, undo_html_encode(x.group(1))
711 )
712 return out
713
714 def start_each(x):
715 no_echo = "echo=False" in x.group(1)
716 alpha = 0.5 if no_echo else 1.0
717 color = "rgba(165, 165, 165, 0.1)" # if "geneach" not in x.group(1) else "rgba(0, 165, 0, 0.1)"
718 return "<span style='opacity: {}; display: inline; background-color: {};' title='{}'>".format(
719 alpha, color, undo_html_encode(x.group(1))
720 )
721
722 def start_block(x):
723 escaped_tag = undo_html_encode(x.group(1))
724 if "hidden=True" in escaped_tag:
725 display = "inline" # none (we actively stip hidden tags right now so we don't need this until we support the UX to show hidden stuff)
726 else:
727 display = "inline"
728 return f"<span style='background-color: rgba(165, 165, 165, 0.1); display: {display};' title='{escaped_tag}'>"
729
730 def role_box(x):
731 # name = x.group(3).lower() # standardize to lowercase for display
732 # content = x.group(4)
733
734 content = x.group(3)
735 tag_text = undo_html_encode(x.group(2))
736 role_name = x.group(1)
737
738 # if we have a generic role tag then the role name is an attribute
739 if role_name == "role":
740 role_name = re.search(r"role_name=([^ ]*)", tag_text).group(1)
741
742 start_pattern = html.escape(self.llm.role_start(role_name)).replace(
743 "|", r"\|"

Callers 2

_ipython_display_Method · 0.95
_update_displayMethod · 0.95

Calls 2

add_spacesFunction · 0.85
searchMethod · 0.45

Tested by

no test coverage detected