@osfactory/otel-hook 0.1.0 → 0.1.2

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/testing.js CHANGED
@@ -1767,6 +1767,7 @@ var createProviderRegistry = (adapters) => {
1767
1767
  errors
1768
1768
  };
1769
1769
  }
1770
+ const nearMisses = [];
1770
1771
  for (const adapter of frozen) {
1771
1772
  let detection;
1772
1773
  try {
@@ -1776,6 +1777,10 @@ var createProviderRegistry = (adapters) => {
1776
1777
  continue;
1777
1778
  }
1778
1779
  if (detection.confidence === "none") {
1780
+ for (const reason of detection.reasons) {
1781
+ const prefixed = `${adapter.id}: ${reason}`;
1782
+ nearMisses.push(prefixed.length <= 160 ? prefixed : `${prefixed.slice(0, 159)}\u2026`);
1783
+ }
1779
1784
  continue;
1780
1785
  }
1781
1786
  if (detection.providerId !== adapter.id) {
@@ -1795,7 +1800,7 @@ var createProviderRegistry = (adapters) => {
1795
1800
  return {
1796
1801
  status: "unknown",
1797
1802
  reason: "no-candidates",
1798
- detection: unknownDetection(),
1803
+ detection: unknownDetection(nearMisses.length === 0 ? void 0 : nearMisses.slice(0, 8)),
1799
1804
  candidates,
1800
1805
  errors
1801
1806
  };
@@ -2663,7 +2668,12 @@ var usageFields = {
2663
2668
  cache_write_tokens: z15.number().int().min(0).optional()
2664
2669
  };
2665
2670
  var envelopeShape = {
2666
- conversation_id: z15.string().min(1),
2671
+ // Not `.min(1)`: see `cursorSessionId`. A payload naming neither
2672
+ // `conversation_id` nor `session_id` is still rejected — by
2673
+ // `recognizeCursorPayload`'s post-parse check — but rejecting it here would
2674
+ // fail the whole discriminated union on a field the adapter can source from
2675
+ // either name.
2676
+ conversation_id: z15.string().optional(),
2667
2677
  generation_id: z15.string().optional(),
2668
2678
  session_id: z15.string().optional(),
2669
2679
  model: z15.string().optional(),
@@ -2837,12 +2847,25 @@ var recognizeCursorPayload = (payload) => {
2837
2847
  detail: issue === void 0 ? "payload does not satisfy the cursor hook schema" : `${issue.path.join(".") || "<root>"}: ${issue.message}`
2838
2848
  };
2839
2849
  }
2850
+ if (cursorSessionId(parsed.data) === void 0) {
2851
+ return {
2852
+ status: "invalid",
2853
+ eventName,
2854
+ detail: "payload names neither conversation_id nor session_id, so it carries no session to attribute telemetry to"
2855
+ };
2856
+ }
2840
2857
  return { status: "modelled", payload: parsed.data };
2841
2858
  };
2842
2859
  var normalizeCursorPayload = (payload) => {
2843
2860
  const recognized = recognizeCursorPayload(payload);
2844
2861
  return recognized?.status === "modelled" ? recognized.payload : void 0;
2845
2862
  };
2863
+ var cursorSessionId = (payload) => {
2864
+ if (payload.conversation_id !== void 0 && payload.conversation_id.length > 0) {
2865
+ return payload.conversation_id;
2866
+ }
2867
+ return payload.session_id !== void 0 && payload.session_id.length > 0 ? payload.session_id : void 0;
2868
+ };
2846
2869
 
2847
2870
  // src/providers/cursor/delivery.ts
2848
2871
  var deliveryComponents = (payload) => {
@@ -2900,12 +2923,16 @@ var cursorDeliveryIdentity = (input) => {
2900
2923
  if (payload === void 0) {
2901
2924
  return void 0;
2902
2925
  }
2926
+ const sessionId = cursorSessionId(payload);
2927
+ if (sessionId === void 0) {
2928
+ return void 0;
2929
+ }
2903
2930
  const identified = deliveryComponents(payload);
2904
2931
  if (identified === void 0) {
2905
2932
  return void 0;
2906
2933
  }
2907
2934
  return {
2908
- sessionId: payload.conversation_id,
2935
+ sessionId,
2909
2936
  sourceEventName: payload.hook_event_name,
2910
2937
  components: identified.components,
2911
2938
  evidence: identified.evidence
@@ -3102,10 +3129,14 @@ var createCursorAdapter = (options = {}) => {
3102
3129
  }
3103
3130
  const workspace = deriveWorkspace(context, payload);
3104
3131
  const discriminator = invocationDiscriminator(payload);
3132
+ const sessionId = cursorSessionId(payload);
3133
+ if (sessionId === void 0) {
3134
+ return [];
3135
+ }
3105
3136
  const occurredAt = context.clock.now();
3106
3137
  const invocationId = context.ids.newInvocationId({
3107
3138
  providerId: id,
3108
- sessionId: payload.conversation_id,
3139
+ sessionId,
3109
3140
  sourceEventName: payload.hook_event_name,
3110
3141
  occurredAt,
3111
3142
  ...discriminator === void 0 ? {} : { discriminator }
@@ -3114,10 +3145,7 @@ var createCursorAdapter = (options = {}) => {
3114
3145
  source: `adapter:${id}`,
3115
3146
  confidence: input.detection.confidence,
3116
3147
  fields: {
3117
- // Cursor's own conversation id, used exactly as reported: never
3118
- // normalized, parent/child matched, or substituted for a derived value.
3119
- // `session_id` repeats it in every capture and is not preferred over it.
3120
- sessionId: payload.conversation_id,
3148
+ sessionId,
3121
3149
  invocationId,
3122
3150
  startedAt: occurredAt,
3123
3151
  ...workspace === void 0 ? {} : { workspace }