tdem-web-sdk 1.0.12 → 1.0.14

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 (35) hide show
  1. package/README.md +21 -0
  2. package/lib/packages/core/src/http/request-finalizer.d.ts +25 -0
  3. package/lib/packages/core/src/index.d.ts +6 -2
  4. package/lib/packages/core/src/interface/config.d.ts +1 -0
  5. package/lib/packages/core/src/interface/env.d.ts +1 -0
  6. package/lib/packages/core/src/interface/event.d.ts +27 -2
  7. package/lib/packages/core/src/interface/index.d.ts +1 -1
  8. package/lib/packages/core/src/pipes/tdem-sample-gate.d.ts +3 -2
  9. package/lib/packages/core/src/sample/evaluate.d.ts +5 -1
  10. package/lib/packages/core/src/sample/eventTypes.d.ts +16 -2
  11. package/lib/packages/core/src/sample/types.d.ts +1 -0
  12. package/lib/packages/core/src/util/event-session.d.ts +5 -0
  13. package/lib/packages/core/src/util/index.d.ts +5 -0
  14. package/lib/packages/web-sdk/src/index.core.d.ts +6 -0
  15. package/lib/packages/web-sdk/src/index.d.ts +2 -0
  16. package/lib/packages/web-sdk/src/interface/core.d.ts +9 -0
  17. package/lib/packages/web-sdk/src/interface/index.d.ts +6 -2
  18. package/lib/packages/web-sdk/src/plugins/cgi-speed/dial-observation.d.ts +44 -0
  19. package/lib/packages/web-sdk/src/plugins/cgi-speed/sse-observer.d.ts +2 -0
  20. package/lib/packages/web-sdk/src/plugins/{session-replay → click-detection}/click-detector.d.ts +10 -7
  21. package/lib/packages/web-sdk/src/plugins/session-replay/index.d.ts +1 -1
  22. package/lib/packages/web-sdk/src/plugins/session-replay/logger.d.ts +4 -33
  23. package/lib/packages/web-sdk/src/plugins/session-replay/types.d.ts +1 -1
  24. package/lib/packages/web-sdk/src/plugins/struggle-monitor.d.ts +4 -0
  25. package/lib/packages/web-sdk/src/tdem.d.ts +11 -0
  26. package/lib/packages/web-sdk/src/util/click-target.d.ts +5 -0
  27. package/lib/packages/web-sdk/src/util/entry-registry.d.ts +28 -0
  28. package/lib/packages/web-sdk/src/util/logger.d.ts +35 -0
  29. package/lib/tdem.core.global.min.js +10 -0
  30. package/lib/tdem.core.min.js +10 -0
  31. package/lib/tdem.f.min.js +3 -3
  32. package/lib/tdem.global.min.js +3 -3
  33. package/lib/tdem.ie.min.js +3 -3
  34. package/lib/tdem.min.js +3 -3
  35. package/package.json +17 -1
