@memorilabs/axon 0.0.1 → 0.1.0

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 (115) hide show
  1. package/README.md +99 -0
  2. package/dist/core/axon.d.ts +67 -0
  3. package/dist/core/axon.d.ts.map +1 -0
  4. package/dist/core/axon.js +68 -0
  5. package/dist/core/axon.js.map +1 -0
  6. package/dist/core/config.d.ts +6 -0
  7. package/dist/core/config.d.ts.map +1 -0
  8. package/dist/core/config.js +9 -0
  9. package/dist/core/config.js.map +1 -0
  10. package/dist/core/index.d.ts +3 -0
  11. package/dist/core/index.d.ts.map +1 -0
  12. package/dist/core/index.js +3 -0
  13. package/dist/core/index.js.map +1 -0
  14. package/dist/errors/axon-error.d.ts +7 -0
  15. package/dist/errors/axon-error.d.ts.map +1 -0
  16. package/dist/errors/axon-error.js +10 -0
  17. package/dist/errors/axon-error.js.map +1 -0
  18. package/dist/errors/hook-error.d.ts +13 -0
  19. package/dist/errors/hook-error.d.ts.map +1 -0
  20. package/dist/errors/hook-error.js +15 -0
  21. package/dist/errors/hook-error.js.map +1 -0
  22. package/dist/errors/index.d.ts +4 -0
  23. package/dist/errors/index.d.ts.map +1 -0
  24. package/dist/errors/index.js +4 -0
  25. package/dist/errors/index.js.map +1 -0
  26. package/dist/errors/unsupported-provider-error.d.ts +9 -0
  27. package/dist/errors/unsupported-provider-error.d.ts.map +1 -0
  28. package/dist/errors/unsupported-provider-error.js +13 -0
  29. package/dist/errors/unsupported-provider-error.js.map +1 -0
  30. package/dist/hooks/hooked.d.ts +48 -0
  31. package/dist/hooks/hooked.d.ts.map +1 -0
  32. package/dist/hooks/hooked.js +95 -0
  33. package/dist/hooks/hooked.js.map +1 -0
  34. package/dist/hooks/registry.d.ts +28 -0
  35. package/dist/hooks/registry.d.ts.map +1 -0
  36. package/dist/hooks/registry.js +50 -0
  37. package/dist/hooks/registry.js.map +1 -0
  38. package/dist/index.d.ts +6 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +6 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/llm/registry.d.ts +29 -0
  43. package/dist/llm/registry.d.ts.map +1 -0
  44. package/dist/llm/registry.js +41 -0
  45. package/dist/llm/registry.js.map +1 -0
  46. package/dist/providers/anthropic/common.d.ts +8 -0
  47. package/dist/providers/anthropic/common.d.ts.map +1 -0
  48. package/dist/providers/anthropic/common.js +58 -0
  49. package/dist/providers/anthropic/common.js.map +1 -0
  50. package/dist/providers/anthropic/detect.d.ts +2 -0
  51. package/dist/providers/anthropic/detect.d.ts.map +1 -0
  52. package/dist/providers/anthropic/detect.js +7 -0
  53. package/dist/providers/anthropic/detect.js.map +1 -0
  54. package/dist/providers/anthropic/index.d.ts +5 -0
  55. package/dist/providers/anthropic/index.d.ts.map +1 -0
  56. package/dist/providers/anthropic/index.js +10 -0
  57. package/dist/providers/anthropic/index.js.map +1 -0
  58. package/dist/providers/anthropic/proxy.d.ts +8 -0
  59. package/dist/providers/anthropic/proxy.d.ts.map +1 -0
  60. package/dist/providers/anthropic/proxy.js +57 -0
  61. package/dist/providers/anthropic/proxy.js.map +1 -0
  62. package/dist/providers/anthropic/types.d.ts +43 -0
  63. package/dist/providers/anthropic/types.d.ts.map +1 -0
  64. package/dist/providers/anthropic/types.js +2 -0
  65. package/dist/providers/anthropic/types.js.map +1 -0
  66. package/dist/providers/index.d.ts +4 -0
  67. package/dist/providers/index.d.ts.map +1 -0
  68. package/dist/providers/index.js +3 -0
  69. package/dist/providers/index.js.map +1 -0
  70. package/dist/providers/openai/common.d.ts +11 -0
  71. package/dist/providers/openai/common.d.ts.map +1 -0
  72. package/dist/providers/openai/common.js +42 -0
  73. package/dist/providers/openai/common.js.map +1 -0
  74. package/dist/providers/openai/detect.d.ts +2 -0
  75. package/dist/providers/openai/detect.d.ts.map +1 -0
  76. package/dist/providers/openai/detect.js +9 -0
  77. package/dist/providers/openai/detect.js.map +1 -0
  78. package/dist/providers/openai/index.d.ts +9 -0
  79. package/dist/providers/openai/index.d.ts.map +1 -0
  80. package/dist/providers/openai/index.js +14 -0
  81. package/dist/providers/openai/index.js.map +1 -0
  82. package/dist/providers/openai/proxy.d.ts +3 -0
  83. package/dist/providers/openai/proxy.d.ts.map +1 -0
  84. package/dist/providers/openai/proxy.js +91 -0
  85. package/dist/providers/openai/proxy.js.map +1 -0
  86. package/dist/providers/openai/responses.d.ts +26 -0
  87. package/dist/providers/openai/responses.d.ts.map +1 -0
  88. package/dist/providers/openai/responses.js +4 -0
  89. package/dist/providers/openai/responses.js.map +1 -0
  90. package/dist/providers/openai/types.d.ts +30 -0
  91. package/dist/providers/openai/types.d.ts.map +1 -0
  92. package/dist/providers/openai/types.js +2 -0
  93. package/dist/providers/openai/types.js.map +1 -0
  94. package/dist/providers/patcher.d.ts +15 -0
  95. package/dist/providers/patcher.d.ts.map +1 -0
  96. package/dist/providers/patcher.js +41 -0
  97. package/dist/providers/patcher.js.map +1 -0
  98. package/dist/types/config.d.ts +23 -0
  99. package/dist/types/config.d.ts.map +1 -0
  100. package/dist/types/config.js +2 -0
  101. package/dist/types/config.js.map +1 -0
  102. package/dist/types/context.d.ts +17 -0
  103. package/dist/types/context.d.ts.map +1 -0
  104. package/dist/types/context.js +13 -0
  105. package/dist/types/context.js.map +1 -0
  106. package/dist/types/index.d.ts +4 -0
  107. package/dist/types/index.d.ts.map +1 -0
  108. package/dist/types/index.js +4 -0
  109. package/dist/types/index.js.map +1 -0
  110. package/dist/types/llm.d.ts +46 -0
  111. package/dist/types/llm.d.ts.map +1 -0
  112. package/dist/types/llm.js +2 -0
  113. package/dist/types/llm.js.map +1 -0
  114. package/package.json +104 -4
  115. package/.npmrc.bak +0 -3
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Memori Axon - TypeScript SDK
2
+
3
+ TypeScript SDK for Memori's hosted memory service.
4
+
5
+ ---
6
+
7
+ ## 🚀 Quick Start
8
+
9
+ ```bash
10
+ # Install dependencies
11
+ npm install
12
+
13
+ # Format existing code
14
+ npm run format
15
+
16
+ # Run type check
17
+ npm run typecheck
18
+
19
+ # Build the project
20
+ npm run build
21
+ ```
22
+
23
+ ---
24
+
25
+ ## 📜 Available Commands
26
+
27
+ ### Development
28
+
29
+ | Command | Description |
30
+ | ----------------- | ----------------------------- |
31
+ | `npm run build` | Compile TypeScript to `dist/` |
32
+ | `npm run example` | Build and run example script |
33
+
34
+ ### Testing
35
+
36
+ | Command | Description |
37
+ | -------------------- | ----------------------- |
38
+ | `npm test` | Run tests once |
39
+ | `npm run test:watch` | Run tests in watch mode |
40
+
41
+ ### Code Quality
42
+
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) |
50
+
51
+ ---
52
+
53
+ ## 🔧 Git Hooks
54
+
55
+ Pre-commit and pre-push hooks are configured to maintain code quality automatically.
56
+
57
+ ### Pre-commit Hook
58
+
59
+ Runs automatically on `git commit`:
60
+
61
+ - ✅ ESLint (with auto-fix)
62
+ - ✅ Prettier (formatting)
63
+ - ✅ Only checks staged files
64
+
65
+ ### Pre-push Hook
66
+
67
+ Runs automatically on `git push`:
68
+
69
+ - ✅ TypeScript type checking
70
+
71
+ ### Bypass Hooks (Use Sparingly)
72
+
73
+ ```bash
74
+ git commit --no-verify # Skip pre-commit hook
75
+ git push --no-verify # Skip pre-push hook
76
+ ```
77
+
78
+ ---
79
+
80
+ ## 📦 Project Structure
81
+
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
+ ```
90
+
91
+ ---
92
+
93
+ ## 🛠️ Development Workflow
94
+
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)
@@ -0,0 +1,67 @@
1
+ import { AxonConfig } from '../types/config.js';
2
+ import { HookRegistry } from '../hooks/registry.js';
3
+ import { LLMRegistry } from '../llm/registry.js';
4
+ import { CallContext, LLMRequest, LLMResponse } from '../types/index.js';
5
+ /**
6
+ * Configuration options for initializing Axon.
7
+ */
8
+ export interface AxonOpts {
9
+ /** Runtime configuration overrides. */
10
+ config?: AxonConfig;
11
+ }
12
+ /**
13
+ * The central hub for the Axon SDK.
14
+ *
15
+ * This class orchestrates the lifecycle of LLM calls, managing:
16
+ * - Provider registration (e.g., wrapping OpenAI).
17
+ * - Hook execution (before/after calls).
18
+ * - Configuration state.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { Axon } from 'axon';
23
+ * import { OpenAI } from 'openai';
24
+ *
25
+ * const axon = new Axon({ config: { failFast: true } });
26
+ * const client = new OpenAI();
27
+ *
28
+ * // 1. Register the client
29
+ * axon.llm.register(client);
30
+ *
31
+ * // 2. Add hooks
32
+ * axon.before.register((req) => {
33
+ * console.log('Sending to:', req.model);
34
+ * return req;
35
+ * });
36
+ *
37
+ * // 3. Use client as normal
38
+ * await client.chat.completions.create({ ... });
39
+ * ```
40
+ */
41
+ export declare class Axon {
42
+ /** The active configuration for this instance. */
43
+ readonly config: Required<AxonConfig>;
44
+ /** Registry for managing third-party LLM providers. */
45
+ readonly llm: LLMRegistry;
46
+ /** Registry for hooks that run *before* the LLM call. */
47
+ readonly before: HookRegistry<'before'>;
48
+ /** Registry for hooks that run *after* the LLM call. */
49
+ readonly after: HookRegistry<'after'>;
50
+ /**
51
+ * Creates a new Axon instance.
52
+ *
53
+ * @param opts - Initialization options, including configuration overrides.
54
+ */
55
+ constructor(opts?: AxonOpts);
56
+ /**
57
+ * Executes the 'before' hook pipeline.
58
+ * @internal
59
+ */
60
+ runBefore(request: LLMRequest, ctx: CallContext): Promise<LLMRequest>;
61
+ /**
62
+ * Executes the 'after' hook pipeline.
63
+ * @internal
64
+ */
65
+ runAfter(request: LLMRequest, response: LLMResponse, ctx: CallContext): Promise<LLMResponse>;
66
+ }
67
+ //# sourceMappingURL=axon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axon.d.ts","sourceRoot":"","sources":["../../src/core/axon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,uCAAuC;IACvC,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,IAAI;IACf,kDAAkD;IAClD,SAAgB,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7C,uDAAuD;IACvD,SAAgB,GAAG,EAAE,WAAW,CAAC;IACjC,yDAAyD;IACzD,SAAgB,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC/C,wDAAwD;IACxD,SAAgB,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAE7C;;;;OAIG;gBACS,IAAI,GAAE,QAAa;IAO/B;;;OAGG;IACG,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAI3E;;;OAGG;IACG,QAAQ,CACZ,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,WAAW,EACrB,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,WAAW,CAAC;CAGxB"}
@@ -0,0 +1,68 @@
1
+ import { defaultAxonConfig } from './config.js';
2
+ import { HookRegistry } from '../hooks/registry.js';
3
+ import { LLMRegistry } from '../llm/registry.js';
4
+ /**
5
+ * The central hub for the Axon SDK.
6
+ *
7
+ * This class orchestrates the lifecycle of LLM calls, managing:
8
+ * - Provider registration (e.g., wrapping OpenAI).
9
+ * - Hook execution (before/after calls).
10
+ * - Configuration state.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Axon } from 'axon';
15
+ * import { OpenAI } from 'openai';
16
+ *
17
+ * const axon = new Axon({ config: { failFast: true } });
18
+ * const client = new OpenAI();
19
+ *
20
+ * // 1. Register the client
21
+ * axon.llm.register(client);
22
+ *
23
+ * // 2. Add hooks
24
+ * axon.before.register((req) => {
25
+ * console.log('Sending to:', req.model);
26
+ * return req;
27
+ * });
28
+ *
29
+ * // 3. Use client as normal
30
+ * await client.chat.completions.create({ ... });
31
+ * ```
32
+ */
33
+ export class Axon {
34
+ /** The active configuration for this instance. */
35
+ config;
36
+ /** Registry for managing third-party LLM providers. */
37
+ llm;
38
+ /** Registry for hooks that run *before* the LLM call. */
39
+ before;
40
+ /** Registry for hooks that run *after* the LLM call. */
41
+ after;
42
+ /**
43
+ * Creates a new Axon instance.
44
+ *
45
+ * @param opts - Initialization options, including configuration overrides.
46
+ */
47
+ constructor(opts = {}) {
48
+ this.config = { ...defaultAxonConfig, ...(opts.config ?? {}) };
49
+ this.llm = new LLMRegistry(this);
50
+ this.before = new HookRegistry('before');
51
+ this.after = new HookRegistry('after');
52
+ }
53
+ /**
54
+ * Executes the 'before' hook pipeline.
55
+ * @internal
56
+ */
57
+ async runBefore(request, ctx) {
58
+ return (await this.before.execute(request, ctx));
59
+ }
60
+ /**
61
+ * Executes the 'after' hook pipeline.
62
+ * @internal
63
+ */
64
+ async runAfter(request, response, ctx) {
65
+ return (await this.after.execute(request, response, ctx));
66
+ }
67
+ }
68
+ //# sourceMappingURL=axon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axon.js","sourceRoot":"","sources":["../../src/core/axon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAWjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,IAAI;IACf,kDAAkD;IAClC,MAAM,CAAuB;IAC7C,uDAAuD;IACvC,GAAG,CAAc;IACjC,yDAAyD;IACzC,MAAM,CAAyB;IAC/C,wDAAwD;IACxC,KAAK,CAAwB;IAE7C;;;;OAIG;IACH,YAAY,OAAiB,EAAE;QAC7B,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,iBAAiB,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;QAC/D,IAAI,CAAC,GAAG,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS,CAAC,OAAmB,EAAE,GAAgB;QACnD,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAe,CAAC;IACjE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ,CACZ,OAAmB,EACnB,QAAqB,EACrB,GAAgB;QAEhB,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAgB,CAAC;IAC3E,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { AxonConfig } from '../types/config.js';
2
+ /**
3
+ * The default configuration values used when no overrides are provided.
4
+ */
5
+ export declare const defaultAxonConfig: Required<AxonConfig>;
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,UAAU,CAIlD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The default configuration values used when no overrides are provided.
3
+ */
4
+ export const defaultAxonConfig = {
5
+ failFast: true,
6
+ postCallBackground: false,
7
+ collectHookTimings: false,
8
+ };
9
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAyB;IACrD,QAAQ,EAAE,IAAI;IACd,kBAAkB,EAAE,KAAK;IACzB,kBAAkB,EAAE,KAAK;CAC1B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Axon } from './axon.js';
2
+ export { defaultAxonConfig } from './config.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Axon } from './axon.js';
2
+ export { defaultAxonConfig } from './config.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Base class for all Axon-related errors.
3
+ */
4
+ export declare class AxonError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ //# sourceMappingURL=axon-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axon-error.d.ts","sourceRoot":"","sources":["../../src/errors/axon-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Base class for all Axon-related errors.
3
+ */
4
+ export class AxonError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'AxonError';
8
+ }
9
+ }
10
+ //# sourceMappingURL=axon-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axon-error.js","sourceRoot":"","sources":["../../src/errors/axon-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { AxonError } from './axon-error.js';
2
+ /**
3
+ * Thrown when a 'before' or 'after' hook fails execution.
4
+ */
5
+ export declare class AxonHookError extends AxonError {
6
+ readonly hook: 'before_call' | 'after_call';
7
+ readonly cause: unknown;
8
+ constructor(opts: {
9
+ hook: 'before_call' | 'after_call';
10
+ cause: unknown;
11
+ });
12
+ }
13
+ //# sourceMappingURL=hook-error.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,15 @@
1
+ import { AxonError } from './axon-error.js';
2
+ /**
3
+ * Thrown when a 'before' or 'after' hook fails execution.
4
+ */
5
+ export class AxonHookError extends AxonError {
6
+ hook;
7
+ cause;
8
+ constructor(opts) {
9
+ super(`${opts.hook} hook failed: ${String(opts.cause)}`);
10
+ this.name = 'AxonHookError';
11
+ this.hook = opts.hook;
12
+ this.cause = opts.cause;
13
+ }
14
+ }
15
+ //# sourceMappingURL=hook-error.js.map
@@ -0,0 +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"}
@@ -0,0 +1,4 @@
1
+ export { AxonError } from './axon-error.js';
2
+ export { AxonHookError } from './hook-error.js';
3
+ export { UnsupportedLLMProviderError } from './unsupported-provider-error.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { AxonError } from './axon-error.js';
2
+ export { AxonHookError } from './hook-error.js';
3
+ export { UnsupportedLLMProviderError } from './unsupported-provider-error.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { AxonError } from './axon-error.js';
2
+ /**
3
+ * Thrown when attempting to register a client that Axon does not recognize.
4
+ */
5
+ export declare class UnsupportedLLMProviderError extends AxonError {
6
+ readonly provider: string;
7
+ constructor(provider: string);
8
+ }
9
+ //# sourceMappingURL=unsupported-provider-error.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,13 @@
1
+ import { AxonError } from './axon-error.js';
2
+ /**
3
+ * Thrown when attempting to register a client that Axon does not recognize.
4
+ */
5
+ export class UnsupportedLLMProviderError extends AxonError {
6
+ provider;
7
+ constructor(provider) {
8
+ super(`Unsupported LLM provider: ${provider}`);
9
+ this.name = 'UnsupportedLLMProviderError';
10
+ this.provider = provider;
11
+ }
12
+ }
13
+ //# sourceMappingURL=unsupported-provider-error.js.map
@@ -0,0 +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"}
@@ -0,0 +1,48 @@
1
+ import { Axon } from '../core/axon.js';
2
+ import { CallContext, LLMRequest, LLMResponse } from '../types/index.js';
3
+ export type ArgsToRequest<TInput> = (args: TInput) => LLMRequest;
4
+ export type RequestToArgs<TInput> = (request: LLMRequest) => TInput;
5
+ export type RawToResponse<TOutput> = (raw: TOutput) => LLMResponse;
6
+ export type ApplyCanonicalToRaw<TOutput> = (raw: TOutput, canonical: LLMResponse) => void;
7
+ /**
8
+ * Intercepts an async iterable stream to buffer content for 'after' hooks.
9
+ * @internal
10
+ */
11
+ export declare class HookedStream<TChunk> implements AsyncIterable<TChunk> {
12
+ private readonly stream;
13
+ private readonly request;
14
+ private readonly ctx;
15
+ private readonly axon;
16
+ private readonly chunkToText;
17
+ private readonly getFinalResponse;
18
+ private accumulatedContent;
19
+ private hasFinished;
20
+ constructor(stream: AsyncIterable<TChunk>, request: LLMRequest, ctx: CallContext, axon: Axon, chunkToText: (chunk: unknown) => string | undefined, getFinalResponse: () => unknown);
21
+ [Symbol.asyncIterator](): AsyncIterator<TChunk>;
22
+ private finalize;
23
+ }
24
+ /**
25
+ * A proxy handler that injects Axon logic into a provider's `create` method.
26
+ * @internal
27
+ */
28
+ export declare class HookedCreateProxy<TInput, TOutput> {
29
+ private opts;
30
+ constructor(opts: {
31
+ create: (input: TInput) => Promise<TOutput>;
32
+ axon: Axon;
33
+ ctxMetadata: Record<string, unknown>;
34
+ argsToRequest: ArgsToRequest<TInput>;
35
+ requestToArgs: RequestToArgs<TInput>;
36
+ rawToResponse: RawToResponse<TOutput>;
37
+ applyCanonicalToRaw?: ApplyCanonicalToRaw<TOutput>;
38
+ chunkToText?: (chunk: unknown) => string | undefined;
39
+ });
40
+ executeCreate(input: TInput): Promise<TOutput>;
41
+ }
42
+ /**
43
+ * @internal
44
+ */
45
+ export declare class CreateFacade {
46
+ static wrap<TInput, TOutput>(originalFn: (input: TInput) => Promise<TOutput>, proxy: HookedCreateProxy<TInput, TOutput>): (input: TInput) => Promise<TOutput>;
47
+ }
48
+ //# sourceMappingURL=hooked.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooked.d.ts","sourceRoot":"","sources":["../../src/hooks/hooked.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAqB,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5F,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CAAC;AACjE,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,MAAM,CAAC;AACpE,MAAM,MAAM,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,OAAO,KAAK,WAAW,CAAC;AACnE,MAAM,MAAM,mBAAmB,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,KAAK,IAAI,CAAC;AAW1F;;;GAGG;AACH,qBAAa,YAAY,CAAC,MAAM,CAAE,YAAW,aAAa,CAAC,MAAM,CAAC;IAK9D,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,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B,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAC/C,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC;CAIvC"}
@@ -0,0 +1,95 @@
1
+ import { createCallContext } from '../types/index.js';
2
+ function isStreamArgs(args) {
3
+ return (typeof args === 'object' &&
4
+ args !== null &&
5
+ 'stream' in args &&
6
+ args.stream);
7
+ }
8
+ /**
9
+ * Intercepts an async iterable stream to buffer content for 'after' hooks.
10
+ * @internal
11
+ */
12
+ export class HookedStream {
13
+ stream;
14
+ request;
15
+ ctx;
16
+ axon;
17
+ chunkToText;
18
+ getFinalResponse;
19
+ accumulatedContent = [];
20
+ hasFinished = false;
21
+ constructor(stream, request, ctx, axon, chunkToText, getFinalResponse) {
22
+ this.stream = stream;
23
+ this.request = request;
24
+ this.ctx = ctx;
25
+ this.axon = axon;
26
+ this.chunkToText = chunkToText;
27
+ this.getFinalResponse = getFinalResponse;
28
+ }
29
+ async *[Symbol.asyncIterator]() {
30
+ try {
31
+ for await (const value of this.stream) {
32
+ const text = this.chunkToText(value);
33
+ if (text) {
34
+ this.accumulatedContent.push(text);
35
+ }
36
+ yield value;
37
+ }
38
+ }
39
+ finally {
40
+ if (!this.hasFinished) {
41
+ this.hasFinished = true;
42
+ await this.finalize();
43
+ }
44
+ }
45
+ }
46
+ async finalize() {
47
+ const canonical = {
48
+ content: this.accumulatedContent.join(''),
49
+ raw: this.getFinalResponse(),
50
+ };
51
+ await this.axon.runAfter(this.request, canonical, this.ctx);
52
+ }
53
+ }
54
+ /**
55
+ * A proxy handler that injects Axon logic into a provider's `create` method.
56
+ * @internal
57
+ */
58
+ export class HookedCreateProxy {
59
+ opts;
60
+ constructor(opts) {
61
+ this.opts = opts;
62
+ }
63
+ async executeCreate(input) {
64
+ const ctx = createCallContext({ metadata: { ...this.opts.ctxMetadata } });
65
+ // 1. Run Before Hooks
66
+ let request = this.opts.argsToRequest(input);
67
+ request = await this.opts.axon.runBefore(request, ctx);
68
+ // 2. Execute Original Method
69
+ const rawArgs = this.opts.requestToArgs(request);
70
+ const isStream = isStreamArgs(rawArgs);
71
+ const raw = await this.opts.create(rawArgs);
72
+ // 3. Handle Streams (Hooks run on completion)
73
+ if (isStream && this.opts.chunkToText) {
74
+ return new HookedStream(raw, request, ctx, this.opts.axon, this.opts.chunkToText, () => raw);
75
+ }
76
+ // 4. Handle Standard Response (Run After Hooks immediately)
77
+ let canonical = this.opts.rawToResponse(raw);
78
+ canonical = await this.opts.axon.runAfter(request, canonical, ctx);
79
+ // 5. Apply mutations back to the raw object
80
+ if (this.opts.applyCanonicalToRaw) {
81
+ this.opts.applyCanonicalToRaw(raw, canonical);
82
+ }
83
+ return raw;
84
+ }
85
+ }
86
+ /**
87
+ * @internal
88
+ */
89
+ export class CreateFacade {
90
+ static wrap(originalFn, proxy) {
91
+ const wrapped = (input) => proxy.executeCreate(input);
92
+ return Object.assign(wrapped, originalFn);
93
+ }
94
+ }
95
+ //# sourceMappingURL=hooked.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooked.js","sourceRoot":"","sources":["../../src/hooks/hooked.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,iBAAiB,EAA2B,MAAM,mBAAmB,CAAC;AAO5F,SAAS,YAAY,CAAC,IAAa;IACjC,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,QAAQ,IAAI,IAAI;QACf,IAA4B,CAAC,MAAM,CACrC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,YAAY;IAKJ;IACA;IACA;IACA;IACA;IACA;IATX,kBAAkB,GAAa,EAAE,CAAC;IAClC,WAAW,GAAG,KAAK,CAAC;IAE5B,YACmB,MAA6B,EAC7B,OAAmB,EACnB,GAAgB,EAChB,IAAU,EACV,WAAmD,EACnD,gBAA+B;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YAAY;IACvB,MAAM,CAAC,IAAI,CACT,UAA+C,EAC/C,KAAyC;QAEzC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9D,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,28 @@
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;
5
+ /**
6
+ * Manages a list of lifecycle hooks for a specific phase.
7
+ *
8
+ * @template P - The lifecycle phase this registry manages ('before' or 'after').
9
+ */
10
+ export declare class HookRegistry<P extends 'before' | 'after'> {
11
+ private readonly phase;
12
+ private hooks;
13
+ constructor(phase: P);
14
+ /**
15
+ * Registers a new hook function.
16
+ * Hooks are executed sequentially in the order they are registered.
17
+ *
18
+ * @param fn - The hook function to execute.
19
+ */
20
+ register(fn: HookType<P>): void;
21
+ /**
22
+ * Executes all registered hooks in sequence.
23
+ * @internal
24
+ */
25
+ execute(...args: unknown[]): Promise<unknown>;
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Manages a list of lifecycle hooks for a specific phase.
3
+ *
4
+ * @template P - The lifecycle phase this registry manages ('before' or 'after').
5
+ */
6
+ export class HookRegistry {
7
+ phase;
8
+ hooks = [];
9
+ constructor(phase) {
10
+ this.phase = phase;
11
+ }
12
+ /**
13
+ * Registers a new hook function.
14
+ * Hooks are executed sequentially in the order they are registered.
15
+ *
16
+ * @param fn - The hook function to execute.
17
+ */
18
+ register(fn) {
19
+ this.hooks.push(fn);
20
+ }
21
+ /**
22
+ * Executes all registered hooks in sequence.
23
+ * @internal
24
+ */
25
+ async execute(...args) {
26
+ if (this.phase === 'before') {
27
+ let currentReq = args[0];
28
+ const ctx = args[1];
29
+ for (const hook of this.hooks) {
30
+ const result = await hook(currentReq, ctx);
31
+ if (result)
32
+ currentReq = result;
33
+ }
34
+ return currentReq;
35
+ }
36
+ if (this.phase === 'after') {
37
+ const req = args[0];
38
+ let currentRes = args[1];
39
+ const ctx = args[2];
40
+ for (const hook of this.hooks) {
41
+ const result = await hook(req, currentRes, ctx);
42
+ if (result)
43
+ currentRes = result;
44
+ }
45
+ return currentRes;
46
+ }
47
+ return undefined;
48
+ }
49
+ }
50
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +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,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,IAA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