pi-xai-oauth 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # pi-xai-oauth
2
+
3
+ xAI (Grok) model provider with OAuth login support for pi.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pi install npm:pi-xai-oauth
9
+ # or
10
+ pi install git:github.com/yourname/pi-xai-oauth
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ After installing, authenticate with:
16
+
17
+ ```bash
18
+ pi /login xai-oauth
19
+ ```
20
+
21
+ Then select any Grok model via `/model`.
22
+
23
+ ## Supported Models
24
+
25
+ - `grok-3`
26
+ - `grok-3-mini`
27
+ - `grok-4`
28
+ - `grok-4.3` (1M context)
29
+
30
+ All models support extended reasoning with thinking levels (`low` / `medium` / `high`).
31
+
32
+ ## Configuration
33
+
34
+ The extension registers the provider as `xai-oauth`.
35
+
36
+ You can override the base URL or add custom headers via `~/.pi/agent/models.json` if needed.
37
+
38
+ ## Authentication
39
+
40
+ This package uses a clean prompt-based flow for xAI API keys.
41
+
42
+ After installing, run:
43
+
44
+ ```bash
45
+ pi /login xai-oauth
46
+ ```
47
+
48
+ Then paste your key from https://console.x.ai
@@ -0,0 +1,106 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import type { OAuthCredentials, OAuthLoginCallbacks } from "@earendil-works/pi-ai";
3
+
4
+ export default function (pi: ExtensionAPI) {
5
+ pi.registerProvider("xai-oauth", {
6
+ name: "xAI (OAuth)",
7
+ baseUrl: "https://api.x.ai/v1",
8
+ api: "openai-completions",
9
+ authHeader: true,
10
+
11
+ oauth: {
12
+ name: "xAI (Grok)",
13
+
14
+ async login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
15
+ const accessToken = await callbacks.onPrompt({
16
+ message:
17
+ "Paste your xAI API key (starts with xai-).\n" +
18
+ "You can get one at https://console.x.ai"
19
+ });
20
+
21
+ return {
22
+ refresh: "",
23
+ access: accessToken.trim(),
24
+ expires: Date.now() + 1000 * 60 * 60 * 24 * 365,
25
+ };
26
+ },
27
+
28
+ async refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials> {
29
+ // xAI currently doesn't require token refresh for API keys.
30
+ // Return the same credentials.
31
+ return credentials;
32
+ },
33
+
34
+ getApiKey(credentials: OAuthCredentials): string {
35
+ return credentials.access;
36
+ },
37
+ },
38
+
39
+ models: [
40
+ {
41
+ id: "grok-3",
42
+ name: "Grok 3",
43
+ reasoning: true,
44
+ input: ["text", "image"],
45
+ contextWindow: 131072,
46
+ maxTokens: 16384,
47
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
48
+ thinkingLevelMap: {
49
+ minimal: null,
50
+ low: "low",
51
+ medium: "medium",
52
+ high: "high",
53
+ xhigh: "high",
54
+ },
55
+ },
56
+ {
57
+ id: "grok-3-mini",
58
+ name: "Grok 3 Mini",
59
+ reasoning: true,
60
+ input: ["text", "image"],
61
+ contextWindow: 131072,
62
+ maxTokens: 16384,
63
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
64
+ thinkingLevelMap: {
65
+ minimal: null,
66
+ low: "low",
67
+ medium: "medium",
68
+ high: "high",
69
+ xhigh: "high",
70
+ },
71
+ },
72
+ {
73
+ id: "grok-4",
74
+ name: "Grok 4",
75
+ reasoning: true,
76
+ input: ["text", "image"],
77
+ contextWindow: 262144,
78
+ maxTokens: 16384,
79
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
80
+ thinkingLevelMap: {
81
+ minimal: null,
82
+ low: "low",
83
+ medium: "medium",
84
+ high: "high",
85
+ xhigh: "high",
86
+ },
87
+ },
88
+ {
89
+ id: "grok-4.3",
90
+ name: "Grok 4.3",
91
+ reasoning: true,
92
+ input: ["text", "image"],
93
+ contextWindow: 1000000,
94
+ maxTokens: 32768,
95
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
96
+ thinkingLevelMap: {
97
+ minimal: null,
98
+ low: "low",
99
+ medium: "medium",
100
+ high: "high",
101
+ xhigh: "high",
102
+ },
103
+ },
104
+ ],
105
+ });
106
+ }
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "pi-xai-oauth",
3
+ "version": "0.1.0",
4
+ "description": "xAI (Grok) provider with OAuth support for pi",
5
+ "keywords": ["pi-package"],
6
+ "license": "MIT",
7
+ "pi": {
8
+ "extensions": ["./extensions"]
9
+ },
10
+ "peerDependencies": {
11
+ "@earendil-works/pi-coding-agent": "*",
12
+ "@earendil-works/pi-ai": "*"
13
+ }
14
+ }