@almightygpt/core 0.7.2 → 0.8.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/dist/adapters/claude.d.ts +8 -1
- package/dist/adapters/claude.d.ts.map +1 -1
- package/dist/adapters/claude.js +26 -7
- package/dist/adapters/claude.js.map +1 -1
- package/dist/adapters/gemini.d.ts +5 -1
- package/dist/adapters/gemini.d.ts.map +1 -1
- package/dist/adapters/gemini.js +23 -10
- package/dist/adapters/gemini.js.map +1 -1
- package/dist/adapters/openai.d.ts +6 -1
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openai.js +28 -16
- package/dist/adapters/openai.js.map +1 -1
- package/dist/auth/keychain.d.ts +30 -0
- package/dist/auth/keychain.d.ts.map +1 -0
- package/dist/auth/keychain.js +106 -0
- package/dist/auth/keychain.js.map +1 -0
- package/dist/auth/resolver.d.ts +32 -0
- package/dist/auth/resolver.d.ts.map +1 -0
- package/dist/auth/resolver.js +58 -0
- package/dist/auth/resolver.js.map +1 -0
- package/dist/auth/types.d.ts +45 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +51 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/validator.d.ts +33 -0
- package/dist/auth/validator.d.ts.map +1 -0
- package/dist/auth/validator.js +130 -0
- package/dist/auth/validator.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/src/adapters/claude.ts +24 -7
- package/src/adapters/gemini.ts +21 -11
- package/src/adapters/openai.ts +26 -15
- package/src/auth/keychain.ts +132 -0
- package/src/auth/resolver.ts +81 -0
- package/src/auth/types.ts +68 -0
- package/src/auth/validator.ts +145 -0
- package/src/index.ts +22 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth subsystem types — provider identifiers, resolution sources,
|
|
3
|
+
* error classes.
|
|
4
|
+
*
|
|
5
|
+
* The auth module's job is to answer one question per call:
|
|
6
|
+
* "where is the API key for <provider>, and what is it?"
|
|
7
|
+
*
|
|
8
|
+
* Resolution priority (top to bottom):
|
|
9
|
+
* 1. Explicit parameter (passed by caller — tests, extension handoff)
|
|
10
|
+
* 2. Environment variable (per-process override; wins over keychain)
|
|
11
|
+
* 3. OS keychain (persistent convenience; @napi-rs/keyring optional)
|
|
12
|
+
* 4. Missing -> throw AuthMissingError
|
|
13
|
+
*
|
|
14
|
+
* Env-wins-over-keychain is intentional. The original draft had the
|
|
15
|
+
* order flipped; Codex's independent review caught that it would
|
|
16
|
+
* silently override the VS Code extension's freshly-stored key with
|
|
17
|
+
* a stale keychain copy. See docs/claude/v0.8-auth-plan.md.
|
|
18
|
+
*/
|
|
19
|
+
export type ProviderId = "openai" | "anthropic" | "google";
|
|
20
|
+
export type KeySource = "explicit" | "env" | "keychain" | "missing";
|
|
21
|
+
export interface KeyResolution {
|
|
22
|
+
provider: ProviderId;
|
|
23
|
+
source: KeySource;
|
|
24
|
+
/** Present iff source !== "missing". */
|
|
25
|
+
key?: string;
|
|
26
|
+
/** Which env var was used (only set when source === "env"). */
|
|
27
|
+
envVar?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when no key is found in any source. Caller should surface
|
|
31
|
+
* the message verbatim — it tells the user exactly how to fix it.
|
|
32
|
+
*/
|
|
33
|
+
export declare class AuthMissingError extends Error {
|
|
34
|
+
readonly provider: ProviderId;
|
|
35
|
+
readonly envVar: string;
|
|
36
|
+
constructor(provider: ProviderId, envVar: string);
|
|
37
|
+
}
|
|
38
|
+
/** Maps each provider to the canonical env var name(s) we read. */
|
|
39
|
+
export declare const PROVIDER_ENV_VARS: Record<ProviderId, readonly string[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Browser-launchable URL where a user creates / manages keys for each
|
|
42
|
+
* provider. Used by the `almightygpt auth <provider>` flow.
|
|
43
|
+
*/
|
|
44
|
+
export declare const PROVIDER_KEY_URLS: Record<ProviderId, string>;
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE3D,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAEpE,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,UAAU,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;IAClB,wCAAwC;IACxC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBACZ,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;CAUjD;AAED,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAKnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAIxD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth subsystem types — provider identifiers, resolution sources,
|
|
3
|
+
* error classes.
|
|
4
|
+
*
|
|
5
|
+
* The auth module's job is to answer one question per call:
|
|
6
|
+
* "where is the API key for <provider>, and what is it?"
|
|
7
|
+
*
|
|
8
|
+
* Resolution priority (top to bottom):
|
|
9
|
+
* 1. Explicit parameter (passed by caller — tests, extension handoff)
|
|
10
|
+
* 2. Environment variable (per-process override; wins over keychain)
|
|
11
|
+
* 3. OS keychain (persistent convenience; @napi-rs/keyring optional)
|
|
12
|
+
* 4. Missing -> throw AuthMissingError
|
|
13
|
+
*
|
|
14
|
+
* Env-wins-over-keychain is intentional. The original draft had the
|
|
15
|
+
* order flipped; Codex's independent review caught that it would
|
|
16
|
+
* silently override the VS Code extension's freshly-stored key with
|
|
17
|
+
* a stale keychain copy. See docs/claude/v0.8-auth-plan.md.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when no key is found in any source. Caller should surface
|
|
21
|
+
* the message verbatim — it tells the user exactly how to fix it.
|
|
22
|
+
*/
|
|
23
|
+
export class AuthMissingError extends Error {
|
|
24
|
+
provider;
|
|
25
|
+
envVar;
|
|
26
|
+
constructor(provider, envVar) {
|
|
27
|
+
super(`No API key found for ${provider}. ` +
|
|
28
|
+
`Run "almightygpt auth ${provider}" to set one up interactively, ` +
|
|
29
|
+
`or export ${envVar} in your shell.`);
|
|
30
|
+
this.name = "AuthMissingError";
|
|
31
|
+
this.provider = provider;
|
|
32
|
+
this.envVar = envVar;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Maps each provider to the canonical env var name(s) we read. */
|
|
36
|
+
export const PROVIDER_ENV_VARS = {
|
|
37
|
+
openai: ["OPENAI_API_KEY"],
|
|
38
|
+
anthropic: ["ANTHROPIC_API_KEY"],
|
|
39
|
+
// Google's SDK historically accepted both names; honor both.
|
|
40
|
+
google: ["GOOGLE_API_KEY", "GEMINI_API_KEY"],
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Browser-launchable URL where a user creates / manages keys for each
|
|
44
|
+
* provider. Used by the `almightygpt auth <provider>` flow.
|
|
45
|
+
*/
|
|
46
|
+
export const PROVIDER_KEY_URLS = {
|
|
47
|
+
openai: "https://platform.openai.com/api-keys",
|
|
48
|
+
anthropic: "https://console.anthropic.com/settings/keys",
|
|
49
|
+
google: "https://aistudio.google.com/apikey",
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAeH;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,QAAQ,CAAa;IACrB,MAAM,CAAS;IACxB,YAAY,QAAoB,EAAE,MAAc;QAC9C,KAAK,CACH,wBAAwB,QAAQ,IAAI;YAClC,yBAAyB,QAAQ,iCAAiC;YAClE,aAAa,MAAM,iBAAiB,CACvC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,CAAC,MAAM,iBAAiB,GAA0C;IACtE,MAAM,EAAE,CAAC,gBAAgB,CAAC;IAC1B,SAAS,EAAE,CAAC,mBAAmB,CAAC;IAChC,6DAA6D;IAC7D,MAAM,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;CAC7C,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA+B;IAC3D,MAAM,EAAE,sCAAsC;IAC9C,SAAS,EAAE,6CAA6C;IACxD,MAAM,EAAE,oCAAoC;CAC7C,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-level key validation.
|
|
3
|
+
*
|
|
4
|
+
* Codex's review caught that listing models (e.g. `GET /v1/models`) can
|
|
5
|
+
* succeed when the key lacks model permission, has quota issues, or
|
|
6
|
+
* has billing-state problems. The user doesn't care that list-models
|
|
7
|
+
* works — they care that AlmightyGPT can run the configured review
|
|
8
|
+
* model.
|
|
9
|
+
*
|
|
10
|
+
* So we validate with the same operation class real reviews use:
|
|
11
|
+
* - OpenAI: tiny chat completion against gpt-4o
|
|
12
|
+
* - Anthropic: tiny messages call against claude-sonnet-4-6
|
|
13
|
+
* - Google: tiny generateContent call against gemini-2.5-flash
|
|
14
|
+
*
|
|
15
|
+
* Cost is fractions of a cent per call. Latency is ~1-3 seconds.
|
|
16
|
+
* Failure surfaces the provider's exact error message so the user
|
|
17
|
+
* can fix it.
|
|
18
|
+
*/
|
|
19
|
+
import type { ProviderId } from "./types.js";
|
|
20
|
+
export interface ValidationResult {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
/** Provider-reported model used (e.g. "gpt-4o-2024-08-06"). */
|
|
23
|
+
model?: string;
|
|
24
|
+
/** Provider's error message verbatim if ok === false. */
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validate that a key can actually invoke the model real reviews use.
|
|
29
|
+
* Returns a result object — never throws on validation failure (only
|
|
30
|
+
* on programmer errors like an unsupported provider).
|
|
31
|
+
*/
|
|
32
|
+
export declare function validateKey(provider: ProviderId, key: string): Promise<ValidationResult>;
|
|
33
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/auth/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAUD;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,UAAU,EACpB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,gBAAgB,CAAC,CAgB3B"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-level key validation.
|
|
3
|
+
*
|
|
4
|
+
* Codex's review caught that listing models (e.g. `GET /v1/models`) can
|
|
5
|
+
* succeed when the key lacks model permission, has quota issues, or
|
|
6
|
+
* has billing-state problems. The user doesn't care that list-models
|
|
7
|
+
* works — they care that AlmightyGPT can run the configured review
|
|
8
|
+
* model.
|
|
9
|
+
*
|
|
10
|
+
* So we validate with the same operation class real reviews use:
|
|
11
|
+
* - OpenAI: tiny chat completion against gpt-4o
|
|
12
|
+
* - Anthropic: tiny messages call against claude-sonnet-4-6
|
|
13
|
+
* - Google: tiny generateContent call against gemini-2.5-flash
|
|
14
|
+
*
|
|
15
|
+
* Cost is fractions of a cent per call. Latency is ~1-3 seconds.
|
|
16
|
+
* Failure surfaces the provider's exact error message so the user
|
|
17
|
+
* can fix it.
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_VALIDATION_MODELS = {
|
|
20
|
+
openai: "gpt-4o",
|
|
21
|
+
anthropic: "claude-sonnet-4-6",
|
|
22
|
+
google: "gemini-2.5-flash",
|
|
23
|
+
};
|
|
24
|
+
const VALIDATION_TIMEOUT_MS = 15_000;
|
|
25
|
+
/**
|
|
26
|
+
* Validate that a key can actually invoke the model real reviews use.
|
|
27
|
+
* Returns a result object — never throws on validation failure (only
|
|
28
|
+
* on programmer errors like an unsupported provider).
|
|
29
|
+
*/
|
|
30
|
+
export async function validateKey(provider, key) {
|
|
31
|
+
try {
|
|
32
|
+
switch (provider) {
|
|
33
|
+
case "openai":
|
|
34
|
+
return await validateOpenAI(key);
|
|
35
|
+
case "anthropic":
|
|
36
|
+
return await validateAnthropic(key);
|
|
37
|
+
case "google":
|
|
38
|
+
return await validateGoogle(key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
error: err instanceof Error ? err.message : String(err),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function validateOpenAI(key) {
|
|
49
|
+
const model = DEFAULT_VALIDATION_MODELS.openai;
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
const timer = setTimeout(() => controller.abort(), VALIDATION_TIMEOUT_MS);
|
|
52
|
+
try {
|
|
53
|
+
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
"content-type": "application/json",
|
|
57
|
+
authorization: `Bearer ${key}`,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
model,
|
|
61
|
+
messages: [{ role: "user", content: "hi" }],
|
|
62
|
+
max_tokens: 1,
|
|
63
|
+
}),
|
|
64
|
+
signal: controller.signal,
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
return { ok: false, error: await res.text().catch(() => res.statusText) };
|
|
68
|
+
}
|
|
69
|
+
const data = (await res.json());
|
|
70
|
+
return { ok: true, model: data.model ?? model };
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function validateAnthropic(key) {
|
|
77
|
+
const model = DEFAULT_VALIDATION_MODELS.anthropic;
|
|
78
|
+
const controller = new AbortController();
|
|
79
|
+
const timer = setTimeout(() => controller.abort(), VALIDATION_TIMEOUT_MS);
|
|
80
|
+
try {
|
|
81
|
+
const res = await fetch("https://api.anthropic.com/v1/messages", {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: {
|
|
84
|
+
"content-type": "application/json",
|
|
85
|
+
"x-api-key": key,
|
|
86
|
+
"anthropic-version": "2023-06-01",
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
model,
|
|
90
|
+
max_tokens: 5,
|
|
91
|
+
messages: [{ role: "user", content: "hi" }],
|
|
92
|
+
}),
|
|
93
|
+
signal: controller.signal,
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
return { ok: false, error: await res.text().catch(() => res.statusText) };
|
|
97
|
+
}
|
|
98
|
+
const data = (await res.json());
|
|
99
|
+
return { ok: true, model: data.model ?? model };
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function validateGoogle(key) {
|
|
106
|
+
const model = DEFAULT_VALIDATION_MODELS.google;
|
|
107
|
+
const controller = new AbortController();
|
|
108
|
+
const timer = setTimeout(() => controller.abort(), VALIDATION_TIMEOUT_MS);
|
|
109
|
+
try {
|
|
110
|
+
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=` +
|
|
111
|
+
encodeURIComponent(key);
|
|
112
|
+
const res = await fetch(url, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: { "content-type": "application/json" },
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
contents: [{ parts: [{ text: "hi" }] }],
|
|
117
|
+
generationConfig: { maxOutputTokens: 5 },
|
|
118
|
+
}),
|
|
119
|
+
signal: controller.signal,
|
|
120
|
+
});
|
|
121
|
+
if (!res.ok) {
|
|
122
|
+
return { ok: false, error: await res.text().catch(() => res.statusText) };
|
|
123
|
+
}
|
|
124
|
+
return { ok: true, model };
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/auth/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAYH,MAAM,yBAAyB,GAA+B;IAC5D,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,mBAAmB;IAC9B,MAAM,EAAE,kBAAkB;CAC3B,CAAC;AAEF,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,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EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5E,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - review/ ✅ task #11 diff review pipeline (with #12/#13/#14 wiring)
|
|
13
13
|
* - budget/ ✅ task #14 BudgetTracker + BudgetExceededError
|
|
14
14
|
*/
|
|
15
|
-
export declare const VERSION = "0.
|
|
15
|
+
export declare const VERSION = "0.8.0";
|
|
16
16
|
export { checkGitStatus, assertSafeToWrite, GitStatusDirtyError, type GitStatusCheck, } from "./git/status.js";
|
|
17
17
|
export { installTemplate, hasExistingConfig, type InstallOptions, type InstallResult, } from "./templates/install.js";
|
|
18
18
|
export { loadConfig, ConfigError } from "./config/load.js";
|
|
@@ -30,4 +30,8 @@ export { collectGitDiff, type DiffOptions, type DiffResult } from "./review/diff
|
|
|
30
30
|
export { writeHumanReviewFile, ReviewFileExistsError, reviewFilePathFor, preflightReviewFileCollision, type WriteReviewFileOptions, } from "./review/write.js";
|
|
31
31
|
export { BudgetTracker, BudgetExceededError, type BudgetCaps, } from "./review/budget.js";
|
|
32
32
|
export type { ReviewEvent, ReviewEventHandler, AgentRoleInRun, } from "./review/events.js";
|
|
33
|
+
export { resolveApiKey, requireApiKey, type ResolveOptions, } from "./auth/resolver.js";
|
|
34
|
+
export { getKeychain, _resetKeychainCache, type KeychainAdapter, } from "./auth/keychain.js";
|
|
35
|
+
export { validateKey, type ValidationResult } from "./auth/validator.js";
|
|
36
|
+
export { AuthMissingError, PROVIDER_ENV_VARS, PROVIDER_KEY_URLS, type ProviderId, type KeySource, type KeyResolution, } from "./auth/types.js";
|
|
33
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
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M,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,cAAc,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - review/ ✅ task #11 diff review pipeline (with #12/#13/#14 wiring)
|
|
13
13
|
* - budget/ ✅ task #14 BudgetTracker + BudgetExceededError
|
|
14
14
|
*/
|
|
15
|
-
export const VERSION = "0.
|
|
15
|
+
export const VERSION = "0.8.0";
|
|
16
16
|
// Git safety primitives
|
|
17
17
|
export { checkGitStatus, assertSafeToWrite, GitStatusDirtyError, } from "./git/status.js";
|
|
18
18
|
// Template installer
|
|
@@ -35,4 +35,9 @@ export { runWorkerReviewerReview, } from "./review/run-worker-reviewer.js";
|
|
|
35
35
|
export { collectGitDiff } from "./review/diff.js";
|
|
36
36
|
export { writeHumanReviewFile, ReviewFileExistsError, reviewFilePathFor, preflightReviewFileCollision, } from "./review/write.js";
|
|
37
37
|
export { BudgetTracker, BudgetExceededError, } from "./review/budget.js";
|
|
38
|
+
// Auth subsystem (v0.8.0+) — resolver, keychain, validator
|
|
39
|
+
export { resolveApiKey, requireApiKey, } from "./auth/resolver.js";
|
|
40
|
+
export { getKeychain, _resetKeychainCache, } from "./auth/keychain.js";
|
|
41
|
+
export { validateKey } from "./auth/validator.js";
|
|
42
|
+
export { AuthMissingError, PROVIDER_ENV_VARS, PROVIDER_KEY_URLS, } from "./auth/types.js";
|
|
38
43
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,wBAAwB;AACxB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,iBAAiB,CAAC;AAEzB,qBAAqB;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,GAGlB,MAAM,wBAAwB,CAAC;AAEhC,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,GAGhB,MAAM,oBAAoB,CAAC;AAE5B,WAAW;AACX,OAAO,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,GAQd,MAAM,qBAAqB,CAAC;AAE7B,sBAAsB;AACtB,OAAO,EAAE,aAAa,EAA6C,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GAGrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO;AACP,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,aAAa,EACb,cAAc,GAIf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,GAGf,MAAM,kBAAkB,CAAC;AAE1B,kBAAkB;AAClB,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAC;AACrC,OAAO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AAClB,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,uBAAuB,GAGxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAqC,MAAM,kBAAkB,CAAC;AACrF,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,4BAA4B,GAE7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAO5B,2DAA2D;AAC3D,OAAO,EACL,aAAa,EACb,aAAa,GAEd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,WAAW,EACX,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAyB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAIlB,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almightygpt/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Core orchestrator, adapters, config, runs, and review logic for AlmightyGPT",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,5 +31,8 @@
|
|
|
31
31
|
"p-limit": "^5.0.0",
|
|
32
32
|
"yaml": "^2.4.0",
|
|
33
33
|
"zod": "^3.23.0"
|
|
34
|
+
},
|
|
35
|
+
"optionalDependencies": {
|
|
36
|
+
"@napi-rs/keyring": "^1.1.6"
|
|
34
37
|
}
|
|
35
38
|
}
|
package/src/adapters/claude.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
type AdapterInput,
|
|
22
22
|
type AdapterOutput,
|
|
23
23
|
} from "./types.js";
|
|
24
|
+
import { resolveApiKey } from "../auth/resolver.js";
|
|
24
25
|
|
|
25
26
|
const PRICING_USD_PER_1M: Record<string, { input: number; output: number }> = {
|
|
26
27
|
// Claude 4.x family (current)
|
|
@@ -47,7 +48,9 @@ export class ClaudeAdapter implements Adapter {
|
|
|
47
48
|
readonly name: string;
|
|
48
49
|
readonly provider = "anthropic";
|
|
49
50
|
|
|
50
|
-
private
|
|
51
|
+
private client: Anthropic | null = null;
|
|
52
|
+
private resolved = false;
|
|
53
|
+
private readonly explicitApiKey: string | undefined;
|
|
51
54
|
readonly defaultModel: string;
|
|
52
55
|
private readonly defaultMaxOutputTokens: number;
|
|
53
56
|
private readonly defaultTimeoutMs: number;
|
|
@@ -57,19 +60,33 @@ export class ClaudeAdapter implements Adapter {
|
|
|
57
60
|
this.defaultModel = options.defaultModel ?? DEFAULT_MODEL;
|
|
58
61
|
this.defaultMaxOutputTokens = options.defaultMaxOutputTokens ?? 4096;
|
|
59
62
|
this.defaultTimeoutMs = options.defaultTimeoutMs ?? 120_000;
|
|
63
|
+
this.explicitApiKey = options.apiKey;
|
|
64
|
+
}
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Lazily resolve the API key on first need. Goes through the
|
|
68
|
+
* unified resolver: explicit → env → keychain → missing.
|
|
69
|
+
*/
|
|
70
|
+
private async ensureClient(): Promise<Anthropic | null> {
|
|
71
|
+
if (this.resolved) return this.client;
|
|
72
|
+
this.resolved = true;
|
|
73
|
+
const opts = this.explicitApiKey ? { explicit: this.explicitApiKey } : {};
|
|
74
|
+
const result = await resolveApiKey("anthropic", opts);
|
|
75
|
+
if (result.source === "missing") return null;
|
|
76
|
+
this.client = new Anthropic({ apiKey: result.key! });
|
|
77
|
+
return this.client;
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
async isAvailable(): Promise<boolean> {
|
|
66
|
-
return this.
|
|
81
|
+
return (await this.ensureClient()) !== null;
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
async execute(input: AdapterInput): Promise<AdapterOutput> {
|
|
70
|
-
|
|
85
|
+
const client = await this.ensureClient();
|
|
86
|
+
if (!client) {
|
|
71
87
|
throw new AdapterError(
|
|
72
|
-
|
|
88
|
+
'No Anthropic API key found. Run "almightygpt auth anthropic" ' +
|
|
89
|
+
"or export ANTHROPIC_API_KEY in your environment.",
|
|
73
90
|
this.name,
|
|
74
91
|
);
|
|
75
92
|
}
|
|
@@ -81,7 +98,7 @@ export class ClaudeAdapter implements Adapter {
|
|
|
81
98
|
const start = Date.now();
|
|
82
99
|
let response: Anthropic.Message;
|
|
83
100
|
try {
|
|
84
|
-
response = await
|
|
101
|
+
response = await client.messages.create(
|
|
85
102
|
{
|
|
86
103
|
model,
|
|
87
104
|
max_tokens: maxOutputTokens,
|
package/src/adapters/gemini.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
type AdapterInput,
|
|
30
30
|
type AdapterOutput,
|
|
31
31
|
} from "./types.js";
|
|
32
|
+
import { resolveApiKey } from "../auth/resolver.js";
|
|
32
33
|
|
|
33
34
|
const PRICING_USD_PER_1M: Record<string, { input: number; output: number }> = {
|
|
34
35
|
"gemini-2.5-pro": { input: 1.25, output: 10.0 },
|
|
@@ -58,7 +59,9 @@ export class GeminiAdapter implements Adapter {
|
|
|
58
59
|
readonly name: string;
|
|
59
60
|
readonly provider = "google";
|
|
60
61
|
|
|
61
|
-
private
|
|
62
|
+
private client: GoogleGenerativeAI | null = null;
|
|
63
|
+
private resolved = false;
|
|
64
|
+
private readonly explicitApiKey: string | undefined;
|
|
62
65
|
readonly defaultModel: string;
|
|
63
66
|
private readonly defaultMaxOutputTokens: number;
|
|
64
67
|
private readonly defaultTimeoutMs: number;
|
|
@@ -73,23 +76,30 @@ export class GeminiAdapter implements Adapter {
|
|
|
73
76
|
// below to make sure the visible response gets the full budget.
|
|
74
77
|
this.defaultMaxOutputTokens = options.defaultMaxOutputTokens ?? 8192;
|
|
75
78
|
this.defaultTimeoutMs = options.defaultTimeoutMs ?? 120_000;
|
|
79
|
+
this.explicitApiKey = options.apiKey;
|
|
80
|
+
}
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
/** Lazily resolve via the unified resolver: explicit → env → keychain. */
|
|
83
|
+
private async ensureClient(): Promise<GoogleGenerativeAI | null> {
|
|
84
|
+
if (this.resolved) return this.client;
|
|
85
|
+
this.resolved = true;
|
|
86
|
+
const opts = this.explicitApiKey ? { explicit: this.explicitApiKey } : {};
|
|
87
|
+
const result = await resolveApiKey("google", opts);
|
|
88
|
+
if (result.source === "missing") return null;
|
|
89
|
+
this.client = new GoogleGenerativeAI(result.key!);
|
|
90
|
+
return this.client;
|
|
82
91
|
}
|
|
83
92
|
|
|
84
93
|
async isAvailable(): Promise<boolean> {
|
|
85
|
-
return this.
|
|
94
|
+
return (await this.ensureClient()) !== null;
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
async execute(input: AdapterInput): Promise<AdapterOutput> {
|
|
89
|
-
|
|
98
|
+
const client = await this.ensureClient();
|
|
99
|
+
if (!client) {
|
|
90
100
|
throw new AdapterError(
|
|
91
|
-
|
|
92
|
-
"
|
|
101
|
+
'No Google API key found. Run "almightygpt auth google" ' +
|
|
102
|
+
"or export GOOGLE_API_KEY (or GEMINI_API_KEY) in your environment.",
|
|
93
103
|
this.name,
|
|
94
104
|
);
|
|
95
105
|
}
|
|
@@ -112,7 +122,7 @@ export class GeminiAdapter implements Adapter {
|
|
|
112
122
|
generationConfig["responseMimeType"] = "application/json";
|
|
113
123
|
}
|
|
114
124
|
|
|
115
|
-
const generative =
|
|
125
|
+
const generative = client.getGenerativeModel({
|
|
116
126
|
model,
|
|
117
127
|
systemInstruction: input.systemPrompt,
|
|
118
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/src/adapters/openai.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import OpenAI from "openai";
|
|
16
16
|
import { AdapterError, type Adapter, type AdapterInput, type AdapterOutput } from "./types.js";
|
|
17
|
+
import { resolveApiKey } from "../auth/resolver.js";
|
|
17
18
|
|
|
18
19
|
/** USD per 1M tokens, by model. Lowercased keys. */
|
|
19
20
|
const PRICING_USD_PER_1M: Record<string, { input: number; output: number }> = {
|
|
@@ -42,7 +43,10 @@ export class OpenAIAdapter implements Adapter {
|
|
|
42
43
|
readonly name: string;
|
|
43
44
|
readonly provider = "openai";
|
|
44
45
|
|
|
45
|
-
private
|
|
46
|
+
private client: OpenAI | null = null;
|
|
47
|
+
private resolved = false;
|
|
48
|
+
private readonly explicitApiKey: string | undefined;
|
|
49
|
+
private readonly organization: string | undefined;
|
|
46
50
|
readonly defaultModel: string;
|
|
47
51
|
private readonly defaultMaxOutputTokens: number;
|
|
48
52
|
private readonly defaultTimeoutMs: number;
|
|
@@ -55,27 +59,34 @@ export class OpenAIAdapter implements Adapter {
|
|
|
55
59
|
this.defaultModel = options.defaultModel ?? DEFAULT_MODEL;
|
|
56
60
|
this.defaultMaxOutputTokens = options.defaultMaxOutputTokens ?? 4096;
|
|
57
61
|
this.defaultTimeoutMs = options.defaultTimeoutMs ?? 120_000;
|
|
62
|
+
this.explicitApiKey = options.apiKey;
|
|
63
|
+
this.organization = options.organization;
|
|
64
|
+
}
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
/** Lazily resolve via the unified resolver: explicit → env → keychain. */
|
|
67
|
+
private async ensureClient(): Promise<OpenAI | null> {
|
|
68
|
+
if (this.resolved) return this.client;
|
|
69
|
+
this.resolved = true;
|
|
70
|
+
const opts = this.explicitApiKey ? { explicit: this.explicitApiKey } : {};
|
|
71
|
+
const result = await resolveApiKey("openai", opts);
|
|
72
|
+
if (result.source === "missing") return null;
|
|
73
|
+
this.client = new OpenAI({
|
|
74
|
+
apiKey: result.key!,
|
|
75
|
+
...(this.organization ? { organization: this.organization } : {}),
|
|
76
|
+
});
|
|
77
|
+
return this.client;
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
async isAvailable(): Promise<boolean> {
|
|
71
|
-
return this.
|
|
81
|
+
return (await this.ensureClient()) !== null;
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
async execute(input: AdapterInput): Promise<AdapterOutput> {
|
|
75
|
-
|
|
85
|
+
const client = await this.ensureClient();
|
|
86
|
+
if (!client) {
|
|
76
87
|
throw new AdapterError(
|
|
77
|
-
|
|
78
|
-
"
|
|
88
|
+
'No OpenAI API key found. Run "almightygpt auth openai" ' +
|
|
89
|
+
"or export OPENAI_API_KEY in your environment.",
|
|
79
90
|
this.name,
|
|
80
91
|
);
|
|
81
92
|
}
|
|
@@ -87,7 +98,7 @@ export class OpenAIAdapter implements Adapter {
|
|
|
87
98
|
const start = Date.now();
|
|
88
99
|
let response: OpenAI.Chat.Completions.ChatCompletion;
|
|
89
100
|
try {
|
|
90
|
-
response = await
|
|
101
|
+
response = await client.chat.completions.create(
|
|
91
102
|
{
|
|
92
103
|
model,
|
|
93
104
|
max_tokens: maxOutputTokens,
|