@juspay/neurolink 13.9.0 → 13.10.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.
@@ -1364,6 +1364,12 @@ export declare class NeuroLink {
1364
1364
  * Create stream response
1365
1365
  */
1366
1366
  private createStreamResponse;
1367
+ /**
1368
+ * Whether `error` is the refusal of a conversation memory writer that opted in
1369
+ * to the erasure write protocol: the typed epoch error, or the CONFIG_ERROR
1370
+ * that storage which is unreachable, or not Redis, raises while the protocol is on.
1371
+ */
1372
+ private isStrictConversationAdmissionFailure;
1367
1373
  /**
1368
1374
  * Handle stream error with fallback
1369
1375
  */
package/dist/neurolink.js CHANGED
@@ -76,7 +76,7 @@ import { SkillsManager } from "./skills/skillsManager.js";
76
76
  import { createSkillCallTools, createSkillTools } from "./skills/skillTools.js";
77
77
  import { getMetricsAggregator, MetricsAggregator, } from "./observability/metricsAggregator.js";
78
78
  import { AnalyticsService, calculateAdvancedCost, parseAnalyticsQualityScore, } from "./analytics/index.js";
79
- import { SpanStatus, SpanType, CircuitBreakerOpenError, ConversationMemoryError, DEFAULT_DECISION_HOOK_TIMEOUT_MS, MAX_DECISION_HOOK_TIMEOUT_MS, ModelAccessDeniedError, } from "./types/index.js";
79
+ import { SpanStatus, SpanType, CircuitBreakerOpenError, ConversationMemoryError, ConversationWriterEpochError, DEFAULT_DECISION_HOOK_TIMEOUT_MS, MAX_DECISION_HOOK_TIMEOUT_MS, ModelAccessDeniedError, } from "./types/index.js";
80
80
  import { resolveTerminalAgentMode } from "./agent/prompts/terminalAgentPrompt.js";
81
81
  import { getExporterRegistry } from "./observability/exporterRegistry.js";
82
82
  import { SpanSerializer } from "./observability/utils/spanSerializer.js";
@@ -6053,6 +6053,11 @@ Current user's request: ${currentInput}`;
6053
6053
  await this.conversationMemory.initialize();
6054
6054
  }
6055
6055
  catch (err) {
6056
+ // Strict storage admission must not silently downgrade to process-local history.
6057
+ if (this.conversationMemoryConfig?.conversationMemory
6058
+ ?.erasureWriteProtocol === "conversation-erasure-v1") {
6059
+ throw err;
6060
+ }
6056
6061
  logger.warn("[NEUROLINK] Redis memory init failed, falling back to in-memory", {
6057
6062
  error: err instanceof Error ? err.message : String(err),
6058
6063
  generateInternalId,
@@ -10067,6 +10072,20 @@ Current user's request: ${currentInput}`;
10067
10072
  });
10068
10073
  return response;
10069
10074
  }
10075
+ /**
10076
+ * Whether `error` is the refusal of a conversation memory writer that opted in
10077
+ * to the erasure write protocol: the typed epoch error, or the CONFIG_ERROR
10078
+ * that storage which is unreachable, or not Redis, raises while the protocol is on.
10079
+ */
10080
+ isStrictConversationAdmissionFailure(error) {
10081
+ if (error instanceof ConversationWriterEpochError) {
10082
+ return true;
10083
+ }
10084
+ return (error instanceof ConversationMemoryError &&
10085
+ error.code === "CONFIG_ERROR" &&
10086
+ this.conversationMemoryConfig?.conversationMemory
10087
+ ?.erasureWriteProtocol === "conversation-erasure-v1");
10088
+ }
10070
10089
  /**
10071
10090
  * Handle stream error with fallback
10072
10091
  */
@@ -10080,6 +10099,12 @@ Current user's request: ${currentInput}`;
10080
10099
  if (error instanceof ContextBudgetExceededError) {
10081
10100
  throw error;
10082
10101
  }
