From 0b8dcaba8fba6069106a2f6dbbeec6785d0866bd Mon Sep 17 00:00:00 2001 From: TseIan Date: Sun, 18 Feb 2024 15:54:14 +0800 Subject: [PATCH] Chore: Add type files and unit test ci for Node.js SDK (#2268) Co-authored-by: xieweicheng --- .github/workflows/tool-test-sdks.yaml | 34 +++++++++++++ sdks/nodejs-client/index.d.ts | 71 +++++++++++++++++++++++++++ sdks/nodejs-client/package.json | 3 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tool-test-sdks.yaml create mode 100644 sdks/nodejs-client/index.d.ts diff --git a/.github/workflows/tool-test-sdks.yaml b/.github/workflows/tool-test-sdks.yaml new file mode 100644 index 0000000000..575ead4b3b --- /dev/null +++ b/.github/workflows/tool-test-sdks.yaml @@ -0,0 +1,34 @@ +name: Run Unit Test For SDKs + +on: + pull_request: + branches: + - main +jobs: + build: + name: unit test for Node.js SDK + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16, 18, 20] + + defaults: + run: + working-directory: sdks/nodejs-client + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: '' + cache-dependency-path: 'yarn.lock' + + - name: Install Dependencies + run: yarn install + + - name: Test + run: yarn test diff --git a/sdks/nodejs-client/index.d.ts b/sdks/nodejs-client/index.d.ts new file mode 100644 index 0000000000..cf1d825221 --- /dev/null +++ b/sdks/nodejs-client/index.d.ts @@ -0,0 +1,71 @@ +// Types.d.ts +export const BASE_URL: string; + +export type RequestMethods = 'GET' | 'POST' | 'PATCH' | 'DELETE'; + +interface Params { + [key: string]: any; +} + +interface HeaderParams { + [key: string]: string; +} + +interface User { +} + +interface ChatMessageConfig { + inputs: any; + query: string; + user: User; + stream?: boolean; + conversation_id?: string | null; + files?: File[] | null; +} + +export declare class DifyClient { + constructor(apiKey: string, baseUrl?: string); + + updateApiKey(apiKey: string): void; + + sendRequest( + method: RequestMethods, + endpoint: string, + data?: any, + params?: Params, + stream?: boolean, + headerParams?: HeaderParams + ): Promise; + + messageFeedback(message_id: string, rating: number, user: User): Promise; + + getApplicationParameters(user: User): Promise; + + fileUpload(data: FormData): Promise; +} + +export declare class CompletionClient extends DifyClient { + createCompletionMessage( + inputs: any, + user: User, + stream?: boolean, + files?: File[] | null + ): Promise; +} + +export declare class ChatClient extends DifyClient { + createChatMessage(config: ChatMessageConfig): Promise; + + getConversationMessages( + user: User, + conversation_id?: string, + first_id?: string | null, + limit?: number | null + ): Promise; + + getConversations(user: User, first_id?: string | null, limit?: number | null, pinned?: boolean | null): Promise; + + renameConversation(conversation_id: string, name: string, user: User): Promise; + + deleteConversation(conversation_id: string, user: User): Promise; +} \ No newline at end of file diff --git a/sdks/nodejs-client/package.json b/sdks/nodejs-client/package.json index 8bd08befc9..a937040a5b 100644 --- a/sdks/nodejs-client/package.json +++ b/sdks/nodejs-client/package.json @@ -1,9 +1,10 @@ { "name": "dify-client", - "version": "2.2.0", + "version": "2.2.1", "description": "This is the Node.js SDK for the Dify.AI API, which allows you to easily integrate Dify.AI into your Node.js applications.", "main": "index.js", "type": "module", + "types":"index.d.ts", "keywords": [ "Dify", "Dify.AI",