@smthrs/observability 0.33.0 → 0.35.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/package.json +5 -4
- package/src/SmithersEvent.ts +71 -1
- package/src/detectCaptureMode.js +6 -1
- package/src/index.d.ts +73 -2
- package/src/index.js +2 -1
- package/src/logging.js +17 -1
- package/src/metrics/index.d.ts +60 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smthrs/observability",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "Concrete Smithers metrics, logging, tracing, and observability integrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,9 +31,10 @@
|
|
|
31
31
|
"grafana/"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@effect/opentelemetry": "4.0.0-beta.
|
|
35
|
-
"@effect/platform-bun": "4.0.0-beta.
|
|
36
|
-
"effect": "4.0.0-beta.
|
|
34
|
+
"@effect/opentelemetry": "4.0.0-beta.105",
|
|
35
|
+
"@effect/platform-bun": "4.0.0-beta.105",
|
|
36
|
+
"@effect/platform-node-shared": "4.0.0-beta.105",
|
|
37
|
+
"effect": "4.0.0-beta.105"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/bun": "latest",
|
package/src/SmithersEvent.ts
CHANGED
|
@@ -25,6 +25,7 @@ type RunState =
|
|
|
25
25
|
| "failed"
|
|
26
26
|
| "cancelled"
|
|
27
27
|
| "succeeded"
|
|
28
|
+
| "succeeded-with-failures"
|
|
28
29
|
| "unknown";
|
|
29
30
|
|
|
30
31
|
type AgentCliActionKind =
|
|
@@ -77,6 +78,15 @@ type AgentCliCompletedEvent = {
|
|
|
77
78
|
|
|
78
79
|
type AgentCliEvent = AgentCliStartedEvent | AgentCliActionEvent | AgentCliCompletedEvent;
|
|
79
80
|
|
|
81
|
+
export type RunCancellationSource = {
|
|
82
|
+
kind: "signal" | "rpc" | "cli" | "engine";
|
|
83
|
+
detail?: string;
|
|
84
|
+
signal?: string;
|
|
85
|
+
clientPid?: number;
|
|
86
|
+
requestId?: string;
|
|
87
|
+
clientIdentity?: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
80
90
|
export type SmithersEvent =
|
|
81
91
|
| {
|
|
82
92
|
type: "SupervisorStarted";
|
|
@@ -121,6 +131,20 @@ export type SmithersEvent =
|
|
|
121
131
|
after: RunState;
|
|
122
132
|
timestampMs: number;
|
|
123
133
|
}
|
|
134
|
+
| {
|
|
135
|
+
type: "RunConcurrencySaturated";
|
|
136
|
+
runId: string;
|
|
137
|
+
requestedDemand: number;
|
|
138
|
+
effectiveCap: number;
|
|
139
|
+
remediationCommand: string;
|
|
140
|
+
/** Present when a lifecycle-linked descendant caused the owner's budget to saturate. */
|
|
141
|
+
descendantRunId?: string;
|
|
142
|
+
/** Which owner budget bound admission. Historical events omit this. */
|
|
143
|
+
budget?: "run" | "subtree";
|
|
144
|
+
/** Present when `budget` is `subtree`. */
|
|
145
|
+
subtreeGroupId?: string;
|
|
146
|
+
timestampMs: number;
|
|
147
|
+
}
|
|
124
148
|
| {
|
|
125
149
|
type: "RunFinished";
|
|
126
150
|
runId: string;
|
|
@@ -135,7 +159,13 @@ export type SmithersEvent =
|
|
|
135
159
|
failedChildKeys?: readonly string[];
|
|
136
160
|
}
|
|
137
161
|
| { type: "RunFailed"; runId: string; error: unknown; timestampMs: number }
|
|
138
|
-
| {
|
|
162
|
+
| {
|
|
163
|
+
type: "RunCancelled";
|
|
164
|
+
runId: string;
|
|
165
|
+
timestampMs: number;
|
|
166
|
+
/** Missing only on historical or unattributed cancellation events. */
|
|
167
|
+
source?: RunCancellationSource;
|
|
168
|
+
}
|
|
139
169
|
| {
|
|
140
170
|
type: "RunContinuedAsNew";
|
|
141
171
|
runId: string;
|
|
@@ -365,6 +395,17 @@ export type SmithersEvent =
|
|
|
365
395
|
error: unknown;
|
|
366
396
|
timestampMs: number;
|
|
367
397
|
}
|
|
398
|
+
| {
|
|
399
|
+
type: "NodeStalled";
|
|
400
|
+
runId: string;
|
|
401
|
+
nodeId: string;
|
|
402
|
+
iteration: number;
|
|
403
|
+
attempt: number;
|
|
404
|
+
identicalFailures: number;
|
|
405
|
+
signature: string;
|
|
406
|
+
error: unknown;
|
|
407
|
+
timestampMs: number;
|
|
408
|
+
}
|
|
368
409
|
| {
|
|
369
410
|
type: "NodeCancelled";
|
|
370
411
|
runId: string;
|
|
@@ -432,6 +473,31 @@ export type SmithersEvent =
|
|
|
432
473
|
iteration: number;
|
|
433
474
|
timestampMs: number;
|
|
434
475
|
}
|
|
476
|
+
| {
|
|
477
|
+
type: "SteerQueued";
|
|
478
|
+
runId: string;
|
|
479
|
+
nodeId: string;
|
|
480
|
+
steerId: string;
|
|
481
|
+
message: string;
|
|
482
|
+
author?: string;
|
|
483
|
+
timestampMs: number;
|
|
484
|
+
}
|
|
485
|
+
| {
|
|
486
|
+
type: "SteerConsumed";
|
|
487
|
+
runId: string;
|
|
488
|
+
nodeId: string;
|
|
489
|
+
iteration: number;
|
|
490
|
+
attempt: number;
|
|
491
|
+
steerId: string;
|
|
492
|
+
timestampMs: number;
|
|
493
|
+
}
|
|
494
|
+
| {
|
|
495
|
+
type: "SteerExpired";
|
|
496
|
+
runId: string;
|
|
497
|
+
nodeId: string;
|
|
498
|
+
steerId: string;
|
|
499
|
+
timestampMs: number;
|
|
500
|
+
}
|
|
435
501
|
| {
|
|
436
502
|
type: "ToolCallStarted";
|
|
437
503
|
runId: string;
|
|
@@ -660,10 +726,14 @@ export type SmithersEvent =
|
|
|
660
726
|
model: string;
|
|
661
727
|
agent: string;
|
|
662
728
|
inputTokens: number;
|
|
729
|
+
/** Non-cached input tokens. Falls back to inputTokens when the provider omits the breakdown. */
|
|
730
|
+
freshInputTokens?: number;
|
|
663
731
|
outputTokens: number;
|
|
664
732
|
cacheReadTokens?: number;
|
|
665
733
|
cacheWriteTokens?: number;
|
|
666
734
|
reasoningTokens?: number;
|
|
735
|
+
/** Estimated USD cost from Smithers' built-in model price table. */
|
|
736
|
+
costUsd?: number;
|
|
667
737
|
timestampMs: number;
|
|
668
738
|
}
|
|
669
739
|
| {
|
package/src/detectCaptureMode.js
CHANGED
|
@@ -9,13 +9,18 @@ import { detectAgentFamily } from "./detectAgentFamily.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export function detectCaptureMode(agent) {
|
|
11
11
|
const family = detectAgentFamily(agent);
|
|
12
|
+
const constructorName = String(agent?.constructor?.name ?? "").toLowerCase();
|
|
12
13
|
const mode = agent?.opts?.mode ?? agent?.mode;
|
|
13
14
|
if (family === "pi") {
|
|
14
15
|
if (mode === "rpc") return "rpc-events";
|
|
15
16
|
if (mode === "json") return "cli-json-stream";
|
|
16
17
|
return "cli-text";
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
// NanocodexAgent consumes its private JSONL bridge internally and exposes
|
|
20
|
+
// already-decoded assistant text through onStdout plus sanitized lifecycle
|
|
21
|
+
// events through onEvent. Parsing that text again as Codex CLI JSONL creates
|
|
22
|
+
// false truncated-json-stream warnings and loses valid deltas.
|
|
23
|
+
if (family === "codex") return constructorName.includes("nanocodexagent") ? "cli-text" : "cli-json-stream";
|
|
19
24
|
const outputFormat = agent?.opts?.outputFormat ?? agent?.outputFormat;
|
|
20
25
|
if (family === "openai" || family === "anthropic") return "sdk-events";
|
|
21
26
|
if (outputFormat === "stream-json") return "cli-json-stream";
|
package/src/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ type AgentSessionTranscriptEvent = {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
type RunStatus = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "waiting-quota" | "paused" | "finished" | "continued" | "failed" | "cancelled";
|
|
136
|
-
type RunState = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "waiting-quota" | "paused" | "recovering" | "stale" | "orphaned" | "failed" | "cancelled" | "succeeded" | "unknown";
|
|
136
|
+
type RunState = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "waiting-quota" | "paused" | "recovering" | "stale" | "orphaned" | "failed" | "cancelled" | "succeeded" | "succeeded-with-failures" | "unknown";
|
|
137
137
|
type AgentCliActionKind = "turn" | "command" | "tool" | "file_change" | "web_search" | "todo_list" | "reasoning" | "warning" | "note";
|
|
138
138
|
type AgentCliActionPhase = "started" | "updated" | "completed";
|
|
139
139
|
type AgentCliEventLevel = "debug" | "info" | "warning" | "error";
|
|
@@ -169,6 +169,14 @@ type AgentCliCompletedEvent = {
|
|
|
169
169
|
usage?: Record<string, unknown>;
|
|
170
170
|
};
|
|
171
171
|
type AgentCliEvent = AgentCliStartedEvent | AgentCliActionEvent | AgentCliCompletedEvent;
|
|
172
|
+
type RunCancellationSource$1 = {
|
|
173
|
+
kind: "signal" | "rpc" | "cli" | "engine";
|
|
174
|
+
detail?: string;
|
|
175
|
+
signal?: string;
|
|
176
|
+
clientPid?: number;
|
|
177
|
+
requestId?: string;
|
|
178
|
+
clientIdentity?: string;
|
|
179
|
+
};
|
|
172
180
|
type SmithersEvent$2 = {
|
|
173
181
|
type: "SupervisorStarted";
|
|
174
182
|
runId: string;
|
|
@@ -209,6 +217,19 @@ type SmithersEvent$2 = {
|
|
|
209
217
|
before: RunState;
|
|
210
218
|
after: RunState;
|
|
211
219
|
timestampMs: number;
|
|
220
|
+
} | {
|
|
221
|
+
type: "RunConcurrencySaturated";
|
|
222
|
+
runId: string;
|
|
223
|
+
requestedDemand: number;
|
|
224
|
+
effectiveCap: number;
|
|
225
|
+
remediationCommand: string;
|
|
226
|
+
/** Present when a lifecycle-linked descendant caused the owner's budget to saturate. */
|
|
227
|
+
descendantRunId?: string;
|
|
228
|
+
/** Which owner budget bound admission. Historical events omit this. */
|
|
229
|
+
budget?: "run" | "subtree";
|
|
230
|
+
/** Present when `budget` is `subtree`. */
|
|
231
|
+
subtreeGroupId?: string;
|
|
232
|
+
timestampMs: number;
|
|
212
233
|
} | {
|
|
213
234
|
type: "RunFinished";
|
|
214
235
|
runId: string;
|
|
@@ -230,6 +251,8 @@ type SmithersEvent$2 = {
|
|
|
230
251
|
type: "RunCancelled";
|
|
231
252
|
runId: string;
|
|
232
253
|
timestampMs: number;
|
|
254
|
+
/** Missing only on historical or unattributed cancellation events. */
|
|
255
|
+
source?: RunCancellationSource$1;
|
|
233
256
|
} | {
|
|
234
257
|
type: "RunContinuedAsNew";
|
|
235
258
|
runId: string;
|
|
@@ -433,6 +456,16 @@ type SmithersEvent$2 = {
|
|
|
433
456
|
attempt: number;
|
|
434
457
|
error: unknown;
|
|
435
458
|
timestampMs: number;
|
|
459
|
+
} | {
|
|
460
|
+
type: "NodeStalled";
|
|
461
|
+
runId: string;
|
|
462
|
+
nodeId: string;
|
|
463
|
+
iteration: number;
|
|
464
|
+
attempt: number;
|
|
465
|
+
identicalFailures: number;
|
|
466
|
+
signature: string;
|
|
467
|
+
error: unknown;
|
|
468
|
+
timestampMs: number;
|
|
436
469
|
} | {
|
|
437
470
|
type: "NodeCancelled";
|
|
438
471
|
runId: string;
|
|
@@ -491,6 +524,28 @@ type SmithersEvent$2 = {
|
|
|
491
524
|
nodeId: string;
|
|
492
525
|
iteration: number;
|
|
493
526
|
timestampMs: number;
|
|
527
|
+
} | {
|
|
528
|
+
type: "SteerQueued";
|
|
529
|
+
runId: string;
|
|
530
|
+
nodeId: string;
|
|
531
|
+
steerId: string;
|
|
532
|
+
message: string;
|
|
533
|
+
author?: string;
|
|
534
|
+
timestampMs: number;
|
|
535
|
+
} | {
|
|
536
|
+
type: "SteerConsumed";
|
|
537
|
+
runId: string;
|
|
538
|
+
nodeId: string;
|
|
539
|
+
iteration: number;
|
|
540
|
+
attempt: number;
|
|
541
|
+
steerId: string;
|
|
542
|
+
timestampMs: number;
|
|
543
|
+
} | {
|
|
544
|
+
type: "SteerExpired";
|
|
545
|
+
runId: string;
|
|
546
|
+
nodeId: string;
|
|
547
|
+
steerId: string;
|
|
548
|
+
timestampMs: number;
|
|
494
549
|
} | {
|
|
495
550
|
type: "ToolCallStarted";
|
|
496
551
|
runId: string;
|
|
@@ -697,10 +752,14 @@ type SmithersEvent$2 = {
|
|
|
697
752
|
model: string;
|
|
698
753
|
agent: string;
|
|
699
754
|
inputTokens: number;
|
|
755
|
+
/** Non-cached input tokens. Falls back to inputTokens when the provider omits the breakdown. */
|
|
756
|
+
freshInputTokens?: number;
|
|
700
757
|
outputTokens: number;
|
|
701
758
|
cacheReadTokens?: number;
|
|
702
759
|
cacheWriteTokens?: number;
|
|
703
760
|
reasoningTokens?: number;
|
|
761
|
+
/** Estimated USD cost from Smithers' built-in model price table. */
|
|
762
|
+
costUsd?: number;
|
|
704
763
|
timestampMs: number;
|
|
705
764
|
} | {
|
|
706
765
|
type: "SnapshotCaptured";
|
|
@@ -1267,6 +1326,17 @@ type CorrelationContext$1 = CorrelationContext$5;
|
|
|
1267
1326
|
declare function updateCurrentCorrelationContext(patch: CorrelationPatch$1): void;
|
|
1268
1327
|
type CorrelationPatch$1 = CorrelationPatch$5;
|
|
1269
1328
|
|
|
1329
|
+
/**
|
|
1330
|
+
* Scope imperative Smithers logs to one host-owned Effect runner. Unlike
|
|
1331
|
+
* {@link setSmithersLogRunner}, this is concurrency-safe: parallel embedded
|
|
1332
|
+
* engine instances keep their loggers isolated across awaits and timers.
|
|
1333
|
+
*
|
|
1334
|
+
* @template T
|
|
1335
|
+
* @param {SmithersLogRunner} runner
|
|
1336
|
+
* @param {() => T} execute
|
|
1337
|
+
* @returns {T}
|
|
1338
|
+
*/
|
|
1339
|
+
declare function runWithSmithersLogRunner<T>(runner: SmithersLogRunner, execute: () => T): T;
|
|
1270
1340
|
/**
|
|
1271
1341
|
* Install the Effect runtime used by fire-and-forget observability logs.
|
|
1272
1342
|
* Returns a restore function so tests and embedded hosts can scope overrides.
|
|
@@ -1312,10 +1382,11 @@ type MetricLabels = MetricLabels$1;
|
|
|
1312
1382
|
type MetricsServiceShape = MetricsServiceShape$3;
|
|
1313
1383
|
type MetricsSnapshot = MetricsSnapshot$1;
|
|
1314
1384
|
type ResolvedSmithersObservabilityOptions = ResolvedSmithersObservabilityOptions$2;
|
|
1385
|
+
type RunCancellationSource = RunCancellationSource$1;
|
|
1315
1386
|
type SmithersEvent = SmithersEvent$2;
|
|
1316
1387
|
type SmithersLogFormat = SmithersLogFormat$1;
|
|
1317
1388
|
type SmithersMetricDefinition = SmithersMetricDefinition$2;
|
|
1318
1389
|
type SmithersObservabilityOptions = SmithersObservabilityOptions$4;
|
|
1319
1390
|
type SmithersObservabilityService = SmithersObservabilityService$2;
|
|
1320
1391
|
|
|
1321
|
-
export { type CorrelationContext, CorrelationContextLive, type CorrelationContextPatch, CorrelationContextService, type CorrelationPatch, type MetricLabels, MetricsService, MetricsServiceLive, type MetricsServiceShape, type MetricsSnapshot, type ResolvedSmithersObservabilityOptions, type SmithersEvent, type SmithersLogFormat, type SmithersMetricDefinition, SmithersObservability, type SmithersObservabilityOptions, type SmithersObservabilityService, TracingService, TracingServiceLive, activeNodes, activeRuns, annotateSmithersTrace, approvalPending, approvalWaitDuration, approvalsDenied, approvalsGranted, approvalsRequested, attemptDuration, cacheHits, cacheMisses, correlationContextFiberRef, correlationContextToLogAnnotations, createSmithersObservabilityLayer, createSmithersOtelLayer, createSmithersRuntimeLayer, dbQueryDuration, dbRetries, dbTransactionDuration, dbTransactionRetries, dbTransactionRollbacks, errorsTotal, eventsEmittedTotal, externalWaitAsyncPending, getCurrentCorrelationContext, getCurrentCorrelationContextEffect, getCurrentSmithersTraceAnnotations, getCurrentSmithersTraceSpan, hotReloadDuration, hotReloadFailures, hotReloads, httpRequestDuration, httpRequests, logDebug, logError, logInfo, logWarning, makeSmithersSpanAttributes, mergeCorrelationContext, metricsServiceAdapter, nodeDuration, nodeRetriesTotal, nodesFailed, nodesFinished, nodesStarted, processHeapUsedBytes, processMemoryRssBytes, processUptimeSeconds, prometheusContentType, promptSizeBytes, renderPrometheusMetrics, replaysStarted, resolveSmithersObservabilityOptions, responseSizeBytes, rewindDurationMs, rewindFramesDeleted, rewindRollbackTotal, rewindSandboxesReverted, rewindTotal, runDuration, runForksCreated, runWithCorrelationContext, runsAncestryDepth, runsCancelledTotal, runsCarriedStateBytes, runsContinuedTotal, runsFailedTotal, runsFinishedTotal, runsResumedTotal, runsTotal, sandboxActive, sandboxBundleSizeBytes, sandboxCompletedTotal, sandboxCreatedTotal, sandboxDurationMs, sandboxPatchCount, sandboxTransportDurationMs, schedulerConcurrencyUtilization, schedulerQueueDepth, schedulerWaitDuration, scorerEventsFailed, scorerEventsFinished, scorerEventsStarted, setSmithersLogRunner, smithersMetricCatalog, smithersMetrics, smithersSpanNames, snapshotDuration, snapshotsCaptured, timerDelayDuration, timersCancelled, timersCreated, timersFired, timersPending, toPrometheusMetricName, tokensCacheReadTotal, tokensCacheWriteTotal, tokensContextWindowBucketTotal, tokensContextWindowPerCall, tokensInputPerCall, tokensInputTotal, tokensOutputPerCall, tokensOutputTotal, tokensReasoningTotal, toolCallErrorsTotal, toolCallsTotal, toolDuration, toolOutputTruncatedTotal, trackEvent as trackSmithersEvent, updateCurrentCorrelationContext, updateProcessMetrics, vcsDuration, withCorrelationContext, withCurrentCorrelationContext, withSmithersSpan };
|
|
1392
|
+
export { type CorrelationContext, CorrelationContextLive, type CorrelationContextPatch, CorrelationContextService, type CorrelationPatch, type MetricLabels, MetricsService, MetricsServiceLive, type MetricsServiceShape, type MetricsSnapshot, type ResolvedSmithersObservabilityOptions, type RunCancellationSource, type SmithersEvent, type SmithersLogFormat, type SmithersMetricDefinition, SmithersObservability, type SmithersObservabilityOptions, type SmithersObservabilityService, TracingService, TracingServiceLive, activeNodes, activeRuns, annotateSmithersTrace, approvalPending, approvalWaitDuration, approvalsDenied, approvalsGranted, approvalsRequested, attemptDuration, cacheHits, cacheMisses, correlationContextFiberRef, correlationContextToLogAnnotations, createSmithersObservabilityLayer, createSmithersOtelLayer, createSmithersRuntimeLayer, dbQueryDuration, dbRetries, dbTransactionDuration, dbTransactionRetries, dbTransactionRollbacks, errorsTotal, eventsEmittedTotal, externalWaitAsyncPending, getCurrentCorrelationContext, getCurrentCorrelationContextEffect, getCurrentSmithersTraceAnnotations, getCurrentSmithersTraceSpan, hotReloadDuration, hotReloadFailures, hotReloads, httpRequestDuration, httpRequests, logDebug, logError, logInfo, logWarning, makeSmithersSpanAttributes, mergeCorrelationContext, metricsServiceAdapter, nodeDuration, nodeRetriesTotal, nodesFailed, nodesFinished, nodesStarted, processHeapUsedBytes, processMemoryRssBytes, processUptimeSeconds, prometheusContentType, promptSizeBytes, renderPrometheusMetrics, replaysStarted, resolveSmithersObservabilityOptions, responseSizeBytes, rewindDurationMs, rewindFramesDeleted, rewindRollbackTotal, rewindSandboxesReverted, rewindTotal, runDuration, runForksCreated, runWithCorrelationContext, runWithSmithersLogRunner, runsAncestryDepth, runsCancelledTotal, runsCarriedStateBytes, runsContinuedTotal, runsFailedTotal, runsFinishedTotal, runsResumedTotal, runsTotal, sandboxActive, sandboxBundleSizeBytes, sandboxCompletedTotal, sandboxCreatedTotal, sandboxDurationMs, sandboxPatchCount, sandboxTransportDurationMs, schedulerConcurrencyUtilization, schedulerQueueDepth, schedulerWaitDuration, scorerEventsFailed, scorerEventsFinished, scorerEventsStarted, setSmithersLogRunner, smithersMetricCatalog, smithersMetrics, smithersSpanNames, snapshotDuration, snapshotsCaptured, timerDelayDuration, timersCancelled, timersCreated, timersFired, timersPending, toPrometheusMetricName, tokensCacheReadTotal, tokensCacheWriteTotal, tokensContextWindowBucketTotal, tokensContextWindowPerCall, tokensInputPerCall, tokensInputTotal, tokensOutputPerCall, tokensOutputTotal, tokensReasoningTotal, toolCallErrorsTotal, toolCallsTotal, toolDuration, toolOutputTruncatedTotal, trackEvent as trackSmithersEvent, updateCurrentCorrelationContext, updateProcessMetrics, vcsDuration, withCorrelationContext, withCurrentCorrelationContext, withSmithersSpan };
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
/** @typedef {import("./_coreMetricsShape.ts").MetricsServiceShape} MetricsServiceShape */
|
|
6
6
|
/** @typedef {import("./_coreMetricsShape.ts").MetricsSnapshot} MetricsSnapshot */
|
|
7
7
|
/** @typedef {import("./ResolvedSmithersObservabilityOptions.ts").ResolvedSmithersObservabilityOptions} ResolvedSmithersObservabilityOptions */
|
|
8
|
+
/** @typedef {import("./SmithersEvent.ts").RunCancellationSource} RunCancellationSource */
|
|
8
9
|
/** @typedef {import("./SmithersEvent.ts").SmithersEvent} SmithersEvent */
|
|
9
10
|
/** @typedef {import("./SmithersLogFormat.ts").SmithersLogFormat} SmithersLogFormat */
|
|
10
11
|
/** @typedef {import("./SmithersMetricDefinition.ts").SmithersMetricDefinition} SmithersMetricDefinition */
|
|
@@ -133,4 +134,4 @@ export {
|
|
|
133
134
|
withCurrentCorrelationContext,
|
|
134
135
|
} from "./correlation.js";
|
|
135
136
|
export { updateCurrentCorrelationContext } from "./correlation.js";
|
|
136
|
-
export { logDebug, logInfo, logWarning, logError, setSmithersLogRunner } from "./logging.js";
|
|
137
|
+
export { logDebug, logInfo, logWarning, logError, runWithSmithersLogRunner, setSmithersLogRunner } from "./logging.js";
|
package/src/logging.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect, Logger, LogLevel } from "effect";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
import { getCurrentSmithersTraceAnnotations } from "./getCurrentSmithersTraceAnnotations.js";
|
|
3
4
|
import {
|
|
4
5
|
correlationContextToLogAnnotations,
|
|
@@ -17,6 +18,7 @@ const LOG_LEVEL_WARNING = 3;
|
|
|
17
18
|
const LOG_LEVEL_ERROR = 4;
|
|
18
19
|
const LOG_RUNNER_KEY = Symbol.for("smithers.observability.logRunner");
|
|
19
20
|
const defaultLoggerLayer = Logger.layer([Logger.consoleLogFmt]);
|
|
21
|
+
const runnerStorage = new AsyncLocalStorage();
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Resolve the minimum imperative log level. The environment value is an
|
|
@@ -77,7 +79,21 @@ const defaultRunner = {
|
|
|
77
79
|
|
|
78
80
|
/** @returns {SmithersLogRunner} */
|
|
79
81
|
function getLogRunner() {
|
|
80
|
-
return getRunnerState().runner ?? defaultRunner;
|
|
82
|
+
return runnerStorage.getStore() ?? getRunnerState().runner ?? defaultRunner;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Scope imperative Smithers logs to one host-owned Effect runner. Unlike
|
|
87
|
+
* {@link setSmithersLogRunner}, this is concurrency-safe: parallel embedded
|
|
88
|
+
* engine instances keep their loggers isolated across awaits and timers.
|
|
89
|
+
*
|
|
90
|
+
* @template T
|
|
91
|
+
* @param {SmithersLogRunner} runner
|
|
92
|
+
* @param {() => T} execute
|
|
93
|
+
* @returns {T}
|
|
94
|
+
*/
|
|
95
|
+
export function runWithSmithersLogRunner(runner, execute) {
|
|
96
|
+
return runnerStorage.run(runner, execute);
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
/**
|
package/src/metrics/index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ type AgentSessionTranscriptEvent = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
type RunStatus = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "waiting-quota" | "paused" | "finished" | "continued" | "failed" | "cancelled";
|
|
123
|
-
type RunState = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "waiting-quota" | "paused" | "recovering" | "stale" | "orphaned" | "failed" | "cancelled" | "succeeded" | "unknown";
|
|
123
|
+
type RunState = "running" | "waiting-approval" | "waiting-event" | "waiting-timer" | "waiting-quota" | "paused" | "recovering" | "stale" | "orphaned" | "failed" | "cancelled" | "succeeded" | "succeeded-with-failures" | "unknown";
|
|
124
124
|
type AgentCliActionKind = "turn" | "command" | "tool" | "file_change" | "web_search" | "todo_list" | "reasoning" | "warning" | "note";
|
|
125
125
|
type AgentCliActionPhase = "started" | "updated" | "completed";
|
|
126
126
|
type AgentCliEventLevel = "debug" | "info" | "warning" | "error";
|
|
@@ -156,6 +156,14 @@ type AgentCliCompletedEvent = {
|
|
|
156
156
|
usage?: Record<string, unknown>;
|
|
157
157
|
};
|
|
158
158
|
type AgentCliEvent = AgentCliStartedEvent | AgentCliActionEvent | AgentCliCompletedEvent;
|
|
159
|
+
type RunCancellationSource$1 = {
|
|
160
|
+
kind: "signal" | "rpc" | "cli" | "engine";
|
|
161
|
+
detail?: string;
|
|
162
|
+
signal?: string;
|
|
163
|
+
clientPid?: number;
|
|
164
|
+
requestId?: string;
|
|
165
|
+
clientIdentity?: string;
|
|
166
|
+
};
|
|
159
167
|
type SmithersEvent$2 = {
|
|
160
168
|
type: "SupervisorStarted";
|
|
161
169
|
runId: string;
|
|
@@ -196,6 +204,19 @@ type SmithersEvent$2 = {
|
|
|
196
204
|
before: RunState;
|
|
197
205
|
after: RunState;
|
|
198
206
|
timestampMs: number;
|
|
207
|
+
} | {
|
|
208
|
+
type: "RunConcurrencySaturated";
|
|
209
|
+
runId: string;
|
|
210
|
+
requestedDemand: number;
|
|
211
|
+
effectiveCap: number;
|
|
212
|
+
remediationCommand: string;
|
|
213
|
+
/** Present when a lifecycle-linked descendant caused the owner's budget to saturate. */
|
|
214
|
+
descendantRunId?: string;
|
|
215
|
+
/** Which owner budget bound admission. Historical events omit this. */
|
|
216
|
+
budget?: "run" | "subtree";
|
|
217
|
+
/** Present when `budget` is `subtree`. */
|
|
218
|
+
subtreeGroupId?: string;
|
|
219
|
+
timestampMs: number;
|
|
199
220
|
} | {
|
|
200
221
|
type: "RunFinished";
|
|
201
222
|
runId: string;
|
|
@@ -217,6 +238,8 @@ type SmithersEvent$2 = {
|
|
|
217
238
|
type: "RunCancelled";
|
|
218
239
|
runId: string;
|
|
219
240
|
timestampMs: number;
|
|
241
|
+
/** Missing only on historical or unattributed cancellation events. */
|
|
242
|
+
source?: RunCancellationSource$1;
|
|
220
243
|
} | {
|
|
221
244
|
type: "RunContinuedAsNew";
|
|
222
245
|
runId: string;
|
|
@@ -420,6 +443,16 @@ type SmithersEvent$2 = {
|
|
|
420
443
|
attempt: number;
|
|
421
444
|
error: unknown;
|
|
422
445
|
timestampMs: number;
|
|
446
|
+
} | {
|
|
447
|
+
type: "NodeStalled";
|
|
448
|
+
runId: string;
|
|
449
|
+
nodeId: string;
|
|
450
|
+
iteration: number;
|
|
451
|
+
attempt: number;
|
|
452
|
+
identicalFailures: number;
|
|
453
|
+
signature: string;
|
|
454
|
+
error: unknown;
|
|
455
|
+
timestampMs: number;
|
|
423
456
|
} | {
|
|
424
457
|
type: "NodeCancelled";
|
|
425
458
|
runId: string;
|
|
@@ -478,6 +511,28 @@ type SmithersEvent$2 = {
|
|
|
478
511
|
nodeId: string;
|
|
479
512
|
iteration: number;
|
|
480
513
|
timestampMs: number;
|
|
514
|
+
} | {
|
|
515
|
+
type: "SteerQueued";
|
|
516
|
+
runId: string;
|
|
517
|
+
nodeId: string;
|
|
518
|
+
steerId: string;
|
|
519
|
+
message: string;
|
|
520
|
+
author?: string;
|
|
521
|
+
timestampMs: number;
|
|
522
|
+
} | {
|
|
523
|
+
type: "SteerConsumed";
|
|
524
|
+
runId: string;
|
|
525
|
+
nodeId: string;
|
|
526
|
+
iteration: number;
|
|
527
|
+
attempt: number;
|
|
528
|
+
steerId: string;
|
|
529
|
+
timestampMs: number;
|
|
530
|
+
} | {
|
|
531
|
+
type: "SteerExpired";
|
|
532
|
+
runId: string;
|
|
533
|
+
nodeId: string;
|
|
534
|
+
steerId: string;
|
|
535
|
+
timestampMs: number;
|
|
481
536
|
} | {
|
|
482
537
|
type: "ToolCallStarted";
|
|
483
538
|
runId: string;
|
|
@@ -684,10 +739,14 @@ type SmithersEvent$2 = {
|
|
|
684
739
|
model: string;
|
|
685
740
|
agent: string;
|
|
686
741
|
inputTokens: number;
|
|
742
|
+
/** Non-cached input tokens. Falls back to inputTokens when the provider omits the breakdown. */
|
|
743
|
+
freshInputTokens?: number;
|
|
687
744
|
outputTokens: number;
|
|
688
745
|
cacheReadTokens?: number;
|
|
689
746
|
cacheWriteTokens?: number;
|
|
690
747
|
reasoningTokens?: number;
|
|
748
|
+
/** Estimated USD cost from Smithers' built-in model price table. */
|
|
749
|
+
costUsd?: number;
|
|
691
750
|
timestampMs: number;
|
|
692
751
|
} | {
|
|
693
752
|
type: "SnapshotCaptured";
|