@adaptic/lumic-utils 1.0.19 → 1.0.20

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 (22) hide show
  1. package/dist/{apollo-client.client-Dfi-rHW-.js → apollo-client.client-DRk6kygw.js} +4 -4
  2. package/dist/{apollo-client.client-Dfi-rHW-.js.map → apollo-client.client-DRk6kygw.js.map} +1 -1
  3. package/dist/{apollo-client.client-guxMwplM.js → apollo-client.client-DVsbR05r.js} +3 -3
  4. package/dist/{apollo-client.client-guxMwplM.js.map → apollo-client.client-DVsbR05r.js.map} +1 -1
  5. package/dist/{apollo-client.server-HwHIFnVk.js → apollo-client.server-Djh4v__C.js} +3 -3
  6. package/dist/{apollo-client.server-HwHIFnVk.js.map → apollo-client.server-Djh4v__C.js.map} +1 -1
  7. package/dist/{apollo-client.server-Blxbp1Gf.js → apollo-client.server-L8JR2ko_.js} +3 -3
  8. package/dist/{apollo-client.server-Blxbp1Gf.js.map → apollo-client.server-L8JR2ko_.js.map} +1 -1
  9. package/dist/{index-Dr85zRZC.js → index-BVl0tRmx.js} +54 -29
  10. package/dist/{index-Dr85zRZC.js.map → index-BVl0tRmx.js.map} +1 -1
  11. package/dist/{index-CSQmloZ-.js → index-CSOg0U0R.js} +54 -29
  12. package/dist/{index-CSQmloZ-.js.map → index-CSOg0U0R.js.map} +1 -1
  13. package/dist/{index-DollRUHQ.js → index-Cs56Fq24.js} +2 -2
  14. package/dist/{index-DollRUHQ.js.map → index-Cs56Fq24.js.map} +1 -1
  15. package/dist/{index-B4tfLvHx.js → index-eU6Q74W8.js} +2 -2
  16. package/dist/{index-B4tfLvHx.js.map → index-eU6Q74W8.js.map} +1 -1
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.mjs +1 -1
  19. package/dist/test.cjs +1 -1
  20. package/dist/test.mjs +1 -1
  21. package/dist/types/types/openai-types.d.ts +8 -1
  22. package/package.json +1 -1
@@ -2354,14 +2354,20 @@ async function createCompletion(content, responseFormat, options = DEFAULT_OPTIO
2354
2354
  });
2355
2355
  throw error;
2356
2356
  }
