Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(nodejs-client): allow empty keyword filters in list APIs (#44097)
D419106f79102c0c2a
diff --git a/sdks/nodejs-client/src/client/chat.ts b/sdks/nodejs-client/src/client/chat.tsindex 488ed7cc800..b4dd4a75591 100644--- a/sdks/nodejs-client/src/client/chat.ts+++ b/sdks/nodejs-client/src/client/chat.ts@@ -306,7 +306,9 @@ export class ChatClient extends DifyClient {listAnnotations(options?: AnnotationListOptions): Promise<DifyResponse<AnnotationResponse>> {ensureOptionalInt(options?.page, 'page')ensureOptionalInt(options?.limit, 'limit')- ensureOptionalString(options?.keyword, 'keyword')+ if (options?.keyword !== '') {+ ensureOptionalString(options?.keyword, 'keyword')+ }return this.http.request({method: 'GET',path: '/apps/annotations',diff --git a/sdks/nodejs-client/src/client/knowledge-base.ts b/sdks/nodejs-client/src/client/knowledge-base.tsindex bab1177d791..b2bd12568e4 100644--- a/sdks/nodejs-client/src/client/knowledge-base.ts+++ b/sdks/nodejs-client/src/client/knowledge-base.ts@@ -57,7 +57,9 @@ export class KnowledgeBaseClient extends DifyClient {async listDatasets(options?: DatasetListOptions): Promise<DifyResponse<KnowledgeBaseResponse>> {ensureOptionalInt(options?.page, 'page')ensureOptionalInt(options?.limit, 'limit')- ensureOptionalString(options?.keyword, 'keyword')+ if (options?.keyword !== '') {+ ensureOptionalString(options?.keyword, 'keyword')+ }ensureOptionalBoolean(options?.includeAll, 'includeAll')const query: QueryParams = {@@ -267,7 +269,9 @@ export class KnowledgeBaseClient extends DifyClient {ensureNonEmptyString(datasetId, 'datasetId')ensureOptionalInt(options?.page, 'page')ensureOptionalInt(options?.limit, 'limit')- ensureOptionalString(options?.keyword, 'keyword')+ if (options?.keyword !== '') {+ ensureOptionalString(options?.keyword, 'keyword')+ }ensureOptionalString(options?.status, 'status')return this.http.request({@@ -352,7 +356,9 @@ export class KnowledgeBaseClient extends DifyClient {ensureNonEmptyString(documentId, 'documentId')ensureOptionalInt(options?.page, 'page')ensureOptionalInt(options?.limit, 'limit')- ensureOptionalString(options?.keyword, 'keyword')+ if (options?.keyword !== '') {+ ensureOptionalString(options?.keyword, 'keyword')+ }if (options?.status && options.status.length > 0) {ensureStringArray(options.status, 'status')}@@ -445,7 +451,9 @@ export class KnowledgeBaseClient extends DifyClient {ensureNonEmptyString(segmentId, 'segmentId')ensureOptionalInt(options?.page, 'page')ensureOptionalInt(options?.limit, 'limit')- ensureOptionalString(options?.keyword, 'keyword')+ if (options?.keyword !== '') {+ ensureOptionalString(options?.keyword, 'keyword')+ }return this.http.request({method: 'GET',diff --git a/sdks/nodejs-client/tests/http.integration.test.ts b/sdks/nodejs-client/tests/http.integration.test.tsindex 2d187c22b18..5d7cf1be8f3 100644--- a/sdks/nodejs-client/tests/http.integration.test.ts+++ b/sdks/nodejs-client/tests/http.integration.test.ts@@ -2,6 +2,8 @@ import type { AddressInfo } from 'node:net'import { createServer } from 'node:http'import { Readable } from 'node:stream'import { afterAll, beforeAll, describe, expect, it } from 'vite-plus/test'+import { ChatClient } from '../src/client/chat'+import { KnowledgeBaseClient } from '../src/client/knowledge-base'import { HttpClient } from '../src/http/client'const readBody = async (stream: NodeJS.ReadableStream): Promise<Buffer> => {@@ -30,7 +32,11 @@ describe('HttpClient integration', () => {body,})- if (req.url?.startsWith('/json')) {+ if (+ req.url?.startsWith('/json') ||+ req.url?.startsWith('/datasets') ||+ req.url?.startsWith('/apps/annotations')+ ) {res.writeHead(200, { 'content-type': 'application/json', 'x-request-id': 'req-json' })res.end(JSON.stringify({ ok: true }))return@@ -159,4 +165,52 @@ describe('HttpClient integration', () => {expect(Array.from(response.data.values())).toEqual([1, 2, 3, 4])})++ const keywordRequests = [+ {+ name: 'datasets',+ path: '/datasets',+ run: (keyword: string) => new KnowledgeBaseClient(client).listDatasets({ keyword }),+ },+ {+ name: 'documents',+ path: '/datasets/ds/documents',+ run: (keyword: string) => new KnowledgeBaseClient(client).listDocuments('ds', { keyword }),+ },+ {+ name: 'segments',+ path: '/datasets/ds/documents/doc/segments',+ run: (keyword: string) =>+ new KnowledgeBaseClient(client).listSegments('ds', 'doc', { keyword }),+ },+ {+ name: 'child chunks',+ path: '/datasets/ds/documents/doc/segments/seg/child_chunks',+ run: (keyword: string) =>+ new KnowledgeBaseClient(client).listChildChunks('ds', 'doc', 'seg', { keyword }),+ },+ {+ name: 'annotations',+ path: '/apps/annotations',+ run: (keyword: string) => new ChatClient(client).listAnnotations({ keyword }),+ },+ ]++ it.each(keywordRequests)('allows an empty keyword when listing $name', async ({ path, run }) => {+ await run('')++ const url = new URL(requests.at(-1)!.url, 'http://localhost')+ expect(url.pathname).toBe(path)+ expect(url.searchParams.has('keyword')).toBe(true)+ expect(url.searchParams.get('keyword')).toBe('')+ })++ it.each(keywordRequests)(+ 'still rejects oversized keywords when listing $name',+ async ({ run }) => {+ await expect(Promise.resolve().then(() => run('a'.repeat(10001)))).rejects.toThrow(+ 'maximum length',+ )+ },+ )})