@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 +2 -0
- package/dist/index.cjs +10 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +10 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -622,6 +622,11 @@ type TracingConfig = {
|
|
|
622
622
|
* when the same agent implementation runs under several logical names.
|
|
623
623
|
*/
|
|
624
624
|
agentName?: string;
|
|
625
|
+
/**
|
|
626
|
+
* Arbitrary key-value tags forwarded to every tracing payload for downstream
|
|
627
|
+
* attribution/reporting; not interpreted by the SDK itself.
|
|
628
|
+
*/
|
|
629
|
+
metadata?: Record<string, string>;
|
|
625
630
|
};
|
|
626
631
|
type SmartAgentTracingConfig = TracingConfig;
|
|
627
632
|
type AgentOptions = {
|
|
@@ -1350,6 +1355,8 @@ type TraceSessionFile = {
|
|
|
1350
1355
|
model?: string;
|
|
1351
1356
|
provider?: string;
|
|
1352
1357
|
};
|
|
1358
|
+
/** Arbitrary key-value tags from `TracingConfig.metadata`, forwarded as-is for downstream attribution/reporting. */
|
|
1359
|
+
metadata?: Record<string, string>;
|
|
1353
1360
|
config: TraceSessionConfigSnapshot;
|
|
1354
1361
|
summary: TraceSessionSummary;
|
|
1355
1362
|
events: TraceEventRecord[];
|
|
@@ -1398,6 +1405,8 @@ type TraceSessionRuntime = {
|
|
|
1398
1405
|
};
|
|
1399
1406
|
/** Caller-supplied agent name override (from TracingConfig.agentName). */
|
|
1400
1407
|
configAgentName?: string;
|
|
1408
|
+
/** Caller-supplied attribution tags (from TracingConfig.metadata). */
|
|
1409
|
+
configMetadata?: Record<string, string>;
|
|
1401
1410
|
resolvedConfig: ResolvedTraceConfig;
|
|
1402
1411
|
events: TraceEventRecord[];
|
|
1403
1412
|
summary: TraceSessionSummary;
|
package/dist/index.d.ts
CHANGED
|
@@ -622,6 +622,11 @@ type TracingConfig = {
|
|
|
622
622
|
* when the same agent implementation runs under several logical names.
|
|
623
623
|
*/
|
|
624
624
|
agentName?: string;
|
|
625
|
+
/**
|
|
626
|
+
* Arbitrary key-value tags forwarded to every tracing payload for downstream
|
|
627
|
+
* attribution/reporting; not interpreted by the SDK itself.
|
|
628
|
+
*/
|
|
629
|
+
metadata?: Record<string, string>;
|
|
625
630
|
};
|
|
626
631
|
type SmartAgentTracingConfig = TracingConfig;
|
|
627
632
|
type AgentOptions = {
|
|
@@ -1350,6 +1355,8 @@ type TraceSessionFile = {
|
|
|
1350
1355
|
model?: string;
|
|
1351
1356
|
provider?: string;
|
|
1352
1357
|
};
|
|
1358
|
+
/** Arbitrary key-value tags from `TracingConfig.metadata`, forwarded as-is for downstream attribution/reporting. */
|
|
1359
|
+
metadata?: Record<string, string>;
|
|
1353
1360
|
config: TraceSessionConfigSnapshot;
|
|
1354
1361
|
summary: TraceSessionSummary;
|
|
1355
1362
|
events: TraceEventRecord[];
|
|
@@ -1398,6 +1405,8 @@ type TraceSessionRuntime = {
|
|
|
1398
1405
|
};
|
|
1399
1406
|
/** Caller-supplied agent name override (from TracingConfig.agentName). */
|
|
1400
1407
|
configAgentName?: string;
|
|
1408
|
+
/** Caller-supplied attribution tags (from TracingConfig.metadata). */
|
|
1409
|
+
configMetadata?: Record<string, string>;
|
|
1401
1410
|
resolvedConfig: ResolvedTraceConfig;
|
|
1402
1411
|
events: TraceEventRecord[];
|
|
1403
1412
|
summary: TraceSessionSummary;
|
package/dist/index.mjs
CHANGED
|
@@ -1152,9 +1152,9 @@ async function postStreamingSessionStart(baseUrl, headers, payload) {
|
|
|
1152
1152
|
const url = `${baseUrl.replace(/\/$/, "")}/stream/${payload.sessionId}/start`;
|
|
1153
1153
|
await postJsonReliable(url, headers, payload, { retry: true });
|
|
1154
1154
|
}
|
|
1155
|
-
async function postStreamingEvent(baseUrl, headers, sessionId, event) {
|
|
1155
|
+
async function postStreamingEvent(baseUrl, headers, sessionId, event, metadata) {
|
|
1156
1156
|
const url = `${baseUrl.replace(/\/$/, "")}/stream/${sessionId}/events`;
|
|
1157
|
-
await postJsonReliable(url, headers, { event }, { retry: false });
|
|
1157
|
+
await postJsonReliable(url, headers, { event, metadata }, { retry: false });
|
|
1158
1158
|
}
|
|
1159
1159
|
async function postStreamingSessionEnd(baseUrl, headers, payload) {
|
|
1160
1160
|
const url = `${baseUrl.replace(/\/$/, "")}/stream/${payload.sessionId}/end`;
|
|
@@ -1261,7 +1261,8 @@ function traceSessionToOtlp(session) {
|
|
|
1261
1261
|
stringAttr("cognipeer.session.id", session.sessionId),
|
|
1262
1262
|
stringAttr("cognipeer.thread.id", session.threadId),
|
|
1263
1263
|
stringAttr("cognipeer.agent.model", session.agent?.model),
|
|
1264
|
-
stringAttr("cognipeer.agent.provider", session.agent?.provider)
|
|
1264
|
+
stringAttr("cognipeer.agent.provider", session.agent?.provider),
|
|
1265
|
+
...Object.entries(session.metadata || {}).map(([key, value]) => stringAttr(`cognipeer.metadata.${key}`, value))
|
|
1265
1266
|
].filter(Boolean);
|
|
1266
1267
|
const rootAttrs = [
|
|
1267
1268
|
stringAttr("cognipeer.session.status", session.status),
|
|
@@ -1636,6 +1637,7 @@ function createTraceSession(opts) {
|
|
|
1636
1637
|
rootSpanId,
|
|
1637
1638
|
threadId: opts.tracing?.threadId,
|
|
1638
1639
|
configAgentName: opts.tracing?.agentName?.trim() || void 0,
|
|
1640
|
+
configMetadata: opts.tracing?.metadata && Object.keys(opts.tracing.metadata).length > 0 ? opts.tracing.metadata : void 0,
|
|
1639
1641
|
startedAt: Date.now(),
|
|
1640
1642
|
resolvedConfig: cfg,
|
|
1641
1643
|
events: [],
|
|
@@ -1674,6 +1676,7 @@ async function startStreamingSession(session, agentRuntime) {
|
|
|
1674
1676
|
threadId: session.threadId,
|
|
1675
1677
|
startedAt: startedAtIso,
|
|
1676
1678
|
agent: agentInfo,
|
|
1679
|
+
metadata: session.configMetadata,
|
|
1677
1680
|
config: configSnapshot
|
|
1678
1681
|
};
|
|
1679
1682
|
if (sink.type === "cognipeer" || sink.type === "http") {
|
|
@@ -1834,7 +1837,7 @@ function recordTraceEvent(session, event) {
|
|
|
1834
1837
|
if (session.resolvedConfig.mode === "streaming" && session.sessionStarted) {
|
|
1835
1838
|
if (sink.type === "cognipeer" || sink.type === "http") {
|
|
1836
1839
|
const headers = sink.type === "cognipeer" ? { Authorization: `Bearer ${sink.apiKey}` } : sink.headers;
|
|
1837
|
-
postStreamingEvent(sink.url, headers, session.sessionId, record).catch((err) => {
|
|
1840
|
+
postStreamingEvent(sink.url, headers, session.sessionId, record, session.configMetadata).catch((err) => {
|
|
1838
1841
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
1839
1842
|
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
1840
1843
|
console.warn("[Tracing] Failed to send streaming event:", errMsg);
|
|
@@ -1886,6 +1889,7 @@ async function finalizeTraceSession(session, params = {}) {
|
|
|
1886
1889
|
endedAt: endedAtIso,
|
|
1887
1890
|
durationMs,
|
|
1888
1891
|
agent: agentInfo || session.agentInfo,
|
|
1892
|
+
metadata: session.configMetadata,
|
|
1889
1893
|
config: configSnapshot,
|
|
1890
1894
|
summary: session.summary,
|
|
1891
1895
|
events: session.events,
|
|
@@ -1920,7 +1924,8 @@ async function finalizeTraceSession(session, params = {}) {
|
|
|
1920
1924
|
durationMs,
|
|
1921
1925
|
status: initialStatus,
|
|
1922
1926
|
summary: session.summary,
|
|
1923
|
-
errors: session.errors
|
|
1927
|
+
errors: session.errors,
|
|
1928
|
+
metadata: session.configMetadata
|
|
1924
1929
|
});
|
|
1925
1930
|
} else {
|
|
1926
1931
|
await postTraceSession(sink.url, headers, payloadForSink);
|