@oh-my-pi/pi-ai 18.2.7 → 18.2.9

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 (133) hide show
  1. package/CHANGELOG.md +49 -18
  2. package/dist/types/auth-gateway/dispatch.d.ts +80 -0
  3. package/dist/types/auth-gateway/http.d.ts +5 -6
  4. package/dist/types/auth-gateway/index.d.ts +1 -0
  5. package/dist/types/auth-gateway/routes/embeddings.d.ts +3 -0
  6. package/dist/types/auth-gateway/routes/images.d.ts +3 -0
  7. package/dist/types/auth-gateway/routes/rerank.d.ts +3 -0
  8. package/dist/types/auth-gateway/routes/speech.d.ts +2 -0
  9. package/dist/types/auth-gateway/routes/systemone.d.ts +2 -0
  10. package/dist/types/auth-gateway/routes/transcriptions.d.ts +3 -0
  11. package/dist/types/auth-gateway/routes/video.d.ts +7 -0
  12. package/dist/types/auth-gateway/server.d.ts +10 -16
  13. package/dist/types/auth-gateway/types.d.ts +5 -0
  14. package/dist/types/auth-storage.d.ts +35 -32
  15. package/dist/types/embeddings/index.d.ts +7 -0
  16. package/dist/types/embeddings/openai-embeddings.d.ts +15 -0
  17. package/dist/types/embeddings/types.d.ts +15 -0
  18. package/dist/types/images/google-antigravity.d.ts +9 -0
  19. package/dist/types/images/google-generative-ai.d.ts +3 -0
  20. package/dist/types/images/index.d.ts +14 -0
  21. package/dist/types/images/openai-hosted.d.ts +3 -0
  22. package/dist/types/images/openai-images.d.ts +5 -0
  23. package/dist/types/images/openrouter-images.d.ts +3 -0
  24. package/dist/types/images/shared.d.ts +34 -0
  25. package/dist/types/images/types.d.ts +31 -0
  26. package/dist/types/index.d.ts +8 -1
  27. package/dist/types/judgment/typesafe.d.ts +2 -0
  28. package/dist/types/providers/amazon-bedrock.d.ts +7 -0
  29. package/dist/types/providers/claude-code-fingerprint.d.ts +22 -3
  30. package/dist/types/providers/embeddings-server.d.ts +32 -0
  31. package/dist/types/providers/google-gemini-cli.d.ts +0 -2
  32. package/dist/types/providers/images-server.d.ts +22 -0
  33. package/dist/types/providers/openai-chat-server-schema.d.ts +2 -2
  34. package/dist/types/providers/rerank-server.d.ts +35 -0
  35. package/dist/types/providers/speech-server.d.ts +8 -0
  36. package/dist/types/providers/systemone-server.d.ts +26 -0
  37. package/dist/types/providers/transcriptions-server.d.ts +32 -0
  38. package/dist/types/providers/video-server.d.ts +39 -0
  39. package/dist/types/rerank/index.d.ts +7 -0
  40. package/dist/types/rerank/openrouter-rerank.d.ts +15 -0
  41. package/dist/types/rerank/types.d.ts +17 -0
  42. package/dist/types/speech/index.d.ts +13 -0
  43. package/dist/types/speech/openai-speech.d.ts +3 -0
  44. package/dist/types/speech/transport.d.ts +7 -0
  45. package/dist/types/speech/types.d.ts +24 -0
  46. package/dist/types/speech/xai-tts.d.ts +7 -0
  47. package/dist/types/transcription/index.d.ts +7 -0
  48. package/dist/types/transcription/openai-transcriptions.d.ts +15 -0
  49. package/dist/types/transcription/types.d.ts +41 -0
  50. package/dist/types/usage/claude-api.d.ts +22 -0
  51. package/dist/types/usage/claude-reset.d.ts +44 -0
  52. package/dist/types/usage.d.ts +111 -5
  53. package/dist/types/utils/schema/json-schema-validator.d.ts +5 -2
  54. package/dist/types/utils/tool-call-loop-guard.d.ts +1 -1
  55. package/dist/types/video/index.d.ts +11 -0
  56. package/dist/types/video/openrouter-video.d.ts +19 -0
  57. package/dist/types/video/types.d.ts +62 -0
  58. package/package.json +30 -6
  59. package/src/auth/sqlite-credential-store.ts +44 -1
  60. package/src/auth-broker/remote-store.ts +6 -6
  61. package/src/auth-broker/wire-schemas.ts +14 -0
  62. package/src/auth-gateway/dispatch.ts +273 -0
  63. package/src/auth-gateway/http.ts +6 -7
  64. package/src/auth-gateway/index.ts +1 -0
  65. package/src/auth-gateway/routes/embeddings.ts +98 -0
  66. package/src/auth-gateway/routes/images.ts +131 -0
  67. package/src/auth-gateway/routes/rerank.ts +87 -0
  68. package/src/auth-gateway/routes/speech.ts +101 -0
  69. package/src/auth-gateway/routes/systemone.ts +116 -0
  70. package/src/auth-gateway/routes/transcriptions.ts +98 -0
  71. package/src/auth-gateway/routes/video.ts +243 -0
  72. package/src/auth-gateway/server.ts +127 -260
  73. package/src/auth-gateway/types.ts +5 -0
  74. package/src/auth-storage.ts +263 -140
  75. package/src/embeddings/index.ts +17 -0
  76. package/src/embeddings/openai-embeddings.ts +141 -0
  77. package/src/embeddings/types.ts +14 -0
  78. package/src/error/flags.ts +10 -0
  79. package/src/error/rate-limit.ts +1 -1
  80. package/src/images/google-antigravity.ts +180 -0
  81. package/src/images/google-generative-ai.ts +92 -0
  82. package/src/images/index.ts +59 -0
  83. package/src/images/openai-hosted.ts +185 -0
  84. package/src/images/openai-images.ts +110 -0
  85. package/src/images/openrouter-images.ts +33 -0
  86. package/src/images/shared.ts +193 -0
  87. package/src/images/types.ts +36 -0
  88. package/src/index.ts +8 -1
  89. package/src/judgment/typesafe.ts +5 -0
  90. package/src/providers/amazon-bedrock.ts +55 -5
  91. package/src/providers/anthropic.ts +45 -11
  92. package/src/providers/aws-credentials.ts +124 -11
  93. package/src/providers/claude-code-fingerprint.ts +55 -3
  94. package/src/providers/embeddings-server.ts +151 -0
  95. package/src/providers/gitlab-duo.ts +20 -4
  96. package/src/providers/google-gemini-cli.ts +0 -8
  97. package/src/providers/google-shared.ts +1 -18
  98. package/src/providers/images-server.ts +159 -0
  99. package/src/providers/openai-chat-server-schema.ts +1 -1
  100. package/src/providers/openai-chat-server.ts +3 -1
  101. package/src/providers/openai-codex-responses.ts +27 -5
  102. package/src/providers/openai-completions.ts +122 -19
  103. package/src/providers/pi-native-server.ts +1 -0
  104. package/src/providers/rerank-server.ts +166 -0
  105. package/src/providers/speech-server.ts +53 -0
  106. package/src/providers/systemone-server.ts +73 -0
  107. package/src/providers/transcriptions-server.ts +243 -0
  108. package/src/providers/video-server.ts +286 -0
  109. package/src/registry/oauth/anthropic.ts +2 -3
  110. package/src/rerank/index.ts +13 -0
  111. package/src/rerank/openrouter-rerank.ts +136 -0
  112. package/src/rerank/types.ts +20 -0
  113. package/src/speech/index.ts +35 -0
  114. package/src/speech/openai-speech.ts +26 -0
  115. package/src/speech/transport.ts +66 -0
  116. package/src/speech/types.ts +37 -0
  117. package/src/speech/xai-tts.ts +41 -0
  118. package/src/stream.ts +13 -4
  119. package/src/transcription/index.ts +17 -0
  120. package/src/transcription/openai-transcriptions.ts +133 -0
  121. package/src/transcription/types.ts +46 -0
  122. package/src/usage/alibaba-token-plan.ts +7 -1
  123. package/src/usage/claude-api.ts +66 -0
  124. package/src/usage/claude-reset.ts +638 -0
  125. package/src/usage/claude.ts +37 -59
  126. package/src/usage/kimi.ts +32 -1
  127. package/src/usage.ts +52 -5
  128. package/src/utils/schema/json-schema-validator.ts +23 -10
  129. package/src/utils/tool-call-loop-guard.ts +2 -2
  130. package/src/utils/validation.ts +145 -50
  131. package/src/video/index.ts +34 -0
  132. package/src/video/openrouter-video.ts +210 -0
  133. package/src/video/types.ts +72 -0
