@vinhnt-sdk/trace 0.4.2 → 0.11.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/LICENSE +21 -21
- package/README.md +200 -0
- package/dist/gen-ai-attributes.d.ts +99 -0
- package/dist/gen-ai-attributes.d.ts.map +1 -0
- package/dist/gen-ai-attributes.js +126 -0
- package/dist/gen-ai-attributes.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/otlp-exporter.d.ts +141 -0
- package/dist/otlp-exporter.d.ts.map +1 -0
- package/dist/otlp-exporter.js +238 -0
- package/dist/otlp-exporter.js.map +1 -0
- package/dist/telemetry.d.ts +27 -0
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +15 -0
- package/dist/telemetry.js.map +1 -1
- package/dist/timeline.d.ts +26 -3
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +33 -14
- package/dist/timeline.js.map +1 -1
- package/dist/tracing.d.ts +6 -3
- package/dist/tracing.d.ts.map +1 -1
- package/dist/tracing.js +8 -5
- package/dist/tracing.js.map +1 -1
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Nguyen Thanh Vinh
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nguyen Thanh Vinh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# @vinhnt-sdk/trace
|
|
2
|
+
|
|
3
|
+
> Status: STABLE
|
|
4
|
+
|
|
5
|
+
Observability for vinhnt-sdk — OpenTelemetry-compatible spans, timeline replay, telemetry aggregation, and cost tracking.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
`ash
|
|
10
|
+
# npm
|
|
11
|
+
npm install @vinhnt-sdk/trace
|
|
12
|
+
|
|
13
|
+
# pnpm (monorepo)
|
|
14
|
+
pnpm add @vinhnt-sdk/trace
|
|
15
|
+
`
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **SpanRecorder** — Record and query OpenTelemetry-compatible spans
|
|
20
|
+
- **GenAI semconv** — OTel `gen_ai.*` attribute keys + builders for chat/tool/agent spans (ADK profile)
|
|
21
|
+
- **Timeline** — Build transcripts from run events for replay
|
|
22
|
+
- **CostMeter** — Track token usage and calculate costs per model
|
|
23
|
+
- **ContextPressure** — Monitor context window utilization
|
|
24
|
+
- **TelemetryProvider** — Interface for custom telemetry backends
|
|
25
|
+
- **OTLP exporter** — `createOtlpSpanExporter` ships spans to any OTLP/HTTP collector (optional)
|
|
26
|
+
- **DEFAULT_MODEL_PRICING** — Built-in pricing for common models
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
` ypescript
|
|
31
|
+
import {
|
|
32
|
+
SpanRecorder,
|
|
33
|
+
CostMeter, calculateCost, DEFAULT_MODEL_PRICING,
|
|
34
|
+
Timeline, buildTranscript,
|
|
35
|
+
} from "@vinhnt-sdk/trace";
|
|
36
|
+
|
|
37
|
+
// Create and record spans
|
|
38
|
+
const recorder = new SpanRecorder();
|
|
39
|
+
const span = recorder.startSpan("llm-call", "client");
|
|
40
|
+
|
|
41
|
+
// ... do work ...
|
|
42
|
+
|
|
43
|
+
recorder.endSpan(span, "ok");
|
|
44
|
+
|
|
45
|
+
// Calculate costs
|
|
46
|
+
const meter = new CostMeter();
|
|
47
|
+
meter.record({
|
|
48
|
+
inputTokens: 1000,
|
|
49
|
+
outputTokens: 500,
|
|
50
|
+
model: "gpt-4o",
|
|
51
|
+
});
|
|
52
|
+
console.log(meter.totalCost); // Cost in USD
|
|
53
|
+
|
|
54
|
+
// Build transcript from events
|
|
55
|
+
const transcript = buildTranscript(events);
|
|
56
|
+
console.log(transcript);
|
|
57
|
+
`
|
|
58
|
+
|
|
59
|
+
## API Reference
|
|
60
|
+
|
|
61
|
+
### Tracing
|
|
62
|
+
|
|
63
|
+
| Export | Type | Description |
|
|
64
|
+
|--------|------|-------------|
|
|
65
|
+
| SpanRecorder | Class | Record and query spans |
|
|
66
|
+
| createSpan | Function | Create a new span |
|
|
67
|
+
| endSpan | Function | End a span with status |
|
|
68
|
+
| ddSpanEvent | Function | Add an event to a span |
|
|
69
|
+
| generateTraceId | Function | Generate a unique trace ID |
|
|
70
|
+
|
|
71
|
+
### Span Types
|
|
72
|
+
|
|
73
|
+
| Export | Type | Description |
|
|
74
|
+
|--------|------|-------------|
|
|
75
|
+
| Span | Interface | A single trace span |
|
|
76
|
+
| SpanKind | Type | Span type (client, server, internal) |
|
|
77
|
+
| SpanStatus | Type | Span completion status |
|
|
78
|
+
| SpanEvent | Interface | Event within a span |
|
|
79
|
+
| SpanNode | Interface | Span tree node |
|
|
80
|
+
| TraceContext | Interface | Trace propagation context |
|
|
81
|
+
|
|
82
|
+
### Timeline
|
|
83
|
+
|
|
84
|
+
| Export | Type | Description |
|
|
85
|
+
|--------|------|-------------|
|
|
86
|
+
| Timeline | Class | Build and query run timelines |
|
|
87
|
+
| uildTranscript | Function | Build transcript from events |
|
|
88
|
+
| TimelineEvent | Interface | Event in a timeline |
|
|
89
|
+
| TranscriptEntry | Interface | Transcript line item |
|
|
90
|
+
|
|
91
|
+
### Telemetry
|
|
92
|
+
|
|
93
|
+
| Export | Type | Description |
|
|
94
|
+
|--------|------|-------------|
|
|
95
|
+
| CostMeter | Class | Track token costs |
|
|
96
|
+
| calculateCost | Function | Calculate cost from tokens |
|
|
97
|
+
| calculateContextPressure | Function | Calculate context utilization |
|
|
98
|
+
| DEFAULT_MODEL_PRICING | Constant | Default pricing for common models |
|
|
99
|
+
| ConsoleTelemetryProvider | Class | Console-based telemetry output |
|
|
100
|
+
|
|
101
|
+
### Telemetry Types
|
|
102
|
+
|
|
103
|
+
| Export | Type | Description |
|
|
104
|
+
|--------|------|-------------|
|
|
105
|
+
| UsageStats | Interface | Token usage statistics |
|
|
106
|
+
| ModelPricing | Interface | Per-1M-token pricing |
|
|
107
|
+
| ContextPressure | Interface | Context window utilization |
|
|
108
|
+
| TelemetryProvider | Interface | Custom telemetry backend |
|
|
109
|
+
|
|
110
|
+
### OTLP Export (P1-9)
|
|
111
|
+
|
|
112
|
+
| Export | Type | Description |
|
|
113
|
+
|--------|------|-------------|
|
|
114
|
+
| createOtlpSpanExporter | Function | OTLP/HTTP JSON exporter (config or env endpoint) |
|
|
115
|
+
| resolveOtlpEndpoint | Function | Resolve endpoint from config / `OTEL_EXPORTER_OTLP_*` |
|
|
116
|
+
| mapSpanToOtlp | Function | Map custom `Span` → OTLP JSON span |
|
|
117
|
+
| buildOtlpExportRequest | Function | Wrap spans into `ExportTraceServiceRequest` |
|
|
118
|
+
| SpanExporter | Interface | `export(spans)` / `shutdown()` seam |
|
|
119
|
+
|
|
120
|
+
Endpoint resolution (first match wins):
|
|
121
|
+
|
|
122
|
+
1. `config.endpoint`
|
|
123
|
+
2. `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
|
|
124
|
+
3. `OTEL_EXPORTER_OTLP_ENDPOINT` + `/v1/traces`
|
|
125
|
+
|
|
126
|
+
Headers: `OTEL_EXPORTER_OTLP_HEADERS` (`k1=v1,k2=v2`) merged with `config.headers`.
|
|
127
|
+
Resource: `config.resourceAttributes` (default `service.name=vinhnt-sdk`, override via `OTEL_SERVICE_NAME` in attributes).
|
|
128
|
+
|
|
129
|
+
### GenAI Semconv (G3.1)
|
|
130
|
+
|
|
131
|
+
| Export | Type | Description |
|
|
132
|
+
|--------|------|-------------|
|
|
133
|
+
| GEN_AI_OPERATIONS | Constant | Operation names: `chat`, `text_completion`, `embeddings`, `invoke_agent`, `execute_tool`, `retrieve`, `invoke_workflow` |
|
|
134
|
+
| GenAiOperation | Type | Union of operation names (autocomplete + extensible) |
|
|
135
|
+
| GEN_AI_* | Constants | OTel `gen_ai.*` attribute keys (request/response/usage/tool/content) |
|
|
136
|
+
| genAiChatRequestAttributes | Function | Request-side attrs (`operation.name`, `provider.name`, `request.model`) |
|
|
137
|
+
| genAiResponseAttributes | Function | Served model + `response.finish_reasons` |
|
|
138
|
+
| genAiUsageAttributes | Function | `usage.input_tokens` / `output_tokens` / `reasoning_tokens` |
|
|
139
|
+
| genAiContentAttributes | Function | Opt-in message attrs — `contentMode: "full"` only (default `no_content`) |
|
|
140
|
+
| genAiToolAttributes | Function | `execute_tool` span attrs (`gen_ai.tool.name` / `tool.call.id`) |
|
|
141
|
+
| genAiInvokeAgentAttributes | Function | Root `invoke_agent` span attrs |
|
|
142
|
+
|
|
143
|
+
Content capture is privacy-gated: without `contentMode: "full"` the builders
|
|
144
|
+
return `{}` — metadata only. Custom attributes use the `vnt.` namespace.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { createOtlpSpanExporter, SpanRecorder } from "@vinhnt-sdk/trace";
|
|
148
|
+
|
|
149
|
+
const recorder = new SpanRecorder();
|
|
150
|
+
// ... record spans ...
|
|
151
|
+
|
|
152
|
+
const exporter = createOtlpSpanExporter({
|
|
153
|
+
endpoint: "http://localhost:4318/v1/traces", // or set env only
|
|
154
|
+
resourceAttributes: { "service.name": "my-agent", "deployment.environment": "dev" },
|
|
155
|
+
});
|
|
156
|
+
await exporter.export(recorder.getSpans());
|
|
157
|
+
await exporter.shutdown();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
No exporter is created unless you call `createOtlpSpanExporter` — default telemetry path unchanged.
|
|
161
|
+
|
|
162
|
+
## Usage Examples
|
|
163
|
+
|
|
164
|
+
### Cost Tracking
|
|
165
|
+
|
|
166
|
+
` ypescript
|
|
167
|
+
import { CostMeter, DEFAULT_MODEL_PRICING } from "@vinhnt-sdk/trace";
|
|
168
|
+
|
|
169
|
+
const meter = new CostMeter();
|
|
170
|
+
|
|
171
|
+
// Track usage across multiple calls
|
|
172
|
+
meter.record({ inputTokens: 1000, outputTokens: 500, model: "gpt-4o" });
|
|
173
|
+
meter.record({ inputTokens: 2000, outputTokens: 1000, model: "gpt-4o-mini" });
|
|
174
|
+
|
|
175
|
+
console.log(meter.totalCost); // Total cost in USD
|
|
176
|
+
`
|
|
177
|
+
|
|
178
|
+
### Custom Telemetry Provider
|
|
179
|
+
|
|
180
|
+
` ypescript
|
|
181
|
+
import type { TelemetryProvider } from "@vinhnt-sdk/trace";
|
|
182
|
+
|
|
183
|
+
const customProvider: TelemetryProvider = {
|
|
184
|
+
name: "datadog",
|
|
185
|
+
async recordSpan(span) {
|
|
186
|
+
await sendToDatadog(span);
|
|
187
|
+
},
|
|
188
|
+
async recordUsage(usage) {
|
|
189
|
+
await sendMetricsToDatadog(usage);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
`
|
|
193
|
+
|
|
194
|
+
## Dependencies
|
|
195
|
+
|
|
196
|
+
- @vinhnt-sdk/schema >=0.5.0
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
MIT
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenAI semantic-convention attribute layer — OTel `gen_ai.*` attributes
|
|
3
|
+
* (ADK profile; research: .agents/research/ai-observability-research.md).
|
|
4
|
+
*
|
|
5
|
+
* Pure constants + tiny builders — zero runtime deps. Spans stay plain
|
|
6
|
+
* `Span` objects (see ./tracing.ts); this module only supplies the standard
|
|
7
|
+
* attribute keys/values so every producer agrees on names.
|
|
8
|
+
*
|
|
9
|
+
* Privacy: content capture is OPT-IN (`contentMode: "full"`). The default
|
|
10
|
+
* `no_content` tier records metadata only (research "Privacy Tiers" #1).
|
|
11
|
+
*/
|
|
12
|
+
/** Attribute keys — core set (research table "Core Attributes"). */
|
|
13
|
+
export declare const GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
14
|
+
export declare const GEN_AI_PROVIDER_NAME = "gen_ai.provider.name";
|
|
15
|
+
export declare const GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
|
|
16
|
+
export declare const GEN_AI_RESPONSE_MODEL = "gen_ai.response.model";
|
|
17
|
+
export declare const GEN_AI_USAGE_INPUT_TOKENS = "gen_ai.usage.input_tokens";
|
|
18
|
+
export declare const GEN_AI_USAGE_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
|
|
19
|
+
export declare const GEN_AI_USAGE_REASONING_TOKENS = "gen_ai.usage.reasoning_tokens";
|
|
20
|
+
export declare const GEN_AI_RESPONSE_FINISH_REASONS = "gen_ai.response.finish_reasons";
|
|
21
|
+
export declare const GEN_AI_CONVERSATION_ID = "gen_ai.conversation.id";
|
|
22
|
+
/** Attribute keys — tool calls (gen_ai.tool.* span attributes). */
|
|
23
|
+
export declare const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
24
|
+
export declare const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
|
|
25
|
+
/** Attribute keys — opt-in content capture (`contentMode: "full"` only). */
|
|
26
|
+
export declare const GEN_AI_INPUT_MESSAGES = "gen_ai.input.messages";
|
|
27
|
+
export declare const GEN_AI_OUTPUT_MESSAGES = "gen_ai.output.messages";
|
|
28
|
+
/**
|
|
29
|
+
* Operation names — research "Agent Spans (5 types)" ∪ core-attributes
|
|
30
|
+
* operations (`chat`, `text_completion`, `embeddings`).
|
|
31
|
+
*/
|
|
32
|
+
export declare const GEN_AI_OPERATIONS: {
|
|
33
|
+
readonly chat: "chat";
|
|
34
|
+
readonly textCompletion: "text_completion";
|
|
35
|
+
readonly embeddings: "embeddings";
|
|
36
|
+
readonly invokeAgent: "invoke_agent";
|
|
37
|
+
readonly executeTool: "execute_tool";
|
|
38
|
+
readonly retrieve: "retrieve";
|
|
39
|
+
readonly invokeWorkflow: "invoke_workflow";
|
|
40
|
+
};
|
|
41
|
+
export type GenAiOperation = (typeof GEN_AI_OPERATIONS)[keyof typeof GEN_AI_OPERATIONS];
|
|
42
|
+
/**
|
|
43
|
+
* Content capture tier — research privacy tiers #1 (default) and #4.
|
|
44
|
+
* `metadata_only`/`redacted` belong to the PromptLogger work (out of scope).
|
|
45
|
+
*/
|
|
46
|
+
export type GenAiContentMode = "no_content" | "full";
|
|
47
|
+
/** Default cap for opt-in content attributes (chars). */
|
|
48
|
+
export declare const DEFAULT_GEN_AI_MAX_CONTENT_LENGTH = 4096;
|
|
49
|
+
/** Custom (non-semconv) attribute keys used by the SDK — `vnt.` namespace. */
|
|
50
|
+
export declare const VNT_TRACE_CONTENT_TRUNCATED = "vnt.trace.content_truncated";
|
|
51
|
+
/** Structural usage subset of `ModelUsage` (kept dependency-free). */
|
|
52
|
+
export interface GenAiUsage {
|
|
53
|
+
readonly promptTokens?: number | undefined;
|
|
54
|
+
readonly completionTokens?: number | undefined;
|
|
55
|
+
readonly reasoningTokens?: number | undefined;
|
|
56
|
+
}
|
|
57
|
+
export interface GenAiContentOptions {
|
|
58
|
+
/** `no_content` (default) → content attributes are omitted entirely. */
|
|
59
|
+
readonly contentMode?: GenAiContentMode | undefined;
|
|
60
|
+
/** Truncation cap for content attributes. Default 4096 chars. */
|
|
61
|
+
readonly maxContentLength?: number | undefined;
|
|
62
|
+
}
|
|
63
|
+
/** Conversation grouping attribute (emitted only when a session id exists). */
|
|
64
|
+
export declare function genAiConversationAttributes(conversationId?: string | undefined): Record<string, unknown>;
|
|
65
|
+
/** Attributes for the start of a chat/completion request. */
|
|
66
|
+
export declare function genAiChatRequestAttributes(params: {
|
|
67
|
+
readonly provider: string;
|
|
68
|
+
readonly model: string;
|
|
69
|
+
readonly conversationId?: string | undefined;
|
|
70
|
+
}): Record<string, unknown>;
|
|
71
|
+
/** Response-side attributes: served model + finish reasons. Omits unset fields. */
|
|
72
|
+
export declare function genAiResponseAttributes(params: {
|
|
73
|
+
readonly model?: string | undefined;
|
|
74
|
+
readonly finishReason?: string | undefined;
|
|
75
|
+
}): Record<string, unknown>;
|
|
76
|
+
/** Token usage attributes — ints, only the fields actually present. */
|
|
77
|
+
export declare function genAiUsageAttributes(usage?: GenAiUsage | undefined): Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Opt-in content attributes — `no_content` (default) returns `{}`.
|
|
80
|
+
* `full` emits `gen_ai.input.messages` / `gen_ai.output.messages` as
|
|
81
|
+
* (possibly truncated) JSON strings + a `vnt.trace.content_truncated` flag.
|
|
82
|
+
*/
|
|
83
|
+
export declare function genAiContentAttributes(params: {
|
|
84
|
+
/** Serialized conversation (request side), ready for JSON encoding. */
|
|
85
|
+
readonly inputJson?: string | undefined;
|
|
86
|
+
/** Serialized assistant output (response side). */
|
|
87
|
+
readonly outputJson?: string | undefined;
|
|
88
|
+
}, options?: GenAiContentOptions | undefined): Record<string, unknown>;
|
|
89
|
+
/** Attributes for an `execute_tool` span. */
|
|
90
|
+
export declare function genAiToolAttributes(params: {
|
|
91
|
+
readonly toolName: string;
|
|
92
|
+
readonly toolCallId?: string | undefined;
|
|
93
|
+
readonly conversationId?: string | undefined;
|
|
94
|
+
}): Record<string, unknown>;
|
|
95
|
+
/** Attributes for a top-level `invoke_agent` span. */
|
|
96
|
+
export declare function genAiInvokeAgentAttributes(params: {
|
|
97
|
+
readonly conversationId?: string | undefined;
|
|
98
|
+
}): Record<string, unknown>;
|
|
99
|
+
//# sourceMappingURL=gen-ai-attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gen-ai-attributes.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AE,OAAO,CAAC,CAiBzB;AAED,6CAA6C;AAC7C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9C,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAO1B;AAED,sDAAsD;AACtD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9C,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAK1B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenAI semantic-convention attribute layer — OTel `gen_ai.*` attributes
|
|
3
|
+
* (ADK profile; research: .agents/research/ai-observability-research.md).
|
|
4
|
+
*
|
|
5
|
+
* Pure constants + tiny builders — zero runtime deps. Spans stay plain
|
|
6
|
+
* `Span` objects (see ./tracing.ts); this module only supplies the standard
|
|
7
|
+
* attribute keys/values so every producer agrees on names.
|
|
8
|
+
*
|
|
9
|
+
* Privacy: content capture is OPT-IN (`contentMode: "full"`). The default
|
|
10
|
+
* `no_content` tier records metadata only (research "Privacy Tiers" #1).
|
|
11
|
+
*/
|
|
12
|
+
/** Attribute keys — core set (research table "Core Attributes"). */
|
|
13
|
+
export const GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
14
|
+
export const GEN_AI_PROVIDER_NAME = "gen_ai.provider.name";
|
|
15
|
+
export const GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
|
|
16
|
+
export const GEN_AI_RESPONSE_MODEL = "gen_ai.response.model";
|
|
17
|
+
export const GEN_AI_USAGE_INPUT_TOKENS = "gen_ai.usage.input_tokens";
|
|
18
|
+
export const GEN_AI_USAGE_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
|
|
19
|
+
export const GEN_AI_USAGE_REASONING_TOKENS = "gen_ai.usage.reasoning_tokens";
|
|
20
|
+
export const GEN_AI_RESPONSE_FINISH_REASONS = "gen_ai.response.finish_reasons";
|
|
21
|
+
export const GEN_AI_CONVERSATION_ID = "gen_ai.conversation.id";
|
|
22
|
+
/** Attribute keys — tool calls (gen_ai.tool.* span attributes). */
|
|
23
|
+
export const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
24
|
+
export const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
|
|
25
|
+
/** Attribute keys — opt-in content capture (`contentMode: "full"` only). */
|
|
26
|
+
export const GEN_AI_INPUT_MESSAGES = "gen_ai.input.messages";
|
|
27
|
+
export const GEN_AI_OUTPUT_MESSAGES = "gen_ai.output.messages";
|
|
28
|
+
/**
|
|
29
|
+
* Operation names — research "Agent Spans (5 types)" ∪ core-attributes
|
|
30
|
+
* operations (`chat`, `text_completion`, `embeddings`).
|
|
31
|
+
*/
|
|
32
|
+
export const GEN_AI_OPERATIONS = {
|
|
33
|
+
chat: "chat",
|
|
34
|
+
textCompletion: "text_completion",
|
|
35
|
+
embeddings: "embeddings",
|
|
36
|
+
invokeAgent: "invoke_agent",
|
|
37
|
+
executeTool: "execute_tool",
|
|
38
|
+
retrieve: "retrieve",
|
|
39
|
+
invokeWorkflow: "invoke_workflow",
|
|
40
|
+
};
|
|
41
|
+
/** Default cap for opt-in content attributes (chars). */
|
|
42
|
+
export const DEFAULT_GEN_AI_MAX_CONTENT_LENGTH = 4_096;
|
|
43
|
+
/** Custom (non-semconv) attribute keys used by the SDK — `vnt.` namespace. */
|
|
44
|
+
export const VNT_TRACE_CONTENT_TRUNCATED = "vnt.trace.content_truncated";
|
|
45
|
+
/** Conversation grouping attribute (emitted only when a session id exists). */
|
|
46
|
+
export function genAiConversationAttributes(conversationId) {
|
|
47
|
+
return conversationId ? { [GEN_AI_CONVERSATION_ID]: conversationId } : {};
|
|
48
|
+
}
|
|
49
|
+
/** Attributes for the start of a chat/completion request. */
|
|
50
|
+
export function genAiChatRequestAttributes(params) {
|
|
51
|
+
return {
|
|
52
|
+
[GEN_AI_OPERATION_NAME]: GEN_AI_OPERATIONS.chat,
|
|
53
|
+
[GEN_AI_PROVIDER_NAME]: params.provider,
|
|
54
|
+
[GEN_AI_REQUEST_MODEL]: params.model,
|
|
55
|
+
...genAiConversationAttributes(params.conversationId),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Response-side attributes: served model + finish reasons. Omits unset fields. */
|
|
59
|
+
export function genAiResponseAttributes(params) {
|
|
60
|
+
const attrs = {};
|
|
61
|
+
if (params.model)
|
|
62
|
+
attrs[GEN_AI_RESPONSE_MODEL] = params.model;
|
|
63
|
+
if (params.finishReason)
|
|
64
|
+
attrs[GEN_AI_RESPONSE_FINISH_REASONS] = [params.finishReason];
|
|
65
|
+
return attrs;
|
|
66
|
+
}
|
|
67
|
+
/** Token usage attributes — ints, only the fields actually present. */
|
|
68
|
+
export function genAiUsageAttributes(usage) {
|
|
69
|
+
if (!usage)
|
|
70
|
+
return {};
|
|
71
|
+
const attrs = {};
|
|
72
|
+
if (typeof usage.promptTokens === "number")
|
|
73
|
+
attrs[GEN_AI_USAGE_INPUT_TOKENS] = usage.promptTokens;
|
|
74
|
+
if (typeof usage.completionTokens === "number")
|
|
75
|
+
attrs[GEN_AI_USAGE_OUTPUT_TOKENS] = usage.completionTokens;
|
|
76
|
+
if (typeof usage.reasoningTokens === "number")
|
|
77
|
+
attrs[GEN_AI_USAGE_REASONING_TOKENS] = usage.reasoningTokens;
|
|
78
|
+
return attrs;
|
|
79
|
+
}
|
|
80
|
+
function truncateContent(value, maxLength) {
|
|
81
|
+
if (value.length <= maxLength)
|
|
82
|
+
return { text: value, truncated: false };
|
|
83
|
+
return { text: value.slice(0, maxLength), truncated: true };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Opt-in content attributes — `no_content` (default) returns `{}`.
|
|
87
|
+
* `full` emits `gen_ai.input.messages` / `gen_ai.output.messages` as
|
|
88
|
+
* (possibly truncated) JSON strings + a `vnt.trace.content_truncated` flag.
|
|
89
|
+
*/
|
|
90
|
+
export function genAiContentAttributes(params, options) {
|
|
91
|
+
if ((options?.contentMode ?? "no_content") !== "full")
|
|
92
|
+
return {};
|
|
93
|
+
const max = options?.maxContentLength ?? DEFAULT_GEN_AI_MAX_CONTENT_LENGTH;
|
|
94
|
+
const attrs = {};
|
|
95
|
+
let truncated = false;
|
|
96
|
+
if (params.inputJson !== undefined) {
|
|
97
|
+
const r = truncateContent(params.inputJson, max);
|
|
98
|
+
attrs[GEN_AI_INPUT_MESSAGES] = r.text;
|
|
99
|
+
truncated = truncated || r.truncated;
|
|
100
|
+
}
|
|
101
|
+
if (params.outputJson !== undefined) {
|
|
102
|
+
const r = truncateContent(params.outputJson, max);
|
|
103
|
+
attrs[GEN_AI_OUTPUT_MESSAGES] = r.text;
|
|
104
|
+
truncated = truncated || r.truncated;
|
|
105
|
+
}
|
|
106
|
+
if (truncated)
|
|
107
|
+
attrs[VNT_TRACE_CONTENT_TRUNCATED] = true;
|
|
108
|
+
return attrs;
|
|
109
|
+
}
|
|
110
|
+
/** Attributes for an `execute_tool` span. */
|
|
111
|
+
export function genAiToolAttributes(params) {
|
|
112
|
+
return {
|
|
113
|
+
[GEN_AI_OPERATION_NAME]: GEN_AI_OPERATIONS.executeTool,
|
|
114
|
+
[GEN_AI_TOOL_NAME]: params.toolName,
|
|
115
|
+
...genAiConversationAttributes(params.conversationId),
|
|
116
|
+
...(params.toolCallId ? { [GEN_AI_TOOL_CALL_ID]: params.toolCallId } : {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Attributes for a top-level `invoke_agent` span. */
|
|
120
|
+
export function genAiInvokeAgentAttributes(params) {
|
|
121
|
+
return {
|
|
122
|
+
[GEN_AI_OPERATION_NAME]: GEN_AI_OPERATIONS.invokeAgent,
|
|
123
|
+
...genAiConversationAttributes(params.conversationId),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=gen-ai-attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gen-ai-attributes.js","sourceRoot":"","sources":["../src/gen-ai-attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAC3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AACrE,MAAM,CAAC,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AACvE,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAC7E,MAAM,CAAC,MAAM,8BAA8B,GAAG,gCAAgC,CAAC;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,mEAAmE;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,iBAAiB;IACjC,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,cAAc;IAC3B,QAAQ,EAAE,UAAU;IACpB,cAAc,EAAE,iBAAiB;CACzB,CAAC;AAUX,y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AAC,IAAI,CAAC;QACvC,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC;IACvC,CAAC;IACD,IAAI,SAAS;QAAE,KAAK,CAAC,2BAA2B,CAAC,GAAG,IAAI,CAAC;IACzD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,mBAAmB,CAAC,MAInC;IACC,OAAO;QACL,CAAC,qBAAqB,CAAC,EAAE,iBAAiB,CAAC,WAAW;QACtD,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,QAAQ;QACnC,GAAG,2BAA2B,CAAC,MAAM,CAAC,cAAc,CAAC;QACrD,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3E,CAAC;AACJ,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,0BAA0B,CAAC,MAE1C;IACC,OAAO;QACL,CAAC,qBAAqB,CAAC,EAAE,iBAAiB,CAAC,WAAW;QACtD,GAAG,2BAA2B,CAAC,MAAM,CAAC,cAAc,CAAC;KACtD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { SpanRecorder, createSpan, endSpan, addSpanEvent, generateTraceId, } from "./tracing.js";
|
|
11
11
|
export type { Span, SpanKind, SpanStatus, SpanEvent, SpanNode, TraceContext } from "./tracing.js";
|
|
12
|
+
export { GEN_AI_OPERATION_NAME, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_MODEL, GEN_AI_RESPONSE_MODEL, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_REASONING_TOKENS, GEN_AI_RESPONSE_FINISH_REASONS, GEN_AI_CONVERSATION_ID, GEN_AI_TOOL_NAME, GEN_AI_TOOL_CALL_ID, GEN_AI_INPUT_MESSAGES, GEN_AI_OUTPUT_MESSAGES, GEN_AI_OPERATIONS, DEFAULT_GEN_AI_MAX_CONTENT_LENGTH, VNT_TRACE_CONTENT_TRUNCATED, genAiConversationAttributes, genAiChatRequestAttributes, genAiResponseAttributes, genAiUsageAttributes, genAiContentAttributes, genAiToolAttributes, genAiInvokeAgentAttributes, } from "./gen-ai-attributes.js";
|
|
13
|
+
export type { GenAiOperation, GenAiContentMode, GenAiUsage, GenAiContentOptions, } from "./gen-ai-attributes.js";
|
|
12
14
|
export { Timeline, buildTranscript } from "./timeline.js";
|
|
13
15
|
export type { TimelineEvent, TimelineEventType, TranscriptEntry } from "./timeline.js";
|
|
14
|
-
export { CostMeter, calculateCost, calculateContextPressure, DEFAULT_MODEL_PRICING, MODEL_PRICING } from "./telemetry.js";
|
|
15
|
-
export type { UsageStats, ModelPricing, ContextPressure } from "./telemetry.js";
|
|
16
|
+
export { CostMeter, calculateCost, calculateContextPressure, DEFAULT_MODEL_PRICING, MODEL_PRICING, ConsoleTelemetryProvider } from "./telemetry.js";
|
|
17
|
+
export type { UsageStats, ModelPricing, ContextPressure, TelemetryProvider } from "./telemetry.js";
|
|
18
|
+
export { createOtlpSpanExporter, resolveOtlpEndpoint, parseOtlpHeaders, mapSpanToOtlp, buildOtlpExportRequest, toOtlpAnyValue, toOtlpAttributes, toOtlpId, msToUnixNano, OTLP_SPAN_KIND, OTLP_STATUS_OK, OTLP_STATUS_ERROR, OTLP_STATUS_UNSET, } from "./otlp-exporter.js";
|
|
19
|
+
export type { OtlpExporterConfig, SpanExporter, FetchLike, OtlpAnyValue, OtlpKeyValue, OtlpSpan, OtlpSpanEvent, OtlpSpanStatus, OtlpResourceSpans, OtlpExportTraceRequest, } from "./otlp-exporter.js";
|
|
16
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAC/C,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlG,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAC/C,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlG,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,6BAA6B,EAC7B,8BAA8B,EAC9B,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,iCAAiC,EACjC,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACpJ,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnG,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
// ── Tracing ──
|
|
11
11
|
export { SpanRecorder, createSpan, endSpan, addSpanEvent, generateTraceId, } from "./tracing.js";
|
|
12
|
+
// ── GenAI semantic conventions (OTel gen_ai.*, ADK profile) ──
|
|
13
|
+
export { GEN_AI_OPERATION_NAME, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_MODEL, GEN_AI_RESPONSE_MODEL, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_REASONING_TOKENS, GEN_AI_RESPONSE_FINISH_REASONS, GEN_AI_CONVERSATION_ID, GEN_AI_TOOL_NAME, GEN_AI_TOOL_CALL_ID, GEN_AI_INPUT_MESSAGES, GEN_AI_OUTPUT_MESSAGES, GEN_AI_OPERATIONS, DEFAULT_GEN_AI_MAX_CONTENT_LENGTH, VNT_TRACE_CONTENT_TRUNCATED, genAiConversationAttributes, genAiChatRequestAttributes, genAiResponseAttributes, genAiUsageAttributes, genAiContentAttributes, genAiToolAttributes, genAiInvokeAgentAttributes, } from "./gen-ai-attributes.js";
|
|
12
14
|
// ── Timeline ──
|
|
13
15
|
export { Timeline, buildTranscript } from "./timeline.js";
|
|
14
16
|
// ── Telemetry ──
|
|
15
|
-
export { CostMeter, calculateCost, calculateContextPressure, DEFAULT_MODEL_PRICING, MODEL_PRICING } from "./telemetry.js";
|
|
17
|
+
export { CostMeter, calculateCost, calculateContextPressure, DEFAULT_MODEL_PRICING, MODEL_PRICING, ConsoleTelemetryProvider } from "./telemetry.js";
|
|
18
|
+
// ── OTLP export (P1-9) ──
|
|
19
|
+
export { createOtlpSpanExporter, resolveOtlpEndpoint, parseOtlpHeaders, mapSpanToOtlp, buildOtlpExportRequest, toOtlpAnyValue, toOtlpAttributes, toOtlpId, msToUnixNano, OTLP_SPAN_KIND, OTLP_STATUS_OK, OTLP_STATUS_ERROR, OTLP_STATUS_UNSET, } from "./otlp-exporter.js";
|
|
16
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,gBAAgB;AAChB,OAAO,EACL,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAC/C,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG1D,kBAAkB;AAClB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAA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