@postalsys/email-ai-tools 1.13.13 → 1.13.15
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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +14 -0
- package/lib/embeddings-query.js +1 -6
- package/lib/generate-embeddings.js +1 -6
- package/lib/generate-summary.js +1 -6
- package/lib/get-api-url.js +36 -0
- package/lib/list-models.js +2 -6
- package/lib/risk-analysis.js +1 -6
- package/package.json +4 -4
- package/test/generate-summary.test.js +9 -0
- package/test/get-api-url.test.js +47 -0
- package/test/list-models.test.js +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.13.15](https://github.com/postalsys/email-ai-tools/compare/v1.13.14...v1.13.15) (2026-07-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **deps:** update undici to 7.29.0 ([1ae29d8](https://github.com/postalsys/email-ai-tools/commit/1ae29d8e7f04eb01c9cd54dc61d41d92358804af))
|
|
9
|
+
|
|
10
|
+
## [1.13.14](https://github.com/postalsys/email-ai-tools/compare/v1.13.13...v1.13.14) (2026-07-23)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* keep the URL path prefix of custom API base URLs ([6c699da](https://github.com/postalsys/email-ai-tools/commit/6c699da65b5b399877f4a84992f4d0a827987d50))
|
|
16
|
+
|
|
3
17
|
## [1.13.13](https://github.com/postalsys/email-ai-tools/compare/v1.13.12...v1.13.13) (2026-07-20)
|
|
4
18
|
|
|
5
19
|
|
package/lib/embeddings-query.js
CHANGED
|
@@ -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 = '
|
|
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 = '
|
|
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
|
|
package/lib/generate-summary.js
CHANGED
|
@@ -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 = '
|
|
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 };
|
package/lib/list-models.js
CHANGED
|
@@ -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 = '
|
|
10
|
-
const OPENAI_API_MODELS = '/v1/models';
|
|
9
|
+
const { getApiUrl, OPENAI_API_BASE_URL } = require('./get-api-url');
|
|
11
10
|
|
|
12
|
-
|
|
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 || {};
|
package/lib/risk-analysis.js
CHANGED
|
@@ -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 = '
|
|
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.
|
|
3
|
+
"version": "1.13.15",
|
|
4
4
|
"description": "Email AI tools",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eslint/eslintrc": "3.3.6",
|
|
25
25
|
"@eslint/js": "10.0.1",
|
|
26
|
-
"eslint": "10.
|
|
26
|
+
"eslint": "10.8.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.
|
|
30
|
+
"prettier": "3.9.6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@postalsys/email-text-tools": "2.4.11",
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"nodemailer": "9.0.3",
|
|
38
38
|
"punycode.js": "2.3.1",
|
|
39
39
|
"tlds": "1.261.0",
|
|
40
|
-
"undici": "7.
|
|
40
|
+
"undici": "7.29.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -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
|
+
});
|
package/test/list-models.test.js
CHANGED
|
@@ -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([
|