10102
+ // A writer that opted in to the erasure write protocol and could not be
10103
+ // admitted must not be answered by a fallback provider that has none of
10104
+ // its history and stores nothing: fail closed, as generate() does.
10105
+ if (this.isStrictConversationAdmissionFailure(error)) {
10106
+ throw error;
10107
+ }
10083
10108
  logger.error("Stream generation failed, attempting fallback", {
10084
10109
  error: error instanceof Error ? error.message : String(error),
10085
10110
  });
@@ -128,6 +128,14 @@ export type MemoryToolResultRecord = {
128
128
  export type ConversationMemoryConfig = {
129
129
  /** Enable conversation memory feature */
130
130
  enabled: boolean;
131
+ /**
132
+ * Opt in to the `conversation-erasure-v1` write protocol on the Redis
133
+ * backend. Initialization then refuses to proceed (and `NeuroLink` does not
134
+ * fall back to in-memory history) unless the server is a standalone Redis
135
+ * with `maxmemory-policy noeviction`. Left unset, writers keep the ordinary
136
+ * storage behaviour and cannot erase permanently.
137
+ */
138
+ erasureWriteProtocol?: ConversationErasureProtocol;
131
139
  /**
132
140
  * How a session's stored tool steps are replayed into later prompts.
133
141
  * Default `"marker"`. `"full"` replays real tool-call / tool-result turns
@@ -473,10 +481,83 @@ export type ConversationMemoryEvents = {
473
481
  * Error types specific to conversation memory
474
482
  */
475
483
  export declare class ConversationMemoryError extends Error {
476
- code: "STORAGE_ERROR" | "CONFIG_ERROR" | "SESSION_NOT_FOUND" | "CLEANUP_ERROR";
484
+ code: "STORAGE_ERROR" | "CONFIG_ERROR" | "SESSION_NOT_FOUND" | "CLEANUP_ERROR" | "SESSION_ERASED";
477
485
  details?: Record<string, unknown> | undefined;
478
- constructor(message: string, code: "STORAGE_ERROR" | "CONFIG_ERROR" | "SESSION_NOT_FOUND" | "CLEANUP_ERROR", details?: Record<string, unknown> | undefined);
486
+ constructor(message: string, code: "STORAGE_ERROR" | "CONFIG_ERROR" | "SESSION_NOT_FOUND" | "CLEANUP_ERROR" | "SESSION_ERASED", details?: Record<string, unknown> | undefined);
479
487
  }
488
+ /** Write-protocol identifier of the conversation erasure fence. */
489
+ export type ConversationErasureProtocol = "conversation-erasure-v1";
490
+ /**
491
+ * Raised when a write reaches a session that was permanently erased. The
492
+ * erasure tombstone outlives the session's data, so a late writer cannot
493
+ * resurrect it.
494
+ */
495
+ export declare class ConversationSessionErasedError extends Error {
496
+ readonly code = "SESSION_ERASED";
497
+ constructor();
498
+ }
499
+ /**
500
+ * Raised when a fenced write cannot prove it belongs to the store epoch it was
501
+ * admitted under: the context is missing or not fenced, the Redis server
502
+ * restarted, or its eviction counter moved.
503
+ */
504
+ export declare class ConversationWriterEpochError extends Error {
505
+ readonly code = "SESSION_WRITER_EPOCH_LOST";
506
+ constructor();
507
+ }
508
+ /**
509
+ * What a Redis conversation writer resolved at initialization.
510
+ * `legacy` keeps the ordinary storage behaviour and cannot erase permanently;
511
+ * `fenced` binds every write to the server run id, store epoch and eviction
512
+ * counter observed at initialization.
513
+ */
514
+ export type ConversationErasureWriteContext = {
515
+ mode: "legacy";
516
+ reason: string;
517
+ strict: false;
518
+ } | {
519
+ mode: "fenced";
520
+ strict: boolean;
521
+ runId: string;
522
+ epoch: string;
523
+ evictedKeys: string;
524
+ evictionPolicy: "noeviction";
525
+ };
526
+ /** Whether this writer participates in the v1 erasure fence. */
527
+ export type ConversationErasureWriterStatus = {
528
+ status: "unsupported";
529
+ protocol: ConversationErasureProtocol;
530
+ strict: boolean;
531
+ reason: string;
532
+ } | {
533
+ status: "participating";
534
+ strict: boolean;
535
+ backend: "redis-standalone";
536
+ protocol: ConversationErasureProtocol;
537
+ serverRunIdDigest: string;
538
+ storeEpochDigest: string;
539
+ evictionPolicy: "noeviction";
540
+ evictionCounter: number;
541
+ };
542
+ /** Receipt returned by a confirmed permanent erasure. */
543
+ export type ConversationErasureResult = {
544
+ status: "erased";
545
+ backend: "redis-standalone";
546
+ protocol: ConversationErasureProtocol;
547
+ participatingWritesFenced: true;
548
+ strictWriteProtocol: true;
549
+ legacyWritersFenced: false;
550
+ sessionId: string;
551
+ userId: string;
552
+ namespaceDigest: string;
553
+ serverRunIdDigest: string;
554
+ storeEpochDigest: string;
555
+ evictionPolicy: "noeviction";
556
+ evictionCounter: number;
557
+ deletedKeys: number;
558
+ removedIndexMembers: number;
559
+ tombstoneExpiry: null;
560
+ };
480
561
  /**
481
562
  * NeuroLink initialization options
482
563
  * Configuration for creating NeuroLink instances with conversation memory
@@ -45,3 +45,27 @@ export class ConversationMemoryError extends Error {
45
45
  this.name = "ConversationMemoryError";
46
46
  }
47
47
  }
48
+ /**
49
+ * Raised when a write reaches a session that was permanently erased. The
50
+ * erasure tombstone outlives the session's data, so a late writer cannot
51
+ * resurrect it.
52
+ */
53
+ export class ConversationSessionErasedError extends Error {
54
+ code = "SESSION_ERASED";
55
+ constructor() {
56
+ super("Session permanently erased; write refused");
57
+ this.name = "ConversationSessionErasedError";
58
+ }
59
+ }
60
+ /**
61
+ * Raised when a fenced write cannot prove it belongs to the store epoch it was
62
+ * admitted under: the context is missing or not fenced, the Redis server
63
+ * restarted, or its eviction counter moved.
64
+ */
65
+ export class ConversationWriterEpochError extends Error {
66
+ code = "SESSION_WRITER_EPOCH_LOST";
67
+ constructor() {
68
+ super("Conversation writer epoch is unavailable or changed; write refused");
69
+ this.name = "ConversationWriterEpochError";
70
+ }
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "13.9.0",
3
+ "version": "13.10.0",
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": {
@@ -120,6 +120,7 @@
120
120
  "test:span-content-redaction": "pnpm exec tsx test/continuous-test-suite-span-content-redaction.ts",
121
121
  "test:voice-turn-memory": "pnpm exec tsx test/continuous-test-suite-voice-turn-memory.ts",
122
122
  "test:redis-atomic-expiry": "pnpm exec tsx test/continuous-test-suite-redis-atomic-expiry.ts",
123
+ "test:conversation-erasure-fence": "pnpm exec tsx test/continuous-test-suite-conversation-erasure-fence.ts",
123
124
  "test:realtime-voice": "pnpm exec tsx test/continuous-test-suite-realtime-voice.ts",
124
125
  "test:error-classification-e2e": "pnpm exec tsx test/continuous-test-suite-error-classification-e2e.ts",
125
126
  "test:error-classifier-contract": "pnpm exec tsx test/continuous-test-suite-error-classifier-contract.ts",