@juspay/neurolink 9.39.0 → 9.40.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 +6 -0
- package/dist/browser/neurolink.min.js +12 -5
- package/dist/lib/neurolink.d.ts +6 -1
- package/dist/lib/neurolink.js +76 -12
- package/dist/lib/types/generateTypes.d.ts +29 -0
- package/dist/lib/types/index.d.ts +1 -1
- package/dist/lib/types/streamTypes.d.ts +7 -0
- package/dist/neurolink.d.ts +6 -1
- package/dist/neurolink.js +76 -12
- package/dist/types/generateTypes.d.ts +29 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/streamTypes.d.ts +7 -0
- package/package.json +2 -2
package/dist/lib/neurolink.d.ts
CHANGED
|
@@ -181,6 +181,10 @@ export declare class NeuroLink {
|
|
|
181
181
|
private registerMemoryRetrievalTools;
|
|
182
182
|
/** Format memory context for prompt inclusion */
|
|
183
183
|
private formatMemoryContext;
|
|
184
|
+
/**
|
|
185
|
+
* Format memory context from multiple users into a labeled block.
|
|
186
|
+
*/
|
|
187
|
+
private formatMultiUserMemoryContext;
|
|
184
188
|
/**
|
|
185
189
|
* Determine whether memory should be read (retrieved) for this call.
|
|
186
190
|
* Respects both the global memory SDK config and per-call overrides.
|
|
@@ -192,13 +196,14 @@ export declare class NeuroLink {
|
|
|
192
196
|
*/
|
|
193
197
|
private shouldWriteMemory;
|
|
194
198
|
/**
|
|
195
|
-
* Retrieve condensed memory for a user.
|
|
199
|
+
* Retrieve condensed memory for a user (and optionally additional users).
|
|
196
200
|
* Returns the input text enhanced with memory context, or unchanged if no memory.
|
|
197
201
|
*/
|
|
198
202
|
private retrieveMemory;
|
|
199
203
|
/**
|
|
200
204
|
* Store a conversation turn in memory (non-blocking).
|
|
201
205
|
* Calls add(userId, content) which internally condenses old + new via LLM.
|
|
206
|
+
* Supports additional users with per-user prompt and maxWords overrides.
|
|
202
207
|
*/
|
|
203
208
|
private storeMemoryInBackground;
|
|
204
209
|
/**
|
package/dist/lib/neurolink.js
CHANGED
|
@@ -823,6 +823,20 @@ export class NeuroLink {
|
|
|
823
823
|
|
|
824
824
|
${memoryContext}
|
|
825
825
|
|
|
826
|
+
Current user's request: ${currentInput}`;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Format memory context from multiple users into a labeled block.
|
|
830
|
+
*/
|
|
831
|
+
formatMultiUserMemoryContext(memories, currentInput) {
|
|
832
|
+
const memoryBlocks = [];
|
|
833
|
+
for (const [label, memory] of memories) {
|
|
834
|
+
memoryBlocks.push(`[${label}]\n${memory}`);
|
|
835
|
+
}
|
|
836
|
+
return `Context from previous conversations:
|
|
837
|
+
|
|
838
|
+
${memoryBlocks.join("\n\n")}
|
|
839
|
+
|
|
826
840
|
Current user's request: ${currentInput}`;
|
|
827
841
|
}
|
|
828
842
|
/**
|
|
@@ -863,32 +877,71 @@ Current user's request: ${currentInput}`;
|
|
|
863
877
|
return true;
|
|
864
878
|
}
|
|
865
879
|
/**
|
|
866
|
-
* Retrieve condensed memory for a user.
|
|
880
|
+
* Retrieve condensed memory for a user (and optionally additional users).
|
|
867
881
|
* Returns the input text enhanced with memory context, or unchanged if no memory.
|
|
868
882
|
*/
|
|
869
|
-
async retrieveMemory(inputText, userId) {
|
|
883
|
+
async retrieveMemory(inputText, userId, additionalUsers) {
|
|
870
884
|
const client = this.ensureMemoryReady();
|
|
871
885
|
if (!client) {
|
|
872
886
|
return inputText;
|
|
873
887
|
}
|
|
874
|
-
|
|
875
|
-
|
|
888
|
+
// Collect all user IDs to read (primary + additional users with read !== false)
|
|
889
|
+
const readableAdditional = (additionalUsers || []).filter((u) => u.read !== false);
|
|
890
|
+
if (readableAdditional.length === 0) {
|
|
891
|
+
// Single user — use original fast path
|
|
892
|
+
const memory = await client.get(userId);
|
|
893
|
+
if (!memory) {
|
|
894
|
+
return inputText;
|
|
895
|
+
}
|
|
896
|
+
return this.formatMemoryContext(memory, inputText);
|
|
897
|
+
}
|
|
898
|
+
// Multi-user: fetch all memories in parallel
|
|
899
|
+
// Build entries with labels for formatting
|
|
900
|
+
const entries = [
|
|
901
|
+
{ id: userId, label: "User" },
|
|
902
|
+
...readableAdditional.map((u) => ({
|
|
903
|
+
id: u.userId,
|
|
904
|
+
label: u.label || u.userId,
|
|
905
|
+
})),
|
|
906
|
+
];
|
|
907
|
+
const results = await Promise.all(entries.map(async (entry) => {
|
|
908
|
+
const memory = await client.get(entry.id);
|
|
909
|
+
return { ...entry, memory };
|
|
910
|
+
}));
|
|
911
|
+
const memories = new Map();
|
|
912
|
+
for (const { label, memory } of results) {
|
|
913
|
+
if (memory) {
|
|
914
|
+
memories.set(label, memory);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (memories.size === 0) {
|
|
876
918
|
return inputText;
|
|
877
919
|
}
|
|
878
|
-
return this.
|
|
920
|
+
return this.formatMultiUserMemoryContext(memories, inputText);
|
|
879
921
|
}
|
|
880
922
|
/**
|
|
881
923
|
* Store a conversation turn in memory (non-blocking).
|
|
882
924
|
* Calls add(userId, content) which internally condenses old + new via LLM.
|
|
925
|
+
* Supports additional users with per-user prompt and maxWords overrides.
|
|
883
926
|
*/
|
|
884
|
-
storeMemoryInBackground(originalPrompt, responseContent, userId) {
|
|
927
|
+
storeMemoryInBackground(originalPrompt, responseContent, userId, additionalUsers) {
|
|
885
928
|
setImmediate(async () => {
|
|
886
929
|
try {
|
|
887
930
|
const client = this.ensureMemoryReady();
|
|
888
|
-
if (client) {
|
|
889
|
-
|
|
890
|
-
await client.add(userId, content);
|
|
931
|
+
if (!client) {
|
|
932
|
+
return;
|
|
891
933
|
}
|
|
934
|
+
const content = `User: ${originalPrompt}\nAssistant: ${responseContent}`;
|
|
935
|
+
// Collect all users to write: primary + additional users with write !== false
|
|
936
|
+
const writeOps = [client.add(userId, content)];
|
|
937
|
+
const writableAdditional = (additionalUsers || []).filter((u) => u.write !== false);
|
|
938
|
+
for (const user of writableAdditional) {
|
|
939
|
+
const addOptions = user.prompt || user.maxWords
|
|
940
|
+
? { prompt: user.prompt, maxWords: user.maxWords }
|
|
941
|
+
: undefined;
|
|
942
|
+
writeOps.push(client.add(user.userId, content, addOptions));
|
|
943
|
+
}
|
|
944
|
+
await Promise.all(writeOps);
|
|
892
945
|
}
|
|
893
946
|
catch (error) {
|
|
894
947
|
logger.warn("Memory storage failed:", error);
|
|
@@ -2428,6 +2481,17 @@ Current user's request: ${currentInput}`;
|
|
|
2428
2481
|
});
|
|
2429
2482
|
}
|
|
2430
2483
|
}
|
|
2484
|
+
// Memory retrieval for generate path
|
|
2485
|
+
if (this.shouldReadMemory(options.memory, options.context?.userId) &&
|
|
2486
|
+
options.context?.userId) {
|
|
2487
|
+
try {
|
|
2488
|
+
options.input.text = await this.retrieveMemory(options.input.text, options.context.userId, options.memory?.additionalUsers);
|
|
2489
|
+
logger.debug("Memory retrieval successful (generate)");
|
|
2490
|
+
}
|
|
2491
|
+
catch (error) {
|
|
2492
|
+
logger.warn("Memory retrieval failed (generate):", error);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2431
2495
|
// 🔧 CRITICAL FIX: Convert to TextGenerationOptions while preserving the input object for multimodal support
|
|
2432
2496
|
const baseOptions = {
|
|
2433
2497
|
prompt: options.input.text,
|
|
@@ -2613,7 +2677,7 @@ Current user's request: ${currentInput}`;
|
|
|
2613
2677
|
// Memory storage
|
|
2614
2678
|
if (this.shouldWriteMemory(options.memory, options.context?.userId, generateResult.content) &&
|
|
2615
2679
|
options.context?.userId) {
|
|
2616
|
-
this.storeMemoryInBackground(originalPrompt ?? "", generateResult.content.trim(), options.context.userId);
|
|
2680
|
+
this.storeMemoryInBackground(originalPrompt ?? "", generateResult.content.trim(), options.context.userId, options.memory?.additionalUsers);
|
|
2617
2681
|
}
|
|
2618
2682
|
}
|
|
2619
2683
|
/**
|
|
@@ -4411,7 +4475,7 @@ Current user's request: ${currentInput}`;
|
|
|
4411
4475
|
if (this.shouldReadMemory(options.memory, options.context?.userId) &&
|
|
4412
4476
|
options.context?.userId) {
|
|
4413
4477
|
try {
|
|
4414
|
-
options.input.text = await this.retrieveMemory(options.input.text, options.context.userId);
|
|
4478
|
+
options.input.text = await this.retrieveMemory(options.input.text, options.context.userId, options.memory?.additionalUsers);
|
|
4415
4479
|
logger.debug("Memory retrieval successful");
|
|
4416
4480
|
}
|
|
4417
4481
|
catch (error) {
|
|
@@ -4724,7 +4788,7 @@ Current user's request: ${currentInput}`;
|
|
|
4724
4788
|
}
|
|
4725
4789
|
}
|
|
4726
4790
|
if (this.shouldWriteMemory(enhancedOptions.memory, enhancedOptions.context?.userId, accumulatedContent)) {
|
|
4727
|
-
this.storeMemoryInBackground(originalPrompt ?? "", accumulatedContent.trim(), enhancedOptions.context?.userId);
|
|
4791
|
+
this.storeMemoryInBackground(originalPrompt ?? "", accumulatedContent.trim(), enhancedOptions.context?.userId, enhancedOptions.memory?.additionalUsers);
|
|
4728
4792
|
}
|
|
4729
4793
|
}
|
|
4730
4794
|
/**
|
|
@@ -426,8 +426,37 @@ export type GenerateOptions = {
|
|
|
426
426
|
read?: boolean;
|
|
427
427
|
/** Whether to write (add/condense) the conversation into memory after completion. Defaults to true. */
|
|
428
428
|
write?: boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Additional users whose memory should be retrieved/stored alongside the primary user.
|
|
431
|
+
* Each entry can override the condensation prompt and maxWords for that user.
|
|
432
|
+
* Primary user is still determined by context.userId.
|
|
433
|
+
*/
|
|
434
|
+
additionalUsers?: AdditionalMemoryUser[];
|
|
429
435
|
};
|
|
430
436
|
};
|
|
437
|
+
/**
|
|
438
|
+
* Represents an additional user whose memory should be included in a generate/stream call.
|
|
439
|
+
* Allows per-user prompt overrides for different memory condensation strategies
|
|
440
|
+
* (e.g. personal preferences vs org-level policies).
|
|
441
|
+
*/
|
|
442
|
+
export type AdditionalMemoryUser = {
|
|
443
|
+
/** The user/owner ID to retrieve or store memory for. */
|
|
444
|
+
userId: string;
|
|
445
|
+
/**
|
|
446
|
+
* Human-readable label used in the formatted memory context.
|
|
447
|
+
* E.g. "Organization Policy", "Team Context", "User Preferences".
|
|
448
|
+
* If not provided, defaults to userId.
|
|
449
|
+
*/
|
|
450
|
+
label?: string;
|
|
451
|
+
/** Whether to read this user's memory and include in context. Defaults to true. */
|
|
452
|
+
read?: boolean;
|
|
453
|
+
/** Whether to write conversation into this user's memory. Defaults to true. */
|
|
454
|
+
write?: boolean;
|
|
455
|
+
/** Custom condensation prompt for this user. Overrides the default Hippocampus prompt. */
|
|
456
|
+
prompt?: string;
|
|
457
|
+
/** Max words for this user's condensed memory. Overrides the default maxWords. */
|
|
458
|
+
maxWords?: number;
|
|
459
|
+
};
|
|
431
460
|
/**
|
|
432
461
|
* Generate function result type - Primary output format
|
|
433
462
|
* Future-ready for multi-modal outputs while maintaining text focus
|
|
@@ -22,7 +22,7 @@ export type { DomainConfig, DomainConfigOptions, DomainEvaluationCriteria, Domai
|
|
|
22
22
|
export * from "./evaluation.js";
|
|
23
23
|
export * from "./evaluationProviders.js";
|
|
24
24
|
export * from "./fileTypes.js";
|
|
25
|
-
export type { EnhancedGenerateResult, EnhancedProvider, FactoryEnhancedProvider, GenerateOptions, GenerateResult as GenerateApiResult, // Renamed to avoid conflict with cli.js GenerateResult
|
|
25
|
+
export type { AdditionalMemoryUser, EnhancedGenerateResult, EnhancedProvider, FactoryEnhancedProvider, GenerateOptions, GenerateResult as GenerateApiResult, // Renamed to avoid conflict with cli.js GenerateResult
|
|
26
26
|
TextGenerationOptions, TextGenerationResult, UnifiedGenerationOptions, } from "./generateTypes.js";
|
|
27
27
|
export * from "./hitlTypes.js";
|
|
28
28
|
export * from "./middlewareTypes.js";
|
|
@@ -10,6 +10,7 @@ import type { Content, ImageWithAltText } from "./content.js";
|
|
|
10
10
|
import type { ChatMessage } from "./conversation.js";
|
|
11
11
|
import type { AIModelProviderConfig } from "./providers.js";
|
|
12
12
|
import type { TTSChunk, TTSOptions } from "./ttsTypes.js";
|
|
13
|
+
import type { AdditionalMemoryUser } from "./generateTypes.js";
|
|
13
14
|
import type { StandardRecord, ValidationSchema } from "./typeAliases.js";
|
|
14
15
|
/**
|
|
15
16
|
* Progress tracking and metadata for streaming operations
|
|
@@ -435,6 +436,12 @@ export type StreamOptions = {
|
|
|
435
436
|
read?: boolean;
|
|
436
437
|
/** Whether to write (add/condense) the conversation into memory after completion. Defaults to true. */
|
|
437
438
|
write?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Additional users whose memory should be retrieved/stored alongside the primary user.
|
|
441
|
+
* Each entry can override the condensation prompt and maxWords for that user.
|
|
442
|
+
* Primary user is still determined by context.userId.
|
|
443
|
+
*/
|
|
444
|
+
additionalUsers?: AdditionalMemoryUser[];
|
|
438
445
|
};
|
|
439
446
|
};
|
|
440
447
|
/**
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -181,6 +181,10 @@ export declare class NeuroLink {
|
|
|
181
181
|
private registerMemoryRetrievalTools;
|
|
182
182
|
/** Format memory context for prompt inclusion */
|
|
183
183
|
private formatMemoryContext;
|
|
184
|
+
/**
|
|
185
|
+
* Format memory context from multiple users into a labeled block.
|
|
186
|
+
*/
|
|
187
|
+
private formatMultiUserMemoryContext;
|
|
184
188
|
/**
|
|
185
189
|
* Determine whether memory should be read (retrieved) for this call.
|
|
186
190
|
* Respects both the global memory SDK config and per-call overrides.
|
|
@@ -192,13 +196,14 @@ export declare class NeuroLink {
|
|
|
192
196
|
*/
|
|
193
197
|
private shouldWriteMemory;
|
|
194
198
|
/**
|
|
195
|
-
* Retrieve condensed memory for a user.
|
|
199
|
+
* Retrieve condensed memory for a user (and optionally additional users).
|
|
196
200
|
* Returns the input text enhanced with memory context, or unchanged if no memory.
|
|
197
201
|
*/
|
|
198
202
|
private retrieveMemory;
|
|
199
203
|
/**
|
|
200
204
|
* Store a conversation turn in memory (non-blocking).
|
|
201
205
|
* Calls add(userId, content) which internally condenses old + new via LLM.
|
|
206
|
+
* Supports additional users with per-user prompt and maxWords overrides.
|
|
202
207
|
*/
|
|
203
208
|
private storeMemoryInBackground;
|
|
204
209
|
/**
|
package/dist/neurolink.js
CHANGED
|
@@ -823,6 +823,20 @@ export class NeuroLink {
|
|
|
823
823
|
|
|
824
824
|
${memoryContext}
|
|
825
825
|
|
|
826
|
+
Current user's request: ${currentInput}`;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Format memory context from multiple users into a labeled block.
|
|
830
|
+
*/
|
|
831
|
+
formatMultiUserMemoryContext(memories, currentInput) {
|
|
832
|
+
const memoryBlocks = [];
|
|
833
|
+
for (const [label, memory] of memories) {
|
|
834
|
+
memoryBlocks.push(`[${label}]\n${memory}`);
|
|
835
|
+
}
|
|
836
|
+
return `Context from previous conversations:
|
|
837
|
+
|
|
838
|
+
${memoryBlocks.join("\n\n")}
|
|
839
|
+
|
|
826
840
|
Current user's request: ${currentInput}`;
|
|
827
841
|
}
|
|
828
842
|
/**
|
|
@@ -863,32 +877,71 @@ Current user's request: ${currentInput}`;
|
|
|
863
877
|
return true;
|
|
864
878
|
}
|
|
865
879
|
/**
|
|
866
|
-
* Retrieve condensed memory for a user.
|
|
880
|
+
* Retrieve condensed memory for a user (and optionally additional users).
|
|
867
881
|
* Returns the input text enhanced with memory context, or unchanged if no memory.
|
|
868
882
|
*/
|
|
869
|
-
async retrieveMemory(inputText, userId) {
|
|
883
|
+
async retrieveMemory(inputText, userId, additionalUsers) {
|
|
870
884
|
const client = this.ensureMemoryReady();
|
|
871
885
|
if (!client) {
|
|
872
886
|
return inputText;
|
|
873
887
|
}
|
|
874
|
-
|
|
875
|
-
|
|
888
|
+
// Collect all user IDs to read (primary + additional users with read !== false)
|
|
889
|
+
const readableAdditional = (additionalUsers || []).filter((u) => u.read !== false);
|
|
890
|
+
if (readableAdditional.length === 0) {
|
|
891
|
+
// Single user — use original fast path
|
|
892
|
+
const memory = await client.get(userId);
|
|
893
|
+
if (!memory) {
|
|
894
|
+
return inputText;
|
|
895
|
+
}
|
|
896
|
+
return this.formatMemoryContext(memory, inputText);
|
|
897
|
+
}
|
|
898
|
+
// Multi-user: fetch all memories in parallel
|
|
899
|
+
// Build entries with labels for formatting
|
|
900
|
+
const entries = [
|
|
901
|
+
{ id: userId, label: "User" },
|
|
902
|
+
...readableAdditional.map((u) => ({
|
|
903
|
+
id: u.userId,
|
|
904
|
+
label: u.label || u.userId,
|
|
905
|
+
})),
|
|
906
|
+
];
|
|
907
|
+
const results = await Promise.all(entries.map(async (entry) => {
|
|
908
|
+
const memory = await client.get(entry.id);
|
|
909
|
+
return { ...entry, memory };
|
|
910
|
+
}));
|
|
911
|
+
const memories = new Map();
|
|
912
|
+
for (const { label, memory } of results) {
|
|
913
|
+
if (memory) {
|
|
914
|
+
memories.set(label, memory);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (memories.size === 0) {
|
|
876
918
|
return inputText;
|
|
877
919
|
}
|
|
878
|
-
return this.
|
|
920
|
+
return this.formatMultiUserMemoryContext(memories, inputText);
|
|
879
921
|
}
|
|
880
922
|
/**
|
|
881
923
|
* Store a conversation turn in memory (non-blocking).
|
|
882
924
|
* Calls add(userId, content) which internally condenses old + new via LLM.
|
|
925
|
+
* Supports additional users with per-user prompt and maxWords overrides.
|
|
883
926
|
*/
|
|
884
|
-
storeMemoryInBackground(originalPrompt, responseContent, userId) {
|
|
927
|
+
storeMemoryInBackground(originalPrompt, responseContent, userId, additionalUsers) {
|
|
885
928
|
setImmediate(async () => {
|
|
886
929
|
try {
|
|
887
930
|
const client = this.ensureMemoryReady();
|
|
888
|
-
if (client) {
|
|
889
|
-
|
|
890
|
-
await client.add(userId, content);
|
|
931
|
+
if (!client) {
|
|
932
|
+
return;
|
|
891
933
|
}
|
|
934
|
+
const content = `User: ${originalPrompt}\nAssistant: ${responseContent}`;
|
|
935
|
+
// Collect all users to write: primary + additional users with write !== false
|
|
936
|
+
const writeOps = [client.add(userId, content)];
|
|
937
|
+
const writableAdditional = (additionalUsers || []).filter((u) => u.write !== false);
|
|
938
|
+
for (const user of writableAdditional) {
|
|
939
|
+
const addOptions = user.prompt || user.maxWords
|
|
940
|
+
? { prompt: user.prompt, maxWords: user.maxWords }
|
|
941
|
+
: undefined;
|
|
942
|
+
writeOps.push(client.add(user.userId, content, addOptions));
|
|
943
|
+
}
|
|
944
|
+
await Promise.all(writeOps);
|
|
892
945
|
}
|
|
893
946
|
catch (error) {
|
|
894
947
|
logger.warn("Memory storage failed:", error);
|
|
@@ -2428,6 +2481,17 @@ Current user's request: ${currentInput}`;
|
|
|
2428
2481
|
});
|
|
2429
2482
|
}
|
|
2430
2483
|
}
|
|
2484
|
+
// Memory retrieval for generate path
|
|
2485
|
+
if (this.shouldReadMemory(options.memory, options.context?.userId) &&
|
|
2486
|
+
options.context?.userId) {
|
|
2487
|
+
try {
|
|
2488
|
+
options.input.text = await this.retrieveMemory(options.input.text, options.context.userId, options.memory?.additionalUsers);
|
|
2489
|
+
logger.debug("Memory retrieval successful (generate)");
|
|
2490
|
+
}
|
|
2491
|
+
catch (error) {
|
|
2492
|
+
logger.warn("Memory retrieval failed (generate):", error);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2431
2495
|
// 🔧 CRITICAL FIX: Convert to TextGenerationOptions while preserving the input object for multimodal support
|
|
2432
2496
|
const baseOptions = {
|
|
2433
2497
|
prompt: options.input.text,
|
|
@@ -2613,7 +2677,7 @@ Current user's request: ${currentInput}`;
|
|
|
2613
2677
|
// Memory storage
|
|
2614
2678
|
if (this.shouldWriteMemory(options.memory, options.context?.userId, generateResult.content) &&
|
|
2615
2679
|
options.context?.userId) {
|
|
2616
|
-
this.storeMemoryInBackground(originalPrompt ?? "", generateResult.content.trim(), options.context.userId);
|
|
2680
|
+
this.storeMemoryInBackground(originalPrompt ?? "", generateResult.content.trim(), options.context.userId, options.memory?.additionalUsers);
|
|
2617
2681
|
}
|
|
2618
2682
|
}
|
|
2619
2683
|
/**
|
|
@@ -4411,7 +4475,7 @@ Current user's request: ${currentInput}`;
|
|
|
4411
4475
|
if (this.shouldReadMemory(options.memory, options.context?.userId) &&
|
|
4412
4476
|
options.context?.userId) {
|
|
4413
4477
|
try {
|
|
4414
|
-
options.input.text = await this.retrieveMemory(options.input.text, options.context.userId);
|
|
4478
|
+
options.input.text = await this.retrieveMemory(options.input.text, options.context.userId, options.memory?.additionalUsers);
|
|
4415
4479
|
logger.debug("Memory retrieval successful");
|
|
4416
4480
|
}
|
|
4417
4481
|
catch (error) {
|
|
@@ -4724,7 +4788,7 @@ Current user's request: ${currentInput}`;
|
|
|
4724
4788
|
}
|
|
4725
4789
|
}
|
|
4726
4790
|
if (this.shouldWriteMemory(enhancedOptions.memory, enhancedOptions.context?.userId, accumulatedContent)) {
|
|
4727
|
-
this.storeMemoryInBackground(originalPrompt ?? "", accumulatedContent.trim(), enhancedOptions.context?.userId);
|
|
4791
|
+
this.storeMemoryInBackground(originalPrompt ?? "", accumulatedContent.trim(), enhancedOptions.context?.userId, enhancedOptions.memory?.additionalUsers);
|
|
4728
4792
|
}
|
|
4729
4793
|
}
|
|
4730
4794
|
/**
|
|
@@ -426,8 +426,37 @@ export type GenerateOptions = {
|
|
|
426
426
|
read?: boolean;
|
|
427
427
|
/** Whether to write (add/condense) the conversation into memory after completion. Defaults to true. */
|
|
428
428
|
write?: boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Additional users whose memory should be retrieved/stored alongside the primary user.
|
|
431
|
+
* Each entry can override the condensation prompt and maxWords for that user.
|
|
432
|
+
* Primary user is still determined by context.userId.
|
|
433
|
+
*/
|
|
434
|
+
additionalUsers?: AdditionalMemoryUser[];
|
|
429
435
|
};
|
|
430
436
|
};
|
|
437
|
+
/**
|
|
438
|
+
* Represents an additional user whose memory should be included in a generate/stream call.
|
|
439
|
+
* Allows per-user prompt overrides for different memory condensation strategies
|
|
440
|
+
* (e.g. personal preferences vs org-level policies).
|
|
441
|
+
*/
|
|
442
|
+
export type AdditionalMemoryUser = {
|
|
443
|
+
/** The user/owner ID to retrieve or store memory for. */
|
|
444
|
+
userId: string;
|
|
445
|
+
/**
|
|
446
|
+
* Human-readable label used in the formatted memory context.
|
|
447
|
+
* E.g. "Organization Policy", "Team Context", "User Preferences".
|
|
448
|
+
* If not provided, defaults to userId.
|
|
449
|
+
*/
|
|
450
|
+
label?: string;
|
|
451
|
+
/** Whether to read this user's memory and include in context. Defaults to true. */
|
|
452
|
+
read?: boolean;
|
|
453
|
+
/** Whether to write conversation into this user's memory. Defaults to true. */
|
|
454
|
+
write?: boolean;
|
|
455
|
+
/** Custom condensation prompt for this user. Overrides the default Hippocampus prompt. */
|
|
456
|
+
prompt?: string;
|
|
457
|
+
/** Max words for this user's condensed memory. Overrides the default maxWords. */
|
|
458
|
+
maxWords?: number;
|
|
459
|
+
};
|
|
431
460
|
/**
|
|
432
461
|
* Generate function result type - Primary output format
|
|
433
462
|
* Future-ready for multi-modal outputs while maintaining text focus
|
package/dist/types/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type { DomainConfig, DomainConfigOptions, DomainEvaluationCriteria, Domai
|
|
|
22
22
|
export * from "./evaluation.js";
|
|
23
23
|
export * from "./evaluationProviders.js";
|
|
24
24
|
export * from "./fileTypes.js";
|
|
25
|
-
export type { EnhancedGenerateResult, EnhancedProvider, FactoryEnhancedProvider, GenerateOptions, GenerateResult as GenerateApiResult, // Renamed to avoid conflict with cli.js GenerateResult
|
|
25
|
+
export type { AdditionalMemoryUser, EnhancedGenerateResult, EnhancedProvider, FactoryEnhancedProvider, GenerateOptions, GenerateResult as GenerateApiResult, // Renamed to avoid conflict with cli.js GenerateResult
|
|
26
26
|
TextGenerationOptions, TextGenerationResult, UnifiedGenerationOptions, } from "./generateTypes.js";
|
|
27
27
|
export * from "./hitlTypes.js";
|
|
28
28
|
export * from "./middlewareTypes.js";
|
|
@@ -10,6 +10,7 @@ import type { Content, ImageWithAltText } from "./content.js";
|
|
|
10
10
|
import type { ChatMessage } from "./conversation.js";
|
|
11
11
|
import type { AIModelProviderConfig } from "./providers.js";
|
|
12
12
|
import type { TTSChunk, TTSOptions } from "./ttsTypes.js";
|
|
13
|
+
import type { AdditionalMemoryUser } from "./generateTypes.js";
|
|
13
14
|
import type { StandardRecord, ValidationSchema } from "./typeAliases.js";
|
|
14
15
|
/**
|
|
15
16
|
* Progress tracking and metadata for streaming operations
|
|
@@ -435,6 +436,12 @@ export type StreamOptions = {
|
|
|
435
436
|
read?: boolean;
|
|
436
437
|
/** Whether to write (add/condense) the conversation into memory after completion. Defaults to true. */
|
|
437
438
|
write?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Additional users whose memory should be retrieved/stored alongside the primary user.
|
|
441
|
+
* Each entry can override the condensation prompt and maxWords for that user.
|
|
442
|
+
* Primary user is still determined by context.userId.
|
|
443
|
+
*/
|
|
444
|
+
additionalUsers?: AdditionalMemoryUser[];
|
|
438
445
|
};
|
|
439
446
|
};
|
|
440
447
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.40.0",
|
|
4
4
|
"description": "Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and deploy AI applications with 13 providers: OpenAI, Anthropic, Google AI, AWS Bedrock, Azure, Hugging Face, Ollama, and Mistral AI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Juspay Technologies",
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
"@google/genai": "^1.43.0",
|
|
201
201
|
"@google/generative-ai": "^0.24.1",
|
|
202
202
|
"@huggingface/inference": "^4.13.14",
|
|
203
|
-
"@juspay/hippocampus": "^0.1.
|
|
203
|
+
"@juspay/hippocampus": "^0.1.4",
|
|
204
204
|
"@langfuse/otel": "^5.0.1",
|
|
205
205
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
206
206
|
"@openrouter/ai-sdk-provider": "^2.2.3",
|