Skip to content

Commit

Permalink
Merge pull request #119 from connery-io/CON-135
Browse files Browse the repository at this point in the history
CON-135: Adjust SDK to the new approach
  • Loading branch information
machulav authored Jun 3, 2024
2 parents 6e827f2 + 1fef291 commit d0b445a
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 951 deletions.
5 changes: 1 addition & 4 deletions packages/connery/src/api/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ActionsController } from './controllers/actions.controller.js';
import { PluginController } from './controllers/plugin.controller.js';
import { OpenAiSpecsService } from './services/openai-specs.service.js';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from './auth.guard.js';
import { OpenAiController } from './controllers/specs.controller.js';
import { PluginService } from './services/plugin.service.js';
import { PluginConfigService } from './services/plugin-config.service.js';
import { HomeController } from './controllers/home.controller.js';

@Module({
imports: [ConfigModule.forRoot({ validate: PluginConfigService.validateEnvConfig }), ConfigModule],
controllers: [HomeController, ActionsController, OpenAiController, PluginController],
controllers: [HomeController, ActionsController, PluginController],
providers: [
{
provide: APP_GUARD,
useClass: AuthGuard,
},
OpenAiSpecsService,
PluginService,
PluginConfigService,
],
Expand Down
6 changes: 2 additions & 4 deletions packages/connery/src/api/controllers/actions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
RunActionResponse,
GenericErrorResponse,
} from '../dto.js';
import { PluginConfigService } from '../services/plugin-config.service.js';

@ApiTags('Actions')
@ApiSecurity('ApiKey')
Expand All @@ -39,7 +38,7 @@ import { PluginConfigService } from '../services/plugin-config.service.js';
})
@Controller('/api/actions')
export class ActionsController {
constructor(private pluginService: PluginService, private pluginConfigService: PluginConfigService) {}
constructor(private pluginService: PluginService) {}

@ApiOperation({
summary: 'List all actions from the plugin.',
Expand Down Expand Up @@ -158,8 +157,7 @@ export class ActionsController {
}

// TODO: throw validation errors as HTTP 400
const defaultConfiguration = this.pluginConfigService.configuration;
const result = await action.run(body.input, defaultConfiguration, body.configuration);
const result = await action.run(body.input);

return {
status: 'success',
Expand Down
8 changes: 4 additions & 4 deletions packages/connery/src/api/controllers/home.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export class HomeController {
@ApiExcludeEndpoint()
@Get()
getHomePage(@Res() res: Response) {
const pluginTitle = this.pluginService.plugin.title;
const pluginName = this.pluginService.plugin.name;
const pluginDescription = this.pluginService.plugin.description;
const listOfActions = this.pluginService.plugin.actions
.map((action) => '<span class="italic">' + action.title + '</span>')
.map((action) => '<span class="italic">' + action.name + '</span>')
.join(', ');

const htmlContent = `
<html>
<head>
<title>${pluginTitle} - ${pluginDescription}</title>
<title>${pluginName} - ${pluginDescription}</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
Expand All @@ -30,7 +30,7 @@ export class HomeController {
<div class="mx-auto max-w-3xl px-4">
<main class="my-10 grid items-center justify-center gap-4 text-center md:gap-10 lg:gap-16">
<div class="space-y-4">
<h1 class="text-3xl font-bold tracking-tighter sm:text-5xl md:text-6xl">✨<br />${pluginTitle}</h1>
<h1 class="text-3xl font-bold tracking-tighter sm:text-5xl md:text-6xl">✨<br />${pluginName}</h1>
<p class="mx-auto max-w-[600px] text-gray-500 md:text-xl/relaxed lg:text-base/relaxed xl:text-xl/relaxed">
${pluginDescription}
</p>
Expand Down
60 changes: 0 additions & 60 deletions packages/connery/src/api/controllers/specs.controller.ts

This file was deleted.

91 changes: 11 additions & 80 deletions packages/connery/src/api/dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { ApiHideProperty, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ActionRuntime, PluginRuntime } from '../types/runtime';
import {
ConfigurationParameterDefinition,
InputParameterDefinition,
MaintainerDefinition,
OutputParameterDefinition,
ValidationDefinition,
} from '../types/definition';
import { ConfigurationObject, InputObject, OutputObject } from '../types/context';
import { InputParameterDefinition, OutputParameterDefinition, ValidationDefinition } from '../types/definition';
import { InputObject, OutputObject } from '../types/context';

//
// Generic response types
Expand Down Expand Up @@ -82,19 +76,6 @@ export class GenericErrorResponse {
// Response types
//

export class Maintainer {
@ApiProperty()
name: string;

@ApiProperty()
email: string;

constructor(maintainer: MaintainerDefinition) {
this.name = maintainer.name;
this.email = maintainer.email;
}
}

export class Validation {
@ApiPropertyOptional()
required?: boolean;
Expand All @@ -104,65 +85,16 @@ export class Validation {
}
}

export class ConfigurationParameter {
@ApiProperty()
key: string;

@ApiProperty()
title: string;

@ApiPropertyOptional()
description?: string;

@ApiProperty({
enum: ['string'],
})
type: 'string';

@ApiPropertyOptional({
type: Validation,
})
validation?: Validation;

constructor(configurationParameter: ConfigurationParameterDefinition) {
this.key = configurationParameter.key;
this.title = configurationParameter.title;
this.description = configurationParameter.description;
this.type = configurationParameter.type;
this.validation = new Validation(configurationParameter.validation);
}
}

export class Plugin {
@ApiProperty()
title: string;
name: string;

@ApiPropertyOptional()
description?: string;

@ApiProperty({
type: ConfigurationParameter,
isArray: true,
title: 'Metadata of the plugin configuration parameters.',
description:
'The configuration parameters are used to configure the plugin and its actions. For example, the API keys, the URLs, credentials, etc., can be configured here to be used in the actions. Configuration parameters can be set in the environment variables of the plugin. But also, they can be set when running an action. The configuration parameters set when running an action will override the configuration parameters set in the environment variables.',
})
configurationParameters: ConfigurationParameter[];

@ApiProperty({
type: Maintainer,
isArray: true,
title: 'The maintainers of the plugin.',
})
maintainers: Maintainer[];

constructor(plugin: PluginRuntime) {
this.title = plugin.title;
this.name = plugin.name;
this.description = plugin.description;
this.configurationParameters = plugin.configurationParameters.map(
(configurationParameter) => new ConfigurationParameter(configurationParameter),
);
this.maintainers = plugin.maintainers.map((maintainer) => new Maintainer(maintainer));
}
}

Expand All @@ -171,7 +103,7 @@ export class InputParameter {
key: string;

@ApiProperty()
title: string;
name: string;

@ApiPropertyOptional()
description?: string;
Expand All @@ -188,7 +120,7 @@ export class InputParameter {

constructor(inputParameter: InputParameterDefinition) {
this.key = inputParameter.key;
this.title = inputParameter.title;
this.name = inputParameter.name;
this.description = inputParameter.description;
this.type = inputParameter.type;
this.validation = new Validation(inputParameter.validation);
Expand All @@ -200,7 +132,7 @@ export class OutputParameter {
key: string;

@ApiProperty()
title: string;
name: string;

@ApiPropertyOptional()
description?: string;
Expand All @@ -217,7 +149,7 @@ export class OutputParameter {

constructor(outputParameter: OutputParameterDefinition) {
this.key = outputParameter.key;
this.title = outputParameter.title;
this.name = outputParameter.name;
this.description = outputParameter.description;
this.type = outputParameter.type;
this.validation = new Validation(outputParameter.validation);
Expand All @@ -229,7 +161,7 @@ export class Action {
key: string;

@ApiProperty()
title: string;
name: string;

@ApiPropertyOptional()
description?: string;
Expand All @@ -255,7 +187,7 @@ export class Action {

constructor(action: ActionRuntime) {
this.key = action.key;
this.title = action.title;
this.name = action.name;
this.description = action.description;
this.type = action.type;
this.inputParameters = action.inputParameters.map((inputParameter) => new InputParameter(inputParameter));
Expand Down Expand Up @@ -307,8 +239,7 @@ export class RunActionRequest {
[key: string]: any;
};

constructor(input: InputObject, configuration?: ConfigurationObject) {
constructor(input: InputObject) {
this.input = input;
this.configuration = configuration;
}
}
2 changes: 0 additions & 2 deletions packages/connery/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ async function initOpeApiSpec(app: INestApplication) {
.addApiKey({ type: 'apiKey', in: 'header', name: 'x-api-key' }, 'ApiKey')
.addTag('Plugin')
.addTag('Actions')
.addTag('Specs', 'Action specifications for different clients.')
.addServer(pluginConfigService.pluginServerUrl, 'Plugin URL')
.build();
const document = SwaggerModule.createDocument(app, config);

Expand Down
Loading

0 comments on commit d0b445a

Please sign in to comment.