@osfactory/otel-hook 0.5.0 → 0.6.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/{adapter-BS7xHKGQ.d.ts → adapter-BJiz6lqM.d.ts} +2 -2
- package/dist/cli.js +47 -24
- package/dist/cli.js.map +1 -1
- package/dist/{events-CzZ5kukS.d.ts → events-B3MHoJTD.d.ts} +72 -1
- package/dist/{filesystem-store-BcOveJYY.d.ts → filesystem-store-r-nNA3BA.d.ts} +1 -1
- package/dist/{hook-DxTakjAD.d.ts → hook-Dh8OO4Wa.d.ts} +4 -4
- package/dist/index.d.ts +11 -11
- package/dist/index.js +50 -24
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -4
- package/dist/install.js +8 -2
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +8 -8
- package/dist/integration.js +2264 -2253
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +757 -212
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-DkTohdIa.d.ts → memory-Bl9ANVff.d.ts} +2 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +13 -2
- package/dist/model.js.map +1 -1
- package/dist/{otlp-log-sink-DaZDPKnR.d.ts → otlp-log-sink-eUEjaLhk.d.ts} +3 -3
- package/dist/{payload-2lnpKodw.d.ts → payload-Ci8_ERm6.d.ts} +1 -1
- package/dist/{ports-B0rC49b3.d.ts → ports-n7KFOpKo.d.ts} +1 -1
- package/dist/providers.d.ts +10 -10
- package/dist/providers.js +32 -13
- package/dist/providers.js.map +1 -1
- package/dist/{registry-DVnPA_b6.d.ts → registry-CIVvRlVK.d.ts} +1 -1
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +11 -6
- package/dist/runtime.js.map +1 -1
- package/dist/{semconv-CtnDdsPk.d.ts → semconv-fPRb-dpU.d.ts} +1 -1
- package/dist/state.d.ts +4 -4
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +945 -412
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +14 -8
- package/dist/testing.js +36 -18
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/telemetry.js
CHANGED
|
@@ -38,10 +38,782 @@ import {
|
|
|
38
38
|
} from "@opentelemetry/semantic-conventions/incubating";
|
|
39
39
|
|
|
40
40
|
// src/version.ts
|
|
41
|
-
var VERSION = "0.
|
|
41
|
+
var VERSION = "0.6.0";
|
|
42
42
|
|
|
43
43
|
// src/telemetry/export-identity.ts
|
|
44
44
|
import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
|
|
45
|
+
|
|
46
|
+
// src/model/events.ts
|
|
47
|
+
import { z as z9 } from "zod";
|
|
48
|
+
|
|
49
|
+
// src/errors/taxonomy.ts
|
|
50
|
+
import { z } from "zod";
|
|
51
|
+
var otelHookErrorCodeSchema = z.enum([
|
|
52
|
+
/** Input was not usable at all (empty stdin, unparsable JSON). */
|
|
53
|
+
"invalid-input",
|
|
54
|
+
/** Input parsed but failed canonical schema validation. */
|
|
55
|
+
"schema-validation-failed",
|
|
56
|
+
/** No adapter claimed the input with sufficient confidence. */
|
|
57
|
+
"provider-unknown",
|
|
58
|
+
/** Several adapters claimed the input at the same confidence. */
|
|
59
|
+
"provider-detection-ambiguous",
|
|
60
|
+
/** An adapter threw or returned a malformed result. */
|
|
61
|
+
"provider-adapter-failure",
|
|
62
|
+
/** Two identity claims disagreed at equal confidence. */
|
|
63
|
+
"identity-conflict",
|
|
64
|
+
/** Required identity fields were absent. */
|
|
65
|
+
"identity-incomplete",
|
|
66
|
+
/** A usage report violated the canonical usage invariants. */
|
|
67
|
+
"usage-invalid",
|
|
68
|
+
/** The state store could not be read or written. */
|
|
69
|
+
"state-store-failure",
|
|
70
|
+
/** The telemetry sink rejected or could not deliver a batch. */
|
|
71
|
+
"telemetry-export-failure",
|
|
72
|
+
/** Content reached the sink boundary in a state the policy forbids. */
|
|
73
|
+
"privacy-policy-violation",
|
|
74
|
+
/** Configuration could not be resolved. */
|
|
75
|
+
"configuration-invalid",
|
|
76
|
+
/** A configured bound (events, batch size) dropped data. */
|
|
77
|
+
"limit-exceeded",
|
|
78
|
+
/**
|
|
79
|
+
* No replay-stable delivery identifier was available for a callback while
|
|
80
|
+
* deduplication was required.
|
|
81
|
+
*/
|
|
82
|
+
"delivery-identifier-unavailable",
|
|
83
|
+
"delivery-claim-superseded",
|
|
84
|
+
/** Anything unanticipated. Always reported, never fatal to the host. */
|
|
85
|
+
"internal-error"
|
|
86
|
+
]);
|
|
87
|
+
var errorSeveritySchema = z.enum(["warning", "error"]);
|
|
88
|
+
var errorPhaseSchema = z.enum([
|
|
89
|
+
"configuration",
|
|
90
|
+
"detection",
|
|
91
|
+
"identity",
|
|
92
|
+
"parsing",
|
|
93
|
+
"normalization",
|
|
94
|
+
"privacy",
|
|
95
|
+
"state",
|
|
96
|
+
"export",
|
|
97
|
+
"shutdown"
|
|
98
|
+
]);
|
|
99
|
+
var failurePostureSchema = z.enum(["fail-open", "fail-closed-attribution"]);
|
|
100
|
+
var ERROR_TAXONOMY = Object.freeze({
|
|
101
|
+
"invalid-input": {
|
|
102
|
+
code: "invalid-input",
|
|
103
|
+
severity: "warning",
|
|
104
|
+
posture: "fail-open",
|
|
105
|
+
retryable: false,
|
|
106
|
+
summary: "Input could not be read or decoded."
|
|
107
|
+
},
|
|
108
|
+
"schema-validation-failed": {
|
|
109
|
+
code: "schema-validation-failed",
|
|
110
|
+
severity: "error",
|
|
111
|
+
posture: "fail-closed-attribution",
|
|
112
|
+
retryable: false,
|
|
113
|
+
summary: "A canonical event failed schema validation and was dropped."
|
|
114
|
+
},
|
|
115
|
+
"provider-unknown": {
|
|
116
|
+
code: "provider-unknown",
|
|
117
|
+
severity: "warning",
|
|
118
|
+
posture: "fail-closed-attribution",
|
|
119
|
+
retryable: false,
|
|
120
|
+
summary: "No adapter recognized the source provider; the input stays unattributed."
|
|
121
|
+
},
|
|
122
|
+
"provider-detection-ambiguous": {
|
|
123
|
+
code: "provider-detection-ambiguous",
|
|
124
|
+
severity: "warning",
|
|
125
|
+
posture: "fail-closed-attribution",
|
|
126
|
+
retryable: false,
|
|
127
|
+
summary: "Multiple adapters claimed the input at equal confidence."
|
|
128
|
+
},
|
|
129
|
+
"provider-adapter-failure": {
|
|
130
|
+
code: "provider-adapter-failure",
|
|
131
|
+
severity: "error",
|
|
132
|
+
posture: "fail-open",
|
|
133
|
+
retryable: false,
|
|
134
|
+
summary: "A provider adapter failed while parsing."
|
|
135
|
+
},
|
|
136
|
+
"identity-conflict": {
|
|
137
|
+
code: "identity-conflict",
|
|
138
|
+
severity: "error",
|
|
139
|
+
posture: "fail-closed-attribution",
|
|
140
|
+
retryable: false,
|
|
141
|
+
summary: "Identity claims disagreed; attribution was declined."
|
|
142
|
+
},
|
|
143
|
+
"identity-incomplete": {
|
|
144
|
+
code: "identity-incomplete",
|
|
145
|
+
severity: "warning",
|
|
146
|
+
posture: "fail-closed-attribution",
|
|
147
|
+
retryable: false,
|
|
148
|
+
summary: "Required identity fields were missing; attribution was declined."
|
|
149
|
+
},
|
|
150
|
+
"usage-invalid": {
|
|
151
|
+
code: "usage-invalid",
|
|
152
|
+
severity: "error",
|
|
153
|
+
posture: "fail-open",
|
|
154
|
+
retryable: false,
|
|
155
|
+
summary: "A usage report violated the canonical usage invariants."
|
|
156
|
+
},
|
|
157
|
+
"state-store-failure": {
|
|
158
|
+
code: "state-store-failure",
|
|
159
|
+
severity: "warning",
|
|
160
|
+
posture: "fail-open",
|
|
161
|
+
retryable: true,
|
|
162
|
+
summary: "State could not be read or written; derived values may be incomplete."
|
|
163
|
+
},
|
|
164
|
+
"telemetry-export-failure": {
|
|
165
|
+
code: "telemetry-export-failure",
|
|
166
|
+
severity: "warning",
|
|
167
|
+
posture: "fail-open",
|
|
168
|
+
retryable: true,
|
|
169
|
+
summary: "The telemetry sink could not accept a batch."
|
|
170
|
+
},
|
|
171
|
+
"privacy-policy-violation": {
|
|
172
|
+
code: "privacy-policy-violation",
|
|
173
|
+
severity: "error",
|
|
174
|
+
posture: "fail-closed-attribution",
|
|
175
|
+
retryable: false,
|
|
176
|
+
summary: "Content violated the resolved privacy policy and was dropped."
|
|
177
|
+
},
|
|
178
|
+
"configuration-invalid": {
|
|
179
|
+
code: "configuration-invalid",
|
|
180
|
+
severity: "error",
|
|
181
|
+
posture: "fail-open",
|
|
182
|
+
retryable: false,
|
|
183
|
+
summary: "Configuration could not be resolved; defaults apply."
|
|
184
|
+
},
|
|
185
|
+
"limit-exceeded": {
|
|
186
|
+
code: "limit-exceeded",
|
|
187
|
+
severity: "warning",
|
|
188
|
+
posture: "fail-open",
|
|
189
|
+
retryable: false,
|
|
190
|
+
summary: "A configured bound was reached and data was dropped."
|
|
191
|
+
},
|
|
192
|
+
"delivery-identifier-unavailable": {
|
|
193
|
+
code: "delivery-identifier-unavailable",
|
|
194
|
+
severity: "warning",
|
|
195
|
+
// Fail-open: the observation is still attributed and exported. Only the
|
|
196
|
+
// at-most-once guarantee is missing, and refusing the telemetry to protect
|
|
197
|
+
// a duplicate count would trade a certain loss for a possible one.
|
|
198
|
+
posture: "fail-open",
|
|
199
|
+
retryable: false,
|
|
200
|
+
summary: "No replay-stable delivery identifier was available; this callback was exported without deduplication."
|
|
201
|
+
},
|
|
202
|
+
"delivery-claim-superseded": {
|
|
203
|
+
code: "delivery-claim-superseded",
|
|
204
|
+
severity: "warning",
|
|
205
|
+
// Fail-open, and specifically *not* silent. A peer reclaimed this callback's
|
|
206
|
+
// claim while this process was still working on it, which means the
|
|
207
|
+
// configured stale window is shorter than this installation's real worst
|
|
208
|
+
// case. Both processes may now have exported the callback, so the
|
|
209
|
+
// at-most-once guarantee did not hold for it — the only honest response is
|
|
210
|
+
// to say so and let the operator raise the window.
|
|
211
|
+
posture: "fail-open",
|
|
212
|
+
retryable: false,
|
|
213
|
+
summary: "A delivery claim was reclaimed by another process before this one committed; the callback may have been exported twice."
|
|
214
|
+
},
|
|
215
|
+
"internal-error": {
|
|
216
|
+
code: "internal-error",
|
|
217
|
+
severity: "error",
|
|
218
|
+
posture: "fail-open",
|
|
219
|
+
retryable: false,
|
|
220
|
+
summary: "An unexpected failure was contained."
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
var describeErrorCode = (code) => ERROR_TAXONOMY[code];
|
|
224
|
+
var attributionOutcomeSchema = z.enum([
|
|
225
|
+
/** Identity resolved; events carry provider and session identity. */
|
|
226
|
+
"attributed",
|
|
227
|
+
/** Identity could not be established safely; nothing was attributed. */
|
|
228
|
+
"declined",
|
|
229
|
+
/** Attribution was attempted and failed unexpectedly. */
|
|
230
|
+
"failed",
|
|
231
|
+
/** Input was recognized but intentionally carried no telemetry. */
|
|
232
|
+
"not-applicable"
|
|
233
|
+
]);
|
|
234
|
+
var attributionReasonSchema = z.enum([
|
|
235
|
+
"provider-unknown",
|
|
236
|
+
"provider-detection-ambiguous",
|
|
237
|
+
"identity-conflict",
|
|
238
|
+
"identity-incomplete",
|
|
239
|
+
"adapter-ignored-input",
|
|
240
|
+
"adapter-failure",
|
|
241
|
+
"invalid-input",
|
|
242
|
+
"internal-error"
|
|
243
|
+
]);
|
|
244
|
+
|
|
245
|
+
// src/model/content.ts
|
|
246
|
+
import { z as z3 } from "zod";
|
|
247
|
+
|
|
248
|
+
// src/model/primitives.ts
|
|
249
|
+
import { z as z2 } from "zod";
|
|
250
|
+
var MAX_IDENTIFIER_LENGTH = 256;
|
|
251
|
+
var MAX_ATTRIBUTE_STRING_LENGTH = 4096;
|
|
252
|
+
var MAX_ATTRIBUTE_ARRAY_LENGTH = 128;
|
|
253
|
+
var nonEmptyStringSchema = z2.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
254
|
+
var epochMillisSchema = z2.number().int().min(0).max(864e13);
|
|
255
|
+
var durationMillisSchema = z2.number().min(0).finite();
|
|
256
|
+
var tokenCountSchema = z2.number().int().min(0);
|
|
257
|
+
var sequenceNumberSchema = z2.number().int().min(0);
|
|
258
|
+
var brandedIdSchema = () => z2.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
259
|
+
var invocationIdSchema = brandedIdSchema().brand();
|
|
260
|
+
var sessionIdSchema = brandedIdSchema().brand();
|
|
261
|
+
var eventIdSchema = brandedIdSchema().brand();
|
|
262
|
+
var WORKSPACE_ID_PATTERN = /^[a-z][a-z0-9]{0,15}:[A-Za-z0-9_-]{8,128}$/;
|
|
263
|
+
var workspaceIdSchema = z2.string().regex(WORKSPACE_ID_PATTERN, "workspace id must be an opaque `<scheme>:<token>` handle").brand();
|
|
264
|
+
var PROVIDER_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
265
|
+
var providerIdSchema = z2.string().min(1).max(64).regex(PROVIDER_ID_PATTERN, "provider id must be lowercase and hyphenated").brand();
|
|
266
|
+
var UNKNOWN_PROVIDER_ID = "unknown";
|
|
267
|
+
var resolvedProviderIdSchema = z2.union([
|
|
268
|
+
providerIdSchema,
|
|
269
|
+
z2.literal(UNKNOWN_PROVIDER_ID)
|
|
270
|
+
]);
|
|
271
|
+
var attributePrimitiveSchema = z2.union([
|
|
272
|
+
z2.string().max(MAX_ATTRIBUTE_STRING_LENGTH),
|
|
273
|
+
z2.number().finite(),
|
|
274
|
+
z2.boolean()
|
|
275
|
+
]);
|
|
276
|
+
var attributeValueSchema = z2.union([
|
|
277
|
+
attributePrimitiveSchema,
|
|
278
|
+
z2.array(attributePrimitiveSchema).max(MAX_ATTRIBUTE_ARRAY_LENGTH)
|
|
279
|
+
]);
|
|
280
|
+
var attributesSchema = z2.record(z2.string().min(1).max(MAX_IDENTIFIER_LENGTH), attributeValueSchema);
|
|
281
|
+
var detectionConfidenceSchema = z2.enum(["none", "weak", "strong", "exact"]);
|
|
282
|
+
var DETECTION_CONFIDENCE_RANK = Object.freeze({
|
|
283
|
+
none: 0,
|
|
284
|
+
weak: 1,
|
|
285
|
+
strong: 2,
|
|
286
|
+
exact: 3
|
|
287
|
+
});
|
|
288
|
+
var sourceTransportSchema = z2.enum([
|
|
289
|
+
"hook-stdin",
|
|
290
|
+
"cli-argument",
|
|
291
|
+
"library-call",
|
|
292
|
+
"test-fixture"
|
|
293
|
+
]);
|
|
294
|
+
|
|
295
|
+
// src/model/content.ts
|
|
296
|
+
var contentKindSchema = z3.enum([
|
|
297
|
+
"prompt",
|
|
298
|
+
"response",
|
|
299
|
+
"reasoning",
|
|
300
|
+
"tool-input",
|
|
301
|
+
"tool-output",
|
|
302
|
+
"error-message",
|
|
303
|
+
"system-instruction",
|
|
304
|
+
"attachment"
|
|
305
|
+
]);
|
|
306
|
+
var contentRoleSchema = z3.enum(["user", "assistant", "system", "tool", "unknown"]);
|
|
307
|
+
var contentDisclosureSchema = z3.enum(["omitted", "masked", "redacted", "raw"]);
|
|
308
|
+
var CONTENT_HASH_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
309
|
+
var contentFactSchema = z3.strictObject({
|
|
310
|
+
kind: contentKindSchema,
|
|
311
|
+
role: contentRoleSchema.optional(),
|
|
312
|
+
/** Unicode code point count of the original content. */
|
|
313
|
+
characterLength: z3.number().int().min(0),
|
|
314
|
+
/** UTF-8 byte length of the original content. */
|
|
315
|
+
byteLength: z3.number().int().min(0),
|
|
316
|
+
/** Stable salted digest of the original content. */
|
|
317
|
+
contentHash: z3.string().regex(CONTENT_HASH_PATTERN),
|
|
318
|
+
disclosure: contentDisclosureSchema,
|
|
319
|
+
/** Disclosed text, bounded by the privacy policy. Absent when omitted. */
|
|
320
|
+
text: z3.string().optional(),
|
|
321
|
+
/** True when `text` was cut short by the configured string bound. */
|
|
322
|
+
truncated: z3.boolean(),
|
|
323
|
+
/** Number of secret-looking spans replaced while producing `text`. */
|
|
324
|
+
secretsRedacted: z3.number().int().min(0),
|
|
325
|
+
/** Optional non-sensitive label, e.g. a MIME type or tool name. */
|
|
326
|
+
label: nonEmptyStringSchema.optional()
|
|
327
|
+
});
|
|
328
|
+
var contentFactsSchema = z3.array(contentFactSchema).max(64);
|
|
329
|
+
|
|
330
|
+
// src/model/extensions.ts
|
|
331
|
+
import { z as z4 } from "zod";
|
|
332
|
+
var EXTENSION_KEY_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*(?:\.[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*)+$/;
|
|
333
|
+
var RESERVED_EXTENSION_NAMESPACES = Object.freeze([
|
|
334
|
+
"otelhook",
|
|
335
|
+
"otel",
|
|
336
|
+
"telemetry"
|
|
337
|
+
]);
|
|
338
|
+
var MAX_EXTENSION_ENTRIES = 64;
|
|
339
|
+
var extensionKeyNamespace = (key) => key.slice(0, key.indexOf("."));
|
|
340
|
+
var isReservedExtensionNamespace = (key) => RESERVED_EXTENSION_NAMESPACES.includes(extensionKeyNamespace(key));
|
|
341
|
+
var extensionsSchema = z4.record(z4.string(), attributeValueSchema).check((ctx) => {
|
|
342
|
+
const keys = Object.keys(ctx.value);
|
|
343
|
+
if (keys.length > MAX_EXTENSION_ENTRIES) {
|
|
344
|
+
ctx.issues.push({
|
|
345
|
+
code: "custom",
|
|
346
|
+
input: ctx.value,
|
|
347
|
+
message: `extensions may contain at most ${MAX_EXTENSION_ENTRIES} entries`
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
for (const key of keys) {
|
|
351
|
+
if (!EXTENSION_KEY_PATTERN.test(key)) {
|
|
352
|
+
ctx.issues.push({
|
|
353
|
+
code: "custom",
|
|
354
|
+
input: ctx.value,
|
|
355
|
+
path: [key],
|
|
356
|
+
message: `extension key ${JSON.stringify(key)} must be namespaced, e.g. "acme.tier"`
|
|
357
|
+
});
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (isReservedExtensionNamespace(key)) {
|
|
361
|
+
ctx.issues.push({
|
|
362
|
+
code: "custom",
|
|
363
|
+
input: ctx.value,
|
|
364
|
+
path: [key],
|
|
365
|
+
message: `extension namespace ${JSON.stringify(extensionKeyNamespace(key))} is reserved`
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
var EMPTY_EXTENSIONS = Object.freeze({});
|
|
371
|
+
var emptyExtensions = () => ({});
|
|
372
|
+
|
|
373
|
+
// src/model/identity.ts
|
|
374
|
+
import { z as z5 } from "zod";
|
|
375
|
+
var workspaceKeySourceSchema = z5.enum([
|
|
376
|
+
"git-remote",
|
|
377
|
+
"git-root",
|
|
378
|
+
"working-directory",
|
|
379
|
+
"explicit",
|
|
380
|
+
"unknown"
|
|
381
|
+
]);
|
|
382
|
+
var workspaceIdentitySchema = z5.strictObject({
|
|
383
|
+
workspaceId: workspaceIdSchema,
|
|
384
|
+
keySource: workspaceKeySourceSchema,
|
|
385
|
+
/** Repository name only; never an owner path or URL with credentials. */
|
|
386
|
+
repositoryName: nonEmptyStringSchema.optional(),
|
|
387
|
+
vcsBranchName: nonEmptyStringSchema.optional(),
|
|
388
|
+
/** Opaque handle for the checked-out revision. */
|
|
389
|
+
vcsRevisionId: nonEmptyStringSchema.optional()
|
|
390
|
+
}).readonly();
|
|
391
|
+
var sourceProvenanceSchema = z5.strictObject({
|
|
392
|
+
providerId: resolvedProviderIdSchema,
|
|
393
|
+
providerVersion: nonEmptyStringSchema.optional(),
|
|
394
|
+
adapterId: nonEmptyStringSchema,
|
|
395
|
+
adapterVersion: nonEmptyStringSchema,
|
|
396
|
+
detectionConfidence: detectionConfidenceSchema,
|
|
397
|
+
/** The provider's own name for the source event, e.g. a hook event name. */
|
|
398
|
+
sourceEventName: nonEmptyStringSchema.optional(),
|
|
399
|
+
transport: sourceTransportSchema
|
|
400
|
+
}).readonly();
|
|
401
|
+
var consumerAttributesSchema = attributesSchema.readonly();
|
|
402
|
+
var invocationIdentitySchema = z5.strictObject({
|
|
403
|
+
invocationId: invocationIdSchema,
|
|
404
|
+
sessionId: sessionIdSchema,
|
|
405
|
+
/** Set when this invocation runs beneath another agent invocation. */
|
|
406
|
+
parentInvocationId: invocationIdSchema.optional(),
|
|
407
|
+
/** Root of the session tree when the provider exposes one. */
|
|
408
|
+
rootSessionId: sessionIdSchema.optional(),
|
|
409
|
+
/** Stable handle for the agent process/instance, when available. */
|
|
410
|
+
agentInstanceId: nonEmptyStringSchema.optional(),
|
|
411
|
+
provenance: sourceProvenanceSchema,
|
|
412
|
+
workspace: workspaceIdentitySchema,
|
|
413
|
+
startedAt: epochMillisSchema,
|
|
414
|
+
consumerAttributes: consumerAttributesSchema
|
|
415
|
+
}).readonly();
|
|
416
|
+
var identityClaimFieldsSchema = z5.strictObject({
|
|
417
|
+
invocationId: invocationIdSchema.optional(),
|
|
418
|
+
sessionId: sessionIdSchema.optional(),
|
|
419
|
+
parentInvocationId: invocationIdSchema.optional(),
|
|
420
|
+
rootSessionId: sessionIdSchema.optional(),
|
|
421
|
+
agentInstanceId: nonEmptyStringSchema.optional(),
|
|
422
|
+
workspace: workspaceIdentitySchema.optional(),
|
|
423
|
+
startedAt: epochMillisSchema.optional()
|
|
424
|
+
});
|
|
425
|
+
var identityClaimSchema = z5.strictObject({
|
|
426
|
+
/** Non-sensitive label, e.g. `adapter:acme-cli` or `env:OTEL_HOOK_SESSION_ID`. */
|
|
427
|
+
source: nonEmptyStringSchema,
|
|
428
|
+
confidence: detectionConfidenceSchema,
|
|
429
|
+
fields: identityClaimFieldsSchema
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// src/model/target.ts
|
|
433
|
+
import { z as z6 } from "zod";
|
|
434
|
+
var targetSourceSchema = z6.enum(["tool-path", "shell-cwd", "session-cwd"]);
|
|
435
|
+
var MAX_TARGET_HINT_PATHS = 8;
|
|
436
|
+
var MAX_TARGET_PATH_LENGTH = 4096;
|
|
437
|
+
var localPathSchema = z6.string().min(1).max(MAX_TARGET_PATH_LENGTH).refine((value) => !value.includes("\0"), "path must not contain NUL");
|
|
438
|
+
var targetHintSchema = z6.strictObject({
|
|
439
|
+
source: targetSourceSchema,
|
|
440
|
+
paths: z6.array(localPathSchema).min(1).max(MAX_TARGET_HINT_PATHS).readonly(),
|
|
441
|
+
/** Absolute directory that relative `paths` resolve against. */
|
|
442
|
+
baseDirectory: localPathSchema.optional()
|
|
443
|
+
}).readonly();
|
|
444
|
+
var worktreeKindSchema = z6.enum(["main", "linked"]);
|
|
445
|
+
var workspaceTargetSchema = z6.strictObject({
|
|
446
|
+
workspaceId: workspaceIdSchema,
|
|
447
|
+
/** Branch checked out in that worktree; absent on a detached HEAD. */
|
|
448
|
+
vcsBranchName: nonEmptyStringSchema.optional(),
|
|
449
|
+
source: targetSourceSchema,
|
|
450
|
+
/** `git-root` handle of the repository's main worktree; absent when there is none to name. */
|
|
451
|
+
repositoryId: workspaceIdSchema.optional(),
|
|
452
|
+
worktreeKind: worktreeKindSchema.optional()
|
|
453
|
+
}).readonly();
|
|
454
|
+
var SUBAGENT_ID_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
455
|
+
var subagentIdSchema = z6.string().regex(SUBAGENT_ID_PATTERN);
|
|
456
|
+
|
|
457
|
+
// src/model/usage.ts
|
|
458
|
+
import { z as z7 } from "zod";
|
|
459
|
+
var usageTemporalitySchema = z7.enum(["delta", "cumulative"]);
|
|
460
|
+
var cacheCreationAccountingSchema = z7.enum([
|
|
461
|
+
"included-in-input",
|
|
462
|
+
"disjoint-from-input",
|
|
463
|
+
"not-reported"
|
|
464
|
+
]);
|
|
465
|
+
var providerTotalAgreementSchema = z7.enum(["unreported", "agrees", "disagrees"]);
|
|
466
|
+
var usageReportSchema = z7.strictObject({
|
|
467
|
+
temporality: usageTemporalitySchema,
|
|
468
|
+
/** Inclusive input tokens. */
|
|
469
|
+
inputTokens: tokenCountSchema.optional(),
|
|
470
|
+
/** Subset of `inputTokens` served from a prompt cache. */
|
|
471
|
+
cachedInputTokens: tokenCountSchema.optional(),
|
|
472
|
+
/** Tokens written to a prompt cache. */
|
|
473
|
+
cacheCreationInputTokens: tokenCountSchema.optional(),
|
|
474
|
+
/** Required when `cacheCreationInputTokens` is present and non-zero. */
|
|
475
|
+
cacheCreationAccounting: cacheCreationAccountingSchema.optional(),
|
|
476
|
+
/** Inclusive output tokens. */
|
|
477
|
+
outputTokens: tokenCountSchema.optional(),
|
|
478
|
+
/** Subset of `outputTokens` spent on reasoning. */
|
|
479
|
+
reasoningOutputTokens: tokenCountSchema.optional(),
|
|
480
|
+
/** Total exactly as the provider reported it, if it reported one. */
|
|
481
|
+
providerTotalTokens: tokenCountSchema.optional()
|
|
482
|
+
});
|
|
483
|
+
var canonicalUsageSchema = z7.strictObject({
|
|
484
|
+
temporality: usageTemporalitySchema,
|
|
485
|
+
inputTokens: tokenCountSchema,
|
|
486
|
+
cachedInputTokens: tokenCountSchema,
|
|
487
|
+
cacheCreationInputTokens: tokenCountSchema,
|
|
488
|
+
cacheCreationAccounting: cacheCreationAccountingSchema,
|
|
489
|
+
outputTokens: tokenCountSchema,
|
|
490
|
+
reasoningOutputTokens: tokenCountSchema,
|
|
491
|
+
/** Derived: input tokens that were neither cache reads nor cache writes. */
|
|
492
|
+
uncachedInputTokens: tokenCountSchema,
|
|
493
|
+
/** Derived: canonical billable total. */
|
|
494
|
+
totalTokens: tokenCountSchema,
|
|
495
|
+
providerTotalTokens: tokenCountSchema.optional(),
|
|
496
|
+
providerTotalAgreement: providerTotalAgreementSchema
|
|
497
|
+
}).check((ctx) => {
|
|
498
|
+
const usage = ctx.value;
|
|
499
|
+
const push = (message) => {
|
|
500
|
+
ctx.issues.push({ code: "custom", input: usage, message });
|
|
501
|
+
};
|
|
502
|
+
if (usage.cachedInputTokens > usage.inputTokens) {
|
|
503
|
+
push("cachedInputTokens must not exceed inputTokens (it is a subset)");
|
|
504
|
+
}
|
|
505
|
+
if (usage.reasoningOutputTokens > usage.outputTokens) {
|
|
506
|
+
push("reasoningOutputTokens must not exceed outputTokens (it is a subset)");
|
|
507
|
+
}
|
|
508
|
+
if (usage.cacheCreationAccounting === "not-reported" && usage.cacheCreationInputTokens !== 0) {
|
|
509
|
+
push("cacheCreationInputTokens must be 0 when cacheCreationAccounting is not-reported");
|
|
510
|
+
}
|
|
511
|
+
const creationInsideInput = usage.cacheCreationAccounting === "included-in-input" ? usage.cacheCreationInputTokens : 0;
|
|
512
|
+
if (usage.cachedInputTokens + creationInsideInput > usage.inputTokens) {
|
|
513
|
+
push(
|
|
514
|
+
"cachedInputTokens + cacheCreationInputTokens must not exceed inputTokens when cache creation is included in input"
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
const expectedUncached = usage.inputTokens - usage.cachedInputTokens - creationInsideInput;
|
|
518
|
+
if (expectedUncached >= 0 && usage.uncachedInputTokens !== expectedUncached) {
|
|
519
|
+
push(`uncachedInputTokens must equal ${expectedUncached}`);
|
|
520
|
+
}
|
|
521
|
+
const creationOutsideInput = usage.cacheCreationAccounting === "disjoint-from-input" ? usage.cacheCreationInputTokens : 0;
|
|
522
|
+
const expectedTotal = usage.inputTokens + creationOutsideInput + usage.outputTokens;
|
|
523
|
+
if (usage.totalTokens !== expectedTotal) {
|
|
524
|
+
push(`totalTokens must equal ${expectedTotal}`);
|
|
525
|
+
}
|
|
526
|
+
const expectedAgreement = usage.providerTotalTokens === void 0 ? "unreported" : usage.providerTotalTokens === expectedTotal ? "agrees" : "disagrees";
|
|
527
|
+
if (usage.providerTotalAgreement !== expectedAgreement) {
|
|
528
|
+
push(`providerTotalAgreement must be ${expectedAgreement}`);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
var normalizeUsage = (report) => {
|
|
532
|
+
const parsed = usageReportSchema.safeParse(report);
|
|
533
|
+
if (!parsed.success) {
|
|
534
|
+
return {
|
|
535
|
+
status: "invalid",
|
|
536
|
+
issues: parsed.error.issues.map((issue) => ({
|
|
537
|
+
code: "invalid-report",
|
|
538
|
+
message: `${issue.path.join(".") || "<root>"}: ${issue.message}`
|
|
539
|
+
}))
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const input = parsed.data;
|
|
543
|
+
const issues = [];
|
|
544
|
+
const notes = [];
|
|
545
|
+
const inputTokens = input.inputTokens ?? 0;
|
|
546
|
+
const cachedInputTokens = input.cachedInputTokens ?? 0;
|
|
547
|
+
const cacheCreationInputTokens = input.cacheCreationInputTokens ?? 0;
|
|
548
|
+
const outputTokens = input.outputTokens ?? 0;
|
|
549
|
+
const reasoningOutputTokens = input.reasoningOutputTokens ?? 0;
|
|
550
|
+
let accounting;
|
|
551
|
+
if (cacheCreationInputTokens === 0) {
|
|
552
|
+
accounting = input.cacheCreationAccounting ?? "not-reported";
|
|
553
|
+
if (accounting !== "not-reported") {
|
|
554
|
+
notes.push(
|
|
555
|
+
`cacheCreationAccounting=${accounting} retained with zero cache-creation tokens`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
} else if (input.cacheCreationAccounting === void 0) {
|
|
559
|
+
issues.push({
|
|
560
|
+
code: "cache-creation-accounting-missing",
|
|
561
|
+
message: "cacheCreationAccounting is required when cacheCreationInputTokens is non-zero; it cannot be inferred"
|
|
562
|
+
});
|
|
563
|
+
accounting = "not-reported";
|
|
564
|
+
} else if (input.cacheCreationAccounting === "not-reported") {
|
|
565
|
+
issues.push({
|
|
566
|
+
code: "cache-creation-accounting-missing",
|
|
567
|
+
message: "cacheCreationAccounting=not-reported conflicts with non-zero cacheCreationInputTokens"
|
|
568
|
+
});
|
|
569
|
+
accounting = "not-reported";
|
|
570
|
+
} else {
|
|
571
|
+
accounting = input.cacheCreationAccounting;
|
|
572
|
+
}
|
|
573
|
+
if (cachedInputTokens > inputTokens) {
|
|
574
|
+
issues.push({
|
|
575
|
+
code: "cached-exceeds-input",
|
|
576
|
+
message: `cachedInputTokens (${cachedInputTokens}) exceeds inclusive inputTokens (${inputTokens})`
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
if (reasoningOutputTokens > outputTokens) {
|
|
580
|
+
issues.push({
|
|
581
|
+
code: "reasoning-exceeds-output",
|
|
582
|
+
message: `reasoningOutputTokens (${reasoningOutputTokens}) exceeds inclusive outputTokens (${outputTokens})`
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
const creationInsideInput = accounting === "included-in-input" ? cacheCreationInputTokens : 0;
|
|
586
|
+
if (cachedInputTokens + creationInsideInput > inputTokens) {
|
|
587
|
+
issues.push({
|
|
588
|
+
code: "cache-creation-exceeds-input",
|
|
589
|
+
message: `cachedInputTokens + cacheCreationInputTokens (${cachedInputTokens + creationInsideInput}) exceeds inclusive inputTokens (${inputTokens})`
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
if (issues.length > 0) {
|
|
593
|
+
return { status: "invalid", issues };
|
|
594
|
+
}
|
|
595
|
+
const creationOutsideInput = accounting === "disjoint-from-input" ? cacheCreationInputTokens : 0;
|
|
596
|
+
const totalTokens = inputTokens + creationOutsideInput + outputTokens;
|
|
597
|
+
const providerTotalAgreement = input.providerTotalTokens === void 0 ? "unreported" : input.providerTotalTokens === totalTokens ? "agrees" : "disagrees";
|
|
598
|
+
if (providerTotalAgreement === "disagrees") {
|
|
599
|
+
notes.push(
|
|
600
|
+
`providerTotalTokens (${input.providerTotalTokens ?? 0}) disagrees with canonical total (${totalTokens}); both retained`
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
const usage = {
|
|
604
|
+
temporality: input.temporality,
|
|
605
|
+
inputTokens,
|
|
606
|
+
cachedInputTokens,
|
|
607
|
+
cacheCreationInputTokens,
|
|
608
|
+
cacheCreationAccounting: accounting,
|
|
609
|
+
outputTokens,
|
|
610
|
+
reasoningOutputTokens,
|
|
611
|
+
uncachedInputTokens: inputTokens - cachedInputTokens - creationInsideInput,
|
|
612
|
+
totalTokens,
|
|
613
|
+
...input.providerTotalTokens === void 0 ? {} : { providerTotalTokens: input.providerTotalTokens },
|
|
614
|
+
providerTotalAgreement
|
|
615
|
+
};
|
|
616
|
+
return { status: "ok", usage, notes };
|
|
617
|
+
};
|
|
618
|
+
var UsageNormalizationError = class extends Error {
|
|
619
|
+
issues;
|
|
620
|
+
constructor(issues) {
|
|
621
|
+
super(`invalid usage report: ${issues.map((issue) => issue.message).join("; ")}`);
|
|
622
|
+
this.name = "UsageNormalizationError";
|
|
623
|
+
this.issues = issues;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
var normalizeUsageOrThrow = (report) => {
|
|
627
|
+
const result = normalizeUsage(report);
|
|
628
|
+
if (result.status === "invalid") {
|
|
629
|
+
throw new UsageNormalizationError(result.issues);
|
|
630
|
+
}
|
|
631
|
+
return result.usage;
|
|
632
|
+
};
|
|
633
|
+
var EMPTY_DELTA_USAGE = Object.freeze(
|
|
634
|
+
normalizeUsageOrThrow({ temporality: "delta" })
|
|
635
|
+
);
|
|
636
|
+
|
|
637
|
+
// src/model/version.ts
|
|
638
|
+
import { z as z8 } from "zod";
|
|
639
|
+
var CANONICAL_SCHEMA_VERSION = 1;
|
|
640
|
+
var canonicalSchemaVersionSchema = z8.literal(CANONICAL_SCHEMA_VERSION);
|
|
641
|
+
|
|
642
|
+
// src/model/events.ts
|
|
643
|
+
var modelDescriptorSchema = z9.strictObject({
|
|
644
|
+
modelId: nonEmptyStringSchema,
|
|
645
|
+
/** Vendor of the model, e.g. `anthropic`. Distinct from the agent provider. */
|
|
646
|
+
vendor: nonEmptyStringSchema.optional(),
|
|
647
|
+
family: nonEmptyStringSchema.optional()
|
|
648
|
+
});
|
|
649
|
+
var costFactsSchema = z9.strictObject({
|
|
650
|
+
/** ISO 4217 code. */
|
|
651
|
+
currency: z9.string().length(3),
|
|
652
|
+
amount: z9.number().min(0).finite(),
|
|
653
|
+
source: z9.enum(["provider-reported", "computed"])
|
|
654
|
+
});
|
|
655
|
+
var canonicalEventTypeSchema = z9.enum([
|
|
656
|
+
"session.start",
|
|
657
|
+
"session.end",
|
|
658
|
+
"prompt.submitted",
|
|
659
|
+
"generation.start",
|
|
660
|
+
"generation.end",
|
|
661
|
+
"tool.start",
|
|
662
|
+
"tool.end",
|
|
663
|
+
"subagent.start",
|
|
664
|
+
"subagent.end",
|
|
665
|
+
"compaction.performed",
|
|
666
|
+
"error.raised"
|
|
667
|
+
]);
|
|
668
|
+
var CANONICAL_EVENT_TYPES = canonicalEventTypeSchema.options;
|
|
669
|
+
var outcomeSchema = z9.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
|
|
670
|
+
var baseEventFields = {
|
|
671
|
+
schemaVersion: canonicalSchemaVersionSchema,
|
|
672
|
+
eventId: eventIdSchema,
|
|
673
|
+
invocationId: invocationIdSchema,
|
|
674
|
+
sessionId: sessionIdSchema,
|
|
675
|
+
/** Per-invocation ordering key. Stable across replays of the same input. */
|
|
676
|
+
sequence: sequenceNumberSchema,
|
|
677
|
+
occurredAt: epochMillisSchema,
|
|
678
|
+
provenance: sourceProvenanceSchema,
|
|
679
|
+
workspace: workspaceIdentitySchema,
|
|
680
|
+
/**
|
|
681
|
+
* The provider's own id for the subagent this event was emitted inside (e.g.
|
|
682
|
+
* Claude Code's `agent_id`). Absent for the top-level agent. Set by the event
|
|
683
|
+
* factory, never by hand.
|
|
684
|
+
*/
|
|
685
|
+
subagentId: subagentIdSchema.optional(),
|
|
686
|
+
extensions: extensionsSchema.default(emptyExtensions)
|
|
687
|
+
};
|
|
688
|
+
var event = (shape) => z9.strictObject({ ...baseEventFields, ...shape });
|
|
689
|
+
var sessionStartEventSchema = event({
|
|
690
|
+
type: z9.literal("session.start"),
|
|
691
|
+
sessionKind: z9.enum(["interactive", "non-interactive", "unknown"]),
|
|
692
|
+
agentName: nonEmptyStringSchema.optional(),
|
|
693
|
+
agentVersion: nonEmptyStringSchema.optional(),
|
|
694
|
+
model: modelDescriptorSchema.optional(),
|
|
695
|
+
/** The git worktree the session runs in, resolved by the core (ADR 0008). */
|
|
696
|
+
target: workspaceTargetSchema.optional()
|
|
697
|
+
});
|
|
698
|
+
var sessionEndEventSchema = event({
|
|
699
|
+
type: z9.literal("session.end"),
|
|
700
|
+
reason: z9.enum(["completed", "aborted", "error", "timeout", "unknown"]),
|
|
701
|
+
durationMillis: durationMillisSchema.optional(),
|
|
702
|
+
/** Session totals, typically cumulative. */
|
|
703
|
+
usage: canonicalUsageSchema.optional(),
|
|
704
|
+
cost: costFactsSchema.optional()
|
|
705
|
+
});
|
|
706
|
+
var promptSubmittedEventSchema = event({
|
|
707
|
+
type: z9.literal("prompt.submitted"),
|
|
708
|
+
promptSource: z9.enum(["user", "automation", "resumed", "unknown"]),
|
|
709
|
+
content: contentFactSchema.optional(),
|
|
710
|
+
turnIndex: z9.number().int().min(0).optional(),
|
|
711
|
+
/** The git worktree the session runs in, resolved by the core (ADR 0008). */
|
|
712
|
+
target: workspaceTargetSchema.optional()
|
|
713
|
+
});
|
|
714
|
+
var generationStartEventSchema = event({
|
|
715
|
+
type: z9.literal("generation.start"),
|
|
716
|
+
generationId: nonEmptyStringSchema,
|
|
717
|
+
model: modelDescriptorSchema,
|
|
718
|
+
requestedMaxOutputTokens: tokenCountSchema.optional(),
|
|
719
|
+
inputContent: contentFactsSchema.optional()
|
|
720
|
+
});
|
|
721
|
+
var generationEndEventSchema = event({
|
|
722
|
+
type: z9.literal("generation.end"),
|
|
723
|
+
generationId: nonEmptyStringSchema,
|
|
724
|
+
model: modelDescriptorSchema,
|
|
725
|
+
outcome: outcomeSchema,
|
|
726
|
+
stopReason: nonEmptyStringSchema.optional(),
|
|
727
|
+
durationMillis: durationMillisSchema.optional(),
|
|
728
|
+
usage: canonicalUsageSchema.optional(),
|
|
729
|
+
cost: costFactsSchema.optional(),
|
|
730
|
+
outputContent: contentFactsSchema.optional()
|
|
731
|
+
});
|
|
732
|
+
var toolKindSchema = z9.enum([
|
|
733
|
+
"read",
|
|
734
|
+
"write",
|
|
735
|
+
"execute",
|
|
736
|
+
"search",
|
|
737
|
+
"network",
|
|
738
|
+
"delegate",
|
|
739
|
+
"other",
|
|
740
|
+
"unknown"
|
|
741
|
+
]);
|
|
742
|
+
var toolStartEventSchema = event({
|
|
743
|
+
type: z9.literal("tool.start"),
|
|
744
|
+
toolCallId: nonEmptyStringSchema,
|
|
745
|
+
toolName: nonEmptyStringSchema,
|
|
746
|
+
toolKind: toolKindSchema,
|
|
747
|
+
generationId: nonEmptyStringSchema.optional(),
|
|
748
|
+
input: contentFactSchema.optional(),
|
|
749
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
750
|
+
target: workspaceTargetSchema.optional()
|
|
751
|
+
});
|
|
752
|
+
var toolEndEventSchema = event({
|
|
753
|
+
type: z9.literal("tool.end"),
|
|
754
|
+
toolCallId: nonEmptyStringSchema,
|
|
755
|
+
toolName: nonEmptyStringSchema,
|
|
756
|
+
outcome: outcomeSchema,
|
|
757
|
+
durationMillis: durationMillisSchema.optional(),
|
|
758
|
+
/** Present when the host asked for or recorded a permission decision. */
|
|
759
|
+
permissionDecision: z9.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
|
|
760
|
+
output: contentFactSchema.optional(),
|
|
761
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
762
|
+
target: workspaceTargetSchema.optional()
|
|
763
|
+
});
|
|
764
|
+
var subagentStartEventSchema = event({
|
|
765
|
+
type: z9.literal("subagent.start"),
|
|
766
|
+
subagentInvocationId: invocationIdSchema,
|
|
767
|
+
subagentType: nonEmptyStringSchema.optional(),
|
|
768
|
+
/** 0 for the top-level agent; 1 for its direct children. */
|
|
769
|
+
delegationDepth: z9.number().int().min(0).max(64),
|
|
770
|
+
model: modelDescriptorSchema.optional()
|
|
771
|
+
});
|
|
772
|
+
var subagentEndEventSchema = event({
|
|
773
|
+
type: z9.literal("subagent.end"),
|
|
774
|
+
subagentInvocationId: invocationIdSchema,
|
|
775
|
+
outcome: outcomeSchema,
|
|
776
|
+
durationMillis: durationMillisSchema.optional(),
|
|
777
|
+
usage: canonicalUsageSchema.optional()
|
|
778
|
+
});
|
|
779
|
+
var compactionPerformedEventSchema = event({
|
|
780
|
+
type: z9.literal("compaction.performed"),
|
|
781
|
+
trigger: z9.enum(["automatic", "manual", "unknown"]),
|
|
782
|
+
/** Provider-reported context size before and after compaction, if known. */
|
|
783
|
+
contextTokensBefore: tokenCountSchema.optional(),
|
|
784
|
+
contextTokensAfter: tokenCountSchema.optional(),
|
|
785
|
+
droppedMessageCount: z9.number().int().min(0).optional(),
|
|
786
|
+
usage: canonicalUsageSchema.optional()
|
|
787
|
+
});
|
|
788
|
+
var errorRaisedEventSchema = event({
|
|
789
|
+
type: z9.literal("error.raised"),
|
|
790
|
+
errorCode: otelHookErrorCodeSchema,
|
|
791
|
+
severity: errorSeveritySchema,
|
|
792
|
+
phase: errorPhaseSchema,
|
|
793
|
+
retryable: z9.boolean(),
|
|
794
|
+
/** Error text is content: it is described, never embedded verbatim by default. */
|
|
795
|
+
message: contentFactSchema.optional(),
|
|
796
|
+
/** Non-sensitive, provider-agnostic short label. */
|
|
797
|
+
detail: nonEmptyStringSchema.optional()
|
|
798
|
+
});
|
|
799
|
+
var canonicalEventSchema = z9.discriminatedUnion("type", [
|
|
800
|
+
sessionStartEventSchema,
|
|
801
|
+
sessionEndEventSchema,
|
|
802
|
+
promptSubmittedEventSchema,
|
|
803
|
+
generationStartEventSchema,
|
|
804
|
+
generationEndEventSchema,
|
|
805
|
+
toolStartEventSchema,
|
|
806
|
+
toolEndEventSchema,
|
|
807
|
+
subagentStartEventSchema,
|
|
808
|
+
subagentEndEventSchema,
|
|
809
|
+
compactionPerformedEventSchema,
|
|
810
|
+
errorRaisedEventSchema
|
|
811
|
+
]);
|
|
812
|
+
var TARGETED_EVENT_TYPES = ["session.start", "prompt.submitted", "tool.start", "tool.end"];
|
|
813
|
+
var TARGETED = new Set(TARGETED_EVENT_TYPES);
|
|
814
|
+
var isTargetedEvent = (event2) => TARGETED.has(event2.type);
|
|
815
|
+
|
|
816
|
+
// src/telemetry/export-identity.ts
|
|
45
817
|
var ATTR_TRACE_ID = "trace_id";
|
|
46
818
|
var ATTR_SPAN_ID = "span_id";
|
|
47
819
|
var ATTR_PARENT_SPAN_ID = "parent_span_id";
|
|
@@ -61,11 +833,11 @@ var ATTR_OTELHOOK_TARGET_SOURCE = "otelhook.target.source";
|
|
|
61
833
|
var ATTR_OTELHOOK_TARGET_REPOSITORY_ID = "otelhook.target.repository.id";
|
|
62
834
|
var ATTR_OTELHOOK_TARGET_WORKTREE_KIND = "otelhook.target.worktree.kind";
|
|
63
835
|
var ATTR_OTELHOOK_USAGE_TEMPORALITY = "otelhook.usage.temporality";
|
|
64
|
-
var targetAttributes = (
|
|
65
|
-
if (
|
|
836
|
+
var targetAttributes = (event2) => {
|
|
837
|
+
if (!isTargetedEvent(event2) || event2.target === void 0) {
|
|
66
838
|
return {};
|
|
67
839
|
}
|
|
68
|
-
const { target } =
|
|
840
|
+
const { target } = event2;
|
|
69
841
|
return {
|
|
70
842
|
[ATTR_OTELHOOK_TARGET_WORKSPACE_ID]: target.workspaceId,
|
|
71
843
|
[ATTR_OTELHOOK_TARGET_SOURCE]: target.source,
|
|
@@ -100,17 +872,17 @@ var hexTraceAttributes = (ids) => ({
|
|
|
100
872
|
...SPAN_ID_HEX_PATTERN.test(ids.spanId) ? { [ATTR_SPAN_ID]: ids.spanId } : {},
|
|
101
873
|
...ids.parentSpanId !== void 0 && SPAN_ID_HEX_PATTERN.test(ids.parentSpanId) ? { [ATTR_PARENT_SPAN_ID]: ids.parentSpanId } : {}
|
|
102
874
|
});
|
|
103
|
-
var exportIdentityAttributes = (
|
|
104
|
-
const { sessionId, providerSessionId } = resolveExportedSessionId(
|
|
875
|
+
var exportIdentityAttributes = (event2, resource, ids) => {
|
|
876
|
+
const { sessionId, providerSessionId } = resolveExportedSessionId(event2.sessionId, resource);
|
|
105
877
|
return {
|
|
106
878
|
[ATTR_SESSION_ID]: sessionId,
|
|
107
879
|
[ATTR_OTELHOOK_SESSION_ID]: providerSessionId,
|
|
108
880
|
[ATTR_GEN_AI_CONVERSATION_ID]: providerSessionId,
|
|
109
|
-
[ATTR_OTELHOOK_INVOCATION_ID]:
|
|
110
|
-
[ATTR_OTELHOOK_PROVIDER_ID]:
|
|
111
|
-
...
|
|
112
|
-
[ATTR_OTELHOOK_WORKSPACE_ID]:
|
|
113
|
-
...
|
|
881
|
+
[ATTR_OTELHOOK_INVOCATION_ID]: event2.invocationId,
|
|
882
|
+
[ATTR_OTELHOOK_PROVIDER_ID]: event2.provenance.providerId,
|
|
883
|
+
...event2.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event2.provenance.providerVersion },
|
|
884
|
+
[ATTR_OTELHOOK_WORKSPACE_ID]: event2.workspace.workspaceId,
|
|
885
|
+
...event2.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event2.subagentId },
|
|
114
886
|
...passthroughHarAttributes(resource),
|
|
115
887
|
...hexTraceAttributes(ids)
|
|
116
888
|
};
|
|
@@ -154,57 +926,60 @@ var familyOf = (type) => {
|
|
|
154
926
|
return void 0;
|
|
155
927
|
}
|
|
156
928
|
};
|
|
157
|
-
var spanScopeRefOf = (
|
|
158
|
-
const family = familyOf(
|
|
929
|
+
var spanScopeRefOf = (event2) => {
|
|
930
|
+
const family = familyOf(event2.type);
|
|
159
931
|
if (family === void 0) {
|
|
160
932
|
return void 0;
|
|
161
933
|
}
|
|
162
|
-
switch (
|
|
934
|
+
switch (event2.type) {
|
|
163
935
|
case "session.start":
|
|
164
936
|
case "session.end":
|
|
165
|
-
return { family, scopeKey:
|
|
937
|
+
return { family, scopeKey: event2.sessionId };
|
|
166
938
|
case "generation.start":
|
|
167
939
|
case "generation.end":
|
|
168
|
-
return { family, scopeKey:
|
|
940
|
+
return { family, scopeKey: event2.generationId };
|
|
169
941
|
case "tool.start":
|
|
170
942
|
case "tool.end":
|
|
171
|
-
return { family, scopeKey:
|
|
943
|
+
return { family, scopeKey: event2.toolCallId };
|
|
172
944
|
case "subagent.start":
|
|
173
945
|
case "subagent.end":
|
|
174
|
-
return { family, scopeKey:
|
|
946
|
+
return { family, scopeKey: event2.subagentInvocationId };
|
|
175
947
|
default:
|
|
176
948
|
return void 0;
|
|
177
949
|
}
|
|
178
950
|
};
|
|
179
|
-
var parentScopeRefOf = (
|
|
180
|
-
if (
|
|
951
|
+
var parentScopeRefOf = (event2) => {
|
|
952
|
+
if (event2.type === "session.start" || event2.type === "session.end") {
|
|
181
953
|
return void 0;
|
|
182
954
|
}
|
|
183
|
-
if (
|
|
184
|
-
return { family: "generation", scopeKey:
|
|
955
|
+
if (event2.type === "tool.start" && event2.generationId !== void 0) {
|
|
956
|
+
return { family: "generation", scopeKey: event2.generationId };
|
|
185
957
|
}
|
|
186
|
-
return { family: "session", scopeKey:
|
|
958
|
+
return { family: "session", scopeKey: event2.sessionId };
|
|
187
959
|
};
|
|
188
|
-
var startOnlySpanAttributes = (
|
|
189
|
-
switch (
|
|
960
|
+
var startOnlySpanAttributes = (event2) => {
|
|
961
|
+
switch (event2.type) {
|
|
962
|
+
// The session's own worktree is carried forward like a tool's target, so
|
|
963
|
+
// the session span a later `session.end` process exports still names it.
|
|
190
964
|
case "session.start":
|
|
191
965
|
return {
|
|
192
|
-
...
|
|
193
|
-
...
|
|
966
|
+
...event2.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: event2.agentName },
|
|
967
|
+
...event2.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: event2.agentVersion },
|
|
968
|
+
...targetAttributes(event2)
|
|
194
969
|
};
|
|
195
970
|
case "generation.start":
|
|
196
971
|
return {
|
|
197
|
-
[ATTR_GEN_AI_REQUEST_MODEL]:
|
|
198
|
-
...
|
|
972
|
+
[ATTR_GEN_AI_REQUEST_MODEL]: event2.model.modelId,
|
|
973
|
+
...event2.model.vendor === void 0 ? {} : { [ATTR_GEN_AI_SYSTEM]: event2.model.vendor }
|
|
199
974
|
};
|
|
200
975
|
// `toolName` and `toolCallId` are on both tool edges, so they are not
|
|
201
976
|
// start-only and persisting them would just pad every record.
|
|
202
977
|
// The target is carried forward too: an end-only process may see a payload
|
|
203
978
|
// with less to go on (no tool input), and the start's evidence still holds.
|
|
204
979
|
case "tool.start":
|
|
205
|
-
return { [ATTR_OTELHOOK_TOOL_KIND]:
|
|
980
|
+
return { [ATTR_OTELHOOK_TOOL_KIND]: event2.toolKind, ...targetAttributes(event2) };
|
|
206
981
|
case "subagent.start":
|
|
207
|
-
return { [ATTR_OTELHOOK_DELEGATION_DEPTH]:
|
|
982
|
+
return { [ATTR_OTELHOOK_DELEGATION_DEPTH]: event2.delegationDepth };
|
|
208
983
|
default:
|
|
209
984
|
return {};
|
|
210
985
|
}
|
|
@@ -222,7 +997,7 @@ var outcomeStatus = (outcome) => {
|
|
|
222
997
|
}
|
|
223
998
|
return { code: SpanStatusCode.ERROR, message: outcome };
|
|
224
999
|
};
|
|
225
|
-
var identityAttributes = (
|
|
1000
|
+
var identityAttributes = (event2, resource, ids) => exportIdentityAttributes(event2, resource, ids);
|
|
226
1001
|
var usageAttributes = (usage, resetDetected) => {
|
|
227
1002
|
if (usage === void 0) {
|
|
228
1003
|
return {};
|
|
@@ -368,7 +1143,8 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
368
1143
|
name = "session";
|
|
369
1144
|
kind = SpanKind.INTERNAL;
|
|
370
1145
|
attributes = {
|
|
371
|
-
...attributes,
|
|
1146
|
+
...withoutTarget(attributes),
|
|
1147
|
+
...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
|
|
372
1148
|
...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
|
|
373
1149
|
...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
|
|
374
1150
|
...end === void 0 ? {} : { [ATTR_OTELHOOK_OUTCOME]: end.reason },
|
|
@@ -454,14 +1230,14 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
454
1230
|
instrumentationScope: scope
|
|
455
1231
|
});
|
|
456
1232
|
};
|
|
457
|
-
var buildStandaloneSpan = (
|
|
458
|
-
const providerId =
|
|
459
|
-
const traceId = deriveTraceId(providerId,
|
|
460
|
-
const spanId = deriveStandaloneSpanId(providerId,
|
|
461
|
-
const parent = parentScopeRefOf(
|
|
462
|
-
const parentSpanId = parent === void 0 ? void 0 : deriveSpanId(providerId,
|
|
1233
|
+
var buildStandaloneSpan = (event2, resource, scope) => {
|
|
1234
|
+
const providerId = event2.provenance.providerId;
|
|
1235
|
+
const traceId = deriveTraceId(providerId, event2.sessionId);
|
|
1236
|
+
const spanId = deriveStandaloneSpanId(providerId, event2.sessionId, event2.type, event2.eventId);
|
|
1237
|
+
const parent = parentScopeRefOf(event2);
|
|
1238
|
+
const parentSpanId = parent === void 0 ? void 0 : deriveSpanId(providerId, event2.sessionId, parent);
|
|
463
1239
|
let attributes = {
|
|
464
|
-
...identityAttributes(
|
|
1240
|
+
...identityAttributes(event2, resource, {
|
|
465
1241
|
traceId,
|
|
466
1242
|
spanId,
|
|
467
1243
|
...parentSpanId === void 0 ? {} : { parentSpanId }
|
|
@@ -469,28 +1245,28 @@ var buildStandaloneSpan = (event, resource, scope) => {
|
|
|
469
1245
|
[ATTR_OTELHOOK_SPAN_PAIRED]: true
|
|
470
1246
|
};
|
|
471
1247
|
let status = { code: SpanStatusCode.UNSET };
|
|
472
|
-
let name =
|
|
473
|
-
switch (
|
|
1248
|
+
let name = event2.type;
|
|
1249
|
+
switch (event2.type) {
|
|
474
1250
|
case "prompt.submitted":
|
|
475
1251
|
name = "prompt";
|
|
476
|
-
attributes = { ...attributes, "otelhook.prompt.source":
|
|
1252
|
+
attributes = { ...attributes, "otelhook.prompt.source": event2.promptSource, ...targetAttributes(event2) };
|
|
477
1253
|
break;
|
|
478
1254
|
case "compaction.performed":
|
|
479
1255
|
name = "compaction";
|
|
480
1256
|
attributes = {
|
|
481
1257
|
...attributes,
|
|
482
|
-
[ATTR_OTELHOOK_COMPACTION_TRIGGER]:
|
|
483
|
-
...usageAttributes(
|
|
1258
|
+
[ATTR_OTELHOOK_COMPACTION_TRIGGER]: event2.trigger,
|
|
1259
|
+
...usageAttributes(event2.usage, false)
|
|
484
1260
|
};
|
|
485
1261
|
break;
|
|
486
1262
|
case "error.raised":
|
|
487
1263
|
name = "error";
|
|
488
|
-
status = { code: SpanStatusCode.ERROR, message:
|
|
1264
|
+
status = { code: SpanStatusCode.ERROR, message: event2.errorCode };
|
|
489
1265
|
attributes = {
|
|
490
1266
|
...attributes,
|
|
491
|
-
[ATTR_ERROR_TYPE]:
|
|
492
|
-
"otelhook.error.phase":
|
|
493
|
-
"otelhook.error.retryable":
|
|
1267
|
+
[ATTR_ERROR_TYPE]: event2.errorCode,
|
|
1268
|
+
"otelhook.error.phase": event2.phase,
|
|
1269
|
+
"otelhook.error.retryable": event2.retryable
|
|
494
1270
|
};
|
|
495
1271
|
break;
|
|
496
1272
|
default:
|
|
@@ -499,8 +1275,8 @@ var buildStandaloneSpan = (event, resource, scope) => {
|
|
|
499
1275
|
return toReadableSpan({
|
|
500
1276
|
name,
|
|
501
1277
|
kind: SpanKind.INTERNAL,
|
|
502
|
-
startMillis:
|
|
503
|
-
endMillis:
|
|
1278
|
+
startMillis: event2.occurredAt,
|
|
1279
|
+
endMillis: event2.occurredAt,
|
|
504
1280
|
attributes,
|
|
505
1281
|
status,
|
|
506
1282
|
traceId,
|
|
@@ -528,21 +1304,21 @@ var layoutBatch = (events) => {
|
|
|
528
1304
|
const groups = /* @__PURE__ */ new Map();
|
|
529
1305
|
const standalone = [];
|
|
530
1306
|
const groupOf = /* @__PURE__ */ new Map();
|
|
531
|
-
for (const
|
|
532
|
-
const ref = spanScopeRefOf(
|
|
1307
|
+
for (const event2 of events) {
|
|
1308
|
+
const ref = spanScopeRefOf(event2);
|
|
533
1309
|
if (ref === void 0) {
|
|
534
|
-
standalone.push(
|
|
1310
|
+
standalone.push(event2);
|
|
535
1311
|
continue;
|
|
536
1312
|
}
|
|
537
|
-
const groupKey = correlationKey(
|
|
1313
|
+
const groupKey = correlationKey(event2.provenance.providerId, event2.sessionId, ref);
|
|
538
1314
|
const group = groups.get(groupKey) ?? { ref };
|
|
539
|
-
if (
|
|
540
|
-
group.start =
|
|
1315
|
+
if (event2.type.endsWith(".start")) {
|
|
1316
|
+
group.start = event2;
|
|
541
1317
|
} else {
|
|
542
|
-
group.end =
|
|
1318
|
+
group.end = event2;
|
|
543
1319
|
}
|
|
544
1320
|
groups.set(groupKey, group);
|
|
545
|
-
groupOf.set(
|
|
1321
|
+
groupOf.set(event2.eventId, groupKey);
|
|
546
1322
|
}
|
|
547
1323
|
return { groups, standalone, groupOf };
|
|
548
1324
|
};
|
|
@@ -599,24 +1375,24 @@ var canonicalEventTraceIdentities = (events, options = {}) => {
|
|
|
599
1375
|
}
|
|
600
1376
|
}
|
|
601
1377
|
const identities = /* @__PURE__ */ new Map();
|
|
602
|
-
for (const
|
|
603
|
-
const providerId =
|
|
604
|
-
const groupKey = layout.groupOf.get(
|
|
1378
|
+
for (const event2 of events) {
|
|
1379
|
+
const providerId = event2.provenance.providerId;
|
|
1380
|
+
const groupKey = layout.groupOf.get(event2.eventId);
|
|
605
1381
|
const plan = groupKey === void 0 ? void 0 : plans.get(groupKey);
|
|
606
1382
|
if (plan === void 0) {
|
|
607
|
-
const parent2 = parentScopeRefOf(
|
|
608
|
-
identities.set(
|
|
609
|
-
traceId: deriveTraceId(providerId,
|
|
610
|
-
spanId: deriveStandaloneSpanId(providerId,
|
|
611
|
-
...parent2 === void 0 ? {} : { parentSpanId: deriveSpanId(providerId,
|
|
1383
|
+
const parent2 = parentScopeRefOf(event2);
|
|
1384
|
+
identities.set(event2.eventId, {
|
|
1385
|
+
traceId: deriveTraceId(providerId, event2.sessionId),
|
|
1386
|
+
spanId: deriveStandaloneSpanId(providerId, event2.sessionId, event2.type, event2.eventId),
|
|
1387
|
+
...parent2 === void 0 ? {} : { parentSpanId: deriveSpanId(providerId, event2.sessionId, parent2) }
|
|
612
1388
|
});
|
|
613
1389
|
continue;
|
|
614
1390
|
}
|
|
615
|
-
const parent = plan.correlation?.parent ?? parentScopeRefOf(
|
|
616
|
-
identities.set(
|
|
1391
|
+
const parent = plan.correlation?.parent ?? parentScopeRefOf(event2);
|
|
1392
|
+
identities.set(event2.eventId, {
|
|
617
1393
|
traceId: plan.traceId,
|
|
618
1394
|
spanId: plan.spanId,
|
|
619
|
-
...parent === void 0 ? {} : { parentSpanId: deriveSpanId(providerId,
|
|
1395
|
+
...parent === void 0 ? {} : { parentSpanId: deriveSpanId(providerId, event2.sessionId, parent) }
|
|
620
1396
|
});
|
|
621
1397
|
}
|
|
622
1398
|
return identities;
|
|
@@ -633,8 +1409,8 @@ var canonicalEventsToReadableSpans = (events, options) => {
|
|
|
633
1409
|
}
|
|
634
1410
|
spans.push(buildLifecycleSpan(plan, options.resource, scope));
|
|
635
1411
|
}
|
|
636
|
-
for (const
|
|
637
|
-
spans.push(buildStandaloneSpan(
|
|
1412
|
+
for (const event2 of layout.standalone) {
|
|
1413
|
+
spans.push(buildStandaloneSpan(event2, options.resource, scope));
|
|
638
1414
|
}
|
|
639
1415
|
return spans;
|
|
640
1416
|
};
|
|
@@ -882,259 +1658,14 @@ var createFileDurableSpool = (options) => createSpoolQueue({
|
|
|
882
1658
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
883
1659
|
|
|
884
1660
|
// src/errors/index.ts
|
|
885
|
-
import { z as
|
|
886
|
-
|
|
887
|
-
// src/model/primitives.ts
|
|
888
|
-
import { z } from "zod";
|
|
889
|
-
var MAX_IDENTIFIER_LENGTH = 256;
|
|
890
|
-
var MAX_ATTRIBUTE_STRING_LENGTH = 4096;
|
|
891
|
-
var MAX_ATTRIBUTE_ARRAY_LENGTH = 128;
|
|
892
|
-
var nonEmptyStringSchema = z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
893
|
-
var epochMillisSchema = z.number().int().min(0).max(864e13);
|
|
894
|
-
var durationMillisSchema = z.number().min(0).finite();
|
|
895
|
-
var tokenCountSchema = z.number().int().min(0);
|
|
896
|
-
var sequenceNumberSchema = z.number().int().min(0);
|
|
897
|
-
var brandedIdSchema = () => z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
898
|
-
var invocationIdSchema = brandedIdSchema().brand();
|
|
899
|
-
var sessionIdSchema = brandedIdSchema().brand();
|
|
900
|
-
var eventIdSchema = brandedIdSchema().brand();
|
|
901
|
-
var WORKSPACE_ID_PATTERN = /^[a-z][a-z0-9]{0,15}:[A-Za-z0-9_-]{8,128}$/;
|
|
902
|
-
var workspaceIdSchema = z.string().regex(WORKSPACE_ID_PATTERN, "workspace id must be an opaque `<scheme>:<token>` handle").brand();
|
|
903
|
-
var PROVIDER_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
904
|
-
var providerIdSchema = z.string().min(1).max(64).regex(PROVIDER_ID_PATTERN, "provider id must be lowercase and hyphenated").brand();
|
|
905
|
-
var UNKNOWN_PROVIDER_ID = "unknown";
|
|
906
|
-
var resolvedProviderIdSchema = z.union([
|
|
907
|
-
providerIdSchema,
|
|
908
|
-
z.literal(UNKNOWN_PROVIDER_ID)
|
|
909
|
-
]);
|
|
910
|
-
var attributePrimitiveSchema = z.union([
|
|
911
|
-
z.string().max(MAX_ATTRIBUTE_STRING_LENGTH),
|
|
912
|
-
z.number().finite(),
|
|
913
|
-
z.boolean()
|
|
914
|
-
]);
|
|
915
|
-
var attributeValueSchema = z.union([
|
|
916
|
-
attributePrimitiveSchema,
|
|
917
|
-
z.array(attributePrimitiveSchema).max(MAX_ATTRIBUTE_ARRAY_LENGTH)
|
|
918
|
-
]);
|
|
919
|
-
var attributesSchema = z.record(z.string().min(1).max(MAX_IDENTIFIER_LENGTH), attributeValueSchema);
|
|
920
|
-
var detectionConfidenceSchema = z.enum(["none", "weak", "strong", "exact"]);
|
|
921
|
-
var DETECTION_CONFIDENCE_RANK = Object.freeze({
|
|
922
|
-
none: 0,
|
|
923
|
-
weak: 1,
|
|
924
|
-
strong: 2,
|
|
925
|
-
exact: 3
|
|
926
|
-
});
|
|
927
|
-
var sourceTransportSchema = z.enum([
|
|
928
|
-
"hook-stdin",
|
|
929
|
-
"cli-argument",
|
|
930
|
-
"library-call",
|
|
931
|
-
"test-fixture"
|
|
932
|
-
]);
|
|
933
|
-
|
|
934
|
-
// src/errors/taxonomy.ts
|
|
935
|
-
import { z as z2 } from "zod";
|
|
936
|
-
var otelHookErrorCodeSchema = z2.enum([
|
|
937
|
-
/** Input was not usable at all (empty stdin, unparsable JSON). */
|
|
938
|
-
"invalid-input",
|
|
939
|
-
/** Input parsed but failed canonical schema validation. */
|
|
940
|
-
"schema-validation-failed",
|
|
941
|
-
/** No adapter claimed the input with sufficient confidence. */
|
|
942
|
-
"provider-unknown",
|
|
943
|
-
/** Several adapters claimed the input at the same confidence. */
|
|
944
|
-
"provider-detection-ambiguous",
|
|
945
|
-
/** An adapter threw or returned a malformed result. */
|
|
946
|
-
"provider-adapter-failure",
|
|
947
|
-
/** Two identity claims disagreed at equal confidence. */
|
|
948
|
-
"identity-conflict",
|
|
949
|
-
/** Required identity fields were absent. */
|
|
950
|
-
"identity-incomplete",
|
|
951
|
-
/** A usage report violated the canonical usage invariants. */
|
|
952
|
-
"usage-invalid",
|
|
953
|
-
/** The state store could not be read or written. */
|
|
954
|
-
"state-store-failure",
|
|
955
|
-
/** The telemetry sink rejected or could not deliver a batch. */
|
|
956
|
-
"telemetry-export-failure",
|
|
957
|
-
/** Content reached the sink boundary in a state the policy forbids. */
|
|
958
|
-
"privacy-policy-violation",
|
|
959
|
-
/** Configuration could not be resolved. */
|
|
960
|
-
"configuration-invalid",
|
|
961
|
-
/** A configured bound (events, batch size) dropped data. */
|
|
962
|
-
"limit-exceeded",
|
|
963
|
-
/**
|
|
964
|
-
* No replay-stable delivery identifier was available for a callback while
|
|
965
|
-
* deduplication was required.
|
|
966
|
-
*/
|
|
967
|
-
"delivery-identifier-unavailable",
|
|
968
|
-
"delivery-claim-superseded",
|
|
969
|
-
/** Anything unanticipated. Always reported, never fatal to the host. */
|
|
970
|
-
"internal-error"
|
|
971
|
-
]);
|
|
972
|
-
var errorSeveritySchema = z2.enum(["warning", "error"]);
|
|
973
|
-
var errorPhaseSchema = z2.enum([
|
|
974
|
-
"configuration",
|
|
975
|
-
"detection",
|
|
976
|
-
"identity",
|
|
977
|
-
"parsing",
|
|
978
|
-
"normalization",
|
|
979
|
-
"privacy",
|
|
980
|
-
"state",
|
|
981
|
-
"export",
|
|
982
|
-
"shutdown"
|
|
983
|
-
]);
|
|
984
|
-
var failurePostureSchema = z2.enum(["fail-open", "fail-closed-attribution"]);
|
|
985
|
-
var ERROR_TAXONOMY = Object.freeze({
|
|
986
|
-
"invalid-input": {
|
|
987
|
-
code: "invalid-input",
|
|
988
|
-
severity: "warning",
|
|
989
|
-
posture: "fail-open",
|
|
990
|
-
retryable: false,
|
|
991
|
-
summary: "Input could not be read or decoded."
|
|
992
|
-
},
|
|
993
|
-
"schema-validation-failed": {
|
|
994
|
-
code: "schema-validation-failed",
|
|
995
|
-
severity: "error",
|
|
996
|
-
posture: "fail-closed-attribution",
|
|
997
|
-
retryable: false,
|
|
998
|
-
summary: "A canonical event failed schema validation and was dropped."
|
|
999
|
-
},
|
|
1000
|
-
"provider-unknown": {
|
|
1001
|
-
code: "provider-unknown",
|
|
1002
|
-
severity: "warning",
|
|
1003
|
-
posture: "fail-closed-attribution",
|
|
1004
|
-
retryable: false,
|
|
1005
|
-
summary: "No adapter recognized the source provider; the input stays unattributed."
|
|
1006
|
-
},
|
|
1007
|
-
"provider-detection-ambiguous": {
|
|
1008
|
-
code: "provider-detection-ambiguous",
|
|
1009
|
-
severity: "warning",
|
|
1010
|
-
posture: "fail-closed-attribution",
|
|
1011
|
-
retryable: false,
|
|
1012
|
-
summary: "Multiple adapters claimed the input at equal confidence."
|
|
1013
|
-
},
|
|
1014
|
-
"provider-adapter-failure": {
|
|
1015
|
-
code: "provider-adapter-failure",
|
|
1016
|
-
severity: "error",
|
|
1017
|
-
posture: "fail-open",
|
|
1018
|
-
retryable: false,
|
|
1019
|
-
summary: "A provider adapter failed while parsing."
|
|
1020
|
-
},
|
|
1021
|
-
"identity-conflict": {
|
|
1022
|
-
code: "identity-conflict",
|
|
1023
|
-
severity: "error",
|
|
1024
|
-
posture: "fail-closed-attribution",
|
|
1025
|
-
retryable: false,
|
|
1026
|
-
summary: "Identity claims disagreed; attribution was declined."
|
|
1027
|
-
},
|
|
1028
|
-
"identity-incomplete": {
|
|
1029
|
-
code: "identity-incomplete",
|
|
1030
|
-
severity: "warning",
|
|
1031
|
-
posture: "fail-closed-attribution",
|
|
1032
|
-
retryable: false,
|
|
1033
|
-
summary: "Required identity fields were missing; attribution was declined."
|
|
1034
|
-
},
|
|
1035
|
-
"usage-invalid": {
|
|
1036
|
-
code: "usage-invalid",
|
|
1037
|
-
severity: "error",
|
|
1038
|
-
posture: "fail-open",
|
|
1039
|
-
retryable: false,
|
|
1040
|
-
summary: "A usage report violated the canonical usage invariants."
|
|
1041
|
-
},
|
|
1042
|
-
"state-store-failure": {
|
|
1043
|
-
code: "state-store-failure",
|
|
1044
|
-
severity: "warning",
|
|
1045
|
-
posture: "fail-open",
|
|
1046
|
-
retryable: true,
|
|
1047
|
-
summary: "State could not be read or written; derived values may be incomplete."
|
|
1048
|
-
},
|
|
1049
|
-
"telemetry-export-failure": {
|
|
1050
|
-
code: "telemetry-export-failure",
|
|
1051
|
-
severity: "warning",
|
|
1052
|
-
posture: "fail-open",
|
|
1053
|
-
retryable: true,
|
|
1054
|
-
summary: "The telemetry sink could not accept a batch."
|
|
1055
|
-
},
|
|
1056
|
-
"privacy-policy-violation": {
|
|
1057
|
-
code: "privacy-policy-violation",
|
|
1058
|
-
severity: "error",
|
|
1059
|
-
posture: "fail-closed-attribution",
|
|
1060
|
-
retryable: false,
|
|
1061
|
-
summary: "Content violated the resolved privacy policy and was dropped."
|
|
1062
|
-
},
|
|
1063
|
-
"configuration-invalid": {
|
|
1064
|
-
code: "configuration-invalid",
|
|
1065
|
-
severity: "error",
|
|
1066
|
-
posture: "fail-open",
|
|
1067
|
-
retryable: false,
|
|
1068
|
-
summary: "Configuration could not be resolved; defaults apply."
|
|
1069
|
-
},
|
|
1070
|
-
"limit-exceeded": {
|
|
1071
|
-
code: "limit-exceeded",
|
|
1072
|
-
severity: "warning",
|
|
1073
|
-
posture: "fail-open",
|
|
1074
|
-
retryable: false,
|
|
1075
|
-
summary: "A configured bound was reached and data was dropped."
|
|
1076
|
-
},
|
|
1077
|
-
"delivery-identifier-unavailable": {
|
|
1078
|
-
code: "delivery-identifier-unavailable",
|
|
1079
|
-
severity: "warning",
|
|
1080
|
-
// Fail-open: the observation is still attributed and exported. Only the
|
|
1081
|
-
// at-most-once guarantee is missing, and refusing the telemetry to protect
|
|
1082
|
-
// a duplicate count would trade a certain loss for a possible one.
|
|
1083
|
-
posture: "fail-open",
|
|
1084
|
-
retryable: false,
|
|
1085
|
-
summary: "No replay-stable delivery identifier was available; this callback was exported without deduplication."
|
|
1086
|
-
},
|
|
1087
|
-
"delivery-claim-superseded": {
|
|
1088
|
-
code: "delivery-claim-superseded",
|
|
1089
|
-
severity: "warning",
|
|
1090
|
-
// Fail-open, and specifically *not* silent. A peer reclaimed this callback's
|
|
1091
|
-
// claim while this process was still working on it, which means the
|
|
1092
|
-
// configured stale window is shorter than this installation's real worst
|
|
1093
|
-
// case. Both processes may now have exported the callback, so the
|
|
1094
|
-
// at-most-once guarantee did not hold for it — the only honest response is
|
|
1095
|
-
// to say so and let the operator raise the window.
|
|
1096
|
-
posture: "fail-open",
|
|
1097
|
-
retryable: false,
|
|
1098
|
-
summary: "A delivery claim was reclaimed by another process before this one committed; the callback may have been exported twice."
|
|
1099
|
-
},
|
|
1100
|
-
"internal-error": {
|
|
1101
|
-
code: "internal-error",
|
|
1102
|
-
severity: "error",
|
|
1103
|
-
posture: "fail-open",
|
|
1104
|
-
retryable: false,
|
|
1105
|
-
summary: "An unexpected failure was contained."
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
|
-
var describeErrorCode = (code) => ERROR_TAXONOMY[code];
|
|
1109
|
-
var attributionOutcomeSchema = z2.enum([
|
|
1110
|
-
/** Identity resolved; events carry provider and session identity. */
|
|
1111
|
-
"attributed",
|
|
1112
|
-
/** Identity could not be established safely; nothing was attributed. */
|
|
1113
|
-
"declined",
|
|
1114
|
-
/** Attribution was attempted and failed unexpectedly. */
|
|
1115
|
-
"failed",
|
|
1116
|
-
/** Input was recognized but intentionally carried no telemetry. */
|
|
1117
|
-
"not-applicable"
|
|
1118
|
-
]);
|
|
1119
|
-
var attributionReasonSchema = z2.enum([
|
|
1120
|
-
"provider-unknown",
|
|
1121
|
-
"provider-detection-ambiguous",
|
|
1122
|
-
"identity-conflict",
|
|
1123
|
-
"identity-incomplete",
|
|
1124
|
-
"adapter-ignored-input",
|
|
1125
|
-
"adapter-failure",
|
|
1126
|
-
"invalid-input",
|
|
1127
|
-
"internal-error"
|
|
1128
|
-
]);
|
|
1129
|
-
|
|
1130
|
-
// src/errors/index.ts
|
|
1131
|
-
var otelHookErrorInfoSchema = z3.strictObject({
|
|
1661
|
+
import { z as z10 } from "zod";
|
|
1662
|
+
var otelHookErrorInfoSchema = z10.strictObject({
|
|
1132
1663
|
code: otelHookErrorCodeSchema,
|
|
1133
1664
|
severity: errorSeveritySchema,
|
|
1134
1665
|
phase: errorPhaseSchema,
|
|
1135
1666
|
posture: failurePostureSchema,
|
|
1136
|
-
retryable:
|
|
1137
|
-
message:
|
|
1667
|
+
retryable: z10.boolean(),
|
|
1668
|
+
message: z10.string().min(1).max(512),
|
|
1138
1669
|
details: attributesSchema.optional(),
|
|
1139
1670
|
occurredAt: epochMillisSchema.optional()
|
|
1140
1671
|
});
|
|
@@ -1195,11 +1726,11 @@ var createHealthTracker = (subsystem, options = {}) => {
|
|
|
1195
1726
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
1196
1727
|
|
|
1197
1728
|
// src/config/resource-attributes.ts
|
|
1198
|
-
import { z as
|
|
1729
|
+
import { z as z12 } from "zod";
|
|
1199
1730
|
|
|
1200
1731
|
// src/privacy/policy.ts
|
|
1201
|
-
import { z as
|
|
1202
|
-
var contentModeSchema =
|
|
1732
|
+
import { z as z11 } from "zod";
|
|
1733
|
+
var contentModeSchema = z11.enum(["omit", "mask", "redact", "raw"]);
|
|
1203
1734
|
var CONTENT_MODE_DISCLOSURE = Object.freeze({
|
|
1204
1735
|
omit: "omitted",
|
|
1205
1736
|
mask: "masked",
|
|
@@ -1225,35 +1756,35 @@ var DEFAULT_SECRET_VALUE_PATTERNS = Object.freeze([
|
|
|
1225
1756
|
"eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}",
|
|
1226
1757
|
"(?:Bearer|Basic)\\s+[A-Za-z0-9._~+/=-]{12,}"
|
|
1227
1758
|
]);
|
|
1228
|
-
var privacyLimitsSchema =
|
|
1759
|
+
var privacyLimitsSchema = z11.strictObject({
|
|
1229
1760
|
/** Maximum characters of disclosed text per content fact or string value. */
|
|
1230
|
-
maxStringLength:
|
|
1761
|
+
maxStringLength: z11.number().int().min(0).max(65536),
|
|
1231
1762
|
/** Maximum nesting depth walked when sanitizing structured values. */
|
|
1232
|
-
maxDepth:
|
|
1763
|
+
maxDepth: z11.number().int().min(1).max(32),
|
|
1233
1764
|
/** Maximum array entries retained when sanitizing structured values. */
|
|
1234
|
-
maxArrayLength:
|
|
1765
|
+
maxArrayLength: z11.number().int().min(1).max(4096),
|
|
1235
1766
|
/** Maximum canonical events emitted per invocation. */
|
|
1236
|
-
maxEventsPerInvocation:
|
|
1767
|
+
maxEventsPerInvocation: z11.number().int().min(1).max(1e4),
|
|
1237
1768
|
/** Maximum object keys retained per level when sanitizing. */
|
|
1238
|
-
maxObjectKeys:
|
|
1769
|
+
maxObjectKeys: z11.number().int().min(1).max(1024)
|
|
1239
1770
|
});
|
|
1240
|
-
var privacyPolicySchema =
|
|
1771
|
+
var privacyPolicySchema = z11.strictObject({
|
|
1241
1772
|
contentMode: contentModeSchema,
|
|
1242
1773
|
/**
|
|
1243
1774
|
* `raw` mode is refused unless this is also true, so a single mistyped
|
|
1244
1775
|
* environment variable cannot start exporting prompts.
|
|
1245
1776
|
*/
|
|
1246
|
-
allowRawContent:
|
|
1777
|
+
allowRawContent: z11.boolean(),
|
|
1247
1778
|
/**
|
|
1248
1779
|
* Salt mixed into every hash. A per-deployment salt makes hashes
|
|
1249
1780
|
* non-correlatable across deployments; an empty salt makes them globally
|
|
1250
1781
|
* comparable. Both are legitimate; the choice is explicit.
|
|
1251
1782
|
*/
|
|
1252
|
-
hashSalt:
|
|
1253
|
-
maskCharacter:
|
|
1254
|
-
redactionPlaceholder:
|
|
1255
|
-
secretKeyPatterns:
|
|
1256
|
-
secretValuePatterns:
|
|
1783
|
+
hashSalt: z11.string().max(256),
|
|
1784
|
+
maskCharacter: z11.string().length(1),
|
|
1785
|
+
redactionPlaceholder: z11.string().min(1).max(64),
|
|
1786
|
+
secretKeyPatterns: z11.array(z11.string().min(1)).max(128).readonly(),
|
|
1787
|
+
secretValuePatterns: z11.array(z11.string().min(1)).max(128).readonly(),
|
|
1257
1788
|
limits: privacyLimitsSchema
|
|
1258
1789
|
});
|
|
1259
1790
|
var DEFAULT_PRIVACY_LIMITS = Object.freeze({
|
|
@@ -1319,12 +1850,12 @@ var checkResourceAttributeKey = (key) => {
|
|
|
1319
1850
|
}
|
|
1320
1851
|
return void 0;
|
|
1321
1852
|
};
|
|
1322
|
-
var resourceAttributeValueSchema =
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1853
|
+
var resourceAttributeValueSchema = z12.union([
|
|
1854
|
+
z12.string().max(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH),
|
|
1855
|
+
z12.number().finite(),
|
|
1856
|
+
z12.boolean()
|
|
1326
1857
|
]);
|
|
1327
|
-
var resourceAttributesSchema =
|
|
1858
|
+
var resourceAttributesSchema = z12.record(z12.string(), resourceAttributeValueSchema).superRefine((value, ctx) => {
|
|
1328
1859
|
const keys = Object.keys(value);
|
|
1329
1860
|
if (keys.length > MAX_RESOURCE_ATTRIBUTES) {
|
|
1330
1861
|
ctx.addIssue({
|
|
@@ -1664,8 +2195,8 @@ var sliceCodePoints = (value, max) => {
|
|
|
1664
2195
|
}
|
|
1665
2196
|
return result;
|
|
1666
2197
|
};
|
|
1667
|
-
var logSignalOf = (
|
|
1668
|
-
switch (
|
|
2198
|
+
var logSignalOf = (event2, factKind) => {
|
|
2199
|
+
switch (event2.type) {
|
|
1669
2200
|
case "session.start":
|
|
1670
2201
|
case "session.end":
|
|
1671
2202
|
return "session";
|
|
@@ -1683,9 +2214,9 @@ var logSignalOf = (event, factKind) => {
|
|
|
1683
2214
|
case "error.raised":
|
|
1684
2215
|
return "error";
|
|
1685
2216
|
case "tool.start":
|
|
1686
|
-
return toolSignal(
|
|
2217
|
+
return toolSignal(event2.toolName, event2.toolKind);
|
|
1687
2218
|
case "tool.end":
|
|
1688
|
-
return toolSignal(
|
|
2219
|
+
return toolSignal(event2.toolName, void 0);
|
|
1689
2220
|
}
|
|
1690
2221
|
};
|
|
1691
2222
|
var toolSignal = (toolName, toolKind) => {
|
|
@@ -1744,16 +2275,16 @@ var logSignalsForLifecycleEvents = (lifecycleEvents) => {
|
|
|
1744
2275
|
}
|
|
1745
2276
|
return LOG_SIGNALS.filter((signal) => signals.has(signal));
|
|
1746
2277
|
};
|
|
1747
|
-
var severityFor = (
|
|
1748
|
-
switch (
|
|
2278
|
+
var severityFor = (event2) => {
|
|
2279
|
+
switch (event2.type) {
|
|
1749
2280
|
case "error.raised":
|
|
1750
|
-
return
|
|
2281
|
+
return event2.severity === "error" ? SeverityNumber.ERROR : SeverityNumber.WARN;
|
|
1751
2282
|
case "session.end":
|
|
1752
|
-
return
|
|
2283
|
+
return event2.reason === "error" || event2.reason === "timeout" ? SeverityNumber.ERROR : event2.reason === "aborted" ? SeverityNumber.WARN : SeverityNumber.INFO;
|
|
1753
2284
|
case "generation.end":
|
|
1754
2285
|
case "tool.end":
|
|
1755
2286
|
case "subagent.end":
|
|
1756
|
-
return
|
|
2287
|
+
return event2.outcome === "error" || event2.outcome === "timeout" ? SeverityNumber.ERROR : event2.outcome === "denied" || event2.outcome === "cancelled" ? SeverityNumber.WARN : SeverityNumber.INFO;
|
|
1757
2288
|
default:
|
|
1758
2289
|
return SeverityNumber.INFO;
|
|
1759
2290
|
}
|
|
@@ -1763,84 +2294,86 @@ var SEVERITY_TEXT = Object.freeze({
|
|
|
1763
2294
|
[SeverityNumber.WARN]: "WARN",
|
|
1764
2295
|
[SeverityNumber.ERROR]: "ERROR"
|
|
1765
2296
|
});
|
|
1766
|
-
var identityAttributes2 = (
|
|
1767
|
-
var eventAttributes = (
|
|
1768
|
-
switch (
|
|
2297
|
+
var identityAttributes2 = (event2, resource, ids) => exportIdentityAttributes(event2, resource, ids);
|
|
2298
|
+
var eventAttributes = (event2) => {
|
|
2299
|
+
switch (event2.type) {
|
|
1769
2300
|
case "session.start":
|
|
1770
2301
|
return {
|
|
1771
|
-
[ATTR_OTELHOOK_SESSION_KIND]:
|
|
1772
|
-
...
|
|
1773
|
-
...
|
|
1774
|
-
...
|
|
2302
|
+
[ATTR_OTELHOOK_SESSION_KIND]: event2.sessionKind,
|
|
2303
|
+
...event2.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME2]: event2.agentName },
|
|
2304
|
+
...event2.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION2]: event2.agentVersion },
|
|
2305
|
+
...event2.model === void 0 ? {} : { [ATTR_GEN_AI_REQUEST_MODEL2]: event2.model.modelId },
|
|
2306
|
+
...targetAttributes(event2)
|
|
1775
2307
|
};
|
|
1776
2308
|
case "session.end":
|
|
1777
2309
|
return {
|
|
1778
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1779
|
-
...usageAttributes2(
|
|
2310
|
+
[ATTR_OTELHOOK_OUTCOME2]: event2.reason,
|
|
2311
|
+
...usageAttributes2(event2.usage)
|
|
1780
2312
|
};
|
|
1781
2313
|
case "prompt.submitted":
|
|
1782
2314
|
return {
|
|
1783
|
-
[ATTR_OTELHOOK_PROMPT_SOURCE]:
|
|
1784
|
-
...
|
|
2315
|
+
[ATTR_OTELHOOK_PROMPT_SOURCE]: event2.promptSource,
|
|
2316
|
+
...event2.turnIndex === void 0 ? {} : { [ATTR_OTELHOOK_PROMPT_TURN_INDEX]: event2.turnIndex },
|
|
2317
|
+
...targetAttributes(event2)
|
|
1785
2318
|
};
|
|
1786
2319
|
case "generation.start":
|
|
1787
2320
|
return {
|
|
1788
2321
|
[ATTR_GEN_AI_OPERATION_NAME2]: "chat",
|
|
1789
|
-
[ATTR_OTELHOOK_GENERATION_ID2]:
|
|
1790
|
-
[ATTR_GEN_AI_REQUEST_MODEL2]:
|
|
1791
|
-
...
|
|
2322
|
+
[ATTR_OTELHOOK_GENERATION_ID2]: event2.generationId,
|
|
2323
|
+
[ATTR_GEN_AI_REQUEST_MODEL2]: event2.model.modelId,
|
|
2324
|
+
...event2.model.vendor === void 0 ? {} : { [ATTR_GEN_AI_SYSTEM2]: event2.model.vendor }
|
|
1792
2325
|
};
|
|
1793
2326
|
case "generation.end":
|
|
1794
2327
|
return {
|
|
1795
2328
|
[ATTR_GEN_AI_OPERATION_NAME2]: "chat",
|
|
1796
|
-
[ATTR_OTELHOOK_GENERATION_ID2]:
|
|
1797
|
-
[ATTR_GEN_AI_RESPONSE_MODEL2]:
|
|
1798
|
-
...
|
|
1799
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1800
|
-
...
|
|
1801
|
-
...usageAttributes2(
|
|
2329
|
+
[ATTR_OTELHOOK_GENERATION_ID2]: event2.generationId,
|
|
2330
|
+
[ATTR_GEN_AI_RESPONSE_MODEL2]: event2.model.modelId,
|
|
2331
|
+
...event2.model.vendor === void 0 ? {} : { [ATTR_GEN_AI_SYSTEM2]: event2.model.vendor },
|
|
2332
|
+
[ATTR_OTELHOOK_OUTCOME2]: event2.outcome,
|
|
2333
|
+
...event2.stopReason === void 0 ? {} : { [ATTR_OTELHOOK_STOP_REASON]: event2.stopReason },
|
|
2334
|
+
...usageAttributes2(event2.usage)
|
|
1802
2335
|
};
|
|
1803
2336
|
case "tool.start":
|
|
1804
2337
|
return {
|
|
1805
|
-
[ATTR_GEN_AI_TOOL_NAME2]:
|
|
1806
|
-
[ATTR_GEN_AI_TOOL_CALL_ID2]:
|
|
1807
|
-
[ATTR_OTELHOOK_TOOL_KIND2]:
|
|
1808
|
-
...
|
|
1809
|
-
...targetAttributes(
|
|
2338
|
+
[ATTR_GEN_AI_TOOL_NAME2]: event2.toolName,
|
|
2339
|
+
[ATTR_GEN_AI_TOOL_CALL_ID2]: event2.toolCallId,
|
|
2340
|
+
[ATTR_OTELHOOK_TOOL_KIND2]: event2.toolKind,
|
|
2341
|
+
...event2.generationId === void 0 ? {} : { [ATTR_OTELHOOK_GENERATION_ID2]: event2.generationId },
|
|
2342
|
+
...targetAttributes(event2)
|
|
1810
2343
|
};
|
|
1811
2344
|
case "tool.end":
|
|
1812
2345
|
return {
|
|
1813
|
-
[ATTR_GEN_AI_TOOL_NAME2]:
|
|
1814
|
-
[ATTR_GEN_AI_TOOL_CALL_ID2]:
|
|
1815
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1816
|
-
...
|
|
1817
|
-
...targetAttributes(
|
|
2346
|
+
[ATTR_GEN_AI_TOOL_NAME2]: event2.toolName,
|
|
2347
|
+
[ATTR_GEN_AI_TOOL_CALL_ID2]: event2.toolCallId,
|
|
2348
|
+
[ATTR_OTELHOOK_OUTCOME2]: event2.outcome,
|
|
2349
|
+
...event2.permissionDecision === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_PERMISSION]: event2.permissionDecision },
|
|
2350
|
+
...targetAttributes(event2)
|
|
1818
2351
|
};
|
|
1819
2352
|
case "subagent.start":
|
|
1820
2353
|
return {
|
|
1821
|
-
[ATTR_OTELHOOK_DELEGATION_DEPTH2]:
|
|
1822
|
-
...
|
|
1823
|
-
...
|
|
2354
|
+
[ATTR_OTELHOOK_DELEGATION_DEPTH2]: event2.delegationDepth,
|
|
2355
|
+
...event2.subagentType === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_TYPE]: event2.subagentType },
|
|
2356
|
+
...event2.model === void 0 ? {} : { [ATTR_GEN_AI_REQUEST_MODEL2]: event2.model.modelId }
|
|
1824
2357
|
};
|
|
1825
2358
|
case "subagent.end":
|
|
1826
2359
|
return {
|
|
1827
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1828
|
-
...usageAttributes2(
|
|
2360
|
+
[ATTR_OTELHOOK_OUTCOME2]: event2.outcome,
|
|
2361
|
+
...usageAttributes2(event2.usage)
|
|
1829
2362
|
};
|
|
1830
2363
|
case "compaction.performed":
|
|
1831
2364
|
return {
|
|
1832
|
-
[ATTR_OTELHOOK_COMPACTION_TRIGGER2]:
|
|
1833
|
-
...
|
|
1834
|
-
...
|
|
1835
|
-
...
|
|
1836
|
-
...usageAttributes2(
|
|
2365
|
+
[ATTR_OTELHOOK_COMPACTION_TRIGGER2]: event2.trigger,
|
|
2366
|
+
...event2.contextTokensBefore === void 0 ? {} : { [ATTR_OTELHOOK_CONTEXT_TOKENS_BEFORE]: event2.contextTokensBefore },
|
|
2367
|
+
...event2.contextTokensAfter === void 0 ? {} : { [ATTR_OTELHOOK_CONTEXT_TOKENS_AFTER]: event2.contextTokensAfter },
|
|
2368
|
+
...event2.droppedMessageCount === void 0 ? {} : { [ATTR_OTELHOOK_DROPPED_MESSAGES]: event2.droppedMessageCount },
|
|
2369
|
+
...usageAttributes2(event2.usage)
|
|
1837
2370
|
};
|
|
1838
2371
|
case "error.raised":
|
|
1839
2372
|
return {
|
|
1840
|
-
[ATTR_ERROR_TYPE2]:
|
|
1841
|
-
[ATTR_OTELHOOK_ERROR_PHASE]:
|
|
1842
|
-
[ATTR_OTELHOOK_ERROR_RETRYABLE]:
|
|
1843
|
-
[ATTR_OTELHOOK_ERROR_SEVERITY]:
|
|
2373
|
+
[ATTR_ERROR_TYPE2]: event2.errorCode,
|
|
2374
|
+
[ATTR_OTELHOOK_ERROR_PHASE]: event2.phase,
|
|
2375
|
+
[ATTR_OTELHOOK_ERROR_RETRYABLE]: event2.retryable,
|
|
2376
|
+
[ATTR_OTELHOOK_ERROR_SEVERITY]: event2.severity
|
|
1844
2377
|
};
|
|
1845
2378
|
}
|
|
1846
2379
|
};
|
|
@@ -1851,20 +2384,20 @@ var usageAttributes2 = (usage) => usage === void 0 ? {} : {
|
|
|
1851
2384
|
[ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS2]: usage.cacheCreationInputTokens,
|
|
1852
2385
|
...usageTemporalityAttributes(usage)
|
|
1853
2386
|
};
|
|
1854
|
-
var contentFactsOf = (
|
|
1855
|
-
switch (
|
|
2387
|
+
var contentFactsOf = (event2) => {
|
|
2388
|
+
switch (event2.type) {
|
|
1856
2389
|
case "prompt.submitted":
|
|
1857
|
-
return
|
|
2390
|
+
return event2.content === void 0 ? [] : [event2.content];
|
|
1858
2391
|
case "generation.start":
|
|
1859
|
-
return
|
|
2392
|
+
return event2.inputContent ?? [];
|
|
1860
2393
|
case "generation.end":
|
|
1861
|
-
return
|
|
2394
|
+
return event2.outputContent ?? [];
|
|
1862
2395
|
case "tool.start":
|
|
1863
|
-
return
|
|
2396
|
+
return event2.input === void 0 ? [] : [event2.input];
|
|
1864
2397
|
case "tool.end":
|
|
1865
|
-
return
|
|
2398
|
+
return event2.output === void 0 ? [] : [event2.output];
|
|
1866
2399
|
case "error.raised":
|
|
1867
|
-
return
|
|
2400
|
+
return event2.message === void 0 ? [] : [event2.message];
|
|
1868
2401
|
default:
|
|
1869
2402
|
return [];
|
|
1870
2403
|
}
|
|
@@ -1939,8 +2472,8 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1939
2472
|
});
|
|
1940
2473
|
const records = [];
|
|
1941
2474
|
let droppedFacts = 0;
|
|
1942
|
-
for (const
|
|
1943
|
-
const identity = identities.get(
|
|
2475
|
+
for (const event2 of events) {
|
|
2476
|
+
const identity = identities.get(event2.eventId);
|
|
1944
2477
|
if (identity === void 0) {
|
|
1945
2478
|
continue;
|
|
1946
2479
|
}
|
|
@@ -1950,8 +2483,8 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1950
2483
|
traceFlags: TraceFlags2.SAMPLED,
|
|
1951
2484
|
isRemote: false
|
|
1952
2485
|
};
|
|
1953
|
-
const shared = eventAttributes(
|
|
1954
|
-
const facts = contentFactsOf(
|
|
2486
|
+
const shared = eventAttributes(event2);
|
|
2487
|
+
const facts = contentFactsOf(event2);
|
|
1955
2488
|
if (facts.length === 0) {
|
|
1956
2489
|
if (records.length >= MAX_LOG_RECORDS_PER_BATCH) {
|
|
1957
2490
|
droppedFacts += 1;
|
|
@@ -1959,9 +2492,9 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1959
2492
|
}
|
|
1960
2493
|
records.push(
|
|
1961
2494
|
buildRecord({
|
|
1962
|
-
event,
|
|
1963
|
-
signal: logSignalOf(
|
|
1964
|
-
attributes:
|
|
2495
|
+
event: event2,
|
|
2496
|
+
signal: logSignalOf(event2),
|
|
2497
|
+
attributes: event2.type === "generation.end" ? { ...shared, [ATTR_CONTENT_KIND]: "response", [ATTR_CONTENT_DISCLOSURE]: "metadata_only" } : shared,
|
|
1965
2498
|
spanContext,
|
|
1966
2499
|
...identity.parentSpanId === void 0 ? {} : { parentSpanId: identity.parentSpanId },
|
|
1967
2500
|
resource: options.resource,
|
|
@@ -1980,8 +2513,8 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1980
2513
|
const body = discloseBody(fact, content);
|
|
1981
2514
|
records.push(
|
|
1982
2515
|
buildRecord({
|
|
1983
|
-
event,
|
|
1984
|
-
signal: logSignalOf(
|
|
2516
|
+
event: event2,
|
|
2517
|
+
signal: logSignalOf(event2, fact.kind),
|
|
1985
2518
|
attributes: { ...shared, ...contentAttributes(fact, body) },
|
|
1986
2519
|
..."text" in body ? { body: body.text } : {},
|
|
1987
2520
|
spanContext,
|