@fractal-solutions/qflow 1.0.33 → 1.0.35

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.
@@ -254,15 +254,17 @@ Parameters: ${params}`;
254
254
  }
255
255
  }
256
256
  parseLLMResponse(llmResponse) {
257
- let parsed;
258
257
  if (typeof llmResponse === 'string') {
259
- // Regex to find json content within ```json ... ``` or just ``` ... ```
260
- const markdownMatch = llmResponse.match(/```(?:json)?\s*([\s\S]*?)\s*```/);
261
- const jsonString = markdownMatch ? markdownMatch[1] : llmResponse;
258
+ let jsonString = llmResponse;
259
+ // Find the first '{' and the last '}' to isolate the JSON object
260
+ const firstBrace = jsonString.indexOf('{');
261
+ const lastBrace = jsonString.lastIndexOf('}');
262
+ if (firstBrace !== -1 && lastBrace > firstBrace) {
263
+ jsonString = jsonString.substring(firstBrace, lastBrace + 1);
264
+ }
262
265
  try {
263
- parsed = JSON.parse(jsonString);
266
+ const parsed = JSON.parse(jsonString);
264
267
  if (parsed.thought && Array.isArray(parsed.tool_calls)) {
265
- // This is a valid, complete tool call plan.
266
268
  return {
267
269
  thought: parsed.thought,
268
270
  toolCalls: parsed.tool_calls,
@@ -271,12 +273,9 @@ Parameters: ${params}`;
271
273
  }
272
274
  }
273
275
  catch (e) {
274
- // JSON.parse failed. This is expected if the LLM just sends a text response.
275
- // We will fall through and treat the original response as a thought.
276
+ // Parsing failed, fall through to treat the original string as a thought.
276
277
  }
277
- // If we are here, it means the response was either not valid JSON,
278
- // or it was valid JSON but didn't have the required 'thought' and 'tool_calls' keys.
279
- // In either case, we treat the entire original response as a thought with no tool calls.
278
+ // Fallback for plain text responses or malformed JSON.
280
279
  return { thought: llmResponse, toolCalls: [], parallel: false };
281
280
  }
282
281
  // This part of the function handles the case where llmResponse is an OBJECT,
@@ -294,7 +293,7 @@ Parameters: ${params}`;
294
293
  }
295
294
  else if (typeof message.content === 'string' && message.content.trim().startsWith('{')) {
296
295
  try {
297
- parsed = JSON.parse(message.content);
296
+ const parsed = JSON.parse(message.content);
298
297
  if (parsed.thought && Array.isArray(parsed.tool_calls)) {
299
298
  return {
300
299
  thought: parsed.thought,
@@ -17,7 +17,9 @@ export class UserInputNode extends AsyncNode {
17
17
  output: process.stdout
18
18
  });
19
19
  return new Promise((resolve) => {
20
- rl.question(prompt, (answer) => {
20
+ // ANSI escape codes for yellow text
21
+ const yellowPrompt = `\x1b[33m${prompt}\x1b[0m`;
22
+ rl.question(yellowPrompt, (answer) => {
21
23
  rl.close();
22
24
  resolve(answer);
23
25
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fractal-solutions/qflow",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "A lightweight and flexible JavaScript library for creating and managing workflows and agents.",
5
5
  "main": "dist/qflow.js",
6
6
  "types": "dist/qflow.d.ts",