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 | // @ts-nocheck |
| #2 | import type { TelemetryClient, TelemetryOptions } from "./telemetry.types"; |
| #3 | |
| #4 | let version = "2.1.36"; |
| #5 | |
| #6 | // Safely check for process.env in different environments |
| #7 | let MEM0_TELEMETRY = true; |
| #8 | try { |
| #9 | MEM0_TELEMETRY = process?.env?.MEM0_TELEMETRY === "false" ? false : true; |
| #10 | } catch (error) {} |
| #11 | const POSTHOG_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX"; |
| #12 | const POSTHOG_HOST = "https://us.i.posthog.com/i/v0/e/"; |
| #13 | |
| #14 | // Simple hash function using random strings |
| #15 | function generateHash(input: string): string { |
| #16 | const randomStr = |
| #17 | Math.random().toString(36).substring(2, 15) + |
| #18 | Math.random().toString(36).substring(2, 15); |
| #19 | return randomStr; |
| #20 | } |
| #21 | |
| #22 | class UnifiedTelemetry implements TelemetryClient { |
| #23 | private apiKey: string; |
| #24 | private host: string; |
| #25 | |
| #26 | constructor(projectApiKey: string, host: string) { |
| #27 | this.apiKey = projectApiKey; |
| #28 | this.host = host; |
| #29 | } |
| #30 | |
| #31 | async captureEvent(distinctId: string, eventName: string, properties = {}) { |
| #32 | if (!MEM0_TELEMETRY) return; |
| #33 | |
| #34 | const eventProperties = { |
| #35 | client_version: version, |
| #36 | timestamp: new Date().toISOString(), |
| #37 | ...properties, |
| #38 | $process_person_profile: false, |
| #39 | $lib: "posthog-node", |
| #40 | }; |
| #41 | |
| #42 | const payload = { |
| #43 | api_key: this.apiKey, |
| #44 | distinct_id: distinctId, |
| #45 | event: eventName, |
| #46 | properties: eventProperties, |
| #47 | }; |
| #48 | |
| #49 | try { |
| #50 | const response = await fetch(this.host, { |
| #51 | method: "POST", |
| #52 | headers: { |
| #53 | "Content-Type": "application/json", |
| #54 | }, |
| #55 | body: JSON.stringify(payload), |
| #56 | }); |
| #57 | |
| #58 | if (!response.ok) { |
| #59 | console.error("Telemetry event capture failed:", await response.text()); |
| #60 | } |
| #61 | } catch (error) { |
| #62 | console.error("Telemetry event capture failed:", error); |
| #63 | } |
| #64 | } |
| #65 | |
| #66 | async shutdown() { |
| #67 | // No shutdown needed for direct API calls |
| #68 | } |
| #69 | } |
| #70 | |
| #71 | const telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST); |
| #72 | |
| #73 | async function captureClientEvent( |
| #74 | eventName: string, |
| #75 | instance: any, |
| #76 | additionalData = {}, |
| #77 | ) { |
| #78 | if (!instance.telemetryId) { |
| #79 | console.warn("No telemetry ID found for instance"); |
| #80 | return; |
| #81 | } |
| #82 | |
| #83 | const eventData = { |
| #84 | function: `${instance.constructor.name}`, |
| #85 | method: eventName, |
| #86 | api_host: instance.host, |
| #87 | timestamp: new Date().toISOString(), |
| #88 | client_version: version, |
| #89 | keys: additionalData?.keys || [], |
| #90 | ...additionalData, |
| #91 | }; |
| #92 | |
| #93 | await telemetry.captureEvent( |
| #94 | instance.telemetryId, |
| #95 | `client.${eventName}`, |
| #96 | eventData, |
| #97 | ); |
| #98 | } |
| #99 | |
| #100 | export { telemetry, captureClientEvent, generateHash }; |
| #101 |