@voicethere/agent 0.15.0 → 0.17.0
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/llm/agent/config.d.ts +8 -0
- package/dist/llm/agent/config.d.ts.map +1 -1
- package/dist/llm/agent/config.js +17 -0
- package/dist/llm/agent/config.js.map +1 -1
- package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
- package/dist/llm/agent/create-llm-agent.js +30 -1
- package/dist/llm/agent/create-llm-agent.js.map +1 -1
- package/dist/llm/agent/redact.d.ts +16 -0
- package/dist/llm/agent/redact.d.ts.map +1 -0
- package/dist/llm/agent/redact.js +154 -0
- package/dist/llm/agent/redact.js.map +1 -0
- package/dist/llm/agent/tool-call-log.d.ts +37 -0
- package/dist/llm/agent/tool-call-log.d.ts.map +1 -0
- package/dist/llm/agent/tool-call-log.js +74 -0
- package/dist/llm/agent/tool-call-log.js.map +1 -0
- package/dist/llm/index.d.ts +3 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/mcp/discovery.d.ts +19 -0
- package/dist/llm/mcp/discovery.d.ts.map +1 -0
- package/dist/llm/mcp/discovery.js +42 -0
- package/dist/llm/mcp/discovery.js.map +1 -0
- package/dist/llm/mcp/index.d.ts +1 -1
- package/dist/llm/mcp/index.d.ts.map +1 -1
- package/dist/llm/mcp/mcp-tool-source.d.ts +4 -0
- package/dist/llm/mcp/mcp-tool-source.d.ts.map +1 -1
- package/dist/llm/mcp/mcp-tool-source.js +10 -0
- package/dist/llm/mcp/mcp-tool-source.js.map +1 -1
- package/dist/llm/mcp/tool-registry.d.ts +20 -0
- package/dist/llm/mcp/tool-registry.d.ts.map +1 -1
- package/dist/llm/mcp/tool-registry.js +76 -7
- package/dist/llm/mcp/tool-registry.js.map +1 -1
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +2 -2
- package/dist/runtime.js.map +1 -1
- package/dist/templates/llm-agent/agent.js +362 -21
- package/eject/llm/loop.ts +37 -2
- package/package.json +1 -1
- package/schema/voicethere.llm.schema.json +9 -0
|
@@ -13923,7 +13923,7 @@ var require_fast_uri = __commonJS({
|
|
|
13923
13923
|
normalizeString(uri, options);
|
|
13924
13924
|
} else if (typeof uri === "object") {
|
|
13925
13925
|
uri = /** @type {T} */
|
|
13926
|
-
parse3(
|
|
13926
|
+
parse3(serialize2(uri, options), options);
|
|
13927
13927
|
}
|
|
13928
13928
|
return uri;
|
|
13929
13929
|
}
|
|
@@ -13961,13 +13961,13 @@ var require_fast_uri = __commonJS({
|
|
|
13961
13961
|
throw new Error(resolved.error);
|
|
13962
13962
|
}
|
|
13963
13963
|
schemelessOptions.skipEscape = true;
|
|
13964
|
-
return
|
|
13964
|
+
return serialize2(resolved, schemelessOptions);
|
|
13965
13965
|
}
|
|
13966
13966
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
13967
13967
|
const target = {};
|
|
13968
13968
|
if (!skipNormalization) {
|
|
13969
|
-
base = parse3(
|
|
13970
|
-
relative = parse3(
|
|
13969
|
+
base = parse3(serialize2(base, options), options);
|
|
13970
|
+
relative = parse3(serialize2(relative, options), options);
|
|
13971
13971
|
}
|
|
13972
13972
|
options = options || {};
|
|
13973
13973
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -14022,7 +14022,7 @@ var require_fast_uri = __commonJS({
|
|
|
14022
14022
|
const normalizedB = normalizeComparableURI(uriB, options);
|
|
14023
14023
|
return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA === normalizedB;
|
|
14024
14024
|
}
|
|
14025
|
-
function
|
|
14025
|
+
function serialize2(cmpts, opts) {
|
|
14026
14026
|
const component = {
|
|
14027
14027
|
host: cmpts.host,
|
|
14028
14028
|
scheme: cmpts.scheme,
|
|
@@ -14294,7 +14294,7 @@ var require_fast_uri = __commonJS({
|
|
|
14294
14294
|
function normalizeStringWithStatus(uri, opts) {
|
|
14295
14295
|
const { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = parseWithStatus(uri, opts);
|
|
14296
14296
|
return {
|
|
14297
|
-
normalized: malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? uri :
|
|
14297
|
+
normalized: malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? uri : serialize2(parsed, opts),
|
|
14298
14298
|
malformedAuthorityOrPort,
|
|
14299
14299
|
malformedPercentEncoding,
|
|
14300
14300
|
malformedSchemeSpecific,
|
|
@@ -14308,7 +14308,7 @@ var require_fast_uri = __commonJS({
|
|
|
14308
14308
|
}
|
|
14309
14309
|
let value;
|
|
14310
14310
|
try {
|
|
14311
|
-
value = typeof uri === "string" ? uri :
|
|
14311
|
+
value = typeof uri === "string" ? uri : serialize2(uri, opts);
|
|
14312
14312
|
} catch {
|
|
14313
14313
|
return void 0;
|
|
14314
14314
|
}
|
|
@@ -14321,7 +14321,7 @@ var require_fast_uri = __commonJS({
|
|
|
14321
14321
|
resolve,
|
|
14322
14322
|
resolveComponent,
|
|
14323
14323
|
equal,
|
|
14324
|
-
serialize,
|
|
14324
|
+
serialize: serialize2,
|
|
14325
14325
|
parse: parse3
|
|
14326
14326
|
};
|
|
14327
14327
|
module.exports = fastUri;
|
|
@@ -21291,6 +21291,41 @@ function resolveModel(provider, model) {
|
|
|
21291
21291
|
|
|
21292
21292
|
// dist/llm/mcp/mcp-tool-source.js
|
|
21293
21293
|
import { createRequire } from "node:module";
|
|
21294
|
+
|
|
21295
|
+
// dist/llm/mcp/discovery.js
|
|
21296
|
+
var TOOLS_DISCOVERED_EVENT = "llm.tools.discovered";
|
|
21297
|
+
var MAX_DISCOVERED_TOOLS = 128;
|
|
21298
|
+
var MAX_DESCRIPTION_CHARS = 120;
|
|
21299
|
+
var MAX_DISCOVERY_FIELDS_CHARS = AGENT_LOG_FIELDS_MAX_CHARS - 192;
|
|
21300
|
+
function cutCodePoints(text, max) {
|
|
21301
|
+
const points = Array.from(text);
|
|
21302
|
+
return points.length <= max ? text : points.slice(0, max).join("");
|
|
21303
|
+
}
|
|
21304
|
+
function buildDiscoveryFields(source, kind, all, exposed) {
|
|
21305
|
+
const base = { event: TOOLS_DISCOVERED_EVENT, source, kind };
|
|
21306
|
+
const acc = [];
|
|
21307
|
+
for (const t of all.slice(0, MAX_DISCOVERED_TOOLS)) {
|
|
21308
|
+
const next = {
|
|
21309
|
+
name: t.name,
|
|
21310
|
+
description: cutCodePoints(t.description, MAX_DESCRIPTION_CHARS),
|
|
21311
|
+
exposed: exposed(t.name)
|
|
21312
|
+
};
|
|
21313
|
+
const size = JSON.stringify({
|
|
21314
|
+
...base,
|
|
21315
|
+
tools: [...acc, next],
|
|
21316
|
+
truncated: true
|
|
21317
|
+
}).length;
|
|
21318
|
+
if (size > MAX_DISCOVERY_FIELDS_CHARS)
|
|
21319
|
+
break;
|
|
21320
|
+
acc.push(next);
|
|
21321
|
+
}
|
|
21322
|
+
return { ...base, tools: acc, truncated: acc.length < all.length };
|
|
21323
|
+
}
|
|
21324
|
+
function toolsHash(all) {
|
|
21325
|
+
return all.map((t) => t.name).sort().join("\n");
|
|
21326
|
+
}
|
|
21327
|
+
|
|
21328
|
+
// dist/llm/mcp/mcp-tool-source.js
|
|
21294
21329
|
var DEFAULT_BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
21295
21330
|
var MAX_LIST_PAGES = 10;
|
|
21296
21331
|
var REQUEST_TIMEOUT_CODE = -32001;
|
|
@@ -21361,6 +21396,8 @@ var McpToolSource = class {
|
|
|
21361
21396
|
deny;
|
|
21362
21397
|
connectTimeoutMs;
|
|
21363
21398
|
log;
|
|
21399
|
+
kind;
|
|
21400
|
+
lastDiscoveryHash;
|
|
21364
21401
|
backoff;
|
|
21365
21402
|
state = "idle";
|
|
21366
21403
|
client;
|
|
@@ -21380,6 +21417,7 @@ var McpToolSource = class {
|
|
|
21380
21417
|
this.connectTimeoutMs = opts.connectTimeoutMs ?? 1e4;
|
|
21381
21418
|
this.log = opts.log ?? (() => {
|
|
21382
21419
|
});
|
|
21420
|
+
this.kind = opts.kind ?? "mcp";
|
|
21383
21421
|
this.backoff = opts.backoffMs && opts.backoffMs.length > 0 ? opts.backoffMs : DEFAULT_BACKOFF_MS;
|
|
21384
21422
|
}
|
|
21385
21423
|
get status() {
|
|
@@ -21544,6 +21582,12 @@ var McpToolSource = class {
|
|
|
21544
21582
|
if (!cursor)
|
|
21545
21583
|
break;
|
|
21546
21584
|
}
|
|
21585
|
+
const hash = toolsHash(out);
|
|
21586
|
+
if (hash !== this.lastDiscoveryHash) {
|
|
21587
|
+
this.lastDiscoveryHash = hash;
|
|
21588
|
+
const exposed = new Set(this.filter(out).map((t) => t.name));
|
|
21589
|
+
this.log("info", "llm tools discovered", buildDiscoveryFields(this.name, this.kind, out, (n) => exposed.has(n)));
|
|
21590
|
+
}
|
|
21547
21591
|
return this.filter(out);
|
|
21548
21592
|
}
|
|
21549
21593
|
async connectOnce() {
|
|
@@ -21603,6 +21647,196 @@ var McpToolSource = class {
|
|
|
21603
21647
|
}
|
|
21604
21648
|
};
|
|
21605
21649
|
|
|
21650
|
+
// dist/llm/agent/redact.js
|
|
21651
|
+
var MIN_SECRET_CHARS = 8;
|
|
21652
|
+
var MAX_DEPTH = 32;
|
|
21653
|
+
var SENSITIVE_KEY_RE = /(password|passwd|secret|token|api[_-]?key|authorization|cookie|private[_-]?key)$/i;
|
|
21654
|
+
var EMAIL_RE = /[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9-]{1,63}(?:\.[A-Za-z0-9-]{1,63}){0,8}\.[A-Za-z]{2,24}/g;
|
|
21655
|
+
var IBAN_CANDIDATE_RE = /\b[A-Z]{2}\d{2}[A-Za-z0-9 ]{11,40}/g;
|
|
21656
|
+
var CARD_RE = /\b\d(?:[ -]?\d){14,18}\b/g;
|
|
21657
|
+
var PHONE_RE = /(?<![\w.:/+-])(?:\+|\()?\d[\d ().-]{6,22}\d(?![\w.:/-])/g;
|
|
21658
|
+
var MAX_PII_CHARS = 65536;
|
|
21659
|
+
var IPV4_RE = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
21660
|
+
var ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
21661
|
+
function isPhone(m) {
|
|
21662
|
+
const d = m.replace(/\D/g, "");
|
|
21663
|
+
if (d.length < 8 || d.length > 15)
|
|
21664
|
+
return false;
|
|
21665
|
+
if (IPV4_RE.test(m) || ISO_DATE_RE.test(m))
|
|
21666
|
+
return false;
|
|
21667
|
+
if (m.startsWith("+") || m.includes("("))
|
|
21668
|
+
return true;
|
|
21669
|
+
return (m.match(/[ .-]/g) ?? []).length >= 2;
|
|
21670
|
+
}
|
|
21671
|
+
var NON_SECRET_AGENT_KEYS = /* @__PURE__ */ new Set([
|
|
21672
|
+
"AGENT_CUSTOMER_CONTEXT",
|
|
21673
|
+
"AGENT_SERVICE_URL"
|
|
21674
|
+
]);
|
|
21675
|
+
function secretValuesFromEnv(env, referenced) {
|
|
21676
|
+
const names = new Set(referenced);
|
|
21677
|
+
for (const k of Object.keys(env)) {
|
|
21678
|
+
if (k.startsWith("AGENT_") && !NON_SECRET_AGENT_KEYS.has(k))
|
|
21679
|
+
names.add(k);
|
|
21680
|
+
}
|
|
21681
|
+
return [...names].map((n) => env[n]).filter((v) => typeof v === "string");
|
|
21682
|
+
}
|
|
21683
|
+
function luhn(digits) {
|
|
21684
|
+
let sum = 0;
|
|
21685
|
+
let dbl = false;
|
|
21686
|
+
for (let i = digits.length - 1; i >= 0; i -= 1) {
|
|
21687
|
+
let d = digits.charCodeAt(i) - 48;
|
|
21688
|
+
if (dbl) {
|
|
21689
|
+
d *= 2;
|
|
21690
|
+
if (d > 9)
|
|
21691
|
+
d -= 9;
|
|
21692
|
+
}
|
|
21693
|
+
sum += d;
|
|
21694
|
+
dbl = !dbl;
|
|
21695
|
+
}
|
|
21696
|
+
return sum % 10 === 0;
|
|
21697
|
+
}
|
|
21698
|
+
function ibanValid(raw) {
|
|
21699
|
+
const s = raw.replace(/ /g, "").toUpperCase();
|
|
21700
|
+
if (s.length < 15 || s.length > 34)
|
|
21701
|
+
return false;
|
|
21702
|
+
const rearranged = s.slice(4) + s.slice(0, 4);
|
|
21703
|
+
let rem = 0;
|
|
21704
|
+
for (const ch of rearranged) {
|
|
21705
|
+
const code = ch.charCodeAt(0);
|
|
21706
|
+
const v = code >= 65 && code <= 90 ? String(code - 55) : ch;
|
|
21707
|
+
if (!/^[0-9]+$/.test(v))
|
|
21708
|
+
return false;
|
|
21709
|
+
for (const digit of v)
|
|
21710
|
+
rem = (rem * 10 + (digit.charCodeAt(0) - 48)) % 97;
|
|
21711
|
+
}
|
|
21712
|
+
return rem === 1;
|
|
21713
|
+
}
|
|
21714
|
+
function redactIbanCandidate(m) {
|
|
21715
|
+
for (let end = m.length; end >= 15; end -= 1) {
|
|
21716
|
+
const head = m.slice(0, end);
|
|
21717
|
+
if (head.endsWith(" "))
|
|
21718
|
+
continue;
|
|
21719
|
+
if (ibanValid(head))
|
|
21720
|
+
return `[redacted:iban]${m.slice(end)}`;
|
|
21721
|
+
}
|
|
21722
|
+
const next = m.slice(1).search(/[A-Z]{2}\d{2}/);
|
|
21723
|
+
if (next >= 0) {
|
|
21724
|
+
const at = next + 1;
|
|
21725
|
+
return m.slice(0, at) + redactIbanCandidate(m.slice(at));
|
|
21726
|
+
}
|
|
21727
|
+
return m;
|
|
21728
|
+
}
|
|
21729
|
+
function redactPii(input) {
|
|
21730
|
+
const text = input.length > MAX_PII_CHARS ? `${input.slice(0, MAX_PII_CHARS)}[truncated]` : input;
|
|
21731
|
+
return text.replace(EMAIL_RE, "[redacted:email]").replace(IBAN_CANDIDATE_RE, redactIbanCandidate).replace(CARD_RE, (m) => {
|
|
21732
|
+
const digits = m.replace(/[ -]/g, "");
|
|
21733
|
+
return [15, 16, 19].includes(digits.length) && "3456".includes(digits[0]) && luhn(digits) ? "[redacted:card]" : m;
|
|
21734
|
+
}).replace(PHONE_RE, (m) => isPhone(m) ? "[redacted:phone]" : m);
|
|
21735
|
+
}
|
|
21736
|
+
function createRedactor(opts) {
|
|
21737
|
+
const secrets = [...new Set(opts.secretValues)].filter((v) => v.length >= MIN_SECRET_CHARS).sort((a, b) => b.length - a.length);
|
|
21738
|
+
const pii = opts.mode === "redacted";
|
|
21739
|
+
const redactText = (text) => {
|
|
21740
|
+
let out = text;
|
|
21741
|
+
for (const s of secrets) {
|
|
21742
|
+
if (out.includes(s))
|
|
21743
|
+
out = out.split(s).join("[redacted:secret]");
|
|
21744
|
+
}
|
|
21745
|
+
return pii ? redactPii(out) : out;
|
|
21746
|
+
};
|
|
21747
|
+
const walk = (value, depth) => {
|
|
21748
|
+
if (typeof value === "string") {
|
|
21749
|
+
const t = value.trim();
|
|
21750
|
+
if (depth < MAX_DEPTH && (t.startsWith("{") || t.startsWith("[")) && t.length > 1) {
|
|
21751
|
+
try {
|
|
21752
|
+
return JSON.stringify(walk(JSON.parse(t), depth + 1));
|
|
21753
|
+
} catch {
|
|
21754
|
+
}
|
|
21755
|
+
}
|
|
21756
|
+
return redactText(value);
|
|
21757
|
+
}
|
|
21758
|
+
if (value === null || typeof value !== "object")
|
|
21759
|
+
return value;
|
|
21760
|
+
if (depth >= MAX_DEPTH)
|
|
21761
|
+
return "[redacted:depth]";
|
|
21762
|
+
if (Array.isArray(value))
|
|
21763
|
+
return value.map((v) => walk(v, depth + 1));
|
|
21764
|
+
const out = {};
|
|
21765
|
+
for (const [k, v] of Object.entries(value)) {
|
|
21766
|
+
const key = redactText(k);
|
|
21767
|
+
out[key] = pii && SENSITIVE_KEY_RE.test(k) ? "[redacted]" : walk(v, depth + 1);
|
|
21768
|
+
}
|
|
21769
|
+
return out;
|
|
21770
|
+
};
|
|
21771
|
+
return { redact: (value) => walk(value, 0) };
|
|
21772
|
+
}
|
|
21773
|
+
|
|
21774
|
+
// dist/llm/agent/tool-call-log.js
|
|
21775
|
+
var TOOL_CALL_EVENT = "llm.tool.call";
|
|
21776
|
+
var MAX_PART_CHARS = 2048;
|
|
21777
|
+
var MAX_FIELDS_CHARS = AGENT_LOG_FIELDS_MAX_CHARS - 192;
|
|
21778
|
+
function cutCodePoints2(text, max) {
|
|
21779
|
+
const points = Array.from(text);
|
|
21780
|
+
return points.length <= max ? text : points.slice(0, max).join("");
|
|
21781
|
+
}
|
|
21782
|
+
function serialize(value) {
|
|
21783
|
+
if (typeof value === "string")
|
|
21784
|
+
return value;
|
|
21785
|
+
if (value === void 0)
|
|
21786
|
+
return "";
|
|
21787
|
+
try {
|
|
21788
|
+
return JSON.stringify(value) ?? "";
|
|
21789
|
+
} catch {
|
|
21790
|
+
return "[unserializable]";
|
|
21791
|
+
}
|
|
21792
|
+
}
|
|
21793
|
+
function buildToolCallFields(a) {
|
|
21794
|
+
const endMs = Math.max(a.endedAt, a.startedAt + 1);
|
|
21795
|
+
const truncated = /* @__PURE__ */ new Set();
|
|
21796
|
+
let input = serialize(a.input);
|
|
21797
|
+
let output = serialize(a.output);
|
|
21798
|
+
if (Array.from(input).length > MAX_PART_CHARS) {
|
|
21799
|
+
input = cutCodePoints2(input, MAX_PART_CHARS);
|
|
21800
|
+
truncated.add("input");
|
|
21801
|
+
}
|
|
21802
|
+
if (Array.from(output).length > MAX_PART_CHARS) {
|
|
21803
|
+
output = cutCodePoints2(output, MAX_PART_CHARS);
|
|
21804
|
+
truncated.add("output");
|
|
21805
|
+
}
|
|
21806
|
+
const build = () => ({
|
|
21807
|
+
event: TOOL_CALL_EVENT,
|
|
21808
|
+
turnId: a.turnId,
|
|
21809
|
+
callId: a.callId,
|
|
21810
|
+
tool: a.tool,
|
|
21811
|
+
source: a.source,
|
|
21812
|
+
kind: a.kind,
|
|
21813
|
+
startedAt: new Date(a.startedAt).toISOString(),
|
|
21814
|
+
endedAt: new Date(endMs).toISOString(),
|
|
21815
|
+
durationMs: endMs - a.startedAt,
|
|
21816
|
+
isError: a.isError,
|
|
21817
|
+
input,
|
|
21818
|
+
output,
|
|
21819
|
+
redaction: a.mode,
|
|
21820
|
+
truncated: [...truncated]
|
|
21821
|
+
});
|
|
21822
|
+
let fields = build();
|
|
21823
|
+
for (const part of ["output", "input"]) {
|
|
21824
|
+
while (JSON.stringify(fields).length > MAX_FIELDS_CHARS) {
|
|
21825
|
+
const cur = part === "output" ? output : input;
|
|
21826
|
+
if (cur.length === 0)
|
|
21827
|
+
break;
|
|
21828
|
+
const next = cutCodePoints2(cur, Math.floor(Array.from(cur).length / 2));
|
|
21829
|
+
if (part === "output")
|
|
21830
|
+
output = next;
|
|
21831
|
+
else
|
|
21832
|
+
input = next;
|
|
21833
|
+
truncated.add(part);
|
|
21834
|
+
fields = build();
|
|
21835
|
+
}
|
|
21836
|
+
}
|
|
21837
|
+
return fields;
|
|
21838
|
+
}
|
|
21839
|
+
|
|
21606
21840
|
// dist/llm/mcp/tool-registry.js
|
|
21607
21841
|
var MAX_TOOLS = 128;
|
|
21608
21842
|
var MAX_RESULT_BYTES = 16384;
|
|
@@ -21635,9 +21869,19 @@ var ToolRegistry = class {
|
|
|
21635
21869
|
sources = [];
|
|
21636
21870
|
log;
|
|
21637
21871
|
warned = /* @__PURE__ */ new Set();
|
|
21872
|
+
toolCallLog;
|
|
21873
|
+
redactor;
|
|
21638
21874
|
constructor(opts = {}) {
|
|
21639
21875
|
this.log = opts.log ?? (() => {
|
|
21640
21876
|
});
|
|
21877
|
+
const tcl = opts.toolCallLog;
|
|
21878
|
+
if (tcl && tcl.mode !== "off") {
|
|
21879
|
+
this.toolCallLog = tcl;
|
|
21880
|
+
this.redactor = createRedactor({
|
|
21881
|
+
secretValues: tcl.secretValues,
|
|
21882
|
+
mode: tcl.mode
|
|
21883
|
+
});
|
|
21884
|
+
}
|
|
21641
21885
|
}
|
|
21642
21886
|
addCustomTool(tool) {
|
|
21643
21887
|
if (this.custom.some((t) => t.name === tool.name)) {
|
|
@@ -21654,19 +21898,74 @@ var ToolRegistry = class {
|
|
|
21654
21898
|
async call(exposedName, args, opts) {
|
|
21655
21899
|
const entry = this.build().find((e) => e.spec.name === exposedName);
|
|
21656
21900
|
if (!entry) {
|
|
21657
|
-
|
|
21901
|
+
const unavailable = {
|
|
21902
|
+
isError: true,
|
|
21903
|
+
content: `tool ${exposedName} is not available`
|
|
21904
|
+
};
|
|
21905
|
+
const at = (this.toolCallLog?.now ?? Date.now)();
|
|
21906
|
+
this.emitCall({ tool: exposedName, source: "", kind: "unknown" }, args, opts, at, at, unavailable);
|
|
21907
|
+
return unavailable;
|
|
21658
21908
|
}
|
|
21909
|
+
const clock = this.toolCallLog?.now ?? Date.now;
|
|
21910
|
+
const startedAt = clock();
|
|
21659
21911
|
let result;
|
|
21660
|
-
|
|
21661
|
-
|
|
21662
|
-
|
|
21663
|
-
|
|
21664
|
-
|
|
21665
|
-
|
|
21912
|
+
try {
|
|
21913
|
+
if (entry.custom) {
|
|
21914
|
+
result = await this.callCustom(entry.custom, args, opts);
|
|
21915
|
+
} else {
|
|
21916
|
+
result = await entry.source.callTool(entry.mcpName, args, {
|
|
21917
|
+
signal: opts.signal,
|
|
21918
|
+
timeoutMs: opts.timeoutMs
|
|
21919
|
+
});
|
|
21920
|
+
}
|
|
21921
|
+
} catch (err) {
|
|
21922
|
+
this.logToolCall(entry, exposedName, args, opts, startedAt, clock(), {
|
|
21923
|
+
isError: true,
|
|
21924
|
+
content: err instanceof Error ? err.message : "tool failed"
|
|
21666
21925
|
});
|
|
21926
|
+
throw err;
|
|
21667
21927
|
}
|
|
21928
|
+
this.logToolCall(entry, exposedName, args, opts, startedAt, clock(), result);
|
|
21668
21929
|
return { isError: result.isError, content: truncateResult(result.content) };
|
|
21669
21930
|
}
|
|
21931
|
+
/** Same log path for calls answered outside the registry (the onToolCall hook). */
|
|
21932
|
+
logExternalCall(name, args, opts, startedAt, endedAt, result) {
|
|
21933
|
+
this.emitCall({ tool: name, source: "onToolCall", kind: "hook" }, args, opts, startedAt, endedAt, result);
|
|
21934
|
+
}
|
|
21935
|
+
logToolCall(entry, exposedName, args, opts, startedAt, endedAt, result) {
|
|
21936
|
+
this.emitCall({
|
|
21937
|
+
tool: exposedName,
|
|
21938
|
+
source: entry.custom ? "custom" : entry.owner,
|
|
21939
|
+
kind: entry.custom ? "custom" : entry.source?.kind ?? "mcp"
|
|
21940
|
+
}, args, opts, startedAt, endedAt, result);
|
|
21941
|
+
}
|
|
21942
|
+
/** One `llm.tool.call` line per call; never throws into the call path. */
|
|
21943
|
+
emitCall(id, args, opts, startedAt, endedAt, result) {
|
|
21944
|
+
const cfg = this.toolCallLog;
|
|
21945
|
+
const redactor = this.redactor;
|
|
21946
|
+
if (!cfg || !redactor || cfg.mode === "off")
|
|
21947
|
+
return;
|
|
21948
|
+
try {
|
|
21949
|
+
cfg.emit(buildToolCallFields({
|
|
21950
|
+
turnId: opts.turnId ?? "",
|
|
21951
|
+
callId: opts.callId ?? "",
|
|
21952
|
+
tool: id.tool,
|
|
21953
|
+
source: id.source,
|
|
21954
|
+
kind: id.kind,
|
|
21955
|
+
startedAt,
|
|
21956
|
+
endedAt,
|
|
21957
|
+
input: redactor.redact(args),
|
|
21958
|
+
output: redactor.redact(result.content),
|
|
21959
|
+
isError: result.isError,
|
|
21960
|
+
mode: cfg.mode
|
|
21961
|
+
}), opts.sessionId);
|
|
21962
|
+
} catch (err) {
|
|
21963
|
+
this.log("warn", "tool call log failed", {
|
|
21964
|
+
tool: id.tool,
|
|
21965
|
+
error: err instanceof Error ? err.name : "error"
|
|
21966
|
+
});
|
|
21967
|
+
}
|
|
21968
|
+
}
|
|
21670
21969
|
async callCustom(tool, args, opts) {
|
|
21671
21970
|
let timer;
|
|
21672
21971
|
try {
|
|
@@ -21773,7 +22072,8 @@ var LLM_AGENT_CONFIG_DEFAULTS = {
|
|
|
21773
22072
|
interruptPolicy: "cancel",
|
|
21774
22073
|
serviceWaitMs: 2e4,
|
|
21775
22074
|
fallbackText: "Sorry, something went wrong. Please try again.",
|
|
21776
|
-
speakChatReplies: true
|
|
22075
|
+
speakChatReplies: true,
|
|
22076
|
+
toolCallLogs: "redacted"
|
|
21777
22077
|
};
|
|
21778
22078
|
var PROVIDER_IDS = ["openai", "anthropic", "gemini", "openrouter"];
|
|
21779
22079
|
var ENV_NAME_RE = /^AGENT_[A-Z0-9_]{1,57}$/;
|
|
@@ -22043,7 +22343,8 @@ var TOP_KEYS = [
|
|
|
22043
22343
|
"interruptPolicy",
|
|
22044
22344
|
"serviceWaitMs",
|
|
22045
22345
|
"fallbackText",
|
|
22046
|
-
"speakChatReplies"
|
|
22346
|
+
"speakChatReplies",
|
|
22347
|
+
"toolCallLogs"
|
|
22047
22348
|
];
|
|
22048
22349
|
function validateLlmAgentConfig(input) {
|
|
22049
22350
|
const c = new Checker();
|
|
@@ -22308,6 +22609,13 @@ function validateLlmAgentConfig(input) {
|
|
|
22308
22609
|
if (b !== void 0)
|
|
22309
22610
|
config2.speakChatReplies = b;
|
|
22310
22611
|
}
|
|
22612
|
+
if (root.toolCallLogs !== void 0) {
|
|
22613
|
+
if (root.toolCallLogs === "full" || root.toolCallLogs === "redacted" || root.toolCallLogs === "off") {
|
|
22614
|
+
config2.toolCallLogs = root.toolCallLogs;
|
|
22615
|
+
} else {
|
|
22616
|
+
c.err("toolCallLogs", 'must be one of "full", "redacted", "off"');
|
|
22617
|
+
}
|
|
22618
|
+
}
|
|
22311
22619
|
if (c.errors.length > 0)
|
|
22312
22620
|
return { ok: false, errors: c.errors };
|
|
22313
22621
|
return { ok: true, config: config2, warnings };
|
|
@@ -22571,7 +22879,12 @@ var LLM_AGENT_CONFIG_JSON_SCHEMA = {
|
|
|
22571
22879
|
maxLength: 500,
|
|
22572
22880
|
default: "Sorry, something went wrong. Please try again."
|
|
22573
22881
|
},
|
|
22574
|
-
speakChatReplies: { type: "boolean", default: true }
|
|
22882
|
+
speakChatReplies: { type: "boolean", default: true },
|
|
22883
|
+
toolCallLogs: {
|
|
22884
|
+
enum: ["full", "redacted", "off"],
|
|
22885
|
+
default: "redacted",
|
|
22886
|
+
description: "Agent log line per tool call. redacted removes secret values, sensitive keys and common personal data; full removes only secret values; off writes nothing."
|
|
22887
|
+
}
|
|
22575
22888
|
}
|
|
22576
22889
|
};
|
|
22577
22890
|
|
|
@@ -22971,7 +23284,24 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
22971
23284
|
}
|
|
22972
23285
|
function buildRegistry(env) {
|
|
22973
23286
|
const reg = new ToolRegistry({
|
|
22974
|
-
log: (level, message, fields) => agentLog(level, message, fields ?? {})
|
|
23287
|
+
log: (level, message, fields) => agentLog(level, message, fields ?? {}),
|
|
23288
|
+
toolCallLog: {
|
|
23289
|
+
mode: config2.toolCallLogs ?? D.toolCallLogs,
|
|
23290
|
+
secretValues: secretValuesFromEnv(env, [
|
|
23291
|
+
config2.apiKeySecret,
|
|
23292
|
+
"AGENT_SERVICE_TOKEN",
|
|
23293
|
+
...(config2.toolSources ?? []).flatMap((src) => {
|
|
23294
|
+
if (src.kind !== "mcp" || !src.auth)
|
|
23295
|
+
return [];
|
|
23296
|
+
if (src.auth.type === "bearer")
|
|
23297
|
+
return [src.auth.secret];
|
|
23298
|
+
if (src.auth.type === "headers")
|
|
23299
|
+
return Object.values(src.auth.headers);
|
|
23300
|
+
return [];
|
|
23301
|
+
})
|
|
23302
|
+
]),
|
|
23303
|
+
emit: (fields, sid) => agentLog("info", "llm tool call", { ...fields }, sid)
|
|
23304
|
+
}
|
|
22975
23305
|
});
|
|
22976
23306
|
for (const tool of opts.tools ?? [])
|
|
22977
23307
|
reg.addCustomTool(tool);
|
|
@@ -22992,6 +23322,7 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
22992
23322
|
}
|
|
22993
23323
|
const source = makeSource({
|
|
22994
23324
|
name: "service",
|
|
23325
|
+
kind: "service",
|
|
22995
23326
|
url: `${base}${src.path ?? D.servicePath}`,
|
|
22996
23327
|
headers,
|
|
22997
23328
|
allow: src.allow,
|
|
@@ -23054,19 +23385,29 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
23054
23385
|
let content = "";
|
|
23055
23386
|
let isError = false;
|
|
23056
23387
|
const work = (async () => {
|
|
23388
|
+
const hookStart = Date.now();
|
|
23057
23389
|
const hooked = hooks2.onToolCall ? await callHook("onToolCall", s.sessionId, () => hooks2.onToolCall({ name: call.name, args: call.input }, ctx)) : void 0;
|
|
23058
23390
|
if (hooked?.ok && hooked.value) {
|
|
23059
|
-
|
|
23391
|
+
const answered = {
|
|
23060
23392
|
content: String(hooked.value.result),
|
|
23061
23393
|
isError: hooked.value.isError === true
|
|
23062
23394
|
};
|
|
23395
|
+
registry2?.logExternalCall(call.name, call.input, {
|
|
23396
|
+
timeoutMs: toolTimeoutMs,
|
|
23397
|
+
sessionId: s.sessionId,
|
|
23398
|
+
turnId: t.turnId,
|
|
23399
|
+
callId: call.id
|
|
23400
|
+
}, hookStart, Date.now(), answered);
|
|
23401
|
+
return answered;
|
|
23063
23402
|
}
|
|
23064
23403
|
if (!registry2)
|
|
23065
23404
|
return { content: "no tools available", isError: true };
|
|
23066
23405
|
return registry2.call(call.name, call.input, {
|
|
23067
23406
|
signal,
|
|
23068
23407
|
timeoutMs: toolTimeoutMs,
|
|
23069
|
-
sessionId: s.sessionId
|
|
23408
|
+
sessionId: s.sessionId,
|
|
23409
|
+
turnId: t.turnId,
|
|
23410
|
+
callId: call.id
|
|
23070
23411
|
});
|
|
23071
23412
|
})();
|
|
23072
23413
|
const raced = await Promise.race([work, aborted2]);
|
package/eject/llm/loop.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copied from @voicethere/agent 0.
|
|
1
|
+
// Copied from @voicethere/agent 0.17.0. Package updates no longer change this file.
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import {
|
|
4
4
|
type AgentHandlers,
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
McpToolSource,
|
|
30
30
|
type McpToolSourceOptions,
|
|
31
31
|
resolveModel,
|
|
32
|
+
secretValuesFromEnv,
|
|
32
33
|
SentenceSplitter,
|
|
33
34
|
ToolRegistry,
|
|
34
35
|
type TurnContext,
|
|
@@ -421,6 +422,22 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
421
422
|
function buildRegistry(env: Record<string, string | undefined>): void {
|
|
422
423
|
const reg = new ToolRegistry({
|
|
423
424
|
log: (level, message, fields) => agentLog(level, message, fields ?? {}),
|
|
425
|
+
toolCallLog: {
|
|
426
|
+
mode: config.toolCallLogs ?? D.toolCallLogs,
|
|
427
|
+
secretValues: secretValuesFromEnv(env, [
|
|
428
|
+
config.apiKeySecret,
|
|
429
|
+
"AGENT_SERVICE_TOKEN",
|
|
430
|
+
...(config.toolSources ?? []).flatMap((src) => {
|
|
431
|
+
if (src.kind !== "mcp" || !src.auth) return [];
|
|
432
|
+
if (src.auth.type === "bearer") return [src.auth.secret];
|
|
433
|
+
if (src.auth.type === "headers")
|
|
434
|
+
return Object.values(src.auth.headers);
|
|
435
|
+
return [];
|
|
436
|
+
}),
|
|
437
|
+
]),
|
|
438
|
+
emit: (fields, sid) =>
|
|
439
|
+
agentLog("info", "llm tool call", { ...fields }, sid),
|
|
440
|
+
},
|
|
424
441
|
});
|
|
425
442
|
for (const tool of opts.tools ?? []) reg.addCustomTool(tool);
|
|
426
443
|
const sources: McpToolSource[] = [];
|
|
@@ -443,6 +460,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
443
460
|
}
|
|
444
461
|
const source = makeSource({
|
|
445
462
|
name: "service",
|
|
463
|
+
kind: "service",
|
|
446
464
|
url: `${base}${src.path ?? D.servicePath}`,
|
|
447
465
|
headers,
|
|
448
466
|
allow: src.allow,
|
|
@@ -517,22 +535,39 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
517
535
|
let content = "";
|
|
518
536
|
let isError = false;
|
|
519
537
|
const work = (async () => {
|
|
538
|
+
const hookStart = Date.now();
|
|
520
539
|
const hooked = hooks.onToolCall
|
|
521
540
|
? await callHook("onToolCall", s.sessionId, () =>
|
|
522
541
|
hooks.onToolCall!({ name: call.name, args: call.input }, ctx),
|
|
523
542
|
)
|
|
524
543
|
: undefined;
|
|
525
544
|
if (hooked?.ok && hooked.value) {
|
|
526
|
-
|
|
545
|
+
const answered = {
|
|
527
546
|
content: String(hooked.value.result),
|
|
528
547
|
isError: hooked.value.isError === true,
|
|
529
548
|
};
|
|
549
|
+
registry?.logExternalCall(
|
|
550
|
+
call.name,
|
|
551
|
+
call.input,
|
|
552
|
+
{
|
|
553
|
+
timeoutMs: toolTimeoutMs,
|
|
554
|
+
sessionId: s.sessionId,
|
|
555
|
+
turnId: t.turnId,
|
|
556
|
+
callId: call.id,
|
|
557
|
+
},
|
|
558
|
+
hookStart,
|
|
559
|
+
Date.now(),
|
|
560
|
+
answered,
|
|
561
|
+
);
|
|
562
|
+
return answered;
|
|
530
563
|
}
|
|
531
564
|
if (!registry) return { content: "no tools available", isError: true };
|
|
532
565
|
return registry.call(call.name, call.input, {
|
|
533
566
|
signal,
|
|
534
567
|
timeoutMs: toolTimeoutMs,
|
|
535
568
|
sessionId: s.sessionId,
|
|
569
|
+
turnId: t.turnId,
|
|
570
|
+
callId: call.id,
|
|
536
571
|
});
|
|
537
572
|
})();
|
|
538
573
|
const raced = await Promise.race([work, aborted]);
|
package/package.json
CHANGED
|
@@ -413,6 +413,15 @@
|
|
|
413
413
|
"speakChatReplies": {
|
|
414
414
|
"type": "boolean",
|
|
415
415
|
"default": true
|
|
416
|
+
},
|
|
417
|
+
"toolCallLogs": {
|
|
418
|
+
"enum": [
|
|
419
|
+
"full",
|
|
420
|
+
"redacted",
|
|
421
|
+
"off"
|
|
422
|
+
],
|
|
423
|
+
"default": "redacted",
|
|
424
|
+
"description": "Agent log line per tool call. redacted removes secret values, sensitive keys and common personal data; full removes only secret values; off writes nothing."
|
|
416
425
|
}
|
|
417
426
|
}
|
|
418
427
|
}
|