MCPcopy Create free account
hub / github.com/astercloud/aster / execute

Function execute

ui/src/composables/useAgentLoop.ts:135–389  ·  view source on GitHub ↗
(input: string, contextData: string = "", resumeState?: { history: any[]; approvedTool?: ApprovalRequest })

Source from the content-addressed store, hash-verified

133 * @param resumeState 恢复状态 (用于 HITL 恢复)
134 */
135 const execute = async (input: string, contextData: string = "", resumeState?: { history: any[]; approvedTool?: ApprovalRequest }): Promise<AgentExecutionResult> => {
136 isRunning.value = true;
137 isPaused.value = false;
138 currentOutput.value = "";
139
140 try {
141 const ws = await initConnection();
142 if (!ws) {
143 throw new Error("WebSocket connection failed");
144 }
145
146 return new Promise((resolve, reject) => {
147 let loopCount = 0;
148 let finalOutput = "";
149
150 // 设置消息处理器
151 const unsubscribe = ws.onMessage((message: any) => {
152 const { type, payload } = message;
153
154 switch (type) {
155 // 思考开始
156 case "think_chunk_start":
157 thinkingStore.startThinking(generateId("msg"));
158 emitThink({
159 stage: "任务规划",
160 reasoning: "分析用户请求...",
161 decision: "准备进入 Agent 执行循环",
162 });
163 break;
164
165 // 思考内容
166 case "think_chunk":
167 thinkingStore.handleThinkChunk(payload?.delta || "");
168 break;
169
170 // 思考结束
171 case "think_chunk_end":
172 thinkingStore.endThinking();
173 break;
174
175 // 文本增量
176 case "text_delta":
177 const delta = payload?.text || "";
178 finalOutput += delta;
179 currentOutput.value = finalOutput;
180 config.onTextDelta?.(delta);
181 break;
182
183 // 工具开始
184 case "tool_start":
185 case "agent_event":
186 if (payload?.type === "tool:start" || payload?.event?.type === "tool:start") {
187 const call = payload?.event?.Call || payload?.call || {};
188 const toolName = call.name || "unknown";
189 const args = call.arguments || {};
190
191 // 检查是否需要审批
192 if (sensitiveTools.includes(toolName)) {

Callers 1

approveAndResumeFunction · 0.70

Calls 5

generateIdFunction · 0.90
initConnectionFunction · 0.85
emitThinkFunction · 0.85
onMessageMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected