@siduri-x/brain 2.0.0 → 2.0.1
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/index.d.ts +5 -2
- package/dist/index.js +13 -2
- package/organ-manifest.json +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BrainOrgan, BrainContext, ResponsePlan } from '@siduri-x/core';
|
|
2
2
|
export interface OpenAICompatibleBrainConfig {
|
|
3
|
-
apiKey
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
apiKeyEnv?: string;
|
|
4
5
|
model: string;
|
|
5
6
|
baseUrl: string;
|
|
6
7
|
timeoutMs?: number;
|
|
@@ -9,7 +10,8 @@ export interface OpenAICompatibleBrainConfig {
|
|
|
9
10
|
maxBackoffMs?: number;
|
|
10
11
|
}
|
|
11
12
|
export interface OpenRouterBrainConfig {
|
|
12
|
-
apiKey
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
apiKeyEnv?: string;
|
|
13
15
|
model: string;
|
|
14
16
|
timeoutMs?: number;
|
|
15
17
|
maxRetries?: number;
|
|
@@ -19,6 +21,7 @@ export interface OpenRouterBrainConfig {
|
|
|
19
21
|
export declare class OpenAICompatibleBrain implements BrainOrgan {
|
|
20
22
|
private config;
|
|
21
23
|
private assembler;
|
|
24
|
+
protected resolvedApiKey: string;
|
|
22
25
|
constructor(config: OpenAICompatibleBrainConfig);
|
|
23
26
|
generatePlan(context: BrainContext): Promise<ResponsePlan>;
|
|
24
27
|
}
|
package/dist/index.js
CHANGED
|
@@ -44,9 +44,18 @@ const ResponsePlanSchema = zod_1.z.object({
|
|
|
44
44
|
class OpenAICompatibleBrain {
|
|
45
45
|
config;
|
|
46
46
|
assembler;
|
|
47
|
+
resolvedApiKey;
|
|
47
48
|
constructor(config) {
|
|
48
49
|
this.config = config;
|
|
49
50
|
this.assembler = new prompt_1.PromptAssembler();
|
|
51
|
+
const defaultEnv = config.baseUrl && !config.baseUrl.includes('openrouter.ai')
|
|
52
|
+
? 'OPENAI_COMPATIBLE_API_KEY'
|
|
53
|
+
: 'OPENROUTER_API_KEY';
|
|
54
|
+
const envKey = config.apiKeyEnv || defaultEnv;
|
|
55
|
+
this.resolvedApiKey = config.apiKey || (typeof process !== 'undefined' && process.env ? (process.env[envKey] || '') : '') || '';
|
|
56
|
+
if (!this.config.apiKey && this.resolvedApiKey) {
|
|
57
|
+
this.config = { ...this.config, apiKey: this.resolvedApiKey };
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
60
|
async generatePlan(context) {
|
|
52
61
|
const { messages } = this.assembler.assemble(context);
|
|
@@ -125,7 +134,7 @@ class OpenAICompatibleBrain {
|
|
|
125
134
|
const response = await fetch(`${this.config.baseUrl.replace(/\/+$/, '')}/chat/completions`, {
|
|
126
135
|
method: "POST",
|
|
127
136
|
headers: {
|
|
128
|
-
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
137
|
+
"Authorization": `Bearer ${this.resolvedApiKey || this.config.apiKey}`,
|
|
129
138
|
"Content-Type": "application/json",
|
|
130
139
|
},
|
|
131
140
|
body: JSON.stringify({
|
|
@@ -196,7 +205,9 @@ class OpenAICompatibleBrain {
|
|
|
196
205
|
exports.OpenAICompatibleBrain = OpenAICompatibleBrain;
|
|
197
206
|
class OpenRouterBrain extends OpenAICompatibleBrain {
|
|
198
207
|
constructor(config) {
|
|
199
|
-
|
|
208
|
+
const apiKeyEnv = config.apiKeyEnv || 'OPENROUTER_API_KEY';
|
|
209
|
+
const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env ? (process.env[apiKeyEnv] || process.env.OPENROUTER_API_KEY || '') : '') || '';
|
|
210
|
+
super({ ...config, baseUrl: 'https://openrouter.ai/api/v1', apiKey, apiKeyEnv });
|
|
200
211
|
}
|
|
201
212
|
}
|
|
202
213
|
exports.OpenRouterBrain = OpenRouterBrain;
|
package/organ-manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siduri-x/brain",
|
|
3
3
|
"organType": "brain",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"displayName": "Brain (Cognition & Planning)",
|
|
6
6
|
"description": "Provider-neutral LLM reasoning, response planning, and proposal generation",
|
|
7
7
|
"entrypoint": "./dist/index.js",
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siduri-x/brain",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"zod": "^4.
|
|
8
|
-
"@siduri-x/core": "2.0.
|
|
7
|
+
"zod": "^4.6.2",
|
|
8
|
+
"@siduri-x/core": "2.0.1"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@types/jest": "^
|
|
12
|
-
"@types/node": "^20.
|
|
13
|
-
"jest": "^
|
|
11
|
+
"@types/jest": "^30.0.0",
|
|
12
|
+
"@types/node": "^22.20.2",
|
|
13
|
+
"jest": "^30.5.1",
|
|
14
14
|
"ts-jest": "^29.4.12",
|
|
15
|
-
"typescript": "^5.
|
|
15
|
+
"typescript": "^5.9.3"
|
|
16
16
|
},
|
|
17
17
|
"description": "Brain organ for LLM reasoning, response planning, and proposal generation",
|
|
18
18
|
"license": "Apache-2.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
|
-
"node": ">=
|
|
28
|
+
"node": ">=22.16.0"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|