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/{data-service-Dk-uLruo.js → data-service-CCdWvcRd.js} +109 -7
- package/dist/data-service-CCdWvcRd.js.map +1 -0
- package/dist/{data-service-BFGYAHRx.mjs → data-service-D7mtXwG5.mjs} +98 -8
- package/dist/data-service-D7mtXwG5.mjs.map +1 -0
- package/dist/index.js +187 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -51
- package/dist/index.mjs.map +1 -1
- package/dist/react-query/index.js +6 -1
- package/dist/react-query/index.js.map +1 -1
- package/dist/react-query/index.mjs +6 -1
- package/dist/react-query/index.mjs.map +1 -1
- package/dist/types/api-endpoints.d.ts +3 -0
- package/dist/types/bedrock.d.ts +20 -5
- package/dist/types/config.d.ts +643 -90
- package/dist/types/data-service.d.ts +4 -0
- package/dist/types/generate.d.ts +4 -0
- package/dist/types/keys.d.ts +4 -1
- package/dist/types/models.d.ts +34 -0
- package/dist/types/parsers.d.ts +2 -1
- package/dist/types/react-query/react-query-service.d.ts +2 -2
- package/dist/types/schemas.d.ts +94 -4
- package/dist/types/types/agents.d.ts +5 -0
- package/dist/types/types/mutations.d.ts +1 -0
- package/dist/types/types/runs.d.ts +125 -0
- package/dist/types/types.d.ts +18 -1
- package/package.json +2 -2
- package/dist/data-service-BFGYAHRx.mjs.map +0 -1
- package/dist/data-service-Dk-uLruo.js.map +0 -1
|
@@ -35,6 +35,131 @@ export declare enum StepEvents {
|
|
|
35
35
|
ON_SUMMARIZE_COMPLETE = "on_summarize_complete",
|
|
36
36
|
ON_SUBAGENT_UPDATE = "on_subagent_update"
|
|
37
37
|
}
|
|
38
|
+
/** Token-tracking event names streamed to the client (separate from StepEvents dispatch). */
|
|
39
|
+
export declare enum UsageEvents {
|
|
40
|
+
ON_CONTEXT_USAGE = "on_context_usage",
|
|
41
|
+
ON_TOKEN_USAGE = "on_token_usage"
|
|
42
|
+
}
|
|
43
|
+
/** Mirrors TokenBudgetBreakdown from @librechat/agents (data-provider cannot import it). */
|
|
44
|
+
export type TTokenBudgetBreakdown = {
|
|
45
|
+
maxContextTokens: number;
|
|
46
|
+
instructionTokens: number;
|
|
47
|
+
systemMessageTokens: number;
|
|
48
|
+
dynamicInstructionTokens: number;
|
|
49
|
+
toolSchemaTokens: number;
|
|
50
|
+
summaryTokens: number;
|
|
51
|
+
toolCount: number;
|
|
52
|
+
messageCount: number;
|
|
53
|
+
messageTokens: number;
|
|
54
|
+
availableForMessages: number;
|
|
55
|
+
/** Per-tool schema token counts (post-multiplier), keyed by tool name */
|
|
56
|
+
toolTokenCounts?: Record<string, number>;
|
|
57
|
+
/** Names of counted tools that are deferred (`defer_loading`) and discovered */
|
|
58
|
+
deferredToolNames?: string[];
|
|
59
|
+
};
|
|
60
|
+
/** Per-model-call context snapshot, dispatched after pruning and before the LLM call. */
|
|
61
|
+
export type TContextUsageEvent = {
|
|
62
|
+
runId?: string;
|
|
63
|
+
agentId?: string;
|
|
64
|
+
breakdown: TTokenBudgetBreakdown;
|
|
65
|
+
/** Usable budget this call: maxContextTokens minus output reserve */
|
|
66
|
+
contextBudget?: number;
|
|
67
|
+
/** Calibrated instruction overhead actually applied this call */
|
|
68
|
+
effectiveInstructionTokens?: number;
|
|
69
|
+
/** Calibrated message tokens before pruning (excluding instructions) */
|
|
70
|
+
prePruneContextTokens?: number;
|
|
71
|
+
/** Tokens still free after instructions + pruned messages */
|
|
72
|
+
remainingContextTokens?: number;
|
|
73
|
+
calibrationRatio?: number;
|
|
74
|
+
/** Output tokens of the response's final model call (the call this pre-invoke
|
|
75
|
+
* snapshot precedes). Populated only on the persisted `metadata.contextUsage`
|
|
76
|
+
* blob so a reloaded multi-call turn adds the same post-snapshot delta the
|
|
77
|
+
* live finalizer did — not the full response `tokenCount`, which the snapshot
|
|
78
|
+
* already includes for earlier steps. */
|
|
79
|
+
completedOutputTokens?: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Request payload for a server-side context-usage projection: "what context
|
|
83
|
+
* would the next call send for this branch under this config", computed by the
|
|
84
|
+
* agents SDK without invoking the model. Powers the gauge in states the live
|
|
85
|
+
* snapshot can't cover (page load of a snapshot-less branch, window/model
|
|
86
|
+
* switch). `messageId` is the viewed branch's tail; the server walks its parent
|
|
87
|
+
* chain.
|
|
88
|
+
*/
|
|
89
|
+
export type TContextProjectionRequest = {
|
|
90
|
+
conversationId: string;
|
|
91
|
+
messageId: string;
|
|
92
|
+
endpoint: string;
|
|
93
|
+
model?: string;
|
|
94
|
+
agentId?: string;
|
|
95
|
+
spec?: string;
|
|
96
|
+
maxContextTokens?: number;
|
|
97
|
+
/** Provider-calibrated ratio from a prior snapshot, applied as a static seed. */
|
|
98
|
+
calibrationRatio?: number;
|
|
99
|
+
/** Client-only cache-bust: a branch content revision so a message edit
|
|
100
|
+
* (which keeps the same tail id) refetches. The server ignores it. */
|
|
101
|
+
revision?: number;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Per-response usage rollup persisted on `responseMessage.metadata.usage`, in
|
|
105
|
+
* display units (input excludes cache; output includes repaired completion).
|
|
106
|
+
* Normalized per-event on the backend before summing so a reloaded conversation
|
|
107
|
+
* reproduces the live branch/total usage exactly, even for mixed-provider turns
|
|
108
|
+
* (summarization/subagent calls on a different provider than the primary).
|
|
109
|
+
*/
|
|
110
|
+
export type TResponseUsage = {
|
|
111
|
+
input: number;
|
|
112
|
+
output: number;
|
|
113
|
+
cacheWrite: number;
|
|
114
|
+
cacheRead: number;
|
|
115
|
+
/** Authoritative USD cost; present only when `interface.contextCost` was on at save */
|
|
116
|
+
cost?: number;
|
|
117
|
+
};
|
|
118
|
+
/** Provider-reported usage for a single completed model call. */
|
|
119
|
+
export type TTokenUsageEvent = {
|
|
120
|
+
input_tokens?: number;
|
|
121
|
+
output_tokens?: number;
|
|
122
|
+
total_tokens?: number;
|
|
123
|
+
input_token_details?: {
|
|
124
|
+
cache_creation?: number;
|
|
125
|
+
cache_read?: number;
|
|
126
|
+
};
|
|
127
|
+
model?: string;
|
|
128
|
+
provider?: string;
|
|
129
|
+
/** Non-primary buckets fold into session cost/totals but not the live
|
|
130
|
+
* context gauge: hidden sequential-agent calls (`sequential`), summary
|
|
131
|
+
* passes (`summarization`), and isolated subagent runs (`subagent`) */
|
|
132
|
+
usage_type?: 'summarization' | 'subagent' | 'sequential';
|
|
133
|
+
runId?: string;
|
|
134
|
+
/** Per-run emission sequence; keeps identical payloads from distinct model calls unique */
|
|
135
|
+
seq?: number;
|
|
136
|
+
/** Authoritative USD cost of this call from the backend (premium tiers, cache
|
|
137
|
+
* rates); present only when `interface.contextCost` is enabled. Clients sum
|
|
138
|
+
* this rather than re-deriving cost from base rates. */
|
|
139
|
+
cost?: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Full prompt token count for one completed model call — the EXACT context the
|
|
143
|
+
* model saw, provider-aware: additive providers (Bedrock) report `input_tokens`
|
|
144
|
+
* excluding cache, so cache reads/writes are added back; subset providers
|
|
145
|
+
* (Anthropic, OpenAI, …) already fold cache into `input_tokens`. When the
|
|
146
|
+
* provider is absent (custom/OpenAI-compatible payloads), fall back to the same
|
|
147
|
+
* magnitude heuristic `normalizeUsageUnits` uses — cache ≤ input means it's
|
|
148
|
+
* already included — so cached events aren't re-inflated. The ground truth the
|
|
149
|
+
* gauge reconciles its calibrated estimate to.
|
|
150
|
+
*/
|
|
151
|
+
export declare const promptTokensFromUsage: (event: TTokenUsageEvent) => number;
|
|
152
|
+
/**
|
|
153
|
+
* Reconciles a pre-invoke context snapshot's CALIBRATED estimate to a call's
|
|
154
|
+
* ACTUAL prompt tokens. The SDK's calibration multiplier scales only
|
|
155
|
+
* `messageTokens` (instructions/summary are raw tiktoken counts), and it can
|
|
156
|
+
* over-shoot badly when a provider injects server-side content the SDK never
|
|
157
|
+
* counted (e.g. Anthropic web search) — pinning the gauge several× too high and
|
|
158
|
+
* persisting it. Trust the provider's own prompt count: keep the raw
|
|
159
|
+
* instruction/summary rows, set `messageTokens` to the remainder, and recompute
|
|
160
|
+
* the free space. No-op when `promptTokens` is unusable.
|
|
161
|
+
*/
|
|
162
|
+
export declare const reconcileContextUsage: (snapshot: TContextUsageEvent, promptTokens: number) => TContextUsageEvent;
|
|
38
163
|
/** Lifecycle phase carried on subagent-progress envelopes (mirrors SDK SubagentUpdatePhase). */
|
|
39
164
|
export type SubagentUpdatePhase = 'start' | 'run_step' | 'run_step_delta' | 'run_step_completed' | 'message_delta' | 'reasoning_delta' | 'stop' | 'error';
|
|
40
165
|
/** Single streamed subagent update forwarded by the SDK's SubagentExecutor. */
|
package/dist/types/types.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { ContentTypes } from './types/runs';
|
|
|
7
7
|
import type { Agent } from './types/assistants';
|
|
8
8
|
export * from './schemas';
|
|
9
9
|
export type TMessages = TMessage[];
|
|
10
|
-
export type TEndpointOption = Pick<TConversation, 'endpoint' | 'endpointType' | 'model' | 'modelLabel' | 'chatGptLabel' | 'promptPrefix' | 'temperature' | 'topP' | 'topK' | 'top_p' | 'frequency_penalty' | 'presence_penalty' | 'maxOutputTokens' | 'maxContextTokens' | 'max_tokens' | 'maxTokens' | 'resendFiles' | 'imageDetail' | 'reasoning_effort' | 'verbosity' | 'instructions' | 'additional_instructions' | 'append_current_datetime' | 'tools' | 'stop' | 'region' | 'additionalModelRequestFields' | 'promptCache' | 'thinking' | 'thinkingBudget' | 'thinkingLevel' | 'effort' | 'thinkingDisplay' | 'assistant_id' | 'agent_id' | 'iconURL' | 'greeting' | 'spec' | 'artifacts' | 'file_ids' | 'system' | 'chatProjectId' | 'examples' | 'context'> & {
|
|
10
|
+
export type TEndpointOption = Pick<TConversation, 'endpoint' | 'endpointType' | 'model' | 'modelLabel' | 'chatGptLabel' | 'promptPrefix' | 'temperature' | 'topP' | 'topK' | 'top_p' | 'frequency_penalty' | 'presence_penalty' | 'maxOutputTokens' | 'maxContextTokens' | 'max_tokens' | 'maxTokens' | 'resendFiles' | 'imageDetail' | 'reasoning_effort' | 'verbosity' | 'instructions' | 'additional_instructions' | 'append_current_datetime' | 'tools' | 'stop' | 'region' | 'additionalModelRequestFields' | 'promptCache' | 'promptCacheTtl' | 'thinking' | 'thinkingBudget' | 'thinkingLevel' | 'effort' | 'thinkingDisplay' | 'assistant_id' | 'agent_id' | 'iconURL' | 'greeting' | 'spec' | 'artifacts' | 'file_ids' | 'system' | 'chatProjectId' | 'examples' | 'context'> & {
|
|
11
11
|
modelDisplayLabel?: string;
|
|
12
12
|
key?: string | null;
|
|
13
13
|
/** @deprecated Assistants API */
|
|
@@ -47,6 +47,8 @@ export type TPayload = Partial<TMessage> & Partial<TEndpointOption> & {
|
|
|
47
47
|
* before the LLM turn runs.
|
|
48
48
|
*/
|
|
49
49
|
manualSkills?: string[];
|
|
50
|
+
/** Browser IANA timezone (e.g. `America/New_York`) used to resolve local-time prompt variables server-side. */
|
|
51
|
+
timezone?: string;
|
|
50
52
|
};
|
|
51
53
|
export type TEditedContent = {
|
|
52
54
|
index: number;
|
|
@@ -237,6 +239,11 @@ export type TArchiveConversationRequest = {
|
|
|
237
239
|
isArchived: boolean;
|
|
238
240
|
};
|
|
239
241
|
export type TArchiveConversationResponse = TConversation;
|
|
242
|
+
export type TPinConversationRequest = {
|
|
243
|
+
conversationId: string;
|
|
244
|
+
pinned: boolean;
|
|
245
|
+
};
|
|
246
|
+
export type TPinConversationResponse = TConversation;
|
|
240
247
|
export type TSharedMessagesResponse = Omit<TSharedLink, 'messages'> & {
|
|
241
248
|
messages: TMessage[];
|
|
242
249
|
};
|
|
@@ -316,6 +323,16 @@ export type TConfig = {
|
|
|
316
323
|
};
|
|
317
324
|
export type TEndpointsConfig = Record<EModelEndpoint | string, TConfig | null | undefined> | undefined;
|
|
318
325
|
export type TModelsConfig = Record<string, string[]>;
|
|
326
|
+
/** Server-resolved context window and pricing for one model. Rates are USD per 1M tokens. */
|
|
327
|
+
export type TModelTokenomics = {
|
|
328
|
+
context?: number;
|
|
329
|
+
prompt?: number;
|
|
330
|
+
completion?: number;
|
|
331
|
+
cacheWrite?: number;
|
|
332
|
+
cacheRead?: number;
|
|
333
|
+
};
|
|
334
|
+
/** endpoint → model → resolved tokenomics, from GET /api/endpoints/token-config */
|
|
335
|
+
export type TTokenConfigMap = Record<string, Record<string, TModelTokenomics>>;
|
|
319
336
|
export type TUpdateTokenCountResponse = {
|
|
320
337
|
count: number;
|
|
321
338
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "librechat-data-provider",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.506",
|
|
4
4
|
"description": "data services for librechat apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"axios": "^1.16.0",
|
|
47
47
|
"dayjs": "^1.11.13",
|
|
48
|
-
"js-yaml": "^4.
|
|
48
|
+
"js-yaml": "^4.2.0",
|
|
49
49
|
"zod": "^3.22.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|