@linxiraos/pi-ai 1.1.26 → 1.2.0
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 +9 -8
- package/README.md +15 -0
- package/dist/types/auth/affinity.d.ts +33 -6
- package/dist/types/auth/cascade.d.ts +44 -7
- package/dist/types/auth/oauth.d.ts +9 -6
- package/dist/types/auth/policy.d.ts +1 -0
- package/dist/types/auth/refresh.d.ts +1 -2
- package/dist/types/auth/select.d.ts +6 -4
- package/dist/types/auth/sqlite-credential-store.d.ts +21 -1
- package/dist/types/auth/store.d.ts +8 -2
- package/dist/types/auth/types.d.ts +99 -15
- package/dist/types/auth-broker/client.d.ts +3 -3
- package/dist/types/auth-broker/discover.d.ts +1 -1
- package/dist/types/auth-broker/refresher.d.ts +6 -1
- package/dist/types/auth-broker/remote-store.d.ts +6 -4
- package/dist/types/auth-broker/server.d.ts +2 -0
- package/dist/types/auth-broker/snapshot-cache.d.ts +12 -0
- package/dist/types/auth-gateway/dispatch.d.ts +13 -5
- package/dist/types/auth-gateway/http.d.ts +0 -2
- package/dist/types/auth-gateway/index.d.ts +1 -0
- package/dist/types/auth-gateway/routes/embeddings.d.ts +2 -2
- package/dist/types/auth-gateway/routes/images.d.ts +3 -3
- package/dist/types/auth-gateway/routes/rerank.d.ts +2 -2
- package/dist/types/auth-gateway/routes/speech.d.ts +2 -2
- package/dist/types/auth-gateway/routes/systemone.d.ts +2 -2
- package/dist/types/auth-gateway/routes/transcriptions.d.ts +2 -2
- package/dist/types/auth-gateway/routes/video.d.ts +4 -4
- package/dist/types/auth-gateway/server.d.ts +22 -5
- package/dist/types/auth-gateway/session-state.d.ts +6 -0
- package/dist/types/auth-gateway/stdio.d.ts +12 -0
- package/dist/types/auth-storage.d.ts +7 -6
- package/dist/types/dialect/terminator-wait.d.ts +19 -0
- package/dist/types/env-api-key.d.ts +21 -0
- package/dist/types/error/auth.d.ts +10 -0
- package/dist/types/error/flags.d.ts +38 -0
- package/dist/types/images/index.d.ts +2 -3
- package/dist/types/images/shared.d.ts +6 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/judgment/index.d.ts +2 -1
- package/dist/types/judgment/native.d.ts +80 -0
- package/dist/types/judgment/openai-decisions.d.ts +3 -0
- package/dist/types/judgment/question-file.d.ts +52 -0
- package/dist/types/judgment/systemone.d.ts +7 -0
- package/dist/types/judgment/types.d.ts +2 -2
- package/dist/types/judgment/wire.d.ts +36 -0
- package/dist/types/provider-details.d.ts +1 -1
- package/dist/types/provider-session-state.d.ts +2 -2
- package/dist/types/providers/anthropic-client.d.ts +10 -0
- package/dist/types/providers/anthropic-state.d.ts +2 -0
- package/dist/types/providers/anthropic.d.ts +38 -3
- package/dist/types/providers/aws-credentials.d.ts +4 -8
- package/dist/types/providers/connect-error-detail.d.ts +9 -0
- package/dist/types/providers/connect-frame.d.ts +44 -0
- package/dist/types/providers/cursor/interaction-query.d.ts +0 -2
- package/dist/types/providers/cursor.d.ts +8 -8
- package/dist/types/providers/google-auth.d.ts +4 -1
- package/dist/types/providers/google-shared.d.ts +24 -4
- package/dist/types/providers/inference-headers.d.ts +6 -0
- package/dist/types/providers/mock.d.ts +3 -1
- package/dist/types/providers/openai-codex/request-transformer.d.ts +2 -0
- package/dist/types/providers/openai-codex-responses.d.ts +1 -1
- package/dist/types/providers/openai-configuration-update.d.ts +20 -11
- package/dist/types/providers/openai-responses-wire.d.ts +1 -55
- package/dist/types/providers/openai-responses.d.ts +40 -3
- package/dist/types/providers/openai-shared.d.ts +30 -5
- package/dist/types/providers/pi-native-client.d.ts +1 -1
- package/dist/types/providers/transform-messages.d.ts +25 -0
- package/dist/types/providers/vision-guard.d.ts +1 -1
- package/dist/types/registry/oauth/cloudflare-workers-ai.d.ts +3 -0
- package/dist/types/registry/oauth/cursor.d.ts +10 -2
- package/dist/types/registry/oauth/index.d.ts +2 -0
- package/dist/types/registry/oauth/snowflake.d.ts +3 -0
- package/dist/types/registry/snowflake.d.ts +4 -0
- package/dist/types/stream.d.ts +0 -21
- package/dist/types/transcription/types.d.ts +2 -1
- package/dist/types/types.d.ts +116 -14
- package/dist/types/usage.d.ts +2 -0
- package/dist/types/utils/anthropic-auth.d.ts +21 -7
- package/dist/types/utils/aws-profile.d.ts +5 -0
- package/dist/types/utils/block-symbols.d.ts +14 -0
- package/dist/types/utils/dsml-leak.d.ts +29 -0
- package/dist/types/utils/glyph-codec.d.ts +1 -1
- package/dist/types/utils/idle-iterator.d.ts +11 -0
- package/dist/types/utils/leaked-thinking-stream.d.ts +1 -1
- package/dist/types/utils/resolve-peer.d.ts +2 -0
- package/dist/types/utils/retry-wait.d.ts +9 -0
- package/dist/types/utils/schema/normalize.d.ts +8 -3
- package/dist/types/utils/stream-markup-healing.d.ts +4 -4
- package/dist/types/utils/tool-call-arguments.d.ts +8 -0
- package/dist/types/utils.d.ts +6 -0
- package/package.json +6 -6
- package/src/auth/affinity.ts +130 -37
- package/src/auth/blocks.ts +94 -15
- package/src/auth/cascade.ts +112 -17
- package/src/auth/health.ts +3 -2
- package/src/auth/oauth.ts +25 -10
- package/src/auth/policy.ts +10 -1
- package/src/auth/pool.ts +0 -5
- package/src/auth/refresh.ts +17 -12
- package/src/auth/resets.ts +1 -1
- package/src/auth/rotation.ts +8 -2
- package/src/auth/select.ts +102 -30
- package/src/auth/sqlite-credential-store.ts +119 -49
- package/src/auth/store.ts +8 -2
- package/src/auth/types.ts +108 -17
- package/src/auth/usage-cache.ts +16 -5
- package/src/auth/usage.ts +2 -2
- package/src/auth-broker/client.ts +7 -4
- package/src/auth-broker/discover.ts +6 -5
- package/src/auth-broker/refresher.ts +8 -1
- package/src/auth-broker/remote-store.ts +200 -62
- package/src/auth-broker/server.ts +316 -130
- package/src/auth-broker/snapshot-cache.ts +142 -2
- package/src/auth-gateway/dispatch.ts +15 -7
- package/src/auth-gateway/http.ts +0 -8
- package/src/auth-gateway/index.ts +1 -0
- package/src/auth-gateway/routes/embeddings.ts +2 -2
- package/src/auth-gateway/routes/images.ts +4 -4
- package/src/auth-gateway/routes/rerank.ts +2 -2
- package/src/auth-gateway/routes/speech.ts +2 -2
- package/src/auth-gateway/routes/systemone.ts +22 -14
- package/src/auth-gateway/routes/transcriptions.ts +2 -2
- package/src/auth-gateway/routes/video.ts +7 -7
- package/src/auth-gateway/server.ts +175 -134
- package/src/auth-gateway/session-state.ts +51 -9
- package/src/auth-gateway/stdio.ts +132 -0
- package/src/auth-storage.ts +23 -9
- package/src/dialect/deepseek.ts +67 -8
- package/src/dialect/gemini.ts +8 -2
- package/src/dialect/hermes.ts +8 -2
- package/src/dialect/kimi.ts +8 -2
- package/src/dialect/qwen-xml.ts +8 -2
- package/src/dialect/qwen3.ts +8 -2
- package/src/dialect/terminator-wait.ts +42 -0
- package/src/env-api-key.ts +78 -0
- package/src/error/auth.ts +20 -0
- package/src/error/flags.ts +143 -24
- package/src/error/rate-limit.ts +8 -6
- package/src/images/google-antigravity.ts +0 -1
- package/src/images/index.ts +3 -17
- package/src/images/openai-hosted.ts +13 -4
- package/src/images/openai-images.ts +19 -13
- package/src/images/shared.ts +10 -2
- package/src/index.ts +2 -1
- package/src/judgment/index.ts +2 -1
- package/src/judgment/native.ts +333 -0
- package/src/judgment/openai-decisions-predicate.md +9 -0
- package/src/judgment/openai-decisions.ts +129 -0
- package/src/judgment/question-file.ts +90 -0
- package/src/judgment/systemone.ts +65 -0
- package/src/judgment/text.ts +9 -1
- package/src/judgment/types.ts +2 -2
- package/src/judgment/wire.ts +42 -0
- package/src/provider-details.ts +1 -1
- package/src/provider-session-state.ts +2 -2
- package/src/providers/amazon-bedrock.ts +19 -8
- package/src/providers/anthropic-client.ts +16 -1
- package/src/providers/anthropic-state.ts +6 -0
- package/src/providers/anthropic.ts +962 -238
- package/src/providers/apple-foundation-models.ts +10 -4
- package/src/providers/aws-credentials.ts +65 -5
- package/src/providers/azure-openai-responses.ts +1 -1
- package/src/providers/connect-error-detail.ts +21 -0
- package/src/providers/connect-frame.ts +107 -0
- package/src/providers/cursor/interaction-query.ts +1 -9
- package/src/providers/cursor.ts +590 -133
- package/src/providers/devin.ts +68 -58
- package/src/providers/factory-droid/gemini.ts +38 -51
- package/src/providers/factory-droid.ts +2 -0
- package/src/providers/gitlab-duo-workflow.ts +5 -2
- package/src/providers/gitlab-duo.ts +1 -0
- package/src/providers/google-auth.ts +10 -3
- package/src/providers/google-gemini-cli.ts +4 -0
- package/src/providers/google-shared.ts +134 -105
- package/src/providers/google-vertex.ts +0 -1
- package/src/providers/google.ts +1 -1
- package/src/providers/inference-headers.ts +19 -0
- package/src/providers/mock.ts +4 -0
- package/src/providers/ollama.ts +1 -1
- package/src/providers/openai-anthropic-shim.ts +1 -0
- package/src/providers/openai-codex/request-transformer.ts +16 -11
- package/src/providers/openai-codex-responses.ts +201 -76
- package/src/providers/openai-completions.ts +12 -2
- package/src/providers/openai-configuration-update.ts +54 -15
- package/src/providers/openai-responses-wire.ts +1 -55
- package/src/providers/openai-responses.ts +437 -33
- package/src/providers/openai-shared.ts +267 -72
- package/src/providers/pi-native-client.ts +2 -2
- package/src/providers/pi-native-server.ts +1 -0
- package/src/providers/systemone-server.ts +1 -1
- package/src/providers/transcriptions-server.ts +1 -1
- package/src/providers/transform-messages.ts +240 -84
- package/src/providers/vision-guard.ts +1 -1
- package/src/registry/aws.ts +51 -14
- package/src/registry/cloudflare-ai-gateway.ts +26 -3
- package/src/registry/hooks/api-key.ts +1 -0
- package/src/registry/hooks/custom.ts +2 -0
- package/src/registry/hooks/env.ts +2 -5
- package/src/registry/oauth/callback-server.ts +6 -1
- package/src/registry/oauth/cloudflare-ai-gateway.ts +2 -2
- package/src/registry/oauth/cloudflare-workers-ai.ts +32 -0
- package/src/registry/oauth/cursor.ts +80 -17
- package/src/registry/oauth/index.ts +5 -0
- package/src/registry/oauth/snowflake.ts +183 -0
- package/src/registry/registry.ts +2 -0
- package/src/registry/snowflake.ts +149 -0
- package/src/stream.ts +85 -107
- package/src/transcription/types.ts +2 -1
- package/src/types.ts +142 -15
- package/src/usage/claude.ts +19 -12
- package/src/usage/commandcode.ts +1 -1
- package/src/usage/cursor.ts +14 -25
- package/src/usage/github-copilot.ts +1 -1
- package/src/usage/kimi.ts +1 -1
- package/src/usage/minimax-code.ts +8 -1
- package/src/usage.ts +8 -0
- package/src/utils/anthropic-auth.ts +34 -10
- package/src/utils/aws-profile.ts +10 -4
- package/src/utils/block-symbols.ts +17 -0
- package/src/utils/dsml-leak.ts +109 -0
- package/src/utils/empty-completion-retry.ts +2 -3
- package/src/utils/glyph-codec.ts +200 -7
- package/src/utils/idle-iterator.ts +80 -35
- package/src/utils/leaked-thinking-stream.ts +47 -25
- package/src/utils/resolve-peer.ts +7 -0
- package/src/utils/retry-wait.ts +19 -0
- package/src/utils/schema/CONSTRAINTS.md +9 -7
- package/src/utils/schema/fields.ts +20 -0
- package/src/utils/schema/normalize.ts +65 -23
- package/src/utils/schema/wire.ts +3 -3
- package/src/utils/stream-markup-healing.ts +4 -4
- package/src/utils/thinking-loop.ts +36 -13
- package/src/utils/tool-call-arguments.ts +16 -0
- package/src/utils/transport-fetch.ts +1 -1
- package/src/utils.ts +41 -10
- package/dist/types/judgment/typesafe.d.ts +0 -49
- package/src/judgment/typesafe.ts +0 -183
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HTTP client for the
|
|
2
|
+
* HTTP client for the zetacode auth-broker server.
|
|
3
3
|
*
|
|
4
4
|
* Used by {@link RemoteAuthCredentialStore} (snapshot pulls) and by
|
|
5
|
-
* `
|
|
5
|
+
* `zetacode auth-broker status` (liveness checks). All endpoints except
|
|
6
6
|
* `/v1/healthz` require a bearer token.
|
|
7
7
|
*/
|
|
8
8
|
import type { AuthCredential, DisabledCredentialSummary, OAuthRefreshReason } from "../auth-storage.js";
|
|
@@ -85,7 +85,7 @@ export declare class AuthBrokerClient {
|
|
|
85
85
|
fetchClientUsageSummary(query?: {
|
|
86
86
|
sinceMs?: number;
|
|
87
87
|
}, signal?: AbortSignal): Promise<ClientUsageSummaryResponse>;
|
|
88
|
-
notifyUsageStale(signal?: AbortSignal): Promise<UsageStaleResponse>;
|
|
88
|
+
notifyUsageStale(provider?: string, signal?: AbortSignal): Promise<UsageStaleResponse>;
|
|
89
89
|
refreshCredential(id: number, signal?: AbortSignal, reason?: OAuthRefreshReason): Promise<CredentialRefreshResponse>;
|
|
90
90
|
disableCredential(id: number, cause: string, signal?: AbortSignal): Promise<CredentialDisableResponse>;
|
|
91
91
|
/**
|
|
@@ -18,7 +18,7 @@ export interface DiscoverAuthStorageOptions {
|
|
|
18
18
|
accountPolicies?: AuthAccountPolicies;
|
|
19
19
|
authStorageOptions?: Omit<AuthStorageOptions, "accountPolicies" | "configValueResolver" | "sourceLabel">;
|
|
20
20
|
}
|
|
21
|
-
/** Path to the local bearer token file. Created by `
|
|
21
|
+
/** Path to the local bearer token file. Created by `zetacode auth-broker token`. */
|
|
22
22
|
export declare function getAuthBrokerTokenFilePath(): string;
|
|
23
23
|
export interface AuthAccountPolicyConfig {
|
|
24
24
|
accountPolicies: AuthAccountPolicies;
|
|
@@ -20,6 +20,11 @@ export declare class AuthBrokerRefresher {
|
|
|
20
20
|
start(): void;
|
|
21
21
|
stop(): void;
|
|
22
22
|
getSchedule(): AuthBrokerRefresherSchedule;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Run one sweep. Exposed for tests.
|
|
25
|
+
*
|
|
26
|
+
* Never rejects: callers fire it unawaited from a timer, so a failed sweep
|
|
27
|
+
* (e.g. an unreadable credential store) is logged and retried next interval.
|
|
28
|
+
*/
|
|
24
29
|
tick(): Promise<void>;
|
|
25
30
|
}
|
|
@@ -73,6 +73,7 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
|
|
|
73
73
|
/** Broker-backed disabled tombstones; empty against brokers predating the endpoint. */
|
|
74
74
|
listDisabledCredentials(provider?: string, signal?: AbortSignal): Promise<DisabledCredentialSummary[]>;
|
|
75
75
|
getCredentialBlock(credentialId: number, providerKey: string, blockScope: string): number | undefined;
|
|
76
|
+
getCredentialBlockScopes(credentialId: number, providerKey: string): Map<string, number>;
|
|
76
77
|
getCredentialBlockReconcileAfter(credentialId: number, providerKey: string, blockScope: string): number | undefined;
|
|
77
78
|
listCredentialBlocks(credentialIds: readonly number[]): StoredCredentialBlock[];
|
|
78
79
|
upsertCredentialBlock(block: StoredCredentialBlock): void;
|
|
@@ -121,7 +122,7 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
|
|
|
121
122
|
/** Drop all cache rows whose keys start with the supplied prefix. */
|
|
122
123
|
deleteCachePrefix(prefix: string): void;
|
|
123
124
|
cleanExpiredCache(): void;
|
|
124
|
-
invalidateUsageCache(signal?: AbortSignal): Promise<void>;
|
|
125
|
+
invalidateUsageCache(provider?: string, signal?: AbortSignal): Promise<void>;
|
|
125
126
|
/**
|
|
126
127
|
* Store-level hook consumed by `AuthStorage` — routes refresh through the
|
|
127
128
|
* broker so the actual refresh token never leaves the broker host. Returns
|
|
@@ -148,9 +149,10 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
|
|
|
148
149
|
ingestUsageReport(provider: Provider, credential: OAuthCredential, report: UsageReport): boolean;
|
|
149
150
|
/**
|
|
150
151
|
* Fold locally observed request usage into the pending report and schedule
|
|
151
|
-
* a flush. One `POST /v1/usage/observed` at most per flush interval
|
|
152
|
-
*
|
|
153
|
-
* (pre-endpoint broker) disables
|
|
152
|
+
* a flush. One `POST /v1/usage/observed` at most per flush interval, plus a
|
|
153
|
+
* final one when the process exits; on failure the batch is retained and
|
|
154
|
+
* retried with the next flush. A 404 (pre-endpoint broker) disables
|
|
155
|
+
* reporting for the life of this store.
|
|
154
156
|
*
|
|
155
157
|
* `client` overrides the reporting identity — the auth-gateway attributes
|
|
156
158
|
* each request to the originating install/app instead of the gateway host.
|
|
@@ -17,6 +17,8 @@ export interface AuthBrokerServerOptions {
|
|
|
17
17
|
bind?: string;
|
|
18
18
|
/** Accept any of these bearer tokens. Empty disables auth (loopback only). */
|
|
19
19
|
bearerTokens: string[];
|
|
20
|
+
/** Honor forwarded peer headers only when the connecting proxy is trusted. Default false. */
|
|
21
|
+
trustProxyHeaders?: boolean;
|
|
20
22
|
/** Broker version string surfaced on `/v1/healthz`. */
|
|
21
23
|
version?: string;
|
|
22
24
|
/** Refresh credentials expiring within this window. Default 5 min. */
|
|
@@ -15,3 +15,15 @@ export interface WriteAuthBrokerSnapshotCacheOptions {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function readAuthBrokerSnapshotCache(opts: ReadAuthBrokerSnapshotCacheOptions): Promise<SnapshotResponse | null>;
|
|
17
17
|
export declare function writeAuthBrokerSnapshotCache(opts: WriteAuthBrokerSnapshotCacheOptions): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Fire-and-forget cache write for snapshot callbacks. The first snapshot after
|
|
20
|
+
* a quiet period is written immediately; later ones within
|
|
21
|
+
* {@link WRITE_COALESCE_MS} collapse into a single trailing write of the
|
|
22
|
+
* newest. A snapshot whose generation and credential content match the last
|
|
23
|
+
* write is skipped (see {@link UNCHANGED_REWRITE_MS}). Pending writes are
|
|
24
|
+
* flushed on process shutdown and by {@link flushAuthBrokerSnapshotCacheWrites};
|
|
25
|
+
* failures are logged, never thrown.
|
|
26
|
+
*/
|
|
27
|
+
export declare function scheduleAuthBrokerSnapshotCacheWrite(opts: WriteAuthBrokerSnapshotCacheOptions): void;
|
|
28
|
+
/** Write every pending scheduled snapshot now and wait for in-flight writes to settle. */
|
|
29
|
+
export declare function flushAuthBrokerSnapshotCacheWrites(): Promise<void>;
|
|
@@ -5,8 +5,9 @@ import type { Api, FetchImpl, Model, Usage } from "../types.js";
|
|
|
5
5
|
import type { ClientUsageIdentity } from "../usage.js";
|
|
6
6
|
import type { AuthGatewayServerOptions } from "./types.js";
|
|
7
7
|
export type ModelResolver = (modelId: string) => Model<Api> | undefined;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** What the gateway's routes need, whatever transport carries the requests. */
|
|
9
|
+
export interface AuthGatewayRouteOptions {
|
|
10
|
+
/** Source of credentials: broker-backed for `serve`, the CLI's own for `stdio`. */
|
|
10
11
|
storage: AuthStorage;
|
|
11
12
|
/**
|
|
12
13
|
* Resolve a client-requested model id to a pi-ai Model. Caller supplies
|
|
@@ -16,9 +17,14 @@ export interface AuthGatewayBootOptions extends AuthGatewayServerOptions {
|
|
|
16
17
|
resolveModel: ModelResolver;
|
|
17
18
|
/** Optional supplier for `/v1/models` listing. Returns the full model array. */
|
|
18
19
|
listModels?: () => Iterable<Model<Api>>;
|
|
20
|
+
/** Providers the host does not serve; `/v1/usage` and `/v1/credentials/check` leave their accounts out. */
|
|
21
|
+
excludeProviders?: ReadonlySet<string>;
|
|
19
22
|
/** Upstream transport for every provider call; defaults to global `fetch`. Test seam. */
|
|
20
23
|
fetch?: FetchImpl;
|
|
21
24
|
}
|
|
25
|
+
/** The HTTP server's options: the routes' plus its listener and inbound auth. */
|
|
26
|
+
export interface AuthGatewayBootOptions extends AuthGatewayServerOptions, AuthGatewayRouteOptions {
|
|
27
|
+
}
|
|
22
28
|
/**
|
|
23
29
|
* The client's own session key, or `undefined` when it sent none. A blank key
|
|
24
30
|
* counts as none: honouring it would collapse every caller that sends an empty
|
|
@@ -59,9 +65,11 @@ export declare function resolveGatewayApiKey(storage: AuthStorage, model: Model<
|
|
|
59
65
|
* to a sibling (usage-limit block vs credential invalidation by error class).
|
|
60
66
|
*
|
|
61
67
|
* `lastKey` tracks the most recent bearer so the switch step invalidates the
|
|
62
|
-
* credential that actually failed
|
|
63
|
-
*
|
|
64
|
-
*
|
|
68
|
+
* credential that actually failed; a retry context's `previousKey` wins, since
|
|
69
|
+
* concurrent operations sharing one resolver (split judgment chunks) each know
|
|
70
|
+
* the bearer they sent. `onResolvedKey` observes every rotation; routes that
|
|
71
|
+
* retain provider session state use it to re-key the account lease, one-shot
|
|
72
|
+
* routes pass `undefined`.
|
|
65
73
|
*/
|
|
66
74
|
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
75
|
/**
|
|
@@ -16,8 +16,6 @@ export declare function gatewayResponseHeaders(model: Model<Api>, info: {
|
|
|
16
16
|
costUsd?: number;
|
|
17
17
|
startedAt?: number;
|
|
18
18
|
}): Record<string, 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
19
|
/** Keep configured gateway credentials out of URL and forwarded/logged request fields. */
|
|
22
20
|
export declare function hasMisplacedBearer(req: Request, url: URL, tokens: ReadonlySet<string>): boolean;
|
|
23
21
|
/**
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
2
|
/** OpenAI-compatible `POST /v1/embeddings` gateway handler. */
|
|
3
|
-
export declare function handleEmbeddings(bootOpts:
|
|
3
|
+
export declare function handleEmbeddings(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function handleImageGenerations(bootOpts:
|
|
3
|
-
export declare function handleImageEdits(bootOpts:
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
|
+
export declare function handleImageGenerations(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
3
|
+
export declare function handleImageEdits(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
2
|
/** OpenRouter-compatible `POST /v1/rerank` gateway handler. */
|
|
3
|
-
export declare function handleRerank(bootOpts:
|
|
3
|
+
export declare function handleRerank(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function handleSpeech(bootOpts:
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
|
+
export declare function handleSpeech(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function handleSystemOne(bootOpts:
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
|
+
export declare function handleSystemOne(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
2
|
/** OpenAI-compatible `POST /v1/audio/transcriptions` gateway handler. */
|
|
3
|
-
export declare function handleTranscriptions(bootOpts:
|
|
3
|
+
export declare function handleTranscriptions(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AuthGatewayRouteOptions } from "../dispatch.js";
|
|
2
2
|
/** OpenRouter-compatible `POST /v1/videos` asynchronous video submit handler. */
|
|
3
|
-
export declare function handleVideoSubmit(bootOpts:
|
|
3
|
+
export declare function handleVideoSubmit(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string): Promise<Response>;
|
|
4
4
|
/** OpenRouter-compatible `GET /v1/videos/:id` asynchronous video poll handler. */
|
|
5
|
-
export declare function handleVideoPoll(bootOpts:
|
|
5
|
+
export declare function handleVideoPoll(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string, gatewayId: string): Promise<Response>;
|
|
6
6
|
/** OpenRouter-compatible `GET /v1/videos/:id/content` streaming video content handler. */
|
|
7
|
-
export declare function handleVideoContent(bootOpts:
|
|
7
|
+
export declare function handleVideoContent(bootOpts: AuthGatewayRouteOptions, req: Request, peer: string, gatewayId: string): Promise<Response>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* zetacode auth-gateway router and 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 →
|
|
9
|
-
*
|
|
8
|
+
* pure protocol translation: foreign wire → omp Context → pi-ai stream() →
|
|
9
|
+
* omp events → foreign wire.
|
|
10
10
|
*
|
|
11
11
|
* Endpoints:
|
|
12
12
|
* GET /healthz → unauth; ok + version
|
|
@@ -23,8 +23,25 @@
|
|
|
23
23
|
* POST /v1/audio/transcriptions → speech-to-text, multipart or JSON base64 in (routes/transcriptions)
|
|
24
24
|
*
|
|
25
25
|
* Chat routes live in this file; every other modality is a `routes/*` module
|
|
26
|
-
* built on the shared plumbing in `dispatch.ts`.
|
|
26
|
+
* built on the shared plumbing in `dispatch.ts`. {@link createAuthGatewayRouter}
|
|
27
|
+
* answers the `/v1/*` routes for any transport: {@link startAuthGateway}
|
|
28
|
+
* serves them over HTTP behind bearer auth, `stdio.ts` over JSON lines.
|
|
27
29
|
*/
|
|
28
|
-
import { type AuthGatewayBootOptions } from "./dispatch.js";
|
|
30
|
+
import { type AuthGatewayBootOptions, type AuthGatewayRouteOptions } from "./dispatch.js";
|
|
29
31
|
import type { AuthGatewayServerHandle } from "./types.js";
|
|
32
|
+
/** The gateway's `/v1/*` routes, for a transport that has already admitted the caller. */
|
|
33
|
+
export interface AuthGatewayRouter {
|
|
34
|
+
/** Answers one request; `peer` names the caller in logs. Never rejects: a crashed route answers 500. */
|
|
35
|
+
route(req: Request, peer: string): Promise<Response>;
|
|
36
|
+
/**
|
|
37
|
+
* Closes the retained provider session state (Codex WebSockets, GitLab Duo
|
|
38
|
+
* workflows), whose sockets and timers would otherwise keep the process alive.
|
|
39
|
+
*/
|
|
40
|
+
close(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The gateway's routes over `opts`, owning their per-session provider state:
|
|
44
|
+
* two routers in one process never share (or tear down) each other's.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createAuthGatewayRouter(opts: AuthGatewayRouteOptions): AuthGatewayRouter;
|
|
30
47
|
export declare function startAuthGateway(opts: AuthGatewayBootOptions): AuthGatewayServerHandle;
|
|
@@ -63,6 +63,12 @@ export interface AuthGatewaySessionStateRequest {
|
|
|
63
63
|
* continues.
|
|
64
64
|
*/
|
|
65
65
|
context: Context;
|
|
66
|
+
/**
|
|
67
|
+
* `JSON.stringify(context.tools)` when the caller already serialized it
|
|
68
|
+
* (the gateway derives its `sessionId` from the same string). Recomputed
|
|
69
|
+
* from `context` when absent.
|
|
70
|
+
*/
|
|
71
|
+
toolsJson?: string;
|
|
66
72
|
/**
|
|
67
73
|
* Stable identity of the account this request's credential resolved to.
|
|
68
74
|
* A change means the gateway switched the session to a sibling credential,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AuthGatewayStdioOptions {
|
|
2
|
+
/** Request lines. */
|
|
3
|
+
input: ReadableStream<Uint8Array>;
|
|
4
|
+
/** Writes one response line, newline included. */
|
|
5
|
+
write(line: string): void;
|
|
6
|
+
/** Answers one request; never rejects (the gateway router's `route`, or a wrapper around it). */
|
|
7
|
+
route(req: Request): Promise<Response>;
|
|
8
|
+
/** Reported on the ready line. */
|
|
9
|
+
version?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Serves `opts.input` until it ends and every request it carried is answered. */
|
|
12
|
+
export declare function serveAuthGatewayStdio(opts: AuthGatewayStdioOptions): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AuthCredentialStore } from "./auth/store.js";
|
|
2
2
|
import type { AuthAccountPolicies, AuthApiKeyOptions, AuthStorageOptions, BlocksApi, CredentialsApi, HealthApi, KeysApi, LimitsApi, OAuthApi, ResetsApi, SessionsApi, UsageApi } from "./auth/types.js";
|
|
3
|
-
export { isSqliteBusyError, isSqliteCorruptionError, SqliteAuthCredentialStore } from "./auth/sqlite-credential-store.js";
|
|
3
|
+
export { isSameOAuthAccount, isSqliteBusyError, isSqliteCorruptionError, matchesReplacementCredential, resolveCredentialIdentityKey, SqliteAuthCredentialStore, } from "./auth/sqlite-credential-store.js";
|
|
4
4
|
export * from "./auth/store.js";
|
|
5
5
|
export * from "./auth/types.js";
|
|
6
6
|
/**
|
|
@@ -35,8 +35,9 @@ export declare class AuthStorage {
|
|
|
35
35
|
/**
|
|
36
36
|
* Apply new account routing policy (live `auth.accountPolicies` /
|
|
37
37
|
* `retry.usageReservePct` change). Throws a configuration error, leaving the
|
|
38
|
-
* active policy untouched, when
|
|
39
|
-
* stored OAuth accounts
|
|
38
|
+
* active policy untouched, when a policy is malformed, a selector matches
|
|
39
|
+
* several stored OAuth accounts, or two policies claim the same account; a
|
|
40
|
+
* policy naming an absent account stays inactive and logs a warning.
|
|
40
41
|
*/
|
|
41
42
|
setAccountPolicies(config: {
|
|
42
43
|
accountPolicies: AuthAccountPolicies;
|
|
@@ -46,9 +47,9 @@ export declare class AuthStorage {
|
|
|
46
47
|
* Swap the backing credential store in place (live `auth.broker.url` change).
|
|
47
48
|
* Loads `store` into fresh store-bound state — pins, blocks, and usage caches are
|
|
48
49
|
* keyed by the old store's row ids — then closes the previous store. Runtime key
|
|
49
|
-
* overrides, account policies, usage-provider
|
|
50
|
-
* subscribers carry over. On a load failure
|
|
51
|
-
* store stays active.
|
|
50
|
+
* overrides, account policies, session account restrictions, usage-provider
|
|
51
|
+
* overrides, and credential event subscribers carry over. On a load failure
|
|
52
|
+
* `store` is closed and the current store stays active.
|
|
52
53
|
*/
|
|
53
54
|
replaceStore(store: AuthCredentialStore, options?: {
|
|
54
55
|
sourceLabel?: string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fast path for in-band scanners that sit inside a body waiting for one fixed
|
|
3
|
+
* terminator (a tool-call close tag) and emit nothing until it arrives.
|
|
4
|
+
*
|
|
5
|
+
* Appending each delta to the scanner's string buffer and calling `indexOf` on
|
|
6
|
+
* it flattens the growing rope on every delta, so a long in-band tool call cost
|
|
7
|
+
* O(n²) copying and scanning. While armed, deltas are set aside and only the new
|
|
8
|
+
* text plus the terminator-length overlap with what came before is searched;
|
|
9
|
+
* the buffer is rebuilt once, when the terminator shows up or the stream ends.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TerminatorWait {
|
|
12
|
+
#private;
|
|
13
|
+
/** Start deferring; `buffered` is the scanner's pending body, known not to contain `terminator`. */
|
|
14
|
+
arm(terminator: string, buffered: string): void;
|
|
15
|
+
/** Take `text` while the terminator is still absent; false means the caller must {@link release} and scan. */
|
|
16
|
+
absorb(text: string): boolean;
|
|
17
|
+
/** Stop deferring and return `buffered` with every absorbed delta appended. */
|
|
18
|
+
release(buffered: string): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get API key for provider from known environment variables, e.g. OPENAI_API_KEY.
|
|
3
|
+
*
|
|
4
|
+
* Will not return API keys for providers that require OAuth tokens.
|
|
5
|
+
* Checks Bun.env, then cwd/.env, then ~/.env.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getEnvApiKey(provider: string): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Name of the environment variable that backs `getEnvApiKey` for a provider,
|
|
10
|
+
* when that provider maps to a single named variable (e.g. `github-copilot` →
|
|
11
|
+
* `COPILOT_GITHUB_TOKEN`). Returns undefined for providers whose env fallback
|
|
12
|
+
* is computed (multi-var pickers, Vertex ADC / Bedrock probes, …) since no
|
|
13
|
+
* single variable name describes the source.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getEnvApiKeyName(provider: string): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Enumerate every provider that has an env-var fallback for `getEnvApiKey`.
|
|
18
|
+
* Used by `zetacode auth-broker migrate --include-env` to discover env-sourced keys
|
|
19
|
+
* that should be uploaded to the broker.
|
|
20
|
+
*/
|
|
21
|
+
export declare function listProvidersWithEnvKey(): string[];
|
|
@@ -10,6 +10,16 @@ export declare class MissingApiKeyError extends Error {
|
|
|
10
10
|
readonly provider: string | undefined;
|
|
11
11
|
constructor(provider?: string, message?: string);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Every usable OAuth credential for a provider failed to refresh with a
|
|
15
|
+
* retryable error (network blip, timeout, 5xx). The stored credentials are
|
|
16
|
+
* intact, so this is classified transient: retrying the request can succeed,
|
|
17
|
+
* unlike {@link MissingApiKeyError}. The refresh failure is kept as `cause`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class OAuthRefreshUnavailableError extends Error {
|
|
20
|
+
readonly provider: string;
|
|
21
|
+
constructor(provider: string, cause: unknown);
|
|
22
|
+
}
|
|
13
23
|
/** A user-facing login flow required an `onPrompt` callback that was not supplied. */
|
|
14
24
|
export declare class OnPromptRequiredError extends Error {
|
|
15
25
|
constructor(providerLabel: string);
|
|
@@ -23,6 +23,16 @@ export declare const Flag: {
|
|
|
23
23
|
readonly FastModeUnsupported: 536870912;
|
|
24
24
|
/** OAuth refresh failed definitively — the stored grant is dead, re-login required. */
|
|
25
25
|
readonly OAuthExpiry: 1073741824;
|
|
26
|
+
/**
|
|
27
|
+
* An Anthropic-compatible endpoint rejected the `cache_control` field with a
|
|
28
|
+
* 400, so prompt-cache breakpoints must be dropped for it.
|
|
29
|
+
*
|
|
30
|
+
* Every bit from {@link Flag.Class} up is already taken, so this claims a low
|
|
31
|
+
* bit instead. Those belong to the raw-status lane — an unclassified id is an
|
|
32
|
+
* HTTP status (100-599, see `statusFromId`) — and 0x800 is 2048, above every
|
|
33
|
+
* status value, so no raw status id can set it.
|
|
34
|
+
*/
|
|
35
|
+
readonly CacheControlUnsupported: 2048;
|
|
26
36
|
/** HTTP 413 byte/media rejection — token compaction cannot shrink bytes or media budgets (#9235). */
|
|
27
37
|
readonly PayloadRejected: 2147483648;
|
|
28
38
|
};
|
|
@@ -43,6 +53,21 @@ export declare function isResponsesRequestBodyReadTimeout(message: {
|
|
|
43
53
|
errorMessage?: string;
|
|
44
54
|
requestBodyReadTimeoutFullReplay?: boolean;
|
|
45
55
|
}): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Codex code for the experimental native turn lane refusing a mid-response
|
|
58
|
+
* `response.steer`; the server then drops the in-flight response and closes
|
|
59
|
+
* the socket.
|
|
60
|
+
*/
|
|
61
|
+
export declare const CODEX_NATIVE_LANE_STEER_REJECTED_CODE = "unsupported_native_inflight_message";
|
|
62
|
+
/**
|
|
63
|
+
* A Codex turn the native turn lane dropped because omp steered it. The
|
|
64
|
+
* rejection answers our own `response.steer`, not the model's health: the
|
|
65
|
+
* provider stops steering the session, so the same model replays cleanly.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isCodexSteerRejection(message: {
|
|
68
|
+
api?: Api;
|
|
69
|
+
errorMessage?: string;
|
|
70
|
+
}): boolean;
|
|
46
71
|
export declare const TRANSIENT_TRANSPORT_PATTERN: RegExp;
|
|
47
72
|
export declare const ANTHROPIC_ACCOUNT_POLICY_PATTERN: RegExp;
|
|
48
73
|
/** Whether an error message represents an Anthropic account-scoped permission/policy denial. */
|
|
@@ -98,6 +123,19 @@ export declare function isGrammarError(error: unknown): boolean;
|
|
|
98
123
|
* Accessor for {@link Flag.FastModeUnsupported}.
|
|
99
124
|
*/
|
|
100
125
|
export declare function isFastModeUnsupported(error: unknown): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* An Anthropic-compatible endpoint returned a 400 rejecting something about
|
|
128
|
+
* `cache_control`. Whether it refused the field or one nested option is not
|
|
129
|
+
* decidable here (see {@link CACHE_CONTROL_FIELD_PATTERN}); the caller's retry
|
|
130
|
+
* ladder settles it by replaying.
|
|
131
|
+
* Accessor for {@link Flag.CacheControlUnsupported}.
|
|
132
|
+
*
|
|
133
|
+
* Unlike the high-bit accessors this also requires a classified id. The flag
|
|
134
|
+
* sits in the raw-status lane (see {@link Flag.CacheControlUnsupported}), and
|
|
135
|
+
* while no HTTP status reaches 0x800, `is` is a bare bit test — the extra gate
|
|
136
|
+
* keeps a stray non-HTTP status out of the retry path.
|
|
137
|
+
*/
|
|
138
|
+
export declare function isCacheControlUnsupported(error: unknown): boolean;
|
|
101
139
|
/**
|
|
102
140
|
* Cline's gateway gates some roster entries (certain free-tier models) to its
|
|
103
141
|
* own product surfaces with a 403. The API key is valid — the restriction is
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Api, type ImageGenerationApi, type Model } from "@linxiraos/pi-catalog/types";
|
|
2
2
|
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
3
|
export * from "./google-antigravity.js";
|
|
4
4
|
export * from "./google-generative-ai.js";
|
|
@@ -6,8 +6,7 @@ export * from "./openai-hosted.js";
|
|
|
6
6
|
export * from "./openai-images.js";
|
|
7
7
|
export * from "./openrouter-images.js";
|
|
8
8
|
export * from "./types.js";
|
|
9
|
-
|
|
10
|
-
export type ImageGenerationApi = "openai-images" | "openrouter-images" | "google-generative-ai" | "google-gemini-cli" | "openai-responses" | "openai-codex-responses";
|
|
9
|
+
export type { ImageGenerationApi } from "@linxiraos/pi-catalog/types";
|
|
11
10
|
/** Whether a catalog API generates images through one of the pi-ai image clients. */
|
|
12
11
|
export declare function isImageGenerationApi(api: Api): api is ImageGenerationApi;
|
|
13
12
|
/** Generate (or edit, when `request.inputImages` is set) images through the transport selected by the model's `api`. */
|
|
@@ -32,6 +32,12 @@ export declare function decodeImageResponse(value: unknown, fetch: FetchImpl, si
|
|
|
32
32
|
images: GeneratedImage[];
|
|
33
33
|
usage: Usage;
|
|
34
34
|
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Mime type of a base64 image, read from its header only. 64 base64 chars
|
|
37
|
+
* decode to 48 bytes, past every magic number `parseImageMetadata` checks, so
|
|
38
|
+
* multi-MB payloads are never fully decoded just to be labelled.
|
|
39
|
+
*/
|
|
40
|
+
export declare function sniffBase64ImageMimeType(base64: string): string | undefined;
|
|
35
41
|
export declare function toDataUrl(image: GeneratedImage): string;
|
|
36
42
|
export declare function resolveOpenAIImageSize(aspectRatio?: string, imageSize?: string): string | undefined;
|
|
37
43
|
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { type Type, type } from "@linxiraos/pi-omptype";
|
|
2
2
|
export * from "./api-registry.js";
|
|
3
3
|
export type * from "./auth-broker/index.js";
|
|
4
|
-
export type { AuthGatewayBootOptions, ModelResolver } from "./auth-gateway/dispatch.js";
|
|
4
|
+
export type { AuthGatewayBootOptions, AuthGatewayRouteOptions, ModelResolver } from "./auth-gateway/dispatch.js";
|
|
5
5
|
export * from "./auth-gateway/types.js";
|
|
6
6
|
export * from "./auth-retry.js";
|
|
7
7
|
export * from "./auth-storage.js";
|
|
@@ -39,6 +39,7 @@ export type * from "./providers/openai-responses.js";
|
|
|
39
39
|
export type * from "./providers/synthetic.js";
|
|
40
40
|
export * from "./registry/index.js";
|
|
41
41
|
export { resolveCacheRetention } from "./utils.js";
|
|
42
|
+
export * from "./env-api-key.js";
|
|
42
43
|
export * from "./stream.js";
|
|
43
44
|
export * from "./types.js";
|
|
44
45
|
export * from "./usage.js";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Api, FetchImpl } from "@linxiraos/pi-catalog/types";
|
|
2
|
+
import { type ApiKey } from "../auth-retry.js";
|
|
3
|
+
import * as AIError from "../error/index.js";
|
|
4
|
+
import type { Model, Usage } from "../types.js";
|
|
5
|
+
import { type Judge, type JudgeOptions, type JudgmentRequest, type JudgmentResult, type Questions } from "./types.js";
|
|
6
|
+
import type { JudgmentWire } from "./wire.js";
|
|
7
|
+
export declare const TYPESAFE_PROVIDER = "typesafe";
|
|
8
|
+
export declare const TYPESAFE_DEFAULT_MODEL = "jev-latest";
|
|
9
|
+
declare const JUDGMENT_WIRES: {
|
|
10
|
+
readonly typesafe: JudgmentWire;
|
|
11
|
+
readonly "openrouter-decisions": JudgmentWire;
|
|
12
|
+
readonly "workers-ai-systemone": JudgmentWire;
|
|
13
|
+
readonly "openai-decisions": JudgmentWire;
|
|
14
|
+
};
|
|
15
|
+
/** APIs {@link NativeJudge} can serve. */
|
|
16
|
+
export type JudgmentApi = keyof typeof JUDGMENT_WIRES;
|
|
17
|
+
/** Whether a catalog API answers judgments natively. */
|
|
18
|
+
export declare function isJudgmentApi(api: Api): api is JudgmentApi;
|
|
19
|
+
/** `TYPESAFE_BASE_URL` when set, else the public API root; trailing slashes stripped. */
|
|
20
|
+
export declare function typesafeBaseUrl(): string;
|
|
21
|
+
/** `TYPESAFE_DEFAULT_MODEL` when set, else {@link TYPESAFE_DEFAULT_MODEL}. */
|
|
22
|
+
export declare function typesafeModel(): string;
|
|
23
|
+
/** Credential and transport overrides for a judge; see {@link createNativeJudge}. */
|
|
24
|
+
export interface NativeJudgeConnection {
|
|
25
|
+
apiKey: ApiKey;
|
|
26
|
+
/** Static headers attached to judgment requests (e.g. proxy routing, gateway auth). */
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
fetch?: FetchImpl;
|
|
29
|
+
}
|
|
30
|
+
export interface NativeJudgeOptions extends NativeJudgeConnection {
|
|
31
|
+
/** Wire dialect; defaults to TypeSafe's own API. */
|
|
32
|
+
api?: JudgmentApi;
|
|
33
|
+
/** Catalog provider reported on results; defaults to {@link TYPESAFE_PROVIDER}. */
|
|
34
|
+
provider?: string;
|
|
35
|
+
/** Defaults to {@link typesafeBaseUrl}. */
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
/** Wire model id; defaults to {@link typesafeModel}. */
|
|
38
|
+
model?: string;
|
|
39
|
+
/** Per-attempt timeout; defaults to {@link DEFAULT_TIMEOUT_MS}. */
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Most questions per request the endpoint accepts, a positive integer; larger
|
|
43
|
+
* requests are split. Unset: no cap.
|
|
44
|
+
*/
|
|
45
|
+
maxQuestions?: number;
|
|
46
|
+
}
|
|
47
|
+
/** Per-call options for {@link NativeJudge.judge}. */
|
|
48
|
+
export interface NativeJudgeCallOptions extends JudgeOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Called before a split judgment rejects, with the summed usage of the chunks that had already
|
|
51
|
+
* succeeded: billed upstream, but their answers are discarded with the failure. Not called when
|
|
52
|
+
* no chunk succeeded or the request was not split.
|
|
53
|
+
*/
|
|
54
|
+
onPartialUsage?: (usage: Usage) => void;
|
|
55
|
+
}
|
|
56
|
+
/** Non-2xx response from a native judgment API. */
|
|
57
|
+
export declare class JudgmentApiError extends AIError.ProviderHttpError {
|
|
58
|
+
readonly name = "JudgmentApiError";
|
|
59
|
+
}
|
|
60
|
+
export declare class NativeJudge implements Judge {
|
|
61
|
+
#private;
|
|
62
|
+
readonly label: string;
|
|
63
|
+
readonly api: JudgmentApi;
|
|
64
|
+
readonly provider: string;
|
|
65
|
+
/** Wire model id sent with every request. */
|
|
66
|
+
readonly model: string;
|
|
67
|
+
readonly baseUrl: string;
|
|
68
|
+
constructor(options: NativeJudgeOptions);
|
|
69
|
+
judge<Q extends Questions>(request: JudgmentRequest<Q>, options?: NativeJudgeCallOptions): Promise<JudgmentResult<Q>>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The {@link NativeJudge} for a catalog judge model: its API's dialect, wire id
|
|
73
|
+
* (`requestModelId ?? id`), base URL, and catalog question cap
|
|
74
|
+
* (`judgment-questions-max`). Shared by the coding agent's judge chain and the
|
|
75
|
+
* auth-gateway System One route so both address a model the same way.
|
|
76
|
+
*
|
|
77
|
+
* @throws ConfigurationError when the model's API is not a judgment API.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createNativeJudge(model: Model, connection: NativeJudgeConnection): NativeJudge;
|
|
80
|
+
export {};
|