@linxiraos/pi-ai 1.1.4 → 1.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/README.md +8 -6
  3. package/dist/types/auth-broker/remote-store.d.ts +13 -2
  4. package/dist/types/auth-gateway/http.d.ts +14 -0
  5. package/dist/types/auth-storage.d.ts +18 -2
  6. package/dist/types/providers/anthropic.d.ts +2 -5
  7. package/dist/types/providers/azure-openai-responses.d.ts +4 -1
  8. package/dist/types/providers/claude-code-fingerprint.d.ts +4 -2
  9. package/dist/types/providers/openai-completions.d.ts +2 -4
  10. package/dist/types/providers/openai-data-uri.d.ts +11 -0
  11. package/dist/types/providers/openai-responses-server-schema.d.ts +220 -76
  12. package/dist/types/providers/openai-responses.d.ts +3 -4
  13. package/dist/types/providers/openai-shared.d.ts +21 -2
  14. package/dist/types/registry/cloudflare-ai-gateway.d.ts +8 -8
  15. package/dist/types/registry/deepinfra.d.ts +6 -0
  16. package/dist/types/registry/oauth/openrouter.d.ts +36 -0
  17. package/dist/types/registry/openrouter.d.ts +7 -6
  18. package/dist/types/registry/registry.d.ts +15 -0
  19. package/dist/types/registry/types.d.ts +3 -0
  20. package/dist/types/registry/yolo-auto.d.ts +15 -0
  21. package/dist/types/types.d.ts +6 -0
  22. package/dist/types/usage/google-antigravity.d.ts +12 -1
  23. package/dist/types/usage.d.ts +29 -10
  24. package/dist/types/utils/empty-completion-retry.d.ts +14 -5
  25. package/package.json +5 -5
  26. package/src/auth/sqlite-credential-store.ts +36 -10
  27. package/src/auth-broker/remote-store.ts +200 -59
  28. package/src/auth-broker/wire-schemas.ts +3 -1
  29. package/src/auth-gateway/http.ts +28 -0
  30. package/src/auth-gateway/server.ts +62 -1
  31. package/src/auth-storage.ts +63 -18
  32. package/src/error/flags.ts +1 -0
  33. package/src/providers/amazon-bedrock.ts +9 -0
  34. package/src/providers/anthropic.ts +11 -9
  35. package/src/providers/azure-openai-responses.ts +21 -9
  36. package/src/providers/claude-code-fingerprint.ts +3 -1
  37. package/src/providers/cursor.ts +61 -29
  38. package/src/providers/ollama.ts +4 -2
  39. package/src/providers/openai-chat-server.ts +1 -12
  40. package/src/providers/openai-codex-responses.ts +101 -28
  41. package/src/providers/openai-completions.ts +69 -8
  42. package/src/providers/openai-data-uri.ts +22 -0
  43. package/src/providers/openai-responses-server-schema.ts +22 -12
  44. package/src/providers/openai-responses-server.ts +64 -23
  45. package/src/providers/openai-responses.ts +9 -7
  46. package/src/providers/openai-shared.ts +100 -57
  47. package/src/providers/pi-native-client.ts +9 -1
  48. package/src/providers/vision-guard.ts +9 -1
  49. package/src/registry/cloudflare-ai-gateway.ts +120 -16
  50. package/src/registry/deepinfra.ts +24 -0
  51. package/src/registry/oauth/anthropic.ts +2 -2
  52. package/src/registry/oauth/oauth.html +8 -2
  53. package/src/registry/oauth/openrouter.ts +120 -0
  54. package/src/registry/openrouter.ts +16 -20
  55. package/src/registry/registry.ts +4 -0
  56. package/src/registry/types.ts +3 -0
  57. package/src/registry/yolo-auto.ts +30 -0
  58. package/src/stream.ts +9 -7
  59. package/src/types.ts +6 -0
  60. package/src/usage/google-antigravity.ts +25 -13
  61. package/src/usage/openai-codex.ts +5 -2
  62. package/src/usage/zai.ts +50 -4
  63. package/src/usage.ts +30 -4
  64. package/src/utils/empty-completion-retry.ts +75 -41
package/CHANGELOG.md CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [1.1.4] - 2026-08-26
5
+ ## [1.1.6] - 2026-08-30
6
6
 
7
- ### Changed
7
+ - 同步上游 OMP v18.0.9(`cc14e04f075d`)。
8
+
9
+ ## [1.1.5] - 2026-08-26
8
10
 
9
- - 同步 1.1.4 发布线(与 1.1.3 无功能差异)。
11
+ - 同步上游 OMP v18.0.5 / v18.0.6:新增 Yolo-Auto / OpenRouter 浏览器登录与 DeepInfra 支持,空补全重试重构(withReplaySafeStreamRetry)。
10
12
 
11
13
  ## [1.1.3] - 2026-08-25
