Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions agentkit/toolkit/cli/interactive_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import readline
# Cross-platform readline support:
# - On Unix, use built-in `readline`
# - On Windows, try `pyreadline3` if available; otherwise gracefully degrade
try:
import readline # type: ignore
except ImportError: # ImportError on Windows or environments without GNU readline
try:
import pyreadline3 as readline # type: ignore
except ImportError:
readline = None # type: ignore
from typing import (
Any,
Dict,
Expand Down Expand Up @@ -128,9 +137,10 @@ def _safe_input(self, prompt_text, default: str = "") -> str:

def prefill():
try:
readline.insert_text(default)
# Ensure default is a string to avoid TypeError
readline.insert_text(str(default))
readline.redisplay()
except (AttributeError, OSError):
except (AttributeError, OSError, TypeError):
# Some readline implementations (e.g., libedit) may not support insert_text or redisplay
# In this case, we'll display the default value in the prompt as a fallback
pass
Expand All @@ -157,8 +167,9 @@ def prefill():
finally:
# Clean up hook; use try-except to prevent errors on unsupported systems
try:
readline.set_pre_input_hook()
except (AttributeError, OSError):
# Unset hook explicitly to avoid TypeError on some implementations
readline.set_pre_input_hook(None)
except (AttributeError, OSError, TypeError):
pass

def generate_config(
Expand Down Expand Up @@ -572,7 +583,13 @@ def _handle_string(
while True:
# Build complete prompt information
if default:
prompt_str = f"\n[{current}/{total}] {icon} {description} (current: {default}{'' if not ('{' in default and '}' in default) else ', content in curly braces is a dynamic placeholder, no need to fill manually'}): "
default_str = str(default)
placeholder_hint = (
", content in curly braces is a dynamic placeholder, no need to fill manually"
if ("{" in default_str and "}" in default_str)
else ""
)
prompt_str = f"\n[{current}/{total}] {icon} {description} (current: {default_str}{placeholder_hint}): "
else:
prompt_str = f"\n[{current}/{total}] {icon} {description}: "

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies = [
"tos>=2.8.7",
"volcengine",
"pyfiglet>=1.0.2",
"pyreadline3; sys_platform == 'win32'",
]

[project.scripts]
Expand Down Expand Up @@ -101,4 +102,4 @@ exclude = [

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/*" = ["F401", "F811"]
"tests/*" = ["F401", "F811"]
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ volcengine-python-sdk
pyfiglet>=1.0.2
inquirerpy>=0.3.4

# Windows-only enhancement for interactive CLI input
pyreadline3; sys_platform == 'win32'

# Development dependencies
pre-commit>=4.3.0