@fencyai/js 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { isChatCompletion } from '../types/ChatCompletion';
2
+ import { getPackageVersion } from '../utils/version';
2
3
  /**
3
4
  * Creates a chat completion by making a POST request to the Fency API.
4
5
  *
@@ -15,6 +16,7 @@ export async function createChatCompletion(params) {
15
16
  headers: {
16
17
  'Content-Type': 'application/json',
17
18
  Authorization: `Bearer ${params.pk}`,
19
+ 'X-Fency-Sdk-Version': getPackageVersion(),
18
20
  },
19
21
  body: JSON.stringify(params.request),
20
22
  });
@@ -1,4 +1,5 @@
1
1
  import { isChatCompletionStream, } from '../types/ChatCompletionStream';
2
+ import { getPackageVersion } from '../utils/version';
2
3
  /**
3
4
  * Creates a new stream by making a POST request to the Fency API.
4
5
  *
@@ -14,6 +15,7 @@ export async function createChatCompletionStream(params) {
14
15
  headers: {
15
16
  'Content-Type': 'application/json',
16
17
  Authorization: `Bearer ${params.pk}`,
18
+ 'X-Fency-Sdk-Version': getPackageVersion(),
17
19
  },
18
20
  });
19
21
  if (!response.ok) {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get the current package version from package.json
3
+ * @returns The package version as a string
4
+ */
5
+ export declare function getPackageVersion(): string;
@@ -0,0 +1,29 @@
1
+ import { readFileSync } from 'fs';
2
+ import { dirname, join } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ // Cache the version to avoid reading the file multiple times
5
+ let cachedVersion = null;
6
+ /**
7
+ * Get the current package version from package.json
8
+ * @returns The package version as a string
9
+ */
10
+ export function getPackageVersion() {
11
+ if (cachedVersion !== null) {
12
+ return cachedVersion;
13
+ }
14
+ try {
15
+ // Get the directory of the current file
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = dirname(__filename);
18
+ // Navigate to the package.json file (2 levels up: utils -> src -> js -> package.json)
19
+ const packageJsonPath = join(__dirname, '../../package.json');
20
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
21
+ return packageJson.version;
22
+ }
23
+ catch (error) {
24
+ // Fallback to a default version if we can't read the package.json
25
+ console.warn('Could not read package version, using fallback:', error);
26
+ cachedVersion = '0.1.35';
27
+ return cachedVersion;
28
+ }
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/js",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "> TODO: description",
5
5
  "author": "staklau <steinaageklaussen@gmail.com>",
6
6
  "homepage": "",
@@ -39,5 +39,5 @@
39
39
  "ts-jest": "^29.1.1",
40
40
  "typescript": "^5.3.3"
41
41
  },
42
- "gitHead": "682c6da971db5839b435a19661d429a3fae54bbb"
42
+ "gitHead": "dec184b1288042cf37fa26c8fbf2f648f7ce533e"
43
43
  }