-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/extensions #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SpliiT
wants to merge
32
commits into
next
Choose a base branch
from
feat/extensions
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/extensions #272
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5871a71
app js edited
SpliiT ab5e187
App.js changes
SpliiT 9e4a435
changes app.js
SpliiT 2f9743c
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
SpliiT c337845
app.js changes
SpliiT 28250e1
aoi
SpliiT 9afa9d0
rm app.js from stores out of /app
SpliiT 76e949b
change log
SpliiT 68c5a44
rm comments
SpliiT 374a4f6
transform code
SpliiT f7d45e9
move logic & refacto
SpliiT c66dc70
move feature
SpliiT 7a8393e
transformer edit
SpliiT 4302d90
add extensionID
SpliiT e2a93e1
rm useless extensionID
SpliiT 007e1a6
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
SpliiT 63727d5
Apply prepare changes
SpliiT 5f2c995
from next
SpliiT 45afffd
Apply prepare changes
SpliiT 9bf35d2
backendPath added
MaxNumerique 24d5703
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
MaxNumerique 6428818
feat: dynamically adjust chat input textarea rows, character limit, a…
SpliiT 7a70c67
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
SpliiT b145f33
Apply prepare changes
SpliiT f8e3287
lauchExtensionMicroservice with backendPath
MaxNumerique a9468f9
test
MaxNumerique ed49890
demo mode and debug
MaxNumerique cf06595
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
JulienChampagnol f2f5355
Apply prepare changes
JulienChampagnol f34b918
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
JulienChampagnol 809d597
merge
JulienChampagnol d2776ab
Apply prepare changes
JulienChampagnol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,10 +67,140 @@ export const useAppStore = defineStore("app", () => { | |
| console.log(`[AppStore] Imported ${importedCount} stores`) | ||
| } | ||
|
|
||
| const loadedExtensions = ref(new Map()) | ||
| const extensionAPI = ref(null) | ||
|
|
||
| function setExtensionAPI(api) { | ||
| extensionAPI.value = api | ||
| } | ||
|
|
||
| function getExtension(path) { | ||
| return loadedExtensions.value.get(path) | ||
| } | ||
|
|
||
| async function loadExtension(path, codeTransformer = null) { | ||
| try { | ||
| if (loadedExtensions.value.has(path)) { | ||
| console.warn(`[AppStore] Extension already loaded from this path: ${path}`) | ||
| throw new Error('This extension file is already loaded') | ||
| } | ||
|
|
||
| if (!extensionAPI.value) { | ||
| throw new Error("Extension API not initialized") | ||
| } | ||
|
|
||
| let finalURL = path | ||
|
|
||
| if (codeTransformer && path.startsWith('blob:')) { | ||
| const response = await fetch(path) | ||
| const code = await response.text() | ||
| const transformedCode = codeTransformer(code) | ||
|
|
||
| const newBlob = new Blob([transformedCode], { type: 'application/javascript' }) | ||
| finalURL = URL.createObjectURL(newBlob) | ||
| } | ||
|
|
||
| const extensionModule = await import(finalURL) | ||
|
|
||
| if (finalURL !== path && finalURL.startsWith('blob:')) { | ||
| URL.revokeObjectURL(finalURL) | ||
| } | ||
|
|
||
| const extensionName = extensionModule.metadata?.name | ||
| if (extensionName) { | ||
| const alreadyLoaded = Array.from(loadedExtensions.value.values()).find( | ||
| ext => ext.metadata?.name === extensionName | ||
| ) | ||
| if (alreadyLoaded) { | ||
| console.warn(`[AppStore] Extension "${extensionName}" is already loaded`) | ||
| throw new Error(`Extension "${extensionName}" is already loaded.`) | ||
| } | ||
| } | ||
|
|
||
| if (typeof extensionModule.install === 'function') { | ||
| await extensionModule.install(extensionAPI.value, path) | ||
SpliiT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const extensionData = { | ||
| module: extensionModule, | ||
| path, | ||
| loadedAt: new Date().toISOString(), | ||
| metadata: extensionModule.metadata || {}, | ||
| enabled: true, | ||
| } | ||
| loadedExtensions.value.set(path, extensionData) | ||
|
|
||
| console.log(`[AppStore] Extension loaded successfully: ${path}`) | ||
|
|
||
| return extensionModule | ||
| } else { | ||
| throw new Error('Extension must export an install function') | ||
| } | ||
| } catch (error) { | ||
| console.error(`[AppStore] Failed to load extension from ${path}:`, error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| function getLoadedExtensions() { | ||
| return Array.from(loadedExtensions.value.values()) | ||
| } | ||
|
|
||
| function unloadExtension(path) { | ||
SpliiT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const extensionData = getExtension(path) | ||
| if (!extensionData) return false | ||
|
|
||
| if (extensionData.module && typeof extensionData.module.uninstall === 'function') { | ||
| try { | ||
| extensionData.module.uninstall(extensionAPI.value, path) | ||
| console.log(`[AppStore] Extension uninstall called: ${path}`) | ||
| } catch (error) { | ||
| console.error(`[AppStore] Error calling uninstall for ${path}:`, error) | ||
| } | ||
| } | ||
|
|
||
| if (extensionAPI.value && typeof extensionAPI.value.unregisterToolsByExtension === 'function') { | ||
| extensionAPI.value.unregisterToolsByExtension(path) | ||
| } | ||
|
|
||
| loadedExtensions.value.delete(path) | ||
| console.log(`[AppStore] Extension unloaded: ${path}`) | ||
| return true | ||
| } | ||
|
|
||
| function toggleExtension(path) { | ||
| const extensionData = getExtension(path) | ||
| if (!extensionData) return false | ||
|
|
||
| extensionData.enabled = !extensionData.enabled | ||
| console.log(`[AppStore] Extension ${extensionData.enabled ? 'enabled' : 'disabled'}: ${path}`) | ||
| return extensionData.enabled | ||
| } | ||
|
|
||
| function setExtensionEnabled(path, enabled) { | ||
| const extensionData = getExtension(path) | ||
| if (!extensionData) return false | ||
|
|
||
| extensionData.enabled = enabled | ||
| console.log(`[AppStore] Extension ${enabled ? 'enabled' : 'disabled'}: ${path}`) | ||
| return true | ||
| } | ||
|
|
||
| function getExtensionEnabled(path) { | ||
| return getExtension(path)?.enabled ?? false | ||
| } | ||
|
|
||
| return { | ||
| stores, | ||
| registerStore, | ||
| exportStores, | ||
| importStores, | ||
| loadedExtensions, | ||
| setExtensionAPI, | ||
| loadExtension, | ||
| getLoadedExtensions, | ||
| unloadExtension, | ||
| toggleExtension, | ||
| setExtensionEnabled, | ||
| getExtensionEnabled, | ||
| } | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce que le transformer doit être donné par l'extension ou fourni par OGW?