@aumos/agent-observability 0.1.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/client.d.ts +107 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +138 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +223 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +36 -0
- package/src/client.ts +301 -0
- package/src/index.ts +30 -0
- package/src/types.ts +261 -0
- package/tsconfig.json +25 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the agent-observability API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentObservabilityClient } from "@aumos/agent-observability";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentObservabilityClient({ baseUrl: "http://localhost:8080" });
|
|
12
|
+
*
|
|
13
|
+
* const traces = await client.getTraces({ agentId: "my-agent", limit: 50 });
|
|
14
|
+
* if (traces.ok) {
|
|
15
|
+
* console.log(`Found ${traces.data.total} traces`);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const costs = await client.getCostReport({ agentId: "my-agent" });
|
|
19
|
+
* if (costs.ok) {
|
|
20
|
+
* console.log(`Total cost: $${costs.data.total_cost_usd.toFixed(4)}`);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import type { AgentSpanKind, ApiResult, CostAttribution, DriftReport, FleetStatus, TraceExport, TraceListResponse } from "./types.js";
|
|
25
|
+
/** Configuration options for the AgentObservabilityClient. */
|
|
26
|
+
export interface AgentObservabilityClientConfig {
|
|
27
|
+
/** Base URL of the agent-observability server (e.g. "http://localhost:8080"). */
|
|
28
|
+
readonly baseUrl: string;
|
|
29
|
+
/** Optional request timeout in milliseconds (default: 30000). */
|
|
30
|
+
readonly timeoutMs?: number;
|
|
31
|
+
/** Optional extra HTTP headers sent with every request. */
|
|
32
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
33
|
+
}
|
|
34
|
+
/** Typed HTTP client for the agent-observability server. */
|
|
35
|
+
export interface AgentObservabilityClient {
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve a paginated list of traces with optional filtering.
|
|
38
|
+
*
|
|
39
|
+
* Results are ordered by timestamp descending (most recent first).
|
|
40
|
+
* Use the `kind` filter to narrow to a specific agent span type such
|
|
41
|
+
* as "llm.call" or "tool.invoke".
|
|
42
|
+
*
|
|
43
|
+
* @param options - Optional filter parameters.
|
|
44
|
+
* @returns A TraceListResponse with matching traces and total count.
|
|
45
|
+
*/
|
|
46
|
+
getTraces(options?: {
|
|
47
|
+
agentId?: string;
|
|
48
|
+
sessionId?: string;
|
|
49
|
+
kind?: AgentSpanKind;
|
|
50
|
+
since?: number;
|
|
51
|
+
until?: number;
|
|
52
|
+
limit?: number;
|
|
53
|
+
}): Promise<ApiResult<TraceListResponse>>;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieve aggregated cost attribution data.
|
|
56
|
+
*
|
|
57
|
+
* Returns cost breakdowns by model, provider, agent, and operation
|
|
58
|
+
* across all LLM calls matching the filter criteria.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Optional filter parameters.
|
|
61
|
+
* @returns A CostAttribution record with per-dimension breakdowns.
|
|
62
|
+
*/
|
|
63
|
+
getCostReport(options?: {
|
|
64
|
+
agentId?: string;
|
|
65
|
+
since?: number;
|
|
66
|
+
until?: number;
|
|
67
|
+
}): Promise<ApiResult<CostAttribution>>;
|
|
68
|
+
/**
|
|
69
|
+
* Run a behavioural drift analysis for an agent.
|
|
70
|
+
*
|
|
71
|
+
* Compares the agent's recent spans against the stored baseline using
|
|
72
|
+
* Z-score analysis. Returns a DriftReport with per-feature Z-scores
|
|
73
|
+
* and a qualitative severity label.
|
|
74
|
+
*
|
|
75
|
+
* @param agentId - The agent to analyse.
|
|
76
|
+
* @param options - Optional window and threshold parameters.
|
|
77
|
+
* @returns A DriftReport with drift status, Z-scores, and severity.
|
|
78
|
+
*/
|
|
79
|
+
getDriftAnalysis(agentId: string, options?: {
|
|
80
|
+
windowSpans?: number;
|
|
81
|
+
sigmaThreshold?: number;
|
|
82
|
+
}): Promise<ApiResult<DriftReport>>;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieve fleet-level health status for all tracked agents.
|
|
85
|
+
*
|
|
86
|
+
* Aggregates drift status, cost totals, and span counts per agent.
|
|
87
|
+
* Useful for dashboard views and alerting on fleet-wide anomalies.
|
|
88
|
+
*
|
|
89
|
+
* @returns A FleetStatus record with per-agent health summaries.
|
|
90
|
+
*/
|
|
91
|
+
getFleetStatus(): Promise<ApiResult<FleetStatus>>;
|
|
92
|
+
/**
|
|
93
|
+
* Export all spans for a specific trace in OTLP-compatible JSON format.
|
|
94
|
+
*
|
|
95
|
+
* @param traceId - The OTel trace ID (hex string).
|
|
96
|
+
* @returns The full TraceExport with all child spans.
|
|
97
|
+
*/
|
|
98
|
+
exportTraces(traceId: string): Promise<ApiResult<TraceExport>>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create a typed HTTP client for the agent-observability server.
|
|
102
|
+
*
|
|
103
|
+
* @param config - Client configuration including base URL.
|
|
104
|
+
* @returns An AgentObservabilityClient instance.
|
|
105
|
+
*/
|
|
106
|
+
export declare function createAgentObservabilityClient(config: AgentObservabilityClientConfig): AgentObservabilityClient;
|
|
107
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":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SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAEnC;;;;;;;OAOG;IACH,cAAc,IAAI,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAElD;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;CAChE;AAMD;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,8BAA8B,GACrC,wBAAwB,CA4G1B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the agent-observability API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentObservabilityClient } from "@aumos/agent-observability";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentObservabilityClient({ baseUrl: "http://localhost:8080" });
|
|
12
|
+
*
|
|
13
|
+
* const traces = await client.getTraces({ agentId: "my-agent", limit: 50 });
|
|
14
|
+
* if (traces.ok) {
|
|
15
|
+
* console.log(`Found ${traces.data.total} traces`);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const costs = await client.getCostReport({ agentId: "my-agent" });
|
|
19
|
+
* if (costs.ok) {
|
|
20
|
+
* console.log(`Total cost: $${costs.data.total_cost_usd.toFixed(4)}`);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Internal helpers
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
async function fetchJson(url, init, timeoutMs) {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
32
|
+
clearTimeout(timeoutId);
|
|
33
|
+
const body = await response.json();
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
const errorBody = body;
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
error: {
|
|
39
|
+
error: errorBody.error ?? "Unknown error",
|
|
40
|
+
detail: errorBody.detail ?? "",
|
|
41
|
+
},
|
|
42
|
+
status: response.status,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return { ok: true, data: body };
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
clearTimeout(timeoutId);
|
|
49
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: { error: "Network error", detail: message },
|
|
53
|
+
status: 0,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function buildHeaders(extraHeaders) {
|
|
58
|
+
return {
|
|
59
|
+
"Content-Type": "application/json",
|
|
60
|
+
Accept: "application/json",
|
|
61
|
+
...extraHeaders,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Client factory
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* Create a typed HTTP client for the agent-observability server.
|
|
69
|
+
*
|
|
70
|
+
* @param config - Client configuration including base URL.
|
|
71
|
+
* @returns An AgentObservabilityClient instance.
|
|
72
|
+
*/
|
|
73
|
+
export function createAgentObservabilityClient(config) {
|
|
74
|
+
const { baseUrl, timeoutMs = 30_000, headers: extraHeaders } = config;
|
|
75
|
+
const baseHeaders = buildHeaders(extraHeaders);
|
|
76
|
+
return {
|
|
77
|
+
async getTraces(options = {}) {
|
|
78
|
+
const params = new URLSearchParams();
|
|
79
|
+
if (options.agentId !== undefined) {
|
|
80
|
+
params.set("agent_id", options.agentId);
|
|
81
|
+
}
|
|
82
|
+
if (options.sessionId !== undefined) {
|
|
83
|
+
params.set("session_id", options.sessionId);
|
|
84
|
+
}
|
|
85
|
+
if (options.kind !== undefined) {
|
|
86
|
+
params.set("kind", options.kind);
|
|
87
|
+
}
|
|
88
|
+
if (options.since !== undefined) {
|
|
89
|
+
params.set("since", String(options.since));
|
|
90
|
+
}
|
|
91
|
+
if (options.until !== undefined) {
|
|
92
|
+
params.set("until", String(options.until));
|
|
93
|
+
}
|
|
94
|
+
if (options.limit !== undefined) {
|
|
95
|
+
params.set("limit", String(options.limit));
|
|
96
|
+
}
|
|
97
|
+
const queryString = params.toString();
|
|
98
|
+
const url = queryString
|
|
99
|
+
? `${baseUrl}/traces?${queryString}`
|
|
100
|
+
: `${baseUrl}/traces`;
|
|
101
|
+
return fetchJson(url, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
102
|
+
},
|
|
103
|
+
async getCostReport(options = {}) {
|
|
104
|
+
const params = new URLSearchParams();
|
|
105
|
+
if (options.agentId !== undefined) {
|
|
106
|
+
params.set("agent_id", options.agentId);
|
|
107
|
+
}
|
|
108
|
+
if (options.since !== undefined) {
|
|
109
|
+
params.set("since", String(options.since));
|
|
110
|
+
}
|
|
111
|
+
if (options.until !== undefined) {
|
|
112
|
+
params.set("until", String(options.until));
|
|
113
|
+
}
|
|
114
|
+
const queryString = params.toString();
|
|
115
|
+
const url = queryString
|
|
116
|
+
? `${baseUrl}/costs?${queryString}`
|
|
117
|
+
: `${baseUrl}/costs`;
|
|
118
|
+
return fetchJson(url, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
119
|
+
},
|
|
120
|
+
async getDriftAnalysis(agentId, options = {}) {
|
|
121
|
+
const params = new URLSearchParams({ agent_id: agentId });
|
|
122
|
+
if (options.windowSpans !== undefined) {
|
|
123
|
+
params.set("window_spans", String(options.windowSpans));
|
|
124
|
+
}
|
|
125
|
+
if (options.sigmaThreshold !== undefined) {
|
|
126
|
+
params.set("sigma_threshold", String(options.sigmaThreshold));
|
|
127
|
+
}
|
|
128
|
+
return fetchJson(`${baseUrl}/drift/analysis?${params.toString()}`, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
129
|
+
},
|
|
130
|
+
async getFleetStatus() {
|
|
131
|
+
return fetchJson(`${baseUrl}/fleet/status`, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
132
|
+
},
|
|
133
|
+
async exportTraces(traceId) {
|
|
134
|
+
return fetchJson(`${baseUrl}/traces/${encodeURIComponent(traceId)}/export`, { method: "GET", headers: baseHeaders }, timeoutMs);
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AA2BH,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,KAAK,UAAU,SAAS,CACtB,GAAW,EACX,IAAiB,EACjB,SAAiB;IAEjB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;IAElE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1E,YAAY,CAAC,SAAS,CAAC,CAAC;QAExB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAa,CAAC;QAE9C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,IAAyB,CAAC;YAC5C,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE;oBACL,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,eAAe;oBACzC,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,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,cAAc;YAClB,OAAO,SAAS,CACd,GAAG,OAAO,eAAe,EACzB,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,EACvC,SAAS,CACV,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,OAAe;YAChC,OAAO,SAAS,CACd,GAAG,OAAO,WAAW,kBAAkB,CAAC,OAAO,CAAC,SAAS,EACzD,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,EACvC,SAAS,CACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agent-observability
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS agent-observability framework.
|
|
5
|
+
* Provides distributed tracing, cost attribution, drift detection,
|
|
6
|
+
* and fleet health monitoring for AI agents.
|
|
7
|
+
*/
|
|
8
|
+
export type { AgentObservabilityClient, AgentObservabilityClientConfig, } from "./client.js";
|
|
9
|
+
export { createAgentObservabilityClient } from "./client.js";
|
|
10
|
+
export type { AgentSpanKind, AgentSpan, TraceExport, TraceListResponse, CostRecord, CostAttribution, DriftSeverity, DriftReport, AgentHealthSummary, FleetStatus, ApiError, ApiResult, } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAG7D,YAAY,EACV,aAAa,EACb,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agent-observability
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS agent-observability framework.
|
|
5
|
+
* Provides distributed tracing, cost attribution, drift detection,
|
|
6
|
+
* and fleet health monitoring for AI agents.
|
|
7
|
+
*/
|
|
8
|
+
export { createAgentObservabilityClient } from "./client.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the agent-observability framework.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python models defined in:
|
|
5
|
+
* agent_observability.spans.types — AgentSpanKind, AgentSpan
|
|
6
|
+
* agent_observability.cost.tracker — CostRecord, CostSummary
|
|
7
|
+
* agent_observability.drift.detector — DriftResult
|
|
8
|
+
* agent_observability.server.models — Trace, TraceListResponse
|
|
9
|
+
*
|
|
10
|
+
* All interfaces use readonly fields to match Python frozen models.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The 8 semantic span kinds for agent observability.
|
|
14
|
+
* Maps to AgentSpanKind enum in agent_observability.spans.types.
|
|
15
|
+
*
|
|
16
|
+
* Span kind values follow the dot-separated naming convention used
|
|
17
|
+
* by the OpenTelemetry semantic conventions for agents:
|
|
18
|
+
* - llm.call — a single LLM request/response cycle
|
|
19
|
+
* - tool.invoke — an external tool or function call
|
|
20
|
+
* - memory.read — reading from any memory backend
|
|
21
|
+
* - memory.write — writing to any memory backend
|
|
22
|
+
* - reasoning.step — a single step in a chain-of-thought
|
|
23
|
+
* - agent.delegate — delegating a sub-task to another agent
|
|
24
|
+
* - human.approval — a human-in-the-loop approval gate
|
|
25
|
+
* - agent.error — a recoverable or unrecoverable agent error
|
|
26
|
+
*/
|
|
27
|
+
export type AgentSpanKind = "llm.call" | "tool.invoke" | "memory.read" | "memory.write" | "reasoning.step" | "agent.delegate" | "human.approval" | "agent.error";
|
|
28
|
+
/**
|
|
29
|
+
* A single span within a trace, enriched with agent-semantic attributes.
|
|
30
|
+
* Combines the OTel span structure with agent-specific metadata.
|
|
31
|
+
*/
|
|
32
|
+
export interface AgentSpan {
|
|
33
|
+
/** OTel span ID (hex string). */
|
|
34
|
+
readonly span_id: string;
|
|
35
|
+
/** OTel trace ID this span belongs to (hex string). */
|
|
36
|
+
readonly trace_id: string;
|
|
37
|
+
/** Human-readable span name (e.g. "llm.call", "tool.invoke"). */
|
|
38
|
+
readonly name: string;
|
|
39
|
+
/** One of the 8 agent-semantic span kinds. */
|
|
40
|
+
readonly kind: AgentSpanKind;
|
|
41
|
+
/** Epoch milliseconds when the span started. */
|
|
42
|
+
readonly start_time_ms: number;
|
|
43
|
+
/** Epoch milliseconds when the span ended (null if still active). */
|
|
44
|
+
readonly end_time_ms: number | null;
|
|
45
|
+
/** Wall-clock duration in milliseconds (null if still active). */
|
|
46
|
+
readonly duration_ms: number | null;
|
|
47
|
+
/** Agent ID attached to this span. */
|
|
48
|
+
readonly agent_id: string;
|
|
49
|
+
/** Session ID attached to this span. */
|
|
50
|
+
readonly session_id: string;
|
|
51
|
+
/** Framework name (e.g. "langchain", "crewai"). */
|
|
52
|
+
readonly framework: string;
|
|
53
|
+
/** All OTel and agent-semantic attributes on the span. */
|
|
54
|
+
readonly attributes: Readonly<Record<string, string | number | boolean>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A complete exported trace — one root trace with all child spans.
|
|
58
|
+
* Maps to the trace response body from the observability server.
|
|
59
|
+
*/
|
|
60
|
+
export interface TraceExport {
|
|
61
|
+
/** OTel trace ID (hex string). */
|
|
62
|
+
readonly trace_id: string;
|
|
63
|
+
/** Primary agent ID for this trace. */
|
|
64
|
+
readonly agent_id: string;
|
|
65
|
+
/** Session identifier. */
|
|
66
|
+
readonly session_id: string;
|
|
67
|
+
/** Task or run identifier. */
|
|
68
|
+
readonly task_id: string;
|
|
69
|
+
/** Service or framework name. */
|
|
70
|
+
readonly service_name: string;
|
|
71
|
+
/** Ordered list of spans in this trace (root span first). */
|
|
72
|
+
readonly spans: readonly AgentSpan[];
|
|
73
|
+
/** Epoch unix timestamp (seconds) when the trace was recorded. */
|
|
74
|
+
readonly timestamp: number;
|
|
75
|
+
/** Arbitrary metadata attached to the trace. */
|
|
76
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Response body for the list-traces endpoint.
|
|
80
|
+
*/
|
|
81
|
+
export interface TraceListResponse {
|
|
82
|
+
readonly traces: readonly TraceExport[];
|
|
83
|
+
readonly total: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A single recorded LLM cost event.
|
|
87
|
+
* Maps to CostRecord in agent_observability.cost.tracker.
|
|
88
|
+
*/
|
|
89
|
+
export interface CostRecord {
|
|
90
|
+
/** Unix epoch timestamp (seconds) of this record. */
|
|
91
|
+
readonly timestamp: number;
|
|
92
|
+
/** Agent that made this LLM call. */
|
|
93
|
+
readonly agent_id: string;
|
|
94
|
+
/** Session this call belongs to. */
|
|
95
|
+
readonly session_id: string;
|
|
96
|
+
/** Task or run identifier. */
|
|
97
|
+
readonly task_id: string;
|
|
98
|
+
/** LLM provider name (e.g. "anthropic", "openai"). */
|
|
99
|
+
readonly provider: string;
|
|
100
|
+
/** Model name (e.g. "claude-sonnet-4-6", "gpt-4o"). */
|
|
101
|
+
readonly model: string;
|
|
102
|
+
/** Number of prompt/input tokens consumed. */
|
|
103
|
+
readonly input_tokens: number;
|
|
104
|
+
/** Number of completion/output tokens generated. */
|
|
105
|
+
readonly output_tokens: number;
|
|
106
|
+
/** Cached prompt tokens (charged at reduced rate by some providers). */
|
|
107
|
+
readonly cached_input_tokens: number;
|
|
108
|
+
/** Computed cost in USD. */
|
|
109
|
+
readonly cost_usd: number;
|
|
110
|
+
/** Semantic label for the operation (e.g. "llm_call", "embedding"). */
|
|
111
|
+
readonly operation: string;
|
|
112
|
+
/** OTel trace ID hex string. */
|
|
113
|
+
readonly trace_id: string;
|
|
114
|
+
/** OTel span ID hex string. */
|
|
115
|
+
readonly span_id: string;
|
|
116
|
+
/** Arbitrary key/value metadata. */
|
|
117
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Aggregated cost summary over a collection of CostRecord instances.
|
|
121
|
+
* Maps to CostSummary in agent_observability.cost.tracker.
|
|
122
|
+
*/
|
|
123
|
+
export interface CostAttribution {
|
|
124
|
+
/** Total cost in USD across all matching records. */
|
|
125
|
+
readonly total_cost_usd: number;
|
|
126
|
+
/** Total prompt/input tokens consumed. */
|
|
127
|
+
readonly total_input_tokens: number;
|
|
128
|
+
/** Total completion/output tokens generated. */
|
|
129
|
+
readonly total_output_tokens: number;
|
|
130
|
+
/** Combined token count. */
|
|
131
|
+
readonly total_tokens: number;
|
|
132
|
+
/** Number of cost records contributing to this summary. */
|
|
133
|
+
readonly record_count: number;
|
|
134
|
+
/** Cost breakdown by model name. */
|
|
135
|
+
readonly by_model: Readonly<Record<string, number>>;
|
|
136
|
+
/** Cost breakdown by provider name. */
|
|
137
|
+
readonly by_provider: Readonly<Record<string, number>>;
|
|
138
|
+
/** Cost breakdown by agent ID. */
|
|
139
|
+
readonly by_agent: Readonly<Record<string, number>>;
|
|
140
|
+
/** Cost breakdown by operation type. */
|
|
141
|
+
readonly by_operation: Readonly<Record<string, number>>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Qualitative severity label for a drift event.
|
|
145
|
+
*/
|
|
146
|
+
export type DriftSeverity = "none" | "low" | "medium" | "high";
|
|
147
|
+
/**
|
|
148
|
+
* Result of a single agent behaviour drift check.
|
|
149
|
+
* Maps to DriftResult in agent_observability.drift.detector.
|
|
150
|
+
*/
|
|
151
|
+
export interface DriftReport {
|
|
152
|
+
/** Agent ID that was checked. */
|
|
153
|
+
readonly agent_id: string;
|
|
154
|
+
/** Unix epoch timestamp (seconds) when the check ran. */
|
|
155
|
+
readonly timestamp: number;
|
|
156
|
+
/** True when at least one feature exceeded the Z-score threshold. */
|
|
157
|
+
readonly drifted: boolean;
|
|
158
|
+
/** Maximum absolute Z-score across all behavioural features. */
|
|
159
|
+
readonly max_z_score: number;
|
|
160
|
+
/** Configured sigma threshold used in this check. */
|
|
161
|
+
readonly threshold: number;
|
|
162
|
+
/** Feature names and their Z-scores for features that exceeded threshold. */
|
|
163
|
+
readonly drifted_features: Readonly<Record<string, number>>;
|
|
164
|
+
/** Z-scores for all behavioural features checked. */
|
|
165
|
+
readonly all_z_scores: Readonly<Record<string, number>>;
|
|
166
|
+
/** Age of the baseline in seconds at check time. */
|
|
167
|
+
readonly baseline_age_seconds: number;
|
|
168
|
+
/** Number of spans in the evaluation window. */
|
|
169
|
+
readonly window_span_count: number;
|
|
170
|
+
/** Qualitative severity label derived from max_z_score vs. threshold. */
|
|
171
|
+
readonly severity: DriftSeverity;
|
|
172
|
+
/** Optional human-readable notes (e.g. skip reason). */
|
|
173
|
+
readonly notes: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Per-agent health summary within the fleet status response.
|
|
177
|
+
*/
|
|
178
|
+
export interface AgentHealthSummary {
|
|
179
|
+
/** Agent identifier. */
|
|
180
|
+
readonly agent_id: string;
|
|
181
|
+
/** Whether this agent is currently drifting. */
|
|
182
|
+
readonly drifting: boolean;
|
|
183
|
+
/** Drift severity for this agent. */
|
|
184
|
+
readonly drift_severity: DriftSeverity;
|
|
185
|
+
/** Total cost attributed to this agent in USD. */
|
|
186
|
+
readonly total_cost_usd: number;
|
|
187
|
+
/** Total number of spans recorded for this agent. */
|
|
188
|
+
readonly span_count: number;
|
|
189
|
+
/** ISO-8601 UTC timestamp of the most recent span. */
|
|
190
|
+
readonly last_seen: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Fleet-level health status aggregating all tracked agents.
|
|
194
|
+
*/
|
|
195
|
+
export interface FleetStatus {
|
|
196
|
+
/** Total number of agents tracked. */
|
|
197
|
+
readonly agent_count: number;
|
|
198
|
+
/** Number of agents currently drifting. */
|
|
199
|
+
readonly drifting_count: number;
|
|
200
|
+
/** Cumulative cost across all agents in USD. */
|
|
201
|
+
readonly total_cost_usd: number;
|
|
202
|
+
/** Total span count across all agents. */
|
|
203
|
+
readonly total_span_count: number;
|
|
204
|
+
/** Per-agent health summaries. */
|
|
205
|
+
readonly agents: readonly AgentHealthSummary[];
|
|
206
|
+
/** ISO-8601 UTC timestamp when this status was generated. */
|
|
207
|
+
readonly generated_at: string;
|
|
208
|
+
}
|
|
209
|
+
/** Standard error payload returned by the agent-observability API. */
|
|
210
|
+
export interface ApiError {
|
|
211
|
+
readonly error: string;
|
|
212
|
+
readonly detail: string;
|
|
213
|
+
}
|
|
214
|
+
/** Result type for all client operations. */
|
|
215
|
+
export type ApiResult<T> = {
|
|
216
|
+
readonly ok: true;
|
|
217
|
+
readonly data: T;
|
|
218
|
+
} | {
|
|
219
|
+
readonly ok: false;
|
|
220
|
+
readonly error: ApiError;
|
|
221
|
+
readonly status: number;
|
|
222
|
+
};
|
|
223
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,aAAa,GACb,aAAa,GACb,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB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;CAC/B;AAMD,sEAAsE;AACtE,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACvC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the agent-observability framework.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python models defined in:
|
|
5
|
+
* agent_observability.spans.types — AgentSpanKind, AgentSpan
|
|
6
|
+
* agent_observability.cost.tracker — CostRecord, CostSummary
|
|
7
|
+
* agent_observability.drift.detector — DriftResult
|
|
8
|
+
* agent_observability.server.models — Trace, TraceListResponse
|
|
9
|
+
*
|
|
10
|
+
* All interfaces use readonly fields to match Python frozen models.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aumos/agent-observability",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for the AumOS agent-observability framework — distributed tracing, cost attribution, and drift detection",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.3.0"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"aumos",
|
|
24
|
+
"agent-observability",
|
|
25
|
+
"opentelemetry",
|
|
26
|
+
"tracing",
|
|
27
|
+
"cost-attribution",
|
|
28
|
+
"drift-detection",
|
|
29
|
+
"llm-observability",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/aumos-ai/agent-observability"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the agent-observability API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentObservabilityClient } from "@aumos/agent-observability";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentObservabilityClient({ baseUrl: "http://localhost:8080" });
|
|
12
|
+
*
|
|
13
|
+
* const traces = await client.getTraces({ agentId: "my-agent", limit: 50 });
|
|
14
|
+
* if (traces.ok) {
|
|
15
|
+
* console.log(`Found ${traces.data.total} traces`);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const costs = await client.getCostReport({ agentId: "my-agent" });
|
|
19
|
+
* if (costs.ok) {
|
|
20
|
+
* console.log(`Total cost: $${costs.data.total_cost_usd.toFixed(4)}`);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type {
|
|
26
|
+
AgentSpanKind,
|
|
27
|
+
ApiError,
|
|
28
|
+
ApiResult,
|
|
29
|
+
CostAttribution,
|
|
30
|
+
DriftReport,
|
|
31
|
+
FleetStatus,
|
|
32
|
+
TraceExport,
|
|
33
|
+
TraceListResponse,
|
|
34
|
+
} from "./types.js";
|
|
35
|
+
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Client configuration
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
/** Configuration options for the AgentObservabilityClient. */
|
|
41
|
+
export interface AgentObservabilityClientConfig {
|
|
42
|
+
/** Base URL of the agent-observability server (e.g. "http://localhost:8080"). */
|
|
43
|
+
readonly baseUrl: string;
|
|
44
|
+
/** Optional request timeout in milliseconds (default: 30000). */
|
|
45
|
+
readonly timeoutMs?: number;
|
|
46
|
+
/** Optional extra HTTP headers sent with every request. */
|
|
47
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Internal helpers
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
async function fetchJson<T>(
|
|
55
|
+
url: string,
|
|
56
|
+
init: RequestInit,
|
|
57
|
+
timeoutMs: number,
|
|
58
|
+
): Promise<ApiResult<T>> {
|
|
59
|
+
const controller = new AbortController();
|
|
60
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
64
|
+
clearTimeout(timeoutId);
|
|
65
|
+
|
|
66
|
+
const body = await response.json() as unknown;
|
|
67
|
+
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
const errorBody = body as Partial<ApiError>;
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error: {
|
|
73
|
+
error: errorBody.error ?? "Unknown error",
|
|
74
|
+
detail: errorBody.detail ?? "",
|
|
75
|
+
},
|
|
76
|
+
status: response.status,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return { ok: true, data: body as T };
|
|
81
|
+
} catch (err: unknown) {
|
|
82
|
+
clearTimeout(timeoutId);
|
|
83
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
error: { error: "Network error", detail: message },
|
|
87
|
+
status: 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function buildHeaders(
|
|
93
|
+
extraHeaders: Readonly<Record<string, string>> | undefined,
|
|
94
|
+
): Record<string, string> {
|
|
95
|
+
return {
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
Accept: "application/json",
|
|
98
|
+
...extraHeaders,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Client interface
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
/** Typed HTTP client for the agent-observability server. */
|
|
107
|
+
export interface AgentObservabilityClient {
|
|
108
|
+
/**
|
|
109
|
+
* Retrieve a paginated list of traces with optional filtering.
|
|
110
|
+
*
|
|
111
|
+
* Results are ordered by timestamp descending (most recent first).
|
|
112
|
+
* Use the `kind` filter to narrow to a specific agent span type such
|
|
113
|
+
* as "llm.call" or "tool.invoke".
|
|
114
|
+
*
|
|
115
|
+
* @param options - Optional filter parameters.
|
|
116
|
+
* @returns A TraceListResponse with matching traces and total count.
|
|
117
|
+
*/
|
|
118
|
+
getTraces(options?: {
|
|
119
|
+
agentId?: string;
|
|
120
|
+
sessionId?: string;
|
|
121
|
+
kind?: AgentSpanKind;
|
|
122
|
+
since?: number;
|
|
123
|
+
until?: number;
|
|
124
|
+
limit?: number;
|
|
125
|
+
}): Promise<ApiResult<TraceListResponse>>;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Retrieve aggregated cost attribution data.
|
|
129
|
+
*
|
|
130
|
+
* Returns cost breakdowns by model, provider, agent, and operation
|
|
131
|
+
* across all LLM calls matching the filter criteria.
|
|
132
|
+
*
|
|
133
|
+
* @param options - Optional filter parameters.
|
|
134
|
+
* @returns A CostAttribution record with per-dimension breakdowns.
|
|
135
|
+
*/
|
|
136
|
+
getCostReport(options?: {
|
|
137
|
+
agentId?: string;
|
|
138
|
+
since?: number;
|
|
139
|
+
until?: number;
|
|
140
|
+
}): Promise<ApiResult<CostAttribution>>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Run a behavioural drift analysis for an agent.
|
|
144
|
+
*
|
|
145
|
+
* Compares the agent's recent spans against the stored baseline using
|
|
146
|
+
* Z-score analysis. Returns a DriftReport with per-feature Z-scores
|
|
147
|
+
* and a qualitative severity label.
|
|
148
|
+
*
|
|
149
|
+
* @param agentId - The agent to analyse.
|
|
150
|
+
* @param options - Optional window and threshold parameters.
|
|
151
|
+
* @returns A DriftReport with drift status, Z-scores, and severity.
|
|
152
|
+
*/
|
|
153
|
+
getDriftAnalysis(
|
|
154
|
+
agentId: string,
|
|
155
|
+
options?: {
|
|
156
|
+
windowSpans?: number;
|
|
157
|
+
sigmaThreshold?: number;
|
|
158
|
+
},
|
|
159
|
+
): Promise<ApiResult<DriftReport>>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Retrieve fleet-level health status for all tracked agents.
|
|
163
|
+
*
|
|
164
|
+
* Aggregates drift status, cost totals, and span counts per agent.
|
|
165
|
+
* Useful for dashboard views and alerting on fleet-wide anomalies.
|
|
166
|
+
*
|
|
167
|
+
* @returns A FleetStatus record with per-agent health summaries.
|
|
168
|
+
*/
|
|
169
|
+
getFleetStatus(): Promise<ApiResult<FleetStatus>>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Export all spans for a specific trace in OTLP-compatible JSON format.
|
|
173
|
+
*
|
|
174
|
+
* @param traceId - The OTel trace ID (hex string).
|
|
175
|
+
* @returns The full TraceExport with all child spans.
|
|
176
|
+
*/
|
|
177
|
+
exportTraces(traceId: string): Promise<ApiResult<TraceExport>>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
// Client factory
|
|
182
|
+
// ---------------------------------------------------------------------------
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Create a typed HTTP client for the agent-observability server.
|
|
186
|
+
*
|
|
187
|
+
* @param config - Client configuration including base URL.
|
|
188
|
+
* @returns An AgentObservabilityClient instance.
|
|
189
|
+
*/
|
|
190
|
+
export function createAgentObservabilityClient(
|
|
191
|
+
config: AgentObservabilityClientConfig,
|
|
192
|
+
): AgentObservabilityClient {
|
|
193
|
+
const { baseUrl, timeoutMs = 30_000, headers: extraHeaders } = config;
|
|
194
|
+
const baseHeaders = buildHeaders(extraHeaders);
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
async getTraces(
|
|
198
|
+
options: {
|
|
199
|
+
agentId?: string;
|
|
200
|
+
sessionId?: string;
|
|
201
|
+
kind?: AgentSpanKind;
|
|
202
|
+
since?: number;
|
|
203
|
+
until?: number;
|
|
204
|
+
limit?: number;
|
|
205
|
+
} = {},
|
|
206
|
+
): Promise<ApiResult<TraceListResponse>> {
|
|
207
|
+
const params = new URLSearchParams();
|
|
208
|
+
if (options.agentId !== undefined) {
|
|
209
|
+
params.set("agent_id", options.agentId);
|
|
210
|
+
}
|
|
211
|
+
if (options.sessionId !== undefined) {
|
|
212
|
+
params.set("session_id", options.sessionId);
|
|
213
|
+
}
|
|
214
|
+
if (options.kind !== undefined) {
|
|
215
|
+
params.set("kind", options.kind);
|
|
216
|
+
}
|
|
217
|
+
if (options.since !== undefined) {
|
|
218
|
+
params.set("since", String(options.since));
|
|
219
|
+
}
|
|
220
|
+
if (options.until !== undefined) {
|
|
221
|
+
params.set("until", String(options.until));
|
|
222
|
+
}
|
|
223
|
+
if (options.limit !== undefined) {
|
|
224
|
+
params.set("limit", String(options.limit));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const queryString = params.toString();
|
|
228
|
+
const url = queryString
|
|
229
|
+
? `${baseUrl}/traces?${queryString}`
|
|
230
|
+
: `${baseUrl}/traces`;
|
|
231
|
+
|
|
232
|
+
return fetchJson<TraceListResponse>(
|
|
233
|
+
url,
|
|
234
|
+
{ method: "GET", headers: baseHeaders },
|
|
235
|
+
timeoutMs,
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
async getCostReport(
|
|
240
|
+
options: { agentId?: string; since?: number; until?: number } = {},
|
|
241
|
+
): Promise<ApiResult<CostAttribution>> {
|
|
242
|
+
const params = new URLSearchParams();
|
|
243
|
+
if (options.agentId !== undefined) {
|
|
244
|
+
params.set("agent_id", options.agentId);
|
|
245
|
+
}
|
|
246
|
+
if (options.since !== undefined) {
|
|
247
|
+
params.set("since", String(options.since));
|
|
248
|
+
}
|
|
249
|
+
if (options.until !== undefined) {
|
|
250
|
+
params.set("until", String(options.until));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const queryString = params.toString();
|
|
254
|
+
const url = queryString
|
|
255
|
+
? `${baseUrl}/costs?${queryString}`
|
|
256
|
+
: `${baseUrl}/costs`;
|
|
257
|
+
|
|
258
|
+
return fetchJson<CostAttribution>(
|
|
259
|
+
url,
|
|
260
|
+
{ method: "GET", headers: baseHeaders },
|
|
261
|
+
timeoutMs,
|
|
262
|
+
);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
async getDriftAnalysis(
|
|
266
|
+
agentId: string,
|
|
267
|
+
options: { windowSpans?: number; sigmaThreshold?: number } = {},
|
|
268
|
+
): Promise<ApiResult<DriftReport>> {
|
|
269
|
+
const params = new URLSearchParams({ agent_id: agentId });
|
|
270
|
+
if (options.windowSpans !== undefined) {
|
|
271
|
+
params.set("window_spans", String(options.windowSpans));
|
|
272
|
+
}
|
|
273
|
+
if (options.sigmaThreshold !== undefined) {
|
|
274
|
+
params.set("sigma_threshold", String(options.sigmaThreshold));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return fetchJson<DriftReport>(
|
|
278
|
+
`${baseUrl}/drift/analysis?${params.toString()}`,
|
|
279
|
+
{ method: "GET", headers: baseHeaders },
|
|
280
|
+
timeoutMs,
|
|
281
|
+
);
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
async getFleetStatus(): Promise<ApiResult<FleetStatus>> {
|
|
285
|
+
return fetchJson<FleetStatus>(
|
|
286
|
+
`${baseUrl}/fleet/status`,
|
|
287
|
+
{ method: "GET", headers: baseHeaders },
|
|
288
|
+
timeoutMs,
|
|
289
|
+
);
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
async exportTraces(traceId: string): Promise<ApiResult<TraceExport>> {
|
|
293
|
+
return fetchJson<TraceExport>(
|
|
294
|
+
`${baseUrl}/traces/${encodeURIComponent(traceId)}/export`,
|
|
295
|
+
{ method: "GET", headers: baseHeaders },
|
|
296
|
+
timeoutMs,
|
|
297
|
+
);
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agent-observability
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS agent-observability framework.
|
|
5
|
+
* Provides distributed tracing, cost attribution, drift detection,
|
|
6
|
+
* and fleet health monitoring for AI agents.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Client and configuration
|
|
10
|
+
export type {
|
|
11
|
+
AgentObservabilityClient,
|
|
12
|
+
AgentObservabilityClientConfig,
|
|
13
|
+
} from "./client.js";
|
|
14
|
+
export { createAgentObservabilityClient } from "./client.js";
|
|
15
|
+
|
|
16
|
+
// Core observability types
|
|
17
|
+
export type {
|
|
18
|
+
AgentSpanKind,
|
|
19
|
+
AgentSpan,
|
|
20
|
+
TraceExport,
|
|
21
|
+
TraceListResponse,
|
|
22
|
+
CostRecord,
|
|
23
|
+
CostAttribution,
|
|
24
|
+
DriftSeverity,
|
|
25
|
+
DriftReport,
|
|
26
|
+
AgentHealthSummary,
|
|
27
|
+
FleetStatus,
|
|
28
|
+
ApiError,
|
|
29
|
+
ApiResult,
|
|
30
|
+
} from "./types.js";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the agent-observability framework.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python models defined in:
|
|
5
|
+
* agent_observability.spans.types — AgentSpanKind, AgentSpan
|
|
6
|
+
* agent_observability.cost.tracker — CostRecord, CostSummary
|
|
7
|
+
* agent_observability.drift.detector — DriftResult
|
|
8
|
+
* agent_observability.server.models — Trace, TraceListResponse
|
|
9
|
+
*
|
|
10
|
+
* All interfaces use readonly fields to match Python frozen models.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Agent span semantic types
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The 8 semantic span kinds for agent observability.
|
|
19
|
+
* Maps to AgentSpanKind enum in agent_observability.spans.types.
|
|
20
|
+
*
|
|
21
|
+
* Span kind values follow the dot-separated naming convention used
|
|
22
|
+
* by the OpenTelemetry semantic conventions for agents:
|
|
23
|
+
* - llm.call — a single LLM request/response cycle
|
|
24
|
+
* - tool.invoke — an external tool or function call
|
|
25
|
+
* - memory.read — reading from any memory backend
|
|
26
|
+
* - memory.write — writing to any memory backend
|
|
27
|
+
* - reasoning.step — a single step in a chain-of-thought
|
|
28
|
+
* - agent.delegate — delegating a sub-task to another agent
|
|
29
|
+
* - human.approval — a human-in-the-loop approval gate
|
|
30
|
+
* - agent.error — a recoverable or unrecoverable agent error
|
|
31
|
+
*/
|
|
32
|
+
export type AgentSpanKind =
|
|
33
|
+
| "llm.call"
|
|
34
|
+
| "tool.invoke"
|
|
35
|
+
| "memory.read"
|
|
36
|
+
| "memory.write"
|
|
37
|
+
| "reasoning.step"
|
|
38
|
+
| "agent.delegate"
|
|
39
|
+
| "human.approval"
|
|
40
|
+
| "agent.error";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A single span within a trace, enriched with agent-semantic attributes.
|
|
44
|
+
* Combines the OTel span structure with agent-specific metadata.
|
|
45
|
+
*/
|
|
46
|
+
export interface AgentSpan {
|
|
47
|
+
/** OTel span ID (hex string). */
|
|
48
|
+
readonly span_id: string;
|
|
49
|
+
/** OTel trace ID this span belongs to (hex string). */
|
|
50
|
+
readonly trace_id: string;
|
|
51
|
+
/** Human-readable span name (e.g. "llm.call", "tool.invoke"). */
|
|
52
|
+
readonly name: string;
|
|
53
|
+
/** One of the 8 agent-semantic span kinds. */
|
|
54
|
+
readonly kind: AgentSpanKind;
|
|
55
|
+
/** Epoch milliseconds when the span started. */
|
|
56
|
+
readonly start_time_ms: number;
|
|
57
|
+
/** Epoch milliseconds when the span ended (null if still active). */
|
|
58
|
+
readonly end_time_ms: number | null;
|
|
59
|
+
/** Wall-clock duration in milliseconds (null if still active). */
|
|
60
|
+
readonly duration_ms: number | null;
|
|
61
|
+
/** Agent ID attached to this span. */
|
|
62
|
+
readonly agent_id: string;
|
|
63
|
+
/** Session ID attached to this span. */
|
|
64
|
+
readonly session_id: string;
|
|
65
|
+
/** Framework name (e.g. "langchain", "crewai"). */
|
|
66
|
+
readonly framework: string;
|
|
67
|
+
/** All OTel and agent-semantic attributes on the span. */
|
|
68
|
+
readonly attributes: Readonly<Record<string, string | number | boolean>>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Trace export
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A complete exported trace — one root trace with all child spans.
|
|
77
|
+
* Maps to the trace response body from the observability server.
|
|
78
|
+
*/
|
|
79
|
+
export interface TraceExport {
|
|
80
|
+
/** OTel trace ID (hex string). */
|
|
81
|
+
readonly trace_id: string;
|
|
82
|
+
/** Primary agent ID for this trace. */
|
|
83
|
+
readonly agent_id: string;
|
|
84
|
+
/** Session identifier. */
|
|
85
|
+
readonly session_id: string;
|
|
86
|
+
/** Task or run identifier. */
|
|
87
|
+
readonly task_id: string;
|
|
88
|
+
/** Service or framework name. */
|
|
89
|
+
readonly service_name: string;
|
|
90
|
+
/** Ordered list of spans in this trace (root span first). */
|
|
91
|
+
readonly spans: readonly AgentSpan[];
|
|
92
|
+
/** Epoch unix timestamp (seconds) when the trace was recorded. */
|
|
93
|
+
readonly timestamp: number;
|
|
94
|
+
/** Arbitrary metadata attached to the trace. */
|
|
95
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Response body for the list-traces endpoint.
|
|
100
|
+
*/
|
|
101
|
+
export interface TraceListResponse {
|
|
102
|
+
readonly traces: readonly TraceExport[];
|
|
103
|
+
readonly total: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Cost attribution
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A single recorded LLM cost event.
|
|
112
|
+
* Maps to CostRecord in agent_observability.cost.tracker.
|
|
113
|
+
*/
|
|
114
|
+
export interface CostRecord {
|
|
115
|
+
/** Unix epoch timestamp (seconds) of this record. */
|
|
116
|
+
readonly timestamp: number;
|
|
117
|
+
/** Agent that made this LLM call. */
|
|
118
|
+
readonly agent_id: string;
|
|
119
|
+
/** Session this call belongs to. */
|
|
120
|
+
readonly session_id: string;
|
|
121
|
+
/** Task or run identifier. */
|
|
122
|
+
readonly task_id: string;
|
|
123
|
+
/** LLM provider name (e.g. "anthropic", "openai"). */
|
|
124
|
+
readonly provider: string;
|
|
125
|
+
/** Model name (e.g. "claude-sonnet-4-6", "gpt-4o"). */
|
|
126
|
+
readonly model: string;
|
|
127
|
+
/** Number of prompt/input tokens consumed. */
|
|
128
|
+
readonly input_tokens: number;
|
|
129
|
+
/** Number of completion/output tokens generated. */
|
|
130
|
+
readonly output_tokens: number;
|
|
131
|
+
/** Cached prompt tokens (charged at reduced rate by some providers). */
|
|
132
|
+
readonly cached_input_tokens: number;
|
|
133
|
+
/** Computed cost in USD. */
|
|
134
|
+
readonly cost_usd: number;
|
|
135
|
+
/** Semantic label for the operation (e.g. "llm_call", "embedding"). */
|
|
136
|
+
readonly operation: string;
|
|
137
|
+
/** OTel trace ID hex string. */
|
|
138
|
+
readonly trace_id: string;
|
|
139
|
+
/** OTel span ID hex string. */
|
|
140
|
+
readonly span_id: string;
|
|
141
|
+
/** Arbitrary key/value metadata. */
|
|
142
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Aggregated cost summary over a collection of CostRecord instances.
|
|
147
|
+
* Maps to CostSummary in agent_observability.cost.tracker.
|
|
148
|
+
*/
|
|
149
|
+
export interface CostAttribution {
|
|
150
|
+
/** Total cost in USD across all matching records. */
|
|
151
|
+
readonly total_cost_usd: number;
|
|
152
|
+
/** Total prompt/input tokens consumed. */
|
|
153
|
+
readonly total_input_tokens: number;
|
|
154
|
+
/** Total completion/output tokens generated. */
|
|
155
|
+
readonly total_output_tokens: number;
|
|
156
|
+
/** Combined token count. */
|
|
157
|
+
readonly total_tokens: number;
|
|
158
|
+
/** Number of cost records contributing to this summary. */
|
|
159
|
+
readonly record_count: number;
|
|
160
|
+
/** Cost breakdown by model name. */
|
|
161
|
+
readonly by_model: Readonly<Record<string, number>>;
|
|
162
|
+
/** Cost breakdown by provider name. */
|
|
163
|
+
readonly by_provider: Readonly<Record<string, number>>;
|
|
164
|
+
/** Cost breakdown by agent ID. */
|
|
165
|
+
readonly by_agent: Readonly<Record<string, number>>;
|
|
166
|
+
/** Cost breakdown by operation type. */
|
|
167
|
+
readonly by_operation: Readonly<Record<string, number>>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
// Drift detection
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Qualitative severity label for a drift event.
|
|
176
|
+
*/
|
|
177
|
+
export type DriftSeverity = "none" | "low" | "medium" | "high";
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Result of a single agent behaviour drift check.
|
|
181
|
+
* Maps to DriftResult in agent_observability.drift.detector.
|
|
182
|
+
*/
|
|
183
|
+
export interface DriftReport {
|
|
184
|
+
/** Agent ID that was checked. */
|
|
185
|
+
readonly agent_id: string;
|
|
186
|
+
/** Unix epoch timestamp (seconds) when the check ran. */
|
|
187
|
+
readonly timestamp: number;
|
|
188
|
+
/** True when at least one feature exceeded the Z-score threshold. */
|
|
189
|
+
readonly drifted: boolean;
|
|
190
|
+
/** Maximum absolute Z-score across all behavioural features. */
|
|
191
|
+
readonly max_z_score: number;
|
|
192
|
+
/** Configured sigma threshold used in this check. */
|
|
193
|
+
readonly threshold: number;
|
|
194
|
+
/** Feature names and their Z-scores for features that exceeded threshold. */
|
|
195
|
+
readonly drifted_features: Readonly<Record<string, number>>;
|
|
196
|
+
/** Z-scores for all behavioural features checked. */
|
|
197
|
+
readonly all_z_scores: Readonly<Record<string, number>>;
|
|
198
|
+
/** Age of the baseline in seconds at check time. */
|
|
199
|
+
readonly baseline_age_seconds: number;
|
|
200
|
+
/** Number of spans in the evaluation window. */
|
|
201
|
+
readonly window_span_count: number;
|
|
202
|
+
/** Qualitative severity label derived from max_z_score vs. threshold. */
|
|
203
|
+
readonly severity: DriftSeverity;
|
|
204
|
+
/** Optional human-readable notes (e.g. skip reason). */
|
|
205
|
+
readonly notes: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// Fleet status
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Per-agent health summary within the fleet status response.
|
|
214
|
+
*/
|
|
215
|
+
export interface AgentHealthSummary {
|
|
216
|
+
/** Agent identifier. */
|
|
217
|
+
readonly agent_id: string;
|
|
218
|
+
/** Whether this agent is currently drifting. */
|
|
219
|
+
readonly drifting: boolean;
|
|
220
|
+
/** Drift severity for this agent. */
|
|
221
|
+
readonly drift_severity: DriftSeverity;
|
|
222
|
+
/** Total cost attributed to this agent in USD. */
|
|
223
|
+
readonly total_cost_usd: number;
|
|
224
|
+
/** Total number of spans recorded for this agent. */
|
|
225
|
+
readonly span_count: number;
|
|
226
|
+
/** ISO-8601 UTC timestamp of the most recent span. */
|
|
227
|
+
readonly last_seen: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Fleet-level health status aggregating all tracked agents.
|
|
232
|
+
*/
|
|
233
|
+
export interface FleetStatus {
|
|
234
|
+
/** Total number of agents tracked. */
|
|
235
|
+
readonly agent_count: number;
|
|
236
|
+
/** Number of agents currently drifting. */
|
|
237
|
+
readonly drifting_count: number;
|
|
238
|
+
/** Cumulative cost across all agents in USD. */
|
|
239
|
+
readonly total_cost_usd: number;
|
|
240
|
+
/** Total span count across all agents. */
|
|
241
|
+
readonly total_span_count: number;
|
|
242
|
+
/** Per-agent health summaries. */
|
|
243
|
+
readonly agents: readonly AgentHealthSummary[];
|
|
244
|
+
/** ISO-8601 UTC timestamp when this status was generated. */
|
|
245
|
+
readonly generated_at: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
// Error and result wrapper
|
|
250
|
+
// ---------------------------------------------------------------------------
|
|
251
|
+
|
|
252
|
+
/** Standard error payload returned by the agent-observability API. */
|
|
253
|
+
export interface ApiError {
|
|
254
|
+
readonly error: string;
|
|
255
|
+
readonly detail: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Result type for all client operations. */
|
|
259
|
+
export type ApiResult<T> =
|
|
260
|
+
| { readonly ok: true; readonly data: T }
|
|
261
|
+
| { readonly ok: false; readonly error: ApiError; readonly status: number };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"exactOptionalPropertyTypes": true,
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"skipLibCheck": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*"],
|
|
24
|
+
"exclude": ["node_modules", "dist"]
|
|
25
|
+
}
|