@@ -7,12 +7,31 @@
7
7
  * `registry` → `registry/oauth/anthropic` → back into the still-initializing
8
8
  * provider module.
9
9
  */
10
- /** Current Claude Code CLI version represented on the Anthropic wire. */
11
- export declare const claudeCodeVersion = "2.1.257";
10
+ /**
11
+ * Pinned Claude Code CLI version: the offline fallback for {@link getClaudeCodeVersion}.
12
+ * Bumped to the latest npm release by `bun run check-spoofed-versions --update`.
13
+ */
14
+ export declare const DEFAULT_CLAUDE_CODE_VERSION = "2.1.280";
12
15
  /** `@anthropic-ai/sdk` version bundled by the current Claude Code release. */
13
16
  export declare const claudeCodeSdkVersion = "0.112.1";
17
+ /**
18
+ * Claude Code CLI version represented on the Anthropic wire (User-Agent, billing
19
+ * header): `PI_AI_CLAUDE_CODE_VERSION` → version adopted from a server rejection
20
+ * (see {@link adoptRequiredClaudeCodeVersion}) → {@link DEFAULT_CLAUDE_CODE_VERSION}.
21
+ */
22
+ export declare function getClaudeCodeVersion(): string;
14
23
  /** User-Agent emitted by Claude Code's CLI inference entrypoint. */
