moltblock 0.3.1 → 0.5.0
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/agents.d.ts +0 -1
- package/dist/agents.js +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +6 -2
- package/dist/config.d.ts +24 -96
- package/dist/config.js +128 -57
- package/dist/entity.d.ts +0 -1
- package/dist/entity.js +0 -1
- package/dist/gateway.d.ts +0 -1
- package/dist/gateway.js +0 -1
- package/dist/governance.d.ts +0 -1
- package/dist/governance.js +0 -1
- package/dist/graph-runner.d.ts +0 -1
- package/dist/graph-runner.js +0 -1
- package/dist/graph-schema.d.ts +5 -56
- package/dist/graph-schema.js +0 -1
- package/dist/handoff.d.ts +0 -1
- package/dist/handoff.js +0 -1
- package/dist/improvement.d.ts +0 -1
- package/dist/improvement.js +0 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/memory.d.ts +0 -1
- package/dist/memory.js +0 -1
- package/dist/persistence.d.ts +0 -1
- package/dist/persistence.js +13 -5
- package/dist/signing.d.ts +0 -1
- package/dist/signing.js +41 -10
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/dist/validation.d.ts +0 -1
- package/dist/validation.js +0 -1
- package/dist/verifier.d.ts +0 -1
- package/dist/verifier.js +12 -6
- package/package.json +10 -10
- package/readme.md +97 -8
- package/dist/agents.d.ts.map +0 -1
- package/dist/agents.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/entity.d.ts.map +0 -1
- package/dist/entity.js.map +0 -1
- package/dist/gateway.d.ts.map +0 -1
- package/dist/gateway.js.map +0 -1
- package/dist/governance.d.ts.map +0 -1
- package/dist/governance.js.map +0 -1
- package/dist/graph-runner.d.ts.map +0 -1
- package/dist/graph-runner.js.map +0 -1
- package/dist/graph-schema.d.ts.map +0 -1
- package/dist/graph-schema.js.map +0 -1
- package/dist/handoff.d.ts.map +0 -1
- package/dist/handoff.js.map +0 -1
- package/dist/improvement.d.ts.map +0 -1
- package/dist/improvement.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js.map +0 -1
- package/dist/persistence.d.ts.map +0 -1
- package/dist/persistence.js.map +0 -1
- package/dist/signing.d.ts.map +0 -1
- package/dist/signing.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js.map +0 -1
- package/dist/verifier.d.ts.map +0 -1
- package/dist/verifier.js.map +0 -1
package/dist/agents.d.ts
CHANGED
|
@@ -21,4 +21,3 @@ export declare function runJudge(gateway: LLMGateway, memory: WorkingMemory, sto
|
|
|
21
21
|
* Returns the role's output string. Used by the graph runner.
|
|
22
22
|
*/
|
|
23
23
|
export declare function runRole(role: string, gateway: LLMGateway, task: string, inputs: Record<string, string>, longTermContext?: string, store?: Store | null): Promise<string>;
|
|
24
|
-
//# sourceMappingURL=agents.d.ts.map
|
package/dist/agents.js
CHANGED
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -14,6 +14,8 @@ async function main() {
|
|
|
14
14
|
.argument("<task>", "Task description (e.g. 'Implement a function add(a,b) that returns a+b.')")
|
|
15
15
|
.option("-t, --test <path>", "Path to file containing test code (e.g. vitest test module). If omitted, only syntax check.")
|
|
16
16
|
.option("--json", "Output result as JSON (draft, critique, final, verification_passed, authoritative_artifact).")
|
|
17
|
+
.option("-p, --provider <name>", "LLM provider (openai, google, zai, local). Auto-detected from env if omitted.")
|
|
18
|
+
.option("-m, --model <name>", "Model for all roles (overrides provider default).")
|
|
17
19
|
.action(async (task, options) => {
|
|
18
20
|
// Validate task input
|
|
19
21
|
const validation = validateTask(task);
|
|
@@ -30,7 +32,10 @@ async function main() {
|
|
|
30
32
|
if (options.test && fs.existsSync(options.test)) {
|
|
31
33
|
testCode = fs.readFileSync(options.test, "utf-8");
|
|
32
34
|
}
|
|
33
|
-
const entity = new CodeEntity(defaultCodeEntityBindings(
|
|
35
|
+
const entity = new CodeEntity(defaultCodeEntityBindings({
|
|
36
|
+
provider: options.provider,
|
|
37
|
+
model: options.model,
|
|
38
|
+
}));
|
|
34
39
|
const memory = await entity.run(task, { testCode });
|
|
35
40
|
if (options.json) {
|
|
36
41
|
const out = {
|
|
@@ -67,4 +72,3 @@ main().catch((err) => {
|
|
|
67
72
|
console.error(err);
|
|
68
73
|
process.exit(1);
|
|
69
74
|
});
|
|
70
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/config.d.ts
CHANGED
|
@@ -8,17 +8,7 @@ export declare const BindingEntrySchema: z.ZodObject<{
|
|
|
8
8
|
base_url: z.ZodString;
|
|
9
9
|
model: z.ZodDefault<z.ZodString>;
|
|
10
10
|
api_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
11
|
-
},
|
|
12
|
-
model: string;
|
|
13
|
-
backend: string;
|
|
14
|
-
base_url: string;
|
|
15
|
-
api_key?: string | null | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
backend: string;
|
|
18
|
-
base_url: string;
|
|
19
|
-
model?: string | undefined;
|
|
20
|
-
api_key?: string | null | undefined;
|
|
21
|
-
}>;
|
|
11
|
+
}, z.core.$strip>;
|
|
22
12
|
export type BindingEntry = z.infer<typeof BindingEntrySchema>;
|
|
23
13
|
export declare const AgentConfigSchema: z.ZodObject<{
|
|
24
14
|
bindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
@@ -26,32 +16,8 @@ export declare const AgentConfigSchema: z.ZodObject<{
|
|
|
26
16
|
base_url: z.ZodString;
|
|
27
17
|
model: z.ZodDefault<z.ZodString>;
|
|
28
18
|
api_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
backend: string;
|
|
32
|
-
base_url: string;
|
|
33
|
-
api_key?: string | null | undefined;
|
|
34
|
-
}, {
|
|
35
|
-
backend: string;
|
|
36
|
-
base_url: string;
|
|
37
|
-
model?: string | undefined;
|
|
38
|
-
api_key?: string | null | undefined;
|
|
39
|
-
}>>>;
|
|
40
|
-
}, "strip", z.ZodTypeAny, {
|
|
41
|
-
bindings?: Record<string, {
|
|
42
|
-
model: string;
|
|
43
|
-
backend: string;
|
|
44
|
-
base_url: string;
|
|
45
|
-
api_key?: string | null | undefined;
|
|
46
|
-
}> | undefined;
|
|
47
|
-
}, {
|
|
48
|
-
bindings?: Record<string, {
|
|
49
|
-
backend: string;
|
|
50
|
-
base_url: string;
|
|
51
|
-
model?: string | undefined;
|
|
52
|
-
api_key?: string | null | undefined;
|
|
53
|
-
}> | undefined;
|
|
54
|
-
}>;
|
|
19
|
+
}, z.core.$strip>>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
55
21
|
export type AgentConfig = z.infer<typeof AgentConfigSchema>;
|
|
56
22
|
export declare const MoltblockConfigSchema: z.ZodObject<{
|
|
57
23
|
agent: z.ZodOptional<z.ZodObject<{
|
|
@@ -60,68 +26,16 @@ export declare const MoltblockConfigSchema: z.ZodObject<{
|
|
|
60
26
|
base_url: z.ZodString;
|
|
61
27
|
model: z.ZodDefault<z.ZodString>;
|
|
62
28
|
api_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
base_url: string;
|
|
67
|
-
api_key?: string | null | undefined;
|
|
68
|
-
}, {
|
|
69
|
-
backend: string;
|
|
70
|
-
base_url: string;
|
|
71
|
-
model?: string | undefined;
|
|
72
|
-
api_key?: string | null | undefined;
|
|
73
|
-
}>>>;
|
|
74
|
-
}, "strip", z.ZodTypeAny, {
|
|
75
|
-
bindings?: Record<string, {
|
|
76
|
-
model: string;
|
|
77
|
-
backend: string;
|
|
78
|
-
base_url: string;
|
|
79
|
-
api_key?: string | null | undefined;
|
|
80
|
-
}> | undefined;
|
|
81
|
-
}, {
|
|
82
|
-
bindings?: Record<string, {
|
|
83
|
-
backend: string;
|
|
84
|
-
base_url: string;
|
|
85
|
-
model?: string | undefined;
|
|
86
|
-
api_key?: string | null | undefined;
|
|
87
|
-
}> | undefined;
|
|
88
|
-
}>>;
|
|
89
|
-
}, "strip", z.ZodTypeAny, {
|
|
90
|
-
agent?: {
|
|
91
|
-
bindings?: Record<string, {
|
|
92
|
-
model: string;
|
|
93
|
-
backend: string;
|
|
94
|
-
base_url: string;
|
|
95
|
-
api_key?: string | null | undefined;
|
|
96
|
-
}> | undefined;
|
|
97
|
-
} | undefined;
|
|
98
|
-
}, {
|
|
99
|
-
agent?: {
|
|
100
|
-
bindings?: Record<string, {
|
|
101
|
-
backend: string;
|
|
102
|
-
base_url: string;
|
|
103
|
-
model?: string | undefined;
|
|
104
|
-
api_key?: string | null | undefined;
|
|
105
|
-
}> | undefined;
|
|
106
|
-
} | undefined;
|
|
107
|
-
}>;
|
|
29
|
+
}, z.core.$strip>>>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
108
32
|
export type MoltblockConfig = z.infer<typeof MoltblockConfigSchema>;
|
|
109
33
|
export declare const ModelBindingSchema: z.ZodObject<{
|
|
110
34
|
backend: z.ZodString;
|
|
111
35
|
baseUrl: z.ZodString;
|
|
112
36
|
apiKey: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
113
37
|
model: z.ZodDefault<z.ZodString>;
|
|
114
|
-
},
|
|
115
|
-
model: string;
|
|
116
|
-
backend: string;
|
|
117
|
-
baseUrl: string;
|
|
118
|
-
apiKey: string | null;
|
|
119
|
-
}, {
|
|
120
|
-
backend: string;
|
|
121
|
-
baseUrl: string;
|
|
122
|
-
model?: string | undefined;
|
|
123
|
-
apiKey?: string | null | undefined;
|
|
124
|
-
}>;
|
|
38
|
+
}, z.core.$strip>;
|
|
125
39
|
export type ModelBinding = z.infer<typeof ModelBindingSchema>;
|
|
126
40
|
/** Track which config source was used */
|
|
127
41
|
export type ConfigSource = "moltblock" | "openclaw" | "env" | null;
|
|
@@ -134,9 +48,23 @@ export declare function getConfigSource(): ConfigSource;
|
|
|
134
48
|
* Returns null if no file or parse error.
|
|
135
49
|
*/
|
|
136
50
|
export declare function loadMoltblockConfig(): MoltblockConfig | null;
|
|
51
|
+
/** Overrides for provider/model selection (e.g. from CLI flags). */
|
|
52
|
+
export interface BindingOverrides {
|
|
53
|
+
provider?: string;
|
|
54
|
+
model?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Auto-detect the best available provider from environment variables.
|
|
58
|
+
* Priority: explicit override > OPENAI_API_KEY > GOOGLE_API_KEY > MOLTBLOCK_ZAI_API_KEY/ZAI_API_KEY > local.
|
|
59
|
+
*/
|
|
60
|
+
export declare function detectProvider(overrideProvider?: string, overrideModel?: string): {
|
|
61
|
+
backend: string;
|
|
62
|
+
baseUrl: string;
|
|
63
|
+
model: string;
|
|
64
|
+
apiKey: string | null;
|
|
65
|
+
};
|
|
137
66
|
/**
|
|
138
67
|
* Model bindings for Code Entity. Load from moltblock.json if present, then env overrides.
|
|
139
|
-
* If no JSON,
|
|
68
|
+
* If no JSON, auto-detects provider from env vars. API keys from env win over JSON.
|
|
140
69
|
*/
|
|
141
|
-
export declare function defaultCodeEntityBindings(): Record<string, ModelBinding>;
|
|
142
|
-
//# sourceMappingURL=config.d.ts.map
|
|
70
|
+
export declare function defaultCodeEntityBindings(overrides?: BindingOverrides): Record<string, ModelBinding>;
|
package/dist/config.js
CHANGED
|
@@ -6,14 +6,30 @@ import fs from "node:fs";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import os from "node:os";
|
|
8
8
|
import { z } from "zod";
|
|
9
|
+
/** JSON.parse reviver that strips prototype pollution keys */
|
|
10
|
+
function safeJsonParse(text) {
|
|
11
|
+
return JSON.parse(text, (key, value) => {
|
|
12
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
9
18
|
// Load .env so MOLTBLOCK_ZAI_API_KEY etc. can be set there
|
|
10
19
|
try {
|
|
11
20
|
const dotenv = await import("dotenv");
|
|
12
|
-
dotenv.config();
|
|
21
|
+
dotenv.config({ quiet: true });
|
|
13
22
|
}
|
|
14
23
|
catch {
|
|
15
24
|
// dotenv not required
|
|
16
25
|
}
|
|
26
|
+
// --- Provider defaults registry ---
|
|
27
|
+
const PROVIDER_DEFAULTS = {
|
|
28
|
+
openai: { baseUrl: "https://api.openai.com/v1", model: "gpt-4o", envKey: "OPENAI_API_KEY" },
|
|
29
|
+
google: { baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai/", model: "gemini-2.0-flash", envKey: "GOOGLE_API_KEY" },
|
|
30
|
+
zai: { baseUrl: "https://api.z.ai/api/paas/v4", model: "glm-4.7-flash", envKey: "MOLTBLOCK_ZAI_API_KEY" },
|
|
31
|
+
local: { baseUrl: "http://localhost:1234/v1", model: "local", envKey: "" },
|
|
32
|
+
};
|
|
17
33
|
// --- Zod schemas (OpenClaw-style config) ---
|
|
18
34
|
export const BindingEntrySchema = z.object({
|
|
19
35
|
backend: z.string().describe("e.g. 'local' or 'zai' or 'openai'"),
|
|
@@ -22,7 +38,7 @@ export const BindingEntrySchema = z.object({
|
|
|
22
38
|
api_key: z.string().nullable().optional().describe("Bearer token; null for local. Prefer env."),
|
|
23
39
|
});
|
|
24
40
|
export const AgentConfigSchema = z.object({
|
|
25
|
-
bindings: z.record(BindingEntrySchema).optional().describe("Per-role model bindings"),
|
|
41
|
+
bindings: z.record(z.string(), BindingEntrySchema).optional().describe("Per-role model bindings"),
|
|
26
42
|
});
|
|
27
43
|
export const MoltblockConfigSchema = z.object({
|
|
28
44
|
agent: AgentConfigSchema.optional().describe("Agent defaults and bindings"),
|
|
@@ -33,12 +49,18 @@ export const ModelBindingSchema = z.object({
|
|
|
33
49
|
apiKey: z.string().nullable().default(null).describe("Bearer token; null for local"),
|
|
34
50
|
model: z.string().default("default").describe("Model name for chat completion"),
|
|
35
51
|
});
|
|
52
|
+
/** Validate that a config path is within allowed directories (cwd, homedir, or tmpdir). */
|
|
53
|
+
function isAllowedConfigPath(filePath) {
|
|
54
|
+
const resolved = path.resolve(filePath);
|
|
55
|
+
const allowed = [path.resolve(process.cwd()), path.resolve(os.homedir()), path.resolve(os.tmpdir())];
|
|
56
|
+
return allowed.some((dir) => resolved.startsWith(dir + path.sep) || resolved === dir);
|
|
57
|
+
}
|
|
36
58
|
/**
|
|
37
59
|
* Resolve moltblock config file: MOLTBLOCK_CONFIG env, then ./moltblock.json, ./.moltblock/moltblock.json, ~/.moltblock/moltblock.json.
|
|
38
60
|
*/
|
|
39
61
|
function moltblockConfigPath() {
|
|
40
62
|
const envPath = (process.env["MOLTBLOCK_CONFIG"] ?? "").trim();
|
|
41
|
-
if (envPath && fs.existsSync(envPath)) {
|
|
63
|
+
if (envPath && isAllowedConfigPath(envPath) && fs.existsSync(envPath)) {
|
|
42
64
|
return envPath;
|
|
43
65
|
}
|
|
44
66
|
const cwd = process.cwd();
|
|
@@ -59,7 +81,7 @@ function moltblockConfigPath() {
|
|
|
59
81
|
*/
|
|
60
82
|
function openclawConfigPath() {
|
|
61
83
|
const envPath = (process.env["OPENCLAW_CONFIG"] ?? "").trim();
|
|
62
|
-
if (envPath && fs.existsSync(envPath)) {
|
|
84
|
+
if (envPath && isAllowedConfigPath(envPath) && fs.existsSync(envPath)) {
|
|
63
85
|
return envPath;
|
|
64
86
|
}
|
|
65
87
|
const cwd = process.cwd();
|
|
@@ -92,7 +114,7 @@ export function loadMoltblockConfig() {
|
|
|
92
114
|
if (moltblockFile) {
|
|
93
115
|
try {
|
|
94
116
|
const raw = fs.readFileSync(moltblockFile, "utf-8");
|
|
95
|
-
const data =
|
|
117
|
+
const data = safeJsonParse(raw);
|
|
96
118
|
const config = MoltblockConfigSchema.parse(data);
|
|
97
119
|
lastConfigSource = "moltblock";
|
|
98
120
|
return config;
|
|
@@ -106,7 +128,7 @@ export function loadMoltblockConfig() {
|
|
|
106
128
|
if (openclawFile) {
|
|
107
129
|
try {
|
|
108
130
|
const raw = fs.readFileSync(openclawFile, "utf-8");
|
|
109
|
-
const data =
|
|
131
|
+
const data = safeJsonParse(raw);
|
|
110
132
|
const config = parseOpenClawConfig(data);
|
|
111
133
|
if (config) {
|
|
112
134
|
lastConfigSource = "openclaw";
|
|
@@ -123,18 +145,49 @@ export function loadMoltblockConfig() {
|
|
|
123
145
|
}
|
|
124
146
|
/**
|
|
125
147
|
* Parse OpenClaw config and convert to MoltblockConfig format.
|
|
126
|
-
*
|
|
148
|
+
* Handles multiple OpenClaw formats: agents.defaults.model.primary ("provider/model"),
|
|
149
|
+
* agent.bindings, providers section, and models section.
|
|
127
150
|
*/
|
|
128
151
|
function parseOpenClawConfig(data) {
|
|
129
152
|
if (!data || typeof data !== "object") {
|
|
130
153
|
return null;
|
|
131
154
|
}
|
|
132
155
|
const obj = data;
|
|
133
|
-
// OpenClaw may have agent.bindings or providers section
|
|
134
|
-
// Try to extract bindings from various possible locations
|
|
135
156
|
let bindings;
|
|
157
|
+
// Check for agents.defaults.model.primary (OpenClaw's actual format: "provider/model")
|
|
158
|
+
if (obj["agents"] && typeof obj["agents"] === "object") {
|
|
159
|
+
const agents = obj["agents"];
|
|
160
|
+
if (agents["defaults"] && typeof agents["defaults"] === "object") {
|
|
161
|
+
const defaults = agents["defaults"];
|
|
162
|
+
if (defaults["model"] && typeof defaults["model"] === "object") {
|
|
163
|
+
const modelConfig = defaults["model"];
|
|
164
|
+
const primary = modelConfig["primary"];
|
|
165
|
+
if (typeof primary === "string" && primary.includes("/")) {
|
|
166
|
+
const parts = primary.split("/");
|
|
167
|
+
const providerName = parts[0] ?? "";
|
|
168
|
+
const modelName = parts.slice(1).join("/");
|
|
169
|
+
const provider = PROVIDER_DEFAULTS[providerName.toLowerCase()];
|
|
170
|
+
if (providerName && provider) {
|
|
171
|
+
const apiKey = getApiKeyForBackend(providerName);
|
|
172
|
+
const binding = {
|
|
173
|
+
backend: providerName.toLowerCase(),
|
|
174
|
+
base_url: provider.baseUrl,
|
|
175
|
+
model: modelName || provider.model,
|
|
176
|
+
api_key: apiKey,
|
|
177
|
+
};
|
|
178
|
+
bindings = {
|
|
179
|
+
generator: binding,
|
|
180
|
+
critic: { ...binding },
|
|
181
|
+
judge: { ...binding },
|
|
182
|
+
verifier: { ...binding },
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
136
189
|
// Check for agent.bindings (same as moltblock)
|
|
137
|
-
if (obj["agent"] && typeof obj["agent"] === "object") {
|
|
190
|
+
if (!bindings && obj["agent"] && typeof obj["agent"] === "object") {
|
|
138
191
|
const agent = obj["agent"];
|
|
139
192
|
if (agent["bindings"] && typeof agent["bindings"] === "object") {
|
|
140
193
|
bindings = extractBindings(agent["bindings"]);
|
|
@@ -227,70 +280,88 @@ function getApiKeyForBackend(backend) {
|
|
|
227
280
|
return env("GOOGLE_API_KEY") || null;
|
|
228
281
|
}
|
|
229
282
|
if (backendLower === "zai") {
|
|
230
|
-
return env("MOLTBLOCK_ZAI_API_KEY") || null;
|
|
283
|
+
return env("MOLTBLOCK_ZAI_API_KEY") || env("ZAI_API_KEY") || null;
|
|
231
284
|
}
|
|
232
285
|
return null;
|
|
233
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Auto-detect the best available provider from environment variables.
|
|
289
|
+
* Priority: explicit override > OPENAI_API_KEY > GOOGLE_API_KEY > MOLTBLOCK_ZAI_API_KEY/ZAI_API_KEY > local.
|
|
290
|
+
*/
|
|
291
|
+
export function detectProvider(overrideProvider, overrideModel) {
|
|
292
|
+
if (overrideProvider) {
|
|
293
|
+
const p = PROVIDER_DEFAULTS[overrideProvider.toLowerCase()];
|
|
294
|
+
if (!p) {
|
|
295
|
+
throw new Error(`Unknown provider "${overrideProvider}". Valid providers: ${Object.keys(PROVIDER_DEFAULTS).join(", ")}`);
|
|
296
|
+
}
|
|
297
|
+
const apiKey = p.envKey ? env(p.envKey) || null : null;
|
|
298
|
+
return {
|
|
299
|
+
backend: overrideProvider.toLowerCase(),
|
|
300
|
+
baseUrl: p.baseUrl,
|
|
301
|
+
model: overrideModel || p.model,
|
|
302
|
+
apiKey,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
// Scan env vars in priority order
|
|
306
|
+
const priority = [
|
|
307
|
+
{ name: "openai", envKey: "OPENAI_API_KEY" },
|
|
308
|
+
{ name: "google", envKey: "GOOGLE_API_KEY" },
|
|
309
|
+
{ name: "zai", envKey: "MOLTBLOCK_ZAI_API_KEY" },
|
|
310
|
+
{ name: "zai", envKey: "ZAI_API_KEY" },
|
|
311
|
+
];
|
|
312
|
+
for (const { name, envKey } of priority) {
|
|
313
|
+
const key = env(envKey);
|
|
314
|
+
if (key) {
|
|
315
|
+
const p = PROVIDER_DEFAULTS[name];
|
|
316
|
+
return {
|
|
317
|
+
backend: name,
|
|
318
|
+
baseUrl: p.baseUrl,
|
|
319
|
+
model: overrideModel || p.model,
|
|
320
|
+
apiKey: key,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// Fallback to local
|
|
325
|
+
const local = PROVIDER_DEFAULTS["local"];
|
|
326
|
+
return {
|
|
327
|
+
backend: "local",
|
|
328
|
+
baseUrl: local.baseUrl,
|
|
329
|
+
model: overrideModel || local.model,
|
|
330
|
+
apiKey: null,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
234
333
|
/**
|
|
235
334
|
* Model bindings for Code Entity. Load from moltblock.json if present, then env overrides.
|
|
236
|
-
* If no JSON,
|
|
335
|
+
* If no JSON, auto-detects provider from env vars. API keys from env win over JSON.
|
|
237
336
|
*/
|
|
238
|
-
export function defaultCodeEntityBindings() {
|
|
337
|
+
export function defaultCodeEntityBindings(overrides) {
|
|
239
338
|
const cfg = loadMoltblockConfig();
|
|
240
|
-
const zaiKey = env("MOLTBLOCK_ZAI_API_KEY");
|
|
241
|
-
const localUrl = env("MOLTBLOCK_GENERATOR_BASE_URL") || "http://localhost:1234/v1";
|
|
242
|
-
const localModel = env("MOLTBLOCK_GENERATOR_MODEL") || "local";
|
|
243
339
|
const envUrl = (key, fallback) => env(key) || fallback;
|
|
244
340
|
const envModel = (key, fallback) => env(key) || fallback;
|
|
245
341
|
const bindingsFromJson = cfg?.agent?.bindings ?? {};
|
|
246
|
-
function bindingFor(role
|
|
342
|
+
function bindingFor(role) {
|
|
247
343
|
const entry = bindingsFromJson[role];
|
|
248
344
|
if (entry) {
|
|
249
345
|
const baseUrl = envUrl(`MOLTBLOCK_${role.toUpperCase()}_BASE_URL`, entry.base_url);
|
|
250
346
|
const model = envModel(`MOLTBLOCK_${role.toUpperCase()}_MODEL`, entry.model ?? "default");
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
347
|
+
const envApiKey = env(`MOLTBLOCK_${role.toUpperCase()}_API_KEY`);
|
|
348
|
+
if (!envApiKey && entry.api_key) {
|
|
349
|
+
console.warn(`Warning: API key for "${role}" loaded from config file. ` +
|
|
350
|
+
`Use environment variables instead for better security.`);
|
|
351
|
+
}
|
|
352
|
+
const apiKey = envApiKey || entry.api_key || getApiKeyForBackend(entry.backend) || null;
|
|
255
353
|
return { backend: entry.backend, baseUrl, apiKey, model };
|
|
256
354
|
}
|
|
257
|
-
// No JSON:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const useZai = Boolean(zaiKey);
|
|
263
|
-
return {
|
|
264
|
-
backend: useZai ? "zai" : "local",
|
|
265
|
-
baseUrl: envUrl("MOLTBLOCK_CRITIC_BASE_URL", useZai ? "https://api.z.ai/api/paas/v4" : localUrl),
|
|
266
|
-
apiKey: useZai ? zaiKey : null,
|
|
267
|
-
model: envModel("MOLTBLOCK_CRITIC_MODEL", useZai ? "glm-4.7-flash" : localModel),
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
if (role === "judge") {
|
|
271
|
-
const useZai = Boolean(zaiKey);
|
|
272
|
-
return {
|
|
273
|
-
backend: useZai ? "zai" : "local",
|
|
274
|
-
baseUrl: envUrl("MOLTBLOCK_JUDGE_BASE_URL", useZai ? "https://api.z.ai/api/paas/v4" : localUrl),
|
|
275
|
-
apiKey: useZai ? zaiKey : null,
|
|
276
|
-
model: envModel("MOLTBLOCK_JUDGE_MODEL", useZai ? "glm-4.7-flash" : localModel),
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
if (role === "verifier") {
|
|
280
|
-
return {
|
|
281
|
-
backend: "local",
|
|
282
|
-
baseUrl: envUrl("MOLTBLOCK_VERIFIER_BASE_URL", localUrl),
|
|
283
|
-
apiKey: null,
|
|
284
|
-
model: envModel("MOLTBLOCK_VERIFIER_MODEL", localModel),
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
return { backend: defaultBackend, baseUrl: defaultBase, apiKey: defaultApiKey, model: defaultModel };
|
|
355
|
+
// No JSON entry for this role: auto-detect provider
|
|
356
|
+
const detected = detectProvider(overrides?.provider, overrides?.model);
|
|
357
|
+
const baseUrl = envUrl(`MOLTBLOCK_${role.toUpperCase()}_BASE_URL`, detected.baseUrl);
|
|
358
|
+
const model = envModel(`MOLTBLOCK_${role.toUpperCase()}_MODEL`, detected.model);
|
|
359
|
+
return { backend: detected.backend, baseUrl, apiKey: detected.apiKey, model };
|
|
288
360
|
}
|
|
289
361
|
return {
|
|
290
|
-
generator: bindingFor("generator"
|
|
291
|
-
critic: bindingFor("critic"
|
|
292
|
-
judge: bindingFor("judge"
|
|
293
|
-
verifier: bindingFor("verifier"
|
|
362
|
+
generator: bindingFor("generator"),
|
|
363
|
+
critic: bindingFor("critic"),
|
|
364
|
+
judge: bindingFor("judge"),
|
|
365
|
+
verifier: bindingFor("verifier"),
|
|
294
366
|
};
|
|
295
367
|
}
|
|
296
|
-
//# sourceMappingURL=config.js.map
|
package/dist/entity.d.ts
CHANGED
|
@@ -28,4 +28,3 @@ export declare class CodeEntity {
|
|
|
28
28
|
* Load an Entity from a declarative graph (JSON/YAML). Returns a GraphRunner.
|
|
29
29
|
*/
|
|
30
30
|
export declare function loadEntityWithGraph(graphPath: string, bindings?: Record<string, ModelBinding>): GraphRunner;
|
|
31
|
-
//# sourceMappingURL=entity.d.ts.map
|
package/dist/entity.js
CHANGED
package/dist/gateway.d.ts
CHANGED
package/dist/gateway.js
CHANGED
package/dist/governance.d.ts
CHANGED
package/dist/governance.js
CHANGED
package/dist/graph-runner.d.ts
CHANGED
package/dist/graph-runner.js
CHANGED
package/dist/graph-schema.d.ts
CHANGED
|
@@ -6,75 +6,25 @@ export declare const GraphNodeSchema: z.ZodObject<{
|
|
|
6
6
|
id: z.ZodString;
|
|
7
7
|
role: z.ZodString;
|
|
8
8
|
binding: z.ZodString;
|
|
9
|
-
},
|
|
10
|
-
id: string;
|
|
11
|
-
role: string;
|
|
12
|
-
binding: string;
|
|
13
|
-
}, {
|
|
14
|
-
id: string;
|
|
15
|
-
role: string;
|
|
16
|
-
binding: string;
|
|
17
|
-
}>;
|
|
9
|
+
}, z.core.$strip>;
|
|
18
10
|
export type GraphNode = z.infer<typeof GraphNodeSchema>;
|
|
19
11
|
export declare const GraphEdgeSchema: z.ZodObject<{
|
|
20
12
|
from: z.ZodString;
|
|
21
13
|
to: z.ZodString;
|
|
22
|
-
},
|
|
23
|
-
from: string;
|
|
24
|
-
to: string;
|
|
25
|
-
}, {
|
|
26
|
-
from: string;
|
|
27
|
-
to: string;
|
|
28
|
-
}>;
|
|
14
|
+
}, z.core.$strip>;
|
|
29
15
|
export type GraphEdge = z.infer<typeof GraphEdgeSchema>;
|
|
30
16
|
export declare const AgentGraphSchema: z.ZodObject<{
|
|
31
17
|
nodes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
32
18
|
id: z.ZodString;
|
|
33
19
|
role: z.ZodString;
|
|
34
20
|
binding: z.ZodString;
|
|
35
|
-
},
|
|
36
|
-
id: string;
|
|
37
|
-
role: string;
|
|
38
|
-
binding: string;
|
|
39
|
-
}, {
|
|
40
|
-
id: string;
|
|
41
|
-
role: string;
|
|
42
|
-
binding: string;
|
|
43
|
-
}>, "many">>;
|
|
21
|
+
}, z.core.$strip>>>;
|
|
44
22
|
edges: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
45
23
|
from: z.ZodString;
|
|
46
24
|
to: z.ZodString;
|
|
47
|
-
},
|
|
48
|
-
from: string;
|
|
49
|
-
to: string;
|
|
50
|
-
}, {
|
|
51
|
-
from: string;
|
|
52
|
-
to: string;
|
|
53
|
-
}>, "many">>;
|
|
25
|
+
}, z.core.$strip>>>;
|
|
54
26
|
final_node: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
55
|
-
},
|
|
56
|
-
nodes: {
|
|
57
|
-
id: string;
|
|
58
|
-
role: string;
|
|
59
|
-
binding: string;
|
|
60
|
-
}[];
|
|
61
|
-
edges: {
|
|
62
|
-
from: string;
|
|
63
|
-
to: string;
|
|
64
|
-
}[];
|
|
65
|
-
final_node?: string | null | undefined;
|
|
66
|
-
}, {
|
|
67
|
-
nodes?: {
|
|
68
|
-
id: string;
|
|
69
|
-
role: string;
|
|
70
|
-
binding: string;
|
|
71
|
-
}[] | undefined;
|
|
72
|
-
edges?: {
|
|
73
|
-
from: string;
|
|
74
|
-
to: string;
|
|
75
|
-
}[] | undefined;
|
|
76
|
-
final_node?: string | null | undefined;
|
|
77
|
-
}>;
|
|
27
|
+
}, z.core.$strip>;
|
|
78
28
|
export type AgentGraphData = z.infer<typeof AgentGraphSchema>;
|
|
79
29
|
/**
|
|
80
30
|
* Declarative agent graph: nodes and edges. Verifier runs on final node(s) output.
|
|
@@ -113,4 +63,3 @@ export declare class AgentGraph {
|
|
|
113
63
|
*/
|
|
114
64
|
static fromData(data: AgentGraphData): AgentGraph;
|
|
115
65
|
}
|
|
116
|
-
//# sourceMappingURL=graph-schema.d.ts.map
|
package/dist/graph-schema.js
CHANGED
package/dist/handoff.d.ts
CHANGED
package/dist/handoff.js
CHANGED
package/dist/improvement.d.ts
CHANGED
package/dist/improvement.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Moltblock — framework for evolving composite intelligences (Entities).
|
|
3
3
|
*/
|
|
4
|
-
export declare const VERSION = "0.
|
|
4
|
+
export declare const VERSION = "0.5.0";
|
|
5
5
|
export type { ModelBinding, BindingEntry, AgentConfig, MoltblockConfig, ChatMessage, VerifiedMemoryEntry, CheckpointEntry, OutcomeEntry, InboxEntry, StrategySuggestion, ReceivedArtifact, GovernanceConfig, } from "./types.js";
|
|
6
6
|
export { WorkingMemory } from "./memory.js";
|
|
7
7
|
export { signArtifact, verifyArtifact, artifactHash } from "./signing.js";
|
|
8
|
-
export { loadMoltblockConfig, defaultCodeEntityBindings, getConfigSource, BindingEntrySchema, AgentConfigSchema, MoltblockConfigSchema, ModelBindingSchema, type ConfigSource, } from "./config.js";
|
|
8
|
+
export { loadMoltblockConfig, defaultCodeEntityBindings, detectProvider, getConfigSource, BindingEntrySchema, AgentConfigSchema, MoltblockConfigSchema, ModelBindingSchema, type BindingOverrides, type ConfigSource, } from "./config.js";
|
|
9
9
|
export { Store, hashGraph, hashMemory, auditLog, getGovernanceValue, setGovernanceValue, putInbox, getInbox, recordOutcome, getRecentOutcomes, getStrategy, setStrategy, } from "./persistence.js";
|
|
10
10
|
export { LLMGateway } from "./gateway.js";
|
|
11
11
|
export { runGenerator, runCritic, runJudge, runRole, } from "./agents.js";
|
|
@@ -17,4 +17,3 @@ export { sendArtifact, receiveArtifacts } from "./handoff.js";
|
|
|
17
17
|
export { critiqueStrategies, applySuggestion, runEval, runImprovementCycle, } from "./improvement.js";
|
|
18
18
|
export { validateTask, validateTestCode, MAX_TASK_LENGTH, MIN_TASK_LENGTH, type ValidationResult, } from "./validation.js";
|
|
19
19
|
export { CodeEntity, loadEntityWithGraph } from "./entity.js";
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|