-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
|
||
const esbuild = require('esbuild') | ||
|
||
const makeAllPackagesExternalPlugin = { | ||
name: 'make-all-packages-external', | ||
setup(build) { | ||
const filter = /^[^./]|^\.[^./]|^\.\.[^/]/ // Must not start with "/" or "./" or "../" | ||
build.onResolve({ filter }, (args) => ({ | ||
path: args.path, | ||
external: true, | ||
})) | ||
}, | ||
} | ||
|
||
esbuild | ||
.build({ | ||
bundle: true, | ||
minify: true, | ||
tsconfig: 'tsconfig.json', | ||
platform: 'node', | ||
target: 'node18', | ||
sourcemap: 'both', | ||
plugins: [makeAllPackagesExternalPlugin], | ||
outdir: 'lib', | ||
entryPoints: ['src/index.ts'], | ||
}) | ||
.catch(() => process.exit(1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
|
||
const yaml = require('js-yaml') | ||
const fs = require('fs'); | ||
|
||
const spec = yaml.load(fs.readFileSync('openapi.yaml', 'utf8')) | ||
|
||
function isObjEmpty (obj) { | ||
return Object.keys(obj).length === 0; | ||
} | ||
|
||
const components = spec['components'] | ||
|
||
if (components) { | ||
Object.keys(components).forEach((key) => { | ||
// Delete empty component schemas | ||
if (isObjEmpty(components[key])) { | ||
delete components[key] | ||
} | ||
}) | ||
|
||
// Delete components if empty | ||
if (isObjEmpty(components)) { | ||
delete spec['components'] | ||
} | ||
} | ||
|
||
const paths = spec['paths'] | ||
|
||
if (paths) { | ||
Object.keys(paths).forEach((key) => { | ||
// Delete empty paths | ||
if (isObjEmpty(paths[key])) { | ||
delete paths[key] | ||
} | ||
|
||
|
||
Object.keys(paths[key]).forEach((method) => { | ||
// Delete empty methods | ||
if (isObjEmpty(paths[key][method])) { | ||
delete paths[key][method] | ||
} | ||
|
||
// Delete security if empty | ||
if (paths[key][method]['security']) { | ||
if (paths[key][method]['security'].length === 0) { | ||
delete paths[key][method]['security'] | ||
} | ||
} | ||
|
||
// Delete openai-conversation-id header if exists - this should not be in spec for the plugin, it is automatically added by openai | ||
if (paths[key][method]['parameters']) { | ||
const conversationIDParameterIdx = paths[key][method]['parameters'].findIndex((parameter) => parameter.name === 'openai-conversation-id' && parameter.in === 'header') | ||
if (conversationIDParameterIdx !== -1) { | ||
paths[key][method]['parameters'].splice(conversationIDParameterIdx, 1) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
const info = spec['info'] | ||
if (info) { | ||
// Delete old info - it is generated from package.json with excessive fields | ||
delete spec['info'] | ||
} | ||
|
||
// Add new info | ||
spec['info'] = { | ||
title: 'E2B Code Interpreter', | ||
description: 'A plugin that allows writting and reading files and running processes in a cloud environment.', | ||
version: 'v1', | ||
} | ||
|
||
fs.writeFileSync('openapi.yaml', yaml.dump(spec, { sortKeys: true, indent: 2, condenseFlow: true, noArrayIndent: true, noCompatMode: true, lineWidth: -1 })) |