@juspay/neurolink 9.82.0 → 9.84.0
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 +18 -0
- package/dist/agent/agent.d.ts +104 -0
- package/dist/agent/agent.js +401 -0
- package/dist/agent/agentNetwork.d.ts +87 -0
- package/dist/agent/agentNetwork.js +458 -0
- package/dist/agent/communication/index.d.ts +9 -0
- package/dist/agent/communication/index.js +9 -0
- package/dist/agent/communication/message-bus.d.ts +113 -0
- package/dist/agent/communication/message-bus.js +406 -0
- package/dist/agent/coordination/coordinator.d.ts +83 -0
- package/dist/agent/coordination/coordinator.js +598 -0
- package/dist/agent/coordination/index.d.ts +10 -0
- package/dist/agent/coordination/index.js +10 -0
- package/dist/agent/coordination/task-distributor.d.ts +113 -0
- package/dist/agent/coordination/task-distributor.js +585 -0
- package/dist/agent/index.d.ts +38 -0
- package/dist/agent/index.js +44 -0
- package/dist/agent/orchestration/index.d.ts +10 -0
- package/dist/agent/orchestration/index.js +10 -0
- package/dist/agent/orchestration/orchestrator.d.ts +114 -0
- package/dist/agent/orchestration/orchestrator.js +476 -0
- package/dist/agent/orchestration/topology.d.ts +164 -0
- package/dist/agent/orchestration/topology.js +520 -0
- package/dist/agent/prompts/routingPrompts.d.ts +63 -0
- package/dist/agent/prompts/routingPrompts.js +201 -0
- package/dist/browser/neurolink.min.js +377 -358
- package/dist/cli/commands/agent.d.ts +37 -0
- package/dist/cli/commands/agent.js +718 -0
- package/dist/cli/factories/commandFactory.d.ts +8 -0
- package/dist/cli/factories/commandFactory.js +116 -0
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/cli/parser.js +4 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/lib/agent/agent.d.ts +104 -0
- package/dist/lib/agent/agent.js +402 -0
- package/dist/lib/agent/agentNetwork.d.ts +87 -0
- package/dist/lib/agent/agentNetwork.js +459 -0
- package/dist/lib/agent/communication/index.d.ts +9 -0
- package/dist/lib/agent/communication/index.js +10 -0
- package/dist/lib/agent/communication/message-bus.d.ts +113 -0
- package/dist/lib/agent/communication/message-bus.js +407 -0
- package/dist/lib/agent/coordination/coordinator.d.ts +83 -0
- package/dist/lib/agent/coordination/coordinator.js +599 -0
- package/dist/lib/agent/coordination/index.d.ts +10 -0
- package/dist/lib/agent/coordination/index.js +11 -0
- package/dist/lib/agent/coordination/task-distributor.d.ts +113 -0
- package/dist/lib/agent/coordination/task-distributor.js +586 -0
- package/dist/lib/agent/index.d.ts +38 -0
- package/dist/lib/agent/index.js +45 -0
- package/dist/lib/agent/orchestration/index.d.ts +10 -0
- package/dist/lib/agent/orchestration/index.js +11 -0
- package/dist/lib/agent/orchestration/orchestrator.d.ts +114 -0
- package/dist/lib/agent/orchestration/orchestrator.js +477 -0
- package/dist/lib/agent/orchestration/topology.d.ts +164 -0
- package/dist/lib/agent/orchestration/topology.js +521 -0
- package/dist/lib/agent/prompts/routingPrompts.d.ts +63 -0
- package/dist/lib/agent/prompts/routingPrompts.js +202 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +19 -0
- package/dist/lib/neurolink.d.ts +129 -0
- package/dist/lib/neurolink.js +276 -0
- package/dist/lib/processors/config/{fileTypes.js → fileExtensions.js} +1 -1
- package/dist/lib/processors/config/index.d.ts +2 -2
- package/dist/lib/processors/config/index.js +2 -2
- package/dist/lib/processors/config/{mimeTypes.js → mimeConstants.js} +1 -1
- package/dist/lib/processors/index.js +8 -0
- package/dist/lib/providers/googleAiStudio.js +28 -7
- package/dist/lib/providers/googleNativeGemini3.d.ts +18 -0
- package/dist/lib/providers/googleNativeGemini3.js +69 -3
- package/dist/lib/providers/googleVertex.js +33 -9
- package/dist/lib/types/agentNetwork.d.ts +1184 -0
- package/dist/lib/types/agentNetwork.js +8 -0
- package/dist/lib/types/cli.d.ts +66 -0
- package/dist/lib/types/common.d.ts +3 -0
- package/dist/lib/types/generate.d.ts +53 -0
- package/dist/lib/types/index.d.ts +2 -0
- package/dist/lib/types/index.js +3 -0
- package/dist/lib/types/ioProcessor.d.ts +119 -0
- package/dist/lib/types/ioProcessor.js +10 -0
- package/dist/lib/types/providers.d.ts +8 -0
- package/dist/lib/types/stream.d.ts +36 -0
- package/dist/lib/utils/piiDetector.d.ts +24 -0
- package/dist/lib/utils/piiDetector.js +221 -0
- package/dist/lib/utils/pricing.js +144 -26
- package/dist/lib/utils/responseValidator.d.ts +21 -0
- package/dist/lib/utils/responseValidator.js +354 -0
- package/dist/lib/utils/tokenUtils.d.ts +11 -0
- package/dist/lib/utils/tokenUtils.js +33 -2
- package/dist/lib/utils/tripwireEvaluator.d.ts +73 -0
- package/dist/lib/utils/tripwireEvaluator.js +285 -0
- package/dist/neurolink.d.ts +129 -0
- package/dist/neurolink.js +276 -0
- package/dist/processors/config/index.d.ts +2 -2
- package/dist/processors/config/index.js +2 -2
- package/dist/processors/index.js +8 -0
- package/dist/providers/googleAiStudio.js +28 -7
- package/dist/providers/googleNativeGemini3.d.ts +18 -0
- package/dist/providers/googleNativeGemini3.js +69 -3
- package/dist/providers/googleVertex.js +33 -9
- package/dist/types/agentNetwork.d.ts +1184 -0
- package/dist/types/agentNetwork.js +7 -0
- package/dist/types/cli.d.ts +66 -0
- package/dist/types/common.d.ts +3 -0
- package/dist/types/generate.d.ts +53 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/ioProcessor.d.ts +119 -0
- package/dist/types/ioProcessor.js +9 -0
- package/dist/types/providers.d.ts +8 -0
- package/dist/types/stream.d.ts +36 -0
- package/dist/utils/piiDetector.d.ts +24 -0
- package/dist/utils/piiDetector.js +220 -0
- package/dist/utils/pricing.js +144 -26
- package/dist/utils/responseValidator.d.ts +21 -0
- package/dist/utils/responseValidator.js +353 -0
- package/dist/utils/tokenUtils.d.ts +11 -0
- package/dist/utils/tokenUtils.js +33 -2
- package/dist/utils/tripwireEvaluator.d.ts +73 -0
- package/dist/utils/tripwireEvaluator.js +284 -0
- package/package.json +1 -1
- /package/dist/lib/processors/config/{fileTypes.d.ts → fileExtensions.d.ts} +0 -0
- /package/dist/lib/processors/config/{mimeTypes.d.ts → mimeConstants.d.ts} +0 -0
- /package/dist/processors/config/{fileTypes.d.ts → fileExtensions.d.ts} +0 -0
- /package/dist/processors/config/{fileTypes.js → fileExtensions.js} +0 -0
- /package/dist/processors/config/{mimeTypes.d.ts → mimeConstants.d.ts} +0 -0
- /package/dist/processors/config/{mimeTypes.js → mimeConstants.js} +0 -0
|
@@ -101,6 +101,23 @@ export function extractCacheReadTokens(usage) {
|
|
|
101
101
|
}
|
|
102
102
|
return undefined;
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Extract cache read token count from the OVERLAPPING-convention nested path
|
|
106
|
+
* used by OpenAI / DeepSeek / NIM / OpenAI-compatible providers:
|
|
107
|
+
* `usage.prompt_tokens_details.cached_tokens`.
|
|
108
|
+
*
|
|
109
|
+
* Unlike {@link extractCacheReadTokens} (non-overlapping Anthropic/Vertex
|
|
110
|
+
* convention where cache tokens are reported SEPARATELY from input), the value
|
|
111
|
+
* returned here is a SUBSET already included in `prompt_tokens`. Callers that
|
|
112
|
+
* use this value MUST subtract it from `input` to avoid double-counting.
|
|
113
|
+
*/
|
|
114
|
+
export function extractCachedInputTokensOverlapping(usage) {
|
|
115
|
+
const cached = usage.prompt_tokens_details?.cached_tokens;
|
|
116
|
+
if (typeof cached === "number" && cached > 0) {
|
|
117
|
+
return cached;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
104
121
|
/**
|
|
105
122
|
* Calculate cache savings percentage
|
|
106
123
|
*
|
|
@@ -149,13 +166,27 @@ export function extractTokenUsage(result, options = {}) {
|
|
|
149
166
|
// Handle nested usage object (some providers wrap usage in a usage property)
|
|
150
167
|
const usage = result.usage && typeof result.usage === "object" ? result.usage : result;
|
|
151
168
|
// Extract base token counts
|
|
152
|
-
|
|
169
|
+
let input = extractInputTokens(usage);
|
|
153
170
|
const output = extractOutputTokens(usage);
|
|
154
171
|
const total = extractTotalTokens(usage, input, output);
|
|
155
172
|
// Extract optional token fields
|
|
156
173
|
const reasoning = extractReasoningTokens(usage);
|
|
157
174
|
const cacheCreationTokens = extractCacheCreationTokens(usage);
|
|
158
|
-
|
|
175
|
+
let cacheReadTokens = extractCacheReadTokens(usage);
|
|
176
|
+
// Overlapping-convention fallback (OpenAI/DeepSeek/NIM/OpenAI-compatible):
|
|
177
|
+
// when no non-overlapping cache-read field was present, look for the nested
|
|
178
|
+
// `prompt_tokens_details.cached_tokens`. That value is a SUBSET already
|
|
179
|
+
// included in `input`, so we must subtract it from `input` to avoid
|
|
180
|
+
// double-counting (and to let calculateCost apply the cheaper cacheRead rate
|
|
181
|
+
// to the cached portion). Only do this when cached <= input so a malformed
|
|
182
|
+
// response can never produce negative input or inflate the total.
|
|
183
|
+
if (cacheReadTokens === undefined) {
|
|
184
|
+
const overlappingCached = extractCachedInputTokensOverlapping(usage);
|
|
185
|
+
if (overlappingCached !== undefined && overlappingCached <= input) {
|
|
186
|
+
cacheReadTokens = overlappingCached;
|
|
187
|
+
input = Math.max(0, input - overlappingCached);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
159
190
|
// Calculate cache savings if enabled
|
|
160
191
|
const cacheSavingsPercent = calculateCacheSavings
|
|
161
192
|
? calculateCacheSavingsPercent(cacheReadTokens, input)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TripwireEvaluator - Standalone health-check utility
|
|
3
|
+
*
|
|
4
|
+
* Evaluates blocking conditions against LLM response data to detect
|
|
5
|
+
* runtime issues such as empty responses, high latency, max tokens hit,
|
|
6
|
+
* and repetition loops.
|
|
7
|
+
*
|
|
8
|
+
* This module has no dependency on the processor pipeline system and can
|
|
9
|
+
* be used independently.
|
|
10
|
+
*
|
|
11
|
+
* @module utils/tripwireEvaluator
|
|
12
|
+
*/
|
|
13
|
+
import type { TripwireData, TripwireConfig, TripwireResult } from "../types/index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Manages and evaluates tripwire conditions against LLM response data.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const evaluator = createDefaultTripwireEvaluator();
|
|
20
|
+
*
|
|
21
|
+
* const result = evaluator.evaluate({
|
|
22
|
+
* responseText: "",
|
|
23
|
+
* latencyMs: 45000,
|
|
24
|
+
* finishReason: "length",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* if (result.triggered && result.action === "abort") {
|
|
28
|
+
* throw new Error(result.message);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class TripwireEvaluator {
|
|
33
|
+
private tripwires;
|
|
34
|
+
/**
|
|
35
|
+
* Register a tripwire. Replaces any existing tripwire with the same id.
|
|
36
|
+
*/
|
|
37
|
+
register(tripwire: TripwireConfig): void;
|
|
38
|
+
/**
|
|
39
|
+
* Remove a registered tripwire by id.
|
|
40
|
+
* @returns true if the tripwire was found and removed, false otherwise.
|
|
41
|
+
*/
|
|
42
|
+
unregister(id: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Evaluate all tripwires and return the highest-priority triggered result.
|
|
45
|
+
*
|
|
46
|
+
* Priority order: "abort" > "warn" > "log"
|
|
47
|
+
*
|
|
48
|
+
* Bug fix (C1): The original implementation returned on the FIRST triggered
|
|
49
|
+
* tripwire regardless of action, which meant a "warn" registered before an
|
|
50
|
+
* "abort" would mask the abort. This implementation evaluates ALL tripwires
|
|
51
|
+
* and promotes the highest-severity action.
|
|
52
|
+
*/
|
|
53
|
+
evaluate(data: TripwireData): TripwireResult;
|
|
54
|
+
/**
|
|
55
|
+
* Evaluate all tripwires and return every triggered result.
|
|
56
|
+
*/
|
|
57
|
+
evaluateAll(data: TripwireData): TripwireResult[];
|
|
58
|
+
/**
|
|
59
|
+
* Return a shallow copy of all registered tripwires.
|
|
60
|
+
*/
|
|
61
|
+
getTripwires(): TripwireConfig[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* All built-in tripwires in default registration order.
|
|
65
|
+
*
|
|
66
|
+
* Registration order does not affect priority — `evaluate()` always promotes
|
|
67
|
+
* the highest-severity action ("abort" > "warn" > "log").
|
|
68
|
+
*/
|
|
69
|
+
export declare const commonTripwires: TripwireConfig[];
|
|
70
|
+
/**
|
|
71
|
+
* Create a TripwireEvaluator pre-loaded with all built-in tripwires.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createDefaultTripwireEvaluator(): TripwireEvaluator;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TripwireEvaluator - Standalone health-check utility
|
|
3
|
+
*
|
|
4
|
+
* Evaluates blocking conditions against LLM response data to detect
|
|
5
|
+
* runtime issues such as empty responses, high latency, max tokens hit,
|
|
6
|
+
* and repetition loops.
|
|
7
|
+
*
|
|
8
|
+
* This module has no dependency on the processor pipeline system and can
|
|
9
|
+
* be used independently.
|
|
10
|
+
*
|
|
11
|
+
* @module utils/tripwireEvaluator
|
|
12
|
+
*/
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// TripwireEvaluator
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Manages and evaluates tripwire conditions against LLM response data.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const evaluator = createDefaultTripwireEvaluator();
|
|
22
|
+
*
|
|
23
|
+
* const result = evaluator.evaluate({
|
|
24
|
+
* responseText: "",
|
|
25
|
+
* latencyMs: 45000,
|
|
26
|
+
* finishReason: "length",
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* if (result.triggered && result.action === "abort") {
|
|
30
|
+
* throw new Error(result.message);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class TripwireEvaluator {
|
|
35
|
+
tripwires = [];
|
|
36
|
+
/**
|
|
37
|
+
* Register a tripwire. Replaces any existing tripwire with the same id.
|
|
38
|
+
*/
|
|
39
|
+
register(tripwire) {
|
|
40
|
+
const existingIndex = this.tripwires.findIndex((t) => t.id === tripwire.id);
|
|
41
|
+
if (existingIndex !== -1) {
|
|
42
|
+
this.tripwires[existingIndex] = tripwire;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.tripwires.push(tripwire);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Remove a registered tripwire by id.
|
|
50
|
+
* @returns true if the tripwire was found and removed, false otherwise.
|
|
51
|
+
*/
|
|
52
|
+
unregister(id) {
|
|
53
|
+
const index = this.tripwires.findIndex((t) => t.id === id);
|
|
54
|
+
if (index !== -1) {
|
|
55
|
+
this.tripwires.splice(index, 1);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Evaluate all tripwires and return the highest-priority triggered result.
|
|
62
|
+
*
|
|
63
|
+
* Priority order: "abort" > "warn" > "log"
|
|
64
|
+
*
|
|
65
|
+
* Bug fix (C1): The original implementation returned on the FIRST triggered
|
|
66
|
+
* tripwire regardless of action, which meant a "warn" registered before an
|
|
67
|
+
* "abort" would mask the abort. This implementation evaluates ALL tripwires
|
|
68
|
+
* and promotes the highest-severity action.
|
|
69
|
+
*/
|
|
70
|
+
evaluate(data) {
|
|
71
|
+
let firstAbort = null;
|
|
72
|
+
let firstWarn = null;
|
|
73
|
+
let firstLog = null;
|
|
74
|
+
for (const tripwire of this.tripwires) {
|
|
75
|
+
let triggered;
|
|
76
|
+
try {
|
|
77
|
+
triggered = tripwire.condition(data);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Skip tripwires whose condition throws — don't let evaluation errors
|
|
81
|
+
// block normal operation.
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (!triggered) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const message = typeof tripwire.message === "function"
|
|
88
|
+
? tripwire.message(data)
|
|
89
|
+
: tripwire.message;
|
|
90
|
+
const result = {
|
|
91
|
+
triggered: true,
|
|
92
|
+
tripwire,
|
|
93
|
+
message,
|
|
94
|
+
action: tripwire.action,
|
|
95
|
+
};
|
|
96
|
+
if (tripwire.action === "abort" && firstAbort === null) {
|
|
97
|
+
firstAbort = result;
|
|
98
|
+
}
|
|
99
|
+
else if (tripwire.action === "warn" && firstWarn === null) {
|
|
100
|
+
firstWarn = result;
|
|
101
|
+
}
|
|
102
|
+
else if (tripwire.action === "log" && firstLog === null) {
|
|
103
|
+
firstLog = result;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (firstAbort !== null) {
|
|
107
|
+
return firstAbort;
|
|
108
|
+
}
|
|
109
|
+
if (firstWarn !== null) {
|
|
110
|
+
return firstWarn;
|
|
111
|
+
}
|
|
112
|
+
if (firstLog !== null) {
|
|
113
|
+
return firstLog;
|
|
114
|
+
}
|
|
115
|
+
return { triggered: false };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Evaluate all tripwires and return every triggered result.
|
|
119
|
+
*/
|
|
120
|
+
evaluateAll(data) {
|
|
121
|
+
const results = [];
|
|
122
|
+
for (const tripwire of this.tripwires) {
|
|
123
|
+
let triggered;
|
|
124
|
+
try {
|
|
125
|
+
triggered = tripwire.condition(data);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (!triggered) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const message = typeof tripwire.message === "function"
|
|
134
|
+
? tripwire.message(data)
|
|
135
|
+
: tripwire.message;
|
|
136
|
+
results.push({
|
|
137
|
+
triggered: true,
|
|
138
|
+
tripwire,
|
|
139
|
+
message,
|
|
140
|
+
action: tripwire.action,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return results;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Return a shallow copy of all registered tripwires.
|
|
147
|
+
*/
|
|
148
|
+
getTripwires() {
|
|
149
|
+
return [...this.tripwires];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// ============================================================================
|
|
153
|
+
// Built-in tripwires
|
|
154
|
+
// ============================================================================
|
|
155
|
+
/**
|
|
156
|
+
* Triggers when the model hit its token output limit (finishReason === "length").
|
|
157
|
+
*/
|
|
158
|
+
const maxTokensTripwire = {
|
|
159
|
+
id: "max-tokens",
|
|
160
|
+
name: "Maximum Tokens Hit",
|
|
161
|
+
description: "Triggers when the model stopped because it reached the token output limit.",
|
|
162
|
+
action: "abort",
|
|
163
|
+
condition: (data) => data.finishReason === "length",
|
|
164
|
+
message: "Model stopped at token limit — response may be truncated.",
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Triggers when the response is empty or only whitespace.
|
|
168
|
+
*/
|
|
169
|
+
const emptyResponseTripwire = {
|
|
170
|
+
id: "empty-response",
|
|
171
|
+
name: "Empty Response",
|
|
172
|
+
description: "Triggers when the model returns an empty or whitespace-only response.",
|
|
173
|
+
action: "abort",
|
|
174
|
+
condition: (data) => data.responseText !== undefined && data.responseText.trim().length === 0,
|
|
175
|
+
message: "Model returned an empty response.",
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Triggers when the response contains highly repetitive phrases.
|
|
179
|
+
* Uses a sliding-window approach: splits into overlapping 10-word windows and
|
|
180
|
+
* counts duplicates. If more than 20% of windows are repeated the response is
|
|
181
|
+
* flagged as a repetition loop.
|
|
182
|
+
*/
|
|
183
|
+
const repetitionLoopTripwire = {
|
|
184
|
+
id: "repetition-loop",
|
|
185
|
+
name: "Repetition Loop",
|
|
186
|
+
description: "Detects when the model is generating repetitive content, indicating a loop.",
|
|
187
|
+
action: "warn",
|
|
188
|
+
condition: (data) => {
|
|
189
|
+
const text = data.responseText;
|
|
190
|
+
if (!text) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const words = text.split(/\s+/);
|
|
194
|
+
if (words.length < 30) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
const windowSize = 10;
|
|
198
|
+
const windows = new Map();
|
|
199
|
+
let duplicates = 0;
|
|
200
|
+
const totalWindows = words.length - windowSize + 1;
|
|
201
|
+
for (let i = 0; i <= words.length - windowSize; i++) {
|
|
202
|
+
const window = words.slice(i, i + windowSize).join(" ");
|
|
203
|
+
const count = (windows.get(window) ?? 0) + 1;
|
|
204
|
+
windows.set(window, count);
|
|
205
|
+
if (count > 1) {
|
|
206
|
+
duplicates++;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return duplicates / totalWindows > 0.2;
|
|
210
|
+
},
|
|
211
|
+
message: "Response contains highly repetitive content — possible generation loop.",
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Triggers when the input text exceeds 100 000 characters.
|
|
215
|
+
*/
|
|
216
|
+
const inputTooLongTripwire = {
|
|
217
|
+
id: "input-too-long",
|
|
218
|
+
name: "Input Too Long",
|
|
219
|
+
description: "Triggers when the input text exceeds the recommended length.",
|
|
220
|
+
action: "abort",
|
|
221
|
+
condition: (data) => data.inputText !== undefined && data.inputText.length > 100_000,
|
|
222
|
+
message: (data) => `Input is ${data.inputText?.length ?? 0} characters — exceeds the 100 000-character limit.`,
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Triggers when the conversation has more than 100 messages.
|
|
226
|
+
*/
|
|
227
|
+
const tooManyMessagesTripwire = {
|
|
228
|
+
id: "too-many-messages",
|
|
229
|
+
name: "Too Many Messages",
|
|
230
|
+
description: "Triggers when the conversation message count exceeds the recommended maximum.",
|
|
231
|
+
action: "warn",
|
|
232
|
+
condition: (data) => data.messageCount !== undefined && data.messageCount > 100,
|
|
233
|
+
message: (data) => `Conversation has ${data.messageCount} messages — consider summarising context.`,
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Triggers when the response text exceeds 50 000 characters.
|
|
237
|
+
*/
|
|
238
|
+
const responseTooLongTripwire = {
|
|
239
|
+
id: "response-too-long",
|
|
240
|
+
name: "Response Too Long",
|
|
241
|
+
description: "Triggers when the response text exceeds the recommended length.",
|
|
242
|
+
action: "warn",
|
|
243
|
+
condition: (data) => data.responseText !== undefined && data.responseText.length > 50_000,
|
|
244
|
+
message: (data) => `Response is ${data.responseText?.length ?? 0} characters — exceeds the 50 000-character limit.`,
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Triggers when the measured end-to-end latency exceeds 30 seconds.
|
|
248
|
+
*/
|
|
249
|
+
const highLatencyTripwire = {
|
|
250
|
+
id: "high-latency",
|
|
251
|
+
name: "High Latency",
|
|
252
|
+
description: "Triggers when the measured response latency exceeds the acceptable threshold.",
|
|
253
|
+
action: "warn",
|
|
254
|
+
condition: (data) => data.latencyMs !== undefined && data.latencyMs > 30_000,
|
|
255
|
+
message: (data) => `Response latency was ${data.latencyMs}ms — exceeds the 30 000ms threshold.`,
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* All built-in tripwires in default registration order.
|
|
259
|
+
*
|
|
260
|
+
* Registration order does not affect priority — `evaluate()` always promotes
|
|
261
|
+
* the highest-severity action ("abort" > "warn" > "log").
|
|
262
|
+
*/
|
|
263
|
+
export const commonTripwires = [
|
|
264
|
+
maxTokensTripwire,
|
|
265
|
+
emptyResponseTripwire,
|
|
266
|
+
repetitionLoopTripwire,
|
|
267
|
+
inputTooLongTripwire,
|
|
268
|
+
tooManyMessagesTripwire,
|
|
269
|
+
responseTooLongTripwire,
|
|
270
|
+
highLatencyTripwire,
|
|
271
|
+
];
|
|
272
|
+
// ============================================================================
|
|
273
|
+
// Factory
|
|
274
|
+
// ============================================================================
|
|
275
|
+
/**
|
|
276
|
+
* Create a TripwireEvaluator pre-loaded with all built-in tripwires.
|
|
277
|
+
*/
|
|
278
|
+
export function createDefaultTripwireEvaluator() {
|
|
279
|
+
const evaluator = new TripwireEvaluator();
|
|
280
|
+
for (const tripwire of commonTripwires) {
|
|
281
|
+
evaluator.register(tripwire);
|
|
282
|
+
}
|
|
283
|
+
return evaluator;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=tripwireEvaluator.js.map
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Enhanced AI provider system with natural MCP tool access.
|
|
6
6
|
* Uses real MCP infrastructure for tool discovery and execution.
|
|
7
7
|
*/
|
|
8
|
+
import type { AgentDefinition, AgentNetworkConfig, NetworkExecutionInput, NetworkExecutionOptions, NetworkExecutionResult, NetworkStreamChunk } from "./types/index.js";
|
|
8
9
|
import type { CompactionConfig, CompactionResult, SpanData, ObservabilityConfig, MetricsSummary, MCPToolAnnotations, TraceView, AuthenticatedContext, AuthProvider, JsonObject, NeuroLinkEvents, TypedEventEmitter, MCPEnhancementsConfig, NeuroLinkAuthConfig, NeurolinkConstructorConfig, ChatMessage, ExternalMCPOperationResult, ExternalMCPServerInstance, ExternalMCPToolInfo, GenerateOptions, GenerateResult, ProviderStatus, TextGenerationOptions, TextGenerationResult, MCPExecutableTool, MCPServerInfo, MCPStatus, StreamOptions, StreamResult, ToolExecutionContext, ToolExecutionSummary, ToolInfo, ToolRegistrationOptions, BatchOperationResult, StreamGenerationEndContext, ToolRoutingServerDescriptor, ToolDedupConfig } from "./types/index.js";
|
|
9
10
|
import { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
|
|
10
11
|
import type { RedisConversationMemoryManager } from "./core/redisConversationMemoryManager.js";
|
|
@@ -2162,6 +2163,134 @@ export declare class NeuroLink {
|
|
|
2162
2163
|
* ```
|
|
2163
2164
|
*/
|
|
2164
2165
|
getEvaluationPreset(presetName: "safety" | "rag" | "quality" | "comprehensive" | "minimal" | "summarization" | "customerSupport" | "codeGeneration"): Promise<import("./types/index.js").PipelineConfig>;
|
|
2166
|
+
/**
|
|
2167
|
+
* Create an Agent instance for multi-agent orchestration.
|
|
2168
|
+
*
|
|
2169
|
+
* Agents are specialized AI entities with defined instructions, tools, and behavior.
|
|
2170
|
+
* They can be composed into networks for complex task orchestration.
|
|
2171
|
+
*
|
|
2172
|
+
* @param definition - Agent definition specifying behavior and capabilities
|
|
2173
|
+
* @returns A new Agent instance
|
|
2174
|
+
*
|
|
2175
|
+
* @example
|
|
2176
|
+
* ```typescript
|
|
2177
|
+
* const researcher = neurolink.createAgent({
|
|
2178
|
+
* id: 'researcher',
|
|
2179
|
+
* name: 'Research Agent',
|
|
2180
|
+
* description: 'Searches and analyzes information from various sources',
|
|
2181
|
+
* instructions: 'You are a research assistant. Search thoroughly and cite sources.',
|
|
2182
|
+
* tools: ['websearchGrounding', 'readFile'],
|
|
2183
|
+
* model: 'gpt-4o'
|
|
2184
|
+
* });
|
|
2185
|
+
*
|
|
2186
|
+
* const result = await researcher.execute('Find recent AI breakthroughs');
|
|
2187
|
+
* ```
|
|
2188
|
+
*
|
|
2189
|
+
* @see {@link AgentDefinition} for definition options
|
|
2190
|
+
* @see {@link Agent} for agent methods
|
|
2191
|
+
* @since 8.38.0
|
|
2192
|
+
*/
|
|
2193
|
+
createAgent(definition: AgentDefinition): Promise<import("./agent/agent.js").Agent>;
|
|
2194
|
+
/**
|
|
2195
|
+
* Create an AgentNetwork for multi-agent orchestration.
|
|
2196
|
+
*
|
|
2197
|
+
* Networks coordinate multiple agents, workflows, and tools with intelligent
|
|
2198
|
+
* LLM-powered routing. The router agent analyzes tasks and delegates to
|
|
2199
|
+
* the most appropriate primitive.
|
|
2200
|
+
*
|
|
2201
|
+
* @param config - Network configuration with agents, workflows, and routing settings
|
|
2202
|
+
* @returns A new AgentNetwork instance
|
|
2203
|
+
*
|
|
2204
|
+
* @example
|
|
2205
|
+
* ```typescript
|
|
2206
|
+
* const network = neurolink.createNetwork({
|
|
2207
|
+
* name: 'Content Team',
|
|
2208
|
+
* description: 'Collaborative content creation pipeline',
|
|
2209
|
+
* agents: [
|
|
2210
|
+
* {
|
|
2211
|
+
* id: 'researcher',
|
|
2212
|
+
* name: 'Researcher',
|
|
2213
|
+
* description: 'Finds and verifies information',
|
|
2214
|
+
* instructions: 'Research topics thoroughly...',
|
|
2215
|
+
* },
|
|
2216
|
+
* {
|
|
2217
|
+
* id: 'writer',
|
|
2218
|
+
* name: 'Writer',
|
|
2219
|
+
* description: 'Creates engaging content',
|
|
2220
|
+
* instructions: 'Write clear, engaging content...',
|
|
2221
|
+
* },
|
|
2222
|
+
* {
|
|
2223
|
+
* id: 'editor',
|
|
2224
|
+
* name: 'Editor',
|
|
2225
|
+
* description: 'Reviews and improves content',
|
|
2226
|
+
* instructions: 'Review for clarity and accuracy...',
|
|
2227
|
+
* }
|
|
2228
|
+
* ],
|
|
2229
|
+
* router: {
|
|
2230
|
+
* model: 'gpt-4o',
|
|
2231
|
+
* confidenceThreshold: 0.7
|
|
2232
|
+
* }
|
|
2233
|
+
* });
|
|
2234
|
+
*
|
|
2235
|
+
* const result = await network.execute({
|
|
2236
|
+
* message: 'Write an article about quantum computing'
|
|
2237
|
+
* });
|
|
2238
|
+
* ```
|
|
2239
|
+
*
|
|
2240
|
+
* @see {@link AgentNetworkConfig} for configuration options
|
|
2241
|
+
* @see {@link AgentNetwork} for network methods
|
|
2242
|
+
* @since 8.38.0
|
|
2243
|
+
*/
|
|
2244
|
+
createNetwork(config: AgentNetworkConfig): Promise<import("./agent/agentNetwork.js").AgentNetwork>;
|
|
2245
|
+
/**
|
|
2246
|
+
* Execute an agent network with the given input.
|
|
2247
|
+
*
|
|
2248
|
+
* @param network - The agent network to execute
|
|
2249
|
+
* @param input - Execution input (message and context)
|
|
2250
|
+
* @param options - Optional execution options
|
|
2251
|
+
* @returns Network execution result with content, trace, and usage
|
|
2252
|
+
*
|
|
2253
|
+
* @see {@link NetworkExecutionInput} for input options
|
|
2254
|
+
* @see {@link NetworkExecutionResult} for result structure
|
|
2255
|
+
* @since 8.38.0
|
|
2256
|
+
*/
|
|
2257
|
+
executeNetwork(network: import("./agent/agentNetwork.js").AgentNetwork, input: NetworkExecutionInput, options?: NetworkExecutionOptions): Promise<NetworkExecutionResult>;
|
|
2258
|
+
/**
|
|
2259
|
+
* Stream agent network execution with real-time events.
|
|
2260
|
+
*
|
|
2261
|
+
* @param network - The agent network to stream
|
|
2262
|
+
* @param input - Execution input (message and context)
|
|
2263
|
+
* @param options - Optional execution options
|
|
2264
|
+
* @returns Async iterable of network stream chunks
|
|
2265
|
+
*
|
|
2266
|
+
* @see {@link NetworkStreamChunk} for chunk types
|
|
2267
|
+
* @since 8.38.0
|
|
2268
|
+
*/
|
|
2269
|
+
streamNetwork(network: import("./agent/agentNetwork.js").AgentNetwork, input: NetworkExecutionInput, options?: NetworkExecutionOptions): AsyncIterable<NetworkStreamChunk>;
|
|
2270
|
+
/**
|
|
2271
|
+
* Create a NetworkOrchestrator for managing multiple agent networks.
|
|
2272
|
+
*
|
|
2273
|
+
* @param config - Orchestrator configuration options
|
|
2274
|
+
* @returns A new NetworkOrchestrator instance
|
|
2275
|
+
* @since 8.38.0
|
|
2276
|
+
*/
|
|
2277
|
+
createOrchestrator(config?: import("./types/index.js").OrchestratorConfig): Promise<import("./agent/orchestration/index.js").NetworkOrchestrator>;
|
|
2278
|
+
/**
|
|
2279
|
+
* Create an AgentCoordinator for managing agent coordination strategies.
|
|
2280
|
+
*
|
|
2281
|
+
* @param config - Coordinator configuration options
|
|
2282
|
+
* @returns A new AgentCoordinator instance
|
|
2283
|
+
* @since 8.38.0
|
|
2284
|
+
*/
|
|
2285
|
+
createCoordinator(config?: import("./types/index.js").CoordinatorConfig): Promise<import("./agent/coordination/index.js").AgentCoordinator>;
|
|
2286
|
+
/**
|
|
2287
|
+
* Create a MessageBus for inter-agent communication.
|
|
2288
|
+
*
|
|
2289
|
+
* @param config - Message bus configuration options
|
|
2290
|
+
* @returns A new MessageBus instance
|
|
2291
|
+
* @since 8.38.0
|
|
2292
|
+
*/
|
|
2293
|
+
createMessageBus(config?: import("./types/index.js").MessageBusConfig): Promise<import("./agent/communication/index.js").MessageBus>;
|
|
2165
2294
|
/**
|
|
2166
2295
|
* Dispose of all resources and cleanup connections
|
|
2167
2296
|
* Call this method when done using the NeuroLink instance to prevent resource leaks
|