setta 0.0.1.dev0__py3-none-any.whl → 0.0.2.dev0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. setta/__init__.py +1 -1
  2. setta/cli/__init__.py +1 -0
  3. setta/cli/connect.py +43 -0
  4. setta/cli/logger.py +225 -0
  5. setta/code_gen/__init__.py +0 -0
  6. setta/code_gen/create_runnable_scripts.py +466 -0
  7. setta/code_gen/export_selected.py +776 -0
  8. setta/code_gen/find_placeholders.py +13 -0
  9. setta/code_gen/python/__init__.py +0 -0
  10. setta/code_gen/python/ast_utils.py +183 -0
  11. setta/code_gen/python/check_scope.py +187 -0
  12. setta/code_gen/python/generate_code.py +280 -0
  13. setta/code_gen/python/make_parseable.py +97 -0
  14. setta/code_gen/python/position_line_col.py +33 -0
  15. setta/code_gen/python/validate_imports.py +87 -0
  16. setta/code_gen/utils.py +120 -0
  17. setta/code_gen/yaml/__init__.py +0 -0
  18. setta/code_gen/yaml/generate_yaml.py +23 -0
  19. setta/code_gen/yaml/section_dict.py +93 -0
  20. setta/database/__init__.py +0 -0
  21. setta/database/backup.py +80 -0
  22. setta/database/db/__init__.py +0 -0
  23. setta/database/db/artifacts/__init__.py +0 -0
  24. setta/database/db/artifacts/load.py +93 -0
  25. setta/database/db/artifacts/save.py +85 -0
  26. setta/database/db/artifacts/save_or_create.py +68 -0
  27. setta/database/db/artifacts/utils.py +13 -0
  28. setta/database/db/codeInfo/__init__.py +0 -0
  29. setta/database/db/codeInfo/copy.py +26 -0
  30. setta/database/db/codeInfo/load.py +65 -0
  31. setta/database/db/codeInfo/save.py +75 -0
  32. setta/database/db/codeInfo/utils.py +33 -0
  33. setta/database/db/evRefs/__init__.py +0 -0
  34. setta/database/db/evRefs/load.py +45 -0
  35. setta/database/db/evRefs/save.py +95 -0
  36. setta/database/db/projects/__init__.py +0 -0
  37. setta/database/db/projects/copy.py +36 -0
  38. setta/database/db/projects/delete.py +7 -0
  39. setta/database/db/projects/load.py +184 -0
  40. setta/database/db/projects/save.py +267 -0
  41. setta/database/db/projects/saveAs.py +40 -0
  42. setta/database/db/projects/utils.py +135 -0
  43. setta/database/db/sectionVariants/__init__.py +0 -0
  44. setta/database/db/sectionVariants/copy.py +28 -0
  45. setta/database/db/sectionVariants/load.py +139 -0
  46. setta/database/db/sectionVariants/save.py +140 -0
  47. setta/database/db/sectionVariants/utils.py +44 -0
  48. setta/database/db/sections/__init__.py +0 -0
  49. setta/database/db/sections/copy.py +70 -0
  50. setta/database/db/sections/jsonSource.py +119 -0
  51. setta/database/db/sections/load.py +350 -0
  52. setta/database/db/sections/save.py +204 -0
  53. setta/database/db/sections/utils.py +13 -0
  54. setta/database/db/uiTypes/__init__.py +0 -0
  55. setta/database/db/uiTypes/copy.py +33 -0
  56. setta/database/db/uiTypes/load.py +51 -0
  57. setta/database/db/uiTypes/save.py +99 -0
  58. setta/database/db/uiTypes/utils.py +27 -0
  59. setta/database/db_init.py +36 -0
  60. setta/database/db_objs.py +102 -0
  61. setta/database/db_path.py +8 -0
  62. setta/database/export_db/__init__.py +0 -0
  63. setta/database/export_db/export_db.py +43 -0
  64. setta/database/export_db/export_raw.py +53 -0
  65. setta/database/export_db/export_readable.py +242 -0
  66. setta/database/export_db/utils.py +16 -0
  67. setta/database/import_db.py +28 -0
  68. setta/database/seed.py +41 -0
  69. setta/database/settings_file.py +118 -0
  70. setta/database/utils.py +32 -0
  71. setta/lsp/__init__.py +0 -0
  72. setta/lsp/file_watcher.py +113 -0
  73. setta/lsp/reader.py +184 -0
  74. setta/lsp/reader_fns/__init__.py +0 -0
  75. setta/lsp/reader_fns/completion.py +84 -0
  76. setta/lsp/reader_fns/definition.py +2 -0
  77. setta/lsp/reader_fns/diagnostics.py +99 -0
  78. setta/lsp/reader_fns/documentHighlight.py +25 -0
  79. setta/lsp/reader_fns/references.py +34 -0
  80. setta/lsp/reader_fns/signatureHelp.py +99 -0
  81. setta/lsp/server.py +150 -0
  82. setta/lsp/utils.py +60 -0
  83. setta/lsp/writer.py +306 -0
  84. setta/routers/__init__.py +11 -0
  85. setta/routers/artifact.py +105 -0
  86. setta/routers/code_info.py +32 -0
  87. setta/routers/dependencies.py +49 -0
  88. setta/routers/in_memory_fn_stdout_websocket.py +21 -0
  89. setta/routers/interactive.py +119 -0
  90. setta/routers/lsp.py +14 -0
  91. setta/routers/projects.py +188 -0
  92. setta/routers/reference_renaming.py +111 -0
  93. setta/routers/sections.py +174 -0
  94. setta/routers/settings.py +40 -0
  95. setta/routers/terminals.py +83 -0
  96. setta/routers/websocket.py +36 -0
  97. setta/server.py +141 -0
  98. setta/start.py +112 -0
  99. setta/static/constants/BaseUITypes.json +153 -0
  100. setta/static/constants/Settings.json +113 -0
  101. setta/static/constants/constants.json +117 -0
  102. setta/static/constants/db_init.sql +249 -0
  103. setta/static/constants/defaultValues.json +125 -0
  104. setta/static/constants/settingsProject.json +276 -0
  105. setta/static/frontend/android-chrome-192x192.png +0 -0
  106. setta/static/frontend/android-chrome-512x512.png +0 -0
  107. setta/static/frontend/apple-touch-icon.png +0 -0
  108. setta/static/frontend/assets/KaTeX_AMS-Regular-0cdd387c.woff2 +0 -0
  109. setta/static/frontend/assets/KaTeX_AMS-Regular-30da91e8.woff +0 -0
  110. setta/static/frontend/assets/KaTeX_AMS-Regular-68534840.ttf +0 -0
  111. setta/static/frontend/assets/KaTeX_Caligraphic-Bold-07d8e303.ttf +0 -0
  112. setta/static/frontend/assets/KaTeX_Caligraphic-Bold-1ae6bd74.woff +0 -0
  113. setta/static/frontend/assets/KaTeX_Caligraphic-Bold-de7701e4.woff2 +0 -0
  114. setta/static/frontend/assets/KaTeX_Caligraphic-Regular-3398dd02.woff +0 -0
  115. setta/static/frontend/assets/KaTeX_Caligraphic-Regular-5d53e70a.woff2 +0 -0
  116. setta/static/frontend/assets/KaTeX_Caligraphic-Regular-ed0b7437.ttf +0 -0
  117. setta/static/frontend/assets/KaTeX_Fraktur-Bold-74444efd.woff2 +0 -0
  118. setta/static/frontend/assets/KaTeX_Fraktur-Bold-9163df9c.ttf +0 -0
  119. setta/static/frontend/assets/KaTeX_Fraktur-Bold-9be7ceb8.woff +0 -0
  120. setta/static/frontend/assets/KaTeX_Fraktur-Regular-1e6f9579.ttf +0 -0
  121. setta/static/frontend/assets/KaTeX_Fraktur-Regular-51814d27.woff2 +0 -0
  122. setta/static/frontend/assets/KaTeX_Fraktur-Regular-5e28753b.woff +0 -0
  123. setta/static/frontend/assets/KaTeX_Main-Bold-0f60d1b8.woff2 +0 -0
  124. setta/static/frontend/assets/KaTeX_Main-Bold-138ac28d.ttf +0 -0
  125. setta/static/frontend/assets/KaTeX_Main-Bold-c76c5d69.woff +0 -0
  126. setta/static/frontend/assets/KaTeX_Main-BoldItalic-70ee1f64.ttf +0 -0
  127. setta/static/frontend/assets/KaTeX_Main-BoldItalic-99cd42a3.woff2 +0 -0
  128. setta/static/frontend/assets/KaTeX_Main-BoldItalic-a6f7ec0d.woff +0 -0
  129. setta/static/frontend/assets/KaTeX_Main-Italic-0d85ae7c.ttf +0 -0
  130. setta/static/frontend/assets/KaTeX_Main-Italic-97479ca6.woff2 +0 -0
  131. setta/static/frontend/assets/KaTeX_Main-Italic-f1d6ef86.woff +0 -0
  132. setta/static/frontend/assets/KaTeX_Main-Regular-c2342cd8.woff2 +0 -0
  133. setta/static/frontend/assets/KaTeX_Main-Regular-c6368d87.woff +0 -0
  134. setta/static/frontend/assets/KaTeX_Main-Regular-d0332f52.ttf +0 -0
  135. setta/static/frontend/assets/KaTeX_Math-BoldItalic-850c0af5.woff +0 -0
  136. setta/static/frontend/assets/KaTeX_Math-BoldItalic-dc47344d.woff2 +0 -0
  137. setta/static/frontend/assets/KaTeX_Math-BoldItalic-f9377ab0.ttf +0 -0
  138. setta/static/frontend/assets/KaTeX_Math-Italic-08ce98e5.ttf +0 -0
  139. setta/static/frontend/assets/KaTeX_Math-Italic-7af58c5e.woff2 +0 -0
  140. setta/static/frontend/assets/KaTeX_Math-Italic-8a8d2445.woff +0 -0
  141. setta/static/frontend/assets/KaTeX_SansSerif-Bold-1ece03f7.ttf +0 -0
  142. setta/static/frontend/assets/KaTeX_SansSerif-Bold-e99ae511.woff2 +0 -0
  143. setta/static/frontend/assets/KaTeX_SansSerif-Bold-ece03cfd.woff +0 -0
  144. setta/static/frontend/assets/KaTeX_SansSerif-Italic-00b26ac8.woff2 +0 -0
  145. setta/static/frontend/assets/KaTeX_SansSerif-Italic-3931dd81.ttf +0 -0
  146. setta/static/frontend/assets/KaTeX_SansSerif-Italic-91ee6750.woff +0 -0
  147. setta/static/frontend/assets/KaTeX_SansSerif-Regular-11e4dc8a.woff +0 -0
  148. setta/static/frontend/assets/KaTeX_SansSerif-Regular-68e8c73e.woff2 +0 -0
  149. setta/static/frontend/assets/KaTeX_SansSerif-Regular-f36ea897.ttf +0 -0
  150. setta/static/frontend/assets/KaTeX_Script-Regular-036d4e95.woff2 +0 -0
  151. setta/static/frontend/assets/KaTeX_Script-Regular-1c67f068.ttf +0 -0
  152. setta/static/frontend/assets/KaTeX_Script-Regular-d96cdf2b.woff +0 -0
  153. setta/static/frontend/assets/KaTeX_Size1-Regular-6b47c401.woff2 +0 -0
  154. setta/static/frontend/assets/KaTeX_Size1-Regular-95b6d2f1.ttf +0 -0
  155. setta/static/frontend/assets/KaTeX_Size1-Regular-c943cc98.woff +0 -0
  156. setta/static/frontend/assets/KaTeX_Size2-Regular-2014c523.woff +0 -0
  157. setta/static/frontend/assets/KaTeX_Size2-Regular-a6b2099f.ttf +0 -0
  158. setta/static/frontend/assets/KaTeX_Size2-Regular-d04c5421.woff2 +0 -0
  159. setta/static/frontend/assets/KaTeX_Size3-Regular-500e04d5.ttf +0 -0
  160. setta/static/frontend/assets/KaTeX_Size3-Regular-6ab6b62e.woff +0 -0
  161. setta/static/frontend/assets/KaTeX_Size4-Regular-99f9c675.woff +0 -0
  162. setta/static/frontend/assets/KaTeX_Size4-Regular-a4af7d41.woff2 +0 -0
  163. setta/static/frontend/assets/KaTeX_Size4-Regular-c647367d.ttf +0 -0
  164. setta/static/frontend/assets/KaTeX_Typewriter-Regular-71d517d6.woff2 +0 -0
  165. setta/static/frontend/assets/KaTeX_Typewriter-Regular-e14fed02.woff +0 -0
  166. setta/static/frontend/assets/KaTeX_Typewriter-Regular-f01f3e87.ttf +0 -0
  167. setta/static/frontend/assets/cormorant-garamond-all-700-italic-c9b58582.woff +0 -0
  168. setta/static/frontend/assets/cormorant-garamond-cyrillic-700-italic-9101ad5f.woff2 +0 -0
  169. setta/static/frontend/assets/cormorant-garamond-cyrillic-ext-700-italic-950de0d6.woff2 +0 -0
  170. setta/static/frontend/assets/cormorant-garamond-latin-700-italic-0bc53e12.woff2 +0 -0
  171. setta/static/frontend/assets/cormorant-garamond-latin-ext-700-italic-525738e0.woff2 +0 -0
  172. setta/static/frontend/assets/cormorant-garamond-vietnamese-700-italic-99563037.woff2 +0 -0
  173. setta/static/frontend/assets/erase-5e0448ea.svg +15 -0
  174. setta/static/frontend/assets/index-1d4b4ecf.css +32 -0
  175. setta/static/frontend/assets/index-ee99dc72.js +678 -0
  176. setta/static/frontend/assets/inter-all-400-normal-054f12d0.woff +0 -0
  177. setta/static/frontend/assets/inter-all-600-normal-c03769e5.woff +0 -0
  178. setta/static/frontend/assets/inter-all-800-normal-15dc6e4b.woff +0 -0
  179. setta/static/frontend/assets/inter-cyrillic-400-normal-a4eee61a.woff2 +0 -0
  180. setta/static/frontend/assets/inter-cyrillic-600-normal-8b14f703.woff2 +0 -0
  181. setta/static/frontend/assets/inter-cyrillic-800-normal-e706eaaa.woff2 +0 -0
  182. setta/static/frontend/assets/inter-cyrillic-ext-400-normal-70047a3b.woff2 +0 -0
  183. setta/static/frontend/assets/inter-cyrillic-ext-600-normal-d4ab9bc4.woff2 +0 -0
  184. setta/static/frontend/assets/inter-cyrillic-ext-800-normal-eae7515a.woff2 +0 -0
  185. setta/static/frontend/assets/inter-greek-400-normal-381ea30d.woff2 +0 -0
  186. setta/static/frontend/assets/inter-greek-600-normal-601f93a2.woff2 +0 -0
  187. setta/static/frontend/assets/inter-greek-800-normal-7af4fb64.woff2 +0 -0
  188. setta/static/frontend/assets/inter-greek-ext-400-normal-27027b17.woff2 +0 -0
  189. setta/static/frontend/assets/inter-greek-ext-600-normal-f2ddf9de.woff2 +0 -0
  190. setta/static/frontend/assets/inter-greek-ext-800-normal-4cb6189e.woff2 +0 -0
  191. setta/static/frontend/assets/inter-latin-400-normal-d56fec21.woff2 +0 -0
  192. setta/static/frontend/assets/inter-latin-600-normal-ff769fa6.woff2 +0 -0
  193. setta/static/frontend/assets/inter-latin-800-normal-5eea1309.woff2 +0 -0
  194. setta/static/frontend/assets/inter-latin-ext-400-normal-bb698d85.woff2 +0 -0
  195. setta/static/frontend/assets/inter-latin-ext-600-normal-ca4808f9.woff2 +0 -0
  196. setta/static/frontend/assets/inter-latin-ext-800-normal-ebdacc0f.woff2 +0 -0
  197. setta/static/frontend/assets/logo/logo.svg +8 -0
  198. setta/static/frontend/assets/pen-455d7d8a.svg +19 -0
  199. setta/static/frontend/assets/source-code-pro-all-500-normal-6bdaa03b.woff +0 -0
  200. setta/static/frontend/assets/source-code-pro-cyrillic-500-normal-288a0d68.woff2 +0 -0
  201. setta/static/frontend/assets/source-code-pro-cyrillic-ext-500-normal-b110a13b.woff2 +0 -0
  202. setta/static/frontend/assets/source-code-pro-greek-500-normal-04328acb.woff2 +0 -0
  203. setta/static/frontend/assets/source-code-pro-latin-500-normal-06edef1e.woff2 +0 -0
  204. setta/static/frontend/assets/source-code-pro-latin-ext-500-normal-6dc60d5e.woff2 +0 -0
  205. setta/static/frontend/assets/web-vitals-44a8e082.js +1 -0
  206. setta/static/frontend/assets/work-sans-all-400-normal-38034a3c.woff +0 -0
  207. setta/static/frontend/assets/work-sans-all-500-normal-550d64e5.woff +0 -0
  208. setta/static/frontend/assets/work-sans-all-600-normal-ccf14060.woff +0 -0
  209. setta/static/frontend/assets/work-sans-all-700-normal-494c2971.woff +0 -0
  210. setta/static/frontend/assets/work-sans-latin-400-normal-36735bc1.woff2 +0 -0
  211. setta/static/frontend/assets/work-sans-latin-500-normal-3790bfda.woff2 +0 -0
  212. setta/static/frontend/assets/work-sans-latin-600-normal-5fba494e.woff2 +0 -0
  213. setta/static/frontend/assets/work-sans-latin-700-normal-a5033d0a.woff2 +0 -0
  214. setta/static/frontend/assets/work-sans-latin-ext-400-normal-c20f571a.woff2 +0 -0
  215. setta/static/frontend/assets/work-sans-latin-ext-500-normal-0f5ac96c.woff2 +0 -0
  216. setta/static/frontend/assets/work-sans-latin-ext-600-normal-97a237d1.woff2 +0 -0
  217. setta/static/frontend/assets/work-sans-latin-ext-700-normal-103e112c.woff2 +0 -0
  218. setta/static/frontend/browserconfig.xml +9 -0
  219. setta/static/frontend/favicon-16x16.png +0 -0
  220. setta/static/frontend/favicon-32x32.png +0 -0
  221. setta/static/frontend/favicon.ico +0 -0
  222. setta/static/frontend/index.html +30 -0
  223. setta/static/frontend/manifest.json +25 -0
  224. setta/static/frontend/mstile-144x144.png +0 -0
  225. setta/static/frontend/mstile-150x150.png +0 -0
  226. setta/static/frontend/mstile-310x150.png +0 -0
  227. setta/static/frontend/mstile-310x310.png +0 -0
  228. setta/static/frontend/mstile-70x70.png +0 -0
  229. setta/static/frontend/robots.txt +3 -0
  230. setta/static/frontend/safari-pinned-tab.svg +18 -0
  231. setta/static/frontend/site.webmanifest +19 -0
  232. setta/static/seed/.DS_Store +0 -0
  233. setta/static/seed/examples/.DS_Store +0 -0
  234. setta/tasks/__init__.py +0 -0
  235. setta/tasks/fns/__init__.py +9 -0
  236. setta/tasks/fns/codeAreaAutocomplete.py +209 -0
  237. setta/tasks/fns/codeAreaFindTemplateVars.py +128 -0
  238. setta/tasks/fns/codeAreaInitializeCode.py +98 -0
  239. setta/tasks/fns/findEVRefs.py +236 -0
  240. setta/tasks/fns/parametersRequest.py +71 -0
  241. setta/tasks/fns/textFieldAutocomplete.py +210 -0
  242. setta/tasks/fns/textFieldInitializeCode.py +99 -0
  243. setta/tasks/fns/typeCheck.py +40 -0
  244. setta/tasks/fns/utils.py +134 -0
  245. setta/tasks/task_runner.py +29 -0
  246. setta/tasks/tasks.py +152 -0
  247. setta/tasks/utils.py +178 -0
  248. setta/terminals/__init__.py +0 -0
  249. setta/terminals/terminals.py +242 -0
  250. setta/terminals/utils.py +37 -0
  251. setta/utils/__init__.py +0 -0
  252. setta/utils/constants.py +148 -0
  253. setta/utils/generate_memorable_string.py +431 -0
  254. setta/utils/generate_new_filename.py +80 -0
  255. setta/utils/section_contents.py +133 -0
  256. setta/utils/utils.py +271 -0
  257. setta/utils/websocket_manager.py +91 -0
  258. setta-0.0.2.dev0.dist-info/LICENSE +201 -0
  259. setta-0.0.2.dev0.dist-info/METADATA +24 -0
  260. setta-0.0.2.dev0.dist-info/RECORD +263 -0
  261. {setta-0.0.1.dev0.dist-info → setta-0.0.2.dev0.dist-info}/WHEEL +1 -1
  262. setta-0.0.2.dev0.dist-info/entry_points.txt +2 -0
  263. setta-0.0.1.dev0.dist-info/METADATA +0 -18
  264. setta-0.0.1.dev0.dist-info/RECORD +0 -5
  265. {setta-0.0.1.dev0.dist-info → setta-0.0.2.dev0.dist-info}/top_level.txt +0 -0
