@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 +1 -1
- package/src/cli.ts +9 -7
- package/src/index.ts +13 -13
- package/src/models.generated.ts +1 -1
- package/src/models.ts +2 -2
- package/src/providers/anthropic.ts +7 -7
- package/src/providers/google-gemini-cli.ts +5 -5
- package/src/providers/google-shared.ts +3 -3
- package/src/providers/google.ts +7 -7
- package/src/providers/openai-completions.ts +7 -7
- package/src/providers/openai-responses.ts +7 -7
- package/src/providers/transorm-messages.ts +1 -1
- package/src/stream.ts +7 -7
- package/src/types.ts +8 -8
- package/src/utils/event-stream.ts +1 -1
- package/src/utils/oauth/anthropic.ts +2 -2
- package/src/utils/oauth/github-copilot.ts +2 -2
- package/src/utils/oauth/google-antigravity.ts +2 -2
- package/src/utils/oauth/google-gemini-cli.ts +2 -2
- package/src/utils/oauth/index.ts +10 -10
- package/src/utils/overflow.ts +1 -1
- package/src/utils/validation.ts +1 -1
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
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
|
|
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
|
+
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";
|
package/src/models.generated.ts
CHANGED
package/src/models.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MODELS } from "./models.generated
|
|
2
|
-
import type { Api, KnownProvider, Model, Usage } from "./types
|
|
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
|
|
8
|
-
import { getEnvApiKey } from "../stream
|
|
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
|
|
25
|
-
import { AssistantMessageEventStream } from "../utils/event-stream
|
|
26
|
-
import { parseStreamingJson } from "../utils/json-parse
|
|
27
|
-
import { sanitizeSurrogates } from "../utils/sanitize-unicode
|
|
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
|
|
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
|
|
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
|
|
20
|
-
import { AssistantMessageEventStream } from "../utils/event-stream
|
|
21
|
-
import { sanitizeSurrogates } from "../utils/sanitize-unicode
|
|
22
|
-
import { convertMessages, convertTools, mapStopReasonString, mapToolChoice } from "./google-shared
|
|
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
|
|
7
|
-
import { sanitizeSurrogates } from "../utils/sanitize-unicode
|
|
8
|
-
import { transformMessages } from "./transorm-messages
|
|
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
|
|
package/src/providers/google.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
GoogleGenAI,
|
|
5
5
|
type ThinkingConfig,
|
|
6
6
|
} from "@google/genai";
|
|
7
|
-
import { calculateCost } from "../models
|
|
8
|
-
import { getEnvApiKey } from "../stream
|
|
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
|
|
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
|
|
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
|
|
12
|
-
import { getEnvApiKey } from "../stream
|
|
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
|
|
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
|
|
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
|
|
14
|
-
import { getEnvApiKey } from "../stream
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2
|
-
import { type AnthropicOptions, streamAnthropic } from "./providers/anthropic
|
|
3
|
-
import { type GoogleOptions, streamGoogle } from "./providers/google
|
|
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
|
|
9
|
-
import { type OpenAICompletionsOptions, streamOpenAICompletions } from "./providers/openai-completions
|
|
10
|
-
import { type OpenAIResponsesOptions, streamOpenAIResponses } from "./providers/openai-responses
|
|
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
|
|
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
|
|
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
|
|
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"
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Anthropic OAuth flow (Claude Pro/Max)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { generatePKCE } from "./pkce
|
|
6
|
-
import type { OAuthCredentials } from "./types
|
|
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
|
|
6
|
-
import type { OAuthCredentials } from "./types
|
|
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
|
|
10
|
-
import type { OAuthCredentials } from "./types
|
|
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
|
|
10
|
-
import type { OAuthCredentials } from "./types
|
|
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(
|
package/src/utils/oauth/index.ts
CHANGED
|
@@ -10,36 +10,36 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
// Anthropic
|
|
13
|
-
export { loginAnthropic, refreshAnthropicToken } from "./anthropic
|
|
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
|
|
20
|
+
} from "./github-copilot";
|
|
21
21
|
// Google Antigravity
|
|
22
22
|
export {
|
|
23
23
|
loginAntigravity,
|
|
24
24
|
refreshAntigravityToken,
|
|
25
|
-
} from "./google-antigravity
|
|
25
|
+
} from "./google-antigravity";
|
|
26
26
|
// Google Gemini CLI
|
|
27
27
|
export {
|
|
28
28
|
loginGeminiCli,
|
|
29
29
|
refreshGoogleCloudToken,
|
|
30
|
-
} from "./google-gemini-cli
|
|
30
|
+
} from "./google-gemini-cli";
|
|
31
31
|
|
|
32
|
-
export * from "./types
|
|
32
|
+
export * from "./types";
|
|
33
33
|
|
|
34
34
|
// ============================================================================
|
|
35
35
|
// High-level API
|
|
36
36
|
// ============================================================================
|
|
37
37
|
|
|
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
|
|
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.
|
package/src/utils/overflow.ts
CHANGED
package/src/utils/validation.ts
CHANGED
|
@@ -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
|
|
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
|