@wudao-org/providers 0.0.0-stage → 0.4.21
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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/anthropic.d.ts +19 -0
- package/dist/anthropic.d.ts.map +1 -0
- package/dist/anthropic.js +621 -0
- package/dist/anthropic.js.map +1 -0
- package/dist/balance.d.ts +28 -0
- package/dist/balance.d.ts.map +1 -0
- package/dist/balance.js +105 -0
- package/dist/balance.js.map +1 -0
- package/dist/config.d.ts +328 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +623 -0
- package/dist/config.js.map +1 -0
- package/dist/dispatcher.d.ts +5 -0
- package/dist/dispatcher.d.ts.map +1 -0
- package/dist/dispatcher.js +21 -0
- package/dist/dispatcher.js.map +1 -0
- package/dist/effort-catalog.d.ts +17 -0
- package/dist/effort-catalog.d.ts.map +1 -0
- package/dist/effort-catalog.js +73 -0
- package/dist/effort-catalog.js.map +1 -0
- package/dist/error-body.d.ts +32 -0
- package/dist/error-body.d.ts.map +1 -0
- package/dist/error-body.js +74 -0
- package/dist/error-body.js.map +1 -0
- package/dist/header-validation.d.ts +57 -0
- package/dist/header-validation.d.ts.map +1 -0
- package/dist/header-validation.js +130 -0
- package/dist/header-validation.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/json-arguments.d.ts +17 -0
- package/dist/json-arguments.d.ts.map +1 -0
- package/dist/json-arguments.js +227 -0
- package/dist/json-arguments.js.map +1 -0
- package/dist/key-pool.d.ts +66 -0
- package/dist/key-pool.d.ts.map +1 -0
- package/dist/key-pool.js +207 -0
- package/dist/key-pool.js.map +1 -0
- package/dist/missing-reasoning-circuit.d.ts +17 -0
- package/dist/missing-reasoning-circuit.d.ts.map +1 -0
- package/dist/missing-reasoning-circuit.js +38 -0
- package/dist/missing-reasoning-circuit.js.map +1 -0
- package/dist/model-failure.d.ts +156 -0
- package/dist/model-failure.d.ts.map +1 -0
- package/dist/model-failure.js +253 -0
- package/dist/model-failure.js.map +1 -0
- package/dist/model-fallback.d.ts +18 -0
- package/dist/model-fallback.d.ts.map +1 -0
- package/dist/model-fallback.js +87 -0
- package/dist/model-fallback.js.map +1 -0
- package/dist/models.d.ts +20 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +55 -0
- package/dist/models.js.map +1 -0
- package/dist/openai-compatible.d.ts +87 -0
- package/dist/openai-compatible.d.ts.map +1 -0
- package/dist/openai-compatible.js +368 -0
- package/dist/openai-compatible.js.map +1 -0
- package/dist/openai-engine.d.ts +18 -0
- package/dist/openai-engine.d.ts.map +1 -0
- package/dist/openai-engine.js +515 -0
- package/dist/openai-engine.js.map +1 -0
- package/dist/openai-images.d.ts +38 -0
- package/dist/openai-images.d.ts.map +1 -0
- package/dist/openai-images.js +301 -0
- package/dist/openai-images.js.map +1 -0
- package/dist/openai-messages.d.ts +40 -0
- package/dist/openai-messages.d.ts.map +1 -0
- package/dist/openai-messages.js +135 -0
- package/dist/openai-messages.js.map +1 -0
- package/dist/openai-wire.d.ts +93 -0
- package/dist/openai-wire.d.ts.map +1 -0
- package/dist/openai-wire.js +151 -0
- package/dist/openai-wire.js.map +1 -0
- package/dist/persona/apply.d.ts +19 -0
- package/dist/persona/apply.d.ts.map +1 -0
- package/dist/persona/apply.js +98 -0
- package/dist/persona/apply.js.map +1 -0
- package/dist/persona/builtins.d.ts +3 -0
- package/dist/persona/builtins.d.ts.map +1 -0
- package/dist/persona/builtins.js +180 -0
- package/dist/persona/builtins.js.map +1 -0
- package/dist/persona/decorator.d.ts +4 -0
- package/dist/persona/decorator.d.ts.map +1 -0
- package/dist/persona/decorator.js +112 -0
- package/dist/persona/decorator.js.map +1 -0
- package/dist/persona/files.d.ts +20 -0
- package/dist/persona/files.d.ts.map +1 -0
- package/dist/persona/files.js +84 -0
- package/dist/persona/files.js.map +1 -0
- package/dist/persona/ids.d.ts +9 -0
- package/dist/persona/ids.d.ts.map +1 -0
- package/dist/persona/ids.js +11 -0
- package/dist/persona/ids.js.map +1 -0
- package/dist/persona/registry.d.ts +12 -0
- package/dist/persona/registry.d.ts.map +1 -0
- package/dist/persona/registry.js +54 -0
- package/dist/persona/registry.js.map +1 -0
- package/dist/persona/runtime.d.ts +23 -0
- package/dist/persona/runtime.d.ts.map +1 -0
- package/dist/persona/runtime.js +32 -0
- package/dist/persona/runtime.js.map +1 -0
- package/dist/persona/schema.d.ts +27 -0
- package/dist/persona/schema.d.ts.map +1 -0
- package/dist/persona/schema.js +165 -0
- package/dist/persona/schema.js.map +1 -0
- package/dist/persona/types.d.ts +38 -0
- package/dist/persona/types.d.ts.map +1 -0
- package/dist/persona/types.js +2 -0
- package/dist/persona/types.js.map +1 -0
- package/dist/pricing.d.ts +40 -0
- package/dist/pricing.d.ts.map +1 -0
- package/dist/pricing.js +70 -0
- package/dist/pricing.js.map +1 -0
- package/dist/quota-park.d.ts +53 -0
- package/dist/quota-park.d.ts.map +1 -0
- package/dist/quota-park.js +135 -0
- package/dist/quota-park.js.map +1 -0
- package/dist/rate-pause.d.ts +28 -0
- package/dist/rate-pause.d.ts.map +1 -0
- package/dist/rate-pause.js +72 -0
- package/dist/rate-pause.js.map +1 -0
- package/dist/registry.d.ts +142 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +471 -0
- package/dist/registry.js.map +1 -0
- package/dist/responses.d.ts +5 -0
- package/dist/responses.d.ts.map +1 -0
- package/dist/responses.js +290 -0
- package/dist/responses.js.map +1 -0
- package/dist/retry-after.d.ts +13 -0
- package/dist/retry-after.d.ts.map +1 -0
- package/dist/retry-after.js +64 -0
- package/dist/retry-after.js.map +1 -0
- package/dist/retry-ladder.d.ts +176 -0
- package/dist/retry-ladder.d.ts.map +1 -0
- package/dist/retry-ladder.js +664 -0
- package/dist/retry-ladder.js.map +1 -0
- package/dist/split-inband-thinking.d.ts +35 -0
- package/dist/split-inband-thinking.d.ts.map +1 -0
- package/dist/split-inband-thinking.js +117 -0
- package/dist/split-inband-thinking.js.map +1 -0
- package/dist/stream-idle.d.ts +97 -0
- package/dist/stream-idle.d.ts.map +1 -0
- package/dist/stream-idle.js +127 -0
- package/dist/stream-idle.js.map +1 -0
- package/dist/tool-call-ids.d.ts +16 -0
- package/dist/tool-call-ids.d.ts.map +1 -0
- package/dist/tool-call-ids.js +36 -0
- package/dist/tool-call-ids.js.map +1 -0
- package/package.json +32 -3
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type InputModality = "text" | "image";
|
|
2
|
+
/** What one cataloged model accepts as request content. */
|
|
3
|
+
export interface ModelDescriptor {
|
|
4
|
+
readonly inputModalities: readonly InputModality[];
|
|
5
|
+
}
|
|
6
|
+
/** The input modalities one model accepts. Uncataloged → ['text']
|
|
7
|
+
* (fail-closed default; the provider adapter refuses images for it). */
|
|
8
|
+
export declare function modelInputModalities(model: string): readonly InputModality[];
|
|
9
|
+
/** The descriptor lookup for a config: an explicit pin beats the catalog,
|
|
10
|
+
* the catalog beats the text-only default. */
|
|
11
|
+
export declare function resolveInputModalities(config: {
|
|
12
|
+
readonly model: string;
|
|
13
|
+
readonly inputModalities?: readonly InputModality[];
|
|
14
|
+
}): readonly InputModality[];
|
|
15
|
+
/** Convenience for callers that only gate images. */
|
|
16
|
+
export declare function modelAcceptsImages(config: {
|
|
17
|
+
readonly model: string;
|
|
18
|
+
readonly inputModalities?: readonly InputModality[];
|
|
19
|
+
}): boolean;
|
|
20
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAE7C,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,eAAe,EAAE,SAAS,aAAa,EAAE,CAAC;CACpD;AA6BD;yEACyE;AACzE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,aAAa,EAAE,CAM5E;AAED;+CAC+C;AAC/C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAAG,SAAS,aAAa,EAAE,CAKxJ;AAED,qDAAqD;AACrD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,aAAa,EAAE,CAAA;CAAE,GAAG,OAAO,CAEnI"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// M79 §3 — per-model input-modality metadata. Capability is EXACT MODEL
|
|
2
|
+
// METADATA, never a provider-level fact (research 40 §1): an uncataloged
|
|
3
|
+
// model — including every text-only default and any custom endpoint name —
|
|
4
|
+
// resolves to ['text'], so images addressed at it fail closed with
|
|
5
|
+
// UNSUPPORTED_CONTENT before any network call. An explicit ProviderConfig
|
|
6
|
+
// pin (inputModalities) beats the catalog: a custom OpenAI-compatible
|
|
7
|
+
// endpoint fronting a vision model can declare itself precisely.
|
|
8
|
+
const TEXT_ONLY = ["text"];
|
|
9
|
+
const TEXT_AND_IMAGE = ["text", "image"];
|
|
10
|
+
/** Exact-name catalog entries (checked before the family prefixes). */
|
|
11
|
+
const KNOWN_VISION_MODELS = {
|
|
12
|
+
// GLM-4V line (zhipu bigmodel OpenAI-compatible endpoint).
|
|
13
|
+
"glm-4v": TEXT_AND_IMAGE,
|
|
14
|
+
"glm-4v-plus": TEXT_AND_IMAGE,
|
|
15
|
+
"glm-4v-flash": TEXT_AND_IMAGE,
|
|
16
|
+
"glm-4v-plus-0111": TEXT_AND_IMAGE,
|
|
17
|
+
// Qwen-VL line (dashscope compatible-mode).
|
|
18
|
+
"qwen-vl-plus": TEXT_AND_IMAGE,
|
|
19
|
+
"qwen-vl-max": TEXT_AND_IMAGE,
|
|
20
|
+
"qwen-vl-ocr": TEXT_AND_IMAGE,
|
|
21
|
+
};
|
|
22
|
+
/** Versioned family prefixes: `glm-4v…`, `glm-4.1v…`, `glm-4.5v…` and the
|
|
23
|
+
* qwen `vl`/`omni`/`qvq` lines (e.g. `qwen2.5-vl-72b-instruct`,
|
|
24
|
+
* `qwen3-vl-plus`, `qwen2.5-omni-7b`). A prefix that later gains a text-only
|
|
25
|
+
* sibling gets an exact-name entry above, which wins. */
|
|
26
|
+
const VISION_MODEL_PREFIXES = [
|
|
27
|
+
/^glm-[\d.]+v/, // glm-4v / glm-4.1v / glm-4.5v families
|
|
28
|
+
/^qwen[\d.]*-vl/, // qwen-vl / qwen2-vl / qwen2.5-vl / qwen3-vl
|
|
29
|
+
/^qwen[\d.]*-omni/, // omni variants take image input
|
|
30
|
+
/^qvq/, // QVQ vision-reasoning line
|
|
31
|
+
];
|
|
32
|
+
/** The input modalities one model accepts. Uncataloged → ['text']
|
|
33
|
+
* (fail-closed default; the provider adapter refuses images for it). */
|
|
34
|
+
export function modelInputModalities(model) {
|
|
35
|
+
const name = model.trim().toLowerCase();
|
|
36
|
+
const exact = KNOWN_VISION_MODELS[name];
|
|
37
|
+
if (exact !== undefined)
|
|
38
|
+
return exact;
|
|
39
|
+
if (VISION_MODEL_PREFIXES.some((re) => re.test(name)))
|
|
40
|
+
return TEXT_AND_IMAGE;
|
|
41
|
+
return TEXT_ONLY;
|
|
42
|
+
}
|
|
43
|
+
/** The descriptor lookup for a config: an explicit pin beats the catalog,
|
|
44
|
+
* the catalog beats the text-only default. */
|
|
45
|
+
export function resolveInputModalities(config) {
|
|
46
|
+
if (config.inputModalities !== undefined && config.inputModalities.length > 0) {
|
|
47
|
+
return config.inputModalities;
|
|
48
|
+
}
|
|
49
|
+
return modelInputModalities(config.model);
|
|
50
|
+
}
|
|
51
|
+
/** Convenience for callers that only gate images. */
|
|
52
|
+
export function modelAcceptsImages(config) {
|
|
53
|
+
return resolveInputModalities(config).includes("image");
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,yEAAyE;AACzE,2EAA2E;AAC3E,mEAAmE;AACnE,0EAA0E;AAC1E,sEAAsE;AACtE,iEAAiE;AASjE,MAAM,SAAS,GAA6B,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,cAAc,GAA6B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnE,uEAAuE;AACvE,MAAM,mBAAmB,GAAuD;IAC9E,2DAA2D;IAC3D,QAAQ,EAAE,cAAc;IACxB,aAAa,EAAE,cAAc;IAC7B,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,cAAc;IAClC,4CAA4C;IAC5C,cAAc,EAAE,cAAc;IAC9B,aAAa,EAAE,cAAc;IAC7B,aAAa,EAAE,cAAc;CAC9B,CAAC;AAEF;;;0DAG0D;AAC1D,MAAM,qBAAqB,GAAsB;IAC/C,cAAc,EAAE,wCAAwC;IACxD,gBAAgB,EAAE,6CAA6C;IAC/D,kBAAkB,EAAE,iCAAiC;IACrD,MAAM,EAAE,4BAA4B;CACrC,CAAC;AAEF;yEACyE;AACzE,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACxC,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,cAAc,CAAC;IAC7E,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;+CAC+C;AAC/C,MAAM,UAAU,sBAAsB,CAAC,MAAuF;IAC5H,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9E,OAAO,MAAM,CAAC,eAAe,CAAC;IAChC,CAAC;IACD,OAAO,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,kBAAkB,CAAC,MAAuF;IACxH,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { AssistantMessage, ModelClient, ModelInput, TerminalRepairKind } from "@wudao-org/core";
|
|
2
|
+
import type { ProviderConfig } from "./config.js";
|
|
3
|
+
import type { PersonaRuntime } from "./persona/runtime.js";
|
|
4
|
+
import type { KeyPool } from "./key-pool.js";
|
|
5
|
+
import { type RatePauseWindow } from "./rate-pause.js";
|
|
6
|
+
import { type StreamIdleWarningInfo } from "./stream-idle.js";
|
|
7
|
+
import type { AttachmentResolver } from "./openai-images.js";
|
|
8
|
+
import type { RetryLadderOptions, RetryObserver } from "./retry-ladder.js";
|
|
9
|
+
export { OVERLOAD_BODY_SIGNATURES, sniffOverloadBody, ProviderHttpError, ContextLengthError, BackgroundOverloadError, isKeyClassFailure, isModelFallbackEligible, ReasoningMandatoryError, isMandatoryReasoningRejection, MANDATORY_REASONING_BODY_SIGNATURES, } from "./model-failure.js";
|
|
10
|
+
export { withRetry, withRetryStream, isRetryableProviderError, isNetworkClassFailure, backoffDelayMs, defaultMaxRetries, overloadBackoffDelayMs, isOverloadError, CONTEXT_LENGTH_BODY_SIGNATURES, CONTEXT_LIMIT_INPUT_LENGTH_RE, matchContextLimitInputLength, sniffContextLengthBody, isContextLengthFailure, parseContextLimitBody, parseMaxTokensOverflow, selfRepairMaxTokensValue, FOREGROUND_QUERY_SOURCES, isOverloadClassFailure, DEFAULT_NETWORK_GRACE_RETRY_MULTIPLIER, DEFAULT_NETWORK_GRACE_MAX_DELAY_MS, StreamOverflowError, TruncatedStreamError, } from "./retry-ladder.js";
|
|
11
|
+
export type { RetryObserver, RetryLadderOptions } from "./retry-ladder.js";
|
|
12
|
+
export { QUOTA_BODY_SIGNATURES, sniffQuotaBody, parseQuotaResetAt, isQuotaParkFailure, tryQuotaParkError, QuotaParkError, } from "./quota-park.js";
|
|
13
|
+
export { MAX_ACCUM_CHARS, TRUNCATED_MARK, capAccumulated, isCappedReasoning, serializePrompt } from "./openai-messages.js";
|
|
14
|
+
export { TOOL_IMAGE_NOTE, assertImagesSupported } from "./openai-images.js";
|
|
15
|
+
export type { AttachmentResolver } from "./openai-images.js";
|
|
16
|
+
export { parseToolCallArguments } from "./json-arguments.js";
|
|
17
|
+
export interface ProviderOptions {
|
|
18
|
+
readonly fetch?: typeof fetch;
|
|
19
|
+
/** Retry-ladder observability: fires before every retry wait, so the loop /
|
|
20
|
+
* CLI can render e.g. `↻ retry 1 (429) in 0.5s`. */
|
|
21
|
+
readonly onRetry?: RetryObserver;
|
|
22
|
+
/** 121 项 1: capacity observer — fires on every overload-class failure the
|
|
23
|
+
* ladder sees (429/503/529/overload body), merged into the ladder options
|
|
24
|
+
* like onRetry. The CLI routes it to the subagent AIMD gate's onThrottle. */
|
|
25
|
+
readonly onOverload?: () => void;
|
|
26
|
+
/** Ladder overrides (tests/evals inject sleep, maxRetries, ...). */
|
|
27
|
+
readonly retry?: RetryLadderOptions;
|
|
28
|
+
/** M56 §1: the multi-key pool. When absent, one is built from the config
|
|
29
|
+
* (`apiKeys` when set, else the single `apiKey`) — pass one in to observe
|
|
30
|
+
* cooldowns from /status and the statusline (`keys n/m`). */
|
|
31
|
+
readonly keyPool?: KeyPool;
|
|
32
|
+
/** 波次 7 #37 (CodeWhale C1): the provider-level 429 pause window. Built
|
|
33
|
+
* per factory when absent; inject one to share a single window across
|
|
34
|
+
* factories/tests behind one endpoint. */
|
|
35
|
+
readonly ratePauseWindow?: RatePauseWindow;
|
|
36
|
+
/** M58 §B: stream idle watchdog, ms. While a response is streaming, no
|
|
37
|
+
* chunk for this long → abort the fetch and raise StreamIdleError (which
|
|
38
|
+
* walks the existing retry ladder). ω99-315: this is the HARD tier's
|
|
39
|
+
* override (env WUDAO_STREAM_IDLE_MS is its env twin); 0 still disables
|
|
40
|
+
* the whole watchdog (both tiers — the M58 escape hatch). Only armed
|
|
41
|
+
* during active streaming — never during tool execution, permission
|
|
42
|
+
* asks, or user interaction (those happen outside the stream call). */
|
|
43
|
+
readonly streamIdleTimeoutMs?: number;
|
|
44
|
+
/** ω99-315: soft tier, ms (default 90_000; settings key stream.idleSoftMs).
|
|
45
|
+
* A silent gap past it fires onStreamIdleWarning ONCE — never cancels,
|
|
46
|
+
* never issues a model request. 0 disables the warning. */
|
|
47
|
+
readonly streamIdleSoftMs?: number;
|
|
48
|
+
/** ω99-315: hard tier, ms (default 300_000; settings key stream.idleHardMs;
|
|
49
|
+
* legacy streamIdleTimeoutMs / WUDAO_STREAM_IDLE_MS override it). A silent
|
|
50
|
+
* gap past it aborts the download and raises the enriched StreamIdleError.
|
|
51
|
+
* 0 disables the abort. */
|
|
52
|
+
readonly streamIdleHardMs?: number;
|
|
53
|
+
/** ω99-315: the soft tier's warn hook (at most once per silent gap). Pure
|
|
54
|
+
* observation — a warning never cancels the stream and never produces a
|
|
55
|
+
* model request; front-ends may render "still thinking, Ns silent". */
|
|
56
|
+
readonly onStreamIdleWarning?: (info: StreamIdleWarningInfo) => void;
|
|
57
|
+
/** M79 §2: the transient image-resolution seam. A request whose history
|
|
58
|
+
* carries ImageBlocks resolves each surviving ref to a `data:` URL HERE —
|
|
59
|
+
* bytes never enter the session log, and the data URL exists only for
|
|
60
|
+
* this one request build. Without a resolver, any image-bearing input
|
|
61
|
+
* fails closed with UNSUPPORTED_CONTENT (no-attachment-store) before any
|
|
62
|
+
* network call. */
|
|
63
|
+
readonly attachments?: AttachmentResolver;
|
|
64
|
+
/** M79 §2: cumulative base64 budget for one request's images (default
|
|
65
|
+
* 20MiB). Over budget → oldest images offload to fixed text
|
|
66
|
+
* placeholders, deterministically; the omitted bytes are never read. */
|
|
67
|
+
readonly maxRequestImageBytes?: number;
|
|
68
|
+
/** persona 层1/2 的运行时(逐调用读取;undefined = 无 persona,字节不变)。 */
|
|
69
|
+
readonly personaRuntime?: PersonaRuntime;
|
|
70
|
+
/** ω99-42: fires ONCE when the mandatory-reasoning repair is first VERIFIED
|
|
71
|
+
* (a repaired request came back 2xx) — the observable edge of the
|
|
72
|
+
* per-client pre-arm flag (status/diagnostics surfaces wire this; the
|
|
73
|
+
* ladder's onRetry line covers the retry itself). */
|
|
74
|
+
readonly onMandatoryRepairApplied?: () => void;
|
|
75
|
+
}
|
|
76
|
+
export declare function createOpenAICompatibleProvider(config: ProviderConfig, options?: ProviderOptions): ModelClient;
|
|
77
|
+
/** Which repair (if any) a finished assistant message needs. Pure; `input` is
|
|
78
|
+
* the request the message answered (ω-2a: the decision is request-level — a
|
|
79
|
+
* reasoning-less tool turn from a none-effort request is the model's
|
|
80
|
+
* legitimate no-reasoning shape, not a malformed turn). The return widens
|
|
81
|
+
* core's TerminalRepairKind with the providers-local "overflow"
|
|
82
|
+
* classification — it never reaches onTerminalRepair (the audit vocabulary
|
|
83
|
+
* is core's); the caller fail-closes instead of replaying. */
|
|
84
|
+
export declare function terminalRepairKind(msg: AssistantMessage, config: ProviderConfig, input?: Pick<ModelInput, "reasoningEffort">): TerminalRepairKind | "overflow" | undefined;
|
|
85
|
+
export { DEFAULT_STREAM_IDLE_SOFT_MS, DEFAULT_STREAM_IDLE_HARD_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, MAX_STREAM_IDLE_TIMEOUT_MS, defaultStreamIdleTimeoutMs, resolveStreamIdleBudget, StreamIdleError, } from "./stream-idle.js";
|
|
86
|
+
export type { StreamIdleBudget, StreamIdleRuntime, StreamIdleWarningInfo } from "./stream-idle.js";
|
|
87
|
+
//# sourceMappingURL=openai-compatible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-compatible.d.ts","sourceRoot":"","sources":["../src/openai-compatible.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAoB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEvH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAO9E,OAAO,EAAmD,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAS/G,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAM3E,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,EAEvB,uBAAuB,EACvB,6BAA6B,EAC7B,mCAAmC,GACpC,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,SAAS,EACT,eAAe,EACf,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,8BAA8B,EAC9B,6BAA6B,EAC7B,4BAA4B,EAC5B,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,w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AAmB,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACrE;;;;;wBAKoB;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAC1C;;6EAEyE;IACzE,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,2DAA2D;IAC3D,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC;;;0DAGsD;IACtD,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;CAChD;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,eAAoB,GAAG,WAAW,CAiHjH;AAoCD;;;;;;+DAM+D;AAC/D,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,cAAc,EACtB,KAAK,GAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAM,GAC9C,kBAAkB,GAAG,UAAU,GAAG,SAAS,CAsC7C;AAwKD,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC9B,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, probeModelClient } from "@wudao-org/core";
|
|
2
|
+
import { acceptsReasoningOnlyFinish, omitsReasoningOnToolTurns, parseReasoningEffort } from "./config.js";
|
|
3
|
+
// 夜移 023: the session-scoped missing-reasoning circuit (Reasonix warn-state).
|
|
4
|
+
import { createMissingReasoningCircuit } from "./missing-reasoning-circuit.js";
|
|
5
|
+
import { createKeyPool } from "./key-pool.js";
|
|
6
|
+
import { createRatePauseWindow } from "./rate-pause.js";
|
|
7
|
+
// r1a Task 3: the M62 §7 ordered model-fallback chain, extracted from this
|
|
8
|
+
// factory and shared by all three protocol factories.
|
|
9
|
+
import { withModelFallback } from "./model-fallback.js";
|
|
10
|
+
// ω99-315: the dual-tier idle watchdog (soft warn / hard abort) — shared with
|
|
11
|
+
// the anthropic/responses sseDataLines. See stream-idle.ts for the contract.
|
|
12
|
+
import { resolveStreamIdleBudget } from "./stream-idle.js";
|
|
13
|
+
// 拆分运动 C:域文件外提后本模块保留工厂 + 终局修复 seam;下面逐名 import
|
|
14
|
+
// 域件、再逐名 re-export 保公共面(anthropic/responses/tests/index 零演进)。
|
|
15
|
+
import { isCappedReasoning } from "./openai-messages.js";
|
|
16
|
+
import { createMandatoryReasoningCall, effectiveReasoningEffort } from "./openai-wire.js";
|
|
17
|
+
import { generateOnceWithSelfRepair, streamOnce } from "./openai-engine.js";
|
|
18
|
+
import { isMaxTokensOverflow400, parseMaxTokensOverflow, selfRepairMaxTokensValue, withRetry, withRetryStream } from "./retry-ladder.js";
|
|
19
|
+
// r1b A1: the typed failure classes + the model-failure predicates now live in
|
|
20
|
+
// model-failure.ts (breaking the openai-compatible ↔ model-fallback import
|
|
21
|
+
// cycle). Re-exported 1:1 below — every existing importer (anthropic/responses/
|
|
22
|
+
// tests/index) is unchanged, and the class definitions stay unique so every
|
|
23
|
+
// instanceof keeps its exact semantics.
|
|
24
|
+
export { OVERLOAD_BODY_SIGNATURES, sniffOverloadBody, ProviderHttpError, ContextLengthError, BackgroundOverloadError, isKeyClassFailure, isModelFallbackEligible,
|
|
25
|
+
// ω99-42: the typed mandatory-reasoning rejection (hermes f6bd1633f7).
|
|
26
|
+
ReasoningMandatoryError, isMandatoryReasoningRejection, MANDATORY_REASONING_BODY_SIGNATURES, } from "./model-failure.js";
|
|
27
|
+
// 拆分运动 C 门面:外提域件的公共面 1:1 re-export(类型走 export type——
|
|
28
|
+
// isolatedModules)。
|
|
29
|
+
export { withRetry, withRetryStream, isRetryableProviderError, isNetworkClassFailure, backoffDelayMs, defaultMaxRetries, overloadBackoffDelayMs, isOverloadError, CONTEXT_LENGTH_BODY_SIGNATURES, CONTEXT_LIMIT_INPUT_LENGTH_RE, matchContextLimitInputLength, sniffContextLengthBody, isContextLengthFailure, parseContextLimitBody, parseMaxTokensOverflow, selfRepairMaxTokensValue, FOREGROUND_QUERY_SOURCES, isOverloadClassFailure, DEFAULT_NETWORK_GRACE_RETRY_MULTIPLIER, DEFAULT_NETWORK_GRACE_MAX_DELAY_MS, StreamOverflowError, TruncatedStreamError, } from "./retry-ladder.js";
|
|
30
|
+
// 113-B3 — the account-quota park domain (identification + the typed error).
|
|
31
|
+
export { QUOTA_BODY_SIGNATURES, sniffQuotaBody, parseQuotaResetAt, isQuotaParkFailure, tryQuotaParkError, QuotaParkError, } from "./quota-park.js";
|
|
32
|
+
export { MAX_ACCUM_CHARS, TRUNCATED_MARK, capAccumulated, isCappedReasoning, serializePrompt } from "./openai-messages.js";
|
|
33
|
+
export { TOOL_IMAGE_NOTE, assertImagesSupported } from "./openai-images.js";
|
|
34
|
+
export { parseToolCallArguments } from "./json-arguments.js";
|
|
35
|
+
export function createOpenAICompatibleProvider(config, options = {}) {
|
|
36
|
+
const doFetch = options.fetch ?? fetch;
|
|
37
|
+
const retry = {
|
|
38
|
+
...options.retry,
|
|
39
|
+
...(options.onRetry !== undefined ? { onRetry: options.onRetry } : {}),
|
|
40
|
+
// 121 项 1: the capacity observer rides the same options fragment.
|
|
41
|
+
...(options.onOverload !== undefined ? { onOverload: options.onOverload } : {}),
|
|
42
|
+
};
|
|
43
|
+
// M56 §1: key selection is per REQUEST (each HTTP attempt), round-robin
|
|
44
|
+
// with per-key cooldown. The key rides only the Authorization header — the
|
|
45
|
+
// body bytes (and the prefix cache) never see it.
|
|
46
|
+
const keyPool = options.keyPool ?? createKeyPool(config.apiKeys ?? [config.apiKey]);
|
|
47
|
+
// 波次 7 #37 (CodeWhale C1): the provider-level 429 pause window — one per
|
|
48
|
+
// factory closure, shared across every leg and every concurrent request of
|
|
49
|
+
// this provider instance (keyPool topology). The pool answers "rotate to a
|
|
50
|
+
// spare key"; the window answers "the provider itself said stop" (single
|
|
51
|
+
// key, or every key cooling): LATER request entries wait it out in 250ms
|
|
52
|
+
// slices, the originator's own ladder retries stay ungated (a transient 429
|
|
53
|
+
// keeps today's fast-recovery behavior), and any 2xx clears it.
|
|
54
|
+
const ratePause = options.ratePauseWindow ?? createRatePauseWindow();
|
|
55
|
+
// M58 §B / ω99-315: the dual-tier budget, resolved once at construction
|
|
56
|
+
// (option → legacy option/env → default) and clamped to the setTimeout
|
|
57
|
+
// limit (a wrap-beyond-2^31-1 value would fire instantly).
|
|
58
|
+
const streamIdle = {
|
|
59
|
+
...resolveStreamIdleBudget({
|
|
60
|
+
softMs: options.streamIdleSoftMs,
|
|
61
|
+
hardMs: options.streamIdleHardMs,
|
|
62
|
+
legacyTimeoutMs: options.streamIdleTimeoutMs,
|
|
63
|
+
}),
|
|
64
|
+
...(options.onStreamIdleWarning !== undefined ? { onSoftWarning: options.onStreamIdleWarning } : {}),
|
|
65
|
+
};
|
|
66
|
+
// M79 §2: the image request context — the transient data-URL resolver and
|
|
67
|
+
// the cumulative base64 budget. Absent resolver = image inputs fail closed
|
|
68
|
+
// (no silent drop, no provider-level capability guessing).
|
|
69
|
+
const imageCtx = {
|
|
70
|
+
budgetBytes: options.maxRequestImageBytes ?? DEFAULT_MAX_REQUEST_IMAGE_BYTES,
|
|
71
|
+
...(options.attachments !== undefined ? { resolver: options.attachments } : {}),
|
|
72
|
+
};
|
|
73
|
+
// ω99-42: the per-client mandatory-reasoning flag — in-process, endpoint-
|
|
74
|
+
// scoped, armed only by a VERIFIED repair (see the ω99-42 block comment in
|
|
75
|
+
// openai-wire.ts, where the runtime now lives).
|
|
76
|
+
const mandatoryFlag = {
|
|
77
|
+
applied: false,
|
|
78
|
+
...(options.onMandatoryRepairApplied !== undefined ? { onApplied: options.onMandatoryRepairApplied } : {}),
|
|
79
|
+
};
|
|
80
|
+
// M62 §7 — the ordered model-fallback chain now lives in withModelFallback
|
|
81
|
+
// (r1a Task 3 extraction; shared by all three protocol factories). This
|
|
82
|
+
// factory provides ONE leg: a single model's generate/stream with the
|
|
83
|
+
// shared retry ladder INSIDE (the chain swaps the model after a leg's
|
|
84
|
+
// ladder gave up — model failure ≠ credential failure; the M56 key pool
|
|
85
|
+
// stays orthogonal, rotating keys INSIDE one model).
|
|
86
|
+
const legClient = (cfg) => {
|
|
87
|
+
// 夜移 023: one circuit per leg (≈ Reasonix's per-config fingerprint,
|
|
88
|
+
// session-scoped) — a missing-reasoning regression on the primary model
|
|
89
|
+
// does not suppress the fallback leg's retries.
|
|
90
|
+
const circuit = createMissingReasoningCircuit();
|
|
91
|
+
return {
|
|
92
|
+
// M70 §2: the leg's model identity (the decorator keeps the chain's
|
|
93
|
+
// PRIMARY identity on the returned client).
|
|
94
|
+
modelId: cfg.model,
|
|
95
|
+
// The retry ladder (M26 P11) wraps BOTH paths: transient transport and
|
|
96
|
+
// listed-status failures are retried with exponential backoff; aborts and
|
|
97
|
+
// argument errors surface immediately. The M48 §2 terminal-shape repair
|
|
98
|
+
// rides INSIDE one ladder attempt: a successful-but-degenerate response
|
|
99
|
+
// (not an error) gets one frozen byte-identical replay.
|
|
100
|
+
async generate(input) {
|
|
101
|
+
// 波次 7 #37: the leg entry gate — a concurrent request defers here
|
|
102
|
+
// while the provider is rate-paused (abort-aware); the ladder retries
|
|
103
|
+
// INSIDE one leg call stay ungated (transient-blip recovery unchanged).
|
|
104
|
+
// M70 §3: the call's QuerySource rides the ladder options (a
|
|
105
|
+
// background source never retries an overload).
|
|
106
|
+
await ratePause.wait(input.signal);
|
|
107
|
+
// ω99-42: one repair runtime per public call — it survives every ladder
|
|
108
|
+
// attempt of THIS call (the repair retry re-enters with the body armed).
|
|
109
|
+
const mr = createMandatoryReasoningCall(mandatoryFlag, cfg);
|
|
110
|
+
return withRetry(() => generateWithRepair(cfg, input, doFetch, keyPool, ratePause, imageCtx, options.personaRuntime, circuit, mr), { ...retry, querySource: input.querySource });
|
|
111
|
+
},
|
|
112
|
+
async *stream(input) {
|
|
113
|
+
// 波次 7 #37: same entry gate as generate (before the first delta).
|
|
114
|
+
await ratePause.wait(input.signal);
|
|
115
|
+
// ω99-42: same per-call repair runtime as generate (see there).
|
|
116
|
+
const mr = createMandatoryReasoningCall(mandatoryFlag, cfg);
|
|
117
|
+
// SSE streaming: posts the same request with stream:true and parses
|
|
118
|
+
// Server-Sent Events. reasoning_content and text deltas are yielded
|
|
119
|
+
// live; tool_call fragments are accumulated across deltas and emitted
|
|
120
|
+
// in the final "done" message. Retries only BEFORE the first delta — a
|
|
121
|
+
// break after output has started is thrown to the loop (never
|
|
122
|
+
// replayed) so no output is duplicated. The M48 §2 repair applies at
|
|
123
|
+
// the done seam; the done message is always the last attempt's.
|
|
124
|
+
// M70 §3: the call's QuerySource rides the ladder options (see generate).
|
|
125
|
+
yield* withRetryStream(() => streamWithRepair(cfg, input, doFetch, keyPool, ratePause, streamIdle, imageCtx, options.personaRuntime, circuit, mr), { ...retry, querySource: input.querySource });
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const chained = withModelFallback(legClient, config);
|
|
130
|
+
// PB-1 探针缝(模型面):工厂返回处装饰 ModelClient 记 model.call 探针
|
|
131
|
+
//(探针关 WUDAO_PROBE≠on = 原对象原引用返回,provider 本体零改动)。
|
|
132
|
+
return probeModelClient({
|
|
133
|
+
// M70 §2: the client's primary model identity (the loop's usage-anchor
|
|
134
|
+
// guards compare it against the answering model on each usage row).
|
|
135
|
+
modelId: config.model,
|
|
136
|
+
async generate(input) {
|
|
137
|
+
// M58 §C: validate a per-input reasoning effort ONCE, at the public
|
|
138
|
+
// boundary — fail-fast OUTSIDE the ladder AND the fallback chain (junk
|
|
139
|
+
// can never succeed on a sibling model either).
|
|
140
|
+
return chained.generate(validatedInputEffort(input));
|
|
141
|
+
},
|
|
142
|
+
async *stream(input) {
|
|
143
|
+
yield* chained.stream(validatedInputEffort(input));
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** M58 §C: validate a per-input reasoning effort ONCE, before the retry
|
|
148
|
+
* ladder — the fail-fast parse error must never walk the ladder (junk can
|
|
149
|
+
* never succeed on retry). The PARSED value rides the returned input, so
|
|
150
|
+
* toOpenAIRequest never re-parses. Absent/empty = the input unchanged (the
|
|
151
|
+
* config's own effort applies). */
|
|
152
|
+
function validatedInputEffort(input) {
|
|
153
|
+
if (input.reasoningEffort === undefined || input.reasoningEffort === "")
|
|
154
|
+
return input;
|
|
155
|
+
return { ...input, reasoningEffort: parseReasoningEffort(input.reasoningEffort) };
|
|
156
|
+
}
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// M48 §2 — terminal-shape repair (Reasonix pair). Two degenerate finishes:
|
|
159
|
+
// reasoning-only reasoning present, content and tool_calls empty — the
|
|
160
|
+
// endpoint thought inside its reasoning budget and never
|
|
161
|
+
// produced an answer. On providers that accept the shape
|
|
162
|
+
// (acceptsReasoningOnlyFinish: deepseek/zai profiles)
|
|
163
|
+
// the finish does NOT end the call.
|
|
164
|
+
// missing-reasoning a tool-call turn carrying no reasoning while the replay
|
|
165
|
+
// contract is ON — the turn the contract expects to
|
|
166
|
+
// replay later is malformed on arrival. ω-2a: gated on
|
|
167
|
+
// the request's effective effort (none = legitimate
|
|
168
|
+
// no-reasoning shape, no replay) and never fired for a
|
|
169
|
+
// client-capped tail (that classifies overflow instead).
|
|
170
|
+
// overflow (ω-2a) a reasoning tail the CLIENT truncated at the 2M-char
|
|
171
|
+
// accumulator cap — incomplete, so it is never
|
|
172
|
+
// freeze-replayed and never replayed as complete on the
|
|
173
|
+
// wire; the message settles as-is with the marker
|
|
174
|
+
// in-band (the most conservative branch of this idiom).
|
|
175
|
+
// Repair = ONE frozen replay: the same config + same input serialize to the
|
|
176
|
+
// same body bytes, resent once, audited through ModelInput.onTerminalRepair
|
|
177
|
+
// BEFORE the resend. A second degenerate finish settles as-is (the response
|
|
178
|
+
// is returned untouched — the loop's stop semantics decide what happens).
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
/** Which repair (if any) a finished assistant message needs. Pure; `input` is
|
|
181
|
+
* the request the message answered (ω-2a: the decision is request-level — a
|
|
182
|
+
* reasoning-less tool turn from a none-effort request is the model's
|
|
183
|
+
* legitimate no-reasoning shape, not a malformed turn). The return widens
|
|
184
|
+
* core's TerminalRepairKind with the providers-local "overflow"
|
|
185
|
+
* classification — it never reaches onTerminalRepair (the audit vocabulary
|
|
186
|
+
* is core's); the caller fail-closes instead of replaying. */
|
|
187
|
+
export function terminalRepairKind(msg, config, input = {}) {
|
|
188
|
+
const hasToolCalls = (msg.toolCalls?.length ?? 0) > 0;
|
|
189
|
+
const capped = isCappedReasoning(msg.reasoning);
|
|
190
|
+
// ω-2a: overflow ≠ missing — a client-capped tail is incomplete, so it is
|
|
191
|
+
// never a healthy replayable tail (Reasonix reasoning_replay.go:61-69).
|
|
192
|
+
if (capped && (config.reasoningReplay === "always" || (config.reasoningReplay === "toolCallTurns" && hasToolCalls))) {
|
|
193
|
+
return "overflow";
|
|
194
|
+
}
|
|
195
|
+
if (!hasToolCalls
|
|
196
|
+
// A capped tail is not the "thought inside its budget" shape — an
|
|
197
|
+
// incomplete tail is never freeze-replayed (ω-2a).
|
|
198
|
+
&& !capped
|
|
199
|
+
&& msg.content === ""
|
|
200
|
+
&& msg.reasoning !== undefined
|
|
201
|
+
&& msg.reasoning !== ""
|
|
202
|
+
&& acceptsReasoningOnlyFinish(config)) {
|
|
203
|
+
return "reasoning-only";
|
|
204
|
+
}
|
|
205
|
+
if (hasToolCalls
|
|
206
|
+
&& msg.reasoning === undefined
|
|
207
|
+
&& (config.reasoningReplay === "toolCallTurns" || config.reasoningReplay === "always")
|
|
208
|
+
// Reasonix 4de837d9a: the replay requirement is effort-aware — reasoning
|
|
209
|
+
// explicitly disabled means a reasoning-less tool turn takes the
|
|
210
|
+
// empty-reasoning fallback (continue, no replay) instead of a wasted
|
|
211
|
+
// frozen re-request on every tool turn.
|
|
212
|
+
&& effectiveReasoningEffort(input, config) !== "none"
|
|
213
|
+
// 夜移 022 (Reasonix reasoning_replay_policy.go): some endpoints (zhipu)
|
|
214
|
+
// legitimately omit reasoning on VALID thinking-enabled tool turns — a
|
|
215
|
+
// provider fact, independent of the effort gate above. Replaying would
|
|
216
|
+
// resend the same request for the same shape on every tool turn.
|
|
217
|
+
&& !omitsReasoningOnToolTurns(config)) {
|
|
218
|
+
return "missing-reasoning";
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
/** 夜移 023: a healthy tool-call turn under the replay contract — the shape
|
|
223
|
+
* whose three-consecutive streak re-arms the missing-reasoning circuit.
|
|
224
|
+
* Same envelope as the missing-reasoning branch above (contract on, effort
|
|
225
|
+
* ≠ none, no provider-legitimate omission), with reasoning PRESENT, non-empty
|
|
226
|
+
* and not client-capped. Plain answers, effort=none turns and omits-flag
|
|
227
|
+
* endpoints never count — the contract was not in force for them. */
|
|
228
|
+
function healthyToolTurnUnderContract(msg, config, input) {
|
|
229
|
+
return (msg.toolCalls?.length ?? 0) > 0
|
|
230
|
+
&& msg.reasoning !== undefined
|
|
231
|
+
&& msg.reasoning !== ""
|
|
232
|
+
&& !isCappedReasoning(msg.reasoning)
|
|
233
|
+
&& (config.reasoningReplay === "toolCallTurns" || config.reasoningReplay === "always")
|
|
234
|
+
&& effectiveReasoningEffort(input, config) !== "none"
|
|
235
|
+
&& !omitsReasoningOnToolTurns(config);
|
|
236
|
+
}
|
|
237
|
+
/** One attempt + at most one frozen replay (non-streaming). M70 §4: the
|
|
238
|
+
* max_tokens self-repair wraps each attempt (a parseable overflow 400 retries
|
|
239
|
+
* once with the reduced cap — see generateOnceWithSelfRepair). */
|
|
240
|
+
async function generateWithRepair(config, input, doFetch, keyPool, ratePause, imageCtx, persona, circuit, mr) {
|
|
241
|
+
// M70 §4: the shared retry context — at most one self-repair per call.
|
|
242
|
+
const retryContext = {};
|
|
243
|
+
const first = await generateOnceWithSelfRepair(config, input, doFetch, keyPool, ratePause, imageCtx, retryContext, persona, mr);
|
|
244
|
+
const kind = terminalRepairKind(first, config, input);
|
|
245
|
+
// ω-2a: overflow settles as-is (the idiom's most conservative branch — same
|
|
246
|
+
// as a second degenerate finish): no frozen replay of an incomplete tail,
|
|
247
|
+
// the marker stays in-band, and the wire replay refuses the tail later.
|
|
248
|
+
// 夜移 023: a clean healthy tool turn under the replay contract is the one
|
|
249
|
+
// observation a no-repair settle makes (feeds the re-arm streak; a no-op
|
|
250
|
+
// while the circuit is closed).
|
|
251
|
+
if (kind === undefined || kind === "overflow") {
|
|
252
|
+
if (kind === undefined && healthyToolTurnUnderContract(first, config, input))
|
|
253
|
+
circuit.noteHealthyToolTurn();
|
|
254
|
+
return first;
|
|
255
|
+
}
|
|
256
|
+
// 夜移 023: the circuit-open settle — a sustained regression settles as-is
|
|
257
|
+
// WITHOUT the frozen replay (one request per turn, not two); the observed
|
|
258
|
+
// regression resets the re-arm streak (an intermittent regression must not
|
|
259
|
+
// re-arm on a sparse streak).
|
|
260
|
+
if (kind === "missing-reasoning" && !circuit.allowsRetry()) {
|
|
261
|
+
circuit.noteSuppressedMissing();
|
|
262
|
+
return first;
|
|
263
|
+
}
|
|
264
|
+
input.onTerminalRepair?.(kind);
|
|
265
|
+
// Frozen replay: same input and the config the SUCCESSFUL leg ran under —
|
|
266
|
+
// review F2: when that leg was self-repaired, the override is part of its
|
|
267
|
+
// bytes, so the replay re-applies it (byte-identical; a recurring 400 on
|
|
268
|
+
// the original cap could not re-repair — the repair is single-shot).
|
|
269
|
+
const replayConfig = retryContext.maxTokensOverride !== undefined
|
|
270
|
+
? { ...config, maxTokens: retryContext.maxTokensOverride }
|
|
271
|
+
: config;
|
|
272
|
+
const settled = await generateOnceWithSelfRepair(replayConfig, input, doFetch, keyPool, ratePause, imageCtx, retryContext, persona, mr);
|
|
273
|
+
// 夜移 023: the replay's own finish decides the window — a replay that ALSO
|
|
274
|
+
// comes back reasoning-less OPENS the circuit (remediation proven useless
|
|
275
|
+
// for this regression); a healthy recovery keeps full protection (the
|
|
276
|
+
// recorded divergence from Reasonix — wudao has no history projection to
|
|
277
|
+
// fall back on, so a working replay is never suppressed).
|
|
278
|
+
if (kind === "missing-reasoning" && terminalRepairKind(settled, config, input) === "missing-reasoning") {
|
|
279
|
+
circuit.noteFailedReplay();
|
|
280
|
+
}
|
|
281
|
+
else if (healthyToolTurnUnderContract(settled, config, input)) {
|
|
282
|
+
circuit.noteHealthyToolTurn();
|
|
283
|
+
}
|
|
284
|
+
return settled;
|
|
285
|
+
}
|
|
286
|
+
/** One attempt + at most one frozen replay (streaming). The first attempt's
|
|
287
|
+
* deltas are already downstream; the replay's events follow them, and its
|
|
288
|
+
* done message is authoritative. */
|
|
289
|
+
async function* streamWithRepair(config, input, doFetch, keyPool, ratePause, streamIdle, imageCtx, persona, circuit, mr) {
|
|
290
|
+
// M70 §4: the shared retry context — at most one self-repair per call. A
|
|
291
|
+
// parseable overflow 400 fails BEFORE any event is yielded (the fetch never
|
|
292
|
+
// streams), so the repaired attempt restarts cleanly.
|
|
293
|
+
const retryContext = {};
|
|
294
|
+
const onceWithSelfRepair = async function* (cfg) {
|
|
295
|
+
try {
|
|
296
|
+
yield* streamOnce(cfg, input, doFetch, keyPool, ratePause, streamIdle, imageCtx, persona, mr);
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
if (!isMaxTokensOverflow400(err) || retryContext.maxTokensOverride !== undefined)
|
|
300
|
+
throw err;
|
|
301
|
+
retryContext.maxTokensOverride = selfRepairMaxTokensValue(parseMaxTokensOverflow(err.body));
|
|
302
|
+
yield* streamOnce({ ...cfg, maxTokens: retryContext.maxTokensOverride }, input, doFetch, keyPool, ratePause, streamIdle, imageCtx, persona, mr);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
let done;
|
|
306
|
+
for await (const ev of onceWithSelfRepair(config)) {
|
|
307
|
+
if (ev.type === "done")
|
|
308
|
+
done = ev.message;
|
|
309
|
+
else
|
|
310
|
+
yield ev;
|
|
311
|
+
}
|
|
312
|
+
if (done === undefined)
|
|
313
|
+
return;
|
|
314
|
+
const kind = terminalRepairKind(done, config, input);
|
|
315
|
+
// ω-2a: overflow settles as-is — the streamed deltas and the marker stay,
|
|
316
|
+
// and the incomplete tail is never re-sent (see generateWithRepair).
|
|
317
|
+
// 夜移 023: same seam as the non-streaming lane — a healthy tool turn
|
|
318
|
+
// feeds the re-arm streak; an open circuit suppresses the missing-reasoning
|
|
319
|
+
// replay (the first attempt's done is authoritative, one request).
|
|
320
|
+
if (kind === undefined || kind === "overflow") {
|
|
321
|
+
if (kind === undefined && healthyToolTurnUnderContract(done, config, input))
|
|
322
|
+
circuit.noteHealthyToolTurn();
|
|
323
|
+
yield { type: "done", message: done };
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (kind === "missing-reasoning" && !circuit.allowsRetry()) {
|
|
327
|
+
circuit.noteSuppressedMissing();
|
|
328
|
+
yield { type: "done", message: done };
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
input.onTerminalRepair?.(kind);
|
|
332
|
+
// Frozen replay: the second attempt's events (deltas + its done message)
|
|
333
|
+
// stream after the first attempt's — the last done is authoritative.
|
|
334
|
+
// Review F2: re-apply the self-repair override when the successful leg ran
|
|
335
|
+
// under it (byte-identical to that leg; see generateWithRepair).
|
|
336
|
+
// 夜移 023: the replay's own finish decides the circuit window (see
|
|
337
|
+
// generateWithRepair) — every event still streams through in order.
|
|
338
|
+
let replayDone;
|
|
339
|
+
for await (const ev of onceWithSelfRepair(retryContext.maxTokensOverride !== undefined ? { ...config, maxTokens: retryContext.maxTokensOverride } : config)) {
|
|
340
|
+
if (ev.type === "done")
|
|
341
|
+
replayDone = ev.message;
|
|
342
|
+
yield ev;
|
|
343
|
+
}
|
|
344
|
+
if (replayDone !== undefined) {
|
|
345
|
+
if (kind === "missing-reasoning" && terminalRepairKind(replayDone, config, input) === "missing-reasoning") {
|
|
346
|
+
circuit.noteFailedReplay();
|
|
347
|
+
}
|
|
348
|
+
else if (healthyToolTurnUnderContract(replayDone, config, input)) {
|
|
349
|
+
circuit.noteHealthyToolTurn();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// ---------------------------------------------------------------------------
|
|
354
|
+
// M58 §B — the stream idle watchdog. A model stream that goes silent (proxy
|
|
355
|
+
// dropped the connection, endpoint hung mid-generation) used to hang the run
|
|
356
|
+
// forever. While a response is streaming, no chunk for the hard budget aborts
|
|
357
|
+
// the fetch and raises the typed StreamIdleError, which walks the EXISTING
|
|
358
|
+
// retry ladder. The retried request re-serializes the same ModelInput →
|
|
359
|
+
// byte-identical body, so the model/prefix cache never sees a difference. The
|
|
360
|
+
// timers reset on every chunk and are armed only during active streaming —
|
|
361
|
+
// tool execution, permission asks, and user interaction happen OUTSIDE the
|
|
362
|
+
// stream call and are never timed.
|
|
363
|
+
// ω99-315: the single 45s tier became DUAL (soft warn 90s / hard abort 300s);
|
|
364
|
+
// the constants, the typed error, and the shared guard live in stream-idle.ts
|
|
365
|
+
// (this module re-exports the legacy surface below).
|
|
366
|
+
// ---------------------------------------------------------------------------
|
|
367
|
+
export { DEFAULT_STREAM_IDLE_SOFT_MS, DEFAULT_STREAM_IDLE_HARD_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, MAX_STREAM_IDLE_TIMEOUT_MS, defaultStreamIdleTimeoutMs, resolveStreamIdleBudget, StreamIdleError, } from "./stream-idle.js";
|
|
368
|
+
//# sourceMappingURL=openai-compatible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-compatible.js","sourceRoot":"","sources":["../src/openai-compatible.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,EAAE,0BAA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,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;YACnE,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,wEAAwE;AACxE,8EAA8E;AAC9E,2EAA2E;AAC3E,2EAA2E;AAC3E,mCAAmC;AACnC,8EAA8E;AAC9E,8EAA8E;AAC9E,qDAAqD;AACrD,8EAA8E;AAE9E,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC9B,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AssistantMessage, ModelInput, ModelStreamEvent } from "@wudao-org/core";
|
|
2
|
+
import type { ProviderConfig } from "./config.js";
|
|
3
|
+
import type { PersonaRuntime } from "./persona/runtime.js";
|
|
4
|
+
import type { KeyPool } from "./key-pool.js";
|
|
5
|
+
import { type RatePauseWindow } from "./rate-pause.js";
|
|
6
|
+
import { type StreamIdleRuntime } from "./stream-idle.js";
|
|
7
|
+
import { type MandatoryReasoningCall } from "./openai-wire.js";
|
|
8
|
+
import type { ImageRequestContext } from "./openai-images.js";
|
|
9
|
+
/** One streaming attempt — the generator the retry ladder calls. */
|
|
10
|
+
export declare function streamOnce(config: ProviderConfig, input: ModelInput, doFetch: typeof fetch, keyPool: KeyPool, ratePause: RatePauseWindow, streamIdle: StreamIdleRuntime, imageCtx: ImageRequestContext, persona: PersonaRuntime | undefined, mr: MandatoryReasoningCall): AsyncGenerator<ModelStreamEvent>;
|
|
11
|
+
/** One attempt + at most one max_tokens self-repair retry (non-streaming).
|
|
12
|
+
* The retryContext records the applied override (single-shot by its
|
|
13
|
+
* presence). Pure plumbing: the attempt receives the (possibly capped)
|
|
14
|
+
* config. */
|
|
15
|
+
export declare function generateOnceWithSelfRepair(config: ProviderConfig, input: ModelInput, doFetch: typeof fetch, keyPool: KeyPool, ratePause: RatePauseWindow, imageCtx: ImageRequestContext, retryContext: {
|
|
16
|
+
maxTokensOverride?: number;
|
|
17
|
+
}, persona: PersonaRuntime | undefined, mr: MandatoryReasoningCall): Promise<AssistantMessage>;
|
|
18
|
+
//# sourceMappingURL=openai-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-engine.d.ts","sourceRoot":"","sources":["../src/openai-engine.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAwB,MAAM,iBAAiB,CAAC;AAE5G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAQlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AASjF,OAAO,EAQL,KAAK,sBAAsB,EAE5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAwJ9D,oEAAoE;AACpE,wBAAuB,UAAU,CAC/B,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,KAAK,EACrB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,eAAe,EAC1B,UAAU,EAAE,iBAAiB,EAC7B,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,EAAE,EAAE,sBAAsB,GACzB,cAAc,CAAC,gBAAgB,CAAC,CAuTlC;AAuCD;;;aAGa;AACb,wBAAsB,0BAA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