@caeliq/llms 1.0.71 → 1.0.73

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 (43) hide show
  1. package/dist/cjs/server.cjs +235 -233
  2. package/dist/cjs/server.cjs.map +4 -4
  3. package/dist/cursor-sdk/inbound-session.d.ts +21 -0
  4. package/dist/cursor-sdk/model-selection.d.ts +23 -0
  5. package/dist/cursor-sdk/session.d.ts +16 -5
  6. package/dist/cursor-sdk/shared.d.ts +10 -1
  7. package/dist/cursor-sdk/turn-output.d.ts +2 -0
  8. package/dist/esm/server.mjs +239 -237
  9. package/dist/esm/server.mjs.map +4 -4
  10. package/dist/routing/protocol-endpoints.d.ts +33 -0
  11. package/dist/services/provider.d.ts +8 -2
  12. package/dist/session-registry.d.ts +30 -3
  13. package/dist/tests/anthropic.third-party-tool-names.d.ts +1 -0
  14. package/dist/tests/codex.bootstrap-buffer.d.ts +1 -0
  15. package/dist/tests/codex.model-catalog.d.ts +1 -0
  16. package/dist/tests/cursor-sdk.inbound-session.d.ts +1 -0
  17. package/dist/tests/cursor-sdk.interrupt-reentry.d.ts +1 -1
  18. package/dist/tests/cursor-sdk.model-remint.d.ts +1 -0
  19. package/dist/tests/cursor-sdk.model-selection.d.ts +1 -0
  20. package/dist/tests/cursor-sdk.on-delta-thinking.d.ts +1 -1
  21. package/dist/tests/cursor-sdk.runner-recovery.d.ts +1 -1
  22. package/dist/tests/cursor-sdk.scratch-report.d.ts +1 -1
  23. package/dist/tests/cursor-sdk.turn-coordination.d.ts +1 -1
  24. package/dist/tests/fallback.request-context.routes.d.ts +1 -0
  25. package/dist/tests/path-alias.build.d.ts +1 -0
  26. package/dist/tests/request-scoped-errors.d.ts +1 -0
  27. package/dist/tests/request-scoped-errors.routes.d.ts +1 -0
  28. package/dist/tests/responses.multi-agent.routes.d.ts +1 -0
  29. package/dist/tests/responses.orphan-delegation.d.ts +1 -0
  30. package/dist/tests/support/isolate-session-registry.d.ts +1 -0
  31. package/dist/tests/web-search.cross-protocol.d.ts +1 -0
  32. package/dist/transformer/claude-auth.transformer.d.ts +11 -2
  33. package/dist/transformer/codex.transformer.d.ts +18 -0
  34. package/dist/types/llm.d.ts +39 -2
  35. package/dist/utils/anthropic-client-policy.d.ts +8 -0
  36. package/dist/utils/claude-billing.d.ts +20 -5
  37. package/dist/utils/codex-bootstrap.d.ts +68 -0
  38. package/dist/utils/codex-model-catalog.d.ts +63 -0
  39. package/dist/utils/nested-agent.d.ts +4 -0
  40. package/dist/utils/openai.responses.util.d.ts +56 -1
  41. package/dist/utils/reasoning-effort.d.ts +3 -20
  42. package/dist/utils/request-scoped-errors.d.ts +92 -0
  43. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  import { UnifiedChatRequest } from "../types/llm";
