@juspay/neurolink 10.3.1 → 10.4.1
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 +12 -0
- package/dist/browser/neurolink.min.js +382 -372
- package/dist/core/modules/GenerationHandler.d.ts +24 -0
- package/dist/core/modules/GenerationHandler.js +18 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/knowledge/context.d.ts +18 -0
- package/dist/knowledge/context.js +91 -0
- package/dist/knowledge/defaults.d.ts +24 -0
- package/dist/knowledge/defaults.js +29 -0
- package/dist/knowledge/engine.d.ts +35 -0
- package/dist/knowledge/engine.js +179 -0
- package/dist/knowledge/index.d.ts +15 -0
- package/dist/knowledge/index.js +15 -0
- package/dist/knowledge/indexCache.d.ts +19 -0
- package/dist/knowledge/indexCache.js +109 -0
- package/dist/knowledge/knowledgeIndex.d.ts +41 -0
- package/dist/knowledge/knowledgeIndex.js +204 -0
- package/dist/knowledge/normalize.d.ts +32 -0
- package/dist/knowledge/normalize.js +74 -0
- package/dist/knowledge/resolve.d.ts +18 -0
- package/dist/knowledge/resolve.js +156 -0
- package/dist/knowledge/retrieval.d.ts +16 -0
- package/dist/knowledge/retrieval.js +221 -0
- package/dist/lib/core/modules/GenerationHandler.d.ts +24 -0
- package/dist/lib/core/modules/GenerationHandler.js +18 -3
- package/dist/lib/files/fileTools.d.ts +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/knowledge/context.d.ts +18 -0
- package/dist/lib/knowledge/context.js +92 -0
- package/dist/lib/knowledge/defaults.d.ts +24 -0
- package/dist/lib/knowledge/defaults.js +30 -0
- package/dist/lib/knowledge/engine.d.ts +35 -0
- package/dist/lib/knowledge/engine.js +180 -0
- package/dist/lib/knowledge/index.d.ts +15 -0
- package/dist/lib/knowledge/index.js +16 -0
- package/dist/lib/knowledge/indexCache.d.ts +19 -0
- package/dist/lib/knowledge/indexCache.js +110 -0
- package/dist/lib/knowledge/knowledgeIndex.d.ts +41 -0
- package/dist/lib/knowledge/knowledgeIndex.js +205 -0
- package/dist/lib/knowledge/normalize.d.ts +32 -0
- package/dist/lib/knowledge/normalize.js +75 -0
- package/dist/lib/knowledge/resolve.d.ts +18 -0
- package/dist/lib/knowledge/resolve.js +157 -0
- package/dist/lib/knowledge/retrieval.d.ts +16 -0
- package/dist/lib/knowledge/retrieval.js +222 -0
- package/dist/lib/neurolink.d.ts +14 -1
- package/dist/lib/neurolink.js +112 -3
- package/dist/lib/types/config.d.ts +12 -0
- package/dist/lib/types/conversation.d.ts +1 -1
- package/dist/lib/types/dynamic.d.ts +12 -0
- package/dist/lib/types/generate.d.ts +14 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/knowledge.d.ts +342 -0
- package/dist/lib/types/knowledge.js +30 -0
- package/dist/lib/types/stream.d.ts +14 -0
- package/dist/neurolink.d.ts +14 -1
- package/dist/neurolink.js +112 -3
- package/dist/types/config.d.ts +12 -0
- package/dist/types/conversation.d.ts +1 -1
- package/dist/types/dynamic.d.ts +12 -0
- package/dist/types/generate.d.ts +14 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/knowledge.d.ts +342 -0
- package/dist/types/knowledge.js +29 -0
- package/dist/types/stream.d.ts +14 -0
- package/package.json +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AIProviderName } from "../constants/enums.js";
|
|
2
2
|
import type { EvaluationData } from "./evaluation.js";
|
|
3
3
|
import type { RAGConfig } from "./rag.js";
|
|
4
|
+
import type { KnowledgeGroundingMetadata, KnowledgeRequestScope } from "./knowledge.js";
|
|
4
5
|
import type { SkillsCallOptions } from "./skills.js";
|
|
5
6
|
import type { AnalyticsData, ToolExecutionEvent, ToolExecutionSummary } from "../types/index.js";
|
|
6
7
|
import type { MiddlewareFactoryOptions, OnChunkCallback, OnErrorCallback, OnFinishCallback } from "../types/middleware.js";
|
|
@@ -169,6 +170,17 @@ export type StreamChunk = {
|
|
|
169
170
|
audio: TTSChunk;
|
|
170
171
|
};
|
|
171
172
|
export type StreamOptions = {
|
|
173
|
+
/**
|
|
174
|
+
* Opt this stream call into the knowledge grounding configured on the
|
|
175
|
+
* NeuroLink instance. Defaults to `false` when omitted.
|
|
176
|
+
*/
|
|
177
|
+
useKnowledgeGrounding?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Enabled integrations used to scope knowledge retrieval for this turn.
|
|
180
|
+
* Used only when `useKnowledgeGrounding` is true and knowledge grounding is
|
|
181
|
+
* enabled on the NeuroLink instance.
|
|
182
|
+
*/
|
|
183
|
+
knowledgeContext?: KnowledgeRequestScope;
|
|
172
184
|
input: {
|
|
173
185
|
/** Prompt text. Optional for media-only modes (avatar, music) that are driven by uploaded files rather than a prompt. */
|
|
174
186
|
text?: string;
|
|
@@ -552,6 +564,8 @@ export type StreamOptions = {
|
|
|
552
564
|
* Future-ready for multi-modal outputs while maintaining text focus
|
|
553
565
|
*/
|
|
554
566
|
export type StreamResult = {
|
|
567
|
+
/** Knowledge-grounding diagnostics for this turn (present only when grounding ran). */
|
|
568
|
+
knowledge?: KnowledgeGroundingMetadata;
|
|
555
569
|
stream: AsyncIterable<{
|
|
556
570
|
content: string;
|
|
557
571
|
reasoning?: string;
|
package/dist/neurolink.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Uses real MCP infrastructure for tool discovery and execution.
|
|
7
7
|
*/
|
|
8
8
|
import type { AgentDefinition, AgentNetworkConfig, NetworkExecutionInput, NetworkExecutionOptions, NetworkExecutionResult, NetworkStreamChunk } from "./types/index.js";
|
|
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, ToolConfig } from "./types/index.js";
|
|
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, ToolConfig, KnowledgeEngineStatus } from "./types/index.js";
|
|
10
10
|
import { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
|
|
11
11
|
import type { RedisConversationMemoryManager } from "./core/redisConversationMemoryManager.js";
|
|
12
12
|
import { ExternalServerManager } from "./mcp/externalServerManager.js";
|
|
@@ -107,6 +107,7 @@ export declare class NeuroLink {
|
|
|
107
107
|
private toolRoutingConfig?;
|
|
108
108
|
private toolRoutingCacheInstance?;
|
|
109
109
|
private toolRoutingVectorCache?;
|
|
110
|
+
private knowledgeGroundingEngine?;
|
|
110
111
|
private toolDedupConfig?;
|
|
111
112
|
private toolsConfig?;
|
|
112
113
|
/** Session-scoped pins of tools discovered via search_tools (tools.discovery mode). */
|
|
@@ -629,6 +630,7 @@ export declare class NeuroLink {
|
|
|
629
630
|
* @param optionsOrPrompt.maxTokens - Maximum tokens to generate
|
|
630
631
|
* @param optionsOrPrompt.thinkingConfig - Extended thinking configuration (thinkingLevel: 'minimal'|'low'|'medium'|'high')
|
|
631
632
|
* @param optionsOrPrompt.context - Context with conversationId and userId for memory
|
|
633
|
+
* @param optionsOrPrompt.useKnowledgeGrounding - Whether to use the instance's configured knowledge for this call
|
|
632
634
|
* @returns Promise resolving to generation result with content and metadata
|
|
633
635
|
*
|
|
634
636
|
* @example Basic text generation
|
|
@@ -904,6 +906,7 @@ export declare class NeuroLink {
|
|
|
904
906
|
* @param options.enableEvaluation - Whether to include response quality evaluation
|
|
905
907
|
* @param options.context - Additional context for the request
|
|
906
908
|
* @param options.evaluationDomain - Domain for specialized evaluation
|
|
909
|
+
* @param options.useKnowledgeGrounding - Whether to use the instance's configured knowledge for this call
|
|
907
910
|
*
|
|
908
911
|
* @returns Promise resolving to StreamResult with an async iterable stream
|
|
909
912
|
*
|
|
@@ -989,6 +992,16 @@ export declare class NeuroLink {
|
|
|
989
992
|
* alone does not activate it.
|
|
990
993
|
*/
|
|
991
994
|
setToolRoutingServers(servers: ToolRoutingServerDescriptor[]): void;
|
|
995
|
+
/** Knowledge-grounding engine health (null when it was not configured). */
|
|
996
|
+
getKnowledgeStatus(): KnowledgeEngineStatus | null;
|
|
997
|
+
private appendKnowledgeGroundingBlockToSystemPrompt;
|
|
998
|
+
/**
|
|
999
|
+
* Retrieve knowledge grounding for a public generate/stream call without
|
|
1000
|
+
* mutating its options. The outer call boundary decides how to apply the
|
|
1001
|
+
* returned context. Returns undefined when the call does not opt in,
|
|
1002
|
+
* grounding is disabled/not applicable, or retrieval fails open.
|
|
1003
|
+
*/
|
|
1004
|
+
private retrieveKnowledgeGrounding;
|
|
992
1005
|
private validateStreamRequestOptions;
|
|
993
1006
|
private maybeHandleWorkflowStreamRequest;
|
|
994
1007
|
private runStandardStreamRequest;
|
package/dist/neurolink.js
CHANGED
|
@@ -32,6 +32,7 @@ import { SYSTEM_LIMITS, DEFAULT_TOOL_ROUTING_TIMEOUT_MS, MIN_RECOVERY_TURN_BUDGE
|
|
|
32
32
|
import { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
|
|
33
33
|
import { buildToolRoutingCatalog, buildRoutingQueryFromHistory, resolveToolRoutingExclusions, } from "./core/toolRouting.js";
|
|
34
34
|
import { ToolRoutingCache } from "./core/toolRoutingCache.js";
|
|
35
|
+
import { DEFAULT_RECENT_TURNS, KnowledgeGroundingEngine, } from "./knowledge/index.js";
|
|
35
36
|
import { AIProviderFactory } from "./core/factory.js";
|
|
36
37
|
import { createToolEventPayload } from "./core/toolEvents.js";
|
|
37
38
|
import { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
@@ -405,6 +406,9 @@ export class NeuroLink {
|
|
|
405
406
|
// vectors are computed once. Cleared when the catalog changes via
|
|
406
407
|
// setToolRoutingServers() so stale vectors are never reused.
|
|
407
408
|
toolRoutingVectorCache;
|
|
409
|
+
// Knowledge grounding: lexical-first host-supplied retrieval engine. Built
|
|
410
|
+
// once from constructor config and undefined unless grounding is enabled.
|
|
411
|
+
knowledgeGroundingEngine;
|
|
408
412
|
// Opt-in tool-signature deduplication config.
|
|
409
413
|
toolDedupConfig;
|
|
410
414
|
toolsConfig;
|
|
@@ -837,6 +841,18 @@ export class NeuroLink {
|
|
|
837
841
|
// multiple NeuroLink instances.
|
|
838
842
|
this.toolRoutingConfig = { ...config.toolRouting };
|
|
839
843
|
}
|
|
844
|
+
const knowledgeGroundingConfig = config?.knowledgeGrounding;
|
|
845
|
+
if (knowledgeGroundingConfig?.enabled) {
|
|
846
|
+
if (Array.isArray(knowledgeGroundingConfig.sources) &&
|
|
847
|
+
knowledgeGroundingConfig.sources.length > 0) {
|
|
848
|
+
// The engine builds its immutable index asynchronously; eligible
|
|
849
|
+
// generate() and stream() calls await readiness before retrieval.
|
|
850
|
+
this.knowledgeGroundingEngine = new KnowledgeGroundingEngine(knowledgeGroundingConfig);
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
logger.warn("[KnowledgeGrounding] enabled but no sources were provided; grounding disabled for this instance");
|
|
854
|
+
}
|
|
855
|
+
}
|
|
840
856
|
if (config?.toolDedup) {
|
|
841
857
|
this.toolDedupConfig = { ...config.toolDedup };
|
|
842
858
|
}
|
|
@@ -853,7 +869,9 @@ export class NeuroLink {
|
|
|
853
869
|
// generate() (marked so it never recursively re-routes). Fails open.
|
|
854
870
|
this.classifierRouter = config?.classifierRouter?.enabled
|
|
855
871
|
? new ClassifierRouter(config.classifierRouter, {
|
|
856
|
-
generate: (genOptions) => this.generate(
|
|
872
|
+
generate: (genOptions) => this.generate({
|
|
873
|
+
...genOptions,
|
|
874
|
+
}),
|
|
857
875
|
logger: {
|
|
858
876
|
debug: (message, meta) => logger.debug(message, meta),
|
|
859
877
|
warn: (message, meta) => logger.warn(message, meta),
|
|
@@ -3045,6 +3063,7 @@ Current user's request: ${currentInput}`;
|
|
|
3045
3063
|
* @param optionsOrPrompt.maxTokens - Maximum tokens to generate
|
|
3046
3064
|
* @param optionsOrPrompt.thinkingConfig - Extended thinking configuration (thinkingLevel: 'minimal'|'low'|'medium'|'high')
|
|
3047
3065
|
* @param optionsOrPrompt.context - Context with conversationId and userId for memory
|
|
3066
|
+
* @param optionsOrPrompt.useKnowledgeGrounding - Whether to use the instance's configured knowledge for this call
|
|
3048
3067
|
* @returns Promise resolving to generation result with content and metadata
|
|
3049
3068
|
*
|
|
3050
3069
|
* @example Basic text generation
|
|
@@ -3131,9 +3150,22 @@ Current user's request: ${currentInput}`;
|
|
|
3131
3150
|
if (typeof optionsOrPrompt !== "string") {
|
|
3132
3151
|
optionsOrPrompt = cloneOptionsForCallIsolation(optionsOrPrompt);
|
|
3133
3152
|
}
|
|
3153
|
+
// Retrieve once at the public call boundary so fallback attempts reuse the
|
|
3154
|
+
// same grounding block and internal preparation cannot inject it twice.
|
|
3155
|
+
const groundingOptions = typeof optionsOrPrompt === "string"
|
|
3156
|
+
? { input: { text: optionsOrPrompt } }
|
|
3157
|
+
: optionsOrPrompt;
|
|
3158
|
+
const knowledgeOutcome = await this.retrieveKnowledgeGrounding(groundingOptions);
|
|
3159
|
+
if (knowledgeOutcome?.ephemeralContext) {
|
|
3160
|
+
const block = knowledgeOutcome.ephemeralContext.content;
|
|
3161
|
+
optionsOrPrompt = {
|
|
3162
|
+
...groundingOptions,
|
|
3163
|
+
systemPrompt: this.appendKnowledgeGroundingBlockToSystemPrompt(groundingOptions.systemPrompt, block),
|
|
3164
|
+
};
|
|
3165
|
+
}
|
|
3134
3166
|
const startedAt = Date.now();
|
|
3135
3167
|
try {
|
|
3136
|
-
|
|
3168
|
+
const result = await this.runWithFallbackOrchestration(optionsOrPrompt, "generate", (opts) => {
|
|
3137
3169
|
// Capture root-ness before startActiveSpan makes generateSpan active.
|
|
3138
3170
|
// The actual guest-rescue stamp is deferred to executeGenerateRequest,
|
|
3139
3171
|
// AFTER prepareGenerateRequest merges auth/requestContext-derived
|
|
@@ -3142,6 +3174,10 @@ Current user's request: ${currentInput}`;
|
|
|
3142
3174
|
const generateIsRoot = !trace.getSpan(context.active());
|
|
3143
3175
|
return tracers.sdk.startActiveSpan("neurolink.generate", { kind: SpanKind.INTERNAL }, (generateSpan) => this.executeGenerateWithMetricsContext(opts, generateSpan, generateIsRoot));
|
|
3144
3176
|
});
|
|
3177
|
+
if (knowledgeOutcome) {
|
|
3178
|
+
result.knowledge = knowledgeOutcome.metadata;
|
|
3179
|
+
}
|
|
3180
|
+
return result;
|
|
3145
3181
|
}
|
|
3146
3182
|
catch (error) {
|
|
3147
3183
|
// Lifecycle middleware (wrapGenerate.catch in builtin/lifecycle.ts)
|
|
@@ -6204,6 +6240,7 @@ Current user's request: ${currentInput}`;
|
|
|
6204
6240
|
* @param options.enableEvaluation - Whether to include response quality evaluation
|
|
6205
6241
|
* @param options.context - Additional context for the request
|
|
6206
6242
|
* @param options.evaluationDomain - Domain for specialized evaluation
|
|
6243
|
+
* @param options.useKnowledgeGrounding - Whether to use the instance's configured knowledge for this call
|
|
6207
6244
|
*
|
|
6208
6245
|
* @returns Promise resolving to StreamResult with an async iterable stream
|
|
6209
6246
|
*
|
|
@@ -6261,8 +6298,23 @@ Current user's request: ${currentInput}`;
|
|
|
6261
6298
|
// top-level keys and left `options.input` shared with the caller.
|
|
6262
6299
|
options = cloneOptionsForCallIsolation(options);
|
|
6263
6300
|
const startedAt = Date.now();
|
|
6301
|
+
// Retrieve once before provider/model fallback orchestration. Every fallback
|
|
6302
|
+
// receives the same explicitly enriched options, without the retrieval helper
|
|
6303
|
+
// mutating its input or injecting the same block more than once.
|
|
6304
|
+
const knowledgeOutcome = await this.retrieveKnowledgeGrounding(options);
|
|
6305
|
+
if (knowledgeOutcome?.ephemeralContext) {
|
|
6306
|
+
const block = knowledgeOutcome.ephemeralContext.content;
|
|
6307
|
+
options = {
|
|
6308
|
+
...options,
|
|
6309
|
+
systemPrompt: this.appendKnowledgeGroundingBlockToSystemPrompt(options.systemPrompt, block),
|
|
6310
|
+
};
|
|
6311
|
+
}
|
|
6264
6312
|
try {
|
|
6265
|
-
|
|
6313
|
+
const result = await this.streamWithIterationFallback(options);
|
|
6314
|
+
if (knowledgeOutcome) {
|
|
6315
|
+
result.knowledge = knowledgeOutcome.metadata;
|
|
6316
|
+
}
|
|
6317
|
+
return result;
|
|
6266
6318
|
}
|
|
6267
6319
|
catch (error) {
|
|
6268
6320
|
// Mirror generate(): fire consumer onError for failures that
|
|
@@ -6930,6 +6982,63 @@ Current user's request: ${currentInput}`;
|
|
|
6930
6982
|
// to recompute exclusions against the new server/tool set.
|
|
6931
6983
|
this.toolRoutingCacheInstance = undefined;
|
|
6932
6984
|
}
|
|
6985
|
+
/** Knowledge-grounding engine health (null when it was not configured). */
|
|
6986
|
+
getKnowledgeStatus() {
|
|
6987
|
+
return this.knowledgeGroundingEngine?.getStatus() ?? null;
|
|
6988
|
+
}
|
|
6989
|
+
appendKnowledgeGroundingBlockToSystemPrompt(systemPrompt, block) {
|
|
6990
|
+
if (typeof systemPrompt === "function") {
|
|
6991
|
+
const originalSystemPrompt = systemPrompt;
|
|
6992
|
+
return async (context) => {
|
|
6993
|
+
const resolved = await resolveDynamicArgument(originalSystemPrompt, context);
|
|
6994
|
+
return resolved.value ? `${resolved.value}\n\n${block}` : block;
|
|
6995
|
+
};
|
|
6996
|
+
}
|
|
6997
|
+
return systemPrompt ? `${systemPrompt}\n\n${block}` : block;
|
|
6998
|
+
}
|
|
6999
|
+
/**
|
|
7000
|
+
* Retrieve knowledge grounding for a public generate/stream call without
|
|
7001
|
+
* mutating its options. The outer call boundary decides how to apply the
|
|
7002
|
+
* returned context. Returns undefined when the call does not opt in,
|
|
7003
|
+
* grounding is disabled/not applicable, or retrieval fails open.
|
|
7004
|
+
*/
|
|
7005
|
+
async retrieveKnowledgeGrounding(options) {
|
|
7006
|
+
const engine = this.knowledgeGroundingEngine;
|
|
7007
|
+
if (!engine ||
|
|
7008
|
+
!engine.isEnabled() ||
|
|
7009
|
+
options.useKnowledgeGrounding !== true) {
|
|
7010
|
+
return undefined;
|
|
7011
|
+
}
|
|
7012
|
+
const query = options.input?.text;
|
|
7013
|
+
if (!query) {
|
|
7014
|
+
return undefined;
|
|
7015
|
+
}
|
|
7016
|
+
try {
|
|
7017
|
+
const conversationMessages = options.conversationMessages !== undefined
|
|
7018
|
+
? options.conversationMessages
|
|
7019
|
+
: await this.fetchRecentRoutingHistory(options);
|
|
7020
|
+
const recentTurns = conversationMessages
|
|
7021
|
+
.filter((message) => message.role === "user" || message.role === "assistant")
|
|
7022
|
+
.slice(-DEFAULT_RECENT_TURNS)
|
|
7023
|
+
.map((message) => ({
|
|
7024
|
+
role: message.role === "assistant"
|
|
7025
|
+
? "assistant"
|
|
7026
|
+
: "user",
|
|
7027
|
+
text: typeof message.content === "string" ? message.content : "",
|
|
7028
|
+
}));
|
|
7029
|
+
return await engine.ground({
|
|
7030
|
+
query,
|
|
7031
|
+
recentTurns,
|
|
7032
|
+
scope: options.knowledgeContext,
|
|
7033
|
+
});
|
|
7034
|
+
}
|
|
7035
|
+
catch (error) {
|
|
7036
|
+
logger.warn("[KnowledgeGrounding] grounding hook failed open", {
|
|
7037
|
+
error: String(error),
|
|
7038
|
+
});
|
|
7039
|
+
return undefined;
|
|
7040
|
+
}
|
|
7041
|
+
}
|
|
6933
7042
|
async validateStreamRequestOptions(options, startTime) {
|
|
6934
7043
|
await this.validateStreamInput(options);
|
|
6935
7044
|
// Input validation for stream
|
package/dist/types/config.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { ModelPoolConfig } from "./modelPool.js";
|
|
|
13
13
|
import type { RequestRouter } from "./requestRouter.js";
|
|
14
14
|
import type { ClassifierRouterConfig } from "./classifierRouter.js";
|
|
15
15
|
import type { SkillsConfig } from "./skills.js";
|
|
16
|
+
import type { KnowledgeGroundingConfig } from "./knowledge.js";
|
|
16
17
|
/**
|
|
17
18
|
* Main NeuroLink configuration type
|
|
18
19
|
*/
|
|
@@ -130,6 +131,17 @@ export type NeurolinkConstructorConfig = {
|
|
|
130
131
|
* Opt-in and fails open on read paths. See {@link SkillsConfig}.
|
|
131
132
|
*/
|
|
132
133
|
skills?: SkillsConfig;
|
|
134
|
+
/**
|
|
135
|
+
* Knowledge grounding: lexical-first host-supplied knowledge retrieval. When
|
|
136
|
+
* enabled with at least one source, a deterministic in-memory retrieval runs
|
|
137
|
+
* before each generate()/stream() turn — independently of tool routing — and
|
|
138
|
+
* attaches a token-bounded, ephemeral knowledge block to the model call. No
|
|
139
|
+
* embeddings or vector store. Opt-in (`enabled: false` by default) and fails
|
|
140
|
+
* open: any retrieval failure leaves the turn ungrounded. Sources are fixed
|
|
141
|
+
* for the lifetime of the instance. See
|
|
142
|
+
* {@link KnowledgeGroundingConfig}.
|
|
143
|
+
*/
|
|
144
|
+
knowledgeGrounding?: KnowledgeGroundingConfig;
|
|
133
145
|
};
|
|
134
146
|
/**
|
|
135
147
|
* Configuration for MCP enhancement modules wired into generate()/stream() paths.
|
|
@@ -429,7 +429,7 @@ export type SessionMetadata = {
|
|
|
429
429
|
* Report type for agentic loop reports
|
|
430
430
|
* Identifies the platform or category of the report
|
|
431
431
|
*/
|
|
432
|
-
export type AgenticLoopReportType = "META" | "GOOGLEADS" | "GOOGLEGA4" | "OTHER";
|
|
432
|
+
export type AgenticLoopReportType = "META" | "GOOGLEADS" | "GOOGLEGA4" | "SHOPIFY" | "BREEZE" | "OTHER";
|
|
433
433
|
/**
|
|
434
434
|
* Status of an agentic loop report
|
|
435
435
|
*/
|
package/dist/types/dynamic.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @module types/dynamic
|
|
8
8
|
*/
|
|
9
9
|
import type { AIProviderName } from "../constants/enums.js";
|
|
10
|
+
import type { KnowledgeRequestScope } from "./knowledge.js";
|
|
10
11
|
/**
|
|
11
12
|
* Context passed to context-aware dynamic argument functions.
|
|
12
13
|
* `requestContext` is whatever the consumer passed as `dynamicContext` —
|
|
@@ -39,6 +40,17 @@ export type DynamicArgument<T> = T | (() => T) | (() => Promise<T>) | ((context:
|
|
|
39
40
|
* instead of static values for context-aware resolution.
|
|
40
41
|
*/
|
|
41
42
|
export type DynamicOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* Opt this call into the knowledge grounding configured on the NeuroLink
|
|
45
|
+
* instance. This flag is intentionally static because grounding runs before
|
|
46
|
+
* dynamic arguments are resolved.
|
|
47
|
+
*/
|
|
48
|
+
useKnowledgeGrounding?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Enabled integrations used to scope knowledge retrieval for this turn.
|
|
51
|
+
* This scope is intentionally static for the same reason.
|
|
52
|
+
*/
|
|
53
|
+
knowledgeContext?: KnowledgeRequestScope;
|
|
42
54
|
model?: DynamicArgument<string>;
|
|
43
55
|
provider?: DynamicArgument<AIProviderName | string>;
|
|
44
56
|
temperature?: DynamicArgument<number>;
|
package/dist/types/generate.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AIProviderName } from "../constants/enums.js";
|
|
2
2
|
import type { RAGConfig } from "./rag.js";
|
|
3
|
+
import type { KnowledgeGroundingMetadata, KnowledgeRequestScope } from "./knowledge.js";
|
|
3
4
|
import type { SkillsCallOptions } from "./skills.js";
|
|
4
5
|
import type { AnalyticsData, TokenUsage } from "./analytics.js";
|
|
5
6
|
import type { JsonValue } from "./common.js";
|
|
@@ -545,6 +546,17 @@ export type GenerateOptions = {
|
|
|
545
546
|
onError?: OnErrorCallback;
|
|
546
547
|
/** Pre-validated user context for the request */
|
|
547
548
|
requestContext?: Record<string, unknown>;
|
|
549
|
+
/**
|
|
550
|
+
* Opt this generation call into the knowledge grounding configured on the
|
|
551
|
+
* NeuroLink instance. Defaults to `false` when omitted.
|
|
552
|
+
*/
|
|
553
|
+
useKnowledgeGrounding?: boolean;
|
|
554
|
+
/**
|
|
555
|
+
* Enabled integrations used to scope knowledge retrieval for this turn.
|
|
556
|
+
* Used only when `useKnowledgeGrounding` is true and knowledge grounding is
|
|
557
|
+
* enabled on the NeuroLink instance.
|
|
558
|
+
*/
|
|
559
|
+
knowledgeContext?: KnowledgeRequestScope;
|
|
548
560
|
/** Raw auth token — validated by configured auth provider */
|
|
549
561
|
auth?: {
|
|
550
562
|
token: string;
|
|
@@ -690,6 +702,8 @@ export type GenerateStopReason = "completed" | "step-cap" | "context-cap" | "tim
|
|
|
690
702
|
*/
|
|
691
703
|
export type GenerateResult = {
|
|
692
704
|
content: string;
|
|
705
|
+
/** Knowledge-grounding diagnostics for this turn (present only when grounding ran). */
|
|
706
|
+
knowledge?: KnowledgeGroundingMetadata;
|
|
693
707
|
/**
|
|
694
708
|
* Parsed structured object when a `schema` was requested. Populated from
|
|
695
709
|
* AI-SDK experimental_output, or from text-mode coercion (balanced-scan +
|
package/dist/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./generate.js";
|
|
|
28
28
|
export * from "./grounding.js";
|
|
29
29
|
export * from "./guardrails.js";
|
|
30
30
|
export * from "./hitl.js";
|
|
31
|
+
export * from "./knowledge.js";
|
|
31
32
|
export * from "./livekit.js";
|
|
32
33
|
export * from "./mcp.js";
|
|
33
34
|
export * from "./mcpOutput.js";
|
package/dist/types/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./generate.js";
|
|
|
29
29
|
export * from "./grounding.js";
|
|
30
30
|
export * from "./guardrails.js";
|
|
31
31
|
export * from "./hitl.js";
|
|
32
|
+
export * from "./knowledge.js";
|
|
32
33
|
export * from "./livekit.js";
|
|
33
34
|
export * from "./mcp.js";
|
|
34
35
|
export * from "./mcpOutput.js";
|