llms-py 3.0.0b3__py3-none-any.whl → 3.0.0b5__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.
llms/ui/ctx.mjs CHANGED
@@ -11,12 +11,13 @@ export class ExtensionScope {
11
11
  this.baseUrl = `${ctx.ai.base}/ext/${this.id}`
12
12
  this.storageKey = `llms.${this.id}`
13
13
  this.state = reactive({})
14
+ this.prefs = reactive(storageObject(this.storageKey))
14
15
  }
15
16
  getPrefs() {
16
- return storageObject(this.storageKey)
17
+ return this.prefs
17
18
  }
18
19
  setPrefs(o) {
19
- storageObject(this.storageKey, Object.assign(this.getPrefs(), o))
20
+ storageObject(this.storageKey, Object.assign(this.prefs, o))
20
21
  }
21
22
  get(url, options) {
22
23
  return this.ctx.ai.get(combinePaths(this.baseUrl, url), options)
@@ -45,7 +46,6 @@ export class AppContext {
45
46
  this.events = new EventBus()
46
47
  this.modalComponents = {}
47
48
  this.extensions = []
48
- this.layout = reactive(storageObject(`llms.layout`))
49
49
  this.chatRequestFilters = []
50
50
  this.chatResponseFilters = []
51
51
  this.chatErrorFilters = []
@@ -53,12 +53,15 @@ export class AppContext {
53
53
  this.updateThreadFilters = []
54
54
  this.top = {}
55
55
  this.left = {}
56
+ this.layout = reactive(storageObject(`llms.layout`))
57
+ this.prefs = reactive(storageObject(ai.prefsKey))
56
58
 
57
59
  if (!Array.isArray(this.layout.hide)) {
58
60
  this.layout.hide = []
59
61
  }
60
62
  Object.assign(app.config.globalProperties, {
61
63
  $ctx: this,
64
+ $prefs: this.prefs,
62
65
  $state: this.state,
63
66
  $layout: this.layout,
64
67
  $ai: ai,
@@ -80,6 +83,12 @@ export class AppContext {
80
83
  this[name] = global
81
84
  })
82
85
  }
86
+ getPrefs() {
87
+ return this.prefs
88
+ }
89
+ setPrefs(o) {
90
+ storageObject(this.ai.prefsKey, Object.assign(this.prefs, o))
91
+ }
83
92
  _validateIcons(icons) {
84
93
  Object.entries(icons).forEach(([id, icon]) => {
85
94
  if (!icon.component) {
@@ -173,12 +182,6 @@ export class AppContext {
173
182
  layoutVisible(key) {
174
183
  return !this.layout.hide.includes(key)
175
184
  }
176
- getPrefs() {
177
- return storageObject(this.ai.prefsKey)
178
- }
179
- setPrefs(o) {
180
- storageObject(this.ai.prefsKey, Object.assign(this.getPrefs(), o))
181
- }
182
185
  toggleTop(name) {
183
186
  console.log('toggleTop', name)
184
187
  this.layout.top = this.layout.top == name ? undefined : name
@@ -193,4 +196,10 @@ export class AppContext {
193
196
  this.router.push({ path })
194
197
  }
195
198
  }
199
+ getJson(url, options) {
200
+ return this.ai.getJson(url, options)
201
+ }
202
+ postJson(url, options) {
203
+ return this.ai.postJson(url, options)
204
+ }
196
205
  }
llms/ui/index.mjs CHANGED
@@ -9,6 +9,7 @@ import ChatModule from './modules/chat/index.mjs'
9
9
  import ThreadsModule from './modules/threads/index.mjs'
10
10
  import ModelSelectorModule from './modules/model-selector.mjs'
11
11
  import AnalyticsModule from './modules/analytics.mjs'
12
+ import ToolsModule from './modules/tools.mjs'
12
13
  import { utilsFunctions, utilsFormatters } from './utils.mjs'
13
14
  import { markdownFormatters } from './markdown.mjs'
14
15
  import { AppContext } from './ctx.mjs'
@@ -22,6 +23,7 @@ const BuiltInModules = {
22
23
  ThreadsModule,
23
24
  ModelSelectorModule,
24
25
  AnalyticsModule,
26
+ ToolsModule,
25
27
  }
26
28
 
27
29
 
@@ -53,10 +55,13 @@ export async function createContext() {
53
55
  }
54
56
  }))
55
57
 
58
+ const installedModules = []
59
+
56
60
  // Install built-in modules sequentially
57
61
  Object.entries(BuiltInModules).forEach(([name, module]) => {
58
62
  try {
59
63
  module.install(ctx)
64
+ installedModules.push({ extension: { id: name }, module: { default: module } })
60
65
  console.log(`Installed built-in: ${name}`)
61
66
  } catch (e) {
62
67
  console.error(`Failed to install built-in ${name}:`, e)
@@ -68,6 +73,7 @@ export async function createContext() {
68
73
  if (result && result.module.default && result.module.default.install) {
69
74
  try {
70
75
  result.module.default.install(ctx)
76
+ installedModules.push(result)
71
77
  console.log(`Installed extension: ${result.extension.id}`)
72
78
  } catch (e) {
73
79
  console.error(`Failed to install extension ${result.extension.id}:`, e)
@@ -103,8 +109,11 @@ export async function createContext() {
103
109
  ctx.router.push({ path: ctx.layout.path })
104
110
  }
105
111
 
112
+ const loadModules = installedModules.filter(x => x.module.default && x.module.default.load)
113
+ console.log('Loading modules: ', loadModules.map(x => x.extension.id))
114
+
106
115
  // Load all extensions in parallel
107
- await Promise.all(ctx.modules.filter(x => x.module.default && x.module.default.load).map(async result => {
116
+ await Promise.all(loadModules.map(async result => {
108
117
  try {
109
118
  await result.module.default.load(ctx)
110
119
  console.log(`Loaded extension: ${result.extension.id}`)