@postalsys/email-ai-tools 1.13.12 → 1.13.14

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.
package/.ncurc.js CHANGED
@@ -7,6 +7,11 @@ module.exports = {
7
7
  target: name => (name === 'undici' ? 'minor' : 'latest'),
8
8
  reject: [
9
9
  // Block package upgrades that moved to ESM
10
- 'nanoid'
10
+ 'nanoid',
11
+ // linkify-it 6.0.0 changed the CommonJS export shape (named bindings instead of
12
+ // the constructor) and stopped linkifying bare domains such as example.com by
13
+ // default, which silently breaks autolinking in plain text content. Stay on 5.x,
14
+ // matching mailparser and @postalsys/email-text-tools so consumers dedupe on one copy.
15
+ 'linkify-it'
11
16
  ]
12
17
  };
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.13.12"
2
+ ".": "1.13.14"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.13.14](https://github.com/postalsys/email-ai-tools/compare/v1.13.13...v1.13.14) (2026-07-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * keep the URL path prefix of custom API base URLs ([6c699da](https://github.com/postalsys/email-ai-tools/commit/6c699da65b5b399877f4a84992f4d0a827987d50))
9
+
10
+ ## [1.13.13](https://github.com/postalsys/email-ai-tools/compare/v1.13.12...v1.13.13) (2026-07-20)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **deps:** update @postalsys/email-text-tools to 2.4.11 ([f272c4d](https://github.com/postalsys/email-ai-tools/commit/f272c4d8c94720b2d462b5b97b97be8745a9a7ff))
16
+
3
17
  ## [1.13.12](https://github.com/postalsys/email-ai-tools/compare/v1.13.11...v1.13.12) (2026-07-05)
4
18
 
5
19
 
@@ -12,7 +12,7 @@ const tokenizer = new GPT3Tokenizer({ type: 'gpt3' });
12
12
  const MAX_ALLOWED_TEXT_LENGTH = 64 * 1024;
13
13
  const DEFAULT_MAX_ALLOWED_TOKENS = 30000;
14
14
 
15
- const OPENAI_API_BASE_URL = 'https://api.openai.com';
15
+ const { getApiUrl, OPENAI_API_BASE_URL } = require('./get-api-url');
16
16
 
17
17
  const OPENAI_API_URL_CHAT = '/v1/chat/completions';
18
18
  const OPENAI_API_URL_INSTRUCT = '/v1/completions';
@@ -123,11 +123,6 @@ You are analyzing user questions regarding email retrieval from a database. From
123
123
  Process the user question:
124
124
  `.trim();
125
125
 
126
- function getApiUrl(baseApiUrl, path) {
127
- let url = new URL(path || '/', baseApiUrl || OPENAI_API_BASE_URL);
128
- return url.href;
129
- }
130
-
131
126
  async function embeddingsQuery(apiToken, opts) {
132
127
  opts = opts || {};
133
128
 
@@ -21,15 +21,10 @@ const linkify = linkifyIt()
21
21
 
22
22
  const tokenizer = new GPT3Tokenizer({ type: 'gpt3' });
23
23
 
24
- const OPENAI_API_BASE_URL = 'https://api.openai.com';
24
+ const { getApiUrl, OPENAI_API_BASE_URL } = require('./get-api-url');
25
25
 
26
26
  const OPENAI_API_URL = '/v1/embeddings';
27
27
 
28
- function getApiUrl(baseApiUrl, path) {
29
- let url = new URL(path || '/', baseApiUrl || OPENAI_API_BASE_URL);
30
- return url.href;
31
- }
32
-
33
28
  async function getChunkEmbeddings(chunk, apiToken, opts) {
34
29
  let { gptModel, verbose, baseApiUrl } = opts || {};
35
30
 
@@ -16,7 +16,7 @@ const MAX_INSTRUCT_TOKENS = 4000;
16
16
  const MAX_RETRIES = 5;
17
17
  const RETRY_DELAY_MS = 1000;
18
18
 
19
- const OPENAI_API_BASE_URL = 'https://api.openai.com';
19
+ const { getApiUrl, OPENAI_API_BASE_URL } = require('./get-api-url');
20
20
 
21
21
  const OPENAI_API_URL_CHAT = '/v1/chat/completions';
22
22
  const OPENAI_API_URL_INSTRUCT = '/v1/completions';
@@ -143,11 +143,6 @@ Output facts:
143
143
 
144
144
  Analyze the following email:`.trim();
145
145
 
146
- function getApiUrl(baseApiUrl, path) {
147
- let url = new URL(path || '/', baseApiUrl || OPENAI_API_BASE_URL);
148
- return url.href;
149
- }
150
-
151
146
  /**
152
147
  * Generates a comprehensive summary and analysis of an email message using OpenAI's API
153
148
  *
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const OPENAI_API_BASE_URL = 'https://api.openai.com';
4
+
5
+ /**
6
+ * Resolves a request URL against a custom API base URL, keeping any path prefix
7
+ * of the base URL intact. This is what makes OpenAI-compatible services that
8
+ * mount the API under a path work, e.g. Azure OpenAI
9
+ * (https://resource.openai.azure.com/openai/v1) or a local Ollama server
10
+ * (http://127.0.0.1:11434/v1).
11
+ *
12
+ * If the base URL path already ends with "/v1" and the request path starts with
13
+ * "/v1", the duplicate segment is dropped, so both "https://api.example.com"
14
+ * and "https://api.example.com/v1" style base URLs resolve to the same request
15
+ * URL.
16
+ *
17
+ * @param {string} [baseApiUrl] - Base API URL (default: OpenAI API)
18
+ * @param {string} [path] - Request path, e.g. "/v1/chat/completions"
19
+ * @returns {string} Absolute request URL
20
+ */
21
+ function getApiUrl(baseApiUrl, path) {
22
+ let url = new URL(baseApiUrl || OPENAI_API_BASE_URL);
23
+
24
+ let basePath = url.pathname.replace(/\/+$/, '');
25
+ let requestPath = path || '/';
26
+
27
+ if (/\/v1$/.test(basePath) && /^\/v1(?=\/|$)/.test(requestPath)) {
28
+ requestPath = requestPath.slice('/v1'.length) || '/';
29
+ }
30
+
31
+ url.pathname = basePath + requestPath;
32
+
33
+ return url.href;
34
+ }
35
+
36
+ module.exports = { getApiUrl, OPENAI_API_BASE_URL };
@@ -6,13 +6,9 @@ const fetchAgent = new Agent({ connect: { timeout: 90 * 1000 } });
6
6
  const util = require('util');
7
7
  const crypto = require('crypto');
8
8
 
9
- const OPENAI_API_BASE_URL = 'https://api.openai.com';
10
- const OPENAI_API_MODELS = '/v1/models';
9
+ const { getApiUrl, OPENAI_API_BASE_URL } = require('./get-api-url');
11
10
 
12
- function getApiUrl(baseApiUrl, path) {
13
- let url = new URL(path || '/', baseApiUrl || OPENAI_API_BASE_URL);
14
- return url.href;
15
- }
11
+ const OPENAI_API_MODELS = '/v1/models';
16
12
 
17
13
  async function listModels(apiToken, opts) {
18
14
  opts = opts || {};
@@ -12,7 +12,7 @@ const tokenizer = new GPT3Tokenizer({ type: 'gpt3' });
12
12
  const MAX_ALLOWED_TEXT_LENGTH = 64 * 1024;
13
13
  const DEFAULT_MAX_ALLOWED_TOKENS = 30000;
14
14
 
15
- const OPENAI_API_BASE_URL = 'https://api.openai.com';
15
+ const { getApiUrl, OPENAI_API_BASE_URL } = require('./get-api-url');
16
16
 
17
17
  const OPENAI_API_URL = '/v1/chat/completions';
18
18
 
@@ -82,11 +82,6 @@ Facts:
82
82
  Analyze the following email:
83
83
  `.trim();
84
84
 
85
- function getApiUrl(baseApiUrl, path) {
86
- let url = new URL(path || '/', baseApiUrl || OPENAI_API_BASE_URL);
87
- return url.href;
88
- }
89
-
90
85
  async function riskAnalysis(message, apiToken, opts) {
91
86
  opts = opts || {};
92
87
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/email-ai-tools",
3
- "version": "1.13.12",
3
+ "version": "1.13.14",
4
4
  "description": "Email AI tools",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,16 +21,16 @@
21
21
  },
22
22
  "homepage": "https://github.com/postalsys/email-ai-tools#readme",
23
23
  "devDependencies": {
24
- "@eslint/eslintrc": "3.3.5",
24
+ "@eslint/eslintrc": "3.3.6",
25
25
  "@eslint/js": "10.0.1",
26
- "eslint": "10.6.0",
26
+ "eslint": "10.7.0",
27
27
  "eslint-config-nodemailer": "1.2.0",
28
28
  "eslint-config-prettier": "10.1.8",
29
29
  "mailparser": "3.9.14",
30
- "prettier": "3.9.4"
30
+ "prettier": "3.9.5"
31
31
  },
32
32
  "dependencies": {
33
- "@postalsys/email-text-tools": "2.4.10",
33
+ "@postalsys/email-text-tools": "2.4.11",
34
34
  "gpt3-tokenizer": "1.1.5",
35
35
  "libmime": "5.4.1",
36
36
  "linkify-it": "5.0.2",
@@ -74,6 +74,15 @@ describe('generateSummary', () => {
74
74
  assert.equal(req.body.messages[1].role, 'user');
75
75
  });
76
76
 
77
+ it('keeps the path prefix of a custom base URL', async () => {
78
+ mock.setHandler(() => chatResponse(summaryResult));
79
+
80
+ await generateSummary(simpleMessage, 'my-api-key', { baseApiUrl: `${mock.url}/openai/v1` });
81
+
82
+ const req = mock.requests[0];
83
+ assert.equal(req.url, '/openai/v1/chat/completions');
84
+ });
85
+
77
86
  it('converts HTML to text when HTML is longer', async () => {
78
87
  mock.setHandler(() => chatResponse(summaryResult));
79
88
 
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const { describe, it } = require('node:test');
4
+ const assert = require('node:assert/strict');
5
+ const { getApiUrl, OPENAI_API_BASE_URL } = require('../lib/get-api-url');
6
+
7
+ describe('getApiUrl', () => {
8
+ it('defaults to the OpenAI API base URL', () => {
9
+ assert.equal(getApiUrl(null, '/v1/models'), 'https://api.openai.com/v1/models');
10
+ assert.equal(getApiUrl('', '/v1/chat/completions'), 'https://api.openai.com/v1/chat/completions');
11
+ assert.equal(OPENAI_API_BASE_URL, 'https://api.openai.com');
12
+ });
13
+
14
+ it('resolves against a base URL without a path', () => {
15
+ assert.equal(getApiUrl('https://api.example.com', '/v1/models'), 'https://api.example.com/v1/models');
16
+ });
17
+
18
+ it('keeps the path prefix of the base URL', () => {
19
+ // Azure OpenAI style resource with the API mounted under a path
20
+ assert.equal(getApiUrl('https://myres.openai.azure.com/openai/v1', '/v1/models'), 'https://myres.openai.azure.com/openai/v1/models');
21
+ assert.equal(
22
+ getApiUrl('https://myres.openai.azure.com/openai/v1', '/v1/chat/completions'),
23
+ 'https://myres.openai.azure.com/openai/v1/chat/completions'
24
+ );
25
+ assert.equal(getApiUrl('https://myres.openai.azure.com/openai', '/v1/embeddings'), 'https://myres.openai.azure.com/openai/v1/embeddings');
26
+ });
27
+
28
+ it('ignores a trailing slash on the base URL', () => {
29
+ assert.equal(getApiUrl('https://api.example.com/', '/v1/models'), 'https://api.example.com/v1/models');
30
+ assert.equal(getApiUrl('https://myres.openai.azure.com/openai/v1/', '/v1/models'), 'https://myres.openai.azure.com/openai/v1/models');
31
+ });
32
+
33
+ it('does not duplicate a /v1 suffix already present on the base URL', () => {
34
+ assert.equal(getApiUrl('https://api.example.com/v1', '/v1/models'), 'https://api.example.com/v1/models');
35
+ assert.equal(getApiUrl('http://127.0.0.1:11434/v1', '/v1/chat/completions'), 'http://127.0.0.1:11434/v1/chat/completions');
36
+ assert.equal(getApiUrl('https://openrouter.example.com/api/v1', '/v1/models'), 'https://openrouter.example.com/api/v1/models');
37
+ });
38
+
39
+ it('does not treat a /v1 mid-path segment as a version suffix', () => {
40
+ assert.equal(getApiUrl('https://api.example.com/v1/proxy', '/v1/models'), 'https://api.example.com/v1/proxy/v1/models');
41
+ });
42
+
43
+ it('handles a missing request path', () => {
44
+ assert.equal(getApiUrl('https://api.example.com'), 'https://api.example.com/');
45
+ assert.equal(getApiUrl('https://api.example.com/v1'), 'https://api.example.com/v1/');
46
+ });
47
+ });
@@ -40,6 +40,15 @@ describe('listModels', () => {
40
40
  assert.ok(req.headers.authorization.includes('Bearer my-api-key'));
41
41
  });
42
42
 
43
+ it('keeps the path prefix of a custom base URL', async () => {
44
+ mock.setHandler(() => modelsResponse());
45
+
46
+ await listModels('my-api-key', { baseApiUrl: `${mock.url}/openai/v1` });
47
+
48
+ const req = mock.requests[0];
49
+ assert.equal(req.url, '/openai/v1/models');
50
+ });
51
+
43
52
  it('filters out openai-dev models', async () => {
44
53
  mock.setHandler(() =>
45
54
  modelsResponse([
@@ -1,11 +0,0 @@
1
- name: "email-ai-tools CodeQL config"
2
-
3
- # Exclude code that is not part of the published library runtime from analysis.
4
- # These paths generate only false-positive noise:
5
- # - tests and their mock server intentionally use fixed local URLs and
6
- # simplified handlers that are not production code
7
- # - examples are standalone usage snippets, not part of the package
8
- paths-ignore:
9
- - test
10
- - '**/test/**'
11
- - examples
@@ -1,48 +0,0 @@
1
- name: "CodeQL Advanced"
2
-
3
- on:
4
- push:
5
- branches: [ "master" ]
6
- pull_request:
7
- branches: [ "master" ]
8
- schedule:
9
- - cron: '40 17 * * 6'
10
-
11
- jobs:
12
- analyze:
13
- name: Analyze (${{ matrix.language }})
14
- runs-on: ubuntu-latest
15
- permissions:
16
- # required for all workflows
17
- security-events: write
18
-
19
- # required to fetch internal or private CodeQL packs
20
- packages: read
21
-
22
- # only required for workflows in private repositories
23
- actions: read
24
- contents: read
25
-
26
- strategy:
27
- fail-fast: false
28
- matrix:
29
- include:
30
- - language: actions
31
- build-mode: none
32
- - language: javascript-typescript
33
- build-mode: none
34
- steps:
35
- - name: Checkout repository
36
- uses: actions/checkout@v4
37
-
38
- - name: Initialize CodeQL
39
- uses: github/codeql-action/init@v4
40
- with:
41
- languages: ${{ matrix.language }}
42
- build-mode: ${{ matrix.build-mode }}
43
- config-file: ./.github/codeql/codeql-config.yml
44
-
45
- - name: Perform CodeQL Analysis
46
- uses: github/codeql-action/analyze@v4
47
- with:
48
- category: "/language:${{matrix.language}}"