mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
Decomplect the half-finished fork so the dependency graph has ONE source with no posthog package identity, living under github.com/hanzoinsights. LAYER 1 (package identity): rename straggler package.json names — @posthog/next->@hanzo/insights-next (Next.js SDK; distinct from the existing @hanzo/insights-nextjs config helper), @posthog/mcp->@hanzo/insights-mcp, @posthog/plugin-utils->@hanzo/insights-plugin-utils, @posthog/react-slim->@hanzo/react-slim, @posthog-tooling/release-> @hanzo/insights-tooling-release, and the @posthog/rrweb* family->@hanzo/rrweb* (matching the already-published @hanzo/rrweb*@0.0.47 + minimumReleaseAgeExclude). Repoint every repository.url/homepage/bugs to github.com/hanzoinsights/insights-js and rebrand the PostHog author/description identity to Hanzo AI. LAYER 2 (cross-package imports): rewrite every internal @posthog/* import to its @hanzo/insights*|@hanzo/rrweb* equivalent and the bare module specifiers posthog-js->@hanzo/insights, posthog-node->@hanzo/insights-node, mirrored in package.json deps + the pnpm-lock importer keys. Result: 0 @posthog/* specifiers in packages/tooling/examples/playground source. LAYER 4 (wire protocol) PRESERVED: window.posthog global, ph_* keys, $-prefixed event names, distinct_id, /decide, /e/, /flags, and the __PosthogExtensions__ hook are left unchanged — the Insights server expects them. Also repair pre-existing fork merge damage that blocked compilation (unrelated to naming; identical to origin/main): restore the @hanzo/insights-core ./process subpath (spawn-local/utils, re-matching the published artifact), the lost constructor/var declarations in core + node clients, the mangled external-scripts-loader, the missing TreeShakeable/isPlainError imports, the DeviceId enum member, and stale ../posthog-core-stateless module paths. 26/34 turbo build tasks now pass; remaining failures (browser/react-native and their dependents) are pre-existing fork damage, not rebrand-caused.
73 lines
2.7 KiB
TypeScript
73 lines
2.7 KiB
TypeScript
/** Google Gemini chat with tool calling, tracked by PostHog via OpenTelemetry. */
|
|
|
|
import { NodeSDK } from '@opentelemetry/sdk-node'
|
|
import { resourceFromAttributes } from '@opentelemetry/resources'
|
|
import { PostHogSpanProcessor } from '@hanzo/insights-ai/otel'
|
|
import { GenAIInstrumentation } from '@traceloop/instrumentation-google-generativeai'
|
|
import { GoogleGenAI, Type } from '@google/genai'
|
|
import type { FunctionDeclaration } from '@google/genai'
|
|
|
|
const sdk = new NodeSDK({
|
|
resource: resourceFromAttributes({
|
|
'service.name': 'example-gemini-app',
|
|
'posthog.distinct_id': 'example-user',
|
|
foo: 'bar',
|
|
conversation_id: 'abc-123',
|
|
}),
|
|
spanProcessors: [
|
|
new PostHogSpanProcessor({
|
|
apiKey: process.env.POSTHOG_API_KEY!,
|
|
host: process.env.POSTHOG_HOST || 'https://us.i.posthog.com',
|
|
}),
|
|
],
|
|
instrumentations: [new GenAIInstrumentation()],
|
|
})
|
|
sdk.start()
|
|
|
|
const weatherTool: FunctionDeclaration = {
|
|
name: 'get_weather',
|
|
description: 'Get current weather for a location',
|
|
parameters: {
|
|
type: Type.OBJECT,
|
|
properties: {
|
|
latitude: { type: Type.NUMBER },
|
|
longitude: { type: Type.NUMBER },
|
|
location_name: { type: Type.STRING },
|
|
},
|
|
required: ['latitude', 'longitude', 'location_name'],
|
|
},
|
|
}
|
|
|
|
async function getWeather(latitude: number, longitude: number, locationName: string): Promise<string> {
|
|
const url = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,relative_humidity_2m,wind_speed_10m`
|
|
const resp = await fetch(url)
|
|
const data = await resp.json()
|
|
const current = data.current
|
|
return `Weather in ${locationName}: ${current.temperature_2m}°C, humidity ${current.relative_humidity_2m}%, wind ${current.wind_speed_10m} km/h`
|
|
}
|
|
|
|
async function main() {
|
|
const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY! })
|
|
|
|
const response = await client.models.generateContent({
|
|
model: 'gemini-2.5-flash',
|
|
contents: "What's the weather like in Dublin, Ireland?",
|
|
config: {
|
|
tools: [{ functionDeclarations: [weatherTool] }],
|
|
},
|
|
})
|
|
|
|
// In production, send tool results back to the model for a final response.
|
|
for (const part of response.candidates?.[0]?.content?.parts ?? []) {
|
|
if (part.text) {
|
|
console.log(part.text)
|
|
} else if (part.functionCall) {
|
|
const args = part.functionCall.args as { latitude: number; longitude: number; location_name: string }
|
|
const result = await getWeather(args.latitude, args.longitude, args.location_name)
|
|
console.log(result)
|
|
}
|
|
}
|
|
}
|
|
|
|
main().finally(() => sdk.shutdown())
|