@juspay/neurolink 12.49.17 → 12.49.19
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/agent/agent.js +80 -4
- package/dist/browser/neurolink.min.js +349 -349
- package/dist/core/analytics.js +3 -18
- package/dist/core/evaluationProviders.d.ts +2 -7
- package/dist/core/evaluationProviders.js +1 -1
- package/dist/core/modules/TelemetryHandler.d.ts +3 -11
- package/dist/core/modules/TelemetryHandler.js +6 -29
- package/dist/neurolink.d.ts +5 -0
- package/dist/neurolink.js +115 -10
- package/dist/types/agentNetwork.d.ts +29 -1
- package/dist/types/common.d.ts +5 -0
- package/dist/types/evaluationProviders.d.ts +6 -0
- package/dist/types/generate.d.ts +3 -1
- package/dist/types/toolRouting.d.ts +6 -0
- package/dist/utils/conversationMemory.js +1 -1
- package/dist/utils/pricing.js +16 -1
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
## [12.49.
|
|
1
|
+
## [12.49.19](https://github.com/juspay/neurolink/compare/v12.49.18...v12.49.19) (2026-10-10)
|
|
2
2
|
|
|
3
3
|
### Bug Fixes
|
|
4
4
|
|
|
5
|
-
- **(BZ-
|
|
5
|
+
- **(BZ-6757):** preserve agent sessions and host-owned turn state ([c4bf59d](https://github.com/juspay/neurolink/commit/c4bf59d3928fe0cccedf2bb0418bb2face362be9))
|
|
6
6
|
|
|
7
7
|
## [11.2.3](https://github.com/juspay/neurolink/compare/v11.2.2...v11.2.3) (2026-08-19)
|
|
8
8
|
|
package/dist/agent/agent.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { EventEmitter } from "events";
|
|
9
9
|
import { ErrorFactory } from "../utils/errorHandling.js";
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
|
+
import { toToolExecutionRecords } from "../core/toolExecutionRecorder.js";
|
|
11
12
|
/**
|
|
12
13
|
* Agent - Wraps a NeuroLink instance with specialized behavior
|
|
13
14
|
*
|
|
@@ -159,6 +160,7 @@ export class Agent {
|
|
|
159
160
|
content: result.content || "",
|
|
160
161
|
object: parsedOutput,
|
|
161
162
|
usage: result.usage,
|
|
163
|
+
cost: result.analytics?.cost,
|
|
162
164
|
toolsUsed: result.toolsUsed,
|
|
163
165
|
// Real per-call records straight from the tool loop (N2)
|
|
164
166
|
toolExecutions: result.toolExecutions,
|
|
@@ -208,6 +210,8 @@ export class Agent {
|
|
|
208
210
|
async *stream(input, options) {
|
|
209
211
|
const startTime = Date.now();
|
|
210
212
|
const traceId = options?.traceId ?? `agent-${this.id}-${Date.now()}`;
|
|
213
|
+
let streamResult;
|
|
214
|
+
let fullContent = "";
|
|
211
215
|
this.emitter.emit("agent:start", {
|
|
212
216
|
agentId: this.id,
|
|
213
217
|
traceId,
|
|
@@ -234,8 +238,7 @@ export class Agent {
|
|
|
234
238
|
const prompt = this.buildPrompt(input, options?.context);
|
|
235
239
|
const streamOptions = this.buildStreamOptions(prompt, options, traceId);
|
|
236
240
|
// Execute via NeuroLink
|
|
237
|
-
|
|
238
|
-
let fullContent = "";
|
|
241
|
+
streamResult = await this.neurolink.stream(streamOptions);
|
|
239
242
|
for await (const chunk of streamResult.stream) {
|
|
240
243
|
// Handle different chunk types from the stream
|
|
241
244
|
if ("content" in chunk && typeof chunk.content === "string") {
|
|
@@ -281,17 +284,37 @@ export class Agent {
|
|
|
281
284
|
this.lastExecutionTime = duration;
|
|
282
285
|
this.executionCount++;
|
|
283
286
|
this.totalExecutionTime += duration;
|
|
287
|
+
let cost;
|
|
288
|
+
try {
|
|
289
|
+
cost = (await streamResult.analytics)?.cost;
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
logger.warn(`[Agent:${this.id}] Stream cost analytics unavailable`);
|
|
293
|
+
}
|
|
294
|
+
const stopReason = streamResult.metadata?.stopReason ?? streamResult.stopReason;
|
|
295
|
+
const error = streamResult.metadata?.error;
|
|
296
|
+
const status = error || stopReason === "provider-error" ? "error" : "success";
|
|
297
|
+
const toolExecutions = toToolExecutionRecords(streamResult.toolExecutions, options?.toolExecutionCapture);
|
|
284
298
|
this.emitter.emit("agent:complete", {
|
|
285
299
|
agentId: this.id,
|
|
286
300
|
traceId,
|
|
287
301
|
duration,
|
|
288
302
|
content: fullContent,
|
|
303
|
+
status,
|
|
304
|
+
toolExecutions,
|
|
305
|
+
stopReason,
|
|
306
|
+
error,
|
|
289
307
|
});
|
|
290
308
|
yield {
|
|
291
309
|
type: "agent-complete",
|
|
292
310
|
agentId: this.id,
|
|
293
311
|
content: fullContent,
|
|
294
312
|
usage: streamResult.usage,
|
|
313
|
+
cost,
|
|
314
|
+
status,
|
|
315
|
+
toolExecutions,
|
|
316
|
+
stopReason,
|
|
317
|
+
error,
|
|
295
318
|
duration,
|
|
296
319
|
timestamp: Date.now(),
|
|
297
320
|
traceId,
|
|
@@ -305,6 +328,10 @@ export class Agent {
|
|
|
305
328
|
});
|
|
306
329
|
yield {
|
|
307
330
|
type: "agent-error",
|
|
331
|
+
status: "error",
|
|
332
|
+
content: fullContent,
|
|
333
|
+
toolExecutions: toToolExecutionRecords(streamResult?.toolExecutions, options?.toolExecutionCapture),
|
|
334
|
+
stopReason: streamResult?.metadata?.stopReason ?? streamResult?.stopReason,
|
|
308
335
|
agentId: this.id,
|
|
309
336
|
error: error instanceof Error ? error.message : String(error),
|
|
310
337
|
timestamp: Date.now(),
|
|
@@ -350,8 +377,11 @@ export class Agent {
|
|
|
350
377
|
*/
|
|
351
378
|
buildPrompt(input, context) {
|
|
352
379
|
let prompt = typeof input === "string" ? input : JSON.stringify(input);
|
|
353
|
-
|
|
354
|
-
|
|
380
|
+
const promptContext = context
|
|
381
|
+
? Object.fromEntries(Object.entries(context).filter(([key]) => key !== "sessionId"))
|
|
382
|
+
: undefined;
|
|
383
|
+
if (promptContext && Object.keys(promptContext).length > 0) {
|
|
384
|
+
prompt = `Context: ${JSON.stringify(promptContext)}\n\nTask: ${prompt}`;
|
|
355
385
|
}
|
|
356
386
|
return prompt;
|
|
357
387
|
}
|
|
@@ -367,10 +397,27 @@ export class Agent {
|
|
|
367
397
|
provider: this.provider,
|
|
368
398
|
model: this.model,
|
|
369
399
|
temperature: this.temperature,
|
|
400
|
+
...(options?.region !== undefined && { region: options.region }),
|
|
401
|
+
...(options?.maxTokens !== undefined && { maxTokens: options.maxTokens }),
|
|
402
|
+
...(options?.disableTools !== undefined && {
|
|
403
|
+
disableTools: options.disableTools,
|
|
404
|
+
}),
|
|
370
405
|
systemPrompt: this.instructions,
|
|
371
406
|
// toolFilter delegates to BaseProvider.applyToolFiltering() natively
|
|
372
407
|
...(this.tools && this.tools.length > 0 && { toolFilter: this.tools }),
|
|
373
408
|
maxSteps: options?.maxSteps ?? this.maxSteps,
|
|
409
|
+
...(options?.enableAnalytics !== undefined && {
|
|
410
|
+
enableAnalytics: options.enableAnalytics,
|
|
411
|
+
}),
|
|
412
|
+
...(options?.maxBudgetUsd !== undefined && {
|
|
413
|
+
maxBudgetUsd: options.maxBudgetUsd,
|
|
414
|
+
}),
|
|
415
|
+
...(options?.disableInternalFallback !== undefined && {
|
|
416
|
+
disableInternalFallback: options.disableInternalFallback,
|
|
417
|
+
}),
|
|
418
|
+
...(options?.toolExecutionCapture && {
|
|
419
|
+
toolExecutionCapture: options.toolExecutionCapture,
|
|
420
|
+
}),
|
|
374
421
|
requestId: traceId,
|
|
375
422
|
// Turn budget + cancellation, forwarded verbatim to generate() — the
|
|
376
423
|
// machinery (wrap-up nudge, stall watchdog, honest stopReason) lives
|
|
@@ -386,10 +433,16 @@ export class Agent {
|
|
|
386
433
|
...(options?.stallTimeoutMs !== undefined && {
|
|
387
434
|
stallTimeoutMs: options.stallTimeoutMs,
|
|
388
435
|
}),
|
|
436
|
+
...(options?.useMemory === false && { memory: { enabled: false } }),
|
|
389
437
|
context: {
|
|
390
438
|
agentId: this.id,
|
|
391
439
|
agentName: this.name,
|
|
392
440
|
...options?.context,
|
|
441
|
+
...(options?.useMemory === false
|
|
442
|
+
? { sessionId: undefined }
|
|
443
|
+
: options?.sessionId !== undefined
|
|
444
|
+
? { sessionId: options.sessionId }
|
|
445
|
+
: {}),
|
|
393
446
|
},
|
|
394
447
|
};
|
|
395
448
|
}
|
|
@@ -405,10 +458,27 @@ export class Agent {
|
|
|
405
458
|
provider: this.provider,
|
|
406
459
|
model: this.model,
|
|
407
460
|
temperature: this.temperature,
|
|
461
|
+
...(options?.region !== undefined && { region: options.region }),
|
|
462
|
+
...(options?.maxTokens !== undefined && { maxTokens: options.maxTokens }),
|
|
463
|
+
...(options?.disableTools !== undefined && {
|
|
464
|
+
disableTools: options.disableTools,
|
|
465
|
+
}),
|
|
408
466
|
systemPrompt: this.instructions,
|
|
409
467
|
// toolFilter delegates to BaseProvider.applyToolFiltering() natively
|
|
410
468
|
...(this.tools && this.tools.length > 0 && { toolFilter: this.tools }),
|
|
411
469
|
maxSteps: options?.maxSteps ?? this.maxSteps,
|
|
470
|
+
...(options?.enableAnalytics !== undefined && {
|
|
471
|
+
enableAnalytics: options.enableAnalytics,
|
|
472
|
+
}),
|
|
473
|
+
...(options?.maxBudgetUsd !== undefined && {
|
|
474
|
+
maxBudgetUsd: options.maxBudgetUsd,
|
|
475
|
+
}),
|
|
476
|
+
...(options?.disableInternalFallback !== undefined && {
|
|
477
|
+
disableInternalFallback: options.disableInternalFallback,
|
|
478
|
+
}),
|
|
479
|
+
...(options?.toolExecutionCapture && {
|
|
480
|
+
toolExecutionCapture: options.toolExecutionCapture,
|
|
481
|
+
}),
|
|
412
482
|
// Turn budget + cancellation, forwarded verbatim to stream()
|
|
413
483
|
...(options?.abortSignal && { abortSignal: options.abortSignal }),
|
|
414
484
|
...(options?.timeout !== undefined && { timeout: options.timeout }),
|
|
@@ -421,11 +491,17 @@ export class Agent {
|
|
|
421
491
|
...(options?.stallTimeoutMs !== undefined && {
|
|
422
492
|
stallTimeoutMs: options.stallTimeoutMs,
|
|
423
493
|
}),
|
|
494
|
+
...(options?.useMemory === false && { memory: { enabled: false } }),
|
|
424
495
|
context: {
|
|
425
496
|
agentId: this.id,
|
|
426
497
|
agentName: this.name,
|
|
427
498
|
traceId,
|
|
428
499
|
...options?.context,
|
|
500
|
+
...(options?.useMemory === false
|
|
501
|
+
? { sessionId: undefined }
|
|
502
|
+
: options?.sessionId !== undefined
|
|
503
|
+
? { sessionId: options.sessionId }
|
|
504
|
+
: {}),
|
|
429
505
|
},
|
|
430
506
|
};
|
|
431
507
|
}
|