librechat-data-provider 0.8.504 → 0.8.506

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/index.js CHANGED
@@ -1,57 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_data_service = require("./data-service-Dk-uLruo.js");
2
+ const require_data_service = require("./data-service-CCdWvcRd.js");
3
3
  let zod = require("zod");
4
4
  let dayjs = require("dayjs");
5
5
  dayjs = require_data_service.__toESM(dayjs);
6
+ let dayjs_plugin_utc = require("dayjs/plugin/utc");
7
+ dayjs_plugin_utc = require_data_service.__toESM(dayjs_plugin_utc);
8
+ let dayjs_plugin_timezone = require("dayjs/plugin/timezone");
9
+ dayjs_plugin_timezone = require_data_service.__toESM(dayjs_plugin_timezone);
6
10
  let axios = require("axios");
7
11
  axios = require_data_service.__toESM(axios);
8
12
  let url = require("url");
9
13
  let crypto = require("crypto");
10
14
  crypto = require_data_service.__toESM(crypto);
11
15
  let js_yaml = require("js-yaml");
12
- //#region src/types/runs.ts
13
- let ContentTypes = /* @__PURE__ */ function(ContentTypes) {
14
- ContentTypes["TEXT"] = "text";
15
- ContentTypes["THINK"] = "think";
16
- ContentTypes["TEXT_DELTA"] = "text_delta";
17
- ContentTypes["TOOL_CALL"] = "tool_call";
18
- ContentTypes["IMAGE_FILE"] = "image_file";
19
- ContentTypes["IMAGE_URL"] = "image_url";
20
- ContentTypes["VIDEO_URL"] = "video_url";
21
- ContentTypes["INPUT_AUDIO"] = "input_audio";
22
- ContentTypes["AGENT_UPDATE"] = "agent_update";
23
- ContentTypes["SUMMARY"] = "summary";
24
- ContentTypes["ERROR"] = "error";
25
- return ContentTypes;
26
- }({});
27
- let StepTypes = /* @__PURE__ */ function(StepTypes) {
28
- StepTypes["TOOL_CALLS"] = "tool_calls";
29
- StepTypes["MESSAGE_CREATION"] = "message_creation";
30
- return StepTypes;
31
- }({});
32
- let ToolCallTypes = /* @__PURE__ */ function(ToolCallTypes) {
33
- ToolCallTypes["FUNCTION"] = "function";
34
- ToolCallTypes["RETRIEVAL"] = "retrieval";
35
- ToolCallTypes["FILE_SEARCH"] = "file_search";
36
- ToolCallTypes["CODE_INTERPRETER"] = "code_interpreter";
37
- ToolCallTypes["TOOL_CALL"] = "tool_call";
38
- return ToolCallTypes;
39
- }({});
40
- /** Event names dispatched by the agent graph and consumed by step handlers. */
41
- let StepEvents = /* @__PURE__ */ function(StepEvents) {
42
- StepEvents["ON_RUN_STEP"] = "on_run_step";
43
- StepEvents["ON_AGENT_UPDATE"] = "on_agent_update";
44
- StepEvents["ON_MESSAGE_DELTA"] = "on_message_delta";
45
- StepEvents["ON_REASONING_DELTA"] = "on_reasoning_delta";
46
- StepEvents["ON_RUN_STEP_DELTA"] = "on_run_step_delta";
47
- StepEvents["ON_RUN_STEP_COMPLETED"] = "on_run_step_completed";
48
- StepEvents["ON_SUMMARIZE_START"] = "on_summarize_start";
49
- StepEvents["ON_SUMMARIZE_DELTA"] = "on_summarize_delta";
50
- StepEvents["ON_SUMMARIZE_COMPLETE"] = "on_summarize_complete";
51
- StepEvents["ON_SUBAGENT_UPDATE"] = "on_subagent_update";
52
- return StepEvents;
53
- }({});
54
- //#endregion
55
16
  //#region src/bedrock.ts
56
17
  const DEFAULT_ENABLED_MAX_TOKENS = 8192;
