@x12i/ai-tools 1.0.2

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 (113) hide show
  1. package/README.md +214 -0
  2. package/dist/AiModelsCatalogClient-4RF5BCDL.cjs +9 -0
  3. package/dist/AiModelsCatalogClient-4RF5BCDL.cjs.map +1 -0
  4. package/dist/AiModelsCatalogClient-B-dNLXX0.d.ts +29 -0
  5. package/dist/AiModelsCatalogClient-CSVlKql5.d.cts +29 -0
  6. package/dist/AiModelsCatalogClient-NUF3CBLW.js +9 -0
  7. package/dist/AiModelsCatalogClient-NUF3CBLW.js.map +1 -0
  8. package/dist/aliases/index.cjs +11 -0
  9. package/dist/aliases/index.cjs.map +1 -0
  10. package/dist/aliases/index.d.cts +21 -0
  11. package/dist/aliases/index.d.ts +21 -0
  12. package/dist/aliases/index.js +11 -0
  13. package/dist/aliases/index.js.map +1 -0
  14. package/dist/catalox/index.cjs +21 -0
  15. package/dist/catalox/index.cjs.map +1 -0
  16. package/dist/catalox/index.d.cts +23 -0
  17. package/dist/catalox/index.d.ts +23 -0
  18. package/dist/catalox/index.js +21 -0
  19. package/dist/catalox/index.js.map +1 -0
  20. package/dist/chunk-2PYACSZ5.cjs +1 -0
  21. package/dist/chunk-2PYACSZ5.cjs.map +1 -0
  22. package/dist/chunk-3E67S427.cjs +1 -0
  23. package/dist/chunk-3E67S427.cjs.map +1 -0
  24. package/dist/chunk-4NAY6HRP.js +137 -0
  25. package/dist/chunk-4NAY6HRP.js.map +1 -0
  26. package/dist/chunk-5HNFAYTO.cjs +254 -0
  27. package/dist/chunk-5HNFAYTO.cjs.map +1 -0
  28. package/dist/chunk-6QGDZTGH.js +127 -0
  29. package/dist/chunk-6QGDZTGH.js.map +1 -0
  30. package/dist/chunk-7Q742NI3.cjs +106 -0
  31. package/dist/chunk-7Q742NI3.cjs.map +1 -0
  32. package/dist/chunk-AJEKEWWB.js +106 -0
  33. package/dist/chunk-AJEKEWWB.js.map +1 -0
  34. package/dist/chunk-AV6OE2YQ.cjs +127 -0
  35. package/dist/chunk-AV6OE2YQ.cjs.map +1 -0
  36. package/dist/chunk-COK34C6P.js +1 -0
  37. package/dist/chunk-COK34C6P.js.map +1 -0
  38. package/dist/chunk-DJ5SWJDY.js +729 -0
  39. package/dist/chunk-DJ5SWJDY.js.map +1 -0
  40. package/dist/chunk-F2F4UEFD.cjs +75 -0
  41. package/dist/chunk-F2F4UEFD.cjs.map +1 -0
  42. package/dist/chunk-G2G4KSC5.js +30 -0
  43. package/dist/chunk-G2G4KSC5.js.map +1 -0
  44. package/dist/chunk-HHNHWYTP.cjs +105 -0
  45. package/dist/chunk-HHNHWYTP.cjs.map +1 -0
  46. package/dist/chunk-HN6UAQAE.cjs +83 -0
  47. package/dist/chunk-HN6UAQAE.cjs.map +1 -0
  48. package/dist/chunk-KHODXGPV.js +1 -0
  49. package/dist/chunk-KHODXGPV.js.map +1 -0
  50. package/dist/chunk-KQOALKKX.js +75 -0
  51. package/dist/chunk-KQOALKKX.js.map +1 -0
  52. package/dist/chunk-LYOU7CA2.cjs +30 -0
  53. package/dist/chunk-LYOU7CA2.cjs.map +1 -0
  54. package/dist/chunk-ML2FRR4L.js +105 -0
  55. package/dist/chunk-ML2FRR4L.js.map +1 -0
  56. package/dist/chunk-MLRHYOCD.js +160 -0
  57. package/dist/chunk-MLRHYOCD.js.map +1 -0
  58. package/dist/chunk-O2A6OVEH.js +240 -0
  59. package/dist/chunk-O2A6OVEH.js.map +1 -0
  60. package/dist/chunk-ONA73BU6.cjs +160 -0
  61. package/dist/chunk-ONA73BU6.cjs.map +1 -0
  62. package/dist/chunk-QCRLKVB3.cjs +137 -0
  63. package/dist/chunk-QCRLKVB3.cjs.map +1 -0
  64. package/dist/chunk-QWAX7VQO.cjs +240 -0
  65. package/dist/chunk-QWAX7VQO.cjs.map +1 -0
  66. package/dist/chunk-TF4L2NEC.cjs +729 -0
  67. package/dist/chunk-TF4L2NEC.cjs.map +1 -0
  68. package/dist/chunk-XRBZQQQU.js +254 -0
  69. package/dist/chunk-XRBZQQQU.js.map +1 -0
  70. package/dist/chunk-YHO57D2V.js +83 -0
  71. package/dist/chunk-YHO57D2V.js.map +1 -0
  72. package/dist/cli/index.cjs +403 -0
  73. package/dist/cli/index.cjs.map +1 -0
  74. package/dist/cli/index.d.cts +1 -0
  75. package/dist/cli/index.d.ts +1 -0
  76. package/dist/cli/index.js +403 -0
  77. package/dist/cli/index.js.map +1 -0
  78. package/dist/cost/index.cjs +7 -0
  79. package/dist/cost/index.cjs.map +1 -0
  80. package/dist/cost/index.d.cts +52 -0
  81. package/dist/cost/index.d.ts +52 -0
  82. package/dist/cost/index.js +7 -0
  83. package/dist/cost/index.js.map +1 -0
  84. package/dist/index.cjs +104 -0
  85. package/dist/index.cjs.map +1 -0
  86. package/dist/index.d.cts +58 -0
  87. package/dist/index.d.ts +58 -0
  88. package/dist/index.js +104 -0
  89. package/dist/index.js.map +1 -0
  90. package/dist/modelNameResolver-Bn8QnkSj.d.ts +80 -0
  91. package/dist/modelNameResolver-bZD-eBSJ.d.cts +80 -0
  92. package/dist/models/index.cjs +33 -0
  93. package/dist/models/index.cjs.map +1 -0
  94. package/dist/models/index.d.cts +75 -0
  95. package/dist/models/index.d.ts +75 -0
  96. package/dist/models/index.js +33 -0
  97. package/dist/models/index.js.map +1 -0
  98. package/dist/sync/index.cjs +38 -0
  99. package/dist/sync/index.cjs.map +1 -0
  100. package/dist/sync/index.d.cts +12 -0
  101. package/dist/sync/index.d.ts +12 -0
  102. package/dist/sync/index.js +38 -0
  103. package/dist/sync/index.js.map +1 -0
  104. package/dist/toolbox/index.cjs +7 -0
  105. package/dist/toolbox/index.cjs.map +1 -0
  106. package/dist/toolbox/index.d.cts +72 -0
  107. package/dist/toolbox/index.d.ts +72 -0
  108. package/dist/toolbox/index.js +7 -0
  109. package/dist/toolbox/index.js.map +1 -0
  110. package/dist/types-DdGB3YaA.d.cts +278 -0
  111. package/dist/types-DdGB3YaA.d.ts +278 -0
  112. package/package.json +115 -0
  113. package/schemas/aliases.json +28 -0
