@squasher-ai/nextjs 0.2.0 → 0.4.0
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/_vendor/node-sdk/actionable-telemetry.d.ts +4 -0
- package/dist/_vendor/node-sdk/actionable-telemetry.js +32 -0
- package/dist/_vendor/node-sdk/aws-lambda.d.ts +19 -0
- package/dist/_vendor/node-sdk/aws-lambda.js +81 -0
- package/dist/_vendor/node-sdk/client.d.ts +54 -0
- package/dist/_vendor/node-sdk/client.js +479 -0
- package/dist/_vendor/node-sdk/delivery-stats.d.ts +40 -0
- package/dist/_vendor/node-sdk/delivery-stats.js +57 -0
- package/dist/_vendor/node-sdk/http.d.ts +22 -0
- package/dist/_vendor/node-sdk/http.js +139 -0
- package/dist/_vendor/node-sdk/index.d.ts +36 -0
- package/dist/_vendor/node-sdk/index.js +84 -0
- package/dist/_vendor/node-sdk/local-events/sink.d.ts +6 -0
- package/dist/_vendor/node-sdk/local-events/sink.js +43 -0
- package/dist/_vendor/node-sdk/trace-context.d.ts +8 -0
- package/dist/_vendor/node-sdk/trace-context.js +13 -0
- package/dist/_vendor/node-sdk/types.d.ts +65 -0
- package/dist/_vendor/node-sdk/types.js +1 -0
- package/dist/_vendor/result-runtime/attempt.d.ts +17 -0
- package/dist/_vendor/result-runtime/attempt.js +62 -0
- package/dist/_vendor/sdk-runtime/batching/index.d.ts +42 -0
- package/dist/_vendor/sdk-runtime/batching/index.js +48 -0
- package/dist/_vendor/sdk-runtime/errors/headers.d.ts +6 -0
- package/dist/_vendor/sdk-runtime/errors/headers.js +44 -0
- package/dist/_vendor/sdk-runtime/errors/index.d.ts +95 -0
- package/dist/_vendor/sdk-runtime/errors/index.js +157 -0
- package/dist/_vendor/sdk-runtime/headers.d.ts +48 -0
- package/dist/_vendor/sdk-runtime/headers.js +67 -0
- package/dist/_vendor/sdk-runtime/platform.d.ts +33 -0
- package/dist/_vendor/sdk-runtime/platform.js +173 -0
- package/dist/_vendor/sdk-runtime/retry.d.ts +50 -0
- package/dist/_vendor/sdk-runtime/retry.js +104 -0
- package/dist/_vendor/sdk-runtime/runtime/actionable-error.d.ts +37 -0
- package/dist/_vendor/sdk-runtime/runtime/actionable-error.js +123 -0
- package/dist/_vendor/sdk-runtime/runtime/environment.d.ts +18 -0
- package/dist/_vendor/sdk-runtime/runtime/environment.js +81 -0
- package/dist/_vendor/sdk-runtime/runtime/public-sdk-runtime.d.ts +12 -0
- package/dist/_vendor/sdk-runtime/runtime/public-sdk-runtime.js +38 -0
- package/dist/_vendor/sdk-runtime/runtime/redaction.d.ts +14 -0
- package/dist/_vendor/sdk-runtime/runtime/redaction.js +120 -0
- package/dist/_vendor/sdk-runtime/runtime/release.d.ts +35 -0
- package/dist/_vendor/sdk-runtime/runtime/release.js +120 -0
- package/dist/_vendor/sdk-runtime/sampling/index.d.ts +43 -0
- package/dist/_vendor/sdk-runtime/sampling/index.js +70 -0
- package/dist/_vendor/telemetry-contract/sdk/public-contract.d.ts +175 -0
- package/dist/_vendor/telemetry-contract/sdk/public-contract.js +5 -0
- package/dist/api-handler.d.ts +1 -2
- package/dist/api-handler.js +2 -2
- package/dist/client.d.ts +1 -2
- package/dist/client.js +2 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -1
- package/dist/middleware.d.ts +0 -1
- package/dist/middleware.js +2 -2
- package/package.json +1 -13
- package/dist/api-handler.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/middleware.d.ts.map +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { readProcessEnvironment } from "./environment.js";
|
|
2
|
+
const MAX_LEN = 200;
|
|
3
|
+
const JUNK_VALUES = new Set([
|
|
4
|
+
"",
|
|
5
|
+
"undefined",
|
|
6
|
+
"null",
|
|
7
|
+
"nan",
|
|
8
|
+
"latest",
|
|
9
|
+
"unknown",
|
|
10
|
+
"(none)",
|
|
11
|
+
"n/a",
|
|
12
|
+
"none",
|
|
13
|
+
]);
|
|
14
|
+
const SEMVER_RE = /^\d+\.\d+\.\d+(?:-[0-9a-zA-Z.-]+)?$/;
|
|
15
|
+
const VERSION_CHAR_RE = /^[A-Za-z0-9._-]+$/;
|
|
16
|
+
const BUILD_CHAR_RE = /^[A-Za-z0-9._-]+$/;
|
|
17
|
+
const SERVICE_CHAR_RE = /^[A-Za-z0-9._/@-]+$/;
|
|
18
|
+
/**
|
|
19
|
+
* Parse + validate a release string. Returns `null` for empty input, junk
|
|
20
|
+
* sentinels, values over 200 chars, or strings with whitespace / control chars.
|
|
21
|
+
* Accepts: `1.2.3`, `v1.2.3`, `svc@1.2.3`, `svc@1.2.3+sha`, `1.2.3+sha`, and
|
|
22
|
+
* bare git shas (non-semver but valid).
|
|
23
|
+
*/
|
|
24
|
+
export function parseRelease(input) {
|
|
25
|
+
if (Object.prototype.toString.call(input) !== "[object String]")
|
|
26
|
+
return null;
|
|
27
|
+
const raw = String(input).trim();
|
|
28
|
+
if (raw.length === 0 || raw.length > MAX_LEN)
|
|
29
|
+
return null;
|
|
30
|
+
if (JUNK_VALUES.has(raw.toLowerCase()))
|
|
31
|
+
return null;
|
|
32
|
+
// Reject whitespace + ASCII control chars (NUL..US, DEL).
|
|
33
|
+
// oxlint-disable-next-line no-control-regex
|
|
34
|
+
if (/[\s\x00-\x1f\x7f]/.test(raw))
|
|
35
|
+
return null;
|
|
36
|
+
// Only the LAST `@` separates service from version, so npm-style scopes
|
|
37
|
+
// like `@org/pkg@1.2.3` parse with `@org/pkg` as the service.
|
|
38
|
+
const atIndex = raw.lastIndexOf("@");
|
|
39
|
+
let service = null;
|
|
40
|
+
let rest = raw;
|
|
41
|
+
if (atIndex >= 0) {
|
|
42
|
+
const left = raw.slice(0, atIndex);
|
|
43
|
+
const right = raw.slice(atIndex + 1);
|
|
44
|
+
if (right.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
service = left.length > 0 ? left : null;
|
|
47
|
+
rest = right;
|
|
48
|
+
}
|
|
49
|
+
if (service !== null && !SERVICE_CHAR_RE.test(service))
|
|
50
|
+
return null;
|
|
51
|
+
const plusIndex = rest.indexOf("+");
|
|
52
|
+
let version;
|
|
53
|
+
let build;
|
|
54
|
+
if (plusIndex >= 0) {
|
|
55
|
+
version = rest.slice(0, plusIndex);
|
|
56
|
+
build = rest.slice(plusIndex + 1);
|
|
57
|
+
if (version.length === 0 || build.length === 0)
|
|
58
|
+
return null;
|
|
59
|
+
if (!BUILD_CHAR_RE.test(build))
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
version = rest;
|
|
64
|
+
build = null;
|
|
65
|
+
}
|
|
66
|
+
if (!VERSION_CHAR_RE.test(version))
|
|
67
|
+
return null;
|
|
68
|
+
// Strip a `v` prefix only when followed by a digit — don't eat the first
|
|
69
|
+
// character of names like `viper`.
|
|
70
|
+
const normalizedVersion = version.length > 1 &&
|
|
71
|
+
(version[0] === "v" || version[0] === "V") &&
|
|
72
|
+
/[0-9]/.test(version[1] ?? "")
|
|
73
|
+
? version.slice(1)
|
|
74
|
+
: version;
|
|
75
|
+
const isSemver = SEMVER_RE.test(normalizedVersion);
|
|
76
|
+
const canonical = [
|
|
77
|
+
service !== null ? `${service}@` : "",
|
|
78
|
+
normalizedVersion,
|
|
79
|
+
build !== null ? `+${build}` : "",
|
|
80
|
+
].join("");
|
|
81
|
+
return { canonical, service, version: normalizedVersion, build, isSemver };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* True when `parseRelease(input)` would accept the value. Pure boolean — use
|
|
85
|
+
* this at validation boundaries that don't need the parsed pieces (e.g. zod
|
|
86
|
+
* `.refine()`, ingest pre-filters).
|
|
87
|
+
*/
|
|
88
|
+
export function isValidRelease(input) {
|
|
89
|
+
return parseRelease(input) !== null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Auto-detect a release from common CI/host env vars so customers on
|
|
93
|
+
* Vercel / Railway / Render / Fly / GitHub Actions get a useful release tag
|
|
94
|
+
* without configuring anything. Explicit `SQUASHER_RELEASE` always wins;
|
|
95
|
+
* values that fail `parseRelease` are skipped and detection continues.
|
|
96
|
+
*/
|
|
97
|
+
export function detectRelease(env = readProcessEnvironment()) {
|
|
98
|
+
const candidates = [
|
|
99
|
+
env.SQUASHER_RELEASE,
|
|
100
|
+
env.VERCEL_GIT_COMMIT_SHA,
|
|
101
|
+
env.RAILWAY_GIT_COMMIT_SHA,
|
|
102
|
+
env.RENDER_GIT_COMMIT,
|
|
103
|
+
env.FLY_MACHINE_VERSION,
|
|
104
|
+
env.GITHUB_SHA,
|
|
105
|
+
npmPackageCandidate(env),
|
|
106
|
+
];
|
|
107
|
+
for (const value of candidates) {
|
|
108
|
+
const parsed = parseRelease(value);
|
|
109
|
+
if (parsed !== null)
|
|
110
|
+
return parsed.canonical;
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
function npmPackageCandidate(env) {
|
|
115
|
+
const version = env.npm_package_version;
|
|
116
|
+
if (!version)
|
|
117
|
+
return null;
|
|
118
|
+
const name = env.npm_package_name;
|
|
119
|
+
return name ? `${name}@${version}` : version;
|
|
120
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface TelemetrySamplingConfig {
|
|
2
|
+
successRate?: number;
|
|
3
|
+
errorRate?: number;
|
|
4
|
+
slowRate?: number;
|
|
5
|
+
slowThresholdMs?: number;
|
|
6
|
+
alwaysSampleUserIds?: string[];
|
|
7
|
+
alwaysSampleReleases?: string[];
|
|
8
|
+
}
|
|
9
|
+
type SamplingAttributePrimitive = boolean | null | number | string;
|
|
10
|
+
type SamplingAttributeValue = SamplingAttributePrimitive | SamplingAttributeValue[] | SamplingAttributes;
|
|
11
|
+
interface SamplingAttributes {
|
|
12
|
+
[key: string]: SamplingAttributeValue;
|
|
13
|
+
}
|
|
14
|
+
interface SamplingEvent {
|
|
15
|
+
attributes?: SamplingAttributes;
|
|
16
|
+
distinct_id?: string;
|
|
17
|
+
event_name?: string;
|
|
18
|
+
kind?: string;
|
|
19
|
+
level?: string;
|
|
20
|
+
message: string;
|
|
21
|
+
release?: string;
|
|
22
|
+
session_id?: string;
|
|
23
|
+
timestamp?: number | string;
|
|
24
|
+
trace?: {
|
|
25
|
+
duration_ms?: number;
|
|
26
|
+
status?: string;
|
|
27
|
+
trace_id?: string;
|
|
28
|
+
};
|
|
29
|
+
user?: {
|
|
30
|
+
id?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface ResolvedTelemetrySampling {
|
|
34
|
+
successRate: number;
|
|
35
|
+
errorRate: number;
|
|
36
|
+
slowRate: number;
|
|
37
|
+
slowThresholdMs: number;
|
|
38
|
+
alwaysSampleUserIds: ReadonlySet<string>;
|
|
39
|
+
alwaysSampleReleases: ReadonlySet<string>;
|
|
40
|
+
}
|
|
41
|
+
export declare function resolveTelemetrySampling(config: TelemetrySamplingConfig | undefined): ResolvedTelemetrySampling;
|
|
42
|
+
export declare function shouldSampleTelemetry(event: SamplingEvent, config: ResolvedTelemetrySampling): boolean;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export function resolveTelemetrySampling(config) {
|
|
2
|
+
return {
|
|
3
|
+
successRate: rate(config?.successRate, 1),
|
|
4
|
+
errorRate: rate(config?.errorRate, 1),
|
|
5
|
+
slowRate: rate(config?.slowRate, 1),
|
|
6
|
+
slowThresholdMs: Math.max(0, config?.slowThresholdMs ?? 1_000),
|
|
7
|
+
alwaysSampleUserIds: new Set(config?.alwaysSampleUserIds ?? []),
|
|
8
|
+
alwaysSampleReleases: new Set(config?.alwaysSampleReleases ?? []),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function shouldSampleTelemetry(event, config) {
|
|
12
|
+
if ((event.distinct_id && config.alwaysSampleUserIds.has(event.distinct_id)) ||
|
|
13
|
+
(event.user?.id && config.alwaysSampleUserIds.has(event.user.id)))
|
|
14
|
+
return true;
|
|
15
|
+
if (event.release && config.alwaysSampleReleases.has(event.release))
|
|
16
|
+
return true;
|
|
17
|
+
// AI generation events are metered usage: dropping them would under-report
|
|
18
|
+
// tokens, cost, and cache reads on the AI dashboards, so they are never sampled.
|
|
19
|
+
if (event.kind === "llm_generation")
|
|
20
|
+
return true;
|
|
21
|
+
// Events in one trace share a hash input, but each outcome class applies its
|
|
22
|
+
// configured threshold. This correlates their decisions without pretending
|
|
23
|
+
// that event sampling is whole-trace tail sampling.
|
|
24
|
+
const durationMs = event.trace?.duration_ms;
|
|
25
|
+
const selectedRate = isFailure(event)
|
|
26
|
+
? config.errorRate
|
|
27
|
+
: durationMs !== undefined && durationMs >= config.slowThresholdMs
|
|
28
|
+
? config.slowRate
|
|
29
|
+
: config.successRate;
|
|
30
|
+
if (selectedRate >= 1)
|
|
31
|
+
return true;
|
|
32
|
+
if (selectedRate <= 0)
|
|
33
|
+
return false;
|
|
34
|
+
return stableFraction(sampleKey(event)) < selectedRate;
|
|
35
|
+
}
|
|
36
|
+
function isFailure(event) {
|
|
37
|
+
if (event.level === "fatal" || event.level === "error" || event.level === "warning")
|
|
38
|
+
return true;
|
|
39
|
+
if (event.kind === "error" || event.trace?.status === "error")
|
|
40
|
+
return true;
|
|
41
|
+
const outcome = event.attributes?.["squasher.outcome"] ?? event.attributes?.outcome;
|
|
42
|
+
return outcome === "failure" || outcome === "error";
|
|
43
|
+
}
|
|
44
|
+
function sampleKey(event) {
|
|
45
|
+
if (event.trace?.trace_id)
|
|
46
|
+
return `trace:${event.trace.trace_id}`;
|
|
47
|
+
return [
|
|
48
|
+
event.session_id,
|
|
49
|
+
event.distinct_id,
|
|
50
|
+
event.user?.id,
|
|
51
|
+
event.event_name,
|
|
52
|
+
event.message,
|
|
53
|
+
event.timestamp === undefined ? undefined : String(event.timestamp),
|
|
54
|
+
]
|
|
55
|
+
.filter((value) => Boolean(value))
|
|
56
|
+
.join("|");
|
|
57
|
+
}
|
|
58
|
+
function stableFraction(value) {
|
|
59
|
+
let hash = 2166136261;
|
|
60
|
+
for (let index = 0; index < value.length; index++) {
|
|
61
|
+
hash ^= value.charCodeAt(index);
|
|
62
|
+
hash = Math.imul(hash, 16777619);
|
|
63
|
+
}
|
|
64
|
+
return (hash >>> 0) / 0x1_0000_0000;
|
|
65
|
+
}
|
|
66
|
+
function rate(value, fallback) {
|
|
67
|
+
if (value === undefined || !Number.isFinite(value))
|
|
68
|
+
return fallback;
|
|
69
|
+
return Math.min(1, Math.max(0, value));
|
|
70
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer-facing telemetry contract shared by the published JavaScript SDKs.
|
|
3
|
+
* This module intentionally contains only the documented ingestion shapes.
|
|
4
|
+
*/
|
|
5
|
+
export type JsonPrimitive = boolean | null | number | string;
|
|
6
|
+
export interface JsonObject {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
}
|
|
9
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
|
|
10
|
+
export type Level = "fatal" | "error" | "warning" | "info" | "debug";
|
|
11
|
+
export interface StackFrame {
|
|
12
|
+
filename?: string;
|
|
13
|
+
function?: string;
|
|
14
|
+
lineno?: number;
|
|
15
|
+
colno?: number;
|
|
16
|
+
in_app?: boolean;
|
|
17
|
+
context_line?: string;
|
|
18
|
+
pre_context?: string[];
|
|
19
|
+
post_context?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface UserContext {
|
|
22
|
+
id?: string;
|
|
23
|
+
email?: string;
|
|
24
|
+
username?: string;
|
|
25
|
+
ip_address?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RequestContext {
|
|
28
|
+
url?: string;
|
|
29
|
+
method?: string;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
export interface Breadcrumb {
|
|
33
|
+
timestamp?: string;
|
|
34
|
+
category?: string;
|
|
35
|
+
message?: string;
|
|
36
|
+
level?: string;
|
|
37
|
+
data?: JsonObject;
|
|
38
|
+
}
|
|
39
|
+
/** Event payload accepted by the documented ingestion endpoint. */
|
|
40
|
+
export interface IngestEvent {
|
|
41
|
+
message: string;
|
|
42
|
+
type?: string;
|
|
43
|
+
stack?: string;
|
|
44
|
+
frames?: StackFrame[];
|
|
45
|
+
level?: Level;
|
|
46
|
+
tags?: Record<string, string>;
|
|
47
|
+
user?: UserContext;
|
|
48
|
+
request?: RequestContext;
|
|
49
|
+
sdk?: {
|
|
50
|
+
name: string;
|
|
51
|
+
version: string;
|
|
52
|
+
};
|
|
53
|
+
timestamp?: string;
|
|
54
|
+
release?: string;
|
|
55
|
+
environment?: string;
|
|
56
|
+
breadcrumbs?: Breadcrumb[];
|
|
57
|
+
extra?: Record<string, JsonValue>;
|
|
58
|
+
session_id?: string;
|
|
59
|
+
kind?: TelemetryKind;
|
|
60
|
+
event_name?: string;
|
|
61
|
+
distinct_id?: string;
|
|
62
|
+
visitor?: VisitorContext;
|
|
63
|
+
analytics?: AnalyticsContext;
|
|
64
|
+
page?: PageContext;
|
|
65
|
+
session?: SessionContext;
|
|
66
|
+
trace?: TraceContext;
|
|
67
|
+
tool_call?: ToolCallContext;
|
|
68
|
+
llm?: LlmContext;
|
|
69
|
+
attributes?: JsonObject;
|
|
70
|
+
measurements?: TelemetryMeasurement[];
|
|
71
|
+
resource_attributes?: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
export interface IngestBatchPayload {
|
|
74
|
+
events: IngestEvent[];
|
|
75
|
+
}
|
|
76
|
+
export type IngestEventBatch = [IngestEvent, ...IngestEvent[]];
|
|
77
|
+
export interface IngestBatchEnvelope {
|
|
78
|
+
events: IngestEventBatch;
|
|
79
|
+
}
|
|
80
|
+
export type IngestJsonBatchPayload = IngestEventBatch | IngestBatchEnvelope;
|
|
81
|
+
export type IngestJsonPayload = IngestEvent | IngestJsonBatchPayload;
|
|
82
|
+
/** An encoded newline-delimited JSON request body. */
|
|
83
|
+
export type IngestNdjsonPayload = string;
|
|
84
|
+
export type IngestRequestPayload = IngestJsonPayload | IngestNdjsonPayload;
|
|
85
|
+
export type TelemetryKind = "error" | "log" | "analytics" | "identify" | "page" | "screen" | "visitor" | "agent_session" | "agent_span" | "tool_call" | "llm_generation" | "agent_score";
|
|
86
|
+
export interface VisitorContext {
|
|
87
|
+
visitor_id?: string;
|
|
88
|
+
anonymous_id?: string;
|
|
89
|
+
account_id?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface AnalyticsContext {
|
|
92
|
+
event?: string;
|
|
93
|
+
category?: string;
|
|
94
|
+
funnel?: string;
|
|
95
|
+
step?: string;
|
|
96
|
+
properties?: JsonObject;
|
|
97
|
+
}
|
|
98
|
+
export interface PageContext {
|
|
99
|
+
name?: string;
|
|
100
|
+
path?: string;
|
|
101
|
+
title?: string;
|
|
102
|
+
referrer?: string;
|
|
103
|
+
search?: string;
|
|
104
|
+
screen_class?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface SessionContext {
|
|
107
|
+
session_type?: string;
|
|
108
|
+
agent_id?: string;
|
|
109
|
+
run_id?: string;
|
|
110
|
+
workflow_id?: string;
|
|
111
|
+
step_id?: string;
|
|
112
|
+
status?: string;
|
|
113
|
+
duration_ms?: number;
|
|
114
|
+
}
|
|
115
|
+
export interface TraceContext {
|
|
116
|
+
trace_id?: string;
|
|
117
|
+
span_id?: string;
|
|
118
|
+
parent_span_id?: string;
|
|
119
|
+
span_name?: string;
|
|
120
|
+
span_kind?: string;
|
|
121
|
+
status?: string;
|
|
122
|
+
duration_ms?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface ToolCallContext {
|
|
125
|
+
name?: string;
|
|
126
|
+
input?: JsonObject;
|
|
127
|
+
output?: JsonObject;
|
|
128
|
+
status?: string;
|
|
129
|
+
duration_ms?: number;
|
|
130
|
+
}
|
|
131
|
+
export interface LlmContext {
|
|
132
|
+
provider?: string;
|
|
133
|
+
model?: string;
|
|
134
|
+
prompt_tokens?: number;
|
|
135
|
+
completion_tokens?: number;
|
|
136
|
+
total_tokens?: number;
|
|
137
|
+
cached_input_tokens?: number;
|
|
138
|
+
cost_usd?: number;
|
|
139
|
+
latency_ms?: number;
|
|
140
|
+
status?: string;
|
|
141
|
+
input?: JsonObject;
|
|
142
|
+
output?: JsonObject;
|
|
143
|
+
}
|
|
144
|
+
export interface TelemetryMeasurement {
|
|
145
|
+
name: string;
|
|
146
|
+
value: number;
|
|
147
|
+
unit?: string;
|
|
148
|
+
}
|
|
149
|
+
/** Outcome-aware SDK sampling. Errors and slow operations are kept by default. */
|
|
150
|
+
export interface TelemetrySamplingConfig {
|
|
151
|
+
successRate?: number;
|
|
152
|
+
errorRate?: number;
|
|
153
|
+
slowRate?: number;
|
|
154
|
+
slowThresholdMs?: number;
|
|
155
|
+
alwaysSampleUserIds?: string[];
|
|
156
|
+
alwaysSampleReleases?: string[];
|
|
157
|
+
}
|
|
158
|
+
export interface IngestResponse {
|
|
159
|
+
id: string;
|
|
160
|
+
status: string;
|
|
161
|
+
accepted?: number;
|
|
162
|
+
}
|
|
163
|
+
export interface SdkConfig {
|
|
164
|
+
apiKey: string;
|
|
165
|
+
projectId: string;
|
|
166
|
+
endpoint?: string;
|
|
167
|
+
environment?: string;
|
|
168
|
+
release?: string;
|
|
169
|
+
debug?: boolean;
|
|
170
|
+
sampling?: TelemetrySamplingConfig;
|
|
171
|
+
beforeSend?: (event: IngestEvent) => IngestEvent | null;
|
|
172
|
+
maxBreadcrumbs?: number;
|
|
173
|
+
resourceAttributes?: Record<string, string>;
|
|
174
|
+
autoFlushIntervalMs?: number;
|
|
175
|
+
}
|
package/dist/api-handler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getClient } from "
|
|
1
|
+
import { getClient } from "./_vendor/node-sdk/index.js";
|
|
2
2
|
type NextApiHandler = (request: Request) => Response | Promise<Response>;
|
|
3
3
|
export type SquasherClientResolver = () => Pick<ReturnType<typeof getClient>, "addBreadcrumb" | "captureError">;
|
|
4
4
|
/**
|
|
@@ -14,4 +14,3 @@ export type SquasherClientResolver = () => Pick<ReturnType<typeof getClient>, "a
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function squasherApiHandler(handler: NextApiHandler, resolveClient?: SquasherClientResolver): NextApiHandler;
|
|
16
16
|
export {};
|
|
17
|
-
//# sourceMappingURL=api-handler.d.ts.map
|
package/dist/api-handler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getClient } from "
|
|
2
|
-
import { attemptAsync } from "
|
|
1
|
+
import { getClient } from "./_vendor/node-sdk/index.js";
|
|
2
|
+
import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
|
|
3
3
|
/**
|
|
4
4
|
* Wrap a Next.js App Router API route handler to capture errors.
|
|
5
5
|
*
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
2
|
-
import { getClient, type JsonObject } from "
|
|
2
|
+
import { getClient, type JsonObject } from "./_vendor/node-sdk/index.js";
|
|
3
3
|
interface Props {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
fallback?: ReactNode;
|
|
@@ -27,4 +27,3 @@ export declare class SquasherErrorBoundary extends Component<Props, State> {
|
|
|
27
27
|
render(): ReactNode;
|
|
28
28
|
}
|
|
29
29
|
export {};
|
|
30
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Component } from "react";
|
|
3
|
-
import { getClient } from "
|
|
4
|
-
import { attempt } from "
|
|
3
|
+
import { getClient } from "./_vendor/node-sdk/index.js";
|
|
4
|
+
import { attempt } from "./_vendor/result-runtime/attempt.js";
|
|
5
5
|
/**
|
|
6
6
|
* Error boundary that captures errors to Squasher.
|
|
7
7
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { SquasherClient, captureGeneration, init, getClient, identify, page, captureError, captureMessage, captureSpan, captureTelemetry, captureToolCall, screen, track, } from "
|
|
2
|
-
export type { AnalyticsContext, JsonObject, SquasherConfig, ErrorEvent, UserContext, Breadcrumb, LlmContext, PageContext, SessionContext, TelemetryKind, TelemetryMeasurement, ToolCallContext, TraceContext, VisitorContext, } from "
|
|
1
|
+
export { SquasherClient, captureGeneration, init, getClient, identify, page, captureError, captureMessage, captureSpan, captureTelemetry, captureToolCall, screen, track, } from "./_vendor/node-sdk/index.js";
|
|
2
|
+
export type { AnalyticsContext, JsonObject, SquasherConfig, ErrorEvent, UserContext, Breadcrumb, LlmContext, PageContext, SessionContext, TelemetryKind, TelemetryMeasurement, ToolCallContext, TraceContext, VisitorContext, } from "./_vendor/node-sdk/index.js";
|
|
3
3
|
export { withSquasher } from "./middleware.js";
|
|
4
4
|
export { squasherApiHandler } from "./api-handler.js";
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { SquasherClient, captureGeneration, init, getClient, identify, page, captureError, captureMessage, captureSpan, captureTelemetry, captureToolCall, screen, track, } from "
|
|
1
|
+
export { SquasherClient, captureGeneration, init, getClient, identify, page, captureError, captureMessage, captureSpan, captureTelemetry, captureToolCall, screen, track, } from "./_vendor/node-sdk/index.js";
|
|
2
2
|
export { withSquasher } from "./middleware.js";
|
|
3
3
|
export { squasherApiHandler } from "./api-handler.js";
|
package/dist/middleware.d.ts
CHANGED
|
@@ -14,4 +14,3 @@ type MiddlewareHandler = (request: NextRequest) => NextResponse | Response | Pro
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function withSquasher(handler: MiddlewareHandler, resolveClient?: SquasherClientResolver): MiddlewareHandler;
|
|
16
16
|
export {};
|
|
17
|
-
//# sourceMappingURL=middleware.d.ts.map
|
package/dist/middleware.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getClient } from "
|
|
2
|
-
import { attemptAsync } from "
|
|
1
|
+
import { getClient } from "./_vendor/node-sdk/index.js";
|
|
2
|
+
import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
|
|
3
3
|
/**
|
|
4
4
|
* Wrap a Next.js middleware to capture errors automatically.
|
|
5
5
|
*
|
package/package.json
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squasher-ai/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Official @squasher-ai/nextjs package for Squasher.",
|
|
5
5
|
"homepage": "https://squasher.ai",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/squasher-ai/squasher.git",
|
|
10
|
-
"directory": "packages/public/sdk-nextjs"
|
|
11
|
-
},
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/squasher-ai/squasher/issues"
|
|
14
|
-
},
|
|
15
7
|
"publishConfig": {
|
|
16
8
|
"access": "public"
|
|
17
9
|
},
|
|
@@ -28,10 +20,6 @@
|
|
|
28
20
|
"types": "./dist/client.d.ts"
|
|
29
21
|
}
|
|
30
22
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@squasher-ai/node": "0.3.0",
|
|
33
|
-
"@squasher-ai/result-utils": "0.2.0"
|
|
34
|
-
},
|
|
35
23
|
"peerDependencies": {
|
|
36
24
|
"next": ">=14.0.0"
|
|
37
25
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../src/api-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,KAAK,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACzE,MAAM,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAC7C,UAAU,CAAC,OAAO,SAAS,CAAC,EAC5B,eAAe,GAAG,cAAc,CACjC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,cAAc,EACvB,aAAa,GAAE,sBAAkC,GAChD,cAAc,CAyBhB"}
|
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5D,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,CACb,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,UAAU,KAChB,UAAU,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;CAC/D;AAED,UAAU,KAAK;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,qBAAsB,SAAQ,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;gBACpD,KAAK,EAAE,KAAK;IAKxB,MAAM,CAAC,wBAAwB,IAAI,KAAK;IAI/B,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAe3D,MAAM,IAAI,SAAS;CAM7B"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,KAAK,GACN,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/middleware.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,KAAK,iBAAiB,GAAG,CACvB,OAAO,EAAE,WAAW,KACjB,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,iBAAiB,EAC1B,aAAa,GAAE,sBAAkC,GAChD,iBAAiB,CAwBnB"}
|