@antseed/telemetry 0.0.0-stage → 0.1.1
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/LICENSE +674 -0
- package/dist/buckets.d.ts +28 -0
- package/dist/buckets.d.ts.map +1 -0
- package/dist/buckets.js +77 -0
- package/dist/buckets.js.map +1 -0
- package/dist/client.d.ts +49 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +107 -0
- package/dist/client.js.map +1 -0
- package/dist/consent.d.ts +39 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +65 -0
- package/dist/consent.js.map +1 -0
- package/dist/failure.d.ts +42 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +87 -0
- package/dist/failure.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/posthog.d.ts +44 -0
- package/dist/posthog.d.ts.map +1 -0
- package/dist/posthog.js +90 -0
- package/dist/posthog.js.map +1 -0
- package/dist/sanitize.d.ts +31 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +59 -0
- package/dist/sanitize.js.map +1 -0
- package/package.json +24 -3
- package/README.md +0 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coarse buckets for the counts, durations and amounts that are sent as a
|
|
3
|
+
* range, not an exact value (for example a deposit amount). Request timings
|
|
4
|
+
* and token counts are sent exactly; see docs/telemetry.md.
|
|
5
|
+
*/
|
|
6
|
+
export type DurationBucket = 'under_30s' | '30s_2m' | '2m_5m' | 'over_5m';
|
|
7
|
+
export type CountBucket = '0' | '1' | '2_5' | '6_20' | '21_plus';
|
|
8
|
+
export type SmallCountBucket = '0' | '1' | '2_3' | '4_plus';
|
|
9
|
+
export type AttemptCountBucket = '1' | '2' | '3_plus';
|
|
10
|
+
export type SellersTriedBucket = '0' | '1' | '2' | '3_plus';
|
|
11
|
+
/** USDC amount buckets, from integer base units (6 decimals). */
|
|
12
|
+
export type UsdcAmountBucket = 'zero' | 'under_0_01' | '0_01_0_1' | '0_1_1' | '1_10' | 'over_10';
|
|
13
|
+
export declare const DURATION_BUCKETS: ReadonlySet<string>;
|
|
14
|
+
export declare const COUNT_BUCKETS: ReadonlySet<string>;
|
|
15
|
+
export declare const SMALL_COUNT_BUCKETS: ReadonlySet<string>;
|
|
16
|
+
export declare const ATTEMPT_COUNT_BUCKETS: ReadonlySet<string>;
|
|
17
|
+
export declare const SELLERS_TRIED_BUCKETS: ReadonlySet<string>;
|
|
18
|
+
export declare const USDC_AMOUNT_BUCKETS: ReadonlySet<string>;
|
|
19
|
+
export declare function durationBucket(ms: number): DurationBucket;
|
|
20
|
+
export declare function countBucket(count: number): CountBucket;
|
|
21
|
+
export declare function smallCountBucket(count: number): SmallCountBucket;
|
|
22
|
+
export declare function attemptCountBucket(attempts: number): AttemptCountBucket;
|
|
23
|
+
export declare function sellersTriedBucket(count: number): SellersTriedBucket;
|
|
24
|
+
/** Buckets a USDC amount given as integer base units (6 decimals). Never a float. */
|
|
25
|
+
export declare function usdcAmountBucket(baseUnits: bigint): UsdcAmountBucket;
|
|
26
|
+
/** HTTP status as sent: an integer in 100–599, else undefined. */
|
|
27
|
+
export declare function telemetryHttpStatus(statusCode: number | undefined): number | undefined;
|
|
28
|
+
//# sourceMappingURL=buckets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buckets.d.ts","sourceRoot":"","sources":["../src/buckets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAC1E,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,GAAG,GAAG,GAAG,GAAG,KAA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,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coarse buckets for the counts, durations and amounts that are sent as a
|
|
3
|
+
* range, not an exact value (for example a deposit amount). Request timings
|
|
4
|
+
* and token counts are sent exactly; see docs/telemetry.md.
|
|
5
|
+
*/
|
|
6
|
+
export const DURATION_BUCKETS = new Set(['under_30s', '30s_2m', '2m_5m', 'over_5m']);
|
|
7
|
+
export const COUNT_BUCKETS = new Set(['0', '1', '2_5', '6_20', '21_plus']);
|
|
8
|
+
export const SMALL_COUNT_BUCKETS = new Set(['0', '1', '2_3', '4_plus']);
|
|
9
|
+
export const ATTEMPT_COUNT_BUCKETS = new Set(['1', '2', '3_plus']);
|
|
10
|
+
export const SELLERS_TRIED_BUCKETS = new Set(['0', '1', '2', '3_plus']);
|
|
11
|
+
export const USDC_AMOUNT_BUCKETS = new Set(['zero', 'under_0_01', '0_01_0_1', '0_1_1', '1_10', 'over_10']);
|
|
12
|
+
export function durationBucket(ms) {
|
|
13
|
+
if (ms < 30_000)
|
|
14
|
+
return 'under_30s';
|
|
15
|
+
if (ms < 2 * 60_000)
|
|
16
|
+
return '30s_2m';
|
|
17
|
+
if (ms < 5 * 60_000)
|
|
18
|
+
return '2m_5m';
|
|
19
|
+
return 'over_5m';
|
|
20
|
+
}
|
|
21
|
+
export function countBucket(count) {
|
|
22
|
+
if (count <= 0)
|
|
23
|
+
return '0';
|
|
24
|
+
if (count === 1)
|
|
25
|
+
return '1';
|
|
26
|
+
if (count <= 5)
|
|
27
|
+
return '2_5';
|
|
28
|
+
if (count <= 20)
|
|
29
|
+
return '6_20';
|
|
30
|
+
return '21_plus';
|
|
31
|
+
}
|
|
32
|
+
export function smallCountBucket(count) {
|
|
33
|
+
if (count <= 0)
|
|
34
|
+
return '0';
|
|
35
|
+
if (count === 1)
|
|
36
|
+
return '1';
|
|
37
|
+
if (count <= 3)
|
|
38
|
+
return '2_3';
|
|
39
|
+
return '4_plus';
|
|
40
|
+
}
|
|
41
|
+
export function attemptCountBucket(attempts) {
|
|
42
|
+
if (attempts <= 1)
|
|
43
|
+
return '1';
|
|
44
|
+
if (attempts === 2)
|
|
45
|
+
return '2';
|
|
46
|
+
return '3_plus';
|
|
47
|
+
}
|
|
48
|
+
export function sellersTriedBucket(count) {
|
|
49
|
+
if (count <= 0)
|
|
50
|
+
return '0';
|
|
51
|
+
if (count === 1)
|
|
52
|
+
return '1';
|
|
53
|
+
if (count === 2)
|
|
54
|
+
return '2';
|
|
55
|
+
return '3_plus';
|
|
56
|
+
}
|
|
57
|
+
/** Buckets a USDC amount given as integer base units (6 decimals). Never a float. */
|
|
58
|
+
export function usdcAmountBucket(baseUnits) {
|
|
59
|
+
if (baseUnits <= 0n)
|
|
60
|
+
return 'zero';
|
|
61
|
+
if (baseUnits < 10000n)
|
|
62
|
+
return 'under_0_01';
|
|
63
|
+
if (baseUnits < 100000n)
|
|
64
|
+
return '0_01_0_1';
|
|
65
|
+
if (baseUnits < 1000000n)
|
|
66
|
+
return '0_1_1';
|
|
67
|
+
if (baseUnits < 10000000n)
|
|
68
|
+
return '1_10';
|
|
69
|
+
return 'over_10';
|
|
70
|
+
}
|
|
71
|
+
/** HTTP status as sent: an integer in 100–599, else undefined. */
|
|
72
|
+
export function telemetryHttpStatus(statusCode) {
|
|
73
|
+
return typeof statusCode === 'number' && Number.isInteger(statusCode) && statusCode >= 100 && statusCode <= 599
|
|
74
|
+
? statusCode
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=buckets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buckets.js","sourceRoot":"","sources":["../src/buckets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,MAAM,CAAC,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AAC1G,MAAM,CAAC,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,C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0 +1,49 @@
|
|
|
1
|
+
import { type EventCatalog } from './sanitize.js';
|
|
2
|
+
import { type PostHogSender } from './posthog.js';
|
|
3
|
+
import type { PostHogConfig } from './consent.js';
|
|
4
|
+
export declare const TELEMETRY_SCHEMA_VERSION = 2;
|
|
5
|
+
/**
|
|
6
|
+
* A host reports only its own UI (the desktop's screens, the gateway's setup
|
|
7
|
+
* funnel); all usage comes from the buyer, whichever host runs it.
|
|
8
|
+
*/
|
|
9
|
+
export type TelemetryProduct = 'desktop' | 'gateway' | 'buyer';
|
|
10
|
+
export type BuyerHost = 'desktop' | 'gateway' | 'standalone';
|
|
11
|
+
export declare const BUYER_HOSTS: ReadonlySet<string>;
|
|
12
|
+
/** Env a host sets on the buyer it spawns. */
|
|
13
|
+
export declare const TELEMETRY_HOST_ENV = "ANTSEED_TELEMETRY_HOST";
|
|
14
|
+
export declare const TELEMETRY_HOST_SESSION_ID_ENV = "ANTSEED_TELEMETRY_HOST_SESSION_ID";
|
|
15
|
+
/** RFC 9562 UUIDv7. PostHog's Sessions explorer derives session start from these bits. */
|
|
16
|
+
export declare function uuidV7(timestampMs?: number): string;
|
|
17
|
+
export declare const UUID_PATTERN: RegExp;
|
|
18
|
+
/** The buyer's normalized EVM address, or null. Nothing else is a distinct id. */
|
|
19
|
+
export declare function normalizeDistinctId(value: string | null | undefined): string | null;
|
|
20
|
+
export declare function normalizeBuyerHost(value: string | undefined): BuyerHost;
|
|
21
|
+
export type TelemetryClientOptions = {
|
|
22
|
+
product: TelemetryProduct;
|
|
23
|
+
appVersion: string;
|
|
24
|
+
platform?: string;
|
|
25
|
+
arch?: string;
|
|
26
|
+
installSource?: string;
|
|
27
|
+
catalog: EventCatalog;
|
|
28
|
+
getDistinctId: () => string | null;
|
|
29
|
+
/** Checked on every capture and before every flush. */
|
|
30
|
+
isEnabled: () => boolean;
|
|
31
|
+
sender?: PostHogSender;
|
|
32
|
+
posthog?: PostHogConfig | null;
|
|
33
|
+
/** Buyer events: who started this buyer, and that host's session. */
|
|
34
|
+
buyerHost?: BuyerHost;
|
|
35
|
+
hostSessionId?: string | null;
|
|
36
|
+
nowMs?: () => number;
|
|
37
|
+
flushIntervalMs?: number;
|
|
38
|
+
maxQueue?: number;
|
|
39
|
+
};
|
|
40
|
+
export type TelemetryClient = {
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
/** Returns whether the event was queued. Never throws. */
|
|
43
|
+
capture: (event: string, properties?: Readonly<Record<string, unknown>>, eventTsMs?: number) => boolean;
|
|
44
|
+
flush: () => Promise<void>;
|
|
45
|
+
/** Bounded flush for shutdown. */
|
|
46
|
+
close: (timeoutMs?: number) => Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
export declare function createTelemetryClient(options: TelemetryClientOptions): TelemetryClient;
|
|
49
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AASA,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAsD,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACtG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC;AAE7D,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,MAAM,CAA4D,CAAC;AAEzG,8CAA8C;AAC9C,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,6BAA6B,sCAAsC,CAAC;AAEjF,0FAA0F;AAC1F,wBAAgB,MAAM,CAAC,WAAW,GAAE,MAAmB,GAAG,MAAM,CAW/D;AAED,eAAO,MAAM,YAAY,QAA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K,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CA+DtF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A product's telemetry client: one envelope, one sanitizer, one queue.
|
|
3
|
+
*
|
|
4
|
+
* Every event carries `schema_version`, `product`, a per-process UUIDv7
|
|
5
|
+
* session id, the app version and platform. Person profiles are never
|
|
6
|
+
* processed, and every capture sets `$geoip_disable: true`, so PostHog derives
|
|
7
|
+
* no location from the request IP.
|
|
8
|
+
*/
|
|
9
|
+
import { randomBytes } from 'node:crypto';
|
|
10
|
+
import { sanitizeEventProperties } from './sanitize.js';
|
|
11
|
+
import { BatchQueue, createPostHogSender } from './posthog.js';
|
|
12
|
+
export const TELEMETRY_SCHEMA_VERSION = 2;
|
|
13
|
+
export const BUYER_HOSTS = new Set(['desktop', 'gateway', 'standalone']);
|
|
14
|
+
/** Env a host sets on the buyer it spawns. */
|
|
15
|
+
export const TELEMETRY_HOST_ENV = 'ANTSEED_TELEMETRY_HOST';
|
|
16
|
+
export const TELEMETRY_HOST_SESSION_ID_ENV = 'ANTSEED_TELEMETRY_HOST_SESSION_ID';
|
|
17
|
+
/** RFC 9562 UUIDv7. PostHog's Sessions explorer derives session start from these bits. */
|
|
18
|
+
export function uuidV7(timestampMs = Date.now()) {
|
|
19
|
+
const bytes = randomBytes(16);
|
|
20
|
+
let remaining = Math.max(0, Math.floor(timestampMs));
|
|
21
|
+
for (let i = 5; i >= 0; i -= 1) {
|
|
22
|
+
bytes[i] = remaining % 256;
|
|
23
|
+
remaining = Math.floor(remaining / 256);
|
|
24
|
+
}
|
|
25
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x70;
|
|
26
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
27
|
+
const hex = bytes.toString('hex');
|
|
28
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
29
|
+
}
|
|
30
|
+
export const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
31
|
+
/** The buyer's normalized EVM address, or null. Nothing else is a distinct id. */
|
|
32
|
+
export function normalizeDistinctId(value) {
|
|
33
|
+
const normalized = value?.trim().toLowerCase() ?? '';
|
|
34
|
+
return /^0x[0-9a-f]{40}$/.test(normalized) ? normalized : null;
|
|
35
|
+
}
|
|
36
|
+
export function normalizeBuyerHost(value) {
|
|
37
|
+
const normalized = value?.trim().toLowerCase() ?? '';
|
|
38
|
+
return BUYER_HOSTS.has(normalized) ? normalized : 'standalone';
|
|
39
|
+
}
|
|
40
|
+
export function createTelemetryClient(options) {
|
|
41
|
+
const now = options.nowMs ?? (() => Date.now());
|
|
42
|
+
const sessionId = uuidV7(now());
|
|
43
|
+
const sender = options.sender
|
|
44
|
+
?? (options.posthog ? createPostHogSender(options.posthog) : async () => undefined);
|
|
45
|
+
const enabled = () => {
|
|
46
|
+
try {
|
|
47
|
+
return options.isEnabled();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const queue = new BatchQueue({
|
|
54
|
+
send: sender,
|
|
55
|
+
isEnabled: enabled,
|
|
56
|
+
...(options.flushIntervalMs !== undefined ? { flushIntervalMs: options.flushIntervalMs } : {}),
|
|
57
|
+
...(options.maxQueue !== undefined ? { maxQueue: options.maxQueue } : {}),
|
|
58
|
+
});
|
|
59
|
+
const hostSessionId = options.hostSessionId && UUID_PATTERN.test(options.hostSessionId)
|
|
60
|
+
? options.hostSessionId.toLowerCase()
|
|
61
|
+
: null;
|
|
62
|
+
const capture = (event, properties, eventTsMs = now()) => {
|
|
63
|
+
try {
|
|
64
|
+
if (!enabled())
|
|
65
|
+
return false;
|
|
66
|
+
const distinctId = normalizeDistinctId(options.getDistinctId());
|
|
67
|
+
if (!distinctId)
|
|
68
|
+
return false;
|
|
69
|
+
const sanitized = sanitizeEventProperties(options.catalog, event, properties);
|
|
70
|
+
if (!sanitized)
|
|
71
|
+
return false;
|
|
72
|
+
const payload = {
|
|
73
|
+
event,
|
|
74
|
+
distinct_id: distinctId,
|
|
75
|
+
timestamp: new Date(eventTsMs).toISOString(),
|
|
76
|
+
properties: {
|
|
77
|
+
$geoip_disable: true,
|
|
78
|
+
$process_person_profile: false,
|
|
79
|
+
schema_version: TELEMETRY_SCHEMA_VERSION,
|
|
80
|
+
product: options.product,
|
|
81
|
+
event_ts_ms: eventTsMs,
|
|
82
|
+
session_id: sessionId,
|
|
83
|
+
$session_id: sessionId,
|
|
84
|
+
app_version: options.appVersion,
|
|
85
|
+
platform: options.platform ?? process.platform,
|
|
86
|
+
arch: options.arch ?? process.arch,
|
|
87
|
+
install_source: options.installSource ?? 'unknown',
|
|
88
|
+
...(options.buyerHost ? { buyer_host: options.buyerHost } : {}),
|
|
89
|
+
...(hostSessionId ? { host_session_id: hostSessionId } : {}),
|
|
90
|
+
...sanitized,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
queue.push(payload);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
sessionId,
|
|
102
|
+
capture,
|
|
103
|
+
flush: () => queue.flush(),
|
|
104
|
+
close: (timeoutMs) => queue.close(timeoutMs),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C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: always off.
|
|
5
|
+
* 2. CI (`CI` set and not false): off.
|
|
6
|
+
* 3. No PostHog project configured (source builds bake none): off.
|
|
7
|
+
* 4. The persisted choice (`telemetry.enabled` in the config file, or the
|
|
8
|
+
* desktop's own preference): `false` turns it off.
|
|
9
|
+
* 5. The product default: off. Only an explicit `true` (the user turned it
|
|
10
|
+
* on) sends anything.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TELEMETRY_ENV = "ANTSEED_TELEMETRY";
|
|
13
|
+
export declare const DO_NOT_TRACK_ENV = "DO_NOT_TRACK";
|
|
14
|
+
export declare const POSTHOG_HOST_ENV = "POSTHOG_HOST";
|
|
15
|
+
export declare const POSTHOG_PROJECT_API_KEY_ENV = "POSTHOG_PROJECT_API_KEY";
|
|
16
|
+
export type ConsentDecision = {
|
|
17
|
+
enabled: true;
|
|
18
|
+
} | {
|
|
19
|
+
enabled: false;
|
|
20
|
+
reason: 'do_not_track' | 'env_disabled' | 'ci' | 'not_configured' | 'user_disabled' | 'not_enabled' | 'dev_build';
|
|
21
|
+
};
|
|
22
|
+
export declare function isCiEnvironment(env: NodeJS.ProcessEnv): boolean;
|
|
23
|
+
export type PostHogConfig = {
|
|
24
|
+
host: string;
|
|
25
|
+
projectApiKey: string;
|
|
26
|
+
};
|
|
27
|
+
/** Runtime env wins over baked values; only HTTPS hosts are accepted. */
|
|
28
|
+
export declare function resolvePostHogConfig(env: NodeJS.ProcessEnv, baked: {
|
|
29
|
+
host: string | null;
|
|
30
|
+
projectApiKey: string | null;
|
|
31
|
+
}): PostHogConfig | null;
|
|
32
|
+
export declare function resolveConsent(input: {
|
|
33
|
+
env: NodeJS.ProcessEnv;
|
|
34
|
+
configured: boolean;
|
|
35
|
+
/** The persisted user choice; undefined when never set. */
|
|
36
|
+
persisted?: boolean;
|
|
37
|
+
isDev?: boolean;
|
|
38
|
+
}): ConsentDecision;
|
|
39
|
+
//# sourceMappingURL=consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,aAAa,sBAAsB,CAAC;AACjD,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAC/C,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAC/C,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE,MAAM,MAAM,eAAe,GACvB;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GACjB;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,cAAc,GAAG,cAAc,GAAG,IAAI,GAAG,gBAAgB,GAAG,eAAe,GAAG,aAAa,GAAG,WAAW,CAAA;CAAE,CAAC;AAa1I,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAG/D;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpE,yEAAyE;AACzE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC3D,aAAa,GAAG,IAAI,CAUtB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,eAAe,CAUlB"}
|
package/dist/consent.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a process may send telemetry. One rule for every product, highest
|
|
3
|
+
* first:
|
|
4
|
+
* 1. `DO_NOT_TRACK=1`, or `ANTSEED_TELEMETRY=0|false|no|off`: always off.
|
|
5
|
+
* 2. CI (`CI` set and not false): off.
|
|
6
|
+
* 3. No PostHog project configured (source builds bake none): off.
|
|
7
|
+
* 4. The persisted choice (`telemetry.enabled` in the config file, or the
|
|
8
|
+
* desktop's own preference): `false` turns it off.
|
|
9
|
+
* 5. The product default: off. Only an explicit `true` (the user turned it
|
|
10
|
+
* on) sends anything.
|
|
11
|
+
*/
|
|
12
|
+
export const TELEMETRY_ENV = 'ANTSEED_TELEMETRY';
|
|
13
|
+
export const DO_NOT_TRACK_ENV = 'DO_NOT_TRACK';
|
|
14
|
+
export const POSTHOG_HOST_ENV = 'POSTHOG_HOST';
|
|
15
|
+
export const POSTHOG_PROJECT_API_KEY_ENV = 'POSTHOG_PROJECT_API_KEY';
|
|
16
|
+
const FALSY = new Set(['0', 'false', 'no', 'off']);
|
|
17
|
+
const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
|
|
18
|
+
function envFlag(value) {
|
|
19
|
+
const normalized = value?.trim().toLowerCase();
|
|
20
|
+
if (!normalized)
|
|
21
|
+
return null;
|
|
22
|
+
if (FALSY.has(normalized))
|
|
23
|
+
return false;
|
|
24
|
+
if (TRUTHY.has(normalized))
|
|
25
|
+
return true;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
export function isCiEnvironment(env) {
|
|
29
|
+
const ci = env['CI']?.trim().toLowerCase();
|
|
30
|
+
return Boolean(ci) && ci !== '0' && ci !== 'false';
|
|
31
|
+
}
|
|
32
|
+
/** Runtime env wins over baked values; only HTTPS hosts are accepted. */
|
|
33
|
+
export function resolvePostHogConfig(env, baked) {
|
|
34
|
+
const host = (env[POSTHOG_HOST_ENV]?.trim() || baked.host || '').replace(/\/+$/, '');
|
|
35
|
+
const projectApiKey = env[POSTHOG_PROJECT_API_KEY_ENV]?.trim() || baked.projectApiKey || '';
|
|
36
|
+
if (!host || !projectApiKey)
|
|
37
|
+
return null;
|
|
38
|
+
try {
|
|
39
|
+
if (new URL(host).protocol !== 'https:')
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return { host, projectApiKey };
|
|
46
|
+
}
|
|
47
|
+
export function resolveConsent(input) {
|
|
48
|
+
const { env } = input;
|
|
49
|
+
if (envFlag(env[DO_NOT_TRACK_ENV]) === true)
|
|
50
|
+
return { enabled: false, reason: 'do_not_track' };
|
|
51
|
+
if (envFlag(env[TELEMETRY_ENV]) === false)
|
|
52
|
+
return { enabled: false, reason: 'env_disabled' };
|
|
53
|
+
if (input.isDev)
|
|
54
|
+
return { enabled: false, reason: 'dev_build' };
|
|
55
|
+
if (isCiEnvironment(env))
|
|
56
|
+
return { enabled: false, reason: 'ci' };
|
|
57
|
+
if (!input.configured)
|
|
58
|
+
return { enabled: false, reason: 'not_configured' };
|
|
59
|
+
if (input.persisted === false)
|
|
60
|
+
return { enabled: false, reason: 'user_disabled' };
|
|
61
|
+
if (input.persisted !== true)
|
|
62
|
+
return { enabled: false, reason: 'not_enabled' };
|
|
63
|
+
return { enabled: true };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.js","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAC/C,MAAM,CAAC,MAAM,2BAA2B,GAAG,yBAAyB,CAAC;AAMrE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACnD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,G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AE,aAAa,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAM9B;IACC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IACtB,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAC/F,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,KAAK,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAC7F,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAChE,IAAI,eAAe,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClE,IAAI,CAAC,KAAK,CAAC,UAAU;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3E,IAAI,KAAK,CAAC,SAAS,KAAK,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAClF,IAAI,KAAK,CAAC,SAAS,KAAK,IAAI;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAC/E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed `failure_reason` taxonomy for a model request, shared by the desktop
|
|
3
|
+
* chat (what the user saw) and the buyer proxy (what the network did). Raw
|
|
4
|
+
* error text is read here and discarded; only the enum leaves the device.
|
|
5
|
+
*/
|
|
6
|
+
export type FailureReason = 'none' | 'out_of_credits' | 'model_needs_paid' | 'seller_dropped_before_output' | 'seller_dropped_mid_answer' | 'seller_5xx' | 'request_rejected' | 'rate_limited' | 'no_seller_available' | 'no_seller_yet' | 'seller_unreachable' | 'timeout' | 'local_error' | 'unknown';
|
|
7
|
+
export declare const FAILURE_REASONS: ReadonlySet<string>;
|
|
8
|
+
/** A classified stop: the kind of failure, and its HTTP status when known. */
|
|
9
|
+
export type FailureSignal = {
|
|
10
|
+
kind: string;
|
|
11
|
+
statusCode?: number;
|
|
12
|
+
};
|
|
13
|
+
export type FailureReasonContext = {
|
|
14
|
+
/** Whether any text/tool output reached the client before the failure. */
|
|
15
|
+
hadPartialOutput: boolean;
|
|
16
|
+
/** Whether any online peer was known when the request was sent. */
|
|
17
|
+
peersDiscoveredAtSend: boolean;
|
|
18
|
+
/** Distinct free sellers known for the model at send. */
|
|
19
|
+
freeSellersKnown: number;
|
|
20
|
+
/** Undefined when the balance is unknown. */
|
|
21
|
+
buyerBalanceZero?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The status an SDK puts in front of an error body: "402 You are out of…",
|
|
25
|
+
* "502 Pinned peer …", "503 {json}", or a streamed "… 400 data: {". Prose such
|
|
26
|
+
* as "429 requests remaining" is not read as a status.
|
|
27
|
+
*/
|
|
28
|
+
export declare function leadingHttpStatus(rawMessage: string): number | undefined;
|
|
29
|
+
export declare function failureHttpStatus(signal: FailureSignal, rawMessage?: string): number | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Collapse a failed request into the fixed taxonomy.
|
|
32
|
+
*
|
|
33
|
+
* - `out_of_credits` / `model_needs_paid`: a 402 or payment-required body;
|
|
34
|
+
* `model_needs_paid` when the balance is zero and no free seller serves
|
|
35
|
+
* the model, so funding is the only way to use it.
|
|
36
|
+
* - `no_seller_yet`: no seller and no peers were known at send (still
|
|
37
|
+
* starting up); `no_seller_available` once peers were known.
|
|
38
|
+
* - `seller_dropped_*`: a stream or connection that ended without a status,
|
|
39
|
+
* split by whether output had started.
|
|
40
|
+
*/
|
|
41
|
+
export declare function classifyFailureReason(signal: FailureSignal, rawMessage: string, context: FailureReasonContext): FailureReason;
|
|
42
|
+
//# sourceMappingURL=failure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,gBAAgB,GAChB,kBAAkB,GAClB,8BAA8B,GAC9B,2BAA2B,GAC3B,YAAY,GACZ,kBAAkB,GAClB,cAAc,GACd,qBAAqB,GACrB,eAAe,GACf,oBAAoB,GACpB,SAAS,GACT,aAAa,GACb,SAAS,CAAC;AAEd,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,CAe9C,CAAC;AAEH,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,0EAA0E;IAC1E,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mEAAmE;IACnE,qBAAqB,EAAE,OAAO,CAAC;IAC/B,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,CAAC;IACzB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AASF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMxE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,SAAK,GAAG,MAAM,GAAG,SAAS,CAE5F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAyBf"}
|
package/dist/failure.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed `failure_reason` taxonomy for a model request, shared by the desktop
|
|
3
|
+
* chat (what the user saw) and the buyer proxy (what the network did). Raw
|
|
4
|
+
* error text is read here and discarded; only the enum leaves the device.
|
|
5
|
+
*/
|
|
6
|
+
export const FAILURE_REASONS = new Set([
|
|
7
|
+
'none',
|
|
8
|
+
'out_of_credits',
|
|
9
|
+
'model_needs_paid',
|
|
10
|
+
'seller_dropped_before_output',
|
|
11
|
+
'seller_dropped_mid_answer',
|
|
12
|
+
'seller_5xx',
|
|
13
|
+
'request_rejected',
|
|
14
|
+
'rate_limited',
|
|
15
|
+
'no_seller_available',
|
|
16
|
+
'no_seller_yet',
|
|
17
|
+
'seller_unreachable',
|
|
18
|
+
'timeout',
|
|
19
|
+
'local_error',
|
|
20
|
+
'unknown',
|
|
21
|
+
]);
|
|
22
|
+
const BUYER_SIDE_FAULT = /antseed_buyer_fault|buyer_request_failed|buyer_payments_inactive|payments_inactive|payment_negotiation_failed/i;
|
|
23
|
+
const PAYMENT_SIGNAL = /payment_required|insufficient_deposits|out of antseed credits/i;
|
|
24
|
+
const NO_SELLER_SIGNAL = /model_not_found|no policy-allowed peer|not served by this peer|model .* not (?:served|available)|no verified peer currently serves|no sellers available/i;
|
|
25
|
+
const NO_PEERS_SIGNAL = /no peers discovered|no sellers available on the network/i;
|
|
26
|
+
const UNREACHABLE_SIGNAL = /\bis not reachable\b|p2p request failed|connection to \S+ failed|\bpeer unreachable\b|ehostunreach|econnrefused/i;
|
|
27
|
+
const TIMEOUT_SIGNAL = /\btimed out\b|\btimeout\b|no answer within/i;
|
|
28
|
+
/**
|
|
29
|
+
* The status an SDK puts in front of an error body: "402 You are out of…",
|
|
30
|
+
* "502 Pinned peer …", "503 {json}", or a streamed "… 400 data: {". Prose such
|
|
31
|
+
* as "429 requests remaining" is not read as a status.
|
|
32
|
+
*/
|
|
33
|
+
export function leadingHttpStatus(rawMessage) {
|
|
34
|
+
const match = /(?:^|:\s)([45]\d{2})\s+data:\s*\{/i.exec(rawMessage)
|
|
35
|
+
?? /^\s*([45]\d{2})\s+(?=[{A-Z])/.exec(rawMessage);
|
|
36
|
+
if (!match)
|
|
37
|
+
return undefined;
|
|
38
|
+
const statusCode = Number(match[1]);
|
|
39
|
+
return Number.isFinite(statusCode) ? statusCode : undefined;
|
|
40
|
+
}
|
|
41
|
+
export function failureHttpStatus(signal, rawMessage = '') {
|
|
42
|
+
return signal.statusCode ?? leadingHttpStatus(rawMessage);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Collapse a failed request into the fixed taxonomy.
|
|
46
|
+
*
|
|
47
|
+
* - `out_of_credits` / `model_needs_paid`: a 402 or payment-required body;
|
|
48
|
+
* `model_needs_paid` when the balance is zero and no free seller serves
|
|
49
|
+
* the model, so funding is the only way to use it.
|
|
50
|
+
* - `no_seller_yet`: no seller and no peers were known at send (still
|
|
51
|
+
* starting up); `no_seller_available` once peers were known.
|
|
52
|
+
* - `seller_dropped_*`: a stream or connection that ended without a status,
|
|
53
|
+
* split by whether output had started.
|
|
54
|
+
*/
|
|
55
|
+
export function classifyFailureReason(signal, rawMessage, context) {
|
|
56
|
+
if (signal.kind === 'aborted')
|
|
57
|
+
return 'none';
|
|
58
|
+
const statusCode = failureHttpStatus(signal, rawMessage);
|
|
59
|
+
if (signal.kind === 'payment_required' || statusCode === 402 || PAYMENT_SIGNAL.test(rawMessage)) {
|
|
60
|
+
return context.buyerBalanceZero === true && context.freeSellersKnown === 0
|
|
61
|
+
? 'model_needs_paid'
|
|
62
|
+
: 'out_of_credits';
|
|
63
|
+
}
|
|
64
|
+
if (BUYER_SIDE_FAULT.test(rawMessage))
|
|
65
|
+
return 'local_error';
|
|
66
|
+
if (NO_SELLER_SIGNAL.test(rawMessage) || NO_PEERS_SIGNAL.test(rawMessage)) {
|
|
67
|
+
return context.peersDiscoveredAtSend && !NO_PEERS_SIGNAL.test(rawMessage)
|
|
68
|
+
? 'no_seller_available'
|
|
69
|
+
: 'no_seller_yet';
|
|
70
|
+
}
|
|
71
|
+
if (signal.kind === 'timeout' || statusCode === 408 || statusCode === 504 || TIMEOUT_SIGNAL.test(rawMessage)) {
|
|
72
|
+
return 'timeout';
|
|
73
|
+
}
|
|
74
|
+
if (statusCode === 429)
|
|
75
|
+
return 'rate_limited';
|
|
76
|
+
if (UNREACHABLE_SIGNAL.test(rawMessage))
|
|
77
|
+
return 'seller_unreachable';
|
|
78
|
+
if (typeof statusCode === 'number' && statusCode >= 500 && statusCode < 600)
|
|
79
|
+
return 'seller_5xx';
|
|
80
|
+
if (typeof statusCode === 'number' && statusCode >= 400 && statusCode < 500)
|
|
81
|
+
return 'request_rejected';
|
|
82
|
+
if (signal.kind === 'network_error' || signal.kind === 'stream_error' || signal.kind === 'unknown') {
|
|
83
|
+
return context.hadPartialOutput ? 'seller_dropped_mid_answer' : 'seller_dropped_before_output';
|
|
84
|
+
}
|
|
85
|
+
return 'unknown';
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=failure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure.js","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAgB;IACzE,MAAM;IACN,gBAAgB;IAChB,kBAAkB;IAClB,8BAA8B;IAC9B,2BAA2B;IAC3B,YAAY;IACZ,kBAAkB;IAClB,cAAc;IACd,qBAAqB;IACrB,eAAe;IACf,oBAAoB;IACpB,SAAS;IACT,aAAa;IACb,SAAS;CACV,CAAC,CAAC;AAmBH,MAAM,gBAAgB,GAAG,gHAAgH,CAAC;AAC1I,MAAM,cAAc,GAAG,gEAAgE,CAAC;AACxF,MAAM,gBAAgB,GAAG,0JAA0J,CAAC;AACpL,MAAM,eAAe,GAAG,0DAA0D,CAAC;AACnF,MAAM,kBAAkB,GAAG,kHA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Ac,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded PostHog transport. Captures queue in memory and leave in batches
|
|
3
|
+
* (`/batch/`), with a short timeout and no retries. Every failure is
|
|
4
|
+
* swallowed: telemetry never affects a request, startup or shutdown.
|
|
5
|
+
*/
|
|
6
|
+
export declare const POSTHOG_CAPTURE_TIMEOUT_MS = 4000;
|
|
7
|
+
export type PostHogEvent = {
|
|
8
|
+
event: string;
|
|
9
|
+
distinct_id: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
properties: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
export type PostHogSender = (events: PostHogEvent[]) => Promise<void>;
|
|
14
|
+
export declare function createPostHogSender(options: {
|
|
15
|
+
host: string;
|
|
16
|
+
projectApiKey: string;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}): PostHogSender;
|
|
19
|
+
export type BatchQueueOptions = {
|
|
20
|
+
send: PostHogSender;
|
|
21
|
+
/** Oldest events are dropped beyond this. */
|
|
22
|
+
maxQueue?: number;
|
|
23
|
+
maxBatch?: number;
|
|
24
|
+
flushIntervalMs?: number;
|
|
25
|
+
/** Checked before each batch is sent; when false the rest of the queue is dropped unsent. */
|
|
26
|
+
isEnabled?: () => boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare class BatchQueue {
|
|
29
|
+
private readonly options;
|
|
30
|
+
private readonly queue;
|
|
31
|
+
private timer;
|
|
32
|
+
private inFlight;
|
|
33
|
+
private readonly maxQueue;
|
|
34
|
+
private readonly maxBatch;
|
|
35
|
+
private readonly flushIntervalMs;
|
|
36
|
+
constructor(options: BatchQueueOptions);
|
|
37
|
+
get size(): number;
|
|
38
|
+
push(event: PostHogEvent): void;
|
|
39
|
+
/** Sends everything queued. Safe to call concurrently; never rejects. */
|
|
40
|
+
flush(): Promise<void>;
|
|
41
|
+
/** Flushes, waiting at most `timeoutMs`. */
|
|
42
|
+
close(timeoutMs?: number): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=posthog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog.d.ts","sourceRoot":"","sources":["../src/posthog.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CAgBvH;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;CAC3B,CAAC;AAEF,qBAAa,UAAU;IAQT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