/**
* Create a new Supabase project.
*
* @param {Object} args - Arguments for creating a project.
* @param {string} args.db_pass - The database password.
* @param {string} args.name - The project name.
* @param {string} args.organization_slug - The organization slug.
* @param {string} args.organization_id - The organization ID.
* @param {string} args.plan - The plan (e.g., "free").
* @param {string} args.region - The region (e.g., "eu-west-2").
* @param {Object} [args.region_selection] - Region selection object.
* @param {string} [args.region_selection.type] - Type of region selection.
* @param {string} [args.region_selection.code] - Region code.
* @param {boolean} [args.kps_enabled] - Whether KPS is enabled.
* @param {string} [args.desired_instance_size] - Desired instance size.
* @param {string} [args.template_url] - Template URL.
* @param {string} [args.release_channel] - Release channel.
* @param {string} [args.postgres_engine] - Postgres engine version.
* @returns {Promise<Object>} - The response from the Supabase Management API.
*/
const createProject = async ({
db_pass,
name,
organization_slug,
organization_id,
plan,
region,
region_selection,
kps_enabled,
desired_instance_size,
template_url,
release_channel,
postgres_engine
}) => {
const baseUrl = 'https://api.supabase.com';
const bearerToken = process.env.SUPABASE_PUBLIC_API_API_KEY;
try {
const url = `${baseUrl}/v1/projects`;
const body = {
db_pass,
name,
organization_slug,
organization_id,
plan,
region,
region_selection,
kps_enabled,
desired_instance_size,
template_url,
release_channel,
postgres_engine
};
// Remove undefined keys
Object.keys(body).forEach(
(key) => body[key] === undefined && delete body[key]
);
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${bearerToken}`
},
body: JSON.stringify(body)
});
if (!response.ok) {
let err;
try {
err = await response.json();
} catch {
err = await response.text();
}
throw new Error(typeof err === 'string' ? err : JSON.stringify(err));
}
return await response.json();
} catch (error) {
return {
error: error instanceof Error ? error.message : JSON.stringify(error)
};
}
};
/**
* Tool definition for creating a Supabase project.
*/
const apiTool = {
function: createProject,
definition: {
type: 'function',
function: {
name: 'create_project',
description: 'Create a new Supabase project.',
parameters: {
type: 'object',
properties: {
db_pass: {
type: 'string',
description: 'The database password.'
},
name: {
type: 'string',
description: 'The project name.'
},
organization_slug: {
type: 'string',
description: 'The organization slug.'
},
organization_id: {
type: 'string',
description: 'The organization ID.'
},
plan: {
type: 'string',
description: 'The plan (e.g., "free").'
},
region: {
type: 'string',
description: 'The region (e.g., "eu-west-2").'
},
region_selection: {
type: 'object',
description: 'Region selection object.',
properties: {
type: { type: 'string', description: 'Type of region selection.' },
code: { type: 'string', description: 'Region code.' }
}
},
kps_enabled: {
type: 'boolean',
description: 'Whether KPS is enabled.'
},
desired_instance_size: {
type: 'string',
description: 'Desired instance size.'
},
template_url: {
type: 'string',
description: 'Template URL.'
},
release_channel: {
type: 'string',
description: 'Release channel.'
},
postgres_engine: {
type: 'string',
description: 'Postgres engine version.'
}
},
required: [
'db_pass',
'name',
'organization_slug',
'organization_id',
'plan',
'region'
]
}
}
}
};
export { apiTool };