@asframe/opencode-iflow-auth 1.0.2 → 1.0.4
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 +2 -2
- package/dist/iflow/proxy.js +5 -4
- package/dist/plugin-proxy.js +39 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -250,8 +250,8 @@ Edit `~/.config/opencode/iflow.json`:
|
|
|
250
250
|
|----------|-------------|
|
|
251
251
|
| `IFLOW_AUTH_DEBUG` | Enable debug logging for auth plugin (`true`/`false`) |
|
|
252
252
|
| `IFLOW_PROXY_DEBUG` | Enable debug logging for proxy plugin (`true`/`false`) |
|
|
253
|
-
| `IFLOW_AUTO_INSTALL_CLI` | Auto-install iflow CLI if not installed (`true
|
|
254
|
-
| `IFLOW_AUTO_LOGIN` | Auto-trigger iflow login if not logged in (`true
|
|
253
|
+
| `IFLOW_AUTO_INSTALL_CLI` | Auto-install iflow CLI if not installed (default: `true`, set `false` to disable) |
|
|
254
|
+
| `IFLOW_AUTO_LOGIN` | Auto-trigger iflow login if not logged in (default: `true`, set `false` to disable) |
|
|
255
255
|
| `IFLOW_DEFAULT_AUTH_METHOD` | Override default auth method |
|
|
256
256
|
| `IFLOW_ACCOUNT_SELECTION_STRATEGY` | Override account selection strategy |
|
|
257
257
|
| `IFLOW_AUTH_SERVER_PORT_START` | Override OAuth server port |
|
package/dist/iflow/proxy.js
CHANGED
|
@@ -6,7 +6,8 @@ const IFLOW_PROXY_HOST = '127.0.0.1';
|
|
|
6
6
|
const IFLOW_API_BASE = 'https://apis.iflow.cn';
|
|
7
7
|
const CLI_REQUIRED_MODELS = ['glm-5', 'glm-5-free', 'glm-5-thinking'];
|
|
8
8
|
const DEBUG = process.env.IFLOW_PROXY_DEBUG === 'true';
|
|
9
|
-
const AUTO_INSTALL_CLI = process.env.IFLOW_AUTO_INSTALL_CLI
|
|
9
|
+
const AUTO_INSTALL_CLI = process.env.IFLOW_AUTO_INSTALL_CLI !== 'false';
|
|
10
|
+
const AUTO_LOGIN = process.env.IFLOW_AUTO_LOGIN !== 'false';
|
|
10
11
|
function log(...args) {
|
|
11
12
|
if (DEBUG) {
|
|
12
13
|
console.error('[IFlowProxy]', ...args);
|
|
@@ -140,10 +141,10 @@ export class IFlowCLIProxy {
|
|
|
140
141
|
console.error('[IFlowProxy]');
|
|
141
142
|
console.error('[IFlowProxy] iflow login');
|
|
142
143
|
console.error('[IFlowProxy]');
|
|
143
|
-
console.error('[IFlowProxy] Or set IFLOW_AUTO_LOGIN=
|
|
144
|
+
console.error('[IFlowProxy] Or set IFLOW_AUTO_LOGIN=false to disable auto-login');
|
|
144
145
|
console.error('[IFlowProxy] ══════════════════════════════════════════════════════════');
|
|
145
146
|
console.error('');
|
|
146
|
-
if (
|
|
147
|
+
if (AUTO_LOGIN) {
|
|
147
148
|
const loginResult = await triggerIFlowLogin();
|
|
148
149
|
if (loginResult.success) {
|
|
149
150
|
this.cliLoggedIn = true;
|
|
@@ -165,7 +166,7 @@ export class IFlowCLIProxy {
|
|
|
165
166
|
console.error('[IFlowProxy] npm install -g iflow-cli');
|
|
166
167
|
console.error('[IFlowProxy] iflow login');
|
|
167
168
|
console.error('[IFlowProxy]');
|
|
168
|
-
console.error('[IFlowProxy] Or set IFLOW_AUTO_INSTALL_CLI=
|
|
169
|
+
console.error('[IFlowProxy] Or set IFLOW_AUTO_INSTALL_CLI=false to disable auto-install');
|
|
169
170
|
console.error('[IFlowProxy] ══════════════════════════════════════════════════════════');
|
|
170
171
|
console.error('');
|
|
171
172
|
}
|
package/dist/plugin-proxy.js
CHANGED
|
@@ -3,10 +3,11 @@ import { AccountManager, generateAccountId } from "./plugin/accounts.js";
|
|
|
3
3
|
import { authorizeIFlowOAuth } from "./iflow/oauth.js";
|
|
4
4
|
import { validateApiKey } from "./iflow/apikey.js";
|
|
5
5
|
import { startOAuthServer } from "./plugin/server.js";
|
|
6
|
-
import { startProxy } from "./iflow/proxy.js";
|
|
6
|
+
import { startProxy, getProxyInstance } from "./iflow/proxy.js";
|
|
7
7
|
import { promptApiKey, promptEmail, } from "./plugin/cli.js";
|
|
8
8
|
import { IFLOW_CONSTANTS, registerIFlowModels } from "./constants.js";
|
|
9
9
|
const DEBUG = process.env.IFLOW_PROXY_DEBUG === 'true';
|
|
10
|
+
const AUTO_START_PROXY = process.env.IFLOW_AUTO_START_PROXY !== 'false';
|
|
10
11
|
function log(...args) {
|
|
11
12
|
if (DEBUG) {
|
|
12
13
|
console.error('[iflow-proxy]', ...args);
|
|
@@ -20,11 +21,25 @@ const openBrowser = (url) => {
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
};
|
|
24
|
+
let proxyStarted = false;
|
|
25
|
+
async function ensureProxyStarted() {
|
|
26
|
+
if (!proxyStarted) {
|
|
27
|
+
if (AUTO_START_PROXY) {
|
|
28
|
+
log('Starting CLI proxy...');
|
|
29
|
+
const proxy = await startProxy();
|
|
30
|
+
proxyStarted = true;
|
|
31
|
+
log('CLI proxy started at:', proxy.getBaseUrl());
|
|
32
|
+
return proxy.getBaseUrl();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return getProxyInstance().getBaseUrl();
|
|
36
|
+
}
|
|
23
37
|
export const IFlowProxyPlugin = async (input) => {
|
|
24
38
|
const config = loadConfig();
|
|
25
39
|
const showToast = (message, variant) => {
|
|
26
40
|
input.client.tui.showToast({ body: { message, variant } }).catch(() => { });
|
|
27
41
|
};
|
|
42
|
+
await ensureProxyStarted();
|
|
28
43
|
return {
|
|
29
44
|
auth: {
|
|
30
45
|
provider: "iflow-proxy",
|
|
@@ -35,34 +50,39 @@ export const IFlowProxyPlugin = async (input) => {
|
|
|
35
50
|
const am = await AccountManager.loadFromDisk(config.account_selection_strategy);
|
|
36
51
|
log('account count:', am.getAccountCount());
|
|
37
52
|
registerIFlowModels(provider);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
const proxyUrl = getProxyInstance().getBaseUrl();
|
|
54
|
+
const proxy = getProxyInstance();
|
|
55
|
+
if (!proxy.isCLIAvailable()) {
|
|
56
|
+
log('CLI not available, returning error');
|
|
57
|
+
showToast('iflow CLI is not available. Please install: npm install -g iflow-cli', 'error');
|
|
41
58
|
return {};
|
|
42
59
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
if (!proxy.isCLILoggedIn()) {
|
|
61
|
+
log('CLI not logged in, returning error');
|
|
62
|
+
showToast('iflow CLI is not logged in. Please run: iflow login', 'error');
|
|
46
63
|
return {};
|
|
47
64
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
log('
|
|
51
|
-
const proxy = await startProxy();
|
|
52
|
-
const proxyUrl = proxy.getBaseUrl();
|
|
53
|
-
log('CLI proxy started at:', proxyUrl);
|
|
65
|
+
const accountCount = am.getAccountCount();
|
|
66
|
+
if (accountCount === 0) {
|
|
67
|
+
log('No accounts found, using CLI auth directly');
|
|
54
68
|
return {
|
|
55
|
-
apiKey:
|
|
69
|
+
apiKey: 'cli-auth',
|
|
56
70
|
baseURL: proxyUrl,
|
|
57
71
|
};
|
|
58
72
|
}
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
const firstAccount = am.getCurrentOrNext();
|
|
74
|
+
if (!firstAccount) {
|
|
75
|
+
log('No available account');
|
|
61
76
|
return {
|
|
62
|
-
apiKey:
|
|
63
|
-
baseURL:
|
|
77
|
+
apiKey: 'cli-auth',
|
|
78
|
+
baseURL: proxyUrl,
|
|
64
79
|
};
|
|
65
80
|
}
|
|
81
|
+
log('Using account:', firstAccount.email, 'apiKey:', firstAccount.apiKey.substring(0, 10) + '...');
|
|
82
|
+
return {
|
|
83
|
+
apiKey: firstAccount.apiKey,
|
|
84
|
+
baseURL: proxyUrl,
|
|
85
|
+
};
|
|
66
86
|
},
|
|
67
87
|
methods: [
|
|
68
88
|
{
|
|
@@ -109,7 +129,7 @@ export const IFlowProxyPlugin = async (input) => {
|
|
|
109
129
|
url: "",
|
|
110
130
|
instructions: "Authorization failed",
|
|
111
131
|
method: "auto",
|
|
112
|
-
callback: async () => ({ type: "failed" })
|
|
132
|
+
callback: async () => ({ type: "failed" })
|
|
113
133
|
});
|
|
114
134
|
}
|
|
115
135
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asframe/opencode-iflow-auth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "OpenCode plugin for iFlow.cn - Access Qwen, DeepSeek, Kimi, GLM-5 models with OAuth 2.0, API Key, and CLI Proxy support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|