genaicode 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-service/ai-studio.js +1 -1
- package/dist/ai-service/ai-studio.js.map +1 -1
- package/dist/ai-service/anthropic.js +4 -1
- package/dist/ai-service/anthropic.js.map +1 -1
- package/dist/ai-service/common.js +1 -1
- package/dist/ai-service/common.js.map +1 -1
- package/dist/ai-service/service-configurations.js +2 -2
- package/dist/ai-service/service-configurations.js.map +1 -1
- package/dist/ai-service/vertex-ai.js +1 -1
- package/dist/ai-service/vertex-ai.js.map +1 -1
- package/dist/files/cache-file.d.ts +4 -1
- package/dist/files/cache-file.js.map +1 -1
- package/dist/files/file-id-utils.d.ts +7 -0
- package/dist/files/file-id-utils.js +25 -0
- package/dist/files/file-id-utils.js.map +1 -0
- package/dist/files/read-files.js +8 -8
- package/dist/files/read-files.js.map +1 -1
- package/dist/files/source-code-tree.js +3 -3
- package/dist/files/source-code-tree.js.map +1 -1
- package/dist/files/source-code-types.d.ts +21 -3
- package/dist/files/summary-cache.d.ts +3 -2
- package/dist/files/summary-cache.js +1 -1
- package/dist/files/summary-cache.js.map +1 -1
- package/dist/main/common/content-bus-types.d.ts +1 -1
- package/dist/main/common/content-bus.js +1 -1
- package/dist/main/common/content-bus.js.map +1 -1
- package/dist/main/ui/frontend/assets/{index-B0R1bgBi.js → index-COR2Vhaf.js} +226 -187
- package/dist/main/ui/frontend/index.html +1 -1
- package/dist/prompt/ai-service-fallback.js +5 -1
- package/dist/prompt/ai-service-fallback.js.map +1 -1
- package/dist/prompt/function-calling.js +4 -1
- package/dist/prompt/function-calling.js.map +1 -1
- package/dist/prompt/function-defs/ask-question.d.ts +1 -0
- package/dist/prompt/function-defs/ask-question.js +25 -0
- package/dist/prompt/function-defs/ask-question.js.map +1 -1
- package/dist/prompt/function-defs/context-compression.d.ts +25 -5
- package/dist/prompt/function-defs/context-compression.js +23 -8
- package/dist/prompt/function-defs/context-compression.js.map +1 -1
- package/dist/prompt/function-defs/extract-file-fragments.d.ts +27 -0
- package/dist/prompt/function-defs/extract-file-fragments.js +36 -0
- package/dist/prompt/function-defs/extract-file-fragments.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/code-generation.js +35 -24
- package/dist/prompt/steps/step-ask-question/handlers/code-generation.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/file-request-utils.d.ts +47 -0
- package/dist/prompt/steps/step-ask-question/handlers/file-request-utils.js +114 -0
- package/dist/prompt/steps/step-ask-question/handlers/file-request-utils.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-code-generation.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-code-generation.js +167 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-code-generation.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-confirm-code-generation.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-confirm-code-generation.js +34 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-confirm-code-generation.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-context-optimization.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-context-optimization.js +32 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-context-optimization.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-create-file.js +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-create-file.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-lint.d.ts +6 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-lint.js +103 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-lint.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-perform-analysis.js +2 -5
- package/dist/prompt/steps/step-ask-question/handlers/handle-perform-analysis.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-reasoning-inference.js +1 -3
- package/dist/prompt/steps/step-ask-question/handlers/handle-reasoning-inference.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-remove-files-from-context.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-remove-files-from-context.js +86 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-remove-files-from-context.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-files-content.d.ts +8 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-files-content.js +134 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-files-content.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-files-fragments.d.ts +8 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-files-fragments.js +171 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-files-fragments.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-permissions.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-permissions.js +69 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-permissions.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-update-file.js +2 -2
- package/dist/prompt/steps/step-ask-question/handlers/handle-update-file.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js +7 -3
- package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +7 -1
- package/dist/prompt/steps/step-ask-question/step-ask-question.js +15 -11
- package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -1
- package/dist/prompt/steps/step-codegen-planning.js +1 -3
- package/dist/prompt/steps/step-codegen-planning.js.map +1 -1
- package/dist/prompt/steps/step-context-compression.d.ts +1 -1
- package/dist/prompt/steps/step-context-compression.js +130 -34
- package/dist/prompt/steps/step-context-compression.js.map +1 -1
- package/dist/prompt/steps/step-context-optimization.js +7 -68
- package/dist/prompt/steps/step-context-optimization.js.map +1 -1
- package/dist/prompt/steps/step-generate-codegen-summary.js +1 -3
- package/dist/prompt/steps/step-generate-codegen-summary.js.map +1 -1
- package/dist/prompt/steps/step-history-update.js +1 -3
- package/dist/prompt/steps/step-history-update.js.map +1 -1
- package/dist/prompt/steps/step-process-file-updates.js +0 -3
- package/dist/prompt/steps/step-process-file-updates.js.map +1 -1
- package/dist/prompt/steps/step-summarization.d.ts +2 -1
- package/dist/prompt/steps/step-summarization.js +6 -5
- package/dist/prompt/steps/step-summarization.js.map +1 -1
- package/dist/prompt/steps/step-verify-patch.js +1 -3
- package/dist/prompt/steps/step-verify-patch.js.map +1 -1
- package/dist/prompt/systemprompt.js +1 -0
- package/dist/prompt/systemprompt.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ModelType } from '../../../../ai-service/common-types.js';
|
|
2
|
+
import { refreshFiles } from '../../../../files/find-files.js';
|
|
3
|
+
import { getSourceCode } from '../../../../files/read-files.js';
|
|
4
|
+
import { getExpandedContextPaths } from '../../../../files/source-code-utils.js';
|
|
5
|
+
import { putSystemMessage } from '../../../../main/common/content-bus.js';
|
|
6
|
+
import { getFunctionDefs } from '../../../function-calling.js';
|
|
7
|
+
import { isFileContentAlreadyProvided, categorizeLegitimateFiles } from './file-request-utils.js';
|
|
8
|
+
export async function handleRequestFilesContent({ askQuestionCall, options, prompt, generateContentFn, }) {
|
|
9
|
+
let requestFilesContentCall = await generateRequestFilesContentCall(generateContentFn, prompt, askQuestionCall, options, ModelType.CHEAP);
|
|
10
|
+
if (!requestFilesContentCall) {
|
|
11
|
+
return {
|
|
12
|
+
breakLoop: true,
|
|
13
|
+
items: [],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
let requestedFiles = getExpandedContextPaths(requestFilesContentCall.args?.filePaths ?? [], options);
|
|
17
|
+
putSystemMessage('Requesting files content', {
|
|
18
|
+
requestedFiles,
|
|
19
|
+
expandedRequestedFiles: requestedFiles.filter((file) => !requestFilesContentCall?.args?.filePaths?.includes(file)),
|
|
20
|
+
});
|
|
21
|
+
// Check which files are already provided in the conversation history
|
|
22
|
+
const alreadyProvidedFiles = requestedFiles.filter((file) => isFileContentAlreadyProvided(file, prompt));
|
|
23
|
+
if (alreadyProvidedFiles.length === requestedFiles.length) {
|
|
24
|
+
putSystemMessage('All requested files are already provided');
|
|
25
|
+
// All requested files are already provided
|
|
26
|
+
prompt.push({
|
|
27
|
+
type: 'assistant',
|
|
28
|
+
text: askQuestionCall.args?.message ?? '',
|
|
29
|
+
functionCalls: [requestFilesContentCall],
|
|
30
|
+
}, {
|
|
31
|
+
type: 'user',
|
|
32
|
+
text: 'The requested file contents are already provided in the conversation history.',
|
|
33
|
+
functionResponses: [
|
|
34
|
+
{
|
|
35
|
+
name: 'requestFilesContent',
|
|
36
|
+
call_id: requestFilesContentCall.id,
|
|
37
|
+
content: JSON.stringify({ filePaths: requestedFiles }),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
cache: true,
|
|
41
|
+
});
|
|
42
|
+
return { breakLoop: false, items: [] };
|
|
43
|
+
}
|
|
44
|
+
// Filter out already provided files
|
|
45
|
+
requestedFiles = requestedFiles.filter((file) => !isFileContentAlreadyProvided(file, prompt));
|
|
46
|
+
// the request may be caused be an appearance of a new file, so lets refresh
|
|
47
|
+
refreshFiles();
|
|
48
|
+
let { legitimateFiles, illegitimateFiles } = categorizeLegitimateFiles(requestedFiles);
|
|
49
|
+
if (illegitimateFiles.length > 0) {
|
|
50
|
+
requestFilesContentCall = await generateRequestFilesContentCall(generateContentFn, prompt, askQuestionCall, options,
|
|
51
|
+
// use non cheap mode, as maybe the cheap mode didn't provide correct files
|
|
52
|
+
ModelType.DEFAULT);
|
|
53
|
+
if (!requestFilesContentCall) {
|
|
54
|
+
return {
|
|
55
|
+
breakLoop: true,
|
|
56
|
+
items: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
requestedFiles = requestFilesContentCall.args?.filePaths ?? [];
|
|
60
|
+
const categorized = categorizeLegitimateFiles(requestedFiles);
|
|
61
|
+
legitimateFiles = categorized.legitimateFiles;
|
|
62
|
+
illegitimateFiles = categorized.illegitimateFiles;
|
|
63
|
+
}
|
|
64
|
+
const sourceCallId = (askQuestionCall.id ?? askQuestionCall.name) + '_source';
|
|
65
|
+
const assistant = {
|
|
66
|
+
type: 'assistant',
|
|
67
|
+
text: askQuestionCall.args?.message ?? '',
|
|
68
|
+
functionCalls: [
|
|
69
|
+
requestFilesContentCall,
|
|
70
|
+
{ name: 'getSourceCode', id: sourceCallId, args: { filePaths: legitimateFiles } },
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
const sourceCode = getSourceCode({ filterPaths: legitimateFiles, forceAll: true, ignoreImportantFiles: true }, options);
|
|
74
|
+
const user = {
|
|
75
|
+
type: 'user',
|
|
76
|
+
text: (alreadyProvidedFiles.length > 0
|
|
77
|
+
? // TODO: Maybe reference to some specific getSourceCode call id
|
|
78
|
+
`Some files were already provided in the conversation history:
|
|
79
|
+
${alreadyProvidedFiles.map((path) => `- ${path}`).join('\n')}
|
|
80
|
+
|
|
81
|
+
Providing content for the remaining files:
|
|
82
|
+
${requestedFiles.map((path) => `- ${path}`).join('\n')}`
|
|
83
|
+
: `All requested file contents have been provided:
|
|
84
|
+
${legitimateFiles.map((path) => `- ${path}`).join('\n')}`) +
|
|
85
|
+
(illegitimateFiles.length > 0
|
|
86
|
+
? `\n\nSome files are not legitimate and their content cannot be provided:
|
|
87
|
+
${illegitimateFiles.map((path) => `- ${path}`).join('\n')}`
|
|
88
|
+
: ''),
|
|
89
|
+
data: { legitimateFiles, illegitimateFiles },
|
|
90
|
+
functionResponses: [
|
|
91
|
+
{
|
|
92
|
+
name: 'requestFilesContent',
|
|
93
|
+
call_id: requestFilesContentCall.id,
|
|
94
|
+
content: JSON.stringify({ filePaths: legitimateFiles }),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'getSourceCode',
|
|
98
|
+
call_id: sourceCallId,
|
|
99
|
+
content: JSON.stringify(sourceCode),
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
cache: true,
|
|
103
|
+
};
|
|
104
|
+
putSystemMessage('Providing files content', {
|
|
105
|
+
requestedFiles,
|
|
106
|
+
legitimateFiles,
|
|
107
|
+
illegitimateFiles,
|
|
108
|
+
});
|
|
109
|
+
prompt.push(assistant, user);
|
|
110
|
+
return { breakLoop: false, items: [] };
|
|
111
|
+
}
|
|
112
|
+
export async function generateRequestFilesContentCall(generateContentFn, prompt, askQuestionCall, options, modelType) {
|
|
113
|
+
const req = [
|
|
114
|
+
[
|
|
115
|
+
...prompt,
|
|
116
|
+
{
|
|
117
|
+
type: 'assistant',
|
|
118
|
+
text: askQuestionCall.args?.message ?? '',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: 'user',
|
|
122
|
+
text: 'Yes, you can request the files contents.',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
getFunctionDefs(),
|
|
126
|
+
'requestFilesContent',
|
|
127
|
+
0.7,
|
|
128
|
+
modelType,
|
|
129
|
+
options,
|
|
130
|
+
];
|
|
131
|
+
const [requestFilesContentCall] = (await generateContentFn(...req));
|
|
132
|
+
return requestFilesContentCall;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=handle-request-files-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-request-files-content.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/handle-request-files-content.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAA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ACE,IAAI,EAAE,qBAAqB;gBAC3B,OAAO,EAAE,uBAAuB,CAAC,EAAE;gBACnC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;aACxD;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,YAAY;gBACrB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;aACpC;SACF;QACD,KAAK,EAAE,IAAI;KACZ,CAAC;IAEF,gBAAgB,CAAC,yBAAyB,EAAE;QAC1C,cAAc;QACd,eAAe;QACf,iBAAiB;KAClB,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAE7B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,iBAA0C,EAC1C,MAAoB,EACpB,eAAgC,EAChC,OAAuB,EACvB,SAAoB;IAEpB,MAAM,GAAG,GAAG;QACV;YACE,GAAG,MAAM;YACT;gBACE,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE;aAC1C;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,0CAA0C;aACjD;SACF;QACD,eAAe,EAAE;QACjB,qBAAqB;QACrB,GAAG;QACH,SAAS;QACT,OAAO;KACe,CAAC;IACzB,MAAM,CAAC,uBAAuB,CAAC,GAAG,CAAC,MAAM,iBAAiB,CAAC,GAAG,GAAG,CAAC,CAEjE,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GenerateContentFunction } from '../../../../ai-service/common-types.js';
|
|
2
|
+
import { PromptItem } from '../../../../ai-service/common-types.js';
|
|
3
|
+
import { FunctionCall } from '../../../../ai-service/common-types.js';
|
|
4
|
+
import { ModelType } from '../../../../ai-service/common-types.js';
|
|
5
|
+
import { CodegenOptions } from '../../../../main/codegen-types.js';
|
|
6
|
+
import { ActionHandlerProps, ActionResult, AskQuestionCall, RequestFilesFragmentsArgs } from '../step-ask-question-types.js';
|
|
7
|
+
export declare function handleRequestFilesFragments({ askQuestionCall, options, prompt, generateContentFn, }: ActionHandlerProps): Promise<ActionResult>;
|
|
8
|
+
export declare function generateRequestFilesFragmentsCall(generateContentFn: GenerateContentFunction, prompt: PromptItem[], askQuestionCall: AskQuestionCall, options: CodegenOptions, modelType: ModelType): Promise<FunctionCall<RequestFilesFragmentsArgs> | undefined>;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { ModelType } from '../../../../ai-service/common-types.js';
|
|
2
|
+
import { generateFileId } from '../../../../files/file-id-utils.js';
|
|
3
|
+
import { getSourceCode } from '../../../../files/read-files.js';
|
|
4
|
+
import { putSystemMessage } from '../../../../main/common/content-bus.js';
|
|
5
|
+
import { getFunctionDefs } from '../../../function-calling.js';
|
|
6
|
+
import { processFileRequests, generateFilesContentPrompt } from './file-request-utils.js';
|
|
7
|
+
export async function handleRequestFilesFragments({ askQuestionCall, options, prompt, generateContentFn, }) {
|
|
8
|
+
let requestFilesFragmentsCall = await generateRequestFilesFragmentsCall(generateContentFn, prompt, askQuestionCall, options, ModelType.CHEAP);
|
|
9
|
+
if (!requestFilesFragmentsCall) {
|
|
10
|
+
return {
|
|
11
|
+
breakLoop: true,
|
|
12
|
+
items: [],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const fragmentPrompt = requestFilesFragmentsCall.args?.fragmentPrompt;
|
|
16
|
+
if (!fragmentPrompt) {
|
|
17
|
+
putSystemMessage('No fragment prompt provided');
|
|
18
|
+
return {
|
|
19
|
+
breakLoop: true,
|
|
20
|
+
items: [],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Process file requests using the utility function
|
|
24
|
+
let { requestedFiles, alreadyProvidedFiles, legitimateFiles, illegitimateFiles } = processFileRequests(requestFilesFragmentsCall.args?.filePaths ?? [], prompt, options);
|
|
25
|
+
if (alreadyProvidedFiles.length === requestedFiles.length) {
|
|
26
|
+
putSystemMessage('All requested files are already provided');
|
|
27
|
+
prompt.push({
|
|
28
|
+
type: 'assistant',
|
|
29
|
+
text: askQuestionCall.args?.message ?? '',
|
|
30
|
+
functionCalls: [requestFilesFragmentsCall],
|
|
31
|
+
}, {
|
|
32
|
+
type: 'user',
|
|
33
|
+
text: 'The requested file fragments are already provided in the conversation history.',
|
|
34
|
+
functionResponses: [
|
|
35
|
+
{
|
|
36
|
+
name: 'requestFilesFragments',
|
|
37
|
+
call_id: requestFilesFragmentsCall.id,
|
|
38
|
+
content: JSON.stringify({ filePaths: requestedFiles }),
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
cache: true,
|
|
42
|
+
});
|
|
43
|
+
return { breakLoop: false, items: [] };
|
|
44
|
+
}
|
|
45
|
+
// If there are illegitimate files, try again with non-cheap mode
|
|
46
|
+
if (illegitimateFiles.length > 0) {
|
|
47
|
+
requestFilesFragmentsCall = await generateRequestFilesFragmentsCall(generateContentFn, prompt, askQuestionCall, options, ModelType.DEFAULT);
|
|
48
|
+
if (!requestFilesFragmentsCall) {
|
|
49
|
+
return {
|
|
50
|
+
breakLoop: true,
|
|
51
|
+
items: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const processed = processFileRequests(requestFilesFragmentsCall.args?.filePaths ?? [], prompt, options);
|
|
55
|
+
requestedFiles = processed.requestedFiles;
|
|
56
|
+
alreadyProvidedFiles = processed.alreadyProvidedFiles;
|
|
57
|
+
legitimateFiles = processed.legitimateFiles;
|
|
58
|
+
illegitimateFiles = processed.illegitimateFiles;
|
|
59
|
+
}
|
|
60
|
+
// Get the content of legitimate files
|
|
61
|
+
const sourceCodeMap = await getSourceCode({ filterPaths: legitimateFiles, forceAll: true, ignoreImportantFiles: true }, options);
|
|
62
|
+
// Extract fragments from files using LLM
|
|
63
|
+
const extractedFragments = await extractFragments(sourceCodeMap, fragmentPrompt, generateContentFn, options);
|
|
64
|
+
const sourceCallId = (askQuestionCall.id ?? askQuestionCall.name) + '_source';
|
|
65
|
+
const assistant = {
|
|
66
|
+
type: 'assistant',
|
|
67
|
+
text: askQuestionCall.args?.message ?? '',
|
|
68
|
+
functionCalls: [
|
|
69
|
+
requestFilesFragmentsCall,
|
|
70
|
+
{ name: 'getSourceCode', id: sourceCallId, args: { filePaths: legitimateFiles } },
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
const fragmentsSourceCode = {};
|
|
74
|
+
for (const fragment of extractedFragments.fragments) {
|
|
75
|
+
fragmentsSourceCode[fragment.filePath] = {
|
|
76
|
+
fileId: generateFileId(fragment.filePath),
|
|
77
|
+
fragments: [fragment.content],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const user = {
|
|
81
|
+
type: 'user',
|
|
82
|
+
text: generateFilesContentPrompt(alreadyProvidedFiles, requestedFiles, legitimateFiles, illegitimateFiles, 'fragments'),
|
|
83
|
+
data: { legitimateFiles, illegitimateFiles },
|
|
84
|
+
functionResponses: [
|
|
85
|
+
{
|
|
86
|
+
name: 'requestFilesFragments',
|
|
87
|
+
call_id: requestFilesFragmentsCall.id,
|
|
88
|
+
content: JSON.stringify({ filePaths: legitimateFiles }),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'getSourceCode',
|
|
92
|
+
call_id: sourceCallId,
|
|
93
|
+
content: JSON.stringify(fragmentsSourceCode),
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
cache: true,
|
|
97
|
+
};
|
|
98
|
+
putSystemMessage('Providing files fragments', {
|
|
99
|
+
requestedFiles,
|
|
100
|
+
legitimateFiles,
|
|
101
|
+
illegitimateFiles,
|
|
102
|
+
fragmentCount: extractedFragments.fragments.length,
|
|
103
|
+
});
|
|
104
|
+
prompt.push(assistant, user);
|
|
105
|
+
return { breakLoop: false, items: [] };
|
|
106
|
+
}
|
|
107
|
+
export async function generateRequestFilesFragmentsCall(generateContentFn, prompt, askQuestionCall, options, modelType) {
|
|
108
|
+
const [requestFilesFragmentsCall] = (await generateContentFn([
|
|
109
|
+
...prompt,
|
|
110
|
+
{
|
|
111
|
+
type: 'assistant',
|
|
112
|
+
text: askQuestionCall.args?.message ?? '',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: 'user',
|
|
116
|
+
text: 'Yes, you can request the file fragments.',
|
|
117
|
+
},
|
|
118
|
+
], getFunctionDefs(), 'requestFilesFragments', 0.7, modelType, options));
|
|
119
|
+
return requestFilesFragmentsCall;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Extract fragments from files using LLM with multi-file support
|
|
123
|
+
*/
|
|
124
|
+
async function extractFragments(sourceCodeMap, fragmentPrompt, generateContentFn, options) {
|
|
125
|
+
const filePaths = Object.keys(sourceCodeMap);
|
|
126
|
+
try {
|
|
127
|
+
// Process all files in a single LLM call
|
|
128
|
+
const [extractFragmentsCall] = (await generateContentFn([
|
|
129
|
+
{
|
|
130
|
+
type: 'systemPrompt',
|
|
131
|
+
systemPrompt: 'You are tasked with extracting relevant fragments from multiple source code files based on a given prompt. ' +
|
|
132
|
+
'Analyze each file thoroughly, identify meaningful sections that match the prompt criteria, and provide clear ' +
|
|
133
|
+
'explanations for your selections. Each fragment must be attributed to its source file for proper tracking.',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: 'assistant',
|
|
137
|
+
text: 'I will analyze the provided files and extract relevant fragments based on your prompt.',
|
|
138
|
+
functionCalls: [{ name: 'getSourceCode', args: { filePaths } }],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: 'user',
|
|
142
|
+
text: `Please extract relevant fragments from the provided files.\nExtraction prompt: ${fragmentPrompt}`,
|
|
143
|
+
functionResponses: [
|
|
144
|
+
{
|
|
145
|
+
name: 'getSourceCode',
|
|
146
|
+
content: JSON.stringify(sourceCodeMap),
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
], getFunctionDefs(), 'extractFileFragments', 0.2, ModelType.CHEAP, options));
|
|
151
|
+
if (!extractFragmentsCall?.args) {
|
|
152
|
+
putSystemMessage('Failed to extract fragments');
|
|
153
|
+
return {
|
|
154
|
+
filePaths,
|
|
155
|
+
fragments: [],
|
|
156
|
+
reasoning: 'Fragment extraction failed',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
putSystemMessage(`Successfully extracted ${extractFragmentsCall.args.fragments.length} fragments from ${filePaths.length} files`);
|
|
160
|
+
return extractFragmentsCall.args;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
putSystemMessage('Error during fragment extraction', { error });
|
|
164
|
+
return {
|
|
165
|
+
filePaths,
|
|
166
|
+
fragments: [],
|
|
167
|
+
reasoning: `Error during fragment extraction: ${error}`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=handle-request-files-fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-request-files-fragments.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/handle-request-files-fragments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAU/D,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE1F,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,EAChD,eAAe,EACf,OAAO,EACP,MAAM,EACN,iBAAiB,GAC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CAAyD,CAAC;QAE3D,IAAI,CAAC,oBAAoB,EAAE,IAAI,EAAE,CAAC;YAChC,gBAAgB,CAAC,6BAA6B,CAAC,CAAC;YAChD,OAAO;gBACL,SAAS;gBACT,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,4BAA4B;aACxC,CAAC;QACJ,CAAC;QAED,gBAAgB,CACd,0BAA0B,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,mBAAmB,SAAS,CAAC,MAAM,QAAQ,CAChH,CAAC;QACF,OAAO,oBAAoB,CAAC,IAAI,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAgB,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAChE,OAAO;YACL,SAAS;YACT,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,qCAAqC,KAAK,EAAE;SACxD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ModelType } from '../../../../ai-service/common-types.js';
|
|
2
|
+
import { askUserForConfirmation } from '../../../../main/common/user-actions.js';
|
|
3
|
+
import { getFunctionDefs } from '../../../function-calling.js';
|
|
4
|
+
export async function handleRequestPermissions({ askQuestionCall, options, prompt, generateContentFn, }) {
|
|
5
|
+
const [requestPermissionsCall] = (await generateContentFn([
|
|
6
|
+
...prompt,
|
|
7
|
+
{
|
|
8
|
+
type: 'assistant',
|
|
9
|
+
text: askQuestionCall.args?.message ?? '',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
type: 'user',
|
|
13
|
+
text: 'Yes, you can request the permissions.',
|
|
14
|
+
},
|
|
15
|
+
], getFunctionDefs(), 'requestPermissions', 0.7, ModelType.CHEAP, options));
|
|
16
|
+
if (!requestPermissionsCall) {
|
|
17
|
+
return {
|
|
18
|
+
breakLoop: true,
|
|
19
|
+
items: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const userConfirmation = await askUserForConfirmation('The assistant is requesting additional permissions. Do you want to grant them?', false, options);
|
|
23
|
+
const user = {
|
|
24
|
+
type: 'user',
|
|
25
|
+
text: userConfirmation ? 'Permissions granted.' : 'Permission request denied.',
|
|
26
|
+
functionResponses: [
|
|
27
|
+
{
|
|
28
|
+
name: 'requestPermissions',
|
|
29
|
+
call_id: requestPermissionsCall.id,
|
|
30
|
+
content: JSON.stringify({ confirmed: userConfirmation.confirmed }),
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
if (userConfirmation.confirmed) {
|
|
35
|
+
updatePermissions(requestPermissionsCall, options);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
breakLoop: false,
|
|
39
|
+
items: [
|
|
40
|
+
{
|
|
41
|
+
assistant: {
|
|
42
|
+
type: 'assistant',
|
|
43
|
+
text: askQuestionCall.args?.message ?? '',
|
|
44
|
+
functionCalls: [requestPermissionsCall],
|
|
45
|
+
},
|
|
46
|
+
user,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function updatePermissions(requestPermissionsCall, options) {
|
|
52
|
+
const permissions = requestPermissionsCall.args;
|
|
53
|
+
if (permissions) {
|
|
54
|
+
if ('enableImagen' in permissions && permissions.enableImagen) {
|
|
55
|
+
options.imagen = options.aiService === 'openai' ? 'dall-e' : 'vertex-ai';
|
|
56
|
+
}
|
|
57
|
+
if ('enableVision' in permissions && permissions.enableVision)
|
|
58
|
+
options.vision = true;
|
|
59
|
+
if ('allowDirectoryCreate' in permissions && permissions.allowDirectoryCreate)
|
|
60
|
+
options.allowDirectoryCreate = true;
|
|
61
|
+
if ('allowFileCreate' in permissions && permissions.allowFileCreate)
|
|
62
|
+
options.allowFileCreate = true;
|
|
63
|
+
if ('allowFileDelete' in permissions && permissions.allowFileDelete)
|
|
64
|
+
options.allowFileDelete = true;
|
|
65
|
+
if ('allowFileMove' in permissions && permissions.allowFileMove)
|
|
66
|
+
options.allowFileMove = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=handle-request-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-request-permissions.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/handle-request-permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAC7C,eAAe,EACf,OAAO,EACP,MAAM,EACN,iBAAiB,GACE;IACnB,MAAM,CAAC,sBAAsB,CAAC,GAAG,CAAC,MAAM,iBAAiB,CACvD;QACE,GAAG,MAAM;QACT;YACE,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE;SAC1C;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,uCAAuC;SAC9C;KACF,EACD,eAAe,EAAE,EACjB,oBAAoB,EACpB,GAAG,EACH,SAAS,CAAC,KAAK,EACf,OAAO,CACR,CAAuD,CAAC;IAEzD,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,OAAO;YACL,SAAS,EAAE,IAAI;YACf,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,sBAAsB,CACnD,gFAAgF,EAChF,KAAK,EACL,OAAO,CACR,CAAC;IAEF,MAAM,IAAI,GAAa;QACrB,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,4BAA4B;QAC9E,iBAAiB,EAAE;YACjB;gBACE,IAAI,EAAE,oBAAoB;gBAC1B,OAAO,EAAE,sBAAsB,CA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,WAAW,IAAI,WAAW,CAAC,aAAa;YAAE,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAChG,CAAC;AACH,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { ModelType } from '../../../../ai-service/common-types.js';
|
|
|
5
5
|
import { askUserForConfirmationWithAnswer } from '../../../../main/common/user-actions.js';
|
|
6
6
|
import { putSystemMessage, putUserMessage } from '../../../../main/common/content-bus.js';
|
|
7
7
|
import { refreshFiles } from '../../../../files/find-files.js';
|
|
8
|
-
import { generateRequestFilesContentCall } from './request-files-content.js';
|
|
8
|
+
import { generateRequestFilesContentCall } from './handle-request-files-content.js';
|
|
9
9
|
import { executeStepEnsureContext } from '../../step-ensure-context.js';
|
|
10
10
|
export const handleUpdateFile = async ({ askQuestionCall, options, prompt, generateContentFn, }) => {
|
|
11
11
|
putSystemMessage('File update requested.', askQuestionCall);
|
|
@@ -31,7 +31,7 @@ export const handleUpdateFile = async ({ askQuestionCall, options, prompt, gener
|
|
|
31
31
|
if (generateConfirmation.answer) {
|
|
32
32
|
putUserMessage(generateConfirmation.answer);
|
|
33
33
|
}
|
|
34
|
-
putSystemMessage('Content generation started.'
|
|
34
|
+
putSystemMessage('Content generation started.');
|
|
35
35
|
// Ensure file content is available in the context
|
|
36
36
|
const requestedFilesCall = await generateRequestFilesContentCall(generateContentFn, prompt, askQuestionCall, options, ModelType.CHEAP);
|
|
37
37
|
if (requestedFilesCall) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-update-file.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/handle-update-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,4DAA4D,CAAC;AAE3G,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"handle-update-file.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/handle-update-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,4DAA4D,CAAC;AAE3G,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExE,MAAM,CAAC,MAAM,gBAAgB,GAAkB,KAAK,EAAE,EACpD,eAAe,EACf,OAAO,EACP,MAAM,EACN,iBAAiB,GAClB,EAAyB,EAAE;IAC1B,gBAAgB,CAAC,wBAAwB,EAAE,eAAe,CAAC,CAAC;IAE5D,+EAA+E;IAC/E,MAAM,oBAAoB,GAAG,MAAM,gCAAgC,CACjE,oHAAoH,EACpH,kBAAkB,EAClB,2BAA2B,EAC3B,KAAK,EACL,OAAO,CACR,CAAC;IAEF,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,CAAC;QACpC,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,KAAK,EAAE;gBAC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EAAE,CAAC,cAAc,CAAC;qBAChC;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,MAAM;wBACZ,IAAI,EACF,wBAAwB;4BACxB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;4BAChE,wEAAwE;wBAC1E,iBAAiB,EAAE;4BACjB;gCACE,IAAI,EAAE,YAAY;gCAClB,OAAO,EAAE,cAAc,CAAC,EAAE;gCAC1B,OAAO,EAAE,EAAE;6BACZ;yBACF;qBACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -4,7 +4,6 @@ import { getSourceCode } from '../../../../files/read-files.js';
|
|
|
4
4
|
import { getExpandedContextPaths } from '../../../../files/source-code-utils.js';
|
|
5
5
|
import { putSystemMessage } from '../../../../main/common/content-bus.js';
|
|
6
6
|
import { getFunctionDefs } from '../../../function-calling.js';
|
|
7
|
-
import { validateAndRecoverSingleResult } from '../../step-validate-recover.js';
|
|
8
7
|
export async function handleRequestFilesContent({ askQuestionCall, options, prompt, generateContentFn, }) {
|
|
9
8
|
let requestFilesContentCall = await generateRequestFilesContentCall(generateContentFn, prompt, askQuestionCall, options, ModelType.CHEAP);
|
|
10
9
|
if (!requestFilesContentCall) {
|
|
@@ -21,6 +20,7 @@ export async function handleRequestFilesContent({ askQuestionCall, options, prom
|
|
|
21
20
|
// Check which files are already provided in the conversation history
|
|
22
21
|
const alreadyProvidedFiles = requestedFiles.filter((file) => isFileContentAlreadyProvided(file, prompt));
|
|
23
22
|
if (alreadyProvidedFiles.length === requestedFiles.length) {
|
|
23
|
+
putSystemMessage('All requested files are already provided');
|
|
24
24
|
// All requested files are already provided
|
|
25
25
|
prompt.push({
|
|
26
26
|
type: 'assistant',
|
|
@@ -100,6 +100,11 @@ ${illegitimateFiles.map((path) => `- ${path}`).join('\n')}`
|
|
|
100
100
|
],
|
|
101
101
|
cache: true,
|
|
102
102
|
};
|
|
103
|
+
putSystemMessage('Providing files content', {
|
|
104
|
+
requestedFiles,
|
|
105
|
+
legitimateFiles,
|
|
106
|
+
illegitimateFiles,
|
|
107
|
+
});
|
|
103
108
|
prompt.push(assistant, user);
|
|
104
109
|
return { breakLoop: false, items: [] };
|
|
105
110
|
}
|
|
@@ -122,8 +127,7 @@ export async function generateRequestFilesContentCall(generateContentFn, prompt,
|
|
|
122
127
|
modelType,
|
|
123
128
|
options,
|
|
124
129
|
];
|
|
125
|
-
const
|
|
126
|
-
const [requestFilesContentCall] = (await validateAndRecoverSingleResult(req, result, generateContentFn));
|
|
130
|
+
const [requestFilesContentCall] = (await generateContentFn(...req));
|
|
127
131
|
return requestFilesContentCall;
|
|
128
132
|
}
|
|
129
133
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-files-content.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/request-files-content.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"request-files-content.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/request-files-content.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,u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,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,OAAO,cAAc,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { PromptItemImage } from '../../../ai-service/common-types.js';
|
|
|
5
5
|
import { FunctionCall } from '../../../ai-service/common-types.js';
|
|
6
6
|
import { CodegenOptions } from '../../../main/codegen-types.js';
|
|
7
7
|
import { PluginActionType } from '../../../ai-service/service-configurations-types.js';
|
|
8
|
-
export type ActionType = 'codeGeneration' | 'sendMessage' | 'generateImage' | 'requestPermissions' | 'requestFilesContent' | 'removeFilesFromContext' | 'confirmCodeGeneration' | 'endConversation' | 'contextOptimization' | 'contextCompression' | 'searchCode' | 'lint' | 'updateFile' | 'performAnalysis' | 'createFile' | 'pullAppContext' | 'genaicodeHelp' | 'pushAppContext' | 'reasoningInference' | PluginActionType;
|
|
8
|
+
export type ActionType = 'codeGeneration' | 'sendMessage' | 'generateImage' | 'requestPermissions' | 'requestFilesContent' | 'removeFilesFromContext' | 'confirmCodeGeneration' | 'endConversation' | 'contextOptimization' | 'contextCompression' | 'searchCode' | 'lint' | 'updateFile' | 'performAnalysis' | 'createFile' | 'pullAppContext' | 'genaicodeHelp' | 'pushAppContext' | 'reasoningInference' | 'requestFilesFragments' | PluginActionType;
|
|
9
9
|
type AskQuestionArgs = {
|
|
10
10
|
actionType: ActionType;
|
|
11
11
|
message: string;
|
|
@@ -45,6 +45,12 @@ export type RequestPermissionsArgs = Record<'allowDirectoryCreate' | 'allowFileC
|
|
|
45
45
|
export type RequestFilesContentArgs = {
|
|
46
46
|
filePaths: string[];
|
|
47
47
|
};
|
|
48
|
+
export type RequestFilesFragmentsArgs = {
|
|
49
|
+
/** Array of file paths to extract fragments from */
|
|
50
|
+
filePaths: string[];
|
|
51
|
+
/** Prompt describing what information should be extracted from the files */
|
|
52
|
+
fragmentPrompt: string;
|
|
53
|
+
};
|
|
48
54
|
export type RemoveFilesFromContextArgs = {
|
|
49
55
|
filePaths: string[];
|
|
50
56
|
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { ModelType } from '../../../ai-service/common-types.js';
|
|
2
2
|
import { putAssistantMessage, putSystemMessage, putUserMessage } from '../../../main/common/content-bus.js';
|
|
3
3
|
import { abortController } from '../../../main/common/abort-controller.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { handleRemoveFilesFromContext } from './handlers/remove-files-from-context.js';
|
|
8
|
-
import { handleRequestPermissions } from './handlers/request-permissions.js';
|
|
4
|
+
import { handleRequestFilesContent } from './handlers/handle-request-files-content.js';
|
|
5
|
+
import { handleContextOptimization } from './handlers/handle-context-optimization.js';
|
|
6
|
+
import { handleRequestFilesFragments } from './handlers/handle-request-files-fragments.js';
|
|
7
|
+
import { handleRemoveFilesFromContext } from './handlers/handle-remove-files-from-context.js';
|
|
8
|
+
import { handleRequestPermissions } from './handlers/handle-request-permissions.js';
|
|
9
9
|
import { handleSendMessage } from './handlers/handle-send-message.js';
|
|
10
10
|
import { handleGenerateImage } from './handlers/handle-generate-image.js';
|
|
11
|
-
import { handleConfirmCodeGeneration } from './handlers/confirm-code-generation.js';
|
|
11
|
+
import { handleConfirmCodeGeneration } from './handlers/handle-confirm-code-generation.js';
|
|
12
12
|
import { handleEndConversation } from './handlers/handle-end-conversation.js';
|
|
13
|
-
import { handleLint } from './handlers/lint.js';
|
|
13
|
+
import { handleLint } from './handlers/handle-lint.js';
|
|
14
14
|
import { getRegisteredActionHandlers } from '../../../main/plugin-loader.js';
|
|
15
|
-
import { handleCodeGeneration } from './handlers/code-generation.js';
|
|
15
|
+
import { handleCodeGeneration } from './handlers/handle-code-generation.js';
|
|
16
16
|
import { handleSearchCode } from './handlers/handle-search-code.js';
|
|
17
17
|
import { handleUpdateFile } from './handlers/handle-update-file.js';
|
|
18
18
|
import { handlePerformAnalysis } from './handlers/handle-perform-analysis.js';
|
|
@@ -22,16 +22,20 @@ import { handlePushAppContext } from './handlers/handle-push-app-context.js';
|
|
|
22
22
|
import { handleReasoningInference } from './handlers/handle-reasoning-inference.js';
|
|
23
23
|
import { handleGenaicodeHelp } from './handlers/handle-genaicode-help.js';
|
|
24
24
|
import { handleContextCompression } from './handlers/handle-context-compression.js';
|
|
25
|
+
import { getUsageMetrics } from '../../../main/common/cost-collector.js';
|
|
25
26
|
export async function executeStepAskQuestion(generateContentFn, generateImageFn, prompt, functionDefs, waitIfPaused, temperature, options) {
|
|
26
27
|
putSystemMessage('Allowing the assistant to ask a question...');
|
|
27
28
|
while (!abortController?.signal.aborted) {
|
|
28
29
|
try {
|
|
30
|
+
// Calculate context size using the total tokens per day (this is not a perfect metric, but it's a good approximation)
|
|
31
|
+
const lastTokenCount = getUsageMetrics().total.tpd;
|
|
29
32
|
const askQuestionCall = await getAskQuestionCall(generateContentFn, prompt, functionDefs, temperature, options);
|
|
33
|
+
const totalTokens = getUsageMetrics().total.tpd - lastTokenCount;
|
|
30
34
|
if (!askQuestionCall) {
|
|
31
35
|
break;
|
|
32
36
|
}
|
|
33
37
|
if (askQuestionCall.args?.message) {
|
|
34
|
-
putAssistantMessage(askQuestionCall.args.message, askQuestionCall.args);
|
|
38
|
+
putAssistantMessage(askQuestionCall.args.message, { ...askQuestionCall.args, contextSize: totalTokens });
|
|
35
39
|
}
|
|
36
40
|
const actionType = askQuestionCall.args?.actionType;
|
|
37
41
|
if (actionType) {
|
|
@@ -91,8 +95,7 @@ async function getAskQuestionCall(generateContentFn, prompt, functionDefs, tempe
|
|
|
91
95
|
ModelType.CHEAP,
|
|
92
96
|
options,
|
|
93
97
|
];
|
|
94
|
-
|
|
95
|
-
askQuestionResult = await validateAndRecoverSingleResult(askQuestionRequest, askQuestionResult, generateContentFn);
|
|
98
|
+
const askQuestionResult = await generateContentFn(...askQuestionRequest);
|
|
96
99
|
return askQuestionResult.find((call) => call.name === 'askQuestion');
|
|
97
100
|
}
|
|
98
101
|
function getActionHandler(actionType) {
|
|
@@ -107,6 +110,7 @@ function getActionHandler(actionType) {
|
|
|
107
110
|
endConversation: handleEndConversation,
|
|
108
111
|
confirmCodeGeneration: handleConfirmCodeGeneration,
|
|
109
112
|
requestFilesContent: handleRequestFilesContent,
|
|
113
|
+
requestFilesFragments: handleRequestFilesFragments,
|
|
110
114
|
requestPermissions: handleRequestPermissions,
|
|
111
115
|
removeFilesFromContext: handleRemoveFilesFromContext,
|
|
112
116
|
sendMessage: handleSendMessage,
|