@memorilabs/axon 0.1.3-beta → 0.1.4-beta

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 (92) hide show
  1. package/README.md +82 -67
  2. package/dist/errors/hook-error.d.ts.map +1 -1
  3. package/dist/errors/hook-error.js +1 -1
  4. package/dist/errors/hook-error.js.map +1 -1
  5. package/dist/errors/unsupported-provider-error.d.ts.map +1 -1
  6. package/dist/errors/unsupported-provider-error.js +2 -1
  7. package/dist/errors/unsupported-provider-error.js.map +1 -1
  8. package/dist/hooks/registry.d.ts +16 -7
  9. package/dist/hooks/registry.d.ts.map +1 -1
  10. package/dist/hooks/registry.js +14 -2
  11. package/dist/hooks/registry.js.map +1 -1
  12. package/dist/llm/registry.d.ts +10 -4
  13. package/dist/llm/registry.d.ts.map +1 -1
  14. package/dist/llm/registry.js +9 -2
  15. package/dist/llm/registry.js.map +1 -1
  16. package/dist/providers/anthropic/common.d.ts.map +1 -1
  17. package/dist/providers/anthropic/common.js.map +1 -1
  18. package/dist/providers/anthropic/detect.d.ts +5 -0
  19. package/dist/providers/anthropic/detect.d.ts.map +1 -1
  20. package/dist/providers/anthropic/detect.js +5 -0
  21. package/dist/providers/anthropic/detect.js.map +1 -1
  22. package/dist/providers/anthropic/proxy.d.ts.map +1 -1
  23. package/dist/providers/anthropic/proxy.js +2 -1
  24. package/dist/providers/anthropic/proxy.js.map +1 -1
  25. package/dist/providers/anthropic/responses.d.ts +22 -0
  26. package/dist/providers/anthropic/responses.d.ts.map +1 -0
  27. package/dist/providers/anthropic/responses.js +2 -0
  28. package/dist/providers/anthropic/responses.js.map +1 -0
  29. package/dist/providers/anthropic/types.d.ts +10 -27
  30. package/dist/providers/anthropic/types.d.ts.map +1 -1
  31. package/dist/providers/gemini/common.d.ts +8 -0
  32. package/dist/providers/gemini/common.d.ts.map +1 -0
  33. package/dist/providers/gemini/common.js +46 -0
  34. package/dist/providers/gemini/common.js.map +1 -0
  35. package/dist/providers/gemini/detect.d.ts +7 -0
  36. package/dist/providers/gemini/detect.d.ts.map +1 -0
  37. package/dist/providers/gemini/detect.js +12 -0
  38. package/dist/providers/gemini/detect.js.map +1 -0
  39. package/dist/providers/gemini/index.d.ts +5 -0
  40. package/dist/providers/gemini/index.d.ts.map +1 -0
  41. package/dist/providers/gemini/index.js +10 -0
  42. package/dist/providers/gemini/index.js.map +1 -0
  43. package/dist/providers/gemini/proxy.d.ts +3 -0
  44. package/dist/providers/gemini/proxy.d.ts.map +1 -0
  45. package/dist/providers/gemini/proxy.js +72 -0
  46. package/dist/providers/gemini/proxy.js.map +1 -0
  47. package/dist/providers/gemini/responses.d.ts +17 -0
  48. package/dist/providers/gemini/responses.d.ts.map +1 -0
  49. package/dist/providers/gemini/responses.js +2 -0
  50. package/dist/providers/gemini/responses.js.map +1 -0
  51. package/dist/providers/gemini/types.d.ts +23 -0
  52. package/dist/providers/gemini/types.d.ts.map +1 -0
  53. package/dist/providers/gemini/types.js +2 -0
  54. package/dist/providers/gemini/types.js.map +1 -0
  55. package/dist/providers/index.d.ts +1 -0
  56. package/dist/providers/index.d.ts.map +1 -1
  57. package/dist/providers/index.js +1 -0
  58. package/dist/providers/index.js.map +1 -1
  59. package/dist/providers/openai/detect.d.ts +5 -0
  60. package/dist/providers/openai/detect.d.ts.map +1 -1
  61. package/dist/providers/openai/detect.js +5 -0
  62. package/dist/providers/openai/detect.js.map +1 -1
  63. package/dist/providers/openai/proxy.d.ts.map +1 -1
  64. package/dist/providers/openai/proxy.js +7 -2
  65. package/dist/providers/openai/proxy.js.map +1 -1
  66. package/dist/providers/openai/responses.d.ts +9 -9
  67. package/dist/providers/openai/responses.d.ts.map +1 -1
  68. package/dist/providers/openai/types.d.ts +5 -0
  69. package/dist/providers/openai/types.d.ts.map +1 -1
  70. package/dist/providers/patcher.d.ts.map +1 -1
  71. package/dist/providers/patcher.js +2 -9
  72. package/dist/providers/patcher.js.map +1 -1
  73. package/dist/providers/telemetry.d.ts.map +1 -1
  74. package/dist/providers/telemetry.js +3 -0
  75. package/dist/providers/telemetry.js.map +1 -1
  76. package/dist/types/index.d.ts +1 -0
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/index.js +1 -0
  79. package/dist/types/index.js.map +1 -1
  80. package/dist/types/llm.d.ts +15 -0
  81. package/dist/types/llm.d.ts.map +1 -1
  82. package/dist/types/registry.d.ts +14 -0
  83. package/dist/types/registry.d.ts.map +1 -0
  84. package/dist/types/registry.js +2 -0
  85. package/dist/types/registry.js.map +1 -0
  86. package/dist/utils/constants.d.ts +19 -0
  87. package/dist/utils/constants.d.ts.map +1 -0
  88. package/dist/utils/constants.js +14 -0
  89. package/dist/utils/constants.js.map +1 -0
  90. package/dist/version.d.ts +1 -1
  91. package/dist/version.js +1 -1
  92. package/package.json +13 -5
