genaicode 0.6.0 → 0.7.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.
Files changed (217) hide show
  1. package/README.md +1 -3
  2. package/dist/ai-service/ai-studio.js +7 -1
  3. package/dist/ai-service/ai-studio.js.map +1 -1
  4. package/dist/ai-service/anthropic.js +49 -19
  5. package/dist/ai-service/anthropic.js.map +1 -1
  6. package/dist/ai-service/chat-gpt.js +28 -11
  7. package/dist/ai-service/chat-gpt.js.map +1 -1
  8. package/dist/ai-service/common.d.ts +5 -4
  9. package/dist/ai-service/common.js +3 -4
  10. package/dist/ai-service/common.js.map +1 -1
  11. package/dist/ai-service/common.test.js +1 -1
  12. package/dist/ai-service/vertex-ai-claude.js +1 -1
  13. package/dist/ai-service/vertex-ai-claude.js.map +1 -1
  14. package/dist/ai-service/vertex-ai.js +7 -1
  15. package/dist/ai-service/vertex-ai.js.map +1 -1
  16. package/dist/cli/cli-options.js +0 -12
  17. package/dist/cli/cli-options.js.map +1 -1
  18. package/dist/cli/cli-params.d.ts +0 -3
  19. package/dist/cli/cli-params.js +0 -9
  20. package/dist/cli/cli-params.js.map +1 -1
  21. package/dist/cli/validate-cli-params.js +1 -7
  22. package/dist/cli/validate-cli-params.js.map +1 -1
  23. package/dist/cli/validate-cli-params.test.js +1 -1
  24. package/dist/cli/validate-cli-params.test.js.map +1 -1
  25. package/dist/eval/codegen-summary.test.d.ts +1 -0
  26. package/dist/eval/codegen-summary.test.js +91 -0
  27. package/dist/eval/codegen-summary.test.js.map +1 -0
  28. package/dist/eval/current-prompt-plugin.d.ts +3 -0
  29. package/dist/eval/current-prompt-plugin.js +10 -0
  30. package/dist/eval/current-prompt-plugin.js.map +1 -0
  31. package/dist/eval/data/current-prompt.d.ts +73 -0
  32. package/dist/eval/data/current-prompt.js +104 -0
  33. package/dist/eval/data/current-prompt.js.map +1 -0
  34. package/dist/eval/data/prompt-assistant-image.d.ts +49 -0
  35. package/dist/eval/data/prompt-assistant-image.js +67 -0
  36. package/dist/eval/data/prompt-assistant-image.js.map +1 -0
  37. package/dist/eval/data/prompt3.d.ts +34 -0
  38. package/dist/eval/data/prompt3.js +71 -0
  39. package/dist/eval/data/prompt3.js.map +1 -0
  40. package/dist/eval/prompt-debug.test.d.ts +1 -0
  41. package/dist/eval/prompt-debug.test.js +71 -0
  42. package/dist/eval/prompt-debug.test.js.map +1 -0
  43. package/dist/eval/prompt2.d.ts +34 -0
  44. package/dist/eval/prompt2.js +125 -0
  45. package/dist/eval/prompt2.js.map +1 -0
  46. package/dist/files/read-files.d.ts +2 -2
  47. package/dist/files/read-files.js +13 -7
  48. package/dist/files/read-files.js.map +1 -1
  49. package/dist/files/read-files.test.js +12 -6
  50. package/dist/files/read-files.test.js.map +1 -1
  51. package/dist/files/source-code-tree.d.ts +12 -0
  52. package/dist/files/source-code-tree.js +27 -0
  53. package/dist/files/source-code-tree.js.map +1 -0
  54. package/dist/main/codegen-types.d.ts +9 -4
  55. package/dist/main/codegen-utils.d.ts +1 -1
  56. package/dist/main/codegen-utils.js +1 -3
  57. package/dist/main/codegen-utils.js.map +1 -1
  58. package/dist/main/codegen.ai-services.test.d.ts +3 -0
  59. package/dist/main/codegen.ai-services.test.js +198 -0
  60. package/dist/main/codegen.ai-services.test.js.map +1 -0
  61. package/dist/main/codegen.cli-options.test.d.ts +3 -0
  62. package/dist/main/codegen.cli-options.test.js +171 -0
  63. package/dist/main/codegen.cli-options.test.js.map +1 -0
  64. package/dist/main/codegen.image-generation.test.d.ts +3 -0
  65. package/dist/main/codegen.image-generation.test.js +187 -0
  66. package/dist/main/codegen.image-generation.test.js.map +1 -0
  67. package/dist/main/codegen.js +4 -7
  68. package/dist/main/codegen.js.map +1 -1
  69. package/dist/main/codegen.test-utils.d.ts +81 -0
  70. package/dist/main/codegen.test-utils.js +88 -0
  71. package/dist/main/codegen.test-utils.js.map +1 -0
  72. package/dist/main/codegen.test.js +47 -28
  73. package/dist/main/codegen.test.js.map +1 -1
  74. package/dist/main/common/content-bus-types.d.ts +6 -0
  75. package/dist/main/common/content-bus.d.ts +2 -2
  76. package/dist/main/common/content-bus.js +3 -1
  77. package/dist/main/common/content-bus.js.map +1 -1
  78. package/dist/main/common/user-actions.d.ts +8 -2
  79. package/dist/main/common/user-actions.js.map +1 -1
  80. package/dist/main/interactive/codegen-interactive.js +0 -4
  81. package/dist/main/interactive/codegen-interactive.js.map +1 -1
  82. package/dist/main/interactive/codegen-interactive.test.js +0 -6
  83. package/dist/main/interactive/codegen-interactive.test.js.map +1 -1
  84. package/dist/main/interactive/common.d.ts +1 -1
  85. package/dist/main/interactive/common.js +0 -2
  86. package/dist/main/interactive/common.js.map +1 -1
  87. package/dist/main/interactive/configure.js +0 -2
  88. package/dist/main/interactive/configure.js.map +1 -1
  89. package/dist/main/interactive/help.js +0 -2
  90. package/dist/main/interactive/help.js.map +1 -1
  91. package/dist/main/interactive/task-file.js +1 -1
  92. package/dist/main/interactive/task-file.js.map +1 -1
  93. package/dist/main/interactive/text-prompt.js +1 -1
  94. package/dist/main/interactive/text-prompt.js.map +1 -1
  95. package/dist/main/interactive/user-action-handlers.js +4 -2
  96. package/dist/main/interactive/user-action-handlers.js.map +1 -1
  97. package/dist/main/plugin-loader.d.ts +2 -1
  98. package/dist/main/plugin-loader.js +8 -0
  99. package/dist/main/plugin-loader.js.map +1 -1
  100. package/dist/main/ui/backend/api.js +9 -3
  101. package/dist/main/ui/backend/api.js.map +1 -1
  102. package/dist/main/ui/backend/service.d.ts +2 -1
  103. package/dist/main/ui/backend/service.js +6 -3
  104. package/dist/main/ui/backend/service.js.map +1 -1
  105. package/dist/main/ui/frontend/assets/{index-Dk_qaEQg.js → index-5e3ykhy6.js} +129 -103
  106. package/dist/main/ui/frontend/index.html +1 -1
  107. package/dist/main/ui/user-action-handlers.js +1 -1
  108. package/dist/main/ui/user-action-handlers.js.map +1 -1
  109. package/dist/prompt/function-calling.js +8 -3
  110. package/dist/prompt/function-calling.js.map +1 -1
  111. package/dist/prompt/function-defs/ask-question.d.ts +5 -0
  112. package/dist/prompt/function-defs/ask-question.js +140 -60
  113. package/dist/prompt/function-defs/ask-question.js.map +1 -1
  114. package/dist/prompt/function-defs/codegen-planning.d.ts +8 -0
  115. package/dist/prompt/function-defs/codegen-planning.js +50 -0
  116. package/dist/prompt/function-defs/codegen-planning.js.map +1 -0
  117. package/dist/prompt/function-defs/codegen-summary.js +2 -2
  118. package/dist/prompt/function-defs/codegen-summary.js.map +1 -1
  119. package/dist/prompt/function-defs/get-source-code.js +32 -2
  120. package/dist/prompt/function-defs/get-source-code.js.map +1 -1
  121. package/dist/prompt/function-defs/optimize-context.js +35 -12
  122. package/dist/prompt/function-defs/optimize-context.js.map +1 -1
  123. package/dist/prompt/limits.js +2 -2
  124. package/dist/prompt/limits.js.map +1 -1
  125. package/dist/prompt/limits.test.js +3 -3
  126. package/dist/prompt/limits.test.js.map +1 -1
  127. package/dist/prompt/prompt-codegen.js +7 -79
  128. package/dist/prompt/prompt-codegen.js.map +1 -1
  129. package/dist/prompt/prompt-codegen.test.js +3 -10
  130. package/dist/prompt/prompt-codegen.test.js.map +1 -1
  131. package/dist/prompt/prompt-service-ask-question.test.js +26 -81
  132. package/dist/prompt/prompt-service-ask-question.test.js.map +1 -1
  133. package/dist/prompt/prompt-service.ai-services.test.d.ts +1 -0
  134. package/dist/prompt/prompt-service.ai-services.test.js +149 -0
  135. package/dist/prompt/prompt-service.ai-services.test.js.map +1 -0
  136. package/dist/prompt/prompt-service.context-optimization.test.d.ts +1 -0
  137. package/dist/prompt/prompt-service.context-optimization.test.js +212 -0
  138. package/dist/prompt/prompt-service.context-optimization.test.js.map +1 -0
  139. package/dist/prompt/prompt-service.image-handling.test.d.ts +1 -0
  140. package/dist/prompt/prompt-service.image-handling.test.js +212 -0
  141. package/dist/prompt/prompt-service.image-handling.test.js.map +1 -0
  142. package/dist/prompt/prompt-service.js +36 -29
  143. package/dist/prompt/prompt-service.js.map +1 -1
  144. package/dist/prompt/prompt-service.test-utils.d.ts +66 -0
  145. package/dist/prompt/prompt-service.test-utils.js +169 -0
  146. package/dist/prompt/prompt-service.test-utils.js.map +1 -0
  147. package/dist/prompt/prompt-service.test.js +96 -20
  148. package/dist/prompt/prompt-service.test.js.map +1 -1
  149. package/dist/prompt/prompt-service.validation-recovery.test.d.ts +1 -0
  150. package/dist/prompt/prompt-service.validation-recovery.test.js +263 -0
  151. package/dist/prompt/prompt-service.validation-recovery.test.js.map +1 -0
  152. package/dist/prompt/static-prompts.d.ts +16 -0
  153. package/dist/prompt/static-prompts.js +22 -0
  154. package/dist/prompt/static-prompts.js.map +1 -0
  155. package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.js +1 -1
  156. package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.js.map +1 -1
  157. package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.d.ts +1 -1
  158. package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.js +7 -4
  159. package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.js.map +1 -1
  160. package/dist/prompt/steps/step-ask-question/handlers/context-optimization.js +6 -4
  161. package/dist/prompt/steps/step-ask-question/handlers/context-optimization.js.map +1 -1
  162. package/dist/prompt/steps/step-ask-question/handlers/default-action.js +1 -2
  163. package/dist/prompt/steps/step-ask-question/handlers/default-action.js.map +1 -1
  164. package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer-with-image.d.ts +2 -0
  165. package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer-with-image.js +86 -0
  166. package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer-with-image.js.map +1 -0
  167. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message-with-image.d.ts +2 -0
  168. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message-with-image.js +103 -0
  169. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message-with-image.js.map +1 -0
  170. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.d.ts +2 -0
  171. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js +22 -0
  172. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js.map +1 -0
  173. package/dist/prompt/steps/step-ask-question/handlers/handler-utils.d.ts +0 -0
  174. package/dist/prompt/steps/step-ask-question/handlers/handler-utils.js +2 -0
  175. package/dist/prompt/steps/step-ask-question/handlers/handler-utils.js.map +1 -0
  176. package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.d.ts +1 -1
  177. package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.js +58 -13
  178. package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.js.map +1 -1
  179. package/dist/prompt/steps/step-ask-question/handlers/request-files-content.d.ts +1 -1
  180. package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js +110 -10
  181. package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js.map +1 -1
  182. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.d.ts +1 -1
  183. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js +49 -24
  184. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js.map +1 -1
  185. package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.js +1 -1
  186. package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.js.map +1 -1
  187. package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.js +1 -0
  188. package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.js.map +1 -1
  189. package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +22 -19
  190. package/dist/prompt/steps/step-ask-question/step-ask-question.d.ts +2 -4
  191. package/dist/prompt/steps/step-ask-question/step-ask-question.js +18 -29
  192. package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -1
  193. package/dist/prompt/steps/step-codegen-planning.d.ts +10 -0
  194. package/dist/prompt/steps/step-codegen-planning.js +69 -0
  195. package/dist/prompt/steps/step-codegen-planning.js.map +1 -0
  196. package/dist/prompt/steps/step-context-optimization.js +110 -80
  197. package/dist/prompt/steps/step-context-optimization.js.map +1 -1
  198. package/dist/prompt/steps/step-context-optimization.test.d.ts +2 -0
  199. package/dist/prompt/steps/step-context-optimization.test.js +456 -0
  200. package/dist/prompt/steps/step-context-optimization.test.js.map +1 -0
  201. package/dist/prompt/steps/step-generate-image.d.ts +8 -1
  202. package/dist/prompt/steps/step-generate-image.js +1 -0
  203. package/dist/prompt/steps/step-generate-image.js.map +1 -1
  204. package/dist/prompt/steps/step-summarization.d.ts +0 -1
  205. package/dist/prompt/steps/step-summarization.js +6 -3
  206. package/dist/prompt/steps/step-summarization.js.map +1 -1
  207. package/dist/prompt/steps/step-validate-recover.js +24 -15
  208. package/dist/prompt/steps/step-validate-recover.js.map +1 -1
  209. package/dist/prompt/systemprompt.d.ts +2 -2
  210. package/dist/prompt/systemprompt.js +74 -176
  211. package/dist/prompt/systemprompt.js.map +1 -1
  212. package/dist/prompt/systemprompt.test.js +2 -3
  213. package/dist/prompt/systemprompt.test.js.map +1 -1
  214. package/dist/vite-genaicode/vite-genaicode-plugin.d.ts +2 -1
  215. package/dist/vite-genaicode/vite-genaicode-plugin.js +15 -2
  216. package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
  217. package/package.json +3 -2
