@osfactory/otel-hook 0.4.1 → 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-BgqtlADe.d.ts → adapter-BJiz6lqM.d.ts} +2 -3
- package/dist/cli.js +100 -35
- package/dist/cli.js.map +1 -1
- package/dist/{events-C3h3GvHj.d.ts → events-B3MHoJTD.d.ts} +190 -1
- package/dist/{filesystem-store-BAq3VGVv.d.ts → filesystem-store-r-nNA3BA.d.ts} +1 -1
- package/dist/{hook-CQiNa88Q.d.ts → hook-Dh8OO4Wa.d.ts} +4 -4
- package/dist/index.d.ts +12 -13
- package/dist/index.js +105 -35
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -5
- package/dist/install.js +13 -3
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +8 -9
- package/dist/integration.js +2299 -2246
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +762 -213
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-kflYgZbg.d.ts → memory-Bl9ANVff.d.ts} +2 -2
- package/dist/model.d.ts +1 -2
- package/dist/model.js +20 -4
- package/dist/model.js.map +1 -1
- package/dist/{otlp-log-sink-BZIgYPKN.d.ts → otlp-log-sink-eUEjaLhk.d.ts} +3 -3
- package/dist/{payload-DpyU8F-z.d.ts → payload-Ci8_ERm6.d.ts} +1 -1
- package/dist/{ports-B_iwJQPQ.d.ts → ports-n7KFOpKo.d.ts} +9 -1
- package/dist/providers.d.ts +10 -11
- package/dist/providers.js +37 -14
- package/dist/providers.js.map +1 -1
- package/dist/{registry-BSBS8t7S.d.ts → registry-CIVvRlVK.d.ts} +1 -1
- package/dist/runtime.d.ts +32 -16
- package/dist/runtime.js +57 -15
- package/dist/runtime.js.map +1 -1
- package/dist/{semconv-BeUPQ7_q.d.ts → semconv-fPRb-dpU.d.ts} +1 -1
- package/dist/state.d.ts +4 -4
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +953 -414
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +14 -9
- package/dist/testing.js +45 -20
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/dist/target-8RfaVxp8.d.ts +0 -83
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";
|
|
@@ -58,16 +830,20 @@ var ATTR_OTELHOOK_SUBAGENT_ID = "otelhook.subagent.id";
|
|
|
58
830
|
var ATTR_VCS_REF_HEAD_NAME = "vcs.ref.head.name";
|
|
59
831
|
var ATTR_OTELHOOK_TARGET_WORKSPACE_ID = "otelhook.target.workspace.id";
|
|
60
832
|
var ATTR_OTELHOOK_TARGET_SOURCE = "otelhook.target.source";
|
|
833
|
+
var ATTR_OTELHOOK_TARGET_REPOSITORY_ID = "otelhook.target.repository.id";
|
|
834
|
+
var ATTR_OTELHOOK_TARGET_WORKTREE_KIND = "otelhook.target.worktree.kind";
|
|
61
835
|
var ATTR_OTELHOOK_USAGE_TEMPORALITY = "otelhook.usage.temporality";
|
|
62
|
-
var targetAttributes = (
|
|
63
|
-
if (
|
|
836
|
+
var targetAttributes = (event2) => {
|
|
837
|
+
if (!isTargetedEvent(event2) || event2.target === void 0) {
|
|
64
838
|
return {};
|
|
65
839
|
}
|
|
66
|
-
const { target } =
|
|
840
|
+
const { target } = event2;
|
|
67
841
|
return {
|
|
68
842
|
[ATTR_OTELHOOK_TARGET_WORKSPACE_ID]: target.workspaceId,
|
|
69
843
|
[ATTR_OTELHOOK_TARGET_SOURCE]: target.source,
|
|
70
|
-
...target.vcsBranchName === void 0 ? {} : { [ATTR_VCS_REF_HEAD_NAME]: target.vcsBranchName }
|
|
844
|
+
...target.vcsBranchName === void 0 ? {} : { [ATTR_VCS_REF_HEAD_NAME]: target.vcsBranchName },
|
|
845
|
+
...target.repositoryId === void 0 ? {} : { [ATTR_OTELHOOK_TARGET_REPOSITORY_ID]: target.repositoryId },
|
|
846
|
+
...target.worktreeKind === void 0 ? {} : { [ATTR_OTELHOOK_TARGET_WORKTREE_KIND]: target.worktreeKind }
|
|
71
847
|
};
|
|
72
848
|
};
|
|
73
849
|
var usageTemporalityAttributes = (usage) => usage === void 0 ? {} : { [ATTR_OTELHOOK_USAGE_TEMPORALITY]: usage.temporality };
|
|
@@ -96,17 +872,17 @@ var hexTraceAttributes = (ids) => ({
|
|
|
96
872
|
...SPAN_ID_HEX_PATTERN.test(ids.spanId) ? { [ATTR_SPAN_ID]: ids.spanId } : {},
|
|
97
873
|
...ids.parentSpanId !== void 0 && SPAN_ID_HEX_PATTERN.test(ids.parentSpanId) ? { [ATTR_PARENT_SPAN_ID]: ids.parentSpanId } : {}
|
|
98
874
|
});
|
|
99
|
-
var exportIdentityAttributes = (
|
|
100
|
-
const { sessionId, providerSessionId } = resolveExportedSessionId(
|
|
875
|
+
var exportIdentityAttributes = (event2, resource, ids) => {
|
|
876
|
+
const { sessionId, providerSessionId } = resolveExportedSessionId(event2.sessionId, resource);
|
|
101
877
|
return {
|
|
102
878
|
[ATTR_SESSION_ID]: sessionId,
|
|
103
879
|
[ATTR_OTELHOOK_SESSION_ID]: providerSessionId,
|
|
104
880
|
[ATTR_GEN_AI_CONVERSATION_ID]: providerSessionId,
|
|
105
|
-
[ATTR_OTELHOOK_INVOCATION_ID]:
|
|
106
|
-
[ATTR_OTELHOOK_PROVIDER_ID]:
|
|
107
|
-
...
|
|
108
|
-
[ATTR_OTELHOOK_WORKSPACE_ID]:
|
|
109
|
-
...
|
|
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 },
|
|
110
886
|
...passthroughHarAttributes(resource),
|
|
111
887
|
...hexTraceAttributes(ids)
|
|
112
888
|
};
|
|
@@ -150,57 +926,60 @@ var familyOf = (type) => {
|
|
|
150
926
|
return void 0;
|
|
151
927
|
}
|
|
152
928
|
};
|
|
153
|
-
var spanScopeRefOf = (
|
|
154
|
-
const family = familyOf(
|
|
929
|
+
var spanScopeRefOf = (event2) => {
|
|
930
|
+
const family = familyOf(event2.type);
|
|
155
931
|
if (family === void 0) {
|
|
156
932
|
return void 0;
|
|
157
933
|
}
|
|
158
|
-
switch (
|
|
934
|
+
switch (event2.type) {
|
|
159
935
|
case "session.start":
|
|
160
936
|
case "session.end":
|
|
161
|
-
return { family, scopeKey:
|
|
937
|
+
return { family, scopeKey: event2.sessionId };
|
|
162
938
|
case "generation.start":
|
|
163
939
|
case "generation.end":
|
|
164
|
-
return { family, scopeKey:
|
|
940
|
+
return { family, scopeKey: event2.generationId };
|
|
165
941
|
case "tool.start":
|
|
166
942
|
case "tool.end":
|
|
167
|
-
return { family, scopeKey:
|
|
943
|
+
return { family, scopeKey: event2.toolCallId };
|
|
168
944
|
case "subagent.start":
|
|
169
945
|
case "subagent.end":
|
|
170
|
-
return { family, scopeKey:
|
|
946
|
+
return { family, scopeKey: event2.subagentInvocationId };
|
|
171
947
|
default:
|
|
172
948
|
return void 0;
|
|
173
949
|
}
|
|
174
950
|
};
|
|
175
|
-
var parentScopeRefOf = (
|
|
176
|
-
if (
|
|
951
|
+
var parentScopeRefOf = (event2) => {
|
|
952
|
+
if (event2.type === "session.start" || event2.type === "session.end") {
|
|
177
953
|
return void 0;
|
|
178
954
|
}
|
|
179
|
-
if (
|
|
180
|
-
return { family: "generation", scopeKey:
|
|
955
|
+
if (event2.type === "tool.start" && event2.generationId !== void 0) {
|
|
956
|
+
return { family: "generation", scopeKey: event2.generationId };
|
|
181
957
|
}
|
|
182
|
-
return { family: "session", scopeKey:
|
|
958
|
+
return { family: "session", scopeKey: event2.sessionId };
|
|
183
959
|
};
|
|
184
|
-
var startOnlySpanAttributes = (
|
|
185
|
-
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.
|
|
186
964
|
case "session.start":
|
|
187
965
|
return {
|
|
188
|
-
...
|
|
189
|
-
...
|
|
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)
|
|
190
969
|
};
|
|
191
970
|
case "generation.start":
|
|
192
971
|
return {
|
|
193
|
-
[ATTR_GEN_AI_REQUEST_MODEL]:
|
|
194
|
-
...
|
|
972
|
+
[ATTR_GEN_AI_REQUEST_MODEL]: event2.model.modelId,
|
|
973
|
+
...event2.model.vendor === void 0 ? {} : { [ATTR_GEN_AI_SYSTEM]: event2.model.vendor }
|
|
195
974
|
};
|
|
196
975
|
// `toolName` and `toolCallId` are on both tool edges, so they are not
|
|
197
976
|
// start-only and persisting them would just pad every record.
|
|
198
977
|
// The target is carried forward too: an end-only process may see a payload
|
|
199
978
|
// with less to go on (no tool input), and the start's evidence still holds.
|
|
200
979
|
case "tool.start":
|
|
201
|
-
return { [ATTR_OTELHOOK_TOOL_KIND]:
|
|
980
|
+
return { [ATTR_OTELHOOK_TOOL_KIND]: event2.toolKind, ...targetAttributes(event2) };
|
|
202
981
|
case "subagent.start":
|
|
203
|
-
return { [ATTR_OTELHOOK_DELEGATION_DEPTH]:
|
|
982
|
+
return { [ATTR_OTELHOOK_DELEGATION_DEPTH]: event2.delegationDepth };
|
|
204
983
|
default:
|
|
205
984
|
return {};
|
|
206
985
|
}
|
|
@@ -218,7 +997,7 @@ var outcomeStatus = (outcome) => {
|
|
|
218
997
|
}
|
|
219
998
|
return { code: SpanStatusCode.ERROR, message: outcome };
|
|
220
999
|
};
|
|
221
|
-
var identityAttributes = (
|
|
1000
|
+
var identityAttributes = (event2, resource, ids) => exportIdentityAttributes(event2, resource, ids);
|
|
222
1001
|
var usageAttributes = (usage, resetDetected) => {
|
|
223
1002
|
if (usage === void 0) {
|
|
224
1003
|
return {};
|
|
@@ -241,7 +1020,9 @@ var TARGET_SOURCE_RANK = Object.freeze({
|
|
|
241
1020
|
var TARGET_KEYS = [
|
|
242
1021
|
ATTR_OTELHOOK_TARGET_WORKSPACE_ID,
|
|
243
1022
|
ATTR_OTELHOOK_TARGET_SOURCE,
|
|
244
|
-
ATTR_VCS_REF_HEAD_NAME
|
|
1023
|
+
ATTR_VCS_REF_HEAD_NAME,
|
|
1024
|
+
ATTR_OTELHOOK_TARGET_REPOSITORY_ID,
|
|
1025
|
+
ATTR_OTELHOOK_TARGET_WORKTREE_KIND
|
|
245
1026
|
];
|
|
246
1027
|
var pickTarget = (attributes) => {
|
|
247
1028
|
const picked = {};
|
|
@@ -362,7 +1143,8 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
362
1143
|
name = "session";
|
|
363
1144
|
kind = SpanKind.INTERNAL;
|
|
364
1145
|
attributes = {
|
|
365
|
-
...attributes,
|
|
1146
|
+
...withoutTarget(attributes),
|
|
1147
|
+
...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
|
|
366
1148
|
...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
|
|
367
1149
|
...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
|
|
368
1150
|
...end === void 0 ? {} : { [ATTR_OTELHOOK_OUTCOME]: end.reason },
|
|
@@ -448,14 +1230,14 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
448
1230
|
instrumentationScope: scope
|
|
449
1231
|
});
|
|
450
1232
|
};
|
|
451
|
-
var buildStandaloneSpan = (
|
|
452
|
-
const providerId =
|
|
453
|
-
const traceId = deriveTraceId(providerId,
|
|
454
|
-
const spanId = deriveStandaloneSpanId(providerId,
|
|
455
|
-
const parent = parentScopeRefOf(
|
|
456
|
-
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);
|
|
457
1239
|
let attributes = {
|
|
458
|
-
...identityAttributes(
|
|
1240
|
+
...identityAttributes(event2, resource, {
|
|
459
1241
|
traceId,
|
|
460
1242
|
spanId,
|
|
461
1243
|
...parentSpanId === void 0 ? {} : { parentSpanId }
|
|
@@ -463,28 +1245,28 @@ var buildStandaloneSpan = (event, resource, scope) => {
|
|
|
463
1245
|
[ATTR_OTELHOOK_SPAN_PAIRED]: true
|
|
464
1246
|
};
|
|
465
1247
|
let status = { code: SpanStatusCode.UNSET };
|
|
466
|
-
let name =
|
|
467
|
-
switch (
|
|
1248
|
+
let name = event2.type;
|
|
1249
|
+
switch (event2.type) {
|
|
468
1250
|
case "prompt.submitted":
|
|
469
1251
|
name = "prompt";
|
|
470
|
-
attributes = { ...attributes, "otelhook.prompt.source":
|
|
1252
|
+
attributes = { ...attributes, "otelhook.prompt.source": event2.promptSource, ...targetAttributes(event2) };
|
|
471
1253
|
break;
|
|
472
1254
|
case "compaction.performed":
|
|
473
1255
|
name = "compaction";
|
|
474
1256
|
attributes = {
|
|
475
1257
|
...attributes,
|
|
476
|
-
[ATTR_OTELHOOK_COMPACTION_TRIGGER]:
|
|
477
|
-
...usageAttributes(
|
|
1258
|
+
[ATTR_OTELHOOK_COMPACTION_TRIGGER]: event2.trigger,
|
|
1259
|
+
...usageAttributes(event2.usage, false)
|
|
478
1260
|
};
|
|
479
1261
|
break;
|
|
480
1262
|
case "error.raised":
|
|
481
1263
|
name = "error";
|
|
482
|
-
status = { code: SpanStatusCode.ERROR, message:
|
|
1264
|
+
status = { code: SpanStatusCode.ERROR, message: event2.errorCode };
|
|
483
1265
|
attributes = {
|
|
484
1266
|
...attributes,
|
|
485
|
-
[ATTR_ERROR_TYPE]:
|
|
486
|
-
"otelhook.error.phase":
|
|
487
|
-
"otelhook.error.retryable":
|
|
1267
|
+
[ATTR_ERROR_TYPE]: event2.errorCode,
|
|
1268
|
+
"otelhook.error.phase": event2.phase,
|
|
1269
|
+
"otelhook.error.retryable": event2.retryable
|
|
488
1270
|
};
|
|
489
1271
|
break;
|
|
490
1272
|
default:
|
|
@@ -493,8 +1275,8 @@ var buildStandaloneSpan = (event, resource, scope) => {
|
|
|
493
1275
|
return toReadableSpan({
|
|
494
1276
|
name,
|
|
495
1277
|
kind: SpanKind.INTERNAL,
|
|
496
|
-
startMillis:
|
|
497
|
-
endMillis:
|
|
1278
|
+
startMillis: event2.occurredAt,
|
|
1279
|
+
endMillis: event2.occurredAt,
|
|
498
1280
|
attributes,
|
|
499
1281
|
status,
|
|
500
1282
|
traceId,
|
|
@@ -522,21 +1304,21 @@ var layoutBatch = (events) => {
|
|
|
522
1304
|
const groups = /* @__PURE__ */ new Map();
|
|
523
1305
|
const standalone = [];
|
|
524
1306
|
const groupOf = /* @__PURE__ */ new Map();
|
|
525
|
-
for (const
|
|
526
|
-
const ref = spanScopeRefOf(
|
|
1307
|
+
for (const event2 of events) {
|
|
1308
|
+
const ref = spanScopeRefOf(event2);
|
|
527
1309
|
if (ref === void 0) {
|
|
528
|
-
standalone.push(
|
|
1310
|
+
standalone.push(event2);
|
|
529
1311
|
continue;
|
|
530
1312
|
}
|
|
531
|
-
const groupKey = correlationKey(
|
|
1313
|
+
const groupKey = correlationKey(event2.provenance.providerId, event2.sessionId, ref);
|
|
532
1314
|
const group = groups.get(groupKey) ?? { ref };
|
|
533
|
-
if (
|
|
534
|
-
group.start =
|
|
1315
|
+
if (event2.type.endsWith(".start")) {
|
|
1316
|
+
group.start = event2;
|
|
535
1317
|
} else {
|
|
536
|
-
group.end =
|
|
1318
|
+
group.end = event2;
|
|
537
1319
|
}
|
|
538
1320
|
groups.set(groupKey, group);
|
|
539
|
-
groupOf.set(
|
|
1321
|
+
groupOf.set(event2.eventId, groupKey);
|
|
540
1322
|
}
|
|
541
1323
|
return { groups, standalone, groupOf };
|
|
542
1324
|
};
|
|
@@ -593,24 +1375,24 @@ var canonicalEventTraceIdentities = (events, options = {}) => {
|
|
|
593
1375
|
}
|
|
594
1376
|
}
|
|
595
1377
|
const identities = /* @__PURE__ */ new Map();
|
|
596
|
-
for (const
|
|
597
|
-
const providerId =
|
|
598
|
-
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);
|
|
599
1381
|
const plan = groupKey === void 0 ? void 0 : plans.get(groupKey);
|
|
600
1382
|
if (plan === void 0) {
|
|
601
|
-
const parent2 = parentScopeRefOf(
|
|
602
|
-
identities.set(
|
|
603
|
-
traceId: deriveTraceId(providerId,
|
|
604
|
-
spanId: deriveStandaloneSpanId(providerId,
|
|
605
|
-
...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) }
|
|
606
1388
|
});
|
|
607
1389
|
continue;
|
|
608
1390
|
}
|
|
609
|
-
const parent = plan.correlation?.parent ?? parentScopeRefOf(
|
|
610
|
-
identities.set(
|
|
1391
|
+
const parent = plan.correlation?.parent ?? parentScopeRefOf(event2);
|
|
1392
|
+
identities.set(event2.eventId, {
|
|
611
1393
|
traceId: plan.traceId,
|
|
612
1394
|
spanId: plan.spanId,
|
|
613
|
-
...parent === void 0 ? {} : { parentSpanId: deriveSpanId(providerId,
|
|
1395
|
+
...parent === void 0 ? {} : { parentSpanId: deriveSpanId(providerId, event2.sessionId, parent) }
|
|
614
1396
|
});
|
|
615
1397
|
}
|
|
616
1398
|
return identities;
|
|
@@ -627,8 +1409,8 @@ var canonicalEventsToReadableSpans = (events, options) => {
|
|
|
627
1409
|
}
|
|
628
1410
|
spans.push(buildLifecycleSpan(plan, options.resource, scope));
|
|
629
1411
|
}
|
|
630
|
-
for (const
|
|
631
|
-
spans.push(buildStandaloneSpan(
|
|
1412
|
+
for (const event2 of layout.standalone) {
|
|
1413
|
+
spans.push(buildStandaloneSpan(event2, options.resource, scope));
|
|
632
1414
|
}
|
|
633
1415
|
return spans;
|
|
634
1416
|
};
|
|
@@ -876,259 +1658,14 @@ var createFileDurableSpool = (options) => createSpoolQueue({
|
|
|
876
1658
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
877
1659
|
|
|
878
1660
|
// src/errors/index.ts
|
|
879
|
-
import { z as
|
|
880
|
-
|
|
881
|
-
// src/model/primitives.ts
|
|
882
|
-
import { z } from "zod";
|
|
883
|
-
var MAX_IDENTIFIER_LENGTH = 256;
|
|
884
|
-
var MAX_ATTRIBUTE_STRING_LENGTH = 4096;
|
|
885
|
-
var MAX_ATTRIBUTE_ARRAY_LENGTH = 128;
|
|
886
|
-
var nonEmptyStringSchema = z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
887
|
-
var epochMillisSchema = z.number().int().min(0).max(864e13);
|
|
888
|
-
var durationMillisSchema = z.number().min(0).finite();
|
|
889
|
-
var tokenCountSchema = z.number().int().min(0);
|
|
890
|
-
var sequenceNumberSchema = z.number().int().min(0);
|
|
891
|
-
var brandedIdSchema = () => z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
892
|
-
var invocationIdSchema = brandedIdSchema().brand();
|
|
893
|
-
var sessionIdSchema = brandedIdSchema().brand();
|
|
894
|
-
var eventIdSchema = brandedIdSchema().brand();
|
|
895
|
-
var WORKSPACE_ID_PATTERN = /^[a-z][a-z0-9]{0,15}:[A-Za-z0-9_-]{8,128}$/;
|
|
896
|
-
var workspaceIdSchema = z.string().regex(WORKSPACE_ID_PATTERN, "workspace id must be an opaque `<scheme>:<token>` handle").brand();
|
|
897
|
-
var PROVIDER_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
898
|
-
var providerIdSchema = z.string().min(1).max(64).regex(PROVIDER_ID_PATTERN, "provider id must be lowercase and hyphenated").brand();
|
|
899
|
-
var UNKNOWN_PROVIDER_ID = "unknown";
|
|
900
|
-
var resolvedProviderIdSchema = z.union([
|
|
901
|
-
providerIdSchema,
|
|
902
|
-
z.literal(UNKNOWN_PROVIDER_ID)
|
|
903
|
-
]);
|
|
904
|
-
var attributePrimitiveSchema = z.union([
|
|
905
|
-
z.string().max(MAX_ATTRIBUTE_STRING_LENGTH),
|
|
906
|
-
z.number().finite(),
|
|
907
|
-
z.boolean()
|
|
908
|
-
]);
|
|
909
|
-
var attributeValueSchema = z.union([
|
|
910
|
-
attributePrimitiveSchema,
|
|
911
|
-
z.array(attributePrimitiveSchema).max(MAX_ATTRIBUTE_ARRAY_LENGTH)
|
|
912
|
-
]);
|
|
913
|
-
var attributesSchema = z.record(z.string().min(1).max(MAX_IDENTIFIER_LENGTH), attributeValueSchema);
|
|
914
|
-
var detectionConfidenceSchema = z.enum(["none", "weak", "strong", "exact"]);
|
|
915
|
-
var DETECTION_CONFIDENCE_RANK = Object.freeze({
|
|
916
|
-
none: 0,
|
|
917
|
-
weak: 1,
|
|
918
|
-
strong: 2,
|
|
919
|
-
exact: 3
|
|
920
|
-
});
|
|
921
|
-
var sourceTransportSchema = z.enum([
|
|
922
|
-
"hook-stdin",
|
|
923
|
-
"cli-argument",
|
|
924
|
-
"library-call",
|
|
925
|
-
"test-fixture"
|
|
926
|
-
]);
|
|
927
|
-
|
|
928
|
-
// src/errors/taxonomy.ts
|
|
929
|
-
import { z as z2 } from "zod";
|
|
930
|
-
var otelHookErrorCodeSchema = z2.enum([
|
|
931
|
-
/** Input was not usable at all (empty stdin, unparsable JSON). */
|
|
932
|
-
"invalid-input",
|
|
933
|
-
/** Input parsed but failed canonical schema validation. */
|
|
934
|
-
"schema-validation-failed",
|
|
935
|
-
/** No adapter claimed the input with sufficient confidence. */
|
|
936
|
-
"provider-unknown",
|
|
937
|
-
/** Several adapters claimed the input at the same confidence. */
|
|
938
|
-
"provider-detection-ambiguous",
|
|
939
|
-
/** An adapter threw or returned a malformed result. */
|
|
940
|
-
"provider-adapter-failure",
|
|
941
|
-
/** Two identity claims disagreed at equal confidence. */
|
|
942
|
-
"identity-conflict",
|
|
943
|
-
/** Required identity fields were absent. */
|
|
944
|
-
"identity-incomplete",
|
|
945
|
-
/** A usage report violated the canonical usage invariants. */
|
|
946
|
-
"usage-invalid",
|
|
947
|
-
/** The state store could not be read or written. */
|
|
948
|
-
"state-store-failure",
|
|
949
|
-
/** The telemetry sink rejected or could not deliver a batch. */
|
|
950
|
-
"telemetry-export-failure",
|
|
951
|
-
/** Content reached the sink boundary in a state the policy forbids. */
|
|
952
|
-
"privacy-policy-violation",
|
|
953
|
-
/** Configuration could not be resolved. */
|
|
954
|
-
"configuration-invalid",
|
|
955
|
-
/** A configured bound (events, batch size) dropped data. */
|
|
956
|
-
"limit-exceeded",
|
|
957
|
-
/**
|
|
958
|
-
* No replay-stable delivery identifier was available for a callback while
|
|
959
|
-
* deduplication was required.
|
|
960
|
-
*/
|
|
961
|
-
"delivery-identifier-unavailable",
|
|
962
|
-
"delivery-claim-superseded",
|
|
963
|
-
/** Anything unanticipated. Always reported, never fatal to the host. */
|
|
964
|
-
"internal-error"
|
|
965
|
-
]);
|
|
966
|
-
var errorSeveritySchema = z2.enum(["warning", "error"]);
|
|
967
|
-
var errorPhaseSchema = z2.enum([
|
|
968
|
-
"configuration",
|
|
969
|
-
"detection",
|
|
970
|
-
"identity",
|
|
971
|
-
"parsing",
|
|
972
|
-
"normalization",
|
|
973
|
-
"privacy",
|
|
974
|
-
"state",
|
|
975
|
-
"export",
|
|
976
|
-
"shutdown"
|
|
977
|
-
]);
|
|
978
|
-
var failurePostureSchema = z2.enum(["fail-open", "fail-closed-attribution"]);
|
|
979
|
-
var ERROR_TAXONOMY = Object.freeze({
|
|
980
|
-
"invalid-input": {
|
|
981
|
-
code: "invalid-input",
|
|
982
|
-
severity: "warning",
|
|
983
|
-
posture: "fail-open",
|
|
984
|
-
retryable: false,
|
|
985
|
-
summary: "Input could not be read or decoded."
|
|
986
|
-
},
|
|
987
|
-
"schema-validation-failed": {
|
|
988
|
-
code: "schema-validation-failed",
|
|
989
|
-
severity: "error",
|
|
990
|
-
posture: "fail-closed-attribution",
|
|
991
|
-
retryable: false,
|
|
992
|
-
summary: "A canonical event failed schema validation and was dropped."
|
|
993
|
-
},
|
|
994
|
-
"provider-unknown": {
|
|
995
|
-
code: "provider-unknown",
|
|
996
|
-
severity: "warning",
|
|
997
|
-
posture: "fail-closed-attribution",
|
|
998
|
-
retryable: false,
|
|
999
|
-
summary: "No adapter recognized the source provider; the input stays unattributed."
|
|
1000
|
-
},
|
|
1001
|
-
"provider-detection-ambiguous": {
|
|
1002
|
-
code: "provider-detection-ambiguous",
|
|
1003
|
-
severity: "warning",
|
|
1004
|
-
posture: "fail-closed-attribution",
|
|
1005
|
-
retryable: false,
|
|
1006
|
-
summary: "Multiple adapters claimed the input at equal confidence."
|
|
1007
|
-
},
|
|
1008
|
-
"provider-adapter-failure": {
|
|
1009
|
-
code: "provider-adapter-failure",
|
|
1010
|
-
severity: "error",
|
|
1011
|
-
posture: "fail-open",
|
|
1012
|
-
retryable: false,
|
|
1013
|
-
summary: "A provider adapter failed while parsing."
|
|
1014
|
-
},
|
|
1015
|
-
"identity-conflict": {
|
|
1016
|
-
code: "identity-conflict",
|
|
1017
|
-
severity: "error",
|
|
1018
|
-
posture: "fail-closed-attribution",
|
|
1019
|
-
retryable: false,
|
|
1020
|
-
summary: "Identity claims disagreed; attribution was declined."
|
|
1021
|
-
},
|
|
1022
|
-
"identity-incomplete": {
|
|
1023
|
-
code: "identity-incomplete",
|
|
1024
|
-
severity: "warning",
|
|
1025
|
-
posture: "fail-closed-attribution",
|
|
1026
|
-
retryable: false,
|
|
1027
|
-
summary: "Required identity fields were missing; attribution was declined."
|
|
1028
|
-
},
|
|
1029
|
-
"usage-invalid": {
|
|
1030
|
-
code: "usage-invalid",
|
|
1031
|
-
severity: "error",
|
|
1032
|
-
posture: "fail-open",
|
|
1033
|
-
retryable: false,
|
|
1034
|
-
summary: "A usage report violated the canonical usage invariants."
|
|
1035
|
-
},
|
|
1036
|
-
"state-store-failure": {
|
|
1037
|
-
code: "state-store-failure",
|
|
1038
|
-
severity: "warning",
|
|
1039
|
-
posture: "fail-open",
|
|
1040
|
-
retryable: true,
|
|
1041
|
-
summary: "State could not be read or written; derived values may be incomplete."
|
|
1042
|
-
},
|
|
1043
|
-
"telemetry-export-failure": {
|
|
1044
|
-
code: "telemetry-export-failure",
|
|
1045
|
-
severity: "warning",
|
|
1046
|
-
posture: "fail-open",
|
|
1047
|
-
retryable: true,
|
|
1048
|
-
summary: "The telemetry sink could not accept a batch."
|
|
1049
|
-
},
|
|
1050
|
-
"privacy-policy-violation": {
|
|
1051
|
-
code: "privacy-policy-violation",
|
|
1052
|
-
severity: "error",
|
|
1053
|
-
posture: "fail-closed-attribution",
|
|
1054
|
-
retryable: false,
|
|
1055
|
-
summary: "Content violated the resolved privacy policy and was dropped."
|
|
1056
|
-
},
|
|
1057
|
-
"configuration-invalid": {
|
|
1058
|
-
code: "configuration-invalid",
|
|
1059
|
-
severity: "error",
|
|
1060
|
-
posture: "fail-open",
|
|
1061
|
-
retryable: false,
|
|
1062
|
-
summary: "Configuration could not be resolved; defaults apply."
|
|
1063
|
-
},
|
|
1064
|
-
"limit-exceeded": {
|
|
1065
|
-
code: "limit-exceeded",
|
|
1066
|
-
severity: "warning",
|
|
1067
|
-
posture: "fail-open",
|
|
1068
|
-
retryable: false,
|
|
1069
|
-
summary: "A configured bound was reached and data was dropped."
|
|
1070
|
-
},
|
|
1071
|
-
"delivery-identifier-unavailable": {
|
|
1072
|
-
code: "delivery-identifier-unavailable",
|
|
1073
|
-
severity: "warning",
|
|
1074
|
-
// Fail-open: the observation is still attributed and exported. Only the
|
|
1075
|
-
// at-most-once guarantee is missing, and refusing the telemetry to protect
|
|
1076
|
-
// a duplicate count would trade a certain loss for a possible one.
|
|
1077
|
-
posture: "fail-open",
|
|
1078
|
-
retryable: false,
|
|
1079
|
-
summary: "No replay-stable delivery identifier was available; this callback was exported without deduplication."
|
|
1080
|
-
},
|
|
1081
|
-
"delivery-claim-superseded": {
|
|
1082
|
-
code: "delivery-claim-superseded",
|
|
1083
|
-
severity: "warning",
|
|
1084
|
-
// Fail-open, and specifically *not* silent. A peer reclaimed this callback's
|
|
1085
|
-
// claim while this process was still working on it, which means the
|
|
1086
|
-
// configured stale window is shorter than this installation's real worst
|
|
1087
|
-
// case. Both processes may now have exported the callback, so the
|
|
1088
|
-
// at-most-once guarantee did not hold for it — the only honest response is
|
|
1089
|
-
// to say so and let the operator raise the window.
|
|
1090
|
-
posture: "fail-open",
|
|
1091
|
-
retryable: false,
|
|
1092
|
-
summary: "A delivery claim was reclaimed by another process before this one committed; the callback may have been exported twice."
|
|
1093
|
-
},
|
|
1094
|
-
"internal-error": {
|
|
1095
|
-
code: "internal-error",
|
|
1096
|
-
severity: "error",
|
|
1097
|
-
posture: "fail-open",
|
|
1098
|
-
retryable: false,
|
|
1099
|
-
summary: "An unexpected failure was contained."
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
var describeErrorCode = (code) => ERROR_TAXONOMY[code];
|
|
1103
|
-
var attributionOutcomeSchema = z2.enum([
|
|
1104
|
-
/** Identity resolved; events carry provider and session identity. */
|
|
1105
|
-
"attributed",
|
|
1106
|
-
/** Identity could not be established safely; nothing was attributed. */
|
|
1107
|
-
"declined",
|
|
1108
|
-
/** Attribution was attempted and failed unexpectedly. */
|
|
1109
|
-
"failed",
|
|
1110
|
-
/** Input was recognized but intentionally carried no telemetry. */
|
|
1111
|
-
"not-applicable"
|
|
1112
|
-
]);
|
|
1113
|
-
var attributionReasonSchema = z2.enum([
|
|
1114
|
-
"provider-unknown",
|
|
1115
|
-
"provider-detection-ambiguous",
|
|
1116
|
-
"identity-conflict",
|
|
1117
|
-
"identity-incomplete",
|
|
1118
|
-
"adapter-ignored-input",
|
|
1119
|
-
"adapter-failure",
|
|
1120
|
-
"invalid-input",
|
|
1121
|
-
"internal-error"
|
|
1122
|
-
]);
|
|
1123
|
-
|
|
1124
|
-
// src/errors/index.ts
|
|
1125
|
-
var otelHookErrorInfoSchema = z3.strictObject({
|
|
1661
|
+
import { z as z10 } from "zod";
|
|
1662
|
+
var otelHookErrorInfoSchema = z10.strictObject({
|
|
1126
1663
|
code: otelHookErrorCodeSchema,
|
|
1127
1664
|
severity: errorSeveritySchema,
|
|
1128
1665
|
phase: errorPhaseSchema,
|
|
1129
1666
|
posture: failurePostureSchema,
|
|
1130
|
-
retryable:
|
|
1131
|
-
message:
|
|
1667
|
+
retryable: z10.boolean(),
|
|
1668
|
+
message: z10.string().min(1).max(512),
|
|
1132
1669
|
details: attributesSchema.optional(),
|
|
1133
1670
|
occurredAt: epochMillisSchema.optional()
|
|
1134
1671
|
});
|
|
@@ -1189,11 +1726,11 @@ var createHealthTracker = (subsystem, options = {}) => {
|
|
|
1189
1726
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
1190
1727
|
|
|
1191
1728
|
// src/config/resource-attributes.ts
|
|
1192
|
-
import { z as
|
|
1729
|
+
import { z as z12 } from "zod";
|
|
1193
1730
|
|
|
1194
1731
|
// src/privacy/policy.ts
|
|
1195
|
-
import { z as
|
|
1196
|
-
var contentModeSchema =
|
|
1732
|
+
import { z as z11 } from "zod";
|
|
1733
|
+
var contentModeSchema = z11.enum(["omit", "mask", "redact", "raw"]);
|
|
1197
1734
|
var CONTENT_MODE_DISCLOSURE = Object.freeze({
|
|
1198
1735
|
omit: "omitted",
|
|
1199
1736
|
mask: "masked",
|
|
@@ -1219,35 +1756,35 @@ var DEFAULT_SECRET_VALUE_PATTERNS = Object.freeze([
|
|
|
1219
1756
|
"eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}",
|
|
1220
1757
|
"(?:Bearer|Basic)\\s+[A-Za-z0-9._~+/=-]{12,}"
|
|
1221
1758
|
]);
|
|
1222
|
-
var privacyLimitsSchema =
|
|
1759
|
+
var privacyLimitsSchema = z11.strictObject({
|
|
1223
1760
|
/** Maximum characters of disclosed text per content fact or string value. */
|
|
1224
|
-
maxStringLength:
|
|
1761
|
+
maxStringLength: z11.number().int().min(0).max(65536),
|
|
1225
1762
|
/** Maximum nesting depth walked when sanitizing structured values. */
|
|
1226
|
-
maxDepth:
|
|
1763
|
+
maxDepth: z11.number().int().min(1).max(32),
|
|
1227
1764
|
/** Maximum array entries retained when sanitizing structured values. */
|
|
1228
|
-
maxArrayLength:
|
|
1765
|
+
maxArrayLength: z11.number().int().min(1).max(4096),
|
|
1229
1766
|
/** Maximum canonical events emitted per invocation. */
|
|
1230
|
-
maxEventsPerInvocation:
|
|
1767
|
+
maxEventsPerInvocation: z11.number().int().min(1).max(1e4),
|
|
1231
1768
|
/** Maximum object keys retained per level when sanitizing. */
|
|
1232
|
-
maxObjectKeys:
|
|
1769
|
+
maxObjectKeys: z11.number().int().min(1).max(1024)
|
|
1233
1770
|
});
|
|
1234
|
-
var privacyPolicySchema =
|
|
1771
|
+
var privacyPolicySchema = z11.strictObject({
|
|
1235
1772
|
contentMode: contentModeSchema,
|
|
1236
1773
|
/**
|
|
1237
1774
|
* `raw` mode is refused unless this is also true, so a single mistyped
|
|
1238
1775
|
* environment variable cannot start exporting prompts.
|
|
1239
1776
|
*/
|
|
1240
|
-
allowRawContent:
|
|
1777
|
+
allowRawContent: z11.boolean(),
|
|
1241
1778
|
/**
|
|
1242
1779
|
* Salt mixed into every hash. A per-deployment salt makes hashes
|
|
1243
1780
|
* non-correlatable across deployments; an empty salt makes them globally
|
|
1244
1781
|
* comparable. Both are legitimate; the choice is explicit.
|
|
1245
1782
|
*/
|
|
1246
|
-
hashSalt:
|
|
1247
|
-
maskCharacter:
|
|
1248
|
-
redactionPlaceholder:
|
|
1249
|
-
secretKeyPatterns:
|
|
1250
|
-
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(),
|
|
1251
1788
|
limits: privacyLimitsSchema
|
|
1252
1789
|
});
|
|
1253
1790
|
var DEFAULT_PRIVACY_LIMITS = Object.freeze({
|
|
@@ -1313,12 +1850,12 @@ var checkResourceAttributeKey = (key) => {
|
|
|
1313
1850
|
}
|
|
1314
1851
|
return void 0;
|
|
1315
1852
|
};
|
|
1316
|
-
var resourceAttributeValueSchema =
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1853
|
+
var resourceAttributeValueSchema = z12.union([
|
|
1854
|
+
z12.string().max(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH),
|
|
1855
|
+
z12.number().finite(),
|
|
1856
|
+
z12.boolean()
|
|
1320
1857
|
]);
|
|
1321
|
-
var resourceAttributesSchema =
|
|
1858
|
+
var resourceAttributesSchema = z12.record(z12.string(), resourceAttributeValueSchema).superRefine((value, ctx) => {
|
|
1322
1859
|
const keys = Object.keys(value);
|
|
1323
1860
|
if (keys.length > MAX_RESOURCE_ATTRIBUTES) {
|
|
1324
1861
|
ctx.addIssue({
|
|
@@ -1658,8 +2195,8 @@ var sliceCodePoints = (value, max) => {
|
|
|
1658
2195
|
}
|
|
1659
2196
|
return result;
|
|
1660
2197
|
};
|
|
1661
|
-
var logSignalOf = (
|
|
1662
|
-
switch (
|
|
2198
|
+
var logSignalOf = (event2, factKind) => {
|
|
2199
|
+
switch (event2.type) {
|
|
1663
2200
|
case "session.start":
|
|
1664
2201
|
case "session.end":
|
|
1665
2202
|
return "session";
|
|
@@ -1677,9 +2214,9 @@ var logSignalOf = (event, factKind) => {
|
|
|
1677
2214
|
case "error.raised":
|
|
1678
2215
|
return "error";
|
|
1679
2216
|
case "tool.start":
|
|
1680
|
-
return toolSignal(
|
|
2217
|
+
return toolSignal(event2.toolName, event2.toolKind);
|
|
1681
2218
|
case "tool.end":
|
|
1682
|
-
return toolSignal(
|
|
2219
|
+
return toolSignal(event2.toolName, void 0);
|
|
1683
2220
|
}
|
|
1684
2221
|
};
|
|
1685
2222
|
var toolSignal = (toolName, toolKind) => {
|
|
@@ -1738,16 +2275,16 @@ var logSignalsForLifecycleEvents = (lifecycleEvents) => {
|
|
|
1738
2275
|
}
|
|
1739
2276
|
return LOG_SIGNALS.filter((signal) => signals.has(signal));
|
|
1740
2277
|
};
|
|
1741
|
-
var severityFor = (
|
|
1742
|
-
switch (
|
|
2278
|
+
var severityFor = (event2) => {
|
|
2279
|
+
switch (event2.type) {
|
|
1743
2280
|
case "error.raised":
|
|
1744
|
-
return
|
|
2281
|
+
return event2.severity === "error" ? SeverityNumber.ERROR : SeverityNumber.WARN;
|
|
1745
2282
|
case "session.end":
|
|
1746
|
-
return
|
|
2283
|
+
return event2.reason === "error" || event2.reason === "timeout" ? SeverityNumber.ERROR : event2.reason === "aborted" ? SeverityNumber.WARN : SeverityNumber.INFO;
|
|
1747
2284
|
case "generation.end":
|
|
1748
2285
|
case "tool.end":
|
|
1749
2286
|
case "subagent.end":
|
|
1750
|
-
return
|
|
2287
|
+
return event2.outcome === "error" || event2.outcome === "timeout" ? SeverityNumber.ERROR : event2.outcome === "denied" || event2.outcome === "cancelled" ? SeverityNumber.WARN : SeverityNumber.INFO;
|
|
1751
2288
|
default:
|
|
1752
2289
|
return SeverityNumber.INFO;
|
|
1753
2290
|
}
|
|
@@ -1757,84 +2294,86 @@ var SEVERITY_TEXT = Object.freeze({
|
|
|
1757
2294
|
[SeverityNumber.WARN]: "WARN",
|
|
1758
2295
|
[SeverityNumber.ERROR]: "ERROR"
|
|
1759
2296
|
});
|
|
1760
|
-
var identityAttributes2 = (
|
|
1761
|
-
var eventAttributes = (
|
|
1762
|
-
switch (
|
|
2297
|
+
var identityAttributes2 = (event2, resource, ids) => exportIdentityAttributes(event2, resource, ids);
|
|
2298
|
+
var eventAttributes = (event2) => {
|
|
2299
|
+
switch (event2.type) {
|
|
1763
2300
|
case "session.start":
|
|
1764
2301
|
return {
|
|
1765
|
-
[ATTR_OTELHOOK_SESSION_KIND]:
|
|
1766
|
-
...
|
|
1767
|
-
...
|
|
1768
|
-
...
|
|
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)
|
|
1769
2307
|
};
|
|
1770
2308
|
case "session.end":
|
|
1771
2309
|
return {
|
|
1772
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1773
|
-
...usageAttributes2(
|
|
2310
|
+
[ATTR_OTELHOOK_OUTCOME2]: event2.reason,
|
|
2311
|
+
...usageAttributes2(event2.usage)
|
|
1774
2312
|
};
|
|
1775
2313
|
case "prompt.submitted":
|
|
1776
2314
|
return {
|
|
1777
|
-
[ATTR_OTELHOOK_PROMPT_SOURCE]:
|
|
1778
|
-
...
|
|
2315
|
+
[ATTR_OTELHOOK_PROMPT_SOURCE]: event2.promptSource,
|
|
2316
|
+
...event2.turnIndex === void 0 ? {} : { [ATTR_OTELHOOK_PROMPT_TURN_INDEX]: event2.turnIndex },
|
|
2317
|
+
...targetAttributes(event2)
|
|
1779
2318
|
};
|
|
1780
2319
|
case "generation.start":
|
|
1781
2320
|
return {
|
|
1782
2321
|
[ATTR_GEN_AI_OPERATION_NAME2]: "chat",
|
|
1783
|
-
[ATTR_OTELHOOK_GENERATION_ID2]:
|
|
1784
|
-
[ATTR_GEN_AI_REQUEST_MODEL2]:
|
|
1785
|
-
...
|
|
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 }
|
|
1786
2325
|
};
|
|
1787
2326
|
case "generation.end":
|
|
1788
2327
|
return {
|
|
1789
2328
|
[ATTR_GEN_AI_OPERATION_NAME2]: "chat",
|
|
1790
|
-
[ATTR_OTELHOOK_GENERATION_ID2]:
|
|
1791
|
-
[ATTR_GEN_AI_RESPONSE_MODEL2]:
|
|
1792
|
-
...
|
|
1793
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1794
|
-
...
|
|
1795
|
-
...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)
|
|
1796
2335
|
};
|
|
1797
2336
|
case "tool.start":
|
|
1798
2337
|
return {
|
|
1799
|
-
[ATTR_GEN_AI_TOOL_NAME2]:
|
|
1800
|
-
[ATTR_GEN_AI_TOOL_CALL_ID2]:
|
|
1801
|
-
[ATTR_OTELHOOK_TOOL_KIND2]:
|
|
1802
|
-
...
|
|
1803
|
-
...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)
|
|
1804
2343
|
};
|
|
1805
2344
|
case "tool.end":
|
|
1806
2345
|
return {
|
|
1807
|
-
[ATTR_GEN_AI_TOOL_NAME2]:
|
|
1808
|
-
[ATTR_GEN_AI_TOOL_CALL_ID2]:
|
|
1809
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1810
|
-
...
|
|
1811
|
-
...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)
|
|
1812
2351
|
};
|
|
1813
2352
|
case "subagent.start":
|
|
1814
2353
|
return {
|
|
1815
|
-
[ATTR_OTELHOOK_DELEGATION_DEPTH2]:
|
|
1816
|
-
...
|
|
1817
|
-
...
|
|
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 }
|
|
1818
2357
|
};
|
|
1819
2358
|
case "subagent.end":
|
|
1820
2359
|
return {
|
|
1821
|
-
[ATTR_OTELHOOK_OUTCOME2]:
|
|
1822
|
-
...usageAttributes2(
|
|
2360
|
+
[ATTR_OTELHOOK_OUTCOME2]: event2.outcome,
|
|
2361
|
+
...usageAttributes2(event2.usage)
|
|
1823
2362
|
};
|
|
1824
2363
|
case "compaction.performed":
|
|
1825
2364
|
return {
|
|
1826
|
-
[ATTR_OTELHOOK_COMPACTION_TRIGGER2]:
|
|
1827
|
-
...
|
|
1828
|
-
...
|
|
1829
|
-
...
|
|
1830
|
-
...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)
|
|
1831
2370
|
};
|
|
1832
2371
|
case "error.raised":
|
|
1833
2372
|
return {
|
|
1834
|
-
[ATTR_ERROR_TYPE2]:
|
|
1835
|
-
[ATTR_OTELHOOK_ERROR_PHASE]:
|
|
1836
|
-
[ATTR_OTELHOOK_ERROR_RETRYABLE]:
|
|
1837
|
-
[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
|
|
1838
2377
|
};
|
|
1839
2378
|
}
|
|
1840
2379
|
};
|
|
@@ -1845,20 +2384,20 @@ var usageAttributes2 = (usage) => usage === void 0 ? {} : {
|
|
|
1845
2384
|
[ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS2]: usage.cacheCreationInputTokens,
|
|
1846
2385
|
...usageTemporalityAttributes(usage)
|
|
1847
2386
|
};
|
|
1848
|
-
var contentFactsOf = (
|
|
1849
|
-
switch (
|
|
2387
|
+
var contentFactsOf = (event2) => {
|
|
2388
|
+
switch (event2.type) {
|
|
1850
2389
|
case "prompt.submitted":
|
|
1851
|
-
return
|
|
2390
|
+
return event2.content === void 0 ? [] : [event2.content];
|
|
1852
2391
|
case "generation.start":
|
|
1853
|
-
return
|
|
2392
|
+
return event2.inputContent ?? [];
|
|
1854
2393
|
case "generation.end":
|
|
1855
|
-
return
|
|
2394
|
+
return event2.outputContent ?? [];
|
|
1856
2395
|
case "tool.start":
|
|
1857
|
-
return
|
|
2396
|
+
return event2.input === void 0 ? [] : [event2.input];
|
|
1858
2397
|
case "tool.end":
|
|
1859
|
-
return
|
|
2398
|
+
return event2.output === void 0 ? [] : [event2.output];
|
|
1860
2399
|
case "error.raised":
|
|
1861
|
-
return
|
|
2400
|
+
return event2.message === void 0 ? [] : [event2.message];
|
|
1862
2401
|
default:
|
|
1863
2402
|
return [];
|
|
1864
2403
|
}
|
|
@@ -1933,8 +2472,8 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1933
2472
|
});
|
|
1934
2473
|
const records = [];
|
|
1935
2474
|
let droppedFacts = 0;
|
|
1936
|
-
for (const
|
|
1937
|
-
const identity = identities.get(
|
|
2475
|
+
for (const event2 of events) {
|
|
2476
|
+
const identity = identities.get(event2.eventId);
|
|
1938
2477
|
if (identity === void 0) {
|
|
1939
2478
|
continue;
|
|
1940
2479
|
}
|
|
@@ -1944,8 +2483,8 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1944
2483
|
traceFlags: TraceFlags2.SAMPLED,
|
|
1945
2484
|
isRemote: false
|
|
1946
2485
|
};
|
|
1947
|
-
const shared = eventAttributes(
|
|
1948
|
-
const facts = contentFactsOf(
|
|
2486
|
+
const shared = eventAttributes(event2);
|
|
2487
|
+
const facts = contentFactsOf(event2);
|
|
1949
2488
|
if (facts.length === 0) {
|
|
1950
2489
|
if (records.length >= MAX_LOG_RECORDS_PER_BATCH) {
|
|
1951
2490
|
droppedFacts += 1;
|
|
@@ -1953,9 +2492,9 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1953
2492
|
}
|
|
1954
2493
|
records.push(
|
|
1955
2494
|
buildRecord({
|
|
1956
|
-
event,
|
|
1957
|
-
signal: logSignalOf(
|
|
1958
|
-
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,
|
|
1959
2498
|
spanContext,
|
|
1960
2499
|
...identity.parentSpanId === void 0 ? {} : { parentSpanId: identity.parentSpanId },
|
|
1961
2500
|
resource: options.resource,
|
|
@@ -1974,8 +2513,8 @@ var canonicalEventsToLogRecords = (events, options) => {
|
|
|
1974
2513
|
const body = discloseBody(fact, content);
|
|
1975
2514
|
records.push(
|
|
1976
2515
|
buildRecord({
|
|
1977
|
-
event,
|
|
1978
|
-
signal: logSignalOf(
|
|
2516
|
+
event: event2,
|
|
2517
|
+
signal: logSignalOf(event2, fact.kind),
|
|
1979
2518
|
attributes: { ...shared, ...contentAttributes(fact, body) },
|
|
1980
2519
|
..."text" in body ? { body: body.text } : {},
|
|
1981
2520
|
spanContext,
|