lemura 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +124 -0
- package/README.md +12 -11
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +10 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +10 -2
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/{storage-CG3nTa6o.d.mts → adapters-BhTAnrOM.d.mts} +79 -46
- package/dist/{storage-DBt_q0wO.d.ts → adapters-CVcfWf85.d.ts} +79 -46
- package/dist/{agent-DxRd93wl.d.ts → agent-38El9_yp.d.ts} +35 -4
- package/dist/{agent-D6uhF-CZ.d.mts → agent-CJvmcAbT.d.mts} +35 -4
- package/dist/context/index.d.mts +71 -7
- package/dist/context/index.d.ts +71 -7
- package/dist/context/index.js +75 -4
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +74 -5
- package/dist/context/index.mjs.map +1 -1
- package/dist/index.d.mts +339 -63
- package/dist/index.d.ts +339 -63
- package/dist/index.js +1018 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1017 -133
- package/dist/index.mjs.map +1 -1
- package/dist/skills/index.d.mts +92 -3
- package/dist/skills/index.d.ts +92 -3
- package/dist/skills/index.js +138 -8
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/index.mjs +138 -8
- package/dist/skills/index.mjs.map +1 -1
- package/dist/skills-Y6D7zSSw.d.mts +66 -0
- package/dist/skills-Y6D7zSSw.d.ts +66 -0
- package/dist/tools/index.d.mts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/types/index.d.mts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/package.json +6 -1
- package/dist/skills-wc8S-OvC.d.mts +0 -14
- package/dist/skills-wc8S-OvC.d.ts +0 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { a as IProviderAdapter, T as TranscriptionRequest,
|
|
2
|
-
export {
|
|
3
|
-
import { S as SessionConfig, I as IToolResponseProcessor, T as ToolResponseEvaluation, M as MCPServerConfig, a as MCPToolDefinition } from './agent-
|
|
4
|
-
export { b as MCPJsonRpcRequest, c as MCPJsonRpcResponse, d as MCPTransportType, e as MediaConfig, f as ToolDecision, g as ToolExecutionBudget, h as ToolFirewallConfig, i as ToolFirewallRule, j as TraceEvent } from './agent-
|
|
1
|
+
import { a as IProviderAdapter, T as TranscriptionRequest, d as TranscriptionResponse, e as SynthesisRequest, A as AudioChunk, V as VisionRequest, f as VisionResponse, g as ImageGenRequest, h as ImageGenResponse, M as ModelInfo, C as ContextWindow, i as Turn, j as ContentBlock, I as IToolDefinition } from './adapters-CVcfWf85.js';
|
|
2
|
+
export { k as CompletionChunk, l as CompletionRequest, m as CompletionResponse, b as IContextStrategy, c as IScratchpadAdapter, n as IStorageAdapter, N as NormalizedMessage, o as STMItem, p as STMRegistryConfig, S as ShortTermMemoryRegistry, q as TokenUsage, r as ToolCall, s as ToolContext, t as ToolResult } from './adapters-CVcfWf85.js';
|
|
3
|
+
import { S as SessionConfig, I as IToolResponseProcessor, T as ToolResponseEvaluation, M as MCPServerConfig, a as MCPToolDefinition } from './agent-38El9_yp.js';
|
|
4
|
+
export { b as MCPJsonRpcRequest, c as MCPJsonRpcResponse, d as MCPTransportType, e as MediaConfig, f as ToolDecision, g as ToolExecutionBudget, h as ToolFirewallConfig, i as ToolFirewallRule, j as TraceEvent } from './agent-38El9_yp.js';
|
|
5
5
|
export { LemuraAdapterError, LemuraContextOverflowError, LemuraError, LemuraMCPConnectionError, LemuraMCPError, LemuraMCPTimeoutError, LemuraMaxIterationsError, LemuraSkillInjectionError, LemuraToolNotFoundError, LemuraToolTimeoutError, LemuraToolValidationError } from './types/index.js';
|
|
6
6
|
import { I as ILogger } from './logger-DxvKliuk.js';
|
|
7
7
|
export { L as LogLevel, a as LogMetadata, S as Severity } from './logger-DxvKliuk.js';
|
|
8
8
|
export { I as IRAGAdapter, R as RAGDocument, a as RAGIngestOptions, b as RAGIngestRequest, c as RAGIngestResponse, d as RAGQueryRequest, e as RAGQueryResponse, f as RAGResult } from './rag-La_Bo-J8.js';
|
|
9
|
-
export { I as ISkill } from './skills-
|
|
9
|
+
export { I as ISkill, S as SkillStrategy } from './skills-Y6D7zSSw.js';
|
|
10
10
|
export { OpenAICompatibleAdapter, OpenAICompatibleAdapterConfig, RetryConfig } from './adapters/index.js';
|
|
11
|
-
export { ContextManager, HistoryCompressionConfig, HistoryCompressionStrategy, InMemoryStorageAdapter, SandwichCompressionConfig, SandwichCompressionStrategy, ScratchpadStrategy } from './context/index.js';
|
|
12
|
-
|
|
13
|
-
export {
|
|
11
|
+
export { ContextManager, HistoryCompressionConfig, HistoryCompressionStrategy, InMemoryScratchpadAdapter, InMemoryStorageAdapter, SandwichCompressionConfig, SandwichCompressionStrategy, ScratchpadStrategy, SummaryInjectionConfig, SummaryInjectionStrategy } from './context/index.js';
|
|
12
|
+
import { ToolRegistry } from './tools/index.js';
|
|
13
|
+
export { SchemaValidationError, ToolFirewallResult, ToolRegistryOptions, evaluateToolFirewall, validateJsonSchema } from './tools/index.js';
|
|
14
|
+
import { SkillInjector } from './skills/index.js';
|
|
14
15
|
export { InMemoryRAGAdapter } from './rag/index.js';
|
|
15
16
|
export { DefaultLogger } from './logger/index.js';
|
|
16
17
|
|
|
@@ -29,22 +30,186 @@ declare class MediaBridge {
|
|
|
29
30
|
supportsVision(): boolean;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
interface Goal {
|
|
34
|
+
id: string;
|
|
35
|
+
statement: string;
|
|
36
|
+
/** High-level sub-goals decomposed from the main statement */
|
|
37
|
+
decomposition: string[];
|
|
38
|
+
successCriteria: string[];
|
|
39
|
+
injectionFrequency: 'always' | 'every_N_turns' | 'on_compression';
|
|
40
|
+
injectionPosition: 'system_prompt' | 'pre_turn';
|
|
41
|
+
/** Sub-goals already completed — updated via `markSubGoalDone()` */
|
|
42
|
+
completedSubGoals?: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* GoalInjector keeps the original task objective visible throughout the ReAct loop,
|
|
46
|
+
* preventing goal drift after many tool calls and context compressions.
|
|
47
|
+
*
|
|
48
|
+
* Usage in SessionManager:
|
|
49
|
+
* - For `system_prompt` position: call `injectInto(prompt)` which appends the goal block.
|
|
50
|
+
* - For `pre_turn` position: call `getFormattedBlock()` and push as a system message.
|
|
51
|
+
*/
|
|
52
|
+
declare class GoalInjector {
|
|
53
|
+
private goal;
|
|
54
|
+
private turnsSinceInjection;
|
|
55
|
+
constructor(goal: Goal);
|
|
56
|
+
/**
|
|
57
|
+
* Returns the formatted `[CURRENT GOAL]` block string — without caring about
|
|
58
|
+
* where it will be placed. Callers decide whether to append to a system prompt
|
|
59
|
+
* or push as a separate message.
|
|
60
|
+
*/
|
|
61
|
+
getFormattedBlock(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Appends the goal block to the given prompt string (for `system_prompt` position).
|
|
64
|
+
* For `pre_turn` position, use `getFormattedBlock()` directly.
|
|
65
|
+
*
|
|
66
|
+
* @param prompt - The existing system prompt to append to.
|
|
67
|
+
*/
|
|
68
|
+
injectInto(prompt: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Returns true when the goal should be re-injected this turn,
|
|
71
|
+
* based on `injectionFrequency`.
|
|
72
|
+
*
|
|
73
|
+
* @param turnIndex - The current turn index in the ReAct loop (0-based)
|
|
74
|
+
* @param compressionOccurred - Whether context was compressed this iteration
|
|
75
|
+
* @param injectionN - The N for 'every_N_turns' frequency (default: 3)
|
|
76
|
+
*/
|
|
77
|
+
shouldInjectThisTurn(turnIndex: number, compressionOccurred?: boolean, injectionN?: number): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Updates the goal with new sub-goal decomposition and success criteria,
|
|
80
|
+
* typically populated by the mini-planning LLM call.
|
|
81
|
+
*/
|
|
82
|
+
updateDecomposition(decomposition: string[], successCriteria?: string[]): void;
|
|
83
|
+
/**
|
|
84
|
+
* Marks a sub-goal as completed so it moves to the "completed" section
|
|
85
|
+
* in subsequent injections.
|
|
86
|
+
*/
|
|
87
|
+
markSubGoalDone(subGoal: string): void;
|
|
88
|
+
/** Returns a snapshot of the current goal state (safe to store in context.metadata). */
|
|
89
|
+
getGoal(): Goal;
|
|
90
|
+
/** Increments the internal turn counter (used for `every_N_turns` frequency). */
|
|
91
|
+
incrementTurn(): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* An optional condition that gates a step's execution on the output of a prior step.
|
|
96
|
+
* When the condition is not met, the step is automatically marked `skipped`.
|
|
97
|
+
*/
|
|
98
|
+
interface StepCondition {
|
|
99
|
+
/** stepId whose output is inspected */
|
|
100
|
+
step: string;
|
|
101
|
+
/** Substring that must be present in the prior step's output to allow this step to run */
|
|
102
|
+
outputContains: string;
|
|
103
|
+
}
|
|
104
|
+
interface ContinuationStep {
|
|
105
|
+
stepId: string;
|
|
106
|
+
toolName: string;
|
|
107
|
+
description: string;
|
|
108
|
+
/** stepIds that must be `done` before this step may run */
|
|
109
|
+
dependsOn: string[];
|
|
110
|
+
status: 'pending' | 'running' | 'done' | 'failed' | 'skipped';
|
|
111
|
+
/**
|
|
112
|
+
* When provided, the step's output is stored under this key in
|
|
113
|
+
* `context.metadata['toolOutputs']` for downstream steps to reference.
|
|
114
|
+
*/
|
|
115
|
+
outputKey?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Maps prior step `outputKey` values to this step's tool parameter names.
|
|
118
|
+
* E.g. `{ data: 'rawData' }` means the tool's `data` param gets the value
|
|
119
|
+
* stored under the `rawData` output key from an earlier step.
|
|
120
|
+
*/
|
|
121
|
+
inputMapping?: Record<string, string>;
|
|
122
|
+
/**
|
|
123
|
+
* Optional condition: the step only runs if the referenced prior step's output
|
|
124
|
+
* contains the given substring. When the condition is not met, the step is skipped.
|
|
125
|
+
*/
|
|
126
|
+
condition?: StepCondition;
|
|
127
|
+
}
|
|
128
|
+
interface ContinuationPlan {
|
|
129
|
+
steps: ContinuationStep[];
|
|
130
|
+
currentStepIndex: number;
|
|
131
|
+
strategy: 'sequential' | 'parallel' | 'conditional';
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Manages a structured multi-step continuation plan for the ReAct loop.
|
|
135
|
+
*
|
|
136
|
+
* Steps are tracked by status (`pending`, `running`, `done`, `failed`, `skipped`).
|
|
137
|
+
* Dependency failures automatically propagate `skipped` to all downstream steps.
|
|
138
|
+
* Step outputs are stored by `outputKey` and made available for `inputMapping`.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const planner = new ContinuationPlanner({
|
|
143
|
+
* steps: [
|
|
144
|
+
* { stepId: 'fetch', toolName: 'fetch_data', description: 'Get raw data', dependsOn: [], outputKey: 'rawData' },
|
|
145
|
+
* { stepId: 'analyze', toolName: 'analyze', description: 'Run analysis', dependsOn: ['fetch'], inputMapping: { data: 'rawData' } },
|
|
146
|
+
* ],
|
|
147
|
+
* currentStepIndex: 0,
|
|
148
|
+
* strategy: 'sequential',
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare class ContinuationPlanner {
|
|
153
|
+
private plan;
|
|
154
|
+
private outputs;
|
|
155
|
+
constructor(plan: ContinuationPlan);
|
|
156
|
+
/** Returns the current plan (deep copy) */
|
|
157
|
+
getPlan(): ContinuationPlan;
|
|
158
|
+
/** Returns a human-readable status string with icons (injected before each iteration) */
|
|
159
|
+
getPlanStatusString(): string;
|
|
160
|
+
private _icon;
|
|
161
|
+
/** Returns all steps whose dependencies are satisfied and that are still pending */
|
|
162
|
+
getReadySteps(): ContinuationStep[];
|
|
163
|
+
/** Returns true when all steps have reached a terminal state */
|
|
164
|
+
isComplete(): boolean;
|
|
165
|
+
/** Marks a step as running */
|
|
166
|
+
markStepRunning(stepId: string): void;
|
|
167
|
+
/**
|
|
168
|
+
* Marks a step as done, stores its output under `outputKey` (if set),
|
|
169
|
+
* and advances `currentStepIndex` to the next pending step.
|
|
170
|
+
*/
|
|
171
|
+
markStepDone(stepId: string, output?: string): void;
|
|
172
|
+
/**
|
|
173
|
+
* Marks a step as failed and propagates `skipped` to all transitively dependent steps.
|
|
174
|
+
*/
|
|
175
|
+
markStepFailed(stepId: string): void;
|
|
176
|
+
/**
|
|
177
|
+
* Marks a step as skipped (e.g., condition not met) and propagates to its dependants.
|
|
178
|
+
*/
|
|
179
|
+
markStepSkipped(stepId: string): void;
|
|
180
|
+
/** Retrieves an output stored by `outputKey` from a completed step */
|
|
181
|
+
getOutput(key: string): string | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Resolves the `inputMapping` for a step into a concrete parameter map,
|
|
184
|
+
* substituting `outputKey` values from prior steps. Static (non-key) values
|
|
185
|
+
* in the mapping are passed through unchanged.
|
|
186
|
+
*/
|
|
187
|
+
resolveInputs(step: ContinuationStep, baseArgs?: Record<string, unknown>): Record<string, unknown>;
|
|
188
|
+
private _updateStep;
|
|
189
|
+
private _skipDependants;
|
|
190
|
+
private _advanceIndex;
|
|
191
|
+
}
|
|
192
|
+
|
|
32
193
|
/**
|
|
33
194
|
* Core entry point for lemura agent sessions.
|
|
34
195
|
*
|
|
35
196
|
* `SessionManager` owns the full ReAct loop lifecycle:
|
|
36
197
|
* - Context window management and compression
|
|
37
|
-
* - Skill injection
|
|
198
|
+
* - Skill injection (with optional token budget)
|
|
38
199
|
* - Tool firewall + schema validation + timeout enforcement
|
|
39
200
|
* - Parallel tool execution (opt-in via `parallelToolCalls`)
|
|
40
201
|
* - maxSteps guard → forced graceful conclusion
|
|
41
|
-
* - Tool response compression (via `
|
|
42
|
-
* - Goal injection (via `enableGoalPlanning`)
|
|
202
|
+
* - Tool response compression (via `ToolResponseProcessor`)
|
|
203
|
+
* - Goal injection + mini-planning step (via `enableGoalPlanning`)
|
|
204
|
+
* - Continuation planning with dependency tracking (via `enableContinuationPlanning`)
|
|
43
205
|
* - Streaming output (`stream()`)
|
|
206
|
+
* - Session lifecycle: `reset()`, `close()`
|
|
44
207
|
*
|
|
45
208
|
* @example
|
|
209
|
+
* ```typescript
|
|
46
210
|
* const session = new SessionManager({ adapter, model: 'gpt-4o', maxTokens: 16_000 });
|
|
47
211
|
* const answer = await session.run('What is the capital of France?');
|
|
212
|
+
* ```
|
|
48
213
|
*/
|
|
49
214
|
declare class SessionManager {
|
|
50
215
|
private contextManager;
|
|
@@ -56,44 +221,146 @@ declare class SessionManager {
|
|
|
56
221
|
private iterations;
|
|
57
222
|
private logger;
|
|
58
223
|
private media;
|
|
224
|
+
private sessionId;
|
|
225
|
+
private scratchpadLoaded;
|
|
226
|
+
private pendingScratchpadClear;
|
|
59
227
|
private stepCounter;
|
|
60
228
|
private toolResponseProcessor;
|
|
61
229
|
private goalInjector;
|
|
62
230
|
private continuationPlanner;
|
|
63
231
|
private mcpRegistry;
|
|
64
|
-
/** Resolves when all MCP servers are connected;
|
|
232
|
+
/** Resolves when all MCP servers are connected; awaited by run() and stream() */
|
|
65
233
|
private mcpReady;
|
|
66
234
|
private totalToolCallCount;
|
|
67
235
|
private perToolCallCount;
|
|
68
236
|
private totalTokens;
|
|
69
237
|
constructor(config: SessionConfig);
|
|
70
238
|
private emitTrace;
|
|
239
|
+
private ensureScratchpadLoaded;
|
|
240
|
+
/** Returns a shallow copy of the current context window. */
|
|
241
|
+
getContext(): ContextWindow;
|
|
242
|
+
/** Returns the current conversation history. */
|
|
243
|
+
getHistory(): Turn[];
|
|
71
244
|
/**
|
|
72
|
-
*
|
|
245
|
+
* Populates the session context with a pre-existing conversation history.
|
|
246
|
+
*
|
|
247
|
+
* Turns are assigned sequential `turnIndex` values starting from 0 and the
|
|
248
|
+
* context `tokenCount` is recalculated automatically. Call this immediately
|
|
249
|
+
* after construction and before the first `run()` / `stream()`.
|
|
250
|
+
*
|
|
251
|
+
* @param history - Raw history entries (role + content, optional toolCalls/toolResults).
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const session = new SessionManager(config);
|
|
256
|
+
* session.loadHistory(savedMessages);
|
|
257
|
+
* const answer = await session.run('Continue where we left off.');
|
|
258
|
+
* ```
|
|
73
259
|
*/
|
|
74
|
-
|
|
260
|
+
loadHistory(history: Array<{
|
|
261
|
+
role: Turn['role'];
|
|
262
|
+
content: Turn['content'];
|
|
263
|
+
toolCalls?: Turn['toolCalls'];
|
|
264
|
+
toolResults?: Turn['toolResults'];
|
|
265
|
+
}>): void;
|
|
266
|
+
/** Returns the `MediaBridge` for direct ASR / TTS / Vision / Image-gen calls. */
|
|
267
|
+
getMedia(): MediaBridge;
|
|
75
268
|
/**
|
|
76
|
-
* Returns the
|
|
269
|
+
* Returns the `ToolRegistry` for runtime tool management.
|
|
270
|
+
*
|
|
271
|
+
* Use this to register or unregister tools after session construction:
|
|
272
|
+
*
|
|
273
|
+
* ```typescript
|
|
274
|
+
* // Add a tool after the user authenticates
|
|
275
|
+
* session.tools.register(paymentTool);
|
|
276
|
+
*
|
|
277
|
+
* // Remove a tool when no longer needed
|
|
278
|
+
* session.tools.unregister('send_payment');
|
|
279
|
+
*
|
|
280
|
+
* // Inspect what's registered
|
|
281
|
+
* const active = session.tools.getAll();
|
|
282
|
+
* console.log(active.map(t => t.name));
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @since 1.4.0
|
|
77
286
|
*/
|
|
78
|
-
|
|
287
|
+
get tools(): ToolRegistry;
|
|
79
288
|
/**
|
|
80
|
-
* Returns the `
|
|
289
|
+
* Returns the `SkillInjector` for runtime skill management.
|
|
290
|
+
*
|
|
291
|
+
* Use this to enable or disable dynamic skills after session construction:
|
|
292
|
+
*
|
|
293
|
+
* ```typescript
|
|
294
|
+
* session.skills.enableSkill('code-review');
|
|
295
|
+
* session.skills.enableByTags(['debugging']);
|
|
296
|
+
* session.skills.disableSkill('verbose-mode');
|
|
297
|
+
* const requiredTools = session.skills.getRequiredTools();
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
300
|
+
* @since 1.4.0
|
|
81
301
|
*/
|
|
82
|
-
|
|
302
|
+
get skills(): SkillInjector;
|
|
303
|
+
/**
|
|
304
|
+
* Sets an explicit multi-step continuation plan that will be tracked and
|
|
305
|
+
* injected as a status block before each ReAct iteration.
|
|
306
|
+
*
|
|
307
|
+
* Dependency tracking, condition evaluation, `outputKey` storage, and
|
|
308
|
+
* `inputMapping` resolution are all handled automatically by the planner.
|
|
309
|
+
*
|
|
310
|
+
* @param steps - The ordered list of continuation steps.
|
|
311
|
+
* @param strategy - Execution strategy ('sequential' | 'parallel' | 'conditional'). Default: 'sequential'.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* await session.setPlan([
|
|
316
|
+
* { stepId: 'fetch', toolName: 'fetch_data', description: 'Get data', dependsOn: [], outputKey: 'rawData' },
|
|
317
|
+
* { stepId: 'analyze', toolName: 'analyze', description: 'Analyze', dependsOn: ['fetch'], inputMapping: { data: 'rawData' } },
|
|
318
|
+
* ]);
|
|
319
|
+
* const result = await session.run('Run the data pipeline.');
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
setPlan(steps: ContinuationStep[], strategy?: ContinuationPlan['strategy']): void;
|
|
323
|
+
/**
|
|
324
|
+
* Manually sets the agent's goal, bypassing the automatic mini-planning LLM call.
|
|
325
|
+
*
|
|
326
|
+
* Use this when you already know the goal structure upfront.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```typescript
|
|
330
|
+
* await session.setGoal({
|
|
331
|
+
* statement: 'Audit the authentication module',
|
|
332
|
+
* decomposition: ['Read src/auth/', 'Identify SQL injection risks', 'Write report'],
|
|
333
|
+
* successCriteria: ['Report covers all audit areas', 'Each finding has a severity rating'],
|
|
334
|
+
* });
|
|
335
|
+
* const result = await session.run('Begin the security audit.');
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
setGoal(goal: Omit<Goal, 'id' | 'injectionFrequency' | 'injectionPosition'>): void;
|
|
83
339
|
/**
|
|
84
340
|
* Connects all configured MCP servers and registers their bridged tools.
|
|
85
341
|
* Called from the constructor as a fire-and-start async task; `run()` and
|
|
86
342
|
* `stream()` await `this.mcpReady` before executing.
|
|
87
343
|
*/
|
|
88
344
|
private _initMCP;
|
|
345
|
+
/**
|
|
346
|
+
* Runs a dedicated planning prompt against the LLM to decompose the user's
|
|
347
|
+
* message into sub-goals and success criteria. Called once at the start of
|
|
348
|
+
* the first `run()` when `enableGoalPlanning` is true and no goal has been
|
|
349
|
+
* manually set via `setGoal()`.
|
|
350
|
+
*/
|
|
351
|
+
private _runMiniPlanningStep;
|
|
89
352
|
/** Builds the system prompt, injecting skills and goal if configured. */
|
|
90
353
|
private buildSystemPrompt;
|
|
91
|
-
/** Builds the messages array for the provider from the current context */
|
|
354
|
+
/** Builds the messages array for the provider from the current context. */
|
|
92
355
|
private buildMessages;
|
|
93
|
-
/** Checks the tool execution budget and throws descriptively if exceeded */
|
|
356
|
+
/** Checks the tool execution budget and throws descriptively if exceeded. */
|
|
94
357
|
private checkExecutionBudget;
|
|
95
|
-
/** Records a tool call in budget counters */
|
|
358
|
+
/** Records a tool call in budget counters. */
|
|
96
359
|
private recordToolCall;
|
|
360
|
+
private isProbablyBase64;
|
|
361
|
+
private isBinaryLike;
|
|
362
|
+
private storeBlob;
|
|
363
|
+
private scrubBlobFields;
|
|
97
364
|
/**
|
|
98
365
|
* Processes a firewall decision for a tool call.
|
|
99
366
|
* Returns true to proceed, false to block.
|
|
@@ -101,11 +368,15 @@ declare class SessionManager {
|
|
|
101
368
|
private passesFirewall;
|
|
102
369
|
/**
|
|
103
370
|
* Executes a single parsed tool call and returns the serialised result string.
|
|
371
|
+
* Also handles continuation plan tracking (step status + output storage).
|
|
104
372
|
*/
|
|
105
373
|
private executeSingleToolCall;
|
|
106
374
|
/**
|
|
107
375
|
* Runs the full ReAct loop for a user message and returns the final assistant response.
|
|
108
376
|
*
|
|
377
|
+
* When `enableGoalPlanning` is true and no goal has been manually set, a mini-planning
|
|
378
|
+
* LLM call is made before the first iteration to decompose the task into sub-goals.
|
|
379
|
+
*
|
|
109
380
|
* @param userMessage - The user's message (string or multimodal content blocks)
|
|
110
381
|
* @returns The assistant's final response string
|
|
111
382
|
* @throws {LemuraMaxIterationsError} When the loop exceeds `maxIterations`
|
|
@@ -121,78 +392,83 @@ declare class SessionManager {
|
|
|
121
392
|
* @returns An `AsyncIterable<string>` of delta tokens from the final response
|
|
122
393
|
*
|
|
123
394
|
* @example
|
|
395
|
+
* ```typescript
|
|
124
396
|
* for await (const token of session.stream('Tell me a story')) {
|
|
125
397
|
* process.stdout.write(token);
|
|
126
398
|
* }
|
|
399
|
+
* ```
|
|
127
400
|
*/
|
|
128
401
|
stream(userMessage: string | ContentBlock[]): AsyncIterable<string>;
|
|
129
402
|
/**
|
|
130
403
|
* Resets the session: clears conversation history, resets iteration counters,
|
|
131
|
-
*
|
|
404
|
+
* tool execution budget tallies, and goal/plan state.
|
|
405
|
+
* The adapter, config, compression strategies, and tools are retained.
|
|
132
406
|
*/
|
|
133
407
|
reset(): void;
|
|
134
408
|
/**
|
|
135
409
|
* Closes the session and disconnects all MCP servers.
|
|
136
410
|
*
|
|
137
|
-
* Call this when you are done with the session
|
|
138
|
-
*
|
|
411
|
+
* Call this when you are done with the session to ensure child processes are
|
|
412
|
+
* terminated and HTTP connections are released.
|
|
139
413
|
*
|
|
140
414
|
* @example
|
|
415
|
+
* ```typescript
|
|
141
416
|
* const session = new SessionManager({ ..., mcpServers: [...] });
|
|
142
417
|
* try {
|
|
143
418
|
* await session.run('Hello');
|
|
144
419
|
* } finally {
|
|
145
420
|
* await session.close();
|
|
146
421
|
* }
|
|
422
|
+
* ```
|
|
147
423
|
*/
|
|
148
424
|
close(): Promise<void>;
|
|
149
425
|
}
|
|
150
426
|
|
|
151
427
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
428
|
+
* Configuration for `ToolResponseProcessor`.
|
|
429
|
+
*
|
|
430
|
+
* Token thresholds define the boundaries between size classes.
|
|
431
|
+
* `budgetPercent` caps the combined token spend of all tool results per iteration.
|
|
432
|
+
*/
|
|
433
|
+
interface ToolResponseProcessorConfig {
|
|
434
|
+
/** Max tokens for a `small` response. Responses at or below this are verbatim. Default: 200 */
|
|
435
|
+
smallMaxTokens?: number;
|
|
436
|
+
/** Max tokens for a `medium` response. Responses at or below this are verbatim. Default: 800 */
|
|
437
|
+
mediumMaxTokens?: number;
|
|
438
|
+
/** Max tokens for a `large` response. Above this threshold → `oversized`. Default: 2000 */
|
|
439
|
+
largeMaxTokens?: number;
|
|
440
|
+
/**
|
|
441
|
+
* Cap total tool-response tokens per iteration as a fraction of session `maxTokens`.
|
|
442
|
+
* E.g. `0.15` means all tool results combined must fit within 15% of the context window.
|
|
443
|
+
* Not enforced by the processor itself — SessionManager uses this to decide when to
|
|
444
|
+
* apply extra compression after all tool results are collected. Default: undefined (no cap).
|
|
445
|
+
*/
|
|
446
|
+
budgetPercent?: number;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Evaluates and compresses tool response strings before they are appended to the
|
|
450
|
+
* context window, preventing large tool outputs from flooding the token budget.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```typescript
|
|
454
|
+
* toolResponseProcessor: new ToolResponseProcessor({
|
|
455
|
+
* smallMaxTokens: 200,
|
|
456
|
+
* mediumMaxTokens: 800,
|
|
457
|
+
* largeMaxTokens: 2000,
|
|
458
|
+
* budgetPercent: 0.15,
|
|
459
|
+
* })
|
|
460
|
+
* ```
|
|
155
461
|
*/
|
|
156
462
|
declare class ToolResponseProcessor implements IToolResponseProcessor {
|
|
463
|
+
private readonly smallMax;
|
|
464
|
+
private readonly mediumMax;
|
|
465
|
+
private readonly largeMax;
|
|
466
|
+
readonly budgetPercent: number | undefined;
|
|
467
|
+
constructor(config?: ToolResponseProcessorConfig);
|
|
157
468
|
evaluate(response: string, tool: IToolDefinition, context: unknown): ToolResponseEvaluation;
|
|
158
469
|
compress(response: string, evaluation: ToolResponseEvaluation): string;
|
|
159
470
|
}
|
|
160
471
|
|
|
161
|
-
interface Goal {
|
|
162
|
-
id: string;
|
|
163
|
-
statement: string;
|
|
164
|
-
decomposition: string[];
|
|
165
|
-
successCriteria: string[];
|
|
166
|
-
injectionFrequency: 'always' | 'every_N_turns' | 'on_compression';
|
|
167
|
-
injectionPosition: 'system_prompt' | 'pre_turn';
|
|
168
|
-
}
|
|
169
|
-
declare class GoalInjector {
|
|
170
|
-
private goal;
|
|
171
|
-
constructor(goal: Goal);
|
|
172
|
-
injectInto(prompt: string): string;
|
|
173
|
-
getGoal(): Goal;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
interface ContinuationStep {
|
|
177
|
-
stepId: string;
|
|
178
|
-
toolName: string;
|
|
179
|
-
description: string;
|
|
180
|
-
dependsOn: string[];
|
|
181
|
-
status: 'pending' | 'running' | 'done' | 'failed' | 'skipped';
|
|
182
|
-
outputKey?: string;
|
|
183
|
-
inputMapping?: Record<string, string>;
|
|
184
|
-
}
|
|
185
|
-
interface ContinuationPlan {
|
|
186
|
-
steps: ContinuationStep[];
|
|
187
|
-
currentStepIndex: number;
|
|
188
|
-
strategy: 'sequential' | 'parallel' | 'conditional';
|
|
189
|
-
}
|
|
190
|
-
declare class ContinuationPlanner {
|
|
191
|
-
private plan;
|
|
192
|
-
constructor(plan: ContinuationPlan);
|
|
193
|
-
getPlanStatusString(): string;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
472
|
declare class StepCounter {
|
|
197
473
|
private maxSteps;
|
|
198
474
|
private toolCallCount;
|
|
@@ -336,4 +612,4 @@ declare class MCPClientRegistry {
|
|
|
336
612
|
private _bridge;
|
|
337
613
|
}
|
|
338
614
|
|
|
339
|
-
export { AudioChunk, ContentBlock, ContextWindow, type ContinuationPlan, ContinuationPlanner, type ContinuationStep, FinalResponseFormatter, type Goal, GoalInjector, ILogger, IProviderAdapter, IToolDefinition, IToolResponseProcessor, ImageGenRequest, ImageGenResponse, MCPClient, MCPClientRegistry, MCPServerConfig, MCPToolDefinition, MediaBridge, ModelInfo, SessionConfig, SessionManager, StepCounter, SynthesisRequest, ToolResponseEvaluation, ToolResponseProcessor, TranscriptionRequest, TranscriptionResponse, Turn, VisionRequest, VisionResponse };
|
|
615
|
+
export { AudioChunk, ContentBlock, ContextWindow, type ContinuationPlan, ContinuationPlanner, type ContinuationStep, FinalResponseFormatter, type Goal, GoalInjector, ILogger, IProviderAdapter, IToolDefinition, IToolResponseProcessor, ImageGenRequest, ImageGenResponse, MCPClient, MCPClientRegistry, MCPServerConfig, MCPToolDefinition, MediaBridge, ModelInfo, SessionConfig, SessionManager, SkillInjector, type StepCondition, StepCounter, SynthesisRequest, ToolRegistry, ToolResponseEvaluation, ToolResponseProcessor, type ToolResponseProcessorConfig, TranscriptionRequest, TranscriptionResponse, Turn, VisionRequest, VisionResponse };
|