orquesta-cli 0.2.18 → 0.2.19

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.
@@ -6,36 +6,74 @@ import { LLMError, TokenLimitError, RateLimitError, ContextLengthError, } from '
6
6
  import { logger, isLLMLogEnabled } from '../../utils/logger.js';
7
7
  import { usageTracker } from '../usage-tracker.js';
8
8
  import { getForcedTier, getBatutaSessionId, setLastBatutaRoute } from '../routing-state.js';
9
- function coerceSyntheticToolCall(content) {
9
+ function extractTopLevelJsonObjects(s) {
10
+ const objects = [];
11
+ let depth = 0;
12
+ let startIdx = -1;
13
+ let inString = false;
14
+ let escaped = false;
15
+ for (let i = 0; i < s.length; i++) {
16
+ const ch = s[i];
17
+ if (inString) {
18
+ if (escaped)
19
+ escaped = false;
20
+ else if (ch === '\\')
21
+ escaped = true;
22
+ else if (ch === '"')
23
+ inString = false;
24
+ continue;
25
+ }
26
+ if (ch === '"') {
27
+ inString = true;
28
+ continue;
29
+ }
30
+ if (ch === '{') {
31
+ if (depth === 0)
32
+ startIdx = i;
33
+ depth++;
34
+ }
35
+ else if (ch === '}') {
36
+ if (depth > 0) {
37
+ depth--;
38
+ if (depth === 0 && startIdx !== -1) {
39
+ objects.push(s.slice(startIdx, i + 1));
40
+ startIdx = -1;
41
+ }
42
+ }
43
+ }
44
+ }
45
+ return objects;
46
+ }
47
+ function coerceSyntheticToolCalls(content) {
10
48
  const trimmed = content.trim();
11
49
  if (!trimmed || !trimmed.includes('"tool"'))
12
- return null;
50
+ return [];
13
51
  const cleaned = trimmed
14
52
  .replace(/^```(?:json)?\s*\n?/i, '')
15
53
  .replace(/\n?```\s*$/i, '')
16
54
  .trim();
17
- const start = cleaned.indexOf('{');
18
- const end = cleaned.lastIndexOf('}');
19
- if (start === -1 || end === -1 || end <= start)
20
- return null;
21
- let parsed;
22
- try {
23
- parsed = JSON.parse(cleaned.slice(start, end + 1));
24
- }
25
- catch {
26
- return null;
55
+ const calls = [];
56
+ for (const objStr of extractTopLevelJsonObjects(cleaned)) {
57
+ let parsed;
58
+ try {
59
+ parsed = JSON.parse(objStr);
60
+ }
61
+ catch {
62
+ continue;
63
+ }
64
+ if (!parsed || typeof parsed !== 'object')
65
+ continue;
66
+ const obj = parsed;
67
+ if (typeof obj.tool !== 'string' || !obj.tool)
68
+ continue;
69
+ const args = obj.arguments && typeof obj.arguments === 'object' ? obj.arguments : {};
70
+ calls.push({
71
+ id: `call_synth_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
72
+ type: 'function',
73
+ function: { name: obj.tool, arguments: JSON.stringify(args) },
74
+ });
27
75
  }
28
- if (!parsed || typeof parsed !== 'object')
29
- return null;
30
- const obj = parsed;
31
- if (typeof obj.tool !== 'string' || !obj.tool)
32
- return null;
33
- const args = obj.arguments && typeof obj.arguments === 'object' ? obj.arguments : {};
34
- return {
35
- id: `call_synth_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
36
- type: 'function',
37
- function: { name: obj.tool, arguments: JSON.stringify(args) },
38
- };
76
+ return calls;
39
77
  }
40
78
  function buildPerRequestHeaders() {
41
79
  const headers = {
@@ -533,12 +571,12 @@ export class LLMClient {
533
571
  const assistantMessage = choice.message;
534
572
  if ((!assistantMessage.tool_calls || assistantMessage.tool_calls.length === 0) &&
535
573
  typeof assistantMessage.content === 'string') {
536
- const coerced = coerceSyntheticToolCall(assistantMessage.content);
537
- if (coerced) {
538
- assistantMessage.tool_calls = [coerced];
574
+ const coerced = coerceSyntheticToolCalls(assistantMessage.content);
575
+ if (coerced.length > 0) {
576
+ assistantMessage.tool_calls = coerced;
539
577
  assistantMessage.content = '';
540
- logger.flow('Recovered synthetic tool call from plain-text content', {
541
- tool: coerced.function.name,
578
+ logger.flow('Recovered synthetic tool call(s) from plain-text content', {
579
+ tools: coerced.map(c => c.function.name).join(', '),
542
580
  });
543
581
  }
544
582
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orquesta-cli",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "Orquesta CLI - AI-powered coding assistant with team collaboration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",