File size: 752 Bytes
3b6afc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { loadSpecs } = require('./loadSpecs');

function transformSpec(input) {
  return {
    name: input.name_for_human,
    pluginKey: input.name_for_model,
    description: input.description_for_human,
    icon: input?.logo_url ?? 'https://placehold.co/70x70.png',
    // TODO: add support for authentication
    isAuthRequired: 'false',
    authConfig: [],
  };
}

async function addOpenAPISpecs(availableTools) {
  try {
    const specs = (await loadSpecs({})).map(transformSpec);
    if (specs.length > 0) {
      return [...specs, ...availableTools];
    }
    return availableTools;
  } catch (error) {
    console.log('addOpenAPISpecs error', error);
    return availableTools;
  }
}

module.exports = {
  transformSpec,
  addOpenAPISpecs,
};