@revenium/perplexity 2.0.7 → 2.0.9

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.
Files changed (51) hide show
  1. package/.env.example +23 -0
  2. package/CHANGELOG.md +99 -113
  3. package/LICENSE +21 -21
  4. package/README.md +528 -376
  5. package/SECURITY.md +34 -34
  6. package/dist/cjs/core/config/loader.js +16 -0
  7. package/dist/cjs/core/config/loader.js.map +1 -1
  8. package/dist/cjs/core/config/manager.js +9 -0
  9. package/dist/cjs/core/config/manager.js.map +1 -1
  10. package/dist/cjs/core/tracking/api-client.js +2 -0
  11. package/dist/cjs/core/tracking/api-client.js.map +1 -1
  12. package/dist/cjs/core/tracking/payload-builder.js +20 -1
  13. package/dist/cjs/core/tracking/payload-builder.js.map +1 -1
  14. package/dist/cjs/core/tracking/usage-tracker.js +1 -1
  15. package/dist/cjs/core/tracking/usage-tracker.js.map +1 -1
  16. package/dist/cjs/utils/summary-printer.js +237 -0
  17. package/dist/cjs/utils/summary-printer.js.map +1 -0
  18. package/dist/cjs/utils/trace-fields.js +136 -0
  19. package/dist/cjs/utils/trace-fields.js.map +1 -0
  20. package/dist/esm/core/config/loader.js +16 -0
  21. package/dist/esm/core/config/loader.js.map +1 -1
  22. package/dist/esm/core/config/manager.js +9 -0
  23. package/dist/esm/core/config/manager.js.map +1 -1
  24. package/dist/esm/core/tracking/api-client.js +2 -0
  25. package/dist/esm/core/tracking/api-client.js.map +1 -1
  26. package/dist/esm/core/tracking/payload-builder.js +20 -1
  27. package/dist/esm/core/tracking/payload-builder.js.map +1 -1
  28. package/dist/esm/core/tracking/usage-tracker.js +1 -1
  29. package/dist/esm/core/tracking/usage-tracker.js.map +1 -1
  30. package/dist/esm/utils/summary-printer.js +233 -0
  31. package/dist/esm/utils/summary-printer.js.map +1 -0
  32. package/dist/esm/utils/trace-fields.js +121 -0
  33. package/dist/esm/utils/trace-fields.js.map +1 -0
  34. package/dist/types/core/config/loader.d.ts.map +1 -1
  35. package/dist/types/core/config/manager.d.ts.map +1 -1
  36. package/dist/types/core/tracking/api-client.d.ts.map +1 -1
  37. package/dist/types/core/tracking/payload-builder.d.ts +1 -1
  38. package/dist/types/core/tracking/payload-builder.d.ts.map +1 -1
  39. package/dist/types/types/index.d.ts +13 -0
  40. package/dist/types/types/index.d.ts.map +1 -1
  41. package/dist/types/utils/summary-printer.d.ts +23 -0
  42. package/dist/types/utils/summary-printer.d.ts.map +1 -0
  43. package/dist/types/utils/trace-fields.d.ts +11 -0
  44. package/dist/types/utils/trace-fields.d.ts.map +1 -0
  45. package/examples/README.md +274 -230
  46. package/examples/advanced.ts +123 -123
  47. package/examples/basic.ts +45 -45
  48. package/examples/getting_started.ts +41 -41
  49. package/examples/metadata.ts +68 -68
  50. package/examples/stream.ts +53 -53
  51. package/package.json +82 -72
