@kenkaiiii/gg-core 6.4.0 → 7.0.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 +20 -9
- package/dist/{chunk-VREIRQMU.js → chunk-BMRRMRUO.js} +19 -14
- package/dist/chunk-BMRRMRUO.js.map +1 -0
- package/dist/{chunk-GXOFTHM5.js → chunk-DNNLWE2F.js} +7 -2
- package/dist/chunk-DNNLWE2F.js.map +1 -0
- package/dist/index.cjs +36 -538
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -182
- package/dist/index.d.ts +6 -182
- package/dist/index.js +6 -510
- package/dist/index.js.map +1 -1
- package/dist/model-registry.cjs +3 -2
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.js +2 -2
- package/dist/paths.cjs +7 -1
- package/dist/paths.cjs.map +1 -1
- package/dist/paths.d.cts +4 -2
- package/dist/paths.d.ts +4 -2
- package/dist/paths.js +3 -1
- package/package.json +5 -6
- package/dist/chunk-GXOFTHM5.js.map +0 -1
- package/dist/chunk-VREIRQMU.js.map +0 -1
package/README.md
CHANGED
|
@@ -52,8 +52,8 @@ console.log(models.map((m) => m.id));
|
|
|
52
52
|
| Provider list | `AUTH_PROVIDERS`: each provider's name, models, sign-in methods and plan/pay-per-token keys, ready for a login screen |
|
|
53
53
|
| Local models | `discoverLocalModels`, `probeEndpoint`: Ollama by default, plus LM Studio, llama.cpp, vLLM or any custom URL |
|
|
54
54
|
| Plan usage | `fetchSubscriptionUsage`: remaining Kimi Code plan usage (Claude reports its own; ChatGPT's is at chatgpt.com/settings/usage) |
|
|
55
|
-
| Paths | `getAppPaths`: every file
|
|
56
|
-
| Other | Logger, file lock
|
|
55
|
+
| Paths | `getAppPaths`: every file kept under `~/.gg/`; `configureAppDataDir` moves them to your own folder |
|
|
56
|
+
| Other | Logger, file lock |
|
|
57
57
|
|
|
58
58
|
`AuthStorage` shares `~/.gg/auth.json` with GG Coder, so a user who has signed in there is already signed in to your tool. Pass a different file path to the constructor to keep your own.
|
|
59
59
|
|
|
@@ -66,16 +66,27 @@ import { getModel } from "@kenkaiiii/gg-core/models";
|
|
|
66
66
|
import { getAppPaths } from "@kenkaiiii/gg-core/paths";
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
## Your own app
|
|
70
|
+
|
|
71
|
+
By default gg-core shares GG Coder's data folder (`~/.gg`) and names GG Coder on sign-in pages and in errors. Set both once at startup:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { configureAppIdentity } from "@kenkaiiii/gg-ai";
|
|
75
|
+
import { configureAppDataDir } from "@kenkaiiii/gg-core";
|
|
76
|
+
|
|
77
|
+
configureAppIdentity({ name: "My App", userAgent: "my-app/1.0 (+https://example.com)" });
|
|
78
|
+
configureAppDataDir("/path/to/my-app-data");
|
|
79
|
+
```
|
|
70
80
|
|
|
71
81
|
## The GG Framework
|
|
72
82
|
|
|
73
|
-
| Package
|
|
74
|
-
|
|
|
75
|
-
| [@kenkaiiii/gg-ai](https://www.npmjs.com/package/@kenkaiiii/gg-ai)
|
|
76
|
-
| [@kenkaiiii/gg-agent](https://www.npmjs.com/package/@kenkaiiii/gg-agent)
|
|
77
|
-
| **@kenkaiiii/gg-core**
|
|
78
|
-
| [@kenkaiiii/
|
|
83
|
+
| Package | What it does |
|
|
84
|
+
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
85
|
+
| [@kenkaiiii/gg-ai](https://www.npmjs.com/package/@kenkaiiii/gg-ai) | One streaming API for every provider |
|
|
86
|
+
| [@kenkaiiii/gg-agent](https://www.npmjs.com/package/@kenkaiiii/gg-agent) | The agent loop: runs tools and feeds results back to the model |
|
|
87
|
+
| **@kenkaiiii/gg-core** | Model list, sign-in and stored credentials, local model discovery (this package) |
|
|
88
|
+
| [@kenkaiiii/gg-engine](https://www.npmjs.com/package/@kenkaiiii/gg-engine) | The coding-agent engine: sessions, tools, skills and MCP |
|
|
89
|
+
| [@kenkaiiii/ggcoder](https://www.npmjs.com/package/@kenkaiiii/ggcoder) | The GG Coder command-line app |
|
|
79
90
|
|
|
80
91
|
Source, issues and the desktop app: [github.com/KenKaiii/gg-framework](https://github.com/KenKaiii/gg-framework).
|
|
81
92
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getAppPaths
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DNNLWE2F.js";
|
|
4
4
|
|
|
5
5
|
// src/kimi-region.ts
|
|
6
|
-
import {
|
|
6
|
+
import { getAppIdentity } from "@kenkaiiii/gg-ai";
|
|
7
7
|
var KIMI_CODE_DEFAULT_BASE_URL = "https://api.kimi.com/coding/v1";
|
|
8
8
|
var KIMI_CODE_OVERSEAS_BASE_URL = "https://api.kimi.ai/coding/v1";
|
|
9
9
|
var KIMI_CODE_BASE_URLS = [KIMI_CODE_DEFAULT_BASE_URL, KIMI_CODE_OVERSEAS_BASE_URL];
|
|
10
10
|
async function probeHost(baseUrl, apiKey, fetchImpl, timeoutMs) {
|
|
11
11
|
try {
|
|
12
12
|
const res = await fetchImpl(`${baseUrl}/models`, {
|
|
13
|
-
headers: { Authorization: `Bearer ${apiKey}`, "User-Agent":
|
|
13
|
+
headers: { Authorization: `Bearer ${apiKey}`, "User-Agent": getAppIdentity().userAgent },
|
|
14
14
|
signal: AbortSignal.timeout(timeoutMs)
|
|
15
15
|
});
|
|
16
16
|
if (res.ok) return "authorized";
|
|
@@ -556,6 +556,7 @@ import http from "http";
|
|
|
556
556
|
import crypto3 from "crypto";
|
|
557
557
|
import fs3 from "fs/promises";
|
|
558
558
|
import path2 from "path";
|
|
559
|
+
import { getAppIdentity as getAppIdentity2 } from "@kenkaiiii/gg-ai";
|
|
559
560
|
|
|
560
561
|
// src/oauth/pkce.ts
|
|
561
562
|
function base64urlEncode(bytes) {
|
|
@@ -588,7 +589,6 @@ var TOKEN_URL = `${ISSUER}/api/accounts/oauth/token`;
|
|
|
588
589
|
var REVOKE_URL = `${ISSUER}/api/accounts/oauth/revoke`;
|
|
589
590
|
var JWKS_URL = `${ISSUER}/.well-known/jwks.json`;
|
|
590
591
|
var REGISTRATION_CLIENT_ID = "dynamic_agent_client";
|
|
591
|
-
var AGENT_NAME = "GG Coder";
|
|
592
592
|
var RESOURCE = "https://api.openai.com/v1";
|
|
593
593
|
var CHATGPT_PLAN_SCOPE = "chatgpt.tokens.use.direct";
|
|
594
594
|
var SCOPES = `openid profile email offline_access resource.invoke ${CHATGPT_PLAN_SCOPE}`;
|
|
@@ -599,10 +599,13 @@ var PREFERRED_PORT = 1455;
|
|
|
599
599
|
var CALLBACK_TIMEOUT_MS = 12e4;
|
|
600
600
|
var MAX_PASTE_ATTEMPTS = 3;
|
|
601
601
|
var ID_TOKEN_CLOCK_SKEW_S = 60;
|
|
602
|
-
var
|
|
602
|
+
var appName = () => getAppIdentity2().name;
|
|
603
|
+
function chatgptPlanNotEnabledMessage() {
|
|
604
|
+
return `ChatGPT plan use isn't enabled for ${appName()}. Allow Use your ChatGPT plan, or add an OpenAI API key.`;
|
|
605
|
+
}
|
|
603
606
|
var ChatGPTPlanNotEnabledError = class extends Error {
|
|
604
607
|
constructor() {
|
|
605
|
-
super(
|
|
608
|
+
super(chatgptPlanNotEnabledMessage());
|
|
606
609
|
this.name = "ChatGPTPlanNotEnabledError";
|
|
607
610
|
}
|
|
608
611
|
};
|
|
@@ -708,7 +711,7 @@ async function loginChatGPT(callbacks, options = {}) {
|
|
|
708
711
|
const redirectUri = `http://127.0.0.1:${listener.port}${CALLBACK_PATH}`;
|
|
709
712
|
const url = new URL(AUTHORIZE_URL);
|
|
710
713
|
url.searchParams.set("client_id", knownClientId ?? REGISTRATION_CLIENT_ID);
|
|
711
|
-
if (!knownClientId) url.searchParams.set("agent_name_hint",
|
|
714
|
+
if (!knownClientId) url.searchParams.set("agent_name_hint", appName());
|
|
712
715
|
url.searchParams.set("ext_agent_host_id", hostId);
|
|
713
716
|
if (registration && current && options.previous?.idToken) {
|
|
714
717
|
url.searchParams.set("id_token_hint", options.previous.idToken);
|
|
@@ -742,7 +745,7 @@ async function loginChatGPT(callbacks, options = {}) {
|
|
|
742
745
|
const clientId = knownClientId ?? issued;
|
|
743
746
|
if (!clientId || clientId === REGISTRATION_CLIENT_ID) {
|
|
744
747
|
throw new Error(
|
|
745
|
-
|
|
748
|
+
`ChatGPT didn't finish registering ${appName()}. Start the sign-in again, and paste the full callback URL if you're on another machine.`
|
|
746
749
|
);
|
|
747
750
|
}
|
|
748
751
|
issuedClientId = clientId;
|
|
@@ -842,7 +845,7 @@ async function startCallbackListener(expectedState, anyPort) {
|
|
|
842
845
|
}
|
|
843
846
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
844
847
|
res.end(
|
|
845
|
-
|
|
848
|
+
`<html><body><h1>You're signed in to ${escapeHtml(appName())}.</h1><p>You can close this tab.</p></body></html>`
|
|
846
849
|
);
|
|
847
850
|
settle?.resolve(url.searchParams);
|
|
848
851
|
server.close();
|
|
@@ -1083,6 +1086,9 @@ async function verifyIdToken(idToken, expected) {
|
|
|
1083
1086
|
if (claims.nonce !== expected.nonce) throw new Error("ChatGPT ID token nonce mismatch.");
|
|
1084
1087
|
return claims;
|
|
1085
1088
|
}
|
|
1089
|
+
function escapeHtml(text) {
|
|
1090
|
+
return text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
1091
|
+
}
|
|
1086
1092
|
|
|
1087
1093
|
// src/file-lock.ts
|
|
1088
1094
|
import fs4 from "fs/promises";
|
|
@@ -1183,7 +1189,7 @@ var processBytes = 0;
|
|
|
1183
1189
|
var rotationFailed = false;
|
|
1184
1190
|
var capped = false;
|
|
1185
1191
|
var sessionId = "";
|
|
1186
|
-
var
|
|
1192
|
+
var appName2 = "app";
|
|
1187
1193
|
var cleanups = [];
|
|
1188
1194
|
var exactSecrets = [];
|
|
1189
1195
|
function rotateIfNeeded(filePath, force = false) {
|
|
@@ -1238,7 +1244,7 @@ function rotateOpenLog() {
|
|
|
1238
1244
|
}
|
|
1239
1245
|
function openLog(filePath, name) {
|
|
1240
1246
|
if (fd !== null || capped) return false;
|
|
1241
|
-
|
|
1247
|
+
appName2 = name;
|
|
1242
1248
|
exactSecrets = environmentSecrets(process.env);
|
|
1243
1249
|
try {
|
|
1244
1250
|
fs5.mkdirSync(path3.dirname(filePath), { recursive: true, mode: 448 });
|
|
@@ -1327,7 +1333,7 @@ function registerLogCleanup(fn) {
|
|
|
1327
1333
|
}
|
|
1328
1334
|
function closeLogger(opts) {
|
|
1329
1335
|
if (fd !== null) {
|
|
1330
|
-
if (opts?.shutdownLine !== false) log("INFO", "shutdown", `${
|
|
1336
|
+
if (opts?.shutdownLine !== false) log("INFO", "shutdown", `${appName2} shutting down`);
|
|
1331
1337
|
try {
|
|
1332
1338
|
if (fd !== null) fs5.closeSync(fd);
|
|
1333
1339
|
} catch {
|
|
@@ -3326,7 +3332,6 @@ export {
|
|
|
3326
3332
|
CHATGPT_PLAN_SCOPE,
|
|
3327
3333
|
CHATGPT_PLAN_BASE_URL,
|
|
3328
3334
|
CHATGPT_USAGE_URL,
|
|
3329
|
-
CHATGPT_PLAN_NOT_ENABLED_MESSAGE,
|
|
3330
3335
|
ChatGPTPlanNotEnabledError,
|
|
3331
3336
|
ChatGPTSignInError,
|
|
3332
3337
|
getChatGPTHostId,
|
|
@@ -3392,4 +3397,4 @@ export {
|
|
|
3392
3397
|
getDefaultThinkingLevel,
|
|
3393
3398
|
getSummaryModel
|
|
3394
3399
|
};
|
|
3395
|
-
//# sourceMappingURL=chunk-
|
|
3400
|
+
//# sourceMappingURL=chunk-BMRRMRUO.js.map
|