15
- export declare const claudeCodeUserAgent = "claude-cli/2.1.257 (external, cli)";
24
+ export declare function getClaudeCodeUserAgent(): string;
25
+ /**
26
+ * Adopts the minimum version named by an Anthropic `claude_code_version_too_old`
27
+ * rejection for the rest of the process, so the pinned fallback going stale costs
28
+ * one rejected request instead of a hard failure.
29
+ *
30
+ * Returns true only when the wire version actually increased — callers retry on
31
+ * true, so a repeated rejection at the same version cannot loop. Always false
32
+ * while `PI_AI_CLAUDE_CODE_VERSION` pins the version explicitly.
33
+ */
34
+ export declare function adoptRequiredClaudeCodeVersion(error: unknown): boolean;
16
35
  /** Prefix used to isolate custom Anthropic OAuth tools from built-in tools. */
17
36
  export declare const claudeToolPrefix: string;
18
37
  /** Identity block prepended by Claude Code's CLI runtime. */
@@ -0,0 +1,32 @@
1
+ import * as AIError from "../error/index.js";
2
+ import type { EmbeddingRequest, EmbeddingResult } from "../embeddings/types.js";
3
+ export declare const MAX_EMBEDDINGS_BODY_BYTES: number;
4
+ export declare class EmbeddingsWireError extends AIError.ValidationError {
5
+ readonly status: number;
6
+ constructor(status: number, message: string, options?: {
7
+ cause?: unknown;
8
+ });
9
+ }
10
+ export interface EmbeddingsParsedRequest {
11
+ modelId: string;
12
+ request: EmbeddingRequest;
13
+ }
14
+ /** Parse an OpenAI-compatible embeddings request with a bounded JSON body. */
15
+ export declare function parseRequest(req: Request): Promise<EmbeddingsParsedRequest>;
16
+ export interface EmbeddingsResponseBody {
17
+ object: "list";
18
+ data: Array<{
19
+ object: "embedding";
20
+ index: number;
21
+ embedding: number[] | string;
22
+ }>;
23
+ model: string;
24
+ usage: {
25
+ prompt_tokens: number;
26
+ total_tokens: number;
27
+ cost?: number;
28
+ };
29
+ }
30
+ /** Encode a canonical result as an OpenAI/OpenRouter embeddings response. */
31
+ export declare function encodeResponse(result: EmbeddingResult, requestedModelId: string): EmbeddingsResponseBody;
32
+ export declare function formatError(status: number, errorType: string, message: string): Response;
@@ -95,9 +95,7 @@ interface CloudCodeAssistRequest {
95
95
  temperature?: number;
96
96
  topP?: number;
97
97
  topK?: number;
98
- minP?: number;
99
98
  presencePenalty?: number;
100
- repetitionPenalty?: number;
101
99
  thinkingConfig?: ThinkingConfig;
102
100
  };