57
18
  const DEFAULT_THINKING_BUDGET = 2e3;
@@ -211,6 +172,7 @@ const bedrockInputSchema = require_data_service.tConversationSchema.pick({
211
172
  thinkingDisplay: true,
212
173
  reasoning_effort: true,
213
174
  promptCache: true,
175
+ promptCacheTtl: true,
214
176
  topK: true,
215
177
  additionalModelRequestFields: true
216
178
  }).transform((obj) => {
@@ -249,6 +211,7 @@ const bedrockInputParser = require_data_service.tConversationSchema.pick({
249
211
  thinkingDisplay: true,
250
212
  reasoning_effort: true,
251
213
  promptCache: true,
214
+ promptCacheTtl: true,
252
215
  topK: true,
253
216
  additionalModelRequestFields: true
254
217
  }).catchall(zod.z.any()).transform((data) => {
@@ -269,7 +232,8 @@ const bedrockInputParser = require_data_service.tConversationSchema.pick({
269
232
  "temperature",
270
233
  "topP",
271
234
  "stop",
272
- "promptCache"
235
+ "promptCache",
236
+ "promptCacheTtl"
273
237
  ];
274
238
  const additionalFields = {};
275
239
  const typedData = data;
@@ -375,6 +339,12 @@ const bedrockInputParser = require_data_service.tConversationSchema.pick({
375
339
  if (typeof typedData.model === "string" && (typedData.model.includes("claude") || typedData.model.includes("nova"))) {
376
340
  if (typedData.promptCache === void 0) typedData.promptCache = true;
377
341
  } else if (typedData.promptCache === true) typedData.promptCache = void 0;
342
+ /**
343
+ * A cache TTL is meaningless without caching — tie it to promptCache. When
344
+ * caching is off or unsupported for the model (cleared above), drop the TTL
345
+ * so an unsupported `1h` is never sent on a non-caching Bedrock request.
346
+ */
347
+ if (typedData.promptCache !== true) typedData.promptCacheTtl = void 0;
378
348
  if (Object.keys(additionalFields).length > 0) typedData.additionalModelRequestFields = {
379
349
  ...typedData.additionalModelRequestFields || {},
380
350
  ...additionalFields
@@ -432,7 +402,100 @@ const bedrockOutputParser = (data) => {
432
402
  return result;
433
403
  };
434
404
  //#endregion
405
+ //#region src/types/runs.ts
406
+ let ContentTypes = /* @__PURE__ */ function(ContentTypes) {
407
+ ContentTypes["TEXT"] = "text";
408
+ ContentTypes["THINK"] = "think";
409
+ ContentTypes["TEXT_DELTA"] = "text_delta";
410
+ ContentTypes["TOOL_CALL"] = "tool_call";
411
+ ContentTypes["IMAGE_FILE"] = "image_file";
412
+ ContentTypes["IMAGE_URL"] = "image_url";
413
+ ContentTypes["VIDEO_URL"] = "video_url";
414
+ ContentTypes["INPUT_AUDIO"] = "input_audio";
415
+ ContentTypes["AGENT_UPDATE"] = "agent_update";
416
+ ContentTypes["SUMMARY"] = "summary";
417
+ ContentTypes["ERROR"] = "error";
418
+ return ContentTypes;
419
+ }({});
420
+ let StepTypes = /* @__PURE__ */ function(StepTypes) {
421
+ StepTypes["TOOL_CALLS"] = "tool_calls";
422
+ StepTypes["MESSAGE_CREATION"] = "message_creation";
423
+ return StepTypes;
424
+ }({});
425
+ let ToolCallTypes = /* @__PURE__ */ function(ToolCallTypes) {
426
+ ToolCallTypes["FUNCTION"] = "function";
427
+ ToolCallTypes["RETRIEVAL"] = "retrieval";
428
+ ToolCallTypes["FILE_SEARCH"] = "file_search";
429
+ ToolCallTypes["CODE_INTERPRETER"] = "code_interpreter";
430
+ ToolCallTypes["TOOL_CALL"] = "tool_call";
431
+ return ToolCallTypes;
432
+ }({});
433
+ /** Event names dispatched by the agent graph and consumed by step handlers. */
434
+ let StepEvents = /* @__PURE__ */ function(StepEvents) {
435
+ StepEvents["ON_RUN_STEP"] = "on_run_step";
436
+ StepEvents["ON_AGENT_UPDATE"] = "on_agent_update";
437
+ StepEvents["ON_MESSAGE_DELTA"] = "on_message_delta";
438
+ StepEvents["ON_REASONING_DELTA"] = "on_reasoning_delta";
439
+ StepEvents["ON_RUN_STEP_DELTA"] = "on_run_step_delta";
440
+ StepEvents["ON_RUN_STEP_COMPLETED"] = "on_run_step_completed";
441
+ StepEvents["ON_SUMMARIZE_START"] = "on_summarize_start";
442
+ StepEvents["ON_SUMMARIZE_DELTA"] = "on_summarize_delta";
443
+ StepEvents["ON_SUMMARIZE_COMPLETE"] = "on_summarize_complete";
444
+ StepEvents["ON_SUBAGENT_UPDATE"] = "on_subagent_update";
445
+ return StepEvents;
446
+ }({});
447
+ /** Token-tracking event names streamed to the client (separate from StepEvents dispatch). */
448
+ let UsageEvents = /* @__PURE__ */ function(UsageEvents) {
449
+ UsageEvents["ON_CONTEXT_USAGE"] = "on_context_usage";
450
+ UsageEvents["ON_TOKEN_USAGE"] = "on_token_usage";
451
+ return UsageEvents;
452
+ }({});
453
+ /**
454
+ * Full prompt token count for one completed model call — the EXACT context the
455
+ * model saw, provider-aware: additive providers (Bedrock) report `input_tokens`
456
+ * excluding cache, so cache reads/writes are added back; subset providers
457
+ * (Anthropic, OpenAI, …) already fold cache into `input_tokens`. When the
458
+ * provider is absent (custom/OpenAI-compatible payloads), fall back to the same
459
+ * magnitude heuristic `normalizeUsageUnits` uses — cache ≤ input means it's
460
+ * already included — so cached events aren't re-inflated. The ground truth the
461
+ * gauge reconciles its calibrated estimate to.
462
+ */
463
+ const promptTokensFromUsage = (event) => {
464
+ const input = event.input_tokens ?? 0;
465
+ const details = event.input_token_details ?? {};
466
+ const cacheRead = details.cache_read ?? 0;
467
+ const cacheCreation = details.cache_creation ?? 0;
468
+ return (event.provider != null ? require_data_service.inputTokensIncludesCache(event.provider) : cacheRead + cacheCreation <= input) ? input : input + cacheRead + cacheCreation;
469
+ };
470
+ /**
471
+ * Reconciles a pre-invoke context snapshot's CALIBRATED estimate to a call's
472
+ * ACTUAL prompt tokens. The SDK's calibration multiplier scales only
473
+ * `messageTokens` (instructions/summary are raw tiktoken counts), and it can
474
+ * over-shoot badly when a provider injects server-side content the SDK never
475
+ * counted (e.g. Anthropic web search) — pinning the gauge several× too high and
476
+ * persisting it. Trust the provider's own prompt count: keep the raw
477
+ * instruction/summary rows, set `messageTokens` to the remainder, and recompute
478
+ * the free space. No-op when `promptTokens` is unusable.
479
+ */
480
+ const reconcileContextUsage = (snapshot, promptTokens) => {
481
+ if (!Number.isFinite(promptTokens) || promptTokens <= 0) return snapshot;
482
+ const { breakdown } = snapshot;
483
+ const budget = snapshot.contextBudget ?? breakdown.maxContextTokens;
484
+ const nonMessageTokens = (breakdown.instructionTokens ?? 0) + (breakdown.summaryTokens ?? 0);
485
+ const messageTokens = Math.max(0, promptTokens - nonMessageTokens);
486
+ return {
487
+ ...snapshot,
488
+ breakdown: {
489
+ ...breakdown,
490
+ messageTokens
491
+ },
492
+ remainingContextTokens: budget != null ? Math.max(0, budget - promptTokens) : snapshot.remainingContextTokens
493
+ };
494
+ };
495
+ //#endregion
435
496
  //#region src/parsers.ts
497
+ dayjs.default.extend(dayjs_plugin_utc.default);
498
+ dayjs.default.extend(dayjs_plugin_timezone.default);
436
499
  const endpointSchemas = {
437
500
  ["openAI"]: require_data_service.openAISchema,
438
501
  ["azureOpenAI"]: require_data_service.openAISchema,
@@ -631,10 +694,24 @@ function findLastSeparatorIndex(text, separators = SEPARATORS) {
631
694
  }
632
695
  return lastIndex;
633
696
  }
634
- function replaceSpecialVars({ text, user, now: inputNow }) {
697
+ /**
698
+ * Anchors a dayjs instant to the user's IANA timezone when one is supplied,
699
+ * so local-time special vars reflect the user's wall clock rather than the
700
+ * server's. Falls back to the original instant for missing or invalid zones.
701
+ */
702
+ function applyTimezone(value, timezone) {
703
+ if (!timezone) return value;
704
+ try {
705
+ const zoned = value.tz(timezone);
706
+ return zoned.isValid() ? zoned : value;
707
+ } catch {
708
+ return value;
709
+ }
710
+ }
711
+ function replaceSpecialVars({ text, user, now: inputNow, timezone }) {
635
712
  let result = text;
636
713
  if (!result) return result;
637
- const now = inputNow != null ? (0, dayjs.default)(inputNow) : (0, dayjs.default)();
714
+ const now = applyTimezone(inputNow != null ? (0, dayjs.default)(inputNow) : (0, dayjs.default)(), timezone);
638
715
  const weekdayName = now.format("dddd");
639
716
  const currentDate = now.format("YYYY-MM-DD");
640
717
  result = result.replace(/{{\s*current_date\s*}}/gi, `${currentDate} (${weekdayName})`);
@@ -4986,6 +5063,14 @@ function validateAndParseOpenAPISpec(specString) {
4986
5063
  }
4987
5064
  //#endregion
4988
5065
  //#region src/createPayload.ts
5066
+ /** Resolves the browser's IANA timezone so the server can localize prompt variables. */
5067
+ function getUserTimezone() {
5068
+ try {
5069
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
5070
+ } catch {
5071
+ return;
5072
+ }
5073
+ }
4989
5074
  function createPayload(submission) {
4990
5075
  const { isEdited, addedConvo, userMessage, isContinued, isTemporary, isRegenerate, conversation, editedContent, ephemeralAgent, endpointOption, manualSkills } = submission;
4991
5076
  const { conversationId } = require_data_service.tConvoUpdateSchema.parse(conversation);
@@ -5004,7 +5089,8 @@ function createPayload(submission) {
5004
5089
  conversationId,
5005
5090
  isContinued: !!(isEdited && isContinued),
5006
5091
  ephemeralAgent: require_data_service.isAssistantsEndpoint(endpoint) ? void 0 : ephemeralAgent,
5007
- manualSkills: require_data_service.isAssistantsEndpoint(endpoint) ? void 0 : manualSkills
5092
+ manualSkills: require_data_service.isAssistantsEndpoint(endpoint) ? void 0 : manualSkills,
5093
+ timezone: getUserTimezone()
5008
5094
  };
5009
5095
  return {
5010
5096
  server,
@@ -5408,6 +5494,22 @@ const anthropic = {
5408
5494
  showDefault: false,
5409
5495
  columnSpan: 2
5410
5496
  },
5497
+ promptCacheTtl: {
5498
+ key: "promptCacheTtl",
5499
+ label: "com_endpoint_prompt_cache_ttl",
5500
+ labelCode: true,
5501
+ description: "com_endpoint_anthropic_prompt_cache_ttl",
5502
+ descriptionCode: true,
5503
+ type: "enum",
5504
+ default: require_data_service.anthropicSettings.promptCacheTtl.default,
5505
+ options: ["5m", "1h"],
5506
+ component: "dropdown",
5507
+ optionType: "conversation",
5508
+ showDefault: false,
5509
+ placeholder: "com_endpoint_prompt_cache_ttl_default",
5510
+ placeholderCode: true,
5511
+ columnSpan: 2
5512
+ },
5411
5513
  thinking: {
5412
5514
  key: "thinking",
5413
5515
  label: "com_endpoint_thinking",
@@ -5563,6 +5665,22 @@ const bedrock = {
5563
5665
  showDefault: false,
5564
5666
  columnSpan: 2
5565
5667
  },
5668
+ promptCacheTtl: {
5669
+ key: "promptCacheTtl",
5670
+ label: "com_endpoint_prompt_cache_ttl",
5671
+ labelCode: true,
5672
+ description: "com_endpoint_anthropic_prompt_cache_ttl",
5673
+ descriptionCode: true,
5674
+ type: "enum",
5675
+ default: void 0,
5676
+ options: ["5m", "1h"],
5677
+ component: "dropdown",
5678
+ optionType: "conversation",
5679
+ showDefault: false,
5680
+ placeholder: "com_endpoint_prompt_cache_ttl_default",
5681
+ placeholderCode: true,
5682
+ columnSpan: 2
5683
+ },
5566
5684
  reasoning_effort: {
5567
5685
  key: "reasoning_effort",
5568
5686
  label: "com_endpoint_reasoning_effort",
@@ -5816,7 +5934,11 @@ const openAI = [
5816
5934
  openAIParams.disableStreaming,
5817
5935
  librechat.fileTokenLimit
5818
5936
  ];
5819
- const openRouter = [...openAI, anthropic.promptCache];
5937
+ const openRouter = [
5938
+ ...openAI,
5939
+ anthropic.promptCache,
5940
+ anthropic.promptCacheTtl
5941
+ ];
5820
5942
  const openAICol1 = [
5821
5943
  baseDefinitions.model,
5822
5944
  librechat.modelLabel,
@@ -5850,6 +5972,7 @@ const anthropicConfig = [
5850
5972
  anthropic.topK,
5851
5973
  librechat.resendFiles,
5852
5974
  anthropic.promptCache,
5975
+ anthropic.promptCacheTtl,
5853
5976
  anthropic.thinking,
5854
5977
  anthropic.thinkingBudget,
5855
5978
  anthropic.effort,
@@ -5870,6 +5993,7 @@ const anthropicCol2 = [
5870
5993
  anthropic.topK,
5871
5994
  librechat.resendFiles,
5872
5995
  anthropic.promptCache,
5996
+ anthropic.promptCacheTtl,
5873
5997
  anthropic.thinking,
5874
5998
  anthropic.thinkingBudget,
5875
5999
  anthropic.effort,
@@ -5889,6 +6013,7 @@ const bedrockAnthropic = [
5889
6013
  librechat.resendFiles,
5890
6014
  bedrock.region,
5891
6015
  bedrock.promptCache,
6016
+ bedrock.promptCacheTtl,
5892
6017
  anthropic.thinking,
5893
6018
  anthropic.thinkingBudget,
5894
6019
  anthropic.effort,
@@ -5926,6 +6051,7 @@ const bedrockGeneral = [
5926
6051
  librechat.resendFiles,
5927
6052
  bedrock.region,
5928
6053
  bedrock.promptCache,
6054
+ bedrock.promptCacheTtl,
5929
6055
  librechat.fileTokenLimit
5930
6056
  ];
5931
6057
  const bedrockAnthropicCol1 = [
@@ -5943,6 +6069,7 @@ const bedrockAnthropicCol2 = [
5943
6069
  librechat.resendFiles,
5944
6070
  bedrock.region,
5945
6071
  bedrock.promptCache,
6072
+ bedrock.promptCacheTtl,
5946
6073
  anthropic.thinking,
5947
6074
  anthropic.thinkingBudget,
5948
6075
  anthropic.effort,
@@ -5989,6 +6116,7 @@ const bedrockGeneralCol2 = [
5989
6116
  librechat.resendFiles,
5990
6117
  bedrock.region,
5991
6118
  bedrock.promptCache,
6119
+ bedrock.promptCacheTtl,
5992
6120
  librechat.fileTokenLimit
5993
6121
  ];
5994
6122
  const bedrockZAI = [
@@ -6078,7 +6206,11 @@ const presetSettings = {
6078
6206
  ["custom"]: openAIColumns,
6079
6207
  ["openrouter"]: {
6080
6208
  col1: openAICol1,
6081
- col2: [...openAICol2, anthropic.promptCache]
6209
+ col2: [
6210
+ ...openAICol2,
6211
+ anthropic.promptCache,
6212
+ anthropic.promptCacheTtl
6213
+ ]
6082
6214
  },
6083
6215
  ["anthropic"]: {
6084
6216
  col1: anthropicCol1,
@@ -6274,6 +6406,7 @@ exports.Time = require_data_service.Time;
6274
6406
  exports.TokenExchangeMethodEnum = require_data_service.TokenExchangeMethodEnum;
6275
6407
  exports.ToolCallTypes = ToolCallTypes;
6276
6408
  exports.Tools = require_data_service.Tools;
6409
+ exports.UsageEvents = UsageEvents;
6277
6410
  exports.Verbosity = require_data_service.Verbosity;
6278
6411
  exports.ViolationTypes = require_data_service.ViolationTypes;
6279
6412
  exports.VisionModes = require_data_service.VisionModes;
@@ -6326,6 +6459,7 @@ exports.breadcrumb = breadcrumb;
6326
6459
  exports.buildLoginRedirectUrl = require_data_service.buildLoginRedirectUrl;
6327
6460
  exports.buildTree = buildTree;
6328
6461
  exports.button = button;
6462
+ exports.cacheSubsetProviders = require_data_service.cacheSubsetProviders;
6329
6463
  exports.calendar = calendar;
6330
6464
  exports.card = card;
6331
6465
  exports.carousel = carousel;
@@ -6442,6 +6576,7 @@ exports.imageTypeMapping = require_data_service.imageTypeMapping;
6442
6576
  exports.inferMimeType = require_data_service.inferMimeType;
6443
6577
  exports.initialModelsConfig = require_data_service.initialModelsConfig;
6444
6578
  exports.input = input;
6579
+ exports.inputTokensIncludesCache = require_data_service.inputTokensIncludesCache;
6445
6580
  exports.interfaceSchema = require_data_service.interfaceSchema;
6446
6581
  exports.isActionTool = require_data_service.isActionTool;
6447
6582
  exports.isAgentsEndpoint = require_data_service.isAgentsEndpoint;
@@ -6506,9 +6641,11 @@ exports.presetSettings = presetSettings;
6506
6641
  exports.principalSchema = require_data_service.principalSchema;
6507
6642
  exports.progress = progress;
6508
6643
  exports.promptPermissionsSchema = promptPermissionsSchema;
6644
+ exports.promptTokensFromUsage = promptTokensFromUsage;
6509
6645
  exports.providerEndpointMap = require_data_service.providerEndpointMap;
6510
6646
  exports.radioGroup = radioGroup;
6511
6647
  exports.rateLimitSchema = require_data_service.rateLimitSchema;
6648
+ exports.reconcileContextUsage = reconcileContextUsage;
6512
6649
  exports.registerPage = require_data_service.registerPage;
6513
6650
  exports.remoteAgentsPermissionsSchema = remoteAgentsPermissionsSchema;
6514
6651
  exports.removeNullishValues = require_data_service.removeNullishValues;