@osfactory/otel-hook 0.1.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/LICENSE +21 -0
- package/README.md +1020 -0
- package/dist/adapter-DIgRACtL.d.ts +303 -0
- package/dist/cli.js +12607 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +233 -0
- package/dist/config.js +996 -0
- package/dist/config.js.map +1 -0
- package/dist/content-CoB7aNP1.d.ts +118 -0
- package/dist/diagnostics.d.ts +58 -0
- package/dist/diagnostics.js +46 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/errors.d.ts +91 -0
- package/dist/errors.js +322 -0
- package/dist/errors.js.map +1 -0
- package/dist/events-VxBnDFaO.d.ts +2044 -0
- package/dist/filesystem-store-J8jjDMTh.d.ts +65 -0
- package/dist/hook-CGpo-vks.d.ts +292 -0
- package/dist/identity-BrVBs901.d.ts +227 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +11798 -0
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +1021 -0
- package/dist/install.js +3271 -0
- package/dist/install.js.map +1 -0
- package/dist/integration.d.ts +303 -0
- package/dist/integration.js +5942 -0
- package/dist/integration.js.map +1 -0
- package/dist/keys-Dej5bN3L.d.ts +7 -0
- package/dist/lifecycle.d.ts +428 -0
- package/dist/lifecycle.js +1077 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/memory-DXVBc8V9.d.ts +94 -0
- package/dist/model.d.ts +45 -0
- package/dist/model.js +1023 -0
- package/dist/model.js.map +1 -0
- package/dist/otlp-log-sink-CeIFDDpn.d.ts +457 -0
- package/dist/payload-CHr53E_v.d.ts +201 -0
- package/dist/policy-D1CrlYn3.d.ts +73 -0
- package/dist/ports-Q8x0ODhs.d.ts +200 -0
- package/dist/primitives-CJ8-rn-f.d.ts +75 -0
- package/dist/privacy.d.ts +51 -0
- package/dist/privacy.js +633 -0
- package/dist/privacy.js.map +1 -0
- package/dist/providers.d.ts +257 -0
- package/dist/providers.js +4398 -0
- package/dist/providers.js.map +1 -0
- package/dist/registry-BzYmC9OC.d.ts +49 -0
- package/dist/runtime.d.ts +32 -0
- package/dist/runtime.js +2907 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema-Cn0-xz8L.d.ts +224 -0
- package/dist/semconv-Baoz-0OI.d.ts +188 -0
- package/dist/service-j4jEO6cZ.d.ts +68 -0
- package/dist/state.d.ts +36 -0
- package/dist/state.js +710 -0
- package/dist/state.js.map +1 -0
- package/dist/taxonomy-DwhTtuWd.d.ts +87 -0
- package/dist/telemetry.d.ts +77 -0
- package/dist/telemetry.js +2294 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/testing.d.ts +155 -0
- package/dist/testing.js +6513 -0
- package/dist/testing.js.map +1 -0
- package/package.json +124 -0
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,2907 @@
|
|
|
1
|
+
// src/runtime/ports.ts
|
|
2
|
+
import { z as z3 } from "zod";
|
|
3
|
+
|
|
4
|
+
// src/model/primitives.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var MAX_IDENTIFIER_LENGTH = 256;
|
|
7
|
+
var MAX_ATTRIBUTE_STRING_LENGTH = 4096;
|
|
8
|
+
var MAX_ATTRIBUTE_ARRAY_LENGTH = 128;
|
|
9
|
+
var nonEmptyStringSchema = z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
10
|
+
var epochMillisSchema = z.number().int().min(0).max(864e13);
|
|
11
|
+
var durationMillisSchema = z.number().min(0).finite();
|
|
12
|
+
var tokenCountSchema = z.number().int().min(0);
|
|
13
|
+
var sequenceNumberSchema = z.number().int().min(0);
|
|
14
|
+
var brandedIdSchema = () => z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
15
|
+
var invocationIdSchema = brandedIdSchema().brand();
|
|
16
|
+
var sessionIdSchema = brandedIdSchema().brand();
|
|
17
|
+
var eventIdSchema = brandedIdSchema().brand();
|
|
18
|
+
var WORKSPACE_ID_PATTERN = /^[a-z][a-z0-9]{0,15}:[A-Za-z0-9_-]{8,128}$/;
|
|
19
|
+
var workspaceIdSchema = z.string().regex(WORKSPACE_ID_PATTERN, "workspace id must be an opaque `<scheme>:<token>` handle").brand();
|
|
20
|
+
var PROVIDER_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
21
|
+
var providerIdSchema = z.string().min(1).max(64).regex(PROVIDER_ID_PATTERN, "provider id must be lowercase and hyphenated").brand();
|
|
22
|
+
var UNKNOWN_PROVIDER_ID = "unknown";
|
|
23
|
+
var resolvedProviderIdSchema = z.union([
|
|
24
|
+
providerIdSchema,
|
|
25
|
+
z.literal(UNKNOWN_PROVIDER_ID)
|
|
26
|
+
]);
|
|
27
|
+
var attributePrimitiveSchema = z.union([
|
|
28
|
+
z.string().max(MAX_ATTRIBUTE_STRING_LENGTH),
|
|
29
|
+
z.number().finite(),
|
|
30
|
+
z.boolean()
|
|
31
|
+
]);
|
|
32
|
+
var attributeValueSchema = z.union([
|
|
33
|
+
attributePrimitiveSchema,
|
|
34
|
+
z.array(attributePrimitiveSchema).max(MAX_ATTRIBUTE_ARRAY_LENGTH)
|
|
35
|
+
]);
|
|
36
|
+
var attributesSchema = z.record(z.string().min(1).max(MAX_IDENTIFIER_LENGTH), attributeValueSchema);
|
|
37
|
+
var detectionConfidenceSchema = z.enum(["none", "weak", "strong", "exact"]);
|
|
38
|
+
var DETECTION_CONFIDENCE_RANK = Object.freeze({
|
|
39
|
+
none: 0,
|
|
40
|
+
weak: 1,
|
|
41
|
+
strong: 2,
|
|
42
|
+
exact: 3
|
|
43
|
+
});
|
|
44
|
+
var sourceTransportSchema = z.enum([
|
|
45
|
+
"hook-stdin",
|
|
46
|
+
"cli-argument",
|
|
47
|
+
"library-call",
|
|
48
|
+
"test-fixture"
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
// src/model/usage.ts
|
|
52
|
+
import { z as z2 } from "zod";
|
|
53
|
+
var usageTemporalitySchema = z2.enum(["delta", "cumulative"]);
|
|
54
|
+
var cacheCreationAccountingSchema = z2.enum([
|
|
55
|
+
"included-in-input",
|
|
56
|
+
"disjoint-from-input",
|
|
57
|
+
"not-reported"
|
|
58
|
+
]);
|
|
59
|
+
var providerTotalAgreementSchema = z2.enum(["unreported", "agrees", "disagrees"]);
|
|
60
|
+
var usageReportSchema = z2.strictObject({
|
|
61
|
+
temporality: usageTemporalitySchema,
|
|
62
|
+
/** Inclusive input tokens. */
|
|
63
|
+
inputTokens: tokenCountSchema.optional(),
|
|
64
|
+
/** Subset of `inputTokens` served from a prompt cache. */
|
|
65
|
+
cachedInputTokens: tokenCountSchema.optional(),
|
|
66
|
+
/** Tokens written to a prompt cache. */
|
|
67
|
+
cacheCreationInputTokens: tokenCountSchema.optional(),
|
|
68
|
+
/** Required when `cacheCreationInputTokens` is present and non-zero. */
|
|
69
|
+
cacheCreationAccounting: cacheCreationAccountingSchema.optional(),
|
|
70
|
+
/** Inclusive output tokens. */
|
|
71
|
+
outputTokens: tokenCountSchema.optional(),
|
|
72
|
+
/** Subset of `outputTokens` spent on reasoning. */
|
|
73
|
+
reasoningOutputTokens: tokenCountSchema.optional(),
|
|
74
|
+
/** Total exactly as the provider reported it, if it reported one. */
|
|
75
|
+
providerTotalTokens: tokenCountSchema.optional()
|
|
76
|
+
});
|
|
77
|
+
var canonicalUsageSchema = z2.strictObject({
|
|
78
|
+
temporality: usageTemporalitySchema,
|
|
79
|
+
inputTokens: tokenCountSchema,
|
|
80
|
+
cachedInputTokens: tokenCountSchema,
|
|
81
|
+
cacheCreationInputTokens: tokenCountSchema,
|
|
82
|
+
cacheCreationAccounting: cacheCreationAccountingSchema,
|
|
83
|
+
outputTokens: tokenCountSchema,
|
|
84
|
+
reasoningOutputTokens: tokenCountSchema,
|
|
85
|
+
/** Derived: input tokens that were neither cache reads nor cache writes. */
|
|
86
|
+
uncachedInputTokens: tokenCountSchema,
|
|
87
|
+
/** Derived: canonical billable total. */
|
|
88
|
+
totalTokens: tokenCountSchema,
|
|
89
|
+
providerTotalTokens: tokenCountSchema.optional(),
|
|
90
|
+
providerTotalAgreement: providerTotalAgreementSchema
|
|
91
|
+
}).check((ctx) => {
|
|
92
|
+
const usage = ctx.value;
|
|
93
|
+
const push = (message) => {
|
|
94
|
+
ctx.issues.push({ code: "custom", input: usage, message });
|
|
95
|
+
};
|
|
96
|
+
if (usage.cachedInputTokens > usage.inputTokens) {
|
|
97
|
+
push("cachedInputTokens must not exceed inputTokens (it is a subset)");
|
|
98
|
+
}
|
|
99
|
+
if (usage.reasoningOutputTokens > usage.outputTokens) {
|
|
100
|
+
push("reasoningOutputTokens must not exceed outputTokens (it is a subset)");
|
|
101
|
+
}
|
|
102
|
+
if (usage.cacheCreationAccounting === "not-reported" && usage.cacheCreationInputTokens !== 0) {
|
|
103
|
+
push("cacheCreationInputTokens must be 0 when cacheCreationAccounting is not-reported");
|
|
104
|
+
}
|
|
105
|
+
const creationInsideInput = usage.cacheCreationAccounting === "included-in-input" ? usage.cacheCreationInputTokens : 0;
|
|
106
|
+
if (usage.cachedInputTokens + creationInsideInput > usage.inputTokens) {
|
|
107
|
+
push(
|
|
108
|
+
"cachedInputTokens + cacheCreationInputTokens must not exceed inputTokens when cache creation is included in input"
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
const expectedUncached = usage.inputTokens - usage.cachedInputTokens - creationInsideInput;
|
|
112
|
+
if (expectedUncached >= 0 && usage.uncachedInputTokens !== expectedUncached) {
|
|
113
|
+
push(`uncachedInputTokens must equal ${expectedUncached}`);
|
|
114
|
+
}
|
|
115
|
+
const creationOutsideInput = usage.cacheCreationAccounting === "disjoint-from-input" ? usage.cacheCreationInputTokens : 0;
|
|
116
|
+
const expectedTotal = usage.inputTokens + creationOutsideInput + usage.outputTokens;
|
|
117
|
+
if (usage.totalTokens !== expectedTotal) {
|
|
118
|
+
push(`totalTokens must equal ${expectedTotal}`);
|
|
119
|
+
}
|
|
120
|
+
const expectedAgreement = usage.providerTotalTokens === void 0 ? "unreported" : usage.providerTotalTokens === expectedTotal ? "agrees" : "disagrees";
|
|
121
|
+
if (usage.providerTotalAgreement !== expectedAgreement) {
|
|
122
|
+
push(`providerTotalAgreement must be ${expectedAgreement}`);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
var normalizeUsage = (report) => {
|
|
126
|
+
const parsed = usageReportSchema.safeParse(report);
|
|
127
|
+
if (!parsed.success) {
|
|
128
|
+
return {
|
|
129
|
+
status: "invalid",
|
|
130
|
+
issues: parsed.error.issues.map((issue) => ({
|
|
131
|
+
code: "invalid-report",
|
|
132
|
+
message: `${issue.path.join(".") || "<root>"}: ${issue.message}`
|
|
133
|
+
}))
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const input = parsed.data;
|
|
137
|
+
const issues = [];
|
|
138
|
+
const notes = [];
|
|
139
|
+
const inputTokens = input.inputTokens ?? 0;
|
|
140
|
+
const cachedInputTokens = input.cachedInputTokens ?? 0;
|
|
141
|
+
const cacheCreationInputTokens = input.cacheCreationInputTokens ?? 0;
|
|
142
|
+
const outputTokens = input.outputTokens ?? 0;
|
|
143
|
+
const reasoningOutputTokens = input.reasoningOutputTokens ?? 0;
|
|
144
|
+
let accounting;
|
|
145
|
+
if (cacheCreationInputTokens === 0) {
|
|
146
|
+
accounting = input.cacheCreationAccounting ?? "not-reported";
|
|
147
|
+
if (accounting !== "not-reported") {
|
|
148
|
+
notes.push(
|
|
149
|
+
`cacheCreationAccounting=${accounting} retained with zero cache-creation tokens`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
} else if (input.cacheCreationAccounting === void 0) {
|
|
153
|
+
issues.push({
|
|
154
|
+
code: "cache-creation-accounting-missing",
|
|
155
|
+
message: "cacheCreationAccounting is required when cacheCreationInputTokens is non-zero; it cannot be inferred"
|
|
156
|
+
});
|
|
157
|
+
accounting = "not-reported";
|
|
158
|
+
} else if (input.cacheCreationAccounting === "not-reported") {
|
|
159
|
+
issues.push({
|
|
160
|
+
code: "cache-creation-accounting-missing",
|
|
161
|
+
message: "cacheCreationAccounting=not-reported conflicts with non-zero cacheCreationInputTokens"
|
|
162
|
+
});
|
|
163
|
+
accounting = "not-reported";
|
|
164
|
+
} else {
|
|
165
|
+
accounting = input.cacheCreationAccounting;
|
|
166
|
+
}
|
|
167
|
+
if (cachedInputTokens > inputTokens) {
|
|
168
|
+
issues.push({
|
|
169
|
+
code: "cached-exceeds-input",
|
|
170
|
+
message: `cachedInputTokens (${cachedInputTokens}) exceeds inclusive inputTokens (${inputTokens})`
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (reasoningOutputTokens > outputTokens) {
|
|
174
|
+
issues.push({
|
|
175
|
+
code: "reasoning-exceeds-output",
|
|
176
|
+
message: `reasoningOutputTokens (${reasoningOutputTokens}) exceeds inclusive outputTokens (${outputTokens})`
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const creationInsideInput = accounting === "included-in-input" ? cacheCreationInputTokens : 0;
|
|
180
|
+
if (cachedInputTokens + creationInsideInput > inputTokens) {
|
|
181
|
+
issues.push({
|
|
182
|
+
code: "cache-creation-exceeds-input",
|
|
183
|
+
message: `cachedInputTokens + cacheCreationInputTokens (${cachedInputTokens + creationInsideInput}) exceeds inclusive inputTokens (${inputTokens})`
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (issues.length > 0) {
|
|
187
|
+
return { status: "invalid", issues };
|
|
188
|
+
}
|
|
189
|
+
const creationOutsideInput = accounting === "disjoint-from-input" ? cacheCreationInputTokens : 0;
|
|
190
|
+
const totalTokens = inputTokens + creationOutsideInput + outputTokens;
|
|
191
|
+
const providerTotalAgreement = input.providerTotalTokens === void 0 ? "unreported" : input.providerTotalTokens === totalTokens ? "agrees" : "disagrees";
|
|
192
|
+
if (providerTotalAgreement === "disagrees") {
|
|
193
|
+
notes.push(
|
|
194
|
+
`providerTotalTokens (${input.providerTotalTokens ?? 0}) disagrees with canonical total (${totalTokens}); both retained`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const usage = {
|
|
198
|
+
temporality: input.temporality,
|
|
199
|
+
inputTokens,
|
|
200
|
+
cachedInputTokens,
|
|
201
|
+
cacheCreationInputTokens,
|
|
202
|
+
cacheCreationAccounting: accounting,
|
|
203
|
+
outputTokens,
|
|
204
|
+
reasoningOutputTokens,
|
|
205
|
+
uncachedInputTokens: inputTokens - cachedInputTokens - creationInsideInput,
|
|
206
|
+
totalTokens,
|
|
207
|
+
...input.providerTotalTokens === void 0 ? {} : { providerTotalTokens: input.providerTotalTokens },
|
|
208
|
+
providerTotalAgreement
|
|
209
|
+
};
|
|
210
|
+
return { status: "ok", usage, notes };
|
|
211
|
+
};
|
|
212
|
+
var UsageNormalizationError = class extends Error {
|
|
213
|
+
issues;
|
|
214
|
+
constructor(issues) {
|
|
215
|
+
super(`invalid usage report: ${issues.map((issue) => issue.message).join("; ")}`);
|
|
216
|
+
this.name = "UsageNormalizationError";
|
|
217
|
+
this.issues = issues;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var normalizeUsageOrThrow = (report) => {
|
|
221
|
+
const result = normalizeUsage(report);
|
|
222
|
+
if (result.status === "invalid") {
|
|
223
|
+
throw new UsageNormalizationError(result.issues);
|
|
224
|
+
}
|
|
225
|
+
return result.usage;
|
|
226
|
+
};
|
|
227
|
+
var EMPTY_DELTA_USAGE = Object.freeze(
|
|
228
|
+
normalizeUsageOrThrow({ temporality: "delta" })
|
|
229
|
+
);
|
|
230
|
+
var requireCumulative = (usage, label) => {
|
|
231
|
+
if (usage.temporality !== "cumulative") {
|
|
232
|
+
throw new UsageNormalizationError([
|
|
233
|
+
{ code: "invalid-report", message: `${label} must have cumulative temporality` }
|
|
234
|
+
]);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var cumulativeToDelta = (previous, current) => {
|
|
238
|
+
requireCumulative(previous, "previous usage");
|
|
239
|
+
requireCumulative(current, "current usage");
|
|
240
|
+
if (previous.cacheCreationAccounting !== current.cacheCreationAccounting && previous.cacheCreationInputTokens !== 0 && current.cacheCreationInputTokens !== 0) {
|
|
241
|
+
throw new UsageNormalizationError([
|
|
242
|
+
{
|
|
243
|
+
code: "cache-creation-accounting-missing",
|
|
244
|
+
message: "cannot diff cumulative usage across differing cacheCreationAccounting modes"
|
|
245
|
+
}
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
const resetDetected = current.inputTokens < previous.inputTokens || current.cachedInputTokens < previous.cachedInputTokens || current.cacheCreationInputTokens < previous.cacheCreationInputTokens || current.outputTokens < previous.outputTokens || current.reasoningOutputTokens < previous.reasoningOutputTokens;
|
|
249
|
+
if (resetDetected) {
|
|
250
|
+
return {
|
|
251
|
+
usage: normalizeUsageOrThrow({ ...toReport(current), temporality: "delta" }),
|
|
252
|
+
resetDetected: true
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const usage = normalizeUsageOrThrow({
|
|
256
|
+
temporality: "delta",
|
|
257
|
+
inputTokens: current.inputTokens - previous.inputTokens,
|
|
258
|
+
cachedInputTokens: current.cachedInputTokens - previous.cachedInputTokens,
|
|
259
|
+
cacheCreationInputTokens: current.cacheCreationInputTokens - previous.cacheCreationInputTokens,
|
|
260
|
+
cacheCreationAccounting: current.cacheCreationAccounting,
|
|
261
|
+
outputTokens: current.outputTokens - previous.outputTokens,
|
|
262
|
+
reasoningOutputTokens: current.reasoningOutputTokens - previous.reasoningOutputTokens
|
|
263
|
+
});
|
|
264
|
+
return { usage, resetDetected: false };
|
|
265
|
+
};
|
|
266
|
+
var toReport = (usage) => ({
|
|
267
|
+
temporality: usage.temporality,
|
|
268
|
+
inputTokens: usage.inputTokens,
|
|
269
|
+
cachedInputTokens: usage.cachedInputTokens,
|
|
270
|
+
cacheCreationInputTokens: usage.cacheCreationInputTokens,
|
|
271
|
+
cacheCreationAccounting: usage.cacheCreationAccounting,
|
|
272
|
+
outputTokens: usage.outputTokens,
|
|
273
|
+
reasoningOutputTokens: usage.reasoningOutputTokens,
|
|
274
|
+
...usage.providerTotalTokens === void 0 ? {} : { providerTotalTokens: usage.providerTotalTokens }
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// src/runtime/ports.ts
|
|
278
|
+
var appliedDeliverySchema = z3.strictObject({
|
|
279
|
+
callbackId: z3.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
|
|
280
|
+
/** How many of that delivery's observations are folded in, counted from one. */
|
|
281
|
+
applications: z3.number().int().min(1).max(4096)
|
|
282
|
+
});
|
|
283
|
+
var stateValueSchema = z3.discriminatedUnion("kind", [
|
|
284
|
+
z3.strictObject({
|
|
285
|
+
kind: z3.literal("usage-cumulative"),
|
|
286
|
+
usage: canonicalUsageSchema,
|
|
287
|
+
/**
|
|
288
|
+
* Optional: absent on every record written before this field existed, which
|
|
289
|
+
* reads as "unknown provenance" and simply forgoes the idempotency check
|
|
290
|
+
* rather than resetting a baseline to gain it.
|
|
291
|
+
*/
|
|
292
|
+
appliedDelivery: appliedDeliverySchema.optional()
|
|
293
|
+
}),
|
|
294
|
+
z3.strictObject({
|
|
295
|
+
kind: z3.literal("sequence"),
|
|
296
|
+
next: sequenceNumberSchema
|
|
297
|
+
}),
|
|
298
|
+
z3.strictObject({
|
|
299
|
+
kind: z3.literal("attributes"),
|
|
300
|
+
attributes: attributesSchema
|
|
301
|
+
})
|
|
302
|
+
]);
|
|
303
|
+
var stateRecordSchema = z3.strictObject({
|
|
304
|
+
/** Incremented on each write; lets callers detect lost updates. */
|
|
305
|
+
revision: z3.number().int().min(0),
|
|
306
|
+
updatedAt: epochMillisSchema,
|
|
307
|
+
value: stateValueSchema
|
|
308
|
+
});
|
|
309
|
+
var logLevelSchema = z3.enum(["silent", "error", "warn", "info", "debug"]);
|
|
310
|
+
var LOG_LEVEL_RANK = Object.freeze({
|
|
311
|
+
silent: 0,
|
|
312
|
+
error: 1,
|
|
313
|
+
warn: 2,
|
|
314
|
+
info: 3,
|
|
315
|
+
debug: 4
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// src/runtime/clock.ts
|
|
319
|
+
var createSystemClock = () => ({
|
|
320
|
+
now: () => epochMillisSchema.parse(Date.now()),
|
|
321
|
+
monotonicMillis: () => Number(process.hrtime.bigint() / 1000000n)
|
|
322
|
+
});
|
|
323
|
+
var createFixedClock = (options = {}) => {
|
|
324
|
+
let wall = options.startMillis ?? 17e11;
|
|
325
|
+
let monotonic = 0;
|
|
326
|
+
const tick = options.tickMillis ?? 0;
|
|
327
|
+
return {
|
|
328
|
+
now: () => {
|
|
329
|
+
const current = wall;
|
|
330
|
+
wall += tick;
|
|
331
|
+
monotonic += tick;
|
|
332
|
+
return epochMillisSchema.parse(current);
|
|
333
|
+
},
|
|
334
|
+
monotonicMillis: () => monotonic,
|
|
335
|
+
advance: (millis) => {
|
|
336
|
+
wall += millis;
|
|
337
|
+
monotonic += millis;
|
|
338
|
+
},
|
|
339
|
+
set: (millis) => {
|
|
340
|
+
wall = millis;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/runtime/ids.ts
|
|
346
|
+
import { createHash, randomUUID } from "crypto";
|
|
347
|
+
var digest = (namespace, parts) => {
|
|
348
|
+
const hash = createHash("sha256");
|
|
349
|
+
hash.update(namespace);
|
|
350
|
+
for (const part of parts) {
|
|
351
|
+
hash.update("\0");
|
|
352
|
+
hash.update(part === void 0 ? "" : String(part));
|
|
353
|
+
}
|
|
354
|
+
return hash.digest("hex");
|
|
355
|
+
};
|
|
356
|
+
var createDeterministicIdGenerator = (options = {}) => {
|
|
357
|
+
const namespace = options.namespace ?? "otel-hook";
|
|
358
|
+
const length = Math.min(Math.max(options.length ?? 32, 16), 64);
|
|
359
|
+
const truncate = (hex) => hex.slice(0, length);
|
|
360
|
+
return {
|
|
361
|
+
newInvocationId: (seed) => invocationIdSchema.parse(
|
|
362
|
+
`inv_${truncate(
|
|
363
|
+
digest(`${namespace}/invocation`, [
|
|
364
|
+
seed.providerId,
|
|
365
|
+
seed.sessionId,
|
|
366
|
+
seed.sourceEventName,
|
|
367
|
+
seed.occurredAt,
|
|
368
|
+
seed.discriminator
|
|
369
|
+
])
|
|
370
|
+
)}`
|
|
371
|
+
),
|
|
372
|
+
newEventId: (seed) => eventIdSchema.parse(
|
|
373
|
+
`evt_${truncate(
|
|
374
|
+
digest(`${namespace}/event`, [
|
|
375
|
+
seed.invocationId,
|
|
376
|
+
seed.sequence,
|
|
377
|
+
seed.eventType,
|
|
378
|
+
seed.discriminator
|
|
379
|
+
])
|
|
380
|
+
)}`
|
|
381
|
+
),
|
|
382
|
+
newOpaqueId: (parts) => truncate(digest(`${namespace}/opaque`, parts))
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
var createRandomIdGenerator = () => ({
|
|
386
|
+
newInvocationId: () => invocationIdSchema.parse(`inv_${randomUUID()}`),
|
|
387
|
+
newEventId: () => eventIdSchema.parse(`evt_${randomUUID()}`),
|
|
388
|
+
newOpaqueId: () => randomUUID().replace(/-/g, "")
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// src/runtime/logger.ts
|
|
392
|
+
var createNullLogger = () => ({
|
|
393
|
+
error: () => void 0,
|
|
394
|
+
warn: () => void 0,
|
|
395
|
+
info: () => void 0,
|
|
396
|
+
debug: () => void 0
|
|
397
|
+
});
|
|
398
|
+
var createStderrLogger = (options = {}) => {
|
|
399
|
+
const level = options.level ?? "warn";
|
|
400
|
+
const write = options.write ?? ((line) => {
|
|
401
|
+
process.stderr.write(line);
|
|
402
|
+
});
|
|
403
|
+
const threshold = LOG_LEVEL_RANK[level];
|
|
404
|
+
const log = (entryLevel, message, fields) => {
|
|
405
|
+
if (LOG_LEVEL_RANK[entryLevel] > threshold || threshold === 0) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const payload = fields === void 0 || Object.keys(fields).length === 0 ? { level: entryLevel, message } : { level: entryLevel, message, fields };
|
|
409
|
+
write(`${JSON.stringify(payload)}
|
|
410
|
+
`);
|
|
411
|
+
};
|
|
412
|
+
return {
|
|
413
|
+
error: (message, fields) => {
|
|
414
|
+
log("error", message, fields);
|
|
415
|
+
},
|
|
416
|
+
warn: (message, fields) => {
|
|
417
|
+
log("warn", message, fields);
|
|
418
|
+
},
|
|
419
|
+
info: (message, fields) => {
|
|
420
|
+
log("info", message, fields);
|
|
421
|
+
},
|
|
422
|
+
debug: (message, fields) => {
|
|
423
|
+
log("debug", message, fields);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// src/errors/index.ts
|
|
429
|
+
import { z as z5 } from "zod";
|
|
430
|
+
|
|
431
|
+
// src/errors/taxonomy.ts
|
|
432
|
+
import { z as z4 } from "zod";
|
|
433
|
+
var otelHookErrorCodeSchema = z4.enum([
|
|
434
|
+
/** Input was not usable at all (empty stdin, unparsable JSON). */
|
|
435
|
+
"invalid-input",
|
|
436
|
+
/** Input parsed but failed canonical schema validation. */
|
|
437
|
+
"schema-validation-failed",
|
|
438
|
+
/** No adapter claimed the input with sufficient confidence. */
|
|
439
|
+
"provider-unknown",
|
|
440
|
+
/** Several adapters claimed the input at the same confidence. */
|
|
441
|
+
"provider-detection-ambiguous",
|
|
442
|
+
/** An adapter threw or returned a malformed result. */
|
|
443
|
+
"provider-adapter-failure",
|
|
444
|
+
/** Two identity claims disagreed at equal confidence. */
|
|
445
|
+
"identity-conflict",
|
|
446
|
+
/** Required identity fields were absent. */
|
|
447
|
+
"identity-incomplete",
|
|
448
|
+
/** A usage report violated the canonical usage invariants. */
|
|
449
|
+
"usage-invalid",
|
|
450
|
+
/** The state store could not be read or written. */
|
|
451
|
+
"state-store-failure",
|
|
452
|
+
/** The telemetry sink rejected or could not deliver a batch. */
|
|
453
|
+
"telemetry-export-failure",
|
|
454
|
+
/** Content reached the sink boundary in a state the policy forbids. */
|
|
455
|
+
"privacy-policy-violation",
|
|
456
|
+
/** Configuration could not be resolved. */
|
|
457
|
+
"configuration-invalid",
|
|
458
|
+
/** A configured bound (events, batch size) dropped data. */
|
|
459
|
+
"limit-exceeded",
|
|
460
|
+
/**
|
|
461
|
+
* No replay-stable delivery identifier was available for a callback while
|
|
462
|
+
* deduplication was required.
|
|
463
|
+
*/
|
|
464
|
+
"delivery-identifier-unavailable",
|
|
465
|
+
"delivery-claim-superseded",
|
|
466
|
+
/** Anything unanticipated. Always reported, never fatal to the host. */
|
|
467
|
+
"internal-error"
|
|
468
|
+
]);
|
|
469
|
+
var errorSeveritySchema = z4.enum(["warning", "error"]);
|
|
470
|
+
var errorPhaseSchema = z4.enum([
|
|
471
|
+
"configuration",
|
|
472
|
+
"detection",
|
|
473
|
+
"identity",
|
|
474
|
+
"parsing",
|
|
475
|
+
"normalization",
|
|
476
|
+
"privacy",
|
|
477
|
+
"state",
|
|
478
|
+
"export",
|
|
479
|
+
"shutdown"
|
|
480
|
+
]);
|
|
481
|
+
var failurePostureSchema = z4.enum(["fail-open", "fail-closed-attribution"]);
|
|
482
|
+
var ERROR_TAXONOMY = Object.freeze({
|
|
483
|
+
"invalid-input": {
|
|
484
|
+
code: "invalid-input",
|
|
485
|
+
severity: "warning",
|
|
486
|
+
posture: "fail-open",
|
|
487
|
+
retryable: false,
|
|
488
|
+
summary: "Input could not be read or decoded."
|
|
489
|
+
},
|
|
490
|
+
"schema-validation-failed": {
|
|
491
|
+
code: "schema-validation-failed",
|
|
492
|
+
severity: "error",
|
|
493
|
+
posture: "fail-closed-attribution",
|
|
494
|
+
retryable: false,
|
|
495
|
+
summary: "A canonical event failed schema validation and was dropped."
|
|
496
|
+
},
|
|
497
|
+
"provider-unknown": {
|
|
498
|
+
code: "provider-unknown",
|
|
499
|
+
severity: "warning",
|
|
500
|
+
posture: "fail-closed-attribution",
|
|
501
|
+
retryable: false,
|
|
502
|
+
summary: "No adapter recognized the source provider; the input stays unattributed."
|
|
503
|
+
},
|
|
504
|
+
"provider-detection-ambiguous": {
|
|
505
|
+
code: "provider-detection-ambiguous",
|
|
506
|
+
severity: "warning",
|
|
507
|
+
posture: "fail-closed-attribution",
|
|
508
|
+
retryable: false,
|
|
509
|
+
summary: "Multiple adapters claimed the input at equal confidence."
|
|
510
|
+
},
|
|
511
|
+
"provider-adapter-failure": {
|
|
512
|
+
code: "provider-adapter-failure",
|
|
513
|
+
severity: "error",
|
|
514
|
+
posture: "fail-open",
|
|
515
|
+
retryable: false,
|
|
516
|
+
summary: "A provider adapter failed while parsing."
|
|
517
|
+
},
|
|
518
|
+
"identity-conflict": {
|
|
519
|
+
code: "identity-conflict",
|
|
520
|
+
severity: "error",
|
|
521
|
+
posture: "fail-closed-attribution",
|
|
522
|
+
retryable: false,
|
|
523
|
+
summary: "Identity claims disagreed; attribution was declined."
|
|
524
|
+
},
|
|
525
|
+
"identity-incomplete": {
|
|
526
|
+
code: "identity-incomplete",
|
|
527
|
+
severity: "warning",
|
|
528
|
+
posture: "fail-closed-attribution",
|
|
529
|
+
retryable: false,
|
|
530
|
+
summary: "Required identity fields were missing; attribution was declined."
|
|
531
|
+
},
|
|
532
|
+
"usage-invalid": {
|
|
533
|
+
code: "usage-invalid",
|
|
534
|
+
severity: "error",
|
|
535
|
+
posture: "fail-open",
|
|
536
|
+
retryable: false,
|
|
537
|
+
summary: "A usage report violated the canonical usage invariants."
|
|
538
|
+
},
|
|
539
|
+
"state-store-failure": {
|
|
540
|
+
code: "state-store-failure",
|
|
541
|
+
severity: "warning",
|
|
542
|
+
posture: "fail-open",
|
|
543
|
+
retryable: true,
|
|
544
|
+
summary: "State could not be read or written; derived values may be incomplete."
|
|
545
|
+
},
|
|
546
|
+
"telemetry-export-failure": {
|
|
547
|
+
code: "telemetry-export-failure",
|
|
548
|
+
severity: "warning",
|
|
549
|
+
posture: "fail-open",
|
|
550
|
+
retryable: true,
|
|
551
|
+
summary: "The telemetry sink could not accept a batch."
|
|
552
|
+
},
|
|
553
|
+
"privacy-policy-violation": {
|
|
554
|
+
code: "privacy-policy-violation",
|
|
555
|
+
severity: "error",
|
|
556
|
+
posture: "fail-closed-attribution",
|
|
557
|
+
retryable: false,
|
|
558
|
+
summary: "Content violated the resolved privacy policy and was dropped."
|
|
559
|
+
},
|
|
560
|
+
"configuration-invalid": {
|
|
561
|
+
code: "configuration-invalid",
|
|
562
|
+
severity: "error",
|
|
563
|
+
posture: "fail-open",
|
|
564
|
+
retryable: false,
|
|
565
|
+
summary: "Configuration could not be resolved; defaults apply."
|
|
566
|
+
},
|
|
567
|
+
"limit-exceeded": {
|
|
568
|
+
code: "limit-exceeded",
|
|
569
|
+
severity: "warning",
|
|
570
|
+
posture: "fail-open",
|
|
571
|
+
retryable: false,
|
|
572
|
+
summary: "A configured bound was reached and data was dropped."
|
|
573
|
+
},
|
|
574
|
+
"delivery-identifier-unavailable": {
|
|
575
|
+
code: "delivery-identifier-unavailable",
|
|
576
|
+
severity: "warning",
|
|
577
|
+
// Fail-open: the observation is still attributed and exported. Only the
|
|
578
|
+
// at-most-once guarantee is missing, and refusing the telemetry to protect
|
|
579
|
+
// a duplicate count would trade a certain loss for a possible one.
|
|
580
|
+
posture: "fail-open",
|
|
581
|
+
retryable: false,
|
|
582
|
+
summary: "No replay-stable delivery identifier was available; this callback was exported without deduplication."
|
|
583
|
+
},
|
|
584
|
+
"delivery-claim-superseded": {
|
|
585
|
+
code: "delivery-claim-superseded",
|
|
586
|
+
severity: "warning",
|
|
587
|
+
// Fail-open, and specifically *not* silent. A peer reclaimed this callback's
|
|
588
|
+
// claim while this process was still working on it, which means the
|
|
589
|
+
// configured stale window is shorter than this installation's real worst
|
|
590
|
+
// case. Both processes may now have exported the callback, so the
|
|
591
|
+
// at-most-once guarantee did not hold for it — the only honest response is
|
|
592
|
+
// to say so and let the operator raise the window.
|
|
593
|
+
posture: "fail-open",
|
|
594
|
+
retryable: false,
|
|
595
|
+
summary: "A delivery claim was reclaimed by another process before this one committed; the callback may have been exported twice."
|
|
596
|
+
},
|
|
597
|
+
"internal-error": {
|
|
598
|
+
code: "internal-error",
|
|
599
|
+
severity: "error",
|
|
600
|
+
posture: "fail-open",
|
|
601
|
+
retryable: false,
|
|
602
|
+
summary: "An unexpected failure was contained."
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
var describeErrorCode = (code) => ERROR_TAXONOMY[code];
|
|
606
|
+
var attributionOutcomeSchema = z4.enum([
|
|
607
|
+
/** Identity resolved; events carry provider and session identity. */
|
|
608
|
+
"attributed",
|
|
609
|
+
/** Identity could not be established safely; nothing was attributed. */
|
|
610
|
+
"declined",
|
|
611
|
+
/** Attribution was attempted and failed unexpectedly. */
|
|
612
|
+
"failed",
|
|
613
|
+
/** Input was recognized but intentionally carried no telemetry. */
|
|
614
|
+
"not-applicable"
|
|
615
|
+
]);
|
|
616
|
+
var attributionReasonSchema = z4.enum([
|
|
617
|
+
"provider-unknown",
|
|
618
|
+
"provider-detection-ambiguous",
|
|
619
|
+
"identity-conflict",
|
|
620
|
+
"identity-incomplete",
|
|
621
|
+
"adapter-ignored-input",
|
|
622
|
+
"adapter-failure",
|
|
623
|
+
"invalid-input",
|
|
624
|
+
"internal-error"
|
|
625
|
+
]);
|
|
626
|
+
|
|
627
|
+
// src/errors/index.ts
|
|
628
|
+
var otelHookErrorInfoSchema = z5.strictObject({
|
|
629
|
+
code: otelHookErrorCodeSchema,
|
|
630
|
+
severity: errorSeveritySchema,
|
|
631
|
+
phase: errorPhaseSchema,
|
|
632
|
+
posture: failurePostureSchema,
|
|
633
|
+
retryable: z5.boolean(),
|
|
634
|
+
message: z5.string().min(1).max(512),
|
|
635
|
+
details: attributesSchema.optional(),
|
|
636
|
+
occurredAt: epochMillisSchema.optional()
|
|
637
|
+
});
|
|
638
|
+
var createErrorInfo = (input) => {
|
|
639
|
+
const descriptor = describeErrorCode(input.code);
|
|
640
|
+
const message = input.detail === void 0 ? `${input.code} during ${input.phase}: ${descriptor.summary}` : `${input.code} during ${input.phase}: ${input.detail}`;
|
|
641
|
+
return otelHookErrorInfoSchema.parse({
|
|
642
|
+
code: descriptor.code,
|
|
643
|
+
severity: descriptor.severity,
|
|
644
|
+
phase: input.phase,
|
|
645
|
+
posture: descriptor.posture,
|
|
646
|
+
retryable: descriptor.retryable,
|
|
647
|
+
message: message.slice(0, 512),
|
|
648
|
+
...input.details === void 0 ? {} : { details: input.details },
|
|
649
|
+
...input.occurredAt === void 0 ? {} : { occurredAt: input.occurredAt }
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
var OtelHookError = class _OtelHookError extends Error {
|
|
653
|
+
info;
|
|
654
|
+
constructor(info) {
|
|
655
|
+
super(info.message);
|
|
656
|
+
this.name = "OtelHookError";
|
|
657
|
+
this.info = info;
|
|
658
|
+
}
|
|
659
|
+
static of(input) {
|
|
660
|
+
return new _OtelHookError(createErrorInfo(input));
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
var isOtelHookError = (value) => value instanceof OtelHookError;
|
|
664
|
+
var describeThrown = (thrown) => {
|
|
665
|
+
if (thrown instanceof Error) {
|
|
666
|
+
return {
|
|
667
|
+
errorName: thrown.name.slice(0, 64) || "Error",
|
|
668
|
+
hasMessage: typeof thrown.message === "string" && thrown.message.length > 0
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
return { errorName: typeof thrown, hasMessage: false };
|
|
672
|
+
};
|
|
673
|
+
var errorInfoFromThrown = (thrown, input) => {
|
|
674
|
+
if (isOtelHookError(thrown)) {
|
|
675
|
+
return thrown.info;
|
|
676
|
+
}
|
|
677
|
+
const described = describeThrown(thrown);
|
|
678
|
+
return createErrorInfo({
|
|
679
|
+
code: input.code ?? "internal-error",
|
|
680
|
+
phase: input.phase,
|
|
681
|
+
detail: `contained ${described.errorName}`,
|
|
682
|
+
details: { "error.name": described.errorName, "error.has_message": described.hasMessage },
|
|
683
|
+
...input.occurredAt === void 0 ? {} : { occurredAt: input.occurredAt }
|
|
684
|
+
});
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// src/runtime/memory.ts
|
|
688
|
+
var createInMemoryStateStore = (options) => {
|
|
689
|
+
const records = /* @__PURE__ */ new Map();
|
|
690
|
+
let failures = options.failOperations ?? 0;
|
|
691
|
+
const guard = (operation) => {
|
|
692
|
+
if (failures > 0) {
|
|
693
|
+
failures -= 1;
|
|
694
|
+
throw new Error(`in-memory state store failure injected during ${operation}`);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
return {
|
|
698
|
+
read: (key) => {
|
|
699
|
+
guard("read");
|
|
700
|
+
return Promise.resolve(records.get(key));
|
|
701
|
+
},
|
|
702
|
+
write: (key, value) => {
|
|
703
|
+
guard("write");
|
|
704
|
+
const previous = records.get(key);
|
|
705
|
+
const record = stateRecordSchema.parse({
|
|
706
|
+
revision: (previous?.revision ?? 0) + 1,
|
|
707
|
+
updatedAt: options.clock.now(),
|
|
708
|
+
value
|
|
709
|
+
});
|
|
710
|
+
records.set(key, record);
|
|
711
|
+
return Promise.resolve(record);
|
|
712
|
+
},
|
|
713
|
+
delete: (key) => {
|
|
714
|
+
guard("delete");
|
|
715
|
+
records.delete(key);
|
|
716
|
+
return Promise.resolve();
|
|
717
|
+
},
|
|
718
|
+
keys: (prefix) => {
|
|
719
|
+
guard("keys");
|
|
720
|
+
return Promise.resolve([...records.keys()].filter((key) => key.startsWith(prefix)).sort());
|
|
721
|
+
},
|
|
722
|
+
snapshot: () => new Map(records),
|
|
723
|
+
failNext: (count) => {
|
|
724
|
+
failures += count;
|
|
725
|
+
},
|
|
726
|
+
clear: () => {
|
|
727
|
+
records.clear();
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
var createRecordingTelemetrySink = (options = {}) => {
|
|
732
|
+
const batches = [];
|
|
733
|
+
let failures = options.failBatches ?? 0;
|
|
734
|
+
let flushes = 0;
|
|
735
|
+
let shutdowns = 0;
|
|
736
|
+
return {
|
|
737
|
+
emit: (events) => {
|
|
738
|
+
if (failures > 0) {
|
|
739
|
+
failures -= 1;
|
|
740
|
+
return Promise.resolve({
|
|
741
|
+
accepted: 0,
|
|
742
|
+
rejected: events.length,
|
|
743
|
+
errors: [
|
|
744
|
+
createErrorInfo({
|
|
745
|
+
code: "telemetry-export-failure",
|
|
746
|
+
phase: "export",
|
|
747
|
+
detail: "recording sink rejected the batch",
|
|
748
|
+
details: { "export.batch_size": events.length }
|
|
749
|
+
})
|
|
750
|
+
]
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
batches.push([...events]);
|
|
754
|
+
return Promise.resolve({ accepted: events.length, rejected: 0, errors: [] });
|
|
755
|
+
},
|
|
756
|
+
flush: () => {
|
|
757
|
+
flushes += 1;
|
|
758
|
+
return Promise.resolve();
|
|
759
|
+
},
|
|
760
|
+
shutdown: () => {
|
|
761
|
+
shutdowns += 1;
|
|
762
|
+
return Promise.resolve();
|
|
763
|
+
},
|
|
764
|
+
batches: () => batches.map((batch) => [...batch]),
|
|
765
|
+
events: () => batches.flat(),
|
|
766
|
+
flushCount: () => flushes,
|
|
767
|
+
shutdownCount: () => shutdowns,
|
|
768
|
+
failNext: (count) => {
|
|
769
|
+
failures += count;
|
|
770
|
+
},
|
|
771
|
+
clear: () => {
|
|
772
|
+
batches.length = 0;
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
};
|
|
776
|
+
var createNullTelemetrySink = () => ({
|
|
777
|
+
emit: (events) => Promise.resolve({ accepted: events.length, rejected: 0, errors: [] }),
|
|
778
|
+
flush: () => Promise.resolve(),
|
|
779
|
+
shutdown: () => Promise.resolve()
|
|
780
|
+
});
|
|
781
|
+
var createRecordingLogger = (level = "debug") => {
|
|
782
|
+
const records = [];
|
|
783
|
+
const threshold = LOG_LEVEL_RANK[level];
|
|
784
|
+
const push = (entryLevel, message, fields) => {
|
|
785
|
+
if (threshold === 0 || LOG_LEVEL_RANK[entryLevel] > threshold) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
records.push({ level: entryLevel, message, ...fields === void 0 ? {} : { fields } });
|
|
789
|
+
};
|
|
790
|
+
return {
|
|
791
|
+
error: (message, fields) => {
|
|
792
|
+
push("error", message, fields);
|
|
793
|
+
},
|
|
794
|
+
warn: (message, fields) => {
|
|
795
|
+
push("warn", message, fields);
|
|
796
|
+
},
|
|
797
|
+
info: (message, fields) => {
|
|
798
|
+
push("info", message, fields);
|
|
799
|
+
},
|
|
800
|
+
debug: (message, fields) => {
|
|
801
|
+
push("debug", message, fields);
|
|
802
|
+
},
|
|
803
|
+
records: () => [...records],
|
|
804
|
+
clear: () => {
|
|
805
|
+
records.length = 0;
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
// src/runtime/delivery.ts
|
|
811
|
+
var PROVIDER_SCOPE_PREFIX = "provider-session";
|
|
812
|
+
var hostDeliveryIdentity = (callbackId, scope) => ({
|
|
813
|
+
scope: scope ?? "delivery",
|
|
814
|
+
callbackId,
|
|
815
|
+
origin: "host",
|
|
816
|
+
evidence: []
|
|
817
|
+
});
|
|
818
|
+
var resolveDeliveryIdentity = (input) => {
|
|
819
|
+
const { ids, providerId, installationId, claim } = input;
|
|
820
|
+
return {
|
|
821
|
+
scope: `${PROVIDER_SCOPE_PREFIX}:${ids.newOpaqueId([
|
|
822
|
+
"delivery-scope",
|
|
823
|
+
providerId,
|
|
824
|
+
installationId,
|
|
825
|
+
claim.sessionId
|
|
826
|
+
])}`,
|
|
827
|
+
callbackId: ids.newOpaqueId([
|
|
828
|
+
"delivery-callback",
|
|
829
|
+
providerId,
|
|
830
|
+
claim.sessionId,
|
|
831
|
+
claim.sourceEventName,
|
|
832
|
+
...claim.components
|
|
833
|
+
]),
|
|
834
|
+
origin: "provider",
|
|
835
|
+
evidence: [...claim.evidence]
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/runtime/hook.ts
|
|
840
|
+
import { z as z15 } from "zod";
|
|
841
|
+
|
|
842
|
+
// src/config/schema.ts
|
|
843
|
+
import { z as z8 } from "zod";
|
|
844
|
+
|
|
845
|
+
// src/privacy/policy.ts
|
|
846
|
+
import { z as z6 } from "zod";
|
|
847
|
+
var contentModeSchema = z6.enum(["omit", "mask", "redact", "raw"]);
|
|
848
|
+
var CONTENT_MODE_DISCLOSURE = Object.freeze({
|
|
849
|
+
omit: "omitted",
|
|
850
|
+
mask: "masked",
|
|
851
|
+
redact: "redacted",
|
|
852
|
+
raw: "raw"
|
|
853
|
+
});
|
|
854
|
+
var DEFAULT_SECRET_KEY_PATTERNS = Object.freeze([
|
|
855
|
+
"(^|[._-])(secret|secrets)([._-]|$)",
|
|
856
|
+
"(^|[._-])(token|tokens)([._-]|$)",
|
|
857
|
+
"(^|[._-])(password|passwd|pwd)([._-]|$)",
|
|
858
|
+
"(^|[._-])(credential|credentials)([._-]|$)",
|
|
859
|
+
"(^|[._-])(api[._-]?key|apikey|access[._-]?key|secret[._-]?key|private[._-]?key)([._-]|$)",
|
|
860
|
+
"(^|[._-])(authorization|auth[._-]?header|bearer)([._-]|$)",
|
|
861
|
+
"(^|[._-])(cookie|set[._-]?cookie)([._-]|$)",
|
|
862
|
+
"(^|[._-])(signature|sig)([._-]|$)"
|
|
863
|
+
]);
|
|
864
|
+
var DEFAULT_SECRET_VALUE_PATTERNS = Object.freeze([
|
|
865
|
+
"AKIA[0-9A-Z]{16}",
|
|
866
|
+
"sk-[A-Za-z0-9_-]{16,}",
|
|
867
|
+
"gh[pousr]_[A-Za-z0-9]{16,}",
|
|
868
|
+
"xox[abprs]-[A-Za-z0-9-]{10,}",
|
|
869
|
+
"-----BEGIN[A-Z ]*PRIVATE KEY-----",
|
|
870
|
+
"eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}",
|
|
871
|
+
"(?:Bearer|Basic)\\s+[A-Za-z0-9._~+/=-]{12,}"
|
|
872
|
+
]);
|
|
873
|
+
var privacyLimitsSchema = z6.strictObject({
|
|
874
|
+
/** Maximum characters of disclosed text per content fact or string value. */
|
|
875
|
+
maxStringLength: z6.number().int().min(0).max(65536),
|
|
876
|
+
/** Maximum nesting depth walked when sanitizing structured values. */
|
|
877
|
+
maxDepth: z6.number().int().min(1).max(32),
|
|
878
|
+
/** Maximum array entries retained when sanitizing structured values. */
|
|
879
|
+
maxArrayLength: z6.number().int().min(1).max(4096),
|
|
880
|
+
/** Maximum canonical events emitted per invocation. */
|
|
881
|
+
maxEventsPerInvocation: z6.number().int().min(1).max(1e4),
|
|
882
|
+
/** Maximum object keys retained per level when sanitizing. */
|
|
883
|
+
maxObjectKeys: z6.number().int().min(1).max(1024)
|
|
884
|
+
});
|
|
885
|
+
var privacyPolicySchema = z6.strictObject({
|
|
886
|
+
contentMode: contentModeSchema,
|
|
887
|
+
/**
|
|
888
|
+
* `raw` mode is refused unless this is also true, so a single mistyped
|
|
889
|
+
* environment variable cannot start exporting prompts.
|
|
890
|
+
*/
|
|
891
|
+
allowRawContent: z6.boolean(),
|
|
892
|
+
/**
|
|
893
|
+
* Salt mixed into every hash. A per-deployment salt makes hashes
|
|
894
|
+
* non-correlatable across deployments; an empty salt makes them globally
|
|
895
|
+
* comparable. Both are legitimate; the choice is explicit.
|
|
896
|
+
*/
|
|
897
|
+
hashSalt: z6.string().max(256),
|
|
898
|
+
maskCharacter: z6.string().length(1),
|
|
899
|
+
redactionPlaceholder: z6.string().min(1).max(64),
|
|
900
|
+
secretKeyPatterns: z6.array(z6.string().min(1)).max(128).readonly(),
|
|
901
|
+
secretValuePatterns: z6.array(z6.string().min(1)).max(128).readonly(),
|
|
902
|
+
limits: privacyLimitsSchema
|
|
903
|
+
});
|
|
904
|
+
var DEFAULT_PRIVACY_LIMITS = Object.freeze({
|
|
905
|
+
maxStringLength: 1024,
|
|
906
|
+
maxDepth: 6,
|
|
907
|
+
maxArrayLength: 64,
|
|
908
|
+
maxEventsPerInvocation: 512,
|
|
909
|
+
maxObjectKeys: 128
|
|
910
|
+
});
|
|
911
|
+
var DEFAULT_PRIVACY_POLICY = Object.freeze({
|
|
912
|
+
contentMode: "omit",
|
|
913
|
+
allowRawContent: false,
|
|
914
|
+
hashSalt: "",
|
|
915
|
+
maskCharacter: "*",
|
|
916
|
+
redactionPlaceholder: "[redacted]",
|
|
917
|
+
secretKeyPatterns: DEFAULT_SECRET_KEY_PATTERNS,
|
|
918
|
+
secretValuePatterns: DEFAULT_SECRET_VALUE_PATTERNS,
|
|
919
|
+
limits: DEFAULT_PRIVACY_LIMITS
|
|
920
|
+
});
|
|
921
|
+
var resolvePrivacyPolicy = (policy) => {
|
|
922
|
+
const parsed = privacyPolicySchema.parse(policy);
|
|
923
|
+
if (parsed.contentMode === "raw" && !parsed.allowRawContent) {
|
|
924
|
+
return {
|
|
925
|
+
policy: { ...parsed, contentMode: "omit" },
|
|
926
|
+
notes: ["contentMode=raw downgraded to omit because allowRawContent is false"]
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
return { policy: parsed, notes: [] };
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
// src/config/resource-attributes.ts
|
|
933
|
+
import { z as z7 } from "zod";
|
|
934
|
+
var MAX_RESOURCE_ATTRIBUTES = 64;
|
|
935
|
+
var MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH = 255;
|
|
936
|
+
var MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH = 2048;
|
|
937
|
+
var RESOURCE_ATTRIBUTE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_./-]*$/;
|
|
938
|
+
var RESERVED_RESOURCE_ATTRIBUTE_KEYS = Object.freeze([
|
|
939
|
+
"service.name",
|
|
940
|
+
"service.namespace"
|
|
941
|
+
]);
|
|
942
|
+
var isReservedResourceAttributeKey = (key) => RESERVED_RESOURCE_ATTRIBUTE_KEYS.includes(key.toLowerCase());
|
|
943
|
+
var SECRET_KEY_MATCHERS = Object.freeze(
|
|
944
|
+
DEFAULT_SECRET_KEY_PATTERNS.flatMap((source) => {
|
|
945
|
+
try {
|
|
946
|
+
return [new RegExp(source, "i")];
|
|
947
|
+
} catch {
|
|
948
|
+
return [];
|
|
949
|
+
}
|
|
950
|
+
})
|
|
951
|
+
);
|
|
952
|
+
var isSecretResourceAttributeKey = (key) => SECRET_KEY_MATCHERS.some((pattern) => pattern.test(key));
|
|
953
|
+
var RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL = Object.freeze({
|
|
954
|
+
empty: "resource attribute key is empty",
|
|
955
|
+
"too-long": `resource attribute key exceeds ${String(MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH)} characters`,
|
|
956
|
+
malformed: "resource attribute key must start with a letter and use only letters, digits, and `_`, `.`, `-`, `/`",
|
|
957
|
+
reserved: "service.name and service.namespace are exporter policy (--service-name / OTEL_HOOK_SERVICE_NAME), not resource attributes",
|
|
958
|
+
"secret-like": "resource attribute key matches a secret-name pattern, so it is never exported"
|
|
959
|
+
});
|
|
960
|
+
var checkResourceAttributeKey = (key) => {
|
|
961
|
+
if (key.length === 0) {
|
|
962
|
+
return "empty";
|
|
963
|
+
}
|
|
964
|
+
if (key.length > MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH) {
|
|
965
|
+
return "too-long";
|
|
966
|
+
}
|
|
967
|
+
if (!RESOURCE_ATTRIBUTE_KEY_PATTERN.test(key)) {
|
|
968
|
+
return "malformed";
|
|
969
|
+
}
|
|
970
|
+
if (isReservedResourceAttributeKey(key)) {
|
|
971
|
+
return "reserved";
|
|
972
|
+
}
|
|
973
|
+
if (isSecretResourceAttributeKey(key)) {
|
|
974
|
+
return "secret-like";
|
|
975
|
+
}
|
|
976
|
+
return void 0;
|
|
977
|
+
};
|
|
978
|
+
var resourceAttributeValueSchema = z7.union([
|
|
979
|
+
z7.string().max(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH),
|
|
980
|
+
z7.number().finite(),
|
|
981
|
+
z7.boolean()
|
|
982
|
+
]);
|
|
983
|
+
var resourceAttributesSchema = z7.record(z7.string(), resourceAttributeValueSchema).superRefine((value, ctx) => {
|
|
984
|
+
const keys = Object.keys(value);
|
|
985
|
+
if (keys.length > MAX_RESOURCE_ATTRIBUTES) {
|
|
986
|
+
ctx.addIssue({
|
|
987
|
+
code: "custom",
|
|
988
|
+
message: `at most ${String(MAX_RESOURCE_ATTRIBUTES)} resource attributes are accepted`
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
for (const key of keys) {
|
|
992
|
+
const rejection = checkResourceAttributeKey(key);
|
|
993
|
+
if (rejection !== void 0) {
|
|
994
|
+
ctx.addIssue({
|
|
995
|
+
code: "custom",
|
|
996
|
+
path: [key],
|
|
997
|
+
message: RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL[rejection]
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}).readonly();
|
|
1002
|
+
var EMPTY_RESOURCE_ATTRIBUTES = Object.freeze({});
|
|
1003
|
+
|
|
1004
|
+
// src/config/schema.ts
|
|
1005
|
+
var logsPolicySchema = z8.strictObject({
|
|
1006
|
+
enabled: z8.boolean(),
|
|
1007
|
+
/**
|
|
1008
|
+
* Full URL for the logs signal.
|
|
1009
|
+
*
|
|
1010
|
+
* Absent, it is derived from `endpoint`: a trailing `/v1/traces` becomes
|
|
1011
|
+
* `/v1/logs`, and an endpoint with no signal path has `/v1/logs` appended.
|
|
1012
|
+
*/
|
|
1013
|
+
endpoint: z8.string().url().max(2048).optional(),
|
|
1014
|
+
includeContent: z8.boolean(),
|
|
1015
|
+
maxBatchSize: z8.number().int().min(1).max(4096)
|
|
1016
|
+
});
|
|
1017
|
+
var DEFAULT_LOGS_POLICY = Object.freeze({
|
|
1018
|
+
enabled: false,
|
|
1019
|
+
includeContent: false,
|
|
1020
|
+
maxBatchSize: 128
|
|
1021
|
+
});
|
|
1022
|
+
var exporterPolicySchema = z8.strictObject({
|
|
1023
|
+
enabled: z8.boolean(),
|
|
1024
|
+
protocol: z8.enum(["http/protobuf", "http/json", "none"]),
|
|
1025
|
+
endpoint: z8.string().url().max(2048).optional(),
|
|
1026
|
+
/**
|
|
1027
|
+
* Header names only. Values are supplied separately at construction time and
|
|
1028
|
+
* are never part of a resolved-config snapshot, which is logged and exported.
|
|
1029
|
+
*/
|
|
1030
|
+
headerNames: z8.array(nonEmptyStringSchema).max(32).readonly(),
|
|
1031
|
+
timeoutMillis: z8.number().int().min(1).max(6e5),
|
|
1032
|
+
maxBatchSize: z8.number().int().min(1).max(4096),
|
|
1033
|
+
maxQueueSize: z8.number().int().min(1).max(65536),
|
|
1034
|
+
maxRetryAttempts: z8.number().int().min(0).max(10),
|
|
1035
|
+
serviceName: nonEmptyStringSchema,
|
|
1036
|
+
serviceNamespace: nonEmptyStringSchema.optional(),
|
|
1037
|
+
/**
|
|
1038
|
+
* Custom attributes merged into the exported OTLP Resource.
|
|
1039
|
+
*
|
|
1040
|
+
* Bounded and validated, and refusing `service.name`/`service.namespace`,
|
|
1041
|
+
* which are the two fields above. Distinct from an invocation's
|
|
1042
|
+
* `consumerAttributes`: this describes the emitting deployment, carries no
|
|
1043
|
+
* identity, and is the same for every span this process exports.
|
|
1044
|
+
*/
|
|
1045
|
+
resourceAttributes: resourceAttributesSchema,
|
|
1046
|
+
/**
|
|
1047
|
+
* The logs signal. Nested under the exporter because it shares the endpoint,
|
|
1048
|
+
* headers, timeout, protocol, service identity, and resource attributes above —
|
|
1049
|
+
* a second top-level section would invite two of each to drift apart.
|
|
1050
|
+
*/
|
|
1051
|
+
logs: logsPolicySchema
|
|
1052
|
+
});
|
|
1053
|
+
var detectionPolicySchema = z8.strictObject({
|
|
1054
|
+
/** Detections below this confidence resolve to the unknown provider. */
|
|
1055
|
+
minimumConfidence: detectionConfidenceSchema,
|
|
1056
|
+
/** When false, an ambiguous detection is an error rather than unknown. */
|
|
1057
|
+
allowAmbiguousFallback: z8.boolean(),
|
|
1058
|
+
/** Optional allow-list of provider ids; empty means "any registered". */
|
|
1059
|
+
allowedProviderIds: z8.array(nonEmptyStringSchema).max(32).readonly()
|
|
1060
|
+
});
|
|
1061
|
+
var diagnosticsPolicySchema = z8.strictObject({
|
|
1062
|
+
logLevel: z8.enum(["silent", "error", "warn", "info", "debug"]),
|
|
1063
|
+
/** Emit `error.raised` events for contained failures. */
|
|
1064
|
+
emitErrorEvents: z8.boolean()
|
|
1065
|
+
});
|
|
1066
|
+
var otelHookConfigSchema = z8.strictObject({
|
|
1067
|
+
exporter: exporterPolicySchema,
|
|
1068
|
+
privacy: privacyPolicySchema,
|
|
1069
|
+
detection: detectionPolicySchema,
|
|
1070
|
+
diagnostics: diagnosticsPolicySchema
|
|
1071
|
+
});
|
|
1072
|
+
var otelHookConfigPatchSchema = z8.strictObject({
|
|
1073
|
+
// `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
|
|
1074
|
+
// merging happens per leaf, so a layer must be able to set `logs.enabled` alone
|
|
1075
|
+
// without also restating the endpoint and the batch size.
|
|
1076
|
+
exporter: exporterPolicySchema.omit({ logs: true }).partial().extend({ logs: logsPolicySchema.partial().optional() }).optional(),
|
|
1077
|
+
privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
|
|
1078
|
+
detection: detectionPolicySchema.partial().optional(),
|
|
1079
|
+
diagnostics: diagnosticsPolicySchema.partial().optional()
|
|
1080
|
+
});
|
|
1081
|
+
var DEFAULT_EXPORTER_POLICY = Object.freeze({
|
|
1082
|
+
enabled: true,
|
|
1083
|
+
protocol: "http/protobuf",
|
|
1084
|
+
headerNames: Object.freeze([]),
|
|
1085
|
+
timeoutMillis: 1e4,
|
|
1086
|
+
maxBatchSize: 128,
|
|
1087
|
+
maxQueueSize: 2048,
|
|
1088
|
+
maxRetryAttempts: 2,
|
|
1089
|
+
serviceName: "coding-agent",
|
|
1090
|
+
resourceAttributes: EMPTY_RESOURCE_ATTRIBUTES,
|
|
1091
|
+
logs: DEFAULT_LOGS_POLICY
|
|
1092
|
+
});
|
|
1093
|
+
var DEFAULT_DETECTION_POLICY = Object.freeze({
|
|
1094
|
+
minimumConfidence: "strong",
|
|
1095
|
+
allowAmbiguousFallback: true,
|
|
1096
|
+
allowedProviderIds: Object.freeze([])
|
|
1097
|
+
});
|
|
1098
|
+
var DEFAULT_DIAGNOSTICS_POLICY = Object.freeze({
|
|
1099
|
+
logLevel: "warn",
|
|
1100
|
+
emitErrorEvents: true
|
|
1101
|
+
});
|
|
1102
|
+
var DEFAULT_CONFIG = Object.freeze({
|
|
1103
|
+
exporter: DEFAULT_EXPORTER_POLICY,
|
|
1104
|
+
privacy: DEFAULT_PRIVACY_POLICY,
|
|
1105
|
+
detection: DEFAULT_DETECTION_POLICY,
|
|
1106
|
+
diagnostics: DEFAULT_DIAGNOSTICS_POLICY
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
// src/model/content.ts
|
|
1110
|
+
import { z as z9 } from "zod";
|
|
1111
|
+
var contentKindSchema = z9.enum([
|
|
1112
|
+
"prompt",
|
|
1113
|
+
"response",
|
|
1114
|
+
"reasoning",
|
|
1115
|
+
"tool-input",
|
|
1116
|
+
"tool-output",
|
|
1117
|
+
"error-message",
|
|
1118
|
+
"system-instruction",
|
|
1119
|
+
"attachment"
|
|
1120
|
+
]);
|
|
1121
|
+
var contentRoleSchema = z9.enum(["user", "assistant", "system", "tool", "unknown"]);
|
|
1122
|
+
var contentDisclosureSchema = z9.enum(["omitted", "masked", "redacted", "raw"]);
|
|
1123
|
+
var CONTENT_HASH_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
1124
|
+
var contentFactSchema = z9.strictObject({
|
|
1125
|
+
kind: contentKindSchema,
|
|
1126
|
+
role: contentRoleSchema.optional(),
|
|
1127
|
+
/** Unicode code point count of the original content. */
|
|
1128
|
+
characterLength: z9.number().int().min(0),
|
|
1129
|
+
/** UTF-8 byte length of the original content. */
|
|
1130
|
+
byteLength: z9.number().int().min(0),
|
|
1131
|
+
/** Stable salted digest of the original content. */
|
|
1132
|
+
contentHash: z9.string().regex(CONTENT_HASH_PATTERN),
|
|
1133
|
+
disclosure: contentDisclosureSchema,
|
|
1134
|
+
/** Disclosed text, bounded by the privacy policy. Absent when omitted. */
|
|
1135
|
+
text: z9.string().optional(),
|
|
1136
|
+
/** True when `text` was cut short by the configured string bound. */
|
|
1137
|
+
truncated: z9.boolean(),
|
|
1138
|
+
/** Number of secret-looking spans replaced while producing `text`. */
|
|
1139
|
+
secretsRedacted: z9.number().int().min(0),
|
|
1140
|
+
/** Optional non-sensitive label, e.g. a MIME type or tool name. */
|
|
1141
|
+
label: nonEmptyStringSchema.optional()
|
|
1142
|
+
});
|
|
1143
|
+
var contentFactsSchema = z9.array(contentFactSchema).max(64);
|
|
1144
|
+
var isContentFactConsistent = (fact) => fact.disclosure === "omitted" ? fact.text === void 0 : fact.text !== void 0;
|
|
1145
|
+
|
|
1146
|
+
// src/model/identity.ts
|
|
1147
|
+
import { z as z10 } from "zod";
|
|
1148
|
+
var workspaceKeySourceSchema = z10.enum([
|
|
1149
|
+
"git-remote",
|
|
1150
|
+
"git-root",
|
|
1151
|
+
"working-directory",
|
|
1152
|
+
"explicit",
|
|
1153
|
+
"unknown"
|
|
1154
|
+
]);
|
|
1155
|
+
var workspaceIdentitySchema = z10.strictObject({
|
|
1156
|
+
workspaceId: workspaceIdSchema,
|
|
1157
|
+
keySource: workspaceKeySourceSchema,
|
|
1158
|
+
/** Repository name only; never an owner path or URL with credentials. */
|
|
1159
|
+
repositoryName: nonEmptyStringSchema.optional(),
|
|
1160
|
+
vcsBranchName: nonEmptyStringSchema.optional(),
|
|
1161
|
+
/** Opaque handle for the checked-out revision. */
|
|
1162
|
+
vcsRevisionId: nonEmptyStringSchema.optional()
|
|
1163
|
+
}).readonly();
|
|
1164
|
+
var UNKNOWN_WORKSPACE_ID = "unknown:0000000000000000";
|
|
1165
|
+
var unknownWorkspaceIdentity = () => workspaceIdentitySchema.parse({
|
|
1166
|
+
workspaceId: UNKNOWN_WORKSPACE_ID,
|
|
1167
|
+
keySource: "unknown"
|
|
1168
|
+
});
|
|
1169
|
+
var sourceProvenanceSchema = z10.strictObject({
|
|
1170
|
+
providerId: resolvedProviderIdSchema,
|
|
1171
|
+
providerVersion: nonEmptyStringSchema.optional(),
|
|
1172
|
+
adapterId: nonEmptyStringSchema,
|
|
1173
|
+
adapterVersion: nonEmptyStringSchema,
|
|
1174
|
+
detectionConfidence: detectionConfidenceSchema,
|
|
1175
|
+
/** The provider's own name for the source event, e.g. a hook event name. */
|
|
1176
|
+
sourceEventName: nonEmptyStringSchema.optional(),
|
|
1177
|
+
transport: sourceTransportSchema
|
|
1178
|
+
}).readonly();
|
|
1179
|
+
var consumerAttributesSchema = attributesSchema.readonly();
|
|
1180
|
+
var invocationIdentitySchema = z10.strictObject({
|
|
1181
|
+
invocationId: invocationIdSchema,
|
|
1182
|
+
sessionId: sessionIdSchema,
|
|
1183
|
+
/** Set when this invocation runs beneath another agent invocation. */
|
|
1184
|
+
parentInvocationId: invocationIdSchema.optional(),
|
|
1185
|
+
/** Root of the session tree when the provider exposes one. */
|
|
1186
|
+
rootSessionId: sessionIdSchema.optional(),
|
|
1187
|
+
/** Stable handle for the agent process/instance, when available. */
|
|
1188
|
+
agentInstanceId: nonEmptyStringSchema.optional(),
|
|
1189
|
+
provenance: sourceProvenanceSchema,
|
|
1190
|
+
workspace: workspaceIdentitySchema,
|
|
1191
|
+
startedAt: epochMillisSchema,
|
|
1192
|
+
consumerAttributes: consumerAttributesSchema
|
|
1193
|
+
}).readonly();
|
|
1194
|
+
var identityClaimFieldsSchema = z10.strictObject({
|
|
1195
|
+
invocationId: invocationIdSchema.optional(),
|
|
1196
|
+
sessionId: sessionIdSchema.optional(),
|
|
1197
|
+
parentInvocationId: invocationIdSchema.optional(),
|
|
1198
|
+
rootSessionId: sessionIdSchema.optional(),
|
|
1199
|
+
agentInstanceId: nonEmptyStringSchema.optional(),
|
|
1200
|
+
workspace: workspaceIdentitySchema.optional(),
|
|
1201
|
+
startedAt: epochMillisSchema.optional()
|
|
1202
|
+
});
|
|
1203
|
+
var identityClaimSchema = z10.strictObject({
|
|
1204
|
+
/** Non-sensitive label, e.g. `adapter:acme-cli` or `env:OTEL_HOOK_SESSION_ID`. */
|
|
1205
|
+
source: nonEmptyStringSchema,
|
|
1206
|
+
confidence: detectionConfidenceSchema,
|
|
1207
|
+
fields: identityClaimFieldsSchema
|
|
1208
|
+
});
|
|
1209
|
+
var CLAIM_FIELDS = [
|
|
1210
|
+
"invocationId",
|
|
1211
|
+
"sessionId",
|
|
1212
|
+
"parentInvocationId",
|
|
1213
|
+
"rootSessionId",
|
|
1214
|
+
"agentInstanceId",
|
|
1215
|
+
"workspace",
|
|
1216
|
+
"startedAt"
|
|
1217
|
+
];
|
|
1218
|
+
var renderClaimValue = (value) => {
|
|
1219
|
+
if (typeof value === "string") {
|
|
1220
|
+
return value;
|
|
1221
|
+
}
|
|
1222
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
1223
|
+
return String(value);
|
|
1224
|
+
}
|
|
1225
|
+
if (value !== null && typeof value === "object" && "workspaceId" in value) {
|
|
1226
|
+
const { workspaceId } = value;
|
|
1227
|
+
return typeof workspaceId === "string" ? workspaceId : "<workspace>";
|
|
1228
|
+
}
|
|
1229
|
+
return "<opaque>";
|
|
1230
|
+
};
|
|
1231
|
+
var resolveInvocationIdentity = (input) => {
|
|
1232
|
+
const parsedClaims = [];
|
|
1233
|
+
const issues = [];
|
|
1234
|
+
for (const [index, claim] of input.claims.entries()) {
|
|
1235
|
+
const parsed2 = identityClaimSchema.safeParse(claim);
|
|
1236
|
+
if (parsed2.success) {
|
|
1237
|
+
parsedClaims.push(parsed2.data);
|
|
1238
|
+
} else {
|
|
1239
|
+
issues.push(
|
|
1240
|
+
`claim[${index}]: ${parsed2.error.issues.map((issue) => `${issue.path.join(".") || "<root>"} ${issue.message}`).join(", ")}`
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
if (issues.length > 0) {
|
|
1245
|
+
return { status: "invalid", issues };
|
|
1246
|
+
}
|
|
1247
|
+
const conflicts = [];
|
|
1248
|
+
const selected = {};
|
|
1249
|
+
for (const field of CLAIM_FIELDS) {
|
|
1250
|
+
const contributors = parsedClaims.filter((claim) => claim.fields[field] !== void 0);
|
|
1251
|
+
if (contributors.length === 0) {
|
|
1252
|
+
continue;
|
|
1253
|
+
}
|
|
1254
|
+
const bestRank = Math.max(
|
|
1255
|
+
...contributors.map((claim) => DETECTION_CONFIDENCE_RANK[claim.confidence])
|
|
1256
|
+
);
|
|
1257
|
+
const best = contributors.filter(
|
|
1258
|
+
(claim) => DETECTION_CONFIDENCE_RANK[claim.confidence] === bestRank
|
|
1259
|
+
);
|
|
1260
|
+
const rendered = /* @__PURE__ */ new Map();
|
|
1261
|
+
for (const claim of best) {
|
|
1262
|
+
const key = JSON.stringify(claim.fields[field]);
|
|
1263
|
+
const sources = rendered.get(key) ?? [];
|
|
1264
|
+
sources.push(claim.source);
|
|
1265
|
+
rendered.set(key, sources);
|
|
1266
|
+
}
|
|
1267
|
+
if (rendered.size > 1) {
|
|
1268
|
+
const [firstBest] = best;
|
|
1269
|
+
conflicts.push({
|
|
1270
|
+
field,
|
|
1271
|
+
confidence: firstBest?.confidence ?? "none",
|
|
1272
|
+
values: best.map((claim) => renderClaimValue(claim.fields[field])),
|
|
1273
|
+
sources: best.map((claim) => claim.source)
|
|
1274
|
+
});
|
|
1275
|
+
continue;
|
|
1276
|
+
}
|
|
1277
|
+
const [winner] = best;
|
|
1278
|
+
if (winner !== void 0) {
|
|
1279
|
+
selected[field] = winner.fields[field];
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (conflicts.length > 0) {
|
|
1283
|
+
return { status: "conflict", conflicts };
|
|
1284
|
+
}
|
|
1285
|
+
const missing = [];
|
|
1286
|
+
if (selected.invocationId === void 0) {
|
|
1287
|
+
missing.push("invocationId");
|
|
1288
|
+
}
|
|
1289
|
+
if (selected.sessionId === void 0) {
|
|
1290
|
+
missing.push("sessionId");
|
|
1291
|
+
}
|
|
1292
|
+
if (missing.length > 0) {
|
|
1293
|
+
return { status: "incomplete", missing };
|
|
1294
|
+
}
|
|
1295
|
+
const startedAt = selected.startedAt ?? input.fallback?.startedAt;
|
|
1296
|
+
if (startedAt === void 0) {
|
|
1297
|
+
return { status: "incomplete", missing: ["startedAt"] };
|
|
1298
|
+
}
|
|
1299
|
+
const workspace = selected.workspace ?? input.fallback?.workspace ?? unknownWorkspaceIdentity();
|
|
1300
|
+
const candidate = {
|
|
1301
|
+
invocationId: selected.invocationId,
|
|
1302
|
+
sessionId: selected.sessionId,
|
|
1303
|
+
...selected.parentInvocationId === void 0 ? {} : { parentInvocationId: selected.parentInvocationId },
|
|
1304
|
+
...selected.rootSessionId === void 0 ? {} : { rootSessionId: selected.rootSessionId },
|
|
1305
|
+
...selected.agentInstanceId === void 0 ? {} : { agentInstanceId: selected.agentInstanceId },
|
|
1306
|
+
provenance: input.provenance,
|
|
1307
|
+
workspace,
|
|
1308
|
+
startedAt,
|
|
1309
|
+
consumerAttributes: input.consumerAttributes ?? {}
|
|
1310
|
+
};
|
|
1311
|
+
const parsed = invocationIdentitySchema.safeParse(candidate);
|
|
1312
|
+
if (!parsed.success) {
|
|
1313
|
+
return {
|
|
1314
|
+
status: "invalid",
|
|
1315
|
+
issues: parsed.error.issues.map(
|
|
1316
|
+
(issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`
|
|
1317
|
+
)
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
return { status: "resolved", identity: parsed.data };
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
// src/model/version.ts
|
|
1324
|
+
import { z as z11 } from "zod";
|
|
1325
|
+
var CANONICAL_SCHEMA_VERSION = 1;
|
|
1326
|
+
var canonicalSchemaVersionSchema = z11.literal(CANONICAL_SCHEMA_VERSION);
|
|
1327
|
+
|
|
1328
|
+
// src/privacy/service.ts
|
|
1329
|
+
import { createHash as createHash2 } from "crypto";
|
|
1330
|
+
|
|
1331
|
+
// src/model/extensions.ts
|
|
1332
|
+
import { z as z12 } from "zod";
|
|
1333
|
+
var EXTENSION_KEY_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*(?:\.[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*)+$/;
|
|
1334
|
+
var RESERVED_EXTENSION_NAMESPACES = Object.freeze([
|
|
1335
|
+
"otelhook",
|
|
1336
|
+
"otel",
|
|
1337
|
+
"telemetry"
|
|
1338
|
+
]);
|
|
1339
|
+
var MAX_EXTENSION_ENTRIES = 64;
|
|
1340
|
+
var extensionKeyNamespace = (key) => key.slice(0, key.indexOf("."));
|
|
1341
|
+
var isReservedExtensionNamespace = (key) => RESERVED_EXTENSION_NAMESPACES.includes(extensionKeyNamespace(key));
|
|
1342
|
+
var isValidExtensionKey = (key) => EXTENSION_KEY_PATTERN.test(key) && !isReservedExtensionNamespace(key);
|
|
1343
|
+
var extensionsSchema = z12.record(z12.string(), attributeValueSchema).check((ctx) => {
|
|
1344
|
+
const keys = Object.keys(ctx.value);
|
|
1345
|
+
if (keys.length > MAX_EXTENSION_ENTRIES) {
|
|
1346
|
+
ctx.issues.push({
|
|
1347
|
+
code: "custom",
|
|
1348
|
+
input: ctx.value,
|
|
1349
|
+
message: `extensions may contain at most ${MAX_EXTENSION_ENTRIES} entries`
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
for (const key of keys) {
|
|
1353
|
+
if (!EXTENSION_KEY_PATTERN.test(key)) {
|
|
1354
|
+
ctx.issues.push({
|
|
1355
|
+
code: "custom",
|
|
1356
|
+
input: ctx.value,
|
|
1357
|
+
path: [key],
|
|
1358
|
+
message: `extension key ${JSON.stringify(key)} must be namespaced, e.g. "acme.tier"`
|
|
1359
|
+
});
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
if (isReservedExtensionNamespace(key)) {
|
|
1363
|
+
ctx.issues.push({
|
|
1364
|
+
code: "custom",
|
|
1365
|
+
input: ctx.value,
|
|
1366
|
+
path: [key],
|
|
1367
|
+
message: `extension namespace ${JSON.stringify(extensionKeyNamespace(key))} is reserved`
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
var EMPTY_EXTENSIONS = Object.freeze({});
|
|
1373
|
+
var emptyExtensions = () => ({});
|
|
1374
|
+
|
|
1375
|
+
// src/privacy/service.ts
|
|
1376
|
+
var compilePatterns = (sources, flags) => {
|
|
1377
|
+
const compiled = [];
|
|
1378
|
+
for (const source of sources) {
|
|
1379
|
+
try {
|
|
1380
|
+
compiled.push(new RegExp(source, flags));
|
|
1381
|
+
} catch {
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
return compiled;
|
|
1386
|
+
};
|
|
1387
|
+
var codePointLength = (value) => [...value].length;
|
|
1388
|
+
var isSanitizedArray = (value) => Array.isArray(value);
|
|
1389
|
+
var sliceCodePoints = (value, max) => {
|
|
1390
|
+
if (max <= 0) {
|
|
1391
|
+
return "";
|
|
1392
|
+
}
|
|
1393
|
+
let result = "";
|
|
1394
|
+
let count = 0;
|
|
1395
|
+
for (const char of value) {
|
|
1396
|
+
if (count >= max) {
|
|
1397
|
+
break;
|
|
1398
|
+
}
|
|
1399
|
+
result += char;
|
|
1400
|
+
count += 1;
|
|
1401
|
+
}
|
|
1402
|
+
return result;
|
|
1403
|
+
};
|
|
1404
|
+
var stableStringify = (value) => {
|
|
1405
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1406
|
+
const walk = (input) => {
|
|
1407
|
+
if (input === null) {
|
|
1408
|
+
return "null";
|
|
1409
|
+
}
|
|
1410
|
+
if (typeof input === "string") {
|
|
1411
|
+
return JSON.stringify(input);
|
|
1412
|
+
}
|
|
1413
|
+
if (typeof input === "number") {
|
|
1414
|
+
return Number.isFinite(input) ? JSON.stringify(input) : "null";
|
|
1415
|
+
}
|
|
1416
|
+
if (typeof input === "boolean") {
|
|
1417
|
+
return input ? "true" : "false";
|
|
1418
|
+
}
|
|
1419
|
+
if (typeof input === "bigint") {
|
|
1420
|
+
return JSON.stringify(input.toString());
|
|
1421
|
+
}
|
|
1422
|
+
if (typeof input !== "object") {
|
|
1423
|
+
return "null";
|
|
1424
|
+
}
|
|
1425
|
+
if (seen.has(input)) {
|
|
1426
|
+
return '"<circular>"';
|
|
1427
|
+
}
|
|
1428
|
+
seen.add(input);
|
|
1429
|
+
if (Array.isArray(input)) {
|
|
1430
|
+
return `[${input.map((entry) => walk(entry)).join(",")}]`;
|
|
1431
|
+
}
|
|
1432
|
+
const record = input;
|
|
1433
|
+
const keys = Object.keys(record).sort();
|
|
1434
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${walk(record[key])}`).join(",")}}`;
|
|
1435
|
+
};
|
|
1436
|
+
return walk(value);
|
|
1437
|
+
};
|
|
1438
|
+
var emptyStats = () => ({
|
|
1439
|
+
truncatedStrings: 0,
|
|
1440
|
+
truncatedArrays: 0,
|
|
1441
|
+
truncatedObjects: 0,
|
|
1442
|
+
redactedKeys: 0,
|
|
1443
|
+
depthExceeded: 0,
|
|
1444
|
+
droppedValues: 0,
|
|
1445
|
+
circularReferences: 0
|
|
1446
|
+
});
|
|
1447
|
+
var createPrivacyService = (policyInput) => {
|
|
1448
|
+
const { policy, notes } = resolvePrivacyPolicy(policyInput);
|
|
1449
|
+
const limits = policy.limits;
|
|
1450
|
+
const secretKeyPatterns = compilePatterns(policy.secretKeyPatterns, "i");
|
|
1451
|
+
const secretValuePatterns = compilePatterns(policy.secretValuePatterns, "g");
|
|
1452
|
+
const hash = (value) => `sha256:${createHash2("sha256").update(policy.hashSalt).update("\0").update(value, "utf8").digest("hex")}`;
|
|
1453
|
+
const isSecretKey = (key) => secretKeyPatterns.some((pattern) => pattern.test(key));
|
|
1454
|
+
const boundString = (value) => {
|
|
1455
|
+
const length = codePointLength(value);
|
|
1456
|
+
if (length <= limits.maxStringLength) {
|
|
1457
|
+
return { text: value, truncated: false };
|
|
1458
|
+
}
|
|
1459
|
+
return { text: sliceCodePoints(value, limits.maxStringLength), truncated: true };
|
|
1460
|
+
};
|
|
1461
|
+
const redactSecretSpans = (value) => {
|
|
1462
|
+
let count = 0;
|
|
1463
|
+
let text = value;
|
|
1464
|
+
for (const pattern of secretValuePatterns) {
|
|
1465
|
+
text = text.replace(new RegExp(pattern.source, pattern.flags), () => {
|
|
1466
|
+
count += 1;
|
|
1467
|
+
return policy.redactionPlaceholder;
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
return { text, count };
|
|
1471
|
+
};
|
|
1472
|
+
const maskText = (value) => Array.from(value, (char) => /\s/.test(char) ? char : policy.maskCharacter).join("");
|
|
1473
|
+
const disclose = (original) => {
|
|
1474
|
+
switch (policy.contentMode) {
|
|
1475
|
+
case "omit":
|
|
1476
|
+
return { text: void 0, truncated: false, secretsRedacted: 0 };
|
|
1477
|
+
case "mask": {
|
|
1478
|
+
const bounded = boundString(original);
|
|
1479
|
+
return { text: maskText(bounded.text), truncated: bounded.truncated, secretsRedacted: 0 };
|
|
1480
|
+
}
|
|
1481
|
+
case "redact": {
|
|
1482
|
+
const redacted = redactSecretSpans(original);
|
|
1483
|
+
const bounded = boundString(redacted.text);
|
|
1484
|
+
return {
|
|
1485
|
+
text: bounded.text,
|
|
1486
|
+
truncated: bounded.truncated,
|
|
1487
|
+
secretsRedacted: redacted.count
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
case "raw": {
|
|
1491
|
+
const bounded = boundString(original);
|
|
1492
|
+
return { text: bounded.text, truncated: bounded.truncated, secretsRedacted: 0 };
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
const describeText = (input) => {
|
|
1497
|
+
const disclosed = disclose(input.text);
|
|
1498
|
+
return {
|
|
1499
|
+
kind: input.kind,
|
|
1500
|
+
...input.role === void 0 ? {} : { role: input.role },
|
|
1501
|
+
characterLength: codePointLength(input.text),
|
|
1502
|
+
byteLength: Buffer.byteLength(input.text, "utf8"),
|
|
1503
|
+
contentHash: hash(input.text),
|
|
1504
|
+
disclosure: CONTENT_MODE_DISCLOSURE[policy.contentMode],
|
|
1505
|
+
...disclosed.text === void 0 ? {} : { text: disclosed.text },
|
|
1506
|
+
truncated: disclosed.truncated,
|
|
1507
|
+
secretsRedacted: disclosed.secretsRedacted,
|
|
1508
|
+
...input.label === void 0 ? {} : { label: input.label }
|
|
1509
|
+
};
|
|
1510
|
+
};
|
|
1511
|
+
const sanitizeValue = (value, depth, stats, seen) => {
|
|
1512
|
+
if (value === null) {
|
|
1513
|
+
return null;
|
|
1514
|
+
}
|
|
1515
|
+
switch (typeof value) {
|
|
1516
|
+
case "string": {
|
|
1517
|
+
const bounded = boundString(value);
|
|
1518
|
+
if (bounded.truncated) {
|
|
1519
|
+
stats.truncatedStrings += 1;
|
|
1520
|
+
}
|
|
1521
|
+
return bounded.text;
|
|
1522
|
+
}
|
|
1523
|
+
case "number":
|
|
1524
|
+
if (!Number.isFinite(value)) {
|
|
1525
|
+
stats.droppedValues += 1;
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
return value;
|
|
1529
|
+
case "boolean":
|
|
1530
|
+
return value;
|
|
1531
|
+
case "bigint":
|
|
1532
|
+
return value.toString();
|
|
1533
|
+
case "undefined":
|
|
1534
|
+
case "function":
|
|
1535
|
+
case "symbol":
|
|
1536
|
+
stats.droppedValues += 1;
|
|
1537
|
+
return null;
|
|
1538
|
+
default:
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
if (depth >= limits.maxDepth) {
|
|
1542
|
+
stats.depthExceeded += 1;
|
|
1543
|
+
return "<depth-exceeded>";
|
|
1544
|
+
}
|
|
1545
|
+
if (seen.has(value)) {
|
|
1546
|
+
stats.circularReferences += 1;
|
|
1547
|
+
return "<circular>";
|
|
1548
|
+
}
|
|
1549
|
+
seen.add(value);
|
|
1550
|
+
if (Array.isArray(value)) {
|
|
1551
|
+
const entries = value.slice(0, limits.maxArrayLength);
|
|
1552
|
+
if (value.length > limits.maxArrayLength) {
|
|
1553
|
+
stats.truncatedArrays += 1;
|
|
1554
|
+
}
|
|
1555
|
+
return entries.map((entry) => sanitizeValue(entry, depth + 1, stats, seen));
|
|
1556
|
+
}
|
|
1557
|
+
if (value instanceof Date) {
|
|
1558
|
+
return value.toISOString();
|
|
1559
|
+
}
|
|
1560
|
+
const record = value;
|
|
1561
|
+
const keys = Object.keys(record);
|
|
1562
|
+
const retained = keys.slice(0, limits.maxObjectKeys);
|
|
1563
|
+
if (keys.length > limits.maxObjectKeys) {
|
|
1564
|
+
stats.truncatedObjects += 1;
|
|
1565
|
+
}
|
|
1566
|
+
const result = {};
|
|
1567
|
+
for (const key of retained) {
|
|
1568
|
+
if (isSecretKey(key)) {
|
|
1569
|
+
stats.redactedKeys += 1;
|
|
1570
|
+
result[key] = policy.redactionPlaceholder;
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
result[key] = sanitizeValue(record[key], depth + 1, stats, seen);
|
|
1574
|
+
}
|
|
1575
|
+
return result;
|
|
1576
|
+
};
|
|
1577
|
+
const sanitizeStructured = (value) => {
|
|
1578
|
+
const stats = emptyStats();
|
|
1579
|
+
const sanitized = sanitizeValue(value, 0, stats, /* @__PURE__ */ new WeakSet());
|
|
1580
|
+
return { value: sanitized, stats };
|
|
1581
|
+
};
|
|
1582
|
+
const toAttributePrimitive = (value) => {
|
|
1583
|
+
if (typeof value === "string") {
|
|
1584
|
+
return value.slice(0, MAX_ATTRIBUTE_STRING_LENGTH);
|
|
1585
|
+
}
|
|
1586
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
1587
|
+
return value;
|
|
1588
|
+
}
|
|
1589
|
+
return void 0;
|
|
1590
|
+
};
|
|
1591
|
+
const flattenToAttributes = (value, prefix) => {
|
|
1592
|
+
const attributes = {};
|
|
1593
|
+
const walk = (current, path) => {
|
|
1594
|
+
if (typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
|
|
1595
|
+
const primitive = toAttributePrimitive(current);
|
|
1596
|
+
if (primitive !== void 0) {
|
|
1597
|
+
attributes[path] = primitive;
|
|
1598
|
+
}
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
if (current === null) {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
if (isSanitizedArray(current)) {
|
|
1605
|
+
const primitives = [];
|
|
1606
|
+
let uniform = true;
|
|
1607
|
+
for (const entry of current) {
|
|
1608
|
+
const entryPrimitive = toAttributePrimitive(entry);
|
|
1609
|
+
if (entryPrimitive === void 0) {
|
|
1610
|
+
uniform = false;
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
primitives.push(entryPrimitive);
|
|
1614
|
+
}
|
|
1615
|
+
if (uniform) {
|
|
1616
|
+
attributes[path] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
for (const [index, entry] of current.entries()) {
|
|
1620
|
+
walk(entry, `${path}.${index}`);
|
|
1621
|
+
}
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
for (const [key, entry] of Object.entries(current)) {
|
|
1625
|
+
walk(entry, path === "" ? key : `${path}.${key}`);
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
walk(value, prefix);
|
|
1629
|
+
return attributes;
|
|
1630
|
+
};
|
|
1631
|
+
const sanitizeAttributes = (value) => {
|
|
1632
|
+
const attributes = {};
|
|
1633
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1634
|
+
if (isSecretKey(key)) {
|
|
1635
|
+
attributes[key] = policy.redactionPlaceholder;
|
|
1636
|
+
continue;
|
|
1637
|
+
}
|
|
1638
|
+
const sanitized = sanitizeStructured(entry).value;
|
|
1639
|
+
const primitive = toAttributePrimitive(sanitized);
|
|
1640
|
+
if (primitive !== void 0) {
|
|
1641
|
+
attributes[key] = primitive;
|
|
1642
|
+
continue;
|
|
1643
|
+
}
|
|
1644
|
+
const flattened = flattenToAttributes(sanitized, key);
|
|
1645
|
+
Object.assign(attributes, flattened);
|
|
1646
|
+
}
|
|
1647
|
+
return attributes;
|
|
1648
|
+
};
|
|
1649
|
+
const sanitizeExtensions = (value) => {
|
|
1650
|
+
const extensions = {};
|
|
1651
|
+
const droppedKeys = [];
|
|
1652
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1653
|
+
if (!isValidExtensionKey(key)) {
|
|
1654
|
+
droppedKeys.push(key);
|
|
1655
|
+
continue;
|
|
1656
|
+
}
|
|
1657
|
+
if (isSecretKey(key)) {
|
|
1658
|
+
extensions[key] = policy.redactionPlaceholder;
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
const sanitized = sanitizeStructured(entry).value;
|
|
1662
|
+
const candidate = attributeValueSchema.safeParse(sanitized);
|
|
1663
|
+
if (candidate.success) {
|
|
1664
|
+
extensions[key] = candidate.data;
|
|
1665
|
+
} else {
|
|
1666
|
+
droppedKeys.push(key);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
return { extensions, droppedKeys };
|
|
1670
|
+
};
|
|
1671
|
+
return {
|
|
1672
|
+
policy,
|
|
1673
|
+
policyNotes: notes,
|
|
1674
|
+
hash,
|
|
1675
|
+
deriveOpaqueId: (namespace, value) => hash(`${namespace}\0${value}`),
|
|
1676
|
+
describeContent: describeText,
|
|
1677
|
+
describeStructured: (input) => {
|
|
1678
|
+
const serialized = stableStringify(input.value);
|
|
1679
|
+
const sanitized = sanitizeStructured(input.value);
|
|
1680
|
+
const base = describeText({
|
|
1681
|
+
kind: input.kind,
|
|
1682
|
+
text: serialized,
|
|
1683
|
+
...input.role === void 0 ? {} : { role: input.role },
|
|
1684
|
+
...input.label === void 0 ? {} : { label: input.label }
|
|
1685
|
+
});
|
|
1686
|
+
if (base.text === void 0) {
|
|
1687
|
+
return base;
|
|
1688
|
+
}
|
|
1689
|
+
const disclosed = disclose(stableStringify(sanitized.value));
|
|
1690
|
+
return {
|
|
1691
|
+
...base,
|
|
1692
|
+
...disclosed.text === void 0 ? {} : { text: disclosed.text },
|
|
1693
|
+
truncated: base.truncated || disclosed.truncated,
|
|
1694
|
+
secretsRedacted: disclosed.secretsRedacted + sanitized.stats.redactedKeys
|
|
1695
|
+
};
|
|
1696
|
+
},
|
|
1697
|
+
isSecretKey,
|
|
1698
|
+
sanitizeStructured,
|
|
1699
|
+
flattenToAttributes,
|
|
1700
|
+
sanitizeAttributes,
|
|
1701
|
+
sanitizeExtensions,
|
|
1702
|
+
boundString
|
|
1703
|
+
};
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
// src/providers/adapter.ts
|
|
1707
|
+
import { z as z14 } from "zod";
|
|
1708
|
+
|
|
1709
|
+
// src/model/events.ts
|
|
1710
|
+
import { z as z13 } from "zod";
|
|
1711
|
+
var modelDescriptorSchema = z13.strictObject({
|
|
1712
|
+
modelId: nonEmptyStringSchema,
|
|
1713
|
+
/** Vendor of the model, e.g. `anthropic`. Distinct from the agent provider. */
|
|
1714
|
+
vendor: nonEmptyStringSchema.optional(),
|
|
1715
|
+
family: nonEmptyStringSchema.optional()
|
|
1716
|
+
});
|
|
1717
|
+
var costFactsSchema = z13.strictObject({
|
|
1718
|
+
/** ISO 4217 code. */
|
|
1719
|
+
currency: z13.string().length(3),
|
|
1720
|
+
amount: z13.number().min(0).finite(),
|
|
1721
|
+
source: z13.enum(["provider-reported", "computed"])
|
|
1722
|
+
});
|
|
1723
|
+
var canonicalEventTypeSchema = z13.enum([
|
|
1724
|
+
"session.start",
|
|
1725
|
+
"session.end",
|
|
1726
|
+
"prompt.submitted",
|
|
1727
|
+
"generation.start",
|
|
1728
|
+
"generation.end",
|
|
1729
|
+
"tool.start",
|
|
1730
|
+
"tool.end",
|
|
1731
|
+
"subagent.start",
|
|
1732
|
+
"subagent.end",
|
|
1733
|
+
"compaction.performed",
|
|
1734
|
+
"error.raised"
|
|
1735
|
+
]);
|
|
1736
|
+
var CANONICAL_EVENT_TYPES = canonicalEventTypeSchema.options;
|
|
1737
|
+
var outcomeSchema = z13.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
|
|
1738
|
+
var baseEventFields = {
|
|
1739
|
+
schemaVersion: canonicalSchemaVersionSchema,
|
|
1740
|
+
eventId: eventIdSchema,
|
|
1741
|
+
invocationId: invocationIdSchema,
|
|
1742
|
+
sessionId: sessionIdSchema,
|
|
1743
|
+
/** Per-invocation ordering key. Stable across replays of the same input. */
|
|
1744
|
+
sequence: sequenceNumberSchema,
|
|
1745
|
+
occurredAt: epochMillisSchema,
|
|
1746
|
+
provenance: sourceProvenanceSchema,
|
|
1747
|
+
workspace: workspaceIdentitySchema,
|
|
1748
|
+
extensions: extensionsSchema.default(emptyExtensions)
|
|
1749
|
+
};
|
|
1750
|
+
var event = (shape) => z13.strictObject({ ...baseEventFields, ...shape });
|
|
1751
|
+
var sessionStartEventSchema = event({
|
|
1752
|
+
type: z13.literal("session.start"),
|
|
1753
|
+
sessionKind: z13.enum(["interactive", "non-interactive", "unknown"]),
|
|
1754
|
+
agentName: nonEmptyStringSchema.optional(),
|
|
1755
|
+
agentVersion: nonEmptyStringSchema.optional(),
|
|
1756
|
+
model: modelDescriptorSchema.optional()
|
|
1757
|
+
});
|
|
1758
|
+
var sessionEndEventSchema = event({
|
|
1759
|
+
type: z13.literal("session.end"),
|
|
1760
|
+
reason: z13.enum(["completed", "aborted", "error", "timeout", "unknown"]),
|
|
1761
|
+
durationMillis: durationMillisSchema.optional(),
|
|
1762
|
+
/** Session totals, typically cumulative. */
|
|
1763
|
+
usage: canonicalUsageSchema.optional(),
|
|
1764
|
+
cost: costFactsSchema.optional()
|
|
1765
|
+
});
|
|
1766
|
+
var promptSubmittedEventSchema = event({
|
|
1767
|
+
type: z13.literal("prompt.submitted"),
|
|
1768
|
+
promptSource: z13.enum(["user", "automation", "resumed", "unknown"]),
|
|
1769
|
+
content: contentFactSchema.optional(),
|
|
1770
|
+
turnIndex: z13.number().int().min(0).optional()
|
|
1771
|
+
});
|
|
1772
|
+
var generationStartEventSchema = event({
|
|
1773
|
+
type: z13.literal("generation.start"),
|
|
1774
|
+
generationId: nonEmptyStringSchema,
|
|
1775
|
+
model: modelDescriptorSchema,
|
|
1776
|
+
requestedMaxOutputTokens: tokenCountSchema.optional(),
|
|
1777
|
+
inputContent: contentFactsSchema.optional()
|
|
1778
|
+
});
|
|
1779
|
+
var generationEndEventSchema = event({
|
|
1780
|
+
type: z13.literal("generation.end"),
|
|
1781
|
+
generationId: nonEmptyStringSchema,
|
|
1782
|
+
model: modelDescriptorSchema,
|
|
1783
|
+
outcome: outcomeSchema,
|
|
1784
|
+
stopReason: nonEmptyStringSchema.optional(),
|
|
1785
|
+
durationMillis: durationMillisSchema.optional(),
|
|
1786
|
+
usage: canonicalUsageSchema.optional(),
|
|
1787
|
+
cost: costFactsSchema.optional(),
|
|
1788
|
+
outputContent: contentFactsSchema.optional()
|
|
1789
|
+
});
|
|
1790
|
+
var toolKindSchema = z13.enum([
|
|
1791
|
+
"read",
|
|
1792
|
+
"write",
|
|
1793
|
+
"execute",
|
|
1794
|
+
"search",
|
|
1795
|
+
"network",
|
|
1796
|
+
"delegate",
|
|
1797
|
+
"other",
|
|
1798
|
+
"unknown"
|
|
1799
|
+
]);
|
|
1800
|
+
var toolStartEventSchema = event({
|
|
1801
|
+
type: z13.literal("tool.start"),
|
|
1802
|
+
toolCallId: nonEmptyStringSchema,
|
|
1803
|
+
toolName: nonEmptyStringSchema,
|
|
1804
|
+
toolKind: toolKindSchema,
|
|
1805
|
+
generationId: nonEmptyStringSchema.optional(),
|
|
1806
|
+
input: contentFactSchema.optional()
|
|
1807
|
+
});
|
|
1808
|
+
var toolEndEventSchema = event({
|
|
1809
|
+
type: z13.literal("tool.end"),
|
|
1810
|
+
toolCallId: nonEmptyStringSchema,
|
|
1811
|
+
toolName: nonEmptyStringSchema,
|
|
1812
|
+
outcome: outcomeSchema,
|
|
1813
|
+
durationMillis: durationMillisSchema.optional(),
|
|
1814
|
+
/** Present when the host asked for or recorded a permission decision. */
|
|
1815
|
+
permissionDecision: z13.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
|
|
1816
|
+
output: contentFactSchema.optional()
|
|
1817
|
+
});
|
|
1818
|
+
var subagentStartEventSchema = event({
|
|
1819
|
+
type: z13.literal("subagent.start"),
|
|
1820
|
+
subagentInvocationId: invocationIdSchema,
|
|
1821
|
+
subagentType: nonEmptyStringSchema.optional(),
|
|
1822
|
+
/** 0 for the top-level agent; 1 for its direct children. */
|
|
1823
|
+
delegationDepth: z13.number().int().min(0).max(64),
|
|
1824
|
+
model: modelDescriptorSchema.optional()
|
|
1825
|
+
});
|
|
1826
|
+
var subagentEndEventSchema = event({
|
|
1827
|
+
type: z13.literal("subagent.end"),
|
|
1828
|
+
subagentInvocationId: invocationIdSchema,
|
|
1829
|
+
outcome: outcomeSchema,
|
|
1830
|
+
durationMillis: durationMillisSchema.optional(),
|
|
1831
|
+
usage: canonicalUsageSchema.optional()
|
|
1832
|
+
});
|
|
1833
|
+
var compactionPerformedEventSchema = event({
|
|
1834
|
+
type: z13.literal("compaction.performed"),
|
|
1835
|
+
trigger: z13.enum(["automatic", "manual", "unknown"]),
|
|
1836
|
+
/** Provider-reported context size before and after compaction, if known. */
|
|
1837
|
+
contextTokensBefore: tokenCountSchema.optional(),
|
|
1838
|
+
contextTokensAfter: tokenCountSchema.optional(),
|
|
1839
|
+
droppedMessageCount: z13.number().int().min(0).optional(),
|
|
1840
|
+
usage: canonicalUsageSchema.optional()
|
|
1841
|
+
});
|
|
1842
|
+
var errorRaisedEventSchema = event({
|
|
1843
|
+
type: z13.literal("error.raised"),
|
|
1844
|
+
errorCode: otelHookErrorCodeSchema,
|
|
1845
|
+
severity: errorSeveritySchema,
|
|
1846
|
+
phase: errorPhaseSchema,
|
|
1847
|
+
retryable: z13.boolean(),
|
|
1848
|
+
/** Error text is content: it is described, never embedded verbatim by default. */
|
|
1849
|
+
message: contentFactSchema.optional(),
|
|
1850
|
+
/** Non-sensitive, provider-agnostic short label. */
|
|
1851
|
+
detail: nonEmptyStringSchema.optional()
|
|
1852
|
+
});
|
|
1853
|
+
var canonicalEventSchema = z13.discriminatedUnion("type", [
|
|
1854
|
+
sessionStartEventSchema,
|
|
1855
|
+
sessionEndEventSchema,
|
|
1856
|
+
promptSubmittedEventSchema,
|
|
1857
|
+
generationStartEventSchema,
|
|
1858
|
+
generationEndEventSchema,
|
|
1859
|
+
toolStartEventSchema,
|
|
1860
|
+
toolEndEventSchema,
|
|
1861
|
+
subagentStartEventSchema,
|
|
1862
|
+
subagentEndEventSchema,
|
|
1863
|
+
compactionPerformedEventSchema,
|
|
1864
|
+
errorRaisedEventSchema
|
|
1865
|
+
]);
|
|
1866
|
+
|
|
1867
|
+
// src/providers/adapter.ts
|
|
1868
|
+
var providerDetectionSchema = z14.strictObject({
|
|
1869
|
+
providerId: resolvedProviderIdSchema,
|
|
1870
|
+
confidence: detectionConfidenceSchema,
|
|
1871
|
+
/**
|
|
1872
|
+
* Short, non-sensitive justifications, e.g. `"payload.hook_event_name present"`.
|
|
1873
|
+
* Reasons are exported in diagnostics, so they must not quote payload values.
|
|
1874
|
+
*/
|
|
1875
|
+
reasons: z14.array(z14.string().min(1).max(160)).max(8),
|
|
1876
|
+
providerVersion: nonEmptyStringSchema.optional(),
|
|
1877
|
+
/** The provider's own name for this event, when the payload states one. */
|
|
1878
|
+
sourceEventName: nonEmptyStringSchema.optional()
|
|
1879
|
+
});
|
|
1880
|
+
var deliveryIdentifierSupportSchema = z14.enum(["none", "partial", "all"]);
|
|
1881
|
+
var DELIVERY_COMPONENT_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
1882
|
+
var deliveryComponentSchema = z14.string().regex(
|
|
1883
|
+
DELIVERY_COMPONENT_PATTERN,
|
|
1884
|
+
"delivery component must be identifier-shaped: no whitespace, no path separators"
|
|
1885
|
+
);
|
|
1886
|
+
var MAX_DELIVERY_COMPONENTS = 8;
|
|
1887
|
+
var providerDeliveryClaimSchema = z14.strictObject({
|
|
1888
|
+
/**
|
|
1889
|
+
* The provider's own session/conversation id. Scopes the callback identity, so
|
|
1890
|
+
* two sessions reusing one tool-call id never collide.
|
|
1891
|
+
*/
|
|
1892
|
+
sessionId: nonEmptyStringSchema,
|
|
1893
|
+
/** The provider's own name for this callback, e.g. `PostToolUse`. */
|
|
1894
|
+
sourceEventName: deliveryComponentSchema,
|
|
1895
|
+
/**
|
|
1896
|
+
* Identifier-shaped payload fields that, together with `sourceEventName`,
|
|
1897
|
+
* name this callback within the session exactly once.
|
|
1898
|
+
*/
|
|
1899
|
+
components: z14.array(deliveryComponentSchema).min(1).max(MAX_DELIVERY_COMPONENTS).readonly(),
|
|
1900
|
+
/**
|
|
1901
|
+
* Short, non-sensitive justifications, e.g. `"payload.tool_use_id names one
|
|
1902
|
+
* tool call"`. Evidence reaches diagnostics, so it must name fields, never
|
|
1903
|
+
* quote their values.
|
|
1904
|
+
*/
|
|
1905
|
+
evidence: z14.array(z14.string().min(1).max(160)).min(1).max(4).readonly()
|
|
1906
|
+
});
|
|
1907
|
+
var DELIVERY_GAP_REASON_PATTERN = /^[^\n\r\t\\/]{1,240}$/;
|
|
1908
|
+
var deliveryGapReasonSchema = z14.string().regex(
|
|
1909
|
+
DELIVERY_GAP_REASON_PATTERN,
|
|
1910
|
+
"delivery gap reason must be one line of prose: no path separators, no control characters"
|
|
1911
|
+
);
|
|
1912
|
+
var MAX_DELIVERY_GAPS = 48;
|
|
1913
|
+
var providerDeliveryGapsSchema = z14.record(deliveryComponentSchema, deliveryGapReasonSchema).refine((gaps) => Object.keys(gaps).length <= MAX_DELIVERY_GAPS, {
|
|
1914
|
+
message: `at most ${String(MAX_DELIVERY_GAPS)} delivery gaps may be declared`
|
|
1915
|
+
});
|
|
1916
|
+
var providerCapabilitiesSchema = z14.strictObject({
|
|
1917
|
+
/** Event types the adapter can produce. */
|
|
1918
|
+
lifecycleEvents: z14.array(canonicalEventTypeSchema).max(32).readonly(),
|
|
1919
|
+
usageTemporality: usageTemporalitySchema,
|
|
1920
|
+
/**
|
|
1921
|
+
* Which accumulator series a `cumulative` report continues — that is, which
|
|
1922
|
+
* previous snapshot the next one should be diffed against.
|
|
1923
|
+
*
|
|
1924
|
+
* Only meaningful when `usageTemporality` is `cumulative`; omit otherwise.
|
|
1925
|
+
*
|
|
1926
|
+
* - `event-scope` (the default when omitted) — each event scope keeps its own
|
|
1927
|
+
* running total, so a `generation.end` snapshot is diffed against the
|
|
1928
|
+
* previous snapshot *for that same generation*.
|
|
1929
|
+
* - `session-lifetime` — the provider maintains **one** running total for the
|
|
1930
|
+
* whole session and stamps it onto whichever callback happens to report it.
|
|
1931
|
+
* Diffing such a snapshot per event scope would restart the baseline on
|
|
1932
|
+
* every new generation id and re-count the entire session total each turn,
|
|
1933
|
+
* so session-level and generation-level snapshots share one baseline.
|
|
1934
|
+
* Subagent snapshots keep their own series regardless: a delegated agent's
|
|
1935
|
+
* counter is not a point on the parent session's curve.
|
|
1936
|
+
*/
|
|
1937
|
+
cumulativeUsageSeries: z14.enum(["event-scope", "session-lifetime"]).optional(),
|
|
1938
|
+
reportsCachedInput: z14.boolean(),
|
|
1939
|
+
reportsCacheCreation: z14.boolean(),
|
|
1940
|
+
cacheCreationAccounting: cacheCreationAccountingSchema,
|
|
1941
|
+
reportsReasoningOutput: z14.boolean(),
|
|
1942
|
+
reportsProviderTotal: z14.boolean(),
|
|
1943
|
+
reportsCost: z14.boolean(),
|
|
1944
|
+
emitsSubagentEvents: z14.boolean(),
|
|
1945
|
+
emitsCompactionEvents: z14.boolean(),
|
|
1946
|
+
/** True when the provider reads a structured response from stdout. */
|
|
1947
|
+
requiresHookResponse: z14.boolean(),
|
|
1948
|
+
/** How much of this provider's hook traffic is replay-identifiable. */
|
|
1949
|
+
deliveryIdentifier: deliveryIdentifierSupportSchema
|
|
1950
|
+
});
|
|
1951
|
+
var providerHookResponseSchema = z14.strictObject({
|
|
1952
|
+
/**
|
|
1953
|
+
* Always 0. A telemetry hook that can fail the host agent is a liability, so
|
|
1954
|
+
* the type forbids expressing anything else (ADR 0004).
|
|
1955
|
+
*/
|
|
1956
|
+
exitCode: z14.literal(0),
|
|
1957
|
+
/** Protocol response text. Omit to write nothing at all. */
|
|
1958
|
+
stdout: z14.string().max(8192).optional(),
|
|
1959
|
+
/** Non-sensitive diagnostic text for stderr. */
|
|
1960
|
+
stderr: z14.string().max(8192).optional(),
|
|
1961
|
+
/** Declares which of the two stdout contracts this response follows. */
|
|
1962
|
+
contract: z14.enum(["silent", "provider-protocol"])
|
|
1963
|
+
});
|
|
1964
|
+
var SILENT_HOOK_RESPONSE = Object.freeze({
|
|
1965
|
+
exitCode: 0,
|
|
1966
|
+
contract: "silent"
|
|
1967
|
+
});
|
|
1968
|
+
var readDeliveryClaim = (adapter, input, context) => {
|
|
1969
|
+
if (adapter.deliveryIdentity === void 0) {
|
|
1970
|
+
return {};
|
|
1971
|
+
}
|
|
1972
|
+
let candidate;
|
|
1973
|
+
try {
|
|
1974
|
+
candidate = adapter.deliveryIdentity(input, context);
|
|
1975
|
+
} catch {
|
|
1976
|
+
return { rejection: `adapter ${adapter.id} threw while reporting a delivery identity` };
|
|
1977
|
+
}
|
|
1978
|
+
if (candidate === void 0) {
|
|
1979
|
+
return {};
|
|
1980
|
+
}
|
|
1981
|
+
const parsed = providerDeliveryClaimSchema.safeParse(candidate);
|
|
1982
|
+
if (!parsed.success) {
|
|
1983
|
+
return {
|
|
1984
|
+
rejection: `adapter ${adapter.id} reported a malformed delivery identity: ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"} ${issue.message}`).join("; ")}`.slice(0, 240)
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
return { claim: parsed.data };
|
|
1988
|
+
};
|
|
1989
|
+
var readDeliveryGap = (adapter, sourceEventName) => {
|
|
1990
|
+
if (sourceEventName === void 0 || adapter.deliveryGaps === void 0) {
|
|
1991
|
+
return void 0;
|
|
1992
|
+
}
|
|
1993
|
+
if (!Object.prototype.hasOwnProperty.call(adapter.deliveryGaps, sourceEventName)) {
|
|
1994
|
+
return void 0;
|
|
1995
|
+
}
|
|
1996
|
+
const parsed = deliveryGapReasonSchema.safeParse(adapter.deliveryGaps[sourceEventName]);
|
|
1997
|
+
return parsed.success ? parsed.data : void 0;
|
|
1998
|
+
};
|
|
1999
|
+
var unknownDetection = (reasons = ["no adapter recognized the input"]) => providerDetectionSchema.parse({
|
|
2000
|
+
providerId: "unknown",
|
|
2001
|
+
confidence: "none",
|
|
2002
|
+
reasons: reasons.slice(0, 8)
|
|
2003
|
+
});
|
|
2004
|
+
|
|
2005
|
+
// src/providers/registry.ts
|
|
2006
|
+
var createProviderRegistry = (adapters) => {
|
|
2007
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2008
|
+
for (const adapter of adapters) {
|
|
2009
|
+
if (byId.has(adapter.id)) {
|
|
2010
|
+
throw createDuplicateAdapterError(adapter.id);
|
|
2011
|
+
}
|
|
2012
|
+
byId.set(adapter.id, adapter);
|
|
2013
|
+
}
|
|
2014
|
+
const frozen = Object.freeze([...adapters]);
|
|
2015
|
+
return {
|
|
2016
|
+
adapters: frozen,
|
|
2017
|
+
get: (id) => byId.get(id),
|
|
2018
|
+
detect: (input, context, policy) => {
|
|
2019
|
+
const errors = [];
|
|
2020
|
+
const candidates = [];
|
|
2021
|
+
if (frozen.length === 0) {
|
|
2022
|
+
return {
|
|
2023
|
+
status: "unknown",
|
|
2024
|
+
reason: "no-adapters-registered",
|
|
2025
|
+
detection: unknownDetection(["no adapters registered"]),
|
|
2026
|
+
candidates,
|
|
2027
|
+
errors
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
for (const adapter of frozen) {
|
|
2031
|
+
let detection;
|
|
2032
|
+
try {
|
|
2033
|
+
detection = providerDetectionSchema.parse(adapter.detect(input, context));
|
|
2034
|
+
} catch (thrown) {
|
|
2035
|
+
errors.push(errorInfoFromThrown(thrown, { code: "provider-adapter-failure", phase: "detection" }));
|
|
2036
|
+
continue;
|
|
2037
|
+
}
|
|
2038
|
+
if (detection.confidence === "none") {
|
|
2039
|
+
continue;
|
|
2040
|
+
}
|
|
2041
|
+
if (detection.providerId !== adapter.id) {
|
|
2042
|
+
errors.push(
|
|
2043
|
+
createErrorInfo({
|
|
2044
|
+
code: "provider-adapter-failure",
|
|
2045
|
+
phase: "detection",
|
|
2046
|
+
detail: `adapter ${adapter.id} claimed provider id ${detection.providerId}`,
|
|
2047
|
+
details: { "adapter.id": adapter.id, "detection.provider_id": detection.providerId }
|
|
2048
|
+
})
|
|
2049
|
+
);
|
|
2050
|
+
continue;
|
|
2051
|
+
}
|
|
2052
|
+
candidates.push({ adapter, detection });
|
|
2053
|
+
}
|
|
2054
|
+
if (candidates.length === 0) {
|
|
2055
|
+
return {
|
|
2056
|
+
status: "unknown",
|
|
2057
|
+
reason: "no-candidates",
|
|
2058
|
+
detection: unknownDetection(),
|
|
2059
|
+
candidates,
|
|
2060
|
+
errors
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
const bestRank = Math.max(
|
|
2064
|
+
...candidates.map((candidate) => DETECTION_CONFIDENCE_RANK[candidate.detection.confidence])
|
|
2065
|
+
);
|
|
2066
|
+
const best = candidates.filter(
|
|
2067
|
+
(candidate) => DETECTION_CONFIDENCE_RANK[candidate.detection.confidence] === bestRank
|
|
2068
|
+
);
|
|
2069
|
+
if (best.length > 1) {
|
|
2070
|
+
return {
|
|
2071
|
+
status: "ambiguous",
|
|
2072
|
+
detection: unknownDetection([
|
|
2073
|
+
`${best.length} adapters matched at equal confidence`,
|
|
2074
|
+
...best.map((candidate) => `candidate ${candidate.adapter.id}`)
|
|
2075
|
+
]),
|
|
2076
|
+
candidates,
|
|
2077
|
+
errors
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
const [winner] = best;
|
|
2081
|
+
if (winner === void 0) {
|
|
2082
|
+
return {
|
|
2083
|
+
status: "unknown",
|
|
2084
|
+
reason: "no-candidates",
|
|
2085
|
+
detection: unknownDetection(),
|
|
2086
|
+
candidates,
|
|
2087
|
+
errors
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
if (bestRank < DETECTION_CONFIDENCE_RANK[policy.minimumConfidence]) {
|
|
2091
|
+
return {
|
|
2092
|
+
status: "unknown",
|
|
2093
|
+
reason: "below-minimum-confidence",
|
|
2094
|
+
detection: unknownDetection([
|
|
2095
|
+
`best confidence ${winner.detection.confidence} is below required ${policy.minimumConfidence}`
|
|
2096
|
+
]),
|
|
2097
|
+
candidates,
|
|
2098
|
+
errors
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
if (policy.allowedProviderIds.length > 0 && !policy.allowedProviderIds.includes(winner.adapter.id)) {
|
|
2102
|
+
return {
|
|
2103
|
+
status: "unknown",
|
|
2104
|
+
reason: "provider-not-allowed",
|
|
2105
|
+
detection: unknownDetection([`provider ${winner.adapter.id} is not in the allow-list`]),
|
|
2106
|
+
candidates,
|
|
2107
|
+
errors
|
|
2108
|
+
};
|
|
2109
|
+
}
|
|
2110
|
+
return {
|
|
2111
|
+
status: "selected",
|
|
2112
|
+
adapter: winner.adapter,
|
|
2113
|
+
detection: winner.detection,
|
|
2114
|
+
candidates,
|
|
2115
|
+
errors
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
};
|
|
2120
|
+
var createDuplicateAdapterError = (id) => new Error(`duplicate provider adapter id: ${id}`);
|
|
2121
|
+
var BUILT_IN_PROVIDERS = Object.freeze([]);
|
|
2122
|
+
|
|
2123
|
+
// src/state/async-lock.ts
|
|
2124
|
+
var LockWaitTimeoutError = class extends Error {
|
|
2125
|
+
lockKey;
|
|
2126
|
+
constructor(key, timeoutMillis) {
|
|
2127
|
+
super(`lock wait exceeded ${timeoutMillis}ms`);
|
|
2128
|
+
this.name = "LockWaitTimeoutError";
|
|
2129
|
+
this.lockKey = key;
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
|
|
2133
|
+
// src/state/store.ts
|
|
2134
|
+
var StateLockTimeoutError = class extends Error {
|
|
2135
|
+
lockKey;
|
|
2136
|
+
constructor(key, timeoutMillis) {
|
|
2137
|
+
super(`state store lock wait for "${key}" exceeded ${String(timeoutMillis)}ms`);
|
|
2138
|
+
this.name = "StateLockTimeoutError";
|
|
2139
|
+
this.lockKey = key;
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
var isStateLockContention = (thrown) => thrown instanceof StateLockTimeoutError || thrown instanceof LockWaitTimeoutError;
|
|
2143
|
+
var isLockingStateStore = (store) => typeof store.withSessionLock === "function";
|
|
2144
|
+
var withOptionalSessionLock = async (store, sessionId, fn, options) => {
|
|
2145
|
+
if (isLockingStateStore(store)) {
|
|
2146
|
+
return store.withSessionLock(sessionId, fn, options);
|
|
2147
|
+
}
|
|
2148
|
+
return fn();
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
// src/runtime/hook.ts
|
|
2152
|
+
var usageScopeSchema = z15.enum(["session", "generation", "subagent"]);
|
|
2153
|
+
var classifyDurability = (input) => {
|
|
2154
|
+
if (!input.attempted) {
|
|
2155
|
+
return "nothing-to-deliver";
|
|
2156
|
+
}
|
|
2157
|
+
if (input.rejected === 0) {
|
|
2158
|
+
return input.accepted === 0 ? "nothing-to-deliver" : "delivered";
|
|
2159
|
+
}
|
|
2160
|
+
return input.accepted === 0 ? "lost" : "partial";
|
|
2161
|
+
};
|
|
2162
|
+
var isCommittable = (durability) => durability !== "lost";
|
|
2163
|
+
var MAX_ERROR_EVENTS = 8;
|
|
2164
|
+
var collectContentFacts = (event2) => {
|
|
2165
|
+
const facts = [];
|
|
2166
|
+
const push = (fact) => {
|
|
2167
|
+
if (fact !== void 0) {
|
|
2168
|
+
facts.push(fact);
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
switch (event2.type) {
|
|
2172
|
+
case "prompt.submitted":
|
|
2173
|
+
push(event2.content);
|
|
2174
|
+
break;
|
|
2175
|
+
case "generation.start":
|
|
2176
|
+
facts.push(...event2.inputContent ?? []);
|
|
2177
|
+
break;
|
|
2178
|
+
case "generation.end":
|
|
2179
|
+
facts.push(...event2.outputContent ?? []);
|
|
2180
|
+
break;
|
|
2181
|
+
case "tool.start":
|
|
2182
|
+
push(event2.input);
|
|
2183
|
+
break;
|
|
2184
|
+
case "tool.end":
|
|
2185
|
+
push(event2.output);
|
|
2186
|
+
break;
|
|
2187
|
+
case "error.raised":
|
|
2188
|
+
push(event2.message);
|
|
2189
|
+
break;
|
|
2190
|
+
default:
|
|
2191
|
+
break;
|
|
2192
|
+
}
|
|
2193
|
+
return facts;
|
|
2194
|
+
};
|
|
2195
|
+
var usageScopeOf = (event2) => {
|
|
2196
|
+
switch (event2.type) {
|
|
2197
|
+
case "session.end":
|
|
2198
|
+
return event2.usage === void 0 ? void 0 : { scope: "session", scopeKey: event2.sessionId, usage: event2.usage };
|
|
2199
|
+
case "compaction.performed":
|
|
2200
|
+
return event2.usage === void 0 ? void 0 : { scope: "session", scopeKey: event2.sessionId, usage: event2.usage };
|
|
2201
|
+
case "generation.end":
|
|
2202
|
+
return event2.usage === void 0 ? void 0 : { scope: "generation", scopeKey: event2.generationId, usage: event2.usage };
|
|
2203
|
+
case "subagent.end":
|
|
2204
|
+
return event2.usage === void 0 ? void 0 : { scope: "subagent", scopeKey: event2.subagentInvocationId, usage: event2.usage };
|
|
2205
|
+
default:
|
|
2206
|
+
return void 0;
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
var sequenceKey = (sessionId) => `sequence:${sessionId}`;
|
|
2210
|
+
var usageKey = (sessionId, scope, scopeKey) => `usage:${sessionId}:${scope}:${scopeKey}`;
|
|
2211
|
+
var baselineScopeOf = (scope, scopeKey, sessionId, series) => series === "session-lifetime" && scope === "generation" ? { scope: "session", scopeKey: sessionId } : { scope, scopeKey };
|
|
2212
|
+
var createOtelHook = (deps) => {
|
|
2213
|
+
const config = deps.config ?? DEFAULT_CONFIG;
|
|
2214
|
+
const registry = deps.registry ?? createProviderRegistry(BUILT_IN_PROVIDERS);
|
|
2215
|
+
const clock = deps.clock ?? createSystemClock();
|
|
2216
|
+
const ids = deps.ids ?? createDeterministicIdGenerator();
|
|
2217
|
+
const privacy = deps.privacy ?? createPrivacyService(config.privacy);
|
|
2218
|
+
const logger = deps.logger ?? createNullLogger();
|
|
2219
|
+
const installationId = deps.installationId ?? "default";
|
|
2220
|
+
const limits = privacy.policy.limits;
|
|
2221
|
+
const expectedDisclosure = CONTENT_MODE_DISCLOSURE[privacy.policy.contentMode];
|
|
2222
|
+
const providerContext = { privacy, clock, ids, logger, limits };
|
|
2223
|
+
let shutdownCompleted = false;
|
|
2224
|
+
const hookResponseFor = (adapter, detection, attribution, attributionReason, emittedEvents, errors) => {
|
|
2225
|
+
if (adapter === void 0) {
|
|
2226
|
+
return SILENT_HOOK_RESPONSE;
|
|
2227
|
+
}
|
|
2228
|
+
try {
|
|
2229
|
+
return adapter.hookResponse(
|
|
2230
|
+
{
|
|
2231
|
+
attribution,
|
|
2232
|
+
...attributionReason === void 0 ? {} : { attributionReason },
|
|
2233
|
+
...detection === void 0 ? {} : { detection },
|
|
2234
|
+
emittedEvents,
|
|
2235
|
+
errors
|
|
2236
|
+
},
|
|
2237
|
+
providerContext
|
|
2238
|
+
);
|
|
2239
|
+
} catch {
|
|
2240
|
+
return SILENT_HOOK_RESPONSE;
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
const readSequenceBase = async (sessionId, diagnostics) => {
|
|
2244
|
+
try {
|
|
2245
|
+
const record = await deps.stateStore.read(sequenceKey(sessionId));
|
|
2246
|
+
if (record?.value.kind === "sequence") {
|
|
2247
|
+
return record.value.next;
|
|
2248
|
+
}
|
|
2249
|
+
return 0;
|
|
2250
|
+
} catch (thrown) {
|
|
2251
|
+
diagnostics.push(
|
|
2252
|
+
errorInfoFromThrown(thrown, { code: "state-store-failure", phase: "state", occurredAt: clock.now() })
|
|
2253
|
+
);
|
|
2254
|
+
return 0;
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
const deriveUsage = async (events, diagnostics, suppress, series) => {
|
|
2258
|
+
const observations = [];
|
|
2259
|
+
for (const event2 of events) {
|
|
2260
|
+
const scoped = usageScopeOf(event2);
|
|
2261
|
+
if (scoped === void 0) {
|
|
2262
|
+
continue;
|
|
2263
|
+
}
|
|
2264
|
+
if (scoped.usage.temporality === "delta") {
|
|
2265
|
+
observations.push({
|
|
2266
|
+
eventId: event2.eventId,
|
|
2267
|
+
sequence: event2.sequence,
|
|
2268
|
+
scope: scoped.scope,
|
|
2269
|
+
scopeKey: scoped.scopeKey,
|
|
2270
|
+
reportedTemporality: "delta",
|
|
2271
|
+
delta: scoped.usage,
|
|
2272
|
+
resetDetected: false
|
|
2273
|
+
});
|
|
2274
|
+
continue;
|
|
2275
|
+
}
|
|
2276
|
+
const baselineScope = baselineScopeOf(scoped.scope, scoped.scopeKey, event2.sessionId, series);
|
|
2277
|
+
const key = usageKey(event2.sessionId, baselineScope.scope, baselineScope.scopeKey);
|
|
2278
|
+
let baseline;
|
|
2279
|
+
try {
|
|
2280
|
+
const record = await deps.stateStore.read(key);
|
|
2281
|
+
if (record?.value.kind === "usage-cumulative") {
|
|
2282
|
+
baseline = record.value.usage;
|
|
2283
|
+
}
|
|
2284
|
+
} catch (thrown) {
|
|
2285
|
+
diagnostics.push(
|
|
2286
|
+
errorInfoFromThrown(thrown, {
|
|
2287
|
+
code: "state-store-failure",
|
|
2288
|
+
phase: "state",
|
|
2289
|
+
occurredAt: clock.now()
|
|
2290
|
+
})
|
|
2291
|
+
);
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
let delta;
|
|
2295
|
+
let resetDetected = false;
|
|
2296
|
+
if (baseline === void 0) {
|
|
2297
|
+
const normalized = normalizeUsage({ ...toReport(scoped.usage), temporality: "delta" });
|
|
2298
|
+
if (normalized.status === "invalid") {
|
|
2299
|
+
diagnostics.push(
|
|
2300
|
+
createErrorInfo({
|
|
2301
|
+
code: "usage-invalid",
|
|
2302
|
+
phase: "normalization",
|
|
2303
|
+
detail: normalized.issues.map((issue) => issue.message).join("; ").slice(0, 400),
|
|
2304
|
+
details: { "event.id": event2.eventId, "usage.scope": scoped.scope },
|
|
2305
|
+
occurredAt: clock.now()
|
|
2306
|
+
})
|
|
2307
|
+
);
|
|
2308
|
+
continue;
|
|
2309
|
+
}
|
|
2310
|
+
delta = normalized.usage;
|
|
2311
|
+
} else {
|
|
2312
|
+
try {
|
|
2313
|
+
const diffed = cumulativeToDelta(baseline, scoped.usage);
|
|
2314
|
+
delta = diffed.usage;
|
|
2315
|
+
resetDetected = diffed.resetDetected;
|
|
2316
|
+
} catch (thrown) {
|
|
2317
|
+
diagnostics.push(
|
|
2318
|
+
errorInfoFromThrown(thrown, {
|
|
2319
|
+
code: "usage-invalid",
|
|
2320
|
+
phase: "normalization",
|
|
2321
|
+
occurredAt: clock.now()
|
|
2322
|
+
})
|
|
2323
|
+
);
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
try {
|
|
2328
|
+
if (!suppress) {
|
|
2329
|
+
await deps.stateStore.write(key, { kind: "usage-cumulative", usage: scoped.usage });
|
|
2330
|
+
}
|
|
2331
|
+
} catch (thrown) {
|
|
2332
|
+
diagnostics.push(
|
|
2333
|
+
errorInfoFromThrown(thrown, {
|
|
2334
|
+
code: "state-store-failure",
|
|
2335
|
+
phase: "state",
|
|
2336
|
+
occurredAt: clock.now()
|
|
2337
|
+
})
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
observations.push({
|
|
2341
|
+
eventId: event2.eventId,
|
|
2342
|
+
sequence: event2.sequence,
|
|
2343
|
+
scope: scoped.scope,
|
|
2344
|
+
scopeKey: scoped.scopeKey,
|
|
2345
|
+
reportedTemporality: "cumulative",
|
|
2346
|
+
delta,
|
|
2347
|
+
resetDetected
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
return observations;
|
|
2351
|
+
};
|
|
2352
|
+
const screenEvents = (events, identity, sequenceBase, diagnostics) => {
|
|
2353
|
+
const kept = [];
|
|
2354
|
+
let dropped = 0;
|
|
2355
|
+
let expectedSequence = sequenceBase;
|
|
2356
|
+
for (const event2 of events) {
|
|
2357
|
+
const reject = (code, detail) => {
|
|
2358
|
+
dropped += 1;
|
|
2359
|
+
diagnostics.push(
|
|
2360
|
+
createErrorInfo({
|
|
2361
|
+
code,
|
|
2362
|
+
phase: code === "privacy-policy-violation" ? "privacy" : "parsing",
|
|
2363
|
+
detail,
|
|
2364
|
+
details: { "event.type": event2.type, "event.sequence": event2.sequence },
|
|
2365
|
+
occurredAt: clock.now()
|
|
2366
|
+
})
|
|
2367
|
+
);
|
|
2368
|
+
};
|
|
2369
|
+
if (kept.length >= limits.maxEventsPerInvocation) {
|
|
2370
|
+
reject("limit-exceeded", `event dropped: maxEventsPerInvocation=${limits.maxEventsPerInvocation}`);
|
|
2371
|
+
continue;
|
|
2372
|
+
}
|
|
2373
|
+
if (event2.schemaVersion !== CANONICAL_SCHEMA_VERSION) {
|
|
2374
|
+
reject("schema-validation-failed", "event carries an unexpected schema version");
|
|
2375
|
+
continue;
|
|
2376
|
+
}
|
|
2377
|
+
if (event2.invocationId !== identity.invocationId || event2.sessionId !== identity.sessionId) {
|
|
2378
|
+
reject("schema-validation-failed", "event identity does not match the resolved invocation");
|
|
2379
|
+
continue;
|
|
2380
|
+
}
|
|
2381
|
+
if (event2.provenance.providerId !== identity.provenance.providerId) {
|
|
2382
|
+
reject("schema-validation-failed", "event provenance does not match the detected provider");
|
|
2383
|
+
continue;
|
|
2384
|
+
}
|
|
2385
|
+
if (event2.sequence !== expectedSequence) {
|
|
2386
|
+
reject(
|
|
2387
|
+
"schema-validation-failed",
|
|
2388
|
+
`event sequence ${event2.sequence} is not consecutive from ${expectedSequence}`
|
|
2389
|
+
);
|
|
2390
|
+
continue;
|
|
2391
|
+
}
|
|
2392
|
+
const facts = collectContentFacts(event2);
|
|
2393
|
+
const offending = facts.find(
|
|
2394
|
+
(fact) => fact.disclosure !== expectedDisclosure || !isContentFactConsistent(fact)
|
|
2395
|
+
);
|
|
2396
|
+
if (offending !== void 0) {
|
|
2397
|
+
reject(
|
|
2398
|
+
"privacy-policy-violation",
|
|
2399
|
+
`content fact disclosure ${offending.disclosure} violates policy ${expectedDisclosure}`
|
|
2400
|
+
);
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
expectedSequence += 1;
|
|
2404
|
+
kept.push(event2);
|
|
2405
|
+
}
|
|
2406
|
+
return { kept, dropped };
|
|
2407
|
+
};
|
|
2408
|
+
const detectionInputFor = (input) => ({
|
|
2409
|
+
payload: input.payload,
|
|
2410
|
+
transport: input.transport,
|
|
2411
|
+
environment: input.environment ?? {},
|
|
2412
|
+
...input.providerHint === void 0 ? {} : { providerHint: input.providerHint }
|
|
2413
|
+
});
|
|
2414
|
+
const resolveDelivery = (input) => {
|
|
2415
|
+
let detected;
|
|
2416
|
+
try {
|
|
2417
|
+
detected = registry.detect(detectionInputFor(input), providerContext, config.detection);
|
|
2418
|
+
} catch {
|
|
2419
|
+
return { status: "unavailable", reason: "provider-unattributed" };
|
|
2420
|
+
}
|
|
2421
|
+
if (detected.status !== "selected") {
|
|
2422
|
+
return { status: "unavailable", reason: "provider-unattributed" };
|
|
2423
|
+
}
|
|
2424
|
+
const { adapter, detection } = detected;
|
|
2425
|
+
const capability = adapter.capabilities.deliveryIdentifier;
|
|
2426
|
+
const named = {
|
|
2427
|
+
providerId: detection.providerId,
|
|
2428
|
+
capability,
|
|
2429
|
+
...detection.sourceEventName === void 0 ? {} : { sourceEventName: detection.sourceEventName }
|
|
2430
|
+
};
|
|
2431
|
+
const gap = readDeliveryGap(adapter, detection.sourceEventName);
|
|
2432
|
+
if (capability === "none") {
|
|
2433
|
+
return {
|
|
2434
|
+
status: "unavailable",
|
|
2435
|
+
reason: "provider-declares-none",
|
|
2436
|
+
...named,
|
|
2437
|
+
...gap === void 0 ? {} : { detail: gap }
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
const read = readDeliveryClaim(adapter, { ...detectionInputFor(input), detection }, providerContext);
|
|
2441
|
+
if (read.rejection !== void 0) {
|
|
2442
|
+
return {
|
|
2443
|
+
status: "unavailable",
|
|
2444
|
+
reason: "claim-rejected",
|
|
2445
|
+
...named,
|
|
2446
|
+
detail: read.rejection
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
if (read.claim === void 0) {
|
|
2450
|
+
return {
|
|
2451
|
+
status: "unavailable",
|
|
2452
|
+
reason: "callback-not-identifiable",
|
|
2453
|
+
...named,
|
|
2454
|
+
...gap === void 0 ? {} : { detail: gap }
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
return {
|
|
2458
|
+
status: "resolved",
|
|
2459
|
+
identity: resolveDeliveryIdentity({
|
|
2460
|
+
ids,
|
|
2461
|
+
providerId: detection.providerId,
|
|
2462
|
+
installationId,
|
|
2463
|
+
claim: read.claim
|
|
2464
|
+
})
|
|
2465
|
+
};
|
|
2466
|
+
};
|
|
2467
|
+
const ingest = async (input, ingestOptions) => {
|
|
2468
|
+
const suppress = ingestOptions?.suppress === true;
|
|
2469
|
+
const diagnostics = [];
|
|
2470
|
+
const environment = input.environment ?? {};
|
|
2471
|
+
const detectionInput = {
|
|
2472
|
+
payload: input.payload,
|
|
2473
|
+
transport: input.transport,
|
|
2474
|
+
environment,
|
|
2475
|
+
...input.providerHint === void 0 ? {} : { providerHint: input.providerHint }
|
|
2476
|
+
};
|
|
2477
|
+
try {
|
|
2478
|
+
const detected = registry.detect(detectionInput, providerContext, config.detection);
|
|
2479
|
+
diagnostics.push(...detected.errors);
|
|
2480
|
+
if (detected.status !== "selected") {
|
|
2481
|
+
const reason = detected.status === "ambiguous" ? "provider-detection-ambiguous" : "provider-unknown";
|
|
2482
|
+
diagnostics.push(
|
|
2483
|
+
createErrorInfo({
|
|
2484
|
+
code: detected.status === "ambiguous" ? "provider-detection-ambiguous" : "provider-unknown",
|
|
2485
|
+
phase: "detection",
|
|
2486
|
+
detail: detected.detection.reasons.join("; ").slice(0, 400),
|
|
2487
|
+
details: { "detection.candidates": detected.candidates.length },
|
|
2488
|
+
occurredAt: clock.now()
|
|
2489
|
+
})
|
|
2490
|
+
);
|
|
2491
|
+
logger.warn("provider not attributed", {
|
|
2492
|
+
"detection.status": detected.status,
|
|
2493
|
+
"detection.candidates": detected.candidates.length
|
|
2494
|
+
});
|
|
2495
|
+
return {
|
|
2496
|
+
ok: true,
|
|
2497
|
+
attribution: "declined",
|
|
2498
|
+
attributionReason: reason,
|
|
2499
|
+
providerId: "unknown",
|
|
2500
|
+
detectionConfidence: detected.detection.confidence,
|
|
2501
|
+
events: [],
|
|
2502
|
+
usageObservations: [],
|
|
2503
|
+
emitted: 0,
|
|
2504
|
+
exportRejected: 0,
|
|
2505
|
+
durability: "nothing-to-deliver",
|
|
2506
|
+
dropped: 0,
|
|
2507
|
+
hookResponse: SILENT_HOOK_RESPONSE,
|
|
2508
|
+
diagnostics
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
const { adapter, detection } = detected;
|
|
2512
|
+
const provenance = sourceProvenanceSchema.parse({
|
|
2513
|
+
providerId: detection.providerId,
|
|
2514
|
+
...detection.providerVersion === void 0 ? {} : { providerVersion: detection.providerVersion },
|
|
2515
|
+
adapterId: adapter.id,
|
|
2516
|
+
adapterVersion: adapter.version,
|
|
2517
|
+
detectionConfidence: detection.confidence,
|
|
2518
|
+
...detection.sourceEventName === void 0 ? {} : { sourceEventName: detection.sourceEventName },
|
|
2519
|
+
transport: input.transport
|
|
2520
|
+
});
|
|
2521
|
+
let adapterClaims = [];
|
|
2522
|
+
try {
|
|
2523
|
+
adapterClaims = adapter.identify({ ...detectionInput, detection }, providerContext);
|
|
2524
|
+
} catch (thrown) {
|
|
2525
|
+
diagnostics.push(
|
|
2526
|
+
errorInfoFromThrown(thrown, {
|
|
2527
|
+
code: "provider-adapter-failure",
|
|
2528
|
+
phase: "identity",
|
|
2529
|
+
occurredAt: clock.now()
|
|
2530
|
+
})
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
const resolution = resolveInvocationIdentity({
|
|
2534
|
+
claims: [...adapterClaims, ...input.identityClaims ?? []],
|
|
2535
|
+
provenance,
|
|
2536
|
+
fallback: {
|
|
2537
|
+
startedAt: clock.now(),
|
|
2538
|
+
workspace: input.workspace ?? unknownWorkspaceIdentity()
|
|
2539
|
+
},
|
|
2540
|
+
consumerAttributes: privacy.sanitizeAttributes(input.consumerAttributes ?? {})
|
|
2541
|
+
});
|
|
2542
|
+
if (resolution.status !== "resolved") {
|
|
2543
|
+
const reason = resolution.status === "conflict" ? "identity-conflict" : "identity-incomplete";
|
|
2544
|
+
const detail = resolution.status === "conflict" ? `conflicting fields: ${resolution.conflicts.map((conflict) => conflict.field).join(", ")}` : resolution.status === "incomplete" ? `missing fields: ${resolution.missing.join(", ")}` : `invalid claims: ${resolution.issues.join("; ")}`;
|
|
2545
|
+
diagnostics.push(
|
|
2546
|
+
createErrorInfo({
|
|
2547
|
+
code: resolution.status === "conflict" ? "identity-conflict" : "identity-incomplete",
|
|
2548
|
+
phase: "identity",
|
|
2549
|
+
detail: detail.slice(0, 400),
|
|
2550
|
+
details: { "provider.id": detection.providerId },
|
|
2551
|
+
occurredAt: clock.now()
|
|
2552
|
+
})
|
|
2553
|
+
);
|
|
2554
|
+
logger.warn("attribution declined", {
|
|
2555
|
+
"identity.status": resolution.status,
|
|
2556
|
+
"provider.id": detection.providerId
|
|
2557
|
+
});
|
|
2558
|
+
return {
|
|
2559
|
+
ok: true,
|
|
2560
|
+
attribution: "declined",
|
|
2561
|
+
attributionReason: reason,
|
|
2562
|
+
providerId: detection.providerId,
|
|
2563
|
+
detectionConfidence: detection.confidence,
|
|
2564
|
+
events: [],
|
|
2565
|
+
usageObservations: [],
|
|
2566
|
+
emitted: 0,
|
|
2567
|
+
exportRejected: 0,
|
|
2568
|
+
durability: "nothing-to-deliver",
|
|
2569
|
+
dropped: 0,
|
|
2570
|
+
hookResponse: hookResponseFor(adapter, detection, "declined", reason, 0, diagnostics),
|
|
2571
|
+
diagnostics
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
const identity = resolution.identity;
|
|
2575
|
+
const prepare = async () => {
|
|
2576
|
+
const sequenceBase = await readSequenceBase(identity.sessionId, diagnostics);
|
|
2577
|
+
let parsed;
|
|
2578
|
+
try {
|
|
2579
|
+
parsed = adapter.parse(
|
|
2580
|
+
{ ...detectionInput, detection, identity, sequenceBase },
|
|
2581
|
+
providerContext
|
|
2582
|
+
);
|
|
2583
|
+
} catch (thrown) {
|
|
2584
|
+
const info = errorInfoFromThrown(thrown, {
|
|
2585
|
+
code: "provider-adapter-failure",
|
|
2586
|
+
phase: "parsing",
|
|
2587
|
+
occurredAt: clock.now()
|
|
2588
|
+
});
|
|
2589
|
+
diagnostics.push(info);
|
|
2590
|
+
return {
|
|
2591
|
+
kind: "early",
|
|
2592
|
+
outcome: {
|
|
2593
|
+
ok: true,
|
|
2594
|
+
attribution: "failed",
|
|
2595
|
+
attributionReason: "adapter-failure",
|
|
2596
|
+
providerId: detection.providerId,
|
|
2597
|
+
detectionConfidence: detection.confidence,
|
|
2598
|
+
identity,
|
|
2599
|
+
events: [],
|
|
2600
|
+
usageObservations: [],
|
|
2601
|
+
emitted: 0,
|
|
2602
|
+
exportRejected: 0,
|
|
2603
|
+
durability: "nothing-to-deliver",
|
|
2604
|
+
dropped: 0,
|
|
2605
|
+
hookResponse: hookResponseFor(adapter, detection, "failed", "adapter-failure", 0, diagnostics),
|
|
2606
|
+
diagnostics
|
|
2607
|
+
}
|
|
2608
|
+
};
|
|
2609
|
+
}
|
|
2610
|
+
if (parsed.status === "ignored") {
|
|
2611
|
+
logger.debug("adapter ignored input", {
|
|
2612
|
+
"provider.id": detection.providerId,
|
|
2613
|
+
"adapter.reason": parsed.reason.slice(0, 160)
|
|
2614
|
+
});
|
|
2615
|
+
return {
|
|
2616
|
+
kind: "early",
|
|
2617
|
+
outcome: {
|
|
2618
|
+
ok: true,
|
|
2619
|
+
attribution: "not-applicable",
|
|
2620
|
+
attributionReason: "adapter-ignored-input",
|
|
2621
|
+
providerId: detection.providerId,
|
|
2622
|
+
detectionConfidence: detection.confidence,
|
|
2623
|
+
identity,
|
|
2624
|
+
events: [],
|
|
2625
|
+
usageObservations: [],
|
|
2626
|
+
emitted: 0,
|
|
2627
|
+
exportRejected: 0,
|
|
2628
|
+
durability: "nothing-to-deliver",
|
|
2629
|
+
dropped: 0,
|
|
2630
|
+
hookResponse: hookResponseFor(
|
|
2631
|
+
adapter,
|
|
2632
|
+
detection,
|
|
2633
|
+
"not-applicable",
|
|
2634
|
+
"adapter-ignored-input",
|
|
2635
|
+
0,
|
|
2636
|
+
diagnostics
|
|
2637
|
+
),
|
|
2638
|
+
diagnostics
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
}
|
|
2642
|
+
if (parsed.status === "failed") {
|
|
2643
|
+
diagnostics.push(parsed.error);
|
|
2644
|
+
return {
|
|
2645
|
+
kind: "early",
|
|
2646
|
+
outcome: {
|
|
2647
|
+
ok: true,
|
|
2648
|
+
attribution: "failed",
|
|
2649
|
+
attributionReason: "adapter-failure",
|
|
2650
|
+
providerId: detection.providerId,
|
|
2651
|
+
detectionConfidence: detection.confidence,
|
|
2652
|
+
identity,
|
|
2653
|
+
events: [],
|
|
2654
|
+
usageObservations: [],
|
|
2655
|
+
emitted: 0,
|
|
2656
|
+
exportRejected: 0,
|
|
2657
|
+
durability: "nothing-to-deliver",
|
|
2658
|
+
dropped: 0,
|
|
2659
|
+
hookResponse: hookResponseFor(adapter, detection, "failed", "adapter-failure", 0, diagnostics),
|
|
2660
|
+
diagnostics
|
|
2661
|
+
}
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
if (parsed.warnings !== void 0 && parsed.warnings.length > 0) {
|
|
2665
|
+
logger.warn("adapter declined part of the payload it understood", {
|
|
2666
|
+
"provider.id": detection.providerId,
|
|
2667
|
+
"adapter.warnings": parsed.warnings.slice(0, 8).map((warning) => warning.slice(0, 200))
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
const screened = screenEvents(parsed.events, identity, sequenceBase, diagnostics);
|
|
2671
|
+
let batch2 = screened.kept;
|
|
2672
|
+
if (config.diagnostics.emitErrorEvents && diagnostics.length > 0) {
|
|
2673
|
+
batch2 = [...batch2, ...buildErrorEvents(diagnostics, identity, sequenceBase + batch2.length, ids, privacy)];
|
|
2674
|
+
}
|
|
2675
|
+
if (!suppress) {
|
|
2676
|
+
try {
|
|
2677
|
+
await deps.stateStore.write(sequenceKey(identity.sessionId), {
|
|
2678
|
+
kind: "sequence",
|
|
2679
|
+
next: sequenceBase + batch2.length
|
|
2680
|
+
});
|
|
2681
|
+
} catch (thrown) {
|
|
2682
|
+
diagnostics.push(
|
|
2683
|
+
errorInfoFromThrown(thrown, {
|
|
2684
|
+
code: "state-store-failure",
|
|
2685
|
+
phase: "state",
|
|
2686
|
+
occurredAt: clock.now()
|
|
2687
|
+
})
|
|
2688
|
+
);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
return { kind: "ready", batch: batch2, dropped: screened.dropped };
|
|
2692
|
+
};
|
|
2693
|
+
let prepared;
|
|
2694
|
+
try {
|
|
2695
|
+
prepared = await withOptionalSessionLock(deps.stateStore, identity.sessionId, prepare);
|
|
2696
|
+
} catch (thrown) {
|
|
2697
|
+
diagnostics.push(
|
|
2698
|
+
errorInfoFromThrown(thrown, {
|
|
2699
|
+
code: "state-store-failure",
|
|
2700
|
+
phase: "state",
|
|
2701
|
+
occurredAt: clock.now()
|
|
2702
|
+
})
|
|
2703
|
+
);
|
|
2704
|
+
if (!isStateLockContention(thrown)) {
|
|
2705
|
+
logger.warn("state store unusable; processing without session serialization", {
|
|
2706
|
+
"provider.id": detection.providerId
|
|
2707
|
+
});
|
|
2708
|
+
prepared = await prepare();
|
|
2709
|
+
} else {
|
|
2710
|
+
logger.warn("session state lock contended; observation declined for retry", {
|
|
2711
|
+
"provider.id": detection.providerId
|
|
2712
|
+
});
|
|
2713
|
+
return {
|
|
2714
|
+
ok: true,
|
|
2715
|
+
attribution: "failed",
|
|
2716
|
+
attributionReason: "internal-error",
|
|
2717
|
+
providerId: detection.providerId,
|
|
2718
|
+
detectionConfidence: detection.confidence,
|
|
2719
|
+
identity,
|
|
2720
|
+
events: [],
|
|
2721
|
+
usageObservations: [],
|
|
2722
|
+
emitted: 0,
|
|
2723
|
+
// Nothing was exported, nothing was reserved, and nothing is on disk,
|
|
2724
|
+
// so the caller must see this as a total loss and retry it.
|
|
2725
|
+
exportRejected: 1,
|
|
2726
|
+
durability: "lost",
|
|
2727
|
+
dropped: 0,
|
|
2728
|
+
hookResponse: hookResponseFor(adapter, detection, "failed", "internal-error", 0, diagnostics),
|
|
2729
|
+
diagnostics
|
|
2730
|
+
};
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
if (prepared.kind === "early") {
|
|
2734
|
+
return prepared.outcome;
|
|
2735
|
+
}
|
|
2736
|
+
const { batch, dropped } = prepared;
|
|
2737
|
+
let emitted = 0;
|
|
2738
|
+
let exportRejected = 0;
|
|
2739
|
+
if (!suppress && batch.length > 0) {
|
|
2740
|
+
try {
|
|
2741
|
+
const result = await deps.sink.emit(batch);
|
|
2742
|
+
emitted = result.accepted;
|
|
2743
|
+
exportRejected = result.rejected;
|
|
2744
|
+
diagnostics.push(...result.errors);
|
|
2745
|
+
} catch (thrown) {
|
|
2746
|
+
exportRejected = batch.length;
|
|
2747
|
+
diagnostics.push(
|
|
2748
|
+
errorInfoFromThrown(thrown, {
|
|
2749
|
+
code: "telemetry-export-failure",
|
|
2750
|
+
phase: "export",
|
|
2751
|
+
occurredAt: clock.now()
|
|
2752
|
+
})
|
|
2753
|
+
);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
const durability = classifyDurability({
|
|
2757
|
+
attempted: !suppress && batch.length > 0,
|
|
2758
|
+
accepted: emitted,
|
|
2759
|
+
rejected: exportRejected
|
|
2760
|
+
});
|
|
2761
|
+
let usageObservations = [];
|
|
2762
|
+
if (durability !== "lost" && !suppress && batch.length > 0) {
|
|
2763
|
+
try {
|
|
2764
|
+
usageObservations = await withOptionalSessionLock(
|
|
2765
|
+
deps.stateStore,
|
|
2766
|
+
identity.sessionId,
|
|
2767
|
+
() => deriveUsage(
|
|
2768
|
+
batch,
|
|
2769
|
+
diagnostics,
|
|
2770
|
+
false,
|
|
2771
|
+
adapter.capabilities.cumulativeUsageSeries ?? "event-scope"
|
|
2772
|
+
)
|
|
2773
|
+
);
|
|
2774
|
+
} catch (thrown) {
|
|
2775
|
+
diagnostics.push(
|
|
2776
|
+
errorInfoFromThrown(thrown, {
|
|
2777
|
+
code: "state-store-failure",
|
|
2778
|
+
phase: "state",
|
|
2779
|
+
occurredAt: clock.now()
|
|
2780
|
+
})
|
|
2781
|
+
);
|
|
2782
|
+
logger.warn("usage accounting could not be committed for a delivered callback", {
|
|
2783
|
+
"provider.id": detection.providerId
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
return {
|
|
2788
|
+
ok: true,
|
|
2789
|
+
attribution: "attributed",
|
|
2790
|
+
providerId: detection.providerId,
|
|
2791
|
+
detectionConfidence: detection.confidence,
|
|
2792
|
+
identity,
|
|
2793
|
+
events: batch,
|
|
2794
|
+
usageObservations,
|
|
2795
|
+
emitted,
|
|
2796
|
+
exportRejected,
|
|
2797
|
+
durability,
|
|
2798
|
+
dropped,
|
|
2799
|
+
hookResponse: hookResponseFor(adapter, detection, "attributed", void 0, emitted, diagnostics),
|
|
2800
|
+
diagnostics
|
|
2801
|
+
};
|
|
2802
|
+
} catch (thrown) {
|
|
2803
|
+
const info = errorInfoFromThrown(thrown, { code: "internal-error", phase: "parsing" });
|
|
2804
|
+
diagnostics.push(info);
|
|
2805
|
+
logger.error("ingest contained an unexpected failure", {
|
|
2806
|
+
"error.code": info.code,
|
|
2807
|
+
...info.details ?? {}
|
|
2808
|
+
});
|
|
2809
|
+
return {
|
|
2810
|
+
ok: true,
|
|
2811
|
+
attribution: "failed",
|
|
2812
|
+
attributionReason: "internal-error",
|
|
2813
|
+
providerId: "unknown",
|
|
2814
|
+
detectionConfidence: "none",
|
|
2815
|
+
events: [],
|
|
2816
|
+
usageObservations: [],
|
|
2817
|
+
emitted: 0,
|
|
2818
|
+
exportRejected: 0,
|
|
2819
|
+
durability: "nothing-to-deliver",
|
|
2820
|
+
dropped: 0,
|
|
2821
|
+
hookResponse: SILENT_HOOK_RESPONSE,
|
|
2822
|
+
diagnostics
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2826
|
+
const flush = async () => {
|
|
2827
|
+
try {
|
|
2828
|
+
await deps.sink.flush();
|
|
2829
|
+
} catch (thrown) {
|
|
2830
|
+
const info = errorInfoFromThrown(thrown, { code: "telemetry-export-failure", phase: "export" });
|
|
2831
|
+
logger.warn("flush failed", { "error.code": info.code });
|
|
2832
|
+
}
|
|
2833
|
+
};
|
|
2834
|
+
const shutdown = async () => {
|
|
2835
|
+
if (shutdownCompleted) {
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
shutdownCompleted = true;
|
|
2839
|
+
await flush();
|
|
2840
|
+
try {
|
|
2841
|
+
await deps.sink.shutdown();
|
|
2842
|
+
} catch (thrown) {
|
|
2843
|
+
const info = errorInfoFromThrown(thrown, {
|
|
2844
|
+
code: "telemetry-export-failure",
|
|
2845
|
+
phase: "shutdown"
|
|
2846
|
+
});
|
|
2847
|
+
logger.warn("shutdown failed", { "error.code": info.code });
|
|
2848
|
+
}
|
|
2849
|
+
};
|
|
2850
|
+
return { resolveDelivery, ingest, flush, shutdown, config };
|
|
2851
|
+
};
|
|
2852
|
+
var buildErrorEvents = (diagnostics, identity, sequenceBase, ids, privacy) => {
|
|
2853
|
+
const events = [];
|
|
2854
|
+
for (const [index, info] of diagnostics.slice(0, MAX_ERROR_EVENTS).entries()) {
|
|
2855
|
+
const sequence = sequenceBase + index;
|
|
2856
|
+
events.push({
|
|
2857
|
+
schemaVersion: CANONICAL_SCHEMA_VERSION,
|
|
2858
|
+
eventId: ids.newEventId({
|
|
2859
|
+
invocationId: identity.invocationId,
|
|
2860
|
+
sequence,
|
|
2861
|
+
eventType: "error.raised",
|
|
2862
|
+
discriminator: info.code
|
|
2863
|
+
}),
|
|
2864
|
+
invocationId: identity.invocationId,
|
|
2865
|
+
sessionId: identity.sessionId,
|
|
2866
|
+
sequence,
|
|
2867
|
+
occurredAt: info.occurredAt ?? identity.startedAt,
|
|
2868
|
+
provenance: identity.provenance,
|
|
2869
|
+
workspace: identity.workspace,
|
|
2870
|
+
extensions: {},
|
|
2871
|
+
type: "error.raised",
|
|
2872
|
+
errorCode: info.code,
|
|
2873
|
+
severity: info.severity,
|
|
2874
|
+
phase: info.phase,
|
|
2875
|
+
retryable: info.retryable,
|
|
2876
|
+
// The message is already a fixed-vocabulary summary, but it still passes
|
|
2877
|
+
// through the privacy service so one policy governs every disclosure.
|
|
2878
|
+
message: privacy.describeContent({ kind: "error-message", text: info.message }),
|
|
2879
|
+
detail: info.code
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
return events;
|
|
2883
|
+
};
|
|
2884
|
+
export {
|
|
2885
|
+
LOG_LEVEL_RANK,
|
|
2886
|
+
appliedDeliverySchema,
|
|
2887
|
+
classifyDurability,
|
|
2888
|
+
createDeterministicIdGenerator,
|
|
2889
|
+
createFixedClock,
|
|
2890
|
+
createInMemoryStateStore,
|
|
2891
|
+
createNullLogger,
|
|
2892
|
+
createNullTelemetrySink,
|
|
2893
|
+
createOtelHook,
|
|
2894
|
+
createRandomIdGenerator,
|
|
2895
|
+
createRecordingLogger,
|
|
2896
|
+
createRecordingTelemetrySink,
|
|
2897
|
+
createStderrLogger,
|
|
2898
|
+
createSystemClock,
|
|
2899
|
+
hostDeliveryIdentity,
|
|
2900
|
+
isCommittable,
|
|
2901
|
+
logLevelSchema,
|
|
2902
|
+
resolveDeliveryIdentity,
|
|
2903
|
+
stateRecordSchema,
|
|
2904
|
+
stateValueSchema,
|
|
2905
|
+
usageScopeSchema
|
|
2906
|
+
};
|
|
2907
|
+
//# sourceMappingURL=runtime.js.map
|