@introspection-sdk/introspection-node 0.4.1 → 0.4.3
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-check-types.log +4 -0
- package/.turbo/turbo-lint.log +5 -0
- package/dist/ai-sdk-integration.d.ts.map +1 -1
- package/dist/ai-sdk-integration.js +2 -2
- package/dist/claude-hooks.d.ts.map +1 -1
- package/dist/claude-hooks.js +3 -3
- package/dist/client.d.ts +42 -132
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +66 -365
- package/dist/client.js.map +1 -0
- package/dist/converters/claude.d.ts +5 -1
- package/dist/converters/claude.d.ts.map +1 -1
- package/dist/converters/claude.js +7 -0
- package/dist/converters/claude.js.map +1 -0
- package/dist/converters/gemini.d.ts +90 -0
- package/dist/converters/gemini.d.ts.map +1 -0
- package/dist/converters/gemini.js +171 -0
- package/dist/converters/gemini.js.map +1 -0
- package/dist/converters/index.d.ts +1 -1
- package/dist/converters/index.d.ts.map +1 -1
- package/dist/converters/index.js +2 -1
- package/dist/converters/index.js.map +1 -0
- package/dist/converters/openai.js +1 -0
- package/dist/converters/openai.js.map +1 -0
- package/dist/converters/openclaw.d.ts +16 -0
- package/dist/converters/openclaw.d.ts.map +1 -0
- package/dist/converters/openclaw.js +49 -0
- package/dist/converters/openinference.js +1 -0
- package/dist/converters/openinference.js.map +1 -0
- package/dist/converters/vercel.d.ts.map +1 -1
- package/dist/converters/vercel.js +31 -3
- package/dist/converters/vercel.js.map +1 -0
- package/dist/http.d.ts +36 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +145 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +24 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -32
- package/dist/index.js.map +1 -0
- package/dist/langchain-handler.d.ts.map +1 -1
- package/dist/langchain-handler.js +2 -2
- package/dist/mastra-exporter.d.ts.map +1 -1
- package/dist/mastra-exporter.js +2 -2
- package/dist/otel/anthropic.d.ts +62 -0
- package/dist/otel/anthropic.d.ts.map +1 -0
- package/dist/otel/anthropic.js +425 -0
- package/dist/otel/anthropic.js.map +1 -0
- package/dist/otel/claude-hooks.d.ts +346 -0
- package/dist/otel/claude-hooks.d.ts.map +1 -0
- package/dist/otel/claude-hooks.js +645 -0
- package/dist/otel/claude-hooks.js.map +1 -0
- package/dist/otel/claude-wrapper.d.ts +93 -0
- package/dist/otel/claude-wrapper.d.ts.map +1 -0
- package/dist/otel/claude-wrapper.js +155 -0
- package/dist/otel/claude-wrapper.js.map +1 -0
- package/dist/otel/gemini.d.ts +48 -0
- package/dist/otel/gemini.d.ts.map +1 -0
- package/dist/otel/gemini.js +297 -0
- package/dist/otel/gemini.js.map +1 -0
- package/dist/otel/index.d.ts +27 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +33 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/otel/langchain-handler.d.ts +112 -0
- package/dist/otel/langchain-handler.d.ts.map +1 -0
- package/dist/otel/langchain-handler.js +555 -0
- package/dist/otel/langchain-handler.js.map +1 -0
- package/dist/otel/logs.d.ts +82 -0
- package/dist/otel/logs.d.ts.map +1 -0
- package/dist/otel/logs.js +271 -0
- package/dist/otel/logs.js.map +1 -0
- package/dist/otel/mastra-exporter.d.ts +87 -0
- package/dist/otel/mastra-exporter.d.ts.map +1 -0
- package/dist/otel/mastra-exporter.js +525 -0
- package/dist/otel/mastra-exporter.js.map +1 -0
- package/dist/otel/pi.d.ts +59 -0
- package/dist/otel/pi.d.ts.map +1 -0
- package/dist/otel/pi.js +67 -0
- package/dist/otel/pi.js.map +1 -0
- package/dist/otel/setup.d.ts +23 -0
- package/dist/otel/setup.d.ts.map +1 -0
- package/dist/otel/setup.js +127 -0
- package/dist/otel/setup.js.map +1 -0
- package/dist/otel/span-processor.d.ts +62 -0
- package/dist/otel/span-processor.d.ts.map +1 -0
- package/dist/otel/span-processor.js +319 -0
- package/dist/otel/span-processor.js.map +1 -0
- package/dist/otel/tracing-processor.d.ts +139 -0
- package/dist/otel/tracing-processor.d.ts.map +1 -0
- package/dist/otel/tracing-processor.js +418 -0
- package/dist/otel/tracing-processor.js.map +1 -0
- package/dist/resources/experiments.d.ts +31 -0
- package/dist/resources/experiments.d.ts.map +1 -0
- package/dist/resources/experiments.js +133 -0
- package/dist/resources/experiments.js.map +1 -0
- package/dist/resources/recipes.d.ts +22 -0
- package/dist/resources/recipes.d.ts.map +1 -0
- package/dist/resources/recipes.js +61 -0
- package/dist/resources/recipes.js.map +1 -0
- package/dist/resources/runtimes.d.ts +76 -0
- package/dist/resources/runtimes.d.ts.map +1 -0
- package/dist/resources/runtimes.js +179 -0
- package/dist/resources/runtimes.js.map +1 -0
- package/dist/runner-resources/files.d.ts +35 -0
- package/dist/runner-resources/files.d.ts.map +1 -0
- package/dist/runner-resources/files.js +131 -0
- package/dist/runner-resources/files.js.map +1 -0
- package/dist/runner-resources/tasks.d.ts +39 -0
- package/dist/runner-resources/tasks.d.ts.map +1 -0
- package/dist/runner-resources/tasks.js +129 -0
- package/dist/runner-resources/tasks.js.map +1 -0
- package/dist/runner.d.ts +80 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +159 -0
- package/dist/runner.js.map +1 -0
- package/dist/span-processor.d.ts.map +1 -1
- package/dist/span-processor.js +3 -3
- package/dist/streaming.d.ts +8 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +67 -0
- package/dist/streaming.js.map +1 -0
- package/dist/tracing-processor.d.ts.map +1 -1
- package/dist/tracing-processor.js +3 -3
- package/dist/types/genai.d.ts +165 -0
- package/dist/types/genai.d.ts.map +1 -0
- package/dist/types/genai.js +82 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +14 -0
- package/dist/utils.js.map +1 -0
- package/dist/version.js +1 -0
- package/dist/version.js.map +1 -0
- package/package.json +83 -25
- package/src/client.ts +76 -471
- package/src/converters/claude.ts +11 -1
- package/src/converters/gemini.ts +243 -0
- package/src/converters/index.ts +13 -7
- package/src/converters/vercel.ts +41 -3
- package/src/http.ts +163 -0
- package/src/index.ts +110 -75
- package/src/{anthropic.ts → otel/anthropic.ts} +95 -8
- package/src/{claude-hooks.ts → otel/claude-hooks.ts} +125 -24
- package/src/{claude-wrapper.ts → otel/claude-wrapper.ts} +1 -1
- package/src/otel/gemini.ts +397 -0
- package/src/otel/index.ts +80 -0
- package/src/{langchain-handler.ts → otel/langchain-handler.ts} +56 -7
- package/src/otel/logs.ts +394 -0
- package/src/{mastra-exporter.ts → otel/mastra-exporter.ts} +86 -23
- package/src/otel/pi.ts +88 -0
- package/src/otel/setup.ts +174 -0
- package/src/{span-processor.ts → otel/span-processor.ts} +17 -10
- package/src/{tracing-processor.ts → otel/tracing-processor.ts} +100 -23
- package/src/resources/experiments.ts +170 -0
- package/src/resources/recipes.ts +73 -0
- package/src/resources/runtimes.ts +231 -0
- package/src/runner-resources/files.ts +163 -0
- package/src/runner-resources/tasks.ts +156 -0
- package/src/runner.ts +194 -0
- package/src/streaming.ts +57 -0
- package/src/utils.ts +15 -0
- package/src/ai-sdk-integration.ts +0 -689
- package/src/converters/ai-sdk.ts +0 -323
package/dist/client.js
CHANGED
|
@@ -1,394 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Introspection Client for Node.js
|
|
3
|
-
* Provides an API for tracking events and feedback using OTLP Logs.
|
|
2
|
+
* Introspection REST Client for Node.js
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Exposes the Control Plane REST surface for managing runtimes and
|
|
5
|
+
* experiments. Calling `client.runtimes(name).run()` or
|
|
6
|
+
* `client.experiments(id).run()` returns a {@link Runner} bound to a Data
|
|
7
|
+
* Plane sandbox.
|
|
8
|
+
*
|
|
9
|
+
* This class is **REST-only** and does not depend on the OpenTelemetry
|
|
10
|
+
* SDK. For event tracking, feedback, identify, and baggage context
|
|
11
|
+
* helpers, use {@link IntrospectionLogs} from
|
|
12
|
+
* `@introspection-sdk/introspection-node/otel`.
|
|
7
13
|
*/
|
|
8
|
-
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
9
|
-
import { LoggerProvider, BatchLogRecordProcessor, } from "@opentelemetry/sdk-logs";
|
|
10
|
-
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
11
|
-
import { resourceFromAttributes, defaultResource, } from "@opentelemetry/resources";
|
|
12
|
-
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
13
|
-
import { propagation, context } from "@opentelemetry/api";
|
|
14
14
|
import { logger as sdkLogger } from "./utils.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { HttpClient } from "./http.js";
|
|
16
|
+
import { attachRuntimes, } from "./resources/runtimes.js";
|
|
17
|
+
import { attachExperiments, } from "./resources/experiments.js";
|
|
18
|
+
import { attachRecipes } from "./resources/recipes.js";
|
|
17
19
|
/**
|
|
18
|
-
* Introspection client
|
|
20
|
+
* Introspection REST client.
|
|
19
21
|
*
|
|
20
22
|
* @example
|
|
21
23
|
* ```typescript
|
|
22
24
|
* const client = new IntrospectionClient({
|
|
23
25
|
* token: process.env.INTROSPECTION_TOKEN,
|
|
26
|
+
* projectId: "proj_…",
|
|
24
27
|
* });
|
|
25
28
|
*
|
|
26
|
-
*
|
|
27
|
-
* client.
|
|
29
|
+
* // Open a runner from a runtime, then drive it.
|
|
30
|
+
* const runner = await client.runtimes("customer-agent").run({
|
|
31
|
+
* identity: { user_id: "u_42" },
|
|
32
|
+
* });
|
|
33
|
+
* const run = await runner.tasks.create({ prompt: "Summarize this repo" });
|
|
34
|
+
* for await (const ev of run.stream()) console.log(ev);
|
|
28
35
|
*
|
|
36
|
+
* await runner.close();
|
|
29
37
|
* await client.shutdown();
|
|
30
38
|
* ```
|
|
31
39
|
*/
|
|
32
40
|
export class IntrospectionClient {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
constructor(options = {}) {
|
|
39
|
-
const token = options.token || process.env.INTROSPECTION_TOKEN || "";
|
|
40
|
-
const serviceName = options.serviceName ||
|
|
41
|
-
process.env.INTROSPECTION_SERVICE_NAME ||
|
|
42
|
-
"introspection-client";
|
|
43
|
-
const advanced = options.advanced || {};
|
|
44
|
-
const baseUrl = advanced.baseUrl ||
|
|
45
|
-
process.env.INTROSPECTION_BASE_URL ||
|
|
46
|
-
"https://otel.introspection.dev";
|
|
47
|
-
if (!token) {
|
|
48
|
-
sdkLogger.warn("IntrospectionClient: No token provided. Events will not be sent.");
|
|
49
|
-
}
|
|
50
|
-
// Construct endpoint URL for logs
|
|
51
|
-
let endpoint;
|
|
52
|
-
if (baseUrl.endsWith("/v1/logs")) {
|
|
53
|
-
endpoint = baseUrl;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
endpoint = `${baseUrl.replace(/\/$/, "")}/v1/logs`;
|
|
57
|
-
}
|
|
58
|
-
// Build headers
|
|
59
|
-
const headers = {
|
|
60
|
-
Authorization: `Bearer ${token}`,
|
|
61
|
-
};
|
|
62
|
-
if (advanced.additionalHeaders) {
|
|
63
|
-
Object.assign(headers, advanced.additionalHeaders);
|
|
64
|
-
}
|
|
65
|
-
// Create OTLP log exporter
|
|
66
|
-
const exporter = new OTLPLogExporter({
|
|
67
|
-
url: endpoint,
|
|
68
|
-
headers,
|
|
69
|
-
});
|
|
70
|
-
// Create batch processor
|
|
71
|
-
const processor = new BatchLogRecordProcessor(exporter, {
|
|
72
|
-
maxQueueSize: advanced.maxBatchSize ?? 100,
|
|
73
|
-
scheduledDelayMillis: advanced.flushInterval ?? 5000,
|
|
74
|
-
});
|
|
75
|
-
// Get default resource and merge with our service name
|
|
76
|
-
const baseResource = defaultResource();
|
|
77
|
-
const introspectionResource = resourceFromAttributes({
|
|
78
|
-
[ATTR_SERVICE_NAME]: serviceName,
|
|
79
|
-
});
|
|
80
|
-
const resource = baseResource.merge(introspectionResource);
|
|
81
|
-
// Create logger provider
|
|
82
|
-
this.loggerProvider = new LoggerProvider({
|
|
83
|
-
resource,
|
|
84
|
-
processors: [processor],
|
|
85
|
-
});
|
|
86
|
-
this.otelLogger = this.loggerProvider.getLogger("@introspection-sdk/introspection-node", VERSION);
|
|
87
|
-
sdkLogger.info(`IntrospectionClient initialized: service=${serviceName}, endpoint=${endpoint}`);
|
|
88
|
-
}
|
|
89
|
-
/** Get gen_ai context from baggage */
|
|
90
|
-
getGenAiFromContext() {
|
|
91
|
-
const baggage = propagation.getBaggage(context.active());
|
|
92
|
-
return {
|
|
93
|
-
conversationId: baggage?.getEntry("gen_ai.conversation.id")?.value,
|
|
94
|
-
previousResponseId: baggage?.getEntry("gen_ai.request.previous_response_id")?.value,
|
|
95
|
-
agentName: baggage?.getEntry("gen_ai.agent.name")?.value,
|
|
96
|
-
agentId: baggage?.getEntry("gen_ai.agent.id")?.value,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/** Get identity from baggage or client instance */
|
|
100
|
-
getIdentityFromContext() {
|
|
101
|
-
const baggage = propagation.getBaggage(context.active());
|
|
102
|
-
return {
|
|
103
|
-
userId: baggage?.getEntry("identity.user_id")?.value || this.userId,
|
|
104
|
-
anonymousId: baggage?.getEntry("identity.anonymous_id")?.value || this.anonymousId,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get current timestamp as OpenTelemetry HrTime.
|
|
109
|
-
* Uses process.hrtime.bigint() for nanosecond precision in Node.js.
|
|
110
|
-
*/
|
|
111
|
-
getTimestamp() {
|
|
112
|
-
const hrTimeNs = process.hrtime.bigint();
|
|
113
|
-
const epochNs = BigInt(Date.now()) * BigInt(1_000_000);
|
|
114
|
-
const offsetNs = hrTimeNs - process.hrtime.bigint() + epochNs;
|
|
115
|
-
const seconds = Number(offsetNs / BigInt(1_000_000_000));
|
|
116
|
-
const nanos = Number(offsetNs % BigInt(1_000_000_000));
|
|
117
|
-
return [seconds, nanos];
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Build log record attributes.
|
|
121
|
-
*/
|
|
122
|
-
buildAttributes(eventName, options = {}) {
|
|
123
|
-
const { properties, traits, conversationId, previousResponseId, eventId } = options;
|
|
124
|
-
// Core fields
|
|
125
|
-
const attributes = {
|
|
126
|
-
"event.name": eventName,
|
|
127
|
-
"event.id": eventId || generateEventId(),
|
|
128
|
-
};
|
|
129
|
-
// Identity
|
|
130
|
-
const identity = this.getIdentityFromContext();
|
|
131
|
-
if (identity.userId) {
|
|
132
|
-
attributes["identity.user.id"] = identity.userId;
|
|
133
|
-
}
|
|
134
|
-
if (identity.anonymousId) {
|
|
135
|
-
attributes["identity.anonymous.id"] = identity.anonymousId;
|
|
136
|
-
}
|
|
137
|
-
// Gen AI context (explicit params override baggage)
|
|
138
|
-
const genAi = this.getGenAiFromContext();
|
|
139
|
-
const finalConversationId = conversationId || genAi.conversationId;
|
|
140
|
-
const finalPreviousResponseId = previousResponseId || genAi.previousResponseId;
|
|
141
|
-
if (finalConversationId) {
|
|
142
|
-
attributes["gen_ai.conversation.id"] = finalConversationId;
|
|
143
|
-
}
|
|
144
|
-
if (finalPreviousResponseId) {
|
|
145
|
-
attributes["gen_ai.request.previous_response_id"] =
|
|
146
|
-
finalPreviousResponseId;
|
|
147
|
-
}
|
|
148
|
-
if (genAi.agentName) {
|
|
149
|
-
attributes["gen_ai.agent.name"] = genAi.agentName;
|
|
150
|
-
}
|
|
151
|
-
if (genAi.agentId) {
|
|
152
|
-
attributes["gen_ai.agent.id"] = genAi.agentId;
|
|
153
|
-
}
|
|
154
|
-
// Flatten properties with "properties." prefix
|
|
155
|
-
if (properties) {
|
|
156
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
157
|
-
if (value != null) {
|
|
158
|
-
const attrKey = `properties.${key}`;
|
|
159
|
-
if (typeof value === "object") {
|
|
160
|
-
attributes[attrKey] = JSON.stringify(value);
|
|
161
|
-
}
|
|
162
|
-
else if (typeof value === "string" ||
|
|
163
|
-
typeof value === "number" ||
|
|
164
|
-
typeof value === "boolean") {
|
|
165
|
-
attributes[attrKey] = value;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// Flatten traits with "context.traits." prefix
|
|
171
|
-
if (traits) {
|
|
172
|
-
for (const [key, value] of Object.entries(traits)) {
|
|
173
|
-
if (value != null) {
|
|
174
|
-
const attrKey = `context.traits.${key}`;
|
|
175
|
-
if (typeof value === "object") {
|
|
176
|
-
attributes[attrKey] = JSON.stringify(value);
|
|
177
|
-
}
|
|
178
|
-
else if (typeof value === "string" ||
|
|
179
|
-
typeof value === "number" ||
|
|
180
|
-
typeof value === "boolean") {
|
|
181
|
-
attributes[attrKey] = value;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return attributes;
|
|
187
|
-
}
|
|
41
|
+
/** @internal — HTTP client pointed at the CP API with the customer key. */
|
|
42
|
+
cpHttp;
|
|
43
|
+
/** @internal — passed through to Runner so it can build its own DP HTTP client. */
|
|
44
|
+
advancedOptions;
|
|
45
|
+
projectId;
|
|
188
46
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* @param properties - Arbitrary key/value pairs attached to the event.
|
|
193
|
-
* @param options - Optional overrides such as a custom `eventId`.
|
|
47
|
+
* CRUD on `/v1/runtimes` and the `(idOrName) => RuntimeHandle` factory.
|
|
48
|
+
* Call as `client.runtimes("customer-agent").run()` or
|
|
49
|
+
* `client.runtimes.list({ project_id })`.
|
|
194
50
|
*/
|
|
195
|
-
|
|
196
|
-
const attributes = this.buildAttributes(eventName, {
|
|
197
|
-
properties,
|
|
198
|
-
eventId: options?.eventId,
|
|
199
|
-
});
|
|
200
|
-
this.otelLogger.emit({
|
|
201
|
-
timestamp: this.getTimestamp(),
|
|
202
|
-
context: context.active(),
|
|
203
|
-
severityNumber: SeverityNumber.INFO,
|
|
204
|
-
severityText: "INFO",
|
|
205
|
-
attributes,
|
|
206
|
-
});
|
|
207
|
-
sdkLogger.debug(`Tracked: ${eventName}`);
|
|
208
|
-
}
|
|
51
|
+
runtimes;
|
|
209
52
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* @param name - Feedback type (e.g. `"thumbs_up"`, `"thumbs_down"`).
|
|
213
|
-
* @param options - Additional feedback context such as comments or conversation ID.
|
|
53
|
+
* CRUD on `/v1/experiments` and the `(id) => ExperimentHandle` factory.
|
|
214
54
|
*/
|
|
215
|
-
|
|
216
|
-
const { comments, conversationId, previousResponseId, eventId, ...extra } = options;
|
|
217
|
-
const properties = { name, ...extra };
|
|
218
|
-
if (comments) {
|
|
219
|
-
properties.comments = comments;
|
|
220
|
-
}
|
|
221
|
-
const attributes = this.buildAttributes("introspection.feedback", {
|
|
222
|
-
properties,
|
|
223
|
-
conversationId: conversationId,
|
|
224
|
-
previousResponseId: previousResponseId,
|
|
225
|
-
eventId: eventId,
|
|
226
|
-
});
|
|
227
|
-
this.otelLogger.emit({
|
|
228
|
-
timestamp: this.getTimestamp(),
|
|
229
|
-
context: context.active(),
|
|
230
|
-
severityNumber: SeverityNumber.INFO,
|
|
231
|
-
severityText: "INFO",
|
|
232
|
-
attributes,
|
|
233
|
-
});
|
|
234
|
-
sdkLogger.debug(`Feedback: ${name}`);
|
|
235
|
-
}
|
|
55
|
+
experiments;
|
|
236
56
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* @param traits - Key/value user properties (e.g. `{ email: "…" }`).
|
|
241
|
-
* @param anonymousId - Optional anonymous identifier to link pre-auth sessions.
|
|
242
|
-
* @param eventId - Optional custom event ID override.
|
|
57
|
+
* CRUD on `/v1/recipes`. Recipes are immutable build artefacts
|
|
58
|
+
* (repository + git ref + commit sha) referenced by runtimes and
|
|
59
|
+
* experiment arms.
|
|
243
60
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
61
|
+
recipes;
|
|
62
|
+
constructor(options = {}) {
|
|
63
|
+
const token = options.token || process.env.INTROSPECTION_TOKEN || "";
|
|
64
|
+
const advanced = options.advanced || {};
|
|
65
|
+
this.advancedOptions = advanced;
|
|
66
|
+
this.projectId =
|
|
67
|
+
options.projectId || process.env.INTROSPECTION_PROJECT_ID || undefined;
|
|
68
|
+
const baseApiUrl = advanced.baseApiUrl ||
|
|
69
|
+
process.env.INTROSPECTION_BASE_API_URL ||
|
|
70
|
+
"https://api.introspection.dev";
|
|
71
|
+
if (!token) {
|
|
72
|
+
sdkLogger.warn("IntrospectionClient: No token provided. REST calls will fail.");
|
|
73
|
+
}
|
|
74
|
+
// CP HTTP client — talks to the customer-facing API with the customer
|
|
75
|
+
// API key. Runners get their own HttpClient instances pointed at the
|
|
76
|
+
// `deployment.endpoint` returned by `/v1/runtimes/{id}/run`.
|
|
77
|
+
this.cpHttp = new HttpClient({
|
|
78
|
+
apiUrl: baseApiUrl,
|
|
79
|
+
token,
|
|
80
|
+
additionalHeaders: advanced.additionalHeaders,
|
|
81
|
+
fetch: advanced.fetch,
|
|
259
82
|
});
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
*
|
|
265
|
-
* @param values - Key/value pairs to store in OTel baggage.
|
|
266
|
-
* @returns A new context containing the baggage entries.
|
|
267
|
-
*/
|
|
268
|
-
createBaggageContext(values) {
|
|
269
|
-
const ctx = context.active();
|
|
270
|
-
let bag = propagation.getBaggage(ctx) || propagation.createBaggage();
|
|
271
|
-
for (const [key, value] of Object.entries(values)) {
|
|
272
|
-
bag = bag.setEntry(key, { value });
|
|
273
|
-
}
|
|
274
|
-
return propagation.setBaggage(ctx, bag);
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Set multiple baggage values and run a callback within that context.
|
|
278
|
-
*
|
|
279
|
-
* @param values - Key/value pairs to store in OTel baggage.
|
|
280
|
-
* @param callback - Function to execute with the baggage context active.
|
|
281
|
-
* @returns The value returned by `callback`.
|
|
282
|
-
*/
|
|
283
|
-
async withBaggage(values, callback) {
|
|
284
|
-
const ctx = this.createBaggageContext(values);
|
|
285
|
-
return await context.with(ctx, callback);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Set `gen_ai.agent.name` (and optionally `gen_ai.agent.id`) baggage and run
|
|
289
|
-
* a callback within that context.
|
|
290
|
-
*
|
|
291
|
-
* @param agentName - The agent name to propagate.
|
|
292
|
-
* @param agentId - Optional agent identifier.
|
|
293
|
-
* @param callback - Function to execute with the agent baggage active.
|
|
294
|
-
* @returns The value returned by `callback`.
|
|
295
|
-
*/
|
|
296
|
-
async withAgent(agentName, agentId, callback) {
|
|
297
|
-
const values = { "gen_ai.agent.name": agentName };
|
|
298
|
-
if (agentId) {
|
|
299
|
-
values["gen_ai.agent.id"] = agentId;
|
|
300
|
-
}
|
|
301
|
-
return await context.with(this.createBaggageContext(values), callback);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Set conversation-related baggage (`gen_ai.conversation.id`,
|
|
305
|
-
* `gen_ai.request.previous_response_id`) and run a callback within that
|
|
306
|
-
* context.
|
|
307
|
-
*
|
|
308
|
-
* @param conversationId - The conversation identifier.
|
|
309
|
-
* @param previousResponseId - The ID of the previous response in the conversation.
|
|
310
|
-
* @param callback - Function to execute with the conversation baggage active.
|
|
311
|
-
* @returns The value returned by `callback`.
|
|
312
|
-
*/
|
|
313
|
-
async withConversation(conversationId, previousResponseId, callback) {
|
|
314
|
-
const values = {};
|
|
315
|
-
if (conversationId) {
|
|
316
|
-
values["gen_ai.conversation.id"] = conversationId;
|
|
317
|
-
}
|
|
318
|
-
if (previousResponseId) {
|
|
319
|
-
values["gen_ai.request.previous_response_id"] = previousResponseId;
|
|
320
|
-
}
|
|
321
|
-
return await context.with(this.createBaggageContext(values), callback);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Set the user ID on this client instance.
|
|
325
|
-
*
|
|
326
|
-
* @param userId - Unique identifier for the user.
|
|
327
|
-
*/
|
|
328
|
-
setUserId(userId) {
|
|
329
|
-
this.userId = userId;
|
|
83
|
+
this.runtimes = attachRuntimes(this, this.cpHttp);
|
|
84
|
+
this.experiments = attachExperiments(this, this.cpHttp);
|
|
85
|
+
this.recipes = attachRecipes(this.cpHttp);
|
|
86
|
+
sdkLogger.info(`IntrospectionClient initialized: api=${baseApiUrl}`);
|
|
330
87
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Set the anonymous ID on this client instance.
|
|
333
|
-
*
|
|
334
|
-
* @param anonymousId - Anonymous identifier used before authentication.
|
|
335
|
-
*/
|
|
336
|
-
setAnonymousId(anonymousId) {
|
|
337
|
-
this.anonymousId = anonymousId;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Set `identity.user_id` baggage and run a callback within that context.
|
|
341
|
-
*
|
|
342
|
-
* @param userId - The user identifier to propagate.
|
|
343
|
-
* @param callback - Function to execute with the user-ID baggage active.
|
|
344
|
-
* @returns The value returned by `callback`.
|
|
345
|
-
*/
|
|
346
|
-
async withUserId(userId, callback) {
|
|
347
|
-
return await context.with(this.createBaggageContext({ "identity.user_id": userId }), callback);
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Set `identity.anonymous_id` baggage and run a callback within that context.
|
|
351
|
-
*
|
|
352
|
-
* @param anonymousId - The anonymous identifier to propagate.
|
|
353
|
-
* @param callback - Function to execute with the anonymous-ID baggage active.
|
|
354
|
-
* @returns The value returned by `callback`.
|
|
355
|
-
*/
|
|
356
|
-
async withAnonymousId(anonymousId, callback) {
|
|
357
|
-
return await context.with(this.createBaggageContext({ "identity.anonymous_id": anonymousId }), callback);
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Get the current anonymous ID stored on this client instance.
|
|
361
|
-
*
|
|
362
|
-
* @returns The anonymous ID, or `undefined` if not set.
|
|
363
|
-
*/
|
|
364
|
-
getAnonymousId() {
|
|
365
|
-
return this.anonymousId;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Reset all client-side state (user ID, anonymous ID, and traits).
|
|
369
|
-
*/
|
|
370
|
-
reset() {
|
|
371
|
-
this.userId = undefined;
|
|
372
|
-
this.anonymousId = undefined;
|
|
373
|
-
this.traits = {};
|
|
374
|
-
sdkLogger.debug("Client state reset");
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Flush all queued log records to the backend.
|
|
378
|
-
*
|
|
379
|
-
* @returns A promise that resolves once the flush completes.
|
|
380
|
-
*/
|
|
381
|
-
async flush() {
|
|
382
|
-
await this.loggerProvider.forceFlush();
|
|
383
|
-
sdkLogger.debug("Flushed pending log records");
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Shut down the client, flushing all pending log records.
|
|
387
|
-
*
|
|
388
|
-
* @returns A promise that resolves once shutdown is complete.
|
|
389
|
-
*/
|
|
88
|
+
/** Close the underlying HTTP client. */
|
|
390
89
|
async shutdown() {
|
|
391
|
-
|
|
90
|
+
// HttpClient has no persistent connections to close, but reserved
|
|
91
|
+
// for future use (e.g. agent keep-alive pools).
|
|
392
92
|
sdkLogger.debug("IntrospectionClient shutdown complete");
|
|
393
93
|
}
|
|
394
94
|
}
|
|
95
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjD,OAA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AAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE1C,SAAS,CAAC,IAAI,CAAC,wCAAwC,UAAU,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,wCAAwC;IACxC,KAAK,CAAC,QAAQ;QACZ,kEAAkE;QAClE,gDAAgD;QAChD,SAAS,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -115,6 +115,10 @@ export interface ClaudeSessionData {
|
|
|
115
115
|
toolNames?: string[];
|
|
116
116
|
/** System instructions / system prompt */
|
|
117
117
|
systemInstructions?: string;
|
|
118
|
+
/** Tokens read from the LLM prompt cache */
|
|
119
|
+
cacheReadInputTokens?: number;
|
|
120
|
+
/** Tokens written to the LLM prompt cache */
|
|
121
|
+
cacheCreationInputTokens?: number;
|
|
118
122
|
}
|
|
119
123
|
/**
|
|
120
124
|
* Convert Claude session data to camelCase {@link GenAiAttributes}.
|
|
@@ -142,5 +146,5 @@ export declare function convertClaudeSessionToGenAI(data: ClaudeSessionData): Ge
|
|
|
142
146
|
* for (const [k, v] of Object.entries(attrs)) span.setAttribute(k, v);
|
|
143
147
|
* ```
|
|
144
148
|
*/
|
|
145
|
-
export declare function convertClaudeSessionToOtelAttributes(data: ClaudeSessionData): Record<string, string | number>;
|
|
149
|
+
export declare function convertClaudeSessionToOtelAttributes(data: ClaudeSessionData): Record<string, string | number | string[] | number[]>;
|
|
146
150
|
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/converters/claude.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV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D,QAAQ,EAAE,aAAa,EAAE,GACxB,YAAY,EAAE,CAKhB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,cAAc,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACtC,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,0CAA0C;IAC1C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,6CAA6C;IAC7C,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,iBAAiB,GACtB,eAAe,CA+DjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAavD"}
|
|
@@ -159,6 +159,12 @@ export function convertClaudeSessionToGenAI(data) {
|
|
|
159
159
|
if (data.outputTokens !== undefined) {
|
|
160
160
|
result.outputTokens = data.outputTokens;
|
|
161
161
|
}
|
|
162
|
+
if (data.cacheReadInputTokens !== undefined) {
|
|
163
|
+
result.cacheReadInputTokens = data.cacheReadInputTokens;
|
|
164
|
+
}
|
|
165
|
+
if (data.cacheCreationInputTokens !== undefined) {
|
|
166
|
+
result.cacheCreationInputTokens = data.cacheCreationInputTokens;
|
|
167
|
+
}
|
|
162
168
|
// Set response ID
|
|
163
169
|
if (data.responseId) {
|
|
164
170
|
result.responseId = data.responseId;
|
|
@@ -200,3 +206,4 @@ export function convertClaudeSessionToOtelAttributes(data) {
|
|
|
200
206
|
}
|
|
201
207
|
return result;
|
|
202
208
|
}
|
|
209
|
+
//# sourceMappingURL=claude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/converters/claude.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAiDxD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kCAAkC,CAChD,MAAc;IAEd,OAAO;QACL;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;SAC3C;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,2BAA2B,CAClC,OAAsC;IAEtC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,KAAK,GAAkB,EAAE,CAAC;IAEhC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;YAC7C,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,IAAc,EAAE,CAAC,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AA0B;IAC1B,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC5B,MAAM,CAAC,kBAAkB,GAAG;YAC1B,EAAE,IAAI,EAAE,MAAe,EAAE,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE;SAC5D,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oCAAoC,CAClD,IAAuB;IAEvB,MAAM,UAAU,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IAExC,iCAAiC;IACjC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;IAC/C,CAAC;IACD,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;IAC3C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini (`@google/genai`) format conversion functions for OTel Gen AI
|
|
3
|
+
* Semantic Conventions.
|
|
4
|
+
*
|
|
5
|
+
* Gemini 3.x / Gemini 3.5+ models emit per-part `thoughtSignature` payloads
|
|
6
|
+
* that carry encrypted reasoning context which MUST be passed back on
|
|
7
|
+
* subsequent turns (especially around tool calls) for the model to maintain
|
|
8
|
+
* its chain of thought.
|
|
9
|
+
*
|
|
10
|
+
* @see https://ai.google.dev/gemini-api/docs/thought-signatures
|
|
11
|
+
*
|
|
12
|
+
* Whenever a Gemini part carries a `thoughtSignature`, this converter emits a
|
|
13
|
+
* `thinking` gen_ai part preceding the visible content. If the part is itself a
|
|
14
|
+
* thought summary (`thought: true`), the visible thought text is used as the
|
|
15
|
+
* thinking content; otherwise the signed-but-redacted sentinel
|
|
16
|
+
* `REDACTED_THINKING_CONTENT` (`"[redacted]"`) is used — mirroring the way the
|
|
17
|
+
* Anthropic instrumentor handles `redacted_thinking` blocks.
|
|
18
|
+
*/
|
|
19
|
+
import type { InputMessage, OutputMessage, SystemInstruction, ToolDefinition } from "@introspection-sdk/types";
|
|
20
|
+
/** Provider name reported on Gemini-produced thinking parts. */
|
|
21
|
+
export declare const GEMINI_PROVIDER_NAME = "gemini";
|
|
22
|
+
/** A single content part as returned by the `@google/genai` SDK. */
|
|
23
|
+
export interface GeminiPart {
|
|
24
|
+
text?: string;
|
|
25
|
+
thought?: boolean;
|
|
26
|
+
thoughtSignature?: string;
|
|
27
|
+
functionCall?: {
|
|
28
|
+
id?: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
args?: unknown;
|
|
31
|
+
};
|
|
32
|
+
functionResponse?: {
|
|
33
|
+
id?: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
response?: unknown;
|
|
36
|
+
};
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/** A Content envelope as used in Gemini `contents` requests and candidate outputs. */
|
|
40
|
+
export interface GeminiContent {
|
|
41
|
+
role?: string;
|
|
42
|
+
parts?: GeminiPart[];
|
|
43
|
+
}
|
|
44
|
+
/** A single candidate from a `generateContent` response. */
|
|
45
|
+
export interface GeminiCandidate {
|
|
46
|
+
content?: GeminiContent;
|
|
47
|
+
finishReason?: string;
|
|
48
|
+
index?: number;
|
|
49
|
+
}
|
|
50
|
+
/** A Gemini tool function declaration. */
|
|
51
|
+
export interface GeminiFunctionDeclaration {
|
|
52
|
+
name?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
parameters?: unknown;
|
|
55
|
+
parametersJsonSchema?: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** A Gemini tool entry — `{ functionDeclarations: [...] }`. */
|
|
58
|
+
export interface GeminiTool {
|
|
59
|
+
functionDeclarations?: GeminiFunctionDeclaration[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert a `contents` array from a Gemini request to gen_ai input messages.
|
|
63
|
+
*
|
|
64
|
+
* Accepts a plain string (the convenience form `generateContent({ contents: "hi" })`)
|
|
65
|
+
* or an array of {@link GeminiContent} objects. Roles are normalized: Gemini's
|
|
66
|
+
* `model` becomes `assistant`.
|
|
67
|
+
*
|
|
68
|
+
* @param contents - The Gemini request's `contents` field.
|
|
69
|
+
* @returns Array of {@link InputMessage} objects.
|
|
70
|
+
*/
|
|
71
|
+
export declare function convertGeminiContentsToInputMessages(contents: string | GeminiContent[] | GeminiContent | undefined): InputMessage[];
|
|
72
|
+
/**
|
|
73
|
+
* Convert Gemini response candidates to gen_ai output messages.
|
|
74
|
+
*
|
|
75
|
+
* @param candidates - The `candidates` array from a `generateContent` response.
|
|
76
|
+
* @returns Array of {@link OutputMessage} objects (one per candidate that has content).
|
|
77
|
+
*/
|
|
78
|
+
export declare function convertGeminiCandidatesToOutputMessages(candidates: GeminiCandidate[] | undefined): OutputMessage[];
|
|
79
|
+
/**
|
|
80
|
+
* Convert a Gemini `systemInstruction` field to gen_ai SystemInstruction[].
|
|
81
|
+
*
|
|
82
|
+
* Gemini accepts either a plain string or a {@link GeminiContent} object.
|
|
83
|
+
*/
|
|
84
|
+
export declare function convertGeminiSystemInstructionToSemconv(systemInstruction: string | GeminiContent | undefined): SystemInstruction[] | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Convert Gemini `tools` (array of `{functionDeclarations}` entries) to gen_ai
|
|
87
|
+
* ToolDefinition[].
|
|
88
|
+
*/
|
|
89
|
+
export declare function convertGeminiToolsToToolDefinitions(tools: GeminiTool[] | undefined): ToolDefinition[] | undefined;
|
|
90
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/converters/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;A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