orquesta-cli 0.2.19 → 0.2.20

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.
@@ -51,9 +51,81 @@ Example:
51
51
  },
52
52
  },
53
53
  };
54
+ function extractTopLevelJsonObjects(s) {
55
+ const objects = [];
56
+ let depth = 0;
57
+ let startIdx = -1;
58
+ let inString = false;
59
+ let escaped = false;
60
+ for (let i = 0; i < s.length; i++) {
61
+ const ch = s[i];
62
+ if (inString) {
63
+ if (escaped)
64
+ escaped = false;
65
+ else if (ch === '\\')
66
+ escaped = true;
67
+ else if (ch === '"')
68
+ inString = false;
69
+ continue;
70
+ }
71
+ if (ch === '"') {
72
+ inString = true;
73
+ continue;
74
+ }
75
+ if (ch === '{') {
76
+ if (depth === 0)
77
+ startIdx = i;
78
+ depth++;
79
+ }
80
+ else if (ch === '}') {
81
+ if (depth > 0) {
82
+ depth--;
83
+ if (depth === 0 && startIdx !== -1) {
84
+ objects.push(s.slice(startIdx, i + 1));
85
+ startIdx = -1;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ return objects;
91
+ }
92
+ function unwrapNestedFinalResponse(message, depth = 0) {
93
+ if (depth > 5)
94
+ return message;
95
+ const trimmed = message.trim();
96
+ if (!trimmed.includes('"tool"') || !trimmed.includes('final_response'))
97
+ return message;
98
+ const cleaned = trimmed
99
+ .replace(/^```(?:json)?\s*\n?/i, '')
100
+ .replace(/\n?```\s*$/i, '')
101
+ .trim();
102
+ for (const objStr of extractTopLevelJsonObjects(cleaned)) {
103
+ let parsed;
104
+ try {
105
+ parsed = JSON.parse(objStr);
106
+ }
107
+ catch {
108
+ continue;
109
+ }
110
+ if (!parsed || typeof parsed !== 'object')
111
+ continue;
112
+ const obj = parsed;
113
+ if (obj.tool === 'final_response' && obj.arguments && typeof obj.arguments.message === 'string') {
114
+ return unwrapNestedFinalResponse(obj.arguments.message, depth + 1);
115
+ }
116
+ }
117
+ return message;
118
+ }
54
119
  async function executeFinalResponse(args) {
55
120
  logger.enter('executeFinalResponse', args);
56
- const message = args['message'];
121
+ let message = args['message'];
122
+ if (typeof message === 'string') {
123
+ const unwrapped = unwrapNestedFinalResponse(message);
124
+ if (unwrapped !== message) {
125
+ logger.flow('final_response: unwrapped nested synthetic tool-call JSON from message');
126
+ message = unwrapped;
127
+ }
128
+ }
57
129
  if (!message || typeof message !== 'string') {
58
130
  logger.warn('Missing or invalid message');
59
131
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orquesta-cli",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "Orquesta CLI - AI-powered coding assistant with team collaboration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",