@@ -0,0 +1,75 @@
1
+ import { a as AiModelRecord, M as ModelListFilters, g as ModelListResult, j as ModelResolutionResult, m as OpenRouterModelApi } from '../types-DdGB3YaA.js';
2
+ export { A as AiModelPricing, O as OpenRouterArchitectureApi, n as OpenRouterModelsQuery, o as OpenRouterModelsResponse, p as OpenRouterOutputModality, q as OpenRouterPricingApi, s as OpenRouterTopProviderApi } from '../types-DdGB3YaA.js';
3
+ import { Catalox, CatalogQueryOptions } from '@x12i/catalox';
4
+
5
+ type AiModelsServiceOptions = {
6
+ catalox: Catalox;
7
+ appId?: string;
8
+ catalogId?: string;
9
+ cacheTtlMs?: number;
10
+ };
11
+ /**
12
+ * High-level model catalog API — list, filter, count, and get full model info.
13
+ */
14
+ declare class AiModelsService {
15
+ private readonly client;
16
+ private readonly catalox;
17
+ private readonly appId;
18
+ private readonly catalogId;
19
+ constructor(options: AiModelsServiceOptions);
20
+ private context;
21
+ /** Load all models (cached). */
22
+ getAllModels(): Promise<Map<string, AiModelRecord>>;
23
+ /** List models with in-memory filters (fast after cache warm). */
24
+ listModels(filters?: ModelListFilters): Promise<ModelListResult>;
25
+ /** Count models matching filters. */
26
+ countModels(filters?: Omit<ModelListFilters, "limit" | "offset">): Promise<number>;
27
+ /**
28
+ * Full model record by id or alias (same resolution as cost calculator).
29
+ */
30
+ getModelInfo(modelIdOrAlias: string): Promise<AiModelRecord | null>;
31
+ /**
32
+ * Query via Catalox indexed fields (provider, status, output modality, tools).
33
+ * Falls back to in-memory filter when Catalox returns partial pages.
34
+ */
35
+ listModelsFromCatalog(filters?: ModelListFilters, options?: CatalogQueryOptions): Promise<ModelListResult>;
36
+ resolve(modelIdOrAlias: string, provider?: string): Promise<ModelResolutionResult>;
37
+ refresh(): Promise<void>;
38
+ }
39
+ /** Convenience: getModelInfo */
40
+ declare function getModelInfo(service: AiModelsService, modelIdOrAlias: string): Promise<AiModelRecord | null>;
41
+
42
+ declare function filterModels(models: Iterable<AiModelRecord>, filters?: ModelListFilters): AiModelRecord[];
43
+ declare function countModels(models: Iterable<AiModelRecord>, filters?: Omit<ModelListFilters, "limit" | "offset">): number;
44
+
45
+ declare function extractProviderId(modelId: string): string;
46
+ declare function normalizeOpenRouterModel(row: OpenRouterModelApi, syncedAt: string): AiModelRecord;
47
+
48
+ /** OpenRouter `supported_parameters` values that indicate reasoning API support. */
49
+ declare const REASONING_SUPPORTED_PARAMETERS: readonly ["reasoning", "include_reasoning"];
50
+ type ReasoningModelInput = Pick<AiModelRecord, "supportedParameters" | "pricing" | "openRouterPricing"> & {
51
+ supportsReasoning?: boolean;
52
+ };
53
+ /**
54
+ * Whether the model accepts OpenRouter's `reasoning` request parameter
55
+ * (effort, max_tokens, exclude, enabled).
56
+ */
57
+ declare function supportsReasoningParameter(model: Pick<AiModelRecord, "supportedParameters">): boolean;
58
+ /**
59
+ * Whether the model bills separate reasoning / thinking tokens
60
+ * (`internal_reasoning` in OpenRouter pricing).
61
+ */
62
+ declare function hasReasoningPricing(model: Pick<AiModelRecord, "pricing" | "openRouterPricing">): boolean;
63
+ /**
64
+ * Compute `supportsReasoning` from catalog fields (used during sync normalization).
65
+ */
66
+ declare function computeSupportsReasoning(model: ReasoningModelInput): boolean;
67
+ /**
68
+ * True when the model supports reasoning tokens (API param and/or separate reasoning pricing).
69
+ *
70
+ * Prefer `model.supportsReasoning` on {@link AiModelRecord} after catalog sync;
71
+ * this helper also works when only partial fields are available.
72
+ */
73
+ declare function isReasoningModel(model: ReasoningModelInput): boolean;
74
+
75
+ export { AiModelRecord, AiModelsService, type AiModelsServiceOptions, ModelListFilters, ModelListResult, OpenRouterModelApi, REASONING_SUPPORTED_PARAMETERS, type ReasoningModelInput, computeSupportsReasoning, countModels, extractProviderId, filterModels, getModelInfo, hasReasoningPricing, isReasoningModel, normalizeOpenRouterModel, supportsReasoningParameter };
@@ -0,0 +1,33 @@
1
+ import "../chunk-COK34C6P.js";
2
+ import {
3
+ AiModelsService,
4
+ countModels,
5
+ filterModels,
6
+ getModelInfo
7
+ } from "../chunk-4NAY6HRP.js";
8
+ import {
9
+ REASONING_SUPPORTED_PARAMETERS,
10
+ computeSupportsReasoning,
11
+ extractProviderId,
12
+ hasReasoningPricing,
13
+ isReasoningModel,
14
+ normalizeOpenRouterModel,
15
+ supportsReasoningParameter
16
+ } from "../chunk-6QGDZTGH.js";
17
+ import "../chunk-KQOALKKX.js";
18
+ import "../chunk-DJ5SWJDY.js";
19
+ import "../chunk-AJEKEWWB.js";
20
+ export {
21
+ AiModelsService,
22
+ REASONING_SUPPORTED_PARAMETERS,
23
+ computeSupportsReasoning,
24
+ countModels,
25
+ extractProviderId,
26
+ filterModels,
27
+ getModelInfo,
28
+ hasReasoningPricing,
29
+ isReasoningModel,
30
+ normalizeOpenRouterModel,
31
+ supportsReasoningParameter
32
+ };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,38 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkLYOU7CA2cjs = require('../chunk-LYOU7CA2.cjs');
6
+
7
+
8
+
9
+ var _chunkONA73BU6cjs = require('../chunk-ONA73BU6.cjs');
10
+ require('../chunk-HHNHWYTP.cjs');
11
+ require('../chunk-AV6OE2YQ.cjs');
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ var _chunkTF4L2NECcjs = require('../chunk-TF4L2NEC.cjs');
22
+ require('../chunk-7Q742NI3.cjs');
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ exports.ModelNameResolver = _chunkTF4L2NECcjs.ModelNameResolver; exports.OpenRouterSyncProvider = _chunkONA73BU6cjs.OpenRouterSyncProvider; exports.buildCatalogIndexes = _chunkTF4L2NECcjs.buildCatalogIndexes; exports.createModelNameResolver = _chunkLYOU7CA2cjs.createModelNameResolver; exports.isRoutedViaOpenRouter = _chunkLYOU7CA2cjs.isRoutedViaOpenRouter; exports.loadOpenRouterRoutingEnv = _chunkTF4L2NECcjs.loadOpenRouterRoutingEnv; exports.normalizeProvider = _chunkTF4L2NECcjs.normalizeProvider; exports.normalizeString = _chunkTF4L2NECcjs.normalizeString; exports.providerIdToEnvKeyPrefix = _chunkTF4L2NECcjs.providerIdToEnvKeyPrefix; exports.resolveModel = _chunkLYOU7CA2cjs.resolveModel; exports.shouldDefaultRouteViaOpenRouter = _chunkTF4L2NECcjs.shouldDefaultRouteViaOpenRouter; exports.syncAiModelsCatalog = _chunkONA73BU6cjs.syncAiModelsCatalog; exports.vendorApiKeyEnvName = _chunkTF4L2NECcjs.vendorApiKeyEnvName;
38
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/sync/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,g6BAAC","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/sync/index.cjs"}
@@ -0,0 +1,12 @@
1
+ export { M as ModelNameResolver, O as OpenRouterSyncProvider, a as OpenRouterSyncProviderOptions, S as SyncOptions, b as SyncResult, c as createModelNameResolver, i as isRoutedViaOpenRouter, r as resolveModel, s as syncAiModelsCatalog } from '../modelNameResolver-bZD-eBSJ.cjs';
2
+ import { a as AiModelRecord, C as CatalogIndexes } from '../types-DdGB3YaA.cjs';
3
+ export { h as ModelResolutionInput, j as ModelResolutionResult, k as ModelResolutionSuccess, l as ModelResolverOptions, r as OpenRouterRoutingConfig, R as ResolutionStrategy, t as ResolvedModel, v as loadOpenRouterRoutingEnv, w as providerIdToEnvKeyPrefix, x as shouldDefaultRouteViaOpenRouter, y as vendorApiKeyEnvName } from '../types-DdGB3YaA.cjs';
4
+ import '@x12i/catalox';
5
+ import 'firebase-admin/firestore';
6
+
7
+ declare function buildCatalogIndexes(catalog: Map<string, AiModelRecord>): CatalogIndexes;
8
+
9
+ declare function normalizeString(input: string): string;
10
+ declare function normalizeProvider(provider: string | undefined): string | undefined;
11
+
12
+ export { buildCatalogIndexes, normalizeProvider, normalizeString };
@@ -0,0 +1,12 @@
1
+ export { M as ModelNameResolver, O as OpenRouterSyncProvider, a as OpenRouterSyncProviderOptions, S as SyncOptions, b as SyncResult, c as createModelNameResolver, i as isRoutedViaOpenRouter, r as resolveModel, s as syncAiModelsCatalog } from '../modelNameResolver-Bn8QnkSj.js';
2
+ import { a as AiModelRecord, C as CatalogIndexes } from '../types-DdGB3YaA.js';
3
+ export { h as ModelResolutionInput, j as ModelResolutionResult, k as ModelResolutionSuccess, l as ModelResolverOptions, r as OpenRouterRoutingConfig, R as ResolutionStrategy, t as ResolvedModel, v as loadOpenRouterRoutingEnv, w as providerIdToEnvKeyPrefix, x as shouldDefaultRouteViaOpenRouter, y as vendorApiKeyEnvName } from '../types-DdGB3YaA.js';
4
+ import '@x12i/catalox';
5
+ import 'firebase-admin/firestore';
6
+
7
+ declare function buildCatalogIndexes(catalog: Map<string, AiModelRecord>): CatalogIndexes;
8
+
9
+ declare function normalizeString(input: string): string;
10
+ declare function normalizeProvider(provider: string | undefined): string | undefined;
11
+
12
+ export { buildCatalogIndexes, normalizeProvider, normalizeString };
@@ -0,0 +1,38 @@
1
+ import {
2
+ createModelNameResolver,
3
+ isRoutedViaOpenRouter,
4
+ resolveModel
5
+ } from "../chunk-G2G4KSC5.js";
6
+ import {
7
+ OpenRouterSyncProvider,
8
+ syncAiModelsCatalog
9
+ } from "../chunk-MLRHYOCD.js";
10
+ import "../chunk-ML2FRR4L.js";
11
+ import "../chunk-6QGDZTGH.js";
12
+ import {
13
+ ModelNameResolver,
14
+ buildCatalogIndexes,
15
+ loadOpenRouterRoutingEnv,
16
+ normalizeProvider,
17
+ normalizeString,
18
+ providerIdToEnvKeyPrefix,
19
+ shouldDefaultRouteViaOpenRouter,
20
+ vendorApiKeyEnvName
21
+ } from "../chunk-DJ5SWJDY.js";
22
+ import "../chunk-AJEKEWWB.js";
23
+ export {
24
+ ModelNameResolver,
25
+ OpenRouterSyncProvider,
26
+ buildCatalogIndexes,
27
+ createModelNameResolver,
28
+ isRoutedViaOpenRouter,
29
+ loadOpenRouterRoutingEnv,
30
+ normalizeProvider,
31
+ normalizeString,
32
+ providerIdToEnvKeyPrefix,
33
+ resolveModel,
34
+ shouldDefaultRouteViaOpenRouter,
35
+ syncAiModelsCatalog,
36
+ vendorApiKeyEnvName
37
+ };
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk5HNFAYTOcjs = require('../chunk-5HNFAYTO.cjs');
4
+
5
+
6
+ exports.AIToolbox = _chunk5HNFAYTOcjs.AIToolbox;
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/toolbox/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACF,gDAAC","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/toolbox/index.cjs"}
@@ -0,0 +1,72 @@
1
+ type FallbackChain = {
2
+ primary: string;
3
+ fallbackChain: string[];
4
+ maxRetries?: number;
5
+ };
6
+ interface Fallback {
7
+ execute<T>(chain: FallbackChain, fn: (model: string) => Promise<T>): Promise<T>;
8
+ }
9
+
10
+ type GuardConfig = {
11
+ jsonSchema?: object;
12
+ banPhrases?: string[];
13
+ minGroundingScore?: number;
14
+ sourceText?: string;
15
+ };
16
+ interface Guard {
17
+ verify(response: string, config: GuardConfig): {
18
+ isValid: boolean;
19
+ errors: string[];
20
+ };
21
+ }
22
+
23
+ type RouteRule = {
24
+ maxTokens?: number;
25
+ keywords?: string[];
26
+ complexity: "low" | "medium" | "high";
27
+ targetModel: string;
28
+ };
29
+ interface Router {
30
+ addRule(rule: RouteRule): void;
31
+ determineModel(prompt: string): Promise<{
32
+ model: string;
33
+ reason: string;
34
+ }>;
35
+ }
36
+
37
+ type TrackResult = {
38
+ requestId: string;
39
+ durationMs: number;
40
+ promptTokens: number;
41
+ completionTokens: number;
42
+ estimatedCostUSD: number;
43
+ requestPayload: unknown;
44
+ responsePayload: unknown;
45
+ };
46
+ type TrackerStorage = "memory" | "sqlite";
47
+ type TrackerOptions = {
48
+ storage?: TrackerStorage;
49
+ sqlitePath?: string;
50
+ };
51
+ interface Tracker {
52
+ logExchange(request: unknown, response: unknown): Promise<TrackResult>;
53
+ wrap<T extends (...args: unknown[]) => Promise<unknown>>(fn: T): T;
54
+ on(event: "exchange", handler: (data: TrackResult) => void): void;
55
+ }
56
+
57
+ type AiToolboxOptions = {
58
+ defaultProvider?: string;
59
+ defaultModel?: string;
60
+ apiKey?: string;
61
+ storage?: TrackerOptions["storage"];
62
+ sqlitePath?: string;
63
+ };
64
+ declare class AIToolbox {
65
+ readonly tracker: Tracker;
66
+ readonly router: Router;
67
+ readonly guard: Guard;
68
+ readonly fallback: Fallback;
69
+ constructor(options?: AiToolboxOptions);
70
+ }
71
+
72
+ export { AIToolbox, type AiToolboxOptions, type Fallback, type FallbackChain, type Guard, type GuardConfig, type RouteRule, type Router, type TrackResult, type Tracker, type TrackerOptions };
@@ -0,0 +1,72 @@
1
+ type FallbackChain = {
2
+ primary: string;
3
+ fallbackChain: string[];
4
+ maxRetries?: number;
5
+ };
6
+ interface Fallback {
7
+ execute<T>(chain: FallbackChain, fn: (model: string) => Promise<T>): Promise<T>;
8
+ }
9
+
10
+ type GuardConfig = {
11
+ jsonSchema?: object;
12
+ banPhrases?: string[];
13
+ minGroundingScore?: number;
14
+ sourceText?: string;
15
+ };
16
+ interface Guard {
17
+ verify(response: string, config: GuardConfig): {
18
+ isValid: boolean;
19
+ errors: string[];
20
+ };
21
+ }
22
+
23
+ type RouteRule = {
24
+ maxTokens?: number;
25
+ keywords?: string[];
26
+ complexity: "low" | "medium" | "high";
27
+ targetModel: string;
28
+ };
29
+ interface Router {
30
+ addRule(rule: RouteRule): void;
31
+ determineModel(prompt: string): Promise<{
32
+ model: string;
33
+ reason: string;
34
+ }>;
35
+ }
36
+
37
+ type TrackResult = {
38
+ requestId: string;
39
+ durationMs: number;
40
+ promptTokens: number;
41
+ completionTokens: number;
42
+ estimatedCostUSD: number;
43
+ requestPayload: unknown;
44
+ responsePayload: unknown;
45
+ };
46
+ type TrackerStorage = "memory" | "sqlite";
47
+ type TrackerOptions = {
48
+ storage?: TrackerStorage;
49
+ sqlitePath?: string;
50
+ };
51
+ interface Tracker {
52
+ logExchange(request: unknown, response: unknown): Promise<TrackResult>;
53
+ wrap<T extends (...args: unknown[]) => Promise<unknown>>(fn: T): T;
54
+ on(event: "exchange", handler: (data: TrackResult) => void): void;
55
+ }
56
+
57
+ type AiToolboxOptions = {
58
+ defaultProvider?: string;
59
+ defaultModel?: string;
60
+ apiKey?: string;
61
+ storage?: TrackerOptions["storage"];
62
+ sqlitePath?: string;
63
+ };
64
+ declare class AIToolbox {
65
+ readonly tracker: Tracker;
66
+ readonly router: Router;
67
+ readonly guard: Guard;
68
+ readonly fallback: Fallback;
69
+ constructor(options?: AiToolboxOptions);
70
+ }
71
+
72
+ export { AIToolbox, type AiToolboxOptions, type Fallback, type FallbackChain, type Guard, type GuardConfig, type RouteRule, type Router, type TrackResult, type Tracker, type TrackerOptions };
@@ -0,0 +1,7 @@
1
+ import {
2
+ AIToolbox
3
+ } from "../chunk-XRBZQQQU.js";
4
+ export {
5
+ AIToolbox
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,278 @@
1
+ /** OpenRouter Models API — https://openrouter.ai/api/v1/models */
2
+ type OpenRouterOutputModality = "text" | "image" | "audio" | "embeddings" | "video" | "speech" | "transcription" | "all";
3
+ type OpenRouterModelsQuery = {
4
+ /** Comma-separated or "all" — default on our sync is "all". */
5
+ output_modalities?: string;
6
+ supported_parameters?: string;
7
+ };
8
+ type OpenRouterPricingApi = {
9
+ prompt: string;
10
+ completion: string;
11
+ request: string;
12
+ image: string;
13
+ web_search?: string;
14
+ internal_reasoning?: string;
15
+ input_cache_read?: string;
16
+ input_cache_write?: string;
17
+ };
18
+ type OpenRouterArchitectureApi = {
19
+ modality?: string;
20
+ input_modalities: string[];
21
+ output_modalities: string[];
22
+ tokenizer: string;
23
+ instruct_type: string | null;
24
+ };
25
+ type OpenRouterTopProviderApi = {
26
+ context_length: number;
27
+ max_completion_tokens: number | null;
28
+ is_moderated: boolean;
29
+ };
30
+ type OpenRouterDefaultParametersApi = {
31
+ temperature?: number | null;
32
+ top_p?: number | null;
33
+ top_k?: number | null;
34
+ frequency_penalty?: number | null;
35
+ presence_penalty?: number | null;
36
+ repetition_penalty?: number | null;
37
+ };
38
+ type OpenRouterModelApi = {
39
+ id: string;
40
+ canonical_slug: string;
41
+ hugging_face_id?: string | null;
42
+ name: string;
43
+ created: number;
44
+ description: string;
45
+ context_length: number;
46
+ architecture: OpenRouterArchitectureApi;
47
+ pricing: OpenRouterPricingApi;
48
+ top_provider: OpenRouterTopProviderApi;
49
+ per_request_limits: unknown | null;
50
+ supported_parameters: string[];
51
+ default_parameters: OpenRouterDefaultParametersApi | null;
52
+ supported_voices?: unknown | null;
53
+ knowledge_cutoff?: string | null;
54
+ expiration_date?: string | null;
55
+ links?: {
56
+ details?: string;
57
+ } | null;
58
+ };
59
+ type OpenRouterModelsResponse = {
60
+ data: OpenRouterModelApi[];
61
+ };
62
+
63
+ type AiModelPricing = {
64
+ promptUsdPerToken: number;
65
+ completionUsdPerToken: number;
66
+ imageUsdPerUnit: number;
67
+ requestUsdPerRequest: number;
68
+ cacheReadUsdPerToken?: number;
69
+ cacheWriteUsdPerToken?: number;
70
+ reasoningUsdPerToken?: number;
71
+ webSearchUsdPerRequest?: number;
72
+ openRouterMarkupUsdPerInputToken?: number;
73
+ openRouterMarkupUsdPerOutputToken?: number;
74
+ pricedAt: string;
75
+ source: "openrouter" | "direct" | "manual";
76
+ };
77
+ /**
78
+ * Canonical catalog record — mirrors OpenRouter Models API fields plus normalized pricing.
79
+ * Stored as-is in Catalox `data`; scalar fields duplicated in `indexed` for queries.
80
+ */
81
+ type AiModelRecord = {
82
+ modelId: string;
83
+ name: string;
84
+ providerId: string;
85
+ canonicalSlug: string;
86
+ status: "active" | "deprecated" | "unknown";
87
+ description: string;
88
+ created: number;
89
+ expirationDate: string | null;
90
+ contextLength: number;
91
+ maxCompletionTokens: number | null;
92
+ isModerated: boolean;
93
+ modality: string;
94
+ inputModalities: string[];
95
+ outputModalities: string[];
96
+ tokenizer: string;
97
+ instructType: string | null;
98
+ supportedParameters: string[];
99
+ defaultParameters: OpenRouterDefaultParametersApi | null;
100
+ perRequestLimits: unknown | null;
101
+ pricing: AiModelPricing;
102
+ /** Raw OpenRouter pricing strings (USD per token/request/unit). */
103
+ openRouterPricing: OpenRouterPricingApi;
104
+ architecture: OpenRouterArchitectureApi;
105
+ topProvider: OpenRouterTopProviderApi;
106
+ /** Full OpenRouter API object — complete mirror for forward compatibility. */
107
+ openRouter: OpenRouterModelApi;
108
+ aliases: string[];
109
+ availableOnOpenRouter: boolean;
110
+ supportsStreaming: boolean;
111
+ supportsTools: boolean;
112
+ /** Exposes reasoning/thinking tokens (OpenRouter `reasoning` param and/or `internal_reasoning` pricing). */
113
+ supportsReasoning: boolean;
114
+ primaryOutputModality: string;
115
+ syncedAt: string;
116
+ syncSource: "openrouter" | "manual";
117
+ };
118
+ type ModelListFilters = {
119
+ providerId?: string;
120
+ status?: AiModelRecord["status"];
121
+ outputModality?: string;
122
+ inputModality?: string;
123
+ supportedParameter?: string;
124
+ supportsTools?: boolean;
125
+ supportsReasoning?: boolean;
126
+ search?: string;
127
+ limit?: number;
128
+ offset?: number;
129
+ };
130
+ type ModelListResult = {
131
+ models: AiModelRecord[];
132
+ total: number;
133
+ limit: number;
134
+ offset: number;
135
+ };
136
+
137
+ type AliasEntry = {
138
+ modelId: string;
139
+ provider: string;
140
+ description?: string;
141
+ tags?: string[];
142
+ addedAt: string;
143
+ updatedAt: string;
144
+ };
145
+ type AliasFileSchema = {
146
+ $schema?: string;
147
+ version: 1;
148
+ updatedAt: string;
149
+ aliases: Record<string, AliasEntry>;
150
+ };
151
+ type ResolvedModelRef = {
152
+ alias: string;
153
+ entry: AliasEntry;
154
+ modelRecord: AiModelRecord | null;
155
+ modelId: string;
156
+ provider: string;
157
+ name: string;
158
+ };
159
+ type AliasValidationReport = {
160
+ total: number;
161
+ ok: number;
162
+ unknown: number;
163
+ broken: number;
164
+ entries: Array<{
165
+ name: string;
166
+ status: "ok" | "unknown" | "broken";
167
+ modelId: string;
168
+ resolvedName?: string;
169
+ issue?: string;
170
+ }>;
171
+ };
172
+
173
+ type AliasRegistryOptions = {
174
+ aliasesPath?: string;
175
+ };
176
+ declare class AliasRegistry {
177
+ private readonly aliasesPath;
178
+ constructor(options?: AliasRegistryOptions);
179
+ get path(): string;
180
+ exists(): boolean;
181
+ init(): void;
182
+ load(): AliasFileSchema;
183
+ get(aliasName: string): AliasEntry | null;
184
+ list(filter?: {
185
+ tag?: string;
186
+ }): Array<{
187
+ name: string;
188
+ } & AliasEntry>;
189
+ set(aliasName: string, entry: Omit<AliasEntry, "addedAt" | "updatedAt">): AliasEntry;
190
+ remove(aliasName: string): boolean;
191
+ rename(from: string, to: string, options?: {
192
+ force?: boolean;
193
+ }): void;
194
+ private writeFile;
195
+ }
196
+
197
+ /**
198
+ * Env naming for vendor direct API keys: `{VENDOR}_API_KEY`
199
+ * where VENDOR is the provider id in UPPER_SNAKE (hyphens → underscores).
200
+ *
201
+ * Examples: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `META_LLAMA_API_KEY`, `X_AI_API_KEY`
202
+ */
203
+ declare function providerIdToEnvKeyPrefix(providerId: string): string;
204
+ declare function vendorApiKeyEnvName(providerId: string): string;
205
+ type OpenRouterRoutingConfig = {
206
+ /** OPENROUTER_API_KEY is set and non-empty */
207
+ hasOpenRouterKey: boolean;
208
+ /** USE_OPENROUTER=true or USE_OPENROUTER=1 */
209
+ useOpenRouterExplicit: boolean;
210
+ /** Read `{PROVIDER}_API_KEY` for a catalog provider id */
211
+ getVendorApiKey(providerId: string): string | undefined;
212
+ };
213
+ /**
214
+ * Load routing hints from process env and optional `.env` (via @x12/env).
215
+ */
216
+ declare function loadOpenRouterRoutingEnv(env?: Record<string, string | undefined>): OpenRouterRoutingConfig;
217
+ /**
218
+ * Default route via OpenRouter when:
219
+ * 1. OPENROUTER_API_KEY is set AND USE_OPENROUTER=true|1, or
220
+ * 2. OPENROUTER_API_KEY is set AND the vendor's `{VENDOR}_API_KEY` is missing.
221
+ */
222
+ declare function shouldDefaultRouteViaOpenRouter(providerId: string | undefined, config: OpenRouterRoutingConfig): boolean;
223
+
224
+ type ModelResolutionInput = {
225
+ /** Provider hint (openrouter, openai, anthropic, …). May be omitted. */
226
+ provider?: string;
227
+ /** Model id, alias, shorthand, or partial name. Required. */
228
+ model: string;
229
+ };
230
+ type ResolutionStrategy = "alias-registry" | "alias-as-provider-correction" | "exact-match" | "catalog-alias-match" | "canonical-slug-match" | "provider-prefix-injection" | "cross-provider-correction" | "version-suffix-strip" | "date-suffix-strip" | "shorthand-expansion" | "partial-name-match" | "local-provider-passthrough";
231
+ type ModelResolutionSuccess = {
232
+ found: true;
233
+ modelId: string;
234
+ record: AiModelRecord | null;
235
+ routedViaOpenRouter: boolean;
236
+ confidence: number;
237
+ resolvedVia: ResolutionStrategy[];
238
+ resolvedReason: string;
239
+ normalisedInput: string;
240
+ };
241
+ type ModelResolutionNotFound = {
242
+ found: false;
243
+ modelId: null;
244
+ record: null;
245
+ attemptedStrategies: ResolutionStrategy[];
246
+ bestRejectedCandidate?: {
247
+ modelId: string;
248
+ confidence: number;
249
+ reason: string;
250
+ };
251
+ reason: string;
252
+ };
253
+ type ModelResolutionResult = ModelResolutionSuccess | ModelResolutionNotFound;
254
+ type ModelResolverOptions = {
255
+ confidenceThreshold?: number;
256
+ aliasRegistry?: AliasRegistry;
257
+ additionalShorthands?: Record<string, string>;
258
+ additionalProviderPatterns?: Array<{
259
+ pattern: RegExp;
260
+ provider: string;
261
+ }>;
262
+ additionalLocalProviders?: string[];
263
+ /** Env-based OpenRouter vs direct routing. Defaults to loadOpenRouterRoutingEnv(). */
264
+ routingEnv?: OpenRouterRoutingConfig;
265
+ };
266
+ type CatalogIndexes = {
267
+ aliasIndex: Map<string, string>;
268
+ slugIndex: Map<string, string>;
269
+ providerPrefixesBySize: string[];
270
+ };
271
+ /** @deprecated Use ModelResolutionSuccess via ModelNameResolver */
272
+ type ResolvedModel = {
273
+ catalogModel: AiModelRecord;
274
+ matchedAlias: string;
275
+ routedViaOpenRouter: boolean;
276
+ };
277
+
278
+ export { type AiModelPricing as A, type CatalogIndexes as C, type ModelListFilters as M, type OpenRouterArchitectureApi as O, type ResolutionStrategy as R, type AiModelRecord as a, type AliasEntry as b, type AliasFileSchema as c, AliasRegistry as d, type AliasRegistryOptions as e, type AliasValidationReport as f, type ModelListResult as g, type ModelResolutionInput as h, type ModelResolutionNotFound as i, type ModelResolutionResult as j, type ModelResolutionSuccess as k, type ModelResolverOptions as l, type OpenRouterModelApi as m, type OpenRouterModelsQuery as n, type OpenRouterModelsResponse as o, type OpenRouterOutputModality as p, type OpenRouterPricingApi as q, type OpenRouterRoutingConfig as r, type OpenRouterTopProviderApi as s, type ResolvedModel as t, type ResolvedModelRef as u, loadOpenRouterRoutingEnv as v, providerIdToEnvKeyPrefix as w, shouldDefaultRouteViaOpenRouter as x, vendorApiKeyEnvName as y };