12
14
 
package/README.md CHANGED
@@ -60,6 +60,7 @@ Unified LLM API with automatic model discovery, provider configuration, token an
60
60
  - **NVIDIA** (requires `NVIDIA_API_KEY`)
61
61
  - **NanoGPT** (requires `NANO_GPT_API_KEY`)
62
62
  - **Novita** (requires `NOVITA_API_KEY`)
63
+ - **DeepInfra** (requires `DEEPINFRA_API_KEY`)
63
64
  - **Hugging Face Inference**
64
65
  - **xAI**
65
66
  - **Venice** (requires `VENICE_API_KEY`)
@@ -75,7 +76,7 @@ Unified LLM API with automatic model discovery, provider configuration, token an
75
76
  - **Qwen Portal** (supports `QWEN_OAUTH_TOKEN` or `QWEN_PORTAL_API_KEY`)
76
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)
77
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.
78
- - **Cloudflare AI Gateway** (requires `CLOUDFLARE_AI_GATEWAY_API_KEY` and provider-specific gateway base URL)
79
+ - **Cloudflare AI Gateway** (supports `/login cloudflare-ai-gateway`, or `CLOUDFLARE_AI_GATEWAY_API_KEY` with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_GATEWAY_ID`)
79
80
  - **Ollama** (local OpenAI-compatible runtime; optional `OLLAMA_API_KEY`)
80
81
  - **Ollama Cloud** (hosted native Ollama API; requires `OLLAMA_CLOUD_API_KEY`)
81
82
  - **llama.cpp** (local OpenAI and Anthropic compatible inference server)
@@ -943,6 +944,7 @@ In Node.js environments, you can set environment variables to avoid passing API
943
944
  | NVIDIA | `NVIDIA_API_KEY` |
944
945
  | NanoGPT | `NANO_GPT_API_KEY` |
945
946
  | Novita | `NOVITA_API_KEY` |
947
+ | DeepInfra | `DEEPINFRA_API_KEY` |
946
948
  | Venice | `VENICE_API_KEY` |
947
949
  | Moonshot | `MOONSHOT_API_KEY` |
948
950
  | xAI | `XAI_API_KEY` |
@@ -958,11 +960,10 @@ In Node.js environments, you can set environment variables to avoid passing API
958
960
  | Xiaomi MiMo | `XIAOMI_API_KEY` |
959
961
  | ZenMux | `ZENMUX_API_KEY` |
960
962
  | vLLM | `VLLM_API_KEY` |
961
- | Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` |
963
+ | Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` + `CLOUDFLARE_ACCOUNT_ID` + `CLOUDFLARE_GATEWAY_ID` |
962
964
  | GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
963
965
 
964
- For Cloudflare AI Gateway models, use provider base URL format
965
- `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.
966
967
 
967
968
  For Anthropic Foundry routing, set `CLAUDE_CODE_USE_FOUNDRY=true` plus:
968
969
  `FOUNDRY_BASE_URL`, `ANTHROPIC_FOUNDRY_API_KEY`, optional `ANTHROPIC_CUSTOM_HEADERS`,
@@ -983,6 +984,7 @@ Provider endpoint defaults for the current OpenAI-compatible integrations:
983
984
  - NVIDIA: `https://integrate.api.nvidia.com/v1`
984
985
  - NanoGPT: `https://nano-gpt.com/api/v1`
985
986
  - Novita: `https://api.novita.ai/openai/v1`
987
+ - DeepInfra: `https://api.deepinfra.com/v1/openai`
986
988
  - Hugging Face Inference: `https://router.huggingface.co/v1`
987
989
  - Venice: `https://api.venice.ai/api/v1`
988
990
  - Xiaomi MiMo: `https://api.xiaomimimo.com/anthropic`
@@ -993,7 +995,7 @@ Provider endpoint defaults for the current OpenAI-compatible integrations:
993
995
  - Ollama: local OpenAI-compatible runtime (`http://127.0.0.1:11434/v1`)
994
996
  - Ollama Cloud: native Ollama API host (`https://ollama.com/api`, configured here as base URL `https://ollama.com`)
995
997
  - LiteLLM: `http://localhost:4000/v1`
996
- - Cloudflare AI Gateway: `https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/anthropic`
998
+ - Cloudflare AI Gateway: native Anthropic, OpenAI, and Workers AI routes under `https://gateway.ai.cloudflare.com/v1/<account>/<gateway>`
997
999
  - Qwen Portal: `https://portal.qwen.ai/v1`
998
1000
  When set, the library automatically uses these keys:
999
1001
 
@@ -1084,7 +1086,7 @@ Credentials are saved to `agent.db` in the agent directory. `/login qianfan` ope
1084
1086
 
1085
1087
  `login` supports OAuth providers (Anthropic, OpenAI Codex, GitHub Copilot, Gemini CLI, Antigravity) and API-key onboarding flows.
1086
1088
 
1087
- For the current API-key onboarding flows, the library covers Together, Moonshot, Qianfan, NVIDIA, NanoGPT, Novita, Hugging Face, Venice, Xiaomi, vLLM, LiteLLM, Cloudflare AI Gateway, Qwen Portal, and Ollama Cloud. Ollama remains the local runtime integration; set `OLLAMA_API_KEY` only when your local or self-hosted deployment enforces bearer auth.
1089
+ For the current API-key onboarding flows, the library covers Together, Moonshot, Qianfan, NVIDIA, NanoGPT, Novita, DeepInfra, Hugging Face, Venice, Xiaomi, vLLM, LiteLLM, Cloudflare AI Gateway, Qwen Portal, and Ollama Cloud. Ollama remains the local runtime integration; set `OLLAMA_API_KEY` only when your local or self-hosted deployment enforces bearer auth.
1088
1090
 
1089
1091
  ### Programmatic OAuth
1090
1092
 
@@ -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
  /**
@@ -35,6 +35,14 @@ export interface RemoteAuthCredentialStoreOptions {
35
35
  accountPool?: AuthBrokerAccountPool;
36
36
  /** Flush cadence for batched observed-usage reports. Default 10s. */
37
37
  observedUsageFlushMs?: number;
38
+ /**
39
+ * Idle window after the last foreground store use before background
40
+ * snapshot sync (SSE stream / long-poll) disconnects and parks. A parked
41
+ * store holds no timers or sockets, so an unclosed store never keeps the
42
+ * process alive longer than one idle window. Sync resumes transparently on
43
+ * the next use. Default 20s.
44
+ */
45
+ backgroundIdleMs?: number;
38
46
  }
