@linxiraos/pi-ai 1.1.5 → 1.1.7
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/CHANGELOG.md +8 -0
- package/README.md +4 -5
- package/dist/types/auth-broker/remote-store.d.ts +5 -2
- package/dist/types/auth-gateway/http.d.ts +14 -0
- package/dist/types/auth-storage.d.ts +18 -2
- package/dist/types/error/rate-limit.d.ts +14 -12
- package/dist/types/providers/claude-code-fingerprint.d.ts +4 -2
- package/dist/types/providers/openai-data-uri.d.ts +11 -0
- package/dist/types/providers/openai-responses-server-schema.d.ts +220 -76
- package/dist/types/providers/openai-shared.d.ts +19 -1
- package/dist/types/registry/api-key-login.d.ts +2 -0
- package/dist/types/registry/api-key-validation.d.ts +1 -0
- package/dist/types/registry/cloudflare-ai-gateway.d.ts +8 -8
- package/dist/types/registry/registry.d.ts +5 -0
- package/dist/types/registry/types.d.ts +3 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/types/usage/google-antigravity.d.ts +12 -1
- package/dist/types/usage.d.ts +29 -10
- package/package.json +5 -5
- package/src/auth/sqlite-credential-store.ts +36 -10
- package/src/auth-broker/remote-store.ts +49 -31
- package/src/auth-broker/wire-schemas.ts +3 -1
- package/src/auth-gateway/http.ts +28 -0
- package/src/auth-gateway/server.ts +62 -1
- package/src/auth-storage.ts +63 -18
- package/src/error/flags.ts +16 -12
- package/src/error/rate-limit.ts +26 -23
- package/src/providers/amazon-bedrock.ts +9 -0
- package/src/providers/anthropic.ts +5 -2
- package/src/providers/claude-code-fingerprint.ts +3 -1
- package/src/providers/cursor.ts +61 -29
- package/src/providers/openai-chat-server.ts +1 -12
- package/src/providers/openai-completions.ts +99 -13
- package/src/providers/openai-data-uri.ts +51 -0
- package/src/providers/openai-responses-server-schema.ts +22 -12
- package/src/providers/openai-responses-server.ts +64 -23
- package/src/providers/openai-shared.ts +72 -51
- package/src/providers/pi-native-client.ts +9 -1
- package/src/registry/api-key-login.ts +3 -1
- package/src/registry/api-key-validation.ts +32 -4
- package/src/registry/cloudflare-ai-gateway.ts +120 -16
- package/src/registry/oauth/anthropic.ts +2 -2
- package/src/registry/oauth/oauth.html +8 -2
- package/src/registry/oauth/perplexity.ts +48 -2
- package/src/registry/oauth/zai.ts +5 -1
- package/src/registry/qianfan.ts +1 -0
- package/src/registry/types.ts +3 -0
- package/src/stream.ts +9 -7
- package/src/types.ts +6 -0
- package/src/usage/google-antigravity.ts +25 -13
- package/src/usage/openai-codex.ts +5 -2
- package/src/usage/zai.ts +50 -4
- package/src/usage.ts +30 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [1.1.7] - 2026-09-01
|
|
6
|
+
|
|
7
|
+
- 同步上游 OMP v18.0.11(`b8ce33a58911c26bed1d84f0db9a5e2e727c49a2`)。
|
|
8
|
+
|
|
9
|
+
## [1.1.6] - 2026-08-30
|
|
10
|
+
|
|
11
|
+
- 同步上游 OMP v18.0.9(`cc14e04f075d`)。
|
|
12
|
+
|
|
5
13
|
## [1.1.5] - 2026-08-26
|
|
6
14
|
|
|
7
15
|
- 同步上游 OMP v18.0.5 / v18.0.6:新增 Yolo-Auto / OpenRouter 浏览器登录与 DeepInfra 支持,空补全重试重构(withReplaySafeStreamRetry)。
|
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ Unified LLM API with automatic model discovery, provider configuration, token an
|
|
|
76
76
|
- **Qwen Portal** (supports `QWEN_OAUTH_TOKEN` or `QWEN_PORTAL_API_KEY`)
|
|
77
77
|
- **QwenCloud Token Plan** (supports `/login alibaba-token-plan`, `ALIBABA_TOKEN_PLAN_API_KEY`, or `BAILIAN_TOKEN_PLAN_API_KEY`; interactive login first selects a region — International (Singapore, default), China (Beijing) for 百炼 Token Plan keys, or a custom base URL — since region keys are non-interchangeable, then optionally stores a `home.qwencloud.com` Cookie request header for best-effort 5-hour and 7-day quota reporting)
|
|
78
78
|
To enable quota reporting, sign in to the Token Plan dashboard, copy the `Cookie` request-header value from a `home.qwencloud.com` request in browser developer tools, and paste it at the second login prompt. Press Enter to skip; the Cookie is sensitive and session-lived, so rerun login when it expires.
|
|
79
|
-
- **Cloudflare AI Gateway** (
|
|
79
|
+
- **Cloudflare AI Gateway** (supports `/login cloudflare-ai-gateway`, or `CLOUDFLARE_AI_GATEWAY_API_KEY` with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_GATEWAY_ID`)
|
|
80
80
|
- **Ollama** (local OpenAI-compatible runtime; optional `OLLAMA_API_KEY`)
|
|
81
81
|
- **Ollama Cloud** (hosted native Ollama API; requires `OLLAMA_CLOUD_API_KEY`)
|
|
82
82
|
- **llama.cpp** (local OpenAI and Anthropic compatible inference server)
|
|
@@ -960,11 +960,10 @@ In Node.js environments, you can set environment variables to avoid passing API
|
|
|
960
960
|
| Xiaomi MiMo | `XIAOMI_API_KEY` |
|
|
961
961
|
| ZenMux | `ZENMUX_API_KEY` |
|
|
962
962
|
| vLLM | `VLLM_API_KEY` |
|
|
963
|
-
| Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY`
|
|
963
|
+
| Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` + `CLOUDFLARE_ACCOUNT_ID` + `CLOUDFLARE_GATEWAY_ID` |
|
|
964
964
|
| GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
|
|
965
965
|
|
|
966
|
-
For Cloudflare
|
|
967
|
-
`https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/anthropic`.
|
|
966
|
+
`/login cloudflare-ai-gateway` collects and stores the gateway token, account ID, and gateway ID. For environment configuration, set all three Cloudflare values above. OMP derives provider endpoints from the account and gateway IDs.
|
|
968
967
|
|
|
969
968
|
For Anthropic Foundry routing, set `CLAUDE_CODE_USE_FOUNDRY=true` plus:
|
|
970
969
|
`FOUNDRY_BASE_URL`, `ANTHROPIC_FOUNDRY_API_KEY`, optional `ANTHROPIC_CUSTOM_HEADERS`,
|
|
@@ -996,7 +995,7 @@ Provider endpoint defaults for the current OpenAI-compatible integrations:
|
|
|
996
995
|
- Ollama: local OpenAI-compatible runtime (`http://127.0.0.1:11434/v1`)
|
|
997
996
|
- Ollama Cloud: native Ollama API host (`https://ollama.com/api`, configured here as base URL `https://ollama.com`)
|
|
998
997
|
- LiteLLM: `http://localhost:4000/v1`
|
|
999
|
-
- Cloudflare AI Gateway: `https://gateway.ai.cloudflare.com/v1/<account>/<gateway
|
|
998
|
+
- Cloudflare AI Gateway: native Anthropic, OpenAI, and Workers AI routes under `https://gateway.ai.cloudflare.com/v1/<account>/<gateway>`
|
|
1000
999
|
- Qwen Portal: `https://portal.qwen.ai/v1`
|
|
1001
1000
|
When set, the library automatically uses these keys:
|
|
1002
1001
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AuthCredential, type AuthCredentialStore, type DisabledCredentialSummary, type OAuthCredential, type StoredAuthCredential, type StoredCredentialBlock } from "../auth-storage.js";
|
|
2
2
|
import type { OAuthCredentials } from "../registry/oauth/types.js";
|
|
3
3
|
import type { Provider } from "../types.js";
|
|
4
|
-
import type { ObservedUsageEntry, UsageReport } from "../usage.js";
|
|
4
|
+
import type { ClientUsageIdentity, ObservedUsageEntry, UsageReport } from "../usage.js";
|
|
5
5
|
import { type AuthBrokerClient } from "./client.js";
|
|
6
6
|
import type { SnapshotResponse } from "./types.js";
|
|
7
7
|
/**
|
|
@@ -138,7 +138,10 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
|
|
|
138
138
|
* a flush. One `POST /v1/usage/observed` at most per flush interval; on
|
|
139
139
|
* failure the batch is retained and retried with the next flush. A 404
|
|
140
140
|
* (pre-endpoint broker) disables reporting for the life of this store.
|
|
141
|
+
*
|
|
142
|
+
* `client` overrides the reporting identity — the auth-gateway attributes
|
|
143
|
+
* each request to the originating install/app instead of the gateway host.
|
|
141
144
|
*/
|
|
142
|
-
recordObservedUsage(entries: ObservedUsageEntry[]): void;
|
|
145
|
+
recordObservedUsage(entries: ObservedUsageEntry[], client?: ClientUsageIdentity): void;
|
|
143
146
|
close(): void;
|
|
144
147
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Api, AssistantMessage, Model } from "../types.js";
|
|
2
|
+
import type { ClientUsageIdentity } from "../usage.js";
|
|
2
3
|
export declare function json(status: number, body: unknown, headers?: Record<string, string>): Response;
|
|
3
4
|
/**
|
|
4
5
|
* Diagnostic response headers for translated inference requests, mirroring the
|
|
@@ -30,6 +31,19 @@ export declare function isAuthorized(req: Request, tokens: ReadonlySet<string>):
|
|
|
30
31
|
* `handleFormatEndpoint`; parsers then read `options.headers`.
|
|
31
32
|
*/
|
|
32
33
|
export declare function captureRequestHeaders(headers: Headers): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the usage-attribution identity for an inbound gateway request.
|
|
36
|
+
*
|
|
37
|
+
* pi-native omp clients send `x-omp-install-id` / `x-omp-hostname` /
|
|
38
|
+
* `x-omp-app` (see `providers/pi-native-client.ts`); any client may set them.
|
|
39
|
+
* Requests without an install id fall back to the gateway host's identity
|
|
40
|
+
* under the `gateway` app label, so unlabeled foreign-SDK traffic (llm-git,
|
|
41
|
+
* openai/anthropic SDKs) still lands in per-client burn tracking instead of
|
|
42
|
+
* vanishing. These headers are attribution-only — they are deliberately
|
|
43
|
+
* absent from {@link captureRequestHeaders}'s allow-list and never reach the
|
|
44
|
+
* upstream provider.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveClientIdentity(headers: Headers): ClientUsageIdentity;
|
|
33
47
|
/**
|
|
34
48
|
* Resolve a prompt-cache identity from inbound request body + headers.
|
|
35
49
|
* Order of precedence (first wins):
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ApiKeyResolver } from "./auth-retry.js";
|
|
2
2
|
import type { OAuthAuthInfo, OAuthController, OAuthCredentials, OAuthProviderId } from "./registry/oauth/types.js";
|
|
3
3
|
import type { Provider } from "./types.js";
|
|
4
|
-
import type { ClientUsageReport, ClientUsageSummary, CredentialRankingStrategy, ObservedUsageEntry, UsageHistoryEntry, UsageHistoryQuery, UsageLogger, UsageProvider, UsageReport } from "./usage.js";
|
|
4
|
+
import type { ClientUsageIdentity, ClientUsageReport, ClientUsageSummary, CredentialRankingStrategy, ObservedUsageEntry, UsageHistoryEntry, UsageHistoryQuery, UsageLogger, UsageProvider, UsageReport } from "./usage.js";
|
|
5
5
|
import { type CodexResetConsumeCode, type CodexResetCredit } from "./usage/openai-codex-reset.js";
|
|
6
6
|
export { isSqliteBusyError, isSqliteCorruptionError, SqliteAuthCredentialStore, } from "./auth/sqlite-credential-store.js";
|
|
7
7
|
export type ApiKeyCredential = {
|
|
@@ -317,8 +317,10 @@ export interface AuthCredentialStore {
|
|
|
317
317
|
* Client hook: forward locally observed request usage. Remote broker stores
|
|
318
318
|
* batch these to the broker so it can attribute token burn per install;
|
|
319
319
|
* local stores omit it and observation is skipped.
|
|
320
|
+
* `client` overrides the reporting identity (gateway requests attribute to
|
|
321
|
+
* the originating client, not the gateway host).
|
|
320
322
|
*/
|
|
321
|
-
recordObservedUsage?(entries: ObservedUsageEntry[]): void;
|
|
323
|
+
recordObservedUsage?(entries: ObservedUsageEntry[], client?: ClientUsageIdentity): void;
|
|
322
324
|
/** Broker host: persist one client's observed-usage report. */
|
|
323
325
|
recordClientUsage?(report: ClientUsageReport): void;
|
|
324
326
|
/** Broker host: aggregate recorded per-client usage since a timestamp. */
|
|
@@ -819,6 +821,18 @@ export declare class AuthStorage {
|
|
|
819
821
|
* `XAI_API_KEY` does not auto-select SuperGrok (`xai-oauth`).
|
|
820
822
|
*/
|
|
821
823
|
hasAuth(provider: string): boolean;
|
|
824
|
+
/**
|
|
825
|
+
* Like {@link hasAuth} but excludes providers whose only credential is the
|
|
826
|
+
* self-resolving {@link AUTHENTICATED_SENTINEL} — the marker AWS/Vertex
|
|
827
|
+
* transports return when a credential *source* merely exists (a stray
|
|
828
|
+
* `~/.aws` profile, an EC2 instance role, Application Default Credentials)
|
|
829
|
+
* without a usable key resolved yet. Default-model auto-selection uses this
|
|
830
|
+
* so an ambiently-available provider (e.g. `amazon-bedrock` via an unrelated
|
|
831
|
+
* AWS profile) does not win the startup default over a provider the user
|
|
832
|
+
* actually signed into and then 403 on the first turn. Explicit selection
|
|
833
|
+
* and picker visibility still go through {@link hasAuth}. See issue #9967.
|
|
834
|
+
*/
|
|
835
|
+
hasConcreteAuth(provider: string): boolean;
|
|
822
836
|
/**
|
|
823
837
|
* Whether a request could resolve a key for this provider, including
|
|
824
838
|
* cross-provider env aliases (`xai-oauth` borrowing `XAI_API_KEY`).
|
|
@@ -915,6 +929,8 @@ export declare class AuthStorage {
|
|
|
915
929
|
};
|
|
916
930
|
costUsd?: number;
|
|
917
931
|
at?: number;
|
|
932
|
+
/** Attribution override; defaults to this process's install identity. */
|
|
933
|
+
client?: ClientUsageIdentity;
|
|
918
934
|
}): void;
|
|
919
935
|
/** Broker host: persist one client's observed-usage report (per-install token burn). */
|
|
920
936
|
recordClientUsage(report: ClientUsageReport): boolean;
|
|
@@ -24,13 +24,15 @@ export declare function calculateRateLimitBackoffMs(reason: RateLimitReason): nu
|
|
|
24
24
|
/**
|
|
25
25
|
* HTTP status codes that, absent richer body classification, represent an
|
|
26
26
|
* account-local usage cap rather than a bad credential or a transient blip.
|
|
27
|
-
* HTTP 402 Payment Required
|
|
27
|
+
* HTTP 402 Payment Required represents an account-billing cap (xAI
|
|
28
28
|
* Grok Build "usage balance exhausted", DeepSeek "Insufficient Balance",
|
|
29
|
-
* OpenRouter credit exhaustion)
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* OpenRouter credit exhaustion) when opaque, payment/deactivation/balance-worded,
|
|
30
|
+
* or QUOTA_EXHAUSTED/CONCURRENT_LIMIT, while informative non-quota 402s (e.g.
|
|
31
|
+
* endpoint subscription requirements) remain non-usage-limits. Always combine
|
|
32
|
+
* with {@link isUsageLimitOutcome} when a message is available.
|
|
32
33
|
*/
|
|
33
34
|
export declare function isUsageLimitStatus(status: number | undefined): boolean;
|
|
35
|
+
export declare function is402BillingCapBody(message: string | undefined): boolean;
|
|
34
36
|
/**
|
|
35
37
|
* Returns true for failures that should burn one credential and rotate to a
|
|
36
38
|
* sibling account. Decision tree:
|
|
@@ -43,13 +45,13 @@ export declare function isUsageLimitStatus(status: number | undefined): boolean;
|
|
|
43
45
|
* empty JSON, HTTP framing only) → rotate conservatively: the server
|
|
44
46
|
* gave us nothing else to go on.
|
|
45
47
|
* 4. Body has content → defer to {@link parseRateLimitReason}. `QUOTA_EXHAUSTED`
|
|
46
|
-
* rotates; for
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* `
|
|
51
|
-
*
|
|
52
|
-
* credentials.
|
|
48
|
+
* rotates; for a 402 status a `CONCURRENT_LIMIT` body also rotates (the cap
|
|
49
|
+
* is concurrent-worded but the status is an exhausted billing cap).
|
|
50
|
+
* `RATE_LIMIT_EXCEEDED` (`Too many requests`, per-minute caps),
|
|
51
|
+
* `MODEL_CAPACITY_EXHAUSTED` (`Service overloaded`), `SERVER_ERROR`, and
|
|
52
|
+
* `UNKNOWN` (e.g. "A subscription is required for this endpoint" or
|
|
53
|
+
* "Please retry in 5s") stay in the provider's own backoff / failure
|
|
54
|
+
* layer so transient or non-quota responses don't burn sibling credentials.
|
|
53
55
|
*/
|
|
54
56
|
export declare function isUsageLimitOutcome(status: number | undefined, message: string | undefined): boolean;
|
|
55
57
|
/**
|
|
@@ -78,6 +80,6 @@ export declare function isAccountScopedCapText(message: string): boolean;
|
|
|
78
80
|
/**
|
|
79
81
|
* A concurrency cap on a non-billing status is shed-and-backoff, not
|
|
80
82
|
* credential-rotatable. This mirrors the exclusion in {@link isUsageLimitOutcome}
|
|
81
|
-
* for the 403 auth-retry entry points. A 402 remains
|
|
83
|
+
* for the 403 auth-retry entry points. A 402 remains an account-billing cap.
|
|
82
84
|
*/
|
|
83
85
|
export declare function isConcurrencyCapExclusion(status: number | undefined, message: string | undefined): boolean;
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
* provider module.
|
|
9
9
|
*/
|
|
10
10
|
/** Claude runtime version bundled by the current Cowork desktop release. */
|
|
11
|
-
export declare const claudeCodeVersion = "2.1.
|
|
11
|
+
export declare const claudeCodeVersion = "2.1.246";
|
|
12
|
+
/** `@anthropic-ai/sdk` version bundled by the current Cowork desktop release. */
|
|
13
|
+
export declare const claudeCodeSdkVersion = "0.112.1";
|
|
12
14
|
/** User-Agent emitted by Cowork's `claude-desktop` inference entrypoint. */
|
|
13
|
-
export declare const coworkUserAgent = "claude-cli/2.1.
|
|
15
|
+
export declare const coworkUserAgent = "claude-cli/2.1.246 (external, claude-desktop)";
|
|
14
16
|
/** Prefix used to isolate custom Anthropic OAuth tools from built-in tools. */
|
|
15
17
|
export declare const claudeToolPrefix: string;
|
|
16
18
|
/** Identity block prepended by Cowork's Claude runtime. */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Base64 payload and media type decoded from a data URI. */
|
|
2
|
+
export interface DecodedDataUri {
|
|
3
|
+
data: string;
|
|
4
|
+
mimeType: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Decodes base64 and percent-encoded `data:` URIs.
|
|
8
|
+
*
|
|
9
|
+
* Returns `undefined` for non-data URLs and data URIs without a comma separator.
|
|
10
|
+
*/
|
|
11
|
+
export declare function decodeDataUri(url: string): DecodedDataUri | undefined;
|