Skip to content

Commit

Permalink
Website: add configuration profile generator (#26244)
Browse files Browse the repository at this point in the history
Changes:
- Added /os-settings, a page where users can generate configuration
profiles
- Updated the docs navigation component to have a link to the os
settings page
- Added a new action: `get-llm-generated-configuration-profile` that
generates a configuration profile in either .mobileconfig, DDM, or CSP
formats.
- Added a new website dependency: ace editor.
  • Loading branch information
eashaw authored Feb 11, 2025
1 parent ebdb4b8 commit 360c23d
Show file tree
Hide file tree
Showing 16 changed files with 30,613 additions and 1 deletion.
103 changes: 103 additions & 0 deletions website/api/controllers/get-llm-generated-configuration-profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module.exports = {


friendlyName: 'Get llm generated configuration profile',


description: '',


inputs: {
profileType: {
type: 'string',
isIn: [
'mobileconfig',
'csp',
'ddm',
],
required: true
},
naturalLanguageInstructions: {
type: 'string',
required: true
}
},


exits: {
success: {
description: 'A configuration profile was successfully generated for a user.',
},
couldNotGenerateProfile: {
description: 'A configuration profile could not be generated for a user using the provided instructions.',
responseType: 'badRequest'
}
},


fn: async function ({profileType, naturalLanguageInstructions}) {

let promptStringByProfileType = {
'csp': 'CSP XML profile that enforces OS settings on Windows devices',
'mobileconfig': 'XML .mobileconfig profile that enforces OS settings on macOS devices',
'ddm': 'Apple DDM MDM profile in XML format that enforces OS settings on macOS devices',
};

let configurationProfilePrompt = `Given this question from an IT admin, generate a ${promptStringByProfileType[profileType]}.
Here are the instructions:
\`\`\`
${naturalLanguageInstructions}
\`\`\`
Please give me all of the above in JSON, with this data shape:
{
"configurationProfile": "TODO"
"profileFilename": "TODO"
"settingsEnforced": [// For each setting enforced by the configuration profile.
{
// The name (key) of the settings that is enforced. e.g., LoginwindowText
name: "TODO",
// The value of the setting that is enforced
value: "TODO",
},
{...}
]
}
If a configuration profile cannot be generated from the provided instructions do not return the datashape above and instead return this JSON in this exact data shape:
{
"couldNotGenerateProfile": true
}
`;

// console.log(configurationProfilePrompt);
let configurationProfileGenerationResult = await sails.helpers.ai.prompt.with({
prompt: configurationProfilePrompt,
baseModel: 'o3-mini-2025-01-31',
// expectJson: true
}).intercept((err)=>{
return new Error(`When trying generate a configuration profile for a user, an error occurred. Full error: ${require('util').inspect(err, {depth: 2})}`);
});
let jsonResult = JSON.parse(configurationProfileGenerationResult);
// console.log(configurationProfileGenerationResult);
// All done.
if(jsonResult.couldNotGenerateProfile) {
throw 'couldNotGenerateProfile';
}
if(!jsonResult.configurationProfile || !jsonResult.profileFilename || !jsonResult.settingsEnforced){
throw 'couldNotGenerateProfile';
}
return {
profile: jsonResult.configurationProfile,
profileFilename: jsonResult.profileFilename,
items: jsonResult.settingsEnforced
};

}


};
27 changes: 27 additions & 0 deletions website/api/controllers/view-os-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {


friendlyName: 'View os settings',


description: 'Display "Os settings" page.',


exits: {

success: {
viewTemplatePath: 'pages/os-settings'
}

},


fn: async function () {

// Respond with view.
return {};

}


};
1 change: 1 addition & 0 deletions website/assets/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Chart": true,
"gtag": true,
"analytics": true,
"ace": true,
// ...etc.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Expand Down
Loading

0 comments on commit 360c23d

Please sign in to comment.