@postalsys/email-ai-tools 2.2.8 → 2.3.1

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/index.d.ts +28 -0
  4. package/dist/cjs/index.js +67 -0
  5. package/dist/cjs/lib/api-request.d.ts +42 -0
  6. package/dist/cjs/lib/api-request.js +183 -0
  7. package/dist/cjs/lib/authentication.d.ts +46 -0
  8. package/{lib → dist/cjs/lib}/authentication.js +33 -44
  9. package/dist/cjs/lib/generate-summary.d.ts +143 -0
  10. package/dist/cjs/lib/generate-summary.js +562 -0
  11. package/dist/cjs/lib/get-api-url.d.ts +19 -0
  12. package/dist/cjs/lib/get-api-url.js +37 -0
  13. package/dist/cjs/lib/list-models.d.ts +46 -0
  14. package/dist/cjs/lib/list-models.js +125 -0
  15. package/dist/cjs/lib/signals.d.ts +72 -0
  16. package/dist/cjs/lib/signals.js +293 -0
  17. package/dist/cjs/lib/token-estimate.d.ts +46 -0
  18. package/{lib → dist/cjs/lib}/token-estimate.js +21 -50
  19. package/dist/cjs/lib/visible-text.d.ts +33 -0
  20. package/dist/cjs/lib/visible-text.js +182 -0
  21. package/dist/cjs/package-info.d.ts +2 -0
  22. package/dist/cjs/package-info.js +6 -0
  23. package/dist/cjs/package.json +3 -0
  24. package/dist/esm/index.d.ts +28 -0
  25. package/dist/esm/index.js +30 -0
  26. package/dist/esm/lib/api-request.d.ts +42 -0
  27. package/{lib → dist/esm/lib}/api-request.js +20 -53
  28. package/dist/esm/lib/authentication.d.ts +46 -0
  29. package/dist/esm/lib/authentication.js +149 -0
  30. package/dist/esm/lib/generate-summary.d.ts +143 -0
  31. package/{lib → dist/esm/lib}/generate-summary.js +59 -155
  32. package/dist/esm/lib/get-api-url.d.ts +19 -0
  33. package/{lib → dist/esm/lib}/get-api-url.js +4 -13
  34. package/dist/esm/lib/list-models.d.ts +46 -0
  35. package/{lib → dist/esm/lib}/list-models.js +19 -50
  36. package/dist/esm/lib/signals.d.ts +72 -0
  37. package/{lib → dist/esm/lib}/signals.js +33 -79
  38. package/dist/esm/lib/token-estimate.d.ts +46 -0
  39. package/dist/esm/lib/token-estimate.js +108 -0
  40. package/dist/esm/lib/visible-text.d.ts +33 -0
  41. package/{lib → dist/esm/lib}/visible-text.js +14 -40
  42. package/dist/esm/package-info.d.ts +2 -0
  43. package/dist/esm/package-info.js +3 -0
  44. package/dist/esm/package.json +3 -0
  45. package/package.json +65 -12
  46. package/.github/VULNERABILITY_REPORT.yml +0 -75
  47. package/.github/workflows/release.yaml +0 -37
  48. package/.github/workflows/test.yaml +0 -35
  49. package/.ncurc.js +0 -23
  50. package/.prettierignore +0 -5
  51. package/.prettierrc.js +0 -10
  52. package/.release-please-manifest.json +0 -3
  53. package/CLAUDE.md +0 -185
  54. package/eslint.config.js +0 -70
  55. package/examples/fixtures/message-1.json +0 -74
  56. package/examples/list-models.js +0 -14
  57. package/examples/summary.js +0 -34
  58. package/index.js +0 -26
  59. package/release-please-config.json +0 -10
  60. package/test/api-request.test.js +0 -169
  61. package/test/authentication.test.js +0 -110
  62. package/test/commonjs-graph.test.js +0 -21
  63. package/test/dispatcher.test.js +0 -94
  64. package/test/generate-summary.test.js +0 -795
  65. package/test/get-api-url.test.js +0 -52
  66. package/test/helpers/mock-server.js +0 -120
  67. package/test/index.test.js +0 -57
  68. package/test/list-models.test.js +0 -302
  69. package/test/signals.test.js +0 -264
  70. package/test/token-estimate.test.js +0 -164
  71. package/test/visible-text.test.js +0 -144