package/README.md CHANGED
@@ -1,99 +1,114 @@
1
- # Memori Axon - TypeScript SDK
2
-
3
- TypeScript SDK for Memori's hosted memory service.
1
+ [![Memori Labs](https://s3.us-east-1.amazonaws.com/images.memorilabs.ai/banner.png)](https://memorilabs.ai/)
2
+
3
+ <p align="center">
4
+ <strong>The universal LLM interceptor and hook registry</strong>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <i>Axon plugs into the official LLM SDKs you already use. It allows you to seamlessly intercept, modify, and monitor LLM requests and responses through a unified hook system without changing your underlying application code.</i>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@memorilabs/axon">
13
+ <img src="https://img.shields.io/npm/v/@memorilabs/axon.svg" alt="NPM version">
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@memorilabs/axon">
16
+ <img src="https://img.shields.io/npm/dm/@memorilabs/axon.svg" alt="NPM Downloads">
17
+ </a>
18
+ <a href="https://opensource.org/license/apache-2-0">
19
+ <img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="License">
20
+ </a>
21
+ <a href="https://discord.gg/abD4eGym6v">
22
+ <img src="https://img.shields.io/discord/1042405378304004156?logo=discord" alt="Discord">
23
+ </a>
24
+ </p>
4
25
 
5
26
  ---
6
27
 
7
- ## 🚀 Quick Start
8
-
9
- ```bash
10
- # Install dependencies
11
- npm install
12
-
13
- # Format existing code
14
- npm run format
28
+ ## Getting Started
15
29
 
16
- # Run type check
17
- npm run typecheck
30
+ Install the Axon SDK and your preferred LLM client using your package manager of choice:
18
31
 
19
- # Build the project
20
- npm run build
32
+ ```bash
33
+ npm install @memorilabs/axon
21
34
  ```
22
35
 
23
- ---
36
+ _(Note: Axon supports `openai`, `@anthropic-ai/sdk`, and `@google/genai` as optional peer dependencies)._
24
37
 
25
- ## 📜 Available Commands
38
+ ## Quickstart Example
26
39
 
27
- ### Development
40
+ ```typescript
41
+ import 'dotenv/config';
42
+ import { OpenAI } from 'openai';
43
+ import { Axon } from '@memorilabs/axon';
28
44
 
29
- | Command | Description |
30
- | ----------------- | ----------------------------- |
31
- | `npm run build` | Compile TypeScript to `dist/` |
32
- | `npm run example` | Build and run example script |
45
+ // 1. Initialize the LLM Client
46
+ const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
33
47
 
34
- ### Testing
48
+ // 2. Initialize Axon and Register the Client
49
+ const axon = new Axon();
50
+ axon.llm.register(client);
35
51
 
36
- | Command | Description |
37
- | -------------------- | ----------------------- |
38
- | `npm test` | Run tests once |
39
- | `npm run test:watch` | Run tests in watch mode |
52
+ // 3. Register a Before Hook (e.g., logging or modifying prompts)
53
+ axon.before.register((req, ctx) => {
54
+ console.log(`[${ctx.traceId}] Intercepted request to model: ${req.model}`);
55
+ // You can modify the request here before it hits the provider
56
+ return req;
57
+ });
40
58
 
41
- ### Code Quality
59
+ // 4. Register an After Hook (e.g., token usage tracking)
60
+ axon.after.register((req, res, ctx) => {
61
+ console.log(`[${ctx.traceId}] Received response. Tokens used: ${res.usage?.totalTokens}`);
62
+ });
42
63
 
43
- | Command | Description |
44
- | ---------------------- | ---------------------------------------- |
45
- | `npm run lint` | Check for linting issues |
46
- | `npm run lint:fix` | Auto-fix linting issues |
47
- | `npm run format` | Format all files with Prettier |
48
- | `npm run format:check` | Check formatting without modifying files |
49
- | `npm run typecheck` | Run TypeScript type checking (no build) |
64
+ async function main() {
65
+ console.log('Sending standard LLM request...');
50
66
 
51
- ---
67
+ // 5. Use your client exactly as you normally would!
68
+ // Axon intercepts this call in the background.
69
+ const response = await client.chat.completions.create({
70
+ model: 'gpt-4o',
71
+ messages: [{ role: 'user', content: 'What is the speed of light?' }],
72
+ });
52
73
 
53
- ## 🔧 Git Hooks
74
+ console.log(`AI: ${response.choices[0].message.content}`);
75
+ }
54
76
 
55
- Pre-commit and pre-push hooks are configured to maintain code quality automatically.
56
-
57
- ### Pre-commit Hook
77
+ main().catch(console.error);
78
+ ```
58
79
 
59
- Runs automatically on `git commit`:
80
+ ## Key Features
60
81
 
61
- - ESLint (with auto-fix)
62
- - Prettier (formatting)
63
- - Only checks staged files
82
+ - **Universal LLM Support:** Works natively with OpenAI, Anthropic Claude, and Google Gemini SDKs.
83
+ - **Unified Hook System:** Write your logic once. Axon normalizes requests and responses across all providers so your hooks work universally.
84
+ - **Zero Overhead:** Plugs directly into your existing client initialization. No need to rewrite your agent or application logic.
85
+ - **Streaming Support:** Seamlessly handles and aggregates asynchronous streaming responses.
86
+ - **Type-Safe:** Written in strict TypeScript with comprehensive definitions for all provider payloads.
64
87
 
65
- ### Pre-push Hook
88
+ ## Supported LLMs
66
89
 
67
- Runs automatically on `git push`:
90
+ - OpenAI (`openai`)
91
+ - Anthropic Claude (`@anthropic-ai/sdk`)
92
+ - Google Gemini (`@google/genai`)
68
93
 
69
- - ✅ TypeScript type checking
94
+ ## Contributing
70
95
 
71
- ### Bypass Hooks (Use Sparingly)
96
+ We welcome contributions from the community! Please see our [Contributing Guidelines](https://github.com/MemoriLabs/axon/blob/main/CONTRIBUTING.md) for details on:
72
97
 
73
- ```bash
74
- git commit --no-verify # Skip pre-commit hook
75
- git push --no-verify # Skip pre-push hook
76
- ```
98
+ - Setting up your development environment
99
+ - Code style and standards
100
+ - Submitting pull requests
101
+ - Reporting issues
77
102
 
78
103
  ---
79
104
 
80
- ## 📦 Project Structure
105
+ ## Support
81
106
 
82
- ```
83
- ts-sdk/
84
- ├── src/ # Source code
85
- ├── tests/ # Test files
86
- ├── examples/ # Example scripts
87
- ├── dist/ # Compiled output (generated)
88
- └── ...config files
89
- ```
107
+ - **Discord**: [https://discord.gg/abD4eGym6v](https://discord.gg/abD4eGym6v)
108
+ - **Issues**: [GitHub Issues](https://github.com/MemoriLabs/axon/issues)
90
109
 
91
110
  ---
92
111
 
93
- ## 🛠️ Development Workflow
112
+ ## License
94
113
 
95
- 1. Make your changes
96
- 2. Run `npm run lint:fix` to auto-fix issues
97
- 3. Run `npm run typecheck` to verify types
98
- 4. Commit your changes (hooks run automatically)
99
- 5. Push to remote (type check runs automatically)
114
+ Apache 2.0 - see [LICENSE](https://github.com/MemoriLabs/axon/blob/main/LICENSE)
@@ -1 +1 @@
1
- {"version":3,"file":"hook-error.d.ts","sourceRoot":"","sources":["../../src/errors/hook-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,SAAgB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IACnD,SAAgB,KAAK,EAAE,OAAO,CAAC;gBAEnB,IAAI,EAAE;QAAE,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;CAMzE"}
1
+ {"version":3,"file":"hook-error.d.ts","sourceRoot":"","sources":["../../src/errors/hook-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,SAAgB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IACnD,SAAgB,KAAK,EAAE,OAAO,CAAC;gBAEnB,IAAI,EAAE;QAAE,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;CAQzE"}
@@ -6,7 +6,7 @@ export class AxonHookError extends AxonError {
6
6
  hook;
7
7
  cause;
8
8
  constructor(opts) {
9
- super(`${opts.hook} hook failed: ${String(opts.cause)}`);
9
+ super(`Axon '${opts.hook}' hook failed during execution. Check your registered hook implementation. Underlying cause: ${String(opts.cause)}`);
10
10
  this.name = 'AxonHookError';
11
11
  this.hook = opts.hook;
12
12
  this.cause = opts.cause;
@@ -1 +1 @@
1
- {"version":3,"file":"hook-error.js","sourceRoot":"","sources":["../../src/errors/hook-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1B,IAAI,CAA+B;IACnC,KAAK,CAAU;IAE/B,YAAY,IAA4D;QACtE,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,iBAAiB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;CACF"}
1
+ {"version":3,"file":"hook-error.js","sourceRoot":"","sources":["../../src/errors/hook-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1B,IAAI,CAA+B;IACnC,KAAK,CAAU;IAE/B,YAAY,IAA4D;QACtE,KAAK,CACH,SAAS,IAAI,CAAC,IAAI,gGAAgG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CACvI,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"unsupported-provider-error.d.ts","sourceRoot":"","sources":["../../src/errors/unsupported-provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,SAAS;IACxD,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,QAAQ,EAAE,MAAM;CAK7B"}
1
+ {"version":3,"file":"unsupported-provider-error.d.ts","sourceRoot":"","sources":["../../src/errors/unsupported-provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,SAAS;IACxD,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,QAAQ,EAAE,MAAM;CAO7B"}
@@ -1,11 +1,12 @@
1
1
  import { AxonError } from './axon-error.js';
2
+ import { SUPPORTED_PROVIDERS } from '../utils/constants.js';
2
3
  /**
3
4
  * Thrown when attempting to register a client that Axon does not recognize.
4
5
  */
5
6
  export class UnsupportedLLMProviderError extends AxonError {
6
7
  provider;
7
8
  constructor(provider) {
8
- super(`Unsupported LLM provider: ${provider}`);
9
+ super(`Unsupported LLM provider: '${provider}'. Axon currently supports patching: ${SUPPORTED_PROVIDERS.join(', ')}. Ensure you are passing an initialized client instance.`);
9
10
  this.name = 'UnsupportedLLMProviderError';
10
11
  this.provider = provider;
11
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unsupported-provider-error.js","sourceRoot":"","sources":["../../src/errors/unsupported-provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,SAAS;IACxC,QAAQ,CAAS;IAEjC,YAAY,QAAgB;QAC1B,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
1
+ {"version":3,"file":"unsupported-provider-error.js","sourceRoot":"","sources":["../../src/errors/unsupported-provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,SAAS;IACxC,QAAQ,CAAS;IAEjC,YAAY,QAAgB;QAC1B,KAAK,CACH,8BAA8B,QAAQ,wCAAwC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,0DAA0D,CACvK,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
@@ -1,11 +1,9 @@
1
- import { CallContext, LLMRequest, LLMResponse } from '../types/index.js';
2
- type BeforeHook = (req: LLMRequest, ctx: CallContext) => LLMRequest | Promise<LLMRequest> | undefined | Promise<undefined>;
3
- type AfterHook = (req: LLMRequest, res: LLMResponse, ctx: CallContext) => LLMResponse | Promise<LLMResponse> | undefined | Promise<undefined>;
4
- type HookType<P> = P extends 'before' ? BeforeHook : AfterHook;
1
+ import { AfterHook, BeforeHook } from '../types/index.js';
2
+ export type HookType<P> = P extends 'before' ? BeforeHook : AfterHook;
5
3
  /**
6
4
  * Manages a list of lifecycle hooks for a specific phase.
7
5
  *
8
- * @template P - The lifecycle phase this registry manages ('before' or 'after').
6
+ * @typeParam P - The lifecycle phase this registry manages ('before' or 'after').
9
7
  */
10
8
  export declare class HookRegistry<P extends 'before' | 'after'> {
11
9
  private readonly phase;
@@ -15,7 +13,19 @@ export declare class HookRegistry<P extends 'before' | 'after'> {
15
13
  * Registers a new hook function.
16
14
  * Hooks are executed sequentially in the order they are registered.
17
15
  *
18
- * @param fn - The hook function to execute.
16
+ * @param fn - The hook function to execute. It can optionally return a modified request/response, or a Promise resolving to one.
17
+ * * @example
18
+ * ```ts
19
+ * // Before Hook Example:
20
+ * axon.before.register((req, ctx) => {
21
+ * console.log(`Sending prompt to ${req.model}`);
22
+ * return req; // Optional: return modified request
23
+ * });
24
+ * * // After Hook Example:
25
+ * axon.after.register((req, res, ctx) => {
26
+ * console.log(`Received ${res.usage?.totalTokens} tokens`);
27
+ * });
28
+ * ```
19
29
  */
20
30
  register(fn: HookType<P>): void;
21
31
  /**
@@ -24,5 +34,4 @@ export declare class HookRegistry<P extends 'before' | 'after'> {
24
34
  */
25
35
  execute(...args: unknown[]): Promise<unknown>;
26
36
  }
27
- export {};
28
37
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/hooks/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEzE,KAAK,UAAU,GAAG,CAChB,GAAG,EAAE,UAAU,EACf,GAAG,EAAE,WAAW,KACb,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEvE,KAAK,SAAS,GAAG,CACf,GAAG,EAAE,UAAU,EACf,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,WAAW,KACb,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEzE,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/D;;;;GAIG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,QAAQ,GAAG,OAAO;IAGxC,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,KAAK,CAA0B;gBAEV,KAAK,EAAE,CAAC;IAErC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI;IAI/B;;;OAGG;IACG,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAyBpD"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/hooks/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAwC,MAAM,mBAAmB,CAAC;AAEhG,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAEtE;;;;GAIG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,QAAQ,GAAG,OAAO;IAGxC,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,KAAK,CAA0B;gBAEV,KAAK,EAAE,CAAC;IAErC;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI;IAI/B;;;OAGG;IACG,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAyBpD"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Manages a list of lifecycle hooks for a specific phase.
3
3
  *
4
- * @template P - The lifecycle phase this registry manages ('before' or 'after').
4
+ * @typeParam P - The lifecycle phase this registry manages ('before' or 'after').
5
5
  */
6
6
  export class HookRegistry {
7
7
  phase;
@@ -13,7 +13,19 @@ export class HookRegistry {
13
13
  * Registers a new hook function.
14
14
  * Hooks are executed sequentially in the order they are registered.
15
15
  *
16
- * @param fn - The hook function to execute.
16
+ * @param fn - The hook function to execute. It can optionally return a modified request/response, or a Promise resolving to one.
17
+ * * @example
18
+ * ```ts
19
+ * // Before Hook Example:
20
+ * axon.before.register((req, ctx) => {
21
+ * console.log(`Sending prompt to ${req.model}`);
22
+ * return req; // Optional: return modified request
23
+ * });
24
+ * * // After Hook Example:
25
+ * axon.after.register((req, res, ctx) => {
26
+ * console.log(`Received ${res.usage?.totalTokens} tokens`);
27
+ * });
28
+ * ```
17
29
  */
18
30
  register(fn) {
19
31
  this.hooks.push(fn);
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/hooks/registry.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAGM;IAFrB,KAAK,GAAuB,EAAE,CAAC;IAEvC,YAA6B,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;IAAG,CAAC;IAEzC;;;;;OAKG;IACH,QAAQ,CAAC,EAAe;QACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,GAAG,IAAe;QAC9B,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,IAAI,UAAU,GAAG,IAAI,CAAC,CAAC,CAAe,CAAC;YACvC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAgB,CAAC;YAEnC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAqB,EAAE,CAAC;gBAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;gBAC3C,IAAI,MAAM;oBAAE,UAAU,GAAG,MAAM,CAAC;YAClC,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAI,CA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AI,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAe,CAAC;YAClC,IAAI,UAAU,GAAG,IAAI,CAAC,CAAC,CAAgB,CAAC;YACxC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAgB,CAAC;YAEnC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAoB,EAAE,CAAC;gBAC7C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;gBAChD,IAAI,MAAM;oBAAE,UAAU,GAAG,MAAM,CAAC;YAClC,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -1,6 +1,5 @@
1
1
  import type { Axon } from '../core/axon.js';
2
- export type ClientMatcher = (client: unknown) => boolean;
3
- export type ClientPatcher = (client: unknown, axon: Axon) => void;
2
+ import { ClientMatcher, ClientPatcher } from '@/types/registry.js';
4
3
  /**
5
4
  * Manages the detection and patching of third-party LLM clients.
6
5
  * This registry acts as the bridge between Axon and libraries like `openai`, `anthropic`, etc.
@@ -20,9 +19,16 @@ export declare class LLMRegistry {
20
19
  /**
21
20
  * Patches a third-party client instance to route calls through Axon.
22
21
  *
23
- * @param client - The initialized LLM client instance (e.g. `new OpenAI(...)`).
22
+ * @param client - The initialized LLM client instance.
24
23
  * @returns The Axon instance for method chaining.
25
- * @throws {UnsupportedLLMProviderError} If the provided client is not supported or recognized.
24
+ * @throws UnsupportedLLMProviderError If the provided client is not supported or recognized.
25
+ * @example
26
+ * ```ts
27
+ * const axon = new Axon();
28
+ * const openai = new OpenAI({ apiKey: '...' });
29
+ * * // Patch the client
30
+ * axon.llm.register(openai);
31
+ * ```
26
32
  */
27
33
  register(client: unknown): Axon;
28
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/llm/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;AACzD,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;AAOlE;;;GAGG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAA8B;gBAEnC,IAAI,EAAE,IAAI;IAEvC;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAI7E;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;CAahC"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/llm/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQnE;;;GAGG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAA8B;gBAEnC,IAAI,EAAE,IAAI;IAEvC;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAI7E;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;CAahC"}
@@ -22,9 +22,16 @@ export class LLMRegistry {
22
22
  /**
23
23
  * Patches a third-party client instance to route calls through Axon.
24
24
  *
25
- * @param client - The initialized LLM client instance (e.g. `new OpenAI(...)`).
25
+ * @param client - The initialized LLM client instance.
26
26
  * @returns The Axon instance for method chaining.
27
- * @throws {UnsupportedLLMProviderError} If the provided client is not supported or recognized.
27
+ * @throws UnsupportedLLMProviderError If the provided client is not supported or recognized.
28
+ * @example
29
+ * ```ts
30
+ * const axon = new Axon();
31
+ * const openai = new OpenAI({ apiKey: '...' });
32
+ * * // Patch the client
33
+ * axon.llm.register(openai);
34
+ * ```
28
35
  */
29
36
  register(client) {
30
37
  for (const reg of LLMRegistry.globalRegistrations) {
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/llm/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAUjE;;;GAGG;AACH,MAAM,OAAO,WAAW;IAGO;IAFrB,MAAM,CAAC,mBAAmB,GAA2B,EAAE,CAAC;IAEhE,YAA6B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAG,CAAC;IAE3C;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAsB,EAAE,OAAsB;QACpE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAe;QACtB,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,mBAAmB,EAAE,CAAC;YAClD,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACxB,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;QAED,6DAA6D;QAC7D,MAAM,UAAU,GACb,MAAqD,EAAE,WAAW,EAAE,IAAI,IAAI,OAAO,MAAM,CAAC;QAC7F,MAAM,IAAI,2BAA2B,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC"}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/llm/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAOjE;;;GAGG;AACH,MAAM,OAAO,WAAW;IAGO;IAFrB,MAAM,CAAC,mBAAmB,GAA2B,EAAE,CAAC;IAEhE,YAA6B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAG,CAAC;IAE3C;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAsB,EAAE,OAAsB;QACpE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,MAAe;QACtB,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,mBAAmB,EAAE,CAAC;YAClD,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACxB,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;QAED,6DAA6D;QAC7D,MAAM,UAAU,GACb,MAAqD,EAAE,WAAW,EAAE,IAAI,IAAI,OAAO,MAAM,CAAC;QAC7F,MAAM,IAAI,2BAA2B,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAqB,MAAM,YAAY,CAAC;AAEjE,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,EAAE,CAgBlE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAKhF;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAS9D;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CASvE;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAYjF"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,EAAE,CAgBlE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAKhF;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAS9D;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CASvE;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAYjF"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/providers/anthropic/common.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAE7E,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAmB,EAAE,EAAE;QACvC,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,mEAAmE;QACnE,IAAI,O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AE,CAAC;QAC9D,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
@@ -1,2 +1,7 @@
1
+ /**
2
+ * Detects if the provided object is an initialized Anthropic client instance.
3
+ * @param client - The object to inspect.
4
+ * @returns True if it matches the Anthropic client shape.
5
+ */
1
6
  export declare function isAnthropicClient(client: unknown): boolean;
2
7
  //# sourceMappingURL=detect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/detect.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAM1D"}
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/detect.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAK1D"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Detects if the provided object is an initialized Anthropic client instance.
3
+ * @param client - The object to inspect.
4
+ * @returns True if it matches the Anthropic client shape.
5
+ */
1
6
  export function isAnthropicClient(client) {
2
7
  if (!client || typeof client !== 'object')
3
8
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"detect.js","sourceRoot":"","sources":["../../../src/providers/anthropic/detect.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAC/C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAExD,MAAM,GAAG,GAAG,MAA6C,CAAC;IAE1D,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;AACvE,CAAC"}
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../../../src/providers/anthropic/detect.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAC/C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACxD,MAAM,GAAG,GAAG,MAAyB,CAAC;IAEtC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;AACvE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAiD/C;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAmBtE"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAmD/C;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAmBtE"}
@@ -1,6 +1,7 @@
1
1
  import { anthropicInputToMessages, messagesToAnthropicInput, contentFromAnthropic, usageFromAnthropic, applyContentToResponse, } from './common.js';
2
2
  import { patchMethod } from '../patcher.js';
3
3
  import { extractSDKVersion } from '../telemetry.js';
4
+ import { PROVIDERS } from '../../utils/constants.js';
4
5
  function extractParams(args) {
5
6
  // Separate model and messages from extra provider-specific parameters
6
7
  const { model: _model, messages: _messages, ...params } = args;
@@ -48,7 +49,7 @@ export function patchAnthropicClient(client, axon) {
48
49
  axon,
49
50
  parent: antClient.messages,
50
51
  methodName: 'create',
51
- ctxMetadata: { provider: 'anthropic', method: 'messages.create', sdkVersion },
52
+ ctxMetadata: { provider: PROVIDERS.ANTHROPIC.id, method: 'messages.create', sdkVersion },
52
53
  argsToRequest,
53
54
  requestToArgs,
54
55
  rawToResponse: rawToCanonical,
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/providers/anthropic/proxy.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,SAAS,aAAa,CAAC,IAAyB;IAC9C,sEAAsE;IACtE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IAC/D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,IAAyB;IAC9C,OAAO;QACL,QAAQ,EAAE,wBAAwB,CAAC,IAAI,CAAC,QAAQ,CAAC;QACjD,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC;KAC5B,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,OAAmB;IACxC,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC1D,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,wBAAwB,CAAC,OAAO,CAAC;QAC3C,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;KACH,CAAC;AAC3B,CAAC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,OAAO,EAAE,OAAO,EAAE,oBAAoB,CAAC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B,CAAC,MAAe,EAAE,IAAU;IAC9D,MAAM,SAAS,GAAG,MAAyB,CAAC;IAC5C,MAAM,UAAU,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAEhD,IAAI,CAAE,SAAgD,CAAC,QAAQ,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,WAAW,CAAC;QACV,IAAI;QACJ,MAAM,EAAE,SAAS,CAAC,QAAQ;QAC1B,UAAU,EAAE,QAAQ;QACpB,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE;QACxF,aAAa;QACb,aAAa;QACb,aAAa,EAAE,cAAc;QAC7B,mBAAmB,EAAE,sBAAsB;QAC3C,WAAW;KACZ,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,22 @@
1
+ export interface AnthropicResponse {
2
+ content: Array<{
3
+ type: string;
4
+ text: string;
5
+ }>;
6
+ usage?: AnthropicUsage;
7
+ [key: string]: unknown;
8
+ }
9
+ export interface AnthropicUsage {
10
+ input_tokens: number;
11
+ output_tokens: number;
12
+ }
13
+ export interface AnthropicStreamEvent {
14
+ type: string;
15
+ delta?: {
16
+ type: string;
17
+ text?: string;
18
+ };
19
+ usage?: AnthropicUsage;
20
+ [key: string]: unknown;
21
+ }
22
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/responses.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../src/providers/anthropic/responses.ts"],"names":[],"mappings":""}
@@ -1,11 +1,3 @@
1
- export interface AnthropicMessage {
2
- role: string;
3
- content: string | Array<{
4
- type: string;
5
- text?: string;
6
- [key: string]: unknown;
7
- }>;
8
- }
9
1
  export interface AnthropicCreateArgs {
10
2
  model: string;
11
3
  messages: AnthropicMessage[];
@@ -13,29 +5,20 @@ export interface AnthropicCreateArgs {
13
5
  max_tokens?: number;
14
6
  [key: string]: unknown;
15
7
  }
16
- export interface AnthropicUsage {
17
- input_tokens: number;
18
- output_tokens: number;
19
- }
20
- export interface AnthropicResponse {
21
- content: Array<{
22
- type: string;
23
- text: string;
24
- }>;
25
- usage?: AnthropicUsage;
26
- [key: string]: unknown;
27
- }
28
- export interface AnthropicStreamEvent {
29
- type: string;
30
- delta?: {
8
+ export interface AnthropicMessage {
9
+ role: string;
10
+ content: string | Array<{
31
11
  type: string;
32
12
  text?: string;
33
- };
34
- usage?: AnthropicUsage;
35
- [key: string]: unknown;
13
+ [key: string]: unknown;
14
+ }>;
36
15
  }
16
+ /**
17
+ * The minimal expected shape of an initialized Anthropic client instance.
18
+ * Axon uses this interface to detect and safely patch the `messages.create` method.
19
+ */
37
20
  export interface AnthropicClient {
38
- messages: {
21
+ messages?: {
39
22
  create: (args: AnthropicCreateArgs) => Promise<unknown>;
40
23
  __axon_patched__?: boolean;
41
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC;CAClF;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE;QACR,MAAM,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;QACxD,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC;CACH"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC;CAClF;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE;QACT,MAAM,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;QACxD,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC;CACH"}
@@ -0,0 +1,8 @@
1
+ import { Message, LLMRequest, Usage, LLMResponse } from '../../types/index.js';
2
+ import { GeminiGenerateContentArgs } from './types.js';
3
+ export declare function geminiInputToMessages(contents: GeminiGenerateContentArgs['contents']): Message[];
4
+ export declare function messagesToGeminiInput(request: LLMRequest): GeminiGenerateContentArgs['contents'];
5
+ export declare function contentFromGemini(response: unknown): string;
6
+ export declare function usageFromGemini(response: unknown): Usage | undefined;
7
+ export declare function applyContentToGeminiResponse(raw: unknown, canonical: LLMResponse): void;
8
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAGvD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,yBAAyB,CAAC,UAAU,CAAC,GAAG,OAAO,EAAE,CAShG;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,UAAU,GAAG,yBAAyB,CAAC,UAAU,CAAC,CAKhG;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAO3D;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CASpE;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAOvF"}
@@ -0,0 +1,46 @@
1
+ export function geminiInputToMessages(contents) {
2
+ if (typeof contents === 'string')
3
+ return [{ role: 'user', content: contents }];
4
+ if (Array.isArray(contents)) {
5
+ return contents.map((c) => ({
6
+ role: (c.role === 'model' ? 'assistant' : 'user'),
7
+ content: c.parts.map((p) => p.text).join(''),
8
+ }));
9
+ }
10
+ return [];
11
+ }
12
+ export function messagesToGeminiInput(request) {
13
+ return request.messages.map((m) => ({
14
+ role: m.role === 'assistant' ? 'model' : m.role,
15
+ parts: [{ text: m.content }],
16
+ }));
17
+ }
18
+ export function contentFromGemini(response) {
19
+ const r = response;
20
+ if (r.text)
21
+ return r.text;
22
+ if (r.candidates?.[0]?.content?.parts?.[0]?.text) {
23
+ return r.candidates[0].content.parts[0].text;
24
+ }
25
+ return '';
26
+ }
27
+ export function usageFromGemini(response) {
28
+ const r = response;
29
+ if (!r.usageMetadata)
30
+ return undefined;
31
+ return {
32
+ promptTokens: r.usageMetadata.promptTokenCount,
33
+ completionTokens: r.usageMetadata.candidatesTokenCount,
34
+ totalTokens: r.usageMetadata.totalTokenCount,
35
+ };
36
+ }
37
+ export function applyContentToGeminiResponse(raw, canonical) {
38
+ const r = raw;
39
+ if (r.candidates?.[0]?.content?.parts?.[0]) {
40
+ r.candidates[0].content.parts[0].text = canonical.content;
41
+ }
42
+ else if (r.text !== undefined) {
43
+ r.text = canonical.content;
44
+ }
45
+ }
46
+ //# sourceMappingURL=common.js.map