@siduri-x/brain 2.0.0 → 2.0.2
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 +26 -6
- 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
|
@@ -25,7 +25,10 @@ const MemoryProposalSchema = zod_1.z.object({
|
|
|
25
25
|
});
|
|
26
26
|
const BehaviorProposalSchema = zod_1.z.object({
|
|
27
27
|
directive: zod_1.z.string(),
|
|
28
|
-
|
|
28
|
+
category: zod_1.z.enum(['guardrail', 'relational', 'behavioral']).optional(),
|
|
29
|
+
scopeActor: zod_1.z.string().optional(),
|
|
30
|
+
supersedesId: zod_1.z.string().optional(),
|
|
31
|
+
priority: zod_1.z.number().optional(),
|
|
29
32
|
});
|
|
30
33
|
const ActionIntentSchema = zod_1.z.object({
|
|
31
34
|
actionId: zod_1.z.string(),
|
|
@@ -36,6 +39,8 @@ const ActionIntentSchema = zod_1.z.object({
|
|
|
36
39
|
const ResponsePlanSchema = zod_1.z.object({
|
|
37
40
|
speech: zod_1.z.string(),
|
|
38
41
|
language: zod_1.z.string(),
|
|
42
|
+
subtitle: zod_1.z.string().optional(),
|
|
43
|
+
subtitles: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
39
44
|
internalMonologue: zod_1.z.string().optional(),
|
|
40
45
|
memoryProposals: zod_1.z.array(MemoryProposalSchema).optional(),
|
|
41
46
|
behaviorProposals: zod_1.z.array(BehaviorProposalSchema).optional(),
|
|
@@ -44,9 +49,18 @@ const ResponsePlanSchema = zod_1.z.object({
|
|
|
44
49
|
class OpenAICompatibleBrain {
|
|
45
50
|
config;
|
|
46
51
|
assembler;
|
|
52
|
+
resolvedApiKey;
|
|
47
53
|
constructor(config) {
|
|
48
54
|
this.config = config;
|
|
49
55
|
this.assembler = new prompt_1.PromptAssembler();
|
|
56
|
+
const defaultEnv = config.baseUrl && !config.baseUrl.includes('openrouter.ai')
|
|
57
|
+
? 'OPENAI_COMPATIBLE_API_KEY'
|
|
58
|
+
: 'OPENROUTER_API_KEY';
|
|
59
|
+
const envKey = config.apiKeyEnv || defaultEnv;
|
|
60
|
+
this.resolvedApiKey = config.apiKey || (typeof process !== 'undefined' && process.env ? (process.env[envKey] || '') : '') || '';
|
|
61
|
+
if (!this.config.apiKey && this.resolvedApiKey) {
|
|
62
|
+
this.config = { ...this.config, apiKey: this.resolvedApiKey };
|
|
63
|
+
}
|
|
50
64
|
}
|
|
51
65
|
async generatePlan(context) {
|
|
52
66
|
const { messages } = this.assembler.assemble(context);
|
|
@@ -61,6 +75,7 @@ class OpenAICompatibleBrain {
|
|
|
61
75
|
properties: {
|
|
62
76
|
speech: { type: "string", description: "The text that the companion will speak." },
|
|
63
77
|
language: { type: "string", description: "The primary language of the speech (e.g., 'en', 'ja', 'id')." },
|
|
78
|
+
subtitle: { type: "string", description: "Optional translation or subtitle of speech in the requested subtitle language." },
|
|
64
79
|
internalMonologue: { type: "string", description: "Internal reasoning before responding." },
|
|
65
80
|
memoryProposals: {
|
|
66
81
|
type: "array",
|
|
@@ -79,10 +94,13 @@ class OpenAICompatibleBrain {
|
|
|
79
94
|
items: {
|
|
80
95
|
type: "object",
|
|
81
96
|
properties: {
|
|
82
|
-
directive: { type: "string" },
|
|
83
|
-
|
|
97
|
+
directive: { type: "string", description: "The natural language behavioral, guardrail, or relational rule." },
|
|
98
|
+
category: { type: "string", enum: ["guardrail", "relational", "behavioral"], description: "Category tier of the directive." },
|
|
99
|
+
scopeActor: { type: "string", description: "Optional specific actor this rule applies to (e.g. 'actor:zagin')." },
|
|
100
|
+
supersedesId: { type: "string", description: "Optional ID of an older directive this rule replaces." },
|
|
101
|
+
priority: { type: "number", description: "Optional legacy priority rank." }
|
|
84
102
|
},
|
|
85
|
-
required: ["directive"
|
|
103
|
+
required: ["directive"]
|
|
86
104
|
}
|
|
87
105
|
},
|
|
88
106
|
actionIntents: {
|
|
@@ -125,7 +143,7 @@ class OpenAICompatibleBrain {
|
|
|
125
143
|
const response = await fetch(`${this.config.baseUrl.replace(/\/+$/, '')}/chat/completions`, {
|
|
126
144
|
method: "POST",
|
|
127
145
|
headers: {
|
|
128
|
-
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
146
|
+
"Authorization": `Bearer ${this.resolvedApiKey || this.config.apiKey}`,
|
|
129
147
|
"Content-Type": "application/json",
|
|
130
148
|
},
|
|
131
149
|
body: JSON.stringify({
|
|
@@ -196,7 +214,9 @@ class OpenAICompatibleBrain {
|
|
|
196
214
|
exports.OpenAICompatibleBrain = OpenAICompatibleBrain;
|
|
197
215
|
class OpenRouterBrain extends OpenAICompatibleBrain {
|
|
198
216
|
constructor(config) {
|
|
199
|
-
|
|
217
|
+
const apiKeyEnv = config.apiKeyEnv || 'OPENROUTER_API_KEY';
|
|
218
|
+
const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env ? (process.env[apiKeyEnv] || process.env.OPENROUTER_API_KEY || '') : '') || '';
|
|
219
|
+
super({ ...config, baseUrl: 'https://openrouter.ai/api/v1', apiKey, apiKeyEnv });
|
|
200
220
|
}
|
|
201
221
|
}
|
|
202
222
|
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.2",
|
|
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.2",
|
|
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.4"
|
|
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",
|