Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adjust CLI to the SDK changes #121

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ export default `import { handler } from '../../src/actions/{{key}}';
// TODO #1: Rename xit() to it() to enable the test.
// TODO #2: Change the test name below to match your use case.
xit('should verify if the {{key}} action works as expected', async () => {
const configuration = {
/* TODO #3: Specify configuration for the plugin. */
};
const input = {
/* TODO #4: Specify input for the action. */
/* TODO #3: Specify input for the action. */
};

const result = await handler({ input, configuration });
const result = await handler({ input });

expect(result).toEqual({
/* TODO #5: Specify the expected value of the result. */
/* TODO #4: Specify the expected value of the result. */
});
});
`;
4 changes: 2 additions & 2 deletions packages/connery/src/cli/add-action/templates/action.ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default `import { ActionDefinition, ActionContext, OutputObject } from 'c

const actionDefinition: ActionDefinition = {
key: '{{key}}',
title: '{{title}}',
name: '{{name}}',
description: '{{description}}',
type: '{{type}}',
inputParameters: [],
Expand All @@ -13,7 +13,7 @@ const actionDefinition: ActionDefinition = {
};
export default actionDefinition;

export async function handler({ input, configuration }: ActionContext): Promise<OutputObject> {
export async function handler({ input }: ActionContext): Promise<OutputObject> {
// TODO: Implement the action logic.

return {};
Expand Down
2 changes: 1 addition & 1 deletion packages/connery/src/cli/add-action/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type AddActionParameters = {
key: string;
title: string;
name: string;
description?: string;
type: string;
};
10 changes: 5 additions & 5 deletions packages/connery/src/cli/add-action/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export async function collectUserInput(): Promise<AddActionParameters> {
logEmptyLine();

const answers = {
actionTitle: await input({
message: styleQuestion('What is the action title?', '(e.g.: Send email)'),
actionName: await input({
message: styleQuestion('What is the action name?', '(e.g.: Send email)'),
transformer: styleAnswer,
validate: (value: string) => {
if (value.trim() === '') {
return styleError('Please enter the action title');
return styleError('Please enter the action name');
}
return true;
},
Expand All @@ -32,8 +32,8 @@ export async function collectUserInput(): Promise<AddActionParameters> {
};

return {
key: toCamelCase(answers.actionTitle.trim()),
title: answers.actionTitle.trim(),
key: toCamelCase(answers.actionName.trim()),
name: answers.actionName.trim(),
description: answers.actionDescription.trim(),
type: answers.actionType.trim(),
};
Expand Down
4 changes: 2 additions & 2 deletions packages/connery/src/cli/init/templates/README.md.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default `# {{plugin.title}}
export default `# {{plugin.name}}

{{plugin.description}}

Expand All @@ -13,7 +13,7 @@ This repository contains the plugin's source code.

## Built using Connery SDK

This plugin is built using [Connery SDK](https://github.com/connery-io/connery), the open-source SDK for AI plugins and actions development.
This plugin is built using [Connery SDK](https://github.com/connery-io/connery), the open-source SDK for creating AI plugins and actions.

[Learn how to use the plugin and its actions.](https://sdk.connery.io/docs/quickstart/use-plugin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { ActionDefinition, ActionContext, OutputObject } from 'connery';

const actionDefinition: ActionDefinition = {
key: 'sampleAction',
title: 'Sample action',
name: 'Sample action',
description: 'A sample action that adds two numbers',
type: 'read',
inputParameters: [
{
key: 'number1',
title: 'Number 1',
name: 'Number 1',
description: 'The first number to add',
type: 'string',
validation: {
Expand All @@ -19,7 +19,7 @@ const actionDefinition: ActionDefinition = {
},
{
key: 'number2',
title: 'Number 2',
name: 'Number 2',
description: 'The second number to add',
type: 'string',
validation: {
Expand All @@ -33,7 +33,7 @@ const actionDefinition: ActionDefinition = {
outputParameters: [
{
key: 'sum',
title: 'Sum',
name: 'Sum',
description: 'The sum of the two numbers',
type: 'string',
validation: {
Expand All @@ -44,7 +44,7 @@ const actionDefinition: ActionDefinition = {
};
export default actionDefinition;

export async function handler({ input, configuration }: ActionContext): Promise<OutputObject> {
export async function handler({ input }: ActionContext): Promise<OutputObject> {
const sum = Number(input.number1) + Number(input.number2);

return {
Expand Down
9 changes: 1 addition & 8 deletions packages/connery/src/cli/init/templates/src/index.ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ export default `import { PluginDefinition, setupPluginServer } from 'connery';
import sampleAction from './actions/sampleAction.js';

