@juspay/neurolink 13.13.2 → 13.13.3
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 +292 -292
- package/dist/neurolink.js +20 -1
- package/dist/telemetry/withSpan.d.ts +1 -1
- package/dist/telemetry/withSpan.js +14 -6
- package/dist/types/observability.d.ts +2 -0
- package/package.json +3 -2
package/dist/neurolink.js
CHANGED
|
@@ -444,6 +444,23 @@ function startTurn(span, optionsOrPrompt) {
|
|
|
444
444
|
});
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
|
+
// A decision provider's failure message can carry the vendor's error body,
|
|
448
|
+
// which is text the vendor controls. Telemetry records the error class, kind
|
|
449
|
+
// and HTTP status instead; the caller still gets the full message.
|
|
450
|
+
function decisionFailureSummary(error) {
|
|
451
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
452
|
+
if (!(error instanceof Error) ||
|
|
453
|
+
typeof cause !== "object" ||
|
|
454
|
+
cause === null ||
|
|
455
|
+
!("kind" in cause) ||
|
|
456
|
+
typeof cause.kind !== "string") {
|
|
457
|
+
return undefined;
|
|
458
|
+
}
|
|
459
|
+
const status = "status" in cause && typeof cause.status === "number"
|
|
460
|
+
? ` (HTTP ${cause.status})`
|
|
461
|
+
: "";
|
|
462
|
+
return `${error.name}: ${cause.kind}${status}`;
|
|
463
|
+
}
|
|
447
464
|
function failTurnSpan(span, error) {
|
|
448
465
|
const message = error.message;
|
|
449
466
|
if (isAbortError(error)) {
|
|
@@ -14986,6 +15003,7 @@ Current user's request: ${currentInput}`;
|
|
|
14986
15003
|
name: "decide",
|
|
14987
15004
|
tracer: tracers.decision,
|
|
14988
15005
|
expectedFailure: () => !providerName,
|
|
15006
|
+
failureSummary: decisionFailureSummary,
|
|
14989
15007
|
attributes: {
|
|
14990
15008
|
"gen_ai.system": providerName,
|
|
14991
15009
|
"gen_ai.operation.name": "decide",
|
|
@@ -15108,7 +15126,8 @@ Current user's request: ${currentInput}`;
|
|
|
15108
15126
|
}
|
|
15109
15127
|
catch (error) {
|
|
15110
15128
|
span.durationMs = Date.now() - startedAt;
|
|
15111
|
-
const ended = SpanSerializer.endSpan(span, SpanStatus.ERROR,
|
|
15129
|
+
const ended = SpanSerializer.endSpan(span, SpanStatus.ERROR, decisionFailureSummary(error) ??
|
|
15130
|
+
(error instanceof Error ? error.message : String(error)));
|
|
15112
15131
|
this.metricsAggregator.recordSpan(ended);
|
|
15113
15132
|
getMetricsAggregator().recordSpan(ended);
|
|
15114
15133
|
throw error;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Span } from "@opentelemetry/api";
|
|
2
2
|
import type { GenerationOperation, GenerationRecord, SpanOptions } from "../types/index.js";
|
|
3
|
-
export declare function markFailure(span: Span, error: unknown, expected?: boolean): void;
|
|
3
|
+
export declare function markFailure(span: Span, error: unknown, expected?: boolean, summarize?: (error: unknown) => string | undefined): void;
|
|
4
4
|
/**
|
|
5
5
|
* @description Ends `span` at WARNING once `stream` is garbage collected while the span is still open, for a stream result whose caller dropped it without reading it to the end or closing it. Best effort: it runs only if and when the collector reclaims `stream`, and a span that already ended is left alone.
|
|
6
6
|
* @param stream {object} - The iterable handed to the caller; `span` must not keep it reachable.
|
|
@@ -24,16 +24,17 @@ function readsAsAbort(error) {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
export function markFailure(span, error, expected = false) {
|
|
27
|
+
export function markFailure(span, error, expected = false, summarize) {
|
|
28
28
|
try {
|
|
29
|
-
recordFailure(span, error, expected);
|
|
29
|
+
recordFailure(span, error, expected, summarize);
|
|
30
30
|
}
|
|
31
31
|
catch {
|
|
32
32
|
// The span keeps whatever was recorded before the value could not be read.
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function recordFailure(span, error, expected) {
|
|
36
|
-
const
|
|
35
|
+
function recordFailure(span, error, expected, summarize) {
|
|
36
|
+
const summary = summarize?.(error);
|
|
37
|
+
const message = summary ?? failureText(error);
|
|
37
38
|
if (readsAsAbort(error)) {
|
|
38
39
|
span.setAttributes({
|
|
39
40
|
[LangfuseOtelSpanAttributes.OBSERVATION_LEVEL]: "WARNING",
|
|
@@ -48,7 +49,14 @@ function recordFailure(span, error, expected) {
|
|
|
48
49
|
[LangfuseOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE]: message,
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
|
-
if (
|
|
52
|
+
if (summary !== undefined) {
|
|
53
|
+
// The thrown error's own message and stack are what the summary replaces.
|
|
54
|
+
span.recordException({
|
|
55
|
+
name: error instanceof Error ? error.name : "Error",
|
|
56
|
+
message,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (error instanceof Error) {
|
|
52
60
|
span.recordException(error);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
@@ -109,7 +117,7 @@ export async function withSpan(options, fn) {
|
|
|
109
117
|
return result;
|
|
110
118
|
}
|
|
111
119
|
catch (error) {
|
|
112
|
-
markFailure(span, error, options.expectedFailure?.(error));
|
|
120
|
+
markFailure(span, error, options.expectedFailure?.(error), options.failureSummary);
|
|
113
121
|
throw error;
|
|
114
122
|
}
|
|
115
123
|
finally {
|
|
@@ -418,6 +418,8 @@ export type SpanOptions = {
|
|
|
418
418
|
attributes?: Record<string, string | number | boolean | undefined>;
|
|
419
419
|
/** Marks a thrown error as an expected skip whose Langfuse level the span set itself, so `withSpan` keeps it instead of raising ERROR. */
|
|
420
420
|
expectedFailure?: (error: unknown) => boolean;
|
|
421
|
+
/** For a failure whose message is text from another system: returns the text to record on the span (status message, level message and exception) in its place. The thrown error is untouched. Return undefined to record the error as it is. */
|
|
422
|
+
failureSummary?: (error: unknown) => string | undefined;
|
|
421
423
|
/** Keeps the span out of the active context, so spans started inside `fn` parent to the nearest ancestor that is exported. */
|
|
422
424
|
detached?: boolean;
|
|
423
425
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "13.13.
|
|
3
|
+
"version": "13.13.3",
|
|
4
4
|
"packageManager": "pnpm@10.34.9+sha512.f49b5a8ea0fdedb44bb3c0c1d6575092a53c2950d95b7ad15df11f17974877a2de3a01c07e934e9b28ce716e51c09a94962c7306d09be2e1e4b18a8c8762fd32",
|
|
5
5
|
"description": "The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002/call) for routing, tool selection and context budgeting. MCP-native (4 transports), voice TTS/STT/realtime, RAG, agents, memory, compaction, 9 observability exporters. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · TypeSafe Jev and more.",
|
|
6
6
|
"author": {
|
|
@@ -215,7 +215,8 @@
|
|
|
215
215
|
"test:rag-bounds": "pnpm exec tsx test/continuous-test-suite-rag-bounds.ts",
|
|
216
216
|
"test:skills": "pnpm exec tsx test/continuous-test-suite-skills.ts",
|
|
217
217
|
"test:decide": "pnpm run test:decide-offline && pnpm run test:decide-live",
|
|
218
|
-
"test:decide-offline": "pnpm exec tsx test/continuous-test-suite-decide.ts",
|
|
218
|
+
"test:decide-offline": "pnpm exec tsx test/continuous-test-suite-decide.ts && pnpm run test:decide-error-redaction",
|
|
219
|
+
"test:decide-error-redaction": "pnpm exec tsx test/continuous-test-suite-decide-error-redaction.ts",
|
|
219
220
|
"test:decide-live": "pnpm exec tsx test/continuous-test-suite-decide-live.ts",
|
|
220
221
|
"test:decide-catalog": "pnpm exec tsx test/continuous-test-suite-decide-catalog.ts",
|
|
221
222
|
"test:agent-mode": "pnpm exec tsx test/continuous-test-suite-agent-mode.ts",
|