orquesta-cli 0.2.19 → 0.2.21
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
|
-
|
|
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 {
|
|
@@ -66,6 +66,28 @@ export const CustomTextInput = ({ value, onChange, onSubmit, onHistoryPrev, onHi
|
|
|
66
66
|
setCursorPosition(newPos);
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
if (str.includes('\x1b[200~')) {
|
|
70
|
+
const startIdx = str.indexOf('\x1b[200~');
|
|
71
|
+
const endIdx = str.indexOf('\x1b[201~');
|
|
72
|
+
const before = str.slice(0, startIdx);
|
|
73
|
+
const body = endIdx !== -1 ? str.slice(startIdx + 6, endIdx) : str.slice(startIdx + 6);
|
|
74
|
+
const after = endIdx !== -1 ? str.slice(endIdx + 6) : '';
|
|
75
|
+
const pasteText = (before + body).replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '');
|
|
76
|
+
let valueAfterPaste = currentValue;
|
|
77
|
+
if (pasteText.length > 0) {
|
|
78
|
+
valueAfterPaste = currentValue.slice(0, currentCursor) + pasteText + currentValue.slice(currentCursor);
|
|
79
|
+
isInternalChangeRef.current = true;
|
|
80
|
+
onChangeRef.current(valueAfterPaste);
|
|
81
|
+
setCursorPosition(currentCursor + pasteText.length);
|
|
82
|
+
if (pasteText.split('\n').length > MULTILINE_COLLAPSE_THRESHOLD) {
|
|
83
|
+
setIsCollapsedViewRef.current(true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (/[\r\n]/.test(after) && onSubmitRef.current) {
|
|
87
|
+
onSubmitRef.current(valueAfterPaste);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
69
91
|
if (str.startsWith('\x1b')) {
|
|
70
92
|
if (str === '\x1b\r' || str === '\x1b\n' || str === '\x1b[13;2u' || str === '\x1b[27;2;13~') {
|
|
71
93
|
const newValue = currentValue.slice(0, currentCursor) + '\n' + currentValue.slice(currentCursor);
|