@linxiraos/pi-ai 1.1.23 → 1.1.24

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 (158) hide show
  1. package/CHANGELOG.md +2 -3
  2. package/THIRD-PARTY-NOTICES.txt +3 -3
  3. package/dist/types/auth/affinity.d.ts +5 -0
  4. package/dist/types/auth/cascade.d.ts +17 -6
  5. package/dist/types/auth/pool.d.ts +7 -5
  6. package/dist/types/auth/rank.d.ts +7 -1
  7. package/dist/types/auth/refresh.d.ts +8 -0
  8. package/dist/types/auth/sqlite-credential-store.d.ts +5 -0
  9. package/dist/types/auth/types.d.ts +25 -6
  10. package/dist/types/auth-broker/protocol.d.ts +12 -0
  11. package/dist/types/auth-gateway/dispatch.d.ts +7 -7
  12. package/dist/types/auth-gateway/http.d.ts +6 -3
  13. package/dist/types/auth-gateway/server.d.ts +3 -3
  14. package/dist/types/auth-gateway/types.d.ts +4 -2
  15. package/dist/types/auth-retry.d.ts +3 -1
  16. package/dist/types/dialect/rendering.d.ts +4 -0
  17. package/dist/types/images/shared.d.ts +5 -2
  18. package/dist/types/index.d.ts +1 -0
  19. package/dist/types/providers/anthropic-wire.d.ts +9 -1
  20. package/dist/types/providers/anthropic.d.ts +25 -1
  21. package/dist/types/providers/aws-sigv4.d.ts +5 -0
  22. package/dist/types/providers/bedrock-anthropic.d.ts +9 -0
  23. package/dist/types/providers/bedrock-request-metadata.d.ts +2 -0
  24. package/dist/types/providers/cursor/interaction-query.d.ts +14 -2
  25. package/dist/types/providers/cursor.d.ts +15 -13
  26. package/dist/types/providers/factory-droid/gemini.d.ts +15 -0
  27. package/dist/types/providers/factory-droid.d.ts +13 -0
  28. package/dist/types/providers/google-shared.d.ts +13 -1
  29. package/dist/types/providers/openai-chat-wire.d.ts +9 -4
  30. package/dist/types/providers/openai-codex/request-transformer.d.ts +1 -1
  31. package/dist/types/providers/openai-codex-responses.d.ts +1 -1
  32. package/dist/types/providers/openai-completions.d.ts +1 -1
  33. package/dist/types/providers/openai-responses-wire.d.ts +2 -2
  34. package/dist/types/providers/transform-messages.d.ts +7 -0
  35. package/dist/types/providers/xai-base-url.d.ts +17 -0
  36. package/dist/types/registry/oauth/device-code.d.ts +2 -2
  37. package/dist/types/registry/oauth/factory-droid.d.ts +3 -0
  38. package/dist/types/registry/oauth/types.d.ts +13 -3
  39. package/dist/types/stream.d.ts +1 -1
  40. package/dist/types/types.d.ts +21 -5
  41. package/dist/types/usage/factory-droid.d.ts +11 -0
  42. package/dist/types/usage/shared.d.ts +13 -1
  43. package/dist/types/usage.d.ts +6 -2
  44. package/dist/types/utils/event-stream.d.ts +8 -0
  45. package/dist/types/utils/http-inspector.d.ts +15 -1
  46. package/dist/types/utils/idle-iterator.d.ts +11 -8
  47. package/dist/types/utils/schema/allowlist.d.ts +2 -0
  48. package/dist/types/utils/schema/index.d.ts +1 -0
  49. package/dist/types/utils/tool-call-arguments.d.ts +9 -0
  50. package/dist/types/utils.d.ts +17 -1
  51. package/package.json +6 -6
  52. package/src/api-registry.ts +1 -0
  53. package/src/auth/affinity.ts +60 -8
  54. package/src/auth/cascade.ts +51 -11
  55. package/src/auth/health.ts +3 -0
  56. package/src/auth/oauth.ts +20 -11
  57. package/src/auth/pool.ts +10 -6
  58. package/src/auth/rank.ts +11 -1
  59. package/src/auth/refresh.ts +27 -2
  60. package/src/auth/select.ts +52 -24
  61. package/src/auth/sqlite-credential-store.ts +49 -18
  62. package/src/auth/types.ts +24 -6
  63. package/src/auth/usage-cache.ts +6 -0
  64. package/src/auth/usage.ts +10 -5
  65. package/src/auth-broker/client.ts +1 -12
  66. package/src/auth-broker/protocol.ts +32 -0
  67. package/src/auth-broker/remote-store.ts +39 -59
  68. package/src/auth-broker/server.ts +1 -20
  69. package/src/auth-broker/snapshot-cache.ts +1 -9
  70. package/src/auth-gateway/dispatch.ts +20 -20
  71. package/src/auth-gateway/http.ts +49 -7
  72. package/src/auth-gateway/routes/embeddings.ts +1 -1
  73. package/src/auth-gateway/routes/images.ts +1 -1
  74. package/src/auth-gateway/routes/rerank.ts +1 -1
  75. package/src/auth-gateway/routes/speech.ts +1 -1
  76. package/src/auth-gateway/routes/systemone.ts +2 -2
  77. package/src/auth-gateway/routes/transcriptions.ts +1 -1
  78. package/src/auth-gateway/routes/video.ts +4 -3
  79. package/src/auth-gateway/server.ts +46 -16
  80. package/src/auth-gateway/types.ts +4 -2
  81. package/src/auth-retry.ts +3 -1
  82. package/src/auth-storage.ts +3 -1
  83. package/src/dialect/anthropic.ts +3 -25
  84. package/src/dialect/deepseek.ts +2 -5
  85. package/src/dialect/harmony.ts +2 -5
  86. package/src/dialect/hermes.ts +2 -5
  87. package/src/dialect/kimi.ts +2 -5
  88. package/src/dialect/minimax.ts +3 -24
  89. package/src/dialect/owned-stream.ts +28 -3
  90. package/src/dialect/qwen3.ts +2 -5
  91. package/src/dialect/rendering.ts +18 -0
  92. package/src/dialect/xml.ts +3 -19
  93. package/src/error/flags.ts +2 -0
  94. package/src/error/rate-limit.ts +11 -0
  95. package/src/images/openai-images.ts +10 -4
  96. package/src/images/shared.ts +9 -4
  97. package/src/index.ts +1 -0
  98. package/src/providers/amazon-bedrock.ts +115 -85
  99. package/src/providers/anthropic-compaction.ts +10 -1
  100. package/src/providers/anthropic-wire.ts +12 -1
  101. package/src/providers/anthropic.ts +190 -50
  102. package/src/providers/apple-foundation-models.ts +2 -1
  103. package/src/providers/aws-sigv4.ts +1 -1
  104. package/src/providers/bedrock-anthropic.ts +30 -0
  105. package/src/providers/bedrock-request-metadata.ts +6 -0
  106. package/src/providers/connect-error-detail.ts +1 -5
  107. package/src/providers/cursor/interaction-query.ts +15 -10
  108. package/src/providers/cursor.ts +1020 -338
  109. package/src/providers/devin.ts +3 -2
  110. package/src/providers/factory-droid/droid-identity.md +1 -0
  111. package/src/providers/factory-droid/gemini.ts +538 -0
  112. package/src/providers/factory-droid.ts +623 -0
  113. package/src/providers/gitlab-duo-workflow.ts +17 -22
  114. package/src/providers/google-shared.ts +11 -5
  115. package/src/providers/ollama.ts +3 -1
  116. package/src/providers/openai-chat-wire.ts +13 -4
  117. package/src/providers/openai-codex/request-transformer.ts +1 -1
  118. package/src/providers/openai-codex-responses.ts +27 -20
  119. package/src/providers/openai-completions.ts +108 -14
  120. package/src/providers/openai-responses-wire.ts +2 -2
  121. package/src/providers/openai-shared.ts +11 -9
  122. package/src/providers/pi-native-client.ts +4 -4
  123. package/src/providers/register-builtins.ts +1 -1
  124. package/src/providers/transform-messages.ts +33 -15
  125. package/src/providers/xai-base-url.ts +32 -0
  126. package/src/registry/engine/device-code.ts +2 -2
  127. package/src/registry/engine/refresh.ts +1 -0
  128. package/src/registry/hooks/device-code.ts +1 -0
  129. package/src/registry/oauth/device-code.ts +19 -3
  130. package/src/registry/oauth/factory-droid.ts +82 -0
  131. package/src/registry/oauth/types.ts +13 -3
  132. package/src/stream.ts +40 -6
  133. package/src/types.ts +42 -6
  134. package/src/usage/claude.ts +4 -11
  135. package/src/usage/cline-pass.ts +2 -14
  136. package/src/usage/cursor.ts +12 -5
  137. package/src/usage/factory-droid.ts +226 -0
  138. package/src/usage/openai-codex.ts +3 -5
  139. package/src/usage/registry.ts +3 -0
  140. package/src/usage/shared.ts +28 -1
  141. package/src/usage/synthetic.ts +4 -40
  142. package/src/usage/umans.ts +8 -36
  143. package/src/usage/xai-oauth.ts +21 -8
  144. package/src/usage/zai.ts +10 -38
  145. package/src/usage.ts +6 -2
  146. package/src/utils/event-stream.ts +13 -0
  147. package/src/utils/http-inspector.ts +67 -11
  148. package/src/utils/idle-iterator.ts +29 -24
  149. package/src/utils/proxy.ts +8 -4
  150. package/src/utils/schema/CONSTRAINTS.md +15 -0
  151. package/src/utils/schema/allowlist.ts +160 -0
  152. package/src/utils/schema/index.ts +1 -0
  153. package/src/utils/schema/json-schema-validator.ts +23 -26
  154. package/src/utils/schema/meta-validator.ts +4 -7
  155. package/src/utils/schema/wire.ts +17 -21
  156. package/src/utils/tool-call-arguments.ts +32 -0
  157. package/src/utils/validation.ts +2 -6
  158. package/src/utils.ts +114 -4
