@juspay/neurolink 12.12.9 → 12.12.11
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 -2
- package/dist/browser/neurolink.min.js +394 -396
- package/dist/cli/commands/proxy.d.ts +4 -0
- package/dist/cli/commands/proxy.js +60 -18
- package/dist/cli/commands/proxyAnalyze.js +8 -1
- package/dist/core/baseProvider.d.ts +0 -22
- package/dist/core/baseProvider.js +18 -81
- package/dist/providers/anthropic/client.js +4 -1
- package/dist/providers/openaiChatCompletionsBase.js +4 -1
- package/dist/proxy/bodyCaptureProcessing.d.ts +22 -0
- package/dist/proxy/bodyCaptureProcessing.js +219 -0
- package/dist/proxy/bodyCaptureWorker.d.ts +16 -0
- package/dist/proxy/bodyCaptureWorker.js +232 -0
- package/dist/proxy/bodyCaptureWorkerEntry.d.ts +1 -0
- package/dist/proxy/bodyCaptureWorkerEntry.js +34 -0
- package/dist/proxy/proxyAnalysis.js +159 -17
- package/dist/proxy/proxyLifecycle.d.ts +25 -0
- package/dist/proxy/proxyLifecycle.js +111 -5
- package/dist/proxy/proxyRequestKind.d.ts +2 -0
- package/dist/proxy/proxyRequestKind.js +6 -0
- package/dist/proxy/proxyRuntimeMetrics.d.ts +3 -0
- package/dist/proxy/proxyRuntimeMetrics.js +34 -0
- package/dist/proxy/requestLogger.d.ts +10 -6
- package/dist/proxy/requestLogger.js +99 -231
- package/dist/proxy/rollingProxyServer.js +15 -4
- package/dist/proxy/rollingWorkerProcess.d.ts +4 -0
- package/dist/proxy/rollingWorkerProcess.js +25 -8
- package/dist/proxy/rollingWorkerProtocol.d.ts +6 -0
- package/dist/proxy/rollingWorkerProtocol.js +12 -1
- package/dist/proxy/rollingWorkerSupervisor.d.ts +28 -0
- package/dist/proxy/rollingWorkerSupervisor.js +73 -25
- package/dist/proxy/socketWorkerRuntime.d.ts +5 -0
- package/dist/proxy/socketWorkerRuntime.js +19 -2
- package/dist/server/routes/codexProxyRoutes.js +39 -3
- package/dist/services/server/ai/observability/instrumentation.js +7 -1
- package/dist/types/cli.d.ts +1 -1
- package/dist/types/proxy.d.ts +69 -4
- package/package.json +1 -1
- package/dist/core/modules/GenerationHandler.d.ts +0 -145
- package/dist/core/modules/GenerationHandler.js +0 -754
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generation Handler Module
|
|
3
|
-
*
|
|
4
|
-
* Handles text generation execution, result formatting, and tool information extraction.
|
|
5
|
-
* Extracted from BaseProvider to follow Single Responsibility Principle.
|
|
6
|
-
*
|
|
7
|
-
* Responsibilities:
|
|
8
|
-
* - Generation execution with AI SDK
|
|
9
|
-
* - Tool information extraction
|
|
10
|
-
* - Result formatting and enhancement
|
|
11
|
-
* - Response analysis and logging
|
|
12
|
-
*
|
|
13
|
-
* @module core/modules/GenerationHandler
|
|
14
|
-
*/
|
|
15
|
-
import type { GenerateTextResult, AIProviderName, EnhancedGenerateResult, NeuroLinkEvents, StandardRecord, TextGenerationOptions, ToolExecutionRecord, TypedEventEmitter } from "../../types/index.js";
|
|
16
|
-
import type { LanguageModel, ModelMessage, Tool } from "../../types/index.js";
|
|
17
|
-
/**
|
|
18
|
-
* Turn budget + wrap-up deadline (parity with the googleVertex native loops).
|
|
19
|
-
* A deadline is engaged only when the caller expressed one: turnTimeoutMs
|
|
20
|
-
* wins, else an explicit generate timeout. Callers that set neither keep the
|
|
21
|
-
* pre-existing behaviour (no wrap-up; the outer defensive timeout in
|
|
22
|
-
* executeStandardGenerateFlow still applies). With `wrapupTimeLeadMs` left of
|
|
23
|
-
* the deadline, the loop stops offering tools (toolChoice: "none") so the
|
|
24
|
-
* model spends the remaining budget producing a final answer instead of being
|
|
25
|
-
* guillotined mid-tool-loop with all work discarded. The lead is clamped to a
|
|
26
|
-
* quarter of the budget so short explicit timeouts (e.g. 30s) don't trigger
|
|
27
|
-
* wrap-up on the very first step.
|
|
28
|
-
*
|
|
29
|
-
* `turnStartMs` anchors the deadline to the ORIGINAL generation start:
|
|
30
|
-
* callGenerateText re-runs on executeGeneration's fallback retries
|
|
31
|
-
* (structured-output conflict, temperature-deprecated) and provider retries,
|
|
32
|
-
* and a deadline computed from Date.now() per attempt would hand each retry
|
|
33
|
-
* a fresh budget — multiplying the caller's wall-clock cap.
|
|
34
|
-
*/
|
|
35
|
-
export declare function resolveTurnBudget(options: TextGenerationOptions, turnStartMs: number): {
|
|
36
|
-
callerTimeoutMs: number | undefined;
|
|
37
|
-
turnBudgetMs: number | undefined;
|
|
38
|
-
wrapupLeadMs: number;
|
|
39
|
-
turnDeadline: number | undefined;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* GenerationHandler class - Handles text generation operations for AI providers
|
|
43
|
-
*/
|
|
44
|
-
export declare class GenerationHandler {
|
|
45
|
-
private readonly providerName;
|
|
46
|
-
private readonly modelName;
|
|
47
|
-
private readonly supportsToolsFn;
|
|
48
|
-
private readonly getTelemetryConfigFn;
|
|
49
|
-
private readonly handleToolStorageFn;
|
|
50
|
-
/**
|
|
51
|
-
* The remaining, optional dependencies.
|
|
52
|
-
*
|
|
53
|
-
* Grouped rather than added as further positional parameters: the
|
|
54
|
-
* constructor is already at the six-parameter cap, and both of these are
|
|
55
|
-
* optional injection seams rather than required collaborators.
|
|
56
|
-
*
|
|
57
|
-
* `generateTextFn` exists because every other dependency of this class
|
|
58
|
-
* arrives through the constructor while `generateText` was reached by
|
|
59
|
-
* static import. `utils/generation.ts` is a bare re-export of `ai`, and an
|
|
60
|
-
* ESM re-export cannot be substituted from a test, so asserting on the
|
|
61
|
-
* arguments this class builds — the entire contract of the system-message
|
|
62
|
-
* hoisting below — had no seam to work through. Production passes neither.
|
|
63
|
-
*/
|
|
64
|
-
private readonly deps;
|
|
65
|
-
constructor(providerName: AIProviderName, modelName: string, supportsToolsFn: () => boolean, getTelemetryConfigFn: (options: TextGenerationOptions, type: string) => {
|
|
66
|
-
isEnabled: boolean;
|
|
67
|
-
functionId?: string;
|
|
68
|
-
metadata?: Record<string, string | number | boolean>;
|
|
69
|
-
} | undefined, handleToolStorageFn: (toolCalls: unknown[], toolResults: unknown[], options: TextGenerationOptions, timestamp: Date) => Promise<void>,
|
|
70
|
-
/**
|
|
71
|
-
* The remaining, optional dependencies.
|
|
72
|
-
*
|
|
73
|
-
* Grouped rather than added as further positional parameters: the
|
|
74
|
-
* constructor is already at the six-parameter cap, and both of these are
|
|
75
|
-
* optional injection seams rather than required collaborators.
|
|
76
|
-
*
|
|
77
|
-
* `generateTextFn` exists because every other dependency of this class
|
|
78
|
-
* arrives through the constructor while `generateText` was reached by
|
|
79
|
-
* static import. `utils/generation.ts` is a bare re-export of `ai`, and an
|
|
80
|
-
* ESM re-export cannot be substituted from a test, so asserting on the
|
|
81
|
-
* arguments this class builds — the entire contract of the system-message
|
|
82
|
-
* hoisting below — had no seam to work through. Production passes neither.
|
|
83
|
-
*/
|
|
84
|
-
deps?: {
|
|
85
|
-
getEmitterFn?: () => TypedEventEmitter<NeuroLinkEvents> | undefined;
|
|
86
|
-
generateTextFn?: (options: Record<string, unknown>) => Promise<GenerateTextResult<Record<string, Tool>, unknown>>;
|
|
87
|
-
});
|
|
88
|
-
/**
|
|
89
|
-
* Helper method to call generateText with optional structured output
|
|
90
|
-
* @private
|
|
91
|
-
*/
|
|
92
|
-
/**
|
|
93
|
-
* The ai-package generate loop.
|
|
94
|
-
*
|
|
95
|
-
* Unreachable: every text provider now implements a native generate() and
|
|
96
|
-
* none of them return here. That was established by trapping the seam —
|
|
97
|
-
* replacing the ai package's generateText with a throwing stub left the full
|
|
98
|
-
* provider matrix passing and zero cells reaching it — and non-text request
|
|
99
|
-
* kinds return from runGenerateInActiveContext before this handler is
|
|
100
|
-
* consulted.
|
|
101
|
-
*
|
|
102
|
-
* Kept as an explicit failure rather than deleted outright so a provider
|
|
103
|
-
* added without a native generate() fails loudly here instead of silently
|
|
104
|
-
* reintroducing a dependency on the removed package.
|
|
105
|
-
*/
|
|
106
|
-
private callGenerateText;
|
|
107
|
-
executeGeneration(model: LanguageModel, messages: ModelMessage[], tools: Record<string, Tool>, options: TextGenerationOptions): Promise<GenerateTextResult<Record<string, Tool>, unknown>>;
|
|
108
|
-
/**
|
|
109
|
-
* Extract cache metrics from provider metadata (e.g. Anthropic's providerMetadata.anthropic)
|
|
110
|
-
* The AI SDK's LanguageModelUsage only has inputTokens/outputTokens.
|
|
111
|
-
* Cache metrics are surfaced via providerMetadata by provider-specific SDK adapters.
|
|
112
|
-
*/
|
|
113
|
-
/**
|
|
114
|
-
* Set gen_ai usage attributes + cache-aware cost on the span from the
|
|
115
|
-
* CROSS-STEP aggregate (result.totalUsage). result.usage is the LAST step
|
|
116
|
-
* only — using it undercounted every multi-step tool loop, and pricing the
|
|
117
|
-
* raw cache-inclusive inputTokens without the cache fields billed cache
|
|
118
|
-
* reads at the full input rate.
|
|
119
|
-
*/
|
|
120
|
-
private setUsageSpanAttributes;
|
|
121
|
-
private extractCacheMetricsFromProviderMetadata;
|
|
122
|
-
/**
|
|
123
|
-
* Log generation completion information
|
|
124
|
-
*/
|
|
125
|
-
logGenerationComplete(generateResult: GenerateTextResult<Record<string, Tool>, unknown>): void;
|
|
126
|
-
/**
|
|
127
|
-
* Extract tool information from generation result
|
|
128
|
-
*/
|
|
129
|
-
extractToolInformation(generateResult: GenerateTextResult<Record<string, Tool>, unknown>): {
|
|
130
|
-
toolsUsed: string[];
|
|
131
|
-
toolExecutions: Array<{
|
|
132
|
-
name: string;
|
|
133
|
-
input: StandardRecord;
|
|
134
|
-
output: unknown;
|
|
135
|
-
}>;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Format the enhanced result
|
|
139
|
-
*/
|
|
140
|
-
formatEnhancedResult(generateResult: GenerateTextResult<Record<string, Tool>, unknown>, tools: Record<string, Tool>, toolsUsed: string[], toolExecutions: ToolExecutionRecord[], options: TextGenerationOptions): EnhancedGenerateResult;
|
|
141
|
-
/**
|
|
142
|
-
* Analyze AI response structure and log detailed debugging information
|
|
143
|
-
*/
|
|
144
|
-
analyzeAIResponse(rawResult: unknown): void;
|
|
145
|
-
}
|