repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import type { |
| #2 | TelemetryClient, |
| #3 | TelemetryInstance, |
| #4 | TelemetryEventData, |
| #5 | } from "./telemetry.types"; |
| #6 | |
| #7 | let version = "2.1.34"; |
| #8 | |
| #9 | // Safely check for process.env in different environments |
| #10 | let MEM0_TELEMETRY = true; |
| #11 | try { |
| #12 | MEM0_TELEMETRY = process?.env?.MEM0_TELEMETRY === "false" ? false : true; |
| #13 | } catch (error) {} |
| #14 | const POSTHOG_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX"; |
| #15 | const POSTHOG_HOST = "https://us.i.posthog.com/i/v0/e/"; |
| #16 | |
| #17 | class UnifiedTelemetry implements TelemetryClient { |
| #18 | private apiKey: string; |
| #19 | private host: string; |
| #20 | |
| #21 | constructor(projectApiKey: string, host: string) { |
| #22 | this.apiKey = projectApiKey; |
| #23 | this.host = host; |
| #24 | } |
| #25 | |
| #26 | async captureEvent(distinctId: string, eventName: string, properties = {}) { |
| #27 | if (!MEM0_TELEMETRY) return; |
| #28 | |
| #29 | const eventProperties = { |
| #30 | client_version: version, |
| #31 | timestamp: new Date().toISOString(), |
| #32 | ...properties, |
| #33 | $process_person_profile: |
| #34 | distinctId === "anonymous" || distinctId === "anonymous-supabase" |
| #35 | ? false |
| #36 | : true, |
| #37 | $lib: "posthog-node", |
| #38 | }; |
| #39 | |
| #40 | const payload = { |
| #41 | api_key: this.apiKey, |
| #42 | distinct_id: distinctId, |
| #43 | event: eventName, |
| #44 | properties: eventProperties, |
| #45 | }; |
| #46 | |
| #47 | try { |
| #48 | const response = await fetch(this.host, { |
| #49 | method: "POST", |
| #50 | headers: { |
| #51 | "Content-Type": "application/json", |
| #52 | }, |
| #53 | body: JSON.stringify(payload), |
| #54 | }); |
| #55 | |
| #56 | if (!response.ok) { |
| #57 | console.error("Telemetry event capture failed:", await response.text()); |
| #58 | } |
| #59 | } catch (error) { |
| #60 | console.error("Telemetry event capture failed:", error); |
| #61 | } |
| #62 | } |
| #63 | |
| #64 | async shutdown() { |
| #65 | // No shutdown needed for direct API calls |
| #66 | } |
| #67 | } |
| #68 | |
| #69 | const telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST); |
| #70 | |
| #71 | async function captureClientEvent( |
| #72 | eventName: string, |
| #73 | instance: TelemetryInstance, |
| #74 | additionalData: Record<string, any> = {}, |
| #75 | ) { |
| #76 | if (!instance.telemetryId) { |
| #77 | console.warn("No telemetry ID found for instance"); |
| #78 | return; |
| #79 | } |
| #80 | |
| #81 | const eventData: TelemetryEventData = { |
| #82 | function: `${instance.constructor.name}`, |
| #83 | method: eventName, |
| #84 | api_host: instance.host, |
| #85 | timestamp: new Date().toISOString(), |
| #86 | client_version: version, |
| #87 | client_source: "nodejs", |
| #88 | ...additionalData, |
| #89 | }; |
| #90 | |
| #91 | await telemetry.captureEvent( |
| #92 | instance.telemetryId, |
| #93 | `mem0.${eventName}`, |
| #94 | eventData, |
| #95 | ); |
| #96 | } |
| #97 | |
| #98 | export { telemetry, captureClientEvent }; |
| #99 |