package/CHANGELOG.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [1.1.23] - 2026-10-01
5
+ ## [1.1.24] - 2026-10-03
6
6
 
7
- ## [1.1.22] - 2026-09-30
7
+ - 网关身份头统一 `x-zeta-*`(消费方同步);新增 `extractHttpStatusFromError`/`extractRetryHint` 导出。
8
8
 
9
- - 随 1.1.22 版本线发布;无面向用户的行为变化。
@@ -1,7 +1,7 @@
1
- OMP THIRD-PARTY NOTICES
1
+ ZETA THIRD-PARTY NOTICES
2
2
  =======================
3
3
 
4
- This generated, self-contained aggregate accompanies OMP release artifacts.
4
+ This generated, self-contained aggregate accompanies Zeta release artifacts.
5
5
  It does not replace package-level license files. First-party licensing grants
6
6
  no rights in third-party code, fonts, data, or marks identified below.
7
7
 
@@ -1046,7 +1046,7 @@ These packages participate only in generation/web build tooling and are not ship
1046
1046
 
1047
1047
  SCOPED NON-PERMISSIVE PACKAGES
1048
1048
  ------------------------------
1049
- The exact @img/sharp-libvips-* 1.2.4 all-target family is LGPL-3.0-or-later. It is not distributed in OMP npm bundles or standalone assets: @huggingface/transformers is always external, installed into a user-side versioned runtime on demand, and sharp is stubbed for speech/text. The dynamically loaded native library remains replaceable. Corresponding source is available from https://github.com/lovell/sharp-libvips.git and upstream libvips sources.
1049
+ The exact @img/sharp-libvips-* 1.2.4 all-target family is LGPL-3.0-or-later. It is not distributed in Zeta npm bundles or standalone assets: @huggingface/transformers is always external, installed into a user-side versioned runtime on demand, and sharp is stubbed for speech/text. The dynamically loaded native library remains replaceable. Corresponding source is available from https://github.com/lovell/sharp-libvips.git and upstream libvips sources.
1050
1050
 
