mirror of
https://github.com/YMengCC/YMeng-CC-New-API.git
synced 2026-11-30 04:37:45 +08:00
* feat(plugins): serve task plugins at the vendors' own paths
A vendor SDK or plain HTTP client can now point at the gateway and keep the
vendor's official paths. Every plugin route is also served under
/{plugin key}, and that address always runs that plugin.
- Plugins declare the vendor's official paths and the gateway adds the
/{key} copy. Existing prefixed addresses keep working, including /ali
for Alibaba Bailian.
- Several plugins may declare the same path. A submit runs on the plugin
whose channel is selected; a query is answered by the plugin that owns
the task.
- Under the gateway's own path segments (/api, /v1, /v1beta and so on)
only built-in plugins get top-level paths; other plugins are served at
their /{key} address. Plugin keys cannot reuse these segments.
- Jimeng uses the official Bearer API (/api/common/v3/submit_task_v2 and
get_result_v2). The /jimeng/ route, which requests could not reach, is
removed.
- MiniMax supports the official v1 query with ?task_id= and
/v1/files/retrieve. The unimplemented GET /v1/files/{id} placeholder is
removed. Vertex AI also accepts v1beta1 paths.
- Vidu routes accept Authorization: Token, and Google routes accept
x-goog-api-key and ?key=. The key is redacted from logs.
- Gemini Veo results are read from generatedSamples, so their videos
download again. Vertex AI videos returned inline are fetched again when
downloaded.
- GET /v1/videos/{id} answers tasks created on xAI's routes in xAI's
format, and :predictLongRunning requests reach the Veo plugin.
- Enabling, activating or promoting a plugin version is refused when it
conflicts with another plugin, and force no longer skips that check.
- The plugin page lists each endpoint once, with a switch between the
vendor path and the /{key} address. Legacy addresses are folded away.
* fix(logging): use the shared query credential masking for key=
The access log already masks credentials passed in the query string,
key included. A second redaction for the Gemini ?key= form rewrote it to
key=[REDACTED], so the log showed two masking styles and the masking
tests failed. Only the shared masking remains.
The Gemini native routes take ?key= out of the URL. With no query left,
the log fell back to the path gin recorded on arrival, which still
carried the key. The log now writes the path alone in that case, and the
plugin API document no longer says the key is logged as key=[REDACTED].
* feat(plugins): answer native plugin routes as the vendors do
A request sent to a vendor's own path now reaches the vendor as the client
wrote it, and the client gets the vendor's reply shape and status. The
gateway answers a native request with its own 400 only when it cannot tell
the model, cannot price the request, or cannot provide the feature; the
vendor checks everything else.
- New gateway rejections of that kind on native routes: callback_url on
Ark, Kling, Vidu and MiniMax; Kling external_task_id and a body with
model but no model_name; xAI storage_options, which was dropped
silently; and for Jimeng, req_json on get_result_v2, a req_key the
plugin cannot price, and frames other than 121 or 241. A value the
plugin cannot read reserves the model's dearest tier, and settlement is
unchanged.
- Native bodies are sent as the client wrote them. Plugins no longer fill
in MiniMax-H3's duration, resolution and ratio or Vidu's
movement_amplitude and images: null, drop Vidu's bgm: false, turn
Jimeng's image and images into image_urls, or merge Ark's content.
Kling requests no longer carry an added aspect_ratio 1:1, cfg_scale 0.5
or model field; without a size Kling uses its own 16:9. DashScope
requests go to the endpoint the client called.
- Replies keep each vendor's shapes and error codes. A native presenter
may answer with the vendor's own status through a reply wrapper
({__status, __headers, __body}): xAI answers a pending video with 202,
DashScope an unknown task with 200 UNKNOWN. A task the gateway failed
shows as failed instead of still running. xAI's native query shows a
video that failed but was charged as failed with xAI's usage, instead of
done; billing is unchanged.
- A native client that asks the vendor for a stream (Seedream with
stream: true, Wan interleaved output with X-DashScope-Sse: enable) gets
the vendor's events as they arrive. Once an event has reached the
client the task settles and is never refunded: a finished stream bills
what was delivered, and a stream that stopped early bills the
reservation and cuts the client's connection, so a downstream gateway
keeps its reservation too. The client leaving does not cancel the
upstream request, which TASK_PLUGIN_PROTOCOL_TIMEOUT_SECONDS bounds. A
JSON reply from an older new-api upstream is still accepted.
- Routes that keep no result (retainResult: false) accept replies up to
MAX_FILE_DOWNLOAD_MB, so b64_json images fit.
- Native decoders get the client's request headers, without gateway
credentials, as ctx.requestHeaders.
- Native routes accept a channel's model aliases and case variants of
model names, as the gateway's own formats do, also on routes that list
their models.
- Kling lists kling-v2-5-turbo, kling-v2-6 and kling-v3, priced in units
per mode, sound and voice; Kling retired kling-v1, kling-v1-6 and
kling-v2-master on 2026-09-15. Vidu lists its current models, from
viduq4-preview to vidu1.5.
- Clients of /v1/videos and the other gateway formats can no longer pass
a native body through the field the plugins use for it internally.
* feat(plugins): add Kling 4.0 to the kling plugin
Kling 4.0 takes the model in the path and has its own request shape, so
the plugin serves POST /text-to-video/kling-4.0, /image-to-video/kling-4.0
and /omni-video/kling-4.0 as native routes, and answers GET
/tasks?task_ids= for their tasks. /v1/videos and the Responses API send
kling-4.0 as text-to-video or image-to-video, with size picking 720p or
1080p.
Billing follows Kling's price list: units per output second by
resolution, or, with an input video, twice the output, or input plus
output when the input is longer. Kling picks the length when the request
has none and only Kling knows how long an input video is, so the
reservation covers the longest of each. A task settles on the units Kling
deducted, or, when Kling took cash, on the durations it reports.
Kling 4.0 Flash has no published price yet and is left out.
* chore(plugins): bump the task plugins this branch changes
Each of these plugins now declares its vendor's own paths and answers
native requests as the vendor does; kling also adds Kling 4.0. That is
new behavior in every one of them, so each takes a minor version:
alibaba 1.5.0, doubao 1.4.0, google 1.2.0, hailuo 1.4.0, jimeng 1.2.0,
kling 1.2.0, vertex-ai 1.2.0, vidu 1.2.0 and xai 1.2.0.
104 lines
13 KiB
TypeScript
104 lines
13 KiB
TypeScript
export type JSONValue = null | boolean | number | string | readonly JSONValue[] | {readonly [key: string]: JSONValue};
|
||
/** json-clone@1, submit-sse-delta@1 and duration-auto@1 are accepted for earlier hosts; new plugins need none of them. */
|
||
export type HostCapability = "json-clone@1" | "submit-sse-delta@1" | "json-order@1" | "duration-auto@1";
|
||
/** Kinds of upstream a driver can address: the vendor API itself, or another New API gateway with the same plugin installed. */
|
||
export type UpstreamKind = "vendor" | "new_api";
|
||
/** Host-injected on every driver hook context. With "new_api" the driver uses its own native-route prefix and the host already set Bearer credentials. */
|
||
export interface UpstreamContext {kind: UpstreamKind}
|
||
export type MutableJSON<T> = T extends readonly (infer Item)[] ? MutableJSON<Item>[] : T extends object ? {-readonly [Key in keyof T]: MutableJSON<T[Key]>} : T;
|
||
export interface HostUtils {
|
||
hasCapability(name: string): boolean;
|
||
/** Independent native JS containers; at most 1 MiB encoded JSON, depth 32 and 32,768 nodes. */
|
||
json: {clone<T extends JSONValue>(value: T): MutableJSON<T>};
|
||
unixNow(): number;
|
||
uuid(): string;
|
||
hmacSHA256(message: string, secret: string): string;
|
||
jwtSignHS256(claims: Record<string, JSONValue>, secret: string): string;
|
||
base64(value: string): string;
|
||
base64URL(value: string): string;
|
||
base64URLDecode(value: string): string;
|
||
volcSignV4(request: {method: string; url: string; headers?: Record<string, string>; body?: string; accessKey: string; secretKey: string; region?: string; service?: string; timestamp?: number}): Record<string, string>;
|
||
/** Synchronous read-only request from driver hooks to the channel Base URL host or allowedHosts. At most 4 per hook call, 15 s each, 30 s in total, 1 MiB per body; redirects are returned, not followed. */
|
||
fetch(request: FetchRequest): FetchResponse;
|
||
}
|
||
export interface FetchRequest {url: string; method?: "GET" | "HEAD"; headers?: Record<string, string>; responseType?: "json" | "bytes"}
|
||
/** headers holds the first value of each header under its canonical name; body is parsed JSON when the response parses, otherwise text, and "" for HEAD; with responseType "bytes" it is an ArrayBuffer of the response bytes. */
|
||
export interface FetchResponse {status: number; headers: Record<string, string>; body: JSONValue | string | ArrayBuffer}
|
||
declare global {const utils: HostUtils;}
|
||
export type FileReference = Readonly<{ref: string; field: string; filename: string; mimeType: string; size: number}>;
|
||
export type FilePlaceholder = Readonly<{__fileRef: string; encoding: "base64" | "dataUrl"; mimeType?: string; maxBytes?: number}>;
|
||
export type DecodedBody =
|
||
| Readonly<{kind: "json"; value: JSONValue}>
|
||
| Readonly<{kind: "form"; fields: Readonly<Record<string, readonly string[]>>}>
|
||
| Readonly<{kind: "multipart"; fields: Readonly<Record<string, readonly string[]>>; files: readonly FileReference[]}>
|
||
| Readonly<{kind: "none"}>;
|
||
|
||
/** requestHeaders: the client's request headers, as DriverContext.requestHeaders holds them. Older gateways do not pass them to decoders. */
|
||
export interface NativeDecodeContext {method: string; path: string; params: Readonly<Record<string, string>>; query: Readonly<Record<string, readonly string[]>>; requestHeaders: Readonly<Record<string, string>>; body: DecodedBody}
|
||
export interface ProtocolDecodeContext extends NativeDecodeContext {protocol: ProtocolName; operation: string; model: string; upstreamModel?: string; stream: boolean}
|
||
export type SubmitIntent = {kind: "submit"; model: string; action?: string; requestBody?: unknown; originTaskIds?: readonly string[]};
|
||
export type QueryIntent = {kind: "query"; taskIds: readonly string[]};
|
||
export type TaskIntent = SubmitIntent | QueryIntent;
|
||
export interface NativeRoute {method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; /** The vendor's own path; the host also serves it under /{key} unless its first segment is the key or a proper prefix of it. */ path: string; type: "submit" | "query" | "dynamic"; action?: string; /** Query routes: the path parameter carrying the gateway task id or, when the path has none, the query-string parameter of that name. Default "task_id". */ taskIdParam?: string; decode?: string; render: string; models?: readonly string[]; retainResult?: boolean}
|
||
export type ProtocolName = "openai_responses" | "openai_video" | "openai_image";
|
||
export type ResponsesMode = "stream" | "sync" | "background";
|
||
export type ProtocolClaim =
|
||
| "openai_video"
|
||
| "openai_image"
|
||
| {name: "openai_responses"; supports: readonly ResponsesMode[]; models?: readonly string[]}
|
||
| {name: "openai_video"; models?: readonly string[]}
|
||
| {name: "openai_image"; models?: readonly string[]};
|
||
/** One entry of the OpenAI ImageResponse `data` array rendered by protocols.openai_image.render. */
|
||
export type ImageResponseEntry = {url?: string; b64_json?: string; revised_prompt?: string};
|
||
export type LocalizedText = string | ({ en: string } & Record<string, string>);
|
||
export type UsageFieldSchema =
|
||
| {type: "number"; unit: "count"; unitLabel?: LocalizedText; description?: LocalizedText}
|
||
| {type: "number"; unit: "second" | "token" | "credit"; unitLabel?: never; description?: LocalizedText}
|
||
| {type: "boolean"; unitLabel?: never; description?: LocalizedText}
|
||
| {enum: readonly string[]; unitLabel?: never; description?: LocalizedText; enumLabels?: Readonly<Record<string, LocalizedText>>};
|
||
export type UsageExample = {label: string; facts: Readonly<Record<string, string | number | boolean>>};
|
||
export type UsageProfile = {models: readonly string[]; schema: Readonly<Record<string, UsageFieldSchema>>; examples?: readonly UsageExample[]};
|
||
export interface Meta {requiredCapabilities?: readonly HostCapability[]; submitResponseTypes?: readonly ("json" | "sse")[]; sortPriority?: number; website?: string; apiVersion: 1; key: string; name: string; icon?: string; description?: LocalizedText; version: string; author: {name: string; url?: string}; baseUrl?: string; channelTypes?: readonly number[]; models: readonly string[]; fetchMode: "per_task" | "batch"; allowedHosts?: readonly string[]; upstreams?: readonly UpstreamKind[]; routes?: readonly NativeRoute[]; protocols?: readonly ProtocolClaim[]; usageSchema?: Readonly<Record<string, UsageFieldSchema>>; usageExamples?: readonly UsageExample[]; usageProfiles?: readonly UsageProfile[]; auth?: "none" | "api_key" | "vertex_oauth" | {type: "none" | "api_key" | "oauth2_jwt"}}
|
||
export interface TaskView {task_id: string; status: string; progress?: string; fail_reason?: string; created_at?: number; updated_at?: number; data?: unknown; properties?: Record<string, unknown>}
|
||
export interface DriverContext {requestBody: unknown; /** Client request headers, first value under the canonical name, without gateway credentials; Content-Type and Accept are always present. Older gateways pass only those two. */ requestHeaders: Readonly<Record<string, string>>; action: string; model: string; upstreamModel: string; baseUrl: string; apiKey?: string; authHeader: string; upstream: UpstreamContext; files: readonly FileReference[]; publicTaskId: string; originTasks?: readonly {taskId: string; upstreamTaskId: string; action: string; status: string; data: unknown}[]}
|
||
export interface TaskQueryContext {taskId: string; publicTaskId: string; action: string; model: string; upstreamModel: string; baseUrl: string; apiKey?: string; authHeader: string; auth?: unknown; upstream: UpstreamContext; data: unknown; state: unknown}
|
||
export interface BatchQueryContext {baseUrl: string; apiKey?: string; authHeader: string; auth?: unknown; upstream: UpstreamContext; tasks: readonly TaskQueryContext[]}
|
||
export type HookHTTPResponse = {readonly status: number; readonly headers: Readonly<Record<string, string>>}
|
||
export interface RequestDescriptor {responseType?: "json" | "sse"; url: string; method?: string; headers?: Record<string, string>; /** JSON body may contain FilePlaceholder objects at any depth; the host replaces each with a Base64 or data-URL string. */ body?: unknown; credentialless?: boolean; action?: string; model?: string; rewriteModel?: string; bodyType?: "json" | "multipart"; parts?: readonly {name: string; value?: unknown; fileRef?: string; filename?: string}[]; /** buildContentRequest only: the artifact's bytes are the base64 string at this path of the JSON reply, a long-running operation. String keys and non-negative integer indices, at most 32 segments. */ contentPath?: readonly (string | number)[]; /** buildContentRequest with contentPath: the artifact's media type, default "video/mp4". */ mimeType?: string}
|
||
export interface UpstreamResponse {statusCode: number; headers: Readonly<Record<string, readonly string[]>>; body: unknown}
|
||
export interface NormalizedTaskResult {taskId?: string; status: "NOT_START" | "SUBMITTED" | "QUEUED" | "IN_PROGRESS" | "SUCCESS" | "FAILURE" | "UNKNOWN"; progress?: string; reason?: string; url?: string; remoteUrl?: string; completionTokens?: number; totalTokens?: number}
|
||
export interface TaskArtifact {key: string; type: "video" | "audio" | "image" | "file"; mimeType?: string}
|
||
export declare const meta: Meta;
|
||
/** A query presenter's context: artifacts holds the gateway download addresses of one task in SUCCESS (from listArtifacts) and is empty otherwise. Throwing "artifact_not_found" answers 404. */
|
||
export interface NativeQueryContext extends NativeDecodeContext {artifacts: Readonly<Record<string, {key: string; type: string; url: string; mimeType?: string}>>}
|
||
/** A native presenter's reply with the vendor's own HTTP status (200–599); only Location and Retry-After may be set, and a reply without __body has no body. Any other value is the JSON body of a 200 reply, or of the host's status for the error presenter. */
|
||
export type NativeReply = {__status: number; __headers?: {Location?: string; "Retry-After"?: string}; __body?: unknown};
|
||
export declare const native: Record<string, ((ctx: NativeDecodeContext) => TaskIntent) | ((ctx: NativeQueryContext, task: TaskView | readonly TaskView[]) => unknown | NativeReply)> & {error?: (ctx: NativeDecodeContext, error: {code: string; message: string; httpStatus: number; retryable: boolean; requestId: string}) => unknown | NativeReply};
|
||
export declare const protocols: {
|
||
openai_responses?: {decodeRequest(ctx: ProtocolDecodeContext): SubmitIntent; renderEvents?(ctx: unknown, task: TaskView, previousState: unknown): unknown; renderFinal?(ctx: unknown, task: TaskView): unknown};
|
||
openai_video?: {decodeRequest(ctx: ProtocolDecodeContext): SubmitIntent; render(ctx: unknown, task: TaskView): unknown};
|
||
/** render returns the OpenAI ImageResponse; the host adds `created` when absent and resolves response_format b64_json. */
|
||
openai_image?: {decodeRequest(ctx: ProtocolDecodeContext): SubmitIntent; render(ctx: unknown, task: TaskView): {created?: number; data: readonly ImageResponseEntry[]} & Record<string, unknown>};
|
||
};
|
||
export declare function buildSubmitRequest(ctx: DriverContext): RequestDescriptor;
|
||
export interface SubmitEvent {event: string; id: string; data: string}
|
||
export type JSONPath = readonly (string | number)[];
|
||
export type JSONChange =
|
||
| {op: "set" | "append"; path: JSONPath; value: JSONValue}
|
||
| {op: "appendText"; path: JSONPath; value: string};
|
||
export interface SubmitEventDeltaResult {changes: readonly JSONChange[]; state: JSONValue; done: boolean}
|
||
/** With submit-sse-delta@1, state is small control data; changes build the separate response body. */
|
||
export declare function parseSubmitEventDelta(ctx: DriverContext, event: SubmitEvent, previousState: JSONValue | null): SubmitEventDeltaResult;
|
||
export declare function parseSubmitEvent(ctx: DriverContext, event: SubmitEvent, previousState: JSONValue | null): {state: JSONValue; done: boolean};
|
||
export declare function parseSubmitResponse(ctx: DriverContext, response: UpstreamResponse): {taskId: string; taskData?: unknown; immediate?: NormalizedTaskResult; state?: unknown};
|
||
/** Query redirects retain credentials only within the channel host and meta.allowedHosts; SSRF checks and HTTPS downgrade protection still apply. */
|
||
export declare function buildQueryRequest(ctx: TaskQueryContext): RequestDescriptor;
|
||
export declare function buildBatchQueryRequest(ctx: BatchQueryContext, tasks: readonly TaskQueryContext[]): RequestDescriptor;
|
||
export declare function parseTaskResult(ctx: TaskQueryContext, body: unknown, response: HookHTTPResponse): NormalizedTaskResult;
|
||
export declare function parseBatchResult(ctx: BatchQueryContext, body: unknown, response: HookHTTPResponse): readonly (NormalizedTaskResult & {taskId: string; data?: unknown; state?: unknown})[];
|
||
export declare function extractUsage(ctx: DriverContext & {usagePurpose?: "facts" | "billing_ratios"}): Readonly<Record<string, string | number | boolean>> | null;
|
||
export declare function extractUsageOnSubmit(ctx: DriverContext, taskData: unknown): Readonly<Record<string, string | number | boolean>> | null;
|
||
export declare function extractUsageOnComplete(task: TaskQueryContext, result: NormalizedTaskResult, data: unknown): Readonly<Record<string, string | number | boolean>> | null;
|
||
export declare function listArtifacts(task: {taskId: string; status: string; action: string; data: unknown; producerVersion: string}): readonly TaskArtifact[];
|
||
export declare function buildContentRequest(ctx: DriverContext & {artifactKey: string; data: unknown; state?: unknown; upstreamTaskId: string; clientRequest: {method: "GET" | "HEAD"; headers: Readonly<Record<string, string>>}}): RequestDescriptor;
|