@osfactory/otel-hook 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/providers.js CHANGED
@@ -1015,6 +1015,7 @@ var createProviderRegistry = (adapters) => {
1015
1015
  errors
1016
1016
  };
1017
1017
  }
1018
+ const nearMisses = [];
1018
1019
  for (const adapter of frozen) {
1019
1020
  let detection;
1020
1021
  try {
@@ -1024,6 +1025,10 @@ var createProviderRegistry = (adapters) => {
1024
1025
  continue;
1025
1026
  }
1026
1027
  if (detection.confidence === "none") {
1028
+ for (const reason of detection.reasons) {
1029
+ const prefixed = `${adapter.id}: ${reason}`;
1030
+ nearMisses.push(prefixed.length <= 160 ? prefixed : `${prefixed.slice(0, 159)}\u2026`);
1031
+ }
1027
1032
  continue;
1028
1033
  }
1029
1034
  if (detection.providerId !== adapter.id) {
@@ -1043,7 +1048,7 @@ var createProviderRegistry = (adapters) => {
1043
1048
  return {
1044
1049
  status: "unknown",
1045
1050
  reason: "no-candidates",
1046
- detection: unknownDetection(),
1051
+ detection: unknownDetection(nearMisses.length === 0 ? void 0 : nearMisses.slice(0, 8)),
1047
1052
  candidates,
1048
1053
  errors
1049
1054
  };
@@ -1911,7 +1916,12 @@ var usageFields = {
1911
1916
  cache_write_tokens: z12.number().int().min(0).optional()
1912
1917
  };
1913
1918
  var envelopeShape = {
1914
- conversation_id: z12.string().min(1),
1919
+ // Not `.min(1)`: see `cursorSessionId`. A payload naming neither
1920
+ // `conversation_id` nor `session_id` is still rejected — by
1921
+ // `recognizeCursorPayload`'s post-parse check — but rejecting it here would
1922
+ // fail the whole discriminated union on a field the adapter can source from
1923
+ // either name.
1924
+ conversation_id: z12.string().optional(),
1915
1925
  generation_id: z12.string().optional(),
1916
1926
  session_id: z12.string().optional(),
1917
1927
  model: z12.string().optional(),
@@ -2085,12 +2095,25 @@ var recognizeCursorPayload = (payload) => {
2085
2095
  detail: issue === void 0 ? "payload does not satisfy the cursor hook schema" : `${issue.path.join(".") || "<root>"}: ${issue.message}`
2086
2096
  };
2087
2097
  }
2098
+ if (cursorSessionId(parsed.data) === void 0) {
2099
+ return {
2100
+ status: "invalid",
2101
+ eventName,
2102
+ detail: "payload names neither conversation_id nor session_id, so it carries no session to attribute telemetry to"
2103
+ };
2104
+ }
2088
2105
  return { status: "modelled", payload: parsed.data };
2089
2106
  };
2090
2107
  var normalizeCursorPayload = (payload) => {
2091
2108
  const recognized = recognizeCursorPayload(payload);
2092
2109
  return recognized?.status === "modelled" ? recognized.payload : void 0;
2093
2110
  };
2111
+ var cursorSessionId = (payload) => {
2112
+ if (payload.conversation_id !== void 0 && payload.conversation_id.length > 0) {
2113
+ return payload.conversation_id;
2114
+ }
2115
+ return payload.session_id !== void 0 && payload.session_id.length > 0 ? payload.session_id : void 0;
2116
+ };
2094
2117
 
2095
2118
  // src/providers/cursor/delivery.ts
2096
2119
  var deliveryComponents = (payload) => {
@@ -2148,12 +2171,16 @@ var cursorDeliveryIdentity = (input) => {
2148
2171
  if (payload === void 0) {
2149
2172
  return void 0;
2150
2173
  }
2174
+ const sessionId = cursorSessionId(payload);
2175
+ if (sessionId === void 0) {
2176
+ return void 0;
2177
+ }
2151
2178
  const identified = deliveryComponents(payload);
2152
2179
  if (identified === void 0) {
2153
2180
  return void 0;
2154
2181
  }
2155
2182
  return {
2156
- sessionId: payload.conversation_id,
2183
+ sessionId,
2157
2184
  sourceEventName: payload.hook_event_name,
2158
2185
  components: identified.components,
2159
2186
  evidence: identified.evidence
@@ -2350,10 +2377,14 @@ var createCursorAdapter = (options = {}) => {
2350
2377
  }
2351
2378
  const workspace = deriveWorkspace(context, payload);
2352
2379
  const discriminator = invocationDiscriminator(payload);
2380
+ const sessionId = cursorSessionId(payload);
2381
+ if (sessionId === void 0) {
2382
+ return [];
2383
+ }
2353
2384
  const occurredAt = context.clock.now();
2354
2385
  const invocationId = context.ids.newInvocationId({
2355
2386
  providerId: id,
2356
- sessionId: payload.conversation_id,
2387
+ sessionId,
2357
2388
  sourceEventName: payload.hook_event_name,
2358
2389
  occurredAt,
2359
2390
  ...discriminator === void 0 ? {} : { discriminator }
@@ -2362,10 +2393,7 @@ var createCursorAdapter = (options = {}) => {
2362
2393
  source: `adapter:${id}`,
2363
2394
  confidence: input.detection.confidence,
2364
2395
  fields: {
2365
- // Cursor's own conversation id, used exactly as reported: never
2366
- // normalized, parent/child matched, or substituted for a derived value.
2367
- // `session_id` repeats it in every capture and is not preferred over it.
2368
- sessionId: payload.conversation_id,
2396
+ sessionId,
2369
2397
  invocationId,
2370
2398
  startedAt: occurredAt,
2371
2399
  ...workspace === void 0 ? {} : { workspace }