@hue-run/sdk 0.1.5 → 0.2.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.
Files changed (56) hide show
  1. package/ENVIRONMENTS.md +182 -0
  2. package/EVALUATIONS.md +12 -0
  3. package/README.md +192 -18
  4. package/dist/ai-sdk.d.ts +9 -1
  5. package/dist/ai-sdk.js +34 -8
  6. package/dist/client.d.ts +121 -6
  7. package/dist/client.js +329 -56
  8. package/dist/config.d.ts +11 -2
  9. package/dist/config.js +36 -7
  10. package/dist/environment/client.d.ts +73 -0
  11. package/dist/environment/client.js +209 -0
  12. package/dist/environment/tools.d.ts +30 -0
  13. package/dist/environment/tools.js +24 -0
  14. package/dist/environment/types.d.ts +429 -0
  15. package/dist/environment/types.js +1 -0
  16. package/dist/environment.d.ts +5 -0
  17. package/dist/environment.js +2 -0
  18. package/dist/evals/attempt.d.ts +454 -0
  19. package/dist/evals/attempt.js +687 -0
  20. package/dist/evals/client.d.ts +99 -5
  21. package/dist/evals/client.js +136 -7
  22. package/dist/evals/environment-evidence.d.ts +6 -0
  23. package/dist/evals/environment-evidence.js +123 -0
  24. package/dist/evals/environment-json.d.ts +3 -0
  25. package/dist/evals/environment-json.js +76 -0
  26. package/dist/evals/json.d.ts +9 -1
  27. package/dist/evals/json.js +14 -6
  28. package/dist/evals/runner.d.ts +61 -2
  29. package/dist/evals/runner.js +71 -9
  30. package/dist/evals/scorer-publication.d.ts +2 -0
  31. package/dist/evals/scorer-publication.js +84 -0
  32. package/dist/evals/scorers.d.ts +11 -0
  33. package/dist/evals/scorers.js +56 -5
  34. package/dist/evals/simulation.d.ts +184 -0
  35. package/dist/evals/simulation.js +603 -0
  36. package/dist/evals/types.d.ts +304 -0
  37. package/dist/evals.d.ts +5 -1
  38. package/dist/evals.js +3 -1
  39. package/dist/experimental-telemetry.d.ts +8 -0
  40. package/dist/experimental-telemetry.js +13 -0
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.js +2 -0
  43. package/dist/managed.d.ts +51 -1
  44. package/dist/managed.js +11 -1
  45. package/dist/privacy.d.ts +2 -0
  46. package/dist/privacy.js +16 -1
  47. package/dist/receipt.d.ts +12 -1
  48. package/dist/receipt.js +10 -1
  49. package/dist/safety.d.ts +1 -2
  50. package/dist/snapshot.js +4 -0
  51. package/dist/transport.d.ts +41 -9
  52. package/dist/transport.js +80 -22
  53. package/dist/types.d.ts +144 -8
  54. package/dist/version.d.ts +2 -0
  55. package/dist/version.js +3 -0
  56. package/package.json +51 -15
package/dist/types.d.ts CHANGED
@@ -1,107 +1,243 @@
1
- import type { Attributes, Context, Span, SpanKind, TracerProvider } from "@opentelemetry/api";
1
+ import type { Attributes, Context, Span, SpanKind, Tracer, TracerProvider } from "@opentelemetry/api";
2
2
  import type { LoggerProvider } from "@opentelemetry/api-logs";
3
+ /**
4
+ * JSON-compatible data: the shape content has on the wire after the helpers encode it. Helpers
5
+ * accept `unknown` and validate at runtime; values that are not plain JSON are omitted with an
6
+ * instrumentation failure instead of being thrown into application code.
7
+ */
3
8
  export type JsonValue = null | boolean | number | string | JsonValue[] | {
4
9
  [key: string]: JsonValue;
5
10
  };
11
+ /** Telemetry signal named by export reports, issues and processors. */
6
12
  export type Signal = "traces" | "logs";
