hammer-ai 0.2.11 → 0.2.13
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/dist/index.d.ts +17 -5
- package/dist/index.js +18 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -875,8 +875,6 @@ interface MemoryLayerConfig {
|
|
|
875
875
|
protectedContextTokens: number;
|
|
876
876
|
/** Maximum tokens for the rendered compressed state. */
|
|
877
877
|
stateBudgetTokens: number;
|
|
878
|
-
/** Hard cap on raw history entries (safety net). */
|
|
879
|
-
maxRawHistory: number;
|
|
880
878
|
/** Minimum turns between compaction attempts. */
|
|
881
879
|
compactionDebounceTurns: number;
|
|
882
880
|
/** Baseline token overhead for system prompt (conservative estimate). */
|
|
@@ -899,7 +897,7 @@ interface MemoryLayerConfig {
|
|
|
899
897
|
* - State rendering (converting TState to human-readable text)
|
|
900
898
|
*
|
|
901
899
|
* The base class provides:
|
|
902
|
-
* - Append-only raw history
|
|
900
|
+
* - Append-only raw history
|
|
903
901
|
* - Token-budgeted sliding window for recent messages
|
|
904
902
|
* - buildMessages assembly (system → state → recent)
|
|
905
903
|
* - Compaction triggering (debounce, threshold check, prune)
|
|
@@ -1152,8 +1150,6 @@ interface AgentMemoryLayerConfig {
|
|
|
1152
1150
|
protectedContextTokens: number;
|
|
1153
1151
|
/** Token budget for the rendered compressed state block. */
|
|
1154
1152
|
stateBudgetTokens: number;
|
|
1155
|
-
/** Hard cap on raw history entries. */
|
|
1156
|
-
maxRawHistory: number;
|
|
1157
1153
|
/** Minimum turns between compaction attempts. */
|
|
1158
1154
|
compactionDebounceTurns: number;
|
|
1159
1155
|
/** Token estimate for the system prompt. */
|
|
@@ -2259,6 +2255,13 @@ interface SubAgentToolOptions {
|
|
|
2259
2255
|
maxSteps?: number;
|
|
2260
2256
|
/** Temperature for LLM calls. Defaults to LLMClient's built-in default (0.2). */
|
|
2261
2257
|
temperature?: number;
|
|
2258
|
+
/**
|
|
2259
|
+
* Whether `execute()` awaits the sub-agent loop before returning.
|
|
2260
|
+
* - `true` (default): the parent agent blocks until the sub-agent finishes.
|
|
2261
|
+
* - `false`: the loop is fired in the background and `execute()` returns
|
|
2262
|
+
* immediately. Override `onSubAgentDispatched()` to track the promise.
|
|
2263
|
+
*/
|
|
2264
|
+
blocking?: boolean;
|
|
2262
2265
|
}
|
|
2263
2266
|
/**
|
|
2264
2267
|
* A Tool that runs its own contained agentic loop.
|
|
@@ -2295,6 +2298,15 @@ declare abstract class SubAgentTool extends Tool {
|
|
|
2295
2298
|
* Override when `getSchema()` adds parameters beyond `task`.
|
|
2296
2299
|
*/
|
|
2297
2300
|
protected buildSubAgentTask(params: Record<string, any>): string;
|
|
2301
|
+
/**
|
|
2302
|
+
* Called when `blocking` is `false`, right after the sub-agent loop is
|
|
2303
|
+
* dispatched in the background. Override to track the promise (e.g. for
|
|
2304
|
+
* pending-generation registries) and return a custom immediate result.
|
|
2305
|
+
*
|
|
2306
|
+
* @param params The raw parameters passed to `execute()`.
|
|
2307
|
+
* @param promise Settles when the background sub-agent loop completes.
|
|
2308
|
+
*/
|
|
2309
|
+
protected onSubAgentDispatched(_params: Record<string, any>, _promise: Promise<void>): ToolResult;
|
|
2298
2310
|
execute(params: Record<string, any>): Promise<ToolResult>;
|
|
2299
2311
|
protected runSubAgentLoop(task: string): Promise<ToolResult>;
|
|
2300
2312
|
}
|
package/dist/index.js
CHANGED
|
@@ -4154,14 +4154,6 @@ var BaseMemoryLayer = class {
|
|
|
4154
4154
|
const timestamp = Date.now();
|
|
4155
4155
|
const msg = this.createMessage(id, role, content, this.currentTurn, timestamp);
|
|
4156
4156
|
this.rawHistory.push(msg);
|
|
4157
|
-
if (this.rawHistory.length > this.config.maxRawHistory) {
|
|
4158
|
-
const excess = this.rawHistory.length - this.config.maxRawHistory;
|
|
4159
|
-
const lastPrunedTurn = this.rawHistory[excess - 1].turn;
|
|
4160
|
-
this.rawHistory.splice(0, excess);
|
|
4161
|
-
if (this.compactionCursor.lastCompactedTurn < lastPrunedTurn) {
|
|
4162
|
-
this.compactionCursor.lastCompactedTurn = lastPrunedTurn;
|
|
4163
|
-
}
|
|
4164
|
-
}
|
|
4165
4157
|
this.onMessageAppended(msg);
|
|
4166
4158
|
return id;
|
|
4167
4159
|
}
|
|
@@ -5227,7 +5219,6 @@ var AgentMemoryLayer = class extends BaseMemoryLayer {
|
|
|
5227
5219
|
compactionTokenThreshold: config.compactionTokenThreshold,
|
|
5228
5220
|
protectedContextTokens: config.protectedContextTokens,
|
|
5229
5221
|
stateBudgetTokens: config.stateBudgetTokens,
|
|
5230
|
-
maxRawHistory: config.maxRawHistory,
|
|
5231
5222
|
compactionDebounceTurns: config.compactionDebounceTurns,
|
|
5232
5223
|
systemPromptOverhead: config.systemPromptOverhead,
|
|
5233
5224
|
tokenEstimator: config.tokenEstimator,
|
|
@@ -5734,7 +5725,6 @@ var SHARED_WORKSPACE_AGENT_MEMORY_PRESET = {
|
|
|
5734
5725
|
// 60_000
|
|
5735
5726
|
stateBudgetTokens: Math.floor(DEFAULT_MAX_CONTEXT_TOKENS * 0.05),
|
|
5736
5727
|
// 10_000
|
|
5737
|
-
maxRawHistory: 2e3,
|
|
5738
5728
|
compactionDebounceTurns: 3,
|
|
5739
5729
|
systemPromptOverhead: 4e3,
|
|
5740
5730
|
toolMemoryExtractor: DEFAULT_TOOL_MEMORY_EXTRACTOR
|
|
@@ -5744,7 +5734,6 @@ function createAgentMemoryLayer(_preset, overrides) {
|
|
|
5744
5734
|
compactionTokenThreshold: SHARED_WORKSPACE_AGENT_MEMORY_PRESET.compactionTokenThreshold,
|
|
5745
5735
|
protectedContextTokens: SHARED_WORKSPACE_AGENT_MEMORY_PRESET.protectedContextTokens,
|
|
5746
5736
|
stateBudgetTokens: SHARED_WORKSPACE_AGENT_MEMORY_PRESET.stateBudgetTokens,
|
|
5747
|
-
maxRawHistory: SHARED_WORKSPACE_AGENT_MEMORY_PRESET.maxRawHistory,
|
|
5748
5737
|
compactionDebounceTurns: SHARED_WORKSPACE_AGENT_MEMORY_PRESET.compactionDebounceTurns,
|
|
5749
5738
|
systemPromptOverhead: SHARED_WORKSPACE_AGENT_MEMORY_PRESET.systemPromptOverhead,
|
|
5750
5739
|
tokenEstimator: overrides?.tokenEstimator ?? new CharTokenEstimator(),
|
|
@@ -7195,10 +7184,28 @@ var SubAgentTool = class extends Tool {
|
|
|
7195
7184
|
buildSubAgentTask(params) {
|
|
7196
7185
|
return typeof params.task === "string" ? params.task.trim() : "";
|
|
7197
7186
|
}
|
|
7187
|
+
// ---- non-blocking hook ------------------------------------------------
|
|
7188
|
+
/**
|
|
7189
|
+
* Called when `blocking` is `false`, right after the sub-agent loop is
|
|
7190
|
+
* dispatched in the background. Override to track the promise (e.g. for
|
|
7191
|
+
* pending-generation registries) and return a custom immediate result.
|
|
7192
|
+
*
|
|
7193
|
+
* @param params The raw parameters passed to `execute()`.
|
|
7194
|
+
* @param promise Settles when the background sub-agent loop completes.
|
|
7195
|
+
*/
|
|
7196
|
+
onSubAgentDispatched(_params, _promise) {
|
|
7197
|
+
return { success: true, pending: true, message: "Sub-agent started in background." };
|
|
7198
|
+
}
|
|
7198
7199
|
// ---- execute ---------------------------------------------------------
|
|
7199
7200
|
async execute(params) {
|
|
7200
7201
|
const task = this.buildSubAgentTask(params);
|
|
7201
7202
|
if (!task) return { success: false, error: "task is required" };
|
|
7203
|
+
if (this.subAgentOptions.blocking === false) {
|
|
7204
|
+
const promise = this.runSubAgentLoop(task).then(() => {
|
|
7205
|
+
}).catch(() => {
|
|
7206
|
+
});
|
|
7207
|
+
return this.onSubAgentDispatched(params, promise);
|
|
7208
|
+
}
|
|
7202
7209
|
return this.runSubAgentLoop(task);
|
|
7203
7210
|
}
|
|
7204
7211
|
// ---- core loop -------------------------------------------------------
|