Skip to content

Commit

Permalink
Improve env handling in plugin routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Jul 30, 2023
1 parent 233917a commit 748f18e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/generated/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function RegisterRoutes(app: Router) {
const args = {
command: {"in":"body","name":"command","required":true,"dataType":"string"},
workDir: {"in":"query","name":"workDir","required":true,"dataType":"string"},
envID: {"default":"Nodejs","in":"query","name":"env","ref":"Environment"},
env: {"default":"Nodejs","in":"query","name":"env","ref":"Environment"},
conversationID: {"in":"header","name":"openai-conversation-id","dataType":"string"},
};

Expand All @@ -69,7 +69,7 @@ export function RegisterRoutes(app: Router) {

function FilesystemController_readFile(request: any, response: any, next: any) {
const args = {
envID: {"default":"Nodejs","in":"query","name":"env","ref":"Environment"},
env: {"default":"Nodejs","in":"query","name":"env","ref":"Environment"},
path: {"in":"query","name":"path","required":true,"dataType":"string"},
conversationID: {"in":"header","name":"openai-conversation-id","dataType":"string"},
};
Expand All @@ -96,7 +96,7 @@ export function RegisterRoutes(app: Router) {

function FilesystemController_writeFile(request: any, response: any, next: any) {
const args = {
envID: {"default":"Nodejs","in":"query","name":"env","ref":"Environment"},
env: {"default":"Nodejs","in":"query","name":"env","ref":"Environment"},
path: {"in":"query","name":"path","required":true,"dataType":"string"},
content: {"in":"body","name":"content","required":true,"dataType":"string"},
conversationID: {"in":"header","name":"openai-conversation-id","dataType":"string"},
Expand Down
8 changes: 4 additions & 4 deletions src/plugin/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class commandController extends Controller {
/**
* @summary Run a command in a shell
*
* @param envID Environment to run the command in
* @param env Environment to run the command in
* @param command Command to run
* @param workDir Working directory to run the command in
* @returns JSON containing the standard output and error output of the command
Expand All @@ -41,11 +41,11 @@ export class commandController extends Controller {
public async runCommand(
@Body() command: string,
@Query() workDir: string,
@Query('env') envID: Environment = defaultEnvironment,
@Query() env: Environment = defaultEnvironment,
@Header(openAIConversationIDHeader) conversationID?: string,
): Promise<CommandResponse> {
const sessionID = getUserSessionID(conversationID, envID)
const session = await CachedSession.findOrStartSession({ sessionID, envID })
const sessionID = getUserSessionID(conversationID, env)
const session = await CachedSession.findOrStartSession({ sessionID, envID: env })

const cachedProcess = await session.startProcess({
cmd: command,
Expand Down
16 changes: 8 additions & 8 deletions src/plugin/filesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export class FilesystemController extends Controller {
/**
* @summary Read the contents of a file at the given path
*
* @param envID Environment where to read the file from
* @param env Environment where to read the file from
* @param path Path to the file to read
* @returns Contents of the file as a string
*/
@Get()
@Produces(textPlainMIME)
public async readFile(
@Query('env') envID: Environment = defaultEnvironment,
@Query() env: Environment = defaultEnvironment,
@Query() path: string,
@Header(openAIConversationIDHeader) conversationID?: string,
): Promise<string> {
const sessionID = getUserSessionID(conversationID, envID)
const session = await CachedSession.findOrStartSession({ sessionID, envID })
const sessionID = getUserSessionID(conversationID, env)
const session = await CachedSession.findOrStartSession({ sessionID, envID: env })

this.setHeader('Content-Type', textPlainMIME)

Expand All @@ -45,20 +45,20 @@ export class FilesystemController extends Controller {
/**
* @summary Write content to a file at the given path
*
* @param envID Environment where to write the file
* @param env Environment where to write the file
* @param path Path to the file to write
* @param content Content to write to the file
*/
@Put()
@Consumes(textPlainMIME)
public async writeFile(
@Query('env') envID: Environment = defaultEnvironment,
@Query() env: Environment = defaultEnvironment,
@Query() path: string,
@Body() content: string,
@Header(openAIConversationIDHeader) conversationID?: string,
) {
const sessionID = getUserSessionID(conversationID, envID)
const session = await CachedSession.findOrStartSession({ sessionID, envID })
const sessionID = getUserSessionID(conversationID, env)
const session = await CachedSession.findOrStartSession({ sessionID, envID: env })

const dir = dirname(path)
await session.session.filesystem!.makeDir(dir)
Expand Down

0 comments on commit 748f18e

Please sign in to comment.