-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtypes.ts
More file actions
85 lines (74 loc) · 2.59 KB
/
Copy pathtypes.ts
File metadata and controls
85 lines (74 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { Counter, Histogram, Span, Tracer } from "@opentelemetry/api"
import type { Logger as OtelLogger } from "@opentelemetry/api-logs"
/** Numeric priority map for log levels; higher value = higher severity. */
export const LEVELS = { debug: 0, info: 1, warn: 2, error: 3 } as const
/** Union of supported log level names. */
export type Level = keyof typeof LEVELS
/** Maximum number of entries kept in `pendingToolSpans` and `pendingPermissions` maps. */
export const MAX_PENDING = 500
/** Structured logger forwarded to the opencode `client.app.log` API. */
export type PluginLogger = (
level: Level,
message: string,
extra?: Record<string, unknown>,
) => Promise<void>
/** OTel resource attributes common to every emitted log and metric. */
export type CommonAttrs = { readonly "project.id": string; readonly "enduser.id"?: string }
/** Writable variant of `CommonAttrs`. */
export type MutableCommonAttrs = { -readonly [K in keyof CommonAttrs]: CommonAttrs[K] }
/** In-flight tool execution tracked between `running` and `completed`/`error` part updates. */
export type PendingToolSpan = {
tool: string
sessionID: string
startMs: number
span?: Span
}
/** Permission prompt tracked between `permission.updated` and `permission.replied`. */
export type PendingPermission = {
type: string
title: string
sessionID: string
}
/** OTel metric instruments created once at plugin startup and shared via `HandlerContext`. */
export type Instruments = {
sessionCounter: Counter
tokenCounter: Counter
costCounter: Counter
linesCounter: Counter
commitCounter: Counter
toolDurationHistogram: Histogram
cacheCounter: Counter
sessionDurationHistogram: Histogram
messageCounter: Counter
sessionTokenGauge: Histogram
sessionCostGauge: Histogram
modelUsageCounter: Counter
retryCounter: Counter
subtaskCounter: Counter
}
/** Accumulated per-session totals used for gauge snapshots on session.idle. */
export type SessionTotals = {
startMs: number
tokens: number
cost: number
messages: number
agent: string
}
/** Shared context threaded through every event handler. */
export type HandlerContext = {
logger: OtelLogger
log: PluginLogger
instruments: Instruments
commonAttrs: CommonAttrs
pendingToolSpans: Map<string, PendingToolSpan>
pendingPermissions: Map<string, PendingPermission>
sessionTotals: Map<string, SessionTotals>
disabledMetrics: Set<string>
disabledTraces: Set<string>
tracer: Tracer
tracePrefix: string
sessionSpans: Map<string, Span>
messageSpans: Map<string, Span>
sessionInputs: Map<string, string>
messageOutputs: Map<string, string>
}