kimi-proxy 0.0.3 → 0.1.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.
Files changed (38) hide show
  1. package/README.md +17 -8
  2. package/dist/config.d.ts +11 -3
  3. package/dist/core/clientAdapters.d.ts +18 -0
  4. package/dist/core/ensureToolCall.d.ts +3 -3
  5. package/dist/core/json.d.ts +3 -0
  6. package/dist/core/pipeline.d.ts +30 -15
  7. package/dist/core/pipelineControl.d.ts +1 -1
  8. package/dist/core/providerAdapters.d.ts +4 -0
  9. package/dist/core/providers/anthropic.d.ts +16 -0
  10. package/dist/core/providers/openai.d.ts +2192 -0
  11. package/dist/core/providers/openrouter.d.ts +31 -0
  12. package/dist/core/providers/shared.d.ts +10 -0
  13. package/dist/core/providers/vertex.d.ts +45 -0
  14. package/dist/core/schemas.d.ts +2841 -0
  15. package/dist/core/transforms.d.ts +44 -0
  16. package/dist/core/types.d.ts +2765 -51
  17. package/dist/index.js +5922 -12
  18. package/dist/index.js.map +37 -1
  19. package/dist/livestore/runtime.d.ts +71 -0
  20. package/dist/persistence/hybridLogStore.d.ts +82 -0
  21. package/dist/persistence/migrateLogs.d.ts +1 -0
  22. package/dist/persistence/signatureCache.d.ts +5 -6
  23. package/dist/server.d.ts +1 -1
  24. package/dist/services/blobSearch/ripgrep.d.ts +17 -0
  25. package/dist/services/kimiFixer.d.ts +1 -1
  26. package/dist/services/logSearch.d.ts +15 -0
  27. package/dist/services/streaming.d.ts +4 -4
  28. package/dist/utils/envResolver.d.ts +1 -1
  29. package/dist/utils/httpCapture.d.ts +19 -0
  30. package/frontend/dist/assets/JSONViewer-516863bb.js +3 -0
  31. package/frontend/dist/assets/index-413f3c24.css +1 -0
  32. package/frontend/dist/assets/index-fd87815b.js +300 -0
  33. package/frontend/dist/assets/wa-sqlite-be172f22.wasm +0 -0
  34. package/frontend/dist/index.html +2 -2
  35. package/package.json +30 -16
  36. package/frontend/dist/assets/JSONViewer-2759ef29.js +0 -3
  37. package/frontend/dist/assets/index-0e7c091b.css +0 -1
  38. package/frontend/dist/assets/index-a3cad95b.js +0 -40
package/README.md CHANGED
@@ -74,6 +74,10 @@ What clients receive:
74
74
 
75
75
  Enable with `ensure_tool_call: true` in model config. The proxy detects missing tool calls and re-prompts the model with a reminder.
76
76
 
77
+ When enabled, the proxy also injects a termination tool named `done` and a system instruction telling the model to call it when finished (optionally with `{"final_answer":"..."}`), then strips that termination tool call from the final response.
78
+
79
+ Control the maximum number of re-prompt attempts with `ENSURE_TOOL_CALL_MAX_ATTEMPTS` (default: `3`, max: `5`).
80
+
77
81
  **Example enforcement flow:**
78
82
 
79
83
  ```
@@ -116,18 +120,20 @@ Distribute traffic across providers using round-robin, weighted random, random,
116
120
 
117
121
  - **Extensible architecture** for adding new models and providers
118
122
  - **Provider support**: OpenAI-compatible APIs, OpenRouter, Vertex AI
123
+ - **Hybrid logging pipeline**: SQLite metadata with filesystem blobs, LiveStore-backed dashboard with virtualized/lazy blob loading
119
124
 
120
- ## Quick Start
125
+ ## Quick Start (Bun)
121
126
 
122
127
  ```bash
123
- pnpm install
128
+ bun install
124
129
  cp .env.example .env
125
130
  cp model-config.example.yaml model-config.yaml
126
131
  # Edit .env and model-config.yaml with your provider keys and models
127
- pnpm run dev
132
+ bun run dev # backend
133
+ bun --cwd frontend dev # dashboard (Vite)
128
134
  ```
129
135
 
130
- The API runs on `http://127.0.0.1:8000` and serves the dashboard at `/`.
136
+ The API runs on `http://127.0.0.1:8000` and serves the dashboard (built assets) at `/`. The dev dashboard uses `VITE_API_URL` to point at the backend (defaults to same origin).
131
137
 
132
138
  ## Configuration
133
139
 
@@ -136,8 +142,10 @@ The API runs on `http://127.0.0.1:8000` and serves the dashboard at `/`.
136
142
  Set environment variables in `.env`:
137
143
 
138
144
  - **Generic OpenAI**: `OPENAI_BASE_URL`, `OPENAI_API_KEY`
