genaicode 0.3.0 → 0.4.1

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 (140) hide show
  1. package/README.md +9 -0
  2. package/dist/ai-service/ai-studio.js +58 -9
  3. package/dist/ai-service/ai-studio.js.map +1 -1
  4. package/dist/ai-service/anthropic.js +1 -0
  5. package/dist/ai-service/anthropic.js.map +1 -1
  6. package/dist/ai-service/chat-gpt.js +1 -0
  7. package/dist/ai-service/chat-gpt.js.map +1 -1
  8. package/dist/ai-service/common.d.ts +12 -3
  9. package/dist/ai-service/common.js +4 -3
  10. package/dist/ai-service/common.js.map +1 -1
  11. package/dist/ai-service/common.test.js +2 -2
  12. package/dist/ai-service/common.test.js.map +1 -1
  13. package/dist/ai-service/unescape-function-call.d.ts +7 -0
  14. package/dist/ai-service/unescape-function-call.js +59 -0
  15. package/dist/ai-service/unescape-function-call.js.map +1 -0
  16. package/dist/ai-service/unescape-function-call.test.d.ts +1 -0
  17. package/dist/ai-service/unescape-function-call.test.js +18 -0
  18. package/dist/ai-service/unescape-function-call.test.js.map +1 -0
  19. package/dist/ai-service/vertex-ai-claude.js +7 -1
  20. package/dist/ai-service/vertex-ai-claude.js.map +1 -1
  21. package/dist/ai-service/vertex-ai.d.ts +1 -1
  22. package/dist/ai-service/vertex-ai.js +63 -13
  23. package/dist/ai-service/vertex-ai.js.map +1 -1
  24. package/dist/cli/cli-options.js +8 -0
  25. package/dist/cli/cli-options.js.map +1 -1
  26. package/dist/cli/cli-params.d.ts +4 -0
  27. package/dist/cli/cli-params.js +12 -3
  28. package/dist/cli/cli-params.js.map +1 -1
  29. package/dist/cli/validate-cli-params.js +9 -1
  30. package/dist/cli/validate-cli-params.js.map +1 -1
  31. package/dist/files/cache-file.d.ts +3 -0
  32. package/dist/files/cache-file.js +36 -0
  33. package/dist/files/cache-file.js.map +1 -0
  34. package/dist/files/read-files.d.ts +4 -1
  35. package/dist/files/read-files.js +5 -3
  36. package/dist/files/read-files.js.map +1 -1
  37. package/dist/files/read-files.test.js +1 -0
  38. package/dist/files/read-files.test.js.map +1 -1
  39. package/dist/files/update-files.js +1 -4
  40. package/dist/files/update-files.js.map +1 -1
  41. package/dist/main/codegen-types.d.ts +2 -0
  42. package/dist/main/codegen.js +7 -2
  43. package/dist/main/codegen.js.map +1 -1
  44. package/dist/main/codegen.test.d.ts +1 -0
  45. package/dist/main/codegen.test.js +20 -7
  46. package/dist/main/codegen.test.js.map +1 -1
  47. package/dist/main/common/cost-collector.d.ts +10 -14
  48. package/dist/main/common/cost-collector.js +83 -17
  49. package/dist/main/common/cost-collector.js.map +1 -1
  50. package/dist/main/interactive/codegen-interactive.test.d.ts +1 -0
  51. package/dist/main/interactive/codegen-interactive.test.js +2 -0
  52. package/dist/main/interactive/codegen-interactive.test.js.map +1 -1
  53. package/dist/main/interactive/codegen-worker.js +5 -2
  54. package/dist/main/interactive/codegen-worker.js.map +1 -1
  55. package/dist/main/ui/backend/api.js +3 -3
  56. package/dist/main/ui/backend/api.js.map +1 -1
  57. package/dist/main/ui/backend/server.js +7 -3
  58. package/dist/main/ui/backend/server.js.map +1 -1
  59. package/dist/main/ui/backend/service.d.ts +3 -2
  60. package/dist/main/ui/backend/service.js +8 -8
  61. package/dist/main/ui/backend/service.js.map +1 -1
  62. package/dist/main/ui/frontend/assets/index-Bj9ZkmiD.js +638 -0
  63. package/dist/main/ui/frontend/index.html +1 -1
  64. package/dist/prompt/ai-service-fallback.js +5 -0
  65. package/dist/prompt/ai-service-fallback.js.map +1 -1
  66. package/dist/prompt/function-calling-validate.js +70 -4
  67. package/dist/prompt/function-calling-validate.js.map +1 -1
  68. package/dist/prompt/function-calling.js +8 -0
  69. package/dist/prompt/function-calling.js.map +1 -1
  70. package/dist/prompt/function-defs/ask-question-reflect.d.ts +20 -0
  71. package/dist/prompt/function-defs/ask-question-reflect.js +21 -0
  72. package/dist/prompt/function-defs/ask-question-reflect.js.map +1 -0
  73. package/dist/prompt/function-defs/ask-question.d.ts +22 -11
  74. package/dist/prompt/function-defs/ask-question.js +42 -11
  75. package/dist/prompt/function-defs/ask-question.js.map +1 -1
  76. package/dist/prompt/function-defs/codegen-summary.d.ts +3 -3
  77. package/dist/prompt/function-defs/codegen-summary.js +4 -4
  78. package/dist/prompt/function-defs/codegen-summary.js.map +1 -1
  79. package/dist/prompt/function-defs/optimize-context.d.ts +16 -11
  80. package/dist/prompt/function-defs/optimize-context.js +16 -11
  81. package/dist/prompt/function-defs/optimize-context.js.map +1 -1
  82. package/dist/prompt/function-defs/read-history.d.ts +13 -0
  83. package/dist/prompt/function-defs/read-history.js +14 -0
  84. package/dist/prompt/function-defs/read-history.js.map +1 -0
  85. package/dist/prompt/function-defs/set-summaries.d.ts +31 -0
  86. package/dist/prompt/function-defs/set-summaries.js +32 -0
  87. package/dist/prompt/function-defs/set-summaries.js.map +1 -0
  88. package/dist/prompt/function-defs/update-history.d.ts +21 -0
  89. package/dist/prompt/function-defs/update-history.js +22 -0
  90. package/dist/prompt/function-defs/update-history.js.map +1 -0
  91. package/dist/prompt/limits.js +2 -2
  92. package/dist/prompt/limits.test.js +3 -3
  93. package/dist/prompt/prompt-codegen.js +25 -13
  94. package/dist/prompt/prompt-codegen.js.map +1 -1
  95. package/dist/prompt/prompt-service-ask-question.test.d.ts +1 -0
  96. package/dist/prompt/prompt-service-ask-question.test.js +74 -8
  97. package/dist/prompt/prompt-service-ask-question.test.js.map +1 -1
  98. package/dist/prompt/prompt-service.d.ts +0 -1
  99. package/dist/prompt/prompt-service.js +41 -21
  100. package/dist/prompt/prompt-service.js.map +1 -1
  101. package/dist/prompt/prompt-service.test.d.ts +1 -0
  102. package/dist/prompt/prompt-service.test.js +40 -30
  103. package/dist/prompt/prompt-service.test.js.map +1 -1
  104. package/dist/prompt/steps/step-ask-question-handlers.d.ts +10 -0
  105. package/dist/prompt/steps/step-ask-question-handlers.js +265 -0
  106. package/dist/prompt/steps/step-ask-question-handlers.js.map +1 -0
  107. package/dist/prompt/steps/step-ask-question-reflect.d.ts +4 -0
  108. package/dist/prompt/steps/step-ask-question-reflect.js +40 -0
  109. package/dist/prompt/steps/step-ask-question-reflect.js.map +1 -0
  110. package/dist/prompt/steps/step-ask-question-types.d.ts +60 -0
  111. package/dist/prompt/steps/step-ask-question-types.js +2 -0
  112. package/dist/prompt/steps/step-ask-question-types.js.map +1 -0
  113. package/dist/prompt/steps/step-ask-question.d.ts +2 -2
  114. package/dist/prompt/steps/step-ask-question.js +65 -82
  115. package/dist/prompt/steps/step-ask-question.js.map +1 -1
  116. package/dist/prompt/steps/step-context-optimization.d.ts +1 -3
  117. package/dist/prompt/steps/step-context-optimization.js +120 -73
  118. package/dist/prompt/steps/step-context-optimization.js.map +1 -1
  119. package/dist/prompt/steps/step-history-update.d.ts +5 -0
  120. package/dist/prompt/steps/step-history-update.js +54 -0
  121. package/dist/prompt/steps/step-history-update.js.map +1 -0
  122. package/dist/prompt/steps/step-summarization.d.ts +8 -0
  123. package/dist/prompt/steps/step-summarization.js +75 -0
  124. package/dist/prompt/steps/step-summarization.js.map +1 -0
  125. package/dist/prompt/steps/step-validate-recover.d.ts +2 -13
  126. package/dist/prompt/steps/step-validate-recover.js +3 -3
  127. package/dist/prompt/steps/step-validate-recover.js.map +1 -1
  128. package/dist/prompt/steps/step-verify-patch.d.ts +1 -2
  129. package/dist/prompt/steps/step-verify-patch.js +3 -10
  130. package/dist/prompt/steps/step-verify-patch.js.map +1 -1
  131. package/dist/prompt/steps/steps-types.d.ts +16 -0
  132. package/dist/prompt/steps/steps-utils.d.ts +7 -0
  133. package/dist/prompt/steps/steps-utils.js +11 -0
  134. package/dist/prompt/steps/steps-utils.js.map +1 -0
  135. package/dist/prompt/systemprompt.js +124 -12
  136. package/dist/prompt/systemprompt.js.map +1 -1
  137. package/dist/prompt/systemprompt.test.js +3 -3
  138. package/dist/prompt/systemprompt.test.js.map +1 -1
  139. package/package.json +5 -1
  140. package/dist/main/ui/frontend/assets/index-D9wcaSJU.js +0 -598