@@ -1,20 +1,32 @@
1
- import { FunctionCall, GenerateContentFunction, PromptItem } from '../../../ai-service/common.js';
1
+ import { FunctionCall, GenerateContentFunction, GenerateImageFunction, PromptItem, PromptItemImage } from '../../../ai-service/common.js';
2
2
  import { CodegenOptions } from '../../../main/codegen-types.js';
3
3
  import { StepResult } from '../steps-types.js';
4
4
  import { PluginActionType } from '../../../main/codegen-types.js';
5
- export type ActionType = 'requestAnswer' | 'requestPermissions' | 'requestFilesContent' | 'removeFilesFromContext' | 'confirmCodeGeneration' | 'startCodeGeneration' | 'cancelCodeGeneration' | 'contextOptimization' | PluginActionType;
5
+ export type ActionType = 'sendMessage' | 'sendMessageWithImage' | 'requestPermissions' | 'requestFilesContent' | 'removeFilesFromContext' | 'confirmCodeGeneration' | 'cancelCodeGeneration' | 'contextOptimization' | PluginActionType;
6
6
  type AskQuestionArgs = {
7
7
  actionType: ActionType;
8
- content: string;
9
- requestFilesContent?: string[];
10
- requestPermissions?: Record<'allowDirectoryCreate' | 'allowFileCreate' | 'allowFileDelete' | 'allowFileMove' | 'enableVision' | 'enableImagen', boolean>;
11
- removeFilesFromContext?: string[];
8
+ message: string;
9
+ };
10
+ export type SendMessageWithImageArgs = {
11
+ prompt: string;
12
+ contextImage?: string;
13
+ };
14
+ export type RequestPermissionsArgs = Record<'allowDirectoryCreate' | 'allowFileCreate' | 'allowFileDelete' | 'allowFileMove' | 'enableVision' | 'enableImagen', boolean>;
15
+ export type RequestFilesContentArgs = {
16
+ filePaths: string[];
17
+ };
18
+ export type RemoveFilesFromContextArgs = {
19
+ filePaths: string[];
20
+ };
21
+ export type ContextOptimizationArgs = {
22
+ filePaths: string[];
12
23
  };
