@asframe/opencode-iflow-auth 1.0.4 → 1.0.6

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.
@@ -13,7 +13,7 @@ export declare const IFLOW_CONSTANTS: {
13
13
  CALLBACK_PORT_START: number;
14
14
  CALLBACK_PORT_RANGE: number;
15
15
  };
16
- export declare const THINKING_MODELS: string[];
16
+ export declare const THINKING_MODEL_PATTERNS: RegExp[];
17
17
  export declare function isThinkingModel(model: string): boolean;
18
18
  export declare function applyThinkingConfig(body: any, model: string): any;
19
19
  export interface IFlowModelConfig {
package/dist/constants.js CHANGED
@@ -14,9 +14,19 @@ export const IFLOW_CONSTANTS = {
14
14
  CALLBACK_PORT_START: 8087,
15
15
  CALLBACK_PORT_RANGE: 10
16
16
  };
17
- export const THINKING_MODELS = ['glm-4.6', 'glm-5', 'qwen3-235b-a22b-thinking-2507', 'deepseek-r1'];
17
+ export const THINKING_MODEL_PATTERNS = [
18
+ /^glm-5/,
19
+ /^glm-4\.7/,
20
+ /^glm-4\.6/,
21
+ /^glm-4/,
22
+ /deepseek/,
23
+ /thinking/,
24
+ /reasoning/,
25
+ /^kimi-k2\.5/,
26
+ /^o1-/
27
+ ];
18
28
  export function isThinkingModel(model) {
19
- return THINKING_MODELS.some((m) => model.startsWith(m));
29
+ return THINKING_MODEL_PATTERNS.some(pattern => pattern.test(model));
20
30
  }
21
31
  export function applyThinkingConfig(body, model) {
22
32
  const thinkingBudget = body.providerOptions?.thinkingConfig?.thinkingBudget;
@@ -1,6 +1,9 @@
1
- import { spawn, execSync, exec } from 'child_process';
1
+ import { spawn, execSync } from 'child_process';
2
2
  import { createServer } from 'http';
3
3
  import { randomUUID } from 'crypto';
4
+ import { existsSync, readFileSync } from 'fs';
5
+ import { homedir } from 'os';
6
+ import { join } from 'path';
4
7
  const IFLOW_PROXY_PORT = 19998;
5
8
  const IFLOW_PROXY_HOST = '127.0.0.1';
6
9
  const IFLOW_API_BASE = 'https://apis.iflow.cn';
@@ -13,6 +16,12 @@ function log(...args) {
13
16
  console.error('[IFlowProxy]', ...args);
14
17
  }
15
18
  }
19
+ function getIFlowConfigPath() {
20
+ return join(homedir(), '.iflow');
21
+ }
22
+ function getIFlowOAuthCredsPath() {
23
+ return join(getIFlowConfigPath(), 'oauth_creds.json');
24
+ }
16
25
  function requiresCLI(model) {
17
26
  return CLI_REQUIRED_MODELS.some(m => model.includes(m));
18
27
  }
@@ -30,25 +39,27 @@ function checkIFlowCLI() {
30
39
  }
31
40
  }
32
41
  function checkIFlowLogin() {
33
- return new Promise((resolve) => {
34
- try {
35
- exec('iflow whoami', { timeout: 5000 }, (error, stdout, stderr) => {
36
- if (error) {
37
- resolve({ loggedIn: false, error: error.message });
38
- return;
39
- }
40
- const output = stdout + stderr;
41
- if (output.includes('Invalid token') || output.includes('not logged in') || output.includes('Please login')) {
42
- resolve({ loggedIn: false, error: 'Not logged in' });
43
- return;
44
- }
45
- resolve({ loggedIn: true });
46
- });
42
+ try {
43
+ const oauthCredsPath = getIFlowOAuthCredsPath();
44
+ if (!existsSync(oauthCredsPath)) {
45
+ log('OAuth creds file not found:', oauthCredsPath);
46
+ return { loggedIn: false, error: 'Not logged in - no oauth_creds.json' };
47
47
  }
48
- catch (error) {
49
- resolve({ loggedIn: false, error: error.message });
48
+ const credsContent = readFileSync(oauthCredsPath, 'utf-8');
49
+ const creds = JSON.parse(credsContent);
50
+ if (!creds.access_token && !creds.apiKey) {
51
+ return { loggedIn: false, error: 'Not logged in - no token' };
50
52
  }
51
- });
53
+ if (creds.expiry_date && Date.now() > creds.expiry_date) {
54
+ return { loggedIn: false, error: 'Token expired' };
55
+ }
56
+ log('iflow CLI is logged in:', creds.userName || creds.userId);
57
+ return { loggedIn: true, apiKey: creds.apiKey };
58
+ }
59
+ catch (error) {
60
+ log('Error checking iflow login:', error.message);
61
+ return { loggedIn: false, error: error.message };
62
+ }
52
63
  }
53
64
  async function triggerIFlowLogin() {
54
65
  log('Triggering iflow login...');
@@ -130,7 +141,7 @@ export class IFlowCLIProxy {
130
141
  this.cliAvailable = cliCheck.installed;
131
142
  this.cliChecked = true;
132
143
  if (cliCheck.installed) {
133
- const loginCheck = await checkIFlowLogin();
144
+ const loginCheck = checkIFlowLogin();
134
145
  this.cliLoggedIn = loginCheck.loggedIn;
135
146
  if (!loginCheck.loggedIn) {
136
147
  console.error('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asframe/opencode-iflow-auth",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",