mini-coder 0.5.14 → 0.6.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 +25 -109
- package/bin/mc.ts +8 -11
- package/bun.lock +79 -269
- package/package.json +17 -22
- package/src/agent.ts +237 -1403
- package/src/args.ts +289 -0
- package/src/headless.ts +43 -358
- package/src/index.ts +29 -1016
- package/src/oauth.ts +117 -0
- package/src/prompt.ts +227 -284
- package/src/session.ts +55 -1306
- package/src/shared.ts +117 -38
- package/src/tool-bash.ts +110 -0
- package/src/tool-edit.ts +133 -0
- package/src/tool-task.ts +114 -0
- package/src/tui-components.ts +150 -0
- package/src/tui-conversation.ts +262 -0
- package/src/tui-editor.ts +29 -0
- package/src/tui-overlay.ts +403 -0
- package/src/tui.ts +236 -0
- package/src/types.ts +160 -0
- package/tsconfig.json +17 -0
- package/BENCHMARK.md +0 -107
- package/LICENSE +0 -9
- package/PROGRESS.md +0 -5
- package/assets/icon-1-minimal.svg +0 -31
- package/assets/icon-2-dark-terminal.svg +0 -48
- package/assets/icon-3-gradient-modern.svg +0 -45
- package/assets/icon-4-filled-bold.svg +0 -54
- package/assets/icon-5-community-badge.svg +0 -63
- package/assets/mc-claude-smart.png +0 -0
- package/assets/mc-gpt-smart.png +0 -0
- package/assets/preview-0-5-0.png +0 -0
- package/assets/preview.gif +0 -0
- package/benchmark-baseline.sh +0 -15
- package/benchmark-loop.sh +0 -19
- package/skills-lock.json +0 -15
- package/src/assistant-output.ts +0 -73
- package/src/cli.ts +0 -134
- package/src/delegation.ts +0 -238
- package/src/errors.ts +0 -15
- package/src/git.ts +0 -247
- package/src/input.ts +0 -168
- package/src/mcp.ts +0 -609
- package/src/paths.ts +0 -37
- package/src/session-message.ts +0 -385
- package/src/settings.ts +0 -449
- package/src/skills.ts +0 -271
- package/src/submit.ts +0 -376
- package/src/text.ts +0 -71
- package/src/theme.ts +0 -330
- package/src/tool-common.ts +0 -93
- package/src/tool-delegate.ts +0 -125
- package/src/tool-grep.ts +0 -606
- package/src/tool-read.ts +0 -313
- package/src/tool-shell.ts +0 -1051
- package/src/tools.ts +0 -1179
- package/src/ui/agent.ts +0 -320
- package/src/ui/commands.test.ts +0 -957
- package/src/ui/commands.ts +0 -848
- package/src/ui/conversation.test.ts +0 -585
- package/src/ui/conversation.ts +0 -1836
- package/src/ui/help.ts +0 -158
- package/src/ui/input.test.ts +0 -64
- package/src/ui/input.ts +0 -138
- package/src/ui/overlay.ts +0 -59
- package/src/ui/runtime.ts +0 -69
- package/src/ui/status.ts +0 -220
- package/src/ui.ts +0 -1190
- package/src/version.ts +0 -48
package/src/oauth.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
|
|
3
|
+
import { getEnvApiKey, getProviders } from "@mariozechner/pi-ai";
|
|
4
|
+
import {
|
|
5
|
+
getOAuthApiKey,
|
|
6
|
+
getOAuthProvider,
|
|
7
|
+
getOAuthProviders,
|
|
8
|
+
type OAuthProviderId,
|
|
9
|
+
} from "@mariozechner/pi-ai/oauth";
|
|
10
|
+
import { AUTH_PATH as AUTH_FILE } from "./shared";
|
|
11
|
+
import type { CliOptions, SavedOAuthCreds } from "./types";
|
|
12
|
+
|
|
13
|
+
export function isOAuthProvider(provider: string): boolean {
|
|
14
|
+
return getOAuthProviders().some(
|
|
15
|
+
(oauthProvider) => oauthProvider.id === provider,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function getAvailableProviders(): Promise<string[]> {
|
|
20
|
+
const auth = await readCreds();
|
|
21
|
+
const loggedInOAuthProviders = getOAuthProviders()
|
|
22
|
+
.map((provider) => provider.id)
|
|
23
|
+
.filter((provider) => auth[provider]);
|
|
24
|
+
const envKeyProviders = getProviders().filter(
|
|
25
|
+
(provider) => !!getEnvApiKey(provider),
|
|
26
|
+
);
|
|
27
|
+
const providers: string[] = [];
|
|
28
|
+
const providerIds = new Set<string>();
|
|
29
|
+
|
|
30
|
+
for (const provider of [...loggedInOAuthProviders, ...envKeyProviders]) {
|
|
31
|
+
if (providerIds.has(provider)) continue;
|
|
32
|
+
|
|
33
|
+
providers.push(provider);
|
|
34
|
+
providerIds.add(provider);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return providers;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function loginOAuth(provider: OAuthProviderId) {
|
|
41
|
+
const oauthProvider = getOAuthProvider(provider);
|
|
42
|
+
if (!oauthProvider) throw new Error(`Unknown OAuth provider: ${provider}`);
|
|
43
|
+
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const creds = await oauthProvider.login({
|
|
51
|
+
onAuth: ({ url, instructions }) => {
|
|
52
|
+
console.log(`Open: ${url}`);
|
|
53
|
+
if (instructions) console.log(instructions);
|
|
54
|
+
},
|
|
55
|
+
onPrompt: async (prompt) => {
|
|
56
|
+
let answer: string = "";
|
|
57
|
+
await rl.question(prompt.message, (a) => (answer = a));
|
|
58
|
+
return answer;
|
|
59
|
+
},
|
|
60
|
+
onProgress: (message) => console.log(message),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await writeCreds({ [provider]: { type: "oauth", ...creds } });
|
|
64
|
+
} finally {
|
|
65
|
+
rl.close();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return await readCreds();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getApiKey(options: CliOptions) {
|
|
72
|
+
const provider = options.model.provider;
|
|
73
|
+
const auth = await readCreds();
|
|
74
|
+
|
|
75
|
+
if (isOAuthProvider(provider)) {
|
|
76
|
+
const result = await getOAuthApiKey(provider, auth);
|
|
77
|
+
if (result) {
|
|
78
|
+
auth[provider] = { type: "oauth", ...result.newCredentials };
|
|
79
|
+
await writeCreds(auth);
|
|
80
|
+
|
|
81
|
+
return result.apiKey;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const envApiKey = getEnvApiKey(provider);
|
|
86
|
+
if (envApiKey) return envApiKey;
|
|
87
|
+
|
|
88
|
+
const knownProviders = getProviders() as string[];
|
|
89
|
+
if (!knownProviders.includes(provider)) {
|
|
90
|
+
if (options.model.api === "openai-completions") {
|
|
91
|
+
// pi-ai requires a truthy apiKey for OpenAI-compatible local providers like Ollama.
|
|
92
|
+
return "dummy";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
throw new Error("Not logged in");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function readCreds(): Promise<SavedOAuthCreds> {
|
|
102
|
+
const file = Bun.file(AUTH_FILE);
|
|
103
|
+
if (await file.exists()) {
|
|
104
|
+
return JSON.parse(await file.text());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function writeCreds(creds: SavedOAuthCreds) {
|
|
111
|
+
await Bun.write(AUTH_FILE, JSON.stringify(await mergeCreds(creds)));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function mergeCreds(newCreds: SavedOAuthCreds) {
|
|
115
|
+
const oldCreds = await readCreds();
|
|
116
|
+
return { ...oldCreds, ...newCreds };
|
|
117
|
+
}
|