@starci/ai-router 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1 - 2026-10-28
4
+
5
+ - Fixed: 0.2.0 shipped corrupt declarations: the build rewrote `.ts` specifiers with a `$1` that sh expanded to nothing, so every `dist/*.d.ts` read `export { X } .js";` and a consumer tsc failed. The declaration step now names `.js` with a replacer function and `"`, and reads alike under sh and cmd.
6
+
3
7
  ## 0.2.0 - 2026-10-27
4
8
 
5
9
  - Breaking: the package is a NestJS module. The root entry is the Nest API (`AiRouterModule`, `AiRouterService`, the tokens and decorators, the options, config, policy and event types, `AiRouterError`, the `StateStore` type); `createRouter`, `definePool`, `validateConfig`, `MemoryStateStore`, `parseSse`, `parseDuration`, `readRateLimit` and `classifyStatus` are no longer exported, and the router engine is reached only through the service.
@@ -1,6 +1,6 @@
1
1
  import type { DynamicModule } from "@nestjs/common";
2
- import type { AiRouterRegisterOptions } .js";
3
- import type { FakeProvider } .js";
2
+ import type { AiRouterRegisterOptions } from "./ai-router.module-definition.js";
3
+ import type { FakeProvider } from "./fake.js";
4
4
  /** What `AiRouterTestingModule.register` takes: a registration whose requests a fake provider answers. */
