MCPcopy Create free account
hub / github.com/Xyntopia/taskyon / parseChatResponse

Function parseChatResponse

src/modules/taskWorker.ts:197–251  ·  view source on GitHub ↗
(
  message: string,
  role: partialTaskDraft['role'] | undefined
)

Source from the content-addressed store, hash-verified

195}
196
197async function parseChatResponse(
198 message: string,
199 role: partialTaskDraft['role'] | undefined
200): Promise<{ taskDraft: partialTaskDraft; execute: boolean }> {
201 // parse the response and create a new task filled with the correct parameters
202 let yamlContent = message.trim();
203 // Use exec() to find a match
204 const yamlBlockRegex = /```(yaml|YAML)\n?([\s\S]*?)\n?```/;
205 const yamlMatch = yamlBlockRegex.exec(yamlContent);
206 if (yamlMatch) {
207 yamlContent = yamlMatch[1]; // Use the captured group
208 }
209 // Parse the extracted or original YAML content
210 const parsedYaml = load(yamlContent);
211 const toolChatResult = await yamlToolChatType.safeParseAsync(parsedYaml);
212 if (toolChatResult.success) {
213 console.log(toolChatResult);
214 if (toolChatResult.data.toolCommand) {
215 return {
216 taskDraft: {
217 role: 'function',
218 content: null,
219 context: {
220 function: {
221 name: toolChatResult.data.toolCommand.name,
222 arguments: toolChatResult.data.toolCommand.args,
223 },
224 },
225 },
226 execute: true,
227 };
228 } else {
229 return {
230 taskDraft: {
231 state: 'Completed',
232 role: role || 'assistant',
233 content:
234 toolChatResult.data.answer ||
235 toolChatResult.data.thought ||
236 message,
237 },
238 execute: false,
239 };
240 }
241 } else {
242 return {
243 taskDraft: {
244 state: 'Completed',
245 role: role || 'system',
246 content: toolChatResult.error.toString(),
247 },
248 execute: false,
249 };
250 }
251}
252
253async function generateFollowUpTasksFromResult(
254 finishedTask: LLMTask,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected