@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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1020 -0
  3. package/dist/adapter-DIgRACtL.d.ts +303 -0
  4. package/dist/cli.js +12607 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config.d.ts +233 -0
  7. package/dist/config.js +996 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/content-CoB7aNP1.d.ts +118 -0
  10. package/dist/diagnostics.d.ts +58 -0
  11. package/dist/diagnostics.js +46 -0
  12. package/dist/diagnostics.js.map +1 -0
  13. package/dist/errors.d.ts +91 -0
  14. package/dist/errors.js +322 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/events-VxBnDFaO.d.ts +2044 -0
  17. package/dist/filesystem-store-J8jjDMTh.d.ts +65 -0
  18. package/dist/hook-CGpo-vks.d.ts +292 -0
  19. package/dist/identity-BrVBs901.d.ts +227 -0
  20. package/dist/index.d.ts +44 -0
  21. package/dist/index.js +11798 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/install.d.ts +1021 -0
  24. package/dist/install.js +3271 -0
  25. package/dist/install.js.map +1 -0
  26. package/dist/integration.d.ts +303 -0
  27. package/dist/integration.js +5942 -0
  28. package/dist/integration.js.map +1 -0
  29. package/dist/keys-Dej5bN3L.d.ts +7 -0
  30. package/dist/lifecycle.d.ts +428 -0
  31. package/dist/lifecycle.js +1077 -0
  32. package/dist/lifecycle.js.map +1 -0
  33. package/dist/memory-DXVBc8V9.d.ts +94 -0
  34. package/dist/model.d.ts +45 -0
  35. package/dist/model.js +1023 -0
  36. package/dist/model.js.map +1 -0
  37. package/dist/otlp-log-sink-CeIFDDpn.d.ts +457 -0
  38. package/dist/payload-CHr53E_v.d.ts +201 -0
  39. package/dist/policy-D1CrlYn3.d.ts +73 -0
  40. package/dist/ports-Q8x0ODhs.d.ts +200 -0
  41. package/dist/primitives-CJ8-rn-f.d.ts +75 -0
  42. package/dist/privacy.d.ts +51 -0
  43. package/dist/privacy.js +633 -0
  44. package/dist/privacy.js.map +1 -0
  45. package/dist/providers.d.ts +257 -0
  46. package/dist/providers.js +4398 -0
  47. package/dist/providers.js.map +1 -0
  48. package/dist/registry-BzYmC9OC.d.ts +49 -0
  49. package/dist/runtime.d.ts +32 -0
  50. package/dist/runtime.js +2907 -0
  51. package/dist/runtime.js.map +1 -0
  52. package/dist/schema-Cn0-xz8L.d.ts +224 -0
  53. package/dist/semconv-Baoz-0OI.d.ts +188 -0
  54. package/dist/service-j4jEO6cZ.d.ts +68 -0
  55. package/dist/state.d.ts +36 -0
  56. package/dist/state.js +710 -0
  57. package/dist/state.js.map +1 -0
  58. package/dist/taxonomy-DwhTtuWd.d.ts +87 -0
  59. package/dist/telemetry.d.ts +77 -0
  60. package/dist/telemetry.js +2294 -0
  61. package/dist/telemetry.js.map +1 -0
  62. package/dist/testing.d.ts +155 -0
  63. package/dist/testing.js +6513 -0
  64. package/dist/testing.js.map +1 -0
  65. package/package.json +124 -0
