@caeliq/llms 1.0.68 → 1.0.69

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.
@@ -0,0 +1,6 @@
1
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
2
+ import type { Transformer } from "../types/transformer";
3
+ /**
4
+ * Dedicated FIM pipeline — does not call prepareInboundRequest / chat Unified.
5
+ */
6
+ export declare function handleFimEndpoint(req: FastifyRequest, reply: FastifyReply, fastify: FastifyInstance, _ownerTransformer: Transformer, routePath: string): Promise<undefined>;
@@ -4,7 +4,7 @@ import type { ResponsesCallIdMap } from "../utils/openai.responses.util";
4
4
  /**
5
5
  * Inbound client protocols supported by CCR's gateway lifecycle.
6
6
  */
7
- export type ClientProtocol = "anthropic_messages" | "openai_chat_completions" | "openai_responses";
7
+ export type ClientProtocol = "anthropic_messages" | "openai_chat_completions" | "openai_responses" | "openai_fim_completions";
8
8
  export interface AnthropicSourceRequestFields {
9
9
  metadata?: Record<string, unknown>;
10
10
  thinking?: Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { LLMProvider } from "../../types/llm";
2
+ import type { Transformer, TransformerContext } from "../../types/transformer";
3
+ import { type UnifiedFimRequest } from "../../utils/fim";
4
+ /**
5
+ * DeepSeek beta completions FIM outbound.
6
+ * Same-kind (future deepseek inbound): auth + URL only.
7
+ * Cross-family from Codestral Unified: prompt+suffix + 4K clamp + non-thinking.
8
+ */
9
+ export declare class FimDeepseekTransformer implements Transformer {
10
+ static TransformerName: string;
11
+ name: string;
12
+ logger?: any;
13
+ transformRequestIn(request: UnifiedFimRequest | any, provider: LLMProvider, context: TransformerContext): Promise<Record<string, any>>;
14
+ transformResponseOut(response: Response): Promise<Response>;
15
+ }
@@ -0,0 +1,14 @@
1
+ import type { LLMProvider } from "../../types/llm";
2
+ import type { Transformer, TransformerContext } from "../../types/transformer";
3
+ import { type UnifiedFimRequest } from "../../utils/fim";
4
+ /**
5
+ * Codestral / Mistral native FIM outbound.
6
+ * Same-kind (mistral inbound): body passthrough — auth + URL only.
7
+ */
8
+ export declare class FimMistralTransformer implements Transformer {
9
+ static TransformerName: string;
10
+ name: string;
11
+ logger?: any;
12
+ transformRequestIn(request: UnifiedFimRequest | any, provider: LLMProvider, context: TransformerContext): Promise<Record<string, any>>;
13
+ transformResponseOut(response: Response): Promise<Response>;
14
+ }
@@ -0,0 +1,15 @@
1
+ import type { LLMProvider } from "../../types/llm";
2
+ import type { Transformer, TransformerContext } from "../../types/transformer";
3
+ import { type UnifiedFimRequest } from "../../utils/fim";
4
+ /**
5
+ * Qwen Completions FIM (LM Studio + DashScope).
6
+ * Same-kind (future qwen inbound): auth + URL only — do not re-template.
7
+ * Cross-family from Codestral Unified: HF tokens in prompt, no suffix field.
8
+ */
9
+ export declare class FimQwenTransformer implements Transformer {
10
+ static TransformerName: string;
11
+ name: string;
12
+ logger?: any;
13
+ transformRequestIn(request: UnifiedFimRequest | any, provider: LLMProvider, context: TransformerContext): Promise<Record<string, any>>;
14
+ transformResponseOut(response: Response): Promise<Response>;
15
+ }
@@ -0,0 +1,22 @@
1
+ import type { LLMProvider } from "../../types/llm";
2
+ import type { Transformer, TransformerContext } from "../../types/transformer";
3
+ import { type UnifiedFimRequest } from "../../utils/fim";
4
+ /**
5
+ * Protocol owner for POST /v1/fim/completions.
6
+ * Validates Codestral-shaped inbound → Unified FIM (v1).
7
+ * Client response framing: same-kind passthrough, else encode to inbound wire.
8
+ */
9
+ export declare class FimTransformer implements Transformer {
10
+ static TransformerName: string;
11
+ name: string;
12
+ endPoint: string;
13
+ logger?: any;
14
+ transformRequestOut(request: any, context: TransformerContext): Promise<any>;
15
+ /**
16
+ * Owner does not perform provider outbound; fim.* transformers do.
17
+ * transformResponseIn is a no-op identity for pipeline compatibility.
18
+ */
19
+ transformResponseIn(response: Response): Promise<Response>;
20
+ }
21
+ /** Type helper — FIM provider transformers accept UnifiedFimRequest. */
22
+ export type FimProviderTransformIn = (request: UnifiedFimRequest, provider: LLMProvider, context: TransformerContext) => Promise<Record<string, any>>;
@@ -0,0 +1,4 @@
1
+ export { FimTransformer } from "./fim.transformer";
2
+ export { FimMistralTransformer } from "./fim.mistral.transformer";
3
+ export { FimDeepseekTransformer } from "./fim.deepseek.transformer";
4
+ export { FimQwenTransformer } from "./fim.qwen.transformer";
@@ -30,6 +30,7 @@ import { ClaudeAuthTransformer } from "./claude-auth.transformer";
30
30
  import { CursorSdkTransformer } from "./cursor-sdk.transformer";
31
31
  import { AntigravityAuthTransformer } from "./antigravity-auth.transformer";
32
32
  import { XaiAuthTransformer } from "./xai-auth.transformer";
33
+ import { FimTransformer, FimMistralTransformer, FimDeepseekTransformer, FimQwenTransformer } from "./fim";
33
34
  declare const _default: {
34
35
  AnthropicTransformer: typeof AnthropicTransformer;
35
36
  GeminiTransformer: typeof GeminiTransformer;
@@ -63,5 +64,9 @@ declare const _default: {
63
64
  CursorSdkTransformer: typeof CursorSdkTransformer;
64
65
  AntigravityAuthTransformer: typeof AntigravityAuthTransformer;
65
66
  XaiAuthTransformer: typeof XaiAuthTransformer;
67
+ FimTransformer: typeof FimTransformer;
68
+ FimMistralTransformer: typeof FimMistralTransformer;
69
+ FimDeepseekTransformer: typeof FimDeepseekTransformer;
70
+ FimQwenTransformer: typeof FimQwenTransformer;
66
71
  };
67
72
  export default _default;
@@ -10,6 +10,8 @@ import { UnifiedChatRequest } from "../types/llm";
10
10
  *
11
11
  * ## Full request pipeline (for context)
12
12
  *
13
+ * Chat protocols share one lifecycle; the Anthropic inbound example:
14
+ *
13
15
  * Client → POST /v1/messages
14
16
  * → AnthropicTransformer.transformRequestOut() // Anthropic → Unified (OpenAI)
15
17
  * → provider.transformer.use[].transformRequestIn() // provider middleware
@@ -24,6 +26,9 @@ import { UnifiedChatRequest } from "../types/llm";
24
26
  * → OpenAITransformer.transformRequestOut() // validate → Unified
25
27
  * → provider.transformer.use[].transformRequestIn()
26
28
  * → … → OpenAITransformer.transformResponseIn() // reasoning_content; strip Unified thinking
29
+ *
30
+ * Responses and FIM use their own owners (`openai-responses`, `Fim`). FIM is a
31
+ * separate pipeline from chat Unified.
27
32
  */
28
33
  export declare class OpenAITransformer implements Transformer {
29
34
  name: string;
@@ -0,0 +1,14 @@
1
+ import type { UnifiedFimRequest } from "./types";
2
+ declare const DEEPSEEK_FIM_MAX_TOKENS = 4096;
3
+ /** Qwen / HF FIM markers for completions prompt. */
4
+ export declare function buildQwenFimPrompt(prompt: string, suffix?: string): string;
5
+ /** Sampling fields shared across FIM outbound bodies. */
6
+ export declare function pickFimSamplingFields(unified: UnifiedFimRequest): Record<string, unknown>;
7
+ /** Native prompt+suffix body (Mistral / DeepSeek field shape). */
8
+ export declare function encodePromptSuffixBody(unified: UnifiedFimRequest, options?: {
9
+ clampMaxTokens?: number;
10
+ disableThinking?: boolean;
11
+ }): Record<string, unknown>;
12
+ export declare function encodeDeepseekFimBody(unified: UnifiedFimRequest): Record<string, unknown>;
13
+ export declare function encodeQwenFimBody(unified: UnifiedFimRequest): Record<string, unknown>;
14
+ export { DEEPSEEK_FIM_MAX_TOKENS };
@@ -0,0 +1,9 @@
1
+ import type { FimInboundKind } from "./kinds";
2
+ import type { UnifiedFimRequest } from "./types";
3
+ /**
4
+ * Inbound → Unified FIM seam.
5
+ * v1: only Codestral/Mistral kind. Future: inboundKind selects an adapter.
6
+ */
7
+ export declare function inboundToUnifiedFim(body: unknown, inboundKind?: FimInboundKind): UnifiedFimRequest;
8
+ /** Clone client body for same-kind passthrough (preserve unknown fields). */
9
+ export declare function cloneFimClientBody(body: unknown, modelName: string): Record<string, unknown>;
@@ -0,0 +1,7 @@
1
+ export type { UnifiedFimRequest, UnifiedFimResponse, UnifiedFimChoice, } from "./types";
2
+ export type { FimInboundKind, FimOutboundFamily } from "./kinds";
3
+ export { V1_FIM_INBOUND_KIND, isFimProviderTransformerName, outboundFamilyFromTransformerName, shouldFimPassthrough, } from "./kinds";
4
+ export { inboundToUnifiedFim, cloneFimClientBody, } from "./inbound";
5
+ export { resolveFimMistralUrl, resolveFimDeepseekUrl, resolveFimQwenCompletionsUrl, bearerAuthHeaders, } from "./url";
6
+ export { buildQwenFimPrompt, pickFimSamplingFields, encodePromptSuffixBody, encodeDeepseekFimBody, encodeQwenFimBody, DEEPSEEK_FIM_MAX_TOKENS, } from "./encode";
7
+ export { encodeFimResponseForInbound, normalizeToFimClientJson, normalizeFimSseDataPayload, } from "./response";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * FIM inbound/outbound family kinds. v1 only implements mistral/codestral
3
+ * inbound; deepseek/qwen inbound adapters are reserved for later.
4
+ */
5
+ export type FimInboundKind = "mistral" | "deepseek" | "qwen";
6
+ export type FimOutboundFamily = "mistral" | "deepseek" | "qwen";
7
+ /** v1 hard-wired inbound kind (Codestral/Mistral-shaped client wire). */
8
+ export declare const V1_FIM_INBOUND_KIND: FimInboundKind;
9
+ export declare function isFimProviderTransformerName(name: string | undefined): boolean;
10
+ export declare function outboundFamilyFromTransformerName(name: string | undefined): FimOutboundFamily | null;
11
+ /**
12
+ * Same-kind passthrough: no request or response shape translation —
13
+ * auth/URL only. Kept generic so future DeepSeek→DeepSeek / Qwen→Qwen
14
+ * inbound works the same.
15
+ */
16
+ export declare function shouldFimPassthrough(inboundKind: FimInboundKind, outboundFamily: FimOutboundFamily): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Encode upstream FIM responses to the **inbound** client wire.
3
+ * Client response shape follows inbound kind (not outbound provider).
4
+ * v1 inbound is mistral/Codestral; deepseek/qwen inbound reserved for later.
5
+ */
6
+ import type { FimInboundKind } from "./kinds";
7
+ /**
8
+ * Normalize upstream JSON to the inbound client wire.
9
+ * @param inboundKind — must match the kind used for inboundToUnifiedFim
10
+ */
11
+ export declare function encodeFimResponseForInbound(payload: any, inboundKind?: FimInboundKind): Record<string, any>;
12
+ /** @deprecated Prefer encodeFimResponseForInbound(payload, inboundKind) */
13
+ export declare function normalizeToFimClientJson(payload: any, inboundKind?: FimInboundKind): Record<string, any>;
14
+ /**
15
+ * Map one SSE data payload to the inbound client wire.
16
+ */
17
+ export declare function normalizeFimSseDataPayload(dataStr: string, inboundKind?: FimInboundKind): string;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Unified FIM intermediate (prompt + optional suffix + sampling).
3
+ * Types live next to FIM utils — not a separate types/fim package.
4
+ *
5
+ * Client response wire follows **inbound** kind (see encodeFimResponseForInbound).
6
+ * v1 inbound is mistral/Codestral chat.completion; other kinds reserved.
7
+ */
8
+ export interface UnifiedFimRequest {
9
+ model: string;
10
+ prompt: string;
11
+ suffix?: string;
12
+ max_tokens?: number;
13
+ temperature?: number;
14
+ top_p?: number;
15
+ stop?: string | string[];
16
+ stream?: boolean;
17
+ min_tokens?: number;
18
+ random_seed?: number;
19
+ }
20
+ /** Choice on mistral/Codestral inbound client wire. */
21
+ export interface UnifiedFimChoice {
22
+ index: number;
23
+ message: {
24
+ role: string;
25
+ content: string;
26
+ };
27
+ finish_reason: string;
28
+ }
29
+ export interface UnifiedFimResponse {
30
+ id: string;
31
+ object: "chat.completion";
32
+ model: string;
33
+ created: number;
34
+ choices: UnifiedFimChoice[];
35
+ usage: {
36
+ prompt_tokens: number;
37
+ completion_tokens: number;
38
+ total_tokens: number;
39
+ };
40
+ [key: string]: unknown;
41
+ }
@@ -0,0 +1,13 @@
1
+ /** Resolve Codestral/Mistral native FIM URL from provider base. */
2
+ export declare function resolveFimMistralUrl(baseUrl: string): URL;
3
+ /**
4
+ * DeepSeek hosted FIM uses beta completions.
5
+ * Prefer explicit …/beta/completions; otherwise derive from host.
6
+ */
7
+ export declare function resolveFimDeepseekUrl(baseUrl: string): URL;
8
+ /**
9
+ * Qwen / LM Studio / DashScope: OpenAI legacy completions.
10
+ * Trust api_base_url when it already ends with /completions.
11
+ */
12
+ export declare function resolveFimQwenCompletionsUrl(baseUrl: string): URL;
13
+ export declare function bearerAuthHeaders(apiKey: string | undefined): Record<string, string>;
@@ -32,4 +32,27 @@ export declare function canonicalReasoning(effortValue: unknown, enabledWhenEffo
32
32
  export declare function applyOpenAIChatReasoning(request: UnifiedChatRequest): UnifiedChatRequest;
33
33
  /** Anthropic accepts low..max, while CCR/OpenAI may additionally emit minimal/ultra/none. */
34
34
  export declare function toAnthropicReasoningEffort(effortValue: unknown): Exclude<ThinkLevel, "none" | "minimal" | "ultra"> | undefined;
35
+ /**
36
+ * GPT-6 family slugs (`gpt-6`, `gpt-6-astra`, `openai/gpt-6-astra`,
37
+ * `codex,gpt-6-astra`). Anchored so `gpt-60` / `gpt-5.6` do not match.
38
+ */
39
+ export declare function isGpt6FamilyModel(model: unknown): boolean;
40
+ /** Astra rejects `none` / `minimal`; OpenAI's migration floor is `low`. */
41
+ export declare function coerceGpt6ReasoningEffort(model: unknown, effort: ThinkLevel | undefined): ThinkLevel | undefined;
42
+ /**
43
+ * Remap unsupported GPT-6 efforts on a Responses/Unified request in place.
44
+ * Covers convert (`openai-responses`) and same-protocol wire-keep (`codex`).
45
+ */
46
+ export declare function applyGpt6ReasoningEffortCoercion(request: {
47
+ model?: unknown;
48
+ reasoning?: {
49
+ effort?: unknown;
50
+ enabled?: boolean;
51
+ } | null;
52
+ }): void;
53
+ /**
54
+ * GPT-6 Astra rejects temperature / top_p / logprobs on Responses. Strip in
55
+ * place when the model is in the gpt-6 family.
56
+ */
57
+ export declare function stripGpt6UnsupportedSampling(request: Record<string, any>): void;
35
58
  export {};
@@ -35,7 +35,7 @@ export interface RouterContext {
35
35
  tokenizerService?: TokenizerService;
36
36
  event?: any;
37
37
  }
38
- export type RouterScenarioType = 'default' | 'background' | 'think' | 'longContext' | 'webSearch' | 'subagent';
38
+ export type RouterScenarioType = 'default' | 'background' | 'think' | 'longContext' | 'webSearch' | 'subagent' | 'fim';
39
39
  export interface RouterFallbackConfig {
40
40
  default?: string[];
41
41
  background?: string[];
@@ -43,6 +43,7 @@ export interface RouterFallbackConfig {
43
43
  longContext?: string[];
44
44
  webSearch?: string[];
45
45
  subagent?: string[];
46
+ fim?: string[];
46
47
  }
47
48
  export declare const router: (req: any, _res: any, context: RouterContext) => Promise<void>;
48
49
  export declare const searchProjectBySession: (sessionId: string, logger?: any) => Promise<string | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caeliq/llms",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "description": "A universal LLM API transformation server",
5
5
  "main": "dist/cjs/server.cjs",
6
6
  "module": "dist/esm/server.mjs",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@anthropic-ai/sdk": "^0.120.0",
33
- "@caeliq/ccr-shared": "^2.1.10",
33
+ "@caeliq/ccr-shared": "^2.1.11",
34
34
  "@cursor/sdk": "^1.0.30",
35
35
  "@fastify/cors": "^11.3.0",
36
36
  "@fastify/rate-limit": "^11.2.0",