103
101
  tools?: {
@@ -0,0 +1,22 @@
1
+ import type { ImageGenerationRequest, ImageGenerationResult } from "../images/types.js";
2
+ export type ImageRequestKind = "generations" | "edits";
3
+ export interface ImagesParsedRequest {
4
+ modelId: string;
5
+ request: ImageGenerationRequest;
6
+ }
7
+ export interface ImagesResponseBody {
8
+ created: number;
9
+ data: Array<{
10
+ b64_json: string;
11
+ revised_prompt?: string;
12
+ }>;
13
+ usage: {
14
+ prompt_tokens: number;
15
+ completion_tokens: number;
16
+ total_tokens: number;
17
+ cost: number;
18
+ };
19
+ }
20
+ export declare function parseRequest(body: unknown | FormData, kind: ImageRequestKind): Promise<ImagesParsedRequest>;
21
+ export declare function encodeResponse(result: ImageGenerationResult, _requestedModelId: string): ImagesResponseBody;
22
+ export declare function formatError(status: number, errorType: string, message: string): Response;
@@ -1048,7 +1048,7 @@ export declare const openaiChatRequestSchema: import("@oh-my-pi/omptype").Fluent
1048
1048
  prediction?: unknown;
1049
1049
  presence_penalty?: number | undefined;
1050
1050
  prompt_cache_key?: unknown;
1051
- reasoning_effort?: "high" | "low" | "max" | "medium" | "minimal" | "xhigh" | undefined;
1051
+ reasoning_effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
1052
1052
  response_format?: unknown;
1053
1053
  safety_identifier?: unknown;
1054
1054
  seed?: number | undefined;
@@ -1263,7 +1263,7 @@ export declare const openaiChatRequestSchema: import("@oh-my-pi/omptype").Fluent
1263
1263
  prediction?: unknown;
1264
1264
  presence_penalty?: number | undefined;
1265
1265
  prompt_cache_key?: unknown;
1266
- reasoning_effort?: "high" | "low" | "max" | "medium" | "minimal" | "xhigh" | undefined;
1266
+ reasoning_effort?: "high" | "low" | "max" | "medium" | "minimal" | "none" | "xhigh" | undefined;
1267
1267
  response_format?: unknown;
1268
1268
  safety_identifier?: unknown;
1269
1269
  seed?: number | undefined;
@@ -0,0 +1,35 @@
1
+ import * as AIError from "../error/index.js";
2
+ import type { RerankRequest, RerankResult } from "../rerank/types.js";
3
+ export declare const MAX_RERANK_BODY_BYTES: number;
4
+ export interface RerankObjectDocument {
5
+ text: string;
6
+ }
7
+ export type RerankWireDocument = string | RerankObjectDocument;
8
+ export interface RerankParsedRequest {
9
+ modelId: string;
10
+ request: RerankRequest;
11
+ originalDocuments: RerankWireDocument[];
12
+ }
13
+ export declare class RerankWireError extends AIError.ValidationError {
14
+ readonly status: number;
15
+ constructor(status: number, message: string, options?: {
16
+ cause?: unknown;
17
+ });
18
+ }
19
+ /** Parse an OpenRouter-compatible JSON rerank request. */
20
+ export declare function parseRequest(req: Request): Promise<RerankParsedRequest>;
21
+ export interface RerankResponseBody {
22
+ model: string;
23
+ results: Array<{
24
+ index: number;
25
+ relevance_score: number;
26
+ document?: RerankObjectDocument;
27
+ }>;
28
+ usage: {
29
+ total_tokens: number;
30
+ cost: number;
31
+ };
32
+ }
33
+ /** Encode a canonical result as the OpenRouter rerank response shape. */
34
+ export declare function encodeResponse(result: RerankResult, requestedModelId: string, originalDocuments: readonly RerankWireDocument[], returnDocuments: boolean): RerankResponseBody;
35
+ export declare function formatError(status: number, errorType: string, message: string): Response;
@@ -0,0 +1,8 @@
1
+ import type { SpeechRequest, SpeechResult } from "../speech/types.js";
2
+ export interface SpeechParsedRequest {
3
+ modelId: string;
4
+ request: SpeechRequest;
5
+ }
6
+ export declare function parseRequest(body: unknown, _headers?: Headers): SpeechParsedRequest;
7
+ export declare function encodeResponse(result: SpeechResult, _requestedModelId: string): Response;
8
+ export declare function formatError(status: number, errorType: string, message: string): Response;
@@ -0,0 +1,26 @@
1
+ import type { JudgmentRequest, JudgmentResult } from "../judgment/types.js";
2
+ export interface SystemOneParsedRequest {
3
+ modelId: string;
4
+ request: JudgmentRequest;
5
+ }
6
+ /** `POST /v1/systemone` response body; `cost` (USD) appears only when the route billed one. */
7
+ export interface SystemOneResponseBody {
8
+ model: string;
9
+ answers: JudgmentResult["answers"];
10
+ usage: {
11
+ input_tokens: number;
12
+ output_tokens: number;
13
+ cost?: number;
14
+ };
15
+ }
16
+ /**
17
+ * Validate the routing-relevant parts of a System One request body.
18
+ *
19
+ * @throws {AIError.ValidationError} naming the offending field when `model`,
20
+ * `state`, or `questions` is missing or malformed.
21
+ */
22
+ export declare function parseRequest(body: unknown): SystemOneParsedRequest;
23
+ /** Re-encode a judgment result in TypeSafe's response shape. */
24
+ export declare function encodeResponse(result: JudgmentResult): SystemOneResponseBody;
25
+ /** TypeSafe answers errors with a status code and a JSON body; the envelope mirrors the other gateway routes. */
26
+ export declare function formatError(status: number, type: string, message: string): Response;
@@ -0,0 +1,32 @@
1
+ import * as AIError from "../error/index.js";
2
+ import type { TranscriptionRequest, TranscriptionResult } from "../transcription/types.js";
3
+ export declare const MAX_TRANSCRIPTION_BODY_BYTES: number;
4
+ export declare class TranscriptionWireError extends AIError.ValidationError {
5
+ readonly status: number;
6
+ constructor(status: number, message: string, options?: {
7
+ cause?: unknown;
8
+ });
9
+ }
10
+ export interface TranscriptionParsedRequest {
11
+ modelId: string;
12
+ request: TranscriptionRequest;
13
+ }
14
+ /** Parse either OpenAI multipart uploads or OpenRouter base64 JSON requests. */
15
+ export declare function parseRequest(req: Request): Promise<TranscriptionParsedRequest>;
16
+ export interface TranscriptionResponseBody {
17
+ text: string;
18
+ language?: string;
19
+ duration?: number;
20
+ segments?: TranscriptionResult["segments"];
21
+ words?: TranscriptionResult["words"];
22
+ usage: {
23
+ input_tokens: number;
24
+ output_tokens: number;
25
+ total_tokens: number;
26
+ cost: number;
27
+ seconds?: number;
28
+ };
29
+ }
30
+ /** Encode a canonical result as the shared OpenAI/OpenRouter transcription response. */
31
+ export declare function encodeResponse(result: TranscriptionResult): TranscriptionResponseBody;
32
+ export declare function formatError(status: number, errorType: string, message: string): Response;
@@ -0,0 +1,39 @@
1
+ import * as AIError from "../error/index.js";
2
+ import type { VideoGenerationRequest, VideoJob } from "../video/types.js";
3
+ export declare class VideoWireError extends AIError.ValidationError {
4
+ readonly status: number;
5
+ constructor(status: number, message: string, options?: {
6
+ cause?: unknown;
7
+ });
8
+ }
9
+ export interface VideoParsedRequest {
10
+ modelId: string;
11
+ request: VideoGenerationRequest;
12
+ }
13
+ export interface GatewayJobIdentity {
14
+ provider: string;
15
+ modelId: string;
16
+ upstreamId: string;
17
+ }
18
+ /** Parse and validate an OpenRouter-compatible video submit body. */
19
+ export declare function parseRequest(body: unknown): VideoParsedRequest;
20
+ /** Encode all provider/model routing needed to resolve a future poll without gateway state. */
21
+ export declare function encodeGatewayJobId(identity: GatewayJobIdentity): string;
22
+ /** Decode a stateless gateway job id, rejecting malformed or incomplete identities. */
23
+ export declare function decodeGatewayJobId(id: string): GatewayJobIdentity;
24
+ export interface VideoResponseBody {
25
+ id: string;
26
+ status: VideoJob["status"];
27
+ polling_url: string;
28
+ generation_id?: string;
29
+ unsigned_urls?: string[];
30
+ error?: string;
31
+ usage?: {
32
+ cost: number;
33
+ };
34
+ }
35
+ /** Rewrite a provider submit response so every future operation returns through this gateway. */
36
+ export declare function encodeSubmitResponse(job: VideoJob, req: Request, gatewayId: string): VideoResponseBody;
37
+ /** Rewrite a provider poll response so content URLs and polling stay on this gateway. */
38
+ export declare function encodePollResponse(job: VideoJob, req: Request, gatewayId: string): VideoResponseBody;
39
+ export declare function formatError(status: number, errorType: string, message: string): Response;
@@ -0,0 +1,7 @@
1
+ import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
2
+ import { type RerankOptions } from "./openrouter-rerank.js";
3
+ import type { RerankRequest, RerankResult } from "./types.js";
4
+ export * from "./openrouter-rerank.js";
5
+ export * from "./types.js";
6
+ /** Dispatch reranking through the transport selected by the catalog model. */
7
+ export declare function rerank(model: Model<Api>, request: RerankRequest, options: RerankOptions): Promise<RerankResult>;
@@ -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 { RerankRequest, RerankResult } from "./types.js";
5
+ export interface RerankOptions {
6
+ apiKey: ApiKey;
7
+ fetch?: FetchImpl;
8
+ signal?: AbortSignal;
9
+ }
10
+ /** Non-2xx response from an OpenRouter-compatible rerank endpoint. */
11
+ export declare class RerankApiError extends AIError.ProviderHttpError {
12
+ readonly name = "RerankApiError";
13
+ }
14
+ /** Call an OpenRouter-compatible rerank endpoint. */
15
+ export declare function rerankOpenRouter(model: Model<Api>, request: RerankRequest, options: RerankOptions): Promise<RerankResult>;
@@ -0,0 +1,17 @@
1
+ import type { Usage } from "@oh-my-pi/pi-catalog/types";
2
+ export interface RerankRequest {
3
+ query: string;
4
+ documents: string[];
5
+ topN?: number;
6
+ returnDocuments?: boolean;
7
+ }
8
+ export interface RerankResultItem {
9
+ index: number;
10
+ relevanceScore: number;
11
+ document?: string;
12
+ }
13
+ export interface RerankResult {
14
+ results: RerankResultItem[];
15
+ model: string;
16
+ usage: Usage;
17
+ }
@@ -0,0 +1,13 @@
1
+ import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
2
+ import type { SpeechOptions, SpeechRequest, SpeechResult } from "./types.js";
3
+ export * from "./openai-speech.js";
4
+ export * from "./transport.js";
5
+ export * from "./types.js";
6
+ export * from "./xai-tts.js";
7
+ /** Catalog APIs {@link synthesizeSpeech} serves; the `tts` tool and the gateway gate on these. */
8
+ export declare const SPEECH_APIS: readonly ["xai-tts", "openai-speech"];
9
+ export type SpeechApi = (typeof SPEECH_APIS)[number];
10
+ /** Whether a catalog API synthesizes speech through a cloud transport (local inference is tool-only). */
11
+ export declare function isSpeechApi(api: Api): api is SpeechApi;
12
+ /** Synthesize speech through the transport selected by the catalog model's `api`. */
13
+ export declare function synthesizeSpeech(model: Model<Api>, request: SpeechRequest, options: SpeechOptions): Promise<SpeechResult>;
@@ -0,0 +1,3 @@
1
+ import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
2
+ import type { SpeechOptions, SpeechRequest, SpeechResult } from "./types.js";
3
+ export declare function synthesizeOpenAiSpeech(model: Model<Api>, request: SpeechRequest, options: SpeechOptions): Promise<SpeechResult>;
@@ -0,0 +1,7 @@
1
+ import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
2
+ import * as AIError from "../error/index.js";
3
+ import { type SpeechFormat, type SpeechOptions, type SpeechResult } from "./types.js";
4
+ export declare class SpeechApiError extends AIError.ProviderHttpError {
5
+ readonly name = "SpeechApiError";
6
+ }
7
+ export declare function postSpeechRequest(model: Model<Api>, path: string, payload: Record<string, unknown>, format: SpeechFormat, options: SpeechOptions): Promise<SpeechResult>;
@@ -0,0 +1,24 @@
1
+ import type { FetchImpl, Usage } from "@oh-my-pi/pi-catalog/types";
2
+ import type { ApiKey } from "../auth-retry.js";
3
+ export declare const SPEECH_FORMATS: readonly ["mp3", "wav", "pcm", "opus", "aac", "flac"];
4
+ export type SpeechFormat = (typeof SPEECH_FORMATS)[number];
5
+ export declare const SPEECH_FORMAT_MIME_TYPES: Record<SpeechFormat, string>;
6
+ export interface SpeechRequest {
7
+ text: string;
8
+ voice?: string;
9
+ format: SpeechFormat;
10
+ speed?: number;
11
+ sampleRate?: number;
12
+ bitRate?: number;
13
+ instructions?: string;
14
+ }
15
+ export interface SpeechResult {
16
+ audio: Uint8Array;
17
+ mimeType: string;
18
+ usage: Usage;
19
+ }
20
+ export interface SpeechOptions {
21
+ apiKey: ApiKey;
22
+ fetch?: FetchImpl;
23
+ signal?: AbortSignal;
24
+ }
@@ -0,0 +1,7 @@
1
+ import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
2
+ import type { SpeechOptions, SpeechRequest, SpeechResult } from "./types.js";
3
+ export declare const DEFAULT_XAI_VOICE_ID = "eve";
4
+ export declare const DEFAULT_XAI_SAMPLE_RATE = 24000;
5
+ export declare const DEFAULT_XAI_BIT_RATE = 128000;
6
+ export declare const XAI_MAX_TEXT_LENGTH = 15000;
7
+ export declare function synthesizeXaiSpeech(model: Model<Api>, request: SpeechRequest, options: SpeechOptions): Promise<SpeechResult>;
@@ -0,0 +1,7 @@
1
+ import type { Api, Model } from "@oh-my-pi/pi-catalog/types";
2
+ import { type TranscriptionOptions } from "./openai-transcriptions.js";
3
+ import type { TranscriptionRequest, TranscriptionResult } from "./types.js";
4
+ export * from "./openai-transcriptions.js";
5
+ export * from "./types.js";
6
+ /** Dispatch an audio transcription through the transport selected by the catalog model. */
7
+ export declare function transcribeAudio(model: Model<Api>, request: TranscriptionRequest, options: TranscriptionOptions): Promise<TranscriptionResult>;
@@ -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 { TranscriptionRequest, TranscriptionResult } from "./types.js";
5
+ export interface TranscriptionOptions {
6
+ apiKey: ApiKey;
7
+ fetch?: FetchImpl;
8
+ signal?: AbortSignal;
9
+ }
10
+ /** Non-2xx response from an OpenAI-compatible transcription endpoint. */
11
+ export declare class TranscriptionApiError extends AIError.ProviderHttpError {
12
+ readonly name = "TranscriptionApiError";
13
+ }
14
+ /** Call an OpenAI/OpenRouter-compatible multipart transcription endpoint. */
15
+ export declare function transcribeOpenAI(model: Model<Api>, request: TranscriptionRequest, options: TranscriptionOptions): Promise<TranscriptionResult>;
@@ -0,0 +1,41 @@
1
+ import type { Usage } from "@oh-my-pi/pi-catalog/types";
2
+ export type TranscriptionResponseFormat = "json" | "verbose_json";
3
+ export type TranscriptionTimestampGranularity = "word" | "segment";
4
+ export interface TranscriptionRequest {
5
+ audio: Uint8Array;
6
+ mimeType: string;
7
+ fileName?: string;
8
+ language?: string;
9
+ prompt?: string;
10
+ temperature?: number;
11
+ responseFormat: TranscriptionResponseFormat;
12
+ timestampGranularities?: TranscriptionTimestampGranularity[];
13
+ }
14
+ /** Provider-specific segment fields are preserved alongside the normalized timestamps and text. */
15
+ export interface TranscriptionSegment {
16
+ id?: number | string;
17
+ start: number;
18
+ end: number;
19
+ text: string;
20
+ speaker?: number | string;
21
+ [key: string]: unknown;
22
+ }
23
+ /** Provider-specific word fields are preserved alongside the normalized timestamps and spelling. */
24
+ export interface TranscriptionWord {
25
+ word: string;
26
+ start: number;
27
+ end: number;
28
+ speaker?: number | string;
29
+ confidence?: number;
30
+ [key: string]: unknown;
31
+ }
32
+ export interface TranscriptionResult {
33
+ text: string;
34
+ language?: string;
35
+ duration?: number;
36
+ segments?: TranscriptionSegment[];
37
+ words?: TranscriptionWord[];
38
+ /** Provider-billed audio duration, which may be present without verbose output. */
39
+ seconds?: number;
40
+ usage: Usage;
41
+ }
@@ -0,0 +1,22 @@
1
+ /** Canonical host for Claude's first-party account API. */
2
+ export declare const DEFAULT_CLAUDE_API_BASE_URL = "https://api.anthropic.com";
3
+ /** Canonical subscription usage and profile endpoint. */
4
+ export declare const DEFAULT_CLAUDE_OAUTH_BASE_URL = "https://api.anthropic.com/api/oauth";
5
+ /** OAuth protocol beta required by Claude's account routes. */
6
+ export declare const CLAUDE_OAUTH_BETA = "oauth-2025-04-20";
7
+ /**
8
+ * Normalize Messages (`/v1`) and OAuth (`/api/oauth`) endpoints to the common
9
+ * API root used by both usage and reset routes. Custom path prefixes survive.
10
+ */
11
+ export declare function normalizeClaudeApiBaseUrl(baseUrl?: string): string;
12
+ /** Resolve the OAuth API base while retaining a configured proxy path prefix. */
13
+ export declare function claudeOAuthBaseUrl(baseUrl?: string): string;
14
+ /** Configured OAuth endpoint followed by canonical fallback, without duplicates. */
15
+ export declare function claudeOAuthBaseUrls(baseUrl?: string): readonly string[];
16
+ /** Resolve a first-party account route against the configured Claude API root. */
17
+ export declare function claudeApiUrl(baseUrl: string | undefined, path: string): string;
18
+ /** Shared OAuth and CLI identity headers for Claude usage, profile, and resets. */
19
+ export declare function buildClaudeOAuthHeaders(accessToken: string, options?: {
20
+ beta?: string;
21
+ json?: boolean;
22
+ }): Record<string, string>;
@@ -0,0 +1,44 @@
1
+ import type { UsageResetCredit, UsageResetCredits } from "../usage.js";
2
+ import type { FetchImpl } from "../types.js";
3
+ /** OAuth credential and transport used for an account's Claude reset operations. */
4
+ export interface ClaudeResetAuth {
5
+ accessToken: string;
6
+ orgId?: string;
7
+ baseUrl?: string;
8
+ fetch: FetchImpl;
9
+ signal?: AbortSignal;
10
+ }
11
+ /** Live reset eligibility plus the exact organization and host used for redemption. */
12
+ export interface ClaudeResetCreditList extends UsageResetCredits {
13
+ credits: UsageResetCredit[];
14
+ orgId?: string;
15
+ /** OAuth API base that answered discovery; pass back as consume `baseUrl`. */
16
+ baseUrl?: string;
17
+ }
18
+ /** Confirmed reset outcome; transport uncertainty never reports a successful spend. */
19
+ export interface ClaudeResetConsumeResult {
20
+ ok: boolean;
21
+ code: string;
22
+ status: number;
23
+ cleared?: string[];
24
+ reason?: string;
25
+ raw?: unknown;
26
+ }
27
+ /**
28
+ * Reuse program blocks when a normal usage response actually includes them.
29
+ * A lone non-redeemable Cedar block is inconclusive because Juniper requires
30
+ * the separate at-wall read, so callers must still perform discovery.
31
+ *
32
+ * @internal
33
+ */
34
+ export declare function parseClaudeResetCreditsFromUsagePayload(payload: unknown, orgId?: string, baseUrl?: string): ClaudeResetCreditList | null;
35
+ /**
36
+ * Discover Claude's saved Cedar grant first, then its Juniper session reset.
37
+ * `null` means discovery failed; a zero-count object is an authoritative answer.
38
+ */
39
+ export declare function listClaudeResetCredits(auth: ClaudeResetAuth): Promise<ClaudeResetCreditList | null>;
40
+ /** Spend exactly the server-selected Claude reset. Mutation requests are never retried. */
41
+ export declare function consumeClaudeResetCredit(auth: ClaudeResetAuth & {
42
+ credit: UsageResetCredit;
43
+ redeemRequestId?: string;
44
+ }): Promise<ClaudeResetConsumeResult>;