1051
1051
  lightningcss 1.32.0 and its exact target leaves are MPL-2.0 build-only dependencies. MPL is not globally allowed and these packages are absent from runtime artifacts.
1052
1052
 
@@ -26,6 +26,11 @@ export declare class SessionAffinity implements SessionsApi {
26
26
  * `lastUsedAtMs` backdates the sticky (session-file pin restores on resume);
27
27
  * it defaults to now for live selections. Automatic re-recording of the same
28
28
  * durable row preserves an explicit user pin.
29
+ *
30
+ * The in-memory sticky is always exact. The persisted row is rewritten only
31
+ * when the credential, its type, or explicitness changes, or when the stored
32
+ * last-use drifts by {@link SESSION_STICKY_PERSIST_INTERVAL_MS} — per-request
33
+ * rewrites were pure database churn.
29
34
  */
30
35
  record(provider: string, sessionId: string | undefined, type: AuthCredential["type"], index: number, lastUsedAtMs?: number, explicit?: boolean): void;
31
36
  /** Retrieves the last credential used by a session. */
@@ -2,7 +2,7 @@ import { type ApiKeyResolver, type ResolvedApiKey } from "../auth-retry.js";
2
2
  import type { SessionAffinity } from "./affinity.js";
3
3
  import type { CredentialPool } from "./pool.js";
4
4
  import type { CredentialSelector } from "./select.js";
5
- import type { AuthApiKeyOptions, AuthCredential, AuthSource, AuthSourceOptions, KeysApi, LimitsApi } from "./types.js";
5
+ import type { AuthApiKeyOptions, AuthCredential, AuthSource, AuthSourceOptions, KeysApi, LimitsApi, OAuthRequestIdentity } from "./types.js";
6
6
  /** Runtime (--api-key) and config (models.yml) key overrides plus the config-value resolver. */
7
7
  export declare class KeyOverrides {
8
8
  #private;
@@ -10,6 +10,8 @@ export declare class KeyOverrides {
10
10
  has(provider: string): boolean;
11
11
  runtimeKey(provider: string): string | undefined;
12
12
  configKey(provider: string): string | undefined;
13
+ /** Config value consulted only after stored OAuth/login credentials. */
14
+ fallbackKey(provider: string): string | undefined;
13
15
  /** Resolve a config value (env var name, "!command", literal) to the secret. */
14
16
  resolve(config: string): Promise<string | undefined>;
15
17
  /**
@@ -30,10 +32,17 @@ export declare class KeyOverrides {
30
32
  *
31
33
  * Lower priority than {@link KeyOverrides.setRuntime} so a CLI `--api-key`
32
34
  * still wins for the duration of a single invocation.
35
+ *
36
+ * `fallback: true` instead ranks the value below stored OAuth and `/login`
37
+ * credentials (at the env-var tier). Providers that own a `/login` flow use
38
+ * this so their default key reference (e.g. an unset env-var name, which
39
+ * resolves to its literal text) cannot shadow the key the user logged in with.
33
40
  */
34
- setConfig(provider: string, apiKeyConfig: string): void;
41
+ setConfig(provider: string, apiKeyConfig: string, options?: {
42
+ fallback?: boolean;
43
+ }): void;
35
44
  /**
36
- * Remove a single config-sourced API key override.
45
+ * Remove a single config-sourced API key (override or fallback).
37
46
  */
38
47
  removeConfig(provider: string): void;
39
48
  /**
@@ -85,7 +94,7 @@ export declare class KeyCascade implements KeysApi {
85
94
  /**
86
95
  * Classify where a provider's auth comes from, following the same precedence
87
96
  * as {@link KeyCascade.get}: runtime override → config override →
88
- * stored OAuth → login-stored api_key → env var → stored api_key.
97
+ * stored OAuth → login-stored api_key → config fallback → env var → stored api_key.
89
98
  * Returns undefined when no auth is configured.
90
99
  *
91
100
  * Compact, structured counterpart to {@link KeyCascade.describe}; `env`
@@ -107,7 +116,7 @@ export declare class KeyCascade implements KeysApi {
107
116
  * Priority (first match wins): runtime override, config override, OAuth,
108
117
  * login API key, environment variable, then another stored API key.
109
118
  */
110
- get(provider: string, sessionId?: string, options?: AuthApiKeyOptions, onCredentialId?: (id: number) => void): Promise<string | undefined>;
119
+ get(provider: string, sessionId?: string, options?: AuthApiKeyOptions, onCredentialId?: (id: number, identity?: OAuthRequestIdentity) => void): Promise<string | undefined>;
111
120
  /**
112
121
  * Build an {@link ApiKeyResolver} backed by this storage, implementing the
113
122
  * central a/b/c auth-retry policy:
@@ -140,7 +149,9 @@ export declare class KeyCascade implements KeysApi {
140
149
  describe(provider: string, sessionId?: string): string | undefined;
141
150
  setRuntime(provider: string, apiKey: string): void;
142
151
  removeRuntime(provider: string): void;
143
- setConfig(provider: string, apiKeyConfig: string): void;
152
+ setConfig(provider: string, apiKeyConfig: string, options?: {
153
+ fallback?: boolean;
154
+ }): void;
144
155
  removeConfig(provider: string): void;
145
156
  clearConfig(): void;
146
157
  setResolver(resolver: (config: string) => Promise<string | undefined>): void;
@@ -46,10 +46,10 @@ export declare class CredentialPool implements CredentialsApi {
46
46
  /**
47
47
  * Adopt credentials another process committed before selecting or rotating.
48
48
  *
49
- * The store is shared across every omp process, but the pool is an
49
+ * The store is shared across every zeta process, but the pool is an
50
50
  * in-process cache refreshed only by this process's own writes. Without
51
51
  * this a long-running session ranks a stale pool for its whole lifetime:
52
- * `omp auth` in another terminal is invisible, rotation reports no usable
52
+ * `zeta-c auth` in another terminal is invisible, rotation reports no usable
53
53
  * sibling while a freshly added account sits unblocked in SQLite, and the
54
54
  * turn degrades to the fallback chain. The auth-broker path already polls;
55
55
  * direct-store sessions had no equivalent.
@@ -116,7 +116,9 @@ export declare class CredentialPool implements CredentialsApi {
116
116
  /**
117
117
  * Persist a refreshed credential by id only while the row still matches this
118
118
  * process's snapshot. A peer rotation wins the CAS and is reloaded instead of
119
- * being overwritten after this process releases its refresh lease.
119
+ * being overwritten after this process releases its refresh lease. An
120
+ * unchanged credential still runs the CAS check (stores skip rewriting
121
+ * identical bytes), so peer rotations are detected without churning the row.
120
122
  *
121
123
  * Returns the row's current index, or -1 when it was disabled or removed.
122
124
  */
@@ -176,7 +178,7 @@ export declare class CredentialPool implements CredentialsApi {
176
178
  */
177
179
  snapshot(): AuthCredentialSnapshot;
178
180
  /**
179
- * Disabled credential tombstones for display surfaces (`omp usage`,
181
+ * Disabled credential tombstones for display surfaces (`zeta-c usage`,
180
182
  * broker `GET /v1/credentials/disabled`). Empty when the backing store
181
183
  * keeps no tombstones or the remote broker predates the endpoint.
182
184
  */
@@ -185,7 +187,7 @@ export declare class CredentialPool implements CredentialsApi {
185
187
  * Force the backing store to revalidate its credential snapshot, then
186
188
  * reload. Remote broker stores re-fetch the snapshot; local stores are
187
189
  * always current, so only the reload runs. Callers that pair live
188
- * per-credential data with stored identities (`omp usage`) use this so a
190
+ * per-credential data with stored identities (`zeta-c usage`) use this so a
189
191
  * disk-cached snapshot cannot misattribute fresh reports.
190
192
  */
191
193
  revalidate(): Promise<void>;
@@ -18,6 +18,11 @@ export type UsageCandidate<T extends AuthCredential> = {
18
18
  inReserve?: boolean;
19
19
  /** True only when reserve ranking had a usable remaining-fraction measurement. */
20
20
  reserveMeasured?: boolean;
21
+ /**
22
+ * Present after ranking: the account's renewable allowance for this request is
23
+ * spent, so if it still serves it draws on paid overage such as Codex credits.
24
+ */
25
+ allowanceSpent?: boolean;
21
26
  };
22
27
  /** OAuth credential eligible for usage ranking. */
23
28
  export type OAuthCandidate = UsageCandidate<OAuthCredential>;
@@ -35,6 +40,7 @@ export type UsageRankedCandidate<T extends AuthCredential> = UsageCandidate<T> &
35
40
  reserveMeasured?: boolean;
36
41
  accountPriority: number;
37
42
  hasPriorityBoost: boolean;
43
+ allowanceSpent: boolean;
38
44
  usageMeasured: boolean;
39
45
  planPriority: number;
40
46
  secondaryUsed: number;
@@ -49,5 +55,5 @@ export type RankedOAuthCandidate = UsageRankedCandidate<OAuthCredential>;
49
55
  export type RankedApiKeyCandidate = UsageRankedCandidate<ApiKeyCredential>;
50
56
  /** Rank accounts by model-plan eligibility when a plan gate applies. */
51
57
  export declare function planPriority(gate: PlanGate | undefined, report: UsageReport | null): number;
52
- /** Sort ranked candidates by blocks, plan, reserve, boost, hot window, usage and drain. */
58
+ /** Sort ranked candidates by blocks, plan, spent allowance, reserve, boost, hot window, usage and drain. */
53
59
  export declare function orderUsageRankedCandidates<T extends AuthCredential>(candidates: UsageRankedCandidate<T>[], planGated: boolean): UsageCandidate<T>[];
@@ -17,6 +17,13 @@ import { type AuthCredentialSnapshotEntry, type AuthStorageOptions, type OAuthCr
17
17
  * the rotation cadence by <4%.
18
18
  */
19
19
  export declare const OAUTH_REFRESH_SKEW_MS = 60000;
20
+ type OrganizationScope = Pick<OAuthCredentials, "orgId" | "region" | "inferenceRegion" | "activeOrganizationId" | "orgName">;
21
+ /**
22
+ * Organization-scoped identity after a refresh: refreshed values win; stored
23
+ * org/residency/inference scope carries over only while the organization is
24
+ * unchanged. The WorkOS selection always falls back to the stored one.
25
+ */
26
+ export declare function mergeRefreshedOrganizationScope(current: OrganizationScope, refreshed: OrganizationScope): OrganizationScope;
20
27
  /** Merge provider refresh bytes with the stored OAuth row, preserving subtype metadata for every refresh path. */
21
28
  export declare function mergeRefreshedCredential<T extends OAuthCredential>(current: T, refreshed: OAuthCredentials): T;
22
29
  /** Dependencies for lease-guarded OAuth refresh. */
@@ -57,3 +64,4 @@ export declare class OAuthRefresher {
57
64
  */
58
65
  refreshById(id: number, signal?: AbortSignal, options?: OAuthRefreshByIdOptions): Promise<AuthCredentialSnapshotEntry>;
59
66
  }
67
+ export {};
@@ -36,6 +36,11 @@ export declare class SqliteAuthCredentialStore implements AuthCredentialStore {
36
36
  listDisabledCredentials(provider?: string): Promise<DisabledCredentialSummary[]>;
37
37
  replaceAuthCredentials(provider: string, credentials: AuthCredential[]): Promise<StoredAuthCredential[]>;
38
38
  upsertAuthCredential(provider: string, credential: AuthCredential): Promise<StoredAuthCredential[]>;
39
+ /**
40
+ * Rewrites a row only when its persisted bytes change: an identical write would
41
+ * still bump `updated_at` and `auth_change_revision`, making every peer process
42
+ * reload credentials for nothing.
43
+ */
39
44
  updateAuthCredential(id: number, credential: AuthCredential): void;
40
45
  tryUpdateAuthCredentialIfMatches(id: number, expectedData: string, credential: AuthCredential, lease?: CredentialRefreshLeaseFence): boolean;
41
46
  deleteAuthCredential(id: number, disabledCause: string): Promise<boolean>;
@@ -80,7 +80,7 @@ export interface StoredCredentialBlock {
80
80
  /**
81
81
  * Identity slice of a disabled (soft-deleted) credential tombstone — cause and
82
82
  * account identity only, never token material. Surfaced so auto-disabled
83
- * accounts (e.g. an expired Anthropic OAuth grant) stay visible in `omp usage`
83
+ * accounts (e.g. an expired Anthropic OAuth grant) stay visible in `zeta-c usage`
84
84
  * instead of silently vanishing until the user notices missing quota.
85
85
  */
86
86
  export interface DisabledCredentialSummary {
@@ -180,6 +180,9 @@ export type CompletionProbeCredential = {
180
180
  email?: string;
181
181
  enterpriseUrl?: string;
182
182
  apiEndpoint?: string;
183
+ orgId?: string;
184
+ region?: string;
185
+ inferenceRegion?: "global" | "eu" | "us";
183
186
  };
184
187
  /**
185
188
  * Caller-supplied bearer probe. Receives the post-refresh credential for a
@@ -318,7 +321,7 @@ export type AuthStorageOptions = {
318
321
  *
319
322
  * Examples:
320
323
  * - `"local ~/.zeta/agent/agent.db"`
321
- * - `"broker http://omp.internal:8765"`
324
+ * - `"broker http://zeta.internal:8765"`
322
325
  */
323
326
  sourceLabel?: string;
324
327
  };
@@ -422,6 +425,12 @@ export type AuthApiKeyOptions = {
422
425
  /** Explicit provider-401 recovery; generic force refreshes leave this unset. */
423
426
  refreshReason?: OAuthRefreshReason;
424
427
  };
428
+ /** Non-secret identity bound to the OAuth credential selected for one request attempt. */
429
+ export interface OAuthRequestIdentity {
430
+ orgId?: string;
431
+ region?: string;
432
+ inferenceRegion?: "global" | "eu" | "us";
433
+ }
425
434
  /**
426
435
  * Refreshed OAuth access plus identity metadata returned by
427
436
  * {@link AuthStorage.oauth.access}. Callers that authenticate via a bearer
@@ -441,6 +450,8 @@ export interface OAuthAccess {
441
450
  /** Organization/workspace the credential is scoped to (Anthropic/ChatGPT multi-subscription). */
442
451
  orgId?: string;
443
452
  orgName?: string;
453
+ region?: string;
454
+ inferenceRegion?: "global" | "eu" | "us";
444
455
  }
445
456
  /**
446
457
  * Identity slice of the credential a successful {@link AuthStorage.oauth.login}
@@ -504,6 +515,8 @@ export interface OAuthAccountSummary {
504
515
  orgName?: string;
505
516
  /** True when this account is the session-sticky OAuth credential requested by `listOAuthAccounts`. */
506
517
  active: boolean;
518
+ /** Last use recorded on the session sticky; set only on the `active` account. */
519
+ lastUsedAtMs?: number;
507
520
  }
508
521
  /** Scope a matching-key invalidation to a session or signal. */
509
522
  export interface InvalidateCredentialMatchingOptions {
@@ -710,7 +723,7 @@ export interface CredentialsApi {
710
723
  * Force the backing store to revalidate its credential snapshot, then
711
724
  * reload. Remote broker stores re-fetch the snapshot; local stores are
712
725
  * always current, so only the reload runs. Callers that pair live
713
- * per-credential data with stored identities (`omp usage`) use this so a
726
+ * per-credential data with stored identities (`zeta-c usage`) use this so a
714
727
  * disk-cached snapshot cannot misattribute fresh reports.
715
728
  */
716
729
  revalidate(): Promise<void>;
@@ -769,7 +782,7 @@ export interface CredentialsApi {
769
782
  */
770
783
  disable(id: number, disabledCause: string): Promise<boolean>;
771
784
  /**
772
- * Disabled credential tombstones for display surfaces (`omp usage`,
785
+ * Disabled credential tombstones for display surfaces (`zeta-c usage`,
773
786
  * broker `GET /v1/credentials/disabled`). Empty when the backing store
774
787
  * keeps no tombstones or the remote broker predates the endpoint.
775
788
  */
@@ -848,10 +861,16 @@ export interface KeysApi {
848
861
  *
849
862
  * Lower priority than {@link setRuntimeApiKey} so a CLI `--api-key`
850
863
  * still wins for the duration of a single invocation.
864
+ *
865
+ * `fallback: true` ranks the value below stored OAuth and `/login`
866
+ * credentials instead, so a provider's default key reference cannot shadow
867
+ * a key the user logged in with.
851
868
  */
852
- setConfig(provider: string, apiKeyConfig: string): void;
869
+ setConfig(provider: string, apiKeyConfig: string, options?: {
870
+ fallback?: boolean;
871
+ }): void;
853
872
  /**
854
- * Remove a single config-sourced API key override.
873
+ * Remove a single config-sourced API key (override or fallback).
855
874
  */
856
875
  removeConfig(provider: string): void;
857
876
  /**
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Auth-broker wire-protocol helpers shared by the server and the client store.
3
+ */
4
+ import type { CredentialBlockSnapshot } from "./types.js";
5
+ /** Parse a snapshot `ETag` / `If-None-Match` value (`"N"`, `W/"N"`, or bare `N`) into a generation. */
6
+ export declare function parseGenerationTag(header: string | null): number | undefined;
7
+ /**
8
+ * Canonical order for a credential's block snapshots. The server and the client
9
+ * store both sort with it, because block lists are compared positionally; the
10
+ * `updatedAtMs` tiebreak keeps otherwise-identical blocks in one stable order.
11
+ */
12
+ export declare function compareCredentialBlockSnapshots(a: CredentialBlockSnapshot, b: CredentialBlockSnapshot): number;
@@ -1,4 +1,4 @@
1
- import type { ApiKeyResolver } from "../auth-retry.js";
1
+ import type { ApiKeyResolver, ResolvedApiKey } from "../auth-retry.js";
2
2
  import type { AuthStorage } from "../auth-storage.js";
3
3
  import { type GatewayErrorClassification } from "../error/gateway.js";
4
4
  import type { Api, FetchImpl, Model, Usage } from "../types.js";
@@ -42,12 +42,12 @@ export declare function resolveGatewayAccount(storage: AuthStorage, provider: st
42
42
  * Resolve the credential for one request from broker-backed storage.
43
43
  *
44
44
  * pi-ai clients never consult `AuthStorage`; the gateway resolves the bearer
45
- * (an OAuth access token refreshed through the broker when needed) and hands
46
- * it to the client. Returns the key, or the error classification the route
47
- * should encode in its own envelope: storage failures map through
48
- * {@link classifyGatewayError}, a provider without any credential is a 401.
45
+ * and its OAuth identity together (refreshing through the broker when needed).
46
+ * Keep this selection snapshot intact even if another request replaces the
47
+ * stored token before dispatch. Storage failures map through
48
+ * {@link classifyGatewayError}; a provider without any credential is a 401.
49
49
  */
50
- export declare function resolveGatewayApiKey(storage: AuthStorage, model: Model<Api>, sessionId: string, signal: AbortSignal, peer: string): Promise<string | GatewayErrorClassification>;
50
+ export declare function resolveGatewayApiKey(storage: AuthStorage, model: Model<Api>, sessionId: string, signal: AbortSignal, peer: string): Promise<ResolvedApiKey | GatewayErrorClassification>;
51
51
  /**
52
52
  * Build the {@link ApiKeyResolver} handed to a pi-ai client for a gateway
53
53
  * request. Drives the central a/b/c auth-retry policy server-side:
@@ -63,7 +63,7 @@ export declare function resolveGatewayApiKey(storage: AuthStorage, model: Model<
63
63
  * routes that retain provider session state use it to re-key the account
64
64
  * lease, one-shot routes pass `undefined`.
65
65
  */
66
- export declare function buildGatewayApiKeyResolver(storage: AuthStorage, model: Model<Api>, sessionId: string, initialKey: string, requestSignal: AbortSignal, format: string, peer: string, onResolvedKey?: (apiKey: string) => void): ApiKeyResolver;
66
+ export declare function buildGatewayApiKeyResolver(storage: AuthStorage, model: Model<Api>, sessionId: string, initialKey: ResolvedApiKey, requestSignal: AbortSignal, format: string, peer: string, onResolvedKey?: (apiKey: string) => void): ApiKeyResolver;
67
67
  /**
68
68
  * Attribute one settled upstream request to the originating client via the
69
69
  * broker's observed-usage channel (`AuthStorage.usage.observe`, batched
@@ -16,7 +16,10 @@ export declare function gatewayResponseHeaders(model: Model<Api>, info: {
16
16
  costUsd?: number;
17
17
  startedAt?: number;
18
18
  }): Record<string, string>;
19
- export declare function resolvePeer(req: Request): string;
19
+ /** Use the socket peer unless the gateway explicitly trusts its reverse proxy. */
20
+ export declare function resolvePeer(req: Request, socketAddress: string, trustProxyHeaders?: boolean): string;
21
+ /** Keep configured gateway credentials out of URL and forwarded/logged request fields. */
22
+ export declare function hasMisplacedBearer(req: Request, url: URL, tokens: ReadonlySet<string>): boolean;
20
23
  /**
21
24
  * Constant-time byte comparison. Falls back to a manual XOR accumulator if
22
25
  * `node:crypto.timingSafeEqual` isn't available. Always processes every byte
@@ -33,8 +36,8 @@ export declare function captureRequestHeaders(headers: Headers): Record<string,
33
36
  /**
34
37
  * Resolve the usage-attribution identity for an inbound gateway request.
35
38
  *
36
- * pi-native omp clients send `x-omp-install-id` / `x-omp-hostname` /
37
- * `x-omp-app` (see `providers/pi-native-client.ts`); any client may set them.
39
+ * pi-native zeta clients send `x-zeta-install-id` / `x-zeta-hostname` /
40
+ * `x-zeta-app` (see `providers/pi-native-client.ts`); any client may set them.
38
41
  * Requests without an install id fall back to the gateway host's identity
39
42
  * under the `gateway` app label, so unlabeled foreign-SDK traffic (llm-git,
40
43
  * openai/anthropic SDKs) still lands in per-client burn tracking instead of
@@ -1,12 +1,12 @@
1
1
  /**
2
- * omp auth-gateway HTTP server.
2
+ * zeta-c auth-gateway HTTP server.
3
3
  *
4
4
  * Accepts any provider-format request (OpenAI chat-completions, Anthropic
5
5
  * messages, OpenAI Responses) and dispatches through pi-ai's `streamSimple()`
6
6
  * — which handles credential injection, anthropic-beta headers, codex
7
7
  * websocket transport, and all the per-provider intricacies. The gateway is
8
- * pure protocol translation: foreign wire → omp Context → pi-ai stream() →
9
- * omp events → foreign wire.
8
+ * pure protocol translation: foreign wire → zeta Context → pi-ai stream() →
9
+ * zeta events → foreign wire.
10
10
  *
11
11
  * Endpoints:
12
12
  * GET /healthz → unauth; ok + version
@@ -1,9 +1,9 @@
1
1
  import type { Effort } from "@linxiraos/pi-catalog/effort";
2
2
  import type { AssistantMessage, AssistantMessageEventStream, CacheRetention, Context, OpenAIResponseInclude, ServiceTier, TokenTaskBudget } from "../types.js";
3
3
  /**
4
- * Wire types for the omp auth-gateway.
4
+ * Wire types for the zeta-c auth-gateway.
5
5
  *
6
- * The gateway sits between unauthenticated clients (containerized omp,
6
+ * The gateway sits between unauthenticated clients (containerized zeta,
7
7
  * llm-git, …) and the broker. It accepts provider-format HTTP requests
8
8
  * (OpenAI chat-completions / Anthropic messages / OpenAI Responses),
9
9
  * dispatches them through pi-ai's `streamSimple()`, and translates the
@@ -125,6 +125,8 @@ export interface AuthGatewayServerOptions {
125
125
  bind?: string;
126
126
  /** Accept any of these bearer tokens. Empty allows unauthenticated calls. */
127
127
  bearerTokens: string[];
128
+ /** Honor forwarded peer headers only when the connecting proxy is trusted. Default false. */
129
+ trustProxyHeaders?: boolean;
128
130
  /** Version surfaced on `/healthz`. */
129
131
  version?: string;
130
132
  }
@@ -1,4 +1,4 @@
1
- import type { LimitsApi, OAuthAccess, OAuthApi } from "./auth/types.js";
1
+ import type { LimitsApi, OAuthAccess, OAuthApi, OAuthRequestIdentity } from "./auth/types.js";
2
2
  import { isAuthRetryableError } from "./error/auth-classify.js";
3
3
  /**
4
4
  * Context passed to an {@link ApiKeyResolver} on each resolution attempt.
@@ -42,6 +42,8 @@ export interface ResolvedApiKey {
42
42
  * already sent it before that block.
43
43
  */
44
44
  afterSiblingWait?: boolean;
45
+ /** Non-secret request scope belonging to this bearer, replaced on account rotation. */
46
+ oauthIdentity?: OAuthRequestIdentity;
45
47
  }
46
48
  export type ApiKeyResolution = string | ResolvedApiKey | undefined;
47
49
  export type ApiKeyResolver = (ctx: ApiKeyResolveContext) => Promise<ApiKeyResolution> | ApiKeyResolution;
@@ -1,4 +1,5 @@
1
1
  import type { AssistantMessage, Message, ToolCall } from "../types.js";
2
+ import { type ToolArgShape } from "./coercion.js";
2
3
  import type { DialectRenderOptions, DialectToolResult } from "./types.js";
3
4
  export declare function renderToolResponseResults(results: readonly DialectToolResult[]): string;
4
5
  export declare function kimiCallId(name: string, id: string, index: number): string;
@@ -15,6 +16,9 @@ export declare function pyCall(name: string, args: Record<string, unknown>): str
15
16
  export declare function pyValue(value: unknown): string;
16
17
  export declare function escapeXmlAttr(value: string): string;
17
18
  export declare function escapeXmlText(value: string): string;
19
+ /** Render one Anthropic-style `<invoke>`; declared string args stay raw, everything else is JSON. */
20
+ export declare function renderInvoke(call: ToolCall, shape: ToolArgShape | undefined): string;
21
+ export declare function renderInvokes(calls: readonly ToolCall[], tools: NonNullable<DialectRenderOptions["tools"]>): string;
18
22
  export type AssistantTranscriptParts = {
19
23
  readonly text: string;
20
24
  readonly thinking: string;
@@ -10,9 +10,11 @@ export declare function usageFromWire(value: unknown): Usage;
10
10
  export declare function imageBaseUrl(model: Model): string;
11
11
  export declare function modelHeaders(model: Model, signal?: AbortSignal): Promise<Record<string, string>>;
12
12
  export declare function errorMessage(rawText: string): string;
13
+ /** Request URL, or a builder for routes that depend on the bearer (xAI's `XAI_BASE_URL` rule). */
14
+ type ImageRequestUrl = string | ((bearer: string) => string);
13
15
  export declare function postJson(options: {
14
16
  model: Model;
15
- url: string;
17
+ url: ImageRequestUrl;
16
18
  body: unknown;
17
19
  apiKey: ApiKey;
18
20
  fetch: FetchImpl;
@@ -20,7 +22,7 @@ export declare function postJson(options: {
20
22
  }): Promise<unknown>;
21
23
  export declare function postMultipart(options: {
22
24
  model: Model;
23
- url: string;
25
+ url: ImageRequestUrl;
24
26
  body: FormData;
25
27
  apiKey: ApiKey;
26
28
  fetch: FetchImpl;
@@ -32,3 +34,4 @@ export declare function decodeImageResponse(value: unknown, fetch: FetchImpl, si
32
34
  }>;
33
35
  export declare function toDataUrl(image: GeneratedImage): string;
34
36
  export declare function resolveOpenAIImageSize(aspectRatio?: string, imageSize?: string): string | undefined;
37
+ export {};
@@ -45,6 +45,7 @@ export * from "./usage.js";
45
45
  export * from "./usage/claude.js";
46
46
  export * from "./usage/claude-reset.js";
47
47
  export * from "./usage/cursor.js";
48
+ export * from "./usage/factory-droid.js";
48
49
  export * from "./usage/gemini.js";
49
50
  export * from "./usage/github-copilot.js";
50
51
  export * from "./usage/google-antigravity.js";
@@ -225,7 +225,15 @@ export type ThinkingConfigAdaptive = {
225
225
  /** Preserved-thinking prefix mismatch policy. */
226
226
  block_binding?: ThinkingBlockBinding;
227
227
  };
228
- export type ThinkingConfigParam = ThinkingConfigEnabled | ThinkingConfigDisabled | ThinkingConfigAdaptive;
228
+ /**
229
+ * Sonnet 5.5's replacement for `disabled`: no up-front thinking, progress
230
+ * updates between tool calls only. Takes no other field, and effort above
231
+ * `high` is rejected alongside it.
232
+ */
233
+ export type ThinkingConfigBetweenTools = {
234
+ type: "between_tools";
235
+ };
236
+ export type ThinkingConfigParam = ThinkingConfigEnabled | ThinkingConfigDisabled | ThinkingConfigAdaptive | ThinkingConfigBetweenTools;
229
237
  export type OutputConfig = {
230
238
  /** Adaptive-thinking effort level (effort beta). */
231
239
  effort?: "low" | "medium" | "high" | "xhigh" | "max" | null;
@@ -217,13 +217,37 @@ type SystemBlockOptions = {
217
217
  export declare function buildAnthropicSystemBlocks(systemPrompt: readonly string[] | undefined, options?: SystemBlockOptions): AnthropicSystemBlock[] | undefined;
218
218
  export declare function normalizeExtraBetas(betas?: string[] | string): string[];
219
219
  export declare function buildAnthropicClientOptions(args: AnthropicClientOptionsArgs): AnthropicClientOptionsResult;
220
+ /**
221
+ * True when enabled thinking on `model` is budget thinking
222
+ * (`thinking.type: "enabled"` with `budget_tokens`) rather than adaptive.
223
+ */
224
+ export declare function usesBudgetThinking(model: Model<"anthropic-messages">): boolean;
225
+ /** The most output tokens a request to `model` may ask for (`max_tokens` ceiling). */
226
+ export declare function anthropicOutputLimit(model: Model<"anthropic-messages">): number;
227
+ /**
228
+ * The `max_tokens` and thinking budget of budget thinking: `max_tokens`
229
+ * rises to leave {@link OUTPUT_FALLBACK_BUFFER} visible output tokens after
230
+ * the budget, within `maxAllowedTokens`, and the budget shrinks when that
231
+ * ceiling leaves less (a non-positive budget means the ceiling is too low).
232
+ */
233
+ export declare function budgetThinkingOutput(maxTokens: number | undefined, budgetTokens: number, maxAllowedTokens: number): {
234
+ maxTokens: number;
235
+ budgetTokens: number;
236
+ };
237
+ /**
238
+ * Whether the conversation has stopped being thinking-led, so routes with
239
+ * `compat.stripThinkingHistory` drop the budget `thinking` config and replay
240
+ * history without thinking blocks. Exported so the factory-droid provider can
241
+ * gate its header-level interleaved beta on the same decision.
242
+ */
243
+ export declare function shouldStripThinkingHistory(messages: readonly Message[]): boolean;
220
244
  /**
221
245
  * A single Anthropic conversation turn, including the mid-conversation
222
246
  * `system` role (Opus 4.8+ and Fable/Mythos 5).
223
247
  */
224
248
  export type AnthropicMessageParam = MessageParam;
225
249
  /**
226
- * Serialize omp {@link Message}s to Anthropic wire messages.
250
+ * Serialize zeta {@link Message}s to Anthropic wire messages.
227
251
  *
228
252
  * `opts.serverSideFallbackEnabled` — when the CURRENT request itself
229
253
  * opts into the server-side-fallback beta chain. Only then may a persisted
@@ -33,6 +33,11 @@ export interface SignParams {
33
33
  /** Override clock for deterministic tests. */
34
34
  date?: Date;
35
35
  }
36
+ /** Coerce a possibly-ArrayBufferLike-backed `Uint8Array` into one over a fresh
37
+ * `ArrayBuffer`, which is what `crypto.subtle.{digest,sign,importKey}` requires
38
+ * under the strict TS DOM typings. No-op when already strict.
39
+ */
40
+ export declare function asStrict(bytes: Uint8Array): Uint8Array<ArrayBuffer>;
36
41
  export declare function toHex(bytes: Uint8Array): string;
37
42
  export declare function sha256(data: Uint8Array | string): Promise<Uint8Array>;
38
43
  export declare function sha256Hex(data: Uint8Array | string): Promise<string>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Fit an Anthropic request body to Bedrock's Anthropic Messages API
3
+ * (`compat.bedrockMessagesApi`): both `/anthropic` routes reject the tool
4
+ * `strict` field, and bedrock-runtime rejects a `metadata.user_id` outside
5
+ * Bedrock's request-metadata pattern. A user id that fits is kept, otherwise
6
+ * its embedded session id, otherwise the metadata is dropped. Mutates and
7
+ * returns `payload`.
8
+ */
9
+ export declare function fitBedrockAnthropicPayload<T>(payload: T): T;
@@ -0,0 +1,2 @@
1
+ /** Check Bedrock's request-metadata character and length limits. Keys must also be nonempty. */
2
+ export declare function isBedrockRequestMetadataValue(value: string): boolean;
@@ -1,5 +1,16 @@
1
- import type http2 from "node:http2";
2
1
  import { type InteractionQuery } from "@linxiraos/pi-catalog/discovery/cursor-proto";
2
+ type ProtoUnknownField = {
3
+ no: number;
4
+ wireType: number;
5
+ data: Uint8Array;
6
+ };
7
+ interface CursorInteractionWriter {
8
+ write(frame: Uint8Array): void;
9
+ }
10
+ /** Wrap one Connect-protocol message: 1 flag byte + 4-byte big-endian length + payload. */
11
+ export declare function frameConnectMessage(data: Uint8Array, flags?: number): Buffer;
12
+ /** Well-formed protobuf-es `$unknown` entries on `message`; anything else on the bag is ignored. */
13
+ export declare function protoUnknownFields(message: object): ProtoUnknownField[];
3
14
  /**
4
15
  * Answer a Cursor `interaction_query` so the Run RPC can continue.
5
16
  *
@@ -12,4 +23,5 @@ import { type InteractionQuery } from "@linxiraos/pi-catalog/discovery/cursor-pr
12
23
  * Unsupported interactive queries are rejected so the server is not stranded.
13
24
  * VM setup is left unanswered rather than reporting a fake success.
14
25
  */
15
- export declare function handleInteractionQuery(query: InteractionQuery, h2Request: http2.ClientHttp2Stream): void;
26
+ export declare function handleInteractionQuery(query: InteractionQuery, h2Request: CursorInteractionWriter): void;
27
+ export {};