raindrop-ai 0.0.25 → 0.0.26

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,190 @@
1
+ // ../../node_modules/uuid/dist/esm-node/native.js
2
+ import crypto from "crypto";
3
+ var native_default = {
4
+ randomUUID: crypto.randomUUID
5
+ };
6
+
7
+ // ../../node_modules/uuid/dist/esm-node/rng.js
8
+ import crypto2 from "crypto";
9
+ var rnds8Pool = new Uint8Array(256);
10
+ var poolPtr = rnds8Pool.length;
11
+ function rng() {
12
+ if (poolPtr > rnds8Pool.length - 16) {
13
+ crypto2.randomFillSync(rnds8Pool);
14
+ poolPtr = 0;
15
+ }
16
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
17
+ }
18
+
19
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
20
+ var byteToHex = [];
21
+ for (let i = 0; i < 256; ++i) {
22
+ byteToHex.push((i + 256).toString(16).slice(1));
23
+ }
24
+ function unsafeStringify(arr, offset = 0) {
25
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
26
+ }
27
+
28
+ // ../../node_modules/uuid/dist/esm-node/v4.js
29
+ function v4(options, buf, offset) {
30
+ if (native_default.randomUUID && !buf && !options) {
31
+ return native_default.randomUUID();
32
+ }
33
+ options = options || {};
34
+ const rnds = options.random || (options.rng || rng)();
35
+ rnds[6] = rnds[6] & 15 | 64;
36
+ rnds[8] = rnds[8] & 63 | 128;
37
+ if (buf) {
38
+ offset = offset || 0;
39
+ for (let i = 0; i < 16; ++i) {
40
+ buf[offset + i] = rnds[i];
41
+ }
42
+ return buf;
43
+ }
44
+ return unsafeStringify(rnds);
45
+ }
46
+ var v4_default = v4;
47
+
48
+ // src/tracing/noOpSpan.ts
49
+ import {
50
+ TraceFlags
51
+ } from "@opentelemetry/api";
52
+ var INVALID_SPAN_CONTEXT = {
53
+ traceId: "",
54
+ spanId: "",
55
+ traceFlags: TraceFlags.NONE,
56
+ isRemote: false
57
+ };
58
+ var NoOpSpan = class {
59
+ spanContext() {
60
+ return INVALID_SPAN_CONTEXT;
61
+ }
62
+ setAttribute(_key, _value) {
63
+ return this;
64
+ }
65
+ setAttributes(_attributes) {
66
+ return this;
67
+ }
68
+ addEvent(_name, _attributesOrStartTime, _startTime) {
69
+ return this;
70
+ }
71
+ addLink(_link) {
72
+ return this;
73
+ }
74
+ addLinks(_links) {
75
+ return this;
76
+ }
77
+ setStatus(_status) {
78
+ return this;
79
+ }
80
+ updateName(_name) {
81
+ return this;
82
+ }
83
+ end(_endTime) {
84
+ }
85
+ recordException(_exception, _time) {
86
+ }
87
+ isRecording() {
88
+ return false;
89
+ }
90
+ };
91
+ var NO_OP_SPAN = new NoOpSpan();
92
+
93
+ // src/tracing/nonLiveInteraction.ts
94
+ var NonLiveInteraction = class {
95
+ constructor(context, traceId, analytics) {
96
+ this.context = context;
97
+ this.analytics = analytics;
98
+ }
99
+ withWorkflow(_params, fn, thisArg, ...args) {
100
+ try {
101
+ return Promise.resolve(fn.apply(thisArg, args));
102
+ } catch (error) {
103
+ return Promise.reject(error);
104
+ }
105
+ }
106
+ withTask(_params, fn, thisArg, ...args) {
107
+ try {
108
+ return Promise.resolve(fn.apply(thisArg, args));
109
+ } catch (error) {
110
+ return Promise.reject(error);
111
+ }
112
+ }
113
+ createTask(_params) {
114
+ return NO_OP_SPAN;
115
+ }
116
+ withContext(_properties, fn, thisArg, ...args) {
117
+ return fn.apply(thisArg, args);
118
+ }
119
+ setProperties(_properties) {
120
+ var _a;
121
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
122
+ eventId: this.context.eventId,
123
+ properties: _properties
124
+ });
125
+ }
126
+ setProperty(_key, _value) {
127
+ var _a;
128
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
129
+ eventId: this.context.eventId,
130
+ properties: {
131
+ [_key]: _value
132
+ }
133
+ });
134
+ }
135
+ addAttachments(_attachments) {
136
+ var _a;
137
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
138
+ eventId: this.context.eventId,
139
+ attachments: _attachments
140
+ });
141
+ }
142
+ setInput(_input) {
143
+ var _a;
144
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
145
+ eventId: this.context.eventId,
146
+ input: _input
147
+ });
148
+ }
149
+ finish(resultEvent) {
150
+ var _a;
151
+ (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
152
+ ...resultEvent,
153
+ eventId: this.context.eventId,
154
+ isPending: false
155
+ });
156
+ }
157
+ };
158
+
159
+ // src/tracing/tracer-core.ts
160
+ var createTracing = (analytics, _apiUrl, _writeKey, _options) => ({
161
+ begin(traceContext) {
162
+ if (!traceContext.eventId) {
163
+ traceContext.eventId = v4_default();
164
+ }
165
+ return new NonLiveInteraction(
166
+ traceContext,
167
+ void 0,
168
+ // No traceId in stub
169
+ analytics
170
+ );
171
+ },
172
+ getActiveInteraction(eventId) {
173
+ return new NonLiveInteraction({ eventId }, void 0, analytics);
174
+ },
175
+ close() {
176
+ analytics == null ? void 0 : analytics.close();
177
+ }
178
+ });
179
+ var implementation = createTracing;
180
+ var tracing = (analytics, apiUrl, writeKey, options) => implementation(analytics, apiUrl, writeKey, options);
181
+ var _setImplementation = (impl) => {
182
+ implementation = impl;
183
+ };
184
+
185
+ export {
186
+ v4_default,
187
+ NonLiveInteraction,
188
+ tracing,
189
+ _setImplementation
190
+ };
@@ -546,4 +546,4 @@ declare class Raindrop {
546
546
  close(): Promise<void>;
547
547
  }
