@oh-my-pi/pi-ai 18.2.6 → 18.2.8
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 +29 -1
- package/THIRD-PARTY-NOTICES.txt +0 -37
- package/dist/types/auth-gateway/dispatch.d.ts +80 -0
- package/dist/types/auth-gateway/http.d.ts +5 -6
- package/dist/types/auth-gateway/index.d.ts +1 -0
- package/dist/types/auth-gateway/routes/embeddings.d.ts +3 -0
- package/dist/types/auth-gateway/routes/images.d.ts +3 -0
- package/dist/types/auth-gateway/routes/rerank.d.ts +3 -0
- package/dist/types/auth-gateway/routes/speech.d.ts +2 -0
- package/dist/types/auth-gateway/routes/systemone.d.ts +2 -0
- package/dist/types/auth-gateway/routes/transcriptions.d.ts +3 -0
- package/dist/types/auth-gateway/routes/video.d.ts +7 -0
- package/dist/types/auth-gateway/server.d.ts +10 -16
- package/dist/types/auth-retry.d.ts +2 -0
- package/dist/types/auth-storage.d.ts +2 -2
- package/dist/types/embeddings/index.d.ts +7 -0
- package/dist/types/embeddings/openai-embeddings.d.ts +15 -0
- package/dist/types/embeddings/types.d.ts +15 -0
- package/dist/types/error/classes.d.ts +4 -1
- package/dist/types/error/flags.d.ts +12 -4
- package/dist/types/images/google-antigravity.d.ts +9 -0
- package/dist/types/images/google-generative-ai.d.ts +3 -0
- package/dist/types/images/index.d.ts +14 -0
- package/dist/types/images/openai-hosted.d.ts +3 -0
- package/dist/types/images/openai-images.d.ts +5 -0
- package/dist/types/images/openrouter-images.d.ts +3 -0
- package/dist/types/images/shared.d.ts +34 -0
- package/dist/types/images/types.d.ts +31 -0
- package/dist/types/index.d.ts +21 -13
- package/dist/types/judgment/types.d.ts +5 -2
- package/dist/types/judgment/typesafe.d.ts +18 -22
- package/dist/types/providers/anthropic-compaction.d.ts +10 -0
- package/dist/types/providers/anthropic-identity.d.ts +18 -0
- package/dist/types/providers/anthropic-state.d.ts +13 -0
- package/dist/types/providers/anthropic.d.ts +6 -59
- package/dist/types/providers/embeddings-server.d.ts +32 -0
- package/dist/types/providers/gitlab-duo.d.ts +0 -1
- package/dist/types/providers/images-server.d.ts +22 -0
- package/dist/types/providers/kimi.d.ts +1 -5
- package/dist/types/providers/openai-codex-attestation.d.ts +6 -0
- package/dist/types/providers/openai-codex-compaction.d.ts +6 -0
- package/dist/types/providers/openai-codex-responses.d.ts +3 -27
- package/dist/types/providers/openai-codex-transport.d.ts +7 -0
- package/dist/types/providers/openai-shared.d.ts +0 -9
- package/dist/types/providers/register-builtins.d.ts +20 -22
- package/dist/types/providers/rerank-server.d.ts +35 -0
- package/dist/types/providers/speech-server.d.ts +8 -0
- package/dist/types/providers/synthetic.d.ts +1 -5
- package/dist/types/providers/systemone-server.d.ts +26 -0
- package/dist/types/providers/transcriptions-server.d.ts +32 -0
- package/dist/types/providers/video-server.d.ts +39 -0
- package/dist/types/rerank/index.d.ts +7 -0
- package/dist/types/rerank/openrouter-rerank.d.ts +15 -0
- package/dist/types/rerank/types.d.ts +17 -0
- package/dist/types/speech/index.d.ts +13 -0
- package/dist/types/speech/openai-speech.d.ts +3 -0
- package/dist/types/speech/transport.d.ts +7 -0
- package/dist/types/speech/types.d.ts +24 -0
- package/dist/types/speech/xai-tts.d.ts +7 -0
- package/dist/types/transcription/index.d.ts +7 -0
- package/dist/types/transcription/openai-transcriptions.d.ts +15 -0
- package/dist/types/transcription/types.d.ts +41 -0
- package/dist/types/video/index.d.ts +11 -0
- package/dist/types/video/openrouter-video.d.ts +19 -0
- package/dist/types/video/types.d.ts +62 -0
- package/package.json +30 -6
- package/src/auth-gateway/dispatch.ts +273 -0
- package/src/auth-gateway/http.ts +6 -7
- package/src/auth-gateway/index.ts +1 -0
- package/src/auth-gateway/routes/embeddings.ts +98 -0
- package/src/auth-gateway/routes/images.ts +131 -0
- package/src/auth-gateway/routes/rerank.ts +87 -0
- package/src/auth-gateway/routes/speech.ts +101 -0
- package/src/auth-gateway/routes/systemone.ts +116 -0
- package/src/auth-gateway/routes/transcriptions.ts +98 -0
- package/src/auth-gateway/routes/video.ts +243 -0
- package/src/auth-gateway/server.ts +123 -260
- package/src/auth-retry.ts +3 -0
- package/src/auth-storage.ts +28 -22
- package/src/embeddings/index.ts +17 -0
- package/src/embeddings/openai-embeddings.ts +141 -0
- package/src/embeddings/types.ts +14 -0
- package/src/error/auth-classify.ts +10 -2
- package/src/error/classes.ts +23 -3
- package/src/error/flags.ts +51 -16
- package/src/error/rate-limit.ts +1 -1
- package/src/images/google-antigravity.ts +180 -0
- package/src/images/google-generative-ai.ts +92 -0
- package/src/images/index.ts +59 -0
- package/src/images/openai-hosted.ts +185 -0
- package/src/images/openai-images.ts +110 -0
- package/src/images/openrouter-images.ts +33 -0
- package/src/images/shared.ts +193 -0
- package/src/images/types.ts +36 -0
- package/src/index.ts +22 -13
- package/src/judgment/types.ts +6 -3
- package/src/judgment/typesafe.ts +58 -48
- package/src/provider-session-state.ts +1 -1
- package/src/providers/anthropic-compaction.ts +54 -0
- package/src/providers/anthropic-identity.ts +136 -0
- package/src/providers/anthropic-state.ts +55 -0
- package/src/providers/anthropic.ts +39 -296
- package/src/providers/bedrock-mantle.ts +1 -1
- package/src/providers/embeddings-server.ts +151 -0
- package/src/providers/gitlab-duo.ts +0 -4
- package/src/providers/images-server.ts +159 -0
- package/src/providers/kimi.ts +1 -8
- package/src/providers/openai-codex-attestation.ts +19 -0
- package/src/providers/openai-codex-compaction.ts +18 -0
- package/src/providers/openai-codex-responses.ts +9 -68
- package/src/providers/openai-codex-transport.ts +18 -0
- package/src/providers/openai-shared.ts +1 -10
- package/src/providers/register-builtins.ts +113 -320
- package/src/providers/rerank-server.ts +166 -0
- package/src/providers/speech-server.ts +53 -0
- package/src/providers/synthetic.ts +1 -8
- package/src/providers/systemone-server.ts +73 -0
- package/src/providers/transcriptions-server.ts +243 -0
- package/src/providers/video-server.ts +286 -0
- package/src/registry/cloudflare-ai-gateway.ts +1 -1
- package/src/rerank/index.ts +13 -0
- package/src/rerank/openrouter-rerank.ts +136 -0
- package/src/rerank/types.ts +20 -0
- package/src/speech/index.ts +35 -0
- package/src/speech/openai-speech.ts +26 -0
- package/src/speech/transport.ts +66 -0
- package/src/speech/types.ts +37 -0
- package/src/speech/xai-tts.ts +41 -0
- package/src/stream.ts +7 -15
- package/src/transcription/index.ts +17 -0
- package/src/transcription/openai-transcriptions.ts +133 -0
- package/src/transcription/types.ts +46 -0
- package/src/utils/anthropic-auth.ts +3 -6
- package/src/video/index.ts +34 -0
- package/src/video/openrouter-video.ts +210 -0
- package/src/video/types.ts +72 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [18.2.8] - 2026-09-21
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added support for text embeddings, document reranking, video generation, image generation across multiple providers, audio speech synthesis, and audio transcription services.
|
|
10
|
+
- Added support for the System One judgment API, including configurable request headers for proxy routing and custom authentication.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Updated API response cost reporting to use aggregate usage totals.
|
|
15
|
+
- Model list responses now optionally include a model kind.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Fixed detection of Claude usage-limit errors.
|
|
20
|
+
|
|
21
|
+
## [18.2.7] - 2026-09-21
|
|
22
|
+
|
|
23
|
+
### Breaking Changes
|
|
24
|
+
|
|
25
|
+
- Anthropic streaming and provider request helpers must now be imported from `@oh-my-pi/pi-ai/providers/anthropic` instead of the package root.
|
|
26
|
+
- Moved the public `NO_AUTH_SENTINEL` export from `providers/openai-shared` to `auth-retry`.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- Anthropic organization-level OAuth permission errors now reliably rotate to sibling credentials and persist blocks across usage reports.
|
|
31
|
+
- Fixed error handling for provider responses that do not include token usage information.
|
|
32
|
+
|
|
5
33
|
## [18.2.6] - 2026-09-18
|
|
6
34
|
|
|
7
35
|
### Fixed
|
|
@@ -78,7 +106,7 @@
|
|
|
78
106
|
- Fixed openai-responses replay wedging a repaired orphan tool-result note between another call's `function_call` and `function_call_output`, which broke round pairing on strict validators (e.g. DeepSeek) with `400 No tool output found for tool call …`: orphan-output/call repair now runs before the interleaved-message hoist, so any injected note is relocated out of the tool-call batch ([#11473](https://github.com/can1357/oh-my-pi/issues/11473)).
|
|
79
107
|
- A stale Anthropic tier block (`tier:fable`, `tier:mythos`) is now cleared once a live usage report shows headroom on both the tier row and the shared windows, instead of idling a usable account until the reported reset. Healing requires a live report, and a credential held by an unscoped block spends no usage request on a probe that cannot lift it ([#11334](https://github.com/can1357/oh-my-pi/pull/11334) by [@AshishKumar4](https://github.com/AshishKumar4)).
|
|
80
108
|
- A running session now picks up credentials another process committed: adding an account in a second terminal is visible to credential selection and rotation without restarting the session, and a session's pinned account is re-resolved by row id so a row another process deleted cannot hand its slot to a sibling ([#11329](https://github.com/can1357/oh-my-pi/pull/11329) by [@AshishKumar4](https://github.com/AshishKumar4)).
|
|
81
|
-
- Fixed rate-limit/overload failures that arrive
|
|
109
|
+
- Fixed rate-limit/overload failures that arrive _inside_ an HTTP 200 body (Azure, LiteLLM-style aggregators, and reverse proxies that already committed to the stream) not advancing `retry.fallbackChains`: a `{"error":{…}}`/`{"code":429}` chunk or a plain-text throttle frame (`429 Too Many Requests`, an nginx page) is now classified as a retryable 429/5xx through the same path an HTTP-status 429 takes, so a busy provider backs off and fails over instead of ending the session. Only bodies the provider actually reported are used: no status is inferred from error wording, and an unreadable body can no longer consume a credential.
|
|
82
110
|
- Fixed tool schema normalization and cycle detection for frozen, sealed, and nonextensible schemas.
|
|
83
111
|
- Reduced memory retained by `complete()` and `completeSimple()` while streaming responses.
|
|
84
112
|
- Antigravity quota summaries now identify Claude/GPT routing copies as one shared upstream pool while preserving model-specific quota selection ([#11268](https://github.com/can1357/oh-my-pi/issues/11268)).
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -335,43 +335,6 @@ This license allows the work and adaptations of it to be shared and used
|
|
|
335
335
|
commercially, as long as it is attributed to Poppy Works. The font is bundled
|
|
336
336
|
here (crates/pi-natives/src/fonts/Silver.ttf) as a CJK/Unicode bitmap fallback.
|
|
337
337
|
|
|
338
|
-
-------------------------------------------------------------------------------
|
|
339
|
-
packages/utils/src/vendor/mermaid-ascii/NOTICE
|
|
340
|
-
|
|
341
|
-
This directory contains an in-house Mermaid-diagram-to-ASCII renderer adapted
|
|
342
|
-
from beautiful-mermaid (https://github.com/lukilabs/beautiful-mermaid), used
|
|
343
|
-
under the MIT License.
|
|
344
|
-
|
|
345
|
-
Copyright (c) 2026 Craft Docs
|
|
346
|
-
|
|
347
|
-
Only the ASCII rendering pipeline is ported (flowchart/state, sequence, class,
|
|
348
|
-
ER, and xychart diagrams); the SVG renderer and its `elkjs` graph-layout
|
|
349
|
-
dependency, the browser entry point, and the SVG theme/style modules were
|
|
350
|
-
dropped. Terminal display width is reimplemented on `Bun.stringWidth`, and
|
|
351
|
-
inline label formatting (HTML tags, markdown emphasis) is reduced to plain text
|
|
352
|
-
for ASCII output. Layout and edge-routing logic is preserved faithfully so
|
|
353
|
-
ASCII output matches the upstream package.
|
|
354
|
-
|
|
355
|
-
MIT License
|
|
356
|
-
|
|
357
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
358
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
359
|
-
in the Software without restriction, including without limitation the rights
|
|
360
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
361
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
362
|
-
furnished to do so, subject to the following conditions:
|
|
363
|
-
|
|
364
|
-
The above copyright notice and this permission notice shall be included in all
|
|
365
|
-
copies or substantial portions of the Software.
|
|
366
|
-
|
|
367
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
368
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
369
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
370
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
371
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
372
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
373
|
-
SOFTWARE.
|
|
374
|
-
|
|
375
338
|
-------------------------------------------------------------------------------
|
|
376
339
|
packages/coding-agent/src/markit/NOTICE
|
|
377
340
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ApiKeyResolver } from "../auth-retry.js";
|
|
2
|
+
import type { AuthStorage } from "../auth-storage.js";
|
|
3
|
+
import { type GatewayErrorClassification } from "../error/gateway.js";
|
|
4
|
+
import type { Api, FetchImpl, Model, Usage } from "../types.js";
|
|
5
|
+
import type { ClientUsageIdentity } from "../usage.js";
|
|
6
|
+
import type { AuthGatewayServerOptions } from "./types.js";
|
|
7
|
+
export type ModelResolver = (modelId: string) => Model<Api> | undefined;
|
|
8
|
+
export interface AuthGatewayBootOptions extends AuthGatewayServerOptions {
|
|
9
|
+
/** Source of credentials. Caller wires this to a broker-backed AuthStorage. */
|
|
10
|
+
storage: AuthStorage;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a client-requested model id to a pi-ai Model. Caller supplies
|
|
13
|
+
* this from a ModelRegistry (lives in `coding-agent` to avoid an inverse
|
|
14
|
+
* dependency in `pi-ai`).
|
|
15
|
+
*/
|
|
16
|
+
resolveModel: ModelResolver;
|
|
17
|
+
/** Optional supplier for `/v1/models` listing. Returns the full model array. */
|
|
18
|
+
listModels?: () => Iterable<Model<Api>>;
|
|
19
|
+
/** Upstream transport for every provider call; defaults to global `fetch`. Test seam. */
|
|
20
|
+
fetch?: FetchImpl;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The client's own session key, or `undefined` when it sent none. A blank key
|
|
24
|
+
* counts as none: honouring it would collapse every caller that sends an empty
|
|
25
|
+
* key into one shared credential-sticky, prefix-cache and provider-session
|
|
26
|
+
* bucket.
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeClientSessionKey(clientKey: string | undefined): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Stable identity of the account a request's credential belongs to.
|
|
31
|
+
*
|
|
32
|
+
* `markUsageLimitReached` and the auth-retry resolver switch a session to a
|
|
33
|
+
* sibling credential, so the provider state retained for that session can
|
|
34
|
+
* outlive the account that taught it. OAuth rows expose an account id / email
|
|
35
|
+
* that survives token refresh — fingerprinting the bearer instead would look
|
|
36
|
+
* like a rotation every time a token refreshes and discard the retained
|
|
37
|
+
* lessons for nothing. Key-based rows fall back to a hash of the key, never
|
|
38
|
+
* the key itself: this value is held for the lifetime of the entry.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveGatewayAccount(storage: AuthStorage, provider: string, sessionId: string, apiKey: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the credential for one request from broker-backed storage.
|
|
43
|
+
*
|
|
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.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveGatewayApiKey(storage: AuthStorage, model: Model<Api>, sessionId: string, signal: AbortSignal, peer: string): Promise<string | GatewayErrorClassification>;
|
|
51
|
+
/**
|
|
52
|
+
* Build the {@link ApiKeyResolver} handed to a pi-ai client for a gateway
|
|
53
|
+
* request. Drives the central a/b/c auth-retry policy server-side:
|
|
54
|
+
*
|
|
55
|
+
* - initial resolve → the credential already resolved for this request.
|
|
56
|
+
* - step (b) `!lastChance` → force-refresh the SAME session-sticky credential
|
|
57
|
+
* (a peer/broker may have rotated its token out from under our cached copy).
|
|
58
|
+
* - step (c) `lastChance` → {@link refreshGatewayApiKeyAfterAuthError} switches
|
|
59
|
+
* to a sibling (usage-limit block vs credential invalidation by error class).
|
|
60
|
+
*
|
|
61
|
+
* `lastKey` tracks the most recent bearer so the switch step invalidates the
|
|
62
|
+
* credential that actually failed. `onResolvedKey` observes every rotation;
|
|
63
|
+
* routes that retain provider session state use it to re-key the account
|
|
64
|
+
* lease, one-shot routes pass `undefined`.
|
|
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;
|
|
67
|
+
/**
|
|
68
|
+
* Attribute one settled upstream request to the originating client via the
|
|
69
|
+
* broker's observed-usage channel (`AuthStorage.recordObservedUsage`, batched
|
|
70
|
+
* by the remote store). Error/aborted turns still record — the provider
|
|
71
|
+
* billed whatever tokens the partial turn consumed; zero-usage results
|
|
72
|
+
* (pre-flight failures) are skipped. `at` defaults to now.
|
|
73
|
+
*/
|
|
74
|
+
export declare function recordGatewayUsage(storage: AuthStorage, model: Model<Api>, client: ClientUsageIdentity, usage: Usage, at?: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* An `AbortController` that follows the inbound request's abort signal. Routes
|
|
77
|
+
* abort it themselves when the response body is cancelled mid-stream, which
|
|
78
|
+
* `req.signal` alone does not observe.
|
|
79
|
+
*/
|
|
80
|
+
export declare function mirrorRequestAbort(req: Request): AbortController;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Api,
|
|
1
|
+
import type { Api, Model } from "../types.js";
|
|
2
2
|
import type { ClientUsageIdentity } from "../usage.js";
|
|
3
3
|
export declare function json(status: number, body: unknown, headers?: Record<string, string>): Response;
|
|
4
4
|
/**
|
|
@@ -7,14 +7,13 @@ export declare function json(status: number, body: unknown, headers?: Record<str
|
|
|
7
7
|
* `request-id` (surfaced as `_request_id` by the OpenAI and Anthropic SDKs,
|
|
8
8
|
* matches the gateway log line), LiteLLM's model-resolution and cost headers,
|
|
9
9
|
* and OpenAI's `openai-processing-ms`. Model/request-id headers are always
|
|
10
|
-
* present; `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* only the identity headers.
|
|
10
|
+
* present; `costUsd` — known only once a non-streaming response has settled —
|
|
11
|
+
* adds the computed cost, and `startedAt` the wall time. Streaming responses
|
|
12
|
+
* send headers before usage exists, so they carry only the identity headers.
|
|
14
13
|
*/
|
|
15
14
|
export declare function gatewayResponseHeaders(model: Model<Api>, info: {
|
|
16
15
|
requestId: string;
|
|
17
|
-
|
|
16
|
+
costUsd?: number;
|
|
18
17
|
startedAt?: number;
|
|
19
18
|
}): Record<string, string>;
|
|
20
19
|
export declare function resolvePeer(req: Request): string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type AuthGatewayBootOptions } from "../dispatch.js";
|
|
2
|
+
export declare function handleImageGenerations(bootOpts: AuthGatewayBootOptions, req: Request, peer: string): Promise<Response>;
|
|
3
|
+
export declare function handleImageEdits(bootOpts: AuthGatewayBootOptions, req: Request, peer: string): Promise<Response>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type AuthGatewayBootOptions } from "../dispatch.js";
|
|
2
|
+
/** OpenRouter-compatible `POST /v1/videos` asynchronous video submit handler. */
|
|
3
|
+
export declare function handleVideoSubmit(bootOpts: AuthGatewayBootOptions, req: Request, peer: string): Promise<Response>;
|
|
4
|
+
/** OpenRouter-compatible `GET /v1/videos/:id` asynchronous video poll handler. */
|
|
5
|
+
export declare function handleVideoPoll(bootOpts: AuthGatewayBootOptions, req: Request, peer: string, gatewayId: string): Promise<Response>;
|
|
6
|
+
/** OpenRouter-compatible `GET /v1/videos/:id/content` streaming video content handler. */
|
|
7
|
+
export declare function handleVideoContent(bootOpts: AuthGatewayBootOptions, req: Request, peer: string, gatewayId: string): Promise<Response>;
|
|
@@ -16,21 +16,15 @@
|
|
|
16
16
|
* POST /v1/chat/completions → OpenAI chat-completions in/out
|
|
17
17
|
* POST /v1/messages → Anthropic messages in/out
|
|
18
18
|
* POST /v1/responses → OpenAI Responses in/out
|
|
19
|
+
* POST /v1/pi/stream → native pi-ai stream in/out
|
|
20
|
+
* POST /v1/systemone | /alpha/decisions → TypeSafe System One judgments (routes/systemone)
|
|
21
|
+
* POST /v1/images[/generations|/edits] → image generation, OpenAI/OpenRouter wire (routes/images)
|
|
22
|
+
* POST /v1/audio/speech → text-to-speech, raw audio out (routes/speech)
|
|
23
|
+
* POST /v1/audio/transcriptions → speech-to-text, multipart or JSON base64 in (routes/transcriptions)
|
|
24
|
+
*
|
|
25
|
+
* Chat routes live in this file; every other modality is a `routes/*` module
|
|
26
|
+
* built on the shared plumbing in `dispatch.ts`.
|
|
19
27
|
*/
|
|
20
|
-
import type
|
|
21
|
-
import type {
|
|
22
|
-
import type { AuthGatewayServerHandle, AuthGatewayServerOptions } from "./types.js";
|
|
23
|
-
export type ModelResolver = (modelId: string) => Model<Api> | undefined;
|
|
24
|
-
export interface AuthGatewayBootOptions extends AuthGatewayServerOptions {
|
|
25
|
-
/** Source of credentials. Caller wires this to a broker-backed AuthStorage. */
|
|
26
|
-
storage: AuthStorage;
|
|
27
|
-
/**
|
|
28
|
-
* Resolve a client-requested model id to a pi-ai Model. Caller supplies
|
|
29
|
-
* this from a ModelRegistry (lives in `coding-agent` to avoid an inverse
|
|
30
|
-
* dependency in `pi-ai`).
|
|
31
|
-
*/
|
|
32
|
-
resolveModel: ModelResolver;
|
|
33
|
-
/** Optional supplier for `/v1/models` listing. Returns the full model array. */
|
|
34
|
-
listModels?: () => Iterable<Model<Api>>;
|
|
35
|
-
}
|
|
28
|
+
import { type AuthGatewayBootOptions } from "./dispatch.js";
|
|
29
|
+
import type { AuthGatewayServerHandle } from "./types.js";
|
|
36
30
|
export declare function startAuthGateway(opts: AuthGatewayBootOptions): AuthGatewayServerHandle;
|
|
@@ -35,6 +35,8 @@ export interface ApiKeyResolveContext {
|
|
|
35
35
|
export type ApiKeyResolver = (ctx: ApiKeyResolveContext) => Promise<string | undefined> | string | undefined;
|
|
36
36
|
/** A static bearer string, or a {@link ApiKeyResolver} that mints/rotates one. */
|
|
37
37
|
export type ApiKey = string | ApiKeyResolver;
|
|
38
|
+
/** Keyless-provider credential marker; transports must not send it in authentication headers. */
|
|
39
|
+
export declare const NO_AUTH_SENTINEL = "N/A";
|
|
38
40
|
/** Narrows {@link ApiKey} to its resolver form. */
|
|
39
41
|
export declare function isApiKeyResolver(key: ApiKey | undefined): key is ApiKeyResolver;
|
|
40
42
|
/**
|
|
@@ -1218,8 +1218,8 @@ export declare class AuthStorage {
|
|
|
1218
1218
|
* stale session stickiness. Fall back to the session-sticky credential only
|
|
1219
1219
|
* when neither explicit target is available. For hard-auth errors, an explicit
|
|
1220
1220
|
* target that no longer matches storage returns `false` without mutation.
|
|
1221
|
-
* Delayed usage-limit errors may instead recover the durable
|
|
1222
|
-
* the bearer fingerprint recorded when the request resolved.
|
|
1221
|
+
* Delayed usage-limit and account-policy errors may instead recover the durable
|
|
1222
|
+
* OAuth row from the bearer fingerprint recorded when the request resolved.
|
|
1223
1223
|
*
|
|
1224
1224
|
* - usage-limit / account-rate-limit error → {@link AuthStorage.markUsageLimitReached}
|
|
1225
1225
|
* (temporary block via its own backoff — default plus server usage-report
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import { type EmbeddingOptions } from "./openai-embeddings.js";
|
|
3
|
+
import type { EmbeddingRequest, EmbeddingResult } from "./types.js";
|
|
4
|
+
export * from "./openai-embeddings.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
/** Dispatch an embedding request through the transport selected by the catalog model. */
|
|
7
|
+
export declare function embed(model: Model<Api>, request: EmbeddingRequest, options: EmbeddingOptions): Promise<EmbeddingResult>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Api, FetchImpl, Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import { type ApiKey } from "../auth-retry.js";
|
|
3
|
+
import * as AIError from "../error/index.js";
|
|
4
|
+
import type { EmbeddingRequest, EmbeddingResult } from "./types.js";
|
|
5
|
+
export interface EmbeddingOptions {
|
|
6
|
+
apiKey: ApiKey;
|
|
7
|
+
fetch?: FetchImpl;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
/** Non-2xx response from an OpenAI-compatible embeddings endpoint. */
|
|
11
|
+
export declare class EmbeddingApiError extends AIError.ProviderHttpError {
|
|
12
|
+
readonly name = "EmbeddingApiError";
|
|
13
|
+
}
|
|
14
|
+
/** Call an OpenAI/OpenRouter-compatible embeddings endpoint. */
|
|
15
|
+
export declare function embedOpenAI(model: Model<Api>, request: EmbeddingRequest, options: EmbeddingOptions): Promise<EmbeddingResult>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Usage } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
export interface EmbeddingRequest {
|
|
3
|
+
input: string | string[] | number[] | number[][];
|
|
4
|
+
dimensions?: number;
|
|
5
|
+
encodingFormat: "float" | "base64";
|
|
6
|
+
user?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface EmbeddingResult {
|
|
9
|
+
embeddings: Array<{
|
|
10
|
+
index: number;
|
|
11
|
+
embedding: number[] | string;
|
|
12
|
+
}>;
|
|
13
|
+
model: string;
|
|
14
|
+
usage: Usage;
|
|
15
|
+
}
|
|
@@ -39,7 +39,10 @@ export declare const __anthropicApiErrorForTesting: {
|
|
|
39
39
|
export declare class AnthropicApiError extends ProviderHttpError {
|
|
40
40
|
readonly headers: Headers;
|
|
41
41
|
readonly requestId: string | null;
|
|
42
|
-
constructor(status: number, message: string, headers: Headers
|
|
42
|
+
constructor(status: number, message: string, headers: Headers, options?: {
|
|
43
|
+
code?: string;
|
|
44
|
+
cause?: unknown;
|
|
45
|
+
});
|
|
43
46
|
static fromResponse(response: Response, signal?: AbortSignal): Promise<AnthropicApiError>;
|
|
44
47
|
}
|
|
45
48
|
/** Network-level failure (DNS, TLS, socket reset) after retries were exhausted. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Api, AssistantMessage } from "../types.js";
|
|
1
|
+
import type { Api, AssistantMessage, Usage } from "../types.js";
|
|
2
2
|
export declare const Flag: {
|
|
3
3
|
readonly Class: 4096;
|
|
4
4
|
readonly ThinkingLoop: 65536;
|
|
@@ -44,6 +44,9 @@ export declare function isResponsesRequestBodyReadTimeout(message: {
|
|
|
44
44
|
requestBodyReadTimeoutFullReplay?: boolean;
|
|
45
45
|
}): boolean;
|
|
46
46
|
export declare const TRANSIENT_TRANSPORT_PATTERN: RegExp;
|
|
47
|
+
export declare const ANTHROPIC_ACCOUNT_POLICY_PATTERN: RegExp;
|
|
48
|
+
/** Whether an error message represents an Anthropic account-scoped permission/policy denial. */
|
|
49
|
+
export declare function isAnthropicAccountPolicyText(text: string, provider?: string, statusArg?: number): boolean;
|
|
47
50
|
/**
|
|
48
51
|
* Local llama.cpp / Ollama deterministic tool-call argument JSON parse failure.
|
|
49
52
|
* The model emitted invalid JSON in a tool call and the server returned HTTP 500
|
|
@@ -121,16 +124,21 @@ export declare function classifyMessage(message: {
|
|
|
121
124
|
errorStatus?: number;
|
|
122
125
|
}): number;
|
|
123
126
|
export declare function attach<E extends object>(error: E, id: number): E;
|
|
127
|
+
/** Overflow-classification evidence, including errors received before token usage is available. */
|
|
128
|
+
export interface ContextOverflowMessage extends Pick<AssistantMessage, "errorId" | "stopReason" | "errorMessage"> {
|
|
129
|
+
readonly usage?: Pick<Usage, "input" | "cacheRead" | "cacheWrite">;
|
|
130
|
+
}
|
|
124
131
|
/** Provider-reported usage proves context-window excess — authoritative, compaction-owned (#9235). */
|
|
125
|
-
export declare function isUsageBackedContextOverflow(message:
|
|
126
|
-
|
|
132
|
+
export declare function isUsageBackedContextOverflow(message: ContextOverflowMessage, contextWindow?: number): boolean;
|
|
133
|
+
/** Classify overflow from error flags, available token usage, or provider error text. */
|
|
134
|
+
export declare function isContextOverflow(message: ContextOverflowMessage, contextWindow?: number): boolean;
|
|
127
135
|
/** HTTP 413 byte/media rejection (#9235); may co-occur with {@link isContextOverflow} for bare `413 (no body)`.
|
|
128
136
|
* Callers with local headroom should skip compaction when this returns true. */
|
|
129
137
|
export declare function isPayloadRejection(message: AssistantMessage): boolean;
|
|
130
138
|
/** Dual-flagged 413 (PayloadRejected + ContextOverflow) with no provider-reported token excess (#9235).
|
|
131
139
|
* The co-flag means a different provider's larger byte/media budget may accept the request.
|
|
132
140
|
* Usage-backed overflows are authoritative window excesses and never ambiguous. */
|
|
133
|
-
export declare function isTextAmbiguousContextOverflow(errorId: number, message:
|
|
141
|
+
export declare function isTextAmbiguousContextOverflow(errorId: number, message: ContextOverflowMessage | undefined, contextWindow?: number): boolean;
|
|
134
142
|
export declare function stringify(id: number | undefined): string;
|
|
135
143
|
/**
|
|
136
144
|
* Transient stream corruption where the response was truncated mid-JSON.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
|
+
interface AntigravityCredentials {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseAntigravityCredentials(raw: string): AntigravityCredentials | undefined;
|
|
8
|
+
export declare function generateAntigravityImage(model: Model, request: ImageGenerationRequest, options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
|
+
export declare function generateGoogleImage(model: Model, request: ImageGenerationRequest, options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
|
+
export * from "./google-antigravity.js";
|
|
4
|
+
export * from "./google-generative-ai.js";
|
|
5
|
+
export * from "./openai-hosted.js";
|
|
6
|
+
export * from "./openai-images.js";
|
|
7
|
+
export * from "./openrouter-images.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
/** Catalog APIs {@link generateImage} serves; the hosted Responses pair needs an explicit carrier model. */
|
|
10
|
+
export type ImageGenerationApi = "openai-images" | "openrouter-images" | "google-generative-ai" | "google-gemini-cli" | "openai-responses" | "openai-codex-responses";
|
|
11
|
+
/** Whether a catalog API generates images through one of the pi-ai image clients. */
|
|
12
|
+
export declare function isImageGenerationApi(api: Api): api is ImageGenerationApi;
|
|
13
|
+
/** Generate (or edit, when `request.inputImages` is set) images through the transport selected by the model's `api`. */
|
|
14
|
+
export declare function generateImage(model: Model<Api>, request: ImageGenerationRequest, options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
|
+
export declare function generateHostedImage(model: Model, request: ImageGenerationRequest, options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
|
+
export declare const XAI_MAX_EDIT_IMAGES = 3;
|
|
4
|
+
export declare function resolveXAIResolution(imageSize?: string): "1k" | "2k";
|
|
5
|
+
export declare function generateOpenAIImage(model: Model, request: ImageGenerationRequest, options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Model } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ImageGenerationOptions, ImageGenerationRequest, ImageGenerationResult } from "./types.js";
|
|
3
|
+
export declare function generateOpenRouterImage(model: Model, request: ImageGenerationRequest, options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FetchImpl, Model, Usage } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ApiKey } from "../auth-retry.js";
|
|
3
|
+
import * as AIError from "../error/index.js";
|
|
4
|
+
import type { GeneratedImage } from "./types.js";
|
|
5
|
+
export declare class ImageApiError extends AIError.ProviderHttpError {
|
|
6
|
+
readonly name = "ImageApiError";
|
|
7
|
+
}
|
|
8
|
+
export declare function emptyUsage(input?: number, output?: number, cost?: number): Usage;
|
|
9
|
+
export declare function usageFromWire(value: unknown): Usage;
|
|
10
|
+
export declare function imageBaseUrl(model: Model): string;
|
|
11
|
+
export declare function modelHeaders(model: Model, signal?: AbortSignal): Promise<Record<string, string>>;
|
|
12
|
+
export declare function errorMessage(rawText: string): string;
|
|
13
|
+
export declare function postJson(options: {
|
|
14
|
+
model: Model;
|
|
15
|
+
url: string;
|
|
16
|
+
body: unknown;
|
|
17
|
+
apiKey: ApiKey;
|
|
18
|
+
fetch: FetchImpl;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<unknown>;
|
|
21
|
+
export declare function postMultipart(options: {
|
|
22
|
+
model: Model;
|
|
23
|
+
url: string;
|
|
24
|
+
body: FormData;
|
|
25
|
+
apiKey: ApiKey;
|
|
26
|
+
fetch: FetchImpl;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}): Promise<unknown>;
|
|
29
|
+
export declare function decodeImageResponse(value: unknown, fetch: FetchImpl, signal?: AbortSignal): Promise<{
|
|
30
|
+
images: GeneratedImage[];
|
|
31
|
+
usage: Usage;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function toDataUrl(image: GeneratedImage): string;
|
|
34
|
+
export declare function resolveOpenAIImageSize(aspectRatio?: string, imageSize?: string): string | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Api, FetchImpl, Model, Usage } from "@oh-my-pi/pi-catalog/types";
|
|
2
|
+
import type { ApiKey } from "../auth-retry.js";
|
|
3
|
+
export interface ImageInput {
|
|
4
|
+
data: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ImageGenerationRequest {
|
|
8
|
+
prompt: string;
|
|
9
|
+
inputImages?: ImageInput[];
|
|
10
|
+
aspectRatio?: string;
|
|
11
|
+
imageSize?: string;
|
|
12
|
+
count?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface GeneratedImage {
|
|
15
|
+
data: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ImageGenerationResult {
|
|
19
|
+
images: GeneratedImage[];
|
|
20
|
+
text?: string;
|
|
21
|
+
usage: Usage;
|
|
22
|
+
}
|
|
23
|
+
export interface ImageGenerationOptions {
|
|
24
|
+
apiKey: ApiKey;
|
|
25
|
+
fetch?: FetchImpl;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
/** Chat model that carries a Responses `image_generation` tool call. */
|
|
28
|
+
carrier?: Model<Api>;
|
|
29
|
+
/** Stable provider session id, used by the Codex Responses carrier. */
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
export { type Type, type } from "@oh-my-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/
|
|
4
|
+
export type { AuthGatewayBootOptions, 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";
|
|
8
8
|
export * from "./error/rate-limit.js";
|
|
9
|
+
export * from "./embeddings/index.js";
|
|
10
|
+
export * from "./images/index.js";
|
|
9
11
|
export * from "./judgment/index.js";
|
|
12
|
+
export * from "./rerank/index.js";
|
|
13
|
+
export * from "./speech/index.js";
|
|
14
|
+
export * from "./transcription/index.js";
|
|
15
|
+
export * from "./video/index.js";
|
|
10
16
|
export * from "./oneshot-retry.js";
|
|
11
17
|
export * from "./provider-details.js";
|
|
12
18
|
export * from "./provider-session-state.js";
|
|
13
|
-
export * from "./providers/anthropic.js";
|
|
14
|
-
export * from "./providers/anthropic-
|
|
15
|
-
export * from "./providers/
|
|
19
|
+
export type * from "./providers/anthropic.js";
|
|
20
|
+
export * from "./providers/anthropic-identity.js";
|
|
21
|
+
export * from "./providers/anthropic-state.js";
|
|
22
|
+
export type * from "./providers/anthropic-client.js";
|
|
23
|
+
export type * from "./providers/azure-openai-responses.js";
|
|
16
24
|
export type * from "./providers/cursor.js";
|
|
17
|
-
export * from "./providers/gitlab-duo.js";
|
|
18
|
-
export * from "./providers/gitlab-duo-workflow.js";
|
|
25
|
+
export type * from "./providers/gitlab-duo.js";
|
|
26
|
+
export type * from "./providers/gitlab-duo-workflow.js";
|
|
19
27
|
export type * from "./providers/google.js";
|
|
20
28
|
export type * from "./providers/google-gemini-cli.js";
|
|
21
29
|
export type * from "./providers/google-vertex.js";
|
|
22
|
-
export * from "./providers/kimi.js";
|
|
23
|
-
export * from "./providers/mock.js";
|
|
24
|
-
export * from "./providers/ollama.js";
|
|
25
|
-
export * from "./providers/openai-codex-responses.js";
|
|
26
|
-
export * from "./providers/openai-completions.js";
|
|
27
|
-
export * from "./providers/openai-responses.js";
|
|
28
|
-
export * from "./providers/synthetic.js";
|
|
30
|
+
export type * from "./providers/kimi.js";
|
|
31
|
+
export type * from "./providers/mock.js";
|
|
32
|
+
export type * from "./providers/ollama.js";
|
|
33
|
+
export type * from "./providers/openai-codex-responses.js";
|
|
34
|
+
export type * from "./providers/openai-completions.js";
|
|
35
|
+
export type * from "./providers/openai-responses.js";
|
|
36
|
+
export type * from "./providers/synthetic.js";
|
|
29
37
|
export * from "./registry/index.js";
|
|
30
38
|
export * from "./stream.js";
|
|
31
39
|
export * from "./types.js";
|
|
@@ -99,5 +99,8 @@ export declare class JudgmentParseError extends Error {
|
|
|
99
99
|
readonly output: string;
|
|
100
100
|
constructor(questionId: string, output: string, detail: string);
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
103
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Usage from a backend that reports token counts and, optionally, one billed
|
|
104
|
+
* USD amount. Judgment pricing is input-only, so the amount lands on `input`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function tokenUsage(input: number, output: number, cost?: number): Usage;
|