@cellaware/utils 8.5.1 → 8.5.3

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.
@@ -76,7 +76,10 @@ export async function generatePdf(html, options) {
76
76
  const totalAttempts = 1 + RETRIES;
77
77
  for (let attempt = 1; attempt <= totalAttempts; attempt++) {
78
78
  const controller = new AbortController();
79
- const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS);
79
+ const timeout = setTimeout(() => {
80
+ console.log(`PDF: attempt ${attempt} timed out after ${TIMEOUT_MS}ms`);
81
+ controller.abort();
82
+ }, TIMEOUT_MS);
80
83
  try {
81
84
  const res = await fetch(url.toString(), {
82
85
  method: "POST",
@@ -99,10 +102,14 @@ export async function generatePdf(html, options) {
99
102
  const ab = await res.arrayBuffer();
100
103
  return Buffer.from(ab);
101
104
  }
105
+ console.log(`PDF: attempt ${attempt} failed with status ${res.status} ${res.statusText}`);
102
106
  const retryable = shouldRetryStatus(res.status);
103
107
  if (retryable && attempt < totalAttempts) {
104
108
  const retryAfter = parseRetryAfterMs(res.headers.get("retry-after"));
105
- const delay = retryAfter !== null ? retryAfter + Math.floor(Math.random() * (JITTER_MS + 1)) : backoffMs(attempt);
109
+ const delay = retryAfter !== null
110
+ ? retryAfter + Math.floor(Math.random() * (JITTER_MS + 1))
111
+ : backoffMs(attempt);
112
+ console.log(`PDF: retryable failure (status ${res.status}), waiting ${delay}ms before retry`);
106
113
  await sleep(delay);
107
114
  continue;
108
115
  }
@@ -118,8 +125,16 @@ export async function generatePdf(html, options) {
118
125
  err?.code === "EAI_AGAIN" ||
119
126
  err?.cause?.code === "ECONNRESET" ||
120
127
  err?.cause?.code === "ETIMEDOUT";
128
+ if (isAbort) {
129
+ console.log(`PDF: attempt ${attempt} aborted`);
130
+ }
131
+ else {
132
+ console.log(`PDF: attempt ${attempt} threw error`, err);
133
+ }
121
134
  if (isTransientNetwork && attempt < totalAttempts) {
122
- await sleep(backoffMs(attempt));
135
+ const delay = backoffMs(attempt);
136
+ console.log(`PDF: transient error, waiting ${delay}ms before retry`);
137
+ await sleep(delay);
123
138
  continue;
124
139
  }
125
140
  throw err;
package/dist/llm/cost.js CHANGED
@@ -1,71 +1,31 @@
1
1
  // https://platform.openai.com/docs/pricing
2
+ const MODEL_COSTS = {
3
+ 'gpt-5.2-pro': { inputCost: 21.00, outputCost: 168.00 },
4
+ 'gpt-5.2': { inputCost: 1.75, outputCost: 14.00 },
5
+ 'gpt-5.2-chat-latest': { inputCost: 1.75, outputCost: 14.00 },
6
+ 'gpt-5.2-codex': { inputCost: 1.75, outputCost: 14.00 },
7
+ 'gpt-5.1': { inputCost: 1.25, outputCost: 10.00 },
8
+ 'gpt-5': { inputCost: 1.25, outputCost: 10.00 },
9
+ 'gpt-5-mini': { inputCost: 0.25, outputCost: 2.00 },
10
+ 'gpt-5-nano': { inputCost: 0.05, outputCost: 0.40 },
11
+ 'gpt-4.1': { inputCost: 2.00, outputCost: 8.00 },
12
+ 'gpt-4.1-mini': { inputCost: 0.40, outputCost: 1.60 },
13
+ 'gpt-4.1-nano': { inputCost: 0.10, outputCost: 0.40 },
14
+ 'gpt-4o': { inputCost: 2.50, outputCost: 10.00 },
15
+ 'gpt-4o-mini': { inputCost: 0.15, outputCost: 0.60 },
16
+ 'o1': { inputCost: 15.00, outputCost: 60.00 },
17
+ 'o1-mini': { inputCost: 1.10, outputCost: 4.40 },
18
+ 'o3': { inputCost: 2.00, outputCost: 8.00 },
19
+ 'o3-mini': { inputCost: 1.10, outputCost: 4.40 },
20
+ 'o4-mini': { inputCost: 1.10, outputCost: 4.40 },
21
+ };
2
22
  export function getLLMCostPerToken(modelName) {
3
- let inputCost = 0.0;
4
- let outputCost = 0.0;
5
- switch (modelName) {
6
- case 'gpt-5.2':
7
- inputCost = 1.75;
8
- outputCost = 14.00;
9
- break;
10
- case 'gpt-5.1':
11
- inputCost = 1.25;
12
- outputCost = 10.00;
13
- break;
14
- case 'gpt-5':
15
- inputCost = 1.25;
16
- outputCost = 10.00;
17
- break;
18
- case 'gpt-5-mini':
19
- inputCost = 0.25;
20
- outputCost = 2.00;
21
- break;
22
- case 'gpt-5-nano':
23
- inputCost = 0.05;
24
- outputCost = 0.40;
25
- break;
26
- case 'gpt-4.1':
27
- inputCost = 2.00;
28
- outputCost = 8.00;
29
- break;
30
- case 'gpt-4.1-mini':
31
- inputCost = 0.40;
32
- outputCost = 1.60;
33
- break;
34
- case 'gpt-4.1-nano':
35
- inputCost = 0.10;
36
- outputCost = 0.40;
37
- break;
38
- case 'gpt-4o':
39
- inputCost = 2.50;
40
- outputCost = 10.00;
41
- break;
42
- case 'gpt-4o-mini':
43
- inputCost = 0.15;
44
- outputCost = 0.60;
45
- break;
46
- case 'o1':
47
- inputCost = 15.00;
48
- outputCost = 60.00;
49
- break;
50
- case 'o1-mini':
51
- inputCost = 1.10;
52
- outputCost = 4.40;
53
- break;
54
- case 'o3':
55
- inputCost = 10.00;
56
- outputCost = 40.00;
57
- break;
58
- case 'o3-mini':
59
- inputCost = 1.10;
60
- outputCost = 4.40;
61
- break;
62
- case 'o4-mini':
63
- inputCost = 1.10;
64
- outputCost = 4.40;
65
- break;
66
- default:
67
- throw new Error(`Model '${modelName}' cost is not configured`);
23
+ const cost = MODEL_COSTS[modelName];
24
+ if (!cost) {
25
+ throw new Error(`Model '${modelName}' cost is not configured`);
68
26
  }
27
+ let inputCost = cost.inputCost;
28
+ let outputCost = cost.outputCost;
69
29
  // OpenAI model costs are measured in millions of tokens -- therefore we need to divide each figure by 1,000,000 before returning.
70
30
  const unit = 1_000_000.0;
71
31
  inputCost /= unit;
@@ -1,4 +1,4 @@
1
- export type ModelName = 'gpt-5.2' | 'gpt-5.1' | 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4o' | 'gpt-4o-mini' | 'o1' | 'o1-mini' | 'o3' | 'o3-mini' | 'o4-mini';
1
+ export type ModelName = 'gpt-5.2-pro' | 'gpt-5.2-codex' | 'gpt-5.2-chat-latest' | 'gpt-5.2' | 'gpt-5.1' | 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4o' | 'gpt-4o-mini' | 'o1' | 'o1-mini' | 'o3' | 'o3-mini' | 'o4-mini';
2
2
  export type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
3
3
  export type Verbosity = 'low' | 'medium' | 'high';
4
4
  export interface OpenAIModelOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.5.1",
3
+ "version": "8.5.3",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",