@runtimescope/collector 0.7.0 → 0.7.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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SecureContextOptions } from 'node:tls';
2
2
 
3
- type EventType = 'network' | 'console' | 'session' | 'state' | 'render' | 'dom_snapshot' | 'performance' | 'database' | 'custom' | 'recon_metadata' | 'recon_design_tokens' | 'recon_fonts' | 'recon_layout_tree' | 'recon_accessibility' | 'recon_computed_styles' | 'recon_element_snapshot' | 'recon_asset_inventory';
3
+ type EventType = 'network' | 'console' | 'session' | 'state' | 'render' | 'dom_snapshot' | 'performance' | 'database' | 'custom' | 'navigation' | 'recon_metadata' | 'recon_design_tokens' | 'recon_fonts' | 'recon_layout_tree' | 'recon_accessibility' | 'recon_computed_styles' | 'recon_element_snapshot' | 'recon_asset_inventory';
4
4
  interface BaseEvent {
5
5
  eventId: string;
6
6
  sessionId: string;
@@ -129,6 +129,12 @@ interface DatabaseEvent extends BaseEvent {
129
129
  error?: string;
130
130
  params?: string;
131
131
  }
132
+ interface NavigationEvent extends BaseEvent {
133
+ eventType: 'navigation';
134
+ from: string;
135
+ to: string;
136
+ trigger: 'pushState' | 'replaceState' | 'popstate' | 'hashchange' | 'initial';
137
+ }
132
138
  interface CustomEvent extends BaseEvent {
133
139
  eventType: 'custom';
134
140
  name: string;
@@ -460,7 +466,7 @@ interface ReconFilter {
460
466
  url?: string;
461
467
  }
462
468
  type ReconEventType = 'recon_metadata' | 'recon_design_tokens' | 'recon_fonts' | 'recon_layout_tree' | 'recon_accessibility' | 'recon_computed_styles' | 'recon_element_snapshot' | 'recon_asset_inventory';
463
- type RuntimeEvent = NetworkEvent | ConsoleEvent | SessionEvent | StateEvent | RenderEvent | DomSnapshotEvent | PerformanceEvent | DatabaseEvent | CustomEvent | ReconMetadataEvent | ReconDesignTokensEvent | ReconFontsEvent | ReconLayoutTreeEvent | ReconAccessibilityEvent | ReconComputedStylesEvent | ReconElementSnapshotEvent | ReconAssetInventoryEvent;
469
+ type RuntimeEvent = NetworkEvent | ConsoleEvent | SessionEvent | StateEvent | RenderEvent | DomSnapshotEvent | PerformanceEvent | DatabaseEvent | NavigationEvent | CustomEvent | ReconMetadataEvent | ReconDesignTokensEvent | ReconFontsEvent | ReconLayoutTreeEvent | ReconAccessibilityEvent | ReconComputedStylesEvent | ReconElementSnapshotEvent | ReconAssetInventoryEvent;
464
470
  interface NetworkFilter {
465
471
  sinceSeconds?: number;
466
472
  urlPattern?: string;
@@ -857,16 +863,22 @@ declare class SqliteStore {
857
863
  private writeBuffer;
858
864
  private flushTimer;
859
865
  private readonly batchSize;
866
+ private readonly dbPath;
867
+ private static readonly MAX_SNAPSHOTS_PER_SESSION;
860
868
  private insertEventStmt;
861
869
  private insertSessionStmt;
862
870
  private updateSessionDisconnectedStmt;
863
871
  constructor(options: SqliteStoreOptions);
872
+ private openDatabase;
873
+ private prepareStatements;
864
874
  private createSchema;
865
875
  addEvent(event: RuntimeEvent, project: string): void;
866
876
  flush(): void;
867
877
  saveSession(info: SessionInfoExtended): void;
868
878
  updateSessionDisconnected(sessionId: string, disconnectedAt: number): void;
869
879
  saveSessionMetrics(sessionId: string, project: string, metrics: unknown, label?: string): void;
880
+ /** Remove oldest snapshots for a session beyond the retention limit */
881
+ private pruneSnapshots;
870
882
  getEvents(filter: HistoricalFilter): RuntimeEvent[];
871
883
  getEventCount(filter: HistoricalFilter): number;
872
884
  getSessions(project: string, limit?: number): SessionInfoExtended[];
@@ -1127,6 +1139,7 @@ declare class CollectorServer {
1127
1139
  private connectCallbacks;
1128
1140
  private disconnectCallbacks;
1129
1141
  private pruneTimer;
1142
+ private heartbeatTimer;
1130
1143
  private tlsConfig;
1131
1144
  constructor(options?: CollectorServerOptions);
1132
1145
  getStore(): EventStore;
@@ -1142,6 +1155,10 @@ declare class CollectorServer {
1142
1155
  private tryStart;
1143
1156
  private handleStartError;
1144
1157
  private ensureSqliteStore;
1158
+ /** Catch runtime errors on the WSS so an unhandled error doesn't crash the process */
1159
+ private setupPersistentErrorHandler;
1160
+ /** Ping all connected clients every 15s — terminate those that don't respond */
1161
+ private startHeartbeat;
1145
1162
  private setupConnectionHandler;
1146
1163
  private handleMessage;
1147
1164
  /** Find the WebSocket for a given sessionId */
@@ -1189,10 +1206,16 @@ declare class RingBuffer<T> {
1189
1206
  */
1190
1207
  declare function detectIssues(events: RuntimeEvent[]): DetectedIssue[];
1191
1208
 
1209
+ declare function isSqliteAvailable(): boolean;
1210
+
1192
1211
  declare class ApiDiscoveryEngine {
1193
1212
  private endpoints;
1194
1213
  private store;
1214
+ private lastRebuildEventCount;
1215
+ private isDirty;
1195
1216
  constructor(store: EventStore);
1217
+ /** Mark the cache dirty so the next read triggers a rebuild */
1218
+ markDirty(): void;
1196
1219
  rebuild(): void;
1197
1220
  private ingestEvent;
1198
1221
  private refineEndpoints;
@@ -1344,6 +1367,7 @@ interface PmProject {
1344
1367
  path?: string;
1345
1368
  claudeProjectKey?: string;
1346
1369
  runtimescopeProject?: string;
1370
+ runtimeApps?: string[];
1347
1371
  phase: ProjectPhase;
1348
1372
  managementAuthorized: boolean;
1349
1373
  probableToComplete: boolean;
@@ -1674,12 +1698,17 @@ declare class HttpServer {
1674
1698
  private sdkBundlePath;
1675
1699
  private activePort;
1676
1700
  private startedAt;
1701
+ private connectedSessionsGetter;
1677
1702
  constructor(store: EventStore, processMonitor?: ProcessMonitor, options?: {
1678
1703
  authManager?: AuthManager;
1679
1704
  allowedOrigins?: string[];
1680
1705
  rateLimiter?: SessionRateLimiter;
1681
1706
  pmStore?: PmStore;
1682
1707
  discovery?: ProjectDiscovery;
1708
+ getConnectedSessions?: () => {
1709
+ sessionId: string;
1710
+ projectName: string;
1711
+ }[];
1683
1712
  });
1684
1713
  private registerRoutes;
1685
1714
  /**
@@ -1723,4 +1752,4 @@ declare function calculateCostMicrodollars(model: string, inputTokens: number, o
1723
1752
  */
1724
1753
  declare function parseSessionJsonl(jsonlPath: string, sessionId: string, projectId: string): Promise<ParseResult>;
1725
1754
 
1726
- export { type ApiChangeRecord, type ApiContract, type ApiContractField, ApiDiscoveryEngine, type ApiEndpoint, type ApiEndpointHealth, type ApiKeyEntry, type AuthConfig, type AuthInfo, AuthManager, BUILT_IN_RULES, type BackgroundSpriteSheet, type BaseEvent, type BuildMeta, type BuildStatus, type CSSArchitecture, type CSSCustomProperty, type CapexClassification, type CapexSummary, CollectorServer, type CollectorServerOptions, type ColorToken, type CommandResponse, type ComputedStyleEntry, ConnectionManager, type ConsoleEvent, type ConsoleFilter, type ConsoleLevel, type CustomEvent, type CustomEventFilter, DataBrowser, type DatabaseConnectionConfig, type DatabaseEvent, type DatabaseFilter, type DatabaseOperation, type DatabaseSchema, type DatabaseSource, type DeployLog, type DetectedBuildTool, type DetectedFramework, type DetectedHosting, type DetectedIssue, type DetectedMetaFramework, type DetectedUILibrary, type DevProcess, type DevProcessType, type DomSnapshotEvent, type ElementSnapshotNode, type EventBatchPayload, EventStore, type EventType, type FontFaceInfo, type FontUsage, type FormFieldInfo, type GitCommit, type GitFileChange, type GitFileStatus, type GitStatus, type GlobalConfig, type GraphQLOperation, type HandshakePayload, type HeadingInfo, type HistoricalFilter, HttpServer, type HttpServerOptions, type IconFontInfo, type ImageAsset, type IndexSuggestion, InfraConnector, type InfraOverview, type InfrastructureConfig, type InlineSVGAsset, type InteractiveElementInfo, type IssueSeverity, type LandmarkInfo, type LayoutNode, type ManagedConnection, type MaskSpriteSheet, type MemoryFile, type MetricDelta, type NetworkEvent, type NetworkFilter, type NormalizedQueryStats, type PerformanceEvent, type PerformanceFilter, type PerformanceMetricName, type PmCapexEntry, type PmNote, type PmProject, type PmSession, PmStore, type PmTask, type PortUsage, ProcessMonitor, type ProjectConfig, ProjectDiscovery, ProjectManager, type ProjectPhase, type ProjectStatus, type RateLimitConfig, type ReadOptions, type ReadResult, type ReconAccessibilityEvent, type ReconAssetInventoryEvent, type ReconComputedStylesEvent, type ReconDesignTokensEvent, type ReconElementSnapshotEvent, type ReconEventType, type ReconFilter, type ReconFontsEvent, type ReconLayoutTreeEvent, type ReconMetadataEvent, type RedactionRule, Redactor, type RedactorConfig, type RenderComponentProfile, type RenderEvent, type RenderFilter, RingBuffer, type RulesFiles, type RuntimeEvent, type RuntimeLog, type SVGSpriteSymbol, type SchemaColumn, type SchemaForeignKey, type SchemaIndex, SchemaIntrospector, type SchemaTable, type ServerCommand, type ServerMetricName, type ServiceInfo, type SessionDiffResult, type SessionEvent, type SessionInfo, type SessionInfoExtended, SessionManager, type SessionMetrics, SessionRateLimiter, type SessionSnapshot, type SessionStats, type SpacingValue, type SpriteFrame, SqliteStore, type SqliteStoreOptions, type StateEvent, type StateFilter, type TaskPriority, type TaskSource, type TaskStatus, type TechStackDetection, type TimelineFilter, type TlsConfig, type ToolResponse, type TypographyToken, type WSMessage, type WebVitalRating, type WorkType, type WriteOptions, type WriteResult, aggregateQueryStats, calculateActiveMinutes, calculateCostMicrodollars, compareSessions, detectIssues, detectN1Queries, detectOverfetching, detectSlowQueries, generateApiKey, loadTlsOptions, parseSessionJsonl, resolveTlsConfig, suggestIndexes };
1755
+ export { type ApiChangeRecord, type ApiContract, type ApiContractField, ApiDiscoveryEngine, type ApiEndpoint, type ApiEndpointHealth, type ApiKeyEntry, type AuthConfig, type AuthInfo, AuthManager, BUILT_IN_RULES, type BackgroundSpriteSheet, type BaseEvent, type BuildMeta, type BuildStatus, type CSSArchitecture, type CSSCustomProperty, type CapexClassification, type CapexSummary, CollectorServer, type CollectorServerOptions, type ColorToken, type CommandResponse, type ComputedStyleEntry, ConnectionManager, type ConsoleEvent, type ConsoleFilter, type ConsoleLevel, type CustomEvent, type CustomEventFilter, DataBrowser, type DatabaseConnectionConfig, type DatabaseEvent, type DatabaseFilter, type DatabaseOperation, type DatabaseSchema, type DatabaseSource, type DeployLog, type DetectedBuildTool, type DetectedFramework, type DetectedHosting, type DetectedIssue, type DetectedMetaFramework, type DetectedUILibrary, type DevProcess, type DevProcessType, type DomSnapshotEvent, type ElementSnapshotNode, type EventBatchPayload, EventStore, type EventType, type FontFaceInfo, type FontUsage, type FormFieldInfo, type GitCommit, type GitFileChange, type GitFileStatus, type GitStatus, type GlobalConfig, type GraphQLOperation, type HandshakePayload, type HeadingInfo, type HistoricalFilter, HttpServer, type HttpServerOptions, type IconFontInfo, type ImageAsset, type IndexSuggestion, InfraConnector, type InfraOverview, type InfrastructureConfig, type InlineSVGAsset, type InteractiveElementInfo, type IssueSeverity, type LandmarkInfo, type LayoutNode, type ManagedConnection, type MaskSpriteSheet, type MemoryFile, type MetricDelta, type NavigationEvent, type NetworkEvent, type NetworkFilter, type NormalizedQueryStats, type PerformanceEvent, type PerformanceFilter, type PerformanceMetricName, type PmCapexEntry, type PmNote, type PmProject, type PmSession, PmStore, type PmTask, type PortUsage, ProcessMonitor, type ProjectConfig, ProjectDiscovery, ProjectManager, type ProjectPhase, type ProjectStatus, type RateLimitConfig, type ReadOptions, type ReadResult, type ReconAccessibilityEvent, type ReconAssetInventoryEvent, type ReconComputedStylesEvent, type ReconDesignTokensEvent, type ReconElementSnapshotEvent, type ReconEventType, type ReconFilter, type ReconFontsEvent, type ReconLayoutTreeEvent, type ReconMetadataEvent, type RedactionRule, Redactor, type RedactorConfig, type RenderComponentProfile, type RenderEvent, type RenderFilter, RingBuffer, type RulesFiles, type RuntimeEvent, type RuntimeLog, type SVGSpriteSymbol, type SchemaColumn, type SchemaForeignKey, type SchemaIndex, SchemaIntrospector, type SchemaTable, type ServerCommand, type ServerMetricName, type ServiceInfo, type SessionDiffResult, type SessionEvent, type SessionInfo, type SessionInfoExtended, SessionManager, type SessionMetrics, SessionRateLimiter, type SessionSnapshot, type SessionStats, type SpacingValue, type SpriteFrame, SqliteStore, type SqliteStoreOptions, type StateEvent, type StateFilter, type TaskPriority, type TaskSource, type TaskStatus, type TechStackDetection, type TimelineFilter, type TlsConfig, type ToolResponse, type TypographyToken, type WSMessage, type WebVitalRating, type WorkType, type WriteOptions, type WriteResult, aggregateQueryStats, calculateActiveMinutes, calculateCostMicrodollars, compareSessions, detectIssues, detectN1Queries, detectOverfetching, detectSlowQueries, generateApiKey, isSqliteAvailable, loadTlsOptions, parseSessionJsonl, resolveTlsConfig, suggestIndexes };
package/dist/index.js CHANGED
@@ -16,10 +16,11 @@ import {
16
16
  calculateActiveMinutes,
17
17
  calculateCostMicrodollars,
18
18
  generateApiKey,
19
+ isSqliteAvailable,
19
20
  loadTlsOptions,
20
21
  parseSessionJsonl,
21
22
  resolveTlsConfig
22
- } from "./chunk-6JZXAFPC.js";
23
+ } from "./chunk-TUFSIGGJ.js";
23
24
 
24
25
  // src/issue-detector.ts
25
26
  function detectIssues(events) {
@@ -476,15 +477,26 @@ function endpointKey(method, normalizedPath, baseUrl) {
476
477
  var ApiDiscoveryEngine = class {
477
478
  endpoints = /* @__PURE__ */ new Map();
478
479
  store;
480
+ lastRebuildEventCount = 0;
481
+ isDirty = true;
479
482
  constructor(store) {
480
483
  this.store = store;
481
484
  }
485
+ /** Mark the cache dirty so the next read triggers a rebuild */
486
+ markDirty() {
487
+ this.isDirty = true;
488
+ }
482
489
  rebuild() {
483
- this.endpoints.clear();
484
490
  const events = this.store.getNetworkRequests();
491
+ if (!this.isDirty && events.length === this.lastRebuildEventCount) {
492
+ return;
493
+ }
494
+ this.endpoints.clear();
485
495
  for (const event of events) {
486
496
  this.ingestEvent(event);
487
497
  }
498
+ this.lastRebuildEventCount = events.length;
499
+ this.isDirty = false;
488
500
  }
489
501
  ingestEvent(event) {
490
502
  const { baseUrl, normalizedPath } = normalizeUrl(event.url);
@@ -2091,6 +2103,7 @@ export {
2091
2103
  detectOverfetching,
2092
2104
  detectSlowQueries,
2093
2105
  generateApiKey,
2106
+ isSqliteAvailable,
2094
2107
  loadTlsOptions,
2095
2108
  parseSessionJsonl,
2096
2109
  resolveTlsConfig,