@@ -0,0 +1,303 @@
1
+ import { z } from 'zod';
2
+ import { OtelHookErrorInfo } from './errors.js';
3
+ import { w as UsageTemporality, b as CanonicalEvent, e as CanonicalEventType } from './events-VxBnDFaO.js';
4
+ import { I as IdentityClaim, d as InvocationIdentity } from './identity-BrVBs901.js';
5
+ import { R as ResolvedProviderId, g as ProviderId, h as SourceTransport } from './primitives-CJ8-rn-f.js';
6
+ import { e as PrivacyLimits } from './policy-D1CrlYn3.js';
7
+ import { P as PrivacyService } from './service-j4jEO6cZ.js';
8
+ import { C as Clock, I as IdGenerator, c as Logger } from './ports-Q8x0ODhs.js';
9
+ import { A as AttributionOutcome, a as AttributionReason } from './taxonomy-DwhTtuWd.js';
10
+
11
+ /** Raw input offered to adapters. `payload` is `unknown` on purpose. */
12
+ type ProviderDetectionInput = {
13
+ /** Decoded but uninterpreted provider payload. Must not escape the adapter. */
14
+ readonly payload: unknown;
15
+ readonly transport: SourceTransport;
16
+ readonly environment: Readonly<Record<string, string | undefined>>;
17
+ /** Caller's assertion of the provider, e.g. from a CLI flag. */
18
+ readonly providerHint?: string;
19
+ };
20
+ declare const providerDetectionSchema: z.ZodObject<{
21
+ providerId: z.ZodUnion<readonly [z.core.$ZodBranded<z.ZodString, "ProviderId", "out">, z.ZodLiteral<"unknown">]>;
22
+ confidence: z.ZodEnum<{
23
+ none: "none";
24
+ weak: "weak";
25
+ strong: "strong";
26
+ exact: "exact";
27
+ }>;
28
+ reasons: z.ZodArray<z.ZodString>;
29
+ providerVersion: z.ZodOptional<z.ZodString>;
30
+ sourceEventName: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strict>;
32
+ type ProviderDetection = z.infer<typeof providerDetectionSchema>;
33
+ /**
34
+ * How much of a provider's hook traffic carries an identifier that survives a
35
+ * redelivery.
36
+ *
37
+ * - `none`: no callback carries one. Redelivery is undetectable from the
38
+ * payload, and deduplication needs a host-supplied delivery id.
39
+ * - `partial`: some callbacks do and some do not — typically per-tool-call and
40
+ * per-turn events do, while session and compaction edges do not.
41
+ * - `all`: every callback the adapter recognizes carries one.
42
+ *
43
+ * Declared rather than probed for the same reason as the usage capabilities
44
+ * below: "this callback has no stable id" and "this adapter never looked" are
45
+ * indistinguishable downstream, and only the first is safe to build on.
46
+ */
47
+ declare const deliveryIdentifierSupportSchema: z.ZodEnum<{
48
+ none: "none";
49
+ partial: "partial";
50
+ all: "all";
51
+ }>;
52
+ type DeliveryIdentifierSupport = z.infer<typeof deliveryIdentifierSupportSchema>;
53
+ /**
54
+ * Shape a delivery-identity component must have.
55
+ *
56
+ * Deliberately narrow. Provider identifiers, integer counters, hook event
57
+ * names, and ISO-8601 timestamps all satisfy it; prose and filesystem paths do
58
+ * not, because neither spaces nor `/` are allowed. So an adapter that
59
+ * accidentally seeds a delivery identity with a prompt, a tool response, or a
60
+ * home directory produces a *rejected claim* rather than a privacy incident —
61
+ * the guard is structural, not a review convention.
62
+ */
63
+ declare const DELIVERY_COMPONENT_PATTERN: RegExp;
64
+ declare const deliveryComponentSchema: z.ZodString;
65
+ /** Most identifier-shaped fields one callback identity may be built from. */
66
+ declare const MAX_DELIVERY_COMPONENTS = 8;
67
+ /**
68
+ * An adapter's assertion that this callback has a replay-stable identity.
69
+ *
70
+ * The adapter reports *components* rather than a finished id: it knows which
71
+ * payload fields are trustworthy, and the runtime owns how they are combined,
72
+ * scoped, and digested. That split is what keeps a raw provider identifier from
73
+ * becoming an on-disk key or a diagnostic attribute (see
74
+ * `resolveDeliveryIdentity`).
75
+ *
76
+ * Returning nothing is always safe. Claiming an identity that is not actually
77
+ * stable is not: it makes the runtime suppress a *genuine* second callback as if
78
+ * it were a redelivery, which silently loses telemetry.
79
+ */
80
+ declare const providerDeliveryClaimSchema: z.ZodObject<{
81
+ sessionId: z.ZodString;
82
+ sourceEventName: z.ZodString;
83
+ components: z.ZodReadonly<z.ZodArray<z.ZodString>>;
84
+ evidence: z.ZodReadonly<z.ZodArray<z.ZodString>>;
85
+ }, z.core.$strict>;
86
+ type ProviderDeliveryClaim = z.infer<typeof providerDeliveryClaimSchema>;
87
+ /**
88
+ * Shape a per-callback delivery *gap* explanation must have.
89
+ *
90
+ * These strings reach a diagnostic, so the same reasoning that constrains
91
+ * {@link deliveryComponentSchema} applies for the opposite purpose: a component
92
+ * must be identifier-shaped, a gap reason must be prose that cannot smuggle a
93
+ * filesystem path or a newline-delimited payload dump into stderr. Spaces are
94
+ * allowed — it is a sentence — and `/`, `\`, and control characters are not,
95
+ * which is what keeps a home directory out of a message an adapter author writes
96
+ * by hand.
97
+ */
98
+ declare const DELIVERY_GAP_REASON_PATTERN: RegExp;
99
+ declare const deliveryGapReasonSchema: z.ZodString;
100
+ /** Most callbacks one adapter may document a delivery gap for. */
101
+ declare const MAX_DELIVERY_GAPS = 48;
102
+ /**
103
+ * Why each of an adapter's callbacks carries no replay-stable identity.
104
+ *
105
+ * Keyed by the provider's *own* event name — the same value `detect` reports as
106
+ * `sourceEventName` — so the runtime can look up the reason for the callback in
107
+ * front of it without parsing the payload a second time.
108
+ *
109
+ * This exists because `callback-not-identifiable` on its own is a true statement
110
+ * that helps nobody: an operator auditing coverage with `--require-callback-id`
111
+ * needs to know *which* callback and *what field would have to exist*, and only
112
+ * the adapter knows that. Keeping it declarative rather than computed means the
113
+ * answer is reviewable next to the protocol it describes, and an exhaustiveness
114
+ * test can insist that adding a hook event without deciding its delivery status
115
+ * reads as an omission.
116
+ */
117
+ declare const providerDeliveryGapsSchema: z.ZodRecord<z.ZodString, z.ZodString>;
118
+ type ProviderDeliveryGaps = z.infer<typeof providerDeliveryGapsSchema>;
119
+ /**
120
+ * What an adapter can actually observe.
121
+ *
122
+ * Capabilities are declared rather than probed so consumers can distinguish
123
+ * "this provider reports no cached tokens" from "this session used no cache" —
124
+ * the two look identical in the data.
125
+ */
126
+ declare const providerCapabilitiesSchema: z.ZodObject<{
127
+ lifecycleEvents: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
128
+ "session.start": "session.start";
129
+ "session.end": "session.end";
130
+ "prompt.submitted": "prompt.submitted";
131
+ "generation.start": "generation.start";
132
+ "generation.end": "generation.end";
133
+ "tool.start": "tool.start";
134
+ "tool.end": "tool.end";
135
+ "subagent.start": "subagent.start";
136
+ "subagent.end": "subagent.end";
137
+ "compaction.performed": "compaction.performed";
138
+ "error.raised": "error.raised";
139
+ }>>>;
140
+ usageTemporality: z.ZodEnum<{
141
+ delta: "delta";
142
+ cumulative: "cumulative";
143
+ }>;
144
+ cumulativeUsageSeries: z.ZodOptional<z.ZodEnum<{
145
+ "event-scope": "event-scope";
146
+ "session-lifetime": "session-lifetime";
147
+ }>>;
148
+ reportsCachedInput: z.ZodBoolean;
149
+ reportsCacheCreation: z.ZodBoolean;
150
+ cacheCreationAccounting: z.ZodEnum<{
151
+ "included-in-input": "included-in-input";
152
+ "disjoint-from-input": "disjoint-from-input";
153
+ "not-reported": "not-reported";
154
+ }>;
155
+ reportsReasoningOutput: z.ZodBoolean;
156
+ reportsProviderTotal: z.ZodBoolean;
157
+ reportsCost: z.ZodBoolean;
158
+ emitsSubagentEvents: z.ZodBoolean;
159
+ emitsCompactionEvents: z.ZodBoolean;
160
+ requiresHookResponse: z.ZodBoolean;
161
+ deliveryIdentifier: z.ZodEnum<{
162
+ none: "none";
163
+ partial: "partial";
164
+ all: "all";
165
+ }>;
166
+ }, z.core.$strict>;
167
+ type ProviderCapabilities = z.infer<typeof providerCapabilitiesSchema>;
168
+ /** Services an adapter is given. Note the absence of a filesystem or network. */
169
+ type ProviderContext = {
170
+ readonly privacy: PrivacyService;
171
+ readonly clock: Clock;
172
+ readonly ids: IdGenerator;
173
+ readonly logger: Logger;
174
+ readonly limits: PrivacyLimits;
175
+ };
176
+ type ProviderIdentityInput = ProviderDetectionInput & {
177
+ readonly detection: ProviderDetection;
178
+ };
179
+ type ProviderParseInput = ProviderDetectionInput & {
180
+ readonly detection: ProviderDetection;
181
+ /** Resolved by the core; adapters never resolve identity themselves. */
182
+ readonly identity: InvocationIdentity;
183
+ /**
184
+ * First sequence number the adapter may use. Sequences must be assigned
185
+ * consecutively from here so event ids stay stable across replays.
186
+ */
187
+ readonly sequenceBase: number;
188
+ };
189
+ type ProviderParseResult = {
190
+ readonly status: "parsed";
191
+ readonly events: readonly CanonicalEvent[];
192
+ readonly warnings?: readonly string[];
193
+ }
194
+ /** The input was recognized but carries no telemetry. Not an error. */
195
+ | {
196
+ readonly status: "ignored";
197
+ readonly reason: string;
198
+ } | {
199
+ readonly status: "failed";
200
+ readonly error: OtelHookErrorInfo;
201
+ };
202
+ declare const providerHookResponseSchema: z.ZodObject<{
203
+ exitCode: z.ZodLiteral<0>;
204
+ stdout: z.ZodOptional<z.ZodString>;
205
+ stderr: z.ZodOptional<z.ZodString>;
206
+ contract: z.ZodEnum<{
207
+ silent: "silent";
208
+ "provider-protocol": "provider-protocol";
209
+ }>;
210
+ }, z.core.$strict>;
211
+ type ProviderHookResponse = z.infer<typeof providerHookResponseSchema>;
212
+ /** The silent response: nothing on stdout, success to the host. */
213
+ declare const SILENT_HOOK_RESPONSE: ProviderHookResponse;
214
+ type ProviderHookResponseInput = {
215
+ readonly attribution: AttributionOutcome;
216
+ readonly attributionReason?: AttributionReason;
217
+ readonly detection?: ProviderDetection;
218
+ readonly emittedEvents: number;
219
+ readonly errors: readonly OtelHookErrorInfo[];
220
+ };
221
+ /**
222
+ * Contract every provider adapter implements.
223
+ *
224
+ * The four methods are deliberately separate: detection must be cheap and
225
+ * side-effect free, identity must be expressible as claims the core can
226
+ * arbitrate, parsing must be the only place that reads the payload, and the hook
227
+ * response must be derivable from the outcome alone.
228
+ */
229
+ interface ProviderAdapter {
230
+ readonly id: ProviderId;
231
+ readonly version: string;
232
+ readonly capabilities: ProviderCapabilities;
233
+ /**
234
+ * Report whether this adapter recognizes the input. Must not throw; must not
235
+ * read files or the network. Return `none` rather than guessing.
236
+ */
237
+ detect(input: ProviderDetectionInput, context: ProviderContext): ProviderDetection;
238
+ /**
239
+ * Contribute identity claims. Returning fewer claims is always safe;
240
+ * fabricating a session id is not.
241
+ */
242
+ identify(input: ProviderIdentityInput, context: ProviderContext): readonly IdentityClaim[];
243
+ /**
244
+ * Report this callback's replay-stable identity, when the payload carries one.
245
+ *
246
+ * Called before `parse`, must be cheap and side-effect free, and must not
247
+ * throw. Return `undefined` whenever the payload's identifying fields are
248
+ * absent or would not survive a redelivery — under-reporting costs
249
+ * deduplication, over-reporting loses real telemetry.
250
+ */
251
+ deliveryIdentity?(input: ProviderIdentityInput, context: ProviderContext): ProviderDeliveryClaim | undefined;
252
+ /**
253
+ * Why each callback that {@link ProviderAdapter.deliveryIdentity} declines
254
+ * carries no replay-stable identity, keyed by the provider's own event name.
255
+ *
256
+ * Static data, not control flow: it never decides whether a callback is
257
+ * deduplicated, only what the runtime can *say* when it is not. An adapter that
258
+ * declares `deliveryIdentifier: "none"` should still populate this — the gap is
259
+ * then the whole story, and "the protocol has no request id" is a far more
260
+ * actionable diagnostic than "not identifiable".
261
+ */
262
+ readonly deliveryGaps?: ProviderDeliveryGaps;
263
+ /** Interpret the payload into canonical events. */
264
+ parse(input: ProviderParseInput, context: ProviderContext): ProviderParseResult;
265
+ /** Provider-specific hook response for the given outcome. */
266
+ hookResponse(input: ProviderHookResponseInput, context: ProviderContext): ProviderHookResponse;
267
+ }
268
+ declare const adapterSupports: (adapter: ProviderAdapter, eventType: CanonicalEventType) => boolean;
269
+ type AdapterDescription = {
270
+ readonly id: ResolvedProviderId;
271
+ readonly version: string;
272
+ readonly lifecycleEvents: readonly string[];
273
+ readonly usageTemporality: UsageTemporality;
274
+ readonly deliveryIdentifier: DeliveryIdentifierSupport;
275
+ };
276
+ declare const describeAdapter: (adapter: ProviderAdapter) => AdapterDescription;
277
+ /**
278
+ * Ask an adapter for a delivery claim, containing anything it does wrong.
279
+ *
280
+ * A `deliveryIdentity` that throws, or that returns a claim the schema rejects
281
+ * (a component carrying prose, more components than the cap), degrades to "no
282
+ * stable identity available" rather than failing the invocation: deduplication
283
+ * is an optimization, and the host's telemetry is not.
284
+ */
285
+ declare const readDeliveryClaim: (adapter: ProviderAdapter, input: ProviderIdentityInput, context: ProviderContext) => {
286
+ readonly claim?: ProviderDeliveryClaim;
287
+ readonly rejection?: string;
288
+ };
289
+ /**
290
+ * Look up why this callback has no replay-stable identity, containing anything
291
+ * the adapter got wrong.
292
+ *
293
+ * Validated on the way out rather than trusted, for the same reason a claim is:
294
+ * the string ends up in a diagnostic an operator reads, and an adapter that pasted
295
+ * a path or a payload excerpt into its own gap table must produce *no detail*
296
+ * rather than a disclosure. Returning `undefined` costs a sentence of explanation
297
+ * and nothing else — the reason code is reported either way.
298
+ */
299
+ declare const readDeliveryGap: (adapter: ProviderAdapter, sourceEventName: string | undefined) => string | undefined;
300
+ declare const asProviderId: (value: string) => ProviderId;
301
+ declare const unknownDetection: (reasons?: readonly string[]) => ProviderDetection;
302
+
303
+ export { type AdapterDescription as A, readDeliveryGap as B, unknownDetection as C, DELIVERY_COMPONENT_PATTERN as D, MAX_DELIVERY_COMPONENTS as M, type ProviderAdapter as P, SILENT_HOOK_RESPONSE as S, DELIVERY_GAP_REASON_PATTERN as a, type DeliveryIdentifierSupport as b, MAX_DELIVERY_GAPS as c, type ProviderCapabilities as d, type ProviderContext as e, type ProviderDeliveryClaim as f, type ProviderDeliveryGaps as g, type ProviderDetection as h, type ProviderDetectionInput as i, type ProviderHookResponse as j, type ProviderHookResponseInput as k, type ProviderIdentityInput as l, type ProviderParseInput as m, type ProviderParseResult as n, adapterSupports as o, asProviderId as p, deliveryComponentSchema as q, deliveryGapReasonSchema as r, deliveryIdentifierSupportSchema as s, describeAdapter as t, providerCapabilitiesSchema as u, providerDeliveryClaimSchema as v, providerDeliveryGapsSchema as w, providerDetectionSchema as x, providerHookResponseSchema as y, readDeliveryClaim as z };