setta/utils/utils.py ADDED
@@ -0,0 +1,271 @@
1
+ import json
2
+ import os
3
+ import re
4
+ from json import JSONDecodeError
5
+ from pathlib import Path
6
+
7
+
8
+ def get_absolute_path(src_path, file_path):
9
+ return (Path(src_path).parent / file_path).resolve()
10
+
11
+
12
+ def is_dev_mode():
13
+ return os.environ.get("SETTA_DEV_MODE")
14
+
15
+
16
+ # https://gist.github.com/bgusach/a967e0587d6e01e889fd1d776c5f3729
17
+ def multireplace(string, replacements):
18
+ """
19
+ Given a string and a replacement map, it returns the replaced string.
20
+
21
+ :param str string: string to execute replacements on
22
+ :param dict replacements: replacement dictionary {value to find: value to replace}
23
+ :rtype: str
24
+
25
+ """
26
+ if not replacements:
27
+ # Edge case that'd produce a funny regex and cause a KeyError
28
+ return string
29
+
30
+ # Place longer ones first to keep shorter substrings from matching where the longer ones should take place
31
+ # For instance given the replacements {'ab': 'AB', 'abc': 'ABC'} against the string 'hey abc', it should produce
32
+ # 'hey ABC' and not 'hey ABc'
33
+ rep_sorted = sorted(replacements, key=len, reverse=True)
34
+ rep_escaped = map(re.escape, rep_sorted)
35
+
36
+ # Create a big OR regex that matches any of the substrings to replace
37
+ pattern = re.compile("|".join(rep_escaped))
38
+
39
+ # For each match, look up the new string in the replacements, being the key the normalized old string
40
+ return pattern.sub(lambda match: replacements[match.group(0)], string)
41
+
42
+
43
+ class QuoteInsensitiveDict(dict):
44
+ def __getitem__(self, key):
45
+ return super().__getitem__(self.normalize_key(key))
46
+
47
+ def __setitem__(self, key, value):
48
+ super().__setitem__(self.normalize_key(key), value)
49
+
50
+ def __contains__(self, key):
51
+ return super().__contains__(self.normalize_key(key))
52
+
53
+ def normalize_key(self, key):
54
+ # Remove outer quotes if present
55
+ key = key.strip("'\"")
56
+ # Replace all quote characters with a standard one
57
+ key = re.sub(r"['\"]", '"', key)
58
+ return key
59
+
60
+
61
+ def nested_access(input_dict, access_string):
62
+ # Split by array/dict access while preserving quotes
63
+ keys = re.findall(r"\[([^\]]+)\]|([^[]+)", access_string)
64
+ # Flatten tuples and handle quotes
65
+ keys = [k[0] if k[0] else k[1] for k in keys]
66
+ # Remove quotes from string keys and convert numeric keys to integers
67
+ keys = [int(k) if k.isdigit() else k.strip("\"'") for k in keys]
68
+
69
+ # Start with the input dictionary
70
+ result = input_dict
71
+
72
+ # Traverse the nested structure
73
+ for idx, key in enumerate(keys):
74
+ if idx == len(keys) - 1:
75
+ break
76
+ result = result[key]
77
+
78
+ return result, key
79
+
80
+
81
+ def recursive_dict_merge(dict1, dict2, strict_top_level_keys=False):
82
+ """
83
+ Recursively merge two dictionaries. For conflicting keys:
84
+ - If both values are dictionaries: merge recursively
85
+ - If both values are lists: concatenate them
86
+ - Otherwise: value from dict2 takes precedence
87
+
88
+ Args:
89
+ dict1 (dict): First dictionary
90
+ dict2 (dict): Second dictionary
91
+ strict_top_level_keys (bool): If True, only keep top-level keys from dict1
92
+
93
+ Returns:
94
+ dict: Merged dictionary
95
+
96
+ Examples:
97
+ >>> d1 = {'a': 1, 'b': {'c': 2, 'd': [1, 2]}}
98
+ >>> d2 = {'b': {'c': 4, 'd': [3, 4]}, 'f': 6}
99
+ >>> recursive_dict_merge(d1, d2)
100
+ {'a': 1, 'b': {'c': 4, 'd': [1, 2, 3, 4]}, 'f': 6}
101
+ >>> recursive_dict_merge(d1, d2, strict_top_level_keys=True)
102
+ {'a': 1, 'b': {'c': 4, 'd': [1, 2, 3, 4]}}
103
+ """
104
+ if strict_top_level_keys:
105
+ # Only process keys that exist in dict1
106
+ dict2 = {k: v for k, v in dict2.items() if k in dict1}
107
+
108
+ merged = dict1.copy()
109
+
110
+ for key, value in dict2.items():
111
+ if key in merged:
112
+ if isinstance(merged[key], dict) and isinstance(value, dict):
113
+ # If both values are dictionaries, merge them recursively
114
+ merged[key] = recursive_dict_merge(merged[key], value)
115
+ elif isinstance(merged[key], list) and isinstance(value, list):
116
+ # If both values are lists, concatenate them
117
+ merged[key] = merged[key] + value
118
+ else:
119
+ # Otherwise, value from dict2 takes precedence
120
+ merged[key] = value
121
+ else:
122
+ merged[key] = value
123
+
124
+ return merged
125
+
126
+
127
+ def try_json(x):
128
+ try:
129
+ return json.loads(x)
130
+ except (JSONDecodeError, TypeError):
131
+ return x
132
+
133
+
134
+ def replace_null_keys_with_none(data):
135
+ """
136
+ Recursively replaces "null" keys with None in a dictionary.
137
+
138
+ Args:
139
+ data: Input dictionary
140
+
141
+ Returns:
142
+ Modified dictionary with "null" keys replaced by None
143
+ """
144
+ if isinstance(data, dict):
145
+ new_dict = {}
146
+ for key, value in data.items():
147
+ # Replace "null" key with None
148
+ new_key = None if key == "null" else key
149
+
150
+ # Recursively process value if it's a dictionary
151
+ if isinstance(value, dict):
152
+ value = replace_null_keys_with_none(value)
153
+ elif isinstance(value, list):
154
+ # Process dictionaries within lists
155
+ value = [
156
+ replace_null_keys_with_none(item)
157
+ if isinstance(item, dict)
158
+ else item
159
+ for item in value
160
+ ]
161
+
162
+ new_dict[new_key] = value
163
+ return new_dict
164
+ return data
165
+
166
+
167
+ def filter_dict(x, keep_keys=None, default_vals=None):
168
+ if not isinstance(x, dict):
169
+ return x
170
+
171
+ return {
172
+ k: filter_dict(v, None, default_vals.get(k) if default_vals else None)
173
+ for k, v in x.items()
174
+ if (keep_keys is None or k in keep_keys)
175
+ and (
176
+ (default_vals is None) or (k not in default_vals) or (v != default_vals[k])
177
+ )
178
+ }
179
+
180
+
181
+ def replace_at_positions(input_string, replacements, return_positions=False):
182
+ """
183
+ Replace substrings at specific positions in the input string.
184
+
185
+ Args:
186
+ input_string (str): The original string to modify
187
+ replacements (list): List of tuples (position, old_value, new_value)
188
+ return_positions (bool): Whether to return new positions of replacements
189
+
190
+ Returns:
191
+ Union[str, Tuple[str, List[Tuple[int, str]]]]:
192
+ If return_positions is False: Modified string with all replacements applied
193
+ If return_positions is True: Tuple of (modified string, list of (old_position, position, new_value))
194
+
195
+ Raises:
196
+ ValueError: If any replacement would result in an invalid operation
197
+ """
198
+ # Sort replacements by position in descending order to avoid position shifts
199
+ replacements = sorted(replacements, reverse=True, key=lambda x: x[0])
200
+
201
+ # Convert string to list for easier manipulation
202
+ result = list(input_string)
203
+
204
+ # Track new positions if requested
205
+ new_positions = []
206
+
207
+ for pos, old, new in replacements:
208
+ # Verify the position is valid
209
+ if pos < 0 or pos >= len(input_string):
210
+ raise ValueError(f"Position {pos} is out of bounds")
211
+
212
+ # Verify the old value matches at the specified position
213
+ if not input_string.startswith(old, pos):
214
+ raise ValueError(
215
+ f"Expected '{old}' at position {pos}, but found '{input_string[pos:pos+len(old)]}'"
216
+ )
217
+
218
+ # Calculate the shift this replacement will cause
219
+ current_shift = len(new) - len(old)
220
+
221
+ # Replace the characters
222
+ result[pos : pos + len(old)] = list(new)
223
+
224
+ # If tracking new positions, add the current replacement's new position
225
+ if return_positions:
226
+ new_positions.append((pos, pos, new))
227
+ # Update all previous entries' positions to account for this shift
228
+ for i in range(len(new_positions) - 1):
229
+ old_pos_i, pos_i, val_i = new_positions[i]
230
+ new_positions[i] = (old_pos_i, pos_i + current_shift, val_i)
231
+
232
+ # Join the result list back into a string
233
+ final_string = "".join(result)
234
+
235
+ # Return based on whether return_positions is requested
236
+ if return_positions:
237
+ return final_string, new_positions
238
+ return final_string
239
+
240
+
241
+ def save_json_to_file(path, data):
242
+ with open(path, "w") as f:
243
+ json.dump(data, f, indent=2)
244
+
245
+
246
+ def prune_dict(id_to_children: dict, keep_ids: list) -> dict:
247
+ """
248
+ Prunes a dictionary to keep only specified IDs and their descendants.
249
+
250
+ Args:
251
+ id_to_children: Dictionary mapping IDs to lists of child IDs
252
+ keep_ids: List of IDs to keep along with their descendants
253
+
254
+ Returns:
255
+ New dictionary containing only the specified IDs and their descendants
256
+ """
257
+ # First find all descendants of the keep_ids
258
+ to_keep = set()
259
+
260
+ def collect_descendants(current_id):
261
+ if current_id not in to_keep: # Avoid cycles
262
+ to_keep.add(current_id)
263
+ for child_id in id_to_children.get(current_id, []):
264
+ collect_descendants(child_id)
265
+
266
+ # Collect all descendants
267
+ for id in keep_ids:
268
+ collect_descendants(id)
269
+
270
+ # Create new dict with only the ids we want to keep
271
+ return {id: children for id, children in id_to_children.items() if id in to_keep}
@@ -0,0 +1,91 @@
1
+ import json
2
+
3
+ from fastapi import WebSocket
4
+ from websockets.exceptions import ConnectionClosedError
5
+
6
+ from setta.tasks.fns.utils import TaskMessage
7
+ from setta.utils.constants import C
8
+ from setta.utils.generate_memorable_string import generate_memorable_string
9
+
10
+
11
+ # https://fastapi.tiangolo.com/advanced/websockets/#handling-disconnections-and-multiple-clients
12
+ class WebsocketManager:
13
+ def __init__(self):
14
+ self.sockets = {}
15
+ self.server_cli_id = "main"
16
+ self.message_id_to_sender_id = {}
17
+
18
+ async def connect(self, websocket: WebSocket):
19
+ await websocket.accept()
20
+ id = websocket.headers.get("websocketId")
21
+ while (not id) or id in self.sockets:
22
+ id = generate_memorable_string()
23
+ self.sockets[id] = {
24
+ "websocket": websocket,
25
+ "isCLI": websocket.headers.get("isCLI", False),
26
+ "location": None,
27
+ }
28
+ await self.broadcast_connections()
29
+ return id
30
+
31
+ async def disconnect(self, id):
32
+ try:
33
+ del self.sockets[id]
34
+ await self.broadcast_connections()
35
+ except ConnectionClosedError:
36
+ pass
37
+
38
+ async def send_message(self, message, fromWebsocketId, tasks):
39
+ if "toWebsocketId" in message:
40
+ if "id" in message:
41
+ self.message_id_to_sender_id[message["id"]] = fromWebsocketId
42
+ wid = message["toWebsocketId"]
43
+ if wid == self.server_cli_id:
44
+ # process task and send any results back to requester
45
+ result = await tasks(
46
+ message["messageType"], TaskMessage.parse_obj(message)
47
+ )
48
+ if "content" in result:
49
+ websocket = self.sockets[fromWebsocketId]["websocket"]
50
+ await websocket.send_text(
51
+ json.dumps(
52
+ {
53
+ "id": message["id"],
54
+ "content": result["content"],
55
+ "messageType": result["messageType"],
56
+ }
57
+ )
58
+ )
59
+ else:
60
+ # just send data to target websocket
61
+ websocket = self.sockets[wid]["websocket"]
62
+ await websocket.send_text(json.dumps(message))
63
+
64
+ if "location" in message:
65
+ self.sockets[fromWebsocketId]["location"] = message["location"]
66
+
67
+ async def send_message_to_requester(self, id, content):
68
+ # just send data to target websocket
69
+ websocket = self.sockets[self.message_id_to_sender_id[id]]["websocket"]
70
+ await websocket.send_text(json.dumps({"id": id, "content": content}))
71
+
72
+ async def send_message_to_location(self, content, messageType, location):
73
+ for w in self.sockets.values():
74
+ if w["location"] == location:
75
+ websocket = w["websocket"]
76
+ await websocket.send_text(
77
+ json.dumps({"content": content, "messageType": messageType})
78
+ )
79
+
80
+ async def broadcast(self, message):
81
+ for s in self.sockets.values():
82
+ await s["websocket"].send_text(json.dumps(message))
83
+
84
+ async def broadcast_connections(self):
85
+ connections = []
86
+ for id, s in self.sockets.items():
87
+ connections.append({"websocketId": id, "isCLI": s["isCLI"]})
88
+ connections.append({"websocketId": self.server_cli_id, "isCLI": True})
89
+ await self.broadcast(
90
+ {"messageType": C.WS_ALL_CONNECTIONS, "connections": connections}
91
+ )
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Kevin Musgrave and Jeff Musgrave
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.2
2
+ Name: setta
3
+ Version: 0.0.2.dev0
4
+ Home-page: https://setta.dev
5
+ Project-URL: GitHub, https://github.com/settadev/setta
6
+ License-File: LICENSE
7
+ Requires-Dist: click==8.1.3
8
+ Requires-Dist: requests==2.28.1
9
+ Requires-Dist: PyYAML==6.0
10
+ Requires-Dist: websockets==11.0.3
11
+ Requires-Dist: fastapi==0.115.4
12
+ Requires-Dist: uvicorn==0.32.0
13
+ Requires-Dist: docstring_parser==0.15
14
+ Requires-Dist: pywinpty==2.0.12; platform_system == "Windows"
15
+ Requires-Dist: ptyprocess==0.7.0; platform_system != "Windows"
16
+ Requires-Dist: psutil==5.9.7
17
+ Requires-Dist: basedpyright==1.25.0
18
+ Requires-Dist: docstring-to-markdown==0.15
19
+ Requires-Dist: black==23.7.0
20
+ Requires-Dist: watchdog==6.0.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: build==1.0.3; extra == "dev"
23
+ Requires-Dist: isort==5.12.0; extra == "dev"
24
+ Requires-Dist: flake8==6.1.0; extra == "dev"