mirror of
https://github.com/open-webui/open-webui
synced 2025-06-08 15:37:22 +00:00
enh: pyodide
This commit is contained in:
parent
8685256002
commit
09cd95bffe
9
package-lock.json
generated
9
package-lock.json
generated
@ -56,7 +56,7 @@
|
|||||||
"prosemirror-schema-list": "^1.4.1",
|
"prosemirror-schema-list": "^1.4.1",
|
||||||
"prosemirror-state": "^1.4.3",
|
"prosemirror-state": "^1.4.3",
|
||||||
"prosemirror-view": "^1.34.3",
|
"prosemirror-view": "^1.34.3",
|
||||||
"pyodide": "^0.26.1",
|
"pyodide": "^0.27.2",
|
||||||
"socket.io-client": "^4.2.0",
|
"socket.io-client": "^4.2.0",
|
||||||
"sortablejs": "^1.15.2",
|
"sortablejs": "^1.15.2",
|
||||||
"svelte-sonner": "^0.3.19",
|
"svelte-sonner": "^0.3.19",
|
||||||
@ -9366,9 +9366,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/pyodide": {
|
"node_modules/pyodide": {
|
||||||
"version": "0.26.1",
|
"version": "0.27.2",
|
||||||
"resolved": "https://registry.npmjs.org/pyodide/-/pyodide-0.26.1.tgz",
|
"resolved": "https://registry.npmjs.org/pyodide/-/pyodide-0.27.2.tgz",
|
||||||
"integrity": "sha512-P+Gm88nwZqY7uBgjbQH8CqqU6Ei/rDn7pS1t02sNZsbyLJMyE2OVXjgNuqVT3KqYWnyGREUN0DbBUCJqk8R0ew==",
|
"integrity": "sha512-sfA2kiUuQVRpWI4BYnU3sX5PaTTt/xrcVEmRzRcId8DzZXGGtPgCBC0gCqjUTUYSa8ofPaSjXmzESc86yvvCHg==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ws": "^8.5.0"
|
"ws": "^8.5.0"
|
||||||
},
|
},
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
"prosemirror-schema-list": "^1.4.1",
|
"prosemirror-schema-list": "^1.4.1",
|
||||||
"prosemirror-state": "^1.4.3",
|
"prosemirror-state": "^1.4.3",
|
||||||
"prosemirror-view": "^1.34.3",
|
"prosemirror-view": "^1.34.3",
|
||||||
"pyodide": "^0.26.1",
|
"pyodide": "^0.27.2",
|
||||||
"socket.io-client": "^4.2.0",
|
"socket.io-client": "^4.2.0",
|
||||||
"sortablejs": "^1.15.2",
|
"sortablejs": "^1.15.2",
|
||||||
"svelte-sonner": "^0.3.19",
|
"svelte-sonner": "^0.3.19",
|
||||||
|
@ -74,33 +74,26 @@ self.onmessage = async (event) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function processResult(result: any): any {
|
function processResult(result: any): any {
|
||||||
// Handle null and undefined
|
// Catch and always return JSON-safe string representations
|
||||||
|
try {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
// Handle null and undefined
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (typeof result === 'string' || typeof result === 'number' || typeof result === 'boolean') {
|
||||||
|
// Handle primitive types directly
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle primitive types
|
|
||||||
if (typeof result !== 'object') {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Date objects
|
|
||||||
if (result instanceof Date) {
|
|
||||||
return result.toISOString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Arrays
|
|
||||||
if (Array.isArray(result)) {
|
if (Array.isArray(result)) {
|
||||||
|
// If it's an array, recursively process items
|
||||||
return result.map((item) => processResult(item));
|
return result.map((item) => processResult(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Proxy objects (assuming they're from Pyodide)
|
|
||||||
if (typeof result.toJs === 'function') {
|
if (typeof result.toJs === 'function') {
|
||||||
|
// If it's a Pyodide proxy object (e.g., Pandas DF, Numpy Array), convert to JS and process recursively
|
||||||
return processResult(result.toJs());
|
return processResult(result.toJs());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle regular objects
|
|
||||||
if (typeof result === 'object') {
|
if (typeof result === 'object') {
|
||||||
|
// Convert JS objects to a recursively serialized representation
|
||||||
const processedObject: { [key: string]: any } = {};
|
const processedObject: { [key: string]: any } = {};
|
||||||
for (const key in result) {
|
for (const key in result) {
|
||||||
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
||||||
@ -109,9 +102,12 @@ function processResult(result: any): any {
|
|||||||
}
|
}
|
||||||
return processedObject;
|
return processedObject;
|
||||||
}
|
}
|
||||||
|
// Stringify anything that's left (e.g., Proxy objects that cannot be directly processed)
|
||||||
// If we can't process it, return null or a placeholder
|
return JSON.stringify(result);
|
||||||
return null;
|
} catch (err) {
|
||||||
|
// In case something unexpected happens, we return a stringified fallback
|
||||||
|
return `[processResult error]: ${err.toString()}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {};
|
export default {};
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user