@revenium/claude-code-metering 0.1.4 → 0.1.6
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/.env.example +15 -0
- package/.eslintrc.js +24 -0
- package/.github/workflows/branch-bypass-alert.yml +68 -0
- package/CODE_OF_CONDUCT.md +57 -0
- package/CONTRIBUTING.md +73 -0
- package/README.md +57 -3
- package/SECURITY.md +46 -0
- package/dist/cli/commands/setup.js +3 -1
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +4 -1
- package/dist/core/api/client.js.map +1 -1
- package/dist/core/tool-context.d.ts +6 -0
- package/dist/core/tool-context.d.ts.map +1 -0
- package/dist/core/tool-context.js +21 -0
- package/dist/core/tool-context.js.map +1 -0
- package/dist/core/tool-tracker.d.ts +4 -0
- package/dist/core/tool-tracker.d.ts.map +1 -0
- package/dist/core/tool-tracker.js +156 -0
- package/dist/core/tool-tracker.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +15 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/tool-metering.d.ts +36 -0
- package/dist/types/tool-metering.d.ts.map +1 -0
- package/dist/types/tool-metering.js +3 -0
- package/dist/types/tool-metering.js.map +1 -0
- package/docs/research/settings-json-telemetry-findings.md +171 -0
- package/examples/README.md +114 -0
- package/examples/validation/validate-installation.sh +212 -0
- package/package.json +4 -10
- package/public-allowlist-node.txt +7 -0
- package/src/cli/commands/backfill.ts +865 -0
- package/src/cli/commands/setup.ts +254 -0
- package/src/cli/commands/status.ts +108 -0
- package/src/cli/commands/test.ts +91 -0
- package/src/cli/index.ts +103 -0
- package/src/core/api/client.ts +194 -0
- package/src/core/config/loader.ts +217 -0
- package/src/core/config/validator.ts +142 -0
- package/src/core/config/writer.ts +212 -0
- package/src/core/shell/detector.ts +92 -0
- package/src/core/shell/profile-updater.ts +131 -0
- package/src/core/tool-context.ts +23 -0
- package/src/core/tool-tracker.ts +204 -0
- package/src/index.ts +12 -0
- package/src/types/index.ts +110 -0
- package/src/types/tool-metering.ts +38 -0
- package/src/utils/constants.ts +80 -0
- package/src/utils/hashing.ts +35 -0
- package/src/utils/masking.ts +32 -0
- package/tests/integration/cli-commands.test.ts +158 -0
- package/tests/unit/backfill-command.test.ts +366 -0
- package/tests/unit/backfill-helpers.test.ts +397 -0
- package/tests/unit/backfill-parse.test.ts +276 -0
- package/tests/unit/backfill-stream.test.ts +147 -0
- package/tests/unit/backfill.test.ts +344 -0
- package/tests/unit/cli-index.test.ts +193 -0
- package/tests/unit/client.test.ts +195 -0
- package/tests/unit/detector.test.ts +247 -0
- package/tests/unit/hashing.test.ts +121 -0
- package/tests/unit/loader.test.ts +272 -0
- package/tests/unit/masking.test.ts +46 -0
- package/tests/unit/profile-updater.test.ts +146 -0
- package/tests/unit/setup.test.ts +557 -0
- package/tests/unit/status.test.ts +149 -0
- package/tests/unit/test.test.ts +165 -0
- package/tests/unit/validator.test.ts +211 -0
- package/tests/unit/writer.test.ts +176 -0
- package/tsconfig.json +20 -0
package/.env.example
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Revenium Claude Code Metering - Environment Variables
|
|
2
|
+
# Copy this file to .env and fill in your values
|
|
3
|
+
|
|
4
|
+
# Your Revenium API key (required)
|
|
5
|
+
# Get this from https://app.revenium.ai
|
|
6
|
+
REVENIUM_API_KEY=hak_your_api_key_here
|
|
7
|
+
|
|
8
|
+
# Optional: Email for usage attribution
|
|
9
|
+
REVENIUM_SUBSCRIBER_EMAIL=developer@company.com
|
|
10
|
+
|
|
11
|
+
# Optional: Organization ID for team tracking
|
|
12
|
+
REVENIUM_ORGANIZATION_ID=my-org
|
|
13
|
+
|
|
14
|
+
# Optional: Product ID for product-level attribution
|
|
15
|
+
REVENIUM_PRODUCT_ID=my-product
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
parserOptions: {
|
|
5
|
+
project: './tsconfig.json',
|
|
6
|
+
ecmaVersion: 2022,
|
|
7
|
+
sourceType: 'module',
|
|
8
|
+
},
|
|
9
|
+
plugins: ['@typescript-eslint'],
|
|
10
|
+
extends: [
|
|
11
|
+
'eslint:recommended',
|
|
12
|
+
'plugin:@typescript-eslint/recommended',
|
|
13
|
+
],
|
|
14
|
+
env: {
|
|
15
|
+
node: true,
|
|
16
|
+
es2022: true,
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
20
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
21
|
+
},
|
|
22
|
+
ignorePatterns: ['dist', 'node_modules', '*.js'],
|
|
23
|
+
};
|
|
24
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
name: Branch Protection Bypass Alert
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, develop, enterprise]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
check-bypass:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Check if push was via PR merge
|
|
12
|
+
id: check
|
|
13
|
+
env:
|
|
14
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
15
|
+
run: |
|
|
16
|
+
echo "Checking commit ${{ github.sha }}..."
|
|
17
|
+
|
|
18
|
+
# Retry logic to handle GitHub API propagation delay
|
|
19
|
+
# The push event can trigger before the PR merge is fully indexed
|
|
20
|
+
MAX_RETRIES=3
|
|
21
|
+
RETRY_DELAY=2
|
|
22
|
+
|
|
23
|
+
for i in $(seq 1 $MAX_RETRIES); do
|
|
24
|
+
MERGED_AT=$(gh api "repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \
|
|
25
|
+
--jq '.[0].merged_at // "null"' 2>/dev/null) || MERGED_AT="error"
|
|
26
|
+
|
|
27
|
+
if [ "$MERGED_AT" != "null" ] && [ "$MERGED_AT" != "error" ] && [ -n "$MERGED_AT" ]; then
|
|
28
|
+
PR_NUM=$(gh api "repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \
|
|
29
|
+
--jq '.[0].number' 2>/dev/null)
|
|
30
|
+
echo "✓ Commit came from merged PR #$PR_NUM (merged at $MERGED_AT)"
|
|
31
|
+
echo "skip=true" >> $GITHUB_OUTPUT
|
|
32
|
+
exit 0
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
if [ $i -lt $MAX_RETRIES ]; then
|
|
36
|
+
echo "Attempt $i: No merged PR found yet, retrying in ${RETRY_DELAY}s..."
|
|
37
|
+
sleep $RETRY_DELAY
|
|
38
|
+
fi
|
|
39
|
+
done
|
|
40
|
+
|
|
41
|
+
# All retries exhausted
|
|
42
|
+
if [ "$MERGED_AT" = "error" ]; then
|
|
43
|
+
echo "⚠ API error after $MAX_RETRIES attempts"
|
|
44
|
+
else
|
|
45
|
+
echo "⚠ No merged PR found after $MAX_RETRIES attempts - possible direct push or bypass"
|
|
46
|
+
fi
|
|
47
|
+
echo "skip=false" >> $GITHUB_OUTPUT
|
|
48
|
+
|
|
49
|
+
- name: Send Slack alert
|
|
50
|
+
if: steps.check.outputs.skip == 'false'
|
|
51
|
+
env:
|
|
52
|
+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
|
|
53
|
+
SLACK_USER_ID: ${{ secrets.SLACK_ADMIN_USER_ID }}
|
|
54
|
+
run: |
|
|
55
|
+
# Escape special characters for JSON
|
|
56
|
+
COMMIT_MSG=$(cat << 'MSGEOF'
|
|
57
|
+
${{ github.event.head_commit.message }}
|
|
58
|
+
MSGEOF
|
|
59
|
+
)
|
|
60
|
+
ESCAPED_MSG=$(echo "$COMMIT_MSG" | head -1 | sed 's/\\/\\\\/g; s/"/\\"/g; s/\t/\\t/g' | tr -d '\n\r')
|
|
61
|
+
|
|
62
|
+
curl -s -X POST https://slack.com/api/chat.postMessage \
|
|
63
|
+
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d "{
|
|
66
|
+
\"channel\": \"$SLACK_USER_ID\",
|
|
67
|
+
\"text\": \":warning: *Branch Protection Bypass Detected*\\n\\n*Repo:* ${{ github.repository }}\\n*Branch:* ${{ github.ref_name }}\\n*Pusher:* ${{ github.actor }}\\n*Commit:* \`${{ github.sha }}\`\\n*Message:* ${ESCAPED_MSG}\\n\\n<${{ github.event.head_commit.url }}|View Commit>\"
|
|
68
|
+
}"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
5
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
6
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
7
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
8
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
9
|
+
identity and orientation.
|
|
10
|
+
|
|
11
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
12
|
+
diverse, inclusive, and healthy community.
|
|
13
|
+
|
|
14
|
+
## Our Standards
|
|
15
|
+
Examples of behavior that contributes to a positive environment include:
|
|
16
|
+
- Demonstrating empathy and kindness toward other people
|
|
17
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
18
|
+
- Giving and gracefully accepting constructive feedback
|
|
19
|
+
- Accepting responsibility and apologizing to those affected by mistakes
|
|
20
|
+
- Focusing on what is best for the community
|
|
21
|
+
|
|
22
|
+
Examples of unacceptable behavior include:
|
|
23
|
+
- The use of sexualized language or imagery, and sexual attention or advances
|
|
24
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
25
|
+
- Public or private harassment
|
|
26
|
+
- Publishing others' private information without explicit permission
|
|
27
|
+
- Other conduct which could reasonably be considered inappropriate
|
|
28
|
+
|
|
29
|
+
## Enforcement Responsibilities
|
|
30
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
31
|
+
acceptable behavior and will take appropriate and fair corrective action.
|
|
32
|
+
|
|
33
|
+
## Scope
|
|
34
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
35
|
+
an individual is officially representing the project in public spaces.
|
|
36
|
+
|
|
37
|
+
## Enforcement
|
|
38
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
39
|
+
reported by contacting the project team at **support@revenium.io**.
|
|
40
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
41
|
+
|
|
42
|
+
The project team is obligated to respect the privacy and security of the
|
|
43
|
+
reporter of any incident.
|
|
44
|
+
|
|
45
|
+
## Enforcement Guidelines
|
|
46
|
+
Community leaders will follow these guidelines in determining the consequences:
|
|
47
|
+
1. **Correction** – Private, written warning.
|
|
48
|
+
2. **Warning** – Clear and public warning of violation.
|
|
49
|
+
3. **Temporary Ban** – Temporary ban from community interaction.
|
|
50
|
+
4. **Permanent Ban** – Permanent removal from community interaction.
|
|
51
|
+
|
|
52
|
+
## Attribution
|
|
53
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
54
|
+
version 2.1, available at
|
|
55
|
+
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.
|
|
56
|
+
|
|
57
|
+
[homepage]: https://www.contributor-covenant.org
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to @revenium/claude-code-metering!
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
1. Fork the repository and create a feature branch
|
|
8
|
+
2. Install dependencies: `npm install`
|
|
9
|
+
3. Make your changes following existing code patterns
|
|
10
|
+
4. Run tests: `npm test`
|
|
11
|
+
5. Build: `npm run build`
|
|
12
|
+
6. Submit a pull request with a clear description
|
|
13
|
+
|
|
14
|
+
## What to Contribute
|
|
15
|
+
|
|
16
|
+
- Bug fixes and improvements
|
|
17
|
+
- New CLI commands
|
|
18
|
+
- Documentation updates
|
|
19
|
+
- Test coverage improvements
|
|
20
|
+
- Shell profile detection improvements
|
|
21
|
+
|
|
22
|
+
## Development Setup
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Clone your fork
|
|
26
|
+
git clone https://github.com/YOUR-USERNAME/revenium-claude-code-sdk.git
|
|
27
|
+
cd revenium-claude-code-sdk
|
|
28
|
+
|
|
29
|
+
# Install dependencies
|
|
30
|
+
npm install
|
|
31
|
+
|
|
32
|
+
# Run in development mode
|
|
33
|
+
npm run dev
|
|
34
|
+
|
|
35
|
+
# Run tests
|
|
36
|
+
npm test
|
|
37
|
+
|
|
38
|
+
# Build for production
|
|
39
|
+
npm run build
|
|
40
|
+
|
|
41
|
+
# Test CLI locally
|
|
42
|
+
npm run cli -- setup --help
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Code Guidelines
|
|
46
|
+
|
|
47
|
+
- Follow the existing TypeScript code style
|
|
48
|
+
- Use async/await for asynchronous operations
|
|
49
|
+
- Include JSDoc comments for public APIs
|
|
50
|
+
- Keep CLI output user-friendly with chalk colors
|
|
51
|
+
- Use ora spinners for long-running operations
|
|
52
|
+
|
|
53
|
+
## Pull Request Guidelines
|
|
54
|
+
|
|
55
|
+
- Keep changes focused and atomic
|
|
56
|
+
- Include tests for new functionality
|
|
57
|
+
- Update documentation if needed
|
|
58
|
+
- Ensure all tests pass before submitting
|
|
59
|
+
- Write clear commit messages
|
|
60
|
+
|
|
61
|
+
## Questions?
|
|
62
|
+
|
|
63
|
+
- Check existing issues first
|
|
64
|
+
- For bugs: Create an issue with reproduction steps
|
|
65
|
+
- For questions: Email support@revenium.io
|
|
66
|
+
|
|
67
|
+
## Security
|
|
68
|
+
|
|
69
|
+
For security vulnerabilities, please follow our [Security Policy](SECURITY.md) - do not create public issues.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
By contributing, you agree your contributions will be licensed under the MIT License.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @revenium/claude-code-metering
|
|
2
2
|
|
|
3
|
-
[](https://github.com/revenium/revenium-claude-code-sdk
|
|
3
|
+
[](https://github.com/revenium/revenium-claude-code-sdk/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/revenium/revenium-claude-code-sdk)
|
|
5
5
|
[](https://nodejs.org)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
@@ -281,6 +281,60 @@ Claude Code exports the following data points:
|
|
|
281
281
|
- Cache read/creation tokens
|
|
282
282
|
- Request timestamps
|
|
283
283
|
|
|
284
|
+
## Tool Metering
|
|
285
|
+
|
|
286
|
+
Track execution of custom tools and external API calls with automatic timing, error handling, and metadata collection.
|
|
287
|
+
|
|
288
|
+
### Quick Example
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { meterTool, setToolContext } from "@revenium/claude-code-metering";
|
|
292
|
+
|
|
293
|
+
// Set context once (propagates to all tool calls)
|
|
294
|
+
setToolContext({
|
|
295
|
+
sessionId: "session-123",
|
|
296
|
+
userId: "user-456"
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// Wrap tool execution
|
|
300
|
+
const result = await meterTool("weather-api", async () => {
|
|
301
|
+
return await fetch("https://api.example.com/weather");
|
|
302
|
+
}, {
|
|
303
|
+
description: "Fetch weather forecast",
|
|
304
|
+
category: "external-api",
|
|
305
|
+
outputFields: ["temperature", "humidity"]
|
|
306
|
+
});
|
|
307
|
+
// Automatically extracts temperature & humidity from result
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Functions
|
|
311
|
+
|
|
312
|
+
**meterTool(toolId, fn, metadata?)**
|
|
313
|
+
- Wraps a function with automatic metering
|
|
314
|
+
- Captures duration, success/failure, and errors
|
|
315
|
+
- Returns function result unchanged
|
|
316
|
+
|
|
317
|
+
**reportToolCall(toolId, report)**
|
|
318
|
+
- Manually report a tool call that was already executed
|
|
319
|
+
- Useful when wrapping isn't possible
|
|
320
|
+
|
|
321
|
+
**Context Management**
|
|
322
|
+
- `setToolContext(ctx)` - Set context for all subsequent tool calls
|
|
323
|
+
- `getToolContext()` - Get current context
|
|
324
|
+
- `clearToolContext()` - Clear context
|
|
325
|
+
- `runWithToolContext(ctx, fn)` - Run function with scoped context
|
|
326
|
+
|
|
327
|
+
### Metadata Options
|
|
328
|
+
|
|
329
|
+
| Field | Description |
|
|
330
|
+
|-------|-------------|
|
|
331
|
+
| `description` | Human-readable tool description |
|
|
332
|
+
| `category` | Tool category (e.g., "external-api", "database") |
|
|
333
|
+
| `version` | Tool version identifier |
|
|
334
|
+
| `tags` | Array of tags for classification |
|
|
335
|
+
| `outputFields` | Array of field names to auto-extract from result |
|
|
336
|
+
| `usageMetadata` | Custom metrics (e.g., tokens, results count) |
|
|
337
|
+
|
|
284
338
|
## Manual Configuration
|
|
285
339
|
|
|
286
340
|
If automatic shell profile update fails, add this line to your shell profile:
|
|
@@ -453,6 +507,6 @@ MIT
|
|
|
453
507
|
|
|
454
508
|
## Support
|
|
455
509
|
|
|
456
|
-
- Issues: https://github.com/revenium/revenium-claude-code-sdk
|
|
510
|
+
- Issues: https://github.com/revenium/revenium-claude-code-sdk/issues
|
|
457
511
|
- Documentation: https://docs.revenium.ai
|
|
458
512
|
- Dashboard: https://app.revenium.ai
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
If you discover a security vulnerability in this package, please report it to us.
|
|
6
|
+
|
|
7
|
+
**DO NOT** create a public GitHub issue for security vulnerabilities.
|
|
8
|
+
|
|
9
|
+
### How to Report
|
|
10
|
+
|
|
11
|
+
Email: support@revenium.io
|
|
12
|
+
|
|
13
|
+
Please include:
|
|
14
|
+
- Package name and version
|
|
15
|
+
- Description of the vulnerability
|
|
16
|
+
- Steps to reproduce (if applicable)
|
|
17
|
+
- Potential impact
|
|
18
|
+
- Suggested fix (if available)
|
|
19
|
+
|
|
20
|
+
We will review and respond to security reports in a timely manner.
|
|
21
|
+
|
|
22
|
+
## Security Best Practices
|
|
23
|
+
|
|
24
|
+
When using this CLI tool:
|
|
25
|
+
|
|
26
|
+
1. **API Keys**: Never commit API keys to version control
|
|
27
|
+
2. **Environment Variables**: The tool stores config in `~/.claude/revenium.env` with appropriate permissions
|
|
28
|
+
3. **PII Handling**: Only email (optional) is sent for attribution - no other PII is transmitted
|
|
29
|
+
4. **Network Security**: All connections use HTTPS to api.revenium.ai
|
|
30
|
+
5. **Updates**: Keep the package updated to the latest version
|
|
31
|
+
|
|
32
|
+
## Data Transmission
|
|
33
|
+
|
|
34
|
+
This tool configures Claude Code to send the following telemetry data:
|
|
35
|
+
- Session ID (anonymous identifier)
|
|
36
|
+
- Model used (e.g., claude-opus-4-5)
|
|
37
|
+
- Token counts (input, output, cache)
|
|
38
|
+
- Timestamps
|
|
39
|
+
- Cost multiplier (subscription tier)
|
|
40
|
+
|
|
41
|
+
No conversation content or PII (beyond optional email) is transmitted.
|
|
42
|
+
|
|
43
|
+
## Additional Resources
|
|
44
|
+
|
|
45
|
+
- [Revenium Documentation](https://docs.revenium.io)
|
|
46
|
+
- [Revenium Privacy Policy](https://www.revenium.ai/privacy)
|
|
@@ -176,7 +176,9 @@ function printSuccessMessage(config) {
|
|
|
176
176
|
console.log(" 1. Restart your terminal or run:");
|
|
177
177
|
console.log(chalk_1.default.cyan(" source ~/.claude/revenium.env"));
|
|
178
178
|
console.log(" 2. Start using Claude Code - telemetry will be sent automatically");
|
|
179
|
-
console.log(" 3.
|
|
179
|
+
console.log(" 3. Import past usage by running: " +
|
|
180
|
+
chalk_1.default.cyan("revenium-metering backfill"));
|
|
181
|
+
console.log(" 4. Check your usage at https://app.revenium.ai");
|
|
180
182
|
console.log("\n" +
|
|
181
183
|
chalk_1.default.dim("Run `revenium-metering status` to verify the configuration at any time."));
|
|
182
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/cli/commands/setup.ts"],"names":[],"mappings":";;;;;AAoCA,oCAoFC;AAxHD,wDAAgC;AAChC,kDAA0B;AAC1B,8CAAsB;AACtB,2DAIkC;AAClC,uDAA+D;AAC/D,iEAIwC;AACxC,2DAA0D;AAC1D,wDAA+D;AAC/D,4EAG6C;AAC7C,8DAA2D;AAa3D;;GAEG;AACI,KAAK,UAAU,YAAY,CAAC,UAAwB,EAAE;IAC3D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,GAAG,CACP,2EAA2E,CAC5E,CACF,CAAC;IAEF,wBAAwB;IACxB,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAEnD,iCAAiC;IACjC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC,oBAAoB,CAAC,CAAC,KAAK,EAAE,CAAC;IAElD,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,IAAA,+BAAmB,EAC5C,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,8BAA8B,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC;YACnE,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,MAAM,CACV,sFAAsF,CACvF,CACF,CAAC;YACF,OAAO,CAAC,IAAI,CA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AC,CAC3C,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;IAEhE,OAAO,CAAC,GAAG,CACT,IAAI;QACF,eAAK,CAAC,GAAG,CACP,yEAAyE,CAC1E,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/core/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAG9B;;GAEG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/core/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAG9B;;GAEG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC,CA2BvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,eAAe,CA2EjB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAI9C;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CA+B5B"}
|
package/dist/core/api/client.js
CHANGED
|
@@ -11,6 +11,8 @@ const loader_js_1 = require("../config/loader.js");
|
|
|
11
11
|
async function sendOtlpLogs(baseEndpoint, apiKey, payload) {
|
|
12
12
|
const fullEndpoint = (0, loader_js_1.getFullOtlpEndpoint)(baseEndpoint);
|
|
13
13
|
const url = `${fullEndpoint}/v1/logs`;
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
const timeoutId = setTimeout(() => controller.abort(), 10_000);
|
|
14
16
|
const response = await fetch(url, {
|
|
15
17
|
method: "POST",
|
|
16
18
|
headers: {
|
|
@@ -18,7 +20,8 @@ async function sendOtlpLogs(baseEndpoint, apiKey, payload) {
|
|
|
18
20
|
"x-api-key": apiKey,
|
|
19
21
|
},
|
|
20
22
|
body: JSON.stringify(payload),
|
|
21
|
-
|
|
23
|
+
signal: controller.signal,
|
|
24
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
22
25
|
if (!response.ok) {
|
|
23
26
|
const errorText = await response.text();
|
|
24
27
|
const safeErrorText = errorText.length > 200 ? errorText.substring(0, 200) + "..." : errorText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/core/api/client.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/core/api/client.ts"],"names":[],"mappings":";;AAUA,oCA+BC;AAyBD,8CA8EC;AAKD,sDAIC;AAKD,kDAmCC;AA5LD,mDAA0D;AAE1D;;GAEG;AACI,KAAK,UAAU,YAAY,CAChC,YAAoB,EACpB,MAAc,EACd,OAAwB;IAExB,MAAM,YAAY,GAAG,IAAA,+BAAmB,EAAC,YA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AE,OAAO,CAAC,CAAC;QACtD,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAEnE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QAEzC,OAAO;YACL,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,+BAA+B,QAAQ,CAAC,eAAe,YAAY;YAC5E,SAAS;SACV,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QACzC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QAEzE,gDAAgD;QAChD,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE1E,OAAO;YACL,OAAO,EAAE,KAAK;YACd,UAAU;YACV,OAAO;YACP,SAAS;SACV,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolContext } from "../types/tool-metering.js";
|
|
2
|
+
export declare function setToolContext(context: ToolContext): void;
|
|
3
|
+
export declare function getToolContext(): ToolContext;
|
|
4
|
+
export declare function clearToolContext(): void;
|
|
5
|
+
export declare function runWithToolContext<T>(context: ToolContext, fn: () => T): T;
|
|
6
|
+
//# sourceMappingURL=tool-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-context.d.ts","sourceRoot":"","sources":["../../src/core/tool-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI7D,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAEzD;AAED,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,OAAO,EAAE,WAAW,EACpB,EAAE,EAAE,MAAM,CAAC,GACV,CAAC,CAEH"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setToolContext = setToolContext;
|
|
4
|
+
exports.getToolContext = getToolContext;
|
|
5
|
+
exports.clearToolContext = clearToolContext;
|
|
6
|
+
exports.runWithToolContext = runWithToolContext;
|
|
7
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
8
|
+
const toolContextStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
9
|
+
function setToolContext(context) {
|
|
10
|
+
toolContextStorage.enterWith(context);
|
|
11
|
+
}
|
|
12
|
+
function getToolContext() {
|
|
13
|
+
return toolContextStorage.getStore() ?? {};
|
|
14
|
+
}
|
|
15
|
+
function clearToolContext() {
|
|
16
|
+
toolContextStorage.enterWith({});
|
|
17
|
+
}
|
|
18
|
+
function runWithToolContext(context, fn) {
|
|
19
|
+
return toolContextStorage.run(context, fn);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=tool-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-context.js","sourceRoot":"","sources":["../../src/core/tool-context.ts"],"names":[],"mappings":";;AAKA,wCAEC;AAED,wCAEC;AAED,4CAEC;AAED,gDAKC;AAtBD,uDAAqD;AAGrD,MAAM,kBAAkB,GAAG,IAAI,oCAAiB,EAAe,CAAC;AAEhE,SAAgB,cAAc,CAAC,OAAoB;IACjD,kBAAkB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,cAAc;IAC5B,OAAO,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC7C,CAAC;AAED,SAAgB,gBAAgB;IAC9B,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,SAAgB,kBAAkB,CAChC,OAAoB,EACpB,EAAW;IAEX,OAAO,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolMetadata, ToolCallReport } from "../types/tool-metering.js";
|
|
2
|
+
export declare function meterTool<T>(toolId: string, fn: () => T | Promise<T>, metadata?: ToolMetadata): Promise<T>;
|
|
3
|
+
export declare function reportToolCall(toolId: string, report: ToolCallReport): void;
|
|
4
|
+
//# sourceMappingURL=tool-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-tracker.d.ts","sourceRoot":"","sources":["../../src/core/tool-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACf,MAAM,2BAA2B,CAAC;AA2InC,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACxB,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,CAAC,CAAC,CA0CZ;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,GACrB,IAAI,CASN"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.meterTool = meterTool;
|
|
4
|
+
exports.reportToolCall = reportToolCall;
|
|
5
|
+
const tool_context_js_1 = require("./tool-context.js");
|
|
6
|
+
const client_js_1 = require("./api/client.js");
|
|
7
|
+
const loader_js_1 = require("./config/loader.js");
|
|
8
|
+
const MIDDLEWARE_SOURCE = "revenium-claude-code-sdk";
|
|
9
|
+
function isPromise(value) {
|
|
10
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
11
|
+
}
|
|
12
|
+
function extractOutputFields(result, fields) {
|
|
13
|
+
if (typeof result !== "object" || result === null) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
const extracted = {};
|
|
17
|
+
for (const field of fields) {
|
|
18
|
+
if (field in result) {
|
|
19
|
+
extracted[field] = result[field];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return extracted;
|
|
23
|
+
}
|
|
24
|
+
function buildToolEventPayload(toolId, durationMs, success, errorMessage, metadata) {
|
|
25
|
+
const context = (0, tool_context_js_1.getToolContext)();
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
return {
|
|
28
|
+
toolId,
|
|
29
|
+
sessionId: context?.sessionId ?? "unknown",
|
|
30
|
+
startTime: now - durationMs,
|
|
31
|
+
endTime: now,
|
|
32
|
+
durationMs,
|
|
33
|
+
success,
|
|
34
|
+
errorMessage,
|
|
35
|
+
metadata,
|
|
36
|
+
userId: context?.userId,
|
|
37
|
+
organizationName: context?.organizationName,
|
|
38
|
+
productName: context?.productName,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createToolOtlpPayload(event) {
|
|
42
|
+
const logAttributes = [
|
|
43
|
+
{ key: "tool.id", value: { stringValue: event.toolId } },
|
|
44
|
+
{ key: "session.id", value: { stringValue: event.sessionId } },
|
|
45
|
+
{ key: "duration_ms", value: { intValue: event.durationMs } },
|
|
46
|
+
{ key: "success", value: { boolValue: event.success } },
|
|
47
|
+
{ key: "middleware.source", value: { stringValue: MIDDLEWARE_SOURCE } },
|
|
48
|
+
];
|
|
49
|
+
if (event.errorMessage) {
|
|
50
|
+
logAttributes.push({ key: "error.message", value: { stringValue: event.errorMessage } });
|
|
51
|
+
}
|
|
52
|
+
if (event.userId) {
|
|
53
|
+
logAttributes.push({ key: "user.id", value: { stringValue: event.userId } });
|
|
54
|
+
}
|
|
55
|
+
if (event.organizationName) {
|
|
56
|
+
logAttributes.push({ key: "organization.name", value: { stringValue: event.organizationName } });
|
|
57
|
+
}
|
|
58
|
+
if (event.productName) {
|
|
59
|
+
logAttributes.push({ key: "product.name", value: { stringValue: event.productName } });
|
|
60
|
+
}
|
|
61
|
+
if (event.metadata?.description) {
|
|
62
|
+
logAttributes.push({ key: "tool.description", value: { stringValue: event.metadata.description } });
|
|
63
|
+
}
|
|
64
|
+
if (event.metadata?.category) {
|
|
65
|
+
logAttributes.push({ key: "tool.category", value: { stringValue: event.metadata.category } });
|
|
66
|
+
}
|
|
67
|
+
if (event.metadata?.version) {
|
|
68
|
+
logAttributes.push({ key: "tool.version", value: { stringValue: event.metadata.version } });
|
|
69
|
+
}
|
|
70
|
+
if (event.metadata?.tags && event.metadata.tags.length > 0) {
|
|
71
|
+
logAttributes.push({ key: "tool.tags", value: { stringValue: event.metadata.tags.join(",") } });
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
resourceLogs: [
|
|
75
|
+
{
|
|
76
|
+
resource: {
|
|
77
|
+
attributes: [
|
|
78
|
+
{ key: "service.name", value: { stringValue: "claude-code" } },
|
|
79
|
+
{ key: "middleware.source", value: { stringValue: MIDDLEWARE_SOURCE } },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
scopeLogs: [
|
|
83
|
+
{
|
|
84
|
+
scope: {
|
|
85
|
+
name: "tool_metering",
|
|
86
|
+
version: "0.1.0",
|
|
87
|
+
},
|
|
88
|
+
logRecords: [
|
|
89
|
+
{
|
|
90
|
+
timeUnixNano: (event.endTime * 1_000_000).toString(),
|
|
91
|
+
body: { stringValue: "tool.call" },
|
|
92
|
+
attributes: logAttributes,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function sendToolEvent(event) {
|
|
102
|
+
const context = (0, tool_context_js_1.getToolContext)();
|
|
103
|
+
const config = await (0, loader_js_1.loadConfig)();
|
|
104
|
+
const endpoint = context?.endpoint ?? config?.endpoint;
|
|
105
|
+
const apiKey = context?.apiKey ?? config?.apiKey;
|
|
106
|
+
if (!endpoint || !apiKey) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const payload = createToolOtlpPayload(event);
|
|
110
|
+
await (0, client_js_1.sendOtlpLogs)(endpoint, apiKey, payload);
|
|
111
|
+
}
|
|
112
|
+
function dispatchToolEvent(event) {
|
|
113
|
+
sendToolEvent(event).catch(() => { });
|
|
114
|
+
}
|
|
115
|
+
function meterTool(toolId, fn, metadata) {
|
|
116
|
+
const startTime = performance.now();
|
|
117
|
+
const handleSuccess = (result) => {
|
|
118
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
119
|
+
let finalMetadata = metadata;
|
|
120
|
+
if (metadata?.outputFields && metadata.outputFields.length > 0) {
|
|
121
|
+
const extracted = extractOutputFields(result, metadata.outputFields);
|
|
122
|
+
finalMetadata = {
|
|
123
|
+
...metadata,
|
|
124
|
+
usageMetadata: {
|
|
125
|
+
...metadata.usageMetadata,
|
|
126
|
+
...extracted,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const event = buildToolEventPayload(toolId, durationMs, true, undefined, finalMetadata);
|
|
131
|
+
dispatchToolEvent(event);
|
|
132
|
+
return result;
|
|
133
|
+
};
|
|
134
|
+
const handleError = (error) => {
|
|
135
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
136
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
137
|
+
const event = buildToolEventPayload(toolId, durationMs, false, errorMessage, metadata);
|
|
138
|
+
dispatchToolEvent(event);
|
|
139
|
+
throw error;
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
const result = fn();
|
|
143
|
+
if (isPromise(result)) {
|
|
144
|
+
return result.then(handleSuccess, handleError);
|
|
145
|
+
}
|
|
146
|
+
return Promise.resolve(handleSuccess(result));
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
return Promise.reject(handleError(error));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function reportToolCall(toolId, report) {
|
|
153
|
+
const event = buildToolEventPayload(toolId, report.durationMs, report.success, report.errorMessage, report.metadata);
|
|
154
|
+
dispatchToolEvent(event);
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=tool-tracker.js.map
|