llms-py 3.0.0__py3-none-any.whl → 3.0.0b1__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 (206) hide show
  1. llms/index.html +77 -35
  2. llms/llms.json +23 -72
  3. llms/main.py +732 -1786
  4. llms/providers.json +1 -1
  5. llms/{extensions/analytics/ui/index.mjs → ui/Analytics.mjs} +238 -154
  6. llms/ui/App.mjs +60 -151
  7. llms/ui/Avatar.mjs +85 -0
  8. llms/ui/Brand.mjs +52 -0
  9. llms/ui/ChatPrompt.mjs +606 -0
  10. llms/ui/Main.mjs +873 -0
  11. llms/ui/ModelSelector.mjs +693 -0
  12. llms/ui/OAuthSignIn.mjs +92 -0
  13. llms/ui/ProviderIcon.mjs +36 -0
  14. llms/ui/ProviderStatus.mjs +105 -0
  15. llms/{extensions/app/ui → ui}/Recents.mjs +65 -91
  16. llms/ui/{modules/chat/SettingsDialog.mjs → SettingsDialog.mjs} +9 -9
  17. llms/{extensions/app/ui/index.mjs → ui/Sidebar.mjs} +58 -124
  18. llms/ui/SignIn.mjs +64 -0
  19. llms/ui/SystemPromptEditor.mjs +31 -0
  20. llms/ui/SystemPromptSelector.mjs +56 -0
  21. llms/ui/Welcome.mjs +8 -0
  22. llms/ui/ai.mjs +53 -125
  23. llms/ui/app.css +111 -1837
  24. llms/ui/lib/charts.mjs +13 -9
  25. llms/ui/lib/servicestack-vue.mjs +3 -3
  26. llms/ui/lib/vue.min.mjs +9 -10
  27. llms/ui/lib/vue.mjs +1602 -1763
  28. llms/ui/markdown.mjs +2 -10
  29. llms/ui/tailwind.input.css +80 -496
  30. llms/ui/threadStore.mjs +572 -0
  31. llms/ui/utils.mjs +117 -113
  32. llms/ui.json +1069 -0
  33. {llms_py-3.0.0.dist-info → llms_py-3.0.0b1.dist-info}/METADATA +1 -1
  34. llms_py-3.0.0b1.dist-info/RECORD +49 -0
  35. llms/__pycache__/__init__.cpython-312.pyc +0 -0
  36. llms/__pycache__/__init__.cpython-313.pyc +0 -0
  37. llms/__pycache__/__init__.cpython-314.pyc +0 -0
  38. llms/__pycache__/__main__.cpython-312.pyc +0 -0
  39. llms/__pycache__/__main__.cpython-314.pyc +0 -0
  40. llms/__pycache__/llms.cpython-312.pyc +0 -0
  41. llms/__pycache__/main.cpython-312.pyc +0 -0
  42. llms/__pycache__/main.cpython-313.pyc +0 -0
  43. llms/__pycache__/main.cpython-314.pyc +0 -0
  44. llms/__pycache__/plugins.cpython-314.pyc +0 -0
  45. llms/extensions/app/README.md +0 -20
  46. llms/extensions/app/__init__.py +0 -530
  47. llms/extensions/app/__pycache__/__init__.cpython-314.pyc +0 -0
  48. llms/extensions/app/__pycache__/db.cpython-314.pyc +0 -0
  49. llms/extensions/app/__pycache__/db_manager.cpython-314.pyc +0 -0
  50. llms/extensions/app/db.py +0 -644
  51. llms/extensions/app/db_manager.py +0 -195
  52. llms/extensions/app/requests.json +0 -9073
  53. llms/extensions/app/threads.json +0 -15290
  54. llms/extensions/app/ui/threadStore.mjs +0 -411
  55. llms/extensions/core_tools/CALCULATOR.md +0 -32
  56. llms/extensions/core_tools/__init__.py +0 -598
  57. llms/extensions/core_tools/__pycache__/__init__.cpython-314.pyc +0 -0
  58. llms/extensions/core_tools/ui/codemirror/addon/edit/closebrackets.js +0 -201
  59. llms/extensions/core_tools/ui/codemirror/addon/edit/closetag.js +0 -185
  60. llms/extensions/core_tools/ui/codemirror/addon/edit/continuelist.js +0 -101
  61. llms/extensions/core_tools/ui/codemirror/addon/edit/matchbrackets.js +0 -160
  62. llms/extensions/core_tools/ui/codemirror/addon/edit/matchtags.js +0 -66
  63. llms/extensions/core_tools/ui/codemirror/addon/edit/trailingspace.js +0 -27
  64. llms/extensions/core_tools/ui/codemirror/addon/selection/active-line.js +0 -72
  65. llms/extensions/core_tools/ui/codemirror/addon/selection/mark-selection.js +0 -119
  66. llms/extensions/core_tools/ui/codemirror/addon/selection/selection-pointer.js +0 -98
  67. llms/extensions/core_tools/ui/codemirror/doc/docs.css +0 -225
  68. llms/extensions/core_tools/ui/codemirror/doc/source_sans.woff +0 -0
  69. llms/extensions/core_tools/ui/codemirror/lib/codemirror.css +0 -344
  70. llms/extensions/core_tools/ui/codemirror/lib/codemirror.js +0 -9884
  71. llms/extensions/core_tools/ui/codemirror/mode/clike/clike.js +0 -942
  72. llms/extensions/core_tools/ui/codemirror/mode/javascript/index.html +0 -118
  73. llms/extensions/core_tools/ui/codemirror/mode/javascript/javascript.js +0 -962
  74. llms/extensions/core_tools/ui/codemirror/mode/javascript/typescript.html +0 -62
  75. llms/extensions/core_tools/ui/codemirror/mode/python/python.js +0 -402
  76. llms/extensions/core_tools/ui/codemirror/theme/dracula.css +0 -40
  77. llms/extensions/core_tools/ui/codemirror/theme/mocha.css +0 -135
  78. llms/extensions/core_tools/ui/index.mjs +0 -650
  79. llms/extensions/gallery/README.md +0 -61
  80. llms/extensions/gallery/__init__.py +0 -61
  81. llms/extensions/gallery/__pycache__/__init__.cpython-314.pyc +0 -0
  82. llms/extensions/gallery/__pycache__/db.cpython-314.pyc +0 -0
  83. llms/extensions/gallery/db.py +0 -298
  84. llms/extensions/gallery/ui/index.mjs +0 -482
  85. llms/extensions/katex/README.md +0 -39
  86. llms/extensions/katex/__init__.py +0 -6
  87. llms/extensions/katex/__pycache__/__init__.cpython-314.pyc +0 -0
  88. llms/extensions/katex/ui/README.md +0 -125
  89. llms/extensions/katex/ui/contrib/auto-render.js +0 -338
  90. llms/extensions/katex/ui/contrib/auto-render.min.js +0 -1
  91. llms/extensions/katex/ui/contrib/auto-render.mjs +0 -244
  92. llms/extensions/katex/ui/contrib/copy-tex.js +0 -127
  93. llms/extensions/katex/ui/contrib/copy-tex.min.js +0 -1
  94. llms/extensions/katex/ui/contrib/copy-tex.mjs +0 -105
  95. llms/extensions/katex/ui/contrib/mathtex-script-type.js +0 -109
  96. llms/extensions/katex/ui/contrib/mathtex-script-type.min.js +0 -1
  97. llms/extensions/katex/ui/contrib/mathtex-script-type.mjs +0 -24
  98. llms/extensions/katex/ui/contrib/mhchem.js +0 -3213
  99. llms/extensions/katex/ui/contrib/mhchem.min.js +0 -1
  100. llms/extensions/katex/ui/contrib/mhchem.mjs +0 -3109
  101. llms/extensions/katex/ui/contrib/render-a11y-string.js +0 -887
  102. llms/extensions/katex/ui/contrib/render-a11y-string.min.js +0 -1
  103. llms/extensions/katex/ui/contrib/render-a11y-string.mjs +0 -800
  104. llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.ttf +0 -0
  105. llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.woff +0 -0
  106. llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  107. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  108. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  109. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  110. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  111. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  112. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  113. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  114. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  115. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  116. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  117. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  118. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  119. llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.ttf +0 -0
  120. llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.woff +0 -0
  121. llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.woff2 +0 -0
  122. llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  123. llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  124. llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  125. llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.ttf +0 -0
  126. llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.woff +0 -0
  127. llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.woff2 +0 -0
  128. llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.ttf +0 -0
  129. llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.woff +0 -0
  130. llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.woff2 +0 -0
  131. llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  132. llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  133. llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  134. llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.ttf +0 -0
  135. llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.woff +0 -0
  136. llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.woff2 +0 -0
  137. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  138. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  139. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  140. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  141. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  142. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  143. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  144. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  145. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  146. llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.ttf +0 -0
  147. llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.woff +0 -0
  148. llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.woff2 +0 -0
  149. llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.ttf +0 -0
  150. llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.woff +0 -0
  151. llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  152. llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.ttf +0 -0
  153. llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.woff +0 -0
  154. llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  155. llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.ttf +0 -0
  156. llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.woff +0 -0
  157. llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  158. llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.ttf +0 -0
  159. llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.woff +0 -0
  160. llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  161. llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  162. llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  163. llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  164. llms/extensions/katex/ui/index.mjs +0 -92
  165. llms/extensions/katex/ui/katex-swap.css +0 -1230
  166. llms/extensions/katex/ui/katex-swap.min.css +0 -1
  167. llms/extensions/katex/ui/katex.css +0 -1230
  168. llms/extensions/katex/ui/katex.js +0 -19080
  169. llms/extensions/katex/ui/katex.min.css +0 -1
  170. llms/extensions/katex/ui/katex.min.js +0 -1
  171. llms/extensions/katex/ui/katex.min.mjs +0 -1
  172. llms/extensions/katex/ui/katex.mjs +0 -18547
  173. llms/extensions/providers/__init__.py +0 -18
  174. llms/extensions/providers/__pycache__/__init__.cpython-314.pyc +0 -0
  175. llms/extensions/providers/__pycache__/anthropic.cpython-314.pyc +0 -0
  176. llms/extensions/providers/__pycache__/chutes.cpython-314.pyc +0 -0
  177. llms/extensions/providers/__pycache__/google.cpython-314.pyc +0 -0
  178. llms/extensions/providers/__pycache__/nvidia.cpython-314.pyc +0 -0
  179. llms/extensions/providers/__pycache__/openai.cpython-314.pyc +0 -0
  180. llms/extensions/providers/__pycache__/openrouter.cpython-314.pyc +0 -0
  181. llms/extensions/providers/anthropic.py +0 -229
  182. llms/extensions/providers/chutes.py +0 -155
  183. llms/extensions/providers/google.py +0 -378
  184. llms/extensions/providers/nvidia.py +0 -105
  185. llms/extensions/providers/openai.py +0 -156
  186. llms/extensions/providers/openrouter.py +0 -72
  187. llms/extensions/system_prompts/README.md +0 -22
  188. llms/extensions/system_prompts/__init__.py +0 -45
  189. llms/extensions/system_prompts/__pycache__/__init__.cpython-314.pyc +0 -0
  190. llms/extensions/system_prompts/ui/index.mjs +0 -280
  191. llms/extensions/system_prompts/ui/prompts.json +0 -1067
  192. llms/extensions/tools/__init__.py +0 -5
  193. llms/extensions/tools/__pycache__/__init__.cpython-314.pyc +0 -0
  194. llms/extensions/tools/ui/index.mjs +0 -204
  195. llms/providers-extra.json +0 -356
  196. llms/ui/ctx.mjs +0 -365
  197. llms/ui/index.mjs +0 -129
  198. llms/ui/modules/chat/ChatBody.mjs +0 -691
  199. llms/ui/modules/chat/index.mjs +0 -828
  200. llms/ui/modules/layout.mjs +0 -243
  201. llms/ui/modules/model-selector.mjs +0 -851
  202. llms_py-3.0.0.dist-info/RECORD +0 -202
  203. {llms_py-3.0.0.dist-info → llms_py-3.0.0b1.dist-info}/WHEEL +0 -0
  204. {llms_py-3.0.0.dist-info → llms_py-3.0.0b1.dist-info}/entry_points.txt +0 -0
  205. {llms_py-3.0.0.dist-info → llms_py-3.0.0b1.dist-info}/licenses/LICENSE +0 -0
  206. {llms_py-3.0.0.dist-info → llms_py-3.0.0b1.dist-info}/top_level.txt +0 -0