const pluginDefinition: PluginDefinition = {
title: '{{plugin.title}}',
name: '{{plugin.name}}',
description: '{{plugin.description}}',
actions: [sampleAction],
configurationParameters: [],
maintainers: [
{
name: '{{maintainer.name}}',
email: '{{maintainer.email}}',
},
],
};

const handler = await setupPluginServer(pluginDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ it('should add 1 and 2 and return 3', async () => {
number1: '1',
number2: '2',
};
const configuration = {};

const result = await handler({ input, configuration });
const result = await handler({ input });

expect(result).toEqual({
sum: '3',
Expand All @@ -19,9 +18,8 @@ it('should add 0 and 0 and return 0', async () => {
number1: '0',
number2: '0',
};
const configuration = {};

const result = await handler({ input, configuration });
const result = await handler({ input });

expect(result).toEqual({
sum: '0',
Expand All @@ -33,9 +31,8 @@ it('should add 1 and -1 and return 0', async () => {
number1: '1',
number2: '-1',
};
const configuration = {};

const result = await handler({ input, configuration });
const result = await handler({ input });

expect(result).toEqual({
sum: '0',
Expand All @@ -47,9 +44,8 @@ it('should add 50.1 and 49.9 and return 100', async () => {
number1: '50.1',
number2: '49.9',
};
const configuration = {};

const result = await handler({ input, configuration });
const result = await handler({ input });

expect(result).toEqual({
sum: '100',
Expand Down
2 changes: 1 addition & 1 deletion packages/connery/src/cli/init/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type InitRepositoryParameters = {
plugin: {
title: string;
name: string;
description: string;
};
maintainer: {
Expand Down
12 changes: 6 additions & 6 deletions packages/connery/src/cli/init/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export async function collectUserInput(): Promise<InitRepositoryParameters> {
logEmptyLine();

const answers = {
pluginTitle: await input({
message: styleQuestion('What is the plugin title?', '(e.g.: Gmail)'),
pluginName: await input({
message: styleQuestion('What is the plugin name?', '(e.g.: Gmail)'),
transformer: styleAnswer,
validate: (value: string) => {
if (value.trim() === '') {
return styleError('Please enter the plugin title');
return styleError('Please enter the plugin name');
}
return true;
},
Expand All @@ -30,7 +30,7 @@ export async function collectUserInput(): Promise<InitRepositoryParameters> {
},
}),
authorName: await input({
message: styleQuestion('What is the mainainer name?'),
message: styleQuestion('What is the mainainer name?', '(for the license)'),
transformer: styleAnswer,
validate: (value: string) => {
if (value.trim() === '') {
Expand All @@ -40,7 +40,7 @@ export async function collectUserInput(): Promise<InitRepositoryParameters> {
},
}),
authorEmail: await input({
message: styleQuestion('What is the maintainer email?'),
message: styleQuestion('What is the maintainer email?', '(for the license)'),
transformer: styleAnswer,
validate: (value: string) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Expand All @@ -61,7 +61,7 @@ export async function collectUserInput(): Promise<InitRepositoryParameters> {

return {
plugin: {
title: answers.pluginTitle.trim(),
name: answers.pluginName.trim(),
description: answers.pluginDescription.trim() || `Plugin built using Connery SDK.`,
},
maintainer: {
Expand Down