opc-agent 4.0.5 → 4.0.7

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.
@@ -19,6 +19,7 @@ export declare class AgentRuntime {
19
19
  private evolveScheduler;
20
20
  loadConfig(filePath: string): Promise<OADDocument>;
21
21
  setHistoryLimit(limit: number): void;
22
+ private loadDotEnv;
22
23
  initialize(config?: OADDocument): Promise<BaseAgent>;
23
24
  start(): Promise<void>;
24
25
  stop(): Promise<void>;
@@ -80,7 +80,33 @@ class AgentRuntime {
80
80
  setHistoryLimit(limit) {
81
81
  this.historyLimit = limit;
82
82
  }
83
+ loadDotEnv() {
84
+ const fs = require('fs');
85
+ const path = require('path');
86
+ const envPath = path.resolve('.env');
87
+ if (!fs.existsSync(envPath))
88
+ return;
89
+ try {
90
+ const content = fs.readFileSync(envPath, 'utf-8');
91
+ for (const line of content.split('\n')) {
92
+ const trimmed = line.trim();
93
+ if (!trimmed || trimmed.startsWith('#'))
94
+ continue;
95
+ const eqIdx = trimmed.indexOf('=');
96
+ if (eqIdx === -1)
97
+ continue;
98
+ const key = trimmed.slice(0, eqIdx).trim();
99
+ const value = trimmed.slice(eqIdx + 1).trim();
100
+ if (!process.env[key]) {
101
+ process.env[key] = value;
102
+ }
103
+ }
104
+ }
105
+ catch { /* ignore */ }
106
+ }
83
107
  async initialize(config) {
108
+ // Auto-load .env file if present
109
+ this.loadDotEnv();
84
110
  const cfg = config ?? this.config;
85
111
  if (!cfg)
86
112
  throw new Error('No config loaded. Call loadConfig() first.');
@@ -434,7 +434,7 @@ function createProvider(name = 'openai', model, baseUrl, apiKey) {
434
434
  else if (finalBaseUrl.includes('dashscope.aliyuncs.com')) {
435
435
  resolvedName = 'qwen';
436
436
  }
437
- return new OpenAICompatibleProvider(resolvedName, finalModel, baseUrl, apiKey);
437
+ return new OpenAICompatibleProvider(resolvedName, finalModel, finalBaseUrl, finalKey);
438
438
  }
439
439
  exports.SUPPORTED_PROVIDERS = ['openai', 'ollama', 'claude-cli', 'deepseek', 'qwen', 'gemini', 'dashscope', 'zhipu', 'moonshot'];
440
440
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opc-agent",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "Open Agent Framework — Build, test, and run AI Agents for business workstations",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,7 +53,31 @@ export class AgentRuntime {
53
53
  this.historyLimit = limit;
54
54
  }
55
55
 
56
+ private loadDotEnv(): void {
57
+ const fs = require('fs');
58
+ const path = require('path');
59
+ const envPath = path.resolve('.env');
60
+ if (!fs.existsSync(envPath)) return;
61
+ try {
62
+ const content = fs.readFileSync(envPath, 'utf-8');
63
+ for (const line of content.split('\n')) {
64
+ const trimmed = line.trim();
65
+ if (!trimmed || trimmed.startsWith('#')) continue;
66
+ const eqIdx = trimmed.indexOf('=');
67
+ if (eqIdx === -1) continue;
68
+ const key = trimmed.slice(0, eqIdx).trim();
69
+ const value = trimmed.slice(eqIdx + 1).trim();
70
+ if (!process.env[key]) {
71
+ process.env[key] = value;
72
+ }
73
+ }
74
+ } catch { /* ignore */ }
75
+ }
76
+
56
77
  async initialize(config?: OADDocument): Promise<BaseAgent> {
78
+ // Auto-load .env file if present
79
+ this.loadDotEnv();
80
+
57
81
  const cfg = config ?? this.config;
58
82
  if (!cfg) throw new Error('No config loaded. Call loadConfig() first.');
59
83
 
@@ -444,7 +444,7 @@ export function createProvider(name: string = 'openai', model?: string, baseUrl?
444
444
  resolvedName = 'qwen';
445
445
  }
446
446
 
447
- return new OpenAICompatibleProvider(resolvedName, finalModel, baseUrl, apiKey);
447
+ return new OpenAICompatibleProvider(resolvedName, finalModel, finalBaseUrl, finalKey);
448
448
  }
449
449
 
450
450
  export const SUPPORTED_PROVIDERS = ['openai', 'ollama', 'claude-cli', 'deepseek', 'qwen', 'gemini', 'dashscope', 'zhipu', 'moonshot'] as const;