@adaptic/lumic-utils 1.0.18 → 1.0.19
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/dist/{apollo-client.client-kEvzgHxw.js → apollo-client.client-Dfi-rHW-.js} +4 -4
- package/dist/{apollo-client.client-kEvzgHxw.js.map → apollo-client.client-Dfi-rHW-.js.map} +1 -1
- package/dist/{apollo-client.client-Cz-ZMwuK.js → apollo-client.client-guxMwplM.js} +3 -3
- package/dist/{apollo-client.client-Cz-ZMwuK.js.map → apollo-client.client-guxMwplM.js.map} +1 -1
- package/dist/{apollo-client.server-C2gZgUkR.js → apollo-client.server-Blxbp1Gf.js} +3 -3
- package/dist/{apollo-client.server-C2gZgUkR.js.map → apollo-client.server-Blxbp1Gf.js.map} +1 -1
- package/dist/{apollo-client.server-BAuFJqgR.js → apollo-client.server-HwHIFnVk.js} +3 -3
- package/dist/{apollo-client.server-BAuFJqgR.js.map → apollo-client.server-HwHIFnVk.js.map} +1 -1
- package/dist/{index-27SewDPi.js → index-B4tfLvHx.js} +2 -2
- package/dist/{index-27SewDPi.js.map → index-B4tfLvHx.js.map} +1 -1
- package/dist/{index-UQOI_SLD.js → index-CSQmloZ-.js} +75 -12
- package/dist/{index-UQOI_SLD.js.map → index-CSQmloZ-.js.map} +1 -1
- package/dist/{index-C_0vRRAD.js → index-DollRUHQ.js} +2 -2
- package/dist/{index-C_0vRRAD.js.map → index-DollRUHQ.js.map} +1 -1
- package/dist/{index-C3ihLNel.js → index-Dr85zRZC.js} +75 -12
- package/dist/{index-C3ihLNel.js.map → index-Dr85zRZC.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/test.cjs +1 -1
- package/dist/test.mjs +1 -1
- package/package.json +1 -1
|
@@ -2106,15 +2106,33 @@ function resetLLMCostTracker() {
|
|
|
2106
2106
|
// llm-openai.ts
|
|
2107
2107
|
/**
|
|
2108
2108
|
* Determines if an LLM error should be retried.
|
|
2109
|
-
*
|
|
2109
|
+
*
|
|
2110
|
+
* Retries on:
|
|
2111
|
+
* - 429 / rate limit errors (transient capacity)
|
|
2112
|
+
* - "could not parse the JSON body" 400s — observed once in production for a
|
|
2113
|
+
* single symbol on the very first conversation turn (Wave 86, 2026-04-11).
|
|
2114
|
+
* The exact same call site succeeds millions of times before and after, and
|
|
2115
|
+
* the prior fix commit `6eaef52` in this repo already eliminated the only
|
|
2116
|
+
* known SDK-v5 cause (passing `tools: undefined/null`). The remaining cases
|
|
2117
|
+
* are virtually always proxy/network corruption of the request body in
|
|
2118
|
+
* flight (request truncated mid-flight, TLS renegotiation, edge proxy
|
|
2119
|
+
* buffer reset). Retrying once with a fresh connection has a high
|
|
2120
|
+
* probability of recovering, and a deterministic SDK-side defect would
|
|
2121
|
+
* re-fail on retry (so we still surface it).
|
|
2110
2122
|
*/
|
|
2111
2123
|
const isRetryableLLMError = (error) => {
|
|
2112
2124
|
if (error instanceof Error) {
|
|
2113
2125
|
const message = error.message;
|
|
2114
|
-
// Retry
|
|
2126
|
+
// Retry on rate limits (429)
|
|
2115
2127
|
if (message.includes('429') || message.includes('rate limit') || message.includes('Rate limit')) {
|
|
2116
2128
|
return true;
|
|
2117
2129
|
}
|
|
2130
|
+
// Retry on transient body-corruption 400s. Match the exact OpenAI error
|
|
2131
|
+
// string to avoid retrying genuine client-side validation 400s (which
|
|
2132
|
+
// would re-fail forever and waste retry budget).
|
|
2133
|
+
if (message.includes('could not parse the JSON body of your request')) {
|
|
2134
|
+
return true;
|
|
2135
|
+
}
|
|
2118
2136
|
}
|
|
2119
2137
|
return false;
|
|
2120
2138
|
};
|
|
@@ -2310,12 +2328,52 @@ async function createCompletion(content, responseFormat, options = DEFAULT_OPTIO
|
|
|
2310
2328
|
if (responseFormatOption.type !== 'text') {
|
|
2311
2329
|
queryOptions.response_format = responseFormatOption;
|
|
2312
2330
|
}
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2331
|
+
let completion;
|
|
2332
|
+
try {
|
|
2333
|
+
completion = await withRetry(() => openai.chat.completions.create(queryOptions), {
|
|
2334
|
+
maxRetries: 3,
|
|
2335
|
+
baseDelayMs: 2000,
|
|
2336
|
+
maxDelayMs: 30000,
|
|
2337
|
+
retryableErrors: isRetryableLLMError,
|
|
2338
|
+
}, `OpenAI:${normalizedModel}`);
|
|
2339
|
+
}
|
|
2340
|
+
catch (error) {
|
|
2341
|
+
// Defensive observability: when the OpenAI SDK rejects our request,
|
|
2342
|
+
// emit a structured snapshot of the queryOptions shape (NOT content) so
|
|
2343
|
+
// a future recurrence of the rare "could not parse JSON body" 400 can be
|
|
2344
|
+
// diagnosed without having to reproduce locally. We deliberately log
|
|
2345
|
+
// metadata only — no message content, no API key — so this is safe even
|
|
2346
|
+
// for production prompts containing sensitive context.
|
|
2347
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2348
|
+
const totalContentChars = messages.reduce((sum, msg) => {
|
|
2349
|
+
if (typeof msg.content === 'string')
|
|
2350
|
+
return sum + msg.content.length;
|
|
2351
|
+
if (Array.isArray(msg.content)) {
|
|
2352
|
+
return sum + msg.content.reduce((s, part) => {
|
|
2353
|
+
if (typeof part === 'object' && part !== null && 'text' in part && typeof part.text === 'string') {
|
|
2354
|
+
return s + part.text.length;
|
|
2355
|
+
}
|
|
2356
|
+
return s;
|
|
2357
|
+
}, 0);
|
|
2358
|
+
}
|
|
2359
|
+
return sum;
|
|
2360
|
+
}, 0);
|
|
2361
|
+
getLumicLogger().error(`OpenAI ChatCompletion call failed for model ${normalizedModel}`, {
|
|
2362
|
+
model: normalizedModel,
|
|
2363
|
+
errorMessage,
|
|
2364
|
+
messageCount: messages.length,
|
|
2365
|
+
roleBreakdown: messages.reduce((acc, msg) => {
|
|
2366
|
+
acc[msg.role] = (acc[msg.role] ?? 0) + 1;
|
|
2367
|
+
return acc;
|
|
2368
|
+
}, {}),
|
|
2369
|
+
totalContentChars,
|
|
2370
|
+
toolCount: queryOptions.tools?.length ?? 0,
|
|
2371
|
+
hasTemperature: queryOptions.temperature !== undefined,
|
|
2372
|
+
hasResponseFormat: queryOptions.response_format !== undefined,
|
|
2373
|
+
hasMaxCompletionTokens: queryOptions.max_completion_tokens !== undefined,
|
|
2374
|
+
});
|
|
2375
|
+
throw error;
|
|
2376
|
+
}
|
|
2319
2377
|
const response = {
|
|
2320
2378
|
id: completion.id,
|
|
2321
2379
|
content: completion.choices[0]?.message?.content || '',
|
|
@@ -7942,7 +8000,12 @@ function translateContextToAnthropic(context) {
|
|
|
7942
8000
|
/** Convert string or content block array to a uniform content block array. */
|
|
7943
8001
|
function toContentBlocks(content) {
|
|
7944
8002
|
if (typeof content === 'string') {
|
|
7945
|
-
|
|
8003
|
+
const textBlock = {
|
|
8004
|
+
type: 'text',
|
|
8005
|
+
text: content,
|
|
8006
|
+
citations: null,
|
|
8007
|
+
};
|
|
8008
|
+
return [textBlock];
|
|
7946
8009
|
}
|
|
7947
8010
|
return content;
|
|
7948
8011
|
}
|
|
@@ -22733,11 +22796,11 @@ let poolConfig = DEFAULT_POOL_CONFIG;
|
|
|
22733
22796
|
async function loadApolloModules() {
|
|
22734
22797
|
if (typeof window === "undefined" || process.env.AWS_EXECUTION_ENV) {
|
|
22735
22798
|
// Server-side (or Lambda): load the CommonJS‑based implementation.
|
|
22736
|
-
return (await Promise.resolve().then(function () { return require('./apollo-client.server-
|
|
22799
|
+
return (await Promise.resolve().then(function () { return require('./apollo-client.server-HwHIFnVk.js'); }));
|
|
22737
22800
|
}
|
|
22738
22801
|
else {
|
|
22739
22802
|
// Client-side: load the ESM‑based implementation.
|
|
22740
|
-
return (await Promise.resolve().then(function () { return require('./apollo-client.client-
|
|
22803
|
+
return (await Promise.resolve().then(function () { return require('./apollo-client.client-guxMwplM.js'); }));
|
|
22741
22804
|
}
|
|
22742
22805
|
}
|
|
22743
22806
|
/**
|
|
@@ -81448,4 +81511,4 @@ exports.withCorrelationId = withCorrelationId;
|
|
|
81448
81511
|
exports.withMetrics = withMetrics;
|
|
81449
81512
|
exports.withRateLimit = withRateLimit;
|
|
81450
81513
|
exports.withRetry = withRetry;
|
|
81451
|
-
//# sourceMappingURL=index-
|
|
81514
|
+
//# sourceMappingURL=index-Dr85zRZC.js.map
|