5
5
  export type AiRouterTestingOptions = Omit<AiRouterRegisterOptions, "fetch"> & {
6
6
  /** The provider every request goes to, in process; script it with `fake.on` and read `fake.calls`. */
@@ -1,11 +1,11 @@
1
- import type { AiRouterModuleOptions } .js";
1
+ import type { AiRouterModuleOptions } from "./ai-router.options.js";
2
2
  /** The extras every registration may set: global visibility, and the name of one of several pools. */
3
3
  export interface AiRouterModuleExtras {
4
4
  readonly isGlobal: boolean;
5
5
  readonly name: string | undefined;
6
6
  }
7
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AiRouterModuleOptions, "register", "createAiRouterOptions", AiRouterModuleExtras>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: .js").PoolConfig<string> & {
8
- readonly on?: .js").AiRouterHandlers;
7
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<AiRouterModuleOptions, "register", "createAiRouterOptions", AiRouterModuleExtras>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: import("./types.js").PoolConfig<string> & {
8
+ readonly on?: import("./ai-router.options.js").AiRouterHandlers;
9
9
  } & Partial<AiRouterModuleExtras>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<AiRouterModuleOptions, "createAiRouterOptions"> & Partial<AiRouterModuleExtras>;
10
10
  /** What `AiRouterModule.register` takes: the options, plus `isGlobal` and `name`. */
11
11
  export type AiRouterRegisterOptions = typeof OPTIONS_TYPE;
@@ -1,6 +1,6 @@
1
1
  import type { DynamicModule } from "@nestjs/common";
2
- import { ConfigurableModuleClass } .js";
3
- import type { AiRouterRegisterAsyncOptions, AiRouterRegisterOptions } .js";
2
+ import { ConfigurableModuleClass } from "./ai-router.module-definition.js";
3
+ import type { AiRouterRegisterAsyncOptions, AiRouterRegisterOptions } from "./ai-router.module-definition.js";
4
4
  /** A pool router as a Nest capability: registered once at the app root, or once per name for several pools. */
5
5
  export declare class AiRouterModule extends ConfigurableModuleClass {
6
6
  /** Registers a router from options known now. */
@@ -1,4 +1,4 @@
1
- import type { PoolConfig, RouterEvents } .js";
1
+ import type { PoolConfig, RouterEvents } from "./types.js";
2
2
  /** One handler per router event, subscribed when the module starts and released when the application shuts down. */
3
3
  export type AiRouterHandlers = {
4
4
  readonly [E in keyof RouterEvents]?: (payload: RouterEvents[E]) => void;
@@ -1,6 +1,6 @@
1
1
  import type { OnApplicationShutdown } from "@nestjs/common";
2
- import type { AiRouter, CallOptions, ChatCompletion, ChatCompletionRequest, ChatStream, EmbeddingsRequest, EmbeddingsResponse, HealthSnapshot, ResetTarget, RouterEvents, StatsSnapshot } .js";
3
- import type { AiRouterHandlers } .js";
2
+ import type { AiRouter, CallOptions, ChatCompletion, ChatCompletionRequest, ChatStream, EmbeddingsRequest, EmbeddingsResponse, HealthSnapshot, ResetTarget, RouterEvents, StatsSnapshot } from "./types.js";
3
+ import type { AiRouterHandlers } from "./ai-router.options.js";
4
4
  /**
5
5
  * The injectable facade over one router. Every call it makes also follows the application's shutdown, and every
6
6
  * handler it subscribed is released then; calls made on the raw router (`AI_ROUTER`) are the caller's to cancel.
@@ -1,4 +1,4 @@
1
- import { AiRouterService } .js";
1
+ import { AiRouterService } from "./ai-router.service.js";
2
2
  /** The injection token of the default instance's raw router (`AiRouter`). */
3
3
  export declare const AI_ROUTER = "AI_ROUTER";
4
4
  /** The token of a raw router: `AI_ROUTER` for the default instance, `AI_ROUTER:<name>` for a named one. */
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Capability, CallOptions, ModelConfig, PoolConfig } .js";
1
+ import type { Capability, CallOptions, ModelConfig, PoolConfig } from "./types.js";
2
2
  /** The capabilities of a model that declares none. */
3
3
  export declare const DEFAULT_CAPABILITIES: readonly Capability[];
4
4
  /** A breaker's thresholds with every default applied. */
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ErrorClass } .js";
1
+ import type { ErrorClass } from "./types.js";
2
2
  /** One failed attempt as an error lists it: where it went and why it failed, never a key value. */
3
3
  export interface AttemptFailure {
4
4
  readonly provider: string;
package/dist/events.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RouterEvents } .js";
1
+ import type { RouterEvents } from "./types.js";
2
2
  type Handler<E extends keyof RouterEvents> = (payload: RouterEvents[E]) => void;
3
3
  /** A typed event fan-out. A handler that throws is isolated: observing a call never breaks it. */
4
4
  export declare class Emitter {
package/dist/fake.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FetchLike, Usage } .js";
1
+ import type { FetchLike, Usage } from "./types.js";
2
2
  /** How a scripted stream behaves. */
3
3
  export interface FakeStream {
4
4
  /** The content pieces, one chunk each. Default: the reply text split at spaces. */
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { AiRouterModule } .js";
2
- export type { AiRouterModuleExtras, AiRouterRegisterAsyncOptions, AiRouterRegisterOptions } .js";
3
- export type { AiRouterHandlers, AiRouterModuleOptions } .js";
4
- export { AiRouterService } .js";
5
- export { AI_ROUTER, getAiRouterServiceToken, getAiRouterToken, InjectAiRouter, InjectAiRouterService } .js";
6
- export { AiRouterError } .js";
7
- export type { AttemptFailure } .js";
8
- export type { HealthRecord, StateStore } .js";
9
- export type * .js";
1
+ export { AiRouterModule } from "./ai-router.module.js";
2
+ export type { AiRouterModuleExtras, AiRouterRegisterAsyncOptions, AiRouterRegisterOptions } from "./ai-router.module-definition.js";
3
+ export type { AiRouterHandlers, AiRouterModuleOptions } from "./ai-router.options.js";
4
+ export { AiRouterService } from "./ai-router.service.js";
5
+ export { AI_ROUTER, getAiRouterServiceToken, getAiRouterToken, InjectAiRouter, InjectAiRouterService } from "./ai-router.tokens.js";
6
+ export { AiRouterError } from "./errors.js";
7
+ export type { AttemptFailure } from "./errors.js";
8
+ export type { HealthRecord, StateStore } from "./store.js";
9
+ export type * from "./types.js";
package/dist/pool.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { ResolvedPolicy, Settings } .js";
2
- import type { Emitter } .js";
3
- import type { RateLimitInfo } .js";
4
- import type { StateStore } .js";
5
- import type { Capability, ErrorClass, HealthSnapshot, KeyConfig, ModelConfig, ProviderConfig, ResetTarget, StatsSnapshot, Usage } .js";
1
+ import type { ResolvedPolicy, Settings } from "./config.js";
2
+ import type { Emitter } from "./events.js";
3
+ import type { RateLimitInfo } from "./headers.js";
4
+ import type { StateStore } from "./store.js";
5
+ import type { Capability, ErrorClass, HealthSnapshot, KeyConfig, ModelConfig, ProviderConfig, ResetTarget, StatsSnapshot, Usage } from "./types.js";
6
6
  /** One routable (provider, key, model) triple and the rank of its model in the call's policy. */
7
7
  export interface Lane {
8
8
  readonly provider: ProviderConfig;
package/dist/router.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { AiRouter, PoolConfig } .js";
1
+ import type { AiRouter, PoolConfig } from "./types.js";
2
2
  /** Creates a router over a pool of providers, keys and models. The pool is validated now; keys are read per attempt. */
3
3
  export declare function createRouter<P extends string = string>(config: PoolConfig<P>): AiRouter<P>;
package/dist/store.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } .js";
1
+ import type { MaybePromise } from "./types.js";
2
2
  /**
3
3
  * The shared health of one key, one provider or one key and model ("lane"). Every field is a JSON number, string or
4
4
  * null, so an adapter can store it anywhere. Times are epoch milliseconds; 0 means "not set".
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AiRouterTestingModule } .js";
2
- export type { AiRouterTestingOptions } .js";
3
- export { createFakeProvider } .js";
4
- export type { FakeCall, FakeMatch, FakeProvider, FakeReply, FakeStream } .js";
1
+ export { AiRouterTestingModule } from "./ai-router-testing.module.js";
2
+ export type { AiRouterTestingOptions } from "./ai-router-testing.module.js";
3
+ export { createFakeProvider } from "./fake.js";
4
+ export type { FakeCall, FakeMatch, FakeProvider, FakeReply, FakeStream } from "./fake.js";
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { StateStore } .js";
1
+ import type { StateStore } from "./store.js";
2
2
  /** A value or a promise of it: store adapters and key resolvers may answer either way. */
3
3
  export type MaybePromise<T> = T | Promise<T>;
4
4
  /** What a model can do; a request needs every capability its shape implies. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/ai-router",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A NestJS module that routes OpenAI-compatible calls across a pool of keys, models and providers: AiRouterModule.register and an injectable AiRouterService for chat, stream and embeddings, with health-aware selection, circuit breakers, rate-limit awareness, retries onto another key, model fallback and redacted telemetry.",
5
5
  "keywords": [
6
6
  "ai",
@@ -62,7 +62,7 @@
62
62
  "provenance": true
63
63
  },
64
64
  "scripts": {
65
- "build": "node -e \"require('node:fs').rmSync('dist', {recursive: true, force: true})\" && tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); for (const f of fs.readdirSync('dist', {recursive: true}).filter((n) => n.endsWith('.d.ts'))) fs.writeFileSync('dist/' + f, fs.readFileSync('dist/' + f, 'utf8').replace(/((?:from |import\\()\\\"\\.\\.?\\/[\\w./-]+)\\.ts\\\"/g, '$1.js\\\"'))\"",
65
+ "build": "node -e \"require('node:fs').rmSync('dist', {recursive: true, force: true})\" && tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); for (const f of fs.readdirSync('dist', {recursive: true}).filter((n) => n.endsWith('.d.ts'))) fs.writeFileSync('dist/' + f, fs.readFileSync('dist/' + f, 'utf8').replace(/((?:from |import\\()['\\x22]\\.\\.?\\/[^'\\x22]+)\\.ts(['\\x22])/g, (all, head, quote) => head + '.js' + quote))\"",
66
66
  "typecheck": "tsc -p tsconfig.json --noEmit",
67
67
  "lint": "eslint .",
68
68
  "test": "npm run typecheck && npm run lint && node --test --experimental-test-coverage --test-coverage-include=\"src/**/*.ts\" --test-coverage-lines=90 \"test/**/*.test.ts\"",