@memberjunction/ai-agents 6.2.0 → 6.3.0-edge.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/README.md +21 -1
- package/dist/AgentContextAssembler.d.ts +127 -0
- package/dist/AgentContextAssembler.d.ts.map +1 -0
- package/dist/AgentContextAssembler.js +482 -0
- package/dist/AgentContextAssembler.js.map +1 -0
- package/dist/AgentDataPreloader.d.ts +5 -1
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +13 -7
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentFeedbackCoordinator.d.ts +169 -0
- package/dist/AgentFeedbackCoordinator.d.ts.map +1 -0
- package/dist/AgentFeedbackCoordinator.js +593 -0
- package/dist/AgentFeedbackCoordinator.js.map +1 -0
- package/dist/AgentStepDispatcher.d.ts +211 -0
- package/dist/AgentStepDispatcher.d.ts.map +1 -0
- package/dist/AgentStepDispatcher.js +729 -0
- package/dist/AgentStepDispatcher.js.map +1 -0
- package/dist/AgentTreeBudgetTracker.d.ts +163 -0
- package/dist/AgentTreeBudgetTracker.d.ts.map +1 -0
- package/dist/AgentTreeBudgetTracker.js +415 -0
- package/dist/AgentTreeBudgetTracker.js.map +1 -0
- package/dist/AgentWakeTriggerService.d.ts +41 -1
- package/dist/AgentWakeTriggerService.d.ts.map +1 -1
- package/dist/AgentWakeTriggerService.js +154 -8
- package/dist/AgentWakeTriggerService.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts +32 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +105 -3
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +14 -1
- package/dist/PayloadManager.js.map +1 -1
- package/dist/SkillMarkdownConverter.d.ts +1 -1
- package/dist/SkillMarkdownConverter.d.ts.map +1 -1
- package/dist/SkillMarkdownConverter.js +4 -4
- package/dist/SkillMarkdownConverter.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts +5 -0
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +5 -0
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-types/base-agent-type.d.ts.map +1 -1
- package/dist/agent-types/base-agent-type.js +8 -1
- package/dist/agent-types/base-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +18 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +2 -0
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/base-agent.d.ts +105 -133
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +395 -1472
- package/dist/base-agent.js.map +1 -1
- package/dist/catalog-narrowing.d.ts +112 -5
- package/dist/catalog-narrowing.d.ts.map +1 -1
- package/dist/catalog-narrowing.js +181 -6
- package/dist/catalog-narrowing.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/pipeline/operators.d.ts.map +1 -1
- package/dist/pipeline/operators.js +1 -1
- package/dist/pipeline/operators.js.map +1 -1
- package/dist/pipeline/pipeline-executor.d.ts +29 -1
- package/dist/pipeline/pipeline-executor.d.ts.map +1 -1
- package/dist/pipeline/pipeline-executor.js +159 -2
- package/dist/pipeline/pipeline-executor.js.map +1 -1
- package/dist/pipeline/pipeline.types.d.ts +19 -1
- package/dist/pipeline/pipeline.types.d.ts.map +1 -1
- package/dist/pipeline/template.d.ts +11 -0
- package/dist/pipeline/template.d.ts.map +1 -1
- package/dist/pipeline/template.js +56 -6
- package/dist/pipeline/template.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.d.ts.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +28 -1
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/media-channel-server.js +1 -1
- package/dist/realtime/media-channel-server.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +122 -2
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +413 -4
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +4 -2
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +27 -38
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-delegation-narrator.js +1 -1
- package/dist/realtime/realtime-delegation-narrator.js.map +1 -1
- package/dist/realtime/realtime-session-runner.d.ts +2 -0
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +24 -3
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/unsafe-object-keys.d.ts +20 -0
- package/dist/unsafe-object-keys.d.ts.map +1 -0
- package/dist/unsafe-object-keys.js +42 -0
- package/dist/unsafe-object-keys.js.map +1 -0
- package/package.json +20 -20
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Extracted prompt context assembly, catalog markdown formatting,
|
|
3
|
+
* and trailing `<mj-runtime-state>` message construction for {@link BaseAgent}.
|
|
4
|
+
*
|
|
5
|
+
* Isolates prompt template data formatting (sub-agents, actions, skills, client tools,
|
|
6
|
+
* application context), response-type auto-alignment, and cache-aware runtime-state
|
|
7
|
+
* message assembly into an independently testable collaborator (`WS-4.5b`).
|
|
8
|
+
*
|
|
9
|
+
* @module @memberjunction/ai-agents
|
|
10
|
+
*/
|
|
11
|
+
import { ResolveClientTools, SystemPlaceholderManager, } from '@memberjunction/ai-core-plus';
|
|
12
|
+
import { BaseLLM, IsPrefixPromptCache } from '@memberjunction/ai';
|
|
13
|
+
import { AIEngine } from '@memberjunction/aiengine';
|
|
14
|
+
import { LogError } from '@memberjunction/core';
|
|
15
|
+
import { IsPlainObject, MJGlobal, NormalizeUUID, UUIDsEqual } from '@memberjunction/global';
|
|
16
|
+
import { DescribeValueSchemaInline, GetStoredValueSchema } from './native-tools/action-param-schema.js';
|
|
17
|
+
import { BindingsForAction, UnboundParams } from './bound-action-params.js';
|
|
18
|
+
import { EscapeRuntimeStateTagsInMessage, RuntimeStateFragmentBuilder, } from './runtime-state-fragment.js';
|
|
19
|
+
import { CURRENT_DATE_PLACEHOLDER, CURRENT_DAY_OF_WEEK_PLACEHOLDER, CURRENT_TIME_PLACEHOLDER, SCRATCHPAD_NOTES_PLACEHOLDER, SCRATCHPAD_TASKS_PLACEHOLDER, SCRATCHPAD_TASK_SUMMARY_PLACEHOLDER, VOLATILE_TEMPLATE_MARKERS, } from './constants.js';
|
|
20
|
+
import { ResolveFinishIfMode } from './agent-types/loop-agent-prompt-params.js';
|
|
21
|
+
import { ClientToolRequestManager } from './ClientToolRequestManager.js';
|
|
22
|
+
/**
|
|
23
|
+
* Coordinates prompt context assembly, catalog markdown generation, and
|
|
24
|
+
* cache-preserving `<mj-runtime-state>` trailing message construction for `BaseAgent`.
|
|
25
|
+
*/
|
|
26
|
+
export class AgentContextAssembler {
|
|
27
|
+
/**
|
|
28
|
+
* Assembles the outgoing message array for a single LLM request under `'trailingMessage'`
|
|
29
|
+
* runtime-state placement: escapes literal `<mj-runtime-state>` tags in non-system history
|
|
30
|
+
* messages and appends the fresh volatile-state fragment last.
|
|
31
|
+
*/
|
|
32
|
+
AssembleOutgoingMessages(history, fragment, isAppendOnly = false) {
|
|
33
|
+
const source = isAppendOnly
|
|
34
|
+
? history
|
|
35
|
+
: history.filter((m) => !m.metadata?.volatileState);
|
|
36
|
+
const sanitized = source.map((m) => m.role === 'system' || m.metadata?.volatileState
|
|
37
|
+
? m
|
|
38
|
+
: EscapeRuntimeStateTagsInMessage(m));
|
|
39
|
+
return [...sanitized, fragment];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns true when the driver serving `model` on `vendor` binds replayed reasoning
|
|
43
|
+
* to the unchanged history prefix before it.
|
|
44
|
+
*/
|
|
45
|
+
DriverRequiresStableReasoningPrefix(model, vendor) {
|
|
46
|
+
if (!model || !vendor) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const engine = AIEngine.Instance;
|
|
50
|
+
const modelVendor = (engine.ModelVendorsByModelID?.get(NormalizeUUID(model.ID)) ?? []).find((mv) => UUIDsEqual(mv.VendorID, vendor.ID) && engine.IsInferenceProvider(mv));
|
|
51
|
+
if (!modelVendor?.DriverClass) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const driver = MJGlobal.Instance.ClassFactory.GetRegistration(BaseLLM, modelVendor.DriverClass)
|
|
55
|
+
?.SubClass;
|
|
56
|
+
return driver?.ReplayedReasoningRequiresStablePrefix === true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Determines whether `model` (as served by `vendor`) sits behind a byte-prefix prompt cache
|
|
60
|
+
* (`LLM.PrefixPromptCache`), read from the model catalog's `ModelConfiguration` cascade —
|
|
61
|
+
* `AIModelType < AIModel < AIVendor.Configuration.ModelDefaults < AIModelVendor` — via
|
|
62
|
+
* `AIEngine.GetEffectiveModelConfiguration`. The most specific layer is the INFERENCE-PROVIDER
|
|
63
|
+
* model-vendor row for `vendor`, whose vendor row supplies the host-wide default that beats the
|
|
64
|
+
* model's own bag; when the vendor is unknown, or has no inference row for this model, the model
|
|
65
|
+
* and type layers still answer. False when no layer declares it, which callers
|
|
66
|
+
* treat as a block cache (replace-in-place).
|
|
67
|
+
*/
|
|
68
|
+
ResolvePrefixPromptCache(model, vendor) {
|
|
69
|
+
if (!model) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const engine = AIEngine.Instance;
|
|
73
|
+
const modelVendor = vendor
|
|
74
|
+
? (engine.ModelVendorsByModelID?.get(NormalizeUUID(model.ID)) ?? []).find((mv) => UUIDsEqual(mv.VendorID, vendor.ID) && engine.IsInferenceProvider(mv))
|
|
75
|
+
: undefined;
|
|
76
|
+
return IsPrefixPromptCache(engine.GetEffectiveModelConfiguration(model.ID, modelVendor?.ID));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns true when unrendered template text contains any volatile state marker
|
|
80
|
+
* (indicating the template still embeds volatile state directly).
|
|
81
|
+
*/
|
|
82
|
+
TemplateTextEmbedsVolatileState(templateText, markers = VOLATILE_TEMPLATE_MARKERS) {
|
|
83
|
+
return markers.some((marker) => templateText.includes(marker));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolves the three temporal placeholders (`_CURRENT_DATE`, `_CURRENT_DAY_OF_WEEK`, `_CURRENT_TIME`)
|
|
87
|
+
* for the trailing runtime-state fragment. Resolves only the three temporal placeholders (by name,
|
|
88
|
+
* through the same registry the template uses, so a registered override applies here too) rather
|
|
89
|
+
* than every system placeholder — this runs on every loop iteration.
|
|
90
|
+
*/
|
|
91
|
+
async ResolveFragmentDateTime(promptParams, onError) {
|
|
92
|
+
const resolve = async (name) => {
|
|
93
|
+
const placeholder = SystemPlaceholderManager.getPlaceholders().find((p) => p.name === name);
|
|
94
|
+
if (!placeholder) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const value = await placeholder.getValue(promptParams);
|
|
99
|
+
return value == null ? null : String(value);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
onError?.(e instanceof Error ? e : String(e), name);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const [date, dayOfWeek, time] = await Promise.all([
|
|
107
|
+
resolve(CURRENT_DATE_PLACEHOLDER),
|
|
108
|
+
resolve(CURRENT_DAY_OF_WEEK_PLACEHOLDER),
|
|
109
|
+
resolve(CURRENT_TIME_PLACEHOLDER),
|
|
110
|
+
]);
|
|
111
|
+
if (!date || !dayOfWeek || !time) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return { Date: date, DayOfWeek: dayOfWeek, Time: time };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Reads scratchpad notes, tasks, and task summary from prepared prompt template data
|
|
118
|
+
* (so the fragment shows exactly what the template would have). Null when the scratchpad
|
|
119
|
+
* is disabled or absent.
|
|
120
|
+
*/
|
|
121
|
+
ReadScratchpadFromTemplateData(data) {
|
|
122
|
+
const notes = data[SCRATCHPAD_NOTES_PLACEHOLDER];
|
|
123
|
+
const tasks = data[SCRATCHPAD_TASKS_PLACEHOLDER];
|
|
124
|
+
const summary = data[SCRATCHPAD_TASK_SUMMARY_PLACEHOLDER];
|
|
125
|
+
if (typeof notes !== 'string' || typeof tasks !== 'string' || typeof summary !== 'string') {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return { Notes: notes, Tasks: tasks, TaskSummary: summary };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Builds the serialized `<mj-runtime-state>` XML block from resolved date/time, scratchpad,
|
|
132
|
+
* payload, and optional relocated specialization.
|
|
133
|
+
*/
|
|
134
|
+
BuildRuntimeStateFragment(input) {
|
|
135
|
+
return new RuntimeStateFragmentBuilder().Build({
|
|
136
|
+
DateTime: input.DateTime,
|
|
137
|
+
Scratchpad: input.Scratchpad,
|
|
138
|
+
// Same value the agent type injects for the template (`payload || {}`), so both placements agree.
|
|
139
|
+
Payload: input.IncludePayload ? { Value: input.Payload || {} } : null,
|
|
140
|
+
Specialization: input.Specialization,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Formats sub-agent details as compact markdown for inclusion in prompt context.
|
|
145
|
+
*/
|
|
146
|
+
FormatSubAgentDetails(subAgents) {
|
|
147
|
+
return subAgents
|
|
148
|
+
.map((sa) => {
|
|
149
|
+
let line = `- **${sa.Name}** — ${sa.Description}`;
|
|
150
|
+
if (sa.ExecutionMode !== 'Sequential') {
|
|
151
|
+
line += ` _(${sa.ExecutionMode}, order: ${sa.ExecutionOrder})_`;
|
|
152
|
+
}
|
|
153
|
+
const presets = AIEngine.Instance.GetAgentConfigurationPresets(sa.ID, true);
|
|
154
|
+
if (presets.length > 0) {
|
|
155
|
+
const presetSummary = presets
|
|
156
|
+
.map((p) => {
|
|
157
|
+
const desc = p.Description?.trim();
|
|
158
|
+
if (p.IsDefault && desc) {
|
|
159
|
+
return `${p.Name} (default: ${desc})`;
|
|
160
|
+
}
|
|
161
|
+
if (p.IsDefault) {
|
|
162
|
+
return `${p.Name} (default)`;
|
|
163
|
+
}
|
|
164
|
+
if (desc) {
|
|
165
|
+
return `${p.Name} (${desc})`;
|
|
166
|
+
}
|
|
167
|
+
return p.Name;
|
|
168
|
+
})
|
|
169
|
+
.join(', ');
|
|
170
|
+
line += `\n Presets: ${presetSummary}`;
|
|
171
|
+
}
|
|
172
|
+
return line;
|
|
173
|
+
})
|
|
174
|
+
.join('\n');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Formats the skill CATALOG as compact markdown — name + description ONLY. This is
|
|
178
|
+
* progressive disclosure by design: the LLM sees just enough to decide whether to activate a
|
|
179
|
+
* skill (via a `'Skill'` next step), but never sees `Instructions` until it does.
|
|
180
|
+
*/
|
|
181
|
+
FormatSkillsCatalog(skills) {
|
|
182
|
+
return skills.map((s) => `- **${s.Name}** — ${s.Description ?? '(no description)'}`).join('\n');
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Formats action details as compact markdown for inclusion in prompt context.
|
|
186
|
+
* Produces ~75% fewer tokens than the previous JSON format while preserving
|
|
187
|
+
* all information the LLM needs to invoke actions correctly.
|
|
188
|
+
*
|
|
189
|
+
* A parameter the run binds (`ExecuteAgentParams.boundActionParams`) is left out, so the model is
|
|
190
|
+
* never told it exists. With no bindings the output is the cached catalog's, unchanged.
|
|
191
|
+
*/
|
|
192
|
+
FormatActionDetails(actions, boundActionParams) {
|
|
193
|
+
return actions
|
|
194
|
+
.map((action) => {
|
|
195
|
+
const lines = [];
|
|
196
|
+
lines.push(`### ${action.Name}`);
|
|
197
|
+
lines.push(action.Description);
|
|
198
|
+
const visibleParams = UnboundParams(action.Params.Items, BindingsForAction(boundActionParams, action.ID));
|
|
199
|
+
const inputParams = visibleParams.filter((p) => {
|
|
200
|
+
const t = p.Type.trim().toLowerCase();
|
|
201
|
+
return t === 'input' || t === 'both';
|
|
202
|
+
});
|
|
203
|
+
const outputParams = visibleParams.filter((p) => {
|
|
204
|
+
const t = p.Type.trim().toLowerCase();
|
|
205
|
+
return t === 'output' || t === 'both';
|
|
206
|
+
});
|
|
207
|
+
if (inputParams.length > 0) {
|
|
208
|
+
lines.push(`**Input:** ${inputParams.map((p) => this.FormatActionParameter(p)).join(', ')}`);
|
|
209
|
+
}
|
|
210
|
+
if (outputParams.length > 0) {
|
|
211
|
+
lines.push(`**Output:** ${outputParams.map((p) => this.FormatActionParameter(p)).join(', ')}`);
|
|
212
|
+
}
|
|
213
|
+
if (action.ResultCodes.Items.length > 0) {
|
|
214
|
+
const rcParts = action.ResultCodes.Items.map((rc) => {
|
|
215
|
+
const marker = rc.IsSuccess ? '✓' : '✗';
|
|
216
|
+
const desc = rc.Description && rc.Description.toLowerCase() !== rc.ResultCode.toLowerCase()
|
|
217
|
+
? ` ${rc.Description}`
|
|
218
|
+
: '';
|
|
219
|
+
return `${rc.ResultCode} ${marker}${desc}`;
|
|
220
|
+
});
|
|
221
|
+
lines.push(`**Results:** ${rcParts.join(' · ')}`);
|
|
222
|
+
}
|
|
223
|
+
return lines.join('\n');
|
|
224
|
+
})
|
|
225
|
+
.join('\n\n');
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Formats a single action parameter as a compact inline markdown string.
|
|
229
|
+
* Uses `\*` suffix for required, `(array)` when `IsArray`, and only shows
|
|
230
|
+
* `ValueType` when it is not `Scalar`/`Other`.
|
|
231
|
+
*/
|
|
232
|
+
FormatActionParameter(param) {
|
|
233
|
+
const requiredMarker = param.IsRequired ? '\\*' : '';
|
|
234
|
+
const parts = [];
|
|
235
|
+
if (param.IsArray) {
|
|
236
|
+
parts.push('array');
|
|
237
|
+
}
|
|
238
|
+
// A stored ValueSchema is the real type, so it replaces the coarse ValueType label — the
|
|
239
|
+
// same information the native tool declaration carries.
|
|
240
|
+
const valueSchema = GetStoredValueSchema(param);
|
|
241
|
+
const vt = param.ValueType?.trim();
|
|
242
|
+
if (valueSchema) {
|
|
243
|
+
parts.push(DescribeValueSchemaInline(valueSchema));
|
|
244
|
+
}
|
|
245
|
+
else if (vt && vt !== 'Scalar' && vt !== 'Other') {
|
|
246
|
+
parts.push(vt);
|
|
247
|
+
}
|
|
248
|
+
const suffix = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
249
|
+
let defaultStr = '';
|
|
250
|
+
if (param.DefaultValue != null && param.DefaultValue !== '') {
|
|
251
|
+
defaultStr = ` (default: ${JSON.stringify(param.DefaultValue)})`;
|
|
252
|
+
}
|
|
253
|
+
const desc = param.Description ? ` — ${param.Description}` : '';
|
|
254
|
+
return `\`${param.Name}\`${requiredMarker}${suffix}${desc}${defaultStr}`;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Resolves the client tools in force for a run: the agent's static metadata tools under the
|
|
258
|
+
* session, app, and override tiers, merged by {@link ResolveClientTools} with its fixed precedence.
|
|
259
|
+
* Both the prompt section and the client-tool execution step resolve through here so the tools
|
|
260
|
+
* offered to the model and the metadata its results are classified against come from one list.
|
|
261
|
+
*/
|
|
262
|
+
ResolveClientToolsForRun(agent, extraData) {
|
|
263
|
+
const engine = AIEngine.Instance;
|
|
264
|
+
// Static tier — agent's metadata tools from the AI Agent Client Tools junction.
|
|
265
|
+
const staticTools = engine.GetClientToolsForAgent(agent.ID).map((tool) => ({
|
|
266
|
+
Name: tool.Name,
|
|
267
|
+
Description: tool.Description,
|
|
268
|
+
InputSchema: tool.InputSchemaJSON ? JSON.parse(tool.InputSchemaJSON) : {},
|
|
269
|
+
OutputSchema: tool.OutputSchemaJSON ? JSON.parse(tool.OutputSchemaJSON) : undefined,
|
|
270
|
+
Category: tool.Category || undefined,
|
|
271
|
+
DefaultTimeoutMs: tool.DefaultTimeoutMs || undefined,
|
|
272
|
+
}));
|
|
273
|
+
// Dynamic (session) tier — client-SDK enriched tools for this session.
|
|
274
|
+
const sessionID = extraData?.sessionID;
|
|
275
|
+
const sessionTools = sessionID ? ClientToolRequestManager.Instance.GetSessionTools(sessionID) : [];
|
|
276
|
+
// App tier — tools the active surface published in the app-context capability manifest.
|
|
277
|
+
const appContext = extraData?.appContext;
|
|
278
|
+
const appTools = appContext?.Capabilities?.Tools ?? [];
|
|
279
|
+
// Override tier — tools passed directly in the run's data.
|
|
280
|
+
const overrideTools = extraData?.clientTools ?? [];
|
|
281
|
+
return ResolveClientTools({
|
|
282
|
+
agentId: agent.ID,
|
|
283
|
+
staticTools,
|
|
284
|
+
sessionTools,
|
|
285
|
+
appTools,
|
|
286
|
+
overrideTools,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Builds the client tool prompt section for system prompt injection across static,
|
|
291
|
+
* session, app, and override tiers (`override > session > app > static`).
|
|
292
|
+
*/
|
|
293
|
+
BuildClientToolPromptSection(agent, extraData) {
|
|
294
|
+
const tools = this.ResolveClientToolsForRun(agent, extraData);
|
|
295
|
+
if (tools.length === 0) {
|
|
296
|
+
return ''; // No client tools available
|
|
297
|
+
}
|
|
298
|
+
const lines = [];
|
|
299
|
+
lines.push("### Client Tools (execute in the user's browser)");
|
|
300
|
+
lines.push("Client tools run in the user's browser and interact with the UI. Use these when you need");
|
|
301
|
+
lines.push('to navigate the user somewhere, display a specific view, switch dashboard tabs, or show');
|
|
302
|
+
lines.push('records. When you choose client tools, set nextStep.type to "ClientTools".');
|
|
303
|
+
lines.push('');
|
|
304
|
+
lines.push('NOTE: Do NOT use client tools for asking the user questions or collecting input.');
|
|
305
|
+
lines.push('Use the "Chat" step for that. Client tools read and change the user\'s UI; some return an image.');
|
|
306
|
+
lines.push('');
|
|
307
|
+
for (const tool of tools) {
|
|
308
|
+
const categoryTag = tool.Category ? ` [${tool.Category}]` : '';
|
|
309
|
+
lines.push(`- **${tool.Name}**${categoryTag}: ${tool.Description}`);
|
|
310
|
+
// Show input parameters from InputSchema
|
|
311
|
+
const props = tool.InputSchema?.properties;
|
|
312
|
+
const required = tool.InputSchema?.required;
|
|
313
|
+
if (props) {
|
|
314
|
+
const paramParts = Object.entries(props).map(([name, schema]) => {
|
|
315
|
+
const req = required?.includes(name) ? '\\*' : '';
|
|
316
|
+
const desc = schema.description ? ` — ${schema.description}` : '';
|
|
317
|
+
return `\`${name}\`${req}${desc}`;
|
|
318
|
+
});
|
|
319
|
+
lines.push(` Inputs: ${paramParts.join(', ')}`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return lines.join('\n');
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Builds the current application context markdown section from `extraData.appContext`.
|
|
326
|
+
*/
|
|
327
|
+
BuildAppContextSection(extraData) {
|
|
328
|
+
const ctx = extraData?.appContext;
|
|
329
|
+
if (!ctx)
|
|
330
|
+
return '';
|
|
331
|
+
const app = ctx['App'];
|
|
332
|
+
const activeNav = ctx['ActiveNavItem'];
|
|
333
|
+
const otherNavs = ctx['OtherNavItems'];
|
|
334
|
+
const user = ctx['User'];
|
|
335
|
+
if (!app?.Name)
|
|
336
|
+
return '';
|
|
337
|
+
const lines = [];
|
|
338
|
+
lines.push('### Current Application Context');
|
|
339
|
+
lines.push(`The user is currently in the **${app.Name}** application${app.Description ? ` — ${app.Description}` : ''}.`);
|
|
340
|
+
if (activeNav?.Name) {
|
|
341
|
+
lines.push('');
|
|
342
|
+
lines.push(`**Active view:** ${activeNav.Name}${activeNav.Description ? ` — ${activeNav.Description}` : ''}${activeNav.ResourceType ? ` (${activeNav.ResourceType})` : ''}`);
|
|
343
|
+
}
|
|
344
|
+
if (otherNavs && otherNavs.length > 0) {
|
|
345
|
+
lines.push('');
|
|
346
|
+
lines.push('**Other views available in this app:**');
|
|
347
|
+
for (const nav of otherNavs) {
|
|
348
|
+
lines.push(`- ${nav.Name}${nav.Description ? ` — ${nav.Description}` : ''}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (user?.Name) {
|
|
352
|
+
lines.push('');
|
|
353
|
+
lines.push(`**User:** ${user.Name}${user.Roles?.length ? ` (Roles: ${user.Roles.join(', ')})` : ''}`);
|
|
354
|
+
}
|
|
355
|
+
// Additional context reported by the active view/component
|
|
356
|
+
const dashboardCtx = ctx['AdditionalContext'];
|
|
357
|
+
if (dashboardCtx && Object.keys(dashboardCtx).length > 0) {
|
|
358
|
+
lines.push('');
|
|
359
|
+
lines.push('**Dashboard state:**');
|
|
360
|
+
for (const [key, value] of Object.entries(dashboardCtx)) {
|
|
361
|
+
if (value === null || value === undefined)
|
|
362
|
+
continue;
|
|
363
|
+
const displayValue = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
364
|
+
lines.push(`- ${key}: ${displayValue}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return lines.join('\n');
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Extracts default values from an agent type's JSON Schema `PromptParamsSchema`.
|
|
371
|
+
*/
|
|
372
|
+
ExtractSchemaDefaults(schemaJson) {
|
|
373
|
+
if (!schemaJson)
|
|
374
|
+
return {};
|
|
375
|
+
try {
|
|
376
|
+
const schema = JSON.parse(schemaJson);
|
|
377
|
+
const defaults = {};
|
|
378
|
+
if (schema.properties) {
|
|
379
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
380
|
+
if (prop.default !== undefined) {
|
|
381
|
+
defaults[key] = prop.default;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return defaults;
|
|
386
|
+
}
|
|
387
|
+
catch (e) {
|
|
388
|
+
LogError(`Failed to parse PromptParamsSchema: ${e instanceof Error ? e.message : String(e)}`);
|
|
389
|
+
return {};
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Applies auto-alignment rules to `includeResponseTypeDefinition` based on documentation
|
|
394
|
+
* and capability flags on `params`.
|
|
395
|
+
*/
|
|
396
|
+
ApplyResponseTypeAutoAlignment(params, explicitResponseType, decisionsEnabled = params.decisionsEnabled === true) {
|
|
397
|
+
// Align a copy: the object may be the caller's per-run override, which sub-agents inherit with the
|
|
398
|
+
// run's data. Writing into it would turn a key "explicit" for every later merge of that override.
|
|
399
|
+
if (IsPlainObject(params.includeResponseTypeDefinition)) {
|
|
400
|
+
params.includeResponseTypeDefinition = { ...params.includeResponseTypeDefinition };
|
|
401
|
+
}
|
|
402
|
+
// Ensure includeResponseTypeDefinition is an object
|
|
403
|
+
else if (!params.includeResponseTypeDefinition ||
|
|
404
|
+
typeof params.includeResponseTypeDefinition !== 'object') {
|
|
405
|
+
params.includeResponseTypeDefinition = {
|
|
406
|
+
payload: true,
|
|
407
|
+
responseForms: true,
|
|
408
|
+
commands: true,
|
|
409
|
+
forEach: true,
|
|
410
|
+
while: true,
|
|
411
|
+
scratchpad: true,
|
|
412
|
+
decisions: true,
|
|
413
|
+
finishIf: true,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
const responseType = params.includeResponseTypeDefinition;
|
|
417
|
+
// finishIf gates are opt-in (`finishIfMode`), and need the master switch. While off, the model is
|
|
418
|
+
// not taught to write one, whatever includeFinishIfDocs says, so the response field below follows it off too.
|
|
419
|
+
if (!decisionsEnabled || ResolveFinishIfMode(params.finishIfMode) === 'off') {
|
|
420
|
+
params.includeFinishIfDocs = false;
|
|
421
|
+
}
|
|
422
|
+
// `decisions` is opt-in too (`includeDecisionsDocs: true`), and needs the master switch. Its docs and
|
|
423
|
+
// types add about 1,200 tokens to every turn, and on the Prompt Eval corpus no model used it
|
|
424
|
+
// (typed-decision plan, Task 4.7). Unset means off, so the response field below follows it off too.
|
|
425
|
+
if (!decisionsEnabled || params.includeDecisionsDocs !== true) {
|
|
426
|
+
params.includeDecisionsDocs = false;
|
|
427
|
+
}
|
|
428
|
+
// Auto-alignment mappings: docs flag → response type property
|
|
429
|
+
const alignmentMappings = [
|
|
430
|
+
{ docsFlag: 'includePayloadInPrompt', responseTypeKey: 'payload' },
|
|
431
|
+
{ docsFlag: 'includeResponseFormDocs', responseTypeKey: 'responseForms' },
|
|
432
|
+
{ docsFlag: 'includeCommandDocs', responseTypeKey: 'commands' },
|
|
433
|
+
{ docsFlag: 'includeForEachDocs', responseTypeKey: 'forEach' },
|
|
434
|
+
{ docsFlag: 'includeWhileDocs', responseTypeKey: 'while' },
|
|
435
|
+
{ docsFlag: 'includeScratchpadDocs', responseTypeKey: 'scratchpad' },
|
|
436
|
+
{ docsFlag: 'includeArtifactToolsDocs', responseTypeKey: 'artifactToolCalls' },
|
|
437
|
+
{ docsFlag: 'includeConversationToolsDocs', responseTypeKey: 'conversationToolCalls' },
|
|
438
|
+
{ docsFlag: 'includePipelineDocs', responseTypeKey: 'pipeline' },
|
|
439
|
+
{ docsFlag: 'includeMemoryWritesDocs', responseTypeKey: 'memoryWrites' },
|
|
440
|
+
{ docsFlag: 'includeDecisionsDocs', responseTypeKey: 'decisions' },
|
|
441
|
+
{ docsFlag: 'includeFinishIfDocs', responseTypeKey: 'finishIf' },
|
|
442
|
+
];
|
|
443
|
+
for (const { docsFlag, responseTypeKey } of alignmentMappings) {
|
|
444
|
+
// Check if the user explicitly set this response type property
|
|
445
|
+
// (not from schema defaults, which always provide true)
|
|
446
|
+
const wasExplicitlySet = explicitResponseType &&
|
|
447
|
+
Object.prototype.hasOwnProperty.call(explicitResponseType, responseTypeKey);
|
|
448
|
+
// Auto-align: if docs flag is false AND user didn't explicitly set the response type
|
|
449
|
+
// then auto-align the response type to false
|
|
450
|
+
if (params[docsFlag] === false && !wasExplicitlySet) {
|
|
451
|
+
responseType[responseTypeKey] = false;
|
|
452
|
+
}
|
|
453
|
+
// If user explicitly set the value, respect it regardless of docs flag
|
|
454
|
+
// Otherwise default to true if not set
|
|
455
|
+
else if (responseType[responseTypeKey] === undefined) {
|
|
456
|
+
responseType[responseTypeKey] = true;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
// With the master switch off, neither decision field is offered, even when set explicitly: the
|
|
460
|
+
// model must not be invited to ask for something the run would refuse.
|
|
461
|
+
if (!decisionsEnabled) {
|
|
462
|
+
responseType.decisions = false;
|
|
463
|
+
responseType.finishIf = false;
|
|
464
|
+
}
|
|
465
|
+
// Capability gates align the OTHER way: default OFF, and the section appears only when the
|
|
466
|
+
// gate is explicitly on. Running these through the loop above would invert their meaning —
|
|
467
|
+
// that loop's `else` branch defaults an unset key to true, which is exactly what a gated
|
|
468
|
+
// capability must never do.
|
|
469
|
+
const gateMappings = [
|
|
470
|
+
{ gateFlag: 'enableTaskGraphs', responseTypeKey: 'tasks' },
|
|
471
|
+
{ gateFlag: 'enableHandoff', responseTypeKey: 'handoff' },
|
|
472
|
+
];
|
|
473
|
+
for (const { gateFlag, responseTypeKey } of gateMappings) {
|
|
474
|
+
const wasExplicitlySet = explicitResponseType &&
|
|
475
|
+
Object.prototype.hasOwnProperty.call(explicitResponseType, responseTypeKey);
|
|
476
|
+
if (!wasExplicitlySet) {
|
|
477
|
+
responseType[responseTypeKey] = params[gateFlag] === true;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
//# sourceMappingURL=AgentContextAssembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentContextAssembler.js","sourceRoot":"","sources":["../src/AgentContextAssembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAOH,kBAAkB,EAClB,wBAAwB,GAC3B,MAAM,8BAA8B,CAAC;AAOtC,OAAO,EAAE,OAAO,EAAe,mBAAmB,EAAE,MAAM,oBAAoB,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YAAY,CAAC,eAAe,CAAC,KAAK,SAAS,EAAE,CAAC;gBACnD,YAAY,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;YACzC,CAAC;QACL,CAAC;QAED,+FAA+F;QAC/F,uEAAuE;QACvE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACpB,YAAY,CAAC,SAAS,GAAG,KAAK,CAAC;YAC/B,YAAY,CAAC,QAAQ,GAAG,KAAK,CAAC;QAClC,CAAC;QAED,2FAA2F;QAC3F,2FAA2F;QAC3F,yFAAyF;QACzF,4BAA4B;QAC5B,MAAM,YAAY,GAAyD;YACvE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,OAAO,EAAE;YAC1D,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE;SAC5D,CAAC;QAEF,KAAK,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,YAAY,EAAE,CAAC;YACvD,MAAM,gBAAgB,GAClB,oBAAoB;gBACpB,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;YAChF,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACpB,YAAY,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;YAC9D,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -37,9 +37,13 @@ export interface PreloadedDataResult {
|
|
|
37
37
|
}
|
|
38
38
|
export declare class AgentDataPreloader extends BaseSingleton<AgentDataPreloader> {
|
|
39
39
|
/**
|
|
40
|
-
* Per-agent cache
|
|
40
|
+
* Per-agent cache, keyed by agent, data source and user. Each entry carries its own
|
|
41
|
+
* data-source-specific TTL (checked on read); the LRU cap bounds total entries so
|
|
42
|
+
* expired-but-never-re-read keys cannot accumulate (one entry per user x agent x source).
|
|
41
43
|
*/
|
|
42
44
|
private _perAgentCache;
|
|
45
|
+
/** Upper bound on cached per-agent datasets before least-recently-used eviction. */
|
|
46
|
+
static readonly MAX_PER_AGENT_CACHE_ENTRIES = 200;
|
|
43
47
|
/**
|
|
44
48
|
* Per-run cache (scoped to a single run ID)
|
|
45
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentDataPreloader.d.ts","sourceRoot":"","sources":["../src/AgentDataPreloader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAqE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,EAAc,aAAa,
|
|
1
|
+
{"version":3,"file":"AgentDataPreloader.d.ts","sourceRoot":"","sources":["../src/AgentDataPreloader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAqE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,EAAc,aAAa,EAAkC,MAAM,wBAAwB,CAAC;AAKnG;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gDAAgD;IAChD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,sDAAsD;IACtD,aAAa,EAAE,gBAAgB,EAAE,CAAC;CACrC;AAmCD,qBAAa,kBAAmB,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACrE;;;;OAIG;IACH,OAAO,CAAC,cAAc,CAEnB;IAEH,oFAAoF;IACpF,gBAAuB,2BAA2B,OAAO;IAEzD;;OAEG;IACH,OAAO,CAAC,YAAY,CAAgD;;IAMpE;;OAEG;IACH,WAAkB,QAAQ,IAAI,kBAAkB,CAE/C;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,gBAAgB,CACzB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,QAAQ,EACrB,KAAK,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,CAAC;IAqF/B;;;;;OAKG;IACI,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IASzC,6CAA6C;IACtC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzC;;;OAGG;IACI,eAAe,IAAI,IAAI;IAS9B,+CAA+C;IACxC,eAAe,IAAI,IAAI;IAI9B;;;;;;OAMG;YACW,kBAAkB;IAwChC;;;;OAIG;YACW,uBAAuB;IAiBrC;;;;;OAKG;YACW,iBAAiB;IAiC/B;;;;OAIG;YACW,cAAc;IAmC5B;;;;OAIG;YACW,eAAe;IAiC7B;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IA0CrB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAuCjB;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;CAG9B"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
14
14
|
import { LogError, LogStatusEx, IsVerboseLoggingEnabled, RunView, RunQuery } from '@memberjunction/core';
|
|
15
|
-
import { UUIDsEqual, BaseSingleton, UserScopedCacheKey } from '@memberjunction/global';
|
|
15
|
+
import { UUIDsEqual, BaseSingleton, UserScopedCacheKey, MJLruCache } from '@memberjunction/global';
|
|
16
16
|
import _ from 'lodash';
|
|
17
17
|
/**
|
|
18
18
|
* Singleton service for preloading agent data sources.
|
|
@@ -38,12 +38,18 @@ import _ from 'lodash';
|
|
|
38
38
|
*/
|
|
39
39
|
const PRELOAD_CONCURRENCY_LIMIT = 10;
|
|
40
40
|
export class AgentDataPreloader extends BaseSingleton {
|
|
41
|
+
/** Upper bound on cached per-agent datasets before least-recently-used eviction. */
|
|
42
|
+
static { this.MAX_PER_AGENT_CACHE_ENTRIES = 200; }
|
|
41
43
|
constructor() {
|
|
42
44
|
super();
|
|
43
45
|
/**
|
|
44
|
-
* Per-agent cache
|
|
46
|
+
* Per-agent cache, keyed by agent, data source and user. Each entry carries its own
|
|
47
|
+
* data-source-specific TTL (checked on read); the LRU cap bounds total entries so
|
|
48
|
+
* expired-but-never-re-read keys cannot accumulate (one entry per user x agent x source).
|
|
45
49
|
*/
|
|
46
|
-
this._perAgentCache = new
|
|
50
|
+
this._perAgentCache = new MJLruCache({
|
|
51
|
+
maxSize: AgentDataPreloader.MAX_PER_AGENT_CACHE_ENTRIES
|
|
52
|
+
});
|
|
47
53
|
/**
|
|
48
54
|
* Per-run cache (scoped to a single run ID)
|
|
49
55
|
*/
|
|
@@ -182,7 +188,7 @@ export class AgentDataPreloader extends BaseSingleton {
|
|
|
182
188
|
* Can be called to force refresh of global cached data.
|
|
183
189
|
*/
|
|
184
190
|
ClearAgentCache() {
|
|
185
|
-
this._perAgentCache.
|
|
191
|
+
this._perAgentCache.Clear();
|
|
186
192
|
LogStatusEx({
|
|
187
193
|
message: `AgentDataPreloader: Cleared all per-agent cache`,
|
|
188
194
|
verboseOnly: true,
|
|
@@ -365,7 +371,7 @@ export class AgentDataPreloader extends BaseSingleton {
|
|
|
365
371
|
if (cacheKey === null) {
|
|
366
372
|
return null;
|
|
367
373
|
}
|
|
368
|
-
const entry = this._perAgentCache.
|
|
374
|
+
const entry = this._perAgentCache.Get(cacheKey);
|
|
369
375
|
if (entry) {
|
|
370
376
|
// Check if expired
|
|
371
377
|
const now = new Date();
|
|
@@ -375,7 +381,7 @@ export class AgentDataPreloader extends BaseSingleton {
|
|
|
375
381
|
}
|
|
376
382
|
else {
|
|
377
383
|
// Expired, remove from cache
|
|
378
|
-
this._perAgentCache.
|
|
384
|
+
this._perAgentCache.Delete(cacheKey);
|
|
379
385
|
}
|
|
380
386
|
}
|
|
381
387
|
return null;
|
|
@@ -414,7 +420,7 @@ export class AgentDataPreloader extends BaseSingleton {
|
|
|
414
420
|
timestamp: new Date(),
|
|
415
421
|
timeoutSeconds: source.CacheTimeoutSeconds
|
|
416
422
|
};
|
|
417
|
-
this._perAgentCache.
|
|
423
|
+
this._perAgentCache.Set(cacheKey, entry);
|
|
418
424
|
}
|
|
419
425
|
}
|
|
420
426
|
/**
|