package/README.md CHANGED
@@ -29,6 +29,27 @@ const tdem = new TDEM({
29
29
 
30
30
  省略 `version` 时,上报里的应用版本是字符串 `1.0.0`。
31
31
 
32
+ ## 入口
33
+
34
+ 同一个包提供两个入口,默认入口保持完整能力:
35
+
36
+ ```javascript
37
+ // 完整入口(默认):含会话回放
38
+ import TDEM from 'tdem-web-sdk';
39
+
40
+ // core 入口:不含会话回放,体积更小
41
+ import TDEMCore from 'tdem-web-sdk/core';
42
+ ```
43
+
44
+ | 入口 | 体积(gzip9) | 能力 |
45
+ |---|---:|---|
46
+ | `tdem-web-sdk` | 148,055 B | 基础监控 + 会话回放 + 错误回溯 + 远程回放策略 |
47
+ | `tdem-web-sdk/core` | 56,184 B(UMD) | 基础监控(错误/性能/资源/API/点击/控制台/SPA/设备/白屏/卡顿/内存/bridge/挣扎事件) |
48
+
49
+ core 入口没有 `sessionReplay`:传入该配置只会 `console.warn` 并忽略,不影响其它监控。IE 与指纹变体只在完整入口提供。
50
+
51
+ 升级整包即可;core 与完整入口可互换引用,回滚请回退整个包版本;同页同时加载两个入口会按项目 id 去重。
52
+
32
53
  ## 什么时候会有数据
33
54
 
34
55
  创建实例后,SDK 会先请求 `POST {url}/api/v1/config`。控制台未打开采集、采样未命中,或这次请求失败且本地没有可用缓存时,后续插件不会启动,事件也不会发出。控制台会出现:
@@ -0,0 +1,25 @@
1
+ /** Fields a request finalizer may add; transport/status and other event fields stay with the collector. */
2
+ export interface RequestFinalizationFields {
3
+ req_dial_links?: string;
4
+ req_dial_links_truncated?: string;
5
+ dns_dial_links?: string;
6
+ dns_dial_links_truncated?: string;
7
+ }
8
+ export declare type RequestFinalizerResult = void | RequestFinalizationFields | PromiseLike<void | RequestFinalizationFields>;
9
+ export interface RequestFinalizerOptions {
10
+ /** Replacing a handler is explicit and invalidates all its pending results. */
11
+ replace?: boolean;
12
+ }
13
+ export interface RequestFinalizerLease<T, R> {
14
+ readonly handler: (observation: Readonly<T>) => R;
15
+ }
16
+ export declare const requestFinalizationFields: (value: unknown) => RequestFinalizationFields;
17
+ /** One owner per module. Disposers and pending results are bound to the registration, not the function identity. */
18
+ export declare const createRequestFinalizerSlot: <T, R extends RequestFinalizerResult = void | RequestFinalizationFields>(onChange?: (() => void) | undefined) => {
19
+ register: (handler: (observation: Readonly<T>) => R, options?: RequestFinalizerOptions) => (() => void);
20
+ capture: () => RequestFinalizerLease<T, R> | null;
21
+ isCurrent: (lease: RequestFinalizerLease<T, R> | null) => boolean;
22
+ onInvalidated: (lease: RequestFinalizerLease<T, R>, cancel: () => void) => (() => void);
23
+ invokeSync: (lease: RequestFinalizerLease<T, R> | null, observation: Readonly<T>) => RequestFinalizationFields;
24
+ invoke: (lease: RequestFinalizerLease<T, R> | null, observation: Readonly<T>, timeoutMs: number) => RequestFinalizationFields | Promise<RequestFinalizationFields>;
25
+ };
@@ -3,11 +3,15 @@ import Core from './core';
3
3
  import Plugin from './plugin';
4
4
  export { Plugin };
5
5
  export default Core;
6
- export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, SSECallOutcome, SSECallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, ProcessSignalEventName, ProcessSignalEventProperties, ProcessSignalEventData, ProcessSignalEvent, AppMetricsEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './interface';
6
+ export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, SSECallOutcome, SSECallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, ProcessSignalEventName, ProcessSignalEventProperties, ProcessSignalEventData, ProcessSignalEvent, AppMetricsEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, resolveEnvironment, } from './interface';
7
7
  export { getDefaultConfig, setConfigUrl, globalAny, REPORT_TIMEOUT, MAX_FROM_LENGTH, ERROR_MSG_IGNORE, URL_SPEED_IGNORE, RESOURCE_TYPE_FETCH, RESOURCE_TYPE_STATIC, UNKNOWN, RESOURCE_TYPE, MAX_PROMISE_ERROR_MSG_LENGTH, } from './constant';
8
8
  export * from './pipes';
9
9
  export * from './util';
10
+ export { eventSession, readEventSession } from './util/event-session';
10
11
  export * from './sample/types';
11
12
  export { evaluateEventSample } from './sample/evaluate';
13
+ export type { EvaluateEventSampleOptions } from './sample/evaluate';
12
14
  export { resolveSampleConfig } from './sample/resolve';
13
- export { WEB_SAMPLE_EVENT_TYPES, isWebSampleEventType } from './sample/eventTypes';
15
+ export { WEB_SAMPLE_EVENT_TYPES, WEB_SAMPLE_EVENT_TYPE_SET, MP_SAMPLE_EVENT_TYPES, MP_SAMPLE_EVENT_TYPE_SET, ANDROID_SAMPLE_EVENT_TYPES, ANDROID_SAMPLE_EVENT_TYPE_SET, IOS_SAMPLE_EVENT_TYPES, IOS_SAMPLE_EVENT_TYPE_SET, ELECTRON_SAMPLE_EVENT_TYPES, ELECTRON_SAMPLE_EVENT_TYPE_SET, isWebSampleEventType, sampleEventTypesFor, sampleEventTypeSet, isSampleEventType, } from './sample/eventTypes';
16
+ export { createRequestFinalizerSlot, requestFinalizationFields } from './http/request-finalizer';
17
+ export type { RequestFinalizationFields, RequestFinalizerResult, RequestFinalizerOptions, RequestFinalizerLease } from './http/request-finalizer';
@@ -28,6 +28,7 @@ export interface Config {
28
28
  onError?: boolean;
29
29
  env?: string;
30
30
  version?: number | string;
31
+ llmVersion?: string;
31
32
  delay?: number;
32
33
  repeat?: number | Record<string, number>;
33
34
  url?: string;
@@ -8,4 +8,5 @@ export declare enum Environment {
8
8
  test = "test",
9
9
  others = "others"
10
10
  }
11
+ export declare const resolveEnvironment: (env?: string | null | undefined) => Environment;
11
12
  export declare const isEnvironment: (val: string) => boolean;
@@ -39,7 +39,9 @@ export declare enum EventType {
39
39
  FORM_SUBMIT_RESULT = "form_submit_result",
40
40
  STRUGGLE = "struggle",
41
41
  CUSTOM = "custom",
42
- LOG = "log"
42
+ LOG = "log",
43
+ DIAL_PROBE = "dial_probe",
44
+ DIAL_MTR = "dial_mtr"
43
45
  }
44
46
  /**
45
47
  * 事件分类枚举
@@ -192,6 +194,8 @@ export interface APIErrorEvent extends BaseEvent {
192
194
  response_body?: string;
193
195
  measurements?: {
194
196
  duration?: number;
197
+ /** 本次请求的 DNS 阶段耗时。未发生解析时为 0;测不到时不写。 */
198
+ dns_time?: number;
195
199
  };
196
200
  exception_stacks?: ExceptionStack[];
197
201
  replay_id?: string;
@@ -271,6 +275,8 @@ export interface APICallEvent extends BaseEvent {
271
275
  url: string;
272
276
  measurements: {
273
277
  duration: number;
278
+ /** 本次请求的 DNS 阶段耗时。未发生解析时为 0;测不到时不写。 */
279
+ dns_time?: number;
274
280
  request_size?: number;
275
281
  response_size?: number;
276
282
  };
@@ -334,6 +340,10 @@ export interface SSECallEvent extends BaseEvent {
334
340
  request_headers?: string;
335
341
  response_headers?: string;
336
342
  replay_offset_ms?: string;
343
+ /** 连接发起时的 llmVersion 快照。空白或未配置为 unknown。 */
344
+ model_version: string;
345
+ /** 已拿到的 IPv4/IPv6 字面量。浏览器省略。 */
346
+ server_ip?: string;
337
347
  };
338
348
  };
339
349
  }
