@adaptic/lumic-utils 1.0.23 → 1.0.25
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-FeVPHV0i.js → apollo-client.client-D6jG5B1n.js} +3 -3
- package/dist/{apollo-client.client-FeVPHV0i.js.map → apollo-client.client-D6jG5B1n.js.map} +1 -1
- package/dist/{apollo-client.client-DrSy1wz-.js → apollo-client.client-DLW-p46Y.js} +4 -4
- package/dist/{apollo-client.client-DrSy1wz-.js.map → apollo-client.client-DLW-p46Y.js.map} +1 -1
- package/dist/{apollo-client.server-CJ6iRLa2.js → apollo-client.server-CXLiLmSz.js} +3 -3
- package/dist/{apollo-client.server-CJ6iRLa2.js.map → apollo-client.server-CXLiLmSz.js.map} +1 -1
- package/dist/{apollo-client.server-BEGHAF48.js → apollo-client.server-Cx30LaNh.js} +3 -3
- package/dist/{apollo-client.server-BEGHAF48.js.map → apollo-client.server-Cx30LaNh.js.map} +1 -1
- package/dist/{index-CWoI2dXN.js → index-Bvc61lYS.js} +76 -18
- package/dist/{index-WGzi__C5.js.map → index-Bvc61lYS.js.map} +1 -1
- package/dist/{index-WGzi__C5.js → index-ChygDqeG.js} +76 -18
- package/dist/{index-CWoI2dXN.js.map → index-ChygDqeG.js.map} +1 -1
- package/dist/{index-Dz0wKyTF.js → index-CqnZ-XiI.js} +2 -2
- package/dist/{index-Dz0wKyTF.js.map → index-CqnZ-XiI.js.map} +1 -1
- package/dist/{index-vRskhk1H.js → index-D2TPDKw0.js} +2 -2
- package/dist/{index-vRskhk1H.js.map → index-D2TPDKw0.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/dist/types/functions/llm-openai.d.ts +5 -0
- package/dist/types/types/openai-types.d.ts +25 -0
- package/dist/types/utils/retry.d.ts +8 -0
- package/package.json +1 -1
|
@@ -2003,11 +2003,19 @@ const DEFAULT_RETRY_CONFIG = {
|
|
|
2003
2003
|
* @throws The last error encountered if all retry attempts fail or if a non-retryable error occurs
|
|
2004
2004
|
*/
|
|
2005
2005
|
async function withRetry(fn, config = {}, label = 'unknown') {
|
|
2006
|
-
const { maxRetries, baseDelayMs, maxDelayMs, retryableErrors, circuitBreaker } = {
|
|
2006
|
+
const { maxRetries, baseDelayMs, maxDelayMs, retryableErrors, circuitBreaker, signal } = {
|
|
2007
2007
|
...DEFAULT_RETRY_CONFIG,
|
|
2008
2008
|
...config,
|
|
2009
2009
|
};
|
|
2010
2010
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2011
|
+
// Short-circuit on cancellation BEFORE starting a fresh attempt so
|
|
2012
|
+
// the caller does not pay the cost of issuing a request whose result
|
|
2013
|
+
// they have already discarded.
|
|
2014
|
+
if (signal?.aborted) {
|
|
2015
|
+
throw signal.reason instanceof Error
|
|
2016
|
+
? signal.reason
|
|
2017
|
+
: new Error('Aborted');
|
|
2018
|
+
}
|
|
2011
2019
|
try {
|
|
2012
2020
|
// If a circuit breaker is provided, execute through it
|
|
2013
2021
|
const result = circuitBreaker
|
|
@@ -2020,6 +2028,13 @@ async function withRetry(fn, config = {}, label = 'unknown') {
|
|
|
2020
2028
|
if (error instanceof CircuitBreakerOpenError) {
|
|
2021
2029
|
throw error;
|
|
2022
2030
|
}
|
|
2031
|
+
// Do not retry on cooperative cancellation — the caller has
|
|
2032
|
+
// explicitly asked us to stop.
|
|
2033
|
+
if (signal?.aborted) {
|
|
2034
|
+
throw signal.reason instanceof Error
|
|
2035
|
+
? signal.reason
|
|
2036
|
+
: new Error('Aborted');
|
|
2037
|
+
}
|
|
2023
2038
|
// Don't retry if we've exhausted all attempts
|
|
2024
2039
|
if (attempt === maxRetries) {
|
|
2025
2040
|
throw error;
|
|
@@ -2033,7 +2048,26 @@ async function withRetry(fn, config = {}, label = 'unknown') {
|
|
|
2033
2048
|
const jitter = Math.random() * 1000;
|
|
2034
2049
|
const delay = Math.min(exponentialDelay + jitter, maxDelayMs);
|
|
2035
2050
|
getLumicLogger().warn(`[${label}] Attempt ${attempt + 1} failed, retrying in ${Math.round(delay)}ms`);
|
|
2036
|
-
|
|
2051
|
+
// Sleep but bail early if signal aborts mid-backoff.
|
|
2052
|
+
await new Promise((resolve, reject) => {
|
|
2053
|
+
const timer = setTimeout(() => {
|
|
2054
|
+
if (signal)
|
|
2055
|
+
signal.removeEventListener('abort', onAbort);
|
|
2056
|
+
resolve();
|
|
2057
|
+
}, delay);
|
|
2058
|
+
const onAbort = () => {
|
|
2059
|
+
clearTimeout(timer);
|
|
2060
|
+
reject(signal?.reason instanceof Error ? signal.reason : new Error('Aborted'));
|
|
2061
|
+
};
|
|
2062
|
+
if (signal) {
|
|
2063
|
+
if (signal.aborted) {
|
|
2064
|
+
clearTimeout(timer);
|
|
2065
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error('Aborted'));
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
2069
|
+
}
|
|
2070
|
+
});
|
|
2037
2071
|
}
|
|
2038
2072
|
}
|
|
2039
2073
|
// This should never be reached, but TypeScript needs it for type safety
|
|
@@ -2526,11 +2560,20 @@ async function createCompletion(content, responseFormat, options = DEFAULT_OPTIO
|
|
|
2526
2560
|
}
|
|
2527
2561
|
let completion;
|
|
2528
2562
|
try {
|
|
2529
|
-
completion = await withRetry(
|
|
2563
|
+
completion = await withRetry(
|
|
2564
|
+
// Pass the AbortSignal into the OpenAI SDK request-options object.
|
|
2565
|
+
// The OpenAI SDK honours `signal` to cancel the in-flight fetch
|
|
2566
|
+
// immediately when it fires — this is what makes caller-driven
|
|
2567
|
+
// cancel-and-restart (e.g. signal-monitoring's materiality
|
|
2568
|
+
// re-trigger path in the engine) actually release the HTTP
|
|
2569
|
+
// connection and response-body buffer rather than just discarding
|
|
2570
|
+
// the resolved value at the engine boundary.
|
|
2571
|
+
() => openai.chat.completions.create(queryOptions, options.signal ? { signal: options.signal } : undefined), {
|
|
2530
2572
|
maxRetries: 3,
|
|
2531
2573
|
baseDelayMs: 2000,
|
|
2532
2574
|
maxDelayMs: 30000,
|
|
2533
2575
|
retryableErrors: isRetryableLLMError,
|
|
2576
|
+
signal: options.signal,
|
|
2534
2577
|
}, `OpenAI:${normalizedModel}`);
|
|
2535
2578
|
}
|
|
2536
2579
|
catch (error) {
|
|
@@ -2688,19 +2731,20 @@ const makeResponsesAPICall = async (input, options = {}) => {
|
|
|
2688
2731
|
apiKey: apiKey,
|
|
2689
2732
|
timeout: options.timeout ?? LLM_TIMEOUT_MS,
|
|
2690
2733
|
});
|
|
2691
|
-
// Remove apiKey, model, and
|
|
2692
|
-
const { apiKey: _, model: __, timeout: ___, ...cleanOptions } = options;
|
|
2734
|
+
// Remove apiKey, model, timeout, and signal from options before creating request body
|
|
2735
|
+
const { apiKey: _, model: __, timeout: ___, signal: ____, ...cleanOptions } = options;
|
|
2693
2736
|
const requestBody = {
|
|
2694
2737
|
model: normalizedModel,
|
|
2695
2738
|
input,
|
|
2696
2739
|
...cleanOptions,
|
|
2697
2740
|
};
|
|
2698
2741
|
// Make the API call to the Responses endpoint
|
|
2699
|
-
const response = await withRetry(() => openai.responses.create(requestBody), {
|
|
2742
|
+
const response = await withRetry(() => openai.responses.create(requestBody, options.signal ? { signal: options.signal } : undefined), {
|
|
2700
2743
|
maxRetries: 3,
|
|
2701
2744
|
baseDelayMs: 2000,
|
|
2702
2745
|
maxDelayMs: 30000,
|
|
2703
2746
|
retryableErrors: isRetryableLLMError,
|
|
2747
|
+
signal: options.signal,
|
|
2704
2748
|
}, `OpenAI-Responses:${normalizedModel}`);
|
|
2705
2749
|
// Responses API exposes cached input tokens under `input_tokens_details.cached_tokens`
|
|
2706
2750
|
// (the equivalent of Chat Completions' `prompt_tokens_details.cached_tokens`).
|
|
@@ -8273,23 +8317,32 @@ async function makeAnthropicCall(content, responseFormat = 'text', options = {})
|
|
|
8273
8317
|
if (systemParts.length > 0) {
|
|
8274
8318
|
requestParams.system = systemParts.join('\n\n');
|
|
8275
8319
|
}
|
|
8276
|
-
//
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8320
|
+
// Sampling controls are intentionally disabled for the Anthropic provider.
|
|
8321
|
+
//
|
|
8322
|
+
// The claude-*-4.x model family rejects any request that specifies BOTH
|
|
8323
|
+
// `temperature` and `top_p` ("`temperature` and `top_p` cannot both be
|
|
8324
|
+
// specified for this model. Please use only one." — HTTP 400), which aborts
|
|
8325
|
+
// the entire caller flow (e.g. the engine's account decision session).
|
|
8326
|
+
// Callers across the org pass both knobs generically, so rather than make
|
|
8327
|
+
// each one provider-aware we drop both here and let Anthropic use its model
|
|
8328
|
+
// defaults. `options.temperature` / `options.top_p` are intentionally not
|
|
8329
|
+
// forwarded. This is the Anthropic adapter only — the OpenAI, DeepSeek, and
|
|
8330
|
+
// OpenAI-compatible adapters still honor `temperature` and `top_p`.
|
|
8283
8331
|
// Translate and add tools if present
|
|
8284
8332
|
if (options.tools && options.tools.length > 0) {
|
|
8285
8333
|
requestParams.tools = translateToolsToAnthropic(options.tools);
|
|
8286
8334
|
}
|
|
8287
8335
|
try {
|
|
8288
|
-
const response = await withRetry(
|
|
8336
|
+
const response = await withRetry(
|
|
8337
|
+
// Pass AbortSignal into the Anthropic SDK request-options object
|
|
8338
|
+
// so caller-driven cancellation interrupts the in-flight HTTP
|
|
8339
|
+
// request immediately. See LLMOptions.signal JSDoc for context.
|
|
8340
|
+
() => client.messages.create(requestParams, options.signal ? { signal: options.signal } : undefined), {
|
|
8289
8341
|
maxRetries: 3,
|
|
8290
8342
|
baseDelayMs: 2000,
|
|
8291
8343
|
maxDelayMs: 30000,
|
|
8292
8344
|
retryableErrors: isRetryableAnthropicError,
|
|
8345
|
+
signal: options.signal,
|
|
8293
8346
|
}, `Anthropic:${model}`);
|
|
8294
8347
|
const inputTokens = response.usage.input_tokens;
|
|
8295
8348
|
const outputTokens = response.usage.output_tokens;
|
|
@@ -8482,11 +8535,16 @@ async function makeOpenAICompatibleCall(content, responseFormat = 'text', option
|
|
|
8482
8535
|
queryOptions.tools = options.tools;
|
|
8483
8536
|
}
|
|
8484
8537
|
try {
|
|
8485
|
-
const completion = await withRetry(
|
|
8538
|
+
const completion = await withRetry(
|
|
8539
|
+
// Pass AbortSignal into the SDK request-options object so
|
|
8540
|
+
// caller-driven cancellation interrupts the in-flight HTTP
|
|
8541
|
+
// request immediately. See LLMOptions.signal JSDoc for context.
|
|
8542
|
+
() => openai.chat.completions.create(queryOptions, options.signal ? { signal: options.signal } : undefined), {
|
|
8486
8543
|
maxRetries: 3,
|
|
8487
8544
|
baseDelayMs: 2000,
|
|
8488
8545
|
maxDelayMs: 30000,
|
|
8489
8546
|
retryableErrors: isRetryableError,
|
|
8547
|
+
signal: options.signal,
|
|
8490
8548
|
}, `${providerConfig.name}:${model}`);
|
|
8491
8549
|
const promptTokens = completion.usage?.prompt_tokens || 0;
|
|
8492
8550
|
const completionTokens = completion.usage?.completion_tokens || 0;
|
|
@@ -23017,11 +23075,11 @@ let poolConfig = DEFAULT_POOL_CONFIG;
|
|
|
23017
23075
|
async function loadApolloModules() {
|
|
23018
23076
|
if (typeof window === "undefined" || process.env.AWS_EXECUTION_ENV) {
|
|
23019
23077
|
// Server-side (or Lambda): load the CommonJS‑based implementation.
|
|
23020
|
-
return (await Promise.resolve().then(function () { return require('./apollo-client.server-
|
|
23078
|
+
return (await Promise.resolve().then(function () { return require('./apollo-client.server-Cx30LaNh.js'); }));
|
|
23021
23079
|
}
|
|
23022
23080
|
else {
|
|
23023
23081
|
// Client-side: load the ESM‑based implementation.
|
|
23024
|
-
return (await Promise.resolve().then(function () { return require('./apollo-client.client-
|
|
23082
|
+
return (await Promise.resolve().then(function () { return require('./apollo-client.client-D6jG5B1n.js'); }));
|
|
23025
23083
|
}
|
|
23026
23084
|
}
|
|
23027
23085
|
/**
|
|
@@ -81732,4 +81790,4 @@ exports.withCorrelationId = withCorrelationId;
|
|
|
81732
81790
|
exports.withMetrics = withMetrics;
|
|
81733
81791
|
exports.withRateLimit = withRateLimit;
|
|
81734
81792
|
exports.withRetry = withRetry;
|
|
81735
|
-
//# sourceMappingURL=index-
|
|
81793
|
+
//# sourceMappingURL=index-ChygDqeG.js.map
|