@@ -0,0 +1,143 @@
1
+ import type { Dispatcher } from 'undici';
2
+ import type { ApiRequestError } from './api-request.js';
3
+ import type { Signal } from './signals.js';
4
+ /** An address as {name, address} */
5
+ export interface SummaryAddress {
6
+ name?: string | null | undefined;
7
+ address?: string | null | undefined;
8
+ }
9
+ /** The email message to analyze */
10
+ export interface SummaryMessage {
11
+ /** Header objects; a value may be a string or a list of strings, encoded words are decoded */
12
+ headers?: Array<{
13
+ key?: string | null | undefined;
14
+ value?: unknown;
15
+ } | null | undefined> | null | undefined;
16
+ /** Decoded subject, used over the subject header */
17
+ subject?: string | null | undefined;
18
+ /** Sender, as a string or as {name, address}, used over the from header */
19
+ from?: string | SummaryAddress | null | undefined;
20
+ /** Message date, used over the date header */
21
+ date?: string | Date | null | undefined;
22
+ /** Attachment objects with {filename, contentType} */
23
+ attachments?: Array<{
24
+ filename?: string | null | undefined;
25
+ contentType?: string | null | undefined;
26
+ [key: string]: unknown;
27
+ } | null | undefined> | null | undefined;
28
+ /** Plain text content */
29
+ text?: string | null | undefined;
30
+ /** HTML content, converted to text when it is the fuller version */
31
+ html?: string | null | undefined;
32
+ }
33
+ export interface GenerateSummaryOptions {
34
+ /** Custom API base URL (default: OpenAI API) */
35
+ baseApiUrl?: string | null | undefined;
36
+ /** Model to use (default: DEFAULT_MODEL) */
37
+ gptModel?: string | null | undefined;
38
+ /** Replaces the role and trust rules at the top of the system message */
39
+ systemPrompt?: string | null | undefined;
40
+ /** Replaces the analysis instructions, including the output properties */
41
+ instructions?: string | null | undefined;
42
+ /** Maximum estimated tokens for the prompt (default 30000, a character-based estimate that errs high) */
43
+ maxTokens?: number | null | undefined;
44
+ /** Sampling temperature (0-2), not sent to a model that is reasoning */
45
+ temperature?: number | string | null | undefined;
46
+ /** Nucleus sampling parameter (0-1), not sent to a model that is reasoning */
47
+ topP?: number | string | null | undefined;
48
+ /** Reasoning effort for reasoning models ("low" when unset for one) */
49
+ reasoningEffort?: string | null | undefined;
50
+ /** Ask for a JSON object response (default true), dropped when the model refuses it */
51
+ jsonMode?: boolean | undefined;
52
+ /** End-user identifier passed to the API */
53
+ user?: string | null | undefined;
54
+ /** Additional headers to include (merged with defaults) */
55
+ allowedHeaders?: string[] | string | null | undefined;
56
+ /** Names of the servers whose Authentication-Results header counts as verified, hosts under them included */
57
+ trustedAuthservIds?: string[] | string | null | undefined;
58
+ /** Whether an Authentication-Results header without an authserv-id counts as verified (Microsoft writes none) */
59
+ acceptUnnamedAuthentication?: boolean | undefined;
60
+ /** Log requests to stderr and include the prompt text in the usage */
61
+ verbose?: boolean | undefined;
62
+ /** undici Dispatcher (for example a ProxyAgent) the API request is sent through */
63
+ dispatcher?: Dispatcher | undefined;
64
+ /** Aborts the API request and any rate limit retry wait */
65
+ signal?: AbortSignal | undefined;
66
+ }
67
+ /** What the model returned, with the documented properties normalized */
68
+ export interface SummaryResult {
69
+ summary?: string;
70
+ sentiment?: 'positive' | 'neutral' | 'negative';
71
+ shouldReply?: boolean;
72
+ riskAssessment?: {
73
+ risk?: number;
74
+ assessment?: string;
75
+ signals?: string[];
76
+ [key: string]: unknown;
77
+ };
78
+ events?: Array<Record<string, string | number | boolean>>;
79
+ actions?: Array<Record<string, string | number | boolean>>;
80
+ [key: string]: unknown;
81
+ }
82
+ export interface SummaryUsage {
83
+ id: string | null;
84
+ model: string;
85
+ servedModel: string | null;
86
+ tokens: number | null;
87
+ promptTokens: number | null;
88
+ completionTokens: number | null;
89
+ time: number;
90
+ charactersRemoved: number;
91
+ /** The prompt text, with `verbose` */
92
+ text?: string;
93
+ }
94
+ /** An error from generateSummary(), carrying the signals found before it */
95
+ export interface SummaryError extends ApiRequestError {
96
+ signals?: Signal[];
97
+ textContent?: string;
98
+ finishReason?: string;
99
+ }
100
+ declare const DEFAULT_MODEL = "gpt-6-luna";
101
+ declare const REASONING_EFFORTS: string[];
102
+ declare const DEFAULT_REASONING_EFFORT = "low";
103
+ declare const DEFAULT_MAX_TOKENS = 30000;
104
+ declare const DEFAULT_SYSTEM_PROMPT: string;
105
+ declare const DEFAULT_INSTRUCTIONS: string;
106
+ /**
107
+ * Tells whether a model name belongs to a family that takes a reasoning effort and, while
108
+ * reasoning, refuses sampling parameters: GPT-5 and later, the open-weight gpt-oss models and
109
+ * the o-series. The "chat" variants of those families are ordinary chat models. A name this does
110
+ * not recognize (an Azure deployment, a prefixed name) is still handled: the backend's refusal
111
+ * of a parameter is honored either way, this only saves the request that learns it
112
+ *
113
+ * @param input - Model name as sent to the API
114
+ */
115
+ declare function isReasoningModel(input: unknown): boolean;
116
+ /**
117
+ * Forgets which parameters a backend refused. Meant for tests
118
+ */
119
+ declare function resetParameterCache(): void;
120
+ /**
121
+ * Analyzes an email message with a chat model and returns what the model reported, untouched
122
+ * except for normalization of the documented properties, beside the request usage
123
+ *
124
+ * @param message - The email message to analyze
125
+ * @param apiToken - API authentication token
126
+ * @param opts - Configuration options
127
+ *
128
+ * @returns The model's JSON object (`result`: sentiment, summary, shouldReply, riskAssessment and
129
+ * so on, with the risk score held at the signals' floor and the signal codes listed under
130
+ * riskAssessment.signals), the request usage and the signals found in code, each with its code,
131
+ * detail and floor
132
+ *
133
+ * @throws Error if the prompt is too long even without any text (code PROMPT_TOO_LONG)
134
+ * @throws Error if the API request fails
135
+ * @throws Error if the response holds no JSON object
136
+ */
137
+ declare function generateSummary(message: SummaryMessage | null | undefined, apiToken: string, opts?: GenerateSummaryOptions | null): Promise<{
138
+ result: SummaryResult;
139
+ usage: SummaryUsage;
140
+ signals: Signal[];
141
+ }>;
142
+ declare const ALLOWED_HEADERS: readonly string[];
143
+ export { generateSummary, isReasoningModel, resetParameterCache, DEFAULT_MODEL, DEFAULT_REASONING_EFFORT, DEFAULT_MAX_TOKENS, DEFAULT_SYSTEM_PROMPT, DEFAULT_INSTRUCTIONS, REASONING_EFFORTS, ALLOWED_HEADERS };