Improve Apps class to enforce required fields and improve title handling. Added validation for name and index URL, as they are mandatory for app creation. Updated title assignment to default to name if not provided.

This commit is contained in:
jelveh
2025-08-06 19:41:14 -07:00
parent e8f6b06723
commit 41a62326bf

View File

@@ -69,11 +69,14 @@ class Apps{
// * allows for: puter.apps.new({name: 'example-app', indexURL: 'https://example.com'}) *
else if (typeof args[0] === 'object' && args[0] !== null) {
let options_raw = args[0];
options = {
object: {
name: options_raw.name,
index_url: options_raw.indexURL,
title: options_raw.title,
// title is optional only if name is provided.
// If title is provided, use it. If not, use name.
title: options_raw.title ?? options_raw.name,
description: options_raw.description,
icon: options_raw.icon,
maximize_on_start: options_raw.maximizeOnStart,
@@ -86,6 +89,27 @@ class Apps{
}
};
}
// name and indexURL are required
if(!options.object.name){
throw {
success: false,
error: {
code: 'invalid_request',
message: 'Name is required'
}
};
}
if(!options.object.index_url){
throw {
success: false,
error: {
code: 'invalid_request',
message: 'Index URL is required'
}
};
}
// Call the original chat.complete method
return await utils.make_driver_method(['object'], 'puter-apps', undefined, 'create').call(this, options);
}