@smithers-orchestrator/observability 0.25.0 → 0.25.1
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/package.json +2 -3
- package/src/SmithersEvent.ts +13 -1
- package/src/_traceEventNormalizers.js +71 -3
- package/src/index.d.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithers-orchestrator/observability",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "Concrete Smithers metrics, logging, tracing, and observability integrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"@effect/opentelemetry": "^0.63.0",
|
|
35
35
|
"@effect/platform": "^0.96.0",
|
|
36
36
|
"@effect/platform-bun": "^0.89.0",
|
|
37
|
-
"effect": "^3.21.1"
|
|
38
|
-
"@smithers-orchestrator/agents": "0.25.0"
|
|
37
|
+
"effect": "^3.21.1"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
40
|
"@types/bun": "latest",
|
package/src/SmithersEvent.ts
CHANGED
|
@@ -121,7 +121,19 @@ export type SmithersEvent =
|
|
|
121
121
|
after: RunState;
|
|
122
122
|
timestampMs: number;
|
|
123
123
|
}
|
|
124
|
-
| {
|
|
124
|
+
| {
|
|
125
|
+
type: "RunFinished";
|
|
126
|
+
runId: string;
|
|
127
|
+
timestampMs: number;
|
|
128
|
+
/**
|
|
129
|
+
* Tasks that ended `failed` but were tolerated (continueOnFail / transient
|
|
130
|
+
* agent failures) so the run still finished. Present only when `> 0` — the
|
|
131
|
+
* run "succeeded" while these children failed. See `docs/runtime/run-state.mdx`.
|
|
132
|
+
*/
|
|
133
|
+
failedChildren?: number;
|
|
134
|
+
/** Task state keys (`nodeId::iteration`) counted by `failedChildren`. */
|
|
135
|
+
failedChildKeys?: readonly string[];
|
|
136
|
+
}
|
|
125
137
|
| { type: "RunFailed"; runId: string; error: unknown; timestampMs: number }
|
|
126
138
|
| { type: "RunCancelled"; runId: string; timestampMs: number }
|
|
127
139
|
| {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { extractTextFromJsonValue } from "@smithers-orchestrator/agents/BaseCliAgent";
|
|
2
|
-
import { normalizeTokenUsage } from "@smithers-orchestrator/agents/BaseCliAgent";
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* @typedef {import('./agentTrace.ts').AgentFamily} AgentFamily
|
|
6
3
|
* @typedef {import('./agentTrace.ts').CanonicalAgentTraceEventKind} CanonicalAgentTraceEventKind
|
|
@@ -27,6 +24,77 @@ import { normalizeTokenUsage } from "@smithers-orchestrator/agents/BaseCliAgent"
|
|
|
27
24
|
* }} NormalizedTraceBatch
|
|
28
25
|
*/
|
|
29
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @param {unknown} value
|
|
29
|
+
* @returns {string | undefined}
|
|
30
|
+
*/
|
|
31
|
+
function extractTextFromJsonValue(value) {
|
|
32
|
+
if (typeof value === "string") return value;
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
const text = value.map((item) => extractTextFromJsonValue(item) ?? "").join("");
|
|
35
|
+
return text || undefined;
|
|
36
|
+
}
|
|
37
|
+
if (!value || typeof value !== "object") return undefined;
|
|
38
|
+
const record = /** @type {Record<string, unknown>} */ (value);
|
|
39
|
+
if (typeof record.text === "string") return record.text;
|
|
40
|
+
if (typeof record.content === "string") return record.content;
|
|
41
|
+
if (typeof record.output_text === "string") return record.output_text;
|
|
42
|
+
if (Array.isArray(record.content)) {
|
|
43
|
+
const text = record.content.map((part) => extractTextFromJsonValue(part) ?? "").join("");
|
|
44
|
+
if (text) return text;
|
|
45
|
+
}
|
|
46
|
+
if (record.type === "text" && record.part) return extractTextFromJsonValue(record.part);
|
|
47
|
+
for (const field of ["response", "message", "result", "output", "data", "item"]) {
|
|
48
|
+
const text = extractTextFromJsonValue(record[field]);
|
|
49
|
+
if (text) return text;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @type {Record<string, ReadonlyArray<ReadonlyArray<string>>>} */
|
|
55
|
+
const _usageFieldAliases = {
|
|
56
|
+
inputTokens: [["inputTokens"], ["promptTokens"], ["prompt_tokens"], ["input_tokens"], ["input"], ["models", "gemini", "tokens", "input"]],
|
|
57
|
+
outputTokens: [["outputTokens"], ["completionTokens"], ["completion_tokens"], ["output_tokens"], ["output"], ["models", "gemini", "tokens", "output"]],
|
|
58
|
+
cacheReadTokens: [["cacheReadTokens"], ["cache_read_input_tokens"], ["cached_input_tokens"], ["cache_read_tokens"], ["inputTokenDetails", "cacheReadTokens"]],
|
|
59
|
+
cacheWriteTokens: [["cacheWriteTokens"], ["cache_write_input_tokens"], ["cache_creation_input_tokens"], ["cache_write_tokens"], ["inputTokenDetails", "cacheWriteTokens"]],
|
|
60
|
+
reasoningTokens: [["reasoningTokens"], ["reasoning_tokens"], ["outputTokenDetails", "reasoningTokens"]],
|
|
61
|
+
totalTokens: [["totalTokens"], ["total_tokens"]],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {unknown} value
|
|
66
|
+
* @param {ReadonlyArray<string>} path
|
|
67
|
+
* @returns {unknown}
|
|
68
|
+
*/
|
|
69
|
+
function _readUsagePath(value, path) {
|
|
70
|
+
let current = value;
|
|
71
|
+
for (const segment of path) {
|
|
72
|
+
if (!current || typeof current !== "object") return undefined;
|
|
73
|
+
current = /** @type {Record<string, unknown>} */ (current)[segment];
|
|
74
|
+
}
|
|
75
|
+
return current;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {unknown} usage
|
|
80
|
+
* @returns {Record<string, number> | null}
|
|
81
|
+
*/
|
|
82
|
+
function normalizeTokenUsage(usage) {
|
|
83
|
+
if (!usage || typeof usage !== "object") return null;
|
|
84
|
+
/** @type {Record<string, number>} */
|
|
85
|
+
const normalized = {};
|
|
86
|
+
for (const [field, aliases] of Object.entries(_usageFieldAliases)) {
|
|
87
|
+
for (const path of aliases) {
|
|
88
|
+
const value = _readUsagePath(usage, path);
|
|
89
|
+
if (typeof value === "number") {
|
|
90
|
+
normalized[field] = value;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return Object.values(normalized).some((v) => Number.isFinite(v) && v > 0) ? normalized : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
30
98
|
/** @type {Record<string, MappedStructuredEvent>} */
|
|
31
99
|
const piSimpleEventMap = {
|
|
32
100
|
session: { kind: "session.start", payloadKind: "pi" },
|
package/src/index.d.ts
CHANGED
|
@@ -213,6 +213,14 @@ type SmithersEvent$2 = {
|
|
|
213
213
|
type: "RunFinished";
|
|
214
214
|
runId: string;
|
|
215
215
|
timestampMs: number;
|
|
216
|
+
/**
|
|
217
|
+
* Tasks that ended `failed` but were tolerated (continueOnFail / transient
|
|
218
|
+
* agent failures) so the run still finished. Present only when `> 0` — the
|
|
219
|
+
* run "succeeded" while these children failed. See `docs/runtime/run-state.mdx`.
|
|
220
|
+
*/
|
|
221
|
+
failedChildren?: number;
|
|
222
|
+
/** Task state keys (`nodeId::iteration`) counted by `failedChildren`. */
|
|
223
|
+
failedChildKeys?: readonly string[];
|
|
216
224
|
} | {
|
|
217
225
|
type: "RunFailed";
|
|
218
226
|
runId: string;
|