7
- interface SharedHueOptions {
13
+ /** Options accepted by every Hue client and transport, whether enabled or disabled. */
14
+ export interface SharedHueOptions {
15
+ /**
16
+ * Whether helpers record prompts, responses, tool arguments and results. Required for an enabled
17
+ * client, with no default; a disabled client (`enabled: false`) defaults it to `false`.
18
+ */
8
19
  captureContent: boolean;
20
+ /** Hue origin, `https://app.hue.run` by default. An origin only: no path, query, fragment or credentials. */
9
21
  baseUrl?: string;
22
+ /** Recorded as the `service.version` resource attribute of an owned client. */
10
23
  serviceVersion?: string;
24
+ /**
25
+ * Additional resource attributes for an owned client, for example `deployment.environment.name`
26
+ * or `service.namespace`. `service.name` and `service.version` from `serviceName` and
27
+ * `serviceVersion` take precedence over same-named keys, as in the OpenTelemetry NodeSDK.
28
+ * Ignored with a warning issue in attach mode, where the application owns the providers and
29
+ * their resource.
30
+ */
31
+ resourceAttributes?: Attributes;
32
+ /**
33
+ * Permits `http://` for hosts other than loopback, for example a docker-compose or in-cluster
34
+ * OpenTelemetry Collector. The project key then travels unencrypted; a one-time warning issue is
35
+ * recorded. Off by default: HTTPS is required except for loopback development servers.
36
+ */
37
+ allowInsecureHttp?: boolean;
11
38
  /** Runs on string values before Hue export, including custom attribute values. */
12
39
  redact?: (value: string, path: string) => string;
40
+ /** Receives sanitized export issues, at most one per second; never server response bodies or keys. */
13
41
  onExportIssue?: (issue: ExportIssue) => void | Promise<void>;
42
+ /** Budget for each export request and connection check in milliseconds, 100–60000. Default 10000. */
14
43
  timeoutMillis?: number;
15
44
  /** Aggregate estimated retained telemetry bytes across both signals, including in-flight work. Default 8 MiB. */
16
45
  maxQueueBytes?: number;
17
46
  }
18
- export type HueOptions = SharedHueOptions & ({
47
+ /**
48
+ * Options for a client that owns its OpenTelemetry providers. An enabled client needs a project
49
+ * key, a service name and an explicit `captureContent` choice. The kill switch (`enabled: false`)
50
+ * exports nothing while helpers keep running application code, so it needs no key and
51
+ * `captureContent` defaults to `false`.
52
+ */
53
+ export type HueOptions = (SharedHueOptions & {
54
+ /** Telemetry is on (the default). */
19
55
  enabled?: true;
56
+ /** Project service key sent as a Bearer token; server side only. */
20
57
  apiKey: string;
58
+ /** Recorded as the `service.name` resource attribute, 1–256 characters. */
21
59
  serviceName: string;
22
- } | {
60
+ }) | (Omit<SharedHueOptions, "captureContent"> & {
61
+ /** Local kill switch: no providers, exports or connection checks. */
23
62
  enabled: false;
63
+ /** Ignored when disabled. */
24
64
  apiKey?: string;
65
+ /** Ignored when disabled. */
25
66
  serviceName?: string;
67
+ /** Optional when disabled; defaults to `false` because nothing is exported. */
68
+ captureContent?: boolean;
26
69
  });
70
+ /** One sanitized delivery or instrumentation problem, kept in a bounded history of 128. */
27
71
  export interface ExportIssue {
72
+ /** Monotonic position in the transport's issue history. */
28
73
  sequence: number;
74
+ /** Signal the issue belongs to. */
29
75
  signal: Signal;
76
+ /** `rejected` by Hue, `failed` to deliver, `dropped` from the queue, `invalid` record or capture, or a non-failing `warning`. */
30
77
  kind: "rejected" | "failed" | "dropped" | "invalid" | "warning";
78
+ /** Records affected; zero for warnings and capture failures. */
31
79
  count: number;
80
+ /** HTTP status when the issue came from a response. */
32
81
  status?: number;
82
+ /** Fixed, sanitized description; never server text or content. */
33
83
  message: string;
34
84
  }
85
+ /** Cumulative delivery counters and current queue gauges for one transport. */
35
86
  export interface ExportReport {
87
+ /** Spans acknowledged by the collector. */
36
88
  acceptedSpans: number;
89
+ /** Log records acknowledged by the collector. */
37
90
  acceptedLogs: number;
91
+ /** Spans the collector rejected in a partial success. */
38
92
  rejectedSpans: number;
93
+ /** Log records the collector rejected in a partial success. */
39
94
  rejectedLogs: number;
95
+ /** Spans whose delivery failed or is uncertain. */
40
96
  failedSpans: number;
97
+ /** Log records whose delivery failed or is uncertain. */
41
98
  failedLogs: number;
99
+ /** Spans queued or in flight right now. */
42
100
  pendingSpans: number;
101
+ /** Log records queued or in flight right now. */
43
102
  pendingLogs: number;
103
+ /** Spans dropped before export because a queue or byte budget was full. */
44
104
  droppedSpans: number;
105
+ /** Log records dropped before export because a queue or byte budget was full. */
45
106
  droppedLogs: number;
107
+ /** Estimated bytes retained by the queue right now. */
46
108
  pendingBytes: number;
109
+ /** Helper capture or instrumentation failures that omitted telemetry while preserving application results. */
47
110
  instrumentationFailures: number;
48
111
  }
112
+ /** Caller budget for {@link HueClient.flushSafe} and {@link HueClient.shutdownSafe}. */
49
113
  export interface SafeLifecycleOptions {
50
114
  /** Caller wait budget, 1–60000 ms. Default 1000. Does not cancel borrowed providers. */
51
115
  timeoutMillis?: number;
52
116
  }
117
+ /** Non-throwing lifecycle outcome. */
53
118
  export interface SafeLifecycleResult {
119
+ /** Work finished within the budget with no new failures and nothing pending. */
54
120
  ok: boolean;
121
+ /** The budget elapsed before the drain finished; work continues in the background. */
55
122
  timedOut: boolean;
123
+ /** Counters at the time the result was produced. */
56
124
  report: ExportReport;
57
125
  }
126
+ /** Options for {@link HueClient.withSpan} and the span-level part of {@link HueClient.model}. */
58
127
  export interface SpanOptions {
128
+ /** OpenTelemetry span kind; `INTERNAL` by default. */
59
129
  kind?: SpanKind;
130
+ /** Attributes set when the span starts. */
60
131
  attributes?: Attributes;
132
+ /** Recorded as `gen_ai.conversation.id` on this span and inherited by nested helper spans. */
61
133
  sessionId?: string;
134
+ /** Recorded as `user.id` on this span and inherited by nested helper spans. */
62
135
  userId?: string;
63
- input?: JsonValue;
136
+ /** Recorded as `input.value` when `captureContent` is true; any JSON-encodable value. */
137
+ input?: unknown;
138
+ /** Explicit parent context, for example from {@link HueClient.extract}. */
64
139
  parentContext?: Context;
65
140
  }
141
+ /** Provider-reported token counts for {@link HueSpan.setUsage}. */
142
+ export interface TokenUsage {
143
+ /** Provider-reported prompt tokens (`gen_ai.usage.input_tokens`). */
144
+ inputTokens?: number;
145
+ /** Provider-reported completion tokens (`gen_ai.usage.output_tokens`). */
146
+ outputTokens?: number;
147
+ }
148
+ /**
149
+ * Options for {@link HueClient.model}: GenAI request metadata plus the {@link SpanOptions} that
150
+ * apply to a client span. `input` is recorded as `gen_ai.input.messages`.
151
+ */
152
+ export interface ModelOptions extends Pick<SpanOptions, "sessionId" | "userId" | "input" | "parentContext"> {
153
+ /** Provider identifier recorded as `gen_ai.provider.name`, for example "openai". */
154
+ provider: string;
155
+ /** Recorded as `gen_ai.operation.name`; defaults to "chat". */
156
+ operation?: string;
157
+ /** Span name; defaults to "{operation} {model}". */
158
+ name?: string;
159
+ }
160
+ /** Value for AI SDK 6's `experimental_telemetry` option; AI SDK 7 uses `hueTelemetry` instead. */
161
+ export interface ExperimentalTelemetrySettings {
162
+ /** Mirrors the client's `enabled` flag. */
163
+ isEnabled: boolean;
164
+ /** Mirrors `captureContent`. */
165
+ recordInputs: boolean;
166
+ /** Mirrors `captureContent`. */
167
+ recordOutputs: boolean;
168
+ /** Hue's tracer, so AI SDK spans parent under `withSpan` and inherit identifiers. */
169
+ tracer: Tracer;
170
+ }
171
+ /** Handle passed to helper callbacks; content methods respect `captureContent` and never throw. */
66
172
  export interface HueSpan {
173
+ /** The underlying OpenTelemetry span, isolated so provider faults cannot reach the callback. */
67
174
  span: Span;
175
+ /** Context with this span active, for APIs that take an explicit context. */
68
176
  context: Context;
177
+ /** Lowercase hex trace ID, or all zeros when the client is disabled. */
69
178
  traceId: string;
179
+ /** Lowercase hex span ID, or all zeros when the client is disabled. */
70
180
  spanId: string;
71
- setInput(value: JsonValue): void;
72
- setOutput(value: JsonValue): void;
181
+ /** Records `input.value` (or `gen_ai.input.messages` inside `model()`); any JSON-encodable value. */
182
+ setInput(value: unknown): void;
183
+ /** Records `output.value` (or `gen_ai.output.messages` inside `model()`); any JSON-encodable value. */
184
+ setOutput(value: unknown): void;
185
+ /** Records nonnegative integer token counts; invalid values are omitted and counted as instrumentation failures. */
186
+ setUsage(usage: TokenUsage): void;
73
187
  }
188
+ /** A tracer provider the client can drain; the OpenTelemetry SDK providers qualify. */
74
189
  export type FlushableTracerProvider = TracerProvider & {
190
+ /** Exports every finished span the provider still holds. */
75
191
  forceFlush(): Promise<void>;
76
192
  };
193
+ /** A logger provider the client can drain; the OpenTelemetry SDK providers qualify. */
77
194
  export type FlushableLoggerProvider = LoggerProvider & {
195
+ /** Exports every emitted log record the provider still holds. */
78
196
  forceFlush(): Promise<void>;
79
197
  };
198
+ /** Project identity returned by {@link HueClient.checkConnection}. */
80
199
  export interface ProjectConnection {
200
+ /** Project ID. */
81
201
  id: string;
202
+ /** Display name. */
82
203
  name: string;
204
+ /** Owning organization ID. */
83
205
  organizationId: string;
206
+ /** URL slug. */
84
207
  slug: string;
85
208
  }
209
+ /** Normalized fields a stored trace receipt can report as present. */
86
210
  export type TraceReceiptField = "input" | "output" | "model" | "usage" | "session";
211
+ /** Evidence that Hue stored a trace, returned by {@link HueClient.verifyTrace}. */
87
212
  export interface TraceReceipt {
213
+ /** The verified trace ID. */
88
214
  traceId: string;
215
+ /** Spans stored for the trace so far. */
89
216
  spanCount: number;
217
+ /** Storage revision; increases as more spans arrive. */
90
218
  revision: number;
91
219
  /** Presence of stored normalized fields; not a judgment of content correctness. */
92
220
  fields: Record<TraceReceiptField, boolean>;
221
+ /** Expected span IDs that are stored. */
93
222
  matchedSpanIds: string[];
223
+ /** Expected span IDs that are not stored yet. */
94
224
  missingSpanIds: string[];
225
+ /** Link to the trace in Hue, on the configured origin. */
95
226
  traceUrl: string;
96
227
  }
228
+ /** Options for {@link HueClient.verifyTrace}. */
97
229
  export interface VerifyTraceOptions {
230
+ /** Up to 100 span IDs that must be stored before the trace counts as verified. */
98
231
  expectedSpanIds?: string[];
232
+ /** Normalized fields that must be present before the trace counts as verified. */
99
233
  requiredFields?: TraceReceiptField[];
100
234
  /** Total request/retry budget, including response bodies. Default 10000; maximum 60000. */
101
235
  timeoutMillis?: number;
102
236
  }
237
+ /** Outcome of {@link HueClient.verifyTrace}. */
103
238
  export interface TraceVerification {
239
+ /** Every expected span and required field was stored within the budget. */
104
240
  verified: boolean;
241
+ /** Latest receipt observed, or `null` when the trace was never found. */
105
242
  receipt: TraceReceipt | null;
106
243
  }
107
- export {};
@@ -0,0 +1,2 @@
1
+ /** Package version shared by the instrumentation scope and the export User-Agent. */
2
+ export declare const sdkVersion = "0.2.1";
@@ -0,0 +1,3 @@
1
+ // Generated by scripts/write-version.mjs from package.json; do not edit by hand.
2
+ /** Package version shared by the instrumentation scope and the export User-Agent. */
3
+ export const sdkVersion = "0.2.1";
package/package.json CHANGED
@@ -1,48 +1,74 @@
1
1
  {
2
2
  "name": "@hue-run/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",
8
- "registry": "https://registry.npmjs.org/",
9
- "provenance": false
8
+ "registry": "https://registry.npmjs.org/"
10
9
  },
11
10
  "homepage": "https://docs.hue.run",
11
+ "bugs": {
12
+ "url": "https://github.com/hue-run/hue-sdk/issues"
13
+ },
12
14
  "repository": {
13
15
  "type": "git",
14
16
  "url": "git+https://github.com/hue-run/hue-sdk.git",
15
17
  "directory": "packages/sdk-typescript"
16
18
  },
17
19
  "description": "Hue OpenTelemetry helpers for Node.js agent applications",
20
+ "keywords": [
21
+ "opentelemetry",
22
+ "otlp",
23
+ "tracing",
24
+ "observability",
25
+ "llm",
26
+ "ai-agents",
27
+ "evaluation",
28
+ "vercel-ai-sdk"
29
+ ],
18
30
  "files": [
19
31
  "dist",
20
32
  "README.md",
21
33
  "EVALUATIONS.md",
34
+ "ENVIRONMENTS.md",
22
35
  "MANAGED_TARGETS.md",
23
36
  "LICENSE"
24
37
  ],
25
38
  "type": "module",
39
+ "sideEffects": [
40
+ "./dist/evals/schema-worker.js"
41
+ ],
26
42
  "exports": {
27
43
  ".": {
28
44
  "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js"
45
+ "import": "./dist/index.js",
46
+ "default": "./dist/index.js"
30
47
  },
31
48
  "./ai-sdk": {
32
49
  "types": "./dist/ai-sdk.d.ts",
33
- "import": "./dist/ai-sdk.js"
50
+ "import": "./dist/ai-sdk.js",
51
+ "default": "./dist/ai-sdk.js"
34
52
  },
35
53
  "./evals": {
36
54
  "types": "./dist/evals.d.ts",
37
- "import": "./dist/evals.js"
55
+ "import": "./dist/evals.js",
56
+ "default": "./dist/evals.js"
57
+ },
58
+ "./environment": {
59
+ "types": "./dist/environment.d.ts",
60
+ "import": "./dist/environment.js",
61
+ "default": "./dist/environment.js"
38
62
  },
39
63
  "./managed": {
40
64
  "types": "./dist/managed.d.ts",
41
- "import": "./dist/managed.js"
42
- }
65
+ "import": "./dist/managed.js",
66
+ "default": "./dist/managed.js"
67
+ },
68
+ "./package.json": "./package.json"
43
69
  },
44
70
  "scripts": {
45
- "build": "tsc -p tsconfig.build.json",
71
+ "build": "node scripts/write-version.mjs && tsc -p tsconfig.build.json",
46
72
  "typecheck": "tsc -p tsconfig.json --noEmit",
47
73
  "test": "bun test tests"
48
74
  },
@@ -53,22 +79,26 @@
53
79
  "@opentelemetry/otlp-transformer": "0.222.0",
54
80
  "@opentelemetry/resources": "2.11.0",
55
81
  "@opentelemetry/sdk-logs": "0.222.0",
56
- "@opentelemetry/sdk-trace": "2.11.0",
57
- "ajv": "8.20.0"
82
+ "@opentelemetry/sdk-trace": "2.11.0"
58
83
  },
59
84
  "devDependencies": {
60
85
  "@ai-sdk/otel": "1.0.99",
61
86
  "@opentelemetry/api": "1.9.1",
87
+ "@opentelemetry/context-async-hooks": "2.11.0",
62
88
  "@types/bun": "1.4.2",
63
- "@types/node": "24.10.1",
89
+ "@types/node": "26.5.1",
64
90
  "ai": "7.0.99",
91
+ "ajv": "8.20.0",
65
92
  "protobufjs": "8.8.0",
66
- "typescript": "7.0.2"
93
+ "typescript": "7.0.2",
94
+ "zod": "4.6.5"
67
95
  },
68
96
  "peerDependencies": {
69
97
  "@ai-sdk/otel": "^1.0.99",
70
98
  "@opentelemetry/api": "^1.9.1",
71
- "ai": "^6.0.0 || ^7.0.99"
99
+ "ai": "^6.0.0 || ^7.0.99",
100
+ "ajv": "^8.17.0",
101
+ "zod": "^4.6.5"
72
102
  },
73
103
  "peerDependenciesMeta": {
74
104
  "@ai-sdk/otel": {
@@ -76,9 +106,15 @@
76
106
  },
77
107
  "ai": {
78
108
  "optional": true
109
+ },
110
+ "ajv": {
111
+ "optional": true
112
+ },
113
+ "zod": {
114
+ "optional": true
79
115
  }
80
116
  },
81
117
  "engines": {
82
- "node": ">=24"
118
+ "node": ">=22.12"
83
119
  }
84
120
  }