zrb 1.0.0a17__py3-none-any.whl → 1.0.0a19__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.
Files changed (144) hide show
  1. zrb/__init__.py +2 -0
  2. zrb/builtin/project/add/fastapp/fastapp_task.py +25 -39
  3. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/.flake8 +3 -0
  4. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/create_column_task.py +14 -0
  5. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +128 -0
  6. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +213 -0
  7. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/any_client_method.template.py → my_app_name/_zrb/entity/template/any_client_method.py} +1 -1
  8. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/module_template → my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/my_entity_usecase.py +4 -5
  9. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/factory.py +13 -0
  10. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/module_template → my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_db_repository.py +4 -4
  11. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/module_template → my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_repository.py +1 -2
  12. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +17 -0
  13. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/input.py +1 -4
  14. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +85 -0
  15. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +154 -0
  16. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +6 -0
  17. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +6 -0
  18. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +9 -0
  19. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/env.py +2 -4
  20. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/script.py.mako +1 -0
  21. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/route.py +3 -3
  22. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/task.py +12 -14
  23. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/util.py +1 -1
  24. zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/venv_task.py +1 -1
  25. zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/app.py +2 -2
  26. zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/base_db_repository.py +1 -1
  27. zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/db_engine.py +1 -1
  28. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +7 -0
  29. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/migrate.py +3 -0
  30. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/client/any_client.py +1 -1
  31. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +7 -0
  32. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +6 -0
  33. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +9 -0
  34. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/env.py +2 -4
  35. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/script.py.mako +1 -0
  36. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration_metadata.py +1 -1
  37. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/route.py +4 -4
  38. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/factory.py +13 -0
  39. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/repository/user_db_repository.py +4 -4
  40. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/repository/user_repository.py +1 -2
  41. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/user_usecase.py +4 -5
  42. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration/env.py +2 -4
  43. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration/script.py.mako +1 -0
  44. zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/route.py +5 -5
  45. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +0 -0
  46. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/__init__.py +0 -0
  47. zrb/builtin/project/add/fastapp/fastapp_util.py +29 -5
  48. zrb/builtin/python.py +4 -1
  49. zrb/builtin/todo.py +35 -14
  50. zrb/callback/callback.py +0 -1
  51. zrb/config.py +1 -0
  52. zrb/content_transformer/content_transformer.py +5 -3
  53. zrb/context/any_context.py +6 -6
  54. zrb/group/group.py +0 -1
  55. zrb/input/any_input.py +4 -0
  56. zrb/input/base_input.py +4 -4
  57. zrb/input/bool_input.py +1 -1
  58. zrb/input/float_input.py +2 -2
  59. zrb/input/int_input.py +1 -1
  60. zrb/input/option_input.py +2 -2
  61. zrb/input/password_input.py +2 -2
  62. zrb/input/text_input.py +2 -2
  63. zrb/runner/cli.py +2 -31
  64. zrb/runner/common_util.py +31 -0
  65. zrb/runner/web_app.py +25 -6
  66. zrb/runner/web_controller/static/pico.min.css +1 -1
  67. zrb/runner/web_controller/static/task-ui/common-util.js +63 -0
  68. zrb/runner/web_controller/static/task-ui/current-session.js +164 -0
  69. zrb/runner/web_controller/static/task-ui/event.js +120 -0
  70. zrb/runner/web_controller/static/task-ui/past-session.js +138 -0
  71. zrb/runner/web_controller/task_ui/controller.py +20 -19
  72. zrb/runner/web_controller/task_ui/view.html +12 -15
  73. zrb/session_state_logger/any_session_state_logger.py +0 -1
  74. zrb/session_state_logger/file_session_state_logger.py +0 -1
  75. zrb/task/base_trigger.py +0 -1
  76. zrb/task/llm_task.py +0 -1
  77. zrb/task/make_task.py +0 -1
  78. zrb/task/scaffolder.py +6 -4
  79. zrb/task/scheduler.py +0 -1
  80. zrb/util/cmd/command.py +0 -1
  81. zrb/util/codemod/append_code_to_class.py +4 -4
  82. zrb/util/codemod/append_code_to_function.py +2 -2
  83. zrb/util/codemod/append_code_to_method.py +2 -2
  84. zrb/util/codemod/prepend_code_to_module.py +2 -2
  85. zrb/util/file.py +1 -1
  86. zrb/util/todo.py +100 -17
  87. zrb/xcom/xcom.py +0 -1
  88. {zrb-1.0.0a17.dist-info → zrb-1.0.0a19.dist-info}/METADATA +1 -1
  89. zrb-1.0.0a19.dist-info/RECORD +241 -0
  90. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/column/create_column_task.py +0 -11
  91. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/factory.py +0 -13
  92. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/entity/task.py +0 -260
  93. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/task.py +0 -143
  94. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/template/module_template/client/api_client.py +0 -6
  95. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/template/module_template/client/direct_client.py +0 -6
  96. zrb/builtin/project/add/fastapp/fastapp_template/_zrb/module/template/module_template/client/factory.py +0 -9
  97. zrb/builtin/project/add/fastapp/fastapp_template/main.py +0 -7
  98. zrb/builtin/project/add/fastapp/fastapp_template/migrate.py +0 -3
  99. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/client/api_client.py +0 -7
  100. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/client/direct_client.py +0 -6
  101. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/client/factory.py +0 -9
  102. zrb/builtin/project/add/fastapp/fastapp_template/module/auth/service/user/repository/factory.py +0 -13
  103. zrb/runner/web_controller/task_ui/partial/common-util.js +0 -37
  104. zrb/runner/web_controller/task_ui/partial/main.js +0 -195
  105. zrb/runner/web_controller/task_ui/partial/show-existing-session.js +0 -97
  106. zrb/runner/web_controller/task_ui/partial/visualize-history.js +0 -104
  107. zrb-1.0.0a17.dist-info/RECORD +0 -234
  108. /zrb/builtin/project/add/fastapp/fastapp_template/{.gitignore → my_app_name/.gitignore} +0 -0
  109. /zrb/builtin/project/add/fastapp/fastapp_template/{README.md → my_app_name/README.md} +0 -0
  110. /zrb/builtin/project/add/fastapp/fastapp_template/{__init__.py → my_app_name/__init__.py} +0 -0
  111. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/config.py +0 -0
  112. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/entity/schema.template.py → my_app_name/_zrb/entity/template/app_template/schema/my_entity.py} +0 -0
  113. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb → my_app_name/_zrb}/group.py +0 -0
  114. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template/migration/versions/.gitkeep → my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py} +0 -0
  115. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/alembic.ini +0 -0
  116. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/client/any_client.py +0 -0
  117. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/README +0 -0
  118. /zrb/builtin/project/add/fastapp/fastapp_template/{module/gateway → my_app_name/_zrb/module/template/app_template/module/my_module}/migration/versions/.gitkeep +0 -0
  119. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/migration_metadata.py +0 -0
  120. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/module_template → my_app_name/_zrb/module/template/app_template/module/my_module}/service/__init__.py +0 -0
  121. /zrb/builtin/project/add/fastapp/fastapp_template/{_zrb/module/template/task_definition.py → my_app_name/_zrb/module/template/module_task_definition.py} +0 -0
  122. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/__init__.py +0 -0
  123. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/base_usecase.py +0 -0
  124. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/error.py +0 -0
  125. /zrb/builtin/project/add/fastapp/fastapp_template/{common → my_app_name/common}/schema.py +0 -0
  126. /zrb/builtin/project/add/fastapp/fastapp_template/{config.py → my_app_name/config.py} +0 -0
  127. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/__init__.py +0 -0
  128. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/alembic.ini +0 -0
  129. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/README +0 -0
  130. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/migration/versions/3093c7336477_add_user_table.py +0 -0
  131. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/__init__.py +0 -0
  132. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/__init__.py +0 -0
  133. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/auth/service/user/repository/__init__.py +0 -0
  134. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/alembic.ini +0 -0
  135. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration/README +0 -0
  136. /zrb/builtin/project/add/fastapp/fastapp_template/{schema/__init__.py → my_app_name/module/gateway/migration/versions/.gitkeep} +0 -0
  137. /zrb/builtin/project/add/fastapp/fastapp_template/{module → my_app_name/module}/gateway/migration_metadata.py +0 -0
  138. /zrb/builtin/project/add/fastapp/fastapp_template/{requirements.txt → my_app_name/requirements.txt} +0 -0
  139. /zrb/builtin/project/add/fastapp/fastapp_template/{schema → my_app_name/schema}/permission.py +0 -0
  140. /zrb/builtin/project/add/fastapp/fastapp_template/{schema → my_app_name/schema}/role.py +0 -0
  141. /zrb/builtin/project/add/fastapp/fastapp_template/{schema → my_app_name/schema}/user.py +0 -0
  142. /zrb/builtin/project/add/fastapp/fastapp_template/{template.env → my_app_name/template.env} +0 -0
  143. {zrb-1.0.0a17.dist-info → zrb-1.0.0a19.dist-info}/WHEEL +0 -0
  144. {zrb-1.0.0a17.dist-info → zrb-1.0.0a19.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,120 @@
1
+ window.addEventListener("load", async function () {
2
+ // Get current session
3
+ if (cfg.SESSION_NAME != "") {
4
+ CURRENT_SESSION.pollCurrentSession();
5
+ }
6
+ // set maxStartDate to today
7
+ const tomorrow = new Date();
8
+ tomorrow.setDate(tomorrow.getDate() + 1); // Move to the next day
9
+ tomorrow.setHours(0, 0, 0, 0);
10
+ const formattedTomorrow = UTIL.toLocalDateInputValue(tomorrow);
11
+ const maxStartAtInput = document.getElementById("max-start-at-input");
12
+ maxStartAtInput.value = formattedTomorrow;
13
+ // set minStartDate to yesterday
14
+ const today = new Date();
15
+ today.setHours(0, 0, 0, 0); // Set time to 00:00:00
16
+ const formattedToday = UTIL.toLocalDateInputValue(today);
17
+ const minStartAtInput = document.getElementById("min-start-at-input");
18
+ minStartAtInput.value = formattedToday;
19
+ // Update session
20
+ PAST_SESSION.pollPastSession();
21
+ });
22
+
23
+
24
+ const submitTaskForm = document.getElementById("submit-task-form");
25
+ submitTaskForm.addEventListener("input", async function(event) {
26
+ const currentInput = event.target;
27
+ const inputs = Array.from(submitTaskForm.querySelectorAll("input[name]"));
28
+ const inputMap = {};
29
+ const fixedInputNames = [];
30
+ for (const input of inputs) {
31
+ fixedInputNames.push(input.name);
32
+ if (input === currentInput) {
33
+ inputMap[input.name] = currentInput.value;
34
+ break;
35
+ } else {
36
+ inputMap[input.name] = input.value;
37
+ }
38
+ }
39
+ const queryString = new URLSearchParams(
40
+ {query: JSON.stringify(inputMap)}
41
+ ).toString();
42
+ try {
43
+ // Send the AJAX request
44
+ const response = await fetch(`${cfg.INPUT_API_URL}?${queryString}`, {
45
+ method: "GET",
46
+ headers: {
47
+ "Content-Type": "application/json"
48
+ },
49
+ });
50
+ if (response.ok) {
51
+ const data = await response.json();
52
+ // Update the values of all subsequent inputs based on the response
53
+ Object.entries(data).forEach(([key, value]) => {
54
+ if (fixedInputNames.includes(key)) {
55
+ return;
56
+ }
57
+ const input = submitTaskForm.querySelector(`[name="${key}"]`);
58
+ input.value = value;
59
+ });
60
+ } else {
61
+ console.error("Failed to fetch updated values:", response.statusText);
62
+ }
63
+ } catch (error) {
64
+ console.error("Error during fetch:", error);
65
+ }
66
+ })
67
+
68
+
69
+ function openPastSessionDialog(event) {
70
+ event.preventDefault();
71
+ const dialog = document.getElementById("past-session-dialog")
72
+ dialog.showModal();
73
+ }
74
+
75
+
76
+ function closePastSessionDialog(event) {
77
+ event.preventDefault();
78
+ const dialog = document.getElementById("past-session-dialog")
79
+ dialog.close();
80
+ }
81
+
82
+
83
+ async function submitNewSessionForm(event) {
84
+ // Prevent the form from submitting the traditional way
85
+ event.preventDefault();
86
+ // Select the form
87
+ const form = document.getElementById("submit-task-form");
88
+ // Initialize an empty object to hold form data
89
+ const formData = {};
90
+ // Iterate through each input in the form
91
+ Array.from(form.elements).forEach(element => {
92
+ // Only include inputs with a name attribute and ignore buttons
93
+ if (element.name && (element.type !== "button" && element.type !== "submit")) {
94
+ formData[element.name] = element.value;
95
+ }
96
+ });
97
+ // Convert formData to JSON
98
+ const jsonData = JSON.stringify(formData);
99
+ try {
100
+ // Send the AJAX request
101
+ const response = await fetch(cfg.SESSION_API_URL, {
102
+ method: "POST",
103
+ headers: {
104
+ "Content-Type": "application/json"
105
+ },
106
+ body: jsonData
107
+ });
108
+ if (response.ok) {
109
+ const data = await response.json();
110
+ cfg.SESSION_NAME = data.session_name;
111
+ history.pushState(null, "", `${cfg.CURRENT_URL}${cfg.SESSION_NAME}`);
112
+ await PAST_SESSION.getAndRenderPastSession(0);
113
+ await CURRENT_SESSION.pollCurrentSession();
114
+ } else {
115
+ console.error("Error:", response);
116
+ }
117
+ } catch (error) {
118
+ console.error("Error:", error);
119
+ }
120
+ }
@@ -0,0 +1,138 @@
1
+ const PAST_SESSION = {
2
+
3
+ async pollPastSession() {
4
+ while (true) {
5
+ await this.getAndRenderPastSession(cfg.PAGE);
6
+ await UTIL.delay(5000);
7
+ }
8
+ },
9
+
10
+ async getAndRenderPastSession(page) {
11
+ cfg.PAGE=page
12
+ const minStartAtInput = document.getElementById("min-start-at-input");
13
+ const minStartAt = UTIL.formatDate(minStartAtInput.value);
14
+ const maxStartAtInput = document.getElementById("max-start-at-input");
15
+ const maxStartAt = UTIL.formatDate(maxStartAtInput.value);
16
+ const queryString = new URLSearchParams({
17
+ page: page,
18
+ from: minStartAt,
19
+ to: maxStartAt,
20
+ }).toString();
21
+ try {
22
+ // Send the AJAX request
23
+ const response = await fetch(`${cfg.SESSION_API_URL}list?${queryString}`, {
24
+ method: "GET",
25
+ headers: {
26
+ "Content-Type": "application/json"
27
+ },
28
+ });
29
+ if (response.ok) {
30
+ const {total, data} = await response.json();
31
+ this.showPastSession(page, total, data);
32
+ } else {
33
+ console.error("Error:", response);
34
+ }
35
+ } catch (error) {
36
+ console.error("Error:", error);
37
+ }
38
+ },
39
+
40
+ showPastSession(page, total, data) {
41
+ const ul = document.getElementById("past-session-ul");
42
+ ul.innerHTML = ''; // Clear existing content
43
+ data.forEach(item => {
44
+ const taskStatus = item.task_status[item.main_task_name];
45
+ const finalStatus = UTIL.getFinalTaskStatus(taskStatus);
46
+ const finalColor = UTIL.getFinalColor(finalStatus);
47
+ const taskHistories = taskStatus.history;
48
+ const taskStartTime = taskHistories.length > 0 ? taskHistories[0].time : ""
49
+ const li = document.createElement('li');
50
+ const a = document.createElement('a');
51
+ const dateSpan = document.createElement('span');
52
+ const statusSpan = document.createElement('span');
53
+ a.textContent = item.name;
54
+ a.target = '_blank';
55
+ a.href = `${cfg.UI_URL}${item.name}`;
56
+ li.appendChild(a);
57
+ statusSpan.style.marginLeft = "10px";
58
+ statusSpan.style.display = 'inline-block';
59
+ statusSpan.style.width = '15px';
60
+ statusSpan.style.height = '15px';
61
+ statusSpan.style.borderRadius = '50%';
62
+ statusSpan.style.border = '2px solid black';
63
+ statusSpan.style.backgroundColor = finalColor;
64
+ li.appendChild(statusSpan);
65
+ dateSpan.style.marginLeft = "10px";
66
+ dateSpan.textContent = taskStartTime;
67
+ li.appendChild(dateSpan);
68
+ ul.appendChild(li);
69
+ });
70
+ const paginationUl = document.getElementById("past-session-pagination-ul");
71
+ paginationUl.innerHTML = ''; // Clear previous pagination
72
+
73
+ const totalPages = Math.ceil(total / 10); // Calculate total pages based on page size
74
+ const maxPagesToShow = 5; // Number of pages to display around the current page
75
+ const halfMaxPages = Math.floor(maxPagesToShow / 2);
76
+
77
+ // Add first page and previous controls
78
+ if (page > 0) {
79
+ paginationUl.appendChild(this.createPageLink("⟪", 0)); // Go to first page
80
+ paginationUl.appendChild(this.createPageLink("⟨", page - 1)); // Go to previous page
81
+ }
82
+
83
+ let startPage = Math.max(0, page - halfMaxPages);
84
+ let endPage = Math.min(totalPages - 1, page + halfMaxPages);
85
+
86
+ if (page <= halfMaxPages) {
87
+ endPage = Math.min(totalPages - 1, maxPagesToShow - 1);
88
+ } else if (page + halfMaxPages >= totalPages) {
89
+ startPage = Math.max(0, totalPages - maxPagesToShow);
90
+ }
91
+
92
+ if (startPage > 1) {
93
+ paginationUl.appendChild(this.createEllipsis());
94
+ }
95
+
96
+ // Add page links within the calculated range
97
+ for (let i = startPage; i <= endPage; i++) {
98
+ if (i === page) {
99
+ const pageLi = document.createElement('li');
100
+ pageLi.textContent = i + 1;
101
+ paginationUl.append(pageLi)
102
+ } else {
103
+ paginationUl.appendChild(this.createPageLink(i + 1, i))
104
+ }
105
+ }
106
+
107
+ // Add ellipsis after the end page if needed
108
+ if (endPage < totalPages - 2) {
109
+ paginationUl.appendChild(this.createEllipsis());
110
+ }
111
+
112
+ // Add next and last page controls
113
+ if (page < totalPages - 1) {
114
+ paginationUl.appendChild(this.createPageLink("⟩", page + 1)); // Go to next page
115
+ paginationUl.appendChild(this.createPageLink("⟫", totalPages - 1)); // Go to last page
116
+ }
117
+ },
118
+
119
+ createPageLink(text, page) {
120
+ const li = document.createElement('li');
121
+ const link = document.createElement('a');
122
+ link.textContent = text;
123
+ link.href = '#';
124
+ link.onclick = (e) => {
125
+ e.preventDefault();
126
+ this.getAndRenderPastSession(page);
127
+ };
128
+ li.appendChild(link);
129
+ return li;
130
+ },
131
+
132
+ createEllipsis() {
133
+ const li = document.createElement('li');
134
+ li.textContent = '...';
135
+ return li;
136
+ },
137
+
138
+ }
@@ -1,3 +1,4 @@
1
+ import json
1
2
  import os
2
3
 
3
4
  from zrb.group.any_group import AnyGroup
@@ -10,14 +11,6 @@ _DIR = os.path.dirname(__file__)
10
11
 
11
12
  _VIEW_TEMPLATE = read_file(os.path.join(_DIR, "view.html"))
12
13
  _TASK_INPUT_TEMPLATE = read_file(os.path.join(_DIR, "partial", "input.html"))
13
- _MAIN_SCRIPT = read_file(os.path.join(_DIR, "partial", "main.js"))
14
- _SHOW_EXISTING_SESSION_SCRIPT = read_file(
15
- os.path.join(_DIR, "partial", "show-existing-session.js")
16
- )
17
- _VISUALIZE_HISTORY_SCRIPT = read_file(
18
- os.path.join(_DIR, "partial", "visualize-history.js")
19
- )
20
- _COMMON_UTIL_SCRIPT = read_file(os.path.join(_DIR, "partial", "common-util.js"))
21
14
 
22
15
 
23
16
  def handle_task_ui(
@@ -31,12 +24,16 @@ def handle_task_ui(
31
24
  # Assemble parent url
32
25
  parent_url_parts = url_parts[:-2] + [""]
33
26
  parent_url = "/".join(parent_url_parts)
34
- # Assemble api url
35
- api_url_parts = list(url_parts)
36
- api_url_parts[1] = "api"
37
- api_url = "/".join(api_url_parts)
27
+ # Assemble session api url
28
+ session_url_parts = list(url_parts)
29
+ session_url_parts[1] = "api/sessions"
30
+ session_api_url = "/".join(session_url_parts)
31
+ # Assemble input api url
32
+ input_url_parts = list(url_parts)
33
+ input_url_parts[1] = "api/inputs"
34
+ input_api_url = "/".join(input_url_parts)
38
35
  # Assemble ui url
39
- ui_url_parts = list(api_url_parts)
36
+ ui_url_parts = list(url_parts)
40
37
  ui_url_parts[1] = "ui"
41
38
  ui_url = "/".join(ui_url_parts)
42
39
  # Assemble task inputs
@@ -58,13 +55,17 @@ def handle_task_ui(
58
55
  "url": url,
59
56
  "parent_url": parent_url,
60
57
  "task_inputs": "\n".join(input_html_list),
61
- "api_url": api_url,
62
58
  "ui_url": ui_url,
63
- "main_script": _MAIN_SCRIPT,
64
- "show_existing_session_script": _SHOW_EXISTING_SESSION_SCRIPT,
65
- "visualize_history_script": _VISUALIZE_HISTORY_SCRIPT,
66
- "common_util_script": _COMMON_UTIL_SCRIPT,
67
- "session_name": session_name,
59
+ "json_cfg": json.dumps(
60
+ {
61
+ "CURRENT_URL": url,
62
+ "SESSION_API_URL": session_api_url,
63
+ "INPUT_API_URL": input_api_url,
64
+ "UI_URL": ui_url,
65
+ "SESSION_NAME": session_name,
66
+ "PAGE": 0,
67
+ }
68
+ ),
68
69
  },
69
70
  )
70
71
  )
@@ -19,16 +19,16 @@
19
19
  <li><a href="/">🏠 Home</a></li>
20
20
  <li><a href="{parent_url}">🔙 Parent</a></li>
21
21
  <li><a href="{ui_url}">🆕 New Session</a></li>
22
- <li><a href="#" onclick="openDialog(event)">📂 Existing Session</a></li>
22
+ <li><a href="#" onclick="openPastSessionDialog(event)">📂 Existing Session</a></li>
23
23
  </ul>
24
24
  </nav>
25
25
  </hgroup>
26
26
  </header>
27
27
 
28
- <dialog id="session-history-dialog">
28
+ <dialog id="past-session-dialog">
29
29
  <article>
30
30
  <header>
31
- <button aria-label="Close" rel="prev" onclick="closeDialog(event)"></button>
31
+ <button aria-label="Close" rel="prev" onclick="closePastSessionDialog(event)"></button>
32
32
  <p>
33
33
  <strong>📂 Existing Session</strong>
34
34
  </p>
@@ -40,11 +40,11 @@
40
40
  <input type="datetime-local" id="max-start-at-input" placeholder="Maximum Start Time" aria-label="Maximum Start Time" />
41
41
  </fieldset>
42
42
  </form>
43
- <ul id="session-history-ul" style="font-family:monospace;"></ul>
43
+ <ul id="past-session-ul" style="font-family:monospace;"></ul>
44
44
  </main>
45
45
  <footer>
46
46
  <nav>
47
- <ul id="session-history-pagination-ul"></ul>
47
+ <ul id="past-session-pagination-ul"></ul>
48
48
  </nav>
49
49
  </footer>
50
50
  </article>
@@ -55,7 +55,7 @@
55
55
  <p>{description}</p>
56
56
  <canvas id="history-canvas" height="0" width="1000" style="width: 100%;"></canvas>
57
57
  <hr />
58
- <form id="submit-task-form" onsubmit="submitForm(event)">
58
+ <form id="submit-task-form" onsubmit="submitNewSessionForm(event)">
59
59
  {task_inputs}
60
60
  <button>🚀 Run</button>
61
61
  </form>
@@ -74,14 +74,11 @@
74
74
 
75
75
  </body>
76
76
  <script>
77
- const CURRENT_URL = '{url}';
78
- const API_URL = '{api_url}';
79
- const UI_URL = `{ui_url}`;
80
- let SESSION_NAME = '{session_name}';
81
- let PAGE = 0;
82
- {main_script}
83
- {common_util_script}
84
- {show_existing_session_script}
85
- {visualize_history_script}
77
+ const cfg = {json_cfg};
86
78
  </script>
79
+ <script src="/static/task-ui/common-util.js"></script>
80
+ <script src="/static/task-ui/past-session.js"></script>
81
+ <script src="/static/task-ui/current-session.js"></script>
82
+ <script src="/static/task-ui/event.js"></script>
83
+
87
84
  </html>
@@ -5,7 +5,6 @@ from zrb.session_state_log.session_state_log import SessionStateLog, SessionStat
5
5
 
6
6
 
7
7
  class AnySessionStateLogger(ABC):
8
-
9
8
  @abstractmethod
10
9
  def write(self, session_log: SessionStateLog):
11
10
  pass
@@ -7,7 +7,6 @@ from zrb.util.file import read_file, write_file
7
7
 
8
8
 
9
9
  class FileSessionStateLogger(AnySessionStateLogger):
10
-
11
10
  def __init__(self, session_log_dir: str):
12
11
  self._session_log_dir = session_log_dir
13
12
 
zrb/task/base_trigger.py CHANGED
@@ -19,7 +19,6 @@ from zrb.xcom.xcom import Xcom
19
19
 
20
20
 
21
21
  class BaseTrigger(BaseTask):
22
-
23
22
  def __init__(
24
23
  self,
25
24
  name: str,
zrb/task/llm_task.py CHANGED
@@ -33,7 +33,6 @@ def scratchpad(thought: str) -> str:
33
33
 
34
34
 
35
35
  class LLMTask(BaseTask):
36
-
37
36
  def __init__(
38
37
  self,
39
38
  name: str,
zrb/task/make_task.py CHANGED
@@ -32,7 +32,6 @@ def make_task(
32
32
  group: AnyGroup | None = None,
33
33
  alias: str | None = None,
34
34
  ) -> Callable[[Callable[[AnyContext], Any]], AnyTask]:
35
-
36
35
  def _make_task(fn: Callable[[AnyContext], Any]) -> BaseTask:
37
36
  task = BaseTask(
38
37
  name=name,
zrb/task/scaffolder.py CHANGED
@@ -84,11 +84,13 @@ class Scaffolder(BaseTask):
84
84
 
85
85
  def _get_content_transformers(self) -> list[AnyContentTransformer]:
86
86
  if callable(self._content_transformers):
87
- return [ContentTransformer(match="*", transform=self._content_transformers)]
87
+ return [
88
+ ContentTransformer(match=".*", transform=self._content_transformers)
89
+ ]
88
90
  if isinstance(self._content_transformers, dict):
89
91
  return [
90
92
  ContentTransformer(
91
- match="*",
93
+ match=".*",
92
94
  transform=self._content_transformers,
93
95
  auto_render=self._render_content_transformers,
94
96
  )
@@ -127,11 +129,11 @@ class Scaffolder(BaseTask):
127
129
  dest_file = os.path.join(
128
130
  dest_dir, self._transform_path(ctx, file_name)
129
131
  )
132
+ ctx.log_info(f"Copying {src_file} to {dest_file}")
130
133
  shutil.copy2(src_file, dest_file)
131
- ctx.log_info(f"Copied {src_file} to {dest_file}")
132
134
  else:
135
+ ctx.log_info(f"Copying {source_path} to {destination_path}")
133
136
  shutil.copy2(source_path, destination_path)
134
- ctx.log_info(f"Copied {source_path} to {destination_path}")
135
137
 
136
138
  def _transform_path(self, ctx: AnyContext, file_path: str):
137
139
  if callable(self._path_transformer):
zrb/task/scheduler.py CHANGED
@@ -16,7 +16,6 @@ from zrb.xcom.xcom import Xcom
16
16
 
17
17
 
18
18
  class Scheduler(BaseTrigger):
19
-
20
19
  def __init__(
21
20
  self,
22
21
  name: str,
zrb/util/cmd/command.py CHANGED
@@ -47,7 +47,6 @@ async def run_command(
47
47
  max_output_line: int = 1000,
48
48
  max_error_line: int = 1000,
49
49
  ) -> tuple[CmdResult, int]:
50
-
51
50
  async def __read_stream(
52
51
  stream, log_method: Callable[..., None], max_lines: int
53
52
  ) -> str:
@@ -4,7 +4,7 @@ import libcst as cst
4
4
  class ClassCodeAdder(cst.CSTTransformer):
5
5
  def __init__(self, class_name: str, new_code: str):
6
6
  self.class_name = class_name
7
- self.new_code = cst.parse_statement(new_code)
7
+ self.new_code = cst.parse_module(new_code).body
8
8
  self.class_found = False
9
9
 
10
10
  def leave_ClassDef(
@@ -15,17 +15,17 @@ class ClassCodeAdder(cst.CSTTransformer):
15
15
  self.class_found = True
16
16
  # Add the method to the class body
17
17
  new_body = updated_node.body.with_changes(
18
- body=updated_node.body.body + (self.new_code,)
18
+ body=updated_node.body.body + tuple(self.new_code)
19
19
  )
20
20
  return updated_node.with_changes(body=new_body)
21
21
  return updated_node
22
22
 
23
23
 
24
- def append_code_to_class(original_code: str, class_name: str, method_code: str) -> str:
24
+ def append_code_to_class(original_code: str, class_name: str, new_code: str) -> str:
25
25
  # Parse the original code into a module
26
26
  module = cst.parse_module(original_code)
27
27
  # Initialize transformer with the class name and method code
28
- transformer = ClassCodeAdder(class_name, method_code)
28
+ transformer = ClassCodeAdder(class_name, new_code)
29
29
  # Apply the transformation
30
30
  modified_module = module.visit(transformer)
31
31
  # Check if the class was found
@@ -5,7 +5,7 @@ class FunctionCodeAdder(cst.CSTTransformer):
5
5
  def __init__(self, function_name: str, new_code: str):
6
6
  self.function_name = function_name
7
7
  # Use parse_module to handle multiple statements
8
- self.new_code = cst.parse_statement(new_code)
8
+ self.new_code = cst.parse_module(new_code).body
9
9
  self.function_found = False
10
10
 
11
11
  def leave_FunctionDef(
@@ -16,7 +16,7 @@ class FunctionCodeAdder(cst.CSTTransformer):
16
16
  self.function_found = True
17
17
  # Add the method to the class body
18
18
  new_body = updated_node.body.with_changes(
19
- body=updated_node.body.body + (self.new_code,)
19
+ body=updated_node.body.body + tuple(self.new_code)
20
20
  )
21
21
  return updated_node.with_changes(body=new_body)
22
22
  return updated_node
@@ -6,7 +6,7 @@ class MethodCodeAdder(cst.CSTTransformer):
6
6
  self.class_name = class_name
7
7
  self.method_name = method_name
8
8
  # Use parse_module to handle multiple statements
9
- self.new_code = cst.parse_statement(new_code)
9
+ self.new_code = cst.parse_module(new_code).body
10
10
  self.class_found = False
11
11
  self.method_found = False
12
12
 
@@ -27,7 +27,7 @@ class MethodCodeAdder(cst.CSTTransformer):
27
27
  ):
28
28
  # Modify the target function by adding the new code
29
29
  body_with_new_code = item.body.with_changes(
30
- body=item.body.body + (self.new_code,) # Add the new code
30
+ body=item.body.body + tuple(self.new_code) # Add the new code
31
31
  )
32
32
  new_body.append(item.with_changes(body=body_with_new_code))
33
33
  self.method_found = True
@@ -1,5 +1,5 @@
1
- def prepend_code_to_module(source_code: str, new_code: str) -> str:
2
- lines = source_code.splitlines()
1
+ def prepend_code_to_module(original_code: str, new_code: str) -> str:
2
+ lines = original_code.splitlines()
3
3
  last_import_index = -1
4
4
  for i, line in enumerate(lines):
5
5
  stripped_line = line.strip()
zrb/util/file.py CHANGED
@@ -15,4 +15,4 @@ def write_file(file_path: str, content: str | list[str]):
15
15
  dir_path = os.path.dirname(file_path)
16
16
  os.makedirs(dir_path, exist_ok=True)
17
17
  with open(file_path, "w") as f:
18
- f.write(content)
18
+ f.write(content.strip())