Skip to content

Commit 23ea93a

Browse files
committed
feat: add resumable hosted terminal sessions
1 parent 5eacd32 commit 23ea93a

3 files changed

Lines changed: 763 additions & 0 deletions

File tree

ksadk/server/app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
)
3535
from ksadk.runners.base_runner import BaseRunner
3636
from ksadk.server.api_models import AgentRunRequest
37+
from ksadk.server.terminal_sessions import TerminalSessionManager, register_terminal_routes
3738
from ksadk_runtime_common.workspace_files import (
3839
build_workspace_files_bootstrap,
3940
create_workspace_files_router,
@@ -158,6 +159,7 @@ def _detached_streaming_response(
158159

159160

160161
async def _shutdown_runner_resources():
162+
terminal_manager.reset_for_tests()
161163
pending_streams = list(_DETACHED_STREAMS)
162164
for task in pending_streams:
163165
task.cancel()
@@ -252,6 +254,13 @@ def _workspace_root_dir() -> Path:
252254
_NATIVE_TUI_FRAMEWORKS = {"hermes", "openclaw"}
253255

254256

257+
def _current_framework() -> str:
258+
if not runner:
259+
return ""
260+
detection_type = getattr(getattr(runner, "detection_result", None), "type", None)
261+
return str(getattr(detection_type, "value", detection_type) or "").strip().lower()
262+
263+
255264
def _build_native_terminal_capability(framework: str) -> dict[str, Any]:
256265
enabled = str(framework or "").strip().lower() in _NATIVE_TUI_FRAMEWORKS
257266
return {
@@ -262,12 +271,18 @@ def _build_native_terminal_capability(framework: str) -> dict[str, Any]:
262271
}
263272

264273

274+
terminal_manager = TerminalSessionManager(
275+
workspace_root_getter=_workspace_root_dir,
276+
framework_getter=_current_framework,
277+
)
278+
265279
app.include_router(
266280
create_workspace_files_router(
267281
root_getter=_workspace_root_dir,
268282
enabled_getter=lambda: workspace_files_enabled(default=True),
269283
)
270284
)
285+
register_terminal_routes(app, terminal_manager)
271286

272287

273288
def set_runner(r: BaseRunner):

0 commit comments

Comments
 (0)