From 70bfa6c8281a9c731b64a83eb905b07f233aa52a Mon Sep 17 00:00:00 2001 From: tellet-q Date: Wed, 18 Dec 2024 09:42:32 +0100 Subject: [PATCH 1/4] Detect client's version and send it to server --- packages/js-client-grpc/src/api-client.ts | 3 ++- packages/js-client-grpc/src/client-version.ts | 1 + packages/js-client-rest/src/api-client.ts | 2 ++ packages/js-client-rest/src/client-version.ts | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 packages/js-client-grpc/src/client-version.ts create mode 100644 packages/js-client-rest/src/client-version.ts diff --git a/packages/js-client-grpc/src/api-client.ts b/packages/js-client-grpc/src/api-client.ts index 5ca8d02..57e16d4 100644 --- a/packages/js-client-grpc/src/api-client.ts +++ b/packages/js-client-grpc/src/api-client.ts @@ -4,6 +4,7 @@ import {Collections} from './proto/collections_service_connect.js'; import {Points} from './proto/points_service_connect.js'; import {Snapshots} from './proto/snapshots_service_connect.js'; import {Qdrant} from './proto/qdrant_connect.js'; +import {PACKAGE_VERSION} from './client-version.js'; type Clients = { collections: PromiseClient; @@ -50,7 +51,7 @@ function createClients(transport: Transport) { export function createApis(baseUrl: string, {timeout, apiKey}: {timeout: number; apiKey?: string}): GrpcClients { const interceptors: Interceptor[] = [ (next) => (req) => { - req.header.set('user-agent', 'qdrant-js'); + req.header.set('user-agent', 'qdrant-js' + String(PACKAGE_VERSION)); return next(req); }, ]; diff --git a/packages/js-client-grpc/src/client-version.ts b/packages/js-client-grpc/src/client-version.ts new file mode 100644 index 0000000..cf44b2c --- /dev/null +++ b/packages/js-client-grpc/src/client-version.ts @@ -0,0 +1 @@ +export const PACKAGE_VERSION = '1.12.0'; diff --git a/packages/js-client-rest/src/api-client.ts b/packages/js-client-rest/src/api-client.ts index ec2a153..2f3dc58 100644 --- a/packages/js-client-rest/src/api-client.ts +++ b/packages/js-client-rest/src/api-client.ts @@ -9,6 +9,7 @@ import {createSnapshotsApi} from './api/snapshots-api.js'; import {createShardsApi} from './api/shards-api.js'; import {QdrantClientTimeoutError, QdrantClientUnexpectedResponseError} from './errors.js'; import {RestArgs} from './types.js'; +import {PACKAGE_VERSION} from './client-version.js'; export type Client = ReturnType>; @@ -56,6 +57,7 @@ export function createClient(baseUrl: string, {headers, timeout, connections}: R const client = Fetcher.for(); // Configure client with 'undici' agent which is used in Node 18+ + headers.set('user-agent', 'qdrant-js/' + String(PACKAGE_VERSION)); client.configure({ baseUrl, init: { diff --git a/packages/js-client-rest/src/client-version.ts b/packages/js-client-rest/src/client-version.ts new file mode 100644 index 0000000..cf44b2c --- /dev/null +++ b/packages/js-client-rest/src/client-version.ts @@ -0,0 +1 @@ +export const PACKAGE_VERSION = '1.12.0'; From 41c2e84430daba788b3f1664324cda64a29601c5 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Wed, 18 Dec 2024 10:33:00 +0100 Subject: [PATCH 2/4] Set header value during QdrantClient instantiating --- packages/js-client-rest/src/api-client.ts | 2 -- packages/js-client-rest/src/qdrant-client.ts | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/js-client-rest/src/api-client.ts b/packages/js-client-rest/src/api-client.ts index 2f3dc58..ec2a153 100644 --- a/packages/js-client-rest/src/api-client.ts +++ b/packages/js-client-rest/src/api-client.ts @@ -9,7 +9,6 @@ import {createSnapshotsApi} from './api/snapshots-api.js'; import {createShardsApi} from './api/shards-api.js'; import {QdrantClientTimeoutError, QdrantClientUnexpectedResponseError} from './errors.js'; import {RestArgs} from './types.js'; -import {PACKAGE_VERSION} from './client-version.js'; export type Client = ReturnType>; @@ -57,7 +56,6 @@ export function createClient(baseUrl: string, {headers, timeout, connections}: R const client = Fetcher.for(); // Configure client with 'undici' agent which is used in Node 18+ - headers.set('user-agent', 'qdrant-js/' + String(PACKAGE_VERSION)); client.configure({ baseUrl, init: { diff --git a/packages/js-client-rest/src/qdrant-client.ts b/packages/js-client-rest/src/qdrant-client.ts index ad243f9..793ebd5 100644 --- a/packages/js-client-rest/src/qdrant-client.ts +++ b/packages/js-client-rest/src/qdrant-client.ts @@ -2,6 +2,7 @@ import {maybe} from '@sevinf/maybe'; import {OpenApiClient, createApis} from './api-client.js'; import {QdrantClientConfigError} from './errors.js'; import {RestArgs, SchemaFor} from './types.js'; +import {PACKAGE_VERSION} from './client-version.js'; export type QdrantClientParams = { port?: number | null; @@ -76,7 +77,7 @@ export class QdrantClient { this._host = host ?? '127.0.0.1'; } - const headers = new Headers([['user-agent', 'qdrant-js']]); + const headers = new Headers([['user-agent', 'qdrant-js/' + String(PACKAGE_VERSION)]]); const metadata = args.headers ?? {}; Object.keys(metadata).forEach((field) => { From 2e56f89f2600dce789a36ab5940ee37e150dd43f Mon Sep 17 00:00:00 2001 From: tellet-q Date: Wed, 18 Dec 2024 10:34:11 +0100 Subject: [PATCH 3/4] Fix --- packages/js-client-grpc/src/api-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js-client-grpc/src/api-client.ts b/packages/js-client-grpc/src/api-client.ts index 57e16d4..88c7bb9 100644 --- a/packages/js-client-grpc/src/api-client.ts +++ b/packages/js-client-grpc/src/api-client.ts @@ -51,7 +51,7 @@ function createClients(transport: Transport) { export function createApis(baseUrl: string, {timeout, apiKey}: {timeout: number; apiKey?: string}): GrpcClients { const interceptors: Interceptor[] = [ (next) => (req) => { - req.header.set('user-agent', 'qdrant-js' + String(PACKAGE_VERSION)); + req.header.set('user-agent', 'qdrant-js/' + String(PACKAGE_VERSION)); return next(req); }, ]; From 5e316de33ea0c1deddd56dac26b0c9120a0e8b88 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Wed, 18 Dec 2024 11:07:13 +0100 Subject: [PATCH 4/4] Add tests --- packages/js-client-grpc/tests/unit/client-version.test.ts | 7 +++++++ packages/js-client-rest/tests/unit/client-version.test.ts | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 packages/js-client-grpc/tests/unit/client-version.test.ts create mode 100644 packages/js-client-rest/tests/unit/client-version.test.ts diff --git a/packages/js-client-grpc/tests/unit/client-version.test.ts b/packages/js-client-grpc/tests/unit/client-version.test.ts new file mode 100644 index 0000000..615ff02 --- /dev/null +++ b/packages/js-client-grpc/tests/unit/client-version.test.ts @@ -0,0 +1,7 @@ +import {test, expect} from 'vitest'; +import {version} from '../../package.json'; +import {PACKAGE_VERSION} from '../../src/client-version.js'; + +test('Client version is consistent', () => { + expect(version).toBe(PACKAGE_VERSION); +}); diff --git a/packages/js-client-rest/tests/unit/client-version.test.ts b/packages/js-client-rest/tests/unit/client-version.test.ts new file mode 100644 index 0000000..615ff02 --- /dev/null +++ b/packages/js-client-rest/tests/unit/client-version.test.ts @@ -0,0 +1,7 @@ +import {test, expect} from 'vitest'; +import {version} from '../../package.json'; +import {PACKAGE_VERSION} from '../../src/client-version.js'; + +test('Client version is consistent', () => { + expect(version).toBe(PACKAGE_VERSION); +});