@voicethere/agent 0.16.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.
@@ -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(serialize(uri, options), options);
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 serialize(resolved, schemelessOptions);
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(serialize(base, options), options);
13970
- relative = parse3(serialize(relative, options), options);
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 serialize(cmpts, opts) {
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 : serialize(parsed, opts),
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 : serialize(uri, opts);
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;
@@ -21647,6 +21647,196 @@ var McpToolSource = class {
21647
21647
  }
21648
21648
  };
21649
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
+
21650
21840
  // dist/llm/mcp/tool-registry.js
21651
21841
  var MAX_TOOLS = 128;
21652
21842
  var MAX_RESULT_BYTES = 16384;
@@ -21679,9 +21869,19 @@ var ToolRegistry = class {
21679
21869
  sources = [];
21680
21870
  log;
21681
21871
  warned = /* @__PURE__ */ new Set();
21872
+ toolCallLog;
21873
+ redactor;
21682
21874
  constructor(opts = {}) {
21683
21875
  this.log = opts.log ?? (() => {
21684
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
+ }
21685
21885
  }
21686
21886
  addCustomTool(tool) {
21687
21887
  if (this.custom.some((t) => t.name === tool.name)) {
@@ -21698,19 +21898,74 @@ var ToolRegistry = class {
21698
21898
  async call(exposedName, args, opts) {
21699
21899
  const entry = this.build().find((e) => e.spec.name === exposedName);
21700
21900
  if (!entry) {
21701
- return { isError: true, content: `tool ${exposedName} is not available` };
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;
21702
21908
  }
21909
+ const clock = this.toolCallLog?.now ?? Date.now;
21910
+ const startedAt = clock();
21703
21911
  let result;
21704
- if (entry.custom) {
21705
- result = await this.callCustom(entry.custom, args, opts);
21706
- } else {
21707
- result = await entry.source.callTool(entry.mcpName, args, {
21708
- signal: opts.signal,
21709
- timeoutMs: opts.timeoutMs
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"
21710
21925
  });
21926
+ throw err;
21711
21927
  }
21928
+ this.logToolCall(entry, exposedName, args, opts, startedAt, clock(), result);
21712
21929
  return { isError: result.isError, content: truncateResult(result.content) };
21713
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
+ }
21714
21969
  async callCustom(tool, args, opts) {
21715
21970
  let timer;
21716
21971
  try {
@@ -21817,7 +22072,8 @@ var LLM_AGENT_CONFIG_DEFAULTS = {
21817
22072
  interruptPolicy: "cancel",
21818
22073
  serviceWaitMs: 2e4,
21819
22074
  fallbackText: "Sorry, something went wrong. Please try again.",
21820
- speakChatReplies: true
22075
+ speakChatReplies: true,
22076
+ toolCallLogs: "redacted"
21821
22077
  };
21822
22078
  var PROVIDER_IDS = ["openai", "anthropic", "gemini", "openrouter"];
21823
22079
  var ENV_NAME_RE = /^AGENT_[A-Z0-9_]{1,57}$/;
@@ -22087,7 +22343,8 @@ var TOP_KEYS = [
22087
22343
  "interruptPolicy",
22088
22344
  "serviceWaitMs",
22089
22345
  "fallbackText",
22090
- "speakChatReplies"
22346
+ "speakChatReplies",
22347
+ "toolCallLogs"
22091
22348
  ];
22092
22349
  function validateLlmAgentConfig(input) {
22093
22350
  const c = new Checker();
@@ -22352,6 +22609,13 @@ function validateLlmAgentConfig(input) {
22352
22609
  if (b !== void 0)
22353
22610
  config2.speakChatReplies = b;
22354
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
+ }
22355
22619
  if (c.errors.length > 0)
22356
22620
  return { ok: false, errors: c.errors };
22357
22621
  return { ok: true, config: config2, warnings };
@@ -22615,7 +22879,12 @@ var LLM_AGENT_CONFIG_JSON_SCHEMA = {
22615
22879
  maxLength: 500,
22616
22880
  default: "Sorry, something went wrong. Please try again."
22617
22881
  },
22618
- 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
+ }
22619
22888
  }
22620
22889
  };
22621
22890
 
@@ -23015,7 +23284,24 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
23015
23284
  }
23016
23285
  function buildRegistry(env) {
23017
23286
  const reg = new ToolRegistry({
23018
- 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
+ }
23019
23305
  });
23020
23306
  for (const tool of opts.tools ?? [])
23021
23307
  reg.addCustomTool(tool);
@@ -23099,19 +23385,29 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
23099
23385
  let content = "";
23100
23386
  let isError = false;
23101
23387
  const work = (async () => {
23388
+ const hookStart = Date.now();
23102
23389
  const hooked = hooks2.onToolCall ? await callHook("onToolCall", s.sessionId, () => hooks2.onToolCall({ name: call.name, args: call.input }, ctx)) : void 0;
23103
23390
  if (hooked?.ok && hooked.value) {
23104
- return {
23391
+ const answered = {
23105
23392
  content: String(hooked.value.result),
23106
23393
  isError: hooked.value.isError === true
23107
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;
23108
23402
  }
23109
23403
  if (!registry2)
23110
23404
  return { content: "no tools available", isError: true };
23111
23405
  return registry2.call(call.name, call.input, {
23112
23406
  signal,
23113
23407
  timeoutMs: toolTimeoutMs,
23114
- sessionId: s.sessionId
23408
+ sessionId: s.sessionId,
23409
+ turnId: t.turnId,
23410
+ callId: call.id
23115
23411
  });
23116
23412
  })();
23117
23413
  const raced = await Promise.race([work, aborted2]);
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.16.0. Package updates no longer change this file.
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[] = [];
@@ -518,22 +535,39 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
518
535
  let content = "";
519
536
  let isError = false;
520
537
  const work = (async () => {
538
+ const hookStart = Date.now();
521
539
  const hooked = hooks.onToolCall
522
540
  ? await callHook("onToolCall", s.sessionId, () =>
523
541
  hooks.onToolCall!({ name: call.name, args: call.input }, ctx),
524
542
  )
525
543
  : undefined;
526
544
  if (hooked?.ok && hooked.value) {
527
- return {
545
+ const answered = {
528
546
  content: String(hooked.value.result),
529
547
  isError: hooked.value.isError === true,
530
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;
531
563
  }
532
564
  if (!registry) return { content: "no tools available", isError: true };
533
565
  return registry.call(call.name, call.input, {
534
566
  signal,
535
567
  timeoutMs: toolTimeoutMs,
536
568
  sessionId: s.sessionId,
569
+ turnId: t.turnId,
570
+ callId: call.id,
537
571
  });
538
572
  })();
539
573
  const raced = await Promise.race([work, aborted]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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
  }