@omnicross/core 0.1.5 → 0.1.6
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/dist/ApiConverter.cjs +2 -2
- package/dist/ApiConverter.js +1 -1
- package/dist/{CompletionService-DdWaAxq0.d.ts → CompletionService-C3BX0Ovy.d.ts} +4 -3
- package/dist/{CompletionService-D3a47vdU.d.cts → CompletionService-kNA17cfI.d.cts} +4 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -5
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -3
- package/dist/{chunk-HRRYG2AX.js → chunk-23S5OPIO.js} +10 -1
- package/dist/chunk-25GXJCEZ.cjs +40 -0
- package/dist/chunk-2JYRIADS.js +40 -0
- package/dist/{chunk-4XMYPW46.cjs → chunk-4VLRHHFE.cjs} +75 -33
- package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
- package/dist/{chunk-C6OV7GCC.js → chunk-6CL5HTPQ.js} +44 -2
- package/dist/chunk-6QQG7YG3.cjs +153 -0
- package/dist/{chunk-3Q6Z6JTO.cjs → chunk-6VUQPOV3.cjs} +277 -86
- package/dist/chunk-7AK7B36B.cjs +44 -0
- package/dist/{chunk-5ZQBEOMD.js → chunk-AT7B7SOZ.js} +25 -2
- package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
- package/dist/chunk-DLXZEZWO.cjs +285 -0
- package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
- package/dist/chunk-EJLH6NFT.cjs +166 -0
- package/dist/chunk-HVBBDBS3.cjs +350 -0
- package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
- package/dist/{chunk-JWVTXXPX.cjs → chunk-KBM2W6UY.cjs} +8 -4
- package/dist/{chunk-PG7PS2NN.cjs → chunk-KCVJWJST.cjs} +14 -2
- package/dist/chunk-LB6EBS6Y.js +69 -0
- package/dist/{chunk-IWQAX3CS.js → chunk-LVUCAWMK.js} +1 -1
- package/dist/chunk-MKF46GNZ.js +350 -0
- package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
- package/dist/{chunk-MFZ5437A.js → chunk-N5T4M4GU.js} +1 -1
- package/dist/{chunk-BODMAL6G.js → chunk-OEWZUX4G.js} +262 -71
- package/dist/chunk-OF3BECU2.cjs +69 -0
- package/dist/{chunk-DDMRUL76.cjs → chunk-OKMJLEXX.cjs} +5 -5
- package/dist/chunk-OPRS4IQZ.js +153 -0
- package/dist/{chunk-D3TDKWRP.js → chunk-SIZQQD6T.js} +14 -2
- package/dist/{chunk-CGKLE6IW.cjs → chunk-SQYVORNP.cjs} +1219 -510
- package/dist/{chunk-6QZGDLL4.js → chunk-TOVPMMHM.js} +5 -1
- package/dist/{chunk-FH2P4OCD.js → chunk-UDCC7EMR.js} +976 -267
- package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
- package/dist/{chunk-K52THW2C.cjs → chunk-V4TXMEJS.cjs} +5 -5
- package/dist/chunk-VRFBB5DB.js +44 -0
- package/dist/chunk-WB6PH56J.js +166 -0
- package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
- package/dist/{chunk-SUEGJ75D.cjs → chunk-WYTEQ4Q5.cjs} +25 -2
- package/dist/{chunk-5ENKBSWO.js → chunk-YJVHCHQX.js} +42 -6
- package/dist/{chunk-VQY5W4YW.cjs → chunk-YK57NMIF.cjs} +44 -8
- package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
- package/dist/completion/ApiKeyPoolService.cjs +12 -0
- package/dist/completion/ApiKeyPoolService.d.cts +6 -0
- package/dist/completion/ApiKeyPoolService.d.ts +6 -0
- package/dist/completion/ApiKeyPoolService.js +12 -0
- package/dist/completion/CompletionService.cjs +25 -23
- package/dist/completion/CompletionService.d.cts +2 -1
- package/dist/completion/CompletionService.d.ts +2 -1
- package/dist/completion/CompletionService.js +24 -22
- package/dist/completion.cjs +25 -23
- package/dist/completion.d.cts +2 -1
- package/dist/completion.d.ts +2 -1
- package/dist/completion.js +24 -22
- package/dist/index.cjs +49 -26
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +52 -29
- package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
- package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
- package/dist/outbound-api/quotaWarn.d.cts +1 -1
- package/dist/outbound-api/quotaWarn.d.ts +1 -1
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +4 -3
- package/dist/outbound-api/routeResolver.d.ts +4 -3
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
- package/dist/outbound-api/types.d.cts +3 -2
- package/dist/outbound-api/types.d.ts +3 -2
- package/dist/outbound-api.cjs +47 -24
- package/dist/outbound-api.d.cts +127 -85
- package/dist/outbound-api.d.ts +127 -85
- package/dist/outbound-api.js +50 -27
- package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +90 -0
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +90 -0
- package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
- package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
- package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
- package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
- package/dist/pipeline/AccountAllowanceStore.js +20 -0
- package/dist/pipeline/AuthSource.d.cts +11 -2
- package/dist/pipeline/AuthSource.d.ts +11 -2
- package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
- package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
- package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
- package/dist/pipeline/BoundAccountSelectionError.js +10 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
- package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
- package/dist/pipeline/SubscriptionAccountHealth.d.cts +34 -6
- package/dist/pipeline/SubscriptionAccountHealth.d.ts +34 -6
- package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
- package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
- package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
- package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
- package/dist/pipeline/SubscriptionAuthSource.js +4 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.d.cts +8 -3
- package/dist/pipeline/executeProviderCall.d.ts +8 -3
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/resolveProviderChain.d.cts +2 -3
- package/dist/pipeline/resolveProviderChain.d.ts +2 -3
- package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
- package/dist/pipeline/upstreamFetch.cjs +3 -2
- package/dist/pipeline/upstreamFetch.js +2 -1
- package/dist/ports/pricing-store.d.cts +4 -3
- package/dist/ports/pricing-store.d.ts +4 -3
- package/dist/ports.d.cts +4 -3
- package/dist/ports.d.ts +4 -3
- package/dist/provider-proxy/ProviderProxy.cjs +25 -23
- package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
- package/dist/provider-proxy/ProviderProxy.js +24 -22
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +27 -23
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +34 -5
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +34 -5
- package/dist/provider-proxy/ingress/providerProxyShared.js +26 -22
- package/dist/provider-proxy/matchText.cjs +4 -2
- package/dist/provider-proxy/matchText.d.cts +41 -6
- package/dist/provider-proxy/matchText.d.ts +41 -6
- package/dist/provider-proxy/matchText.js +3 -1
- package/dist/provider-proxy/types.d.cts +30 -2
- package/dist/provider-proxy/types.d.ts +30 -2
- package/dist/provider-proxy.cjs +25 -23
- package/dist/provider-proxy.d.cts +1 -0
- package/dist/provider-proxy.d.ts +1 -0
- package/dist/provider-proxy.js +24 -22
- package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-CHTv_Bs5.d.ts} +1 -1
- package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-kepxnfcC.d.cts} +1 -1
- package/dist/transformer/TransformerChainExecutor.cjs +2 -2
- package/dist/transformer/TransformerChainExecutor.js +1 -1
- package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
- package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
- package/dist/transformer/transformers/GeminiTransformer.js +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
- package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
- package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
- package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
- package/dist/transformer/transformers/OpenAITransformer.js +6 -0
- package/dist/transformer/transformers.cjs +8 -14
- package/dist/transformer/transformers.d.cts +12 -48
- package/dist/transformer/transformers.d.ts +12 -48
- package/dist/transformer/transformers.js +12 -18
- package/dist/transformer/types.d.cts +17 -0
- package/dist/transformer/types.d.ts +17 -0
- package/dist/transformer.cjs +10 -11
- package/dist/transformer.d.cts +1 -2
- package/dist/transformer.d.ts +1 -2
- package/dist/transformer.js +9 -10
- package/dist/{types-B8Arpxn0.d.cts → types-H3wGZSOo.d.cts} +134 -7
- package/dist/{types-lgPYQuZS.d.ts → types-hsoKrVQS.d.ts} +134 -7
- package/dist/usage/pricing-engine.cjs +2 -2
- package/dist/usage/pricing-engine.d.cts +9 -1
- package/dist/usage/pricing-engine.d.ts +9 -1
- package/dist/usage/pricing-engine.js +1 -1
- package/dist/usage.cjs +2 -2
- package/dist/usage.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7FEBOPJO.cjs +0 -50
- package/dist/chunk-DWKQZ2SK.cjs +0 -254
- package/dist/chunk-IAXWICZU.js +0 -69
- package/dist/chunk-IB3FDI4O.js +0 -50
- package/dist/chunk-OQWKZCXP.js +0 -242
- package/dist/chunk-QWBWGODS.cjs +0 -69
- package/dist/chunk-YMFAJFQT.cjs +0 -173
- package/dist/chunk-ZCIQ3L3R.cjs +0 -242
- package/dist/chunk-ZJZAOKI7.js +0 -254
- package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
- package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
- package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
- package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
- package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
- package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
|
@@ -8,7 +8,8 @@ import { L as Logger } from './logger-4GvQNzhE.js';
|
|
|
8
8
|
import { ProviderConfigSource } from './ports/provider-config-source.js';
|
|
9
9
|
import { P as ProviderProxy } from './ProviderProxy-C-xqrkKi.js';
|
|
10
10
|
import { ProviderProxyDeps } from './provider-proxy/types.js';
|
|
11
|
-
import {
|
|
11
|
+
import { BoundAccountFallbackPolicy } from './pipeline/BoundAccountSelectionError.js';
|
|
12
|
+
import { c as KeySpend } from './keyPolicy-zdWTu3CQ.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* keySpendTracker — a cheap in-memory per-key accumulated-spend cache
|
|
@@ -313,15 +314,30 @@ interface EndpointRoutingConfig {
|
|
|
313
314
|
/**
|
|
314
315
|
* OPTIONAL subscription-mode binding to ONE specific subscription account id
|
|
315
316
|
* (provider/subscription duality). Absent/blank ⇒ the provider's account pool
|
|
316
|
-
* auto-schedules (priority/LRU/health). When set
|
|
317
|
-
*
|
|
317
|
+
* auto-schedules (priority/LRU/health). When set, strict mode requires this
|
|
318
|
+
* account to serve; the pool is a fallback only with the explicit policy below.
|
|
318
319
|
*/
|
|
319
320
|
boundAccountId?: string;
|
|
321
|
+
/**
|
|
322
|
+
* What a bound account does when it cannot serve this request. Meaningful
|
|
323
|
+
* only with `boundAccountId`; normalization drops it otherwise. A legacy
|
|
324
|
+
* bound endpoint with no field migrates to `'strict'`. The pool is used only
|
|
325
|
+
* when this is explicitly set to `'pool'`.
|
|
326
|
+
*/
|
|
327
|
+
boundAccountFallbackPolicy?: BoundAccountFallbackPolicy;
|
|
328
|
+
/**
|
|
329
|
+
* Runtime-only account-group selector used by a {@link GatewayBinding}.
|
|
330
|
+
* Legacy endpoint persistence does not synthesize this field; it is projected
|
|
331
|
+
* from an independent binding immediately before route resolution.
|
|
332
|
+
*/
|
|
333
|
+
boundAccountGroup?: string;
|
|
320
334
|
/**
|
|
321
335
|
* OPTIONAL provider-mode binding to ONE specific BYO key id (from the
|
|
322
336
|
* provider's key pool). Absent/blank ⇒ the provider's default key / key pool.
|
|
323
337
|
*/
|
|
324
338
|
boundKeyId?: string;
|
|
339
|
+
/** Strict by default; `'pool'` permits the provider's normal key pool. */
|
|
340
|
+
boundKeyFallbackPolicy?: BoundAccountFallbackPolicy;
|
|
325
341
|
/**
|
|
326
342
|
* OPTIONAL "background model id" override list (role-based `gemini` only).
|
|
327
343
|
* When set, an incoming requested model id appearing in this list is
|
|
@@ -364,7 +380,7 @@ interface ConcurrencyQueueConfig {
|
|
|
364
380
|
* Persisted + strictly validated like the queue segments; applied to the shared
|
|
365
381
|
* `SubscriptionAccountHealth` tracker at daemon boot.
|
|
366
382
|
* - `overloadCooldownEnabled` default **true** — a 529 places the account in
|
|
367
|
-
* overload cooldown (
|
|
383
|
+
* overload cooldown (enabled by default).
|
|
368
384
|
* - `overloadCooldownMs` default **600000** (10 min), valid `60000..3600000`.
|
|
369
385
|
*/
|
|
370
386
|
interface AccountHealthConfig {
|
|
@@ -397,6 +413,89 @@ interface AccountProbeConfig {
|
|
|
397
413
|
historySize: number;
|
|
398
414
|
staggerMs: number;
|
|
399
415
|
}
|
|
416
|
+
/** A resource selected by a client-to-upstream gateway binding. */
|
|
417
|
+
type GatewayBindingTarget = {
|
|
418
|
+
kind: 'account';
|
|
419
|
+
providerId: string;
|
|
420
|
+
accountId: string;
|
|
421
|
+
} | {
|
|
422
|
+
kind: 'account-group';
|
|
423
|
+
providerId: string;
|
|
424
|
+
group: string;
|
|
425
|
+
} | {
|
|
426
|
+
/**
|
|
427
|
+
* The provider's WHOLE subscription pool, with no account preference —
|
|
428
|
+
* plain priority/LRU/health scheduling. Distinct from `account-group`,
|
|
429
|
+
* which pins a preferred group, and from `provider`, which is BYO-key.
|
|
430
|
+
*/
|
|
431
|
+
kind: 'account-pool';
|
|
432
|
+
providerId: string;
|
|
433
|
+
} | {
|
|
434
|
+
kind: 'provider';
|
|
435
|
+
providerId: string;
|
|
436
|
+
keyId?: string;
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* Behavior when a binding cannot serve the requested model or credential.
|
|
440
|
+
* `next` yields to the next matching route (and lets a bound account fall back
|
|
441
|
+
* to its provider pool); `fail` keeps the route strict and errors instead.
|
|
442
|
+
*/
|
|
443
|
+
type GatewayBindingFallback = 'next' | 'fail';
|
|
444
|
+
/** Which named API keys may enter a downstream route. */
|
|
445
|
+
type GatewayBindingKeyScope = 'all' | 'selected';
|
|
446
|
+
/** Whether the downstream model id is forwarded or explicitly remapped. */
|
|
447
|
+
type GatewayBindingModelMode = 'passthrough' | 'mapped';
|
|
448
|
+
/** One exact or `*` wildcard model-name rewrite owned by a downstream route. */
|
|
449
|
+
interface GatewayModelMapping {
|
|
450
|
+
source: string;
|
|
451
|
+
target: ModelRef;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Independent client-to-upstream route aggregate.
|
|
455
|
+
*
|
|
456
|
+
* A binding belongs to exactly one endpoint and one upstream resource. Keeping
|
|
457
|
+
* it separate from account/provider DTOs lets the same resource participate in
|
|
458
|
+
* multiple client-key routes without changing its identity or secret shape.
|
|
459
|
+
*/
|
|
460
|
+
interface GatewayBinding {
|
|
461
|
+
id: string;
|
|
462
|
+
name: string;
|
|
463
|
+
enabled: boolean;
|
|
464
|
+
/** Legacy entries without this field keep the former all-vs-list behavior. */
|
|
465
|
+
keyScope?: GatewayBindingKeyScope;
|
|
466
|
+
/** Used only when `keyScope` resolves to `selected`. */
|
|
467
|
+
apiKeyIds?: string[];
|
|
468
|
+
endpoint: OutboundEndpoint;
|
|
469
|
+
target: GatewayBindingTarget;
|
|
470
|
+
/** Lower values win. Key-scoped bindings win before this comparison. */
|
|
471
|
+
priority?: number;
|
|
472
|
+
/** Next yields to the following matching route; fail keeps the binding strict. */
|
|
473
|
+
fallback: GatewayBindingFallback;
|
|
474
|
+
/** Empty passthrough routes preserve the client's requested model id. */
|
|
475
|
+
modelMode?: GatewayBindingModelMode;
|
|
476
|
+
/** Preferred generic mapping shape; legacy endpoint-specific fields remain readable. */
|
|
477
|
+
modelMappings?: GatewayModelMapping[];
|
|
478
|
+
modelMap?: Record<string, ModelRef>;
|
|
479
|
+
models?: ModelRef[];
|
|
480
|
+
dispatchMode?: ChatDispatchMode;
|
|
481
|
+
prefixTargets?: ModelPrefixTargets;
|
|
482
|
+
defaultModel?: ModelRef;
|
|
483
|
+
backgroundModel?: ModelRef;
|
|
484
|
+
backgroundModelIds?: string[];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Optional allowance-aware account scheduling. Default-off keeps allowance
|
|
488
|
+
* telemetry display-only. When enabled, only fresh Claude/Codex snapshots are
|
|
489
|
+
* considered: accounts above `demoteAtPercent` receive a temporary priority
|
|
490
|
+
* penalty; accounts above `pauseAtPercent` are excluded until the provider's
|
|
491
|
+
* reset/freshness deadline. Missing or stale data never excludes an account.
|
|
492
|
+
*/
|
|
493
|
+
interface AllowanceSchedulingConfig {
|
|
494
|
+
enabled: boolean;
|
|
495
|
+
demoteAtPercent: number;
|
|
496
|
+
pauseAtPercent: number;
|
|
497
|
+
priorityPenalty: number;
|
|
498
|
+
}
|
|
400
499
|
/**
|
|
401
500
|
* Client-fingerprint segment (subscription-client-fingerprint #7). Opt-in,
|
|
402
501
|
* default OFF: when disabled the claude-subscription outbound headers are
|
|
@@ -435,8 +534,19 @@ interface OutboundApiServerConfig {
|
|
|
435
534
|
enabled: boolean;
|
|
436
535
|
/** When true the listener binds `0.0.0.0` (LAN) instead of `127.0.0.1`. */
|
|
437
536
|
networkBinding: boolean;
|
|
438
|
-
/**
|
|
537
|
+
/**
|
|
538
|
+
* LEGACY per-endpoint routing config, one per endpoint (4 entries). No longer
|
|
539
|
+
* a routing source: {@link normalizeServerConfig} projects any configured
|
|
540
|
+
* entry into {@link bindings} once and leaves these blank. Retained as the
|
|
541
|
+
* projection shape {@link EndpointRoutingConfig} and for embedders that build
|
|
542
|
+
* a config by hand.
|
|
543
|
+
*/
|
|
439
544
|
endpoints: EndpointRoutingConfig[];
|
|
545
|
+
/**
|
|
546
|
+
* Resource-centric routes — the SSOT for routing. Optional in the raw
|
|
547
|
+
* persisted shape; normalized Omnicross configs always carry an array.
|
|
548
|
+
*/
|
|
549
|
+
bindings?: GatewayBinding[];
|
|
440
550
|
/** Persisted port (fixed default; falls back to ephemeral on EADDRINUSE). */
|
|
441
551
|
port?: number;
|
|
442
552
|
/**
|
|
@@ -463,6 +573,8 @@ interface OutboundApiServerConfig {
|
|
|
463
573
|
* boot; a change takes effect on restart. Default-off ⇒ no scheduler runs.
|
|
464
574
|
*/
|
|
465
575
|
accountProbe?: AccountProbeConfig;
|
|
576
|
+
/** Default-off allowance-aware scheduling; hot-reloaded by the daemon. */
|
|
577
|
+
allowanceScheduling?: AllowanceSchedulingConfig;
|
|
466
578
|
/**
|
|
467
579
|
* Layered upstream-proxy segment (upstream-proxy). Optional; when absent no
|
|
468
580
|
* global/provider proxy applies (direct egress). `normalizeServerConfig` drops
|
|
@@ -546,6 +658,12 @@ interface OutboundApiKeyInfo {
|
|
|
546
658
|
createdAt: number;
|
|
547
659
|
lastUsedAt: number | null;
|
|
548
660
|
revoked: boolean;
|
|
661
|
+
/** Intended consumer. Existing rows default to a general client key. */
|
|
662
|
+
kind?: 'client' | 'integration';
|
|
663
|
+
/** Optional endpoint allow-list. Absent means every outbound endpoint. */
|
|
664
|
+
allowedEndpoints?: OutboundEndpoint[];
|
|
665
|
+
/** When true the key is rejected unless the TCP peer is loopback. */
|
|
666
|
+
loopbackOnly?: boolean;
|
|
549
667
|
/**
|
|
550
668
|
* Per-key concurrency ceiling for the outbound concurrency gate. Absent or
|
|
551
669
|
* `0` = unlimited (the gate is bypassed entirely for this key).
|
|
@@ -571,7 +689,7 @@ interface OutboundApiKeyInfo {
|
|
|
571
689
|
rateLimitWindowMs?: number | null;
|
|
572
690
|
/** Master switch: when false/unset the model list is inert (no restriction). */
|
|
573
691
|
enableModelRestriction?: boolean;
|
|
574
|
-
/** Restriction mode; absent ⇒ `'blacklist'
|
|
692
|
+
/** Restriction mode; absent ⇒ `'blacklist'`. */
|
|
575
693
|
restrictionMode?: OutboundKeyModelRestrictionMode;
|
|
576
694
|
/** The model-id list the mode acts on (bare modelIds; empty allowlist denies all). */
|
|
577
695
|
restrictedModels?: string[];
|
|
@@ -637,6 +755,12 @@ interface OutboundKeyDbRow {
|
|
|
637
755
|
createdAt: number;
|
|
638
756
|
lastUsedAt: number | null;
|
|
639
757
|
revokedAt: number | null;
|
|
758
|
+
/** Intended consumer. Existing rows without this field remain client keys. */
|
|
759
|
+
kind?: 'client' | 'integration';
|
|
760
|
+
/** Optional endpoint allow-list for least-privilege integration keys. */
|
|
761
|
+
allowedEndpoints?: OutboundEndpoint[];
|
|
762
|
+
/** Restrict use to requests whose direct socket peer is loopback. */
|
|
763
|
+
loopbackOnly?: boolean;
|
|
640
764
|
/**
|
|
641
765
|
* Per-key concurrency ceiling. Absent/`0` = unlimited = the concurrency gate
|
|
642
766
|
* is bypassed for this key. Persisted by the daemon (`omnicross-uqc-daemon`).
|
|
@@ -676,6 +800,9 @@ interface OutboundKeyDb {
|
|
|
676
800
|
keyHash: string;
|
|
677
801
|
keyPrefix: string;
|
|
678
802
|
createdAt?: number;
|
|
803
|
+
kind?: 'client' | 'integration';
|
|
804
|
+
allowedEndpoints?: OutboundEndpoint[];
|
|
805
|
+
loopbackOnly?: boolean;
|
|
679
806
|
}): Promise<OutboundKeyDbRow>;
|
|
680
807
|
outboundApiKeysRevoke(id: string): Promise<boolean>;
|
|
681
808
|
outboundApiKeysTouchLastUsed(id: string): Promise<boolean>;
|
|
@@ -751,4 +878,4 @@ interface OutboundApiDeps {
|
|
|
751
878
|
readonly logger?: Logger;
|
|
752
879
|
}
|
|
753
880
|
|
|
754
|
-
export { type AccountProbeConfig as A,
|
|
881
|
+
export { type AccountProbeConfig as A, computeVoucherGrant as B, type ChatDispatchMode as C, generateVoucherCode as D, ENDPOINT_MODEL_KINDS as E, type FingerprintConfig as F, type GatewayBinding as G, hashVoucherCode as H, newVoucherId as I, startOfLocalDay as J, type KeySpendReader as K, startOfLocalWeek as L, type MessagesModelKind as M, toVoucherInfo as N, type OutboundKeyDb as O, voucherCodePrefix as P, type ModelRef as Q, type RequestRole as R, type AccountHealthConfig as S, type OutboundKeyModelRestrictionMode as T, type UserMessageQueueConfig as U, type VoucherCreateInput as V, type AllowanceSchedulingConfig as a, type ConcurrencyQueueConfig as b, type EndpointRoutingConfig as c, type GatewayBindingFallback as d, type GatewayBindingKeyScope as e, type GatewayBindingModelMode as f, type GatewayBindingTarget as g, type GatewayModelMapping as h, type KeySpendSeeder as i, KeySpendTracker as j, type KindMappedEndpoint as k, type ModelKind as l, type ModelPrefixTargets as m, type OutboundApiDeps as n, type OutboundApiKeyCreated as o, type OutboundApiKeyInfo as p, type OutboundApiServerConfig as q, type OutboundApiServerStatus as r, type OutboundEndpoint as s, type OutboundFormatUrls as t, type OutboundKeyActivationMode as u, type OutboundKeyDbRow as v, type OutboundKeyPolicy as w, type OutboundProxyConfig as x, type ResponsesModelKind as y, type VoucherDb as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkDLXZEZWOcjs = require('../chunk-DLXZEZWO.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
exports.PricingEngine =
|
|
6
|
+
exports.PricingEngine = _chunkDLXZEZWOcjs.PricingEngine;
|
|
@@ -9,7 +9,8 @@ import { PricingStore } from '../ports/pricing-store.cjs';
|
|
|
9
9
|
* Persistence goes through the injected `PricingStore` port. Sources of
|
|
10
10
|
* pricing rows:
|
|
11
11
|
* - 'builtin' — bundled fallback prices, seeded by the host
|
|
12
|
-
* - 'litellm' —
|
|
12
|
+
* - 'litellm' — primary catalog from LiteLLM's public JSON
|
|
13
|
+
* - 'openrouter' — supplemental OpenRouter route pricing
|
|
13
14
|
* - 'user' — hand-edited; protected from auto-overwrite
|
|
14
15
|
*
|
|
15
16
|
* @module usage/pricing-engine
|
|
@@ -29,8 +30,12 @@ interface CostCalculation {
|
|
|
29
30
|
interface PricingEngineOptions {
|
|
30
31
|
/** Override the pricing-source JSON URL — useful for testing. */
|
|
31
32
|
sourceUrl?: string;
|
|
33
|
+
/** Override the supplemental OpenRouter catalog URL. */
|
|
34
|
+
openRouterSourceUrl?: string;
|
|
32
35
|
/** Override `fetch` — useful for testing. */
|
|
33
36
|
fetchImpl?: typeof fetch;
|
|
37
|
+
/** Bound each remote source independently; both sources are fetched in parallel. */
|
|
38
|
+
fetchTimeoutMs?: number;
|
|
34
39
|
}
|
|
35
40
|
declare class PricingEngine {
|
|
36
41
|
private store;
|
|
@@ -46,6 +51,8 @@ declare class PricingEngine {
|
|
|
46
51
|
*/
|
|
47
52
|
private cacheByModel;
|
|
48
53
|
private cacheLoaded;
|
|
54
|
+
/** Coalesce manual and background refreshes to prevent a catalog stampede. */
|
|
55
|
+
private refreshInFlight;
|
|
49
56
|
constructor(store: PricingStore, logger: Logger, options?: PricingEngineOptions);
|
|
50
57
|
/** Lazy-load and cache the full pricing table. */
|
|
51
58
|
private ensureCache;
|
|
@@ -77,6 +84,7 @@ declare class PricingEngine {
|
|
|
77
84
|
calculateCost(providerId: string, modelId: string, usage: UsageTokens): Promise<CostCalculation>;
|
|
78
85
|
upsertManual(input: PricingEntryInput): Promise<PricingEntry>;
|
|
79
86
|
fetchLatestFromSource(): Promise<PricingFetchResult>;
|
|
87
|
+
private refreshSources;
|
|
80
88
|
resolveConflicts(decisions: PricingConflictDecision[], pendingIncoming: Map<string, PricingEntryInput>): Promise<PricingResolution>;
|
|
81
89
|
}
|
|
82
90
|
|
|
@@ -9,7 +9,8 @@ import { PricingStore } from '../ports/pricing-store.js';
|
|
|
9
9
|
* Persistence goes through the injected `PricingStore` port. Sources of
|
|
10
10
|
* pricing rows:
|
|
11
11
|
* - 'builtin' — bundled fallback prices, seeded by the host
|
|
12
|
-
* - 'litellm' —
|
|
12
|
+
* - 'litellm' — primary catalog from LiteLLM's public JSON
|
|
13
|
+
* - 'openrouter' — supplemental OpenRouter route pricing
|
|
13
14
|
* - 'user' — hand-edited; protected from auto-overwrite
|
|
14
15
|
*
|
|
15
16
|
* @module usage/pricing-engine
|
|
@@ -29,8 +30,12 @@ interface CostCalculation {
|
|
|
29
30
|
interface PricingEngineOptions {
|
|
30
31
|
/** Override the pricing-source JSON URL — useful for testing. */
|
|
31
32
|
sourceUrl?: string;
|
|
33
|
+
/** Override the supplemental OpenRouter catalog URL. */
|
|
34
|
+
openRouterSourceUrl?: string;
|
|
32
35
|
/** Override `fetch` — useful for testing. */
|
|
33
36
|
fetchImpl?: typeof fetch;
|
|
37
|
+
/** Bound each remote source independently; both sources are fetched in parallel. */
|
|
38
|
+
fetchTimeoutMs?: number;
|
|
34
39
|
}
|
|
35
40
|
declare class PricingEngine {
|
|
36
41
|
private store;
|
|
@@ -46,6 +51,8 @@ declare class PricingEngine {
|
|
|
46
51
|
*/
|
|
47
52
|
private cacheByModel;
|
|
48
53
|
private cacheLoaded;
|
|
54
|
+
/** Coalesce manual and background refreshes to prevent a catalog stampede. */
|
|
55
|
+
private refreshInFlight;
|
|
49
56
|
constructor(store: PricingStore, logger: Logger, options?: PricingEngineOptions);
|
|
50
57
|
/** Lazy-load and cache the full pricing table. */
|
|
51
58
|
private ensureCache;
|
|
@@ -77,6 +84,7 @@ declare class PricingEngine {
|
|
|
77
84
|
calculateCost(providerId: string, modelId: string, usage: UsageTokens): Promise<CostCalculation>;
|
|
78
85
|
upsertManual(input: PricingEntryInput): Promise<PricingEntry>;
|
|
79
86
|
fetchLatestFromSource(): Promise<PricingFetchResult>;
|
|
87
|
+
private refreshSources;
|
|
80
88
|
resolveConflicts(decisions: PricingConflictDecision[], pendingIncoming: Map<string, PricingEntryInput>): Promise<PricingResolution>;
|
|
81
89
|
}
|
|
82
90
|
|
package/dist/usage.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-EYZYXJTJ.cjs');
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkDLXZEZWOcjs = require('./chunk-DLXZEZWO.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunkSNYBEXLBcjs = require('./chunk-SNYBEXLB.cjs');
|
|
@@ -9,4 +9,4 @@ require('./chunk-XSVNC2UD.cjs');
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.PricingEngine =
|
|
12
|
+
exports.PricingEngine = _chunkDLXZEZWOcjs.PricingEngine; exports.UsageRecorder = _chunkSNYBEXLBcjs.UsageRecorder;
|
package/dist/usage.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnicross/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Omnicross LLM serving core 鈥?provider dispatch, completion pipeline, transformers, and the provider proxy.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sayo (https://github.com/Dumoedss)",
|
package/dist/chunk-7FEBOPJO.cjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/transformer/transformers/OpenCodeGoTransformer.ts
|
|
2
|
-
var OpenCodeGoTransformer = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
|
|
3
|
-
static __initStatic() {this.TransformerName = "opencodego"}
|
|
4
|
-
__init() {this.name = "opencodego"}
|
|
5
|
-
__init2() {this.endPoint = "/v1/chat/completions"}
|
|
6
|
-
|
|
7
|
-
async auth(request, _provider, _context) {
|
|
8
|
-
return { body: request, config: { headers: {} } };
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Unified → OpenAI Chat Completions.
|
|
12
|
-
* Unified IS chat completions shape; this is mostly stripping `meta` and
|
|
13
|
-
* normalizing string-content single-block messages.
|
|
14
|
-
*/
|
|
15
|
-
async transformRequestIn(request, _provider, _context) {
|
|
16
|
-
const messages = request.messages.map((m) => {
|
|
17
|
-
const content = m.content;
|
|
18
|
-
const normalizedContent = Array.isArray(content) && content.length === 1 && _optionalChain([content, 'access', _ => _[0], 'optionalAccess', _2 => _2.type]) === "text" ? content[0].text : content;
|
|
19
|
-
const out2 = { role: m.role, content: normalizedContent };
|
|
20
|
-
if (m.tool_calls) out2.tool_calls = m.tool_calls;
|
|
21
|
-
if (m.tool_call_id) out2.tool_call_id = m.tool_call_id;
|
|
22
|
-
return out2;
|
|
23
|
-
});
|
|
24
|
-
const out = {
|
|
25
|
-
model: request.model,
|
|
26
|
-
messages,
|
|
27
|
-
stream: request.stream
|
|
28
|
-
};
|
|
29
|
-
if (request.temperature !== void 0) out.temperature = request.temperature;
|
|
30
|
-
if (request.max_tokens !== void 0) out.max_tokens = request.max_tokens;
|
|
31
|
-
if (request.tools && request.tools.length > 0) out.tools = request.tools;
|
|
32
|
-
if (request.tool_choice !== void 0) out.tool_choice = request.tool_choice;
|
|
33
|
-
if (_optionalChain([request, 'access', _3 => _3.reasoning, 'optionalAccess', _4 => _4.effort]) && request.reasoning.effort !== "none") {
|
|
34
|
-
out.reasoning_effort = request.reasoning.effort;
|
|
35
|
-
}
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* OpenAI Chat Completions response → Unified.
|
|
40
|
-
* The upstream's response shape already matches Unified — pass through.
|
|
41
|
-
* The endpoint AnthropicTransformer re-encodes to Anthropic for the SDK.
|
|
42
|
-
*/
|
|
43
|
-
async transformResponseOut(response, _context) {
|
|
44
|
-
return response;
|
|
45
|
-
}
|
|
46
|
-
}, _class.__initStatic(), _class);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
exports.OpenCodeGoTransformer = OpenCodeGoTransformer;
|
package/dist/chunk-DWKQZ2SK.cjs
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/transformer/transformers/ReasoningTransformer.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _thinkingconfig = require('@omnicross/contracts/thinking-config');
|
|
8
|
-
var ReasoningTransformer = (_class = class {
|
|
9
|
-
static __initStatic() {this.TransformerName = "reasoning"}
|
|
10
|
-
__init() {this.name = "reasoning"}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
constructor(options) {;_class.prototype.__init.call(this);
|
|
14
|
-
this.enabled = _optionalChain([options, 'optionalAccess', _ => _.enable]) !== false;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Transform request: convert reasoning config to thinking parameters
|
|
18
|
-
* Uses model-specific budget calculation based on effort level
|
|
19
|
-
*/
|
|
20
|
-
async transformRequestIn(request, provider, _context) {
|
|
21
|
-
const extendedRequest = request;
|
|
22
|
-
const modelId = request.model;
|
|
23
|
-
if (!this.enabled) {
|
|
24
|
-
extendedRequest.thinking = {
|
|
25
|
-
type: "disabled",
|
|
26
|
-
budget_tokens: -1
|
|
27
|
-
};
|
|
28
|
-
extendedRequest.enable_thinking = false;
|
|
29
|
-
return extendedRequest;
|
|
30
|
-
}
|
|
31
|
-
if (request.reasoning) {
|
|
32
|
-
const effortLevel = request.reasoning.effort || "none";
|
|
33
|
-
const userMaxTokens = request.reasoning.max_tokens || request.max_tokens;
|
|
34
|
-
const calculatedBudget = _thinkingconfig.calculateThinkingBudget.call(void 0, modelId, effortLevel, userMaxTokens);
|
|
35
|
-
const providerName = _optionalChain([provider, 'access', _2 => _2.name, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]) || "";
|
|
36
|
-
if (providerName === "anthropic" || providerName.includes("claude")) {
|
|
37
|
-
const thinkingConfig = _thinkingconfig.buildAnthropicThinking.call(void 0, modelId, effortLevel, userMaxTokens);
|
|
38
|
-
if (thinkingConfig) {
|
|
39
|
-
extendedRequest.thinking = thinkingConfig;
|
|
40
|
-
} else {
|
|
41
|
-
extendedRequest.thinking = {
|
|
42
|
-
type: "disabled"
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
} else if (providerName === "openai" || modelId.match(/^o[134]/i)) {
|
|
46
|
-
const reasoningEffort = _thinkingconfig.getOpenAIReasoningEffort.call(void 0, effortLevel);
|
|
47
|
-
if (reasoningEffort) {
|
|
48
|
-
extendedRequest.reasoning_effort = reasoningEffort;
|
|
49
|
-
}
|
|
50
|
-
extendedRequest.thinking = {
|
|
51
|
-
type: effortLevel === "none" ? "disabled" : "enabled",
|
|
52
|
-
budget_tokens: calculatedBudget
|
|
53
|
-
};
|
|
54
|
-
} else if (providerName === "deepseek" && _optionalChain([modelId, 'optionalAccess', _5 => _5.startsWith, 'call', _6 => _6("deepseek-v4")])) {
|
|
55
|
-
extendedRequest.thinking = {
|
|
56
|
-
type: effortLevel === "none" ? "disabled" : "enabled",
|
|
57
|
-
budget_tokens: calculatedBudget
|
|
58
|
-
};
|
|
59
|
-
if (effortLevel !== "none") {
|
|
60
|
-
extendedRequest.reasoning_effort = effortLevel === "high" ? "max" : "high";
|
|
61
|
-
}
|
|
62
|
-
} else if (providerName === "deepseek" || providerName === "qwen" || providerName === "alibaba") {
|
|
63
|
-
const qwenConfig = _thinkingconfig.buildQwenThinkingConfig.call(void 0, effortLevel, userMaxTokens);
|
|
64
|
-
extendedRequest.enable_thinking = qwenConfig.enable_thinking;
|
|
65
|
-
if (qwenConfig.thinking_budget) {
|
|
66
|
-
extendedRequest.thinking_budget = qwenConfig.thinking_budget;
|
|
67
|
-
}
|
|
68
|
-
extendedRequest.thinking = {
|
|
69
|
-
type: qwenConfig.enable_thinking ? "enabled" : "disabled",
|
|
70
|
-
budget_tokens: calculatedBudget
|
|
71
|
-
};
|
|
72
|
-
} else {
|
|
73
|
-
extendedRequest.thinking = {
|
|
74
|
-
type: effortLevel === "none" ? "disabled" : "enabled",
|
|
75
|
-
budget_tokens: calculatedBudget
|
|
76
|
-
};
|
|
77
|
-
extendedRequest.enable_thinking = effortLevel !== "none";
|
|
78
|
-
}
|
|
79
|
-
_optionalChain([this, 'access', _7 => _7.logger, 'optionalAccess', _8 => _8.debug, 'call', _9 => _9(`[ReasoningTransformer] Model: ${modelId}, Effort: ${effortLevel}, Budget: ${calculatedBudget}`)]);
|
|
80
|
-
}
|
|
81
|
-
return extendedRequest;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Transform response: convert reasoning_content to thinking blocks
|
|
85
|
-
*/
|
|
86
|
-
async transformResponseOut(response, _context) {
|
|
87
|
-
if (!this.enabled) return response;
|
|
88
|
-
const contentType = _nullishCoalesce(response.headers.get("Content-Type"), () => ( ""));
|
|
89
|
-
if (contentType.includes("application/json")) {
|
|
90
|
-
return this.handleJsonResponse(response);
|
|
91
|
-
} else if (contentType.includes("stream") || contentType.includes("text/event-stream")) {
|
|
92
|
-
return this.handleStreamResponse(response);
|
|
93
|
-
}
|
|
94
|
-
return response;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Handle JSON (non-streaming) response
|
|
98
|
-
*/
|
|
99
|
-
async handleJsonResponse(response) {
|
|
100
|
-
const jsonResponse = await response.json();
|
|
101
|
-
if (_optionalChain([jsonResponse, 'access', _10 => _10.choices, 'optionalAccess', _11 => _11[0], 'optionalAccess', _12 => _12.message, 'optionalAccess', _13 => _13.reasoning_content])) {
|
|
102
|
-
jsonResponse.thinking = {
|
|
103
|
-
content: jsonResponse.choices[0].message.reasoning_content
|
|
104
|
-
};
|
|
105
|
-
delete jsonResponse.choices[0].message.reasoning_content;
|
|
106
|
-
}
|
|
107
|
-
return new Response(JSON.stringify(jsonResponse), {
|
|
108
|
-
status: response.status,
|
|
109
|
-
statusText: response.statusText,
|
|
110
|
-
headers: response.headers
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Handle streaming response - convert reasoning_content to thinking blocks
|
|
115
|
-
*/
|
|
116
|
-
handleStreamResponse(response) {
|
|
117
|
-
if (!response.body) {
|
|
118
|
-
return response;
|
|
119
|
-
}
|
|
120
|
-
const decoder = new TextDecoder();
|
|
121
|
-
const encoder = new TextEncoder();
|
|
122
|
-
let reasoningContent = "";
|
|
123
|
-
let isReasoningComplete = false;
|
|
124
|
-
let buffer = "";
|
|
125
|
-
const stream = new ReadableStream({
|
|
126
|
-
start: async (controller) => {
|
|
127
|
-
const reader = response.body.getReader();
|
|
128
|
-
const processLine = (line) => {
|
|
129
|
-
_optionalChain([this, 'access', _14 => _14.logger, 'optionalAccess', _15 => _15.debug, 'call', _16 => _16("Processing reasoning line:", line)]);
|
|
130
|
-
if (line.startsWith("data: ") && line.trim() !== "data: [DONE]") {
|
|
131
|
-
try {
|
|
132
|
-
const data = JSON.parse(line.slice(6));
|
|
133
|
-
if (_optionalChain([data, 'access', _17 => _17.choices, 'optionalAccess', _18 => _18[0], 'optionalAccess', _19 => _19.delta, 'optionalAccess', _20 => _20.reasoning_content])) {
|
|
134
|
-
reasoningContent += data.choices[0].delta.reasoning_content;
|
|
135
|
-
const thinkingChunk = {
|
|
136
|
-
...data,
|
|
137
|
-
choices: [
|
|
138
|
-
{
|
|
139
|
-
...data.choices[0],
|
|
140
|
-
delta: {
|
|
141
|
-
...data.choices[0].delta,
|
|
142
|
-
thinking: {
|
|
143
|
-
content: data.choices[0].delta.reasoning_content
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
};
|
|
149
|
-
delete thinkingChunk.choices[0].delta.reasoning_content;
|
|
150
|
-
const thinkingLine = `data: ${JSON.stringify(thinkingChunk)}
|
|
151
|
-
|
|
152
|
-
`;
|
|
153
|
-
controller.enqueue(encoder.encode(thinkingLine));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if ((_optionalChain([data, 'access', _21 => _21.choices, 'optionalAccess', _22 => _22[0], 'optionalAccess', _23 => _23.delta, 'optionalAccess', _24 => _24.content]) || _optionalChain([data, 'access', _25 => _25.choices, 'optionalAccess', _26 => _26[0], 'optionalAccess', _27 => _27.delta, 'optionalAccess', _28 => _28.tool_calls])) && reasoningContent && !isReasoningComplete) {
|
|
157
|
-
isReasoningComplete = true;
|
|
158
|
-
const signature = Date.now().toString();
|
|
159
|
-
const thinkingChunk = {
|
|
160
|
-
...data,
|
|
161
|
-
choices: [
|
|
162
|
-
{
|
|
163
|
-
...data.choices[0],
|
|
164
|
-
delta: {
|
|
165
|
-
...data.choices[0].delta,
|
|
166
|
-
content: null,
|
|
167
|
-
thinking: {
|
|
168
|
-
signature
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
]
|
|
173
|
-
};
|
|
174
|
-
delete thinkingChunk.choices[0].delta.reasoning_content;
|
|
175
|
-
const thinkingLine = `data: ${JSON.stringify(thinkingChunk)}
|
|
176
|
-
|
|
177
|
-
`;
|
|
178
|
-
controller.enqueue(encoder.encode(thinkingLine));
|
|
179
|
-
}
|
|
180
|
-
if (_optionalChain([data, 'access', _29 => _29.choices, 'optionalAccess', _30 => _30[0], 'optionalAccess', _31 => _31.delta, 'optionalAccess', _32 => _32.reasoning_content])) {
|
|
181
|
-
delete data.choices[0].delta.reasoning_content;
|
|
182
|
-
}
|
|
183
|
-
if (_optionalChain([data, 'access', _33 => _33.choices, 'optionalAccess', _34 => _34[0], 'optionalAccess', _35 => _35.delta]) && Object.keys(data.choices[0].delta).length > 0) {
|
|
184
|
-
if (isReasoningComplete) {
|
|
185
|
-
data.choices[0].index++;
|
|
186
|
-
}
|
|
187
|
-
const modifiedLine = `data: ${JSON.stringify(data)}
|
|
188
|
-
|
|
189
|
-
`;
|
|
190
|
-
controller.enqueue(encoder.encode(modifiedLine));
|
|
191
|
-
}
|
|
192
|
-
} catch (_e) {
|
|
193
|
-
controller.enqueue(encoder.encode(line + "\n"));
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
controller.enqueue(encoder.encode(line + "\n"));
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
try {
|
|
200
|
-
while (true) {
|
|
201
|
-
const { done, value } = await reader.read();
|
|
202
|
-
if (done) {
|
|
203
|
-
if (buffer.trim()) {
|
|
204
|
-
const lines2 = buffer.split("\n");
|
|
205
|
-
for (const line of lines2) {
|
|
206
|
-
if (line.trim()) {
|
|
207
|
-
controller.enqueue(encoder.encode(line + "\n"));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
214
|
-
buffer += chunk;
|
|
215
|
-
const lines = buffer.split("\n");
|
|
216
|
-
buffer = lines.pop() || "";
|
|
217
|
-
for (const line of lines) {
|
|
218
|
-
if (!line.trim()) continue;
|
|
219
|
-
try {
|
|
220
|
-
processLine(line);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
_optionalChain([this, 'access', _36 => _36.logger, 'optionalAccess', _37 => _37.error, 'call', _38 => _38("Error processing reasoning stream line:", error)]);
|
|
223
|
-
controller.enqueue(encoder.encode(line + "\n"));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
} catch (error) {
|
|
228
|
-
_optionalChain([this, 'access', _39 => _39.logger, 'optionalAccess', _40 => _40.error, 'call', _41 => _41("Reasoning stream error:", error)]);
|
|
229
|
-
controller.error(error);
|
|
230
|
-
} finally {
|
|
231
|
-
try {
|
|
232
|
-
reader.releaseLock();
|
|
233
|
-
} catch (e) {
|
|
234
|
-
_optionalChain([this, 'access', _42 => _42.logger, 'optionalAccess', _43 => _43.error, 'call', _44 => _44("Error releasing reader lock:", e)]);
|
|
235
|
-
}
|
|
236
|
-
controller.close();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
return new Response(stream, {
|
|
241
|
-
status: response.status,
|
|
242
|
-
statusText: response.statusText,
|
|
243
|
-
headers: new Headers({
|
|
244
|
-
"Content-Type": "text/event-stream",
|
|
245
|
-
"Cache-Control": "no-cache",
|
|
246
|
-
Connection: "keep-alive"
|
|
247
|
-
})
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
}, _class.__initStatic(), _class);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
exports.ReasoningTransformer = ReasoningTransformer;
|