145
+ - **Anthropic**: `ANTHROPIC_API_KEY`, optional `ANTHROPIC_BASE_URL`
139
146
  - **OpenRouter**: `OPENROUTER_API_KEY`, `OPENROUTER_PROVIDERS` (optional), `OPENROUTER_ORDER` (optional)
140
147
  - **Vertex AI**: `VERTEX_PROJECT_ID`, `VERTEX_LOCATION`, `GOOGLE_APPLICATION_CREDENTIALS`
148
+ - `GOOGLE_APPLICATION_CREDENTIALS` can be a path to the JSON key file or the JSON payload itself. Use `VERTEX_CHAT_ENDPOINT` to point at a private MaaS endpoint if needed.
141
149
 
142
150
  ### Models
143
151
 
@@ -159,14 +167,15 @@ models:
159
167
 
160
168
  ## Dashboard
161
169
 
162
- The web dashboard shows request/response logs and metrics. Access it at the root path when running the proxy.
170
+ The web dashboard shows request/response logs and metrics. Access it at the root path when running the proxy. LiveStore metadata sync pulls from `/api/livestore/pull` in batches (size controlled by `LIVESTORE_BATCH`) and lazily fetches blobs on expansion. Build the dashboard with `bun run build:all` to serve static assets from the backend.
163
171
 
164
172
  ## Development
165
173
 
166
174
  ```bash
167
- pnpm run dev # Run with hot reload
168
- pnpm run test # Run unit tests
169
- pnpm run build # TypeScript build
175
+ bun run dev # Run backend with hot reload
176
+ bun --cwd frontend dev # Run dashboard
177
+ bun test # Run tests
178
+ bun run build:all # Build server + dashboard
170
179
  ```
171
180
 
172
181
  ## Docker
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { OpenAIConfig } from "./core/providers/openaiProvider.js";
2
- import { OpenRouterConfig } from "./core/providers/openRouterProvider.js";
3
- import { VertexConfig } from "./core/providers/vertexProvider.js";
1
+ import { OpenAIConfig } from "./core/providers/openai.js";
2
+ import { OpenRouterConfig } from "./core/providers/openrouter.js";
3
+ import { VertexConfig } from "./core/providers/vertex.js";
4
4
  import { LoadBalancingStrategy, ModelDefinition } from "./core/modelRegistry.js";
