zrb 1.8.10__py3-none-any.whl → 1.21.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of zrb might be problematic. Click here for more details.
- zrb/__init__.py +126 -113
- zrb/__main__.py +1 -1
- zrb/attr/type.py +10 -7
- zrb/builtin/__init__.py +2 -50
- zrb/builtin/git.py +12 -1
- zrb/builtin/group.py +31 -15
- zrb/builtin/http.py +7 -8
- zrb/builtin/llm/attachment.py +40 -0
- zrb/builtin/llm/chat_completion.py +274 -0
- zrb/builtin/llm/chat_session.py +152 -85
- zrb/builtin/llm/chat_session_cmd.py +288 -0
- zrb/builtin/llm/chat_trigger.py +79 -0
- zrb/builtin/llm/history.py +7 -9
- zrb/builtin/llm/llm_ask.py +221 -98
- zrb/builtin/llm/tool/api.py +74 -52
- zrb/builtin/llm/tool/cli.py +46 -17
- zrb/builtin/llm/tool/code.py +71 -90
- zrb/builtin/llm/tool/file.py +301 -241
- zrb/builtin/llm/tool/note.py +84 -0
- zrb/builtin/llm/tool/rag.py +38 -8
- zrb/builtin/llm/tool/sub_agent.py +67 -50
- zrb/builtin/llm/tool/web.py +146 -122
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +7 -7
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +5 -5
- zrb/builtin/project/add/fastapp/fastapp_util.py +1 -1
- zrb/builtin/searxng/config/settings.yml +5671 -0
- zrb/builtin/searxng/start.py +21 -0
- zrb/builtin/setup/latex/ubuntu.py +1 -0
- zrb/builtin/setup/ubuntu.py +1 -1
- zrb/builtin/shell/autocomplete/bash.py +4 -3
- zrb/builtin/shell/autocomplete/zsh.py +4 -3
- zrb/builtin/todo.py +13 -2
- zrb/config/config.py +614 -0
- zrb/config/default_prompt/file_extractor_system_prompt.md +112 -0
- zrb/config/default_prompt/interactive_system_prompt.md +29 -0
- zrb/config/default_prompt/persona.md +1 -0
- zrb/config/default_prompt/repo_extractor_system_prompt.md +112 -0
- zrb/config/default_prompt/repo_summarizer_system_prompt.md +29 -0
- zrb/config/default_prompt/summarization_prompt.md +57 -0
- zrb/config/default_prompt/system_prompt.md +38 -0
- zrb/config/llm_config.py +339 -0
- zrb/config/llm_context/config.py +166 -0
- zrb/config/llm_context/config_parser.py +40 -0
- zrb/config/llm_context/workflow.py +81 -0
- zrb/config/llm_rate_limitter.py +190 -0
- zrb/{runner → config}/web_auth_config.py +17 -22
- zrb/context/any_shared_context.py +17 -1
- zrb/context/context.py +16 -2
- zrb/context/shared_context.py +18 -8
- zrb/group/any_group.py +12 -5
- zrb/group/group.py +67 -3
- zrb/input/any_input.py +5 -1
- zrb/input/base_input.py +18 -6
- zrb/input/option_input.py +13 -1
- zrb/input/text_input.py +8 -25
- zrb/runner/cli.py +25 -23
- zrb/runner/common_util.py +24 -19
- zrb/runner/web_app.py +3 -3
- zrb/runner/web_route/docs_route.py +1 -1
- zrb/runner/web_route/error_page/serve_default_404.py +1 -1
- zrb/runner/web_route/error_page/show_error_page.py +1 -1
- zrb/runner/web_route/home_page/home_page_route.py +2 -2
- zrb/runner/web_route/login_api_route.py +1 -1
- zrb/runner/web_route/login_page/login_page_route.py +2 -2
- zrb/runner/web_route/logout_api_route.py +1 -1
- zrb/runner/web_route/logout_page/logout_page_route.py +2 -2
- zrb/runner/web_route/node_page/group/show_group_page.py +1 -1
- zrb/runner/web_route/node_page/node_page_route.py +1 -1
- zrb/runner/web_route/node_page/task/show_task_page.py +1 -1
- zrb/runner/web_route/refresh_token_api_route.py +1 -1
- zrb/runner/web_route/static/static_route.py +1 -1
- zrb/runner/web_route/task_input_api_route.py +6 -6
- zrb/runner/web_route/task_session_api_route.py +20 -12
- zrb/runner/web_util/cookie.py +1 -1
- zrb/runner/web_util/token.py +1 -1
- zrb/runner/web_util/user.py +8 -4
- zrb/session/any_session.py +24 -17
- zrb/session/session.py +50 -25
- zrb/session_state_logger/any_session_state_logger.py +9 -4
- zrb/session_state_logger/file_session_state_logger.py +16 -6
- zrb/session_state_logger/session_state_logger_factory.py +1 -1
- zrb/task/any_task.py +30 -9
- zrb/task/base/context.py +17 -9
- zrb/task/base/execution.py +15 -8
- zrb/task/base/lifecycle.py +8 -4
- zrb/task/base/monitoring.py +12 -7
- zrb/task/base_task.py +69 -5
- zrb/task/base_trigger.py +12 -5
- zrb/task/cmd_task.py +1 -1
- zrb/task/llm/agent.py +154 -161
- zrb/task/llm/agent_runner.py +152 -0
- zrb/task/llm/config.py +47 -18
- zrb/task/llm/conversation_history.py +209 -0
- zrb/task/llm/conversation_history_model.py +67 -0
- zrb/task/llm/default_workflow/coding/workflow.md +41 -0
- zrb/task/llm/default_workflow/copywriting/workflow.md +68 -0
- zrb/task/llm/default_workflow/git/workflow.md +118 -0
- zrb/task/llm/default_workflow/golang/workflow.md +128 -0
- zrb/task/llm/default_workflow/html-css/workflow.md +135 -0
- zrb/task/llm/default_workflow/java/workflow.md +146 -0
- zrb/task/llm/default_workflow/javascript/workflow.md +158 -0
- zrb/task/llm/default_workflow/python/workflow.md +160 -0
- zrb/task/llm/default_workflow/researching/workflow.md +153 -0
- zrb/task/llm/default_workflow/rust/workflow.md +162 -0
- zrb/task/llm/default_workflow/shell/workflow.md +299 -0
- zrb/task/llm/error.py +24 -10
- zrb/task/llm/file_replacement.py +206 -0
- zrb/task/llm/file_tool_model.py +57 -0
- zrb/task/llm/history_processor.py +206 -0
- zrb/task/llm/history_summarization.py +11 -166
- zrb/task/llm/print_node.py +193 -69
- zrb/task/llm/prompt.py +242 -45
- zrb/task/llm/subagent_conversation_history.py +41 -0
- zrb/task/llm/tool_wrapper.py +260 -57
- zrb/task/llm/workflow.py +76 -0
- zrb/task/llm_task.py +182 -171
- zrb/task/make_task.py +2 -3
- zrb/task/rsync_task.py +26 -11
- zrb/task/scheduler.py +4 -4
- zrb/util/attr.py +54 -39
- zrb/util/callable.py +23 -0
- zrb/util/cli/markdown.py +12 -0
- zrb/util/cli/text.py +30 -0
- zrb/util/file.py +29 -11
- zrb/util/git.py +8 -11
- zrb/util/git_diff_model.py +10 -0
- zrb/util/git_subtree.py +9 -14
- zrb/util/git_subtree_model.py +32 -0
- zrb/util/init_path.py +1 -1
- zrb/util/markdown.py +62 -0
- zrb/util/string/conversion.py +2 -2
- zrb/util/todo.py +17 -50
- zrb/util/todo_model.py +46 -0
- zrb/util/truncate.py +23 -0
- zrb/util/yaml.py +204 -0
- zrb/xcom/xcom.py +10 -0
- zrb-1.21.29.dist-info/METADATA +270 -0
- {zrb-1.8.10.dist-info → zrb-1.21.29.dist-info}/RECORD +140 -98
- {zrb-1.8.10.dist-info → zrb-1.21.29.dist-info}/WHEEL +1 -1
- zrb/config.py +0 -335
- zrb/llm_config.py +0 -411
- zrb/llm_rate_limitter.py +0 -125
- zrb/task/llm/context.py +0 -102
- zrb/task/llm/context_enrichment.py +0 -199
- zrb/task/llm/history.py +0 -211
- zrb-1.8.10.dist-info/METADATA +0 -264
- {zrb-1.8.10.dist-info → zrb-1.21.29.dist-info}/entry_points.txt +0 -0
zrb/input/text_input.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import subprocess
|
|
3
|
-
import tempfile
|
|
4
1
|
from collections.abc import Callable
|
|
5
2
|
|
|
6
|
-
from zrb.config import CFG
|
|
3
|
+
from zrb.config.config import CFG
|
|
7
4
|
from zrb.context.any_shared_context import AnySharedContext
|
|
8
5
|
from zrb.input.base_input import BaseInput
|
|
9
|
-
from zrb.util.
|
|
6
|
+
from zrb.util.cli.text import edit_text
|
|
10
7
|
|
|
11
8
|
|
|
12
9
|
class TextInput(BaseInput):
|
|
@@ -85,24 +82,10 @@ class TextInput(BaseInput):
|
|
|
85
82
|
comment_prompt_message = (
|
|
86
83
|
f"{self.comment_start}{prompt_message}{self.comment_end}"
|
|
87
84
|
)
|
|
88
|
-
comment_prompt_message_eol = f"{comment_prompt_message}\n"
|
|
89
85
|
default_value = self.get_default_str(shared_ctx)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if default_value:
|
|
97
|
-
temp_file.write(default_value.encode())
|
|
98
|
-
temp_file.flush()
|
|
99
|
-
subprocess.call([self.editor_cmd, temp_file_name])
|
|
100
|
-
# Read the edited content
|
|
101
|
-
edited_content = read_file(temp_file_name)
|
|
102
|
-
parts = [
|
|
103
|
-
text.strip() for text in edited_content.split(comment_prompt_message, 1)
|
|
104
|
-
]
|
|
105
|
-
edited_content = "\n".join(parts).lstrip()
|
|
106
|
-
os.remove(temp_file_name)
|
|
107
|
-
print(f"{prompt_message}: {edited_content}")
|
|
108
|
-
return edited_content
|
|
86
|
+
return edit_text(
|
|
87
|
+
prompt_message=comment_prompt_message,
|
|
88
|
+
value=default_value,
|
|
89
|
+
editor=self.editor_cmd,
|
|
90
|
+
extension=self._extension,
|
|
91
|
+
)
|
zrb/runner/cli.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
|
-
from zrb.config import CFG
|
|
4
|
+
from zrb.config.config import CFG
|
|
5
|
+
from zrb.config.web_auth_config import web_auth_config
|
|
5
6
|
from zrb.context.any_context import AnyContext
|
|
6
7
|
from zrb.context.shared_context import SharedContext
|
|
7
8
|
from zrb.group.any_group import AnyGroup
|
|
8
9
|
from zrb.group.group import Group
|
|
9
|
-
from zrb.runner.common_util import
|
|
10
|
-
from zrb.runner.web_app import create_web_app
|
|
11
|
-
from zrb.runner.web_auth_config import web_auth_config
|
|
10
|
+
from zrb.runner.common_util import get_task_str_kwargs
|
|
12
11
|
from zrb.session.session import Session
|
|
13
12
|
from zrb.session_state_logger.session_state_logger_factory import session_state_logger
|
|
14
13
|
from zrb.task.any_task import AnyTask
|
|
@@ -39,23 +38,25 @@ class Cli(Group):
|
|
|
39
38
|
def banner(self) -> str:
|
|
40
39
|
return CFG.BANNER
|
|
41
40
|
|
|
42
|
-
def run(self,
|
|
43
|
-
|
|
44
|
-
node, node_path,
|
|
41
|
+
def run(self, str_args: list[str] = []):
|
|
42
|
+
str_kwargs, str_args = self._extract_kwargs_from_args(str_args)
|
|
43
|
+
node, node_path, str_args = extract_node_from_args(self, str_args)
|
|
45
44
|
if isinstance(node, AnyGroup):
|
|
46
45
|
self._show_group_info(node)
|
|
47
46
|
return
|
|
48
|
-
if "h" in
|
|
47
|
+
if "h" in str_kwargs or "help" in str_kwargs:
|
|
49
48
|
self._show_task_info(node)
|
|
50
49
|
return
|
|
51
|
-
|
|
50
|
+
task_str_kwargs = get_task_str_kwargs(
|
|
51
|
+
task=node, str_args=str_args, str_kwargs=str_kwargs, cli_mode=True
|
|
52
|
+
)
|
|
52
53
|
try:
|
|
53
|
-
result = self._run_task(node,
|
|
54
|
+
result = self._run_task(node, str_args, task_str_kwargs)
|
|
54
55
|
if result is not None:
|
|
55
56
|
print(result)
|
|
56
57
|
return result
|
|
57
58
|
finally:
|
|
58
|
-
run_command = self._get_run_command(node_path,
|
|
59
|
+
run_command = self._get_run_command(node_path, task_str_kwargs)
|
|
59
60
|
self._print_run_command(run_command)
|
|
60
61
|
|
|
61
62
|
def _print_run_command(self, run_command: str):
|
|
@@ -65,11 +66,14 @@ class Cli(Group):
|
|
|
65
66
|
file=sys.stderr,
|
|
66
67
|
)
|
|
67
68
|
|
|
68
|
-
def _get_run_command(
|
|
69
|
+
def _get_run_command(
|
|
70
|
+
self, node_path: list[str], task_str_kwargs: dict[str, str]
|
|
71
|
+
) -> str:
|
|
69
72
|
parts = [self.name] + node_path
|
|
70
|
-
if len(
|
|
73
|
+
if len(task_str_kwargs) > 0:
|
|
71
74
|
parts += [
|
|
72
|
-
self._get_run_command_param(key, val)
|
|
75
|
+
self._get_run_command_param(key, val)
|
|
76
|
+
for key, val in task_str_kwargs.items()
|
|
73
77
|
]
|
|
74
78
|
return " ".join(parts)
|
|
75
79
|
|
|
@@ -82,13 +86,9 @@ class Cli(Group):
|
|
|
82
86
|
self, task: AnyTask, args: list[str], run_kwargs: dict[str, str]
|
|
83
87
|
) -> tuple[Any]:
|
|
84
88
|
shared_ctx = SharedContext(args=args)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
shared_ctx, run_kwargs[task_input.name]
|
|
89
|
-
)
|
|
90
|
-
continue
|
|
91
|
-
return task.run(Session(shared_ctx=shared_ctx, root_group=self))
|
|
89
|
+
return task.run(
|
|
90
|
+
Session(shared_ctx=shared_ctx, root_group=self), str_kwargs=run_kwargs
|
|
91
|
+
)
|
|
92
92
|
|
|
93
93
|
def _show_task_info(self, task: AnyTask):
|
|
94
94
|
description = task.description
|
|
@@ -151,11 +151,11 @@ class Cli(Group):
|
|
|
151
151
|
kwargs[key] = args[i + 1]
|
|
152
152
|
i += 1 # Skip the next argument as it's a value
|
|
153
153
|
else:
|
|
154
|
-
kwargs[key] =
|
|
154
|
+
kwargs[key] = "true"
|
|
155
155
|
elif arg.startswith("-"):
|
|
156
156
|
# Handle short flags like -t or -n
|
|
157
157
|
key = arg[1:]
|
|
158
|
-
kwargs[key] =
|
|
158
|
+
kwargs[key] = "true"
|
|
159
159
|
else:
|
|
160
160
|
# Anything else is considered a positional argument
|
|
161
161
|
residual_args.append(arg)
|
|
@@ -187,6 +187,8 @@ server_group = cli.add_group(
|
|
|
187
187
|
async def start_server(_: AnyContext):
|
|
188
188
|
from uvicorn import Config, Server
|
|
189
189
|
|
|
190
|
+
from zrb.runner.web_app import create_web_app
|
|
191
|
+
|
|
190
192
|
app = create_web_app(cli, web_auth_config, session_state_logger)
|
|
191
193
|
server = Server(
|
|
192
194
|
Config(
|
zrb/runner/common_util.py
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
1
|
from zrb.context.shared_context import SharedContext
|
|
4
2
|
from zrb.task.any_task import AnyTask
|
|
5
3
|
|
|
6
4
|
|
|
7
|
-
def
|
|
8
|
-
task: AnyTask,
|
|
5
|
+
def get_task_str_kwargs(
|
|
6
|
+
task: AnyTask, str_args: list[str], str_kwargs: dict[str, str], cli_mode: bool
|
|
9
7
|
) -> dict[str, str]:
|
|
10
8
|
arg_index = 0
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
shared_ctx = SharedContext(args=args)
|
|
9
|
+
dummmy_shared_ctx = SharedContext()
|
|
10
|
+
task_str_kwargs = {}
|
|
14
11
|
for task_input in task.inputs:
|
|
12
|
+
task_name = task_input.name
|
|
15
13
|
if task_input.name in str_kwargs:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
task_str_kwargs[task_input.name] = str_kwargs[task_name]
|
|
15
|
+
# Update dummy shared context for next input default value
|
|
16
|
+
task_input.update_shared_context(
|
|
17
|
+
dummmy_shared_ctx, str_value=str_kwargs[task_name]
|
|
18
|
+
)
|
|
19
|
+
elif arg_index < len(str_args) and task_input.allow_positional_parsing:
|
|
20
|
+
task_str_kwargs[task_name] = str_args[arg_index]
|
|
21
|
+
# Update dummy shared context for next input default value
|
|
22
|
+
task_input.update_shared_context(
|
|
23
|
+
dummmy_shared_ctx, str_value=task_str_kwargs[task_name]
|
|
24
|
+
)
|
|
22
25
|
arg_index += 1
|
|
23
26
|
else:
|
|
24
27
|
if cli_mode and task_input.always_prompt:
|
|
25
|
-
str_value = task_input.prompt_cli_str(
|
|
28
|
+
str_value = task_input.prompt_cli_str(dummmy_shared_ctx)
|
|
26
29
|
else:
|
|
27
|
-
str_value = task_input.get_default_str(
|
|
28
|
-
|
|
29
|
-
# Update shared context for next input default value
|
|
30
|
-
task_input.update_shared_context(
|
|
31
|
-
|
|
30
|
+
str_value = task_input.get_default_str(dummmy_shared_ctx)
|
|
31
|
+
task_str_kwargs[task_name] = str_value
|
|
32
|
+
# Update dummy shared context for next input default value
|
|
33
|
+
task_input.update_shared_context(
|
|
34
|
+
dummmy_shared_ctx, str_value=task_str_kwargs[task_name]
|
|
35
|
+
)
|
|
36
|
+
return task_str_kwargs
|
zrb/runner/web_app.py
CHANGED
|
@@ -2,9 +2,9 @@ import asyncio
|
|
|
2
2
|
import sys
|
|
3
3
|
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
|
-
from zrb.config import CFG
|
|
5
|
+
from zrb.config.config import CFG
|
|
6
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
6
7
|
from zrb.group.any_group import AnyGroup
|
|
7
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
8
8
|
from zrb.runner.web_route.docs_route import serve_docs
|
|
9
9
|
from zrb.runner.web_route.error_page.serve_default_404 import serve_default_404
|
|
10
10
|
from zrb.runner.web_route.home_page.home_page_route import serve_home_page
|
|
@@ -39,7 +39,7 @@ def create_web_app(
|
|
|
39
39
|
async def lifespan(app: FastAPI):
|
|
40
40
|
capitalized_group_name = CFG.ROOT_GROUP_NAME.capitalize()
|
|
41
41
|
for line in CFG.BANNER.split("\n") + [
|
|
42
|
-
f"{capitalized_group_name} Server running on http://localhost:{
|
|
42
|
+
f"{capitalized_group_name} Server running on http://localhost:{CFG.WEB_HTTP_PORT}"
|
|
43
43
|
]:
|
|
44
44
|
print(line, file=sys.stderr)
|
|
45
45
|
yield
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING
|
|
2
2
|
|
|
3
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
3
4
|
from zrb.group.any_group import AnyGroup
|
|
4
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
5
5
|
from zrb.runner.web_route.error_page.show_error_page import show_error_page
|
|
6
6
|
from zrb.runner.web_util.user import get_user_from_request
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
|
-
from zrb.config import CFG
|
|
4
|
+
from zrb.config.config import CFG
|
|
5
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
5
6
|
from zrb.group.any_group import AnyGroup
|
|
6
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
7
7
|
from zrb.runner.web_util.html import (
|
|
8
8
|
get_html_auth_link,
|
|
9
9
|
get_html_subgroup_info,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING, Annotated
|
|
2
2
|
|
|
3
|
-
from zrb.
|
|
3
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
4
4
|
from zrb.runner.web_util.cookie import set_auth_cookie
|
|
5
5
|
from zrb.runner.web_util.token import generate_tokens_by_credentials
|
|
6
6
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
|
-
from zrb.config import CFG
|
|
4
|
+
from zrb.config.config import CFG
|
|
5
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
5
6
|
from zrb.group.any_group import AnyGroup
|
|
6
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
7
7
|
from zrb.runner.web_util.html import get_html_auth_link
|
|
8
8
|
from zrb.runner.web_util.user import get_user_from_request
|
|
9
9
|
from zrb.util.file import read_file
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
|
-
from zrb.config import CFG
|
|
4
|
+
from zrb.config.config import CFG
|
|
5
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
5
6
|
from zrb.group.any_group import AnyGroup
|
|
6
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
7
7
|
from zrb.runner.web_util.html import get_html_auth_link
|
|
8
8
|
from zrb.runner.web_util.user import get_user_from_request
|
|
9
9
|
from zrb.util.file import read_file
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
4
5
|
from zrb.context.shared_context import SharedContext
|
|
5
6
|
from zrb.group.any_group import AnyGroup
|
|
6
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
7
7
|
from zrb.runner.web_route.error_page.show_error_page import show_error_page
|
|
8
8
|
from zrb.runner.web_route.node_page.group.show_group_page import show_group_page
|
|
9
9
|
from zrb.runner.web_route.node_page.task.show_task_page import show_task_page
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING
|
|
2
2
|
|
|
3
|
-
from zrb.
|
|
3
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
4
4
|
from zrb.runner.web_schema.token import RefreshTokenRequest
|
|
5
5
|
from zrb.runner.web_util.cookie import set_auth_cookie
|
|
6
6
|
from zrb.runner.web_util.token import regenerate_tokens
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
4
5
|
from zrb.group.any_group import AnyGroup
|
|
5
|
-
from zrb.runner.common_util import
|
|
6
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
6
|
+
from zrb.runner.common_util import get_task_str_kwargs
|
|
7
7
|
from zrb.runner.web_util.user import get_user_from_request
|
|
8
8
|
from zrb.task.any_task import AnyTask
|
|
9
9
|
from zrb.util.group import NodeNotFoundError, extract_node_from_args
|
|
@@ -39,9 +39,9 @@ def serve_task_input_api(
|
|
|
39
39
|
if isinstance(task, AnyTask):
|
|
40
40
|
if not user.can_access_task(task):
|
|
41
41
|
return JSONResponse(content={"detail": "Forbidden"}, status_code=403)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
task=task,
|
|
42
|
+
str_kwargs = json.loads(query)
|
|
43
|
+
task_str_kwargs = get_task_str_kwargs(
|
|
44
|
+
task=task, str_args=[], str_kwargs=str_kwargs, cli_mode=False
|
|
45
45
|
)
|
|
46
|
-
return
|
|
46
|
+
return task_str_kwargs
|
|
47
47
|
return JSONResponse(content={"detail": "Not found"}, status_code=404)
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import os
|
|
3
2
|
from datetime import datetime, timedelta
|
|
4
3
|
from typing import TYPE_CHECKING, Any
|
|
5
4
|
|
|
5
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
6
6
|
from zrb.context.shared_context import SharedContext
|
|
7
7
|
from zrb.group.any_group import AnyGroup
|
|
8
|
-
from zrb.runner.web_auth_config import WebAuthConfig
|
|
9
8
|
from zrb.runner.web_schema.session import NewSessionResponse
|
|
10
9
|
from zrb.runner.web_util.user import get_user_from_request
|
|
11
10
|
from zrb.session.session import Session
|
|
12
|
-
from zrb.session_state_log.session_state_log import SessionStateLog, SessionStateLogList
|
|
13
11
|
from zrb.session_state_logger.any_session_state_logger import AnySessionStateLogger
|
|
14
12
|
from zrb.task.any_task import AnyTask
|
|
15
13
|
from zrb.util.group import NodeNotFoundError, extract_node_from_args, get_node_path
|
|
16
14
|
|
|
17
15
|
if TYPE_CHECKING:
|
|
18
|
-
# We want fastapi to only be loaded when necessary to decrease footprint
|
|
19
|
-
|
|
20
16
|
from fastapi import FastAPI
|
|
21
17
|
|
|
18
|
+
from zrb.session_state_log.session_state_log import (
|
|
19
|
+
SessionStateLog,
|
|
20
|
+
SessionStateLogList,
|
|
21
|
+
)
|
|
22
|
+
|
|
22
23
|
|
|
23
24
|
def serve_task_session_api(
|
|
24
25
|
app: "FastAPI",
|
|
@@ -30,6 +31,11 @@ def serve_task_session_api(
|
|
|
30
31
|
from fastapi import Query, Request
|
|
31
32
|
from fastapi.responses import JSONResponse
|
|
32
33
|
|
|
34
|
+
from zrb.session_state_log.session_state_log import (
|
|
35
|
+
SessionStateLog,
|
|
36
|
+
SessionStateLogList,
|
|
37
|
+
)
|
|
38
|
+
|
|
33
39
|
@app.post("/api/v1/task-sessions/{path:path}")
|
|
34
40
|
async def create_new_task_session_api(
|
|
35
41
|
path: str,
|
|
@@ -50,9 +56,7 @@ def serve_task_session_api(
|
|
|
50
56
|
return JSONResponse(content={"detail": "Forbidden"}, status_code=403)
|
|
51
57
|
session_name = residual_args[0] if residual_args else None
|
|
52
58
|
if not session_name:
|
|
53
|
-
shared_ctx = SharedContext(
|
|
54
|
-
env={**dict(os.environ), "_ZRB_WEB_ENV": "1"}
|
|
55
|
-
)
|
|
59
|
+
shared_ctx = SharedContext(is_web_mode=True)
|
|
56
60
|
session = Session(shared_ctx=shared_ctx, root_group=root_group)
|
|
57
61
|
coro = asyncio.create_task(task.async_run(session, str_kwargs=inputs))
|
|
58
62
|
coroutines.append(coro)
|
|
@@ -110,8 +114,10 @@ def serve_task_session_api(
|
|
|
110
114
|
|
|
111
115
|
|
|
112
116
|
def sanitize_session_state_log_list(
|
|
113
|
-
task: AnyTask, session_state_log_list: SessionStateLogList
|
|
114
|
-
) -> SessionStateLogList:
|
|
117
|
+
task: AnyTask, session_state_log_list: "SessionStateLogList"
|
|
118
|
+
) -> "SessionStateLogList":
|
|
119
|
+
from zrb.session_state_log.session_state_log import SessionStateLogList
|
|
120
|
+
|
|
115
121
|
return SessionStateLogList(
|
|
116
122
|
total=session_state_log_list.total,
|
|
117
123
|
data=[
|
|
@@ -122,8 +128,8 @@ def sanitize_session_state_log_list(
|
|
|
122
128
|
|
|
123
129
|
|
|
124
130
|
def sanitize_session_state_log(
|
|
125
|
-
task: AnyTask, session_state_log: SessionStateLog
|
|
126
|
-
) -> SessionStateLog:
|
|
131
|
+
task: AnyTask, session_state_log: "SessionStateLog"
|
|
132
|
+
) -> "SessionStateLog":
|
|
127
133
|
"""
|
|
128
134
|
In session, we create snake_case aliases of inputs.
|
|
129
135
|
The purpose was to increase ergonomics, so that user can use `input.system_prompt`
|
|
@@ -131,6 +137,8 @@ def sanitize_session_state_log(
|
|
|
131
137
|
However, when we serve the session through HTTP API,
|
|
132
138
|
we only want to show the original input names.
|
|
133
139
|
"""
|
|
140
|
+
from zrb.session_state_log.session_state_log import SessionStateLog
|
|
141
|
+
|
|
134
142
|
enhanced_inputs = session_state_log.input
|
|
135
143
|
real_inputs = {}
|
|
136
144
|
for real_input in task.inputs:
|
zrb/runner/web_util/cookie.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from datetime import datetime, timedelta, timezone
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
|
-
from zrb.
|
|
4
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
5
5
|
from zrb.runner.web_schema.token import Token
|
|
6
6
|
|
|
7
7
|
if TYPE_CHECKING:
|
zrb/runner/web_util/token.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from datetime import datetime, timedelta, timezone
|
|
2
2
|
|
|
3
|
-
from zrb.
|
|
3
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
4
4
|
from zrb.runner.web_schema.token import Token
|
|
5
5
|
from zrb.runner.web_util.user import get_user_by_credentials
|
|
6
6
|
|
zrb/runner/web_util/user.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING
|
|
2
2
|
|
|
3
|
-
from zrb.
|
|
3
|
+
from zrb.config.web_auth_config import WebAuthConfig
|
|
4
4
|
from zrb.runner.web_schema.user import User
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
@@ -19,7 +19,7 @@ def get_user_by_credentials(
|
|
|
19
19
|
|
|
20
20
|
async def get_user_from_request(
|
|
21
21
|
web_auth_config: WebAuthConfig, request: "Request"
|
|
22
|
-
) -> User
|
|
22
|
+
) -> User:
|
|
23
23
|
from fastapi.security import OAuth2PasswordBearer
|
|
24
24
|
|
|
25
25
|
if not web_auth_config.enable_auth:
|
|
@@ -45,7 +45,11 @@ def _get_user_from_cookie(
|
|
|
45
45
|
return None
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def _get_user_from_token(
|
|
48
|
+
def _get_user_from_token(
|
|
49
|
+
web_auth_config: WebAuthConfig, token: str | None
|
|
50
|
+
) -> User | None:
|
|
51
|
+
if token is None:
|
|
52
|
+
return None
|
|
49
53
|
try:
|
|
50
54
|
from jose import jwt
|
|
51
55
|
|
|
@@ -54,7 +58,7 @@ def _get_user_from_token(web_auth_config: WebAuthConfig, token: str) -> User | N
|
|
|
54
58
|
web_auth_config.secret_key,
|
|
55
59
|
options={"require_sub": True, "require_exp": True},
|
|
56
60
|
)
|
|
57
|
-
username: str = payload.get("sub")
|
|
61
|
+
username: str | None = payload.get("sub")
|
|
58
62
|
if username is None:
|
|
59
63
|
return None
|
|
60
64
|
user = web_auth_config.find_user_by_username(username)
|