@raindrop-ai/pi-agent 0.0.2 → 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Raindrop AI
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 CHANGED
@@ -15,7 +15,7 @@ import { getModel } from "@mariozechner/pi-ai";
15
15
  import { createRaindropPiAgent } from "@raindrop-ai/pi-agent";
16
16
 
17
17
  const raindrop = createRaindropPiAgent({
18
- writeKey: "rk_...",
18
+ writeKey: "your-write-key",
19
19
  userId: "user-123",
20
20
  });
21
21
 
@@ -1,101 +1,4 @@
1
- // package.json
2
- var package_default = {
3
- name: "@raindrop-ai/pi-agent",
4
- version: "0.0.2",
5
- description: "Raindrop observability for Pi Agent \u2014 automatic tracing via subscriber or pi-coding-agent extension",
6
- type: "module",
7
- license: "MIT",
8
- repository: {
9
- type: "git",
10
- url: "git+https://github.com/raindrop-ai/raindrop-js.git",
11
- directory: "packages/pi-agent"
12
- },
13
- homepage: "https://github.com/raindrop-ai/raindrop-js/tree/main/packages/pi-agent#readme",
14
- bugs: {
15
- url: "https://github.com/raindrop-ai/raindrop-js/issues"
16
- },
17
- keywords: [
18
- "pi-package",
19
- "raindrop",
20
- "pi-agent",
21
- "observability",
22
- "tracing"
23
- ],
24
- exports: {
25
- ".": {
26
- types: "./dist/index.d.ts",
27
- import: "./dist/index.js",
28
- require: "./dist/index.cjs"
29
- },
30
- "./extension": {
31
- types: "./dist/extension.d.ts",
32
- import: "./dist/extension.js",
33
- require: "./dist/extension.cjs"
34
- }
35
- },
36
- pi: {
37
- extensions: [
38
- "./dist/extension.js"
39
- ]
40
- },
41
- sideEffects: false,
42
- files: [
43
- "dist/**",
44
- "README.md"
45
- ],
46
- scripts: {
47
- build: "tsup",
48
- dev: "tsup --watch",
49
- clean: "rm -rf dist",
50
- test: "vitest run",
51
- "test:watch": "vitest"
52
- },
53
- peerDependencies: {
54
- "@mariozechner/pi-agent-core": ">=0.60.0",
55
- "@mariozechner/pi-coding-agent": ">=0.65.2"
56
- },
57
- peerDependenciesMeta: {
58
- "@mariozechner/pi-coding-agent": {
59
- optional: true
60
- }
61
- },
62
- devDependencies: {
63
- "@raindrop-ai/core": "workspace:*",
64
- "@mariozechner/pi-agent-core": "^0.66.0",
65
- "@mariozechner/pi-coding-agent": "^0.66.0",
66
- "@types/node": "^20.11.17",
67
- msw: "^2.12.7",
68
- tsup: "^8.5.1",
69
- typescript: "^5.7.3",
70
- vitest: "^2.1.9"
71
- },
72
- tsup: {
73
- entry: [
74
- "src/index.ts",
75
- "src/extension.ts"
76
- ],
77
- format: [
78
- "cjs",
79
- "esm"
80
- ],
81
- dts: {
82
- resolve: true
83
- },
84
- clean: true,
85
- noExternal: [
86
- "@raindrop-ai/core"
87
- ]
88
- },
89
- publishConfig: {
90
- access: "public"
91
- }
92
- };
93
-
94
- // src/version.ts
95
- var libraryName = package_default.name;
96
- var libraryVersion = package_default.version;
97
-
98
- // ../core/dist/chunk-4UCYIEH4.js
1
+ // ../core/dist/chunk-OLYXZCOK.js
99
2
  function getCrypto() {
100
3
  const c = globalThis.crypto;
101
4
  return c;
@@ -299,6 +202,91 @@ function buildExportTraceServiceRequest(spans, serviceName = "raindrop.core", se
299
202
  ]
300
203
  };
301
204
  }
