@agentuity/runtime 0.1.31 → 0.1.33

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.
@@ -106,19 +106,26 @@ export class HTTPSessionEventProvider implements SessionEventProvider {
106
106
  * @param event SessionCompleteEvent
107
107
  */
108
108
  async complete(event: SessionCompleteEvent): Promise<void> {
109
- // Only send complete if we successfully sent a start event
110
- // This prevents sending orphaned complete events when start was skipped
111
- if (!this.startedSessions.has(event.id)) {
112
- internal.info('[session-http] skipping complete event - no matching start: %s', event.id);
113
- return;
114
- }
115
- this.startedSessions.delete(event.id);
116
-
109
+ // Always create the "Session End" span for telemetry purposes.
110
+ // This span is used by Catalyst to detect when a session has completed,
111
+ // so it must always be emitted even if we don't send the HTTP event.
117
112
  const tracer = trace.getTracer('session');
118
113
  const currentContext = context.active();
119
114
  const span = tracer.startSpan('Session End', {}, currentContext);
120
115
 
121
116
  try {
117
+ // Only send HTTP complete event if we successfully sent a start event.
118
+ // This prevents sending orphaned complete events when start was skipped.
119
+ // However, we still create the span above for telemetry.
120
+ if (!this.startedSessions.has(event.id)) {
121
+ internal.info(
122
+ '[session-http] skipping HTTP complete event (no matching start), but emitting Session End span: %s',
123
+ event.id
124
+ );
125
+ span.setStatus({ code: SpanStatusCode.OK });
126
+ return;
127
+ }
128
+
122
129
  internal.info(
123
130
  '[session-http] sending complete event: %s, userData: %s',
124
131
  event.id,
@@ -137,6 +144,7 @@ export class HTTPSessionEventProvider implements SessionEventProvider {
137
144
  );
138
145
 
139
146
  if (resp.success) {
147
+ this.startedSessions.delete(event.id);
140
148
  internal.info('[session-http] complete event sent successfully: %s', event.id);
141
149
  this.logger.debug('Session complete event sent successfully: %s', event.id);
142
150
  span.setStatus({ code: SpanStatusCode.OK });
package/src/session.ts CHANGED
@@ -1408,6 +1408,7 @@ export class ThreadWebSocketClient {
1408
1408
  this.ws = new WebSocket(this.wsUrl);
1409
1409
 
1410
1410
  this.ws.addEventListener('open', () => {
1411
+ internal.info('WebSocket connected');
1411
1412
  // Send authentication (do NOT clear timeout yet - wait for auth response)
1412
1413
  this.ws?.send(JSON.stringify({ authorization: this.apiKey }));
1413
1414
  });