/**
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
import UIWindow from './UIWindow.js'
async function UIWindowRequestPermission(options){
options = options ?? {};
options.reload_on_success = options.reload_on_success ?? false;
return new Promise(async (resolve) => {
let drivers = [
{
name: 'puter-chat-completion',
human_name: 'AI Chat Completion',
description: 'This app wants to generate text using AI. This may incur costs on your behalf.',
},
{
name: 'puter-image-generation',
human_name: 'AI Image Generation',
description: 'This app wants to generate images using AI. This may incur costs on your behalf.',
},
{
name: 'puter-kvstore',
human_name: 'Puter Storage',
description: 'This app wants to securely store data in your Puter account. This app will not be able to access your personal data or data stored by other apps.',
}
]
let parts = options.permission.split(":");
let driver_name = parts[1];
let action_name = parts[2];
function findDriverByName(driverName) {
return drivers.find(driver => driver.name === driverName);
}
let driver = findDriverByName(driver_name);
if(driver === undefined){
resolve(false);
return;
}
let h = ``;
h += `
`;
h += `
`;
// title
h += `
"${html_encode(options.app_uid ?? options.origin)}" would Like to use ${html_encode(driver.human_name)}
`;
// todo show the real description of action
h += `