@almadar/agent 2.0.4 → 3.1.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/builder/builder-tools.d.ts +26 -0
- package/dist/builder/index.d.ts +10 -0
- package/dist/builder/index.js +424 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/types.d.ts +20 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +589 -18
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/local-memory-backend.d.ts +80 -0
- package/dist/neural/index.d.ts +12 -0
- package/dist/neural/index.js +86 -0
- package/dist/neural/index.js.map +1 -0
- package/dist/neural/masar-client.d.ts +42 -0
- package/dist/neural/types.d.ts +111 -0
- package/dist/persistence/index.d.ts +1 -0
- package/dist/persistence/index.js +194 -3
- package/dist/persistence/index.js.map +1 -1
- package/dist/persistence/local-session-backend.d.ts +57 -0
- package/package.json +11 -2
package/dist/index.js
CHANGED
|
@@ -1299,6 +1299,98 @@ var init_orbital_batch_subagent = __esm({
|
|
|
1299
1299
|
});
|
|
1300
1300
|
}
|
|
1301
1301
|
});
|
|
1302
|
+
|
|
1303
|
+
// src/neural/masar-client.ts
|
|
1304
|
+
var masar_client_exports = {};
|
|
1305
|
+
__export(masar_client_exports, {
|
|
1306
|
+
MasarClient: () => MasarClient
|
|
1307
|
+
});
|
|
1308
|
+
function toNeuralPipelineResult(data) {
|
|
1309
|
+
return {
|
|
1310
|
+
success: data.success,
|
|
1311
|
+
validationPass: data.validation_pass,
|
|
1312
|
+
compilationPass: false,
|
|
1313
|
+
goalMatch: data.goal_match ?? 0,
|
|
1314
|
+
totalSteps: data.total_steps ?? 0,
|
|
1315
|
+
fixRounds: data.fix_rounds ?? 0,
|
|
1316
|
+
llmCalls: data.llm_calls ?? 0,
|
|
1317
|
+
durationMs: data.duration_ms ?? 0,
|
|
1318
|
+
schema: data.schema ?? null,
|
|
1319
|
+
schemaPath: null,
|
|
1320
|
+
actions: data.actions ?? [],
|
|
1321
|
+
validationErrors: data.validation_errors ?? [],
|
|
1322
|
+
compilationErrors: [],
|
|
1323
|
+
error: data.error ?? null
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function makeErrorResult(error) {
|
|
1327
|
+
return {
|
|
1328
|
+
success: false,
|
|
1329
|
+
validationPass: false,
|
|
1330
|
+
compilationPass: false,
|
|
1331
|
+
goalMatch: 0,
|
|
1332
|
+
totalSteps: 0,
|
|
1333
|
+
fixRounds: 0,
|
|
1334
|
+
llmCalls: 0,
|
|
1335
|
+
durationMs: 0,
|
|
1336
|
+
schema: null,
|
|
1337
|
+
schemaPath: null,
|
|
1338
|
+
actions: [],
|
|
1339
|
+
validationErrors: [],
|
|
1340
|
+
compilationErrors: [],
|
|
1341
|
+
error
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
var MasarClient;
|
|
1345
|
+
var init_masar_client = __esm({
|
|
1346
|
+
"src/neural/masar-client.ts"() {
|
|
1347
|
+
MasarClient = class {
|
|
1348
|
+
constructor(options) {
|
|
1349
|
+
this.baseUrl = (options?.baseUrl ?? process.env["MASAR_URL"] ?? "https://masar-345008351456.europe-west4.run.app").replace(/\/$/, "");
|
|
1350
|
+
this.timeoutMs = options?.timeoutMs ?? 12e4;
|
|
1351
|
+
this.onProgress = options?.onProgress ?? null;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Generate an .orb schema from a natural language prompt.
|
|
1355
|
+
*
|
|
1356
|
+
* Sends the prompt to the Masar server which runs the full neural pipeline
|
|
1357
|
+
* (goal parsing, GFlowNet generation, validation, LLM fix loop) and returns
|
|
1358
|
+
* the result.
|
|
1359
|
+
*/
|
|
1360
|
+
async generate(prompt) {
|
|
1361
|
+
this.onProgress?.("request", `Sending prompt to Masar at ${this.baseUrl}`);
|
|
1362
|
+
const url = `${this.baseUrl}/generate`;
|
|
1363
|
+
const controller = new AbortController();
|
|
1364
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1365
|
+
try {
|
|
1366
|
+
const response = await fetch(url, {
|
|
1367
|
+
method: "POST",
|
|
1368
|
+
headers: { "Content-Type": "application/json" },
|
|
1369
|
+
body: JSON.stringify({ prompt }),
|
|
1370
|
+
signal: controller.signal
|
|
1371
|
+
});
|
|
1372
|
+
if (!response.ok) {
|
|
1373
|
+
const body = await response.text().catch(() => "");
|
|
1374
|
+
return makeErrorResult(
|
|
1375
|
+
`Masar server returned ${response.status} ${response.statusText}${body ? `: ${body}` : ""}`
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
const data = await response.json();
|
|
1379
|
+
this.onProgress?.("response", data.success ? "Generation succeeded" : `Generation failed: ${data.error ?? "unknown"}`);
|
|
1380
|
+
return toNeuralPipelineResult(data);
|
|
1381
|
+
} catch (err) {
|
|
1382
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
1383
|
+
return makeErrorResult(`Masar request timed out after ${this.timeoutMs}ms`);
|
|
1384
|
+
}
|
|
1385
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1386
|
+
return makeErrorResult(`Masar request failed: ${message}`);
|
|
1387
|
+
} finally {
|
|
1388
|
+
clearTimeout(timeout);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1302
1394
|
var ExtractedRequirementsSchema = z.object({
|
|
1303
1395
|
/** Entity names to create */
|
|
1304
1396
|
entities: z.array(z.string()).optional().default([]),
|
|
@@ -3792,27 +3884,27 @@ var CombineSchemaInputSchema = z.object({
|
|
|
3792
3884
|
validate: z.boolean().optional().default(true)
|
|
3793
3885
|
});
|
|
3794
3886
|
async function autoCollectOrbitals(workDir) {
|
|
3795
|
-
const
|
|
3796
|
-
const
|
|
3797
|
-
const orbitalsDir =
|
|
3798
|
-
if (!
|
|
3799
|
-
const files2 =
|
|
3887
|
+
const fs12 = await import('fs');
|
|
3888
|
+
const path13 = await import('path');
|
|
3889
|
+
const orbitalsDir = path13.join(workDir, ".orbitals");
|
|
3890
|
+
if (!fs12.existsSync(orbitalsDir)) {
|
|
3891
|
+
const files2 = fs12.readdirSync(workDir).filter(
|
|
3800
3892
|
(f) => f.endsWith(".json") && (f.startsWith("orbital-") || f.includes("orbital"))
|
|
3801
3893
|
);
|
|
3802
3894
|
if (files2.length === 0) {
|
|
3803
3895
|
throw new Error("No orbitals found. Generate orbitals first using generate_orbital, or provide them directly.");
|
|
3804
3896
|
}
|
|
3805
3897
|
return files2.map((f) => {
|
|
3806
|
-
const content =
|
|
3898
|
+
const content = fs12.readFileSync(path13.join(workDir, f), "utf-8");
|
|
3807
3899
|
return JSON.parse(content);
|
|
3808
3900
|
});
|
|
3809
3901
|
}
|
|
3810
|
-
const files =
|
|
3902
|
+
const files = fs12.readdirSync(orbitalsDir).filter((f) => f.endsWith(".json"));
|
|
3811
3903
|
if (files.length === 0) {
|
|
3812
3904
|
throw new Error("No orbitals found in .orbitals/ directory.");
|
|
3813
3905
|
}
|
|
3814
3906
|
return files.map((f) => {
|
|
3815
|
-
const content =
|
|
3907
|
+
const content = fs12.readFileSync(path13.join(orbitalsDir, f), "utf-8");
|
|
3816
3908
|
return JSON.parse(content);
|
|
3817
3909
|
});
|
|
3818
3910
|
}
|
|
@@ -6972,6 +7064,7 @@ function createEvalWorkflowWrapper(options = {}) {
|
|
|
6972
7064
|
}
|
|
6973
7065
|
};
|
|
6974
7066
|
}
|
|
7067
|
+
path__default.join(os.homedir(), ".almadar", "sessions");
|
|
6975
7068
|
var FirestoreStore = class extends BaseStore {
|
|
6976
7069
|
constructor(options) {
|
|
6977
7070
|
super();
|
|
@@ -7129,9 +7222,9 @@ var FirestoreStore = class extends BaseStore {
|
|
|
7129
7222
|
let query = this.db.collection(this.collection);
|
|
7130
7223
|
if (op.matchConditions) {
|
|
7131
7224
|
for (const condition of op.matchConditions) {
|
|
7132
|
-
const
|
|
7225
|
+
const path13 = condition.path.filter((p) => p !== "*").join("/");
|
|
7133
7226
|
if (condition.matchType === "prefix") {
|
|
7134
|
-
query = query.where("namespaceKey", ">=",
|
|
7227
|
+
query = query.where("namespaceKey", ">=", path13).where("namespaceKey", "<", path13 + "\uFFFF");
|
|
7135
7228
|
}
|
|
7136
7229
|
}
|
|
7137
7230
|
}
|
|
@@ -9173,6 +9266,162 @@ function debounceSync(syncManager, delay = 100) {
|
|
|
9173
9266
|
}, delay);
|
|
9174
9267
|
};
|
|
9175
9268
|
}
|
|
9269
|
+
var DEFAULT_MEMORY_DIR = path__default.join(os.homedir(), ".almadar", "memory");
|
|
9270
|
+
var LocalMemoryBackend = class {
|
|
9271
|
+
constructor(options = {}) {
|
|
9272
|
+
this.memoryDir = options.memoryDir ?? DEFAULT_MEMORY_DIR;
|
|
9273
|
+
fs3__default.mkdirSync(this.memoryDir, { recursive: true });
|
|
9274
|
+
}
|
|
9275
|
+
filePath(name) {
|
|
9276
|
+
return path__default.join(this.memoryDir, `${name}.orb`);
|
|
9277
|
+
}
|
|
9278
|
+
readInstances(name) {
|
|
9279
|
+
const fp = this.filePath(name);
|
|
9280
|
+
if (!fs3__default.existsSync(fp)) return [];
|
|
9281
|
+
try {
|
|
9282
|
+
const raw = JSON.parse(fs3__default.readFileSync(fp, "utf-8"));
|
|
9283
|
+
return raw?.orbitals?.[0]?.instances ?? [];
|
|
9284
|
+
} catch {
|
|
9285
|
+
return [];
|
|
9286
|
+
}
|
|
9287
|
+
}
|
|
9288
|
+
writeInstances(name, instances) {
|
|
9289
|
+
const schema = {
|
|
9290
|
+
name: `memory-${name}`,
|
|
9291
|
+
version: "1.0.0",
|
|
9292
|
+
orbitals: [
|
|
9293
|
+
{
|
|
9294
|
+
name,
|
|
9295
|
+
entity: { name, fields: [] },
|
|
9296
|
+
instances
|
|
9297
|
+
}
|
|
9298
|
+
]
|
|
9299
|
+
};
|
|
9300
|
+
fs3__default.writeFileSync(this.filePath(name), JSON.stringify(schema, null, 2));
|
|
9301
|
+
}
|
|
9302
|
+
// =========================================================================
|
|
9303
|
+
// Error Resolution Memory (ACTIVE)
|
|
9304
|
+
// =========================================================================
|
|
9305
|
+
async recordErrorResolution(resolution) {
|
|
9306
|
+
const instances = this.readInstances("errors");
|
|
9307
|
+
const id = `err_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
|
|
9308
|
+
const existing = instances.find(
|
|
9309
|
+
(e) => e.errorSignature === resolution.errorSignature
|
|
9310
|
+
);
|
|
9311
|
+
if (existing) {
|
|
9312
|
+
existing.resolution = resolution.resolution;
|
|
9313
|
+
existing.usageCount++;
|
|
9314
|
+
this.writeInstances("errors", instances);
|
|
9315
|
+
return existing.id;
|
|
9316
|
+
}
|
|
9317
|
+
instances.push({
|
|
9318
|
+
...resolution,
|
|
9319
|
+
id,
|
|
9320
|
+
createdAt: Date.now(),
|
|
9321
|
+
usageCount: 0
|
|
9322
|
+
});
|
|
9323
|
+
this.writeInstances("errors", instances);
|
|
9324
|
+
return id;
|
|
9325
|
+
}
|
|
9326
|
+
async findErrorResolution(errorSignature) {
|
|
9327
|
+
const instances = this.readInstances("errors");
|
|
9328
|
+
return instances.find((e) => e.errorSignature === errorSignature) ?? null;
|
|
9329
|
+
}
|
|
9330
|
+
async searchErrorResolutions(query) {
|
|
9331
|
+
const instances = this.readInstances("errors");
|
|
9332
|
+
const lower = query.toLowerCase();
|
|
9333
|
+
return instances.filter(
|
|
9334
|
+
(e) => e.errorMessage.toLowerCase().includes(lower) || e.errorSignature.toLowerCase().includes(lower) || e.resolution.toLowerCase().includes(lower)
|
|
9335
|
+
);
|
|
9336
|
+
}
|
|
9337
|
+
async getAllErrorResolutions() {
|
|
9338
|
+
return this.readInstances("errors");
|
|
9339
|
+
}
|
|
9340
|
+
// =========================================================================
|
|
9341
|
+
// User Preferences (STUBBED - returns empty until eval proves value)
|
|
9342
|
+
// =========================================================================
|
|
9343
|
+
async getUserPreferences(_userId) {
|
|
9344
|
+
return null;
|
|
9345
|
+
}
|
|
9346
|
+
async updateUserPreferences(_userId, _preferences) {
|
|
9347
|
+
}
|
|
9348
|
+
// =========================================================================
|
|
9349
|
+
// Generation Session History (ACTIVE)
|
|
9350
|
+
// =========================================================================
|
|
9351
|
+
async recordGeneration(_userId, session) {
|
|
9352
|
+
const instances = this.readInstances("sessions");
|
|
9353
|
+
const id = `gen_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
|
|
9354
|
+
instances.push({
|
|
9355
|
+
...session,
|
|
9356
|
+
id,
|
|
9357
|
+
userId: _userId,
|
|
9358
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
9359
|
+
});
|
|
9360
|
+
const trimmed = instances.slice(-50);
|
|
9361
|
+
this.writeInstances("sessions", trimmed);
|
|
9362
|
+
return id;
|
|
9363
|
+
}
|
|
9364
|
+
async getGenerationSession(sessionId) {
|
|
9365
|
+
const instances = this.readInstances("sessions");
|
|
9366
|
+
return instances.find((s) => s.id === sessionId) ?? null;
|
|
9367
|
+
}
|
|
9368
|
+
async getUserGenerationHistory(_userId, limit) {
|
|
9369
|
+
const instances = this.readInstances("sessions");
|
|
9370
|
+
const sorted = instances.sort(
|
|
9371
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
9372
|
+
);
|
|
9373
|
+
return limit ? sorted.slice(0, limit) : sorted;
|
|
9374
|
+
}
|
|
9375
|
+
// =========================================================================
|
|
9376
|
+
// Project Context (STUBBED)
|
|
9377
|
+
// =========================================================================
|
|
9378
|
+
async getProjectContext(_appId) {
|
|
9379
|
+
return null;
|
|
9380
|
+
}
|
|
9381
|
+
async updateProjectContext(_appId, _update) {
|
|
9382
|
+
}
|
|
9383
|
+
// =========================================================================
|
|
9384
|
+
// Pattern Affinity (STUBBED)
|
|
9385
|
+
// =========================================================================
|
|
9386
|
+
async updatePatternAffinity(_userId, _patternId, _outcome, _context) {
|
|
9387
|
+
}
|
|
9388
|
+
async getPatternAffinity(_userId, _patternId) {
|
|
9389
|
+
return null;
|
|
9390
|
+
}
|
|
9391
|
+
async getUserPatterns(_userId) {
|
|
9392
|
+
return [];
|
|
9393
|
+
}
|
|
9394
|
+
// =========================================================================
|
|
9395
|
+
// User Feedback (STUBBED)
|
|
9396
|
+
// =========================================================================
|
|
9397
|
+
async recordFeedback(_sessionId, _feedback) {
|
|
9398
|
+
}
|
|
9399
|
+
// =========================================================================
|
|
9400
|
+
// Interrupt / Tool Approval (STUBBED)
|
|
9401
|
+
// =========================================================================
|
|
9402
|
+
async recordInterruptDecision(_sessionId, _userId, _interruptData) {
|
|
9403
|
+
}
|
|
9404
|
+
async getSessionInterrupts(_sessionId) {
|
|
9405
|
+
return [];
|
|
9406
|
+
}
|
|
9407
|
+
async getToolApprovalPreference(_userId, _toolName) {
|
|
9408
|
+
return null;
|
|
9409
|
+
}
|
|
9410
|
+
async shouldAutoApproveTool(_userId, _toolName) {
|
|
9411
|
+
return false;
|
|
9412
|
+
}
|
|
9413
|
+
// =========================================================================
|
|
9414
|
+
// Checkpoints (STUBBED)
|
|
9415
|
+
// =========================================================================
|
|
9416
|
+
async recordCheckpoint(_userId, _checkpointData) {
|
|
9417
|
+
}
|
|
9418
|
+
async getUserCheckpoints(_userId, _limit) {
|
|
9419
|
+
return [];
|
|
9420
|
+
}
|
|
9421
|
+
async getThreadCheckpoints(_threadId) {
|
|
9422
|
+
return [];
|
|
9423
|
+
}
|
|
9424
|
+
};
|
|
9176
9425
|
var OnlineEvalSampler = class extends EventEmitter {
|
|
9177
9426
|
constructor(config = {}) {
|
|
9178
9427
|
super();
|
|
@@ -10113,10 +10362,10 @@ var SinkManager = class {
|
|
|
10113
10362
|
* Notify all sinks that a file was written.
|
|
10114
10363
|
* Returns results from each sink — failures in one don't affect others.
|
|
10115
10364
|
*/
|
|
10116
|
-
async notifyFileWritten(
|
|
10365
|
+
async notifyFileWritten(path13, content, meta) {
|
|
10117
10366
|
if (this.sinks.length === 0) return [];
|
|
10118
10367
|
const results = await Promise.allSettled(
|
|
10119
|
-
this.sinks.map((sink) => sink.onFileWritten(
|
|
10368
|
+
this.sinks.map((sink) => sink.onFileWritten(path13, content, meta))
|
|
10120
10369
|
);
|
|
10121
10370
|
return results.map((result, i) => ({
|
|
10122
10371
|
sinkName: this.sinks[i].name,
|
|
@@ -10305,11 +10554,11 @@ var GitSink = class {
|
|
|
10305
10554
|
getCwd() {
|
|
10306
10555
|
return this.client.getCwd();
|
|
10307
10556
|
}
|
|
10308
|
-
async onFileWritten(
|
|
10557
|
+
async onFileWritten(path13, _content, meta) {
|
|
10309
10558
|
if (!this.available) return;
|
|
10310
10559
|
this.commitQueue = this.commitQueue.then(async () => {
|
|
10311
|
-
const message = formatCommitMessage(
|
|
10312
|
-
await this.client.add([
|
|
10560
|
+
const message = formatCommitMessage(path13, meta);
|
|
10561
|
+
await this.client.add([path13]);
|
|
10313
10562
|
await this.client.commit(message);
|
|
10314
10563
|
});
|
|
10315
10564
|
await this.commitQueue;
|
|
@@ -10351,8 +10600,8 @@ var GitSink = class {
|
|
|
10351
10600
|
}
|
|
10352
10601
|
}
|
|
10353
10602
|
};
|
|
10354
|
-
function formatCommitMessage(
|
|
10355
|
-
const filename = basename(
|
|
10603
|
+
function formatCommitMessage(path13, meta) {
|
|
10604
|
+
const filename = basename(path13);
|
|
10356
10605
|
switch (meta.fileType) {
|
|
10357
10606
|
case "orbital":
|
|
10358
10607
|
return `add(${meta.orbitalName ?? filename}): orbital generated`;
|
|
@@ -10797,11 +11046,333 @@ async function executeSandboxedFallback(code, inputs, timeoutMs) {
|
|
|
10797
11046
|
return { success: false, error: message, timedOut };
|
|
10798
11047
|
}
|
|
10799
11048
|
}
|
|
11049
|
+
|
|
11050
|
+
// src/neural/index.ts
|
|
11051
|
+
init_masar_client();
|
|
11052
|
+
|
|
11053
|
+
// src/builder/builder-tools.ts
|
|
11054
|
+
function createBuilderTools(config) {
|
|
11055
|
+
const tools = [
|
|
11056
|
+
createValidateBuilderTool(config),
|
|
11057
|
+
createGenerateOrbitalBuilderTool(),
|
|
11058
|
+
createCombineOrbitalsBuilderTool(),
|
|
11059
|
+
createQueryStructureBuilderTool(),
|
|
11060
|
+
createAutoFixBuilderTool(config)
|
|
11061
|
+
];
|
|
11062
|
+
if (config.pythonExecutor) {
|
|
11063
|
+
tools.push(createNeuralGenerateBuilderTool());
|
|
11064
|
+
}
|
|
11065
|
+
return tools;
|
|
11066
|
+
}
|
|
11067
|
+
function createValidateBuilderTool(config) {
|
|
11068
|
+
return {
|
|
11069
|
+
name: "validate",
|
|
11070
|
+
description: "Validate an .orb schema. Returns errors and warnings.",
|
|
11071
|
+
parameters: {
|
|
11072
|
+
type: "object",
|
|
11073
|
+
properties: {
|
|
11074
|
+
schema: { type: "string", description: "The .orb schema JSON string to validate" }
|
|
11075
|
+
},
|
|
11076
|
+
required: ["schema"]
|
|
11077
|
+
},
|
|
11078
|
+
async execute(args) {
|
|
11079
|
+
const schema = args.schema;
|
|
11080
|
+
return config.executor.validateSchema(schema);
|
|
11081
|
+
}
|
|
11082
|
+
};
|
|
11083
|
+
}
|
|
11084
|
+
function createGenerateOrbitalBuilderTool() {
|
|
11085
|
+
return {
|
|
11086
|
+
name: "generate_orbital",
|
|
11087
|
+
description: "Generate a single orbital definition from a spec using an LLM subagent.",
|
|
11088
|
+
parameters: {
|
|
11089
|
+
type: "object",
|
|
11090
|
+
properties: {
|
|
11091
|
+
name: { type: "string", description: "Orbital name" },
|
|
11092
|
+
entityName: { type: "string", description: "Entity name (PascalCase)" },
|
|
11093
|
+
traitNames: { type: "array", description: "List of trait names" },
|
|
11094
|
+
fields: { type: "array", description: "Optional field definitions [{name, type, required?}]" },
|
|
11095
|
+
description: { type: "string", description: "Optional entity description" },
|
|
11096
|
+
provider: { type: "string", description: "LLM provider (deepseek, anthropic, openrouter)" },
|
|
11097
|
+
model: { type: "string", description: "LLM model name" }
|
|
11098
|
+
},
|
|
11099
|
+
required: ["name", "entityName", "traitNames"]
|
|
11100
|
+
},
|
|
11101
|
+
async execute(args) {
|
|
11102
|
+
const { getSubagentSystemPrompt: getSubagentSystemPrompt2 } = await import('@almadar/skills');
|
|
11103
|
+
const { LLMClient: LLMClient8 } = await import('@almadar/llm');
|
|
11104
|
+
const systemPrompt = getSubagentSystemPrompt2();
|
|
11105
|
+
const provider = args.provider ?? "deepseek";
|
|
11106
|
+
const model = args.model ?? "deepseek-chat";
|
|
11107
|
+
const fields = args.fields;
|
|
11108
|
+
const fieldsList = fields?.length ? fields.map((f) => ` - ${f.name}: ${f.type}${f.required ? " (required)" : ""}`).join("\n") : " (infer appropriate fields from the entity name and description)";
|
|
11109
|
+
const userPrompt = `Generate a complete FullOrbitalUnit for this orbital:
|
|
11110
|
+
|
|
11111
|
+
Name: ${args.name}
|
|
11112
|
+
Entity: ${args.entityName}
|
|
11113
|
+
Traits: ${args.traitNames.join(", ")}
|
|
11114
|
+
${args.description ? `Description: ${args.description}` : ""}
|
|
11115
|
+
|
|
11116
|
+
Fields:
|
|
11117
|
+
${fieldsList}
|
|
11118
|
+
|
|
11119
|
+
Return ONLY valid JSON matching the FullOrbitalUnit schema. No markdown fences, no explanation text.`;
|
|
11120
|
+
const client = new LLMClient8({
|
|
11121
|
+
provider,
|
|
11122
|
+
model
|
|
11123
|
+
});
|
|
11124
|
+
const text = await client.callRaw({
|
|
11125
|
+
systemPrompt,
|
|
11126
|
+
userPrompt,
|
|
11127
|
+
maxTokens: 8192
|
|
11128
|
+
});
|
|
11129
|
+
const orbital = extractJson(text);
|
|
11130
|
+
if (!orbital) {
|
|
11131
|
+
return { success: false, error: "Failed to parse orbital JSON from LLM response" };
|
|
11132
|
+
}
|
|
11133
|
+
const obj = orbital;
|
|
11134
|
+
if (!obj.name || !obj.entity || !obj.traits) {
|
|
11135
|
+
return { success: false, error: "Generated orbital missing required fields (name, entity, traits)" };
|
|
11136
|
+
}
|
|
11137
|
+
return { success: true, orbital };
|
|
11138
|
+
}
|
|
11139
|
+
};
|
|
11140
|
+
}
|
|
11141
|
+
function createCombineOrbitalsBuilderTool() {
|
|
11142
|
+
return {
|
|
11143
|
+
name: "combine_orbitals",
|
|
11144
|
+
description: "Combine multiple orbital definitions into a single .orb schema JSON string.",
|
|
11145
|
+
parameters: {
|
|
11146
|
+
type: "object",
|
|
11147
|
+
properties: {
|
|
11148
|
+
appName: { type: "string", description: "Application name" },
|
|
11149
|
+
orbitals: { type: "array", description: "Array of orbital definition objects" }
|
|
11150
|
+
},
|
|
11151
|
+
required: ["appName", "orbitals"]
|
|
11152
|
+
},
|
|
11153
|
+
async execute(args) {
|
|
11154
|
+
const orbitals = args.orbitals;
|
|
11155
|
+
const appName = args.appName;
|
|
11156
|
+
if (!orbitals.length) {
|
|
11157
|
+
return { success: false, error: "No orbitals provided" };
|
|
11158
|
+
}
|
|
11159
|
+
const schema = {
|
|
11160
|
+
name: appName,
|
|
11161
|
+
version: "1.0.0",
|
|
11162
|
+
orbitals
|
|
11163
|
+
};
|
|
11164
|
+
return {
|
|
11165
|
+
success: true,
|
|
11166
|
+
schema: JSON.stringify(schema, null, 2),
|
|
11167
|
+
orbitalCount: orbitals.length
|
|
11168
|
+
};
|
|
11169
|
+
}
|
|
11170
|
+
};
|
|
11171
|
+
}
|
|
11172
|
+
function createQueryStructureBuilderTool() {
|
|
11173
|
+
return {
|
|
11174
|
+
name: "query_structure",
|
|
11175
|
+
description: "Get a lightweight map of a schema (orbital names, entities, traits, field counts).",
|
|
11176
|
+
parameters: {
|
|
11177
|
+
type: "object",
|
|
11178
|
+
properties: {
|
|
11179
|
+
schema: { type: "string", description: "The .orb schema JSON string" }
|
|
11180
|
+
},
|
|
11181
|
+
required: ["schema"]
|
|
11182
|
+
},
|
|
11183
|
+
async execute(args) {
|
|
11184
|
+
try {
|
|
11185
|
+
const parsed = JSON.parse(args.schema);
|
|
11186
|
+
const orbitals = parsed.orbitals ?? [];
|
|
11187
|
+
return {
|
|
11188
|
+
name: parsed.name,
|
|
11189
|
+
orbitals: orbitals.map((o) => ({
|
|
11190
|
+
name: o.name,
|
|
11191
|
+
entityName: getEntityName5(o.entity),
|
|
11192
|
+
traits: getTraitNames2(o.traits ?? []),
|
|
11193
|
+
totalFields: countFields(o.entity),
|
|
11194
|
+
totalStates: countStates(o.traits ?? [])
|
|
11195
|
+
}))
|
|
11196
|
+
};
|
|
11197
|
+
} catch (err) {
|
|
11198
|
+
return { error: `Failed to parse schema: ${err instanceof Error ? err.message : String(err)}` };
|
|
11199
|
+
}
|
|
11200
|
+
}
|
|
11201
|
+
};
|
|
11202
|
+
}
|
|
11203
|
+
function createAutoFixBuilderTool(config) {
|
|
11204
|
+
return {
|
|
11205
|
+
name: "auto_fix",
|
|
11206
|
+
description: "Attempt to fix validation errors in a schema using LLM repair.",
|
|
11207
|
+
parameters: {
|
|
11208
|
+
type: "object",
|
|
11209
|
+
properties: {
|
|
11210
|
+
schema: { type: "string", description: "The .orb schema JSON string with errors" },
|
|
11211
|
+
errors: { type: "array", description: "Validation errors to fix [{code, message}]" },
|
|
11212
|
+
warnings: { type: "array", description: "Validation warnings to fix [{code, message}]" },
|
|
11213
|
+
provider: { type: "string", description: "LLM provider" },
|
|
11214
|
+
model: { type: "string", description: "LLM model" }
|
|
11215
|
+
},
|
|
11216
|
+
required: ["schema", "errors"]
|
|
11217
|
+
},
|
|
11218
|
+
async execute(args) {
|
|
11219
|
+
const { getSubagentSystemPrompt: getSubagentSystemPrompt2 } = await import('@almadar/skills');
|
|
11220
|
+
const { LLMClient: LLMClient8 } = await import('@almadar/llm');
|
|
11221
|
+
const orbitalKnowledge = getSubagentSystemPrompt2();
|
|
11222
|
+
const provider = args.provider ?? "deepseek";
|
|
11223
|
+
const model = args.model ?? "deepseek-chat";
|
|
11224
|
+
const errors = args.errors;
|
|
11225
|
+
const warnings = args.warnings ?? [];
|
|
11226
|
+
const issues = [
|
|
11227
|
+
...errors.map((e) => `ERROR [${e.code}]: ${e.message}`),
|
|
11228
|
+
...warnings.map((w) => `WARNING [${w.code}]: ${w.message}`)
|
|
11229
|
+
].join("\n");
|
|
11230
|
+
const client = new LLMClient8({
|
|
11231
|
+
provider,
|
|
11232
|
+
model
|
|
11233
|
+
});
|
|
11234
|
+
const text = await client.callRaw({
|
|
11235
|
+
systemPrompt: `You are a schema repair tool for .orb orbital schemas.
|
|
11236
|
+
|
|
11237
|
+
${orbitalKnowledge}
|
|
11238
|
+
|
|
11239
|
+
Return ONLY valid JSON.`,
|
|
11240
|
+
userPrompt: `Fix ALL validation errors and warnings in this schema.
|
|
11241
|
+
|
|
11242
|
+
ISSUES:
|
|
11243
|
+
${issues}
|
|
11244
|
+
|
|
11245
|
+
SCHEMA:
|
|
11246
|
+
${args.schema}
|
|
11247
|
+
|
|
11248
|
+
Return the COMPLETE corrected schema as valid JSON.`,
|
|
11249
|
+
maxTokens: 8192
|
|
11250
|
+
});
|
|
11251
|
+
const fixed = extractJson(text);
|
|
11252
|
+
if (!fixed) {
|
|
11253
|
+
return { success: false, error: "Failed to parse fixed schema from LLM response" };
|
|
11254
|
+
}
|
|
11255
|
+
const fixedStr = JSON.stringify(fixed, null, 2);
|
|
11256
|
+
const valResult = await config.executor.validateSchema(fixedStr);
|
|
11257
|
+
return {
|
|
11258
|
+
success: valResult.success,
|
|
11259
|
+
schema: fixedStr,
|
|
11260
|
+
remainingErrors: valResult.errors.length,
|
|
11261
|
+
remainingWarnings: valResult.warnings.length
|
|
11262
|
+
};
|
|
11263
|
+
}
|
|
11264
|
+
};
|
|
11265
|
+
}
|
|
11266
|
+
function createNeuralGenerateBuilderTool(config) {
|
|
11267
|
+
return {
|
|
11268
|
+
name: "neural_generate",
|
|
11269
|
+
description: "Generate a schema using the GFlowNet neural pipeline. Fast (2-10s) but best for simple apps (1-2 entities).",
|
|
11270
|
+
parameters: {
|
|
11271
|
+
type: "object",
|
|
11272
|
+
properties: {
|
|
11273
|
+
prompt: { type: "string", description: "Natural language description of the app to build" },
|
|
11274
|
+
provider: { type: "string", description: "LLM provider for goal parsing and auto-fix" },
|
|
11275
|
+
model: { type: "string", description: "LLM model" },
|
|
11276
|
+
samples: { type: "number", description: "Number of GFlowNet samples (default: 5)" },
|
|
11277
|
+
temperature: { type: "number", description: "Sampling temperature (default: 0.8)" }
|
|
11278
|
+
},
|
|
11279
|
+
required: ["prompt"]
|
|
11280
|
+
},
|
|
11281
|
+
async execute(args) {
|
|
11282
|
+
const { MasarClient: MasarClient2 } = await Promise.resolve().then(() => (init_masar_client(), masar_client_exports));
|
|
11283
|
+
const client = new MasarClient2({
|
|
11284
|
+
timeoutMs: 12e4
|
|
11285
|
+
});
|
|
11286
|
+
const result = await client.generate(args.prompt);
|
|
11287
|
+
return result;
|
|
11288
|
+
}
|
|
11289
|
+
};
|
|
11290
|
+
}
|
|
11291
|
+
function getEntityName5(entity) {
|
|
11292
|
+
if (!entity) return "Unknown";
|
|
11293
|
+
if (typeof entity === "string") return entity.replace(".entity", "");
|
|
11294
|
+
if (typeof entity === "object" && entity !== null && "name" in entity) {
|
|
11295
|
+
return entity.name;
|
|
11296
|
+
}
|
|
11297
|
+
return "Unknown";
|
|
11298
|
+
}
|
|
11299
|
+
function getTraitNames2(traits) {
|
|
11300
|
+
const names = [];
|
|
11301
|
+
for (const t of traits) {
|
|
11302
|
+
if (typeof t === "object" && t !== null) {
|
|
11303
|
+
if ("ref" in t) names.push(t.ref);
|
|
11304
|
+
else if ("name" in t) names.push(t.name);
|
|
11305
|
+
}
|
|
11306
|
+
}
|
|
11307
|
+
return names;
|
|
11308
|
+
}
|
|
11309
|
+
function countFields(entity) {
|
|
11310
|
+
if (!entity || typeof entity !== "object") return 0;
|
|
11311
|
+
const e = entity;
|
|
11312
|
+
return Array.isArray(e.fields) ? e.fields.length : 0;
|
|
11313
|
+
}
|
|
11314
|
+
function countStates(traits) {
|
|
11315
|
+
let total = 0;
|
|
11316
|
+
for (const t of traits) {
|
|
11317
|
+
if (typeof t === "object" && t !== null && "stateMachine" in t) {
|
|
11318
|
+
const sm = t.stateMachine;
|
|
11319
|
+
if (sm?.states) total += sm.states.length;
|
|
11320
|
+
}
|
|
11321
|
+
}
|
|
11322
|
+
return total;
|
|
11323
|
+
}
|
|
11324
|
+
function extractJson(text) {
|
|
11325
|
+
try {
|
|
11326
|
+
return JSON.parse(text.trim());
|
|
11327
|
+
} catch {
|
|
11328
|
+
}
|
|
11329
|
+
const fenceMatch = /```(?:json)?\s*\n?([\s\S]*?)\n?```/.exec(text);
|
|
11330
|
+
if (fenceMatch) {
|
|
11331
|
+
try {
|
|
11332
|
+
return JSON.parse(fenceMatch[1].trim());
|
|
11333
|
+
} catch {
|
|
11334
|
+
}
|
|
11335
|
+
}
|
|
11336
|
+
const braceStart = text.indexOf("{");
|
|
11337
|
+
if (braceStart >= 0) {
|
|
11338
|
+
let depth = 0;
|
|
11339
|
+
let inString = false;
|
|
11340
|
+
let escape = false;
|
|
11341
|
+
for (let i = braceStart; i < text.length; i++) {
|
|
11342
|
+
const ch = text[i];
|
|
11343
|
+
if (escape) {
|
|
11344
|
+
escape = false;
|
|
11345
|
+
continue;
|
|
11346
|
+
}
|
|
11347
|
+
if (ch === "\\" && inString) {
|
|
11348
|
+
escape = true;
|
|
11349
|
+
continue;
|
|
11350
|
+
}
|
|
11351
|
+
if (ch === '"') {
|
|
11352
|
+
inString = !inString;
|
|
11353
|
+
continue;
|
|
11354
|
+
}
|
|
11355
|
+
if (inString) continue;
|
|
11356
|
+
if (ch === "{") depth++;
|
|
11357
|
+
if (ch === "}") {
|
|
11358
|
+
depth--;
|
|
11359
|
+
if (depth === 0) {
|
|
11360
|
+
try {
|
|
11361
|
+
return JSON.parse(text.slice(braceStart, i + 1));
|
|
11362
|
+
} catch {
|
|
11363
|
+
}
|
|
11364
|
+
break;
|
|
11365
|
+
}
|
|
11366
|
+
}
|
|
11367
|
+
}
|
|
11368
|
+
}
|
|
11369
|
+
return null;
|
|
11370
|
+
}
|
|
10800
11371
|
var export_applySectionUpdate = domain_language_exports.applySectionUpdate;
|
|
10801
11372
|
var export_convertDomainToSchema = domain_language_exports.convertDomainToSchema;
|
|
10802
11373
|
var export_convertSchemaToDomain = domain_language_exports.convertSchemaToDomain;
|
|
10803
11374
|
var export_deleteSection = domain_language_exports.deleteSection;
|
|
10804
11375
|
|
|
10805
|
-
export { AgenticSearchEngine, AuditLog, CRITICAL_COMMAND_PATTERNS, CircuitBreaker, CircuitState, ContinueRequestSchema, DEFAULT_COMPACTION_CONFIG, EVENT_BUDGETS, ExtractedRequirementsSchema, FirestoreCheckpointer, FirestoreSessionStore, FirestoreSink, FirestoreStore, GenerateRequestSchema, GitClient, GitSink, MemoryManager, MemoryOrbitalSchema, MemorySessionBackend, MetricsCollector, MultiUserManager, ObservabilityCollector, OnlineEvalSampler, PreferenceLearner, RateLimiter, ResumeRequestSchema, SessionManager, SinkManager, StateSyncManager, TOOL_GATES, ThresholdAuthorizer, WORKSPACE_LAYOUT, WorkflowBuilder, WorkflowEngine, WorkspaceManager, analyzeFailures, export_applySectionUpdate as applySectionUpdate, classifyCommand, classifyComplexity, combineOrbitals, combineOrbitalsToSchema, consumeToken, export_convertDomainToSchema as convertDomainToSchema, export_convertSchemaToDomain as convertSchemaToDomain, createAgentTools, createAgenticSearchEngine, createApplyChunkTool, createCombineSchemasTool, createConstructCombinedDomainTool, createDomainOrbitalTools, createErrorFixerSubagent, createEvalWorkflowWrapper, createExecuteTool, createExtractChunkTool, createFinishTaskTool, createGenerateOrbitalDomainTool, createGenerateSchemaTool, createOnlineEvalSampler, createOrbitalSubagentTool, createPreferenceLearner, createProjectOrbTemplate, createQuerySchemaStructureTool, createSSEEvent, createSchemaChunkingTools, createSchemaGenerationWorkflow, createSchemaGeneratorSubagent, createSchemaOrbTemplate, createSkillAgent, createSubagentConfigs, createSubagentEventWrapper, createSubagents, createSummaryPrompt, createTestAnalyzerSubagent, createTraitEventWrapper, createTraitSubagentTool, createUserContext, createUserOrbTemplate, createValidateSchemaTool, createWorkflowEngine, createWorkflowToolWrapper, debounceSync, export_deleteSection as deleteSection, endObservabilitySession, estimateCacheSavings, estimateCombineComplexity, estimateComplexity, estimateTokens, executeSandboxed, extractFileOperation, extractInterruptData, formatSSEEvent, formatSummary, generateFullOrbital, getBudgetWarningMessage, getEventBudget, getExecutionStrategy, getInterruptConfig, getMultiUserManager, getObservabilityCollector, getPerformanceSnapshot, getStateSyncManager, hasInterrupt, isAdmin, isCompleteEvent, isErrorEvent, isExecutionEvent, isFileOperation, isSSECompleteEvent, isSSEErrorEvent, isSSEGenerationLogEvent, isSSEInterruptEvent, isSSEMessageEvent, isSSEStartEvent, isSSESubagentEvent, isSSETodoDetailEvent, isSSETodoUpdateEvent, isSSEToolCallEvent, isSchemaEvent, isStartEvent, isTodoUpdate, isTokenValid, issueToken, needsCompaction, parseDeepAgentEvent, parseOrb, parseSSEEvent, quickComplexityCheck, readOrb, readOrbInstances, recordEvent, requireOwnership, resetMultiUserManager, resetObservabilityCollector, resetStateSyncManager, resumeSkillAgent, reviewSamples, revokeToken, routeGeneration, serializeOrb, startObservabilitySession, transformAgentEvent, transformAgentEventMulti, validateCommandPaths, verifyToken, withSync, writeOrb, writeOrbInstances };
|
|
11376
|
+
export { AgenticSearchEngine, AuditLog, CRITICAL_COMMAND_PATTERNS, CircuitBreaker, CircuitState, ContinueRequestSchema, DEFAULT_COMPACTION_CONFIG, EVENT_BUDGETS, ExtractedRequirementsSchema, FirestoreCheckpointer, FirestoreSessionStore, FirestoreSink, FirestoreStore, GenerateRequestSchema, GitClient, GitSink, LocalMemoryBackend, MasarClient, MemoryManager, MemoryOrbitalSchema, MemorySessionBackend, MetricsCollector, MultiUserManager, ObservabilityCollector, OnlineEvalSampler, PreferenceLearner, RateLimiter, ResumeRequestSchema, SessionManager, SinkManager, StateSyncManager, TOOL_GATES, ThresholdAuthorizer, WORKSPACE_LAYOUT, WorkflowBuilder, WorkflowEngine, WorkspaceManager, analyzeFailures, export_applySectionUpdate as applySectionUpdate, classifyCommand, classifyComplexity, combineOrbitals, combineOrbitalsToSchema, consumeToken, export_convertDomainToSchema as convertDomainToSchema, export_convertSchemaToDomain as convertSchemaToDomain, createAgentTools, createAgenticSearchEngine, createApplyChunkTool, createBuilderTools, createCombineSchemasTool, createConstructCombinedDomainTool, createDomainOrbitalTools, createErrorFixerSubagent, createEvalWorkflowWrapper, createExecuteTool, createExtractChunkTool, createFinishTaskTool, createGenerateOrbitalDomainTool, createGenerateSchemaTool, createOnlineEvalSampler, createOrbitalSubagentTool, createPreferenceLearner, createProjectOrbTemplate, createQuerySchemaStructureTool, createSSEEvent, createSchemaChunkingTools, createSchemaGenerationWorkflow, createSchemaGeneratorSubagent, createSchemaOrbTemplate, createSkillAgent, createSubagentConfigs, createSubagentEventWrapper, createSubagents, createSummaryPrompt, createTestAnalyzerSubagent, createTraitEventWrapper, createTraitSubagentTool, createUserContext, createUserOrbTemplate, createValidateSchemaTool, createWorkflowEngine, createWorkflowToolWrapper, debounceSync, export_deleteSection as deleteSection, endObservabilitySession, estimateCacheSavings, estimateCombineComplexity, estimateComplexity, estimateTokens, executeSandboxed, extractFileOperation, extractInterruptData, formatSSEEvent, formatSummary, generateFullOrbital, getBudgetWarningMessage, getEventBudget, getExecutionStrategy, getInterruptConfig, getMultiUserManager, getObservabilityCollector, getPerformanceSnapshot, getStateSyncManager, hasInterrupt, isAdmin, isCompleteEvent, isErrorEvent, isExecutionEvent, isFileOperation, isSSECompleteEvent, isSSEErrorEvent, isSSEGenerationLogEvent, isSSEInterruptEvent, isSSEMessageEvent, isSSEStartEvent, isSSESubagentEvent, isSSETodoDetailEvent, isSSETodoUpdateEvent, isSSEToolCallEvent, isSchemaEvent, isStartEvent, isTodoUpdate, isTokenValid, issueToken, needsCompaction, parseDeepAgentEvent, parseOrb, parseSSEEvent, quickComplexityCheck, readOrb, readOrbInstances, recordEvent, requireOwnership, resetMultiUserManager, resetObservabilityCollector, resetStateSyncManager, resumeSkillAgent, reviewSamples, revokeToken, routeGeneration, serializeOrb, startObservabilitySession, transformAgentEvent, transformAgentEventMulti, validateCommandPaths, verifyToken, withSync, writeOrb, writeOrbInstances };
|
|
10806
11377
|
//# sourceMappingURL=index.js.map
|
|
10807
11378
|
//# sourceMappingURL=index.js.map
|