@juspay/neurolink 12.14.21 → 12.15.1
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/CHANGELOG.md +2 -6
- package/dist/browser/neurolink.min.js +397 -397
- package/dist/cli/commands/auth.js +6 -2
- package/dist/cli/commands/proxy.d.ts +4 -0
- package/dist/cli/commands/proxy.js +119 -39
- package/dist/cli/index.js +8 -18
- package/dist/cli/lifecycle.d.ts +8 -0
- package/dist/cli/lifecycle.js +90 -0
- package/dist/core/baseProvider.d.ts +6 -3
- package/dist/core/baseProvider.js +7 -3
- package/dist/providers/amazonBedrock/client.d.ts +7 -5
- package/dist/providers/amazonBedrock/client.js +125 -16
- package/dist/providers/cohere.d.ts +2 -2
- package/dist/providers/cohere.js +5 -1
- package/dist/providers/googleAiStudio/client.d.ts +3 -3
- package/dist/providers/googleAiStudio/client.js +6 -2
- package/dist/providers/googleVertex/client.d.ts +2 -2
- package/dist/providers/googleVertex/client.js +5 -1
- package/dist/providers/jina.d.ts +2 -2
- package/dist/providers/jina.js +5 -1
- package/dist/providers/litellm/client.d.ts +2 -2
- package/dist/providers/litellm/client.js +5 -1
- package/dist/providers/ollama/client.d.ts +2 -2
- package/dist/providers/ollama/client.js +5 -1
- package/dist/providers/openAI/client.d.ts +3 -3
- package/dist/providers/openAI/client.js +6 -2
- package/dist/providers/voyage.d.ts +2 -2
- package/dist/providers/voyage.js +5 -1
- package/dist/proxy/codexAccountUsage.js +18 -6
- package/dist/proxy/codexFallback.js +17 -10
- package/dist/proxy/codexUsage.js +3 -0
- package/dist/proxy/proxyAnalysis.js +14 -11
- package/dist/proxy/proxyTokenUsage.d.ts +7 -0
- package/dist/proxy/proxyTokenUsage.js +21 -0
- package/dist/proxy/proxyTracer.d.ts +2 -0
- package/dist/proxy/proxyTracer.js +21 -40
- package/dist/proxy/quotaHeaders.js +7 -3
- package/dist/rag/document/MDocument.d.ts +19 -1
- package/dist/rag/document/MDocument.js +30 -3
- package/dist/rag/document/imageLoader.d.ts +55 -0
- package/dist/rag/document/imageLoader.js +183 -0
- package/dist/rag/index.d.ts +1 -0
- package/dist/rag/index.js +2 -0
- package/dist/rag/pipeline/RAGPipeline.d.ts +54 -1
- package/dist/rag/pipeline/RAGPipeline.js +358 -1
- package/dist/rag/ragIntegration.js +146 -25
- package/dist/server/routes/claudeProxyRoutes.js +35 -1
- package/dist/server/routes/codexProxyRoutes.d.ts +5 -9
- package/dist/server/routes/codexProxyRoutes.js +106 -18
- package/dist/types/codex.d.ts +10 -0
- package/dist/types/providers.d.ts +21 -1
- package/dist/types/proxy.d.ts +24 -6
- package/dist/types/rag.d.ts +144 -0
- package/dist/types/rag.js +12 -1
- package/dist/utils/pricing.js +4 -2
- package/docs-site/static/search-index.json +1 -1
- package/package.json +2 -1
package/dist/types/proxy.d.ts
CHANGED
|
@@ -221,6 +221,7 @@ export type InternalResult = {
|
|
|
221
221
|
total: number;
|
|
222
222
|
cacheCreationTokens?: number;
|
|
223
223
|
cacheReadTokens?: number;
|
|
224
|
+
reasoning?: number;
|
|
224
225
|
};
|
|
225
226
|
toolCalls?: Array<{
|
|
226
227
|
toolCallId: string;
|
|
@@ -576,6 +577,8 @@ export type RequestLogEntry = {
|
|
|
576
577
|
method: string;
|
|
577
578
|
path: string;
|
|
578
579
|
model: string;
|
|
580
|
+
/** Client model when a different upstream model served the request. */
|
|
581
|
+
requestedModel?: string;
|
|
579
582
|
stream: boolean;
|
|
580
583
|
toolCount: number;
|
|
581
584
|
account: string;
|
|
@@ -590,10 +593,14 @@ export type RequestLogEntry = {
|
|
|
590
593
|
errorCode?: string;
|
|
591
594
|
/** Whether changing credentials can affect this transport failure. */
|
|
592
595
|
transportScope?: ProxyTransportScope;
|
|
596
|
+
/** True when input includes the cache breakdown (native Codex wire usage). */
|
|
597
|
+
inputIncludesCachedTokens?: boolean;
|
|
593
598
|
inputTokens?: number;
|
|
594
599
|
outputTokens?: number;
|
|
595
600
|
cacheCreationTokens?: number;
|
|
596
601
|
cacheReadTokens?: number;
|
|
602
|
+
/** Reasoning tokens are a subset of output, never additional usage. */
|
|
603
|
+
reasoningTokens?: number;
|
|
597
604
|
/**
|
|
598
605
|
* Provider that actually served the request, for costing. Absent on records
|
|
599
606
|
* written before this field existed; `proxyAnalysis` then falls back to a
|
|
@@ -814,6 +821,10 @@ export type RequestAttemptLogEntry = {
|
|
|
814
821
|
rateLimitKind?: "transient" | "quota";
|
|
815
822
|
/** Reset-aware cooldown reason selected for a rate-limited attempt. */
|
|
816
823
|
cooldownReason?: "transient" | "session" | "weekly" | "unified";
|
|
824
|
+
/** Reset reported by a structured quota rejection, epoch milliseconds. */
|
|
825
|
+
quotaResetAt?: number;
|
|
826
|
+
/** Unknown scope never implies an account-wide long-window rejection. */
|
|
827
|
+
quotaScope?: "session" | "weekly" | "unknown";
|
|
817
828
|
inputTokens?: number;
|
|
818
829
|
outputTokens?: number;
|
|
819
830
|
cacheCreationTokens?: number;
|
|
@@ -828,9 +839,9 @@ export type RequestAttemptLogEntry = {
|
|
|
828
839
|
traceFlags?: number;
|
|
829
840
|
};
|
|
830
841
|
/** Additional fields recorded when a Codex response becomes client-final. */
|
|
831
|
-
export type CodexFinalLogExtra = Partial<Pick<RequestLogEntry, "errorType" | "errorMessage" | "errorCode" | "transportScope" | "inputTokens" | "outputTokens" | "cacheReadTokens" | "cacheCreationTokens" | "terminalOutcome" | "firstUsefulOutputMs" | "firstUsefulOutputStatus" | "firstUsefulOutputEvent">>;
|
|
842
|
+
export type CodexFinalLogExtra = Partial<Pick<RequestLogEntry, "errorType" | "errorMessage" | "errorCode" | "transportScope" | "inputTokens" | "outputTokens" | "cacheReadTokens" | "cacheCreationTokens" | "reasoningTokens" | "terminalOutcome" | "firstUsefulOutputMs" | "firstUsefulOutputStatus" | "firstUsefulOutputEvent">>;
|
|
832
843
|
/** Additional fields recorded for each upstream Codex account attempt. */
|
|
833
|
-
export type CodexAttemptLogExtra = Partial<Pick<RequestAttemptLogEntry, "errorType" | "errorMessage" | "errorCode" | "transportScope" | "retryable" | "rateLimitKind" | "cooldownReason">>;
|
|
844
|
+
export type CodexAttemptLogExtra = Partial<Pick<RequestAttemptLogEntry, "errorType" | "errorMessage" | "errorCode" | "transportScope" | "retryable" | "rateLimitKind" | "cooldownReason" | "quotaResetAt" | "quotaScope">>;
|
|
834
845
|
/** Minimal persistence contract needed by Codex rotating-token refreshes. */
|
|
835
846
|
export type CodexRefreshTokenStore = {
|
|
836
847
|
peekTokens(provider: string): Promise<StoredOAuthTokens | null>;
|
|
@@ -863,6 +874,7 @@ export type ClaudeFinalRequestLogger = (status: number, accountLabel: string, ac
|
|
|
863
874
|
outputTokens?: number;
|
|
864
875
|
cacheCreationTokens?: number;
|
|
865
876
|
cacheReadTokens?: number;
|
|
877
|
+
reasoningTokens?: number;
|
|
866
878
|
errorCode?: string;
|
|
867
879
|
transportScope?: ProxyTransportScope;
|
|
868
880
|
}) => void;
|
|
@@ -1246,15 +1258,15 @@ export type AccountQuota = {
|
|
|
1246
1258
|
/** Top-level unified status. A rejected value can be authoritative even
|
|
1247
1259
|
* while both 5h and 7d sub-window statuses still report allowed. */
|
|
1248
1260
|
unifiedStatus?: string;
|
|
1249
|
-
/** 0.0-1.0
|
|
1261
|
+
/** 0.0-1.0 utilization; ignore the numeric placeholder when status is unknown. */
|
|
1250
1262
|
sessionUsed: number;
|
|
1251
|
-
/** "allowed" | "throttled" | "rejected" */
|
|
1263
|
+
/** "allowed" | "throttled" | "rejected" | "unknown" */
|
|
1252
1264
|
sessionStatus: string;
|
|
1253
1265
|
/** Unix timestamp (seconds) when the 5h window resets */
|
|
1254
1266
|
sessionResetAt: number;
|
|
1255
|
-
/** 0.0-1.0
|
|
1267
|
+
/** 0.0-1.0 utilization; ignore the numeric placeholder when status is unknown. */
|
|
1256
1268
|
weeklyUsed: number;
|
|
1257
|
-
/** "allowed" | "throttled" | "rejected" */
|
|
1269
|
+
/** "allowed" | "throttled" | "rejected" | "unknown" */
|
|
1258
1270
|
weeklyStatus: string;
|
|
1259
1271
|
/** Unix timestamp (seconds) when the 7d window resets */
|
|
1260
1272
|
weeklyResetAt: number;
|
|
@@ -1700,6 +1712,8 @@ export type UpstreamAttemptContext = {
|
|
|
1700
1712
|
};
|
|
1701
1713
|
/** Token usage and rate-limit utilisation recorded at end of request. */
|
|
1702
1714
|
export type UsageContext = {
|
|
1715
|
+
/** True when input includes the cache breakdown (native Codex wire usage). */
|
|
1716
|
+
inputIncludesCachedTokens?: boolean;
|
|
1703
1717
|
inputTokens: number;
|
|
1704
1718
|
outputTokens: number;
|
|
1705
1719
|
cacheCreationTokens: number;
|
|
@@ -2008,6 +2022,7 @@ export type ProxyAnalysisReport = {
|
|
|
2008
2022
|
requestsWithCacheRead: number;
|
|
2009
2023
|
cacheReadTokens: number;
|
|
2010
2024
|
cacheCreationTokens: number;
|
|
2025
|
+
/** Ordinary input, excluding the separately reported cache read/write buckets. */
|
|
2011
2026
|
inputTokens: number;
|
|
2012
2027
|
outputTokens: number;
|
|
2013
2028
|
requestHitRate: number | null;
|
|
@@ -2068,6 +2083,7 @@ export type ProxyAnalysisFinalRequestRecord = {
|
|
|
2068
2083
|
accountType: string;
|
|
2069
2084
|
model: string | null;
|
|
2070
2085
|
provider: string | null;
|
|
2086
|
+
inputIncludesCachedTokens?: boolean;
|
|
2071
2087
|
inputTokens: number | null;
|
|
2072
2088
|
outputTokens: number | null;
|
|
2073
2089
|
cacheReadTokens: number | null;
|
|
@@ -2104,6 +2120,8 @@ export type CodexStreamUsage = {
|
|
|
2104
2120
|
/** Cache writes, which bill at a premium over both reads and plain input. */
|
|
2105
2121
|
cacheCreationTokens: number;
|
|
2106
2122
|
reasoningTokens: number;
|
|
2123
|
+
/** Whether the provider supplied a valid reasoning breakdown. */
|
|
2124
|
+
reasoningTokensObserved?: boolean;
|
|
2107
2125
|
};
|
|
2108
2126
|
/** Semantic completion evidence observed in native Codex SSE bytes. */
|
|
2109
2127
|
export type CodexStreamEvidence = {
|
package/dist/types/rag.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Tool } from "./tools.js";
|
|
2
|
+
import type { EmbedInput } from "./providers.js";
|
|
2
3
|
/**
|
|
3
4
|
* RAG Type Definitions
|
|
4
5
|
*
|
|
@@ -231,6 +232,8 @@ export type RAGPipelineConfig = {
|
|
|
231
232
|
enableReranking?: boolean;
|
|
232
233
|
/** Reranking model configuration */
|
|
233
234
|
rerankingModel?: EmbeddingModelConfig;
|
|
235
|
+
/** Multi-modal RAG configuration (image + text embeddings) */
|
|
236
|
+
multiModal?: MultiModalRAGConfig;
|
|
234
237
|
};
|
|
235
238
|
/**
|
|
236
239
|
* Ingestion options
|
|
@@ -419,6 +422,18 @@ export type VectorStore = {
|
|
|
419
422
|
includeVectors?: boolean;
|
|
420
423
|
}): Promise<VectorQueryResult[]>;
|
|
421
424
|
};
|
|
425
|
+
/**
|
|
426
|
+
* Structural extension of {@link VectorStore} for stores that can also write
|
|
427
|
+
* vectors via `upsert()` (e.g. {@link InMemoryVectorStore}). Custom stores
|
|
428
|
+
* that expose an `upsert` method satisfy this type without a cast.
|
|
429
|
+
*/
|
|
430
|
+
export type UpsertableVectorStore = VectorStore & {
|
|
431
|
+
upsert(indexName: string, items: Array<{
|
|
432
|
+
id: string;
|
|
433
|
+
vector: number[];
|
|
434
|
+
metadata?: Record<string, unknown>;
|
|
435
|
+
}>): Promise<void>;
|
|
436
|
+
};
|
|
422
437
|
/** Minimal shape of a query result, satisfied by both `pg` and `pglite`. */
|
|
423
438
|
export type PgQueryResult<T = unknown> = {
|
|
424
439
|
rows: T[];
|
|
@@ -1330,3 +1345,132 @@ export type DocumentState = {
|
|
|
1330
1345
|
};
|
|
1331
1346
|
/** Canonical RAG error code. */
|
|
1332
1347
|
export type RAGErrorCode = "RAG_CHUNKING_ERROR" | "RAG_CHUNKING_INVALID_CONFIG" | "RAG_CHUNKING_STRATEGY_NOT_FOUND" | "RAG_CHUNKING_EMPTY_CONTENT" | "RAG_CHUNKING_SIZE_EXCEEDED" | "RAG_METADATA_EXTRACTION_ERROR" | "RAG_METADATA_EXTRACTION_TIMEOUT" | "RAG_METADATA_SCHEMA_INVALID" | "RAG_METADATA_EXTRACTOR_NOT_FOUND" | "RAG_EMBEDDING_ERROR" | "RAG_EMBEDDING_DIMENSION_MISMATCH" | "RAG_EMBEDDING_RATE_LIMIT" | "RAG_EMBEDDING_PROVIDER_ERROR" | "RAG_VECTOR_QUERY_ERROR" | "RAG_VECTOR_QUERY_TIMEOUT" | "RAG_VECTOR_STORE_UNAVAILABLE" | "RAG_VECTOR_STORE_CONNECTION_ERROR" | "RAG_VECTOR_INDEX_NOT_FOUND" | "RAG_RERANKER_ERROR" | "RAG_RERANKER_NOT_FOUND" | "RAG_RERANKER_API_ERROR" | "RAG_GRAPH_ERROR" | "RAG_GRAPH_TRAVERSAL_ERROR" | "RAG_GRAPH_NODE_NOT_FOUND" | "RAG_PIPELINE_ERROR" | "RAG_PIPELINE_STAGE_FAILED" | "RAG_PIPELINE_PARTIAL_FAILURE" | "RAG_CIRCUIT_BREAKER_OPEN" | "RAG_CIRCUIT_BREAKER_HALF_OPEN_LIMIT" | "RAG_OPERATION_TIMEOUT" | "RAG_RETRY_EXHAUSTED" | "RAG_INVALID_CONFIGURATION";
|
|
1348
|
+
/**
|
|
1349
|
+
* Modality of an embedding model
|
|
1350
|
+
*/
|
|
1351
|
+
export type EmbeddingModality = "text" | "image" | "multimodal";
|
|
1352
|
+
/**
|
|
1353
|
+
* Multi-modal embedding model configuration
|
|
1354
|
+
*/
|
|
1355
|
+
export type MultiModalEmbeddingConfig = {
|
|
1356
|
+
/** Provider name (e.g. "bedrock") */
|
|
1357
|
+
provider: string;
|
|
1358
|
+
/** Model name (e.g. "amazon.titan-embed-image-v1") */
|
|
1359
|
+
modelName: string;
|
|
1360
|
+
/** What modalities this model supports */
|
|
1361
|
+
modality: EmbeddingModality;
|
|
1362
|
+
/** Embedding dimension (e.g. 1024 for Titan Image) */
|
|
1363
|
+
dimensions?: number;
|
|
1364
|
+
};
|
|
1365
|
+
/**
|
|
1366
|
+
* Image metadata attached to multi-modal chunks
|
|
1367
|
+
*/
|
|
1368
|
+
export type ImageChunkMetadata = {
|
|
1369
|
+
/** Image width in pixels */
|
|
1370
|
+
width?: number;
|
|
1371
|
+
/** Image height in pixels */
|
|
1372
|
+
height?: number;
|
|
1373
|
+
/** Image MIME type */
|
|
1374
|
+
mimeType?: string;
|
|
1375
|
+
/** Image format (jpeg, png, webp, etc.) */
|
|
1376
|
+
format?: string;
|
|
1377
|
+
/** Original file path or URL */
|
|
1378
|
+
source?: string;
|
|
1379
|
+
/** Whether this chunk contains image data */
|
|
1380
|
+
hasImage: boolean;
|
|
1381
|
+
};
|
|
1382
|
+
/**
|
|
1383
|
+
* Extended chunk type for multi-modal RAG.
|
|
1384
|
+
* Contains optional image data alongside text for image+text search.
|
|
1385
|
+
*/
|
|
1386
|
+
export type MultiModalChunk = Chunk & {
|
|
1387
|
+
/** Image data as Buffer or base64 string (present for image chunks) */
|
|
1388
|
+
image?: Buffer | string;
|
|
1389
|
+
/** Image MIME type */
|
|
1390
|
+
imageMimeType?: string;
|
|
1391
|
+
/** Image-specific metadata */
|
|
1392
|
+
imageMeta?: ImageChunkMetadata;
|
|
1393
|
+
};
|
|
1394
|
+
/**
|
|
1395
|
+
* Multi-modal query input — can be text, image, or both.
|
|
1396
|
+
* Same shape as EmbedInput.
|
|
1397
|
+
*/
|
|
1398
|
+
export type MultiModalQuery = EmbedInput;
|
|
1399
|
+
/**
|
|
1400
|
+
* Multi-modal RAG pipeline configuration extension.
|
|
1401
|
+
* Passed alongside RAGPipelineConfig to enable multi-modal features.
|
|
1402
|
+
*/
|
|
1403
|
+
export type MultiModalRAGConfig = {
|
|
1404
|
+
/** Whether multi-modal RAG is enabled */
|
|
1405
|
+
enabled: boolean;
|
|
1406
|
+
/** Embedding model for multi-modal content */
|
|
1407
|
+
embeddingModel: MultiModalEmbeddingConfig;
|
|
1408
|
+
/** How to generate text from images for indexing: "caption" uses LLM vision, "filename" uses filename, "none" skips text */
|
|
1409
|
+
imageTextStrategy?: "caption" | "filename" | "none";
|
|
1410
|
+
/** Maximum image file size in bytes (default: 10MB) */
|
|
1411
|
+
maxImageSize?: number;
|
|
1412
|
+
/** Supported image MIME types */
|
|
1413
|
+
supportedFormats?: string[];
|
|
1414
|
+
/** Provider for generating image captions (used with imageTextStrategy: "caption") */
|
|
1415
|
+
captionProvider?: string;
|
|
1416
|
+
/** Model for generating image captions */
|
|
1417
|
+
captionModel?: string;
|
|
1418
|
+
};
|
|
1419
|
+
/**
|
|
1420
|
+
* Match type indicating how the result was found
|
|
1421
|
+
*/
|
|
1422
|
+
export type MultiModalMatchType = "text-to-text" | "text-to-image" | "image-to-image" | "image-to-text";
|
|
1423
|
+
/**
|
|
1424
|
+
* Image search result from multi-modal retrieval
|
|
1425
|
+
*/
|
|
1426
|
+
export type MultiModalSearchResult = {
|
|
1427
|
+
/** The chunk containing the match */
|
|
1428
|
+
chunk: MultiModalChunk;
|
|
1429
|
+
/** Similarity score (0-1) */
|
|
1430
|
+
score: number;
|
|
1431
|
+
/** How this match was found */
|
|
1432
|
+
matchType: MultiModalMatchType;
|
|
1433
|
+
};
|
|
1434
|
+
/**
|
|
1435
|
+
* Supported image MIME types for multi-modal RAG
|
|
1436
|
+
*/
|
|
1437
|
+
export declare const SUPPORTED_IMAGE_MIME_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "image/bmp", "image/tiff", "image/avif"];
|
|
1438
|
+
/**
|
|
1439
|
+
* Image document loaded for RAG ingestion
|
|
1440
|
+
*/
|
|
1441
|
+
export type ImageDocument = {
|
|
1442
|
+
/** Unique identifier for this image document */
|
|
1443
|
+
id: string;
|
|
1444
|
+
/** Text representation (filename, alt text, or caption) */
|
|
1445
|
+
text: string;
|
|
1446
|
+
/** Raw image data */
|
|
1447
|
+
image: Buffer;
|
|
1448
|
+
/** Image MIME type */
|
|
1449
|
+
mimeType: string;
|
|
1450
|
+
/** Metadata about the image */
|
|
1451
|
+
metadata: {
|
|
1452
|
+
/** Original file path or URL */
|
|
1453
|
+
source: string;
|
|
1454
|
+
/** Image width in pixels (if detectable) */
|
|
1455
|
+
width?: number;
|
|
1456
|
+
/** Image height in pixels (if detectable) */
|
|
1457
|
+
height?: number;
|
|
1458
|
+
/** Image format (jpeg, png, webp, etc.) */
|
|
1459
|
+
format?: string;
|
|
1460
|
+
/** File size in bytes */
|
|
1461
|
+
size: number;
|
|
1462
|
+
};
|
|
1463
|
+
};
|
|
1464
|
+
/**
|
|
1465
|
+
* Options for loading images
|
|
1466
|
+
*/
|
|
1467
|
+
export type ImageLoaderOptions = {
|
|
1468
|
+
/** Custom metadata to attach to the image document */
|
|
1469
|
+
metadata?: Record<string, unknown>;
|
|
1470
|
+
/** Maximum image file size in bytes (default: 10MB) */
|
|
1471
|
+
maxImageSize?: number;
|
|
1472
|
+
/** Timeout for URL fetches in milliseconds (default: 30000) */
|
|
1473
|
+
fetchTimeout?: number;
|
|
1474
|
+
/** Custom headers for URL fetches */
|
|
1475
|
+
headers?: Record<string, string>;
|
|
1476
|
+
};
|
package/dist/types/rag.js
CHANGED
package/dist/utils/pricing.js
CHANGED
|
@@ -899,8 +899,10 @@ export function calculateCost(provider, model, usage) {
|
|
|
899
899
|
// priced providers still get the cheaper cacheRead rate.
|
|
900
900
|
cost += usage.cacheReadTokens * (rates.cacheRead ?? rates.input);
|
|
901
901
|
}
|
|
902
|
-
if (usage.cacheCreationTokens
|
|
903
|
-
|
|
902
|
+
if (usage.cacheCreationTokens) {
|
|
903
|
+
// Like cache reads, disjoint cache writes must not silently become free
|
|
904
|
+
// when a model has no separate creation rate. Preserve explicit zero rates.
|
|
905
|
+
cost += usage.cacheCreationTokens * (rates.cacheCreation ?? rates.input);
|
|
904
906
|
}
|
|
905
907
|
return Math.round(cost * 1_000_000) / 1_000_000; // Round to 6 decimal places
|
|
906
908
|
}
|