genaicode 0.11.1 → 0.12.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.
- package/README.md +3 -9
- package/dist/ai-service/ai-studio.d.ts +18 -1
- package/dist/ai-service/ai-studio.js +92 -21
- package/dist/ai-service/ai-studio.js.map +1 -1
- package/dist/ai-service/anthropic.js +59 -25
- package/dist/ai-service/anthropic.js.map +1 -1
- package/dist/ai-service/common-types.d.ts +8 -3
- package/dist/ai-service/common.d.ts +5 -1
- package/dist/ai-service/common.js +9 -0
- package/dist/ai-service/common.js.map +1 -1
- package/dist/ai-service/dall-e.js +1 -0
- package/dist/ai-service/dall-e.js.map +1 -1
- package/dist/ai-service/github-models.d.ts +13 -0
- package/dist/ai-service/github-models.js +51 -0
- package/dist/ai-service/github-models.js.map +1 -0
- package/dist/ai-service/local-llm.js +2 -1
- package/dist/ai-service/local-llm.js.map +1 -1
- package/dist/ai-service/openai-responses.d.ts +9 -0
- package/dist/ai-service/openai-responses.js +286 -0
- package/dist/ai-service/openai-responses.js.map +1 -0
- package/dist/ai-service/openai.js +22 -10
- package/dist/ai-service/openai.js.map +1 -1
- package/dist/ai-service/service-configurations-types.d.ts +7 -7
- package/dist/ai-service/service-configurations.d.ts +1 -0
- package/dist/ai-service/service-configurations.js +41 -36
- package/dist/ai-service/service-configurations.js.map +1 -1
- package/dist/ai-service/vertex-ai-claude.js +2 -2
- package/dist/ai-service/vertex-ai-claude.js.map +1 -1
- package/dist/ai-service/vertex-ai.d.ts +1 -0
- package/dist/ai-service/vertex-ai.js +4 -332
- package/dist/ai-service/vertex-ai.js.map +1 -1
- package/dist/cli/cli-options.js +1 -1
- package/dist/cli/cli-options.js.map +1 -1
- package/dist/cli/validate-cli-params.js +1 -1
- package/dist/cli/validate-cli-params.js.map +1 -1
- package/dist/files/cache-file.d.ts +4 -0
- package/dist/files/cache-file.js +21 -0
- package/dist/files/cache-file.js.map +1 -1
- package/dist/files/find-files.d.ts +1 -0
- package/dist/files/find-files.js +4 -1
- package/dist/files/find-files.js.map +1 -1
- package/dist/files/source-code-utils.js +1 -1
- package/dist/files/summary-cache.d.ts +1 -1
- package/dist/files/summary-cache.js +1 -1
- package/dist/files/summary-cache.js.map +1 -1
- package/dist/main/codegen-utils.d.ts +6 -1
- package/dist/main/codegen-utils.js +21 -2
- package/dist/main/codegen-utils.js.map +1 -1
- package/dist/main/codegen.js +2 -2
- package/dist/main/codegen.js.map +1 -1
- package/dist/main/common/content-bus-types.d.ts +17 -1
- package/dist/main/common/content-bus.d.ts +3 -1
- package/dist/main/common/content-bus.js +23 -1
- package/dist/main/common/content-bus.js.map +1 -1
- package/dist/main/common/user-actions.d.ts +3 -0
- package/dist/main/common/user-actions.js +10 -0
- package/dist/main/common/user-actions.js.map +1 -1
- package/dist/main/config-lib.js +3 -2
- package/dist/main/config-lib.js.map +1 -1
- package/dist/main/config-types.d.ts +4 -0
- package/dist/main/config.js +4 -0
- package/dist/main/config.js.map +1 -1
- package/dist/main/interactive/select-ai-service.js +0 -1
- package/dist/main/interactive/select-ai-service.js.map +1 -1
- package/dist/main/interactive/user-action-handlers.js +7 -2
- package/dist/main/interactive/user-action-handlers.js.map +1 -1
- package/dist/main/knowledge/knowledge-store.d.ts +6 -0
- package/dist/main/knowledge/knowledge-store.js +128 -0
- package/dist/main/knowledge/knowledge-store.js.map +1 -0
- package/dist/main/knowledge/types.d.ts +20 -0
- package/dist/main/knowledge/types.js +2 -0
- package/dist/main/knowledge/types.js.map +1 -0
- package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.js +17 -3
- package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.js.map +1 -1
- package/dist/main/ui/common/api-types.d.ts +67 -4
- package/dist/main/ui/common/api-types.js +12 -1
- package/dist/main/ui/common/api-types.js.map +1 -1
- package/dist/main/ui/frontend/assets/index-j9Oi9iiP.js +2635 -0
- package/dist/main/ui/frontend/index.html +1 -1
- package/dist/main/ui/user-action-handlers.js +7 -1
- package/dist/main/ui/user-action-handlers.js.map +1 -1
- package/dist/project-profiles/types.d.ts +4 -4
- package/dist/project-profiles/types.js +4 -4
- package/dist/project-profiles/types.js.map +1 -1
- package/dist/prompt/function-calling-validate.js +2 -1
- package/dist/prompt/function-calling-validate.js.map +1 -1
- package/dist/prompt/function-calling.js +4 -0
- package/dist/prompt/function-calling.js.map +1 -1
- package/dist/prompt/function-defs/ask-question.js +4 -0
- package/dist/prompt/function-defs/ask-question.js.map +1 -1
- package/dist/prompt/function-defs/container-task-commands.d.ts +10 -0
- package/dist/prompt/function-defs/container-task-commands.js +185 -0
- package/dist/prompt/function-defs/container-task-commands.js.map +1 -0
- package/dist/prompt/function-defs/run-container-task.d.ts +11 -0
- package/dist/prompt/function-defs/run-container-task.js +41 -0
- package/dist/prompt/function-defs/run-container-task.js.map +1 -0
- package/dist/prompt/function-defs/web-search.d.ts +9 -0
- package/dist/prompt/function-defs/web-search.js +16 -0
- package/dist/prompt/function-defs/web-search.js.map +1 -0
- package/dist/prompt/limits.js +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.d.ts +7 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.js +301 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.d.ts +12 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.js +41 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/complete-task.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/complete-task.js +49 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/complete-task.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-from-container.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-from-container.js +190 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-from-container.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-to-container.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-to-container.js +139 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-to-container.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/edit-file.d.ts +10 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/edit-file.js +93 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/edit-file.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/fail-task.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/fail-task.js +72 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/fail-task.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/gain-knowledge.d.ts +10 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/gain-knowledge.js +125 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/gain-knowledge.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/interrupt-controller.d.ts +19 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/interrupt-controller.js +33 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/interrupt-controller.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/query-knowledge.d.ts +8 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/query-knowledge.js +85 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/query-knowledge.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/request-secret.d.ts +6 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/request-secret.js +122 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/request-secret.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/run-command.d.ts +7 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/run-command.js +146 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/run-command.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/send-message.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/send-message.js +56 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/send-message.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/set-execution-plan.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/set-execution-plan.js +56 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/set-execution-plan.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/update-execution-plan.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/update-execution-plan.js +39 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/update-execution-plan.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/view-file.d.ts +10 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/view-file.js +95 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/view-file.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/web-search.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/web-search.js +96 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/web-search.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/wrap-context.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/wrap-context.js +123 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/wrap-context.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.d.ts +34 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.js +332 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.d.ts +11 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.js +50 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.d.ts +28 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.js +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.js +202 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-types.d.ts +52 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-types.js +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-types.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-check.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-check.js +15 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-check.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-utils.d.ts +50 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-utils.js +358 -0
- package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-utils.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-compound-action.js +2 -2
- package/dist/prompt/steps/step-ask-question/handlers/handle-compound-action.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-explore-external-directories.js +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-explore-external-directories.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-genaicode-help.js +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-genaicode-help.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-generate-image.js +2 -2
- package/dist/prompt/steps/step-ask-question/handlers/handle-generate-image.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-perform-analysis.js +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-perform-analysis.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-run-container-task.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-run-container-task.js +7 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-run-container-task.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/handle-web-search.d.ts +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-web-search.js +85 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-web-search.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +1 -1
- package/dist/prompt/steps/step-ask-question/step-ask-question.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question.js +11 -1
- package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -1
- package/dist/prompt/steps/step-codegen-planning.js +1 -1
- package/dist/prompt/steps/step-codegen-planning.js.map +1 -1
- package/dist/prompt/steps/step-summarization.js +17 -10
- package/dist/prompt/steps/step-summarization.js.map +1 -1
- package/dist/prompt/systemprompt.js +3 -0
- package/dist/prompt/systemprompt.js.map +1 -1
- package/dist/utils/docker-utils.d.ts +37 -0
- package/dist/utils/docker-utils.js +258 -0
- package/dist/utils/docker-utils.js.map +1 -0
- package/dist/vite-genaicode/vite-genaicode-plugin.js +8 -1
- package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
- package/package.json +13 -5
- package/dist/main/ui/frontend/assets/index-DylPpHEw.js +0 -2256
package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { putAssistantMessage, putSystemMessage, putUserMessage } from '../../../../../main/common/content-bus.js';
|
|
2
|
+
import { askUserForConfirmation, askUserForInput } from '../../../../../main/common/user-actions.js';
|
|
3
|
+
import { copyFromContainer, copyToContainer, executeCommand, listFilesInContainerArchive, } from '../../../../../utils/docker-utils.js';
|
|
4
|
+
export async function handleCompleteTask(props) {
|
|
5
|
+
const { actionResult, taskExecutionPrompt } = props;
|
|
6
|
+
const args = actionResult.args;
|
|
7
|
+
putSystemMessage('✅ Task marked as complete by internal operator.');
|
|
8
|
+
taskExecutionPrompt.push({
|
|
9
|
+
type: 'assistant',
|
|
10
|
+
text: 'Completing the task.',
|
|
11
|
+
functionCalls: [actionResult],
|
|
12
|
+
}, {
|
|
13
|
+
type: 'user',
|
|
14
|
+
functionResponses: [
|
|
15
|
+
{
|
|
16
|
+
name: 'completeTask',
|
|
17
|
+
call_id: actionResult.id || undefined,
|
|
18
|
+
content: 'Task completed successfully.',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
shouldBreakOuter: true,
|
|
24
|
+
success: true,
|
|
25
|
+
summary: args.summary,
|
|
26
|
+
commandsExecutedIncrement: 0,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export async function handleFailTask(props) {
|
|
30
|
+
const { actionResult, taskExecutionPrompt } = props;
|
|
31
|
+
const args = actionResult.args;
|
|
32
|
+
putSystemMessage('❌ Task marked as failed by internal operator.');
|
|
33
|
+
taskExecutionPrompt.push({
|
|
34
|
+
type: 'assistant',
|
|
35
|
+
text: 'Failing the task.',
|
|
36
|
+
functionCalls: [actionResult],
|
|
37
|
+
}, {
|
|
38
|
+
type: 'user',
|
|
39
|
+
functionResponses: [
|
|
40
|
+
{
|
|
41
|
+
name: 'failTask',
|
|
42
|
+
call_id: actionResult.id || undefined,
|
|
43
|
+
content: 'Task marked as failed.',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
shouldBreakOuter: true,
|
|
49
|
+
success: false,
|
|
50
|
+
summary: args.reason,
|
|
51
|
+
commandsExecutedIncrement: 0,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export async function handleWrapContext(props) {
|
|
55
|
+
const { actionResult, taskExecutionPrompt, computeContextMetrics, maxContextItems, maxContextSize } = props;
|
|
56
|
+
const args = actionResult.args;
|
|
57
|
+
if (!args?.summary) {
|
|
58
|
+
putSystemMessage('⚠️ wrapContext called without summary; ignoring.');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
putSystemMessage('🗂️ Context wrapped by internal operator.', args);
|
|
62
|
+
const assistantMsg = {
|
|
63
|
+
type: 'assistant',
|
|
64
|
+
text: 'Wrapping context for continued processing.',
|
|
65
|
+
functionCalls: [actionResult],
|
|
66
|
+
};
|
|
67
|
+
const userResp = {
|
|
68
|
+
type: 'user',
|
|
69
|
+
functionResponses: [
|
|
70
|
+
{
|
|
71
|
+
name: 'wrapContext',
|
|
72
|
+
call_id: actionResult.id || undefined,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
const previousWraps = taskExecutionPrompt.filter((item) => item.functionCalls?.some((call) => call.name === 'wrapContext') ||
|
|
77
|
+
item.functionResponses?.some((resp) => resp.name === 'wrapContext'));
|
|
78
|
+
for (const wrap of previousWraps) {
|
|
79
|
+
delete wrap.text;
|
|
80
|
+
wrap.functionCalls = wrap.functionCalls?.filter((call) => call.name === 'wrapContext');
|
|
81
|
+
wrap.functionResponses = wrap.functionResponses?.filter((resp) => resp.name === 'wrapContext');
|
|
82
|
+
}
|
|
83
|
+
taskExecutionPrompt.splice(0, taskExecutionPrompt.length);
|
|
84
|
+
taskExecutionPrompt.push(...previousWraps, assistantMsg, userResp);
|
|
85
|
+
const { messageCount, estimatedTokens } = computeContextMetrics();
|
|
86
|
+
if (messageCount < maxContextItems && estimatedTokens < maxContextSize) {
|
|
87
|
+
userResp.text = `The context is within limits: ${messageCount} messages, ${estimatedTokens} tokens is less than the maximum allowed: ${maxContextItems} messages, ${maxContextSize} tokens.`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
91
|
+
}
|
|
92
|
+
export async function handleSetExecutionPlan(props) {
|
|
93
|
+
const { actionResult, taskExecutionPrompt } = props;
|
|
94
|
+
const args = actionResult.args;
|
|
95
|
+
if (!args?.plan) {
|
|
96
|
+
putSystemMessage('⚠️ setExecutionPlan called without plan; ignoring.');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
putSystemMessage('📝 Execution plan recorded.', args);
|
|
100
|
+
taskExecutionPrompt.push({
|
|
101
|
+
type: 'assistant',
|
|
102
|
+
text: 'Setting execution plan.',
|
|
103
|
+
functionCalls: [actionResult],
|
|
104
|
+
}, {
|
|
105
|
+
type: 'user',
|
|
106
|
+
functionResponses: [{ name: 'setExecutionPlan', call_id: actionResult.id || undefined }],
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
110
|
+
}
|
|
111
|
+
export async function handleUpdateExecutionPlan(props) {
|
|
112
|
+
const { actionResult, taskExecutionPrompt } = props;
|
|
113
|
+
const args = actionResult.args;
|
|
114
|
+
if (!args?.progress) {
|
|
115
|
+
putSystemMessage('⚠️ updateExecutionPlan called without progress; ignoring.');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
putSystemMessage('📈 Execution plan updated.', args);
|
|
119
|
+
taskExecutionPrompt.push({
|
|
120
|
+
type: 'assistant',
|
|
121
|
+
text: 'Updating execution plan.',
|
|
122
|
+
functionCalls: [actionResult],
|
|
123
|
+
}, {
|
|
124
|
+
type: 'user',
|
|
125
|
+
functionResponses: [{ name: 'updateExecutionPlan', call_id: actionResult.id || undefined }],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
129
|
+
}
|
|
130
|
+
export async function handleSendMessage(props) {
|
|
131
|
+
const { actionResult, taskExecutionPrompt, options } = props;
|
|
132
|
+
const args = actionResult.args;
|
|
133
|
+
putAssistantMessage(args.message);
|
|
134
|
+
taskExecutionPrompt.push({
|
|
135
|
+
type: 'assistant',
|
|
136
|
+
functionCalls: [actionResult],
|
|
137
|
+
});
|
|
138
|
+
if (args.isQuestion) {
|
|
139
|
+
const response = await askUserForInput('Your answer', args.message, options);
|
|
140
|
+
putUserMessage(response.answer);
|
|
141
|
+
taskExecutionPrompt.push({
|
|
142
|
+
type: 'user',
|
|
143
|
+
text: response.answer,
|
|
144
|
+
functionResponses: [
|
|
145
|
+
{
|
|
146
|
+
name: 'sendMessage',
|
|
147
|
+
call_id: actionResult.id || undefined,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
taskExecutionPrompt.push({
|
|
154
|
+
type: 'user',
|
|
155
|
+
functionResponses: [
|
|
156
|
+
{
|
|
157
|
+
name: 'sendMessage',
|
|
158
|
+
call_id: actionResult.id || undefined,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
164
|
+
}
|
|
165
|
+
export async function handleRunCommand(props) {
|
|
166
|
+
const { actionResult, taskExecutionPrompt, container, maxOutputLength } = props;
|
|
167
|
+
const args = actionResult.args;
|
|
168
|
+
const { command, workingDir, reasoning, stdin, truncMode } = args;
|
|
169
|
+
putSystemMessage(`💿 Executing command: ${reasoning}`, args);
|
|
170
|
+
const { output, exitCode } = await executeCommand(container, command, stdin, workingDir);
|
|
171
|
+
let managedOutput = output;
|
|
172
|
+
if (output.length > maxOutputLength) {
|
|
173
|
+
if (truncMode === 'start') {
|
|
174
|
+
managedOutput = output.slice(0, maxOutputLength) + '\\n\\n[... output truncated for context management ...]';
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
managedOutput = '[... output truncated for context management ...]' + output.slice(-maxOutputLength);
|
|
178
|
+
}
|
|
179
|
+
putSystemMessage(`⚠️ Command output truncated (${output.length} -> ${managedOutput.length} chars)`);
|
|
180
|
+
}
|
|
181
|
+
putSystemMessage('Command executed', { managedOutput, exitCode });
|
|
182
|
+
taskExecutionPrompt.push({
|
|
183
|
+
type: 'assistant',
|
|
184
|
+
text: `Executing command with reasoning: ${reasoning}`,
|
|
185
|
+
functionCalls: [actionResult],
|
|
186
|
+
}, {
|
|
187
|
+
type: 'user',
|
|
188
|
+
functionResponses: [
|
|
189
|
+
{
|
|
190
|
+
name: 'runCommand',
|
|
191
|
+
call_id: actionResult.id || undefined,
|
|
192
|
+
content: `Command executed successfully.\\n\\nOutput:\\n${managedOutput}\\n\\nExit Code: ${exitCode}`,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
});
|
|
196
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 1 };
|
|
197
|
+
}
|
|
198
|
+
export async function handleCopyToContainer(props) {
|
|
199
|
+
const { actionResult, taskExecutionPrompt, container, options } = props;
|
|
200
|
+
const args = actionResult.args;
|
|
201
|
+
putAssistantMessage(`Preparing to copy from host path "${args.hostPath}" to container path "${args.containerPath}".`);
|
|
202
|
+
const confirmation = await askUserForConfirmation(`Do you want to proceed with the copy operation?`, true, options);
|
|
203
|
+
if (!confirmation.confirmed) {
|
|
204
|
+
putSystemMessage('Copy to container cancelled by user.');
|
|
205
|
+
taskExecutionPrompt.push({
|
|
206
|
+
type: 'assistant',
|
|
207
|
+
functionCalls: [actionResult],
|
|
208
|
+
}, {
|
|
209
|
+
type: 'user',
|
|
210
|
+
functionResponses: [
|
|
211
|
+
{
|
|
212
|
+
name: 'copyToContainer',
|
|
213
|
+
call_id: actionResult.id || undefined,
|
|
214
|
+
content: 'User cancelled the copy operation.',
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
await copyToContainer(container, args.hostPath, args.containerPath);
|
|
222
|
+
taskExecutionPrompt.push({
|
|
223
|
+
type: 'assistant',
|
|
224
|
+
functionCalls: [actionResult],
|
|
225
|
+
}, {
|
|
226
|
+
type: 'user',
|
|
227
|
+
functionResponses: [
|
|
228
|
+
{
|
|
229
|
+
name: 'copyToContainer',
|
|
230
|
+
call_id: actionResult.id || undefined,
|
|
231
|
+
content: `Successfully copied ${args.hostPath} to container path ${args.containerPath}.`,
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
238
|
+
putSystemMessage('❌ Error copying to container', { error: errorMessage });
|
|
239
|
+
taskExecutionPrompt.push({
|
|
240
|
+
type: 'assistant',
|
|
241
|
+
functionCalls: [actionResult],
|
|
242
|
+
}, {
|
|
243
|
+
type: 'user',
|
|
244
|
+
functionResponses: [
|
|
245
|
+
{
|
|
246
|
+
name: 'copyToContainer',
|
|
247
|
+
call_id: actionResult.id || undefined,
|
|
248
|
+
content: `Error: ${errorMessage}`,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
254
|
+
}
|
|
255
|
+
export async function handleCopyFromContainer(props) {
|
|
256
|
+
const { actionResult, taskExecutionPrompt, container, options } = props;
|
|
257
|
+
const args = actionResult.args;
|
|
258
|
+
try {
|
|
259
|
+
const filesToCopy = await listFilesInContainerArchive(container, args.containerPath);
|
|
260
|
+
if (filesToCopy.length === 0) {
|
|
261
|
+
const message = `No files found at container path "${args.containerPath}" to copy.`;
|
|
262
|
+
putSystemMessage(message);
|
|
263
|
+
taskExecutionPrompt.push({
|
|
264
|
+
type: 'assistant',
|
|
265
|
+
functionCalls: [actionResult],
|
|
266
|
+
}, {
|
|
267
|
+
type: 'user',
|
|
268
|
+
functionResponses: [
|
|
269
|
+
{
|
|
270
|
+
name: 'copyFromContainer',
|
|
271
|
+
call_id: actionResult.id || undefined,
|
|
272
|
+
content: message,
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
});
|
|
276
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
277
|
+
}
|
|
278
|
+
const fileListStr = filesToCopy.map((f) => ` - ${f}`).join('\\n');
|
|
279
|
+
putAssistantMessage(`The following files will be copied from container path "${args.containerPath}" to host path "${args.hostPath}":\\n${fileListStr}`);
|
|
280
|
+
const confirmation = await askUserForConfirmation(`Do you want to proceed?`, true, options);
|
|
281
|
+
if (!confirmation.confirmed) {
|
|
282
|
+
putSystemMessage('Copy from container cancelled by user.');
|
|
283
|
+
taskExecutionPrompt.push({
|
|
284
|
+
type: 'assistant',
|
|
285
|
+
functionCalls: [actionResult],
|
|
286
|
+
}, {
|
|
287
|
+
type: 'user',
|
|
288
|
+
functionResponses: [
|
|
289
|
+
{
|
|
290
|
+
name: 'copyFromContainer',
|
|
291
|
+
call_id: actionResult.id || undefined,
|
|
292
|
+
content: 'User cancelled the copy operation.',
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
297
|
+
}
|
|
298
|
+
await copyFromContainer(container, args.containerPath, args.hostPath);
|
|
299
|
+
taskExecutionPrompt.push({
|
|
300
|
+
type: 'assistant',
|
|
301
|
+
functionCalls: [actionResult],
|
|
302
|
+
}, {
|
|
303
|
+
type: 'user',
|
|
304
|
+
functionResponses: [
|
|
305
|
+
{
|
|
306
|
+
name: 'copyFromContainer',
|
|
307
|
+
call_id: actionResult.id || undefined,
|
|
308
|
+
content: `Successfully copied from container path ${args.containerPath} to ${args.hostPath}.`,
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
315
|
+
putSystemMessage('❌ Error copying from container', { error: errorMessage });
|
|
316
|
+
taskExecutionPrompt.push({
|
|
317
|
+
type: 'assistant',
|
|
318
|
+
functionCalls: [actionResult],
|
|
319
|
+
}, {
|
|
320
|
+
type: 'user',
|
|
321
|
+
functionResponses: [
|
|
322
|
+
{
|
|
323
|
+
name: 'copyFromContainer',
|
|
324
|
+
call_id: actionResult.id || undefined,
|
|
325
|
+
content: `Error: ${errorMessage}`,
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=container-command-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container-command-handlers.js","sourceRoot":"","sources":["../../../../../../src/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAClH,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AACrG,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,2BAA2B,GAC5B,MAAM,sCAAsC,CAAC;AA4B9C,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,KAA4E;IAE5E,MAAM,EAAE,YAAY,EAAE,mBAAmB,EAAE,GAAG,KAAK,CAAC;IACpD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAwB,CAAC;IAC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EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QAC5E,mBAAmB,CAAC,IAAI,CACtB;YACE,IAAI,EAAE,WAAW;YACjB,aAAa,EAAE,CAAC,YAAY,CAAC;SAC9B,EACD;YACE,IAAI,EAAE,MAAM;YACZ,iBAAiB,EAAE;gBACjB;oBACE,IAAI,EAAE,mBAAmB;oBACzB,OAAO,EAAE,YAAY,CAAC,EAAE,IAAI,SAAS;oBACrC,OAAO,EAAE,UAAU,YAAY,EAAE;iBAClC;aACF;SACF,CACF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAC,EAAE,CAAC;AACnE,CAAC"}
|
package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FunctionDef } from '../../../../../ai-service/common-types.js';
|
|
2
|
+
import { CommandHandler } from './container-commands-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Gets all function definitions for the container commands.
|
|
5
|
+
* It resolves any definition functions into concrete FunctionDef objects.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getContainerCommandDefs(): FunctionDef[];
|
|
8
|
+
/**
|
|
9
|
+
* Gets the handler for a specific command by name.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getContainerCommandHandler(name: string): CommandHandler | undefined;
|
package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { completeTaskDef, handleCompleteTask } from './commands/complete-task.js';
|
|
2
|
+
import { failTaskDef, handleFailTask } from './commands/fail-task.js';
|
|
3
|
+
import { setExecutionPlanDef, handleSetExecutionPlan } from './commands/set-execution-plan.js';
|
|
4
|
+
import { updateExecutionPlanDef, handleUpdateExecutionPlan } from './commands/update-execution-plan.js';
|
|
5
|
+
import { sendMessageDef, handleSendMessage } from './commands/send-message.js';
|
|
6
|
+
import { runCommandDef, handleRunCommand } from './commands/run-command.js';
|
|
7
|
+
import { getCopyToContainerDef, handleCopyToContainer } from './commands/copy-to-container.js';
|
|
8
|
+
import { getCopyFromContainerDef, handleCopyFromContainer } from './commands/copy-from-container.js';
|
|
9
|
+
import { handleWebSearch } from './commands/web-search.js';
|
|
10
|
+
import { webSearchDef } from '../../../../function-defs/web-search.js';
|
|
11
|
+
import { requestSecretDef, handleRequestSecret } from './commands/request-secret.js';
|
|
12
|
+
import { gainKnowledgeDef, handleGainKnowledge } from './commands/gain-knowledge.js';
|
|
13
|
+
import { queryKnowledgeDef, handleQueryKnowledge } from './commands/query-knowledge.js';
|
|
14
|
+
import { viewFileDef, handleViewFile } from './commands/view-file.js';
|
|
15
|
+
import { editFileDef, handleEditFile } from './commands/edit-file.js';
|
|
16
|
+
const commandRegistry = new Map();
|
|
17
|
+
function registerCommand(name, def, handler) {
|
|
18
|
+
commandRegistry.set(name, { def, handler: handler });
|
|
19
|
+
}
|
|
20
|
+
// Register all available commands
|
|
21
|
+
registerCommand('completeTask', completeTaskDef, handleCompleteTask);
|
|
22
|
+
registerCommand('failTask', failTaskDef, handleFailTask);
|
|
23
|
+
registerCommand('setExecutionPlan', setExecutionPlanDef, handleSetExecutionPlan);
|
|
24
|
+
registerCommand('updateExecutionPlan', updateExecutionPlanDef, handleUpdateExecutionPlan);
|
|
25
|
+
registerCommand('sendMessage', sendMessageDef, handleSendMessage);
|
|
26
|
+
registerCommand('runCommand', runCommandDef, handleRunCommand);
|
|
27
|
+
registerCommand('copyToContainer', getCopyToContainerDef, handleCopyToContainer);
|
|
28
|
+
registerCommand('copyFromContainer', getCopyFromContainerDef, handleCopyFromContainer);
|
|
29
|
+
registerCommand('webSearch', webSearchDef, handleWebSearch);
|
|
30
|
+
registerCommand('requestSecret', requestSecretDef, handleRequestSecret);
|
|
31
|
+
registerCommand('gainKnowledge', gainKnowledgeDef, handleGainKnowledge);
|
|
32
|
+
registerCommand('queryKnowledge', queryKnowledgeDef, handleQueryKnowledge);
|
|
33
|
+
registerCommand('viewFile', viewFileDef, handleViewFile);
|
|
34
|
+
registerCommand('editFile', editFileDef, handleEditFile);
|
|
35
|
+
/**
|
|
36
|
+
* Gets all function definitions for the container commands.
|
|
37
|
+
* It resolves any definition functions into concrete FunctionDef objects.
|
|
38
|
+
*/
|
|
39
|
+
export function getContainerCommandDefs() {
|
|
40
|
+
return Array.from(commandRegistry.values()).map((command) => {
|
|
41
|
+
return typeof command.def === 'function' ? command.def() : command.def;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets the handler for a specific command by name.
|
|
46
|
+
*/
|
|
47
|
+
export function getContainerCommandHandler(name) {
|
|
48
|
+
return commandRegistry.get(name)?.handler;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=container-commands-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container-commands-registry.js","sourceRoot":"","sources":["../../../../../../src/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AACxG,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,0B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E,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;AACxE,eAAe,CAAC,eAAe,EAAE,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;AACxE,eAAe,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;AAC3E,eAAe,CAAC,UAAU,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AACzD,eAAe,CAAC,UAAU,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1D,OAAO,OAAO,OAAO,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACrD,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;AAC5C,CAAC"}
|
package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Docker from 'dockerode';
|
|
2
|
+
import { FunctionCall, GenerateContentFunction, PromptItem, FunctionDef } from '../../../../../ai-service/common-types.js';
|
|
3
|
+
import { CodegenOptions } from '../../../../../main/codegen-types.js';
|
|
4
|
+
export interface CommandHandlerBaseProps {
|
|
5
|
+
actionResult: FunctionCall;
|
|
6
|
+
systemPrompt: PromptItem;
|
|
7
|
+
taskPrompt: PromptItem;
|
|
8
|
+
taskExecutionPrompt: PromptItem[];
|
|
9
|
+
generateContentFn: GenerateContentFunction;
|
|
10
|
+
container: Docker.Container;
|
|
11
|
+
options: CodegenOptions;
|
|
12
|
+
maxContextItems: number;
|
|
13
|
+
maxContextSize: number;
|
|
14
|
+
maxOutputLength: number;
|
|
15
|
+
}
|
|
16
|
+
export type CommandHandlerResult = void | {
|
|
17
|
+
success?: boolean;
|
|
18
|
+
summary?: string;
|
|
19
|
+
commandsExecutedIncrement?: number;
|
|
20
|
+
shouldBreakOuter?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export interface CommandHandler<T extends CommandHandlerBaseProps = CommandHandlerBaseProps> {
|
|
23
|
+
(props: T): Promise<CommandHandlerResult>;
|
|
24
|
+
}
|
|
25
|
+
export interface Command<T extends CommandHandlerBaseProps = CommandHandlerBaseProps> {
|
|
26
|
+
def: FunctionDef | (() => FunctionDef);
|
|
27
|
+
handler: CommandHandler<T>;
|
|
28
|
+
}
|
package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container-commands-types.js","sourceRoot":"","sources":["../../../../../../src/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.ts"],"names":[],"mappings":""}
|
package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import Docker from 'dockerode';
|
|
2
|
+
import { ModelType } from '../../../../../ai-service/common-types.js';
|
|
3
|
+
import { putAssistantMessage, putContainerLog, putSystemMessage, putUserMessage, } from '../../../../../main/common/content-bus.js';
|
|
4
|
+
import { askUserForConfirmationWithAnswer } from '../../../../../main/common/user-actions.js';
|
|
5
|
+
import { abortController } from '../../../../../main/common/abort-controller.js';
|
|
6
|
+
import { runContainerTaskDef } from '../../../../function-defs/run-container-task.js';
|
|
7
|
+
import { cleanupOrphanedContainers, createAndStartContainer, executeCommand, pullImage, stopContainer, } from './utils/docker-utils.js';
|
|
8
|
+
import { commandExecutionLoop } from './command-execution-loop.js';
|
|
9
|
+
import { getFunctionDefs } from '../../../../function-calling.js';
|
|
10
|
+
export async function runContainerTaskOrchestrator({ askQuestionCall, prompt, generateContentFn, options, waitIfPaused, }) {
|
|
11
|
+
const docker = new Docker({ socketPath: '/var/run/docker.sock' });
|
|
12
|
+
await cleanupOrphanedContainers(docker);
|
|
13
|
+
if (abortController?.signal.aborted) {
|
|
14
|
+
putContainerLog('warn', 'Container task aborted before start.');
|
|
15
|
+
putSystemMessage('Container task aborted before start.');
|
|
16
|
+
return { breakLoop: true, items: [] };
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
putContainerLog('info', 'Container task: generating proper task request');
|
|
20
|
+
const request = [
|
|
21
|
+
[
|
|
22
|
+
...prompt,
|
|
23
|
+
{
|
|
24
|
+
type: 'assistant',
|
|
25
|
+
text: askQuestionCall.args.message,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'user',
|
|
29
|
+
text: 'I understand that you want to run a container task. Please provide the Docker image and task description.',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
{
|
|
33
|
+
functionDefs: getFunctionDefs(),
|
|
34
|
+
requiredFunctionName: runContainerTaskDef.name,
|
|
35
|
+
temperature: 0.7,
|
|
36
|
+
modelType: ModelType.CHEAP,
|
|
37
|
+
expectedResponseType: {
|
|
38
|
+
text: false,
|
|
39
|
+
functionCall: true,
|
|
40
|
+
media: false,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
options,
|
|
44
|
+
];
|
|
45
|
+
const response = await generateContentFn(...request);
|
|
46
|
+
const runContainerTaskCall = response
|
|
47
|
+
.filter((item) => item.type === 'functionCall')
|
|
48
|
+
.map((item) => item.functionCall).find((call) => call.name === 'runContainerTask');
|
|
49
|
+
if (!runContainerTaskCall?.args?.image || !runContainerTaskCall.args.taskDescription) {
|
|
50
|
+
putContainerLog('error', 'Failed to get valid runContainerTask request');
|
|
51
|
+
putSystemMessage('❌ Failed to get valid runContainerTask request');
|
|
52
|
+
prompt.push({
|
|
53
|
+
type: 'assistant',
|
|
54
|
+
text: askQuestionCall.args.message,
|
|
55
|
+
}, {
|
|
56
|
+
type: 'user',
|
|
57
|
+
text: 'Failed to get valid runContainerTask request',
|
|
58
|
+
});
|
|
59
|
+
return { breakLoop: false, items: [] };
|
|
60
|
+
}
|
|
61
|
+
putAssistantMessage(`I would like to run a container task with image: ${runContainerTaskCall.args.image}`, runContainerTaskCall.args);
|
|
62
|
+
const confirmation = await askUserForConfirmationWithAnswer(`Do you want to run the task?`, 'Run task', 'Reject', true, options);
|
|
63
|
+
if (!confirmation.confirmed) {
|
|
64
|
+
putContainerLog('warn', 'Container task cancelled by user.');
|
|
65
|
+
putSystemMessage('Container task cancelled by user.');
|
|
66
|
+
if (confirmation.answer) {
|
|
67
|
+
putUserMessage(confirmation.answer);
|
|
68
|
+
}
|
|
69
|
+
prompt.push({
|
|
70
|
+
type: 'assistant',
|
|
71
|
+
text: askQuestionCall.args.message,
|
|
72
|
+
}, {
|
|
73
|
+
type: 'user',
|
|
74
|
+
text: 'I reject running the container task.' + (confirmation.answer ? ` ${confirmation.answer}` : ''),
|
|
75
|
+
});
|
|
76
|
+
return { breakLoop: false, items: [] };
|
|
77
|
+
}
|
|
78
|
+
prompt.push({
|
|
79
|
+
type: 'assistant',
|
|
80
|
+
text: askQuestionCall.args.message,
|
|
81
|
+
}, {
|
|
82
|
+
type: 'user',
|
|
83
|
+
text: 'I accept running the container task.' + (confirmation.answer ? ` ${confirmation.answer}` : ''),
|
|
84
|
+
});
|
|
85
|
+
const { image, taskDescription, workingDir } = runContainerTaskCall.args;
|
|
86
|
+
putContainerLog('info', `Starting container task with image: ${image}`);
|
|
87
|
+
putSystemMessage(`🐳 Starting container task with image: ${image}`);
|
|
88
|
+
if (confirmation.answer) {
|
|
89
|
+
putUserMessage(confirmation.answer);
|
|
90
|
+
}
|
|
91
|
+
if (abortController?.signal.aborted) {
|
|
92
|
+
putContainerLog('warn', 'Container task aborted before pulling image.');
|
|
93
|
+
putSystemMessage('Container task aborted by user.');
|
|
94
|
+
return { breakLoop: true, items: [] };
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
await pullImage(docker, image);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
101
|
+
putSystemMessage('❌ Failed to pull Docker image', { error: errorMessage });
|
|
102
|
+
// The pullImage function already logs the detailed error to the terminal.
|
|
103
|
+
prompt.push({
|
|
104
|
+
type: 'assistant',
|
|
105
|
+
text: askQuestionCall.args.message,
|
|
106
|
+
functionCalls: [runContainerTaskCall],
|
|
107
|
+
}, {
|
|
108
|
+
type: 'user',
|
|
109
|
+
functionResponses: [
|
|
110
|
+
{
|
|
111
|
+
name: 'runContainerTask',
|
|
112
|
+
call_id: runContainerTaskCall.id || undefined,
|
|
113
|
+
content: `Failed to pull Docker image: ${errorMessage}`,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
return { breakLoop: false, items: [] };
|
|
118
|
+
}
|
|
119
|
+
let container;
|
|
120
|
+
let onAbort;
|
|
121
|
+
try {
|
|
122
|
+
container = await createAndStartContainer(docker, image);
|
|
123
|
+
onAbort = () => {
|
|
124
|
+
putContainerLog('warn', 'Execution interrupted by user. Stopping container...', undefined, 'docker');
|
|
125
|
+
// Best-effort stop; stopContainer is idempotent/safe via try/catch
|
|
126
|
+
if (container) {
|
|
127
|
+
stopContainer(container).catch(() => { });
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
abortController?.signal.addEventListener('abort', onAbort);
|
|
131
|
+
putContainerLog('info', 'Ensuring working directory exists.');
|
|
132
|
+
await executeCommand(container, '/bin/sh', `mkdir -p ${workingDir}`, '', '/');
|
|
133
|
+
putContainerLog('info', 'Entering command execution loop.');
|
|
134
|
+
const { success, summary } = await commandExecutionLoop(runContainerTaskCall.args, container, taskDescription, generateContentFn, options, waitIfPaused);
|
|
135
|
+
const finalMessage = `✅ Task finished with status: ${success ? 'Success' : 'Failed'}.
|
|
136
|
+
|
|
137
|
+
**Summary:**
|
|
138
|
+
${summary}`;
|
|
139
|
+
putContainerLog(success ? 'success' : 'error', `Task finished. Summary: ${summary}`);
|
|
140
|
+
putSystemMessage(finalMessage);
|
|
141
|
+
prompt.push({
|
|
142
|
+
type: 'assistant',
|
|
143
|
+
text: askQuestionCall.args.message,
|
|
144
|
+
functionCalls: [runContainerTaskCall],
|
|
145
|
+
}, {
|
|
146
|
+
type: 'user',
|
|
147
|
+
functionResponses: [
|
|
148
|
+
{
|
|
149
|
+
name: 'runContainerTask',
|
|
150
|
+
call_id: runContainerTaskCall.id || undefined,
|
|
151
|
+
content: finalMessage,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
return { breakLoop: false, items: [] };
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
159
|
+
putContainerLog('error', 'An error occurred during the container task', { error: errorMessage });
|
|
160
|
+
putSystemMessage('❌ An error occurred during the container task', {
|
|
161
|
+
error: errorMessage,
|
|
162
|
+
});
|
|
163
|
+
prompt.push({
|
|
164
|
+
type: 'assistant',
|
|
165
|
+
text: askQuestionCall.args.message,
|
|
166
|
+
functionCalls: [runContainerTaskCall],
|
|
167
|
+
}, {
|
|
168
|
+
type: 'user',
|
|
169
|
+
functionResponses: [
|
|
170
|
+
{
|
|
171
|
+
name: 'runContainerTask',
|
|
172
|
+
call_id: runContainerTaskCall.id || undefined,
|
|
173
|
+
content: `An error occurred during the container task: ${errorMessage}`,
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
return { breakLoop: false, items: [] };
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
if (container) {
|
|
181
|
+
await stopContainer(container);
|
|
182
|
+
if (onAbort) {
|
|
183
|
+
abortController?.signal.removeEventListener('abort', onAbort);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
190
|
+
putContainerLog('error', 'Error during container task initialization', { error: errorMessage });
|
|
191
|
+
putSystemMessage('Error during container task initialization', { error: errorMessage });
|
|
192
|
+
prompt.push({
|
|
193
|
+
type: 'assistant',
|
|
194
|
+
text: askQuestionCall.args.message,
|
|
195
|
+
}, {
|
|
196
|
+
type: 'user',
|
|
197
|
+
text: `Error during container task initialization: ${errorMessage}`,
|
|
198
|
+
});
|
|
199
|
+
return { breakLoop: false, items: [] };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=container-task-orchestrator.js.map
|