@oh-my-pi/pi-ai 1.338.0 → 2.0.1337

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-ai",
3
- "version": "1.338.0",
3
+ "version": "2.0.1337",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/cli.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
- import { loginAnthropic } from "./utils/oauth/anthropic.js";
4
- import { loginGitHubCopilot } from "./utils/oauth/github-copilot.js";
5
- import { loginAntigravity } from "./utils/oauth/google-antigravity.js";
6
- import { loginGeminiCli } from "./utils/oauth/google-gemini-cli.js";
7
- import { getOAuthProviders } from "./utils/oauth/index.js";
8
- import type { OAuthCredentials, OAuthProvider } from "./utils/oauth/types.js";
3
+ import { logger } from "@oh-my-pi/pi-coding-agent";
4
+ import { loginAnthropic } from "./utils/oauth/anthropic";
5
+ import { loginGitHubCopilot } from "./utils/oauth/github-copilot";
6
+ import { loginAntigravity } from "./utils/oauth/google-antigravity";
7
+ import { loginGeminiCli } from "./utils/oauth/google-gemini-cli";
8
+ import { getOAuthProviders } from "./utils/oauth/index";
9
+ import type { OAuthCredentials, OAuthProvider } from "./utils/oauth/types";
9
10
 
10
11
  const AUTH_FILE = "auth.json";
11
12
  const PROVIDERS = getOAuthProviders();
@@ -26,7 +27,8 @@ async function loadAuth(): Promise<Record<string, { type: "oauth" } & OAuthCrede
26
27
  if (!(await file.exists())) return {};
27
28
  try {
28
29
  return await file.json();
29
- } catch {
30
+ } catch (err) {
31
+ logger.debug("Failed to parse config file", { error: String(err) });
30
32
  return {};
31
33
  }
32
34
  }
package/src/index.ts CHANGED
@@ -1,13 +1,13 @@
1
- export * from "./models.js";
2
- export * from "./providers/anthropic.js";
3
- export * from "./providers/google.js";
4
- export * from "./providers/google-gemini-cli.js";
5
- export * from "./providers/openai-completions.js";
6
- export * from "./providers/openai-responses.js";
7
- export * from "./stream.js";
8
- export * from "./types.js";
9
- export * from "./utils/event-stream.js";
10
- export * from "./utils/oauth/index.js";
11
- export * from "./utils/overflow.js";
12
- export * from "./utils/typebox-helpers.js";
13
- export * from "./utils/validation.js";
1
+ export * from "./models";
2
+ export * from "./providers/anthropic";
3
+ export * from "./providers/google";
4
+ export * from "./providers/google-gemini-cli";
5
+ export * from "./providers/openai-completions";
6
+ export * from "./providers/openai-responses";
7
+ export * from "./stream";
8
+ export * from "./types";
9
+ export * from "./utils/event-stream";
10
+ export * from "./utils/oauth/index";
11
+ export * from "./utils/overflow";
12
+ export * from "./utils/typebox-helpers";
13
+ export * from "./utils/validation";
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated by scripts/generate-models.ts
2
2
  // Do not edit manually - run 'npm run generate-models' to update
3
3
 
4
- import type { Model } from "./types.js";
4
+ import type { Model } from "./types";
5
5
 
