happy-imou-cloud 1.1.7 → 2.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/dist/{setupOfflineReconnection-ndObLZk0.mjs → BaseReasoningProcessor-BKLRCKTU.mjs} +133 -90
- package/dist/{setupOfflineReconnection-obypStdD.cjs → BaseReasoningProcessor-BRCQXCZY.cjs} +134 -90
- package/dist/{types-BXyraW9R.mjs → api-BGXYX0yH.mjs} +198 -170
- package/dist/{types-BSTmyv9d.cjs → api-D7OK-mML.cjs} +219 -192
- package/dist/command-CnLtKtP-.mjs +51 -0
- package/dist/command-G85giEAF.cjs +54 -0
- package/dist/future-Dq4Ha1Dn.cjs +24 -0
- package/dist/future-xRdLl3vf.mjs +22 -0
- package/dist/{index-DVI4b0mv.cjs → index-B_wlQBy2.cjs} +5493 -7142
- package/dist/{index-CUmYqKWt.mjs → index-C7Y0R-MI.mjs} +5482 -7143
- package/dist/index.cjs +19 -21
- package/dist/index.mjs +19 -21
- package/dist/lib.cjs +3 -2
- package/dist/lib.d.cts +17 -0
- package/dist/lib.d.mts +17 -0
- package/dist/lib.mjs +2 -1
- package/dist/{persistence-BGsuPqaO.mjs → persistence-BA_unuca.mjs} +8 -4
- package/dist/{persistence-BRH9F6RS.cjs → persistence-DHgf1CTG.cjs} +10 -6
- package/dist/registerKillSessionHandler-C2-yHm1V.mjs +428 -0
- package/dist/registerKillSessionHandler-CLREXN11.cjs +433 -0
- package/dist/runClaude-CwAitpX-.cjs +3274 -0
- package/dist/runClaude-uNC5Eym4.mjs +3271 -0
- package/dist/runCodex-B-05E-YZ.mjs +1846 -0
- package/dist/runCodex-Cm0VTqw_.cjs +1848 -0
- package/dist/{runGemini-C3dDtGOV.cjs → runGemini-CLWjwDYS.cjs} +25 -1366
- package/dist/{runGemini-B-EK_BJQ.mjs → runGemini-_biXvQAH.mjs} +12 -1353
- package/dist/types-CiliQpqS.mjs +52 -0
- package/dist/types-DVk3crez.cjs +54 -0
- package/package.json +13 -12
- package/scripts/devtools/README.md +9 -0
- package/scripts/devtools/generate-mock-credentials.ts +94 -0
- package/scripts/release-smoke.mjs +62 -0
- package/dist/config-BQNrtwRY.cjs +0 -183
- package/dist/config-Dn99YH37.mjs +0 -173
- package/dist/runCodex-Cez8cuIh.cjs +0 -1143
- package/dist/runCodex-X0BfjcZH.mjs +0 -1140
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const UsageSchema = z.object({
|
|
4
|
+
input_tokens: z.number().int().nonnegative(),
|
|
5
|
+
cache_creation_input_tokens: z.number().int().nonnegative().optional(),
|
|
6
|
+
cache_read_input_tokens: z.number().int().nonnegative().optional(),
|
|
7
|
+
output_tokens: z.number().int().nonnegative(),
|
|
8
|
+
service_tier: z.string().optional()
|
|
9
|
+
}).passthrough();
|
|
10
|
+
const RawJSONLinesSchema = z.discriminatedUnion("type", [
|
|
11
|
+
// User message - validates uuid and message.content
|
|
12
|
+
z.object({
|
|
13
|
+
type: z.literal("user"),
|
|
14
|
+
isSidechain: z.boolean().optional(),
|
|
15
|
+
isMeta: z.boolean().optional(),
|
|
16
|
+
uuid: z.string(),
|
|
17
|
+
// Used in getMessageKey()
|
|
18
|
+
message: z.object({
|
|
19
|
+
content: z.union([z.string(), z.any()])
|
|
20
|
+
// Used in sessionScanner.ts
|
|
21
|
+
}).passthrough()
|
|
22
|
+
}).passthrough(),
|
|
23
|
+
// Assistant message - only validates uuid and type
|
|
24
|
+
// message object is optional to handle synthetic error messages (isApiErrorMessage: true)
|
|
25
|
+
// which may have different structure than normal assistant messages
|
|
26
|
+
z.object({
|
|
27
|
+
uuid: z.string(),
|
|
28
|
+
type: z.literal("assistant"),
|
|
29
|
+
message: z.object({
|
|
30
|
+
usage: UsageSchema.optional(),
|
|
31
|
+
// Used in apiSession.ts
|
|
32
|
+
model: z.string().optional()
|
|
33
|
+
// Used for cost calculation
|
|
34
|
+
}).passthrough().optional()
|
|
35
|
+
}).passthrough(),
|
|
36
|
+
// Summary message - validates summary and leafUuid
|
|
37
|
+
z.object({
|
|
38
|
+
type: z.literal("summary"),
|
|
39
|
+
summary: z.string(),
|
|
40
|
+
// Used in apiSession.ts
|
|
41
|
+
leafUuid: z.string()
|
|
42
|
+
// Used in getMessageKey()
|
|
43
|
+
}).passthrough(),
|
|
44
|
+
// System message - validates uuid
|
|
45
|
+
z.object({
|
|
46
|
+
type: z.literal("system"),
|
|
47
|
+
uuid: z.string()
|
|
48
|
+
// Used in getMessageKey()
|
|
49
|
+
}).passthrough()
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export { RawJSONLinesSchema as R };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var z = require('zod');
|
|
4
|
+
|
|
5
|
+
const UsageSchema = z.z.object({
|
|
6
|
+
input_tokens: z.z.number().int().nonnegative(),
|
|
7
|
+
cache_creation_input_tokens: z.z.number().int().nonnegative().optional(),
|
|
8
|
+
cache_read_input_tokens: z.z.number().int().nonnegative().optional(),
|
|
9
|
+
output_tokens: z.z.number().int().nonnegative(),
|
|
10
|
+
service_tier: z.z.string().optional()
|
|
11
|
+
}).passthrough();
|
|
12
|
+
const RawJSONLinesSchema = z.z.discriminatedUnion("type", [
|
|
13
|
+
// User message - validates uuid and message.content
|
|
14
|
+
z.z.object({
|
|
15
|
+
type: z.z.literal("user"),
|
|
16
|
+
isSidechain: z.z.boolean().optional(),
|
|
17
|
+
isMeta: z.z.boolean().optional(),
|
|
18
|
+
uuid: z.z.string(),
|
|
19
|
+
// Used in getMessageKey()
|
|
20
|
+
message: z.z.object({
|
|
21
|
+
content: z.z.union([z.z.string(), z.z.any()])
|
|
22
|
+
// Used in sessionScanner.ts
|
|
23
|
+
}).passthrough()
|
|
24
|
+
}).passthrough(),
|
|
25
|
+
// Assistant message - only validates uuid and type
|
|
26
|
+
// message object is optional to handle synthetic error messages (isApiErrorMessage: true)
|
|
27
|
+
// which may have different structure than normal assistant messages
|
|
28
|
+
z.z.object({
|
|
29
|
+
uuid: z.z.string(),
|
|
30
|
+
type: z.z.literal("assistant"),
|
|
31
|
+
message: z.z.object({
|
|
32
|
+
usage: UsageSchema.optional(),
|
|
33
|
+
// Used in apiSession.ts
|
|
34
|
+
model: z.z.string().optional()
|
|
35
|
+
// Used for cost calculation
|
|
36
|
+
}).passthrough().optional()
|
|
37
|
+
}).passthrough(),
|
|
38
|
+
// Summary message - validates summary and leafUuid
|
|
39
|
+
z.z.object({
|
|
40
|
+
type: z.z.literal("summary"),
|
|
41
|
+
summary: z.z.string(),
|
|
42
|
+
// Used in apiSession.ts
|
|
43
|
+
leafUuid: z.z.string()
|
|
44
|
+
// Used in getMessageKey()
|
|
45
|
+
}).passthrough(),
|
|
46
|
+
// System message - validates uuid
|
|
47
|
+
z.z.object({
|
|
48
|
+
type: z.z.literal("system"),
|
|
49
|
+
uuid: z.z.string()
|
|
50
|
+
// Used in getMessageKey()
|
|
51
|
+
}).passthrough()
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
exports.RawJSONLinesSchema = RawJSONLinesSchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "happy-imou-cloud",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "hicloud - Imou 企业定制版。关键是 happy!移动端远程 AI 编程工具,支持 Claude Code、Codex 和 Gemini CLI",
|
|
5
5
|
"author": "long.zhu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,23 +45,24 @@
|
|
|
45
45
|
"typecheck": "tsc --noEmit",
|
|
46
46
|
"build": "shx rm -rf dist && npx tsc --noEmit && pkgroll",
|
|
47
47
|
"// ==== Testing ====": "",
|
|
48
|
-
"test": "
|
|
49
|
-
"test:integration": "
|
|
48
|
+
"test": "yarn build && vitest run",
|
|
49
|
+
"test:integration": "yarn build && vitest run --config vitest.integration.config.ts",
|
|
50
50
|
"test:integration:watch": "vitest run --config vitest.integration.config.ts --watch",
|
|
51
|
-
"test:coverage": "
|
|
51
|
+
"test:coverage": "yarn build && vitest run --coverage && node scripts/generate-coverage-report.js",
|
|
52
52
|
"// ==== Benchmarks ====": "",
|
|
53
|
-
"bench": "
|
|
54
|
-
"bench:auth": "
|
|
53
|
+
"bench": "yarn build && vitest bench src/daemon/integration/benchmarks/",
|
|
54
|
+
"bench:auth": "yarn build && vitest bench src/daemon/integration/benchmarks/auth.bench.ts",
|
|
55
55
|
"bench:report": "node scripts/generate-benchmark-report.js",
|
|
56
56
|
"// ==== Start & Dev ====": "",
|
|
57
|
-
"start": "
|
|
57
|
+
"start": "yarn build && node ./bin/happy-cloud.mjs",
|
|
58
58
|
"dev": "tsx src/index.ts",
|
|
59
|
-
"dev:local-server": "
|
|
60
|
-
"dev:integration-test-env": "
|
|
59
|
+
"dev:local-server": "yarn build && tsx --env-file .env.dev-local-server src/index.ts",
|
|
60
|
+
"dev:integration-test-env": "yarn build && tsx --env-file .env.integration-test src/index.ts",
|
|
61
61
|
"// ==== Release ====": "",
|
|
62
|
-
"prepublishOnly": "npm run build",
|
|
63
|
-
"release": "
|
|
64
|
-
"
|
|
62
|
+
"prepublishOnly": "npm run build",
|
|
63
|
+
"release": "yarn install && release-it",
|
|
64
|
+
"release:smoke": "node ./scripts/release-smoke.mjs",
|
|
65
|
+
"// ==== Dev/Stable Variant Management ====": "",
|
|
65
66
|
"stable": "node scripts/env-wrapper.cjs stable",
|
|
66
67
|
"dev:variant": "node scripts/env-wrapper.cjs dev",
|
|
67
68
|
"// ==== Stable Version Quick Commands ====": "",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock Credentials Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates a mock access.key file for testing CLI authentication.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* npx tsx scripts/generate-mock-credentials.ts
|
|
8
|
+
*
|
|
9
|
+
* Environment:
|
|
10
|
+
* HAPPY_CLOUD_HOME_DIR - Override default data directory (default: ~/.happy-cloud-dev-test)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import * as crypto from 'crypto';
|
|
16
|
+
|
|
17
|
+
interface AccessKey {
|
|
18
|
+
token: string;
|
|
19
|
+
encryption: {
|
|
20
|
+
publicKey: string; // Base64 encoded
|
|
21
|
+
machineKey: string; // Base64 encoded
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Generate a random Base64 encoded key
|
|
26
|
+
function generateKey(): string {
|
|
27
|
+
return crypto.randomBytes(32).toString('base64');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Generate a mock JWT token (simplified - not for production use)
|
|
31
|
+
function generateTestToken(): string {
|
|
32
|
+
const header = Buffer.from(
|
|
33
|
+
JSON.stringify({
|
|
34
|
+
alg: 'HS256',
|
|
35
|
+
typ: 'JWT',
|
|
36
|
+
})
|
|
37
|
+
).toString('base64url');
|
|
38
|
+
|
|
39
|
+
const payload = Buffer.from(
|
|
40
|
+
JSON.stringify({
|
|
41
|
+
sub: 'test-user',
|
|
42
|
+
iat: Math.floor(Date.now() / 1000),
|
|
43
|
+
exp: Math.floor(Date.now() / 1000) + 86400, // 24 hours
|
|
44
|
+
machineId: 'test-machine',
|
|
45
|
+
iss: 'happy-cloud',
|
|
46
|
+
})
|
|
47
|
+
).toString('base64url');
|
|
48
|
+
|
|
49
|
+
// Simplified signature (placeholder only - not for real verification)
|
|
50
|
+
const signature = crypto.randomBytes(32).toString('base64url');
|
|
51
|
+
|
|
52
|
+
return `${header}.${payload}.${signature}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function main(): Promise<void> {
|
|
56
|
+
const dataDir = process.env.HAPPY_CLOUD_HOME_DIR || path.join(process.env.HOME || process.env.USERPROFILE || '~', '.happy-cloud-dev-test');
|
|
57
|
+
const accessKeyPath = path.join(dataDir, 'access.key');
|
|
58
|
+
|
|
59
|
+
// Ensure data directory exists
|
|
60
|
+
if (!fs.existsSync(dataDir)) {
|
|
61
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
62
|
+
console.log(`📁 Created data directory: ${dataDir}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Generate mock credentials
|
|
66
|
+
const accessKey: AccessKey = {
|
|
67
|
+
token: generateTestToken(),
|
|
68
|
+
encryption: {
|
|
69
|
+
publicKey: generateKey(),
|
|
70
|
+
machineKey: generateKey(),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Write access.key file
|
|
75
|
+
fs.writeFileSync(accessKeyPath, JSON.stringify(accessKey, null, 2), 'utf-8');
|
|
76
|
+
|
|
77
|
+
console.log('');
|
|
78
|
+
console.log('✅ Mock credentials generated successfully!');
|
|
79
|
+
console.log('');
|
|
80
|
+
console.log(`📄 File: ${accessKeyPath}`);
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log('Contents:');
|
|
83
|
+
console.log('---');
|
|
84
|
+
console.log(JSON.stringify(accessKey, null, 2));
|
|
85
|
+
console.log('---');
|
|
86
|
+
console.log('');
|
|
87
|
+
console.log('Note: This is a mock token for testing purposes only.');
|
|
88
|
+
console.log(' It will not pass real server verification.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
main().catch((error) => {
|
|
92
|
+
console.error('Error generating mock credentials:', error);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { dirname, resolve } from 'node:path';
|
|
6
|
+
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const packageRoot = resolve(here, '..');
|
|
9
|
+
|
|
10
|
+
function runStep(name, command, args, options = {}) {
|
|
11
|
+
console.log(`\n[release-smoke] ${name}`);
|
|
12
|
+
console.log(`> ${command} ${args.join(' ')}`);
|
|
13
|
+
|
|
14
|
+
const result = spawnSync(command, args, {
|
|
15
|
+
cwd: packageRoot,
|
|
16
|
+
stdio: 'inherit',
|
|
17
|
+
shell: process.platform === 'win32',
|
|
18
|
+
env: process.env,
|
|
19
|
+
...options,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (result.status !== 0) {
|
|
23
|
+
throw new Error(`[release-smoke] Step failed: ${name}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shouldRunProviderSmoke(provider) {
|
|
28
|
+
return process.env[`HAPPY_SMOKE_${provider.toUpperCase()}`] === '1';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function main() {
|
|
32
|
+
runStep('typecheck', 'yarn', ['tsc', '--noEmit']);
|
|
33
|
+
runStep('unit runtime suite', 'yarn', [
|
|
34
|
+
'vitest',
|
|
35
|
+
'run',
|
|
36
|
+
'src/runtime/executeProvider.test.ts',
|
|
37
|
+
'src/runtime/command.test.ts',
|
|
38
|
+
'src/runtime/launch.test.ts',
|
|
39
|
+
'src/runtime/RuntimeShell.test.ts',
|
|
40
|
+
'src/runtime/createDefaultRuntimeShell.test.ts',
|
|
41
|
+
'src/security/signedTransport.test.ts',
|
|
42
|
+
'src/agent/initializeAgents.test.ts',
|
|
43
|
+
'src/agent/factories/factories.test.ts',
|
|
44
|
+
'src/packageContract.test.ts',
|
|
45
|
+
]);
|
|
46
|
+
runStep('build', 'yarn', ['build']);
|
|
47
|
+
runStep('runtime providers', 'yarn', ['tsx', 'src/index.ts', 'runtime', 'providers']);
|
|
48
|
+
runStep('help', 'yarn', ['tsx', 'src/index.ts', '--help']);
|
|
49
|
+
|
|
50
|
+
if (shouldRunProviderSmoke('cursor')) {
|
|
51
|
+
runStep('cursor smoke', 'yarn', ['tsx', 'src/index.ts', 'cursor', 'release smoke']);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
main();
|
|
57
|
+
console.log('\n[release-smoke] All required steps passed');
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
60
|
+
console.error(`\n${message}`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
package/dist/config-BQNrtwRY.cjs
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var os = require('os');
|
|
6
|
-
var child_process = require('child_process');
|
|
7
|
-
var api = require('./types-BSTmyv9d.cjs');
|
|
8
|
-
|
|
9
|
-
const GEMINI_API_KEY_ENV = "GEMINI_API_KEY";
|
|
10
|
-
const GOOGLE_API_KEY_ENV = "GOOGLE_API_KEY";
|
|
11
|
-
const GEMINI_MODEL_ENV = "GEMINI_MODEL";
|
|
12
|
-
const DEFAULT_GEMINI_MODEL = "gemini-2.5-pro";
|
|
13
|
-
|
|
14
|
-
function readGeminiLocalConfig() {
|
|
15
|
-
let token = null;
|
|
16
|
-
let model = null;
|
|
17
|
-
let googleCloudProject = null;
|
|
18
|
-
let googleCloudProjectEmail = null;
|
|
19
|
-
const possiblePaths = [
|
|
20
|
-
path.join(os.homedir(), ".gemini", "oauth_creds.json"),
|
|
21
|
-
// Main OAuth credentials file
|
|
22
|
-
path.join(os.homedir(), ".gemini", "config.json"),
|
|
23
|
-
path.join(os.homedir(), ".config", "gemini", "config.json"),
|
|
24
|
-
path.join(os.homedir(), ".gemini", "auth.json"),
|
|
25
|
-
path.join(os.homedir(), ".config", "gemini", "auth.json")
|
|
26
|
-
];
|
|
27
|
-
for (const configPath of possiblePaths) {
|
|
28
|
-
if (fs.existsSync(configPath)) {
|
|
29
|
-
try {
|
|
30
|
-
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
31
|
-
if (!token) {
|
|
32
|
-
const foundToken = config.access_token || config.token || config.apiKey || config.GEMINI_API_KEY;
|
|
33
|
-
if (foundToken && typeof foundToken === "string") {
|
|
34
|
-
token = foundToken;
|
|
35
|
-
api.logger.debug(`[Gemini] Found token in ${configPath}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!model) {
|
|
39
|
-
const foundModel = config.model || config.GEMINI_MODEL;
|
|
40
|
-
if (foundModel && typeof foundModel === "string") {
|
|
41
|
-
model = foundModel;
|
|
42
|
-
api.logger.debug(`[Gemini] Found model in ${configPath}: ${model}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!googleCloudProject) {
|
|
46
|
-
const foundProject = config.googleCloudProject || config.google_cloud_project || config.projectId;
|
|
47
|
-
if (foundProject && typeof foundProject === "string") {
|
|
48
|
-
googleCloudProject = foundProject;
|
|
49
|
-
if (config.googleCloudProjectEmail && typeof config.googleCloudProjectEmail === "string") {
|
|
50
|
-
googleCloudProjectEmail = config.googleCloudProjectEmail;
|
|
51
|
-
}
|
|
52
|
-
api.logger.debug(`[Gemini] Found Google Cloud Project in ${configPath}: ${googleCloudProject}${googleCloudProjectEmail ? ` (for ${googleCloudProjectEmail})` : ""}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
api.logger.debug(`[Gemini] Failed to read config from ${configPath}:`, error);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (!token) {
|
|
61
|
-
try {
|
|
62
|
-
const gcloudToken = child_process.execSync("gcloud auth application-default print-access-token", {
|
|
63
|
-
encoding: "utf8",
|
|
64
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
65
|
-
timeout: 5e3
|
|
66
|
-
}).trim();
|
|
67
|
-
if (gcloudToken && gcloudToken.length > 0) {
|
|
68
|
-
token = gcloudToken;
|
|
69
|
-
api.logger.debug("[Gemini] Found token via gcloud Application Default Credentials");
|
|
70
|
-
}
|
|
71
|
-
} catch (error) {
|
|
72
|
-
api.logger.debug("[Gemini] gcloud Application Default Credentials not available");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!googleCloudProject) {
|
|
76
|
-
const envProject = process.env.GOOGLE_CLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT_ID;
|
|
77
|
-
if (envProject) {
|
|
78
|
-
googleCloudProject = envProject;
|
|
79
|
-
googleCloudProjectEmail = null;
|
|
80
|
-
api.logger.debug(`[Gemini] Found Google Cloud Project from env: ${googleCloudProject}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return { token, model, googleCloudProject, googleCloudProjectEmail };
|
|
84
|
-
}
|
|
85
|
-
function determineGeminiModel(explicitModel, localConfig) {
|
|
86
|
-
if (explicitModel !== void 0) {
|
|
87
|
-
if (explicitModel === null) {
|
|
88
|
-
return process.env[GEMINI_MODEL_ENV] || DEFAULT_GEMINI_MODEL;
|
|
89
|
-
} else {
|
|
90
|
-
return explicitModel;
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
const envModel = process.env[GEMINI_MODEL_ENV];
|
|
94
|
-
api.logger.debug(`[Gemini] Model selection: env[GEMINI_MODEL_ENV]=${envModel}, localConfig.model=${localConfig.model}, DEFAULT=${DEFAULT_GEMINI_MODEL}`);
|
|
95
|
-
const model = envModel || localConfig.model || DEFAULT_GEMINI_MODEL;
|
|
96
|
-
api.logger.debug(`[Gemini] Selected model: ${model}`);
|
|
97
|
-
return model;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function saveGeminiModelToConfig(model) {
|
|
101
|
-
try {
|
|
102
|
-
const configDir = path.join(os.homedir(), ".gemini");
|
|
103
|
-
const configPath = path.join(configDir, "config.json");
|
|
104
|
-
if (!fs.existsSync(configDir)) {
|
|
105
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
106
|
-
}
|
|
107
|
-
let config = {};
|
|
108
|
-
if (fs.existsSync(configPath)) {
|
|
109
|
-
try {
|
|
110
|
-
config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
111
|
-
} catch (error) {
|
|
112
|
-
api.logger.debug(`[Gemini] Failed to read existing config, creating new one`);
|
|
113
|
-
config = {};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
config.model = model;
|
|
117
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
118
|
-
api.logger.debug(`[Gemini] Saved model "${model}" to ${configPath}`);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
api.logger.debug(`[Gemini] Failed to save model to config:`, error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function saveGoogleCloudProjectToConfig(projectId, email) {
|
|
124
|
-
try {
|
|
125
|
-
const configDir = path.join(os.homedir(), ".gemini");
|
|
126
|
-
const configPath = path.join(configDir, "config.json");
|
|
127
|
-
if (!fs.existsSync(configDir)) {
|
|
128
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
129
|
-
}
|
|
130
|
-
let config = {};
|
|
131
|
-
if (fs.existsSync(configPath)) {
|
|
132
|
-
try {
|
|
133
|
-
config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
134
|
-
} catch {
|
|
135
|
-
config = {};
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
config.googleCloudProject = projectId;
|
|
139
|
-
if (email) {
|
|
140
|
-
config.googleCloudProjectEmail = email;
|
|
141
|
-
}
|
|
142
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
143
|
-
api.logger.debug(`[Gemini] Saved Google Cloud Project "${projectId}"${email ? ` for ${email}` : ""} to ${configPath}`);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
api.logger.debug(`[Gemini] Failed to save Google Cloud Project to config:`, error);
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function getInitialGeminiModel() {
|
|
150
|
-
const localConfig = readGeminiLocalConfig();
|
|
151
|
-
return process.env[GEMINI_MODEL_ENV] || localConfig.model || DEFAULT_GEMINI_MODEL;
|
|
152
|
-
}
|
|
153
|
-
function getGeminiModelSource(explicitModel, localConfig) {
|
|
154
|
-
if (explicitModel !== void 0 && explicitModel !== null) {
|
|
155
|
-
return "explicit";
|
|
156
|
-
} else if (process.env[GEMINI_MODEL_ENV]) {
|
|
157
|
-
return "env-var";
|
|
158
|
-
} else if (localConfig.model) {
|
|
159
|
-
return "local-config";
|
|
160
|
-
} else {
|
|
161
|
-
return "default";
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
var config = /*#__PURE__*/Object.freeze({
|
|
166
|
-
__proto__: null,
|
|
167
|
-
determineGeminiModel: determineGeminiModel,
|
|
168
|
-
getGeminiModelSource: getGeminiModelSource,
|
|
169
|
-
getInitialGeminiModel: getInitialGeminiModel,
|
|
170
|
-
readGeminiLocalConfig: readGeminiLocalConfig,
|
|
171
|
-
saveGeminiModelToConfig: saveGeminiModelToConfig,
|
|
172
|
-
saveGoogleCloudProjectToConfig: saveGoogleCloudProjectToConfig
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
exports.GEMINI_API_KEY_ENV = GEMINI_API_KEY_ENV;
|
|
176
|
-
exports.GEMINI_MODEL_ENV = GEMINI_MODEL_ENV;
|
|
177
|
-
exports.GOOGLE_API_KEY_ENV = GOOGLE_API_KEY_ENV;
|
|
178
|
-
exports.config = config;
|
|
179
|
-
exports.determineGeminiModel = determineGeminiModel;
|
|
180
|
-
exports.getGeminiModelSource = getGeminiModelSource;
|
|
181
|
-
exports.getInitialGeminiModel = getInitialGeminiModel;
|
|
182
|
-
exports.readGeminiLocalConfig = readGeminiLocalConfig;
|
|
183
|
-
exports.saveGeminiModelToConfig = saveGeminiModelToConfig;
|
package/dist/config-Dn99YH37.mjs
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { homedir } from 'os';
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
import { l as logger } from './types-BXyraW9R.mjs';
|
|
6
|
-
|
|
7
|
-
const GEMINI_API_KEY_ENV = "GEMINI_API_KEY";
|
|
8
|
-
const GOOGLE_API_KEY_ENV = "GOOGLE_API_KEY";
|
|
9
|
-
const GEMINI_MODEL_ENV = "GEMINI_MODEL";
|
|
10
|
-
const DEFAULT_GEMINI_MODEL = "gemini-2.5-pro";
|
|
11
|
-
|
|
12
|
-
function readGeminiLocalConfig() {
|
|
13
|
-
let token = null;
|
|
14
|
-
let model = null;
|
|
15
|
-
let googleCloudProject = null;
|
|
16
|
-
let googleCloudProjectEmail = null;
|
|
17
|
-
const possiblePaths = [
|
|
18
|
-
join(homedir(), ".gemini", "oauth_creds.json"),
|
|
19
|
-
// Main OAuth credentials file
|
|
20
|
-
join(homedir(), ".gemini", "config.json"),
|
|
21
|
-
join(homedir(), ".config", "gemini", "config.json"),
|
|
22
|
-
join(homedir(), ".gemini", "auth.json"),
|
|
23
|
-
join(homedir(), ".config", "gemini", "auth.json")
|
|
24
|
-
];
|
|
25
|
-
for (const configPath of possiblePaths) {
|
|
26
|
-
if (existsSync(configPath)) {
|
|
27
|
-
try {
|
|
28
|
-
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
29
|
-
if (!token) {
|
|
30
|
-
const foundToken = config.access_token || config.token || config.apiKey || config.GEMINI_API_KEY;
|
|
31
|
-
if (foundToken && typeof foundToken === "string") {
|
|
32
|
-
token = foundToken;
|
|
33
|
-
logger.debug(`[Gemini] Found token in ${configPath}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (!model) {
|
|
37
|
-
const foundModel = config.model || config.GEMINI_MODEL;
|
|
38
|
-
if (foundModel && typeof foundModel === "string") {
|
|
39
|
-
model = foundModel;
|
|
40
|
-
logger.debug(`[Gemini] Found model in ${configPath}: ${model}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (!googleCloudProject) {
|
|
44
|
-
const foundProject = config.googleCloudProject || config.google_cloud_project || config.projectId;
|
|
45
|
-
if (foundProject && typeof foundProject === "string") {
|
|
46
|
-
googleCloudProject = foundProject;
|
|
47
|
-
if (config.googleCloudProjectEmail && typeof config.googleCloudProjectEmail === "string") {
|
|
48
|
-
googleCloudProjectEmail = config.googleCloudProjectEmail;
|
|
49
|
-
}
|
|
50
|
-
logger.debug(`[Gemini] Found Google Cloud Project in ${configPath}: ${googleCloudProject}${googleCloudProjectEmail ? ` (for ${googleCloudProjectEmail})` : ""}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} catch (error) {
|
|
54
|
-
logger.debug(`[Gemini] Failed to read config from ${configPath}:`, error);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!token) {
|
|
59
|
-
try {
|
|
60
|
-
const gcloudToken = execSync("gcloud auth application-default print-access-token", {
|
|
61
|
-
encoding: "utf8",
|
|
62
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
63
|
-
timeout: 5e3
|
|
64
|
-
}).trim();
|
|
65
|
-
if (gcloudToken && gcloudToken.length > 0) {
|
|
66
|
-
token = gcloudToken;
|
|
67
|
-
logger.debug("[Gemini] Found token via gcloud Application Default Credentials");
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
logger.debug("[Gemini] gcloud Application Default Credentials not available");
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (!googleCloudProject) {
|
|
74
|
-
const envProject = process.env.GOOGLE_CLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT_ID;
|
|
75
|
-
if (envProject) {
|
|
76
|
-
googleCloudProject = envProject;
|
|
77
|
-
googleCloudProjectEmail = null;
|
|
78
|
-
logger.debug(`[Gemini] Found Google Cloud Project from env: ${googleCloudProject}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return { token, model, googleCloudProject, googleCloudProjectEmail };
|
|
82
|
-
}
|
|
83
|
-
function determineGeminiModel(explicitModel, localConfig) {
|
|
84
|
-
if (explicitModel !== void 0) {
|
|
85
|
-
if (explicitModel === null) {
|
|
86
|
-
return process.env[GEMINI_MODEL_ENV] || DEFAULT_GEMINI_MODEL;
|
|
87
|
-
} else {
|
|
88
|
-
return explicitModel;
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
const envModel = process.env[GEMINI_MODEL_ENV];
|
|
92
|
-
logger.debug(`[Gemini] Model selection: env[GEMINI_MODEL_ENV]=${envModel}, localConfig.model=${localConfig.model}, DEFAULT=${DEFAULT_GEMINI_MODEL}`);
|
|
93
|
-
const model = envModel || localConfig.model || DEFAULT_GEMINI_MODEL;
|
|
94
|
-
logger.debug(`[Gemini] Selected model: ${model}`);
|
|
95
|
-
return model;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function saveGeminiModelToConfig(model) {
|
|
99
|
-
try {
|
|
100
|
-
const configDir = join(homedir(), ".gemini");
|
|
101
|
-
const configPath = join(configDir, "config.json");
|
|
102
|
-
if (!existsSync(configDir)) {
|
|
103
|
-
mkdirSync(configDir, { recursive: true });
|
|
104
|
-
}
|
|
105
|
-
let config = {};
|
|
106
|
-
if (existsSync(configPath)) {
|
|
107
|
-
try {
|
|
108
|
-
config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
109
|
-
} catch (error) {
|
|
110
|
-
logger.debug(`[Gemini] Failed to read existing config, creating new one`);
|
|
111
|
-
config = {};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
config.model = model;
|
|
115
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
116
|
-
logger.debug(`[Gemini] Saved model "${model}" to ${configPath}`);
|
|
117
|
-
} catch (error) {
|
|
118
|
-
logger.debug(`[Gemini] Failed to save model to config:`, error);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function saveGoogleCloudProjectToConfig(projectId, email) {
|
|
122
|
-
try {
|
|
123
|
-
const configDir = join(homedir(), ".gemini");
|
|
124
|
-
const configPath = join(configDir, "config.json");
|
|
125
|
-
if (!existsSync(configDir)) {
|
|
126
|
-
mkdirSync(configDir, { recursive: true });
|
|
127
|
-
}
|
|
128
|
-
let config = {};
|
|
129
|
-
if (existsSync(configPath)) {
|
|
130
|
-
try {
|
|
131
|
-
config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
132
|
-
} catch {
|
|
133
|
-
config = {};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
config.googleCloudProject = projectId;
|
|
137
|
-
if (email) {
|
|
138
|
-
config.googleCloudProjectEmail = email;
|
|
139
|
-
}
|
|
140
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
141
|
-
logger.debug(`[Gemini] Saved Google Cloud Project "${projectId}"${email ? ` for ${email}` : ""} to ${configPath}`);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
logger.debug(`[Gemini] Failed to save Google Cloud Project to config:`, error);
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function getInitialGeminiModel() {
|
|
148
|
-
const localConfig = readGeminiLocalConfig();
|
|
149
|
-
return process.env[GEMINI_MODEL_ENV] || localConfig.model || DEFAULT_GEMINI_MODEL;
|
|
150
|
-
}
|
|
151
|
-
function getGeminiModelSource(explicitModel, localConfig) {
|
|
152
|
-
if (explicitModel !== void 0 && explicitModel !== null) {
|
|
153
|
-
return "explicit";
|
|
154
|
-
} else if (process.env[GEMINI_MODEL_ENV]) {
|
|
155
|
-
return "env-var";
|
|
156
|
-
} else if (localConfig.model) {
|
|
157
|
-
return "local-config";
|
|
158
|
-
} else {
|
|
159
|
-
return "default";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var config = /*#__PURE__*/Object.freeze({
|
|
164
|
-
__proto__: null,
|
|
165
|
-
determineGeminiModel: determineGeminiModel,
|
|
166
|
-
getGeminiModelSource: getGeminiModelSource,
|
|
167
|
-
getInitialGeminiModel: getInitialGeminiModel,
|
|
168
|
-
readGeminiLocalConfig: readGeminiLocalConfig,
|
|
169
|
-
saveGeminiModelToConfig: saveGeminiModelToConfig,
|
|
170
|
-
saveGoogleCloudProjectToConfig: saveGoogleCloudProjectToConfig
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
export { GEMINI_API_KEY_ENV as G, GOOGLE_API_KEY_ENV as a, GEMINI_MODEL_ENV as b, getInitialGeminiModel as c, determineGeminiModel as d, config as e, getGeminiModelSource as g, readGeminiLocalConfig as r, saveGeminiModelToConfig as s };
|