@subcortex-ai/sdk 0.3.8 → 0.3.9

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 CHANGED
@@ -1979,16 +1979,25 @@ function toContextXml(user, options = {}) {
1979
1979
  if (knowledge.length > 0) {
1980
1980
  lines.push(` <knowledge count="${knowledge.length}">`);
1981
1981
  for (const mem of knowledge) {
1982
+ if (mem.predicate.startsWith("signal:")) {
1983
+ const sigType = mem.predicate.slice(7);
1984
+ const val = mem.value;
1985
+ const content = typeof val === "object" && val?.content ? String(val.content) : formatValue(mem.value);
1986
+ const intensity = typeof val === "object" && val?.intensity ? Number(val.intensity) : mem.confidence;
1987
+ const about = typeof val === "object" && val?.aboutSubject ? ` about="${esc(String(val.aboutSubject))}"` : "";
1988
+ lines.push(` <signal type="${esc(sigType)}" intensity="${fmtConf(intensity)}"${about}>${esc(content)}</signal>`);
1989
+ continue;
1990
+ }
1982
1991
  const memSignals = findSignalsForFact(mem, signalsByAbout);
1983
1992
  if (memSignals.length > 0) {
1984
1993
  lines.push(` <fact predicate="${esc(mem.predicate)}" confidence="${fmtConf(mem.confidence)}">`);
1985
- lines.push(` ${esc(String(mem.value))}`);
1994
+ lines.push(` ${esc(formatValue(mem.value))}`);
1986
1995
  for (const sig of memSignals) {
1987
1996
  lines.push(` ${renderSignal(sig)}`);
1988
1997
  }
1989
1998
  lines.push(` </fact>`);
1990
1999
  } else {
1991
- lines.push(` <fact predicate="${esc(mem.predicate)}" confidence="${fmtConf(mem.confidence)}">${esc(String(mem.value))}</fact>`);
2000
+ lines.push(` <fact predicate="${esc(mem.predicate)}" confidence="${fmtConf(mem.confidence)}">${esc(formatValue(mem.value))}</fact>`);
1992
2001
  }
1993
2002
  }
1994
2003
  lines.push(` </knowledge>`);
@@ -2030,6 +2039,12 @@ function findSignalsForFact(fact, signalsByAbout) {
2030
2039
  }
2031
2040
  return results;
2032
2041
  }
2042
+ function formatValue(v) {
2043
+ if (v === null || v === void 0) return "";
2044
+ if (typeof v === "string") return v;
2045
+ if (typeof v === "object" && "content" in v) return String(v.content);
2046
+ return JSON.stringify(v);
2047
+ }
2033
2048
  function fmtConf(n) {
2034
2049
  return n.toFixed(2);
2035
2050
  }