@withgateway/sdk 0.1.12 → 0.1.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.
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Scores & success signals — record evaluation results and ROI-shaped success
3
+ * signals against a Gateway project.
4
+ *
5
+ * A **score** is any evaluation value attached to a trace or session (visible
6
+ * on the Scores page and in trace/session detail). A **success signal** is a
7
+ * score carrying `metadata["gateway.success.signal"]`, which the platform's
8
+ * Success Metrics feature aggregates into a metric's headline count/pass-rate
9
+ * (the `HOOK` metric source). Emit one whenever a real unit of business value
10
+ * happens ("resolved a ticket", "ran an eval", "a human accepted an edit").
11
+ *
12
+ * This mirrors the Python SDK's `Run.score()` / `Run.success()`
13
+ * (`gatewaysdk/sdk/src/gatewaysdk/run.py`). The score shape — name, numeric
14
+ * value, `gateway.success.signal` + `gateway.success.metricName` metadata, and
15
+ * the trace/session target — is IDENTICAL so the platform aggregates signals
16
+ * from either SDK unchanged.
17
+ *
18
+ * ```typescript
19
+ * import { ScoresClient } from "@withgateway/sdk/scores";
20
+ *
21
+ * const scores = ScoresClient.fromEnv();
22
+ * // A pass/fail signal that feeds the "resolved_ticket" Success Metric:
23
+ * await scores.success("resolved_ticket", true, {
24
+ * agentId: "support-triage",
25
+ * sessionId,
26
+ * });
27
+ * // A numeric signal:
28
+ * await scores.success("handle_time_s", 42, { agentId: "support-triage", sessionId });
29
+ * ```
30
+ *
31
+ * Under `tracing.initIsolated(...)` the returned handle exposes a `scores`
32
+ * client already bound to that project's keys — that is how the platform
33
+ * self-traces its own agents into dedicated projects.
34
+ */
35
+ /** Score value data type, matching Gateway's ingestion schema. */
36
+ type ScoreDataType = "NUMERIC" | "CATEGORICAL" | "BOOLEAN";
37
+ /** Reserved metadata keys that mark a score as an aggregatable success signal. */
38
+ declare const SUCCESS_SIGNAL_KEY = "gateway.success.signal";
39
+ declare const SUCCESS_METRIC_NAME_KEY = "gateway.success.metricName";
40
+ declare const AGENT_ID_KEY = "gateway.agent.id";
41
+ type ScoreOptions = {
42
+ /**
43
+ * Trace to link the score to. Auto-detected from the active OpenTelemetry
44
+ * span when omitted and no `sessionId` is given (mirrors the Python SDK).
45
+ */
46
+ traceId?: string;
47
+ /** Session to link the score to. Preferred target when present. */
48
+ sessionId?: string;
49
+ /** Dataset-run to link the score to (dataset-run scores). */
50
+ datasetRunId?: string;
51
+ /** Span-level score — requires `traceId`. */
52
+ observationId?: string;
53
+ /** "NUMERIC" | "CATEGORICAL" | "BOOLEAN"; inferred when omitted. */
54
+ dataType?: ScoreDataType;
55
+ /** Optional comment stored alongside the score. */
56
+ comment?: string;
57
+ /** Extra metadata merged into the score. */
58
+ metadata?: Record<string, unknown>;
59
+ /** Environment tag; defaults to the project's `default` environment. */
60
+ environment?: string;
61
+ };
62
+ type SuccessOptions = Omit<ScoreOptions, "dataType"> & {
63
+ /**
64
+ * The agent this signal belongs to (`gateway.agent.id`). Lets the platform
65
+ * roll the signal into that agent's Success Metric without a trace join.
66
+ */
67
+ agentId?: string;
68
+ /** The Success Metric name; defaults to the signal `name`. */
69
+ metricName?: string;
70
+ /** Override the inferred "BOOLEAN"/"NUMERIC" data type. */
71
+ dataType?: "NUMERIC" | "BOOLEAN";
72
+ };
73
+ type ScoresClientConfig = {
74
+ host: string;
75
+ publicKey: string;
76
+ secretKey: string;
77
+ timeoutSeconds?: number;
78
+ debug?: boolean;
79
+ };
80
+ type ScoresClientFromEnvConfig = Partial<ScoresClientConfig>;
81
+ /** Raised by the low-level {@link ScoresClient.postScore} on a failed request. */
82
+ declare class ScoreError extends Error {
83
+ constructor(message: string, options?: {
84
+ cause?: unknown;
85
+ });
86
+ }
87
+ /**
88
+ * Read the current trace id (32-hex) from the active OpenTelemetry span, or
89
+ * undefined when there is no valid active span. Mirrors the Python SDK's
90
+ * `_get_current_trace_id`.
91
+ */
92
+ declare function currentTraceId(): string | undefined;
93
+ /**
94
+ * Client for Gateway's public scores ingestion endpoint (Basic project keys).
95
+ * The `score`/`success` convenience methods are FAIL-SOFT — they never reject
96
+ * into the caller, they warn and resolve — matching the Python SDK's
97
+ * fire-and-forget scoring. The raw {@link postScore} throws on failure for
98
+ * callers that want to handle it.
99
+ */
100
+ declare class ScoresClient {
101
+ private readonly host;
102
+ private readonly publicKey;
103
+ private readonly secretKey;
104
+ private readonly timeoutSeconds;
105
+ private readonly debug;
106
+ constructor(config: ScoresClientConfig);
107
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
108
+ static fromEnv(config?: ScoresClientFromEnvConfig): ScoresClient;
109
+ /**
110
+ * Post a score, throwing {@link ScoreError} on any failure. Builds the exact
111
+ * `POST /api/public/scores` body the Python SDK sends: exactly one of
112
+ * `sessionId` / `traceId` (+ optional `observationId`) / `datasetRunId`.
113
+ * When no target is provided, the active OTel trace id is used; if none is
114
+ * available the call is a no-op (returns without posting), matching Python.
115
+ */
116
+ postScore(name: string, value: number | string, options?: ScoreOptions): Promise<void>;
117
+ /**
118
+ * Build the score request body, or null when no target can be resolved.
119
+ * Split out so it is unit-testable and shared by score()/success().
120
+ */
121
+ buildScoreBody(name: string, value: number | string, options?: ScoreOptions): Record<string, unknown> | null;
122
+ /**
123
+ * Post a score, FAIL-SOFT: warns and resolves on any failure so a broken
124
+ * transport never throws into (or rejects out of) the caller.
125
+ */
126
+ score(name: string, value: number | string, options?: ScoreOptions): Promise<void>;
127
+ /**
128
+ * Emit a SUCCESS SIGNAL that feeds a Gateway Success Metric — a score tagged
129
+ * with `gateway.success.signal` + `gateway.success.metricName` (and the agent
130
+ * identity when `agentId` is set). A boolean `value` records a 1/0 BOOLEAN
131
+ * score (pass/fail); a number records a NUMERIC score. FAIL-SOFT.
132
+ *
133
+ * The metadata shape matches the Python SDK's `Run.success()` exactly, so the
134
+ * platform's Success Metrics aggregation counts signals from either SDK
135
+ * without change.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * await scores.success("resolved_ticket", true, { agentId: "support-triage", sessionId });
140
+ * await scores.success("handle_time_s", 42, { agentId: "support-triage", sessionId });
141
+ * ```
142
+ */
143
+ success(name: string, value?: boolean | number, options?: SuccessOptions): Promise<void>;
144
+ private request;
145
+ private authHeader;
146
+ private log;
147
+ private warn;
148
+ }
149
+ /**
150
+ * Emit a success signal using credentials from the environment
151
+ * (GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY) — the ergonomic
152
+ * top-level entry point for the default `tracing.init()` path, mirroring the
153
+ * Python SDK's `run.success(...)`. FAIL-SOFT end to end: a missing/invalid
154
+ * environment or a transport failure warns and resolves, never throwing into
155
+ * the caller. For isolated providers use the handle's bound client
156
+ * (`handle.scores.success(...)`) instead so the signal lands in that project.
157
+ */
158
+ declare function success(name: string, value?: boolean | number, options?: SuccessOptions): Promise<void>;
159
+ /** Lowercase convenience namespace, matching the `users` export. */
160
+ declare const scores: {
161
+ fromEnv: typeof ScoresClient.fromEnv;
162
+ success: typeof success;
163
+ };
164
+
165
+ export { AGENT_ID_KEY, SUCCESS_METRIC_NAME_KEY, SUCCESS_SIGNAL_KEY, type ScoreDataType, ScoreError, type ScoreOptions, ScoresClient, type ScoresClientConfig, type ScoresClientFromEnvConfig, type SuccessOptions, currentTraceId, scores, success };
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Scores & success signals — record evaluation results and ROI-shaped success
3
+ * signals against a Gateway project.
4
+ *
5
+ * A **score** is any evaluation value attached to a trace or session (visible
6
+ * on the Scores page and in trace/session detail). A **success signal** is a
7
+ * score carrying `metadata["gateway.success.signal"]`, which the platform's
8
+ * Success Metrics feature aggregates into a metric's headline count/pass-rate
9
+ * (the `HOOK` metric source). Emit one whenever a real unit of business value
10
+ * happens ("resolved a ticket", "ran an eval", "a human accepted an edit").
11
+ *
12
+ * This mirrors the Python SDK's `Run.score()` / `Run.success()`
13
+ * (`gatewaysdk/sdk/src/gatewaysdk/run.py`). The score shape — name, numeric
14
+ * value, `gateway.success.signal` + `gateway.success.metricName` metadata, and
15
+ * the trace/session target — is IDENTICAL so the platform aggregates signals
16
+ * from either SDK unchanged.
17
+ *
18
+ * ```typescript
19
+ * import { ScoresClient } from "@withgateway/sdk/scores";
20
+ *
21
+ * const scores = ScoresClient.fromEnv();
22
+ * // A pass/fail signal that feeds the "resolved_ticket" Success Metric:
23
+ * await scores.success("resolved_ticket", true, {
24
+ * agentId: "support-triage",
25
+ * sessionId,
26
+ * });
27
+ * // A numeric signal:
28
+ * await scores.success("handle_time_s", 42, { agentId: "support-triage", sessionId });
29
+ * ```
30
+ *
31
+ * Under `tracing.initIsolated(...)` the returned handle exposes a `scores`
32
+ * client already bound to that project's keys — that is how the platform
33
+ * self-traces its own agents into dedicated projects.
34
+ */
35
+ /** Score value data type, matching Gateway's ingestion schema. */
36
+ type ScoreDataType = "NUMERIC" | "CATEGORICAL" | "BOOLEAN";
37
+ /** Reserved metadata keys that mark a score as an aggregatable success signal. */
38
+ declare const SUCCESS_SIGNAL_KEY = "gateway.success.signal";
39
+ declare const SUCCESS_METRIC_NAME_KEY = "gateway.success.metricName";
40
+ declare const AGENT_ID_KEY = "gateway.agent.id";
41
+ type ScoreOptions = {
42
+ /**
43
+ * Trace to link the score to. Auto-detected from the active OpenTelemetry
44
+ * span when omitted and no `sessionId` is given (mirrors the Python SDK).
45
+ */
46
+ traceId?: string;
47
+ /** Session to link the score to. Preferred target when present. */
48
+ sessionId?: string;
49
+ /** Dataset-run to link the score to (dataset-run scores). */
50
+ datasetRunId?: string;
51
+ /** Span-level score — requires `traceId`. */
52
+ observationId?: string;
53
+ /** "NUMERIC" | "CATEGORICAL" | "BOOLEAN"; inferred when omitted. */
54
+ dataType?: ScoreDataType;
55
+ /** Optional comment stored alongside the score. */
56
+ comment?: string;
57
+ /** Extra metadata merged into the score. */
58
+ metadata?: Record<string, unknown>;
59
+ /** Environment tag; defaults to the project's `default` environment. */
60
+ environment?: string;
61
+ };
62
+ type SuccessOptions = Omit<ScoreOptions, "dataType"> & {
63
+ /**
64
+ * The agent this signal belongs to (`gateway.agent.id`). Lets the platform
65
+ * roll the signal into that agent's Success Metric without a trace join.
66
+ */
67
+ agentId?: string;
68
+ /** The Success Metric name; defaults to the signal `name`. */
69
+ metricName?: string;
70
+ /** Override the inferred "BOOLEAN"/"NUMERIC" data type. */
71
+ dataType?: "NUMERIC" | "BOOLEAN";
72
+ };
73
+ type ScoresClientConfig = {
74
+ host: string;
75
+ publicKey: string;
76
+ secretKey: string;
77
+ timeoutSeconds?: number;
78
+ debug?: boolean;
79
+ };
80
+ type ScoresClientFromEnvConfig = Partial<ScoresClientConfig>;
81
+ /** Raised by the low-level {@link ScoresClient.postScore} on a failed request. */
82
+ declare class ScoreError extends Error {
83
+ constructor(message: string, options?: {
84
+ cause?: unknown;
85
+ });
86
+ }
87
+ /**
88
+ * Read the current trace id (32-hex) from the active OpenTelemetry span, or
89
+ * undefined when there is no valid active span. Mirrors the Python SDK's
90
+ * `_get_current_trace_id`.
91
+ */
92
+ declare function currentTraceId(): string | undefined;
93
+ /**
94
+ * Client for Gateway's public scores ingestion endpoint (Basic project keys).
95
+ * The `score`/`success` convenience methods are FAIL-SOFT — they never reject
96
+ * into the caller, they warn and resolve — matching the Python SDK's
97
+ * fire-and-forget scoring. The raw {@link postScore} throws on failure for
98
+ * callers that want to handle it.
99
+ */
100
+ declare class ScoresClient {
101
+ private readonly host;
102
+ private readonly publicKey;
103
+ private readonly secretKey;
104
+ private readonly timeoutSeconds;
105
+ private readonly debug;
106
+ constructor(config: ScoresClientConfig);
107
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
108
+ static fromEnv(config?: ScoresClientFromEnvConfig): ScoresClient;
109
+ /**
110
+ * Post a score, throwing {@link ScoreError} on any failure. Builds the exact
111
+ * `POST /api/public/scores` body the Python SDK sends: exactly one of
112
+ * `sessionId` / `traceId` (+ optional `observationId`) / `datasetRunId`.
113
+ * When no target is provided, the active OTel trace id is used; if none is
114
+ * available the call is a no-op (returns without posting), matching Python.
115
+ */
116
+ postScore(name: string, value: number | string, options?: ScoreOptions): Promise<void>;
117
+ /**
118
+ * Build the score request body, or null when no target can be resolved.
119
+ * Split out so it is unit-testable and shared by score()/success().
120
+ */
121
+ buildScoreBody(name: string, value: number | string, options?: ScoreOptions): Record<string, unknown> | null;
122
+ /**
123
+ * Post a score, FAIL-SOFT: warns and resolves on any failure so a broken
124
+ * transport never throws into (or rejects out of) the caller.
125
+ */
126
+ score(name: string, value: number | string, options?: ScoreOptions): Promise<void>;
127
+ /**
128
+ * Emit a SUCCESS SIGNAL that feeds a Gateway Success Metric — a score tagged
129
+ * with `gateway.success.signal` + `gateway.success.metricName` (and the agent
130
+ * identity when `agentId` is set). A boolean `value` records a 1/0 BOOLEAN
131
+ * score (pass/fail); a number records a NUMERIC score. FAIL-SOFT.
132
+ *
133
+ * The metadata shape matches the Python SDK's `Run.success()` exactly, so the
134
+ * platform's Success Metrics aggregation counts signals from either SDK
135
+ * without change.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * await scores.success("resolved_ticket", true, { agentId: "support-triage", sessionId });
140
+ * await scores.success("handle_time_s", 42, { agentId: "support-triage", sessionId });
141
+ * ```
142
+ */
143
+ success(name: string, value?: boolean | number, options?: SuccessOptions): Promise<void>;
144
+ private request;
145
+ private authHeader;
146
+ private log;
147
+ private warn;
148
+ }
149
+ /**
150
+ * Emit a success signal using credentials from the environment
151
+ * (GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY) — the ergonomic
152
+ * top-level entry point for the default `tracing.init()` path, mirroring the
153
+ * Python SDK's `run.success(...)`. FAIL-SOFT end to end: a missing/invalid
154
+ * environment or a transport failure warns and resolves, never throwing into
155
+ * the caller. For isolated providers use the handle's bound client
156
+ * (`handle.scores.success(...)`) instead so the signal lands in that project.
157
+ */
158
+ declare function success(name: string, value?: boolean | number, options?: SuccessOptions): Promise<void>;
159
+ /** Lowercase convenience namespace, matching the `users` export. */
160
+ declare const scores: {
161
+ fromEnv: typeof ScoresClient.fromEnv;
162
+ success: typeof success;
163
+ };
164
+
165
+ export { AGENT_ID_KEY, SUCCESS_METRIC_NAME_KEY, SUCCESS_SIGNAL_KEY, type ScoreDataType, ScoreError, type ScoreOptions, ScoresClient, type ScoresClientConfig, type ScoresClientFromEnvConfig, type SuccessOptions, currentTraceId, scores, success };
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/scores/index.ts
21
+ var scores_exports = {};
22
+ __export(scores_exports, {
23
+ AGENT_ID_KEY: () => AGENT_ID_KEY,
24
+ SUCCESS_METRIC_NAME_KEY: () => SUCCESS_METRIC_NAME_KEY,
25
+ SUCCESS_SIGNAL_KEY: () => SUCCESS_SIGNAL_KEY,
26
+ ScoreError: () => ScoreError,
27
+ ScoresClient: () => ScoresClient,
28
+ currentTraceId: () => currentTraceId,
29
+ scores: () => scores,
30
+ success: () => success
31
+ });
32
+ module.exports = __toCommonJS(scores_exports);
33
+ var import_api = require("@opentelemetry/api");
34
+ var SUCCESS_SIGNAL_KEY = "gateway.success.signal";
35
+ var SUCCESS_METRIC_NAME_KEY = "gateway.success.metricName";
36
+ var AGENT_ID_KEY = "gateway.agent.id";
37
+ var ScoreError = class extends Error {
38
+ constructor(message, options) {
39
+ super(message);
40
+ this.name = "ScoreError";
41
+ this.cause = options?.cause;
42
+ }
43
+ };
44
+ function currentTraceId() {
45
+ try {
46
+ const span = import_api.trace.getActiveSpan();
47
+ if (!span) return void 0;
48
+ const ctx = span.spanContext();
49
+ if (!ctx || !(0, import_api.isSpanContextValid)(ctx)) return void 0;
50
+ return ctx.traceId;
51
+ } catch {
52
+ return void 0;
53
+ }
54
+ }
55
+ var ScoresClient = class _ScoresClient {
56
+ host;
57
+ publicKey;
58
+ secretKey;
59
+ timeoutSeconds;
60
+ debug;
61
+ constructor(config) {
62
+ this.host = config.host.replace(/\/$/, "");
63
+ this.publicKey = config.publicKey;
64
+ this.secretKey = config.secretKey;
65
+ this.timeoutSeconds = config.timeoutSeconds ?? 15;
66
+ this.debug = config.debug ?? false;
67
+ }
68
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
69
+ static fromEnv(config = {}) {
70
+ const host = config.host ?? process.env.GATEWAY_HOST;
71
+ const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
72
+ const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;
73
+ const missing = [
74
+ ["host", host],
75
+ ["publicKey", publicKey],
76
+ ["secretKey", secretKey]
77
+ ].filter(([, value]) => !value).map(([name]) => name);
78
+ if (missing.length > 0) {
79
+ throw new ScoreError(
80
+ `Missing Gateway scores configuration: ${missing.join(", ")}`
81
+ );
82
+ }
83
+ return new _ScoresClient({
84
+ ...config,
85
+ host,
86
+ publicKey,
87
+ secretKey
88
+ });
89
+ }
90
+ /**
91
+ * Post a score, throwing {@link ScoreError} on any failure. Builds the exact
92
+ * `POST /api/public/scores` body the Python SDK sends: exactly one of
93
+ * `sessionId` / `traceId` (+ optional `observationId`) / `datasetRunId`.
94
+ * When no target is provided, the active OTel trace id is used; if none is
95
+ * available the call is a no-op (returns without posting), matching Python.
96
+ */
97
+ async postScore(name, value, options = {}) {
98
+ const body = this.buildScoreBody(name, value, options);
99
+ if (!body) {
100
+ this.log(
101
+ "score '%s' dropped: no sessionId, traceId or datasetRunId available",
102
+ name
103
+ );
104
+ return;
105
+ }
106
+ await this.request("POST", "/api/public/scores", body);
107
+ }
108
+ /**
109
+ * Build the score request body, or null when no target can be resolved.
110
+ * Split out so it is unit-testable and shared by score()/success().
111
+ */
112
+ buildScoreBody(name, value, options = {}) {
113
+ const traceId = options.traceId ?? currentTraceId();
114
+ const target = {};
115
+ if (options.sessionId) {
116
+ target.sessionId = options.sessionId;
117
+ } else if (options.datasetRunId) {
118
+ target.datasetRunId = options.datasetRunId;
119
+ } else if (traceId) {
120
+ target.traceId = traceId;
121
+ if (options.observationId) target.observationId = options.observationId;
122
+ } else {
123
+ return null;
124
+ }
125
+ const metadata = {
126
+ source: "gatewaysdk",
127
+ ...options.metadata ?? {}
128
+ };
129
+ return {
130
+ name,
131
+ value,
132
+ dataType: options.dataType ?? "NUMERIC",
133
+ environment: options.environment ?? "default",
134
+ ...options.comment ? { comment: options.comment } : {},
135
+ metadata,
136
+ ...target
137
+ };
138
+ }
139
+ /**
140
+ * Post a score, FAIL-SOFT: warns and resolves on any failure so a broken
141
+ * transport never throws into (or rejects out of) the caller.
142
+ */
143
+ async score(name, value, options = {}) {
144
+ try {
145
+ await this.postScore(name, value, options);
146
+ } catch (error) {
147
+ this.warn(`score '${name}' failed`, error);
148
+ }
149
+ }
150
+ /**
151
+ * Emit a SUCCESS SIGNAL that feeds a Gateway Success Metric — a score tagged
152
+ * with `gateway.success.signal` + `gateway.success.metricName` (and the agent
153
+ * identity when `agentId` is set). A boolean `value` records a 1/0 BOOLEAN
154
+ * score (pass/fail); a number records a NUMERIC score. FAIL-SOFT.
155
+ *
156
+ * The metadata shape matches the Python SDK's `Run.success()` exactly, so the
157
+ * platform's Success Metrics aggregation counts signals from either SDK
158
+ * without change.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * await scores.success("resolved_ticket", true, { agentId: "support-triage", sessionId });
163
+ * await scores.success("handle_time_s", 42, { agentId: "support-triage", sessionId });
164
+ * ```
165
+ */
166
+ async success(name, value = true, options = {}) {
167
+ const { numericValue, inferredType } = coerceSignalValue(value);
168
+ const { agentId, metricName, metadata, dataType, ...rest } = options;
169
+ const signalMetadata = {
170
+ ...metadata ?? {},
171
+ [SUCCESS_SIGNAL_KEY]: true,
172
+ [SUCCESS_METRIC_NAME_KEY]: metricName ?? name,
173
+ ...agentId ? { [AGENT_ID_KEY]: agentId } : {}
174
+ };
175
+ await this.score(name, numericValue, {
176
+ ...rest,
177
+ dataType: dataType ?? inferredType,
178
+ metadata: signalMetadata
179
+ });
180
+ }
181
+ async request(method, path, payload) {
182
+ let response;
183
+ try {
184
+ response = await fetch(`${this.host}${path}`, {
185
+ method,
186
+ headers: {
187
+ Authorization: this.authHeader(),
188
+ "Content-Type": "application/json"
189
+ },
190
+ body: JSON.stringify(payload),
191
+ signal: AbortSignal.timeout(this.timeoutSeconds * 1e3)
192
+ });
193
+ } catch (error) {
194
+ throw new ScoreError(
195
+ `${method} ${path} failed: ${error instanceof Error ? error.message : String(error)}`,
196
+ { cause: error }
197
+ );
198
+ }
199
+ const text = await response.text();
200
+ if (!response.ok) {
201
+ throw new ScoreError(
202
+ `${method} ${path} failed (${response.status}): ${text.slice(0, 500)}`
203
+ );
204
+ }
205
+ this.log("%s %s -> %s", method, path, response.status);
206
+ }
207
+ authHeader() {
208
+ return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
209
+ "base64"
210
+ )}`;
211
+ }
212
+ log(message, ...args) {
213
+ if (this.debug) {
214
+ console.log(`[gateway.scores] ${message}`, ...args);
215
+ }
216
+ }
217
+ warn(message, ...args) {
218
+ console.warn(`[gateway.scores] ${message}`, ...args);
219
+ }
220
+ };
221
+ function coerceSignalValue(value) {
222
+ if (typeof value === "boolean") {
223
+ return { numericValue: value ? 1 : 0, inferredType: "BOOLEAN" };
224
+ }
225
+ return { numericValue: value, inferredType: "NUMERIC" };
226
+ }
227
+ async function success(name, value = true, options = {}) {
228
+ let client;
229
+ try {
230
+ client = ScoresClient.fromEnv();
231
+ } catch (error) {
232
+ console.warn(`[gateway.scores] success '${name}' skipped`, error);
233
+ return;
234
+ }
235
+ await client.success(name, value, options);
236
+ }
237
+ var scores = {
238
+ fromEnv: ScoresClient.fromEnv,
239
+ success
240
+ };
241
+ // Annotate the CommonJS export names for ESM import in node:
242
+ 0 && (module.exports = {
243
+ AGENT_ID_KEY,
244
+ SUCCESS_METRIC_NAME_KEY,
245
+ SUCCESS_SIGNAL_KEY,
246
+ ScoreError,
247
+ ScoresClient,
248
+ currentTraceId,
249
+ scores,
250
+ success
251
+ });
252
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/scores/index.ts"],"sourcesContent":["/**\n * Scores & success signals — record evaluation results and ROI-shaped success\n * signals against a Gateway project.\n *\n * A **score** is any evaluation value attached to a trace or session (visible\n * on the Scores page and in trace/session detail). A **success signal** is a\n * score carrying `metadata[\"gateway.success.signal\"]`, which the platform's\n * Success Metrics feature aggregates into a metric's headline count/pass-rate\n * (the `HOOK` metric source). Emit one whenever a real unit of business value\n * happens (\"resolved a ticket\", \"ran an eval\", \"a human accepted an edit\").\n *\n * This mirrors the Python SDK's `Run.score()` / `Run.success()`\n * (`gatewaysdk/sdk/src/gatewaysdk/run.py`). The score shape — name, numeric\n * value, `gateway.success.signal` + `gateway.success.metricName` metadata, and\n * the trace/session target — is IDENTICAL so the platform aggregates signals\n * from either SDK unchanged.\n *\n * ```typescript\n * import { ScoresClient } from \"@withgateway/sdk/scores\";\n *\n * const scores = ScoresClient.fromEnv();\n * // A pass/fail signal that feeds the \"resolved_ticket\" Success Metric:\n * await scores.success(\"resolved_ticket\", true, {\n * agentId: \"support-triage\",\n * sessionId,\n * });\n * // A numeric signal:\n * await scores.success(\"handle_time_s\", 42, { agentId: \"support-triage\", sessionId });\n * ```\n *\n * Under `tracing.initIsolated(...)` the returned handle exposes a `scores`\n * client already bound to that project's keys — that is how the platform\n * self-traces its own agents into dedicated projects.\n */\n\nimport { isSpanContextValid, trace } from \"@opentelemetry/api\";\n\n/** Score value data type, matching Gateway's ingestion schema. */\nexport type ScoreDataType = \"NUMERIC\" | \"CATEGORICAL\" | \"BOOLEAN\";\n\n/** Reserved metadata keys that mark a score as an aggregatable success signal. */\nexport const SUCCESS_SIGNAL_KEY = \"gateway.success.signal\";\nexport const SUCCESS_METRIC_NAME_KEY = \"gateway.success.metricName\";\nexport const AGENT_ID_KEY = \"gateway.agent.id\";\n\nexport type ScoreOptions = {\n /**\n * Trace to link the score to. Auto-detected from the active OpenTelemetry\n * span when omitted and no `sessionId` is given (mirrors the Python SDK).\n */\n traceId?: string;\n /** Session to link the score to. Preferred target when present. */\n sessionId?: string;\n /** Dataset-run to link the score to (dataset-run scores). */\n datasetRunId?: string;\n /** Span-level score — requires `traceId`. */\n observationId?: string;\n /** \"NUMERIC\" | \"CATEGORICAL\" | \"BOOLEAN\"; inferred when omitted. */\n dataType?: ScoreDataType;\n /** Optional comment stored alongside the score. */\n comment?: string;\n /** Extra metadata merged into the score. */\n metadata?: Record<string, unknown>;\n /** Environment tag; defaults to the project's `default` environment. */\n environment?: string;\n};\n\nexport type SuccessOptions = Omit<ScoreOptions, \"dataType\"> & {\n /**\n * The agent this signal belongs to (`gateway.agent.id`). Lets the platform\n * roll the signal into that agent's Success Metric without a trace join.\n */\n agentId?: string;\n /** The Success Metric name; defaults to the signal `name`. */\n metricName?: string;\n /** Override the inferred \"BOOLEAN\"/\"NUMERIC\" data type. */\n dataType?: \"NUMERIC\" | \"BOOLEAN\";\n};\n\nexport type ScoresClientConfig = {\n host: string;\n publicKey: string;\n secretKey: string;\n timeoutSeconds?: number;\n debug?: boolean;\n};\n\nexport type ScoresClientFromEnvConfig = Partial<ScoresClientConfig>;\n\n/** Raised by the low-level {@link ScoresClient.postScore} on a failed request. */\nexport class ScoreError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = \"ScoreError\";\n this.cause = options?.cause;\n }\n}\n\n/**\n * Read the current trace id (32-hex) from the active OpenTelemetry span, or\n * undefined when there is no valid active span. Mirrors the Python SDK's\n * `_get_current_trace_id`.\n */\nexport function currentTraceId(): string | undefined {\n try {\n const span = trace.getActiveSpan();\n if (!span) return undefined;\n const ctx = span.spanContext();\n if (!ctx || !isSpanContextValid(ctx)) return undefined;\n return ctx.traceId;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Client for Gateway's public scores ingestion endpoint (Basic project keys).\n * The `score`/`success` convenience methods are FAIL-SOFT — they never reject\n * into the caller, they warn and resolve — matching the Python SDK's\n * fire-and-forget scoring. The raw {@link postScore} throws on failure for\n * callers that want to handle it.\n */\nexport class ScoresClient {\n private readonly host: string;\n private readonly publicKey: string;\n private readonly secretKey: string;\n private readonly timeoutSeconds: number;\n private readonly debug: boolean;\n\n constructor(config: ScoresClientConfig) {\n this.host = config.host.replace(/\\/$/, \"\");\n this.publicKey = config.publicKey;\n this.secretKey = config.secretKey;\n this.timeoutSeconds = config.timeoutSeconds ?? 15;\n this.debug = config.debug ?? false;\n }\n\n /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */\n static fromEnv(config: ScoresClientFromEnvConfig = {}): ScoresClient {\n const host = config.host ?? process.env.GATEWAY_HOST;\n const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;\n\n const missing = [\n [\"host\", host],\n [\"publicKey\", publicKey],\n [\"secretKey\", secretKey],\n ]\n .filter(([, value]) => !value)\n .map(([name]) => name);\n\n if (missing.length > 0) {\n throw new ScoreError(\n `Missing Gateway scores configuration: ${missing.join(\", \")}`,\n );\n }\n\n return new ScoresClient({\n ...config,\n host: host!,\n publicKey: publicKey!,\n secretKey: secretKey!,\n });\n }\n\n /**\n * Post a score, throwing {@link ScoreError} on any failure. Builds the exact\n * `POST /api/public/scores` body the Python SDK sends: exactly one of\n * `sessionId` / `traceId` (+ optional `observationId`) / `datasetRunId`.\n * When no target is provided, the active OTel trace id is used; if none is\n * available the call is a no-op (returns without posting), matching Python.\n */\n async postScore(\n name: string,\n value: number | string,\n options: ScoreOptions = {},\n ): Promise<void> {\n const body = this.buildScoreBody(name, value, options);\n if (!body) {\n this.log(\n \"score '%s' dropped: no sessionId, traceId or datasetRunId available\",\n name,\n );\n return;\n }\n await this.request(\"POST\", \"/api/public/scores\", body);\n }\n\n /**\n * Build the score request body, or null when no target can be resolved.\n * Split out so it is unit-testable and shared by score()/success().\n */\n buildScoreBody(\n name: string,\n value: number | string,\n options: ScoreOptions = {},\n ): Record<string, unknown> | null {\n // Prefer sessionId (scores typically grade a whole session/rollout), then\n // datasetRunId, then an explicit traceId, then the ambient OTel trace.\n const traceId = options.traceId ?? currentTraceId();\n const target: Record<string, unknown> = {};\n if (options.sessionId) {\n target.sessionId = options.sessionId;\n } else if (options.datasetRunId) {\n target.datasetRunId = options.datasetRunId;\n } else if (traceId) {\n target.traceId = traceId;\n if (options.observationId) target.observationId = options.observationId;\n } else {\n return null;\n }\n\n // Base metadata mirrors the Python SDK (source tag), then the caller's\n // metadata is merged on top — identical to `score_metadata.update(...)`.\n const metadata: Record<string, unknown> = {\n source: \"gatewaysdk\",\n ...(options.metadata ?? {}),\n };\n\n return {\n name,\n value,\n dataType: options.dataType ?? \"NUMERIC\",\n environment: options.environment ?? \"default\",\n ...(options.comment ? { comment: options.comment } : {}),\n metadata,\n ...target,\n };\n }\n\n /**\n * Post a score, FAIL-SOFT: warns and resolves on any failure so a broken\n * transport never throws into (or rejects out of) the caller.\n */\n async score(\n name: string,\n value: number | string,\n options: ScoreOptions = {},\n ): Promise<void> {\n try {\n await this.postScore(name, value, options);\n } catch (error) {\n this.warn(`score '${name}' failed`, error);\n }\n }\n\n /**\n * Emit a SUCCESS SIGNAL that feeds a Gateway Success Metric — a score tagged\n * with `gateway.success.signal` + `gateway.success.metricName` (and the agent\n * identity when `agentId` is set). A boolean `value` records a 1/0 BOOLEAN\n * score (pass/fail); a number records a NUMERIC score. FAIL-SOFT.\n *\n * The metadata shape matches the Python SDK's `Run.success()` exactly, so the\n * platform's Success Metrics aggregation counts signals from either SDK\n * without change.\n *\n * @example\n * ```ts\n * await scores.success(\"resolved_ticket\", true, { agentId: \"support-triage\", sessionId });\n * await scores.success(\"handle_time_s\", 42, { agentId: \"support-triage\", sessionId });\n * ```\n */\n async success(\n name: string,\n value: boolean | number = true,\n options: SuccessOptions = {},\n ): Promise<void> {\n const { numericValue, inferredType } = coerceSignalValue(value);\n const { agentId, metricName, metadata, dataType, ...rest } = options;\n\n // Required signal keys are written LAST so a caller's `metadata` cannot\n // accidentally clobber them and silently drop the signal from aggregation.\n const signalMetadata: Record<string, unknown> = {\n ...(metadata ?? {}),\n [SUCCESS_SIGNAL_KEY]: true,\n [SUCCESS_METRIC_NAME_KEY]: metricName ?? name,\n ...(agentId ? { [AGENT_ID_KEY]: agentId } : {}),\n };\n\n await this.score(name, numericValue, {\n ...rest,\n dataType: dataType ?? inferredType,\n metadata: signalMetadata,\n });\n }\n\n private async request(\n method: \"POST\",\n path: string,\n payload: Record<string, unknown>,\n ): Promise<void> {\n let response: Response;\n try {\n response = await fetch(`${this.host}${path}`, {\n method,\n headers: {\n Authorization: this.authHeader(),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n signal: AbortSignal.timeout(this.timeoutSeconds * 1000),\n });\n } catch (error) {\n throw new ScoreError(\n `${method} ${path} failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n\n const text = await response.text();\n if (!response.ok) {\n throw new ScoreError(\n `${method} ${path} failed (${response.status}): ${text.slice(0, 500)}`,\n );\n }\n this.log(\"%s %s -> %s\", method, path, response.status);\n }\n\n private authHeader(): string {\n return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(\n \"base64\",\n )}`;\n }\n\n private log(message: string, ...args: unknown[]): void {\n if (this.debug) {\n console.log(`[gateway.scores] ${message}`, ...args);\n }\n }\n\n private warn(message: string, ...args: unknown[]): void {\n console.warn(`[gateway.scores] ${message}`, ...args);\n }\n}\n\n/** Map a success value to its numeric score + inferred data type. */\nfunction coerceSignalValue(value: boolean | number): {\n numericValue: number;\n inferredType: \"NUMERIC\" | \"BOOLEAN\";\n} {\n if (typeof value === \"boolean\") {\n return { numericValue: value ? 1 : 0, inferredType: \"BOOLEAN\" };\n }\n return { numericValue: value, inferredType: \"NUMERIC\" };\n}\n\n/**\n * Emit a success signal using credentials from the environment\n * (GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY) — the ergonomic\n * top-level entry point for the default `tracing.init()` path, mirroring the\n * Python SDK's `run.success(...)`. FAIL-SOFT end to end: a missing/invalid\n * environment or a transport failure warns and resolves, never throwing into\n * the caller. For isolated providers use the handle's bound client\n * (`handle.scores.success(...)`) instead so the signal lands in that project.\n */\nexport async function success(\n name: string,\n value: boolean | number = true,\n options: SuccessOptions = {},\n): Promise<void> {\n let client: ScoresClient;\n try {\n client = ScoresClient.fromEnv();\n } catch (error) {\n console.warn(`[gateway.scores] success '${name}' skipped`, error);\n return;\n }\n await client.success(name, value, options);\n}\n\n/** Lowercase convenience namespace, matching the `users` export. */\nexport const scores = {\n fromEnv: ScoresClient.fromEnv,\n success,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA,iBAA0C;AAMnC,IAAM,qBAAqB;AAC3B,IAAM,0BAA0B;AAChC,IAAM,eAAe;AA+CrB,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,QAAQ,SAAS;AAAA,EACxB;AACF;AA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