@oriro/orirocli 0.1.2 → 0.1.3
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/cli.js +45 -3
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -1527,6 +1527,48 @@ function scrubMessageIdentity(msg) {
|
|
|
1527
1527
|
};
|
|
1528
1528
|
}
|
|
1529
1529
|
|
|
1530
|
+
// src/routers/tool-sanitize.ts
|
|
1531
|
+
var CONTROL_TOKEN = /<\|[^|]*\|>/g;
|
|
1532
|
+
var RECIPIENT_PREFIX = /^(?:to=)?(?:functions?|tools?|recipient)[.=]/i;
|
|
1533
|
+
var RECIPIENT = /(?:to=)?(?:functions?|tools?|recipient)[.=]([A-Za-z0-9_.:-]+)/i;
|
|
1534
|
+
var CLEAN_NAME = /^[A-Za-z0-9_.:-]+$/;
|
|
1535
|
+
function sanitizeToolName(raw) {
|
|
1536
|
+
if (!raw) return raw;
|
|
1537
|
+
if (!raw.includes("<|") && !RECIPIENT_PREFIX.test(raw)) return raw;
|
|
1538
|
+
const base = (raw.split("<|")[0] ?? "").replace(RECIPIENT_PREFIX, "").trim();
|
|
1539
|
+
if (base && CLEAN_NAME.test(base)) return base;
|
|
1540
|
+
const recip = raw.match(RECIPIENT);
|
|
1541
|
+
if (recip?.[1]) return recip[1];
|
|
1542
|
+
const m = raw.replace(CONTROL_TOKEN, " ").match(/[A-Za-z_][A-Za-z0-9_.:-]*/);
|
|
1543
|
+
return m ? m[0] : raw;
|
|
1544
|
+
}
|
|
1545
|
+
function sanitizeMessageToolCalls(msg) {
|
|
1546
|
+
let changed = false;
|
|
1547
|
+
const content = msg.content.map((c) => {
|
|
1548
|
+
if (c.type === "toolCall") {
|
|
1549
|
+
const name = sanitizeToolName(c.name);
|
|
1550
|
+
if (name !== c.name) {
|
|
1551
|
+
changed = true;
|
|
1552
|
+
return { ...c, name };
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
return c;
|
|
1556
|
+
});
|
|
1557
|
+
return changed ? { ...msg, content } : msg;
|
|
1558
|
+
}
|
|
1559
|
+
function sanitizeEventToolCalls(ev) {
|
|
1560
|
+
let next = ev;
|
|
1561
|
+
if ("partial" in next && next.partial) {
|
|
1562
|
+
const partial = sanitizeMessageToolCalls(next.partial);
|
|
1563
|
+
if (partial !== next.partial) next = { ...next, partial };
|
|
1564
|
+
}
|
|
1565
|
+
if (next.type === "toolcall_end" && next.toolCall) {
|
|
1566
|
+
const name = sanitizeToolName(next.toolCall.name);
|
|
1567
|
+
if (name !== next.toolCall.name) next = { ...next, toolCall: { ...next.toolCall, name } };
|
|
1568
|
+
}
|
|
1569
|
+
return next;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1530
1572
|
// src/routers/mux-provider.ts
|
|
1531
1573
|
var MUX_PROVIDER = "oriro-mux";
|
|
1532
1574
|
var MUX_MODEL = "oriro-free";
|
|
@@ -1576,17 +1618,17 @@ async function driveMux(out, mux, byId, context, options) {
|
|
|
1576
1618
|
committed = true;
|
|
1577
1619
|
if (ev.type === "done") {
|
|
1578
1620
|
mux.recordSuccess(id, Date.now() - t0);
|
|
1579
|
-
const clean = scrubMessageIdentity(ev.message);
|
|
1621
|
+
const clean = sanitizeMessageToolCalls(scrubMessageIdentity(ev.message));
|
|
1580
1622
|
out.push({ type: "done", reason: ev.reason, message: clean });
|
|
1581
1623
|
out.end(clean);
|
|
1582
1624
|
return;
|
|
1583
1625
|
}
|
|
1584
1626
|
lastPartial = ev.partial;
|
|
1585
|
-
out.push(ev);
|
|
1627
|
+
out.push(sanitizeEventToolCalls(ev));
|
|
1586
1628
|
}
|
|
1587
1629
|
if (failedBeforeContent) continue;
|
|
1588
1630
|
mux.recordSuccess(id, Date.now() - t0);
|
|
1589
|
-
out.end(lastPartial ? scrubMessageIdentity(lastPartial) : void 0);
|
|
1631
|
+
out.end(lastPartial ? sanitizeMessageToolCalls(scrubMessageIdentity(lastPartial)) : void 0);
|
|
1590
1632
|
return;
|
|
1591
1633
|
} catch (e) {
|
|
1592
1634
|
mux.recordFailure(id, e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oriro/orirocli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "ORIRO — a free, on-device-friendly terminal AI agent. Built on the Pi agent harness (used as a library).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
"dev": "tsx src/cli.ts",
|
|
23
23
|
"build": "tsup",
|
|
24
24
|
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test:unit": "tsx scripts/test-tool-sanitize.ts",
|
|
25
26
|
"smoke": "npm run build && node scripts/smoke.mjs",
|
|
26
|
-
"prepublishOnly": "npm run build && node scripts/smoke.mjs && node scripts/prepublish-check.mjs",
|
|
27
|
+
"prepublishOnly": "npm run build && npm run test:unit && node scripts/smoke.mjs && node scripts/prepublish-check.mjs",
|
|
27
28
|
"start": "node dist/cli.js"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|