6
6
  export const MODELS = {
7
7
  "anthropic": {
package/src/models.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { MODELS } from "./models.generated.js";
2
- import type { Api, KnownProvider, Model, Usage } from "./types.js";
1
+ import { MODELS } from "./models.generated";
2
+ import type { Api, KnownProvider, Model, Usage } from "./types";
3
3
 
4
4
  const modelRegistry: Map<string, Map<string, Model<Api>>> = new Map();
5
5
 
@@ -4,8 +4,8 @@ import type {
4
4
  MessageCreateParamsStreaming,
5
5
  MessageParam,
6
6
  } from "@anthropic-ai/sdk/resources/messages.js";
7
- import { calculateCost } from "../models.js";
8
- import { getEnvApiKey } from "../stream.js";
7
+ import { calculateCost } from "../models";
8
+ import { getEnvApiKey } from "../stream";
9
9
  import type {
10
10
  Api,
11
11
  AssistantMessage,
@@ -21,12 +21,12 @@ import type {
21
21
  Tool,
22
22
  ToolCall,
23
23
  ToolResultMessage,
24
- } from "../types.js";
25
- import { AssistantMessageEventStream } from "../utils/event-stream.js";
26
- import { parseStreamingJson } from "../utils/json-parse.js";
27
- import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
24
+ } from "../types";
25
+ import { AssistantMessageEventStream } from "../utils/event-stream";
26
+ import { parseStreamingJson } from "../utils/json-parse";
27
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode";
28
28
 
29
- import { transformMessages } from "./transorm-messages.js";
29
+ import { transformMessages } from "./transorm-messages";
30
30
 
31
31
  /**
32
32
  * Convert content blocks to Anthropic API format
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import type { Content, ThinkingConfig } from "@google/genai";
8
- import { calculateCost } from "../models.js";
8
+ import { calculateCost } from "../models";
9
9
  import type {
10
10
  Api,
11
11
  AssistantMessage,
@@ -16,10 +16,10 @@ import type {
16
16
  TextContent,
17
17
  ThinkingContent,
18
18
  ToolCall,
19
- } from "../types.js";
20
- import { AssistantMessageEventStream } from "../utils/event-stream.js";
21
- import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
22
- import { convertMessages, convertTools, mapStopReasonString, mapToolChoice } from "./google-shared.js";
19
+ } from "../types";
20
+ import { AssistantMessageEventStream } from "../utils/event-stream";
21
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode";
22
+ import { convertMessages, convertTools, mapStopReasonString, mapToolChoice } from "./google-shared";
23
23
 
24
24
  /**
25
25
  * Thinking level for Gemini 3 models.
@@ -3,9 +3,9 @@
3
3
  */
4
4
 
5
5
  import { type Content, FinishReason, FunctionCallingConfigMode, type Part, type Schema } from "@google/genai";
6
- import type { Context, ImageContent, Model, StopReason, TextContent, Tool } from "../types.js";
7
- import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
8
- import { transformMessages } from "./transorm-messages.js";
6
+ import type { Context, ImageContent, Model, StopReason, TextContent, Tool } from "../types";
7
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode";
8
+ import { transformMessages } from "./transorm-messages";
9
9
 
10
10
  type GoogleApiType = "google-generative-ai" | "google-gemini-cli";
11
11
 
@@ -4,8 +4,8 @@ import {
4
4
  GoogleGenAI,
5
5
  type ThinkingConfig,
6
6
  } from "@google/genai";
7
- import { calculateCost } from "../models.js";
8
- import { getEnvApiKey } from "../stream.js";
7
+ import { calculateCost } from "../models";
8
+ import { getEnvApiKey } from "../stream";
9
9
  import type {
10
10
  Api,
11
11
  AssistantMessage,
@@ -16,11 +16,11 @@ import type {
16
16
  TextContent,
17
17
  ThinkingContent,
18
18
  ToolCall,
19
- } from "../types.js";
20
- import { AssistantMessageEventStream } from "../utils/event-stream.js";
21
- import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
22
- import type { GoogleThinkingLevel } from "./google-gemini-cli.js";
23
- import { convertMessages, convertTools, mapStopReason, mapToolChoice } from "./google-shared.js";
19
+ } from "../types";
20
+ import { AssistantMessageEventStream } from "../utils/event-stream";
21
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode";
22
+ import type { GoogleThinkingLevel } from "./google-gemini-cli";
23
+ import { convertMessages, convertTools, mapStopReason, mapToolChoice } from "./google-shared";
24
24
 
25
25
  export interface GoogleOptions extends StreamOptions {
26
26
  toolChoice?: "auto" | "none" | "any";
@@ -8,8 +8,8 @@ import type {
8
8
  ChatCompletionMessageParam,
9
9
  ChatCompletionToolMessageParam,
10
10
  } from "openai/resources/chat/completions.js";
11
- import { calculateCost } from "../models.js";
12
- import { getEnvApiKey } from "../stream.js";
11
+ import { calculateCost } from "../models";
12
+ import { getEnvApiKey } from "../stream";
13
13
  import type {
14
14
  AssistantMessage,
15
15
  Context,
@@ -23,11 +23,11 @@ import type {
23
23
  ThinkingContent,
24
24
  Tool,
25
25
  ToolCall,
26
- } from "../types.js";
27
- import { AssistantMessageEventStream } from "../utils/event-stream.js";
28
- import { parseStreamingJson } from "../utils/json-parse.js";
29
- import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
30
- import { transformMessages } from "./transorm-messages.js";
26
+ } from "../types";
27
+ import { AssistantMessageEventStream } from "../utils/event-stream";
28
+ import { parseStreamingJson } from "../utils/json-parse";
29
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode";
30
+ import { transformMessages } from "./transorm-messages";
31
31
 
32
32
  /**
33
33
  * Normalize tool call ID for Mistral.
@@ -10,8 +10,8 @@ import type {
10
10
  ResponseOutputMessage,
11
11
  ResponseReasoningItem,
12
12
  } from "openai/resources/responses/responses.js";
13
- import { calculateCost } from "../models.js";
14
- import { getEnvApiKey } from "../stream.js";
13
+ import { calculateCost } from "../models";
14
+ import { getEnvApiKey } from "../stream";
15
15
  import type {
16
16
  Api,
17
17
  AssistantMessage,
@@ -24,11 +24,11 @@ import type {
24
24
  ThinkingContent,
25
25
  Tool,
26
26
  ToolCall,
27
- } from "../types.js";
28
- import { AssistantMessageEventStream } from "../utils/event-stream.js";
29
- import { parseStreamingJson } from "../utils/json-parse.js";
30
- import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
31
- import { transformMessages } from "./transorm-messages.js";
27
+ } from "../types";
28
+ import { AssistantMessageEventStream } from "../utils/event-stream";
29
+ import { parseStreamingJson } from "../utils/json-parse";
30
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode";
31
+ import { transformMessages } from "./transorm-messages";
32
32
 
33
33
  /** Fast deterministic hash to shorten long strings */
34
34
  function shortHash(str: string): string {
@@ -1,4 +1,4 @@
1
- import type { Api, AssistantMessage, Message, Model, ToolCall, ToolResultMessage } from "../types.js";
1
+ import type { Api, AssistantMessage, Message, Model, ToolCall, ToolResultMessage } from "../types";
2
2
 
3
3
  /**
4
4
  * Normalize tool call ID for GitHub Copilot cross-API compatibility.
package/src/stream.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { supportsXhigh } from "./models.js";
2
- import { type AnthropicOptions, streamAnthropic } from "./providers/anthropic.js";
3
- import { type GoogleOptions, streamGoogle } from "./providers/google.js";
1
+ import { supportsXhigh } from "./models";
2
+ import { type AnthropicOptions, streamAnthropic } from "./providers/anthropic";
3
+ import { type GoogleOptions, streamGoogle } from "./providers/google";
4
4
  import {
5
5
  type GoogleGeminiCliOptions,
6
6
  type GoogleThinkingLevel,
7
7
  streamGoogleGeminiCli,
8
- } from "./providers/google-gemini-cli.js";
9
- import { type OpenAICompletionsOptions, streamOpenAICompletions } from "./providers/openai-completions.js";
10
- import { type OpenAIResponsesOptions, streamOpenAIResponses } from "./providers/openai-responses.js";
8
+ } from "./providers/google-gemini-cli";
9
+ import { type OpenAICompletionsOptions, streamOpenAICompletions } from "./providers/openai-completions";
10
+ import { type OpenAIResponsesOptions, streamOpenAIResponses } from "./providers/openai-responses";
11
11
  import type {
12
12
  Api,
13
13
  AssistantMessage,
@@ -18,7 +18,7 @@ import type {
18
18
  OptionsForApi,
19
19
  ReasoningEffort,
20
20
  SimpleStreamOptions,
21
- } from "./types.js";
21
+ } from "./types";
22
22
 
23
23
  /**
24
24
  * Get API key for provider from known environment variables, e.g. OPENAI_API_KEY.
package/src/types.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { AnthropicOptions } from "./providers/anthropic.js";
2
- import type { GoogleOptions } from "./providers/google.js";
3
- import type { GoogleGeminiCliOptions } from "./providers/google-gemini-cli.js";
4
- import type { OpenAICompletionsOptions } from "./providers/openai-completions.js";
5
- import type { OpenAIResponsesOptions } from "./providers/openai-responses.js";
6
- import type { AssistantMessageEventStream } from "./utils/event-stream.js";
7
-
8
- export type { AssistantMessageEventStream } from "./utils/event-stream.js";
1
+ import type { AnthropicOptions } from "./providers/anthropic";
2
+ import type { GoogleOptions } from "./providers/google";
3
+ import type { GoogleGeminiCliOptions } from "./providers/google-gemini-cli";
4
+ import type { OpenAICompletionsOptions } from "./providers/openai-completions";
5
+ import type { OpenAIResponsesOptions } from "./providers/openai-responses";
6
+ import type { AssistantMessageEventStream } from "./utils/event-stream";
7
+
8
+ export type { AssistantMessageEventStream } from "./utils/event-stream";
9
9
 
10
10
  export type Api =
11
11
  | "openai-completions"
@@ -1,4 +1,4 @@
1
- import type { AssistantMessage, AssistantMessageEvent } from "../types.js";
1
+ import type { AssistantMessage, AssistantMessageEvent } from "../types";
2
2
 
3
3
  // Generic event stream class for async iteration
4
4
  export class EventStream<T, R = T> implements AsyncIterable<T> {
@@ -2,8 +2,8 @@
2
2
  * Anthropic OAuth flow (Claude Pro/Max)
3
3
  */
4
4
 
5
- import { generatePKCE } from "./pkce.js";
6
- import type { OAuthCredentials } from "./types.js";
5
+ import { generatePKCE } from "./pkce";
6
+ import type { OAuthCredentials } from "./types";
7
7
 
8
8
  const decode = (s: string) => atob(s);
9
9
  const CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
@@ -2,8 +2,8 @@
2
2
  * GitHub Copilot OAuth flow
3
3
  */
4
4
 
5
- import { getModels } from "../../models.js";
6
- import type { OAuthCredentials } from "./types.js";
5
+ import { getModels } from "../../models";
6
+ import type { OAuthCredentials } from "./types";
7
7
 
8
8
  const decode = (s: string) => atob(s);
9
9
  const CLIENT_ID = decode("SXYxLmI1MDdhMDhjODdlY2ZlOTg=");
@@ -6,8 +6,8 @@
6
6
  * It is only intended for CLI use, not browser environments.
7
7
  */
8
8
 
9
- import { generatePKCE } from "./pkce.js";
10
- import type { OAuthCredentials } from "./types.js";
9
+ import { generatePKCE } from "./pkce";
10
+ import type { OAuthCredentials } from "./types";
11
11
 
12
12
  // Antigravity OAuth credentials (different from Gemini CLI)
13
13
  const decode = (s: string) => atob(s);
@@ -6,8 +6,8 @@
6
6
  * It is only intended for CLI use, not browser environments.
7
7
  */
8
8
 
9
- import { generatePKCE } from "./pkce.js";
10
- import type { OAuthCredentials } from "./types.js";
9
+ import { generatePKCE } from "./pkce";
10
+ import type { OAuthCredentials } from "./types";
11
11
 
12
12
  const decode = (s: string) => atob(s);
13
13
  const CLIENT_ID = decode(
@@ -10,36 +10,36 @@
10
10
  */
11
11
 
12
12
  // Anthropic
13
- export { loginAnthropic, refreshAnthropicToken } from "./anthropic.js";
13
+ export { loginAnthropic, refreshAnthropicToken } from "./anthropic";
14
14
  // GitHub Copilot
15
15
  export {
16
16
  getGitHubCopilotBaseUrl,
17
17
  loginGitHubCopilot,
18
18
  normalizeDomain,
19
19
  refreshGitHubCopilotToken,
20
- } from "./github-copilot.js";
20
+ } from "./github-copilot";
21
21
  // Google Antigravity
22
22
  export {
23
23
  loginAntigravity,
24
24
  refreshAntigravityToken,
25
- } from "./google-antigravity.js";
25
+ } from "./google-antigravity";
26
26
  // Google Gemini CLI
27
27
  export {
28
28
  loginGeminiCli,
29
29
  refreshGoogleCloudToken,
30
- } from "./google-gemini-cli.js";
30
+ } from "./google-gemini-cli";
31
31
 
32
- export * from "./types.js";
32
+ export * from "./types";
33
33
 
34
34
  // ============================================================================
35
35
  // High-level API
36
36
  // ============================================================================
37
37
 
38
- import { refreshAnthropicToken } from "./anthropic.js";
39
- import { refreshGitHubCopilotToken } from "./github-copilot.js";
40
- import { refreshAntigravityToken } from "./google-antigravity.js";
41
- import { refreshGoogleCloudToken } from "./google-gemini-cli.js";
42
- import type { OAuthCredentials, OAuthProvider, OAuthProviderInfo } from "./types.js";
38
+ import { refreshAnthropicToken } from "./anthropic";
39
+ import { refreshGitHubCopilotToken } from "./github-copilot";
40
+ import { refreshAntigravityToken } from "./google-antigravity";
41
+ import { refreshGoogleCloudToken } from "./google-gemini-cli";
42
+ import type { OAuthCredentials, OAuthProvider, OAuthProviderInfo } from "./types";
43
43
 
44
44
  /**
45
45
  * Refresh token for any OAuth provider.
@@ -1,4 +1,4 @@
1
- import type { AssistantMessage } from "../types.js";
1
+ import type { AssistantMessage } from "../types";
2
2
 
3
3
  /**
4
4
  * Regex patterns to detect context overflow errors from different providers.
@@ -5,7 +5,7 @@ import addFormatsModule from "ajv-formats";
5
5
  const Ajv = (AjvModule as any).default || AjvModule;
6
6
  const addFormats = (addFormatsModule as any).default || addFormatsModule;
7
7
 
8
- import type { Tool, ToolCall } from "../types.js";
8
+ import type { Tool, ToolCall } from "../types";
9
9
 
10
10
  // Detect if we're in a browser extension environment with strict CSP
11
11
  // Chrome extensions with Manifest V3 don't allow eval/Function constructor