tuna-agent 0.1.158 → 0.1.159
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/daemon/index.d.ts +1 -0
- package/dist/daemon/index.js +4 -11
- package/dist/daemon/load-env.d.ts +1 -0
- package/dist/daemon/load-env.js +28 -0
- package/package.json +1 -1
package/dist/daemon/index.d.ts
CHANGED
package/dist/daemon/index.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
+
// ⚠ MUST be first: side-effect import that populates process.env from
|
|
2
|
+
// ~/.tuna-agent/.env BEFORE any other module captures env at its top
|
|
3
|
+
// level. See load-env.ts for the long-form explanation.
|
|
4
|
+
import './load-env.js';
|
|
1
5
|
import fs from 'fs';
|
|
2
6
|
import path from 'path';
|
|
3
7
|
import os from 'os';
|
|
4
|
-
// Load .env from ~/.tuna-agent/.env if exists (ensure OPENAI_API_KEY etc. available)
|
|
5
|
-
const envPath = path.join(os.homedir(), '.tuna-agent', '.env');
|
|
6
|
-
if (fs.existsSync(envPath)) {
|
|
7
|
-
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
8
|
-
for (const line of envContent.split('\n')) {
|
|
9
|
-
const match = line.match(/^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
10
|
-
if (match && !process.env[match[1]]) {
|
|
11
|
-
process.env[match[1]] = match[2].replace(/^["']|["']$/g, '');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
8
|
import { AgentWebSocketClient } from './ws-client.js';
|
|
16
9
|
import { removePid, loadConfig, saveConfig } from '../config/store.js';
|
|
17
10
|
import { validateMessage } from '../utils/message-schemas.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Side-effect module: load ~/.tuna-agent/.env into process.env BEFORE any
|
|
2
|
+
// other daemon module reads process.env at its top level.
|
|
3
|
+
//
|
|
4
|
+
// daemon/index.ts must import this FIRST so the side-effect runs before
|
|
5
|
+
// modules like analyze-video-handler.ts capture `process.env.OPENAI_API_KEY`
|
|
6
|
+
// into a module-top const. ESM imports execute in dependency order, so
|
|
7
|
+
// putting this import line above the analyze-video-handler import (directly
|
|
8
|
+
// or transitively) guarantees the env is populated when those consts are
|
|
9
|
+
// evaluated.
|
|
10
|
+
//
|
|
11
|
+
// Previously the env loader lived inline in daemon/index.ts AFTER the
|
|
12
|
+
// imports — but ES module imports are processed BEFORE any executable code
|
|
13
|
+
// in the file, so analyze-video-handler captured OPENAI_API_KEY='' and the
|
|
14
|
+
// analyze flow died with 'OPENAI_API_KEY not set' even though the .env
|
|
15
|
+
// file was correct.
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import os from 'os';
|
|
19
|
+
const envPath = path.join(os.homedir(), '.tuna-agent', '.env');
|
|
20
|
+
if (fs.existsSync(envPath)) {
|
|
21
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
22
|
+
for (const line of envContent.split('\n')) {
|
|
23
|
+
const match = line.match(/^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
24
|
+
if (match && !process.env[match[1]]) {
|
|
25
|
+
process.env[match[1]] = match[2].replace(/^["']|["']$/g, '');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|