Skip to content

Commit 60efb7f

Browse files
author
yaroslav8765
committed
fix: removed Adapters.ts and created 5 new adapters files and one index.js file
1 parent 970e0cc commit 60efb7f

File tree

8 files changed

+215
-214
lines changed

8 files changed

+215
-214
lines changed

adminforth/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import SocketBroker from './modules/socketBroker.js';
3838
// exports
3939
export * from './types/Back.js';
4040
export * from './types/Common.js';
41-
export * from './types/Adapters.js';
41+
export {EmailAdapter, CompletionAdapter,ImageGenerationAdapter, OAuth2Adapter, StorageAdapter} from './types/adapters/index.js';
4242
export { interpretResource };
4343
export { AdminForthPlugin };
4444
export { suggestIfTypo, RateLimiter, RAMLock, getClientIp };

adminforth/types/Adapters.ts

Lines changed: 0 additions & 213 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export interface CompletionAdapter {
2+
3+
/**
4+
* This method is called to validate the configuration of the adapter
5+
* and should throw a clear user-readbale error if the configuration is invalid.
6+
*/
7+
validate(): void;
8+
9+
/**
10+
* This method should return a text completion based on the provided content and stop sequence.
11+
* @param content - The input text to complete
12+
* @param stop - An array of stop sequences to indicate where to stop the completion
13+
* @param maxTokens - The maximum number of tokens to generate
14+
* @returns A promise that resolves to an object containing the completed text and other metadata
15+
*/
16+
complete(
17+
content: string,
18+
stop: string[],
19+
maxTokens: number,
20+
): Promise<{
21+
content?: string;
22+
finishReason?: string;
23+
error?: string;
24+
}>;
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export interface EmailAdapter {
2+
3+
/**
4+
* This method is called to validate the configuration of the adapter
5+
* and should throw a clear user-readbale error if the configuration is invalid.
6+
*/
7+
validate(): Promise<void>;
8+
9+
/**
10+
* This method should send an email using the adapter
11+
* @param from - The sender's email address
12+
* @param to - The recipient's email address
13+
* @param text - The plain text version of the email
14+
* @param html - The HTML version of the email
15+
* @param subject - The subject of the email
16+
*/
17+
sendEmail(
18+
from: string,
19+
to: string,
20+
text: string,
21+
html: string,
22+
subject: string
23+
): Promise<{
24+
error?: string;
25+
ok?: boolean;
26+
}>;
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export interface ImageGenerationAdapter {
2+
3+
/**
4+
* This method is called to validate the configuration of the adapter
5+
* and should throw a clear user-readbale error if the configuration is invalid.
6+
*/
7+
validate(): void;
8+
9+
/**
10+
* Return max number of images which model can generate in one request
11+
*/
12+
outputImagesMaxCountSupported(): number;
13+
14+
/**
15+
* Return the list of supported dimensions in format ["100x500", "200x200"]
16+
*/
17+
outputDimensionsSupported(): string[];
18+
19+
/**
20+
* Input file extension supported
21+
*/
22+
inputFileExtensionSupported(): string[];
23+
24+
/**
25+
* This method should generate an image based on the provided prompt and input files.
26+
* @param prompt - The prompt to generate the image
27+
* @param inputFiles - An array of input file paths (optional)
28+
* @param n - The number of images to generate (default is 1)
29+
* @param size - The size of the generated image (default is the lowest dimension supported)
30+
* @returns A promise that resolves to an object containing the generated image URLs and any error message
31+
*/
32+
generate({
33+
prompt,
34+
inputFiles,
35+
n,
36+
size,
37+
}: {
38+
prompt: string,
39+
inputFiles: string[],
40+
41+
// default = lowest dimension supported
42+
size?: string,
43+
44+
// one by default
45+
n?: number
46+
}): Promise<{
47+
imageURLs?: string[];
48+
error?: string;
49+
}>;
50+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/**
3+
* This interface is used to implement OAuth2 authentication adapters.
4+
*/
5+
export interface OAuth2Adapter {
6+
/**
7+
* This method should return navigatable URL to the OAuth2 provider authentication page.
8+
*/
9+
getAuthUrl(): string;
10+
11+
/**
12+
* This method should return the token from the OAuth2 provider using the provided code and redirect URI.
13+
* @param code - The authorization code received from the OAuth2 provider
14+
* @param redirect_uri - The redirect URI used in the authentication request
15+
* @returns A promise that resolves to an object containing the email address of the authenticated user
16+
*/
17+
getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string }>;
18+
19+
/**
20+
* This method should return text (content) of SVG icon which will be used in the UI.
21+
* Use official SVG icons with simplest possible conent, omit icons which have base64 encoded raster images inside.
22+
*/
23+
getIcon(): string;
24+
25+
/**
26+
* This method should return the text to be displayed on the button in the UI
27+
*/
28+
getButtonText?(): string;
29+
30+
/**
31+
* This method should return the name of the adapter
32+
*/
33+
getName?(): string;
34+
}

0 commit comments

Comments
 (0)