raindrop-ai 0.0.56 → 0.0.58

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,219 @@
1
+ // src/tracing/noOpSpan.ts
2
+ import {
3
+ TraceFlags
4
+ } from "@opentelemetry/api";
5
+ var INVALID_SPAN_CONTEXT = {
6
+ traceId: "",
7
+ spanId: "",
8
+ traceFlags: TraceFlags.NONE,
9
+ isRemote: false
10
+ };
11
+ var NoOpSpan = class {
12
+ spanContext() {
13
+ return INVALID_SPAN_CONTEXT;
14
+ }
15
+ setAttribute(_key, _value) {
16
+ return this;
17
+ }
18
+ setAttributes(_attributes) {
19
+ return this;
20
+ }
21
+ addEvent(_name, _attributesOrStartTime, _startTime) {
22
+ return this;
23
+ }
24
+ addLink(_link) {
25
+ return this;
26
+ }
27
+ addLinks(_links) {
28
+ return this;
29
+ }
30
+ setStatus(_status) {
31
+ return this;
32
+ }
33
+ updateName(_name) {
34
+ return this;
35
+ }
36
+ end(_endTime) {
37
+ }
38
+ recordException(_exception, _time) {
39
+ }
40
+ isRecording() {
41
+ return false;
42
+ }
43
+ };
44
+ var NO_OP_SPAN = new NoOpSpan();
45
+
46
+ // src/tracing/nonLiveInteraction.ts
47
+ var NonLiveInteraction = class {
48
+ constructor(context, traceId, analytics) {
49
+ this.context = context;
50
+ this.analytics = analytics;
51
+ }
52
+ withSpan(_params, fn, thisArg, ...args) {
53
+ var _a;
54
+ if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
55
+ console.log("[raindrop] using withSpan in nonLiveInteraction");
56
+ }
57
+ try {
58
+ return Promise.resolve(fn.apply(thisArg, args));
59
+ } catch (error) {
60
+ return Promise.reject(error);
61
+ }
62
+ }
63
+ withTool(_params, fn, thisArg, ...args) {
64
+ var _a;
65
+ if ((_a = this.analytics) == null ? void 0 : _a.debugLogs) {
66
+ console.log("[raindrop] using withTool in nonLiveInteraction");
67
+ }
68
+ try {
69
+ return Promise.resolve(fn.apply(thisArg, args));
70
+ } catch (error) {
71
+ return Promise.reject(error);
72
+ }
73
+ }
74
+ startSpan(_params) {
75
+ return NO_OP_SPAN;
76
+ }
77
+ setProperties(_properties) {
78
+ var _a;
79
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
80
+ eventId: this.context.eventId,
81
+ properties: _properties
82
+ });
83
+ }
84
+ setProperty(_key, _value) {
85
+ var _a;
86
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
87
+ eventId: this.context.eventId,
88
+ properties: {
89
+ [_key]: _value
90
+ }
91
+ });
92
+ }
93
+ addAttachments(_attachments) {
94
+ var _a;
95
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
96
+ eventId: this.context.eventId,
97
+ attachments: _attachments
98
+ });
99
+ }
100
+ setInput(_input) {
101
+ var _a;
102
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
103
+ eventId: this.context.eventId,
104
+ input: _input
105
+ });
106
+ }
107
+ finish(resultEvent) {
108
+ var _a;
109
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
110
+ ...resultEvent,
111
+ eventId: this.context.eventId,
112
+ isPending: false
113
+ });
114
+ }
115
+ };
116
+
117
+ // src/tracing/nonLiveTracer.ts
118
+ var NoOpTracer = class {
119
+ withSpan(_params, fn, thisArg, ...args) {
120
+ try {
121
+ return Promise.resolve(fn.apply(thisArg, args));
122
+ } catch (error) {
123
+ return Promise.reject(error);
124
+ }
125
+ }
126
+ };
127
+
128
+ // src/tracing/tracer-core.ts
129
+ var getGlobalRegistry = () => {
130
+ if (typeof globalThis !== "undefined") {
131
+ globalThis.__RAINDROP_TRACING_REGISTRY__ = globalThis.__RAINDROP_TRACING_REGISTRY__ || {
132
+ hasRealImplementation: false,
133
+ realImplementation: null
134
+ };
135
+ return globalThis.__RAINDROP_TRACING_REGISTRY__;
136
+ } else if (typeof window !== "undefined") {
137
+ window.__RAINDROP_TRACING_REGISTRY__ = window.__RAINDROP_TRACING_REGISTRY__ || {
138
+ hasRealImplementation: false,
139
+ realImplementation: null
140
+ };
141
+ return window.__RAINDROP_TRACING_REGISTRY__;
142
+ } else if (typeof global !== "undefined") {
143
+ global.__RAINDROP_TRACING_REGISTRY__ = global.__RAINDROP_TRACING_REGISTRY__ || {
144
+ hasRealImplementation: false,
145
+ realImplementation: null
146
+ };
147
+ return global.__RAINDROP_TRACING_REGISTRY__;
148
+ }
149
+ return {
150
+ hasRealImplementation: false,
151
+ realImplementation: null
152
+ };
153
+ };
154
+ var createTracing = (analytics, _apiUrl, _writeKey, _options, isDebug = false) => ({
155
+ createSpanProcessor(processorOptions) {
156
+ return {
157
+ forceFlush: async () => {
158
+ },
159
+ onStart: (span, parentContext) => {
160
+ },
161
+ onEnd: (span) => {
162
+ },
163
+ shutdown: async () => {
164
+ }
165
+ };
166
+ },
167
+ begin(traceContext) {
168
+ if (isDebug) {
169
+ console.log("not using traces");
170
+ }
171
+ if (!traceContext.eventId) {
172
+ traceContext.eventId = crypto.randomUUID();
173
+ }
174
+ analytics._trackAiPartial({
175
+ ...traceContext
176
+ });
177
+ return new NonLiveInteraction(
178
+ traceContext,
179
+ void 0,
180
+ // No traceId in stub
181
+ analytics
182
+ );
183
+ },
184
+ getActiveInteraction(eventId) {
185
+ return new NonLiveInteraction({ eventId }, void 0, analytics);
186
+ },
187
+ tracer(globalProperties) {
188
+ return new NoOpTracer();
189
+ },
190
+ async close() {
191
+ }
192
+ });
193
+ var tracing = (analytics, apiUrl, writeKey, options, isDebug = false) => {
194
+ const registry = getGlobalRegistry();
195
+ if (registry.hasRealImplementation && registry.realImplementation) {
196
+ if (isDebug) {
197
+ console.log("[raindrop] Using real tracing implementation");
198
+ }
199
+ return registry.realImplementation(analytics, apiUrl, writeKey, options, isDebug);
200
+ }
201
+ if (isDebug) {
202
+ console.log("[raindrop] Using stub implementation");
203
+ }
204
+ return createTracing(analytics, apiUrl, writeKey, options, isDebug);
205
+ };
206
+ var _setImplementation = (impl) => {
207
+ const registry = getGlobalRegistry();
208
+ registry.realImplementation = impl;
209
+ registry.hasRealImplementation = true;
210
+ if (typeof process !== "undefined" && process.env.RAINDROP_DEBUG === "true") {
211
+ console.log("[raindrop] Set real implementation in global registry");
212
+ }
213
+ };
214
+
215
+ export {
216
+ NonLiveInteraction,
217
+ tracing,
218
+ _setImplementation
219
+ };