llms/ui/ctx.mjs DELETED
@@ -1,365 +0,0 @@
1
-
2
- import { reactive, markRaw } from 'vue'
3
- import { EventBus, humanize, combinePaths } from "@servicestack/client"
4
- import { storageObject } from './utils.mjs'
5
-
6
- export class ExtensionScope {
7
- constructor(ctx, id) {
8
- /**@type {AppContext} */
9
- this.ctx = ctx
10
- this.id = id
11
- this.baseUrl = `${ctx.ai.base}/ext/${this.id}`
12
- this.storageKey = `llms.${this.id}`
13
- this.state = reactive({})
14
- this.prefs = reactive(storageObject(this.storageKey))
15
- }
16
- getPrefs() {
17
- return this.prefs
18
- }
19
- setPrefs(o) {
20
- storageObject(this.storageKey, Object.assign(this.prefs, o))
21
- }
22
- savePrefs() {
23
- storageObject(this.storageKey, this.prefs)
24
- }
25
- setState(o) {
26
- Object.assign(this.state, o)
27
- }
28
- get(url, options) {
29
- return this.ctx.ai.get(combinePaths(this.baseUrl, url), options)
30
- }
31
- delete(url, options) {
32
- return this.ctx.ai.get(combinePaths(this.baseUrl, url), {
33
- ...options,
34
- method: 'DELETE'
35
- })
36
- }
37
- async getJson(url, options) {
38
- return this.ctx.ai.getJson(combinePaths(this.baseUrl, url), options)
39
- }
40
- async deleteJson(url, options) {
41
- return this.ctx.ai.getJson(combinePaths(this.baseUrl, url), {
42
- ...options,
43
- method: 'DELETE'
44
- })
45
- }
46
- post(url, options) {
47
- return this.ctx.ai.post(combinePaths(this.baseUrl, url), options)
48
- }
49
- put(url, options) {
50
- return this.ctx.ai.post(combinePaths(this.baseUrl, url), {
51
- ...options,
52
- method: 'PUT'
53
- })
54
- }
55
- patch(url, options) {
56
- return this.ctx.ai.post(combinePaths(this.baseUrl, url), {
57
- ...options,
58
- method: 'PATCH'
59
- })
60
- }
61
- async postForm(url, options) {
62
- return await this.ctx.ai.postForm(combinePaths(this.baseUrl, url), options)
63
- }
64
- async postJson(url, body) {
65
- return this.ctx.ai.postJson(combinePaths(this.baseUrl, url), {
66
- body: body instanceof FormData ? body : JSON.stringify(body)
67
- })
68
- }
69
- async putJson(url, body) {
70
- return this.ctx.ai.postJson(combinePaths(this.baseUrl, url), {
71
- method: 'PUT',
72
- body: body instanceof FormData ? body : JSON.stringify(body)
73
- })
74
- }
75
- async patchJson(url, body) {
76
- return this.ctx.ai.postJson(combinePaths(this.baseUrl, url), {
77
- method: 'PATCH',
78
- body: body instanceof FormData ? body : JSON.stringify(body)
79
- })
80
- }
81
- async createJsonResult(res) {
82
- return this.ctx.ai.createJsonResult(res)
83
- }
84
- createErrorStatus(status) {
85
- return this.ctx.ai.createErrorStatus(status)
86
- }
87
- createErrorResult(e) {
88
- return this.ctx.ai.createErrorResult(e)
89
- }
90
- setError(e, msg = null) {
91
- const prefix = this.id ? `[${this.id}] ` : ''
92
- this.ctx.setError(e, msg ? `${prefix} ${msg}` : prefix)
93
- }
94
- clearError() {
95
- this.ctx.clearError()
96
- }
97
- toast(msg) {
98
- this.ctx.toast(msg)
99
- }
100
- }
101
-
102
- export class AppContext {
103
- constructor({ app, routes, ai, fmt, utils, marked }) {
104
- this.app = app
105
- this.routes = routes
106
- this.ai = ai
107
- this.fmt = fmt
108
- this.utils = utils
109
- this._components = {}
110
- this.marked = marked
111
-
112
- this.state = reactive({})
113
- this.events = new EventBus()
114
- this.modalComponents = {}
115
- this.extensions = []
116
- this.markedFilters = []
117
- this.chatRequestFilters = []
118
- this.chatResponseFilters = []
119
- this.chatErrorFilters = []
120
- this.createThreadFilters = []
121
- this.updateThreadFilters = []
122
- this.top = {}
123
- this.left = {}
124
- this.layout = reactive(storageObject(`llms.layout`))
125
- this.prefs = reactive(storageObject(ai.prefsKey))
126
- this._onRouterBeforeEach = []
127
- this._onClass = []
128
-
129
- if (!Array.isArray(this.layout.hide)) {
130
- this.layout.hide = []
131
- }
132
- Object.assign(app.config.globalProperties, {
133
- $ctx: this,
134
- $prefs: this.prefs,
135
- $state: this.state,
136
- $layout: this.layout,
137
- $ai: ai,
138
- $fmt: fmt,
139
- $utils: utils,
140
- })
141
- Object.keys(app.config.globalProperties).forEach(key => {
142
- globalThis[key] = app.config.globalProperties[key]
143
- })
144
- document.addEventListener('keydown', (e) => this.handleKeydown(e))
145
- }
146
- async init() {
147
- Object.assign(this.state, await this.ai.init(this))
148
- Object.assign(this.fmt, {
149
- markdown: this.renderMarkdown.bind(this)
150
- })
151
- }
152
- setGlobals(globals) {
153
- Object.entries(globals).forEach(([name, global]) => {
154
- const globalName = '$' + name
155
- globalThis[globalName] = this.app.config.globalProperties[globalName] = global
156
- this[name] = global
157
- })
158
- }
159
- getPrefs() {
160
- return this.prefs
161
- }
162
- setPrefs(o) {
163
- storageObject(this.ai.prefsKey, Object.assign(this.prefs, o))
164
- }
165
- _validateIcons(icons) {
166
- Object.entries(icons).forEach(([id, icon]) => {
167
- if (!icon.component) {
168
- console.error(`Icon ${id} is missing component property`)
169
- }
170
- icon.id = id
171
- if (!icon.name) {
172
- icon.name = humanize(id)
173
- }
174
- if (typeof icon.isActive != 'function') {
175
- icon.isActive = () => false
176
- }
177
- })
178
- return icons
179
- }
180
- setTopIcons(icons) {
181
- Object.assign(this.top, this._validateIcons(icons))
182
- }
183
- setLeftIcons(icons) {
184
- Object.assign(this.left, this._validateIcons(icons))
185
- }
186
- component(name, component) {
187
- if (!name) return name
188
- if (component) {
189
- this._components[name] = component
190
- }
191
- return component || this._components[name] || this.app.component(name)
192
- }
193
- components(components) {
194
- if (components) {
195
- Object.keys(components).forEach(name => {
196
- this._components[name] = components[name]
197
- })
198
- }
199
- return this._components
200
- }
201
- scope(extension) {
202
- return new ExtensionScope(this, extension)
203
- }
204
- modals(modals) {
205
- Object.keys(modals).forEach(name => {
206
- const modal = markRaw(modals[name])
207
- this.modalComponents[name] = modal
208
- this.component(name, modal)
209
- })
210
- }
211
- openModal(name) {
212
- const component = this.modalComponents[name]
213
- if (!component) {
214
- console.error(`Modal ${name} not found`)
215
- return
216
- }
217
- console.debug('openModal', name)
218
- this.router.push({ query: { open: name } })
219
- this.events.publish('modal:open', name)
220
- return component
221
- }
222
- closeModal(name) {
223
- console.debug('closeModal', name)
224
- this.router.push({ query: { open: undefined } })
225
- this.events.publish('modal:close', name)
226
- }
227
- handleKeydown(e) {
228
- if (e.key === 'Escape') {
229
- const modal = this.router.currentRoute.value?.query?.open
230
- if (modal) {
231
- this.closeModal(modal)
232
- }
233
- this.events.publish(`keydown:Escape`, e)
234
- }
235
- }
236
- setState(o) {
237
- Object.assign(this.state, o)
238
- }
239
- setLayout(o) {
240
- Object.assign(this.layout, o)
241
- storageObject(`llms.layout`, this.layout)
242
- }
243
- toggleLayout(key, toggle = undefined) {
244
- const hide = toggle == undefined
245
- ? !this.layout.hide.includes(key)
246
- : !toggle
247
- console.log('toggleLayout', key, hide)
248
- if (hide) {
249
- this.layout.hide.push(key)
250
- } else {
251
- this.layout.hide = this.layout.hide.filter(k => k != key)
252
- }
253
- storageObject(`llms.layout`, this.layout)
254
- }
255
- layoutVisible(key) {
256
- return !this.layout.hide.includes(key)
257
- }
258
- toggleTop(name, toggle) {
259
- if (toggle === false) {
260
- this.layout.top = undefined
261
- } else if (toggle === true) {
262
- this.layout.top = name
263
- } else {
264
- this.layout.top = this.layout.top == name ? undefined : name
265
- }
266
- storageObject(`llms.layout`, this.layout)
267
- console.log('toggleTop', name, toggle, this.layout.top, this.layout.top === name)
268
- return this.layout.top === name
269
- }
270
- togglePath(path, toggle) {
271
- const currentPath = this.router.currentRoute.value?.path
272
- console.log('togglePath', path, currentPath, toggle)
273
- if (currentPath != path) {
274
- if (toggle === undefined) {
275
- toggle = true
276
- }
277
- this.router.push({ path })
278
- }
279
- this.toggleLayout('left', toggle)
280
- return toggle
281
- }
282
-
283
- createErrorStatus(status) {
284
- return this.ai.createErrorStatus(status)
285
- }
286
- createErrorResult(e) {
287
- return this.ai.createErrorResult(e)
288
- }
289
- setError(error, msg = null) {
290
- this.state.error = error
291
- if (error) {
292
- if (msg) {
293
- console.error(error.message, msg, error)
294
- } else {
295
- console.error(error.message, error)
296
- }
297
- }
298
- }
299
- clearError() {
300
- this.state.error = null
301
- }
302
-
303
- async getJson(url, options) {
304
- return await this.ai.getJson(url, options)
305
- }
306
- async post(url, options) {
307
- return await this.ai.post(url, options)
308
- }
309
- async postForm(url, options) {
310
- return await this.ai.postForm(url, options)
311
- }
312
- async postJson(url, options) {
313
- return await this.ai.postJson(url, options)
314
- }
315
- to(route) {
316
- if (typeof route == 'string') {
317
- route = route.startsWith(this.ai.base)
318
- ? route
319
- : combinePaths(this.ai.base, route)
320
- const path = { path: route }
321
- console.log('to', path)
322
- this.router.push(path)
323
- } else {
324
- route.path = route.path.startsWith(this.ai.base)
325
- ? route.path
326
- : combinePaths(this.ai.base, route.path)
327
- console.log('to', route)
328
- this.router.push(route)
329
- }
330
- }
331
-
332
- // Events
333
- onRouterBeforeEach(callback) {
334
- this._onRouterBeforeEach.push(callback)
335
- }
336
-
337
- onClass(callback) {
338
- this._onClass.push(callback)
339
- }
340
-
341
- cls(id, cls) {
342
- if (this._onClass.length) {
343
- this._onClass.forEach(callback => {
344
- cls = callback(id, cls) ?? cls
345
- })
346
- }
347
- return cls
348
- }
349
- toast(msg) {
350
- this.setState({ toast: msg })
351
- }
352
-
353
- renderMarkdown(content) {
354
- if (Array.isArray(content)) {
355
- content = content.filter(c => c.type === 'text').map(c => c.text).join('\n')
356
- }
357
- // Handled by katex
358
- // if (content) {
359
- // content = content
360
- // .replaceAll(`\\[ \\boxed{`, '\n<span class="inline-block text-xl text-blue-500 bg-blue-50 dark:text-blue-400 dark:bg-blue-950 px-3 py-1 rounded">')
361
- // .replaceAll('} \\]', '</span>\n')
362
- // }
363
- return this.marked.parse(content || '')
364
- }
365
- }
llms/ui/index.mjs DELETED
@@ -1,129 +0,0 @@
1
-
2
- import { createApp } from 'vue'
3
- import { createWebHistory, createRouter } from "vue-router"
4
- import ServiceStackVue, { useFormatters } from "@servicestack/vue"
5
- import App from './App.mjs'
6
- import ai from './ai.mjs'
7
- import LayoutModule from './modules/layout.mjs'
8
- import ChatModule from './modules/chat/index.mjs'
9
- import ModelSelectorModule from './modules/model-selector.mjs'
10
- import { utilsFunctions, utilsFormatters } from './utils.mjs'
11
- import { marked, markdownFormatters } from './markdown.mjs'
12
- import { AppContext } from './ctx.mjs'
13
-
14
- const Components = {
15
- }
16
-
17
- const BuiltInModules = {
18
- LayoutModule,
19
- ChatModule,
20
- ModelSelectorModule,
21
- }
22
-
23
-
24
- export async function createContext() {
25
- const app = createApp(App)
26
-
27
- app.use(ServiceStackVue)
28
- Object.keys(Components).forEach(name => {
29
- app.component(name, Components[name])
30
- })
31
-
32
- const fmt = Object.assign({}, useFormatters(), utilsFormatters())
33
- const utils = Object.assign({}, utilsFunctions())
34
- const routes = []
35
-
36
- const ctx = new AppContext({ app, routes, ai, fmt, utils, marked })
37
- app.provide('ctx', ctx)
38
- await ctx.init()
39
-
40
- // Load modules in parallel
41
- const validExtensions = ctx.state.extensions.filter(x => x.path);
42
- ctx.modules = await Promise.all(validExtensions.map(async extension => {
43
- try {
44
- const module = await import(extension.path)
45
- const order = module.default.order || 0
46
- return { extension, module, order }
47
- } catch (e) {
48
- console.error(`Failed to load extension module ${extension.name}:`, e)
49
- return null
50
- }
51
- }))
52
-
53
- // sort modules by order
54
- ctx.modules.sort((a, b) => a.order - b.order)
55
-
56
- const installedModules = []
57
-
58
- // Install built-in modules sequentially
59
- Object.entries(BuiltInModules).forEach(([name, module]) => {
60
- try {
61
- module.install(ctx)
62
- installedModules.push({ extension: { id: name }, module: { default: module } })
63
- console.log(`Installed built-in: ${name}`)
64
- } catch (e) {
65
- console.error(`Failed to install built-in ${name}:`, e)
66
- }
67
- })
68
-
69
- // Install extensions sequentially
70
- for (const result of ctx.modules) {
71
- if (result && result.module.default && result.module.default.install) {
72
- try {
73
- result.module.default.install(ctx)
74
- installedModules.push(result)
75
- console.log(`Installed extension: ${result.extension.id}`)
76
- } catch (e) {
77
- console.error(`Failed to install extension ${result.extension.id}:`, e)
78
- }
79
- }
80
- }
81
-
82
- // Register all components with Vue
83
- Object.entries(ctx._components).forEach(([name, component]) => {
84
- app.component(name, component)
85
- })
86
-
87
- // Add fallback route and create router
88
- routes.push({ path: '/:fallback(.*)*', component: ctx.component('Home') })
89
- routes.forEach(r => r.path = ai.base + r.path)
90
- ctx.router = createRouter({
91
- history: createWebHistory(),
92
- routes,
93
- })
94
- app.use(ctx.router)
95
-
96
- ctx.router.beforeEach((to, from) => {
97
- const title = to.meta.title || 'Chat'
98
- console.debug('router:change', to.path, title)
99
- ctx.setLayout({ path: to.path })
100
- ctx.setState({ title })
101
- document.title = title
102
- return true
103
- })
104
- ctx._onRouterBeforeEach.forEach(ctx.router.beforeEach)
105
-
106
- if (ai.hasAccess) {
107
- if (ctx.layout.path && location.pathname === '/' && !location.search) {
108
- console.log('redirecting to saved path: ', ctx.layout.path)
109
- ctx.router.push({ path: ctx.layout.path })
110
- }
111
- } else {
112
- ctx.router.push({ path: '/' })
113
- }
114
-
115
- const loadModules = installedModules.filter(x => x.module.default && x.module.default.load)
116
- console.log('Loading modules: ', loadModules.map(x => x.extension.id))
117
-
118
- // Load all extensions in parallel
119
- await Promise.all(loadModules.map(async result => {
120
- try {
121
- await result.module.default.load(ctx)
122
- console.log(`Loaded extension: ${result.extension.id}`)
123
- } catch (e) {
124
- console.error(`Failed to load extension ${result.extension.id}:`, e)
125
- }
126
- }))
127
-
128
- return ctx
129
- }