2
+ import type { HostedWebSearchRequest } from "../routing/protocol-endpoints";
2
3
  export interface ResponsesCallIdMap {
3
4
  /** Original client call_id → sanitized id (and reverse). */
4
5
  forward: Map<string, string>;
@@ -18,11 +19,47 @@ export declare function mapCallId(map: ResponsesCallIdMap, id: unknown, directio
18
19
  * collisions resolve identically in both directions.
19
20
  */
20
21
  export declare function sanitizeResponsesWireCallIds(body: any, callIdMap?: ResponsesCallIdMap): any;
22
+ /**
23
+ * Opt-in inbound compatibility for Codex multi-agent traffic (CLIProxyAPI
24
+ * `orphan-delegation-compatibility` / `optimize-multi-agent-v2` port).
25
+ *
26
+ * Both flags default to false and are read from top-level config
27
+ * (`orphanDelegationCompatibility` / `orphan_delegation_compatibility`,
28
+ * `optimizeMultiAgentV2` / `optimize_multi_agent_v2`). Orphan conversion
29
+ * additionally requires the `X-Openai-Subagent: collab_spawn` request header,
30
+ * so unrelated clients never silently change shape.
31
+ */
32
+ export interface ResponsesInboundCompatOptions {
33
+ orphanDelegationCompatibility?: boolean;
34
+ optimizeMultiAgentV2?: boolean;
35
+ /** True when the collab_spawn subagent header is present on the request. */
36
+ subagentCollabSpawn?: boolean;
37
+ }
38
+ export declare function hasCollabSpawnSubagentHeader(headers: unknown): boolean;
39
+ export declare function resolveResponsesInboundCompat(headers: unknown, configService?: {
40
+ get(key: string): any;
41
+ }): ResponsesInboundCompatOptions;
42
+ /**
43
+ * Apply the opt-in multi-agent compatibility to the Responses client wire.
44
+ *
45
+ * Same-protocol wire keep (primary and fallback) sends `clientWireBody`
46
+ * upstream instead of the Unified projection, so the Unified-side conversion
47
+ * alone would still ship items the upstream cannot correlate or does not
48
+ * know. Under the same gates as responsesRequestToUnified:
49
+ * - orphan outputs (flag + `collab_spawn` header) become user message items,
50
+ * ordered exactly like the Unified projection;
51
+ * - role-less `agent_message` items (`optimizeMultiAgentV2`) become user
52
+ * message items with their content parts preserved.
53
+ * Role-bearing `agent_message` items and every other item stay byte-identical.
54
+ * Call only after normalization has validated the body. Returns the input
55
+ * body when nothing changes.
56
+ */
57
+ export declare function repairResponsesWireMultiAgentCompat(body: any, compat: ResponsesInboundCompatOptions): any;
21
58
  /**
22
59
  * Client Responses wire → Unified (Chat Completions shape).
23
60
  * Supports the Responses MVP subset; rejects CCR-unsupported stateful fields.
24
61
  */
25
- export declare function responsesRequestToUnified(body: any, callIdMap?: ResponsesCallIdMap, customToolNames?: Set<string>): UnifiedChatRequest;
62
+ export declare function responsesRequestToUnified(body: any, callIdMap?: ResponsesCallIdMap, customToolNames?: Set<string>, compat?: ResponsesInboundCompatOptions): UnifiedChatRequest;
26
63
  /** Responses `include` is a string list; drop non-strings rather than invent values. */
27
64
  export declare function normalizeResponsesInclude(include: unknown): string[] | undefined;
28
65
  export declare function isResponsesReasoningItemId(value: unknown): value is string;
@@ -170,6 +207,14 @@ export interface CodexIsolateConventionsOptions {
170
207
  * apply the exec/patch normalizers in one place so stream finalize, the
171
208
  * completed skeleton, and the non-stream JSON path cannot drift. */
172
209
  export declare function normalizeClientCustomToolInput(name: string | undefined, rawArguments: string, options?: CodexIsolateConventionsOptions): string;
210
+ /**
211
+ * Hosted web search options from a Responses `web_search` tool. Unified keeps
212
+ * only the `web_search` function projection, so destinations that run the
213
+ * search themselves (Anthropic server tools) read these request-locally.
214
+ */
215
+ export declare function hostedWebSearchFromResponsesTools(tools: unknown): HostedWebSearchRequest | undefined;
216
+ /** Approximate location fields shared by Responses and Chat search options. */
217
+ export declare function hostedUserLocation(location: any): Pick<HostedWebSearchRequest, "userLocation">;
173
218
  /** Unified Chat JSON → Responses API non-stream response. */
174
219
  export declare function unifiedResponseToResponses(chat: any, options?: {
175
220
  originalModel?: string;
@@ -185,10 +230,20 @@ export interface ResponsesStreamState {
185
230
  textClosed: boolean;
186
231
  textOutputIndex?: number;
187
232
  textContent: string;
233
+ /** Unified text length before the current text item (annotation offsets). */
234
+ textBase: number;
235
+ /** Unified text length emitted so far across all text items. */
236
+ totalTextLength: number;
237
+ textAnnotations: any[];
188
238
  closedTextItems: Array<{
189
239
  id: string;
190
240
  outputIndex: number;
191
241
  content: string;
242
+ annotations: any[];
243
+ }>;
244
+ webSearchCalls: Array<{
245
+ item: any;
246
+ outputIndex: number;
192
247
  }>;
193
248
  toolCalls: Map<number, {
194
249
  id: string;
@@ -33,28 +33,11 @@ export declare function applyOpenAIChatReasoning(request: UnifiedChatRequest): U
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
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.
36
+ * GPT-6 family slugs (`gpt-6`, `gpt-6-astra`, `gpt-6.1-sol`,
37
+ * `openai/gpt-6-astra`, `codex,gpt-6.1-sol`). Anchored so `gpt-60` /
38
+ * `gpt-5.6` do not match.
38
39
  */
39
40
  export declare function isGpt6FamilyModel(model: unknown): boolean;
40
- /** Astra/Sol reject `none` / `minimal`; OpenAI's migration floor is `low`. */
41
- export declare function coerceGpt6ReasoningEffort(model: unknown, effort: ThinkLevel | undefined): ThinkLevel | undefined;
42
- /**
43
- * GPT-6 Luna slugs (`gpt-6-luna`, `openai/gpt-6-luna`, `codex,gpt-6-luna`).
44
- * Anchored so `gpt-6-sol` / `gpt-6-astra` do not match.
45
- */
46
- export declare function isGpt6LunaModel(model: unknown): boolean;
47
- /**
48
- * Remap unsupported GPT-6 efforts on a Responses/Unified request in place.
49
- * Covers convert (`openai-responses`) and same-protocol wire-keep (`codex`).
50
- */
51
- export declare function applyGpt6ReasoningEffortCoercion(request: {
52
- model?: unknown;
53
- reasoning?: {
54
- effort?: unknown;
55
- enabled?: boolean;
56
- } | null;
57
- }): void;
58
41
  /**
59
42
  * GPT-6 Astra rejects temperature / top_p / logprobs on Responses. Strip in
60
43
  * place when the model is in the gpt-6 family.
@@ -0,0 +1,92 @@
1
+ export type RequestScopedErrorAction = "stop" | "stop-and-cooldown" | "continue" | "continue-and-cooldown";
2
+ export interface RequestScopedErrorRule {
3
+ status?: number;
4
+ match?: string[];
5
+ match_regex?: string[];
6
+ matchRegex?: string[];
7
+ "match-regex"?: string[];
8
+ action: RequestScopedErrorAction;
9
+ cooldown_seconds?: number;
10
+ cooldownSeconds?: number;
11
+ }
12
+ export interface NormalizedScopedErrorRule {
13
+ status?: number;
14
+ /** Lowercased substring patterns. */
15
+ match: string[];
16
+ matchRegex: RegExp[];
17
+ action: RequestScopedErrorAction;
18
+ cooldownSeconds: number;
19
+ }
20
+ /** A config rule rejected by validation; `index` is -1 for a non-array list. */
21
+ export interface ScopedErrorRuleIssue {
22
+ index: number;
23
+ reason: string;
24
+ }
25
+ /** Default cooldown for `*-and-cooldown` actions (matches legacy 60s transient). */
26
+ export declare const DEFAULT_SCOPED_ERROR_COOLDOWN_SECONDS = 60;
27
+ /** Accepted spellings of the rule-list key, canonical first. */
28
+ export declare const SCOPED_ERROR_RULE_KEYS: readonly ["request_scoped_errors", "requestScopedErrors", "request-scoped-errors"];
29
+ /**
30
+ * Compile raw config rules. An invalid rule (unknown key, bad action, status,
31
+ * pattern list, regex or cooldown) is dropped and reported via `onInvalid`;
32
+ * it is never widened into a broader match.
33
+ */
34
+ export declare function normalizeRequestScopedErrorRules(input: unknown, onInvalid?: (issue: ScopedErrorRuleIssue) => void): NormalizedScopedErrorRule[];
35
+ /**
36
+ * Compiled rules for a raw config list, cached per list object so validation
37
+ * (and its `onInvalid` reports) runs once per config value, not per request.
38
+ */
39
+ export declare function compiledScopedErrorRules(input: unknown, onInvalid?: (issue: ScopedErrorRuleIssue) => void): NormalizedScopedErrorRule[];
40
+ /** Read a rule list from a config carrier under any accepted key spelling. */
41
+ export declare function readScopedErrorRulesFromCarrier(carrier: unknown): unknown;
42
+ /** Top-level (global) rule list from a config service, any key spelling. */
43
+ export declare function readGlobalScopedErrorRules(configService: {
44
+ get(key: string): unknown;
45
+ }): unknown;
46
+ /** Upper bound (chars) on the raw text kept for rule matching. */
47
+ export declare const MAX_SCOPED_ERROR_CLASSIFICATION_CHARS = 16384;
48
+ /** Attach the raw upstream error text an error was built from. */
49
+ export declare function attachScopedErrorClassificationText(error: unknown, rawText: unknown): void;
50
+ /** Raw classification text previously attached to an error, if any. */
51
+ export declare function readScopedErrorClassificationText(error: unknown): string | undefined;
52
+ /** HTTP status for classification: explicit field first, then upstream snapshot. */
53
+ export declare function errorStatusForClassification(error: any): number | undefined;
54
+ /**
55
+ * Searchable body text. Prefers the raw upstream text a producer attached;
56
+ * without it, falls back to the message plus any captured upstream body. A
57
+ * specific error code is appended either way. The error `type` (always
58
+ * `api_error` for provider failures) is never included.
59
+ */
60
+ export declare function errorTextForClassification(error: any): string;
61
+ /** First matching rule, or undefined when nothing matches. */
62
+ export declare function matchScopedErrorRule(error: any, rules: NormalizedScopedErrorRule[]): NormalizedScopedErrorRule | undefined;
63
+ export type ScopedErrorDecision = {
64
+ kind: "default";
65
+ } | {
66
+ kind: "stop" | "continue";
67
+ rule: NormalizedScopedErrorRule;
68
+ cooldown: boolean;
69
+ };
70
+ /**
71
+ * Classify an upstream error against provider rules first, then global rules.
72
+ * `stop` forces a terminal failure (no fallback); `continue` forces fallback
73
+ * eligibility even when the status alone would not qualify.
74
+ */
75
+ export declare function decideScopedError(error: any, providerRules: NormalizedScopedErrorRule[], globalRules: NormalizedScopedErrorRule[]): ScopedErrorDecision;
76
+ /**
77
+ * Cooldown key. The model drops its `[1m]` context marker: the primary route
78
+ * strips it before dispatch while fallback entries keep it as configured,
79
+ * yet both name the same upstream model.
80
+ */
81
+ export declare function scopedErrorCooldownKey(providerName: string, model: string): string;
82
+ export declare class ScopedErrorCooldownRegistry {
83
+ private readonly expiries;
84
+ put(providerName: string, model: string, cooldownSeconds?: number, now?: number): void;
85
+ isCooledDown(providerName: string, model: string, now?: number): boolean;
86
+ /** Drop every expired entry so keys that are never re-read cannot pile up. */
87
+ prune(now?: number): void;
88
+ /** Number of tracked entries, expired or not. */
89
+ get size(): number;
90
+ }
91
+ /** The cooldown registry owned by `scope`, created on first use. */
92
+ export declare function scopedErrorCooldownsFor(scope: object): ScopedErrorCooldownRegistry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caeliq/llms",
3
- "version": "1.0.71",
3
+ "version": "1.0.73",
4
4
  "description": "A universal LLM API transformation server",
5
5
  "main": "dist/cjs/server.cjs",
6
6
  "module": "dist/esm/server.mjs",
@@ -30,8 +30,8 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@anthropic-ai/sdk": "^0.120.0",
33
- "@caeliq/ccr-shared": "^2.1.13",
34
- "@cursor/sdk": "^1.0.32",
33
+ "@caeliq/ccr-shared": "^2.1.15",
34
+ "@cursor/sdk": "^1.0.36",
35
35
  "@fastify/cors": "^11.3.0",
36
36
  "@fastify/rate-limit": "^11.2.0",
37
37
  "@google/genai": "^2.18.0",