39
47
  export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
40
48
  #private;
@@ -130,7 +138,10 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
130
138
  * a flush. One `POST /v1/usage/observed` at most per flush interval; on
131
139
  * failure the batch is retained and retried with the next flush. A 404
132
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.
133
144
  */
134
- recordObservedUsage(entries: ObservedUsageEntry[]): void;
145
+ recordObservedUsage(entries: ObservedUsageEntry[], client?: ClientUsageIdentity): void;
135
146
  close(): void;
136
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;
@@ -218,11 +218,8 @@ export declare function isInvalidThinkingSignatureError(message: string): boolea
218
218
  */
219
219
  export declare function maybeAddReplayUnsignedThinkingHint(model: Model<"anthropic-messages">, message: string): string;
220
220
  /**
221
- * Public entry: wrap the single-attempt streamer with bounded empty-completion
222
- * retries (a benign terminal stop carrying no content/usage would otherwise
223
- * stall the agent loop). The inner attempt keeps its own provider-failure retry
224
- * loop; this layer only re-issues a fresh request on an empty success. Shared
225
- * with the OpenAI-completions provider via `withEmptyCompletionRetry`.
221
+ * Public entry: retry benign empty completions before they reach the agent
222
+ * loop. The inner attempt owns Anthropic provider-failure retries.
226
223
  */
227
224
  export declare const streamAnthropic: StreamFunction<"anthropic-messages">;
228
225
  export type AnthropicSystemBlock = {
@@ -12,6 +12,9 @@ export interface AzureOpenAIResponsesOptions extends StreamOptions {
12
12
  disableReasoning?: boolean;
13
13
  }
14
14
  /**
15
- * Generate function for Azure OpenAI Responses API
15
+ * Retries transient Azure stream failures only before assistant output commits
16
+ * the attempt. The unsupported explicit prompt-cache config is rejected
17
+ * synchronously here — callers of the direct entrypoint get the immediate
18
+ * `ConfigurationError` rather than a stream whose `.result()` rejects later.
16
19
  */
17
20
  export declare const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses">;
@@ -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.220";
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.220 (external, claude-desktop)";
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. */
@@ -38,10 +38,8 @@ export interface OpenAICompletionsOptions extends StreamOptions {
38
38
  promptCache?: OpenAIPromptCacheOptions;
39
39
  }
40
40
  /**
41
- * Public entry: wrap the single-attempt streamer with bounded empty-completion
42
- * retries flaky gateways occasionally 200 with `delta: {}` + `finish_reason:
43
- * "stop"` and no usage, which would otherwise stall the agent loop. Shared with
44
- * the Anthropic provider via `withEmptyCompletionRetry`.
41
+ * Retries benign empty completions and transient provider failures only before
42
+ * assistant output commits the attempt.
45
43
  */
46
44
  export declare const streamOpenAICompletions: StreamFunction<"openai-completions">;
47
45
  export declare function parseChunkUsage(rawUsage: object, model: Model<"openai-completions">, premiumRequests: number | undefined): AssistantMessage["usage"];
@@ -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;