@juspay/neurolink 9.79.3 → 9.80.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 +12 -0
- package/dist/browser/neurolink.min.js +349 -348
- package/dist/cli/factories/commandFactory.js +61 -0
- package/dist/cli/utils/classifierRouterFlags.d.ts +19 -0
- package/dist/cli/utils/classifierRouterFlags.js +111 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/neurolink.d.ts +14 -0
- package/dist/lib/neurolink.js +131 -0
- package/dist/lib/providers/googleVertex.d.ts +3 -1
- package/dist/lib/providers/googleVertex.js +160 -38
- package/dist/lib/routing/classifierRouter.d.ts +52 -0
- package/dist/lib/routing/classifierRouter.js +269 -0
- package/dist/lib/routing/classifierStrategies.d.ts +23 -0
- package/dist/lib/routing/classifierStrategies.js +156 -0
- package/dist/lib/routing/index.d.ts +2 -0
- package/dist/lib/routing/index.js +2 -0
- package/dist/lib/session/globalSessionState.d.ts +10 -1
- package/dist/lib/session/globalSessionState.js +18 -0
- package/dist/lib/types/classifierRouter.d.ts +193 -0
- package/dist/lib/types/classifierRouter.js +17 -0
- package/dist/lib/types/cli.d.ts +27 -3
- package/dist/lib/types/config.d.ts +10 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +2 -0
- package/dist/neurolink.d.ts +14 -0
- package/dist/neurolink.js +131 -0
- package/dist/providers/googleVertex.d.ts +3 -1
- package/dist/providers/googleVertex.js +160 -38
- package/dist/routing/classifierRouter.d.ts +52 -0
- package/dist/routing/classifierRouter.js +268 -0
- package/dist/routing/classifierStrategies.d.ts +23 -0
- package/dist/routing/classifierStrategies.js +155 -0
- package/dist/routing/index.d.ts +2 -0
- package/dist/routing/index.js +2 -0
- package/dist/session/globalSessionState.d.ts +10 -1
- package/dist/session/globalSessionState.js +18 -0
- package/dist/types/classifierRouter.d.ts +193 -0
- package/dist/types/classifierRouter.js +16 -0
- package/dist/types/cli.d.ts +27 -3
- package/dist/types/config.d.ts +10 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/package.json +2 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClassifierRouter types — generic "classify → pick model + tools → run".
|
|
3
|
+
*
|
|
4
|
+
* A ClassifierRouter inspects an incoming request, classifies it by difficulty
|
|
5
|
+
* (and optional required capabilities / suggested tools), then selects a
|
|
6
|
+
* provider/model from a host-declared "available base" pool — routing harder
|
|
7
|
+
* tasks to more capable models and easier tasks to cheaper/faster ones — and
|
|
8
|
+
* optionally narrows the tool set for that request.
|
|
9
|
+
*
|
|
10
|
+
* It is entirely opt-in (constructor config, `enabled: false` by default) and
|
|
11
|
+
* fails open: any classifier or selection error leaves the call unrouted.
|
|
12
|
+
*
|
|
13
|
+
* Type names are domain-prefixed `Classifier*` to stay globally unique across
|
|
14
|
+
* `src/lib/types/` (see CLAUDE.md rule 9).
|
|
15
|
+
*/
|
|
16
|
+
/** Coarse difficulty buckets the classifier maps a request into. */
|
|
17
|
+
export type ClassifierDifficulty = "trivial" | "simple" | "moderate" | "hard" | "expert";
|
|
18
|
+
/** Which classification strategy to run. */
|
|
19
|
+
export type ClassifierStrategyKind = "heuristic" | "llm";
|
|
20
|
+
/**
|
|
21
|
+
* The classifier's verdict for a single request. Strategy-agnostic: produced
|
|
22
|
+
* by both the heuristic and the LLM classifier.
|
|
23
|
+
*/
|
|
24
|
+
export type ClassifierDecision = {
|
|
25
|
+
/** The classified difficulty bucket. */
|
|
26
|
+
difficulty: ClassifierDifficulty;
|
|
27
|
+
/** Confidence in the classification (0–1). */
|
|
28
|
+
confidence: number;
|
|
29
|
+
/** Capability tags the request needs (e.g. "vision", "tools", "reasoning"). */
|
|
30
|
+
requiredCapabilities?: string[];
|
|
31
|
+
/** Tool names the classifier thinks the task needs (allowlist hint). */
|
|
32
|
+
suggestedTools?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* When the LLM classifier picks a model directly, the chosen candidate id
|
|
35
|
+
* (matches a `ClassifierCandidate.id`). Ignored by the heuristic classifier.
|
|
36
|
+
*/
|
|
37
|
+
selectedModelId?: string;
|
|
38
|
+
/** Human-readable explanation, emitted at debug level. */
|
|
39
|
+
reason?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Lightweight model descriptor handed to the LLM classifier so it can select a
|
|
43
|
+
* model directly from the pool by `id` — the generic path for custom models.
|
|
44
|
+
*/
|
|
45
|
+
export type ClassifierCandidate = {
|
|
46
|
+
id: string;
|
|
47
|
+
provider: string;
|
|
48
|
+
model?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
tiers?: ClassifierDifficulty[];
|
|
51
|
+
capabilities?: string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* One candidate (provider, model, region) in the available base pool, with
|
|
55
|
+
* optional routing metadata. When `cost`/`quality`/`capabilities` are omitted,
|
|
56
|
+
* the router enriches them from the model registry (by `model` name/alias).
|
|
57
|
+
*/
|
|
58
|
+
export type ClassifierRouterPoolMember = {
|
|
59
|
+
provider: string;
|
|
60
|
+
model?: string;
|
|
61
|
+
region?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Stable id the LLM classifier references when selecting a model directly.
|
|
64
|
+
* Defaults to `${provider}/${model}` (or just `provider`) when omitted.
|
|
65
|
+
*/
|
|
66
|
+
id?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Plain-English description of when to use this model (e.g. "cheap & fast,
|
|
69
|
+
* for simple Q&A" / "powerful reasoning model for complex analysis"). Drives
|
|
70
|
+
* LLM-based model selection — the only metadata needed for custom models that
|
|
71
|
+
* are NOT in the registry (LiteLLM, OpenAI-compatible, self-hosted, …).
|
|
72
|
+
*/
|
|
73
|
+
description?: string;
|
|
74
|
+
/** Difficulty tiers this member is eligible for. Omit = eligible for all. */
|
|
75
|
+
tiers?: ClassifierDifficulty[];
|
|
76
|
+
/** Relative cost (lower = cheaper). Preferred for easy tiers. */
|
|
77
|
+
cost?: number;
|
|
78
|
+
/** Relative quality/capability (higher = more capable). Preferred for hard tiers. */
|
|
79
|
+
quality?: number;
|
|
80
|
+
/** Capability tags this member supports (e.g. "vision", "tools"). */
|
|
81
|
+
capabilities?: string[];
|
|
82
|
+
/** Tiebreak weight when scores are equal. Default: 1. */
|
|
83
|
+
weight?: number;
|
|
84
|
+
};
|
|
85
|
+
/** Per-difficulty tool policy applied to the request. */
|
|
86
|
+
export type ClassifierToolDirective = {
|
|
87
|
+
/** Allowlist of tool names to keep (maps to `options.toolFilter`). */
|
|
88
|
+
toolFilter?: string[];
|
|
89
|
+
/** Denylist of tool names to drop (appended to `options.excludeTools`). */
|
|
90
|
+
excludeTools?: string[];
|
|
91
|
+
};
|
|
92
|
+
/** Provider/model the LLM classifier strategy itself runs on. */
|
|
93
|
+
export type ClassifierModelRef = {
|
|
94
|
+
provider?: string;
|
|
95
|
+
model?: string;
|
|
96
|
+
region?: string;
|
|
97
|
+
temperature?: number;
|
|
98
|
+
};
|
|
99
|
+
/** Constructor-level configuration for the classifier router. */
|
|
100
|
+
export type ClassifierRouterConfig = {
|
|
101
|
+
/** Master switch. When false/absent, the router is never built. */
|
|
102
|
+
enabled: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Classification strategy. Default: "heuristic" (no LLM, zero added latency).
|
|
105
|
+
* "llm" runs a cheap classifier model (see `classifierModel`).
|
|
106
|
+
*/
|
|
107
|
+
classifier?: ClassifierStrategyKind;
|
|
108
|
+
/** Model used by the "llm" strategy. Defaults to provider/model auto. */
|
|
109
|
+
classifierModel?: ClassifierModelRef;
|
|
110
|
+
/** The available base pool the router selects a model from. */
|
|
111
|
+
pool: ClassifierRouterPoolMember[];
|
|
112
|
+
/**
|
|
113
|
+
* Explicit difficulty → members map. When a difficulty has entries here they
|
|
114
|
+
* take precedence over metadata scoring of `pool`.
|
|
115
|
+
*/
|
|
116
|
+
tierMap?: Partial<Record<ClassifierDifficulty, ClassifierRouterPoolMember[]>>;
|
|
117
|
+
/** Per-difficulty tool directives applied to the request. */
|
|
118
|
+
toolDirectives?: Partial<Record<ClassifierDifficulty, ClassifierToolDirective>>;
|
|
119
|
+
/** Hard timeout (ms) for the LLM classifier call. Default: 8000. */
|
|
120
|
+
timeoutMs?: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* The router's combined decision: a provider/model/region override plus an
|
|
124
|
+
* optional tool narrowing. Any undefined field means "keep what the caller
|
|
125
|
+
* already configured". Returning `null` from the router is a valid no-op.
|
|
126
|
+
*/
|
|
127
|
+
export type ClassifierRouterDecision = {
|
|
128
|
+
provider?: string;
|
|
129
|
+
model?: string;
|
|
130
|
+
region?: string;
|
|
131
|
+
/** Allowlist applied to `options.toolFilter`. */
|
|
132
|
+
toolFilter?: string[];
|
|
133
|
+
/** Denylist appended to `options.excludeTools`. */
|
|
134
|
+
excludeTools?: string[];
|
|
135
|
+
/** The difficulty this decision was made for (debug/telemetry). */
|
|
136
|
+
difficulty?: ClassifierDifficulty;
|
|
137
|
+
/** Remaining ranked candidates, best-first, for downstream failover. */
|
|
138
|
+
modelFallbacks?: ClassifierRouterPoolMember[];
|
|
139
|
+
/** Human-readable explanation, emitted at debug level. */
|
|
140
|
+
reason?: string;
|
|
141
|
+
};
|
|
142
|
+
/** Lightweight request snapshot handed to the router. */
|
|
143
|
+
export type ClassifierRouterInput = {
|
|
144
|
+
prompt: string;
|
|
145
|
+
estimatedInputTokens?: number;
|
|
146
|
+
hasTools?: boolean;
|
|
147
|
+
requiresVision?: boolean;
|
|
148
|
+
thinkingLevel?: string;
|
|
149
|
+
sessionId?: string;
|
|
150
|
+
};
|
|
151
|
+
/** Enriched per-model metadata used while ranking pool members. */
|
|
152
|
+
export type ClassifierModelMeta = {
|
|
153
|
+
cost?: number;
|
|
154
|
+
quality?: number;
|
|
155
|
+
capabilities?: string[];
|
|
156
|
+
};
|
|
157
|
+
/** Minimal options accepted by the injected LLM-classifier `generate` fn. */
|
|
158
|
+
export type ClassifierGenerateOptions = {
|
|
159
|
+
input: {
|
|
160
|
+
text: string;
|
|
161
|
+
};
|
|
162
|
+
systemPrompt?: string;
|
|
163
|
+
provider?: string;
|
|
164
|
+
model?: string;
|
|
165
|
+
region?: string;
|
|
166
|
+
temperature?: number;
|
|
167
|
+
maxTokens?: number;
|
|
168
|
+
disableTools?: boolean;
|
|
169
|
+
schema?: unknown;
|
|
170
|
+
timeout?: number | string;
|
|
171
|
+
context?: Record<string, unknown>;
|
|
172
|
+
};
|
|
173
|
+
/** Minimal result shape the LLM classifier reads back. */
|
|
174
|
+
export type ClassifierGenerateResult = {
|
|
175
|
+
content?: string;
|
|
176
|
+
structuredData?: unknown;
|
|
177
|
+
};
|
|
178
|
+
/** Injected LLM caller — typically a bound `NeuroLink.generate`. */
|
|
179
|
+
export type ClassifierGenerateFn = (options: ClassifierGenerateOptions) => Promise<ClassifierGenerateResult>;
|
|
180
|
+
/** Minimal logger surface the router uses (debug/warn). */
|
|
181
|
+
export type ClassifierLogger = {
|
|
182
|
+
debug: (message: string, meta?: unknown) => void;
|
|
183
|
+
warn: (message: string, meta?: unknown) => void;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Injected dependencies — keep `ClassifierRouter` provider-import-free and
|
|
187
|
+
* unit-testable (mirrors the `toolRouting` generateFn-injection pattern).
|
|
188
|
+
*/
|
|
189
|
+
export type ClassifierRouterDeps = {
|
|
190
|
+
/** LLM caller for the "llm" strategy. Omit to disable LLM classification. */
|
|
191
|
+
generate?: ClassifierGenerateFn;
|
|
192
|
+
logger?: ClassifierLogger;
|
|
193
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClassifierRouter types — generic "classify → pick model + tools → run".
|
|
3
|
+
*
|
|
4
|
+
* A ClassifierRouter inspects an incoming request, classifies it by difficulty
|
|
5
|
+
* (and optional required capabilities / suggested tools), then selects a
|
|
6
|
+
* provider/model from a host-declared "available base" pool — routing harder
|
|
7
|
+
* tasks to more capable models and easier tasks to cheaper/faster ones — and
|
|
8
|
+
* optionally narrows the tool set for that request.
|
|
9
|
+
*
|
|
10
|
+
* It is entirely opt-in (constructor config, `enabled: false` by default) and
|
|
11
|
+
* fails open: any classifier or selection error leaves the call unrouted.
|
|
12
|
+
*
|
|
13
|
+
* Type names are domain-prefixed `Classifier*` to stay globally unique across
|
|
14
|
+
* `src/lib/types/` (see CLAUDE.md rule 9).
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
package/dist/types/cli.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type BaseCommandArgs = {
|
|
|
45
45
|
/**
|
|
46
46
|
* Generate command arguments
|
|
47
47
|
*/
|
|
48
|
-
export type GenerateCommandArgs = BaseCommandArgs & CliToolRoutingFlags & {
|
|
48
|
+
export type GenerateCommandArgs = BaseCommandArgs & CliToolRoutingFlags & CliClassifierRouterFlags & {
|
|
49
49
|
/** Input text or prompt */
|
|
50
50
|
input?: string;
|
|
51
51
|
/** AI provider to use */
|
|
@@ -110,7 +110,7 @@ export type GenerateCommandArgs = BaseCommandArgs & CliToolRoutingFlags & {
|
|
|
110
110
|
/**
|
|
111
111
|
* Stream command arguments
|
|
112
112
|
*/
|
|
113
|
-
export type StreamCommandArgs = BaseCommandArgs & CliToolRoutingFlags & {
|
|
113
|
+
export type StreamCommandArgs = BaseCommandArgs & CliToolRoutingFlags & CliClassifierRouterFlags & {
|
|
114
114
|
/** Input text or prompt */
|
|
115
115
|
input?: string;
|
|
116
116
|
/** AI provider to use */
|
|
@@ -137,7 +137,7 @@ export type StreamCommandArgs = BaseCommandArgs & CliToolRoutingFlags & {
|
|
|
137
137
|
/**
|
|
138
138
|
* Batch command arguments
|
|
139
139
|
*/
|
|
140
|
-
export type BatchCommandArgs = BaseCommandArgs & CliToolRoutingFlags & {
|
|
140
|
+
export type BatchCommandArgs = BaseCommandArgs & CliToolRoutingFlags & CliClassifierRouterFlags & {
|
|
141
141
|
/** Input file path */
|
|
142
142
|
file?: string;
|
|
143
143
|
/** AI provider to use */
|
|
@@ -1526,3 +1526,27 @@ export type CliToolRoutingFlags = {
|
|
|
1526
1526
|
*/
|
|
1527
1527
|
toolRoutingServers?: string;
|
|
1528
1528
|
};
|
|
1529
|
+
/**
|
|
1530
|
+
* CLI flags for the classifier router (`--classifier-*`). Builds a
|
|
1531
|
+
* ClassifierRouterConfig that is injected at SDK construction time.
|
|
1532
|
+
*/
|
|
1533
|
+
export type CliClassifierRouterFlags = {
|
|
1534
|
+
/** Master enable switch (--classifier-router). */
|
|
1535
|
+
classifierRouter?: boolean;
|
|
1536
|
+
/** Strategy: "heuristic" (default) or "llm" (--classifier-strategy). */
|
|
1537
|
+
classifierStrategy?: string;
|
|
1538
|
+
/** LLM-classifier provider override (--classifier-model-provider). */
|
|
1539
|
+
classifierModelProvider?: string;
|
|
1540
|
+
/** LLM-classifier model override (--classifier-model-name). */
|
|
1541
|
+
classifierModelName?: string;
|
|
1542
|
+
/** LLM-classifier region override (--classifier-model-region). */
|
|
1543
|
+
classifierModelRegion?: string;
|
|
1544
|
+
/**
|
|
1545
|
+
* Path to a JSON file OR inline JSON array of pool members
|
|
1546
|
+
* (--classifier-pool). Each entry: { provider, model?, region?, description?,
|
|
1547
|
+
* tiers?, cost?, quality?, capabilities?, id? }.
|
|
1548
|
+
*/
|
|
1549
|
+
classifierPool?: string;
|
|
1550
|
+
/** LLM-classifier hard timeout in ms (--classifier-timeout). */
|
|
1551
|
+
classifierTimeout?: number;
|
|
1552
|
+
};
|
package/dist/types/config.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { AuthProvider, AuthProviderType, AuthProviderConfig, Auth0Config, C
|
|
|
11
11
|
import type { NeurolinkCredentials } from "./providers.js";
|
|
12
12
|
import type { ModelPoolConfig } from "./modelPool.js";
|
|
13
13
|
import type { RequestRouter } from "./requestRouter.js";
|
|
14
|
+
import type { ClassifierRouterConfig } from "./classifierRouter.js";
|
|
14
15
|
/**
|
|
15
16
|
* Main NeuroLink configuration type
|
|
16
17
|
*/
|
|
@@ -104,6 +105,15 @@ export type NeurolinkConstructorConfig = {
|
|
|
104
105
|
* error proceeds unrouted.
|
|
105
106
|
*/
|
|
106
107
|
requestRouter?: RequestRouter;
|
|
108
|
+
/**
|
|
109
|
+
* Pre-call classifier router: classifies each request by difficulty and
|
|
110
|
+
* selects a provider/model from a configured "available base" pool — routing
|
|
111
|
+
* harder tasks to more capable models and easier tasks to cheaper/faster
|
|
112
|
+
* ones — and optionally narrows the tool set. Opt-in (`enabled: false` by
|
|
113
|
+
* default) and fails open. Skipped when a `modelPool` is configured or the
|
|
114
|
+
* caller pinned both `provider` and `model`. See {@link ClassifierRouterConfig}.
|
|
115
|
+
*/
|
|
116
|
+
classifierRouter?: ClassifierRouterConfig;
|
|
107
117
|
};
|
|
108
118
|
/**
|
|
109
119
|
* Configuration for MCP enhancement modules wired into generate()/stream() paths.
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -80,3 +80,5 @@ export * from "./safeFetch.js";
|
|
|
80
80
|
export * from "./modelPool.js";
|
|
81
81
|
// RequestRouter — pluggable pre-call provider/model selection (M9.x+)
|
|
82
82
|
export * from "./requestRouter.js";
|
|
83
|
+
// ClassifierRouter — classify → pick model + tools from a base pool (M9.x+)
|
|
84
|
+
export * from "./classifierRouter.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.80.1",
|
|
4
4
|
"packageManager": "pnpm@10.15.1",
|
|
5
5
|
"description": "Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applications with 21+ providers: OpenAI, Anthropic, Google AI Studio, Google Vertex, AWS Bedrock, Azure OpenAI, Mistral, LiteLLM, SageMaker, Hugging Face, Ollama, OpenAI-compatible, OpenRouter, DeepSeek, NVIDIA NIM, LM Studio, llama.cpp, plus voice (OpenAI TTS, ElevenLabs, Deepgram, Azure Speech).",
|
|
6
6
|
"author": {
|
|
@@ -132,6 +132,7 @@
|
|
|
132
132
|
"// CI tier — fast, no live AI calls, safe for every commit": "",
|
|
133
133
|
"test:unit:vitest": "pnpm exec vitest run test/toolRouting.test.ts",
|
|
134
134
|
"test:tool-routing": "pnpm run test:unit:vitest && npx tsx test/continuous-test-suite-tool-routing.ts",
|
|
135
|
+
"test:classifier-router": "npx tsx test/continuous-test-suite-classifier-router.ts",
|
|
135
136
|
"test:tool-routing-semantic:vitest": "pnpm exec vitest run test/toolRoutingSemantic.test.ts",
|
|
136
137
|
"test:tool-routing-semantic": "pnpm run test:tool-routing-semantic:vitest && npx tsx test/continuous-test-suite-tool-routing-semantic.ts",
|
|
137
138
|
"test:unit": "pnpm run test:envguard && pnpm run test:bugfixes && pnpm run test:mcp:infra && pnpm run test:mcp:bash && pnpm run test:mcp:limits && pnpm run test:mcp:spans && pnpm run test:autoresearch:redis && pnpm run test:unit:vitest && pnpm run test:tool-routing-cli:vitest && pnpm run test:tool-dedup:vitest && pnpm run test:model-pool:vitest && pnpm run test:tool-routing-semantic:vitest && pnpm run test:anthropic-tools-policy && pnpm run test:anthropic-multimodal && pnpm run test:excel-interop",
|