548
548
 
549
- export { type AiTrackEvent as A, MAX_INGEST_SIZE_BYTES as M, Raindrop as R };
549
+ export { type AiTrackEvent as A, type Interaction as I, MAX_INGEST_SIZE_BYTES as M, type PartialAiTrackEvent as P, Raindrop as R };
@@ -546,4 +546,4 @@ declare class Raindrop {
546
546
  close(): Promise<void>;
547
547
  }
548
548
 
549
- export { type AiTrackEvent as A, MAX_INGEST_SIZE_BYTES as M, Raindrop as R };
549
+ export { type AiTrackEvent as A, type Interaction as I, MAX_INGEST_SIZE_BYTES as M, type PartialAiTrackEvent as P, Raindrop as R };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MAX_INGEST_SIZE_BYTES, R as Raindrop, R as default } from './index-Dx0acc0k.mjs';
1
+ export { M as MAX_INGEST_SIZE_BYTES, R as Raindrop, R as default } from './index-6U6ncOea.mjs';
2
2
  import '@dawn/schemas/ingest';
3
3
  import '@opentelemetry/api';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { M as MAX_INGEST_SIZE_BYTES, R as Raindrop, R as default } from './index-Dx0acc0k.js';
1
+ export { M as MAX_INGEST_SIZE_BYTES, R as Raindrop, R as default } from './index-6U6ncOea.js';
2
2
  import '@dawn/schemas/ingest';
3
3
  import '@opentelemetry/api';
package/dist/index.js CHANGED
@@ -164,12 +164,11 @@ var v4_default = v4;
164
164
  // package.json
