@revenium/google-core
v0.2.3
Published
Core utilities for Revenium Google middleware packages
Readme
@revenium/google-core
Core utilities and shared functionality for Revenium Google middleware packages.
Overview
This package provides the foundational components used by @revenium/google-genai and @revenium/google-vertex middleware packages. It is designed as an internal dependency and is not intended for direct use in applications.
What's Included
- Logger - Configurable logging system for middleware operations
- Metering - Core metering and tracking functionality
- Revenium Client - HTTP client for Revenium API communication
- Types - Shared TypeScript interfaces and types
- Utilities - Common helper functions and tools
Installation
This package is automatically installed as a dependency when you install @revenium/google-genai or @revenium/google-vertex:
npm install @revenium/google-genai
# or
npm install @revenium/google-vertexYou typically do not need to install this package directly.
Usage
This package is consumed internally by the middleware packages. If you're building applications, you should use @revenium/google-genai or @revenium/google-vertex instead.
For middleware package developers:
import { Logger, Metering, ReveniumClient } from "@revenium/google-core";Tool Metering
Track execution of custom tools and external API calls with automatic timing, error handling, and metadata collection.
Quick Example
import { meterTool, setToolContext } from "@revenium/google-core";
// Set context once (propagates to all tool calls)
setToolContext({
agent: "my-agent",
traceId: "session-123"
});
// Wrap tool execution
const result = await meterTool("weather-api", async () => {
return await fetch("https://api.example.com/weather");
}, {
operation: "get_forecast",
outputFields: ["temperature", "humidity"]
});
// Automatically extracts temperature & humidity from resultFunctions
meterTool(toolId, fn, metadata?)
- Wraps a function with automatic metering
- Captures duration, success/failure, and errors
- Returns function result unchanged
reportToolCall(toolId, report)
- Manually report a tool call that was already executed
- Useful when wrapping isn't possible
Context Management
setToolContext(ctx)- Set context for all subsequent tool callsgetToolContext()- Get current contextclearToolContext()- Clear contextrunWithToolContext(ctx, fn)- Run function with scoped context
Metadata Options
| Field | Description |
|-------|-------------|
| operation | Tool operation name (e.g., "search", "scrape") |
| outputFields | Array of field names to auto-extract from result |
| usageMetadata | Custom metrics (e.g., tokens, results count) |
| agent, traceId, etc. | Context fields (inherited from setToolContext) |
Configuration
The core package respects the following environment variables:
REVENIUM_METERING_API_KEY- API key for Revenium serviceREVENIUM_METERING_BASE_URL- Base URL for Revenium API (default: https://api.revenium.ai)REVENIUM_LOG_LEVEL- Logging level (DEBUG, INFO, WARN, ERROR)
Package Information
- Version: 0.1.1
- License: MIT
- Repository: revenium-middleware-google-node
Related Packages
- @revenium/google-genai - Google AI middleware
- @revenium/google-vertex - Vertex AI middleware
Documentation
For complete documentation, see:
Support
For issues, feature requests, or contributions:
Contributing
See CONTRIBUTING.md
Security
See SECURITY.md
