repoburg 1.3.69 → 1.3.71
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/backend/.env +2 -2
- package/backend/.eslintrc.js +5 -0
- package/backend/dist/src/application-state/application-state.controller.d.ts +5 -0
- package/backend/dist/src/application-state/application-state.controller.js +22 -0
- package/backend/dist/src/application-state/application-state.controller.js.map +1 -1
- package/backend/dist/src/application-state/application-state.service.d.ts +2 -0
- package/backend/dist/src/application-state/application-state.service.js +11 -0
- package/backend/dist/src/application-state/application-state.service.js.map +1 -1
- package/backend/dist/src/application-state/dto/set-history-compression-enabled.dto.d.ts +3 -0
- package/backend/dist/src/application-state/dto/set-history-compression-enabled.dto.js +21 -0
- package/backend/dist/src/application-state/dto/set-history-compression-enabled.dto.js.map +1 -0
- package/backend/dist/src/core-entities/ai-action.entity.d.ts +1 -0
- package/backend/dist/src/core-entities/ai-action.entity.js +4 -0
- package/backend/dist/src/core-entities/ai-action.entity.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.module.js +2 -1
- package/backend/dist/src/interactive-chat/chat.module.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.service.d.ts +5 -1
- package/backend/dist/src/interactive-chat/chat.service.js +42 -4
- package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/apply-diff.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/apply-diff.handler.js +14 -11
- package/backend/dist/src/llm-orchestration/action-handlers/apply-diff.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/create-file.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/create-file.handler.js +15 -10
- package/backend/dist/src/llm-orchestration/action-handlers/create-file.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/delete-file.handler.js +15 -2
- package/backend/dist/src/llm-orchestration/action-handlers/delete-file.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/execute-code.handler.js +8 -3
- package/backend/dist/src/llm-orchestration/action-handlers/execute-code.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/final.handler.js +8 -2
- package/backend/dist/src/llm-orchestration/action-handlers/final.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/get-session-history.handler.js +0 -5
- package/backend/dist/src/llm-orchestration/action-handlers/get-session-history.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js +41 -16
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/list-sub-agents.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/list-sub-agents.handler.js +1 -7
- package/backend/dist/src/llm-orchestration/action-handlers/list-sub-agents.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/new-session.handler.d.ts +2 -2
- package/backend/dist/src/llm-orchestration/action-handlers/new-session.handler.js +10 -10
- package/backend/dist/src/llm-orchestration/action-handlers/new-session.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/overwrite-file.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/overwrite-file.handler.js +13 -7
- package/backend/dist/src/llm-orchestration/action-handlers/overwrite-file.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/patch.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/patch.handler.js +19 -15
- package/backend/dist/src/llm-orchestration/action-handlers/patch.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/quick-edit.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/quick-edit.handler.js +16 -19
- package/backend/dist/src/llm-orchestration/action-handlers/quick-edit.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/request-context.handler.d.ts +8 -2
- package/backend/dist/src/llm-orchestration/action-handlers/request-context.handler.js +75 -17
- package/backend/dist/src/llm-orchestration/action-handlers/request-context.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.d.ts +4 -1
- package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.js +34 -10
- package/backend/dist/src/llm-orchestration/action-handlers/run-command.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/use-mcp-tool.handler.d.ts +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/use-mcp-tool.handler.js +8 -7
- package/backend/dist/src/llm-orchestration/action-handlers/use-mcp-tool.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/write-todo.handler.js +11 -2
- package/backend/dist/src/llm-orchestration/action-handlers/write-todo.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/history-compression.service.d.ts +12 -0
- package/backend/dist/src/llm-orchestration/history-compression.service.js +128 -0
- package/backend/dist/src/llm-orchestration/history-compression.service.js.map +1 -0
- package/backend/dist/src/llm-orchestration/hooks/follow-up-post-execution.hook.d.ts +1 -16
- package/backend/dist/src/llm-orchestration/hooks/follow-up-post-execution.hook.js +14 -155
- package/backend/dist/src/llm-orchestration/hooks/follow-up-post-execution.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/hooks/invalid-tool-feedback.hook.js +14 -0
- package/backend/dist/src/llm-orchestration/hooks/invalid-tool-feedback.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/hooks/yolo-mode-post-execution.hook.js +4 -2
- package/backend/dist/src/llm-orchestration/hooks/yolo-mode-post-execution.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.d.ts +0 -28
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js +0 -11
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-orchestration.module.js +5 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.module.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +20 -25
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
- package/backend/dist/src/llm-provider/alibaba-llm.provider.js +17 -8
- package/backend/dist/src/llm-provider/alibaba-llm.provider.js.map +1 -1
- package/backend/dist/src/llm-provider/llm-provider.interface.d.ts +1 -1
- package/backend/dist/src/llm-provider/openrouter-llm.provider.js +7 -0
- package/backend/dist/src/llm-provider/openrouter-llm.provider.js.map +1 -1
- package/backend/dist/src/llm-provider/zai-llm.provider.js +7 -0
- package/backend/dist/src/llm-provider/zai-llm.provider.js.map +1 -1
- package/backend/dist/src/seeding/data/tool-hooks/eslint-hook.d.ts +1 -1
- package/backend/dist/src/seeding/data/tool-hooks/eslint-hook.js +23 -10
- package/backend/dist/src/seeding/data/tool-hooks/eslint-hook.js.map +1 -1
- package/backend/dist/src/session-inputs/dto/session-input.dto.d.ts +1 -0
- package/backend/dist/src/session-inputs/dto/session-input.dto.js +5 -0
- package/backend/dist/src/session-inputs/dto/session-input.dto.js.map +1 -1
- package/backend/dist/src/session-inputs/session-inputs.service.d.ts +1 -1
- package/backend/dist/src/session-inputs/session-inputs.service.js +10 -0
- package/backend/dist/src/session-inputs/session-inputs.service.js.map +1 -1
- package/backend/dist/src/tool-hooks/tool-hooks.service.js +0 -5
- package/backend/dist/src/tool-hooks/tool-hooks.service.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
var RunCommandHandler_1;
|
|
9
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
13
|
exports.RunCommandHandler = void 0;
|
|
@@ -14,13 +17,15 @@ const util_1 = require("util");
|
|
|
14
17
|
const run_command_args_dto_1 = require("./dto/run-command.args.dto");
|
|
15
18
|
const class_transformer_1 = require("class-transformer");
|
|
16
19
|
const class_validator_1 = require("class-validator");
|
|
17
|
-
const handler_validation_error_1 = require("../errors/handler-validation.error");
|
|
18
20
|
const utils_1 = require("../../utils");
|
|
19
21
|
const fs = require("fs/promises");
|
|
20
22
|
const path = require("path");
|
|
23
|
+
const application_state_service_1 = require("../../application-state/application-state.service");
|
|
24
|
+
const gpt_tokenizer_1 = require("gpt-tokenizer");
|
|
21
25
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
22
26
|
let RunCommandHandler = RunCommandHandler_1 = class RunCommandHandler {
|
|
23
|
-
constructor() {
|
|
27
|
+
constructor(applicationStateService) {
|
|
28
|
+
this.applicationStateService = applicationStateService;
|
|
24
29
|
this.toolName = 'run_command';
|
|
25
30
|
this.logger = new common_1.Logger(RunCommandHandler_1.name);
|
|
26
31
|
this.projectRoot = process.env.REPOBURG_PROJECT_PATH || process.cwd();
|
|
@@ -86,14 +91,20 @@ let RunCommandHandler = RunCommandHandler_1 = class RunCommandHandler {
|
|
|
86
91
|
`;
|
|
87
92
|
return `\n${definition.trim()}\n`;
|
|
88
93
|
}
|
|
89
|
-
async execute(args,
|
|
94
|
+
async execute(args, _context) {
|
|
90
95
|
const validatedArgs = (0, class_transformer_1.plainToClass)(run_command_args_dto_1.RunCommandArgsDto, args);
|
|
91
96
|
const errors = await (0, class_validator_1.validate)(validatedArgs);
|
|
92
97
|
if (errors.length > 0) {
|
|
93
98
|
const errorMessages = errors
|
|
94
99
|
.map((err) => Object.values(err.constraints || {}).join(', '))
|
|
95
100
|
.join('; ');
|
|
96
|
-
|
|
101
|
+
return {
|
|
102
|
+
status: 'FAILURE',
|
|
103
|
+
summary: `Invalid arguments for ${this.toolName}.`,
|
|
104
|
+
error_message: errorMessages,
|
|
105
|
+
persisted_args: args,
|
|
106
|
+
execution_log: { output: '', error_message: errorMessages },
|
|
107
|
+
};
|
|
97
108
|
}
|
|
98
109
|
const { command_string } = validatedArgs;
|
|
99
110
|
let unifiedOutput;
|
|
@@ -131,21 +142,34 @@ ${command_string}
|
|
|
131
142
|
.unlink(scriptPath)
|
|
132
143
|
.catch((err) => this.logger.warn(`Failed to cleanup temp file ${scriptPath}: ${err.message}`));
|
|
133
144
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
const tokenCount = (0, gpt_tokenizer_1.countTokens)(unifiedOutput);
|
|
146
|
+
const tokenLimit = await this.applicationStateService.getFollowupTokenLimit();
|
|
147
|
+
if (tokenCount > tokenLimit) {
|
|
148
|
+
const ratio = tokenLimit / tokenCount;
|
|
149
|
+
const truncatedLength = Math.floor(unifiedOutput.length * ratio);
|
|
150
|
+
const truncatedOutput = unifiedOutput.slice(0, truncatedLength);
|
|
151
|
+
const truncationWarning = `\n\n[OUTPUT TRUNCATED: ${tokenCount} tokens exceeds limit of ${tokenLimit}. Consider redirecting large outputs to a file and using request_context to read it.]`;
|
|
152
|
+
unifiedOutput = truncatedOutput + truncationWarning;
|
|
153
|
+
errorMessage =
|
|
154
|
+
(errorMessage || '') +
|
|
155
|
+
`Output truncated due to size limit (${tokenCount} > ${tokenLimit} tokens).`;
|
|
156
|
+
this.logger.warn(`Command output truncated: ${tokenCount} tokens exceeds limit of ${tokenLimit}`);
|
|
157
|
+
}
|
|
138
158
|
return {
|
|
139
159
|
status,
|
|
140
160
|
summary: `${summary} Output captured.`,
|
|
141
161
|
persisted_args: { command_string },
|
|
142
162
|
error_message: errorMessage,
|
|
143
|
-
execution_log: {
|
|
163
|
+
execution_log: {
|
|
164
|
+
output: unifiedOutput,
|
|
165
|
+
error_message: errorMessage || '',
|
|
166
|
+
},
|
|
144
167
|
};
|
|
145
168
|
}
|
|
146
169
|
};
|
|
147
170
|
exports.RunCommandHandler = RunCommandHandler;
|
|
148
171
|
exports.RunCommandHandler = RunCommandHandler = RunCommandHandler_1 = __decorate([
|
|
149
|
-
(0, common_1.Injectable)()
|
|
172
|
+
(0, common_1.Injectable)(),
|
|
173
|
+
__metadata("design:paramtypes", [application_state_service_1.ApplicationStateService])
|
|
150
174
|
], RunCommandHandler);
|
|
151
175
|
//# sourceMappingURL=run-command.handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-command.handler.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/action-handlers/run-command.handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-command.handler.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/action-handlers/run-command.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AAOpD,iDAAqC;AACrC,+BAAiC;AACjC,qEAA+D;AAC/D,yDAAiD;AACjD,qDAA2C;AAE3C,uCAAqE;AACrE,kCAAkC;AAClC,6BAA6B;AAC7B,iGAA4F;AAC5F,iDAA4C;AAE5C,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAG3B,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAW5B,YACmB,uBAAgD;QAAhD,4BAAuB,GAAvB,uBAAuB,CAAyB;QAX1D,aAAQ,GAAG,aAAa,CAAC;QACjB,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;QAC5C,gBAAW,GAC1B,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACpC,YAAO,GAAW,IAAI,CAAC,IAAI,CAC1C,IAAI,CAAC,WAAW,EAChB,WAAW,EACX,MAAM,CACP,CAAC;IAIC,CAAC;IAEJ,WAAW;QACT,OAAO;YACL,IAAI,EAAE,IAA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,2BAAW,EAAC,aAAa,CAAC,CAAC;QAC9C,MAAM,UAAU,GACd,MAAM,IAAI,CAAC,uBAAuB,CAAC,qBAAqB,EAAE,CAAC;QAE7D,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;YAE5B,MAAM,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;YACtC,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;YACjE,MAAM,eAAe,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;YAEhE,MAAM,iBAAiB,GAAG,0BAA0B,UAAU,4BAA4B,UAAU,uFAAuF,CAAC;YAE5L,aAAa,GAAG,eAAe,GAAG,iBAAiB,CAAC;YACpD,YAAY;gBACV,CAAC,YAAY,IAAI,EAAE,CAAC;oBACpB,uCAAuC,UAAU,MAAM,UAAU,WAAW,CAAC;YAE/E,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,6BAA6B,UAAU,4BAA4B,UAAU,EAAE,CAChF,CAAC;QACJ,CAAC;QAED,OAAO;YACL,MAAM;YACN,OAAO,EAAE,GAAG,OAAO,mBAAmB;YACtC,cAAc,EAAE,EAAE,cAAc,EAAE;YAClC,aAAa,EAAE,YAAY;YAC3B,aAAa,EAAE;gBACb,MAAM,EAAE,aAAa;gBACrB,aAAa,EAAE,YAAY,IAAI,EAAE;aAClC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAlNY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAaiC,mDAAuB;GAZxD,iBAAiB,CAkN7B"}
|
|
@@ -11,5 +11,5 @@ export declare class UseMcpToolHandler implements ActionHandler {
|
|
|
11
11
|
getDefinition(useJsonFormat?: boolean): string;
|
|
12
12
|
execute(args: {
|
|
13
13
|
[key: string]: any;
|
|
14
|
-
},
|
|
14
|
+
}, _context: PlanExecutionContext): Promise<ActionExecutionResult>;
|
|
15
15
|
}
|
|
@@ -16,7 +16,6 @@ const mcp_service_1 = require("../../mcp/mcp.service");
|
|
|
16
16
|
const use_mcp_tool_args_dto_1 = require("./dto/use-mcp-tool.args.dto");
|
|
17
17
|
const class_transformer_1 = require("class-transformer");
|
|
18
18
|
const class_validator_1 = require("class-validator");
|
|
19
|
-
const handler_validation_error_1 = require("../errors/handler-validation.error");
|
|
20
19
|
const utils_1 = require("../../utils");
|
|
21
20
|
let UseMcpToolHandler = UseMcpToolHandler_1 = class UseMcpToolHandler {
|
|
22
21
|
constructor(mcpService) {
|
|
@@ -83,22 +82,24 @@ let UseMcpToolHandler = UseMcpToolHandler_1 = class UseMcpToolHandler {
|
|
|
83
82
|
`;
|
|
84
83
|
return definition.trim();
|
|
85
84
|
}
|
|
86
|
-
async execute(args,
|
|
85
|
+
async execute(args, _context) {
|
|
87
86
|
const validatedArgs = (0, class_transformer_1.plainToClass)(use_mcp_tool_args_dto_1.UseMcpToolArgsDto, args);
|
|
88
87
|
const errors = await (0, class_validator_1.validate)(validatedArgs);
|
|
89
88
|
if (errors.length > 0) {
|
|
90
89
|
const errorMessages = errors
|
|
91
90
|
.map((err) => Object.values(err.constraints || {}).join(', '))
|
|
92
91
|
.join('; ');
|
|
93
|
-
|
|
92
|
+
return {
|
|
93
|
+
status: 'FAILURE',
|
|
94
|
+
summary: `Invalid arguments for ${this.toolName}.`,
|
|
95
|
+
error_message: errorMessages,
|
|
96
|
+
persisted_args: args,
|
|
97
|
+
execution_log: { output: '', error_message: errorMessages },
|
|
98
|
+
};
|
|
94
99
|
}
|
|
95
100
|
const { server_name, mcp_tool_name, arguments: tool_args } = validatedArgs;
|
|
96
101
|
const { stdout, stderr } = await this.mcpService.executeMcpTool(server_name, mcp_tool_name, tool_args);
|
|
97
102
|
const unifiedOutput = stdout || stderr || '(Tool produced no output)';
|
|
98
|
-
context.outputs.mcp_tools.push({
|
|
99
|
-
tool_name: `${server_name}.${mcp_tool_name}`,
|
|
100
|
-
output: unifiedOutput,
|
|
101
|
-
});
|
|
102
103
|
return {
|
|
103
104
|
status: 'SUCCESS',
|
|
104
105
|
summary: `MCP tool "${server_name}.${mcp_tool_name}" executed. Output captured.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-tool.handler.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/action-handlers/use-mcp-tool.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AAOpD,uDAAmD;AACnD,uEAAgE;AAChE,yDAAiD;AACjD,qDAA2C;
|
|
1
|
+
{"version":3,"file":"use-mcp-tool.handler.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/action-handlers/use-mcp-tool.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AAOpD,uDAAmD;AACnD,uEAAgE;AAChE,yDAAiD;AACjD,qDAA2C;AAE3C,uCAAqE;AAG9D,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAI5B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAH1C,aAAQ,GAAG,cAAc,CAAC;QAClB,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;IAEP,CAAC;IAEvD,WAAW;QACT,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACrC,SAAS,EAAE;gBACT;oBACE,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,gDAAgD;oBAC7D,QAAQ,EAAE,IAAI;iBACf;gBACD;oBACE,IAAI,EAAE,eAAe;oBACrB,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,iDAAiD;oBAC9D,QAAQ,EAAE,IAAI;iBACf;gBACD;oBACE,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,6FAA6F;oBAC/F,QAAQ,EA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;gBAC5B,cAAc,EAAE,IAAI;gBACpB,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE;aAC5D,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC;QAC3E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAC7D,WAAW,EACX,aAAa,EACb,SAAS,CACV,CAAC;QAEF,MAAM,aAAa,GAAG,MAAM,IAAI,MAAM,IAAI,2BAA2B,CAAC;QAEtE,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,aAAa,WAAW,IAAI,aAAa,8BAA8B;YAChF,cAAc,EAAE;gBACd,WAAW;gBACX,SAAS,EAAE,aAAa;gBACxB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;aACrC;YACD,aAAa,EAAE;gBACb,MAAM,EAAE,aAAa;aACtB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA3HY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAK8B,wBAAU;GAJxC,iBAAiB,CA2H7B"}
|
|
@@ -13,7 +13,6 @@ const fs = require("fs/promises");
|
|
|
13
13
|
const path = require("path");
|
|
14
14
|
const class_transformer_1 = require("class-transformer");
|
|
15
15
|
const class_validator_1 = require("class-validator");
|
|
16
|
-
const handler_validation_error_1 = require("../errors/handler-validation.error");
|
|
17
16
|
const write_todo_args_dto_1 = require("./dto/write-todo.args.dto");
|
|
18
17
|
const utils_1 = require("../../utils");
|
|
19
18
|
let WriteTodoHandler = WriteTodoHandler_1 = class WriteTodoHandler {
|
|
@@ -111,7 +110,13 @@ let WriteTodoHandler = WriteTodoHandler_1 = class WriteTodoHandler {
|
|
|
111
110
|
const errorMessages = errors
|
|
112
111
|
.map((err) => Object.values(err.constraints || {}).join(', '))
|
|
113
112
|
.join('; ');
|
|
114
|
-
|
|
113
|
+
return {
|
|
114
|
+
status: 'FAILURE',
|
|
115
|
+
summary: `Invalid arguments for ${this.toolName}.`,
|
|
116
|
+
error_message: errorMessages,
|
|
117
|
+
persisted_args: args,
|
|
118
|
+
execution_log: { output: '', error_message: errorMessages },
|
|
119
|
+
};
|
|
115
120
|
}
|
|
116
121
|
const { file_path, content } = validatedArgs;
|
|
117
122
|
const safePath = this.resolveAndValidatePath(file_path);
|
|
@@ -124,6 +129,10 @@ let WriteTodoHandler = WriteTodoHandler_1 = class WriteTodoHandler {
|
|
|
124
129
|
summary: `TODO file "${file_path}" updated.`,
|
|
125
130
|
persisted_args: { file_path, content },
|
|
126
131
|
original_content_for_revert: originalContent,
|
|
132
|
+
execution_log: {
|
|
133
|
+
output: `${file_path} has been updated.`,
|
|
134
|
+
error_message: '',
|
|
135
|
+
},
|
|
127
136
|
};
|
|
128
137
|
}
|
|
129
138
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-todo.handler.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/action-handlers/write-todo.handler.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAKwB;AACxB,kCAAkC;AAClC,6BAA6B;AAC7B,yDAAiD;AACjD,qDAA2C;
|
|
1
|
+
{"version":3,"file":"write-todo.handler.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/action-handlers/write-todo.handler.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAKwB;AACxB,kCAAkC;AAClC,6BAA6B;AAC7B,yDAAiD;AACjD,qDAA2C;AAQ3C,mEAA6D;AAC7D,uCAAqE;AAG9D,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAAtB;QACI,aAAQ,GAAG,YAAY,CAAC;QAChB,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;QAC3C,gBAAW,GAC1B,OAAO,CAAC,GAAG,CAAC,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Service } from '../application-state/application-state.service';
|
|
3
|
+
export declare class HistoryCompressionService {
|
|
4
|
+
private readonly applicationStateService;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
private readonly FILE_MARKER_REGEX;
|
|
7
|
+
constructor(applicationStateService: ApplicationStateService);
|
|
8
|
+
compress(history: LlmContent[]): Promise<LlmContent[]>;
|
|
9
|
+
private extractFilePaths;
|
|
10
|
+
private normalizePath;
|
|
11
|
+
private redactToolResult;
|
|
12
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var HistoryCompressionService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.HistoryCompressionService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const application_state_service_1 = require("../application-state/application-state.service");
|
|
16
|
+
let HistoryCompressionService = HistoryCompressionService_1 = class HistoryCompressionService {
|
|
17
|
+
constructor(applicationStateService) {
|
|
18
|
+
this.applicationStateService = applicationStateService;
|
|
19
|
+
this.logger = new common_1.Logger(HistoryCompressionService_1.name);
|
|
20
|
+
this.FILE_MARKER_REGEX = /\/\/ File: (\.?[^\n]+)/g;
|
|
21
|
+
}
|
|
22
|
+
async compress(history) {
|
|
23
|
+
const enabled = await this.applicationStateService.getHistoryCompressionEnabled();
|
|
24
|
+
if (!enabled) {
|
|
25
|
+
this.logger.debug('History compression is disabled');
|
|
26
|
+
return history;
|
|
27
|
+
}
|
|
28
|
+
if (history.length === 0) {
|
|
29
|
+
return history;
|
|
30
|
+
}
|
|
31
|
+
const toolCallToIndex = new Map();
|
|
32
|
+
const toolResultIndices = [];
|
|
33
|
+
for (let i = 0; i < history.length; i++) {
|
|
34
|
+
const turn = history[i];
|
|
35
|
+
if (turn.role === 'model' && turn.tool_calls) {
|
|
36
|
+
for (const tc of turn.tool_calls) {
|
|
37
|
+
if (tc.function?.name === 'request_context') {
|
|
38
|
+
toolCallToIndex.set(tc.id, i);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (turn.role === 'tool' && turn.tool_call_id) {
|
|
43
|
+
toolResultIndices.push(i);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const fileToLatestIndex = new Map();
|
|
47
|
+
for (let i = history.length - 1; i >= 0; i--) {
|
|
48
|
+
const turn = history[i];
|
|
49
|
+
if (turn.role !== 'tool' || !turn.tool_call_id)
|
|
50
|
+
continue;
|
|
51
|
+
const modelTurnIndex = toolCallToIndex.get(turn.tool_call_id);
|
|
52
|
+
if (modelTurnIndex === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
const text = turn.parts.map((p) => p.text).join('');
|
|
55
|
+
const filePaths = this.extractFilePaths(text);
|
|
56
|
+
for (const filePath of filePaths) {
|
|
57
|
+
const normalized = this.normalizePath(filePath);
|
|
58
|
+
if (!fileToLatestIndex.has(normalized)) {
|
|
59
|
+
fileToLatestIndex.set(normalized, i);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (fileToLatestIndex.size === 0) {
|
|
64
|
+
return history;
|
|
65
|
+
}
|
|
66
|
+
const result = history.map((turn, index) => {
|
|
67
|
+
if (turn.role !== 'tool' || !turn.tool_call_id) {
|
|
68
|
+
return turn;
|
|
69
|
+
}
|
|
70
|
+
const modelTurnIndex = toolCallToIndex.get(turn.tool_call_id);
|
|
71
|
+
if (modelTurnIndex === undefined) {
|
|
72
|
+
return turn;
|
|
73
|
+
}
|
|
74
|
+
const text = turn.parts.map((p) => p.text).join('');
|
|
75
|
+
const filePaths = this.extractFilePaths(text);
|
|
76
|
+
if (filePaths.length === 0) {
|
|
77
|
+
return turn;
|
|
78
|
+
}
|
|
79
|
+
const filesToRedact = [];
|
|
80
|
+
for (const filePath of filePaths) {
|
|
81
|
+
const normalized = this.normalizePath(filePath);
|
|
82
|
+
const latestIndex = fileToLatestIndex.get(normalized);
|
|
83
|
+
if (latestIndex !== undefined && latestIndex > index) {
|
|
84
|
+
filesToRedact.push(filePath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (filesToRedact.length === 0) {
|
|
88
|
+
return turn;
|
|
89
|
+
}
|
|
90
|
+
return this.redactToolResult(turn, filesToRedact);
|
|
91
|
+
});
|
|
92
|
+
const redactedCount = result.filter((t, i) => t !== history[i] && t.role === 'tool').length;
|
|
93
|
+
if (redactedCount > 0) {
|
|
94
|
+
this.logger.log(`Compressed history: redacted ${redactedCount} older request_context result(s)`);
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
extractFilePaths(text) {
|
|
99
|
+
const paths = [];
|
|
100
|
+
let match;
|
|
101
|
+
this.FILE_MARKER_REGEX.lastIndex = 0;
|
|
102
|
+
while ((match = this.FILE_MARKER_REGEX.exec(text)) !== null) {
|
|
103
|
+
paths.push(match[1]);
|
|
104
|
+
}
|
|
105
|
+
return paths;
|
|
106
|
+
}
|
|
107
|
+
normalizePath(path) {
|
|
108
|
+
let normalized = path.replace(/^\.?\/*/, '');
|
|
109
|
+
normalized = normalized.replace(/\/+$/, '');
|
|
110
|
+
return normalized;
|
|
111
|
+
}
|
|
112
|
+
redactToolResult(turn, filesToRedact) {
|
|
113
|
+
const fileList = filesToRedact.length === 1
|
|
114
|
+
? filesToRedact[0]
|
|
115
|
+
: `${filesToRedact.length} files`;
|
|
116
|
+
const redactionMessage = `[Content for ${fileList} redacted - see newer request_context]`;
|
|
117
|
+
return {
|
|
118
|
+
...turn,
|
|
119
|
+
parts: [{ text: redactionMessage }],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
exports.HistoryCompressionService = HistoryCompressionService;
|
|
124
|
+
exports.HistoryCompressionService = HistoryCompressionService = HistoryCompressionService_1 = __decorate([
|
|
125
|
+
(0, common_1.Injectable)(),
|
|
126
|
+
__metadata("design:paramtypes", [application_state_service_1.ApplicationStateService])
|
|
127
|
+
], HistoryCompressionService);
|
|
128
|
+
//# sourceMappingURL=history-compression.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-compression.service.js","sourceRoot":"","sources":["../../../src/llm-orchestration/history-compression.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,8FAAyF;AAUlF,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAQpC,YACmB,uBAAgD;QAAhD,4BAAuB,GAAvB,uBAAuB,CAAyB;QARlD,WAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;QAKpD,sBAAiB,GAAG,yBAAyB,CAAC;IAI5D,CAAC;IASJ,KAAK,CAAC,QAAQ,CAAC,OAAqB;QAElC,MAAM,OAAO,GACX,MAAM,IAAI,CAAC,uBAAuB,CAAC,4BAA4B,EAAE,CAAC;QACpE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,OAAO,CAAC;QACjB,C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CAAC;IASO,aAAa,CAAC,IAAY;QAEhC,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAE7C,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC5C,OAAO,UAAU,CAAC;IACpB,CAAC;IASO,gBAAgB,CACtB,IAAgB,EAChB,aAAuB;QAGvB,MAAM,QAAQ,GACZ,aAAa,CAAC,MAAM,KAAK,CAAC;YACxB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,QAAQ,CAAC;QAEtC,MAAM,gBAAgB,GAAG,gBAAgB,QAAQ,wCAAwC,CAAC;QAG1F,OAAO;YACL,GAAG,IAAI;YACP,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC;CACF,CAAA;AAlMY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAUiC,mDAAuB;GATxD,yBAAyB,CAkMrC"}
|
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import { PostExecutionHook } from './post-execution-hook.interface';
|
|
2
2
|
import { PlanExecutionContext } from '../llm-orchestration.interfaces';
|
|
3
3
|
import { SessionInput } from '../../core-entities';
|
|
4
|
-
import { ChatService } from '../../interactive-chat/chat.service';
|
|
5
4
|
import { SessionInputsService } from '../../session-inputs/session-inputs.service';
|
|
6
|
-
import { EventsGateway } from '../../events/events.gateway';
|
|
7
|
-
import { SystemPromptsService } from '../../system-prompts/system-prompts.service';
|
|
8
|
-
import { SessionsService } from '../../sessions/sessions.service';
|
|
9
|
-
import { ApplicationStateService } from '../../application-state/application-state.service';
|
|
10
5
|
export declare class FollowUpPostExecutionHook implements PostExecutionHook {
|
|
11
|
-
private readonly chatService;
|
|
12
6
|
private readonly sessionInputsService;
|
|
13
|
-
private readonly eventsGateway;
|
|
14
|
-
private readonly systemPromptsService;
|
|
15
|
-
private readonly sessionsService;
|
|
16
|
-
private readonly applicationStateService;
|
|
17
7
|
private readonly logger;
|
|
18
|
-
constructor(
|
|
8
|
+
constructor(sessionInputsService: SessionInputsService);
|
|
19
9
|
run(sessionInput: SessionInput, context: PlanExecutionContext): Promise<void>;
|
|
20
|
-
private handleValidationFeedback;
|
|
21
|
-
private handleHaltedPlan;
|
|
22
|
-
private handleAutoContextFetch;
|
|
23
|
-
private handleNewSession;
|
|
24
|
-
private handleCommandOutputs;
|
|
25
10
|
}
|
|
@@ -15,21 +15,10 @@ var FollowUpPostExecutionHook_1;
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.FollowUpPostExecutionHook = void 0;
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
|
-
const gpt_tokenizer_1 = require("gpt-tokenizer");
|
|
19
|
-
const chat_service_1 = require("../../interactive-chat/chat.service");
|
|
20
18
|
const session_inputs_service_1 = require("../../session-inputs/session-inputs.service");
|
|
21
|
-
const events_gateway_1 = require("../../events/events.gateway");
|
|
22
|
-
const system_prompts_service_1 = require("../../system-prompts/system-prompts.service");
|
|
23
|
-
const sessions_service_1 = require("../../sessions/sessions.service");
|
|
24
|
-
const application_state_service_1 = require("../../application-state/application-state.service");
|
|
25
19
|
let FollowUpPostExecutionHook = FollowUpPostExecutionHook_1 = class FollowUpPostExecutionHook {
|
|
26
|
-
constructor(
|
|
27
|
-
this.chatService = chatService;
|
|
20
|
+
constructor(sessionInputsService) {
|
|
28
21
|
this.sessionInputsService = sessionInputsService;
|
|
29
|
-
this.eventsGateway = eventsGateway;
|
|
30
|
-
this.systemPromptsService = systemPromptsService;
|
|
31
|
-
this.sessionsService = sessionsService;
|
|
32
|
-
this.applicationStateService = applicationStateService;
|
|
33
22
|
this.logger = new common_1.Logger(FollowUpPostExecutionHook_1.name);
|
|
34
23
|
}
|
|
35
24
|
async run(sessionInput, context) {
|
|
@@ -37,159 +26,29 @@ let FollowUpPostExecutionHook = FollowUpPostExecutionHook_1 = class FollowUpPost
|
|
|
37
26
|
this.logger.log('Follow-up hook skipped because hook chain was halted.');
|
|
38
27
|
return;
|
|
39
28
|
}
|
|
40
|
-
if (context.
|
|
41
|
-
|
|
42
|
-
context.flags.follow_up_initiated = true;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (context.flags.should_halt && context.followUpAction) {
|
|
46
|
-
await this.handleHaltedPlan(sessionInput, context);
|
|
47
|
-
context.flags.follow_up_initiated = true;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (context.outputs.commands.length > 0 ||
|
|
51
|
-
context.outputs.mcp_tools.length > 0 ||
|
|
52
|
-
context.outputs.sub_agents.length > 0 ||
|
|
53
|
-
context.outputs.session_history.length > 0) {
|
|
54
|
-
await this.handleCommandOutputs(sessionInput, context);
|
|
55
|
-
context.flags.follow_up_initiated = true;
|
|
29
|
+
if (context.flags.is_final) {
|
|
30
|
+
this.logger.log('Plan marked as final. No follow-up will be initiated.');
|
|
56
31
|
return;
|
|
57
32
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
feedbackMessage += `- Tool: \`${err.tool_name}\`\n - Error: ${err.error}\n`;
|
|
65
|
-
}
|
|
66
|
-
const tokenCount = (0, gpt_tokenizer_1.countTokens)(feedbackMessage);
|
|
67
|
-
const followupLimit = await this.applicationStateService.getFollowupTokenLimit();
|
|
68
|
-
if (tokenCount > followupLimit) {
|
|
69
|
-
this.logger.warn(`Validation feedback exceeds token limit (${tokenCount} > ${followupLimit}). Replacing with error message.`);
|
|
70
|
-
feedbackMessage = `The plan had multiple validation errors. Please retry with simpler tool usage.`;
|
|
71
|
-
}
|
|
72
|
-
this.logger.log('Triggering self-correction AI call due to validation errors.');
|
|
73
|
-
const feedbackDto = {
|
|
74
|
-
user_prompt: feedbackMessage,
|
|
75
|
-
execution_strategy: sessionInput.execution_strategy,
|
|
76
|
-
ad_hoc_context_definition: undefined,
|
|
77
|
-
context_template_id: undefined,
|
|
78
|
-
};
|
|
79
|
-
await this.sessionInputsService.create(sessionInput.session_id, feedbackDto);
|
|
80
|
-
}
|
|
81
|
-
async handleHaltedPlan(sessionInput, context) {
|
|
82
|
-
this.logger.log(`Handling halted plan with follow-up action: ${context.followUpAction.type}`);
|
|
83
|
-
switch (context.followUpAction.type) {
|
|
84
|
-
case 'AUTO_CONTEXT_FETCH':
|
|
85
|
-
await this.handleAutoContextFetch(sessionInput, context.followUpAction.data);
|
|
86
|
-
break;
|
|
87
|
-
case 'NEW_SESSION':
|
|
88
|
-
await this.handleNewSession(context.followUpAction.data);
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
this.logger.warn(`Unknown follow-up action type: ${context.followUpAction.type}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async handleAutoContextFetch(originalInput, data) {
|
|
95
|
-
const session = await this.sessionsService.findOne(originalInput.session_id);
|
|
96
|
-
const newDto = {
|
|
97
|
-
user_prompt: '',
|
|
98
|
-
execution_strategy: originalInput.execution_strategy,
|
|
99
|
-
ad_hoc_context_definition: JSON.stringify(data),
|
|
100
|
-
context_template_id: session.default_followup_context_template_id,
|
|
101
|
-
};
|
|
102
|
-
const generatedContext = await this.sessionInputsService.generateContextString(originalInput.session_id, newDto);
|
|
103
|
-
const tokenCount = (0, gpt_tokenizer_1.countTokens)(generatedContext);
|
|
104
|
-
const followupLimit = await this.applicationStateService.getFollowupTokenLimit();
|
|
105
|
-
if (tokenCount > followupLimit) {
|
|
106
|
-
this.logger.warn(`Auto context fetch exceeds token limit (${tokenCount} > ${followupLimit}). Sending feedback to AI.`);
|
|
107
|
-
const feedbackDto = {
|
|
108
|
-
user_prompt: `The context you requested is too large (${tokenCount} tokens, limit is ${followupLimit}). Please request a smaller context by specifying fewer files or folders, or ask the user to break this task into smaller steps.`,
|
|
109
|
-
execution_strategy: originalInput.execution_strategy,
|
|
33
|
+
if (context.toolResults.length > 0) {
|
|
34
|
+
this.logger.log(`Triggering follow-up with ${context.toolResults.length} tool result(s)`);
|
|
35
|
+
await this.sessionInputsService.create(sessionInput.session_id, {
|
|
36
|
+
user_prompt: '',
|
|
37
|
+
execution_strategy: sessionInput.execution_strategy,
|
|
38
|
+
skip_persistence: true,
|
|
110
39
|
ad_hoc_context_definition: undefined,
|
|
111
40
|
context_template_id: undefined,
|
|
112
|
-
};
|
|
113
|
-
await this.sessionInputsService.create(originalInput.session_id, feedbackDto);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
this.logger.log(`Auto Context Fetch is re-submitting for session ${originalInput.session_id}. Generated context: ${tokenCount} tokens.`);
|
|
117
|
-
await this.sessionInputsService.create(originalInput.session_id, newDto);
|
|
118
|
-
}
|
|
119
|
-
async handleNewSession(data) {
|
|
120
|
-
this.eventsGateway.sendToAll('external-new-session', {});
|
|
121
|
-
const defaultSystemPrompt = await this.systemPromptsService.findDefault();
|
|
122
|
-
if (defaultSystemPrompt?.prompt_content) {
|
|
123
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
124
|
-
this.eventsGateway.sendToAll('system-prompt-update', {
|
|
125
|
-
systemPrompt: defaultSystemPrompt.prompt_content,
|
|
126
41
|
});
|
|
42
|
+
context.flags.follow_up_initiated = true;
|
|
43
|
+
return;
|
|
127
44
|
}
|
|
128
|
-
|
|
129
|
-
session_title: 'Handover Session',
|
|
130
|
-
});
|
|
131
|
-
if (data.handover_string) {
|
|
132
|
-
const executionStrategy = await this.applicationStateService.getExecutionStrategy();
|
|
133
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
134
|
-
this.sessionInputsService
|
|
135
|
-
.create(newSession.id, {
|
|
136
|
-
user_prompt: data.handover_string,
|
|
137
|
-
execution_strategy: executionStrategy,
|
|
138
|
-
context_template_id: newSession.default_initial_context_template_id,
|
|
139
|
-
})
|
|
140
|
-
.catch((err) => {
|
|
141
|
-
this.logger.error(`Error creating initial session input from handover: ${err.message}`, err.stack);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
145
|
-
this.eventsGateway.sendToAll('session-created', {
|
|
146
|
-
sessionId: newSession.id,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
async handleCommandOutputs(sessionInput, context) {
|
|
150
|
-
let followUpMessage = 'The previous plan produced the following outputs. Please analyze them and continue with the next logical step.\n\n';
|
|
151
|
-
for (const cmd of context.outputs.commands) {
|
|
152
|
-
followUpMessage += `--- Output from: \`run_command\` ---\n`;
|
|
153
|
-
followUpMessage += `Command: ${cmd.command}\nOutput:\n${cmd.output}\n\n`;
|
|
154
|
-
}
|
|
155
|
-
for (const tool of context.outputs.mcp_tools) {
|
|
156
|
-
followUpMessage += `--- Output from: \`use_mcp_tool\` ---\n`;
|
|
157
|
-
followUpMessage += `Tool: ${tool.tool_name}\nOutput:\n${tool.output}\n\n`;
|
|
158
|
-
}
|
|
159
|
-
for (const agent of context.outputs.sub_agents) {
|
|
160
|
-
followUpMessage += `--- Available Sub-Agent: ${agent.agent_name} ---\n`;
|
|
161
|
-
followUpMessage += `${agent.output}\n\n`;
|
|
162
|
-
}
|
|
163
|
-
for (const history of context.outputs.session_history) {
|
|
164
|
-
followUpMessage += `--- Output from: \`get_session_history\` ---\n`;
|
|
165
|
-
followUpMessage += `Session ID: ${history.session_id}\nEntry Count: ${history.entry_count}\nOutput:\n${history.output}\n\n`;
|
|
166
|
-
}
|
|
167
|
-
const tokenCount = (0, gpt_tokenizer_1.countTokens)(followUpMessage);
|
|
168
|
-
const followupLimit = await this.applicationStateService.getFollowupTokenLimit();
|
|
169
|
-
if (tokenCount > followupLimit) {
|
|
170
|
-
this.logger.warn(`Follow-up message exceeds token limit (${tokenCount} > ${followupLimit}). Replacing with error message.`);
|
|
171
|
-
followUpMessage = `The previous plan produced very large outputs (${tokenCount} tokens, limit is ${followupLimit}). Please ask the user to request smaller outputs or split the task into smaller steps.`;
|
|
172
|
-
}
|
|
173
|
-
this.logger.log('Triggering follow-up AI call with consolidated outputs.');
|
|
174
|
-
const feedbackDto = {
|
|
175
|
-
user_prompt: followUpMessage,
|
|
176
|
-
execution_strategy: sessionInput.execution_strategy,
|
|
177
|
-
ad_hoc_context_definition: undefined,
|
|
178
|
-
context_template_id: undefined,
|
|
179
|
-
};
|
|
180
|
-
await this.sessionInputsService.create(sessionInput.session_id, feedbackDto);
|
|
45
|
+
this.logger.log('No tool results - no follow-up needed.');
|
|
181
46
|
}
|
|
182
47
|
};
|
|
183
48
|
exports.FollowUpPostExecutionHook = FollowUpPostExecutionHook;
|
|
184
49
|
exports.FollowUpPostExecutionHook = FollowUpPostExecutionHook = FollowUpPostExecutionHook_1 = __decorate([
|
|
185
50
|
(0, common_1.Injectable)(),
|
|
186
|
-
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() =>
|
|
187
|
-
|
|
188
|
-
__metadata("design:paramtypes", [chat_service_1.ChatService,
|
|
189
|
-
session_inputs_service_1.SessionInputsService,
|
|
190
|
-
events_gateway_1.EventsGateway,
|
|
191
|
-
system_prompts_service_1.SystemPromptsService,
|
|
192
|
-
sessions_service_1.SessionsService,
|
|
193
|
-
application_state_service_1.ApplicationStateService])
|
|
51
|
+
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => session_inputs_service_1.SessionInputsService))),
|
|
52
|
+
__metadata("design:paramtypes", [session_inputs_service_1.SessionInputsService])
|
|
194
53
|
], FollowUpPostExecutionHook);
|
|
195
54
|
//# sourceMappingURL=follow-up-post-execution.hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"follow-up-post-execution.hook.js","sourceRoot":"","sources":["../../../../src/llm-orchestration/hooks/follow-up-post-execution.hook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwE;
|
|
1
|
+
{"version":3,"file":"follow-up-post-execution.hook.js","sourceRo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