5
5
  export interface AppConfig {
6
6
  server: {
@@ -9,13 +9,21 @@ export interface AppConfig {
9
9
  };
10
10
  logging: {
11
11
  dbPath: string;
12
+ blobRoot: string;
12
13
  };
13
14
  streaming: {
14
15
  delay: number;
15
16
  chunkSize: number;
16
17
  };
18
+ livestore: {
19
+ batchSize: number;
20
+ };
17
21
  providers: {
18
22
  openai?: OpenAIConfig;
23
+ anthropic?: {
24
+ apiKey: string;
25
+ baseUrl?: string;
26
+ };
19
27
  openrouter?: OpenRouterConfig;
20
28
  vertex?: VertexConfig;
21
29
  };
@@ -0,0 +1,18 @@
1
+ import { ClientFormat, type JsonValue } from "./types.js";
2
+ import { ClientAdapter, Request, Response } from "./types.js";
3
+ import { type ClientRequest } from "./schemas.js";
4
+ export declare class OpenAIChatClientAdapter implements ClientAdapter {
5
+ clientFormat: ClientFormat;
6
+ toUlx(body: ClientRequest, headers: Record<string, string>): Request;
7
+ fromUlx(ulxResponse: Response, _ulxRequest: Request): JsonValue;
8
+ }
9
+ export declare class AnthropicMessagesClientAdapter implements ClientAdapter {
10
+ clientFormat: ClientFormat;
11
+ toUlx(body: ClientRequest, headers: Record<string, string>): Request;
12
+ fromUlx(ulxResponse: Response): JsonValue;
13
+ }
14
+ export declare class OpenAIResponsesClientAdapter implements ClientAdapter {
15
+ clientFormat: ClientFormat;
16
+ toUlx(body: ClientRequest, headers: Record<string, string>): Request;
17
+ fromUlx(ulxResponse: Response, ulxRequest: Request): JsonValue;
18
+ }
@@ -1,4 +1,4 @@
1
- import { JsonObject, JsonValue } from "./types.js";
1
+ import type { JsonObject, JsonValue, Message, Tool } from "./types.js";
2
2
  export declare const ENSURE_TOOL_CALL_STATE_KEY = "__ensureToolCall";
3
3
  export declare const DEFAULT_TERMINATION_TOOL_NAME = "done";
4
4
  export interface EnsureToolCallState extends JsonObject {
@@ -16,9 +16,9 @@ export declare function getEnsureToolCallState(state: Record<string, JsonValue>)
16
16
  export declare function buildBaseInstruction(toolName: string): string;
17
17
  export declare function buildReminderInstruction(toolName: string): string;
18
18
  export declare function buildFinalAnswerRequirementInstruction(toolName: string): string;
19
- export declare function createTerminationToolDefinition(name: string): JsonObject;
19
+ export declare function createTerminationToolDefinition(name: string): Tool;
20
20
  /**
21
21
  * Get messages from the last user message to the end of the array.
22
22
  * Returns empty array if no user message is found.
23
23
  */
24
- export declare function getMessagesSinceLastUser(messages: JsonValue[]): JsonValue[];
24
+ export declare function getMessagesSinceLastUser(messages: Message[] | undefined): Message[];
@@ -0,0 +1,3 @@
1
+ import type { JsonObject } from "./types.js";
2
+ export declare function safeJsonString(value: unknown): string;
3
+ export declare function safeJsonParseObject(value: string | undefined): JsonObject;
@@ -1,17 +1,32 @@
1
- import { PipelineResult, ProxyRequest, RequestTransform, ResponseTransform, JsonObject } from "./types.js";
2
- import { ConverterRegistry } from "./converters/types.js";
3
- import { LLMProvider } from "./providers/types.js";
4
- interface PipelineDeps {
5
- converterRegistry: ConverterRegistry;
6
- requestTransforms: RequestTransform[];
7
- responseTransforms: ResponseTransform[];
1
+ import { type ClientRequest } from "./schemas.js";
2
+ import type { JsonObject } from "./types.js";
3
+ import { ClientAdapter, PipelineResult as PipelineResult, ProviderAdapter, Transform as Transform, Operation as Operation } from "./types.js";
4
+ export declare class ClientRegistry {
5
+ private adapters;
6
+ register(adapter: ClientAdapter): void;
7
+ resolve(clientFormat: string): ClientAdapter;
8
8
  }
9
- export declare class LLMProxyPipeline {
10
- private readonly deps;
11
- constructor(deps: PipelineDeps);
12
- execute(provider: LLMProvider, request: ProxyRequest, providerConfig?: JsonObject): Promise<PipelineResult>;
13
- private applyRequestTransforms;
14
- private applyResponseTransforms;
15
- private transformsByStage;
9
+ export declare class ProviderRegistry {
10
+ private adapters;
11
+ register(adapter: ProviderAdapter): void;
12
+ resolve(key: string): ProviderAdapter;
13
+ }
14
+ export interface PipelineOptions {
15
+ clientFormat: string;
16
+ providerKey: string;
17
+ providerConfig?: JsonObject;
18
+ requestBody: ClientRequest;
19
+ requestHeaders: Record<string, string>;
20
+ operation: Operation;
21
+ requestId?: string;
22
+ profile?: string;
23
+ ensureToolCall?: boolean;
24
+ }
25
+ export declare class Pipeline {
26
+ private readonly clients;
27
+ private readonly providers;
28
+ private readonly transforms;
29
+ constructor(clients: ClientRegistry, providers: ProviderRegistry, transforms?: Transform[]);
30
+ execute(options: PipelineOptions): Promise<PipelineResult>;
31
+ private runTransforms;
16
32
  }
17
- export {};
@@ -1,4 +1,4 @@
1
- import { JsonValue } from "./types.js";
1
+ import type { JsonValue } from "./types.js";
2
2
  export declare const PIPELINE_MAX_ATTEMPTS_KEY = "__pipelineMaxAttempts";
3
3
  export declare const PIPELINE_RETRY_FLAG_KEY = "__pipelineRetryRequested";
4
4
  export declare const SYNTHETIC_RESPONSE_FLAG_KEY = "__syntheticResponseRequested";
@@ -0,0 +1,4 @@
1
+ export { AnthropicProviderAdapter } from "./providers/anthropic.js";
2
+ export { OpenAIProviderAdapter } from "./providers/openai.js";
3
+ export { OpenRouterProviderAdapter } from "./providers/openrouter.js";
4
+ export { VertexProviderAdapter } from "./providers/vertex.js";
@@ -0,0 +1,16 @@
1
+ import { type JsonObject } from "../types.js";
2
+ import { ProviderAdapter, ProviderResponse, Request, Response } from "../types.js";
3
+ export interface AnthropicProviderConfig {
4
+ apiKey: string;
5
+ baseUrl?: string;
6
+ }
7
+ export declare class AnthropicProviderAdapter implements ProviderAdapter {
8
+ private readonly config;
9
+ key: string;
10
+ providerFormat: string;
11
+ constructor(config: AnthropicProviderConfig);
12
+ private resolveConfig;
13
+ invoke(request: Request, config?: JsonObject): Promise<ProviderResponse>;
14
+ toUlxResponse(payload: ProviderResponse, request: Request): Response;
15
+ private buildAnthropicPayload;
16
+ }