205
+ var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
206
+ var WORKSHOP_ENV_VAR = "RAINDROP_WORKSHOP";
207
+ var DEFAULT_LOCAL_WORKSHOP_URL = "http://localhost:5899/v1/";
208
+ function readEnvVar(name) {
209
+ var _a;
210
+ try {
211
+ const env = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env;
212
+ if (env && typeof env[name] === "string" && env[name].length > 0) {
213
+ return env[name];
214
+ }
215
+ } catch (e) {
216
+ }
217
+ return void 0;
218
+ }
219
+ function readWorkshopEnv() {
220
+ const raw = readEnvVar(WORKSHOP_ENV_VAR);
221
+ if (raw === void 0) return void 0;
222
+ const trimmed = raw.trim();
223
+ if (trimmed.length === 0) return void 0;
224
+ if (/^https?:\/\//i.test(trimmed)) return { url: trimmed };
225
+ if (/^(1|true|yes|on)$/i.test(trimmed)) return "enable";
226
+ if (/^(0|false|no|off)$/i.test(trimmed)) return "disable";
227
+ return void 0;
228
+ }
229
+ function isLocalDevHost(hostname2) {
230
+ if (!hostname2) return false;
231
+ if (hostname2 === "localhost" || hostname2 === "127.0.0.1" || hostname2 === "0.0.0.0" || hostname2 === "::1") {
232
+ return true;
233
+ }
234
+ if (hostname2.endsWith(".localhost")) return true;
235
+ return false;
236
+ }
237
+ function readRuntimeHostname() {
238
+ try {
239
+ const loc = globalThis == null ? void 0 : globalThis.location;
240
+ if (loc && typeof loc.hostname === "string" && loc.hostname.length > 0) {
241
+ return loc.hostname;
242
+ }
243
+ } catch (e) {
244
+ }
245
+ return void 0;
246
+ }
247
+ function shouldAutoEnableLocalWorkshop() {
248
+ if (isLocalDevHost(readRuntimeHostname())) return true;
249
+ if (readEnvVar("NODE_ENV") === "development") return true;
250
+ return false;
251
+ }
252
+ function resolveLocalDebuggerBaseUrl(baseUrl) {
253
+ var _a, _b, _c;
254
+ if (baseUrl === null) return null;
255
+ if (typeof baseUrl === "string" && baseUrl.length > 0) {
256
+ return (_a = formatEndpoint(baseUrl)) != null ? _a : null;
257
+ }
258
+ const explicitUrlEnv = readEnvVar(LOCAL_DEBUGGER_ENV_VAR);
259
+ if (explicitUrlEnv) return (_b = formatEndpoint(explicitUrlEnv)) != null ? _b : null;
260
+ const workshopEnv = readWorkshopEnv();
261
+ if (workshopEnv === "disable") return null;
262
+ if (workshopEnv === "enable") return DEFAULT_LOCAL_WORKSHOP_URL;
263
+ if (workshopEnv && "url" in workshopEnv) return (_c = formatEndpoint(workshopEnv.url)) != null ? _c : null;
264
+ if (shouldAutoEnableLocalWorkshop()) return DEFAULT_LOCAL_WORKSHOP_URL;
265
+ return null;
266
+ }
267
+ function mirrorTraceExportToLocalDebugger(body, options = {}) {
268
+ var _a;
269
+ const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
270
+ if (!baseUrl) return;
271
+ void postJson(`${baseUrl}traces`, body, {}, {
272
+ maxAttempts: 1,
273
+ debug: (_a = options.debug) != null ? _a : false,
274
+ sdkName: options.sdkName
275
+ }).catch(() => {
276
+ });
277
+ }
278
+ function mirrorPartialEventToLocalDebugger(event, options = {}) {
279
+ var _a;
280
+ const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
281
+ if (!baseUrl) return;
282
+ const headers = options.writeKey ? { Authorization: `Bearer ${options.writeKey}` } : {};
283
+ void postJson(`${baseUrl}events/track_partial`, event, headers, {
284
+ maxAttempts: 1,
285
+ debug: (_a = options.debug) != null ? _a : false,
286
+ sdkName: options.sdkName
287
+ }).catch(() => {
288
+ });
289
+ }
302
290
  function mergePatches(target, source) {
303
291
  var _a, _b, _c, _d;
304
292
  const out = { ...target, ...source };
@@ -316,7 +304,7 @@ var EventShipper = class {
316
304
  this.sticky = /* @__PURE__ */ new Map();
317
305
  this.timers = /* @__PURE__ */ new Map();
318
306
  this.inFlight = /* @__PURE__ */ new Set();
319
- var _a, _b, _c, _d, _e, _f, _g;
307
+ var _a, _b, _c, _d, _e, _f, _g, _h;
320
308
  this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
321
309
  this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
322
310
  this.enabled = opts.enabled !== false;
@@ -325,11 +313,15 @@ var EventShipper = class {
325
313
  this.sdkName = (_d = opts.sdkName) != null ? _d : "core";
326
314
  this.prefix = `[raindrop-ai/${this.sdkName}]`;
327
315
  this.defaultEventName = (_e = opts.defaultEventName) != null ? _e : "ai_generation";
316
+ this.localDebuggerUrl = (_f = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _f : void 0;
317
+ if (this.debug && this.localDebuggerUrl) {
318
+ console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
319
+ }
328
320
  const isNode = typeof process !== "undefined" && typeof process.version === "string";
329
321
  this.context = {
330
322
  library: {
331
- name: (_f = opts.libraryName) != null ? _f : "@raindrop-ai/core",
332
- version: (_g = opts.libraryVersion) != null ? _g : "0.0.0"
323
+ name: (_g = opts.libraryName) != null ? _g : "@raindrop-ai/core",
324
+ version: (_h = opts.libraryVersion) != null ? _h : "0.0.0"
333
325
  },
334
326
  metadata: {
335
327
  jsRuntime: isNode ? "node" : "web",
@@ -415,6 +407,7 @@ var EventShipper = class {
415
407
  }
416
408
  }
417
409
  ];
410
+ if (!this.writeKey) return;
418
411
  const url = `${this.baseUrl}signals/track`;
419
412
  try {
420
413
  await postJson(url, body, this.authHeaders(), {
@@ -445,6 +438,7 @@ var EventShipper = class {
445
438
  traits: (_a = user.traits) != null ? _a : {}
446
439
  };
447
440
  });
441
+ if (!this.writeKey) return;
448
442
  if (body.length === 0) return;
449
443
  const url = `${this.baseUrl}users/identify`;
450
444
  try {
@@ -521,6 +515,18 @@ var EventShipper = class {
521
515
  endpoint: url
522
516
  });
523
517
  }
518
+ if (this.localDebuggerUrl) {
519
+ mirrorPartialEventToLocalDebugger(payload, {
520
+ baseUrl: this.localDebuggerUrl,
521
+ writeKey: this.writeKey,
522
+ debug: this.debug,
523
+ sdkName: this.sdkName
524
+ });
525
+ }
526
+ if (!this.writeKey) {
527
+ if (!isPending) this.sticky.delete(eventId);
528
+ return;
529
+ }
524
530
  const p = postJson(url, payload, this.authHeaders(), {
525
531
  maxAttempts: 3,
526
532
  debug: this.debug,
@@ -545,28 +551,11 @@ var EventShipper = class {
545
551
  }
546
552
  }
547
553
  };
548
- var LOCAL_DEBUGGER_ENV_VAR = "RAINDROP_LOCAL_DEBUGGER";
549
- function resolveLocalDebuggerBaseUrl(baseUrl) {
550
- var _a, _b, _c;
551
- const resolved = (_b = baseUrl != null ? baseUrl : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a[LOCAL_DEBUGGER_ENV_VAR] : void 0) != null ? _b : null;
552
- return resolved ? (_c = formatEndpoint(resolved)) != null ? _c : null : null;
553
- }
554
- function mirrorTraceExportToLocalDebugger(body, options = {}) {
555
- var _a;
556
- const baseUrl = resolveLocalDebuggerBaseUrl(options.baseUrl);
557
- if (!baseUrl) return;
558
- void postJson(`${baseUrl}traces`, body, {}, {
559
- maxAttempts: 1,
560
- debug: (_a = options.debug) != null ? _a : false,
561
- sdkName: options.sdkName
562
- }).catch(() => {
563
- });
564
- }
565
554
  var TraceShipper = class {
566
555
  constructor(opts) {
567
556
  this.queue = [];
568
557
  this.inFlight = /* @__PURE__ */ new Set();
569
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
558
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
570
559
  this.writeKey = (_a = opts.writeKey) == null ? void 0 : _a.trim();
571
560
  this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
572
561
  this.enabled = opts.enabled !== false;
@@ -579,12 +568,9 @@ var TraceShipper = class {
579
568
  this.prefix = `[raindrop-ai/${this.sdkName}]`;
580
569
  this.serviceName = (_g = opts.serviceName) != null ? _g : "raindrop.core";
581
570
  this.serviceVersion = (_h = opts.serviceVersion) != null ? _h : "0.0.0";
582
- const localDebugger = typeof process !== "undefined" ? (_i = process.env) == null ? void 0 : _i.RAINDROP_LOCAL_DEBUGGER : void 0;
583
- if (localDebugger) {
584
- this.localDebuggerUrl = (_j = resolveLocalDebuggerBaseUrl(localDebugger)) != null ? _j : void 0;
585
- if (this.debug) {
586
- console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
587
- }
571
+ this.localDebuggerUrl = (_i = resolveLocalDebuggerBaseUrl(opts.localDebuggerUrl)) != null ? _i : void 0;
572
+ if (this.debug && this.localDebuggerUrl) {
573
+ console.log(`${this.prefix} Local debugger mirroring: ${this.localDebuggerUrl}`);
588
574
  }
589
575
  }
590
576
  isDebugEnabled() {
@@ -712,6 +698,7 @@ var TraceShipper = class {
712
698
  }
713
699
  while (this.queue.length > 0) {
714
700
  const batch = this.queue.splice(0, this.maxBatchSize);
701
+ if (!this.writeKey) continue;
715
702
  const body = buildExportTraceServiceRequest(batch, this.serviceName, this.serviceVersion);
716
703
  const url = `${this.baseUrl}traces`;
717
704
  if (this.debug) {
@@ -754,6 +741,103 @@ var TraceShipper = class {
754
741
  import { AsyncLocalStorage } from "async_hooks";
755
742
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
756
743
 
744
+ // package.json
745
+ var package_default = {
746
+ name: "@raindrop-ai/pi-agent",
747
+ version: "0.0.3",
748
+ description: "Raindrop observability for Pi Agent \u2014 automatic tracing via subscriber or pi-coding-agent extension",
749
+ type: "module",
750
+ license: "MIT",
751
+ repository: {
752
+ type: "git",
753
+ url: "git+https://github.com/raindrop-ai/raindrop-js.git",
754
+ directory: "packages/pi-agent"
755
+ },
756
+ homepage: "https://github.com/raindrop-ai/raindrop-js/tree/main/packages/pi-agent#readme",
757
+ bugs: {
758
+ url: "https://github.com/raindrop-ai/raindrop-js/issues"
759
+ },
760
+ keywords: [
761
+ "pi-package",
762
+ "raindrop",
763
+ "pi-agent",
764
+ "observability",
765
+ "tracing"
766
+ ],
767
+ exports: {
768
+ ".": {
769
+ types: "./dist/index.d.ts",
770
+ import: "./dist/index.js",
771
+ require: "./dist/index.cjs"
772
+ },
773
+ "./extension": {
774
+ types: "./dist/extension.d.ts",
775
+ import: "./dist/extension.js",
776
+ require: "./dist/extension.cjs"
777
+ }
778
+ },
779
+ pi: {
780
+ extensions: [
781
+ "./dist/extension.js"
782
+ ]
783
+ },
784
+ sideEffects: false,
785
+ files: [
786
+ "dist/**",
787
+ "README.md"
788
+ ],
789
+ scripts: {
790
+ build: "tsup",
791
+ dev: "tsup --watch",
792
+ clean: "rm -rf dist",
793
+ test: "vitest run",
794
+ "test:watch": "vitest"
795
+ },
796
+ peerDependencies: {
797
+ "@mariozechner/pi-agent-core": ">=0.60.0",
798
+ "@mariozechner/pi-coding-agent": ">=0.65.2"
799
+ },
800
+ peerDependenciesMeta: {
801
+ "@mariozechner/pi-coding-agent": {
802
+ optional: true
803
+ }
804
+ },
805
+ devDependencies: {
806
+ "@raindrop-ai/core": "workspace:*",
807
+ "@mariozechner/pi-agent-core": "^0.66.0",
808
+ "@mariozechner/pi-coding-agent": "^0.66.0",
809
+ "@types/node": "^20.11.17",
810
+ msw: "^2.12.7",
811
+ tsup: "^8.5.1",
812
+ typescript: "^5.7.3",
813
+ vitest: "^2.1.9"
814
+ },
815
+ tsup: {
816
+ entry: [
817
+ "src/index.ts",
818
+ "src/extension.ts"
819
+ ],
820
+ format: [
821
+ "cjs",
822
+ "esm"
823
+ ],
824
+ dts: {
825
+ resolve: true
826
+ },
827
+ clean: true,
828
+ noExternal: [
829
+ "@raindrop-ai/core"
830
+ ]
831
+ },
832
+ publishConfig: {
833
+ access: "public"
834
+ }
835
+ };
836
+
837
+ // src/version.ts
838
+ var libraryName = package_default.name;
839
+ var libraryVersion = package_default.version;
840
+
757
841
  // src/internal/shipper.ts
758
842
  var EventShipper2 = class extends EventShipper {
759
843
  constructor(opts) {
@@ -901,12 +985,13 @@ function getUsername() {
901
985
  }
902
986
 
903
987
  export {
904
- libraryVersion,
905
988
  randomUUID,
906
989
  generateId,
907
990
  nowUnixNanoString,
908
991
  attrString,
909
992
  attrInt,
993
+ resolveLocalDebuggerBaseUrl,
994
+ libraryVersion,
910
995
  EventShipper2 as EventShipper,
911
996
  TraceShipper2 as TraceShipper,
912
997
  extractUserText,