@@ -729,7 +739,15 @@ export interface LogEvent extends BaseEvent {
729
739
  /**
730
740
  * 所有事件的联合类型
731
741
  */
732
- export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | SSECallEvent | WebVitalsEvent | LagDetectedEvent | NoResponseEvent | BlankScreenEvent | MemoryUsageEvent | AppMetricsEvent | ProcessSignalEvent | MemoryOOMEvent | FileIoEvent | ClickEvent | ScrollEvent | LongPressEvent | PageViewEvent | LifecycleEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent;
742
+ export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | SSECallEvent | WebVitalsEvent | LagDetectedEvent | NoResponseEvent | BlankScreenEvent | MemoryUsageEvent | AppMetricsEvent | ProcessSignalEvent | MemoryOOMEvent | FileIoEvent | ClickEvent | ScrollEvent | LongPressEvent | PageViewEvent | LifecycleEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent | DialEvent;
743
+ export interface DialEvent extends BaseEvent {
744
+ event_type: EventType.DIAL_PROBE | EventType.DIAL_MTR;
745
+ event_category: EventCategory.NETWORK;
746
+ platform?: string;
747
+ os?: string;
748
+ session_id?: string;
749
+ user_id?: string;
750
+ }
733
751
  /** @internal Protocol-level input used by automatic struggle detectors. */
734
752
  export interface ReportStruggleParams {
735
753
  type: StruggleEventName;
@@ -751,6 +769,13 @@ export interface ReportStruggleParams {
751
769
  tags?: Record<string, string>;
752
770
  /** Business properties written flat into data.event_properties. */
753
771
  properties?: EventProperties;
772
+ /** @internal Frozen source context for delayed automatic detections. */
773
+ sourceContext?: {
774
+ timestamp: number;
775
+ sessionId: string;
776
+ viewId: string;
777
+ replayId: string;
778
+ };
754
779
  }
755
780
  export interface ReportFormSubmitResultParams {
756
781
  status: FormSubmitStatus;
@@ -2,5 +2,5 @@ export { Config, InternalConfig, CoreApiConfig, PagePerformanceStruct } from './
2
2
  export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, PlatTypeNum, NetworkTypeNum, } from './log';
3
3
  export { SendOption, SendSuccess, SendFail, SendType, } from './send';
4
4
  export { Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, } from './transport';
5
- export { Environment, } from './env';
5
+ export { Environment, resolveEnvironment, } from './env';
6
6
  export { EventType, EventCategory, BaseEvent, EventContext, SDKInfo, AppInfo, CollectEventsRequest, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, SSECallOutcome, SSECallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, ProcessSignalEventName, ProcessSignalEventProperties, ProcessSignalEventData, ProcessSignalEvent, AppMetricsEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './event';
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * TDEM 采样闸门管道
3
3
  *
4
- * Web:若实例上挂了 `_tdemSampleConfig`(规则化文档),按事件独立抽签。
5
- * 其它端:保持 Session 全有/全无闸门。
4
+ * 若实例上挂了 `_tdemSampleConfig`(规则化文档),按事件独立抽签。
5
+ * 可通过 `_tdemSampleEvaluateOptions` 注入闭集与 page_path 派生策略。
6
+ * 未挂文档时保持 Session 全有/全无闸门。
6
7
  */
7
8
  import { Pipe } from './index';
8
9
  import { TDEMEvent } from '../interface/event';
@@ -1,2 +1,6 @@
1
1
  import { SampleConfigDocument, SampleEventView } from './types';
2
- export declare function evaluateEventSample(event: SampleEventView, config?: SampleConfigDocument, random?: () => number): boolean;
2
+ export declare type EvaluateEventSampleOptions = {
3
+ closedSet?: ReadonlySet<string>;
4
+ derivePagePath?: boolean;
5
+ };
6
+ export declare function evaluateEventSample(event: SampleEventView, config?: SampleConfigDocument, random?: () => number, options?: EvaluateEventSampleOptions): boolean;
@@ -1,9 +1,23 @@
1
1
  /**
2
2
  * Web 规则化采样左树闭集,对齐 event-types-inventory.md §3.1。
3
- * 不含 rage_click / lcp 等假类型,也不含 behavior 大类(click / page_view / struggle 等永远 100%)。
3
+ * 不含 rage_click / lcp 等假类型,也不含 behavior / log(永远 100%;log 与自定义事件重叠,前端不提供采样)。
4
+ *
5
+ * 104 四端闭集与 Web 并存;不要用 WEB_SAMPLE_EVENT_TYPES 去过滤 Electron / 原生。
4
6
  */
5
- export declare const WEB_SAMPLE_EVENT_CATEGORIES: readonly ["error", "performance", "network", "custom", "log"];
7
+ export declare const WEB_SAMPLE_EVENT_CATEGORIES: readonly ["error", "performance", "network", "custom"];
6
8
  export declare type WebSampleEventCategory = (typeof WEB_SAMPLE_EVENT_CATEGORIES)[number];
7
9
  export declare const WEB_SAMPLE_EVENT_TYPES: Record<WebSampleEventCategory, readonly string[]>;
8
10
  export declare const WEB_SAMPLE_EVENT_TYPE_SET: ReadonlySet<string>;
9
11
  export declare function isWebSampleEventType(type: string): boolean;
12
+ export declare const MP_SAMPLE_EVENT_TYPES: Record<string, readonly string[]>;
13
+ export declare const ANDROID_SAMPLE_EVENT_TYPES: Record<string, readonly string[]>;
14
+ export declare const IOS_SAMPLE_EVENT_TYPES: Record<string, readonly string[]>;
15
+ export declare const ELECTRON_SAMPLE_EVENT_TYPES: Record<string, readonly string[]>;
16
+ export declare const MP_SAMPLE_EVENT_TYPE_SET: ReadonlySet<string>;
17
+ export declare const ANDROID_SAMPLE_EVENT_TYPE_SET: ReadonlySet<string>;
18
+ export declare const IOS_SAMPLE_EVENT_TYPE_SET: ReadonlySet<string>;
19
+ export declare const ELECTRON_SAMPLE_EVENT_TYPE_SET: ReadonlySet<string>;
20
+ export declare type RuleSamplingAppType = 'web' | 'wx-miniprogram' | 'android' | 'ios' | 'electron';
21
+ export declare function sampleEventTypesFor(appType: string): Record<string, readonly string[]> | undefined;
22
+ export declare function sampleEventTypeSet(appType: string): ReadonlySet<string> | undefined;
23
+ export declare function isSampleEventType(appType: string, type: string): boolean;
@@ -46,6 +46,7 @@ export interface SampleEventView {
46
46
  browser?: string;
47
47
  browser_version?: string;
48
48
  network?: string;
49
+ process_type?: string;
49
50
  tags?: Record<string, unknown>;
50
51
  event_properties?: Record<string, unknown>;
51
52
  }
@@ -0,0 +1,5 @@
1
+ import Core from '../core';
2
+ import { TDEMEvent } from '../interface/event';
3
+ export declare function readEventSession(tdem: Core): string;
4
+ export declare function stampEventSession(event: TDEMEvent, sessionId: string): void;
5
+ export declare function eventSession(event: TDEMEvent): string | undefined;
@@ -13,6 +13,11 @@ export declare const buildLog2Json: (logs: any | any[]) => string;
13
13
  interface P {
14
14
  [k: string]: any;
15
15
  }
16
+ /**
17
+ * 抹掉上报里的敏感词 eval(微信会拦截含该词的请求)。
18
+ * evaluate_script 含有子串 eval,必须原样保留,否则键会变成 evaIuate_script。
19
+ */
20
+ export declare function maskEvalKeyword(input: string): string;
16
21
  /**
17
22
  * 拼接上报请求 query 参数
18
23
  * @param url
@@ -0,0 +1,6 @@
1
+ import './polyfill';
2
+ import TDEM from './tdem';
3
+ declare const _default: typeof TDEM;
4
+ export default _default;
5
+ export { registerCgiRequestFinalizer } from './plugins/cgi-speed/dial-observation';
6
+ export type { CoreWebConfig } from './interface/core';
@@ -1,4 +1,6 @@
1
1
  import './polyfill';
2
2
  import TDEM from './tdem';
3
3
  export default TDEM;
4
+ export { registerCgiRequestFinalizer } from './plugins/cgi-speed/dial-observation';
4
5
  export { WebConfig, LagMonitorConfig, BlankScreenConfig, MemoryMonitorConfig, ElementMatcher, } from './interface';
6
+ export type { CgiDialObservation, CgiRequestFinalizer } from './plugins/cgi-speed/dial-observation';
@@ -0,0 +1,9 @@
1
+ import { WebConfig } from './index';
2
+ /**
3
+ * core 入口对外配置投影。
4
+ *
5
+ * 复用完整入口的 `WebConfig` 定义,仅剔除回放相关字段,不手写第二份配置,
6
+ * 避免两套类型随实现漂移。core 入口不注册会话回放,因此 `sessionReplay`
7
+ * 不应出现在core类型面里。
8
+ */
9
+ export declare type CoreWebConfig = Omit<WebConfig, 'sessionReplay'>;
@@ -1,5 +1,6 @@
1
1
  import { Config, InternalConfig, CoreApiConfig, TraceType, TraceRequestHeader, PagePerformanceStruct, SampleConfigDocument } from "../../../core/src";
2
2
  import { SessionReplayConfig } from '../plugins/session-replay/types';
3
+ import { StruggleMonitorConfig } from '../plugins/struggle-monitor';
3
4
  export declare type ApiMonitorConfig = CoreApiConfig & {
4
5
  injectTraceHeader?: TraceType;
5
6
  injectTraceUrls?: Array<string | RegExp>;
@@ -105,10 +106,13 @@ export interface WebConfig extends Config {
105
106
  websocket?: boolean | WebSocketMonitorConfig;
106
107
  webVitals?: boolean | WebVitalsConfig;
107
108
  sessionReplay?: boolean | SessionReplayConfig;
108
- sampleConfigPreference?: 'remote-first' | 'local-first';
109
- sampleConfig?: SampleConfigDocument;
110
109
  /** 远程优先 | 本地优先;默认 remote-first */
111
110
  sampleConfigPreference?: 'remote-first' | 'local-first';
111
+ sampleConfig?: SampleConfigDocument;
112
+ struggleMonitor?: boolean | StruggleMonitorConfig;
113
+ lagMonitor?: boolean | LagMonitorConfig;
114
+ blankScreen?: boolean | BlankScreenConfig;
115
+ memoryMonitor?: boolean | MemoryMonitorConfig;
112
116
  }
113
117
  /**
114
118
  * Web SDK 内部过渡配置。
@@ -0,0 +1,44 @@
1
+ import type { RequestFinalizationFields, RequestFinalizerResult, RequestFinalizerLease } from "../../../../core/src";
2
+ export interface CgiDialObservation {
3
+ requestId: string;
4
+ source: 'renderer_fetch_xhr';
5
+ host: string;
6
+ url: string;
7
+ statusCode: number;
8
+ errorCode: string;
9
+ durationMs: number;
10
+ /** Browser DNS interval; absent when no usable timing entry is available. */
11
+ dnsTimeMs?: number;
12
+ willReport: boolean;
13
+ process: 'renderer';
14
+ startedAtMs: number;
15
+ }
16
+ export declare type CgiRequestFinalizer = (observation: Readonly<CgiDialObservation>) => RequestFinalizerResult;
17
+ export declare const registerCgiRequestFinalizer: (handler: (observation: Readonly<CgiDialObservation>) => RequestFinalizerResult, options?: import("../../../../core/src").RequestFinalizerOptions) => () => void;
18
+ export declare const beginCgiRequest: (url: string, initiatorType?: "fetch" | "xmlhttprequest" | undefined) => string;
19
+ export declare const endCgiRequest: (url: string, id?: string | undefined) => void;
20
+ /** Transport has ended, but keep its owner until the deferred HTTP report is finalized. */
21
+ export declare const releaseCgiRequest: (id: string) => void;
22
+ export declare const rendererDnsTime: (url: string, startedAtMs: number, requestId?: string | undefined) => number | undefined;
23
+ export declare const waitForRendererResourceTiming: (url: string, startedAtMs: number, requestId?: string | undefined) => Promise<'settled' | 'timeout'> | 'settled';
24
+ export declare const notifyCgiFinalObservation: (input: {
25
+ requestId: string;
26
+ url: string;
27
+ statusCode: number;
28
+ durationMs: number;
29
+ willReport: boolean;
30
+ startedAtMs: number;
31
+ transportFailure?: boolean | undefined;
32
+ timingUnavailable?: boolean | undefined;
33
+ }, owner?: RequestFinalizerLease<CgiDialObservation, RequestFinalizerResult> | null, measured?: {
34
+ ms?: number | undefined;
35
+ } | undefined) => RequestFinalizationFields | Promise<RequestFinalizationFields>;
36
+ export declare const publishAfterDialObservation: (input: {
37
+ requestId: string;
38
+ url: string;
39
+ statusCode: number;
40
+ durationMs: number;
41
+ willReport: boolean;
42
+ startedAtMs: number;
43
+ transportFailure?: boolean;
44
+ }, publish: (fields: RequestFinalizationFields, dnsTime?: number | undefined) => void) => void;
@@ -33,6 +33,7 @@ export declare function resolveSseNetworkMeta(input: {
33
33
  httpMethod: string;
34
34
  redirectCount: number;
35
35
  };
36
+ export declare function normalizeModelVersion(value: unknown): string;
36
37
  export declare function createSseObserver(options: {
37
38
  url: string;
38
39
  httpMethod: string;
@@ -43,6 +44,7 @@ export declare function createSseObserver(options: {
43
44
  redirectCount?: number;
44
45
  replayId?: string | undefined;
45
46
  now?: () => number;
47
+ llmVersion?: string;
46
48
  }): SseObserver;
47
49
  export declare function readSseResponseBody(body: {
48
50
  getReader: () => {
@@ -14,7 +14,7 @@ export interface ClickDetectorOptions {
14
14
  slowClickThreshold?: number;
15
15
  /** 愤怒点击次数阈值,默认 5 */
16
16
  rageClickCount?: number;
17
- /** 愤怒点击时间窗口(毫秒),默认 1000 */
17
+ /** 愤怒点击时间窗口(毫秒),默认 3000 */
18
18
  rageClickWindow?: number;
19
19
  /** 慢点击回调 */
20
20
  onSlowClick?: (data: SlowClickData) => void;
@@ -26,6 +26,7 @@ export interface ClickDetectorOptions {
26
26
  onEffectiveAction?: (data: EffectiveActionData) => void;
27
27
  /** 死点击回调 */
28
28
  onDeadClick?: (data: DeadClickData) => void;
29
+ getClickContext?: () => string;
29
30
  }
30
31
  /** 慢点击数据 */
31
32
  export interface SlowClickData {
@@ -48,6 +49,8 @@ export interface RageClickData {
48
49
  timeWindowMs: number;
49
50
  /** 开始时间戳 */
50
51
  timestamp: number;
52
+ clicks: ClickStartData[];
53
+ lastTimestamp: number;
51
54
  }
52
55
  /** 死点击数据 */
53
56
  export interface DeadClickData {
@@ -74,7 +77,7 @@ export interface ClickStartData {
74
77
  node: ClickNodeInfo;
75
78
  timestamp: number;
76
79
  target: HTMLElement;
77
- event: PointerEvent;
80
+ event: MouseEvent;
78
81
  effectiveActionReason?: EffectiveActionReason;
79
82
  }
80
83
  /** 有效动作数据 */
@@ -93,9 +96,10 @@ export declare class ClickDetector {
93
96
  private clickNode;
94
97
  private slowClickTimeoutId;
95
98
  private mutationObserver;
96
- private clickHistory;
97
- private rageActiveTarget;
98
- private rageLastClickTime;
99
+ private rage;
100
+ private rageTimer;
101
+ private closeRage;
102
+ private onVisibility;
99
103
  constructor(options?: ClickDetectorOptions);
100
104
  /**
101
105
  * 启动检测
@@ -113,6 +117,7 @@ export declare class ClickDetector {
113
117
  * 处理 click 事件(用于愤怒点击检测)
114
118
  */
115
119
  private handleClick;
120
+ finishRage(): void;
116
121
  /**
117
122
  * 启动 MutationObserver
118
123
  */
@@ -129,7 +134,6 @@ export declare class ClickDetector {
129
134
  * 清理慢点击检测状态
130
135
  */
131
136
  private cleanupSlowClick;
132
- private isSameTarget;
133
137
  /**
134
138
  * 标记当前点击已产生有效动作
135
139
  */
@@ -138,7 +142,6 @@ export declare class ClickDetector {
138
142
  /**
139
143
  * 获取可点击元素
140
144
  */
141
- private getClickableElement;
142
145
  private getExternalNavigationReason;
143
146
  /**
144
147
  * 获取节点信息
@@ -14,7 +14,7 @@ export { EventBuffer } from './event-buffer';
14
14
  export { RecorderManager } from './recorder-manager';
15
15
  export { SamplerManager } from './sampler-manager';
16
16
  export { Uploader } from './uploader';
17
- export { ClickDetector } from './click-detector';
17
+ export { ClickDetector } from '../click-detection/click-detector';
18
18
  export * from './types';
19
19
  export * from './constants';
20
20
  export * from './privacy';
@@ -1,35 +1,6 @@
1
1
  /**
2
- * SessionReplay Logger - 统一日志管理
3
- *
4
- * 所有 session-replay 模块的日志统一通过此模块输出:
5
- * - 支持 debug 开关,默认关闭,生产环境不输出任何日志
6
- * - 避免 console.warn/error 被日志监控误杀
7
- * - 统一前缀格式 [SessionReplay:模块名]
2
+ * SessionReplay Logger - compatibility re-export.
3
+ * Shared click detection uses the same debug logger without importing
4
+ * anything from the session-replay directory.
8
5
  */
9
- /**
10
- * 设置 debug 模式
11
- * @param enabled true 时输出所有级别日志,false 时静默
12
- */
13
- export declare function setDebugMode(enabled: boolean): void;
14
- /**
15
- * 获取 debug 模式状态
16
- */
17
- export declare function isDebugMode(): boolean;
18
- /**
19
- * 普通信息日志(debug 模式下输出)
20
- */
21
- export declare function logInfo(module: string, ...args: any[]): void;
22
- /**
23
- * 调试日志(debug 模式下输出)
24
- */
25
- export declare function logDebug(module: string, ...args: any[]): void;
26
- /**
27
- * 警告日志(debug 模式下输出)
28
- * 不使用 console.warn,避免被日志监控捕获
29
- */
30
- export declare function logWarn(module: string, ...args: any[]): void;
31
- /**
32
- * 错误日志(始终输出,因为错误通常需要被感知)
33
- * 使用 console.log 而非 console.error,避免被日志监控误杀
34
- */
35
- export declare function logError(module: string, ...args: any[]): void;
6
+ export * from '../../util/logger';
@@ -57,7 +57,7 @@ export interface SessionReplayConfig {
57
57
  slowClickThreshold?: number;
58
58
  /** 愤怒点击次数阈值,默认 5 */
59
59
  rageClickCount?: number;
60
- /** 愤怒点击时间窗口(毫秒),默认 1000 */
60
+ /** 愤怒点击时间窗口(毫秒),默认 3000 */
61
61
  rageClickWindow?: number;
62
62
  /**
63
63
  * 是否启用 Mutation 合并(默认 false)
@@ -6,6 +6,8 @@ export interface StruggleMonitorConfig {
6
6
  click?: {
7
7
  enabled?: boolean;
8
8
  deadClickWindowMs?: number;
9
+ /** Same-node trailing debounce, 1..60000ms; default 1000ms. */
10
+ deadClickDebounceIntervalMs?: number;
9
11
  rageClickWindowMs?: number;
10
12
  rageClickCount?: number;
11
13
  errorClickWindowMs?: number;
@@ -18,6 +20,8 @@ export interface StruggleMonitorConfig {
18
20
  resolveOnApiSuccess?: boolean;
19
21
  ignoreDeadClickSelectors?: string[];
20
22
  effectiveActionSelectors?: string[];
23
+ /** 额外视为可点击的选择器,用于事件委托等无法从 DOM 识别的控件。 */
24
+ clickableSelectors?: string[];
21
25
  };
22
26
  performance?: {
23
27
  enabled?: boolean;
@@ -1,6 +1,13 @@
1
1
  import Core, { SendOption, SendSuccess, SendFail, InternalSdkOptions, ReportPageViewOptions } from "../../core/src";
2
2
  import { MarkDoms, InternalWebConfig } from './interface';
3
3
  export default class TDEM extends Core {
4
+ /**
5
+ * 入口标识,由 index.ts / index.core.ts 在模块加载时设置,
6
+ * 用于注册表 warn 文案与 owner 归属,不影响去重 key(key 始终是项目 id)。
7
+ */
8
+ static entryName: string;
9
+ /** 是否因同项目 id 已被其它入口初始化而跳过本次初始化(公开只读语义,便于验证) */
10
+ _entrySkipped: boolean;
4
11
  static sessionID: string;
5
12
  sendNow: boolean;
6
13
  isReportReady: boolean;
@@ -102,4 +109,8 @@ export default class TDEM extends Core {
102
109
  TTI?: number;
103
110
  from?: string;
104
111
  }>): void;
112
+ /**
113
+ * 销毁实例时释放入口注册表占用,允许同项目 id 后续重新初始化。
114
+ */
115
+ destroy(force?: boolean): void;
105
116
  }
@@ -0,0 +1,5 @@
1
+ import Core, { TDEMEvent } from "../../../core/src";
2
+ export declare function interactionTarget(element: Element): HTMLElement;
3
+ export declare function isClickable(element: Element, extraSelectors?: string[]): boolean;
4
+ export declare function rememberSourceClick(event: Event, tdem: Core, source: TDEMEvent): void;
5
+ export declare function sourceClick(event: Event, tdem: Core): TDEMEvent | undefined;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 跨 bundle 入口注册表:以项目 id 为 key,保证同页只初始化一份 core。
3
+ *
4
+ * 完整入口与轻量入口各自内嵌一份编译后的 core,因此注册表不能放在模块变量里,
5
+ * 只能挂到全局对象(globalThis)上让两个 bundle 共享;也不依赖 `window.TDEM`。
6
+ *
7
+ * - 首个 claim 的入口成为 owner,另一个入口用同 id claim 时返回 `skipped_duplicate`;
8
+ * - 同一入口重复 claim 保持历史行为(同入口多实例仍允许);
9
+ * - 不同项目 id 互不影响;无项目 id 时不去重;
10
+ * - `state` 记录 claim → initialized,供"已初始化 core 数"断言使用。
11
+ */
12
+ export interface EntryRecord {
13
+ owner: string;
14
+ /** 0 = claimed,1 = initialized */
15
+ state: 0 | 1;
16
+ }
17
+ export declare type EntryClaim = {
18
+ status: 'owned' | 'skipped_duplicate';
19
+ owner: string;
20
+ };
21
+ export declare function claimEntry(projectId: unknown, owner: string): EntryClaim;
22
+ export declare function markEntryInitialized(projectId: unknown, owner: string): void;
23
+ export declare function releaseEntry(projectId: unknown, owner: string): void;
24
+ export declare function getEntryOwner(projectId: unknown): string | null;
25
+ export declare function getInitializedEntryCount(projectId?: unknown): number;
26
+ /** 仅用于测试隔离。 */
27
+ export declare function resetEntryRegistry(): void;
28
+ export declare const ENTRY_REGISTRY_KEY = "__TDEM_ENTRY_REGISTRY__";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * SessionReplay Logger - 统一日志管理
3
+ *
4
+ * 所有 session-replay 模块的日志统一通过此模块输出:
5
+ * - 支持 debug 开关,默认关闭,生产环境不输出任何日志
6
+ * - 避免 console.warn/error 被日志监控误杀
7
+ * - 统一前缀格式 [SessionReplay:模块名]
8
+ */
9
+ /**
10
+ * 设置 debug 模式
11
+ * @param enabled true 时输出所有级别日志,false 时静默
12
+ */
13
+ export declare function setDebugMode(enabled: boolean): void;
14
+ /**
15
+ * 获取 debug 模式状态
16
+ */
17
+ export declare function isDebugMode(): boolean;
18
+ /**
19
+ * 普通信息日志(debug 模式下输出)
20
+ */
21
+ export declare function logInfo(module: string, ...args: any[]): void;
22
+ /**
23
+ * 调试日志(debug 模式下输出)
24
+ */
25
+ export declare function logDebug(module: string, ...args: any[]): void;
26
+ /**
27
+ * 警告日志(debug 模式下输出)
28
+ * 不使用 console.warn,避免被日志监控捕获
29
+ */
30
+ export declare function logWarn(module: string, ...args: any[]): void;
31
+ /**
32
+ * 错误日志(始终输出,因为错误通常需要被感知)
33
+ * 使用 console.log 而非 console.error,避免被日志监控误杀
34
+ */
35
+ export declare function logError(module: string, ...args: any[]): void;