@glassflow-ai/rius 0.1.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.
@@ -0,0 +1,156 @@
1
+ import { Tracer, Span } from '@opentelemetry/api';
2
+ import { SpanExporter } from '@opentelemetry/sdk-trace-base';
3
+
4
+ /** Redacts content attribute values at export. Receives the key when it accepts one. */
5
+ type Mask = (value: unknown, context?: {
6
+ key: string;
7
+ }) => unknown;
8
+ interface RiusOptions {
9
+ endpoint?: string;
10
+ apiKey?: string;
11
+ serviceName?: string;
12
+ disabled?: boolean;
13
+ sampleRate?: number;
14
+ captureContent?: boolean;
15
+ mask?: Mask;
16
+ }
17
+
18
+ interface InitOptions extends RiusOptions {
19
+ /** Inject an exporter instead of OTLP. The test seam; prefer this to mocking. */
20
+ spanExporter?: SpanExporter;
21
+ }
22
+ declare class RiusClient {
23
+ private readonly provider;
24
+ private readonly health?;
25
+ /** Resolves with the names of the auto-instrumentations that attached. */
26
+ readonly ready: Promise<string[]>;
27
+ private constructor();
28
+ /** Drains the queue. Resolves false if the most recent export failed. */
29
+ flush(): Promise<boolean>;
30
+ /**
31
+ * Drains and tears down the provider, then releases the global registration
32
+ * so a later init() can reconfigure the SDK.
33
+ */
34
+ shutdown(): Promise<void>;
35
+ }
36
+ declare function init(options?: InitOptions): RiusClient;
37
+ /** The SDK tracer. Scope name is wire-visible; do not parameterize it. */
38
+ declare function getTracer(): Tracer;
39
+
40
+ declare enum SpanKind {
41
+ AGENT = "AGENT",
42
+ LLM = "LLM",
43
+ TOOL = "TOOL",
44
+ RETRIEVER = "RETRIEVER",
45
+ EMBEDDING = "EMBEDDING",
46
+ CHAIN = "CHAIN"
47
+ }
48
+
49
+ interface SpanOptions {
50
+ kind?: SpanKind;
51
+ input?: unknown;
52
+ }
53
+ /** A handle over a span. Chainable setters; `end()` is idempotent. */
54
+ declare class Observation {
55
+ readonly span: Span;
56
+ protected ended: boolean;
57
+ constructor(span: Span);
58
+ setInput(value: unknown): this;
59
+ setOutput(value: unknown): this;
60
+ setAttribute(key: string, value: unknown): this;
61
+ /**
62
+ * Record an error on the span and set ERROR status. This is exactly what the
63
+ * `startAsCurrent*` helpers do on a thrown error, exposed so the manual
64
+ * `start*` path does not have to reach through `.span` to match it.
65
+ *
66
+ * Accepts `unknown` because that is what a `catch` binding is; a non-Error
67
+ * throwable is wrapped so `recordException` still gets a real Error.
68
+ */
69
+ recordException(error: unknown): this;
70
+ end(): void;
71
+ /** Lets callers write `using obs = startSpan(...)`. Sugar over end(). */
72
+ [Symbol.dispose](): void;
73
+ }
74
+ /**
75
+ * Create a span and return a handle. You MUST call end() (or use `using`).
76
+ * The span is parented to whatever is current but does NOT become current.
77
+ */
78
+ declare function startSpan(name: string, options?: SpanOptions): Observation;
79
+ /** The body of a scoped span. */
80
+ type SpanBody<T> = (observation: Observation) => Promise<T> | T;
81
+ /**
82
+ * Run `fn` with a new span active, so spans created inside it nest under this
83
+ * one across async boundaries. Auto-ends, records exceptions, rethrows.
84
+ *
85
+ * `options` is optional, so the common case is `startAsCurrentSpan(name, fn)`
86
+ * rather than `startAsCurrentSpan(name, {}, fn)`. The callback stays last.
87
+ */
88
+ declare function startAsCurrentSpan<T>(name: string, fn: SpanBody<T>): Promise<T>;
89
+ declare function startAsCurrentSpan<T>(name: string, options: SpanOptions, fn: SpanBody<T>): Promise<T>;
90
+
91
+ interface GenerationOptions {
92
+ model?: string;
93
+ provider?: string;
94
+ input?: unknown;
95
+ /**
96
+ * Request parameters, each recorded as `gen_ai.request.<key>` — for example
97
+ * `{ temperature: 0.2, max_tokens: 512 }`. Keys are passed through verbatim,
98
+ * so use the provider's own parameter names.
99
+ */
100
+ modelParameters?: Record<string, unknown>;
101
+ }
102
+ /** An LLM call. Content uses gen_ai message keys, never input.value. */
103
+ declare class Generation extends Observation {
104
+ private firstTokenRecorded;
105
+ setInput(value: unknown): this;
106
+ setOutput(value: unknown): this;
107
+ setModel(model: string): this;
108
+ setUsage(usage: {
109
+ inputTokens?: number;
110
+ outputTokens?: number;
111
+ }): this;
112
+ /**
113
+ * Why generation stopped (`gen_ai.response.finish_reasons`), e.g. `"stop"`,
114
+ * `"length"`, `"tool_calls"`. The convention is a list; a single reason is
115
+ * wrapped so callers do not have to.
116
+ */
117
+ setFinishReasons(reasons: string | string[]): this;
118
+ /**
119
+ * The TTFT anchor: event time minus span start. Idempotent: only the
120
+ * first call records the event, so a streaming loop can call this
121
+ * unconditionally on every chunk without inflating the span. A no-op
122
+ * after the span has ended.
123
+ */
124
+ recordFirstToken(): this;
125
+ }
126
+ /** Create a generation span and return a handle. You MUST call end(). */
127
+ declare function startGeneration(name: string, options?: GenerationOptions): Generation;
128
+ /** The body of a scoped generation. */
129
+ type GenerationBody<T> = (generation: Generation) => Promise<T> | T;
130
+ /**
131
+ * Run `fn` with a generation span active. Auto-ends, records exceptions.
132
+ *
133
+ * `options` is optional, so `startAsCurrentGeneration(name, fn)` works without
134
+ * an empty object. The callback stays last.
135
+ */
136
+ declare function startAsCurrentGeneration<T>(name: string, fn: GenerationBody<T>): Promise<T>;
137
+ declare function startAsCurrentGeneration<T>(name: string, options: GenerationOptions, fn: GenerationBody<T>): Promise<T>;
138
+
139
+ interface ObserveOptions {
140
+ name?: string;
141
+ kind?: SpanKind;
142
+ captureInput?: boolean;
143
+ captureOutput?: boolean;
144
+ }
145
+ /**
146
+ * Wrap a function so each call becomes a span. Returns a function with the
147
+ * same signature, so call sites and types are unchanged.
148
+ *
149
+ * A wrapper rather than a decorator on purpose: TypeScript decorators apply
150
+ * only to class members, and most agent code is plain functions.
151
+ */
152
+ declare function observe<F extends (...args: never[]) => unknown>(fn: F, options?: ObserveOptions): (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;
153
+
154
+ declare const VERSION = "0.1.0";
155
+
156
+ export { Generation, type GenerationBody, type GenerationOptions, type InitOptions, type Mask, Observation, type ObserveOptions, RiusClient, type RiusOptions, type SpanBody, SpanKind, type SpanOptions, VERSION, getTracer, init, observe, startAsCurrentGeneration, startAsCurrentSpan, startGeneration, startSpan };
@@ -0,0 +1,156 @@
1
+ import { Tracer, Span } from '@opentelemetry/api';
2
+ import { SpanExporter } from '@opentelemetry/sdk-trace-base';
3
+
4
+ /** Redacts content attribute values at export. Receives the key when it accepts one. */
5
+ type Mask = (value: unknown, context?: {
6
+ key: string;
7
+ }) => unknown;
8
+ interface RiusOptions {
9
+ endpoint?: string;
10
+ apiKey?: string;
11
+ serviceName?: string;
12
+ disabled?: boolean;
13
+ sampleRate?: number;
14
+ captureContent?: boolean;
15
+ mask?: Mask;
16
+ }
17
+
18
+ interface InitOptions extends RiusOptions {
19
+ /** Inject an exporter instead of OTLP. The test seam; prefer this to mocking. */
20
+ spanExporter?: SpanExporter;
21
+ }
22
+ declare class RiusClient {
23
+ private readonly provider;
24
+ private readonly health?;
25
+ /** Resolves with the names of the auto-instrumentations that attached. */
26
+ readonly ready: Promise<string[]>;
27
+ private constructor();
28
+ /** Drains the queue. Resolves false if the most recent export failed. */
29
+ flush(): Promise<boolean>;
30
+ /**
31
+ * Drains and tears down the provider, then releases the global registration
32
+ * so a later init() can reconfigure the SDK.
33
+ */
34
+ shutdown(): Promise<void>;
35
+ }
36
+ declare function init(options?: InitOptions): RiusClient;
37
+ /** The SDK tracer. Scope name is wire-visible; do not parameterize it. */
38
+ declare function getTracer(): Tracer;
39
+
40
+ declare enum SpanKind {
41
+ AGENT = "AGENT",
42
+ LLM = "LLM",
43
+ TOOL = "TOOL",
44
+ RETRIEVER = "RETRIEVER",
45
+ EMBEDDING = "EMBEDDING",
46
+ CHAIN = "CHAIN"
47
+ }
48
+
49
+ interface SpanOptions {
50
+ kind?: SpanKind;
51
+ input?: unknown;
52
+ }
53
+ /** A handle over a span. Chainable setters; `end()` is idempotent. */
54
+ declare class Observation {
55
+ readonly span: Span;
56
+ protected ended: boolean;
57
+ constructor(span: Span);
58
+ setInput(value: unknown): this;
59
+ setOutput(value: unknown): this;
60
+ setAttribute(key: string, value: unknown): this;
61
+ /**
62
+ * Record an error on the span and set ERROR status. This is exactly what the
63
+ * `startAsCurrent*` helpers do on a thrown error, exposed so the manual
64
+ * `start*` path does not have to reach through `.span` to match it.
65
+ *
66
+ * Accepts `unknown` because that is what a `catch` binding is; a non-Error
67
+ * throwable is wrapped so `recordException` still gets a real Error.
68
+ */
69
+ recordException(error: unknown): this;
70
+ end(): void;
71
+ /** Lets callers write `using obs = startSpan(...)`. Sugar over end(). */
72
+ [Symbol.dispose](): void;
73
+ }
74
+ /**
75
+ * Create a span and return a handle. You MUST call end() (or use `using`).
76
+ * The span is parented to whatever is current but does NOT become current.
77
+ */
78
+ declare function startSpan(name: string, options?: SpanOptions): Observation;
79
+ /** The body of a scoped span. */
80
+ type SpanBody<T> = (observation: Observation) => Promise<T> | T;
81
+ /**
82
+ * Run `fn` with a new span active, so spans created inside it nest under this
83
+ * one across async boundaries. Auto-ends, records exceptions, rethrows.
84
+ *
85
+ * `options` is optional, so the common case is `startAsCurrentSpan(name, fn)`
86
+ * rather than `startAsCurrentSpan(name, {}, fn)`. The callback stays last.
87
+ */
88
+ declare function startAsCurrentSpan<T>(name: string, fn: SpanBody<T>): Promise<T>;
89
+ declare function startAsCurrentSpan<T>(name: string, options: SpanOptions, fn: SpanBody<T>): Promise<T>;
90
+
91
+ interface GenerationOptions {
92
+ model?: string;
93
+ provider?: string;
94
+ input?: unknown;
95
+ /**
96
+ * Request parameters, each recorded as `gen_ai.request.<key>` — for example
97
+ * `{ temperature: 0.2, max_tokens: 512 }`. Keys are passed through verbatim,
98
+ * so use the provider's own parameter names.
99
+ */
100
+ modelParameters?: Record<string, unknown>;
101
+ }
102
+ /** An LLM call. Content uses gen_ai message keys, never input.value. */
103
+ declare class Generation extends Observation {
104
+ private firstTokenRecorded;
105
+ setInput(value: unknown): this;
106
+ setOutput(value: unknown): this;
107
+ setModel(model: string): this;
108
+ setUsage(usage: {
109
+ inputTokens?: number;
110
+ outputTokens?: number;
111
+ }): this;
112
+ /**
113
+ * Why generation stopped (`gen_ai.response.finish_reasons`), e.g. `"stop"`,
114
+ * `"length"`, `"tool_calls"`. The convention is a list; a single reason is
115
+ * wrapped so callers do not have to.
116
+ */
117
+ setFinishReasons(reasons: string | string[]): this;
118
+ /**
119
+ * The TTFT anchor: event time minus span start. Idempotent: only the
120
+ * first call records the event, so a streaming loop can call this
121
+ * unconditionally on every chunk without inflating the span. A no-op
122
+ * after the span has ended.
123
+ */
124
+ recordFirstToken(): this;
125
+ }
126
+ /** Create a generation span and return a handle. You MUST call end(). */
127
+ declare function startGeneration(name: string, options?: GenerationOptions): Generation;
128
+ /** The body of a scoped generation. */
129
+ type GenerationBody<T> = (generation: Generation) => Promise<T> | T;
130
+ /**
131
+ * Run `fn` with a generation span active. Auto-ends, records exceptions.
132
+ *
133
+ * `options` is optional, so `startAsCurrentGeneration(name, fn)` works without
134
+ * an empty object. The callback stays last.
135
+ */
136
+ declare function startAsCurrentGeneration<T>(name: string, fn: GenerationBody<T>): Promise<T>;
137
+ declare function startAsCurrentGeneration<T>(name: string, options: GenerationOptions, fn: GenerationBody<T>): Promise<T>;
138
+
139
+ interface ObserveOptions {
140
+ name?: string;
141
+ kind?: SpanKind;
142
+ captureInput?: boolean;
143
+ captureOutput?: boolean;
144
+ }
145
+ /**
146
+ * Wrap a function so each call becomes a span. Returns a function with the
147
+ * same signature, so call sites and types are unchanged.
148
+ *
149
+ * A wrapper rather than a decorator on purpose: TypeScript decorators apply
150
+ * only to class members, and most agent code is plain functions.
151
+ */
152
+ declare function observe<F extends (...args: never[]) => unknown>(fn: F, options?: ObserveOptions): (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;
153
+
154
+ declare const VERSION = "0.1.0";
155
+
156
+ export { Generation, type GenerationBody, type GenerationOptions, type InitOptions, type Mask, Observation, type ObserveOptions, RiusClient, type RiusOptions, type SpanBody, SpanKind, type SpanOptions, VERSION, getTracer, init, observe, startAsCurrentGeneration, startAsCurrentSpan, startGeneration, startSpan };