Skip to content

Commit

Permalink
馃毀 wip: OpenAI Manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Dec 11, 2023
1 parent deda889 commit 1e815c5
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 51 deletions.
92 changes: 48 additions & 44 deletions src/features/PluginStore/PluginItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LobeChatPluginMeta } from '@lobehub/chat-plugin-sdk';
import { Avatar, Tag } from '@lobehub/ui';
import { Button } from 'antd';
import { createStyles } from 'antd-style';
Expand All @@ -9,6 +8,7 @@ import { Flexbox } from 'react-layout-kit';

import { useToolStore } from '@/store/tool';
import { pluginSelectors, pluginStoreSelectors } from '@/store/tool/selectors';
import { InstallPluginMeta } from '@/types/tool/plugin';

import PluginSettings from './PluginSettings';

Expand All @@ -28,54 +28,58 @@ const useStyles = createStyles(({ css, token }) => ({
line-height: 2;
`,
}));
const PluginItem = memo<LobeChatPluginMeta>(({ identifier, createdAt, homepage, author, meta }) => {
const [installed, installing, installPlugin, unInstallPlugin] = useToolStore((s) => [
pluginSelectors.isPluginInstalled(identifier)(s),
pluginStoreSelectors.isPluginInstallLoading(identifier)(s),
s.installPlugin,
s.uninstallPlugin,
]);
const { styles } = useStyles();

const { t } = useTranslation('plugin');
return (
<Flexbox gap={8} padding={16}>
<Flexbox horizontal justify={'space-between'}>
<Avatar avatar={meta.avatar} size={56} style={{ flex: 'none' }} />
const PluginItem = memo<InstallPluginMeta>(
({ identifier, createdAt, homepage, author, type, meta = {} }) => {
console.log(type);
const [installed, installing, installPlugin, unInstallPlugin] = useToolStore((s) => [
pluginSelectors.isPluginInstalled(identifier)(s),
pluginStoreSelectors.isPluginInstallLoading(identifier)(s),
s.installPlugin,
s.uninstallPlugin,
]);
const { styles } = useStyles();

<Flexbox gap={8} horizontal>
<PluginSettings identifier={identifier} />
<Button
loading={installing}
onClick={() => {
if (installed) {
unInstallPlugin(identifier);
} else installPlugin(identifier);
}}
type={installed ? 'default' : 'primary'}
>
{t(installed ? 'store.uninstall' : 'store.install')}
</Button>
</Flexbox>
</Flexbox>
const { t } = useTranslation('plugin');
return (
<Flexbox gap={8} padding={16}>
<Flexbox horizontal justify={'space-between'}>
<Avatar avatar={meta.avatar} size={56} style={{ flex: 'none' }} />

<Flexbox gap={4}>
<Flexbox align={'center'} gap={8} horizontal>
<div className={styles.title}>{meta.title}</div>
<Tag className={styles.tag}> {identifier}</Tag>
<Flexbox gap={8} horizontal>
<PluginSettings identifier={identifier} />
<Button
loading={installing}
onClick={() => {
if (installed) {
unInstallPlugin(identifier);
} else installPlugin(identifier);
}}
type={installed ? 'default' : 'primary'}
>
{t(installed ? 'store.uninstall' : 'store.install')}
</Button>
</Flexbox>
</Flexbox>
<div className={styles.desc}>{meta.description}</div>
<Flexbox className={styles.link} gap={8} horizontal>
{author && (
<Link className={styles.link} href={homepage} target={'_blank'}>
@{author}
</Link>
)}
{t('store.releasedAt', { createdAt })}

<Flexbox gap={4}>
<Flexbox align={'center'} gap={8} horizontal>
<div className={styles.title}>{meta.title}</div>
<Tag className={styles.tag}> {identifier}</Tag>
</Flexbox>
<div className={styles.desc}>{meta.description}</div>
<Flexbox className={styles.link} gap={8} horizontal>
{author && (
<Link className={styles.link} href={homepage ?? ''} target={'_blank'}>
@{author}
</Link>
)}
{createdAt && t('store.releasedAt', { createdAt })}
</Flexbox>
</Flexbox>
</Flexbox>
</Flexbox>
);
});
);
},
);

export default PluginItem;
147 changes: 147 additions & 0 deletions src/services/__tests__/openapi/OpenAPI_Auth_API_Key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"components": {
"schemas": {
"Vendor": {
"type": "string",
"enum": ["visa", "master-card", "diners-club", "american-express", "discover", "jcb"]
},
"GetRandomCardNumberResponse": {
"type": "object",
"properties": {
"vendors": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Vendor"
}
}
}
},
"GetVendorsResponse": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"vendor": {
"type": "string",
"items": {
"$ref": "#/components/schemas/Vendor"
}
}
}
},
"ErrorResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
},
"securitySchemes": {
"apiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-OpenAPIHub-Key"
}
}
},
"info": {
"title": "Trial API Credit Card Number Generator",
"description": "# Introduction\nThis is Trial API Credit Card Number Generator",
"version": "1.0.2"
},
"openapi": "3.0.0",
"paths": {
"/random_card_number": {
"get": {
"operationId": "getRandomCardNumber",
"tags": ["Credit Card Number Generator"],
"summary": "It is API to generate random credit card numbers",
"description": "Generate random credit card numbers",
"parameters": [
{
"name": "vendor",
"in": "query",
"required": true,
"schema": {
"$ref": "#/components/schemas/Vendor"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetRandomCardNumberResponse"
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
]
}
},
"/vendors": {
"get": {
"operationId": "getSupportedVendors",
"tags": ["Credit Card Number Generator"],
"summary": "It is API to get list of supported vendors",
"description": "Return list of supported vendors",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetVendorsResponse"
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
]
}
}
},
"servers": [
{
"url": "https://trial-api-credit-card-number-generator-2m83.gw.openapihub.com"
},
{
"url": "https://5953f2e3-b62c-40cf-bd13-6ffa26e0dd4b-2m83.gw.openapihub.com"
}
],
"tags": []
}
43 changes: 43 additions & 0 deletions src/services/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LobeTool } from '@/types/tool';
import { LobeToolCustomPlugin } from '@/types/tool/plugin';

import { InstallPluginParams, pluginService } from '../plugin';
import OpenAPI_Auth_API_Key from './openapi/OpenAPI_Auth_API_Key.json';
import OpenAPIV2 from './openapi/OpenAPI_V2.json';
import openAPIV3 from './openapi/OpenAPI_V3.json';

Expand Down Expand Up @@ -344,4 +345,46 @@ describe('PluginService', () => {
expect(plugins).toMatchSnapshot();
});
});

describe('convertAuthToSettingsSchema', () => {
it('do not need has settings', async () => {
const plugins = await pluginService.convertAuthToSettingsSchema(OpenAPIV2);

expect(plugins).toEqual({
properties: {},
type: 'object',
});
});

it('can convert OpenAPI Bear key to settings', async () => {
const plugins = await pluginService.convertAuthToSettingsSchema(openAPIV3);

expect(plugins).toEqual({
HTTPBearer: {
description: 'HTTPBearer Bearer token',
type: 'string',
},
required: ['HTTPBearer'],
});
});

it('can convert OpenAPI Auth API key to settings', async () => {
const settings = await pluginService.convertAuthToSettingsSchema(OpenAPI_Auth_API_Key, {
type: 'object',
properties: {
abc: {},
},
required: ['abc', 'apiKeyAuth'],
});

expect(settings).toEqual({
apiKeyAuth: {
description: 'apiKeyAuth API Key',
type: 'string',
},
abc: {},
required: ['abc', 'apiKeyAuth'],
});
});
});
});
Loading

0 comments on commit 1e815c5

Please sign in to comment.