13
24
  export type AskQuestionCall = FunctionCall<AskQuestionArgs>;
14
25
  export interface AssistantItem {
15
26
  type: 'assistant';
16
27
  text: string;
17
- functionCalls: FunctionCall[];
28
+ functionCalls?: FunctionCall[];
29
+ images?: PromptItemImage[];
18
30
  cache?: true;
19
31
  }
20
32
  export interface UserItem {
@@ -22,9 +34,10 @@ export interface UserItem {
22
34
  text: string;
23
35
  functionResponses?: Array<{
24
36
  name: string;
25
- call_id: string;
37
+ call_id: string | undefined;
26
38
  content: string | undefined;
27
39
  }>;
40
+ images?: PromptItemImage[];
28
41
  cache?: true;
29
42
  }
30
43
  export interface ActionResult {
@@ -40,17 +53,7 @@ export type ActionHandlerProps = {
40
53
  prompt: PromptItem[];
41
54
  options: CodegenOptions;
42
55
  generateContentFn: GenerateContentFunction;
43
- messages: {
44
- contextSourceCode: (paths: string[], pathsOnly: boolean) => string;
45
- };
56
+ generateImageFn: GenerateImageFunction;
46
57
  };
47
58
  export type ActionHandler = (props: ActionHandlerProps) => Promise<ActionResult>;
48
- export interface EscalationDecision {
49
- shouldEscalate: boolean;
50
- reason: string;
51
- }
52
- export interface SelfReflectionContext {
53
- escalationCount: number;
54
- lastEscalationTime: number;
55
- }
56
59
  export {};
@@ -1,6 +1,4 @@
1
- import { FunctionDef, GenerateContentFunction, PromptItem } from '../../../ai-service/common.js';
1
+ import { FunctionDef, GenerateContentFunction, PromptItem, GenerateImageFunction } from '../../../ai-service/common.js';
2
2
  import { StepResult } from '../steps-types.js';
3
3
  import { CodegenOptions } from '../../../main/codegen-types.js';
4
- export declare function executeStepAskQuestion(generateContentFn: GenerateContentFunction, prompt: PromptItem[], functionDefs: FunctionDef[], temperature: number, messages: {
5
- contextSourceCode: (paths: string[], pathsOnly: boolean) => string;
6
- }, options: CodegenOptions): Promise<StepResult>;
4
+ export declare function executeStepAskQuestion(generateContentFn: GenerateContentFunction, generateImageFn: GenerateImageFunction, prompt: PromptItem[], functionDefs: FunctionDef[], temperature: number, options: CodegenOptions): Promise<StepResult>;
@@ -7,38 +7,39 @@ import { handleContextOptimization } from './handlers/context-optimization.js';
7
7
  import { handleRemoveFilesFromContext } from './handlers/remove-files-from-context.js';
8
8
  import { handleRequestPermissions } from './handlers/request-permissions.js';
9
9
  import { handleDefaultAction } from './handlers/default-action.js';
10
- import { handleRequestAnswer } from './handlers/handle-request-answer.js';
11
- import { handleStartCodeGeneration } from './handlers/start-code-generation.js';
10
+ import { handleSendMessage } from './handlers/handle-send-message.js';
11
+ import { handleSendMessageWithImage } from './handlers/handle-send-message-with-image.js';
12
12
  import { handleConfirmCodeGeneration } from './handlers/confirm-code-generation.js';
13
13
  import { handleCancelCodeGeneration } from './handlers/cancel-code-generation.js';
14
14
  import { getRegisteredActionHandlers } from '../../../main/plugin-loader.js';
15
- import { performSelfReflection } from './step-ask-question-reflect.js';
16
- export async function executeStepAskQuestion(generateContentFn, prompt, functionDefs, temperature, messages, options) {
15
+ export async function executeStepAskQuestion(generateContentFn, generateImageFn, prompt, functionDefs, temperature, options) {
17
16
  console.log('Allowing the assistant to ask a question...');
18
- const selfReflectionContext = {
19
- escalationCount: 0,
20
- lastEscalationTime: 0,
21
- };
22
17
  while (!abortController?.signal.aborted) {
23
18
  try {
24
- const askQuestionCall = await getAskQuestionCall(generateContentFn, prompt, functionDefs, temperature, options, selfReflectionContext);
19
+ const askQuestionCall = await getAskQuestionCall(generateContentFn, prompt, functionDefs, temperature, options);
25
20
  if (!askQuestionCall) {
26
21
  break;
27
22
  }
28
23
  console.log('Assistant asks:', askQuestionCall.args);
29
- if (askQuestionCall.args?.content) {
30
- putAssistantMessage(askQuestionCall.args.content, askQuestionCall.args);
24
+ if (askQuestionCall.args?.message) {
25
+ putAssistantMessage(askQuestionCall.args.message, askQuestionCall.args);
31
26
  }
32
27
  const actionType = askQuestionCall.args?.actionType;
33
28
  if (actionType) {
34
29
  const actionHandler = getActionHandler(actionType);
35
- const result = await actionHandler({ askQuestionCall, prompt, options, messages, generateContentFn });
30
+ const result = await actionHandler({
31
+ askQuestionCall,
32
+ prompt,
33
+ options,
34
+ generateContentFn,
35
+ generateImageFn,
36
+ });
36
37
  // This is important to display the content to the user interface (ui or interactive cli)
37
38
  putUserMessage(result.items.slice(-1)[0].user.text);
39
+ prompt.push(...result.items.map(({ assistant, user }) => [assistant, user]).flat());
38
40
  if (result.breakLoop) {
39
41
  return result.stepResult;
40
42
  }
41
- prompt.push(...result.items.map(({ assistant, user }) => [assistant, user]).flat());
42
43
  console.log('The question was answered');
43
44
  }
44
45
  else {
@@ -55,23 +56,11 @@ export async function executeStepAskQuestion(generateContentFn, prompt, function
55
56
  putSystemMessage('Assistant did not ask a question. This unexpected, we need to abort.');
56
57
  return StepResult.BREAK;
57
58
  }
58
- async function getAskQuestionCall(generateContentFn, prompt, functionDefs, temperature, options, selfReflectionContext) {
59
+ async function getAskQuestionCall(generateContentFn, prompt, functionDefs, temperature, options) {
59
60
  const askQuestionRequest = [prompt, functionDefs, 'askQuestion', temperature, true, options];
60
61
  let askQuestionResult = await generateContentFn(...askQuestionRequest);
61
62
  askQuestionResult = await validateAndRecoverSingleResult(askQuestionRequest, askQuestionResult, generateContentFn);
62
- const cheapModelResponse = askQuestionResult.find((call) => call.name === 'askQuestion');
63
- if (cheapModelResponse) {
64
- const escalationDecision = await performSelfReflection(cheapModelResponse, selfReflectionContext, prompt, functionDefs, options, generateContentFn);
65
- if (escalationDecision.shouldEscalate) {
66
- console.log('Self-reflection suggests escalating to non-cheap model.');
67
- // Re-run with non-cheap model
68
- const nonCheapRequest = [prompt, functionDefs, 'askQuestion', temperature, false, options];
69
- let nonCheapResult = await generateContentFn(...nonCheapRequest);
70
- nonCheapResult = await validateAndRecoverSingleResult(nonCheapRequest, nonCheapResult, generateContentFn);
71
- return nonCheapResult.find((call) => call.name === 'askQuestion');
72
- }
73
- }
74
- return cheapModelResponse;
63
+ return askQuestionResult.find((call) => call.name === 'askQuestion');
75
64
  }
76
65
  function getActionHandler(actionType) {
77
66
  // First, check if there's a plugin-provided handler for this action type
@@ -83,11 +72,11 @@ function getActionHandler(actionType) {
83
72
  const handlers = {
84
73
  cancelCodeGeneration: handleCancelCodeGeneration,
85
74
  confirmCodeGeneration: handleConfirmCodeGeneration,
86
- startCodeGeneration: handleStartCodeGeneration,
87
75
  requestFilesContent: handleRequestFilesContent,
88
76
  requestPermissions: handleRequestPermissions,
89
77
  removeFilesFromContext: handleRemoveFilesFromContext,
90
- requestAnswer: handleRequestAnswer,
78
+ sendMessage: handleSendMessage,
79
+ sendMessageWithImage: handleSendMessageWithImage,
91
80
  contextOptimization: handleContextOptimization,
92
81
  };
93
82
  return handlers[actionType] || handleDefaultAction;
@@ -1 +1 @@
1
- {"version":3,"file":"step-ask-question.js","sourceRoot":"","sources":["../../../../src/prompt/steps/step-ask-question/step-ask-question.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC5G,OAAO,EAAE,eAAe,EAA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EAAE,iBAAiB,CAAC,CAAC;YAC1G,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAgC,CAAC;QACnG,CAAC;IACH,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAsB;IAC9C,yEAAyE;IACzE,MAAM,aAAa,GAAG,2BAA2B,EAAE,CAAC,GAAG,CAAC,UAAgC,CAAC,CAAC;IAC1F,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,2DAA2D;IAC3D,MAAM,QAAQ,GAAsC;QAClD,oBAAoB,EAAE,0BAA0B;QAChD,qBAAqB,EAAE,2BAA2B;QAClD,mBAAmB,EAAE,yBAAyB;QAC9C,mBAAmB,EAAE,yBAAyB;QAC9C,kBAAkB,EAAE,wBAAwB;QAC5C,sBAAsB,EAAE,4BAA4B;QACpD,aAAa,EAAE,mBAAmB;QAClC,mBAAmB,EAAE,yBAAyB;KAC/C,CAAC;IAEF,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,mBAAmB,CAAC;AACrD,CAAC"}
1
+ {"version":3,"file":"step-ask-question.js","sourceRoot":"","sources":["../../../../src/prompt/steps/step-ask-question/step-ask-question.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAy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W,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClH,IAAI,iBAAiB,GAAG,MAAM,iBAAiB,CAAC,GAAG,kBAAkB,CAAC,CAAC;IACvE,iBAAiB,GAAG,MAAM,8BAA8B,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAEnH,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAgC,CAAC;AACtG,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAsB;IAC9C,yEAAyE;IACzE,MAAM,aAAa,GAAG,2BAA2B,EAAE,CAAC,GAAG,CAAC,UAAgC,CAAC,CAAC;IAC1F,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,2DAA2D;IAC3D,MAAM,QAAQ,GAAsC;QAClD,oBAAoB,EAAE,0BAA0B;QAChD,qBAAqB,EAAE,2BAA2B;QAClD,mBAAmB,EAAE,yBAAyB;QAC9C,kBAAkB,EAAE,wBAAwB;QAC5C,sBAAsB,EAAE,4BAA4B;QACpD,WAAW,EAAE,iBAAiB;QAC9B,oBAAoB,EAAE,0BAA0B;QAChD,mBAAmB,EAAE,yBAAyB;KAC/C,CAAC;IAEF,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,mBAAmB,CAAC;AACrD,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { GenerateContentFunction, PromptItem } from '../../ai-service/common.js';
2
+ import { CodegenOptions } from '../../main/codegen-types.js';
3
+ import { StepResult } from './steps-types.js';
4
+ export declare const PLANNING_PROMPT = "Please analyze the conversation so far and help plan the implementation:\n\n1. Review the conversation history and requirements\n2. Thoughtfully analyze the problem\n3. Create a step-by-step implementation plan\n4. List all files that will be affected during implementation\n\nRemember to:\n- Consider both direct and indirect dependencies\n- Think about how changes in one file might affect others\n- Include all necessary file paths\n- Explain your reasoning for each step\n- Consider edge cases and potential issues\n\nOutput the plan using `codegenPlanning` function provding all the required fields.";
5
+ /**
6
+ * Execute the codegen planning step
7
+ * This step analyzes the conversation and produces a detailed implementation plan
8
+ * before proceeding with actual code generation
9
+ */
10
+ export declare function executeStepCodegenPlanning(generateContentFn: GenerateContentFunction, prompt: PromptItem[], options: CodegenOptions): Promise<StepResult>;
@@ -0,0 +1,69 @@
1
+ import { getFunctionDefs } from '../function-calling.js';
2
+ import { putSystemMessage } from '../../main/common/content-bus.js';
3
+ import { validateAndRecoverSingleResult } from './step-validate-recover.js';
4
+ import { StepResult } from './steps-types.js';
5
+ import { CODEGEN_SUMMARY_PROMPT } from '../static-prompts.js';
6
+ export const PLANNING_PROMPT = `Please analyze the conversation so far and help plan the implementation:
7
+
8
+ 1. Review the conversation history and requirements
9
+ 2. Thoughtfully analyze the problem
10
+ 3. Create a step-by-step implementation plan
11
+ 4. List all files that will be affected during implementation
12
+
13
+ Remember to:
14
+ - Consider both direct and indirect dependencies
15
+ - Think about how changes in one file might affect others
16
+ - Include all necessary file paths
17
+ - Explain your reasoning for each step
18
+ - Consider edge cases and potential issues
19
+
20
+ Output the plan using \`codegenPlanning\` function provding all the required fields.`;
21
+ /**
22
+ * Execute the codegen planning step
23
+ * This step analyzes the conversation and produces a detailed implementation plan
24
+ * before proceeding with actual code generation
25
+ */
26
+ export async function executeStepCodegenPlanning(generateContentFn, prompt, options) {
27
+ putSystemMessage('Starting codegen planning phase...');
28
+ // Add the planning prompt to the conversation
29
+ if (prompt.slice(-1)[0].type === 'user') {
30
+ prompt.slice(-1)[0].text += '\n\\n' + PLANNING_PROMPT;
31
+ }
32
+ else {
33
+ prompt.push({ type: 'user', text: PLANNING_PROMPT });
34
+ }
35
+ const planningRequest = [
36
+ prompt,
37
+ getFunctionDefs(),
38
+ 'codegenPlanning',
39
+ options.temperature ?? 0.7,
40
+ options.cheap ?? true,
41
+ options,
42
+ ];
43
+ try {
44
+ let planningResult = await generateContentFn(...planningRequest);
45
+ planningResult = await validateAndRecoverSingleResult(planningRequest, planningResult, generateContentFn);
46
+ const codegenPlanningRequest = planningResult.find((call) => call.name === 'codegenPlanning');
47
+ if (codegenPlanningRequest) {
48
+ putSystemMessage('Planning phase completed successfully', codegenPlanningRequest.args);
49
+ // Store the planning response in conversation history
50
+ prompt.push({ type: 'assistant', functionCalls: planningResult });
51
+ prompt.push({
52
+ type: 'user',
53
+ functionResponses: planningResult.map((call) => ({ name: call.name, call_id: call.id })),
54
+ text: CODEGEN_SUMMARY_PROMPT,
55
+ cache: true,
56
+ });
57
+ return StepResult.CONTINUE;
58
+ }
59
+ else {
60
+ putSystemMessage('Did not receive codegen planning result');
61
+ return StepResult.BREAK;
62
+ }
63
+ }
64
+ catch (error) {
65
+ putSystemMessage('Error during planning phase: ' + error.message);
66
+ return StepResult.BREAK;
67
+ }
68
+ }
69
+ //# sourceMappingURL=step-codegen-planning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-codegen-planning.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-codegen-planning.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;qFAcsD,CAAC;AAEtF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,iBAA0C,EAC1C,MAAoB,EACpB,OAAuB;IAEvB,gBAAgB,CAAC,oCAAoC,CAAC,CAAC;IAEvD,8CAA8C;IAC9C,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,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AO,UAAU,CAAC,QAAQ,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,gBAAgB,CAAC,yCAAyC,CAAC,CAAC;YAC5D,OAAO,UAAU,CAAC,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAgB,CAAC,+BAA+B,GAAI,KAAe,CAAC,OAAO,CAAC,CAAC;QAC7E,OAAO,UAAU,CAAC,KAAK,CAAC;IAC1B,CAAC;AACH,CAAC"}
@@ -6,6 +6,7 @@ import { estimateTokenCount } from '../token-estimator.js';
6
6
  import { getSummary } from './step-summarization.js';
7
7
  import { validateAndRecoverSingleResult } from './step-validate-recover.js';
8
8
  import { getSourceCodeResponse } from './steps-utils.js';
9
+ import { getSourceCodeTree, parseSourceCodeTree } from '../../files/source-code-tree.js';
9
10
  const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for code generation. Please perform the following tasks and respond by calling the \`optimizeContext\` function with the appropriate arguments:
10
11
 
11
12
  1. **Relevance and Token Cost Evaluation**:
@@ -31,13 +32,11 @@ const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for
31
32
  - The function should have the following parameters:
32
33
  - \`"userPrompt"\`: The user's original prompt.
33
34
  - \`"optimizedContext"\`: An array of objects, each containing:
34
- - \`"path"\`: The absolute file path.
35
+ - \`"filePath"\`: The absolute file path.
35
36
  - \`"relevance"\`: The calculated relevance score (0 to 1).
36
- - \`"tokenCount"\`: The token count for the file.
37
- - \`"totalTokenCount"\`: The estimated total token count for the context.
38
37
 
39
38
  **Important Guidelines**:
40
- - **Only include files that are mentioned in \`getSourceCode\` function responses**. **Do not add any other files**.
39
+ - **Only include files that are mentioned in \`getSourceCode\` function response**. **Do not add any other files**.
41
40
  - **Do not infer or guess additional files**.
42
41
  - **Evaluate each file individually** based on the criteria above.
43
42
  - **Avoid assumptions or hallucinations**; stick strictly to the provided data.
@@ -46,6 +45,7 @@ const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for
46
45
  - **Do not include any extra text** outside of the function call.
47
46
  - **Ensure the JSON is properly formatted** and **does not contain strings representing JSON** (i.e., do not stringify the JSON, do not wrap strings into quotes).
48
47
  - **Do not return files which are not relevant to the user prompt. Use relevance rating to judge that**
48
+ - **Formulate full file paths correctly using directoryPath and filePath from the \`getSourceCode\` function response**.
49
49
 
50
50
  **Example of valid Function Call**:
51
51
 
@@ -53,18 +53,15 @@ const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for
53
53
  {
54
54
  "function": "optimizeContext",
55
55
  "arguments": {
56
- "userPrompt": "Please review the helper modules.",
57
- "totalTokenCount": 800,
56
+ "userPrompt": "Please review the helper module.",
58
57
  "optimizedContext": [
59
58
  {
60
59
  "path": "/home/src/utils/helpers.js",
61
60
  "relevance": 0.9,
62
- "tokenCount": 500
63
61
  },
64
62
  {
65
63
  "path": "/home/src/utils/math.js",
66
- "relevance": 0.8,
67
- "tokenCount": 300
64
+ "relevance": 0.4,
68
65
  }
69
66
  ]
70
67
  }
@@ -73,80 +70,89 @@ const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for
73
70
 
74
71
  Now could you please analyze the source code and return me the optimized context?
75
72
  `;
76
- const BATCH_SIZE = 100;
73
+ // const BATCH_SIZE = 100;
77
74
  const MAX_TOTAL_TOKENS = 10000;
78
75
  export async function executeStepContextOptimization(generateContentFn, prompt, options) {
79
76
  const fullSourceCode = getSourceCode({ forceAll: true }, options);
77
+ const tokensBefore = estimateTokenCount(JSON.stringify(fullSourceCode));
78
+ if (tokensBefore < MAX_TOTAL_TOKENS) {
79
+ putSystemMessage('Context optimization is not needed, because the code base is small.');
80
+ return StepResult.CONTINUE;
81
+ }
80
82
  const sourceCodeResponse = getSourceCodeResponse(prompt);
81
83
  if (!sourceCodeResponse || !sourceCodeResponse.content) {
82
84
  console.warn('Could not find source code response, something is wrong, but lets continue anyway.');
83
85
  return StepResult.CONTINUE;
84
86
  }
85
- const sourceCode = JSON.parse(sourceCodeResponse.content);
86
- const sourceCodeEntries = Object.entries(sourceCode);
87
- // Lets remove source code from the context, because we will be providing it below, so lets not duplicate (and save some tokens)
88
- const sourceCodeResponseContent = sourceCodeResponse.content;
89
- sourceCodeResponse.content = '{}';
87
+ const sourceCode = parseSourceCodeTree(JSON.parse(sourceCodeResponse.content));
90
88
  try {
91
89
  putSystemMessage('Context optimization is starting');
92
- const totalFiles = sourceCodeEntries.length;
93
- const batchCount = Math.ceil(totalFiles / BATCH_SIZE);
94
- const optimizedContext = new Set();
95
- for (let batchIndex = 0; batchIndex < batchCount; batchIndex++) {
96
- const start = batchIndex * BATCH_SIZE;
97
- const end = Math.min((batchIndex + 1) * BATCH_SIZE, totalFiles);
98
- const batchSourceCode = Object.fromEntries(sourceCodeEntries.filter(([path], index) => optimizedContext.has(path) || (index >= start && index <= end)));
99
- const optimizationPrompt = [
100
- ...prompt,
101
- {
102
- type: 'assistant',
103
- text: 'Thank you for describing the task, I have noticed you have provided a very large context for your question. The amount of source code is very big in particular. Can we do something about it?',
104
- functionCalls: [
105
- { id: 'get_batch_source', name: 'getSourceCode', args: { filePaths: Object.keys(batchSourceCode) } },
106
- ],
107
- },
108
- {
109
- type: 'user',
110
- text: OPTIMIZATION_PROMPT,
111
- functionResponses: [
112
- { call_id: 'get_batch_source', name: 'getSourceCode', content: JSON.stringify(batchSourceCode) },
113
- ],
114
- },
115
- ];
116
- const request = [
117
- optimizationPrompt,
118
- getFunctionDefs(),
119
- 'optimizeContext',
120
- 0.2,
121
- true,
122
- options,
123
- ];
124
- let result = await generateContentFn(...request);
125
- result = await validateAndRecoverSingleResult(request, result, generateContentFn);
126
- const batchOptimized = parseOptimizationResult(result);
127
- if (!batchOptimized) {
128
- putSystemMessage(`Warning: Context optimization failed to produce useful summaries for batch ${batchIndex + 1}. We need to abort.`);
129
- return StepResult.BREAK;
130
- }
131
- optimizedContext.clear();
132
- batchOptimized.forEach((path) => optimizedContext.add(path));
90
+ const optimizationPrompt = [
91
+ ...prompt,
92
+ {
93
+ type: 'assistant',
94
+ text: 'Thank you for describing the task, I have noticed you have provided a very large context for your question. The amount of source code is very big in particular. Can we do something about it?',
95
+ },
96
+ {
97
+ type: 'user',
98
+ text: OPTIMIZATION_PROMPT,
99
+ },
100
+ ];
101
+ const request = [optimizationPrompt, getFunctionDefs(), 'optimizeContext', 0.2, true, options];
102
+ let result = await generateContentFn(...request);
103
+ result = await validateAndRecoverSingleResult(request, result, generateContentFn);
104
+ const optimizedContext = parseOptimizationResult(fullSourceCode, result);
105
+ if (!optimizedContext) {
106
+ putSystemMessage(`Warning: Context optimization failed. We need to abort.`);
107
+ return StepResult.BREAK;
133
108
  }
134
- if (optimizedContext.size === 0) {
135
- // Restore the original context
136
- sourceCodeResponse.content = sourceCodeResponseContent;
109
+ if (optimizedContext.length === 0) {
137
110
  putSystemMessage('Warning: Context optimization failed to produce useful summaries for all batches. Proceeding with current context.');
138
111
  return StepResult.CONTINUE;
139
112
  }
140
- const tokensBefore = estimateTokenCount(JSON.stringify(fullSourceCode));
141
113
  putSystemMessage('Context optimization in progress.', Array.from(optimizedContext));
142
- const optimizedSourceCode = optimizeSourceCode(sourceCode, fullSourceCode, Array.from(optimizedContext));
114
+ const [optimizedSourceCode, contentTokenCount, summaryTokenCount] = optimizeSourceCode(sourceCode, fullSourceCode, Array.from(optimizedContext));
143
115
  const tokensAfter = estimateTokenCount(JSON.stringify(optimizedSourceCode));
144
116
  const percentageReduced = ((tokensBefore - tokensAfter) / tokensBefore) * 100;
145
- // Update the getSourceCode function response in the prompt
146
- sourceCodeResponse.content = JSON.stringify(optimizedSourceCode);
117
+ // Clear previous getSourceCode responses
118
+ clearPreviousSourceCodeResponses(prompt);
119
+ prompt.push({
120
+ type: 'assistant',
121
+ // we may want to put text question here
122
+ functionCalls: [
123
+ {
124
+ name: 'requestFilesContent',
125
+ args: {
126
+ filePaths: Object.keys(optimizedSourceCode),
127
+ },
128
+ },
129
+ {
130
+ name: 'getSourceCode',
131
+ args: {
132
+ filePaths: Object.keys(optimizedSourceCode),
133
+ },
134
+ },
135
+ ],
136
+ }, {
137
+ type: 'user',
138
+ // we may want to put text answer here
139
+ functionResponses: [
140
+ {
141
+ name: 'requestFilesContent',
142
+ content: JSON.stringify({ filePaths: Object.keys(optimizedSourceCode) }),
143
+ },
144
+ {
145
+ name: 'getSourceCode',
146
+ content: JSON.stringify(getSourceCodeTree(optimizedSourceCode)),
147
+ },
148
+ ],
149
+ cache: true,
150
+ });
147
151
  putSystemMessage('Context optimization completed successfully.', {
148
152
  tokensBefore,
149
153
  tokensAfter,
154
+ contentTokenCount,
155
+ summaryTokenCount,
150
156
  percentageReduced: percentageReduced.toFixed(2) + '%',
151
157
  });
152
158
  return StepResult.CONTINUE;
@@ -157,20 +163,24 @@ export async function executeStepContextOptimization(generateContentFn, prompt,
157
163
  return StepResult.BREAK;
158
164
  }
159
165
  }
160
- function parseOptimizationResult(calls) {
166
+ function parseOptimizationResult(fullSourceCode, calls) {
161
167
  const optimizeCall = calls.find((call) => call.name === 'optimizeContext');
162
168
  if (!optimizeCall || !optimizeCall.args || !optimizeCall.args.optimizedContext) {
163
169
  return null;
164
170
  }
165
171
  let totalTokens = 0;
166
172
  const result = [];
167
- for (const item of optimizeCall.args.optimizedContext.sort((a, b) => (a.relevance > b.relevance ? -1 : 1))) {
168
- if (item.relevance < 0.5) {
173
+ for (const item of optimizeCall.args.optimizedContext.sort((a, b) => a.relevance > b.relevance ? -1 : 1)) {
174
+ const { filePath, relevance } = item;
175
+ if (relevance < 0.5) {
169
176
  break;
170
177
  }
171
- totalTokens += item.tokenCount;
172
- result.push(item.filePath);
173
- if (totalTokens > MAX_TOTAL_TOKENS && item.relevance < 0.7) {
178
+ const content = (fullSourceCode[filePath] && 'content' in fullSourceCode[filePath]
179
+ ? fullSourceCode[filePath]?.content
180
+ : undefined) ?? '';
181
+ totalTokens += estimateTokenCount(content);
182
+ result.push([item.filePath, item.relevance]);
183
+ if (totalTokens > MAX_TOTAL_TOKENS && relevance < 0.7) {
174
184
  break;
175
185
  }
176
186
  }
@@ -178,23 +188,43 @@ function parseOptimizationResult(calls) {
178
188
  }
179
189
  function optimizeSourceCode(sourceCode, fullSourceCode, optimizedContext) {
180
190
  const optimizedSourceCode = {};
181
- for (const [path] of Object.entries(sourceCode)) {
182
- const isContext = optimizedContext.includes(path);
191
+ let contentTokenCount = 0;
192
+ let summaryTokenCount = 0;
193
+ for (const [path] of Object.entries(fullSourceCode)) {
194
+ const isContext = optimizedContext.filter((item) => item[0] === path).length > 0;
183
195
  const summary = getSummary(path);
184
- if (isContext) {
196
+ const content = (fullSourceCode[path] && 'content' in fullSourceCode[path] ? fullSourceCode[path]?.content : undefined) ?? null;
197
+ if (isContext && content && !(sourceCode[path] && 'content' in sourceCode[path])) {
198
+ contentTokenCount += estimateTokenCount(content);
185
199
  optimizedSourceCode[path] = {
186
- content: ('content' in fullSourceCode[path] ? fullSourceCode[path]?.content : undefined) ?? null,
187
- ...summary,
200
+ content,
188
201
  };
189
202
  }
190
203
  else {
191
- optimizedSourceCode[path] = summary
192
- ? { ...summary }
193
- : {
194
- content: null,
195
- };
204
+ summaryTokenCount += estimateTokenCount(summary?.summary ?? '');
205
+ }
206
+ }
207
+ return [optimizedSourceCode, contentTokenCount, summaryTokenCount];
208
+ }
209
+ /**
210
+ * Helper function to clear content from previous getSourceCode responses while preserving the conversation structure
211
+ */
212
+ function clearPreviousSourceCodeResponses(prompt) {
213
+ for (const item of prompt) {
214
+ if (item.type === 'user' && item.functionResponses) {
215
+ for (const response of item.functionResponses) {
216
+ if (response.name === 'getSourceCode' && response.content) {
217
+ // Zero out the contents but keep the structure
218
+ const sourceCode = parseSourceCodeTree(JSON.parse(response.content));
219
+ for (const path in sourceCode) {
220
+ if ('content' in sourceCode[path]) {
221
+ delete sourceCode[path];
222
+ }
223
+ }
224
+ response.content = JSON.stringify(getSourceCodeTree(sourceCode));
225
+ }
226
+ }
196
227
  }
197
228
  }
198
- return optimizedSourceCode;
199
229
  }
200
230
  //# sourceMappingURL=step-context-optimization.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"step-context-optimization.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-context-optimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAiB,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkE3B,CAAC;AAEF,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,iBAA0C,EAC1C,MAAoB,EACpB,OAAuB;IAEvB,MAAM,cAAc,GAAG,aAAa,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAClE,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzD,IAAI,CAAC,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,oFAAoF,CAAC,CAAC;QACnG,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAkB,CAAC;IAC3E,MAAM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AAC;IACH,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"step-context-optimization.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-context-optimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAiB,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAkB,MAAM,iCAAiC,CAAC;AAEzG,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8D3B,CAAC;AAEF,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,iBAA0C,EAC1C,MAAoB,EACpB,OAAuB;IAEvB,MAAM,cAAc,GAAG,aAAa,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IAExE,IAAI,YAAY,GAAG,gBAAgB,EAAE,CAAC;QACpC,gBAAgB,CAAC,qEAAqE,CAAC,CAAC;QACxF,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,MAAM,kBAAkB,GAAG,qBAAqB,C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