@cognipeer/agent-sdk 0.9.3 → 0.9.4

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/README.md CHANGED
@@ -417,6 +417,8 @@ You can disable payload capture with `logData: false` to keep only metrics, or c
417
417
 
418
418
  Each session/event also carries OTel-compatible correlation identifiers (`traceId`, `rootSpanId`, `spanId`, `parentSpanId`) so you can stitch agent traces into distributed telemetry pipelines.
419
419
 
420
+ Pass `tracing: { metadata: { ... } }` to attach arbitrary key-value tags (e.g. `{ complexity: "complex" }`) to every payload sent to the sink. The SDK does not interpret these tags itself — they're forwarded as-is so a downstream consumer (e.g. Console) can use them as reporting/attribution dimensions.
421
+
420
422
  ## Development
421
423
 
422
424
  Install dependencies and build the package:
package/dist/index.cjs CHANGED
@@ -1162,9 +1162,9 @@ async function postStreamingSessionStart(baseUrl, headers, payload) {
1162
1162
  const url = `${baseUrl.replace(/\/$/, "")}/stream/${payload.sessionId}/start`;
1163
1163
  await postJsonReliable(url, headers, payload, { retry: true });
1164
1164
  }
1165
- async function postStreamingEvent(baseUrl, headers, sessionId, event) {
1165
+ async function postStreamingEvent(baseUrl, headers, sessionId, event, metadata) {
1166
1166
  const url = `${baseUrl.replace(/\/$/, "")}/stream/${sessionId}/events`;
1167
- await postJsonReliable(url, headers, { event }, { retry: false });
1167
+ await postJsonReliable(url, headers, { event, metadata }, { retry: false });
1168
1168
  }
1169
1169
  async function postStreamingSessionEnd(baseUrl, headers, payload) {
1170
1170
  const url = `${baseUrl.replace(/\/$/, "")}/stream/${payload.sessionId}/end`;
@@ -1271,7 +1271,8 @@ function traceSessionToOtlp(session) {
1271
1271
  stringAttr("cognipeer.session.id", session.sessionId),
1272
1272
  stringAttr("cognipeer.thread.id", session.threadId),
1273
1273
  stringAttr("cognipeer.agent.model", session.agent?.model),
1274
- stringAttr("cognipeer.agent.provider", session.agent?.provider)
1274
+ stringAttr("cognipeer.agent.provider", session.agent?.provider),
1275
+ ...Object.entries(session.metadata || {}).map(([key, value]) => stringAttr(`cognipeer.metadata.${key}`, value))
1275
1276
  ].filter(Boolean);
1276
1277
  const rootAttrs = [
1277
1278
  stringAttr("cognipeer.session.status", session.status),
@@ -1646,6 +1647,7 @@ function createTraceSession(opts) {
1646
1647
  rootSpanId,
1647
1648
  threadId: opts.tracing?.threadId,
1648
1649
  configAgentName: opts.tracing?.agentName?.trim() || void 0,
1650
+ configMetadata: opts.tracing?.metadata && Object.keys(opts.tracing.metadata).length > 0 ? opts.tracing.metadata : void 0,
1649
1651
  startedAt: Date.now(),
1650
1652
  resolvedConfig: cfg,
1651
1653
  events: [],
@@ -1684,6 +1686,7 @@ async function startStreamingSession(session, agentRuntime) {
1684
1686
  threadId: session.threadId,
1685
1687
  startedAt: startedAtIso,
1686
1688
  agent: agentInfo,
1689
+ metadata: session.configMetadata,
1687
1690
  config: configSnapshot
1688
1691
  };
1689
1692
  if (sink.type === "cognipeer" || sink.type === "http") {
@@ -1844,7 +1847,7 @@ function recordTraceEvent(session, event) {
1844
1847
  if (session.resolvedConfig.mode === "streaming" && session.sessionStarted) {
1845
1848
  if (sink.type === "cognipeer" || sink.type === "http") {
1846
1849
  const headers = sink.type === "cognipeer" ? { Authorization: `Bearer ${sink.apiKey}` } : sink.headers;
1847
- postStreamingEvent(sink.url, headers, session.sessionId, record).catch((err) => {
1850
+ postStreamingEvent(sink.url, headers, session.sessionId, record, session.configMetadata).catch((err) => {
1848
1851
  const errMsg = err instanceof Error ? err.message : String(err);
1849
1852
  if (typeof console !== "undefined" && typeof console.warn === "function") {
1850
1853
  console.warn("[Tracing] Failed to send streaming event:", errMsg);
@@ -1896,6 +1899,7 @@ async function finalizeTraceSession(session, params = {}) {
1896
1899
  endedAt: endedAtIso,
1897
1900
  durationMs,
1898
1901
  agent: agentInfo || session.agentInfo,
1902
+ metadata: session.configMetadata,
1899
1903
  config: configSnapshot,
1900
1904
  summary: session.summary,
1901
1905
  events: session.events,
@@ -1930,7 +1934,8 @@ async function finalizeTraceSession(session, params = {}) {
1930
1934
  durationMs,
1931
1935
  status: initialStatus,
1932
1936
  summary: session.summary,
1933
- errors: session.errors
1937
+ errors: session.errors,
1938
+ metadata: session.configMetadata
1934
1939
  });
1935
1940
  } else {
1936
1941
  await postTraceSession(sink.url, headers, payloadForSink);