open-agents-ai 0.187.283 → 0.187.285
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.
- package/dist/index.js +69 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -328305,6 +328305,37 @@ function extractToolJson(text) {
|
|
|
328305
328305
|
}
|
|
328306
328306
|
return null;
|
|
328307
328307
|
}
|
|
328308
|
+
function extractToolJsonLoose(text) {
|
|
328309
|
+
const stripped = text.replace(/```[a-zA-Z]*|```/g, "\n");
|
|
328310
|
+
const exact = extractToolJson(stripped);
|
|
328311
|
+
if (exact) return exact;
|
|
328312
|
+
const match = stripped.match(/[\{][\s\S]*[\}]/);
|
|
328313
|
+
if (match) {
|
|
328314
|
+
try {
|
|
328315
|
+
const obj = JSON.parse(match[0]);
|
|
328316
|
+
if (typeof obj.tool === "string") {
|
|
328317
|
+
const args2 = obj.args && typeof obj.args === "object" ? obj.args : {};
|
|
328318
|
+
return { name: obj.tool, args: args2 };
|
|
328319
|
+
}
|
|
328320
|
+
} catch {
|
|
328321
|
+
}
|
|
328322
|
+
}
|
|
328323
|
+
return null;
|
|
328324
|
+
}
|
|
328325
|
+
function stripToolJsonLines(text) {
|
|
328326
|
+
const lines = text.split(/\r?\n/);
|
|
328327
|
+
const kept = lines.filter((l2) => {
|
|
328328
|
+
const t2 = l2.trim();
|
|
328329
|
+
if (!t2.startsWith("{") || !t2.endsWith("}")) return true;
|
|
328330
|
+
try {
|
|
328331
|
+
const obj = JSON.parse(t2);
|
|
328332
|
+
return !(typeof obj.tool === "string");
|
|
328333
|
+
} catch {
|
|
328334
|
+
return true;
|
|
328335
|
+
}
|
|
328336
|
+
});
|
|
328337
|
+
return kept.join("\n").trim();
|
|
328338
|
+
}
|
|
328308
328339
|
var VAD_SILENCE_MS, MAX_SEGMENT_MS, MAX_CONTEXT_TURNS, SYSTEM_PROMPT2, MIN_SIGNAL_SCORE, NOISE_ONLY_RE, VoiceChatSession;
|
|
328309
328340
|
var init_voicechat = __esm({
|
|
328310
328341
|
"packages/cli/src/tui/voicechat.ts"() {
|
|
@@ -328330,6 +328361,7 @@ Rules:
|
|
|
328330
328361
|
toolRelay = null;
|
|
328331
328362
|
verbose = false;
|
|
328332
328363
|
debugSnr = false;
|
|
328364
|
+
heuristicsEnabled = true;
|
|
328333
328365
|
toolCatalogNote = null;
|
|
328334
328366
|
toolRelay = null;
|
|
328335
328367
|
// State machine
|
|
@@ -328370,6 +328402,7 @@ Rules:
|
|
|
328370
328402
|
this.toolRelay = opts.toolRelay ?? null;
|
|
328371
328403
|
this.verbose = Boolean(opts.verbose);
|
|
328372
328404
|
this.debugSnr = Boolean(opts.debugSnr);
|
|
328405
|
+
this.heuristicsEnabled = opts.heuristicsEnabled !== false;
|
|
328373
328406
|
this.toolRelay = opts.toolRelay ?? null;
|
|
328374
328407
|
this.onStatus = opts.onStatus ?? (() => {
|
|
328375
328408
|
});
|
|
@@ -328597,7 +328630,7 @@ ${snap.trim()}` });
|
|
|
328597
328630
|
}
|
|
328598
328631
|
const lastUser = [...this.context].reverse().find((m2) => m2.role === "user")?.content || "";
|
|
328599
328632
|
let preAnswered = false;
|
|
328600
|
-
if (this.toolRelay && lastUser) {
|
|
328633
|
+
if (this.heuristicsEnabled && this.toolRelay && lastUser) {
|
|
328601
328634
|
const lower = lastUser.toLowerCase();
|
|
328602
328635
|
const wantList = /(list|show|explore|browse|what's in|whats in|contents).*(dir|directory|folder|files)/.test(lower);
|
|
328603
328636
|
const wantEnv = /(what\s+dir|cwd|current\s+dir|working\s+directory|where\s+are\s+you)/.test(lower);
|
|
@@ -328630,9 +328663,12 @@ ${out}` });
|
|
|
328630
328663
|
} catch {
|
|
328631
328664
|
}
|
|
328632
328665
|
}
|
|
328633
|
-
let response =
|
|
328634
|
-
|
|
328635
|
-
|
|
328666
|
+
let response = "";
|
|
328667
|
+
for (let i2 = 0; i2 < 3; i2++) {
|
|
328668
|
+
response = await this.streamOllamaInference(this.abortController.signal);
|
|
328669
|
+
if (!this.toolRelay) break;
|
|
328670
|
+
const toolReq = extractToolJsonLoose(response);
|
|
328671
|
+
if (!toolReq) break;
|
|
328636
328672
|
const { name: name11, args: args2 } = toolReq;
|
|
328637
328673
|
let toolOutput = "";
|
|
328638
328674
|
try {
|
|
@@ -328646,18 +328682,19 @@ ${out}` });
|
|
|
328646
328682
|
}
|
|
328647
328683
|
this.context.push({ role: "system", content: `Tool ${name11} result (authoritative):
|
|
328648
328684
|
${toolOutput}` });
|
|
328649
|
-
response = await this.streamOllamaInference(this.abortController.signal);
|
|
328650
328685
|
}
|
|
328651
328686
|
if (!this.active) return;
|
|
328652
|
-
if (this.toolRelay && /\b(can't|cannot)\b/i.test(response) && this.toolCatalogNote) {
|
|
328687
|
+
if (this.heuristicsEnabled && this.toolRelay && /\b(can't|cannot)\b/i.test(response) && this.toolCatalogNote) {
|
|
328653
328688
|
this.context.push({ role: "system", content: `You have tools. Use them. ${this.toolCatalogNote}` });
|
|
328654
328689
|
response = await this.streamOllamaInference(this.abortController.signal);
|
|
328655
328690
|
}
|
|
328656
328691
|
if (response.trim()) {
|
|
328657
|
-
|
|
328692
|
+
const finalSpoken = stripToolJsonLines(response.trim());
|
|
328693
|
+
this.context.push({ role: "assistant", content: finalSpoken });
|
|
328658
328694
|
this.setState("SPEAKING");
|
|
328659
|
-
this.onAgentSpeech(
|
|
328660
|
-
this.voice.speak(
|
|
328695
|
+
this.onAgentSpeech(finalSpoken);
|
|
328696
|
+
this.voice.speak(finalSpoken);
|
|
328697
|
+
this.voiceTranscript.push({ role: "assistant", content: finalSpoken, ts: Date.now() });
|
|
328661
328698
|
this.voiceTranscript.push({ role: "assistant", content: response.trim(), ts: Date.now() });
|
|
328662
328699
|
if (this.runner) {
|
|
328663
328700
|
this.injectSummary();
|
|
@@ -333301,6 +333338,7 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
333301
333338
|
model: currentConfig2.model,
|
|
333302
333339
|
apiKey: currentConfig2.apiKey,
|
|
333303
333340
|
runner: summaryRunner,
|
|
333341
|
+
heuristicsEnabled: true,
|
|
333304
333342
|
toolRelay: {
|
|
333305
333343
|
async call(name11, args2) {
|
|
333306
333344
|
try {
|
|
@@ -333323,6 +333361,21 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
333323
333361
|
}
|
|
333324
333362
|
return "No active task; set args.start=true to begin one.";
|
|
333325
333363
|
}
|
|
333364
|
+
if (name11 === "voice_tool_catalog") {
|
|
333365
|
+
const cat2 = activeTask2?.runner.getToolCatalog() ?? [];
|
|
333366
|
+
const allow = /* @__PURE__ */ new Set(["list_directory", "file_read", "grep_search", "find_files", "memory_read", "memory_search", "todo_read"]);
|
|
333367
|
+
const filtered = cat2.filter((t2) => allow.has(t2.name));
|
|
333368
|
+
return JSON.stringify(filtered, null, 2);
|
|
333369
|
+
}
|
|
333370
|
+
if (name11 === "voice_tool_call") {
|
|
333371
|
+
const toolName = String(args2?.name || "").trim();
|
|
333372
|
+
const toolArgs = args2?.args || {};
|
|
333373
|
+
const allow = /* @__PURE__ */ new Set(["list_directory", "file_read", "grep_search", "find_files", "memory_read", "memory_search", "todo_read"]);
|
|
333374
|
+
if (!allow.has(toolName)) return `Tool not allowed: ${toolName}`;
|
|
333375
|
+
if (!activeTask2) return "No active task.";
|
|
333376
|
+
const result = await activeTask2.runner.runToolByName(toolName, toolArgs);
|
|
333377
|
+
return result.success ? result.output : `Error: ${result.error || "unknown"}`;
|
|
333378
|
+
}
|
|
333326
333379
|
if (name11 === "voice_env") {
|
|
333327
333380
|
const os8 = __require("node:os");
|
|
333328
333381
|
const p2 = __require("node:process");
|
|
@@ -333357,15 +333410,13 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
333357
333410
|
return JSON.stringify({ dir: base3, items }, null, 2);
|
|
333358
333411
|
}
|
|
333359
333412
|
if (name11 === "voice_read_file") {
|
|
333360
|
-
|
|
333361
|
-
|
|
333362
|
-
|
|
333363
|
-
|
|
333364
|
-
|
|
333365
|
-
|
|
333366
|
-
|
|
333367
|
-
return txt.length > max ? txt.slice(0, max) + `
|
|
333368
|
-
... [truncated ${txt.length - max} chars]` : txt;
|
|
333413
|
+
if (activeTask2) {
|
|
333414
|
+
const rel = String(args2?.path || "");
|
|
333415
|
+
const max = Math.max(0, Math.min(8192, Number(args2?.max) || 2048));
|
|
333416
|
+
const out = await activeTask2.runner.runToolByName("file_read", { path: rel, maxBytes: max });
|
|
333417
|
+
return out.success ? out.output : `Error: ${out.error || "unknown"}`;
|
|
333418
|
+
}
|
|
333419
|
+
return "No active task.";
|
|
333369
333420
|
}
|
|
333370
333421
|
return `Unknown tool: ${name11}`;
|
|
333371
333422
|
} catch (e2) {
|
package/package.json
CHANGED