2357
+ // OpenAI returns cached input tokens under `prompt_tokens_details.cached_tokens`
2358
+ // when prompts >1024 tokens hit the automatic prompt cache. We surface this
2359
+ // as a first-class field so cost tracking and dashboards reflect the real
2360
+ // (discounted) input cost rather than billing every input token at full rate.
2361
+ const cachedTokens = completion.usage?.prompt_tokens_details?.cached_tokens ?? 0;
2357
2362
  const response = {
2358
2363
  id: completion.id,
2359
2364
  content: completion.choices[0]?.message?.content || '',
2360
2365
  tool_calls: completion.choices[0]?.message?.tool_calls,
2361
- usage: completion.usage || {
2362
- prompt_tokens: 0,
2363
- completion_tokens: 0,
2364
- total_tokens: 0,
2366
+ usage: {
2367
+ prompt_tokens: completion.usage?.prompt_tokens ?? 0,
2368
+ completion_tokens: completion.usage?.completion_tokens ?? 0,
2369
+ total_tokens: completion.usage?.total_tokens ?? 0,
2370
+ cached_tokens: cachedTokens,
2365
2371
  },
2366
2372
  system_fingerprint: completion.system_fingerprint,
2367
2373
  service_tier: options.service_tier,
@@ -2384,8 +2390,10 @@ const makeOpenAIChatCompletionCall = async (content, responseFormat = 'text', op
2384
2390
  ...options,
2385
2391
  };
2386
2392
  const completion = await createCompletion(content, responseFormat, mergedOptions);
2387
- // Track cost in the global cost tracker
2388
- getLLMCostTracker().trackUsage('openai', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens);
2393
+ // Track cost in the global cost tracker. Pass cached tokens through so the
2394
+ // tracker applies the discounted cached-input rate (typically ~50% of the
2395
+ // standard input rate) instead of billing every input token at full price.
2396
+ getLLMCostTracker().trackUsage('openai', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, completion.usage.cached_tokens);
2389
2397
  // Handle tool calls differently
2390
2398
  if (completion.tool_calls && completion.tool_calls.length > 0) {
2391
2399
  const toolCallResponse = {
@@ -2403,7 +2411,8 @@ const makeOpenAIChatCompletionCall = async (content, responseFormat = 'text', op
2403
2411
  reasoning_tokens: 0,
2404
2412
  provider: 'openai',
2405
2413
  model: completion.model,
2406
- cost: calculateCost('openai', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0),
2414
+ cached_tokens: completion.usage.cached_tokens,
2415
+ cost: calculateCost('openai', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, completion.usage.cached_tokens),
2407
2416
  },
2408
2417
  tool_calls: completion.tool_calls,
2409
2418
  };
@@ -2421,7 +2430,8 @@ const makeOpenAIChatCompletionCall = async (content, responseFormat = 'text', op
2421
2430
  reasoning_tokens: 0,
2422
2431
  provider: 'openai',
2423
2432
  model: completion.model,
2424
- cost: calculateCost('openai', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0),
2433
+ cached_tokens: completion.usage.cached_tokens,
2434
+ cost: calculateCost('openai', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, completion.usage.cached_tokens),
2425
2435
  },
2426
2436
  tool_calls: completion.tool_calls,
2427
2437
  };
@@ -2476,8 +2486,11 @@ const makeResponsesAPICall = async (input, options = {}) => {
2476
2486
  maxDelayMs: 30000,
2477
2487
  retryableErrors: isRetryableLLMError,
2478
2488
  }, `OpenAI-Responses:${normalizedModel}`);
2489
+ // Responses API exposes cached input tokens under `input_tokens_details.cached_tokens`
2490
+ // (the equivalent of Chat Completions' `prompt_tokens_details.cached_tokens`).
2491
+ const responsesCachedTokens = response.usage?.input_tokens_details?.cached_tokens || 0;
2479
2492
  // Track cost in the global cost tracker
2480
- getLLMCostTracker().trackUsage('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0);
2493
+ getLLMCostTracker().trackUsage('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0, responsesCachedTokens);
2481
2494
  // Extract tool calls from the output
2482
2495
  const toolCalls = response.output
2483
2496
  ?.filter((item) => item.type === 'function_call')
@@ -2518,7 +2531,8 @@ const makeResponsesAPICall = async (input, options = {}) => {
2518
2531
  reasoning_tokens: response.usage?.output_tokens_details?.reasoning_tokens || 0,
2519
2532
  provider: 'openai',
2520
2533
  model: normalizedModel,
2521
- cost: calculateCost('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0),
2534
+ cached_tokens: responsesCachedTokens,
2535
+ cost: calculateCost('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0, responsesCachedTokens),
2522
2536
  },
2523
2537
  tool_calls: toolCalls,
2524
2538
  ...(codeInterpreterOutputs ? { code_interpreter_outputs: codeInterpreterOutputs } : {}),
@@ -2550,7 +2564,8 @@ const makeResponsesAPICall = async (input, options = {}) => {
2550
2564
  reasoning_tokens: response.usage?.output_tokens_details?.reasoning_tokens || 0,
2551
2565
  provider: 'openai',
2552
2566
  model: normalizedModel,
2553
- cost: calculateCost('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0),
2567
+ cached_tokens: responsesCachedTokens,
2568
+ cost: calculateCost('openai', normalizedModel, response.usage?.input_tokens || 0, response.usage?.output_tokens || 0, response.usage?.output_tokens_details?.reasoning_tokens || 0, responsesCachedTokens),
2554
2569
  },
2555
2570
  tool_calls: toolCalls,
2556
2571
  ...(codeInterpreterOutputs ? { code_interpreter_outputs: codeInterpreterOutputs } : {}),
@@ -8742,14 +8757,25 @@ async function createDeepseekCompletion(content, responseFormat, options = {}) {
8742
8757
  maxDelayMs: 30000,
8743
8758
  retryableErrors: isRetryableDeepseekError,
8744
8759
  }, `Deepseek:${normalizedModel}`);
8760
+ // DeepSeek surfaces cached input tokens in two places on the usage object:
8761
+ // - `prompt_cache_hit_tokens` (DeepSeek-native field, see
8762
+ // https://api-docs.deepseek.com/guides/kv_cache)
8763
+ // - `prompt_tokens_details.cached_tokens` (OpenAI-compatible alias)
8764
+ // Prefer the OpenAI-compatible name so a single canonical field works for
8765
+ // both providers; fall back to the DeepSeek-native name if absent.
8766
+ const usageRaw = completion.usage;
8767
+ const cachedTokens = usageRaw?.prompt_tokens_details?.cached_tokens ??
8768
+ usageRaw?.prompt_cache_hit_tokens ??
8769
+ 0;
8745
8770
  return {
8746
8771
  id: completion.id,
8747
8772
  content: completion.choices[0]?.message?.content || '',
8748
8773
  tool_calls: completion.choices[0]?.message?.tool_calls,
8749
- usage: completion.usage || {
8750
- prompt_tokens: 0,
8751
- completion_tokens: 0,
8752
- total_tokens: 0,
8774
+ usage: {
8775
+ prompt_tokens: completion.usage?.prompt_tokens ?? 0,
8776
+ completion_tokens: completion.usage?.completion_tokens ?? 0,
8777
+ total_tokens: completion.usage?.total_tokens ?? 0,
8778
+ cached_tokens: cachedTokens,
8753
8779
  },
8754
8780
  system_fingerprint: completion.system_fingerprint,
8755
8781
  provider: 'deepseek',
@@ -8791,7 +8817,7 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
8791
8817
  reasoning_tokens: 0,
8792
8818
  provider: 'deepseek',
8793
8819
  model: modelName,
8794
- cache_hit_tokens: 0,
8820
+ cached_tokens: 0,
8795
8821
  cost: 0,
8796
8822
  },
8797
8823
  tool_calls: undefined,
@@ -8810,7 +8836,7 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
8810
8836
  reasoning_tokens: 0,
8811
8837
  provider: 'deepseek',
8812
8838
  model: modelName,
8813
- cache_hit_tokens: 0,
8839
+ cached_tokens: 0,
8814
8840
  cost: 0,
8815
8841
  },
8816
8842
  tool_calls: undefined,
@@ -8818,8 +8844,9 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
8818
8844
  }
8819
8845
  try {
8820
8846
  const completion = await createDeepseekCompletion(content, responseFormat, mergedOptions);
8821
- // Track cost in the global cost tracker
8822
- getLLMCostTracker().trackUsage('deepseek', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens);
8847
+ // Track cost in the global cost tracker. Pass cached tokens through so the
8848
+ // discounted cached-input pricing tier is applied.
8849
+ getLLMCostTracker().trackUsage('deepseek', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, completion.usage.cached_tokens);
8823
8850
  // Handle tool calls similarly to OpenAI
8824
8851
  if (completion.tool_calls && completion.tool_calls.length > 0) {
8825
8852
  const toolCallResponse = {
@@ -8837,9 +8864,8 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
8837
8864
  reasoning_tokens: 0, // Deepseek doesn't provide reasoning tokens separately
8838
8865
  provider: 'deepseek',
8839
8866
  model: completion.model,
8840
- cache_hit_tokens: 0, // Not provided directly in API response
8841
- cost: calculateCost('deepseek', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, 0 // Cache hit tokens (not provided in the response)
8842
- ),
8867
+ cached_tokens: completion.usage.cached_tokens,
8868
+ cost: calculateCost('deepseek', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, completion.usage.cached_tokens),
8843
8869
  },
8844
8870
  tool_calls: completion.tool_calls,
8845
8871
  };
@@ -8857,9 +8883,8 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
8857
8883
  reasoning_tokens: 0, // Deepseek doesn't provide reasoning tokens separately
8858
8884
  provider: 'deepseek',
8859
8885
  model: completion.model,
8860
- cache_hit_tokens: 0, // Not provided directly in API response
8861
- cost: calculateCost('deepseek', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, 0 // Cache hit tokens (not provided in the response)
8862
- ),
8886
+ cached_tokens: completion.usage.cached_tokens,
8887
+ cost: calculateCost('deepseek', completion.model, completion.usage.prompt_tokens, completion.usage.completion_tokens, 0, completion.usage.cached_tokens),
8863
8888
  },
8864
8889
  tool_calls: completion.tool_calls,
8865
8890
  };
@@ -8877,7 +8902,7 @@ const makeDeepseekCall = async (content, responseFormat = 'json', options = {})
8877
8902
  reasoning_tokens: 0,
8878
8903
  provider: 'deepseek',
8879
8904
  model: modelName,
8880
- cache_hit_tokens: 0,
8905
+ cached_tokens: 0,
8881
8906
  cost: 0,
8882
8907
  },
8883
8908
  tool_calls: undefined,
@@ -22776,11 +22801,11 @@ let poolConfig = DEFAULT_POOL_CONFIG;
22776
22801
  async function loadApolloModules() {
22777
22802
  if (typeof window === "undefined" || process.env.AWS_EXECUTION_ENV) {
22778
22803
  // Server-side (or Lambda): load the CommonJS‑based implementation.
22779
- return (await import('./apollo-client.server-Blxbp1Gf.js'));
22804
+ return (await import('./apollo-client.server-L8JR2ko_.js'));
22780
22805
  }
22781
22806
  else {
22782
22807
  // Client-side: load the ESM‑based implementation.
22783
- return (await import('./apollo-client.client-Dfi-rHW-.js'));
22808
+ return (await import('./apollo-client.client-DRk6kygw.js'));
22784
22809
  }
22785
22810
  }
22786
22811
  /**
@@ -81304,4 +81329,4 @@ const lumic = {
81304
81329
  };
81305
81330
 
81306
81331
  export { GraphQLInterfaceType as $, print as A, getNamedType as B, isInputType as C, isRequiredArgument as D, isNamedType as E, GraphQLError as F, GraphQLNonNull as G, isOutputType as H, isRequiredInputField as I, isCompositeType as J, Kind as K, getNullableType as L, getEnterLeaveForKind as M, isNode as N, OperationTypeNode as O, didYouMean as P, naturalCompare as Q, suggestionList as R, specifiedScalarTypes as S, keyMap as T, isType as U, isNullableType as V, visit as W, visitInParallel as X, keyValMap as Y, assertObjectType as Z, GraphQLScalarType as _, isListType as a, validateGoogleSheetsRange as a$, GraphQLUnionType as a0, GraphQLInputObjectType as a1, assertNullableType as a2, assertInterfaceType as a3, mapValue as a4, isSpecifiedScalarType as a5, isPrintableAsBlockString as a6, printBlockString as a7, BREAK as a8, GRAPHQL_MAX_INT as a9, printSourceLocation as aA, resolveObjMapThunk as aB, resolveReadonlyArrayThunk as aC, valueFromASTUntyped as aD, version$4 as aE, versionInfo as aF, getAugmentedNamespace as aG, isDigit$1 as aH, isNameStart as aI, dedentBlockStringLines as aJ, isNameContinue as aK, setLumicLogger as aL, getLumicLogger as aM, sanitizeForLog as aN, sanitizeError as aO, sanitizeAWSAuth as aP, sanitizeObject as aQ, getSecrets as aR, resetSecrets as aS, requireSecret as aT, withRetry as aU, CircuitBreaker as aV, CircuitBreakerState as aW, CircuitBreakerOpenError as aX, DEFAULT_CIRCUIT_BREAKER_CONFIG as aY, validateSlackChannel as aZ, validateS3Key as a_, GRAPHQL_MIN_INT as aa, GraphQLFloat as ab, GraphQLInt as ac, Location as ad, Token as ae, assertAbstractType as af, assertCompositeType as ag, assertEnumType as ah, assertEnumValueName as ai, assertInputObjectType as aj, assertInputType as ak, assertLeafType as al, assertListType as am, assertNamedType as an, assertNonNullType as ao, assertOutputType as ap, assertScalarType as aq, assertType as ar, assertUnionType as as, assertWrappingType as at, formatError as au, getLocation as av, getVisitFn as aw, isWrappingType as ax, printError as ay, printLocation as az, isAbstractType as b, PDFError as b$, LLMCostTracker as b0, getLLMCostTracker as b1, setLLMCostTracker as b2, resetLLMCostTracker as b3, setMetricsCollector as b4, getMetricsCollector as b5, resetMetricsCollector as b6, withMetrics as b7, generateCorrelationId as b8, getCorrelationId as b9, openAIChatCompletionSchema as bA, openAIImageResponseSchema as bB, validateOpenAIChatCompletion as bC, safeValidateOpenAIChatCompletion as bD, perplexityResponseSchema as bE, validatePerplexityResponse as bF, safeValidatePerplexityResponse as bG, googleSheetsValueRangeSchema as bH, validateGoogleSheetsResponse as bI, safeValidateGoogleSheetsResponse as bJ, s3ListObjectsSchema as bK, s3GetObjectSchema as bL, lambdaInvokeResponseSchema as bM, validateS3ListObjects as bN, safeValidateS3ListObjects as bO, validateLambdaResponse as bP, safeValidateLambdaResponse as bQ, createValidator as bR, createSafeValidator as bS, LumicError as bT, SlackError as bU, LLMError as bV, AWSLambdaError as bW, AWSS3Error as bX, GoogleSheetsError as bY, PerplexityError as bZ, JsonParseError as b_, getCorrelationContext as ba, withCorrelationId as bb, getCorrelationHeaders as bc, TokenBucketRateLimiter as bd, RATE_LIMIT_PROFILES as be, getRateLimiter as bf, resetAllRateLimiters as bg, withRateLimit as bh, checkIntegrationHealth as bi, SUPPORTED_MODELS as bj, isValidModel as bk, getModelCapabilities as bl, getModelProvider as bm, MODEL_ALIASES as bn, OPENAI_COMPATIBLE_PROVIDERS as bo, PROVIDER_DEFAULT_MODELS as bp, LLM_DEFAULT_PROVIDER as bq, LLM_MINI_PROVIDER as br, LLM_NORMAL_PROVIDER as bs, LLM_ADVANCED_PROVIDER as bt, LLM_PROVIDER as bu, LLM_MODEL_MINI as bv, LLM_MODEL_NORMAL as bw, LLM_MODEL_ADVANCED as bx, makeAnthropicCall as by, makeOpenAICompatibleCall as bz, isInterfaceType as c, ZipError as c0, SLACK_TIMEOUT_MS as c1, PERPLEXITY_TIMEOUT_MS as c2, GOOGLE_SHEETS_TIMEOUT_MS as c3, LLM_TIMEOUT_MS as c4, AWS_LAMBDA_TIMEOUT_MS as c5, AWS_S3_TIMEOUT_MS as c6, OPENWEATHER_TIMEOUT_MS as c7, GENERIC_FETCH_TIMEOUT_MS as c8, isObjectType as d, assertName as e, devAssert as f, isObjectLike as g, defineArguments as h, isNonNullType as i, argsToArgsConfig as j, GraphQLBoolean as k, lumic as l, GraphQLString as m, instanceOf as n, inspect as o, isInputObjectType as p, isLeafType as q, isEnumType as r, GraphQLID as s, toObjMap as t, invariant as u, GraphQLObjectType as v, GraphQLEnumType as w, GraphQLList as x, isScalarType as y, isUnionType as z };
81307
- //# sourceMappingURL=index-CSQmloZ-.js.map
81332
+ //# sourceMappingURL=index-CSOg0U0R.js.map