@mcp-abap-adt/llm-agent-libs 30.32.3 → 31.0.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/README.md +33 -0
- package/dist/agent/rag-orchestrator-types.d.ts +4 -2
- package/dist/agent/rag-orchestrator-types.d.ts.map +1 -1
- package/dist/agent/rag-orchestrator.d.ts.map +1 -1
- package/dist/agent/rag-orchestrator.js +11 -4
- package/dist/agent/rag-orchestrator.js.map +1 -1
- package/dist/agent.d.ts +4 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +13 -3
- package/dist/agent.js.map +1 -1
- package/dist/builder-types.d.ts +7 -1
- package/dist/builder-types.d.ts.map +1 -1
- package/dist/builder-types.js +12 -0
- package/dist/builder-types.js.map +1 -1
- package/dist/builder.d.ts +19 -7
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +179 -93
- package/dist/builder.js.map +1 -1
- package/dist/context/context-assembler.d.ts.map +1 -1
- package/dist/context/context-assembler.js +7 -3
- package/dist/context/context-assembler.js.map +1 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.d.ts +1 -0
- package/dist/coordinator/adaptive/adaptive-interpreter.d.ts.map +1 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.js +1 -0
- package/dist/coordinator/adaptive/adaptive-interpreter.js.map +1 -1
- package/dist/coordinator/dag/dag-plan-interpreter.d.ts.map +1 -1
- package/dist/coordinator/dag/dag-plan-interpreter.js +2 -0
- package/dist/coordinator/dag/dag-plan-interpreter.js.map +1 -1
- package/dist/coordinator/dag/llm-dag-planner.d.ts.map +1 -1
- package/dist/coordinator/dag/llm-dag-planner.js +1 -0
- package/dist/coordinator/dag/llm-dag-planner.js.map +1 -1
- package/dist/coordinator/dag/llm-finalizer.d.ts.map +1 -1
- package/dist/coordinator/dag/llm-finalizer.js +2 -1
- package/dist/coordinator/dag/llm-finalizer.js.map +1 -1
- package/dist/coordinator/dag/llm-review-strategy.d.ts.map +1 -1
- package/dist/coordinator/dag/llm-review-strategy.js +2 -0
- package/dist/coordinator/dag/llm-review-strategy.js.map +1 -1
- package/dist/coordinator/dag/replan-error-strategy.d.ts.map +1 -1
- package/dist/coordinator/dag/replan-error-strategy.js +1 -0
- package/dist/coordinator/dag/replan-error-strategy.js.map +1 -1
- package/dist/coordinator/dag/subagent-state-oracle.d.ts.map +1 -1
- package/dist/coordinator/dag/subagent-state-oracle.js +1 -0
- package/dist/coordinator/dag/subagent-state-oracle.js.map +1 -1
- package/dist/coordinator/dialogue/dialogue-session.d.ts +3 -1
- package/dist/coordinator/dialogue/dialogue-session.d.ts.map +1 -1
- package/dist/coordinator/dialogue/dialogue-session.js +7 -0
- package/dist/coordinator/dialogue/dialogue-session.js.map +1 -1
- package/dist/coordinator/dialogue/planner-memory.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-memory.js +3 -4
- package/dist/coordinator/dialogue/planner-memory.js.map +1 -1
- package/dist/coordinator/dialogue/task-board.d.ts +1 -0
- package/dist/coordinator/dialogue/task-board.d.ts.map +1 -1
- package/dist/coordinator/dialogue/task-board.js +2 -0
- package/dist/coordinator/dialogue/task-board.js.map +1 -1
- package/dist/coordinator/dispatch/self.d.ts.map +1 -1
- package/dist/coordinator/dispatch/self.js +5 -0
- package/dist/coordinator/dispatch/self.js.map +1 -1
- package/dist/coordinator/dispatch/subagent.d.ts.map +1 -1
- package/dist/coordinator/dispatch/subagent.js +2 -0
- package/dist/coordinator/dispatch/subagent.js.map +1 -1
- package/dist/coordinator/planning/one-shot.d.ts.map +1 -1
- package/dist/coordinator/planning/one-shot.js +1 -0
- package/dist/coordinator/planning/one-shot.js.map +1 -1
- package/dist/coordinator/planning/replan-on-error.d.ts.map +1 -1
- package/dist/coordinator/planning/replan-on-error.js +1 -0
- package/dist/coordinator/planning/replan-on-error.js.map +1 -1
- package/dist/health/agent-health.d.ts +3 -2
- package/dist/health/agent-health.d.ts.map +1 -1
- package/dist/health/agent-health.js +1 -1
- package/dist/health/agent-health.js.map +1 -1
- package/dist/health/health-checker.d.ts +2 -0
- package/dist/health/health-checker.d.ts.map +1 -1
- package/dist/health/health-checker.js +5 -0
- package/dist/health/health-checker.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/pipeline.d.ts +7 -3
- package/dist/interfaces/pipeline.d.ts.map +1 -1
- package/dist/interfaces/pipeline.js +0 -11
- package/dist/interfaces/pipeline.js.map +1 -1
- package/dist/mcp/tool-registry.d.ts +3 -2
- package/dist/mcp/tool-registry.d.ts.map +1 -1
- package/dist/mcp/tool-registry.js +1 -1
- package/dist/mcp/tool-registry.js.map +1 -1
- package/dist/pipeline/context.d.ts +7 -1
- package/dist/pipeline/context.d.ts.map +1 -1
- package/dist/pipeline/context.js +0 -17
- package/dist/pipeline/context.js.map +1 -1
- package/dist/pipeline/default-pipeline.d.ts +2 -2
- package/dist/pipeline/default-pipeline.d.ts.map +1 -1
- package/dist/pipeline/default-pipeline.js +31 -30
- package/dist/pipeline/default-pipeline.js.map +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.js +6 -0
- package/dist/pipeline/handlers/adaptive-coordinator.js.map +1 -1
- package/dist/pipeline/handlers/coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/coordinator.js +18 -3
- package/dist/pipeline/handlers/coordinator.js.map +1 -1
- package/dist/pipeline/handlers/dag-coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/dag-coordinator.js +12 -0
- package/dist/pipeline/handlers/dag-coordinator.js.map +1 -1
- package/dist/pipeline/handlers/expand.d.ts +1 -1
- package/dist/pipeline/handlers/expand.d.ts.map +1 -1
- package/dist/pipeline/handlers/expand.js +2 -1
- package/dist/pipeline/handlers/expand.js.map +1 -1
- package/dist/pipeline/handlers/history-upsert.d.ts.map +1 -1
- package/dist/pipeline/handlers/history-upsert.js +3 -16
- package/dist/pipeline/handlers/history-upsert.js.map +1 -1
- package/dist/pipeline/handlers/rag-query.d.ts +0 -20
- package/dist/pipeline/handlers/rag-query.d.ts.map +1 -1
- package/dist/pipeline/handlers/rag-query.js +10 -42
- package/dist/pipeline/handlers/rag-query.js.map +1 -1
- package/dist/pipeline/handlers/rerank.d.ts +1 -1
- package/dist/pipeline/handlers/rerank.js +3 -3
- package/dist/pipeline/handlers/rerank.js.map +1 -1
- package/dist/pipeline/handlers/skill-select.d.ts +0 -11
- package/dist/pipeline/handlers/skill-select.d.ts.map +1 -1
- package/dist/pipeline/handlers/skill-select.js +6 -1
- package/dist/pipeline/handlers/skill-select.js.map +1 -1
- package/dist/pipeline/handlers/subagent.d.ts.map +1 -1
- package/dist/pipeline/handlers/subagent.js +5 -0
- package/dist/pipeline/handlers/subagent.js.map +1 -1
- package/dist/pipeline/handlers/tool-loop.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-loop.js +26 -15
- package/dist/pipeline/handlers/tool-loop.js.map +1 -1
- package/dist/pipeline/handlers/tool-select.d.ts +0 -14
- package/dist/pipeline/handlers/tool-select.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-select.js +6 -15
- package/dist/pipeline/handlers/tool-select.js.map +1 -1
- package/dist/pipeline/handlers/wrap-final-response.d.ts +3 -0
- package/dist/pipeline/handlers/wrap-final-response.d.ts.map +1 -0
- package/dist/pipeline/handlers/wrap-final-response.js +6 -0
- package/dist/pipeline/handlers/wrap-final-response.js.map +1 -0
- package/dist/pipeline/pipeline-to-stream.d.ts +2 -2
- package/dist/pipeline/pipeline-to-stream.d.ts.map +1 -1
- package/dist/pipeline/pipeline-to-stream.js +2 -2
- package/dist/pipeline/pipeline-to-stream.js.map +1 -1
- package/dist/rag/owner-bound-query.d.ts +6 -0
- package/dist/rag/owner-bound-query.d.ts.map +1 -0
- package/dist/rag/owner-bound-query.js +85 -0
- package/dist/rag/owner-bound-query.js.map +1 -0
- package/dist/retrieval/relevance-query.d.ts +10 -0
- package/dist/retrieval/relevance-query.d.ts.map +1 -0
- package/dist/retrieval/relevance-query.js +9 -0
- package/dist/retrieval/relevance-query.js.map +1 -0
- package/dist/retrieval/reranked-retrieval.d.ts.map +1 -1
- package/dist/retrieval/reranked-retrieval.js +2 -1
- package/dist/retrieval/reranked-retrieval.js.map +1 -1
- package/dist/session/session-graph-factory.d.ts +5 -3
- package/dist/session/session-graph-factory.d.ts.map +1 -1
- package/dist/session/session-graph-factory.js +3 -0
- package/dist/session/session-graph-factory.js.map +1 -1
- package/dist/session/session-graph.d.ts +5 -0
- package/dist/session/session-graph.d.ts.map +1 -1
- package/dist/session/session-graph.js +4 -0
- package/dist/session/session-graph.js.map +1 -1
- package/dist/session/session-registry.d.ts +5 -1
- package/dist/session/session-registry.d.ts.map +1 -1
- package/dist/session/session-registry.js +20 -2
- package/dist/session/session-registry.js.map +1 -1
- package/dist/subagent/default-context-builder.d.ts.map +1 -1
- package/dist/subagent/default-context-builder.js +14 -2
- package/dist/subagent/default-context-builder.js.map +1 -1
- package/dist/subagent/direct-llm-subagent.d.ts.map +1 -1
- package/dist/subagent/direct-llm-subagent.js +1 -0
- package/dist/subagent/direct-llm-subagent.js.map +1 -1
- package/dist/subagent/smart-agent-subagent.d.ts.map +1 -1
- package/dist/subagent/smart-agent-subagent.js +5 -1
- package/dist/subagent/smart-agent-subagent.js.map +1 -1
- package/dist/testing/index.d.ts +16 -2
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +46 -13
- package/dist/testing/index.js.map +1 -1
- package/package.json +2 -2
package/dist/builder.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RagAccess } from '@mcp-abap-adt/llm-agent';
|
|
1
2
|
/**
|
|
2
3
|
* SmartAgentBuilder — fluent builder for SmartAgent.
|
|
3
4
|
*
|
|
@@ -7,15 +8,18 @@
|
|
|
7
8
|
* resolved externally by the composition root (SmartServer, CLI).
|
|
8
9
|
*
|
|
9
10
|
* Usage:
|
|
10
|
-
* const
|
|
11
|
+
* const result = await new SmartAgentBuilder()
|
|
12
|
+
* .withRagAccess(ragAccess)
|
|
11
13
|
* .withMainLlm(myLlm)
|
|
12
14
|
* .setToolsRag(myRag)
|
|
13
15
|
* .build();
|
|
16
|
+
* if (!result.ok) throw result.error;
|
|
17
|
+
* const handle = result.value;
|
|
14
18
|
*/
|
|
15
19
|
import type { AnyLogger, IClientAdapter, IContextAssembler, ICoordinatorConfig, IHistoryMemory, IHistorySummarizer, ILlm, ILlmApiAdapter, ILlmCallStrategy, ILlmRateLimiter, IMcpClient, IMcpFailureClassifier, IMcpRequestHeadersStrategy, IMcpServer, IModelProvider, IQueryExpander, IRequestLogger, IRetrievalStrategy, ISkillManager, ISubAgent, ISubpromptClassifier, IToolCache, IToolNamespace, IToolRecordKey, IToolSelectionStrategy, McpConnectionConfig, SubAgentRegistry, ToolLoopContextStrategyFactory } from '@mcp-abap-adt/llm-agent';
|
|
16
20
|
import { CircuitBreaker, type CircuitBreakerConfig, type IQueryEmbedder, type IRag, type IRagEditor, type IRagProvider, type IRagProviderRegistry, type IRagRegistry, type RagCollectionMeta, type RagRegistryCreateCollectionParams } from '@mcp-abap-adt/llm-agent';
|
|
17
21
|
import { SmartAgent, type SmartAgentConfig } from './agent.js';
|
|
18
|
-
import type { BuilderMcpConfig, SmartAgentBuilderConfig,
|
|
22
|
+
import type { BuilderMcpConfig, SmartAgentBuilderConfig, SmartAgentBuildResult } from './builder-types.js';
|
|
19
23
|
import type { IMcpConnectionStrategy } from './interfaces/mcp-connection-strategy.js';
|
|
20
24
|
import type { IPipeline } from './interfaces/pipeline.js';
|
|
21
25
|
import type { IMetrics } from './metrics/types.js';
|
|
@@ -27,14 +31,18 @@ import type { IReranker } from './reranker/types.js';
|
|
|
27
31
|
import type { ISessionManager } from './session/types.js';
|
|
28
32
|
import type { ITracer } from './tracer/types.js';
|
|
29
33
|
import type { IOutputValidator } from './validator/types.js';
|
|
30
|
-
export type { BuilderMcpConfig, BuilderPromptsConfig, SmartAgentBuilderConfig, SmartAgentHandle, } from './builder-types.js';
|
|
34
|
+
export type { BuilderMcpConfig, BuilderPromptsConfig, SmartAgentBuilderConfig, SmartAgentBuildResult, SmartAgentHandle, } from './builder-types.js';
|
|
35
|
+
export { BuilderConfigError, unwrapBuilderResult } from './builder-types.js';
|
|
31
36
|
/**
|
|
32
37
|
* Assemble the {@link McpConnectionConfig} array from the builder's `mcp`
|
|
33
38
|
* config and attach an optional {@link IMcpRequestHeadersStrategy} to each
|
|
34
39
|
* entry. Exported for unit-testing; not part of the public package barrel.
|
|
35
40
|
*/
|
|
36
41
|
export declare function prepareMcpConfigs(mcp: BuilderMcpConfig | BuilderMcpConfig[] | undefined, requestHeadersStrategy?: IMcpRequestHeadersStrategy): McpConnectionConfig[];
|
|
42
|
+
/** Bind a store to the breaker of the embedder used to construct it. */
|
|
43
|
+
export declare function bindRagEmbedderBreaker(store: IRag, breaker: CircuitBreaker): void;
|
|
37
44
|
export declare class SmartAgentBuilder {
|
|
45
|
+
private _ragAccess?;
|
|
38
46
|
private readonly cfg;
|
|
39
47
|
private _mainLlm?;
|
|
40
48
|
private _helperLlm?;
|
|
@@ -91,6 +99,7 @@ export declare class SmartAgentBuilder {
|
|
|
91
99
|
private _ragProviderRegistry?;
|
|
92
100
|
constructor(cfg?: SmartAgentBuilderConfig);
|
|
93
101
|
/** Set the main LLM used in the tool loop (required). */
|
|
102
|
+
withRagAccess(access: RagAccess): this;
|
|
94
103
|
withMainLlm(llm: ILlm): this;
|
|
95
104
|
/** Set a model provider for model discovery and metadata. */
|
|
96
105
|
withModelProvider(provider: IModelProvider): this;
|
|
@@ -106,7 +115,10 @@ export declare class SmartAgentBuilder {
|
|
|
106
115
|
setHistoryRag(rag: IRag): this;
|
|
107
116
|
/** Register an IRagProvider for dynamic collection creation. */
|
|
108
117
|
addRagProvider(provider: IRagProvider): this;
|
|
109
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Register a static RAG collection. build() requires meta.scope and its
|
|
120
|
+
* scope-specific owner identifier; missing ownership is a BuilderConfigError.
|
|
121
|
+
*/
|
|
110
122
|
addRagCollection(params: {
|
|
111
123
|
name: string;
|
|
112
124
|
rag: IRag;
|
|
@@ -217,8 +229,8 @@ export declare class SmartAgentBuilder {
|
|
|
217
229
|
withApiAdapter(adapter: ILlmApiAdapter): this;
|
|
218
230
|
/**
|
|
219
231
|
* Use breakers created and owned by the caller (shared across builders).
|
|
220
|
-
* Only the embedder breaker is taken: registry stores
|
|
221
|
-
* `FallbackRag`
|
|
232
|
+
* Only the embedder breaker is taken: unbound registry stores and stores bound
|
|
233
|
+
* to that breaker are wrapped in `FallbackRag` unless already guarded by it. The
|
|
222
234
|
* main LLM gets no new breaker (the caller passes pre-wrapped LLMs); when it
|
|
223
235
|
* is a `CircuitBreakerLlm`, the builder's retry goes UNDER it, on the same
|
|
224
236
|
* breaker, so one call counts once. When both
|
|
@@ -377,6 +389,6 @@ export declare class SmartAgentBuilder {
|
|
|
377
389
|
* listener (e.g. strategy-wrapped) is the one queried.
|
|
378
390
|
*/
|
|
379
391
|
private buildRetrievalSource;
|
|
380
|
-
build(): Promise<
|
|
392
|
+
build(): Promise<SmartAgentBuildResult>;
|
|
381
393
|
}
|
|
382
394
|
//# sourceMappingURL=builder.d.ts.map
|
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKzD;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,IAAI,EACJ,c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AE,OAAO,GAAG,IAAI;IAK1C,yEAAyE;IACzE,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAK3C,sEAAsE;IACtE,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7C,iEAAiE;IACjE,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAS5C;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAS7C;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IActB,KAAK,IAAI,OAAO,CAAC,qBAAqB,CAAC;CA81B9C"}
|
package/dist/builder.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
* SmartAgentBuilder — fluent builder for SmartAgent.
|
|
3
|
-
*
|
|
4
|
-
* Assembles a SmartAgent from interface-based components.
|
|
5
|
-
* The builder itself has NO knowledge of concrete providers —
|
|
6
|
-
* all dependencies must be injected via `withXxx()` methods or
|
|
7
|
-
* resolved externally by the composition root (SmartServer, CLI).
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* const handle = await new SmartAgentBuilder()
|
|
11
|
-
* .withMainLlm(myLlm)
|
|
12
|
-
* .setToolsRag(myRag)
|
|
13
|
-
* .build();
|
|
14
|
-
*/
|
|
1
|
+
import { reservedGlobalNameError, validateRagOwner, } from '@mcp-abap-adt/llm-agent';
|
|
15
2
|
import { buildNamespacedTools, CircuitBreaker, CircuitBreakerLlm, collectServerDescriptors, defaultToolNamespace, FallbackRag, InMemoryRag, isRagDecorator, normaliseLogger, QueryEmbedding, ragStoreKey, SimpleRagProviderRegistry, SimpleRagRegistry, } from '@mcp-abap-adt/llm-agent';
|
|
16
3
|
import { makeConnectionStrategy } from '@mcp-abap-adt/llm-agent-mcp';
|
|
17
4
|
import { SmartAgent } from './agent.js';
|
|
18
|
-
import { isModelProvider } from './builder-types.js';
|
|
5
|
+
import { BuilderConfigError, isModelProvider } from './builder-types.js';
|
|
19
6
|
import { LlmClassifier, } from './classifier/llm-classifier.js';
|
|
20
7
|
import { ContextAssembler, } from './context/context-assembler.js';
|
|
21
8
|
import { ExplicitActivation, HybridDispatch, OneShotPlanning, SelfDispatch, SubAgentDispatch, } from './coordinator/index.js';
|
|
@@ -32,6 +19,7 @@ import { ownBuiltInStore } from './retrieval/strategy-rag.js';
|
|
|
32
19
|
import { DefaultSubAgentContextBuilder, } from './subagent/default-context-builder.js';
|
|
33
20
|
import { SmartAgentSubAgent } from './subagent/smart-agent-subagent.js';
|
|
34
21
|
import { stopAll } from './util/stop-all.js';
|
|
22
|
+
export { BuilderConfigError, unwrapBuilderResult } from './builder-types.js';
|
|
35
23
|
// ---------------------------------------------------------------------------
|
|
36
24
|
// Helpers
|
|
37
25
|
// ---------------------------------------------------------------------------
|
|
@@ -47,6 +35,23 @@ export function prepareMcpConfigs(mcp, requestHeadersStrategy) {
|
|
|
47
35
|
}
|
|
48
36
|
return configs.map((c) => ({ ...c, requestHeadersStrategy }));
|
|
49
37
|
}
|
|
38
|
+
const ragEmbedderBreakers = new WeakMap();
|
|
39
|
+
/** Bind a store to the breaker of the embedder used to construct it. */
|
|
40
|
+
export function bindRagEmbedderBreaker(store, breaker) {
|
|
41
|
+
ragEmbedderBreakers.set(store, breaker);
|
|
42
|
+
}
|
|
43
|
+
function storeEmbedderBreaker(store) {
|
|
44
|
+
let current = store;
|
|
45
|
+
for (let depth = 0; current && depth < 16; depth++) {
|
|
46
|
+
const breaker = ragEmbedderBreakers.get(current);
|
|
47
|
+
if (breaker)
|
|
48
|
+
return breaker;
|
|
49
|
+
if (current instanceof FallbackRag)
|
|
50
|
+
return current.breaker;
|
|
51
|
+
current = isRagDecorator(current) ? current.inner : undefined;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
50
55
|
/** True when `store`, or a store it decorates, is a FallbackRag on `breaker` (bounded walk). */
|
|
51
56
|
function isGuardedBy(store, breaker) {
|
|
52
57
|
let cur = store;
|
|
@@ -61,6 +66,7 @@ function isGuardedBy(store, breaker) {
|
|
|
61
66
|
// SmartAgentBuilder
|
|
62
67
|
// ---------------------------------------------------------------------------
|
|
63
68
|
export class SmartAgentBuilder {
|
|
69
|
+
_ragAccess;
|
|
64
70
|
cfg;
|
|
65
71
|
// All components injected via fluent setters
|
|
66
72
|
_mainLlm;
|
|
@@ -123,6 +129,10 @@ export class SmartAgentBuilder {
|
|
|
123
129
|
// Fluent setters
|
|
124
130
|
// -------------------------------------------------------------------------
|
|
125
131
|
/** Set the main LLM used in the tool loop (required). */
|
|
132
|
+
withRagAccess(access) {
|
|
133
|
+
this._ragAccess = access;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
126
136
|
withMainLlm(llm) {
|
|
127
137
|
this._mainLlm = llm;
|
|
128
138
|
return this;
|
|
@@ -162,7 +172,10 @@ export class SmartAgentBuilder {
|
|
|
162
172
|
this._providers.push(provider);
|
|
163
173
|
return this;
|
|
164
174
|
}
|
|
165
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Register a static RAG collection. build() requires meta.scope and its
|
|
177
|
+
* scope-specific owner identifier; missing ownership is a BuilderConfigError.
|
|
178
|
+
*/
|
|
166
179
|
addRagCollection(params) {
|
|
167
180
|
this._staticCollections.push(params);
|
|
168
181
|
return this;
|
|
@@ -335,8 +348,8 @@ export class SmartAgentBuilder {
|
|
|
335
348
|
}
|
|
336
349
|
/**
|
|
337
350
|
* Use breakers created and owned by the caller (shared across builders).
|
|
338
|
-
* Only the embedder breaker is taken: registry stores
|
|
339
|
-
* `FallbackRag`
|
|
351
|
+
* Only the embedder breaker is taken: unbound registry stores and stores bound
|
|
352
|
+
* to that breaker are wrapped in `FallbackRag` unless already guarded by it. The
|
|
340
353
|
* main LLM gets no new breaker (the caller passes pre-wrapped LLMs); when it
|
|
341
354
|
* is a `CircuitBreakerLlm`, the builder's retry goes UNDER it, on the same
|
|
342
355
|
* breaker, so one call counts once. When both
|
|
@@ -630,6 +643,41 @@ export class SmartAgentBuilder {
|
|
|
630
643
|
}
|
|
631
644
|
async build() {
|
|
632
645
|
const log = this._logger;
|
|
646
|
+
if (!this._ragAccess) {
|
|
647
|
+
return {
|
|
648
|
+
ok: false,
|
|
649
|
+
error: new BuilderConfigError('ragAccess is required'),
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
// Validate before model calls, registry mutations or external resources.
|
|
653
|
+
const staticCollections = [];
|
|
654
|
+
for (const collection of this._staticCollections) {
|
|
655
|
+
const owner = validateRagOwner(collection.meta);
|
|
656
|
+
if (!owner.ok) {
|
|
657
|
+
return {
|
|
658
|
+
ok: false,
|
|
659
|
+
error: new BuilderConfigError(`Collection '${collection.name}': ${owner.error.message}`),
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
const identity = owner.value;
|
|
663
|
+
const reserved = reservedGlobalNameError(identity.scope, collection.name);
|
|
664
|
+
if (reserved)
|
|
665
|
+
return { ok: false, error: reserved };
|
|
666
|
+
const ownerId = identity.scope === 'session'
|
|
667
|
+
? identity.sessionId
|
|
668
|
+
: identity.scope === 'user'
|
|
669
|
+
? identity.userId
|
|
670
|
+
: identity.scope === 'role'
|
|
671
|
+
? identity.roleId
|
|
672
|
+
: undefined;
|
|
673
|
+
if (ownerId !== undefined && !ownerId.trim()) {
|
|
674
|
+
return {
|
|
675
|
+
ok: false,
|
|
676
|
+
error: new BuilderConfigError(`Collection '${collection.name}': a ${identity.scope} collection needs a non-empty owner identifier`),
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
staticCollections.push({ ...collection, owner: identity });
|
|
680
|
+
}
|
|
633
681
|
// ---- Validate required dependencies -----------------------------------
|
|
634
682
|
const mainLlm = this._mainLlm;
|
|
635
683
|
if (!mainLlm) {
|
|
@@ -718,25 +766,11 @@ export class SmartAgentBuilder {
|
|
|
718
766
|
// `idempotent: true` and are skipped when already present. Ordinary callers
|
|
719
767
|
// leave it unset so a genuine name collision still surfaces instead of
|
|
720
768
|
// silently keeping the old RAG/editor/meta.
|
|
721
|
-
for (const c of
|
|
722
|
-
if (c.idempotent && ragRegistry.get(c.name, c.
|
|
769
|
+
for (const c of staticCollections) {
|
|
770
|
+
if (c.idempotent && ragRegistry.get(c.name, c.owner.scope, c.owner))
|
|
723
771
|
continue;
|
|
724
772
|
ragRegistry.register(c.name, c.rag, c.editor, c.meta);
|
|
725
773
|
}
|
|
726
|
-
// Mirror the built-in toolsRag / historyRag into the registry so the projection preserves
|
|
727
|
-
// ragStores.tools / ragStores.history behavior that existing handlers rely on.
|
|
728
|
-
if (toolsRag && !ragRegistry.get('tools', 'global')) {
|
|
729
|
-
ragRegistry.register('tools', toolsRag, undefined, {
|
|
730
|
-
displayName: 'tools',
|
|
731
|
-
scope: 'global',
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
if (historyRag && !ragRegistry.get('history', 'global')) {
|
|
735
|
-
ragRegistry.register('history', historyRag, undefined, {
|
|
736
|
-
displayName: 'history',
|
|
737
|
-
scope: 'global',
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
774
|
// Create any queued dynamic collections at startup.
|
|
741
775
|
for (const c of this._pendingDynamicCollections) {
|
|
742
776
|
const res = await ragRegistry.createCollection(c);
|
|
@@ -749,11 +783,15 @@ export class SmartAgentBuilder {
|
|
|
749
783
|
// configuration naming one keeps working — and a user or session collection
|
|
750
784
|
// is keyed user/<name> or session/<name>, so one name in several scopes gives
|
|
751
785
|
// several keys and nothing overwrites anything (§6.4).
|
|
786
|
+
let projectedHistoryRag = historyRag;
|
|
787
|
+
let projectedToolsRag = toolsRag;
|
|
752
788
|
const ragStores = {};
|
|
753
789
|
const rebuildProjection = () => {
|
|
754
790
|
for (const k of Object.keys(ragStores))
|
|
755
791
|
delete ragStores[k];
|
|
756
792
|
for (const m of ragRegistry.list()) {
|
|
793
|
+
if (reservedGlobalNameError(m.scope ?? 'global', m.name))
|
|
794
|
+
continue;
|
|
757
795
|
const r = ragRegistry.get(m.name, m.scope ?? 'global');
|
|
758
796
|
if (!r)
|
|
759
797
|
continue;
|
|
@@ -761,7 +799,38 @@ export class SmartAgentBuilder {
|
|
|
761
799
|
// registry entry stays as registered; idempotent through IRagDecorator.
|
|
762
800
|
const key = ragStoreKey(m);
|
|
763
801
|
const strategy = this._retrievalStrategies.get(key);
|
|
764
|
-
|
|
802
|
+
const parsedOwner = validateRagOwner({
|
|
803
|
+
...m,
|
|
804
|
+
scope: m.scope ?? 'global',
|
|
805
|
+
});
|
|
806
|
+
const owner = parsedOwner.ok ? parsedOwner.value : undefined;
|
|
807
|
+
if (!owner)
|
|
808
|
+
continue;
|
|
809
|
+
ragStores[key] = {
|
|
810
|
+
name: m.name,
|
|
811
|
+
owner,
|
|
812
|
+
rag: strategy ? applyRetrievalStrategy(r, strategy) : r,
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
if (projectedToolsRag) {
|
|
816
|
+
const strategy = this._retrievalStrategies.get('tools');
|
|
817
|
+
ragStores.tools = {
|
|
818
|
+
name: 'tools',
|
|
819
|
+
owner: { scope: 'internal' },
|
|
820
|
+
rag: strategy
|
|
821
|
+
? applyRetrievalStrategy(projectedToolsRag, strategy)
|
|
822
|
+
: projectedToolsRag,
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
if (projectedHistoryRag) {
|
|
826
|
+
const strategy = this._retrievalStrategies.get('history');
|
|
827
|
+
ragStores.history = {
|
|
828
|
+
name: 'history',
|
|
829
|
+
owner: { scope: 'session', perRequest: true },
|
|
830
|
+
rag: strategy
|
|
831
|
+
? applyRetrievalStrategy(projectedHistoryRag, strategy)
|
|
832
|
+
: projectedHistoryRag,
|
|
833
|
+
};
|
|
765
834
|
}
|
|
766
835
|
};
|
|
767
836
|
rebuildProjection();
|
|
@@ -798,12 +867,31 @@ export class SmartAgentBuilder {
|
|
|
798
867
|
onStateChange: cbCfg.onStateChange ?? makeOnStateChange('embedder'),
|
|
799
868
|
});
|
|
800
869
|
circuitBreakers.push(embedderBreaker);
|
|
870
|
+
if (historyRag &&
|
|
871
|
+
(!storeEmbedderBreaker(historyRag) ||
|
|
872
|
+
storeEmbedderBreaker(historyRag) === embedderBreaker) &&
|
|
873
|
+
!(this._sharedBreakers && isGuardedBy(historyRag, embedderBreaker))) {
|
|
874
|
+
projectedHistoryRag = new FallbackRag(historyRag, new InMemoryRag(), embedderBreaker);
|
|
875
|
+
rebuildProjection();
|
|
876
|
+
}
|
|
877
|
+
if (toolsRag &&
|
|
878
|
+
(!storeEmbedderBreaker(toolsRag) ||
|
|
879
|
+
storeEmbedderBreaker(toolsRag) === embedderBreaker) &&
|
|
880
|
+
!(this._sharedBreakers && isGuardedBy(toolsRag, embedderBreaker))) {
|
|
881
|
+
projectedToolsRag = new FallbackRag(toolsRag, new InMemoryRag(), embedderBreaker);
|
|
882
|
+
rebuildProjection();
|
|
883
|
+
}
|
|
801
884
|
// list() is a snapshot, so changing entries while iterating is safe.
|
|
802
885
|
for (const meta of ragRegistry.list()) {
|
|
803
886
|
const scope = meta.scope ?? 'global';
|
|
804
887
|
const store = ragRegistry.get(meta.name, scope);
|
|
805
888
|
if (!store)
|
|
806
889
|
continue;
|
|
890
|
+
// A shared registry can contain stores built with another embedder.
|
|
891
|
+
// Unbound stores inherit this builder's breaker.
|
|
892
|
+
const storeBreaker = storeEmbedderBreaker(store);
|
|
893
|
+
if (storeBreaker && storeBreaker !== embedderBreaker)
|
|
894
|
+
continue;
|
|
807
895
|
if (this._sharedBreakers && isGuardedBy(store, embedderBreaker)) {
|
|
808
896
|
continue;
|
|
809
897
|
}
|
|
@@ -1024,13 +1112,6 @@ export class SmartAgentBuilder {
|
|
|
1024
1112
|
new HistorySummarizer(summarizerLlm, agentCfg.historyTurnSummaryPrompt
|
|
1025
1113
|
? { prompt: agentCfg.historyTurnSummaryPrompt }
|
|
1026
1114
|
: undefined);
|
|
1027
|
-
if (historyRag && !ragRegistry.get('history', 'global')) {
|
|
1028
|
-
ragRegistry.register('history', historyRag, undefined, {
|
|
1029
|
-
displayName: 'history',
|
|
1030
|
-
scope: 'global',
|
|
1031
|
-
});
|
|
1032
|
-
// ragStores projection updates via mutation listener.
|
|
1033
|
-
}
|
|
1034
1115
|
}
|
|
1035
1116
|
// ---- Plugin loader (optional) -------------------------------------------
|
|
1036
1117
|
let loadedPlugins;
|
|
@@ -1075,7 +1156,7 @@ export class SmartAgentBuilder {
|
|
|
1075
1156
|
const ownTools = toolsRag && toolsStrategy
|
|
1076
1157
|
? applyRetrievalStrategy(toolsRag, toolsStrategy)
|
|
1077
1158
|
: toolsRag;
|
|
1078
|
-
const toolSource = this.buildRetrievalSource(toolsRag, this._embedder, () => ownBuiltInStore(toolsRag, ownTools, ragStores.tools));
|
|
1159
|
+
const toolSource = this.buildRetrievalSource(toolsRag, this._embedder, () => ownBuiltInStore(toolsRag, ownTools, ragStores.tools?.rag));
|
|
1079
1160
|
const defaultContextBuilder = new DefaultSubAgentContextBuilder({
|
|
1080
1161
|
toolSource,
|
|
1081
1162
|
});
|
|
@@ -1105,6 +1186,7 @@ export class SmartAgentBuilder {
|
|
|
1105
1186
|
toolsRag,
|
|
1106
1187
|
historyRag,
|
|
1107
1188
|
ragStores,
|
|
1189
|
+
ragAccess: this._ragAccess,
|
|
1108
1190
|
retrievalStrategies: Object.fromEntries(this._retrievalStrategies),
|
|
1109
1191
|
ragRegistry,
|
|
1110
1192
|
ragProviderRegistry,
|
|
@@ -1140,6 +1222,7 @@ export class SmartAgentBuilder {
|
|
|
1140
1222
|
helperLlm: this._helperLlm,
|
|
1141
1223
|
mcpClients,
|
|
1142
1224
|
ragStores,
|
|
1225
|
+
ragAccess: this._ragAccess,
|
|
1143
1226
|
ragRegistry,
|
|
1144
1227
|
ragProviderRegistry,
|
|
1145
1228
|
classifier,
|
|
@@ -1215,59 +1298,62 @@ export class SmartAgentBuilder {
|
|
|
1215
1298
|
apiAdapters.set(name, adapter);
|
|
1216
1299
|
}
|
|
1217
1300
|
return {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1301
|
+
ok: true,
|
|
1302
|
+
value: {
|
|
1303
|
+
agent,
|
|
1304
|
+
chat: (messages, tools, options) => agent.currentMainLlm.chat(messages, tools, options),
|
|
1305
|
+
streamChat: (messages, tools, options) => agent.currentMainLlm.streamChat(messages, tools, options),
|
|
1306
|
+
requestLogger,
|
|
1307
|
+
close: async () => {
|
|
1308
|
+
// Best-effort, like every other teardown routine in this codebase
|
|
1309
|
+
// (SessionGraph.dispose(), SessionGraphFactory's per-stop loop): a
|
|
1310
|
+
// failure in ONE resource must not stop the rest from being torn
|
|
1311
|
+
// down, and close() itself never throws — it is routinely awaited
|
|
1312
|
+
// in a `finally` block, where a raised error would either mask
|
|
1313
|
+
// whatever the `try` block was doing or force every caller to wrap
|
|
1314
|
+
// a routine cleanup call in its own try/catch. Failures are never
|
|
1315
|
+
// swallowed SILENTLY, though: both surface through `log` (or
|
|
1316
|
+
// console.warn without one), the same pattern used everywhere else
|
|
1317
|
+
// teardown failures are reported in this branch.
|
|
1318
|
+
const warn = (message) => {
|
|
1319
|
+
if (log) {
|
|
1320
|
+
log.log({ type: 'warning', traceId: 'builder', message });
|
|
1321
|
+
}
|
|
1322
|
+
else {
|
|
1323
|
+
console.warn(`[builder] ${message}`);
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
try {
|
|
1327
|
+
await connectionStrategy?.dispose?.();
|
|
1236
1328
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1329
|
+
catch (err) {
|
|
1330
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1331
|
+
warn(`close_connection_strategy_dispose_failed: ${message}`);
|
|
1239
1332
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1333
|
+
await stopAll(closeFns, (err) => {
|
|
1334
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1335
|
+
warn(`close_mcp_stop_failed: ${message}`);
|
|
1336
|
+
});
|
|
1337
|
+
},
|
|
1338
|
+
circuitBreakers,
|
|
1339
|
+
ragStores,
|
|
1340
|
+
ragRegistry,
|
|
1341
|
+
mcpClients,
|
|
1342
|
+
modelProvider,
|
|
1343
|
+
getApiAdapter: (name) => apiAdapters.get(name),
|
|
1344
|
+
listApiAdapters: () => [...apiAdapters.keys()],
|
|
1345
|
+
// Absent (not just undefined-valued) on the caller-provided-`mcpClients`
|
|
1346
|
+
// branch, where `resolved` is undefined and namespacing was never
|
|
1347
|
+
// computed — matches the SmartAgentHandle field docs.
|
|
1348
|
+
...(resolved
|
|
1349
|
+
? {
|
|
1350
|
+
namespacedTools,
|
|
1351
|
+
toolProvenance,
|
|
1352
|
+
mcpClientDescriptors: resolved.clientDescriptors,
|
|
1353
|
+
configuredSlotCount: resolved.configuredSlotCount,
|
|
1354
|
+
}
|
|
1355
|
+
: {}),
|
|
1252
1356
|
},
|
|
1253
|
-
circuitBreakers,
|
|
1254
|
-
ragStores,
|
|
1255
|
-
ragRegistry,
|
|
1256
|
-
mcpClients,
|
|
1257
|
-
modelProvider,
|
|
1258
|
-
getApiAdapter: (name) => apiAdapters.get(name),
|
|
1259
|
-
listApiAdapters: () => [...apiAdapters.keys()],
|
|
1260
|
-
// Absent (not just undefined-valued) on the caller-provided-`mcpClients`
|
|
1261
|
-
// branch, where `resolved` is undefined and namespacing was never
|
|
1262
|
-
// computed — matches the SmartAgentHandle field docs.
|
|
1263
|
-
...(resolved
|
|
1264
|
-
? {
|
|
1265
|
-
namespacedTools,
|
|
1266
|
-
toolProvenance,
|
|
1267
|
-
mcpClientDescriptors: resolved.clientDescriptors,
|
|
1268
|
-
configuredSlotCount: resolved.configuredSlotCount,
|
|
1269
|
-
}
|
|
1270
|
-
: {}),
|
|
1271
1357
|
};
|
|
1272
1358
|
}
|
|
1273
1359
|
catch (err) {
|