package/.env.example ADDED
@@ -0,0 +1,23 @@
1
+ # Revenium Configuration (Required)
2
+ REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
3
+ REVENIUM_METERING_BASE_URL=https://api.revenium.ai
4
+
5
+ # Perplexity Configuration (Required)
6
+ PERPLEXITY_API_KEY=pplx_your_perplexity_api_key_here
7
+ PERPLEXITY_API_BASE_URL=https://api.perplexity.ai
8
+
9
+ # Trace Visualization Fields (Optional)
10
+ REVENIUM_ENVIRONMENT=production
11
+ REVENIUM_REGION=us-east-1
12
+ REVENIUM_CREDENTIAL_ALIAS=Perplexity Production Key
13
+ REVENIUM_TRACE_TYPE=customer_support
14
+ REVENIUM_TRACE_NAME=Support Ticket #12345
15
+ REVENIUM_PARENT_TRANSACTION_ID=parent-txn-123
16
+ REVENIUM_TRANSACTION_NAME=Answer Customer Question
17
+ REVENIUM_RETRY_NUMBER=0
18
+
19
+ # Debug Configuration (Optional)
20
+ REVENIUM_DEBUG=false
21
+
22
+ # AWS Region Detection (Optional - auto-detected if not set)
23
+ AWS_REGION=us-east-1
package/CHANGELOG.md CHANGED
@@ -1,113 +1,99 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ## [3.0.0] - 2025-11-08
11
-
12
- ### Added
13
-
14
- - Initialize()/GetClient() pattern
15
- - Configure() function for manual configuration
16
- - IsInitialized() function to check initialization state
17
- - Reset() function for testing scenarios
18
- - Automatic .env file loading via dotenv
19
- - Complete modular architecture with core/ directory structure
20
- - New examples: basic.ts, metadata.ts, advanced.ts, stream.ts (renamed from streaming.ts)
21
- - COST_LIMIT and COMPLETION_LIMIT stop reasons to mapper (per API spec)
22
- - Support for all 7 operationType enum values (CHAT, GENERATE, EMBED, CLASSIFY, SUMMARIZE, TRANSLATE, OTHER)
23
-
24
- ### Changed
25
-
26
- - **BREAKING:** Complete API redesign to pattern (Initialize/GetClient)
27
- - **BREAKING:** Removed old initialization functions (initializeReveniumFromEnv, initializePerplexityFromEnv)
28
- - **BREAKING:** Removed old wrapper functions (createChatCompletion, createStreamingChatCompletion)
29
- - **BREAKING:** responseQualityScore now uses 0.0-1.0 scale (was 0-100) per updated API specification
30
- - **API Compliance:** provider value changed from 'PERPLEXITY' to 'Perplexity' (proper casing per spec)
31
- - **API Compliance:** modelSource changed to 'PERPLEXITY' for consistency
32
- - **API Compliance:** middlewareSource changed from 'nodejs' to 'revenium-perplexity-node' per spec format
33
- - **API Compliance:** cacheCreationTokenCount now undefined (not 0) when provider doesn't report
34
- - **API Compliance:** cacheReadTokenCount now uses ?? operator (not ||) to preserve 0 values
35
- - **API Compliance:** timeToFirstToken now undefined (not hardcoded) until real TTFB tracking implemented
36
- - Restructured src/ with modular core/client, core/config, core/middleware, core/providers, core/tracking
37
- - Email addresses now masked in debug logs for PII protection
38
- - All examples updated to use 0.0-1.0 scale for responseQualityScore
39
- - Removed hardcoded model lists - middleware now accepts any model name
40
-
41
- ### Fixed
42
-
43
- - Removed broken file references from examples documentation
44
- - Removed non-existent config options from documentation (apiTimeout, failSilent, maxRetries)
45
- - config.debug property now properly enables debug logging
46
- - Updated OpenAI version requirement to match peer dependency (v5.0.0+)
47
- - Removed taskId field from all files (field does not exist in API spec)
48
- - Added CANCELLED stop reason to mapper for completeness
49
- - validateMetadata now checks 0.0-1.0 scale for responseQualityScore
50
- - Fallback provider detection now uses 'Perplexity' not 'PERPLEXITY' (proper casing)
51
- - reasoningTokenCount now optional (undefined when not reported, per spec)
52
-
53
- ## [2.0.4] - 2025-10-21
54
-
55
- ### Changed
56
-
57
- - Enhanced package.json with examples in files array
58
- - Added community health files (CODE_OF_CONDUCT.md, CONTRIBUTING.md, SECURITY.md)
59
- - Updated .gitignore with security report patterns
60
- - Added engines field for Node.js version requirements
61
-
62
- ## [2.0.3] - 2025-10-17
63
-
64
- ### Changed
65
-
66
- - Documentation improvements with absolute path references
67
-
68
- ## [2.0.2] - 2025-10-09
69
-
70
- ### Changed
71
-
72
- - Internal updates and improvements
73
-
74
- ## [2.0.1] - 2025-10-09
75
-
76
- ### Changed
77
-
78
- - Bug fixes and stability improvements
79
-
80
- ## [2.0.0] - 2025-10-09
81
-
82
- ### Added
83
-
84
- - Complete code restructuring with core/ directory organization
85
- - Dual package exports (ESM + CommonJS) support
86
- - TypeScript declaration maps for better debugging
87
- - Enhanced build system with separate CJS, ESM, and types builds
88
-
89
- ### Changed
90
-
91
- - Restructured src/ directory with core/config, core/tracking, core/wrapper
92
- - Enhanced README with comprehensive documentation
93
-
94
- ## [1.0.0] - 2025-09-23
95
-
96
- ### Added
97
-
98
- - Initial release of Perplexity AI middleware
99
- - Automatic token counting and usage tracking
100
- - Streaming support with automatic tracking
101
- - Custom metadata integration
102
- - TypeScript support with full type safety
103
- - Comprehensive error handling
104
- - Background processing for non-blocking tracking
105
- - Debug logging support
106
-
107
- [3.0.0]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v3.0.0
108
- [2.0.4]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.4
109
- [2.0.3]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.3
110
- [2.0.2]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.2
111
- [2.0.1]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.1
112
- [2.0.0]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.0
113
- [1.0.0]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v1.0.0
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.0.9] - 2026-01-06
9
+
10
+ ### Added
11
+
12
+ - Trace visualization fields support for distributed tracing and analytics
13
+ - New trace fields: environment, region, credentialAlias, traceType, traceName, parentTransactionId, transactionName, retryNumber, operationSubtype
14
+ - Automatic region detection from AWS/Azure/GCP environment variables with fallback to AWS EC2 metadata service
15
+ - Comprehensive unit tests for all trace field functions
16
+ - Jest testing infrastructure with full test coverage
17
+ - Updated .env.example with trace visualization field examples
18
+ - Documentation for trace visualization fields in README.md
19
+
20
+ ### Changed
21
+
22
+ - buildPayload function is now async to support region detection
23
+ - Updated ReveniumPayload interface with trace visualization fields
24
+
25
+ ## [2.0.8] - 2025-11-14
26
+
27
+ ### Changed
28
+
29
+ - Updated documentation with semver range examples
30
+ - Enhanced package structure for better npm distribution
31
+ - Improved installation instructions and clarity
32
+ - Improved metadata table clarity and accuracy with better field descriptions
33
+
34
+ ### Fixed
35
+
36
+ - Updated dashboard URL references to app.revenium.ai
37
+ - Documentation improvements for better user experience
38
+
39
+ ## [2.0.4] - 2025-10-21
40
+
41
+ ### Changed
42
+
43
+ - Enhanced package.json with examples in files array
44
+ - Added community health files (CODE_OF_CONDUCT.md, CONTRIBUTING.md, SECURITY.md)
45
+ - Updated .gitignore with security report patterns
46
+ - Added engines field for Node.js version requirements
47
+
48
+ ## [2.0.3] - 2025-10-17
49
+
50
+ ### Changed
51
+
52
+ - Documentation improvements with absolute path references
53
+
54
+ ## [2.0.2] - 2025-10-09
55
+
56
+ ### Changed
57
+
58
+ - Internal updates and improvements
59
+
60
+ ## [2.0.1] - 2025-10-09
61
+
62
+ ### Changed
63
+
64
+ - Bug fixes and stability improvements
65
+
66
+ ## [2.0.0] - 2025-10-09
67
+
68
+ ### Added
69
+
70
+ - Complete code restructuring with core/ directory organization
71
+ - Dual package exports (ESM + CommonJS) support
72
+ - TypeScript declaration maps for better debugging
73
+ - Enhanced build system with separate CJS, ESM, and types builds
74
+
75
+ ### Changed
76
+
77
+ - Restructured src/ directory with core/config, core/tracking, core/wrapper
78
+ - Enhanced README with comprehensive documentation
79
+
80
+ ## [1.0.0] - 2025-09-23
81
+
82
+ ### Added
83
+
84
+ - Initial release of Perplexity AI middleware
85
+ - Automatic token counting and usage tracking
86
+ - Streaming support with automatic tracking
87
+ - Custom metadata integration
88
+ - TypeScript support with full type safety
89
+ - Comprehensive error handling
90
+ - Background processing for non-blocking tracking
91
+ - Debug logging support
92
+
93
+ [2.0.8]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.8
94
+ [2.0.4]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.4
95
+ [2.0.3]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.3
96
+ [2.0.2]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.2
97
+ [2.0.1]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.1
98
+ [2.0.0]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v2.0.0
99
+ [1.0.0]: https://github.com/revenium/revenium-middleware-perplexity-node/releases/tag/v1.0.0
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Revenium
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Revenium
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.