@@ -0,0 +1,14 @@
1
+ export const readHistory = {
2
+ name: 'readHistory',
3
+ description: 'This function reads the history from the cache and returns it as a string.',
4
+ parameters: {
5
+ type: 'object',
6
+ properties: {
7
+ dateTime: {
8
+ type: 'string',
9
+ },
10
+ },
11
+ required: [],
12
+ },
13
+ };
14
+ //# sourceMappingURL=read-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-history.js","sourceRoot":"","sources":["../../../src/prompt/function-defs/read-history.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,4EAA4E;IACzF,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;aACf;SACF;QACD,QAAQ,EAAE,EAAE;KACb;CACF,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Function definition for setSummaries
3
+ */
4
+ export declare const setSummaries: {
5
+ readonly name: "setSummaries";
6
+ readonly description: "Use this function to save summaries of files";
7
+ readonly parameters: {
8
+ readonly type: "object";
9
+ readonly properties: {
10
+ readonly summaries: {
11
+ readonly type: "array";
12
+ readonly description: "An array of results, each corresponding to an analyzed file, containing the absolute file path, and a brief summary.";
13
+ readonly items: {
14
+ readonly type: "object";
15
+ readonly properties: {
16
+ readonly filePath: {
17
+ readonly type: "string";
18
+ readonly description: "The absolute file path of the analyzed file.";
19
+ };
20
+ readonly summary: {
21
+ readonly type: "string";
22
+ readonly description: "A summary of the file's content, highlighting its main purpose, functionality, or details which may be useful for context optimization.";
23
+ };
24
+ };
25
+ readonly required: readonly ["filePath", "summary"];
26
+ };
27
+ };
28
+ };
29
+ readonly required: readonly ["summaries"];
30
+ };
31
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Function definition for setSummaries
3
+ */
4
+ export const setSummaries = {
5
+ name: 'setSummaries',
6
+ description: 'Use this function to save summaries of files',
7
+ parameters: {
8
+ type: 'object',
9
+ properties: {
10
+ summaries: {
11
+ type: 'array',
12
+ description: 'An array of results, each corresponding to an analyzed file, containing the absolute file path, and a brief summary.',
13
+ items: {
14
+ type: 'object',
15
+ properties: {
16
+ filePath: {
17
+ type: 'string',
18
+ description: 'The absolute file path of the analyzed file.',
19
+ },
20
+ summary: {
21
+ type: 'string',
22
+ description: "A summary of the file's content, highlighting its main purpose, functionality, or details which may be useful for context optimization.",
23
+ },
24
+ },
25
+ required: ['filePath', 'summary'],
26
+ },
27
+ },
28
+ },
29
+ required: ['summaries'],
30
+ },
31
+ };
32
+ //# sourceMappingURL=set-summaries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-summaries.js","sourceRoot":"","sources":["../../../src/prompt/function-defs/set-summaries.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,8CAA8C;IAC3D,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE;gBACT,IAAI,EAAE,OAAO;gBACb,WAAW,EACT,sHAAsH;gBACxH,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,QAAQ,EAAE;4BACR,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,8CAA8C;yBAC5D;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,QAAQ;4BACd,WAAW,EACT,yIAAyI;yBAC5I;qBACF;oBACD,QAAQ,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC;iBAClC;aACF;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,CAAC;KACxB;CACO,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Function definition for updateHistory
3
+ */
4
+ export declare const updateHistory: {
5
+ readonly name: "updateHistory";
6
+ readonly description: "Update the history.";
7
+ readonly parameters: {
8
+ readonly type: "object";
9
+ readonly properties: {
10
+ readonly recentConversationSummary: {
11
+ readonly type: "string";
12
+ readonly description: "Summary of recent conversation";
13
+ };
14
+ readonly newHistoryContent: {
15
+ readonly type: "string";
16
+ readonly description: "The new history content, combination of recent conversation summary, and current history";
17
+ };
18
+ };
19
+ readonly required: readonly ["recentConversationSummary", "newHistoryContent"];
20
+ };
21
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Function definition for updateHistory
3
+ */
4
+ export const updateHistory = {
5
+ name: 'updateHistory',
6
+ description: 'Update the history.',
7
+ parameters: {
8
+ type: 'object',
9
+ properties: {
10
+ recentConversationSummary: {
11
+ type: 'string',
12
+ description: 'Summary of recent conversation',
13
+ },
14
+ newHistoryContent: {
15
+ type: 'string',
16
+ description: 'The new history content, combination of recent conversation summary, and current history',
17
+ },
18
+ },
19
+ required: ['recentConversationSummary', 'newHistoryContent'],
20
+ },
21
+ };
22
+ //# sourceMappingURL=update-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-history.js","sourceRoot":"","sources":["../../../src/prompt/function-defs/update-history.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,qBAAqB;IAClC,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,yBAAyB,EAAE;gBACzB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;aAC9C;YACD,iBAAiB,EAAE;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0FAA0F;aACxG;SACF;QACD,QAAQ,EAAE,CAAC,2BAA2B,EAAE,mBAAmB,CAAC;KAC7D;CACO,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import assert from 'node:assert';
2
2
  import { estimateTokenCount } from './token-estimator.js';
3
- const SYSTEM_PROMPT_LIMIT = 1000;
4
- const CODEGEN_PROMPT_LIMIT = 800;
3
+ const SYSTEM_PROMPT_LIMIT = 2700;
4
+ const CODEGEN_PROMPT_LIMIT = 850;
5
5
  const SOURCE_CODE_LIMIT = 100000;
6
6
  function verifyPromptLimit(promptType, prompt, limit) {
7
7
  const tokenCount = estimateTokenCount(prompt);
@@ -7,8 +7,8 @@ describe('Prompt Limits', () => {
7
7
  expect(() => verifySystemPromptLimit(validPrompt)).not.toThrow();
8
8
  });
9
9
  it('should throw for a prompt exceeding the limit', () => {
10
- const invalidPrompt = 'A '.repeat(2000);
11
- expect(() => verifySystemPromptLimit(invalidPrompt)).toThrow('Token limit exceeded: 1300 > 1000');
10
+ const invalidPrompt = 'A '.repeat(5000);
11
+ expect(() => verifySystemPromptLimit(invalidPrompt)).toThrow('Token limit exceeded: 3250 > 2700');
12
12
  });
13
13
  });
14
14
  describe('verifyCodegenPromptLimit', () => {
@@ -18,7 +18,7 @@ describe('Prompt Limits', () => {
18
18
  });
19
19
  it('should throw for a prompt exceeding the limit', () => {
20
20
  const invalidPrompt = 'B '.repeat(10000);
21
- expect(() => verifyCodegenPromptLimit(invalidPrompt)).toThrow('Token limit exceeded: 6500 > 800');
21
+ expect(() => verifyCodegenPromptLimit(invalidPrompt)).toThrow('Token limit exceeded: 6500 > 850');
22
22
  });
23
23
  });
24
24
  describe('verifySourceCodeLimit', () => {
@@ -34,28 +34,37 @@ export function getCodeGenPrompt(options) {
34
34
  ? 'This is your task: ' + explicitPrompt + '\n\n'
35
35
  : codeGenFiles.length > 0
36
36
  ? `I have marked some files with the ${CODEGEN_TRIGGER} fragments:\n${codeGenFiles.join('\n')}\nYour task is to generate updates for those files according to the ${CODEGEN_TRIGGER} comments/context.`
37
- : `No files are marked with ${CODEGEN_TRIGGER} fragment, so you can consider doing changes in any file${askQuestion ? ', but you should consult me by asking a question first.' : ''}.`;
37
+ : `No files are marked with the ${CODEGEN_TRIGGER} fragment, so you can consider making changes in any file${askQuestion ? ', but you should consult me by asking a question first.' : ''}.`;
38
38
  const codeGenPrompt = `${taskPrompt}
39
39
 
40
- Before proceeding with code generation, please summarize the proposed updates by calling the \`codegenSummary\` function with the appropriate arguments.
40
+ Before proceeding with code generation, please:
41
41
 
42
- Ensure that you include:
42
+ 1. **Analyze the task and requirements**.
43
43
 
44
- - **\`explanation\`**: A brief description of the planned changes or reasoning for no changes.
44
+ 2. **Use the \`askQuestion\` function** to seek clarification if needed. For analysis requests, use the 'requestAnswer' actionType.
45
45
 
46
- - **\`fileUpdates\`**: A list of proposed file updates, each with required properties:
47
- - **\`path\`**: Absolute file path to be updated.
48
- - **\`updateToolName\`**: The tool to be used for the update (e.g., \`createFile\`, \`updateFile\`).
49
- - **\`prompt\`**: A detailed prompt summarizing the planned changes for this file.
50
- - **Other Properties**: Include any other necessary properties as per the \`codegenSummary\` function definition.
46
+ 3. **When you believe code changes are necessary**, use the 'confirmCodeGeneration' actionType to confirm with the user before proceeding.
51
47
 
52
- - **\`contextPaths\`**: A list of file paths that should be used as context for the code generation requests.
48
+ 4. **Only after confirmation**, summarize the plan of updates by calling the \`codegenSummary\` function with the appropriate arguments.
49
+
50
+ - Ensure that you include:
51
+ - **\`explanation\`**: A brief description of the planned changes or reasoning for no changes.
52
+ - **\`fileUpdates\`**: A list of proposed file updates, each with required properties:
53
+ - **\`path\`**: Absolute file path to be updated.
54
+ - **\`updateToolName\`**: The tool to be used for the update (e.g., \`createFile\`, \`updateFile\`).
55
+ - **\`prompt\`**: A detailed prompt summarizing the planned changes for this file.
56
+ - **Other Properties**: Include any other necessary properties as per the \`codegenSummary\` function definition.
57
+ - **\`contextPaths\`**: A list of file paths that should be used as context for the code generation requests.
58
+
59
+ 5. **Context Optimization**: Utilize the \`contextOptimization\` actionType to manage and optimize the context during code generation tasks. Generate a prompt using the \`contextOptimization\` property to guide the LLM in determining which parts of the context are most relevant to keep, enhancing efficiency and focus.
60
+
61
+ 6. **Check ActionType Selection**: Always verify that the correct \`actionType\` is being used, especially before requesting file content, to ensure the 'requestFilesContent' actionType is applied. This helps maintain vigilance and accuracy in task execution.
53
62
 
54
63
  ## My Requirements for Task Execution:
55
64
 
56
65
  ${importantTextPrompts ? `${importantTextPrompts}\n` : ''}
57
66
  ${considerAllFiles
58
- ? 'You are allowed to modify all files in the application regardless if they contain codegen fragments or not.'
67
+ ? 'You are allowed to modify all files in the application regardless of whether they contain codegen fragments.'
59
68
  : 'Do not modify files which do not contain the fragments.'}
60
69
  ${allowFileCreate ? 'You are allowed to create new files.' : 'Do not create new files. (request permission via `askQuestion`)'}
61
70
  ${allowFileDelete
@@ -69,7 +78,10 @@ ${vision ? 'You are allowed to analyze image assets.' : 'Do not analyze image as
69
78
  ${imagen
70
79
  ? 'You are allowed to generate images.'
71
80
  : 'You are not allowed to generate images. (request permission via `askQuestion`)'}
72
- `;
81
+
82
+ Remember to optimize token usage by reducing context when appropriate during askQuestion conversations. This will help avoid hitting rate limits and improve overall efficiency.
83
+
84
+ Start from generating codegen summary, this summary will be used as a context to generate updates, so make sure that it contains useful information.`;
73
85
  if (verbose) {
74
86
  console.log('Code gen prompt:');
75
87
  console.log(codeGenPrompt);
@@ -94,7 +106,7 @@ Lint command stderr:
94
106
  ${stderr}
95
107
  \`\`\`
96
108
 
97
- Please suggest changes to fix these lint errors.`;
109
+ Please suggest changes to fix these lint errors. Use the 'requestAnswer' actionType if you need any clarifications before proposing fixes.`;
98
110
  if (verbose) {
99
111
  console.log('Lint fix prompt:');
100
112
  console.log(lintFixPrompt);
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-codegen.js","sourceRoot":"","sources":["../../src/prompt/prompt-codegen.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,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C,CAAC,qCAAqC;QACvC,CAAC,CAAC,gFACN;;;;sJAIsJ,CAAC;IAErJ,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC;IAED,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAExC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;AAC5C,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,EAAE,OAAO,EAAkB,EAAE,MAAc,EAAE,MAAc;IAC3G,MAAM,aAAa,GAAG;;gBAER,OAAO;;;;EAIrB,MAAM;;;;;;EAMN,MAAM;;;2IAGmI,CAAC;IAE1I,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC;IAED,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAExC,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import '../cli/cli-params.js';
2
+ import '../files/cache-file.js';
2
3
  import '../files/read-files.js';
3
4
  import '../files/find-files.js';
@@ -4,6 +4,7 @@ import * as vertexAi from '../ai-service/vertex-ai.js';
4
4
  import * as prompts from '@inquirer/prompts';
5
5
  import { CancelablePromise } from '@inquirer/type';
6
6
  import '../cli/cli-params.js';
7
+ import '../files/cache-file.js';
7
8
  import '../files/read-files.js';
8
9
  import '../files/find-files.js';
9
10
  import { getCodeGenPrompt } from './prompt-codegen.js';
@@ -29,6 +30,7 @@ vi.mock('../cli/cli-params.js', () => ({
29
30
  cheap: false,
30
31
  askQuestion: true,
31
32
  }));
33
+ vi.mock('../files/cache-file.js');
32
34
  // Mock find-files module
33
35
  vi.mock('../files/find-files.js', () => ({
34
36
  getSourceFiles: () => [],
@@ -64,9 +66,8 @@ describe('promptService with askQuestion', () => {
64
66
  name: 'askQuestion',
65
67
  args: {
66
68
  content: 'Do you want to proceed with code generation?',
67
- shouldPrompt: true,
69
+ actionType: 'requestAnswer',
68
70
  promptNecessity: 80,
69
- stopCodegen: false,
70
71
  },
71
72
  },
72
73
  ];
@@ -75,9 +76,8 @@ describe('promptService with askQuestion', () => {
75
76
  name: 'askQuestion',
76
77
  args: {
77
78
  content: 'Ok lets go',
78
- shouldPrompt: false,
79
+ actionType: 'startCodeGeneration',
79
80
  promptNecessity: 80,
80
- stopCodegen: false,
81
81
  },
82
82
  },
83
83
  ];
@@ -113,9 +113,8 @@ describe('promptService with askQuestion', () => {
113
113
  name: 'askQuestion',
114
114
  args: {
115
115
  content: 'Stopping code generation as requested.',
116
- shouldPrompt: false,
117
116
  promptNecessity: 100,
118
- stopCodegen: true,
117
+ actionType: 'cancelCodeGeneration',
119
118
  },
120
119
  },
121
120
  ];
@@ -125,7 +124,7 @@ describe('promptService with askQuestion', () => {
125
124
  expect(result).toEqual([]);
126
125
  expect(console.log).toHaveBeenCalledWith('Assistant requested to stop code generation. Exiting...', undefined);
127
126
  });
128
- it('should proceed with code generation when askQuestion returns shouldPrompt: false', async () => {
127
+ it('should not proceed with code generation when no askQuestion requests', async () => {
129
128
  const mockAskQuestionCall = [];
130
129
  const mockCodegenSummary = [
131
130
  {
@@ -138,12 +137,79 @@ describe('promptService with askQuestion', () => {
138
137
  },
139
138
  ];
140
139
  vi.mocked(vertexAi.generateContent)
140
+ .mockResolvedValueOnce(mockAskQuestionCall)
141
141
  .mockResolvedValueOnce(mockAskQuestionCall)
142
142
  .mockResolvedValueOnce(mockCodegenSummary);
143
143
  await promptService(GENERATE_CONTENT_FNS, GENERATE_IMAGE_FNS, getCodeGenPrompt({ aiService: 'vertex-ai', disableContextOptimization: true, interactive: true }));
144
144
  expect(vertexAi.generateContent).toHaveBeenCalledTimes(2);
145
145
  expect(prompts.input).not.toHaveBeenCalled();
146
- expect(console.log).toHaveBeenCalledWith('Assistant did not ask a question. Proceeding with code generation.');
146
+ });
147
+ it('should handle self-reflection mechanism', async () => {
148
+ const mockAskQuestionCall = [
149
+ {
150
+ name: 'askQuestion',
151
+ args: {
152
+ content: 'Do you want to proceed with code generation?',
153
+ actionType: 'requestAnswer',
154
+ promptNecessity: 80,
155
+ },
156
+ },
157
+ ];
158
+ const mockAskQuestionReflectCall = [
159
+ {
160
+ name: 'askQuestionReflect',
161
+ args: {
162
+ shouldEscalate: 70,
163
+ reason: 'The response requires more advanced processing.',
164
+ },
165
+ },
166
+ ];
167
+ const mockAskQuestionReflectCall2 = [
168
+ {
169
+ name: 'askQuestionReflect',
170
+ args: {
171
+ shouldEscalate: 30,
172
+ reason: 'The response is ok.',
173
+ },
174
+ },
175
+ ];
176
+ const mockAskQuestionCall2 = [
177
+ {
178
+ name: 'askQuestion',
179
+ args: {
180
+ content: 'Startin code generation',
181
+ actionType: 'startCodeGeneration',
182
+ promptNecessity: 80,
183
+ },
184
+ },
185
+ ];
186
+ const mockCodegenSummary = [
187
+ {
188
+ name: 'codegenSummary',
189
+ args: {
190
+ fileUpdates: [],
191
+ contextPaths: [],
192
+ explanation: 'No updates needed',
193
+ },
194
+ },
195
+ ];
196
+ vi.mocked(vertexAi.generateContent)
197
+ .mockResolvedValueOnce(mockAskQuestionCall)
198
+ .mockResolvedValueOnce(mockAskQuestionReflectCall)
199
+ .mockResolvedValueOnce(mockAskQuestionCall)
200
+ .mockResolvedValueOnce(mockAskQuestionCall2)
201
+ .mockResolvedValueOnce(mockAskQuestionReflectCall2)
202
+ .mockResolvedValueOnce(mockCodegenSummary);
203
+ vi.mocked(prompts.input).mockImplementationOnce(() => CancelablePromise.resolve('Yes'));
204
+ await promptService(GENERATE_CONTENT_FNS, GENERATE_IMAGE_FNS, getCodeGenPrompt({
205
+ aiService: 'vertex-ai',
206
+ disableContextOptimization: true,
207
+ interactive: true,
208
+ askQuestion: true,
209
+ selfReflectionEnabled: true,
210
+ }));
211
+ expect(vertexAi.generateContent).toHaveBeenCalledTimes(6);
212
+ expect(console.log).toHaveBeenCalledWith('Received codegen summary, will collect partial updates', expect.any(Object));
147
213
  });
148
214
  });
149
215
  //# sourceMappingURL=prompt-service-ask-question.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-service-ask-question.test.js","sourceRoot":"","sources":["../../src/prompt/prompt-service-ask-question.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAEvD,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,sBAAsB,CAAC;AAC9B,OAAO,wBAAwB,CAAC;AAChC,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AAEzF,EAAE,CAAC,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAC5E,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IAClC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;CACf,CAAC,CAAC,CAAC;AACJ,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,mBAAmB,EAAE,KAAK;IAC1B,gBAAgB,EAAE,KAAK;IACvB,cAAc,EAAE,KAAK;IACrB,cAAc,EAAE,KAAK;IACrB,eAAe,EAAE,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C,GAAG,CAAC,CAAC,oBAAoB,CAAC,yDAAyD,EAAE,SAAS,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;QAChG,MAAM,mBAAmB,GAAmB,EAAE,CAAC;QAC/C,MAAM,kBAAkB,GAAG;YACzB;gBACE,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE;oBACJ,WAAW,EAAE,EAAE;oBACf,YAAY,EAAE,EAAE;oBAChB,WAAW,EAAE,mBAAmB;iBACjC;aACF;SACF,CAAC;QAEF,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;aAChC,qBAAqB,CAAC,mBAAmB,CAAC;aAC1C,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;QAE7C,MAAM,aAAa,CACjB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,0BAA0B,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAClG,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,oEAAoE,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"prompt-service-ask-question.test.js","sourceRoot":"","sources":["../../src/prompt/prompt-service-ask-question.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,Q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ACJ,WAAW,EAAE,EAAE;oBACf,YAAY,EAAE,EAAE;oBAChB,WAAW,EAAE,mBAAmB;iBACjC;aACF;SACF,CAAC;QAEF,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;aAChC,qBAAqB,CAAC,mBAAmB,CAAC;aAC1C,qBAAqB,CAAC,0BAA0B,CAAC;aACjD,qBAAqB,CAAC,mBAAmB,CAAC;aAC1C,qBAAqB,CAAC,oBAAoB,CAAC;aAC3C,qBAAqB,CAAC,2BAA2B,CAAC;aAClD,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;QAE7C,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,sBAAsB,CAC7C,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAA8B,CACpE,CAAC;QAEF,MAAM,aAAa,CACjB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,CAAC;YACf,SAAS,EAAE,WAAW;YACtB,0BAA0B,EAAE,IAAI;YAChC,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,IAAI;YACjB,qBAAqB,EAAE,IAAI;SAC5B,CAAC,CACH,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,oBAAoB,CACtC,wDAAwD,EACxD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CACnB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -17,6 +17,5 @@ declare function prepareMessages(codegen: CodegenPrompt): {
17
17
  contextSourceCode: (paths: string[], pathsOnly?: boolean) => string;
18
18
  imageAssets: string;
19
19
  partialPromptTemplate(path: string): string;
20
- invalidFunctionCall: string;
21
20
  };
22
21
  export {};
@@ -13,9 +13,10 @@ import { executeStepContextOptimization } from './steps/step-context-optimizatio
13
13
  import { StepResult } from './steps/steps-types.js';
14
14
  import { putSystemMessage } from '../main/common/content-bus.js';
15
15
  import { handleAiServiceFallback } from './ai-service-fallback.js';
16
+ import { summarizeSourceCode } from './steps/step-summarization.js';
17
+ import { executeStepHistoryUpdate, getCurrentHistory } from './steps/step-history-update.js';
16
18
  /** A function that communicates with model using */
17
19
  export async function promptService(generateContentFns, generateImageFns, codegenPrompt, waitIfPaused = () => Promise.resolve()) {
18
- const messages = prepareMessages(codegenPrompt);
19
20
  const generateContentFn = async (...args) => {
20
21
  return await handleAiServiceFallback(generateContentFns, codegenPrompt.options.aiService, codegenPrompt.options, ...args);
21
22
  };
@@ -23,16 +24,35 @@ export async function promptService(generateContentFns, generateImageFns, codege
23
24
  assert(codegenPrompt.options.imagen, 'imagen value must be provided');
24
25
  return generateImageFns[codegenPrompt.options.imagen](...args);
25
26
  };
26
- // First stage: generate code generation summary, which should not take a lot of output tokens
27
+ const { result, prompt } = await executePromptService(generateContentFn, generateImageFn, codegenPrompt, waitIfPaused);
28
+ if (codegenPrompt.options.historyEnabled) {
29
+ await executeStepHistoryUpdate(generateContentFn, prompt, codegenPrompt.options);
30
+ }
31
+ return result;
32
+ }
33
+ async function executePromptService(generateContentFn, generateImageFn, codegenPrompt, waitIfPaused = () => Promise.resolve()) {
34
+ const messages = prepareMessages(codegenPrompt);
35
+ // First stage: summarize the source code
36
+ if (!codegenPrompt.options.disableContextOptimization) {
37
+ await summarizeSourceCode(generateContentFn, getSourceCode({ forceAll: true }, codegenPrompt.options), codegenPrompt.options);
38
+ }
39
+ // Second stage: generate code generation summary, which should not take a lot of output tokens
27
40
  const getSourceCodeRequest = { name: 'getSourceCode' };
28
41
  const prompt = [
29
42
  { type: 'systemPrompt', systemPrompt: getSystemPrompt(codegenPrompt.options) },
30
43
  { type: 'user', text: messages.suggestSourceCode },
31
- { type: 'assistant', text: messages.requestSourceCode, functionCalls: [getSourceCodeRequest] },
44
+ {
45
+ type: 'assistant',
46
+ text: messages.requestSourceCode,
47
+ functionCalls: [getSourceCodeRequest, ...(codegenPrompt.options.historyEnabled ? [{ name: 'readHistory' }] : [])],
48
+ },
32
49
  ];
33
50
  const getSourceCodeResponse = {
34
51
  type: 'user',
35
- functionResponses: [{ name: 'getSourceCode', content: messages.sourceCode }],
52
+ functionResponses: [
53
+ { name: 'getSourceCode', content: messages.sourceCode },
54
+ ...(codegenPrompt.options.historyEnabled ? [{ name: 'readHistory', content: getCurrentHistory() }] : []),
55
+ ],
36
56
  cache: true,
37
57
  };
38
58
  prompt.push(getSourceCodeResponse);
@@ -50,17 +70,17 @@ export async function promptService(generateContentFns, generateImageFns, codege
50
70
  }
51
71
  // Execute the context optimization step
52
72
  if (!codegenPrompt.options.disableContextOptimization) {
53
- const sourceCode = JSON.parse(messages.sourceCode);
54
- const optimizationResult = await executeStepContextOptimization(generateContentFn, prompt, sourceCode, codegenPrompt.options);
73
+ const optimizationResult = await executeStepContextOptimization(generateContentFn, prompt, codegenPrompt.options);
55
74
  if (optimizationResult === StepResult.BREAK) {
56
- return [];
75
+ return { result: [], prompt };
57
76
  }
58
77
  }
59
78
  // Execute the ask question step
60
- if (codegenPrompt.options.askQuestion !== false &&
61
- (codegenPrompt.options.interactive || codegenPrompt.options.ui) &&
62
- (await executeStepAskQuestion(generateContentFn, prompt, functionDefs, codegenPrompt.options.temperature ?? 0.7, codegenPrompt.options.cheap ?? false, messages, codegenPrompt.options)) === StepResult.BREAK) {
63
- return [];
79
+ if (codegenPrompt.options.askQuestion !== false && (codegenPrompt.options.interactive || codegenPrompt.options.ui)) {
80
+ const askQuestionResult = await executeStepAskQuestion(generateContentFn, prompt, functionDefs, codegenPrompt.options.temperature ?? 0.7, messages, codegenPrompt.options);
81
+ if (askQuestionResult === StepResult.BREAK) {
82
+ return { result: [], prompt };
83
+ }
64
84
  }
65
85
  else if (codegenPrompt.options.askQuestion === false) {
66
86
  console.log('Ask question is not enabled.');
@@ -78,7 +98,7 @@ export async function promptService(generateContentFns, generateImageFns, codege
78
98
  if (codegenSummaryRequest) {
79
99
  // Second stage: for each file request the actual code updates
80
100
  putSystemMessage('Received codegen summary, will collect partial updates', codegenSummaryRequest.args);
81
- baseResult = await validateAndRecoverSingleResult(baseRequest, baseResult, messages, generateContentFn);
101
+ baseResult = await validateAndRecoverSingleResult(baseRequest, baseResult, generateContentFn);
82
102
  codegenSummaryRequest = baseResult.find((call) => call.name === 'codegenSummary');
83
103
  // Sometimes the result happens to be a string
84
104
  assert(Array.isArray(codegenSummaryRequest?.args?.fileUpdates), 'fileUpdates is not an array');
@@ -88,7 +108,7 @@ export async function promptService(generateContentFns, generateImageFns, codege
88
108
  // Monkey patch the initial getSourceCode, do not send parts of source code that are consider irrelevant
89
109
  getSourceCodeRequest.args = {
90
110
  filePaths: [
91
- ...codegenSummaryRequest.args.fileUpdates.map((file) => file.path),
111
+ ...codegenSummaryRequest.args.fileUpdates.map((file) => file.filePath),
92
112
  ...codegenSummaryRequest.args.contextPaths,
93
113
  ...(importantContext.files ?? []),
94
114
  ],
@@ -105,7 +125,7 @@ export async function promptService(generateContentFns, generateImageFns, codege
105
125
  });
106
126
  const result = [];
107
127
  for (const file of codegenSummaryRequest.args.fileUpdates) {
108
- putSystemMessage('Collecting partial update for: ' + file.path + ' using tool: ' + file.updateToolName, file);
128
+ putSystemMessage('Collecting partial update for: ' + file.filePath + ' using tool: ' + file.updateToolName, file);
109
129
  console.log('- Prompt:', file.prompt);
110
130
  console.log('- Temperature', file.temperature);
111
131
  console.log('- Cheap', file.cheap);
@@ -116,10 +136,10 @@ export async function promptService(generateContentFns, generateImageFns, codege
116
136
  await waitIfPaused();
117
137
  // this is needed, otherwise we will get an error
118
138
  if (prompt.slice(-1)[0].type === 'user') {
119
- prompt.slice(-1)[0].text = file.prompt ?? messages.partialPromptTemplate(file.path);
139
+ prompt.slice(-1)[0].text = file.prompt ?? messages.partialPromptTemplate(file.filePath);
120
140
  }
121
141
  else {
122
- prompt.push({ type: 'user', text: file.prompt ?? messages.partialPromptTemplate(file.path) });
142
+ prompt.push({ type: 'user', text: file.prompt ?? messages.partialPromptTemplate(file.filePath) });
123
143
  }
124
144
  if (codegenPrompt.options.vision && file.contextImageAssets) {
125
145
  prompt.slice(-1)[0].images = file.contextImageAssets.map((path) => ({
@@ -139,7 +159,7 @@ export async function promptService(generateContentFns, generateImageFns, codege
139
159
  let partialResult = await generateContentFn(...partialRequest);
140
160
  putSystemMessage('Received partial update', partialResult);
141
161
  // Validate if function call is compliant with the schema
142
- partialResult = await validateAndRecoverSingleResult(partialRequest, partialResult, messages, generateContentFn);
162
+ partialResult = await validateAndRecoverSingleResult(partialRequest, partialResult, generateContentFn);
143
163
  // Handle image generation requests
144
164
  const generateImageCall = partialResult.find((call) => call.name === 'generateImage');
145
165
  if (generateImageCall) {
@@ -148,21 +168,22 @@ export async function promptService(generateContentFns, generateImageFns, codege
148
168
  // Verify if patchFile is one of the functions called, and test if patch is valid and can be applied successfully
149
169
  const patchFileCall = partialResult.find((call) => call.name === 'patchFile');
150
170
  if (patchFileCall) {
151
- partialResult = await executeStepVerifyPatch(patchFileCall.args, generateContentFn, prompt, functionDefs, file.temperature ?? codegenPrompt.options.temperature, file.cheap === true, messages, codegenPrompt.options);
171
+ partialResult = await executeStepVerifyPatch(patchFileCall.args, generateContentFn, prompt, functionDefs, file.temperature ?? codegenPrompt.options.temperature, file.cheap === true, codegenPrompt.options);
152
172
  }
153
173
  // add the code gen result to the context, as the subsequent code gen may depend on the result
154
174
  prompt.push({ type: 'assistant', functionCalls: partialResult }, {
155
175
  type: 'user',
176
+ text: 'Update applied.',
156
177
  functionResponses: partialResult.map((call) => ({ name: call.name, call_id: call.id })),
157
178
  });
158
179
  result.push(...partialResult);
159
180
  }
160
- return result;
181
+ return { result, prompt };
161
182
  }
162
183
  else {
163
184
  // This is unexpected, if happens probably means no code updates.
164
185
  putSystemMessage('Did not receive codegen summary, returning result.');
165
- return baseResult;
186
+ return { result: baseResult, prompt };
166
187
  }
167
188
  }
168
189
  /**
@@ -182,7 +203,6 @@ function prepareMessages(codegen) {
182
203
  partialPromptTemplate(path) {
183
204
  return `Thank you for providing the summary, now suggest changes for the \`${path}\` file using appropriate tools.`;
184
205
  },
185
- invalidFunctionCall: 'Function call was invalid, please analyze the error and respond with corrected function call.',
186
206
  };
187
207
  }
188
208
  //# sourceMappingURL=prompt-service.js.map