165
165
  var package_default = {
166
166
  name: "raindrop-ai",
167
- version: "0.0.25",
167
+ version: "0.0.26",
168
168
  main: "dist/index.js",
169
169
  module: "dist/index.mjs",
170
170
  types: "dist/index.d.ts",
171
171
  license: "MIT",
172
- sideEffects: false,
173
172
  exports: {
174
173
  ".": {
175
174
  types: "./dist/index.d.ts",
@@ -180,6 +179,12 @@ var package_default = {
180
179
  types: "./dist/vercel/index.d.ts",
181
180
  import: "./dist/vercel/index.mjs",
182
181
  require: "./dist/vercel/index.js"
182
+ },
183
+ "./tracing": {
184
+ types: "./dist/tracing/index.d.ts",
185
+ node: "./dist/tracing/index.js",
186
+ import: "./dist/tracing/index.mjs",
187
+ require: "./dist/tracing/index.js"
183
188
  }
184
189
  },
185
190
  files: [
@@ -202,12 +207,15 @@ var package_default = {
202
207
  "@dawn-analytics/redact-pii": "0.1.2",
203
208
  "@opentelemetry/api": "^1.9.0",
204
209
  "@opentelemetry/sdk-trace-node": "^2.0.0",
205
- "@traceloop/node-server-sdk": "^0.12.2",
206
210
  weakref: "^0.2.1",
207
211
  zod: "^3.23.8"
208
212
  },
209
213
  peerDependencies: {
210
- ai: "^4.1.17"
214
+ ai: "^4.1.17",
215
+ "@traceloop/node-server-sdk": "^0.12.2"
216
+ },
217
+ optionalDependencies: {
218
+ "@traceloop/node-server-sdk": "^0.12.2"
211
219
  },
212
220
  publishConfig: {
213
221
  access: "public"
@@ -215,7 +223,8 @@ var package_default = {
215
223
  tsup: {
216
224
  entry: [
217
225
  "src/index.ts",
218
- "src/vercel/index.ts"
226
+ "src/vercel/index.ts",
227
+ "src/tracing/index.ts"
219
228
  ],
220
229
  format: [
221
230
  "cjs",
@@ -318,149 +327,12 @@ function redactPII(event) {
318
327
  return event;
319
328
  }
320
329
 
321
- // src/tracing/index.ts
322
- var import_api3 = require("@opentelemetry/api");
323
- var traceloop2 = __toESM(require("@traceloop/node-server-sdk"));
324
- var import_weakref = require("weakref");
325
-
326
- // src/tracing/liveInteraction.ts
327
- var import_api = require("@opentelemetry/api");
328
- var traceloop = __toESM(require("@traceloop/node-server-sdk"));
329
- function getPropertiesFromContext(context2) {
330
- const properties = {
331
- ...context2.userId && { user_id: context2.userId },
332
- ...context2.convoId && { convo_id: context2.convoId },
333
- ...context2.eventId && { event_id: context2.eventId },
334
- ...context2.properties || {}
335
- };
336
- if (context2.attachments && context2.attachments.length > 0) {
337
- properties.attachments = JSON.stringify(context2.attachments);
338
- }
339
- return properties;
340
- }
341
- var LiveInteraction = class {
342
- constructor(context2, traceId, analytics) {
343
- this.context = context2;
344
- this.analytics = analytics;
345
- this.tracer = import_api.trace.getTracer("traceloop.tracer");
346
- this.traceId = traceId;
347
- }
348
- async withWorkflow(params, fn, thisArg, ...args) {
349
- const workflowName = typeof params === "string" ? params : params.name;
350
- const properties = typeof params === "string" ? getPropertiesFromContext(this.context) : {
351
- ...getPropertiesFromContext(this.context),
352
- ...params.properties || {}
353
- };
354
- const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
355
- return traceloop.withWorkflow(
356
- {
357
- name: workflowName,
358
- associationProperties: properties,
359
- inputParameters
360
- },
361
- fn,
362
- thisArg,
363
- ...args
364
- );
365
- }
366
- async withTask(params, fn, thisArg, ...args) {
367
- const taskName = typeof params === "string" ? params : params.name;
368
- const properties = typeof params === "string" ? {
369
- ...getPropertiesFromContext(this.context),
370
- task_kind: "internal"
371
- } : {
372
- ...getPropertiesFromContext(this.context),
373
- task_kind: params.kind,
374
- ...params.properties || {}
375
- };
376
- const inputParameters = typeof params === "string" ? void 0 : params.inputParameters;
377
- return traceloop.withTask(
378
- {
379
- name: taskName,
380
- associationProperties: properties,
381
- inputParameters
382
- },
383
- fn,
384
- thisArg,
385
- ...args
386
- );
387
- }
388
- createTask(params) {
389
- const { name, properties = {} } = params;
390
- const span = this.tracer.startSpan(name);
391
- span.setAttributes(getPropertiesFromContext(this.context));
392
- span.setAttribute("traceloop.span.kind", "task");
393
- Object.entries(properties).forEach(([key, value]) => {
394
- span.setAttribute("traceloop.association.properties." + key, String(value));
395
- });
396
- return span;
397
- }
398
- withContext(properties, fn, thisArg, ...args) {
399
- const newContext = {
400
- ...this.context,
401
- properties: { ...this.context.properties, ...properties }
402
- };
403
- return traceloop.withAssociationProperties(
404
- getPropertiesFromContext(newContext),
405
- fn,
406
- thisArg,
407
- ...args
408
- );
409
- }
410
- setProperties(properties) {
411
- var _a;
412
- this.context.properties = { ...this.context.properties, ...properties };
413
- (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
414
- eventId: this.context.eventId,
415
- properties
416
- });
417
- }
418
- setProperty(key, value) {
419
- var _a;
420
- this.context.properties = { ...this.context.properties, [key]: value };
421
- (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
422
- eventId: this.context.eventId,
423
- properties: { [key]: value }
424
- });
425
- }
426
- addAttachments(attachments) {
427
- var _a;
428
- if (!this.context.attachments) {
429
- this.context.attachments = [];
430
- }
431
- this.context.attachments.push(...attachments);
432
- (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
433
- eventId: this.context.eventId,
434
- attachments
435
- });
436
- }
437
- setInput(input) {
438
- var _a;
439
- this.context.input = input;
440
- (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
441
- eventId: this.context.eventId,
442
- input
443
- });
444
- }
445
- finish(resultEvent) {
446
- var _a;
447
- if (this.traceId) {
448
- this.setProperty("trace_id", this.traceId);
449
- }
450
- (_a = this.analytics) == null ? void 0 : _a._trackAiPartial({
451
- ...resultEvent,
452
- eventId: resultEvent.eventId || this.context.eventId,
453
- isPending: false
454
- });
455
- }
456
- };
457
-
458
330
  // src/tracing/noOpSpan.ts
459
- var import_api2 = require("@opentelemetry/api");
331
+ var import_api = require("@opentelemetry/api");
460
332
  var INVALID_SPAN_CONTEXT = {
461
333
  traceId: "",
462
334
  spanId: "",
463
- traceFlags: import_api2.TraceFlags.NONE,
335
+ traceFlags: import_api.TraceFlags.NONE,
464
336
  isRemote: false
465
337
  };
466
338
  var NoOpSpan = class {
@@ -500,8 +372,8 @@ var NO_OP_SPAN = new NoOpSpan();
500
372
 
501
373
  // src/tracing/nonLiveInteraction.ts
502
374
  var NonLiveInteraction = class {
503
- constructor(context2, traceId, analytics) {
504
- this.context = context2;
375
+ constructor(context, traceId, analytics) {
376
+ this.context = context;
505
377
  this.analytics = analytics;
506
378
  }
507
379
  withWorkflow(_params, fn, thisArg, ...args) {
@@ -564,52 +436,28 @@ var NonLiveInteraction = class {
564
436
  }
565
437
  };
566
438
 
567
- // src/tracing/index.ts
568
- var activeInteractions = new import_weakref.WeakValueMap();
569
- function getCurrentTraceId() {
570
- var _a;
571
- return (_a = import_api3.trace.getSpan(import_api3.context.active())) == null ? void 0 : _a.spanContext().traceId;
572
- }
573
- var tracing = (analytics, apiUrl, writeKey, options) => {
574
- const { logLevel, ...otherOptions } = options;
575
- const traceloopClient = traceloop2.initialize({
576
- baseUrl: apiUrl,
577
- apiKey: writeKey,
578
- ...otherOptions
579
- });
580
- return {
581
- begin(traceContext) {
582
- if (!traceContext.eventId) {
583
- traceContext.eventId = v4_default();
584
- }
585
- const traceId = getCurrentTraceId();
586
- analytics._trackAiPartial({
587
- ...traceContext
588
- });
589
- const interaction = new LiveInteraction(
590
- traceContext,
591
- traceId,
592
- analytics
593
- );
594
- if (traceId) {
595
- activeInteractions.set(traceId, interaction);
596
- }
597
- return interaction;
598
- },
599
- getActiveInteraction(eventId) {
600
- const traceId = getCurrentTraceId();
601
- if (!traceId) {
602
- return new NonLiveInteraction({ eventId }, void 0, analytics);
603
- }
604
- return activeInteractions.get(traceId) || new NonLiveInteraction({ eventId }, void 0, analytics);
605
- },
606
- close() {
607
- activeInteractions.clear();
608
- analytics == null ? void 0 : analytics.close();
609
- traceloop2.forceFlush();
610
- }
611
- };
612
- };
439
+ // src/tracing/tracer-core.ts
440
+ var createTracing = (analytics, _apiUrl, _writeKey, _options) => ({
441
+ begin(traceContext) {
442
+ if (!traceContext.eventId) {
443
+ traceContext.eventId = v4_default();
444
+ }
445
+ return new NonLiveInteraction(
446
+ traceContext,
447
+ void 0,
448
+ // No traceId in stub
449
+ analytics
450
+ );
451
+ },
452
+ getActiveInteraction(eventId) {
453
+ return new NonLiveInteraction({ eventId }, void 0, analytics);
454
+ },
455
+ close() {
456
+ analytics == null ? void 0 : analytics.close();
457
+ }
458
+ });
459
+ var implementation = createTracing;
460
+ var tracing = (analytics, apiUrl, writeKey, options) => implementation(analytics, apiUrl, writeKey, options);
613
461
 
614
462
  // src/types.ts
615
463
  var import_zod2 = require("zod");
@@ -663,7 +511,9 @@ var Raindrop = class {
663
511
  this.redactPii = (_e = config.redactPii) != null ? _e : false;
664
512
  this.context = this.getContext();
665
513
  const url = new URL(this.apiUrl);
666
- this._tracing = tracing(this, url.origin, this.writeKey, { disableBatch: true });
514
+ this._tracing = tracing(this, url.origin, this.writeKey, {
515
+ disableBatch: false
516
+ });
667
517
  }
668
518
  formatEndpoint(endpoint) {
669
519
  if (endpoint) {
@@ -896,7 +746,7 @@ var Raindrop = class {
896
746
  }
897
747
  getContext() {
898
748
  const runtime = detectRuntime();
899
- const context2 = {
749
+ const context = {
900
750
  library: {
901
751
  name: package_default.name,
902
752
  version: package_default.version
@@ -906,9 +756,9 @@ var Raindrop = class {
906
756
  }
907
757
  };
908
758
  if (runtime === "node") {
909
- context2.metadata.nodeVersion = process.version;
759
+ context.metadata.nodeVersion = process.version;
910
760
  }
911
- return context2;
761
+ return context;
912
762
  }
913
763
  formatZodError(error) {
914
764
  return error.issues.map((issue) => `(path: ${issue.path.join(".")}): ${issue.message}`).join(", ");