@axiom-lattice/core 2.1.14 → 2.1.16

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.mjs CHANGED
@@ -1120,14 +1120,884 @@ ${trimmedQuery}
1120
1120
  }
1121
1121
  );
1122
1122
 
1123
+ // src/tool_lattice/load_skills/index.ts
1124
+ import z7 from "zod";
1125
+
1126
+ // src/store_lattice/InMemoryThreadStore.ts
1127
+ var InMemoryThreadStore = class {
1128
+ constructor() {
1129
+ // Map<assistantId, Map<threadId, Thread>>
1130
+ this.threads = /* @__PURE__ */ new Map();
1131
+ }
1132
+ /**
1133
+ * Get all threads for a specific assistant
1134
+ */
1135
+ async getThreadsByAssistantId(assistantId) {
1136
+ const assistantThreads = this.threads.get(assistantId);
1137
+ if (!assistantThreads) {
1138
+ return [];
1139
+ }
1140
+ return Array.from(assistantThreads.values());
1141
+ }
1142
+ /**
1143
+ * Get a thread by ID for a specific assistant
1144
+ */
1145
+ async getThreadById(assistantId, threadId) {
1146
+ const assistantThreads = this.threads.get(assistantId);
1147
+ if (!assistantThreads) {
1148
+ return void 0;
1149
+ }
1150
+ return assistantThreads.get(threadId);
1151
+ }
1152
+ /**
1153
+ * Create a new thread for an assistant
1154
+ */
1155
+ async createThread(assistantId, threadId, data) {
1156
+ const now = /* @__PURE__ */ new Date();
1157
+ const thread = {
1158
+ id: threadId,
1159
+ assistantId,
1160
+ metadata: data.metadata || {},
1161
+ createdAt: now,
1162
+ updatedAt: now
1163
+ };
1164
+ if (!this.threads.has(assistantId)) {
1165
+ this.threads.set(assistantId, /* @__PURE__ */ new Map());
1166
+ }
1167
+ const assistantThreads = this.threads.get(assistantId);
1168
+ assistantThreads.set(threadId, thread);
1169
+ return thread;
1170
+ }
1171
+ /**
1172
+ * Update an existing thread
1173
+ */
1174
+ async updateThread(assistantId, threadId, updates) {
1175
+ const assistantThreads = this.threads.get(assistantId);
1176
+ if (!assistantThreads) {
1177
+ return null;
1178
+ }
1179
+ const existing = assistantThreads.get(threadId);
1180
+ if (!existing) {
1181
+ return null;
1182
+ }
1183
+ const updated = {
1184
+ ...existing,
1185
+ metadata: {
1186
+ ...existing.metadata,
1187
+ ...updates.metadata || {}
1188
+ },
1189
+ updatedAt: /* @__PURE__ */ new Date()
1190
+ };
1191
+ assistantThreads.set(threadId, updated);
1192
+ return updated;
1193
+ }
1194
+ /**
1195
+ * Delete a thread by ID
1196
+ */
1197
+ async deleteThread(assistantId, threadId) {
1198
+ const assistantThreads = this.threads.get(assistantId);
1199
+ if (!assistantThreads) {
1200
+ return false;
1201
+ }
1202
+ return assistantThreads.delete(threadId);
1203
+ }
1204
+ /**
1205
+ * Check if thread exists
1206
+ */
1207
+ async hasThread(assistantId, threadId) {
1208
+ const assistantThreads = this.threads.get(assistantId);
1209
+ if (!assistantThreads) {
1210
+ return false;
1211
+ }
1212
+ return assistantThreads.has(threadId);
1213
+ }
1214
+ /**
1215
+ * Clear all threads (useful for testing)
1216
+ */
1217
+ clear() {
1218
+ this.threads.clear();
1219
+ }
1220
+ /**
1221
+ * Get all threads for all assistants (useful for debugging)
1222
+ */
1223
+ getAllThreads() {
1224
+ const allThreads = [];
1225
+ for (const assistantThreads of this.threads.values()) {
1226
+ allThreads.push(...Array.from(assistantThreads.values()));
1227
+ }
1228
+ return allThreads;
1229
+ }
1230
+ };
1231
+
1232
+ // src/store_lattice/InMemoryAssistantStore.ts
1233
+ var InMemoryAssistantStore = class {
1234
+ constructor() {
1235
+ this.assistants = /* @__PURE__ */ new Map();
1236
+ }
1237
+ /**
1238
+ * Get all assistants
1239
+ */
1240
+ async getAllAssistants() {
1241
+ return Array.from(this.assistants.values());
1242
+ }
1243
+ /**
1244
+ * Get assistant by ID
1245
+ */
1246
+ async getAssistantById(id) {
1247
+ return this.assistants.get(id) || null;
1248
+ }
1249
+ /**
1250
+ * Create a new assistant
1251
+ */
1252
+ async createAssistant(id, data) {
1253
+ const now = /* @__PURE__ */ new Date();
1254
+ const assistant = {
1255
+ id,
1256
+ name: data.name,
1257
+ description: data.description,
1258
+ graphDefinition: data.graphDefinition,
1259
+ createdAt: now,
1260
+ updatedAt: now
1261
+ };
1262
+ this.assistants.set(id, assistant);
1263
+ return assistant;
1264
+ }
1265
+ /**
1266
+ * Update an existing assistant
1267
+ */
1268
+ async updateAssistant(id, updates) {
1269
+ const existing = this.assistants.get(id);
1270
+ if (!existing) {
1271
+ return null;
1272
+ }
1273
+ const updated = {
1274
+ ...existing,
1275
+ ...updates,
1276
+ updatedAt: /* @__PURE__ */ new Date()
1277
+ };
1278
+ this.assistants.set(id, updated);
1279
+ return updated;
1280
+ }
1281
+ /**
1282
+ * Delete an assistant by ID
1283
+ */
1284
+ async deleteAssistant(id) {
1285
+ return this.assistants.delete(id);
1286
+ }
1287
+ /**
1288
+ * Check if assistant exists
1289
+ */
1290
+ async hasAssistant(id) {
1291
+ return this.assistants.has(id);
1292
+ }
1293
+ /**
1294
+ * Clear all assistants (useful for testing)
1295
+ */
1296
+ clear() {
1297
+ this.assistants.clear();
1298
+ }
1299
+ };
1300
+
1301
+ // src/store_lattice/FileSystemSkillStore.ts
1302
+ import * as fs from "fs/promises";
1303
+ import * as path from "path";
1304
+
1305
+ // src/skill_lattice/skillNameValidator.ts
1306
+ var SKILL_NAME_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
1307
+ var MIN_LENGTH = 1;
1308
+ var MAX_LENGTH = 64;
1309
+ function isValidSkillName(name) {
1310
+ if (!name || typeof name !== "string") {
1311
+ return false;
1312
+ }
1313
+ if (name.length < MIN_LENGTH || name.length > MAX_LENGTH) {
1314
+ return false;
1315
+ }
1316
+ return SKILL_NAME_REGEX.test(name);
1317
+ }
1318
+ function validateSkillName(name) {
1319
+ if (!name || typeof name !== "string") {
1320
+ throw new Error("Skill name is required and must be a string");
1321
+ }
1322
+ if (name.length < MIN_LENGTH || name.length > MAX_LENGTH) {
1323
+ throw new Error(
1324
+ `Skill name must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters`
1325
+ );
1326
+ }
1327
+ if (!SKILL_NAME_REGEX.test(name)) {
1328
+ throw new Error(
1329
+ "Skill name must be lowercase alphanumeric with single hyphen separators, not start or end with -, and not contain consecutive --. Pattern: ^[a-z0-9]+(-[a-z0-9]+)*$"
1330
+ );
1331
+ }
1332
+ }
1333
+
1334
+ // src/store_lattice/FileSystemSkillStore.ts
1335
+ function parseFrontmatter(content) {
1336
+ const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/;
1337
+ const match = content.match(frontmatterRegex);
1338
+ if (!match) {
1339
+ console.warn("[parseFrontmatter] No frontmatter match found in content");
1340
+ return { frontmatter: {}, body: content };
1341
+ }
1342
+ const frontmatterText = match[1];
1343
+ const body = match[2] || "";
1344
+ const frontmatter = {};
1345
+ const lines = frontmatterText.split("\n");
1346
+ let currentKey = null;
1347
+ let metadataIndent = 0;
1348
+ for (let i = 0; i < lines.length; i++) {
1349
+ const line = lines[i];
1350
+ const trimmed = line.trim();
1351
+ if (!trimmed || trimmed.startsWith("#")) {
1352
+ continue;
1353
+ }
1354
+ const indentMatch = line.match(/^(\s*)/);
1355
+ const indent = indentMatch ? indentMatch[1].length : 0;
1356
+ if (currentKey === "metadata" && indent > metadataIndent) {
1357
+ const colonIndex2 = trimmed.indexOf(":");
1358
+ if (colonIndex2 !== -1) {
1359
+ const key2 = trimmed.substring(0, colonIndex2).trim();
1360
+ let value2 = trimmed.substring(colonIndex2 + 1).trim();
1361
+ if (value2.startsWith('"') && value2.endsWith('"') || value2.startsWith("'") && value2.endsWith("'")) {
1362
+ value2 = value2.slice(1, -1);
1363
+ }
1364
+ if (!frontmatter.metadata) {
1365
+ frontmatter.metadata = {};
1366
+ }
1367
+ frontmatter.metadata[key2] = value2;
1368
+ }
1369
+ continue;
1370
+ }
1371
+ if (currentKey === "subSkills" && indent > metadataIndent) {
1372
+ if (trimmed.startsWith("-")) {
1373
+ let value2 = trimmed.substring(1).trim();
1374
+ if (value2.startsWith('"') && value2.endsWith('"') || value2.startsWith("'") && value2.endsWith("'")) {
1375
+ value2 = value2.slice(1, -1);
1376
+ }
1377
+ if (!frontmatter.subSkills) {
1378
+ frontmatter.subSkills = [];
1379
+ }
1380
+ frontmatter.subSkills.push(value2);
1381
+ }
1382
+ continue;
1383
+ }
1384
+ if ((currentKey === "metadata" || currentKey === "subSkills") && indent <= metadataIndent) {
1385
+ currentKey = null;
1386
+ metadataIndent = 0;
1387
+ }
1388
+ const colonIndex = trimmed.indexOf(":");
1389
+ if (colonIndex === -1) {
1390
+ continue;
1391
+ }
1392
+ const key = trimmed.substring(0, colonIndex).trim();
1393
+ let value = trimmed.substring(colonIndex + 1).trim();
1394
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
1395
+ value = value.slice(1, -1);
1396
+ }
1397
+ if (key === "metadata") {
1398
+ if (value === "" || value === "{}") {
1399
+ if (i + 1 < lines.length) {
1400
+ const nextLine = lines[i + 1];
1401
+ const nextIndent = nextLine.match(/^(\s*)/)?.[1].length || 0;
1402
+ if (nextIndent > indent) {
1403
+ currentKey = "metadata";
1404
+ metadataIndent = indent;
1405
+ frontmatter.metadata = {};
1406
+ continue;
1407
+ }
1408
+ }
1409
+ frontmatter[key] = {};
1410
+ } else if (value.startsWith("{")) {
1411
+ try {
1412
+ frontmatter[key] = JSON.parse(value);
1413
+ } catch {
1414
+ frontmatter[key] = {};
1415
+ }
1416
+ } else {
1417
+ frontmatter[key] = {};
1418
+ }
1419
+ } else if (key === "subSkills") {
1420
+ if (value === "" || value === "[]") {
1421
+ if (i + 1 < lines.length) {
1422
+ const nextLine = lines[i + 1];
1423
+ const nextIndent = nextLine.match(/^(\s*)/)?.[1].length || 0;
1424
+ if (nextIndent > indent && nextLine.trim().startsWith("-")) {
1425
+ currentKey = "subSkills";
1426
+ metadataIndent = indent;
1427
+ frontmatter.subSkills = [];
1428
+ continue;
1429
+ }
1430
+ }
1431
+ frontmatter[key] = [];
1432
+ } else if (value.startsWith("[")) {
1433
+ try {
1434
+ frontmatter[key] = JSON.parse(value);
1435
+ } catch {
1436
+ frontmatter[key] = [];
1437
+ }
1438
+ } else {
1439
+ frontmatter[key] = [];
1440
+ }
1441
+ } else {
1442
+ frontmatter[key] = value;
1443
+ }
1444
+ }
1445
+ return { frontmatter, body };
1446
+ }
1447
+ function generateFrontmatter(data) {
1448
+ const lines = ["---"];
1449
+ lines.push(`name: ${data.name}`);
1450
+ lines.push(`description: ${data.description}`);
1451
+ if (data.license) {
1452
+ lines.push(`license: ${data.license}`);
1453
+ }
1454
+ if (data.compatibility) {
1455
+ lines.push(`compatibility: ${data.compatibility}`);
1456
+ }
1457
+ if (data.metadata && Object.keys(data.metadata).length > 0) {
1458
+ lines.push("metadata:");
1459
+ for (const [key, value] of Object.entries(data.metadata)) {
1460
+ lines.push(` ${key}: ${value}`);
1461
+ }
1462
+ }
1463
+ if (data.subSkills && data.subSkills.length > 0) {
1464
+ lines.push("subSkills:");
1465
+ for (const subSkill of data.subSkills) {
1466
+ lines.push(` - ${subSkill}`);
1467
+ }
1468
+ }
1469
+ lines.push("---");
1470
+ return lines.join("\n");
1471
+ }
1472
+ var FileSystemSkillStore = class {
1473
+ constructor(options = {}) {
1474
+ const defaultPath = "lattice_store/skills";
1475
+ const providedPath = options.rootDir || defaultPath;
1476
+ if (path.isAbsolute(providedPath)) {
1477
+ this.rootDir = providedPath;
1478
+ } else {
1479
+ this.rootDir = path.resolve(process.cwd(), providedPath);
1480
+ }
1481
+ this.ensureDirectoryExists().catch((error) => {
1482
+ console.error("Failed to initialize FileSystemSkillStore:", error);
1483
+ });
1484
+ }
1485
+ /**
1486
+ * Ensure the root directory exists
1487
+ */
1488
+ async ensureDirectoryExists() {
1489
+ try {
1490
+ await fs.access(this.rootDir);
1491
+ } catch {
1492
+ await fs.mkdir(this.rootDir, { recursive: true });
1493
+ }
1494
+ }
1495
+ /**
1496
+ * Get directory path for a skill name
1497
+ * Name is used as the directory name, and SKILL.md is the fixed filename
1498
+ */
1499
+ getSkillDirectoryPath(name) {
1500
+ if (name.includes("..") || name.includes("/") || name.includes("\\")) {
1501
+ throw new Error(`Invalid skill name: ${name} (contains invalid characters)`);
1502
+ }
1503
+ return path.join(this.rootDir, name);
1504
+ }
1505
+ /**
1506
+ * Get file path for a skill name
1507
+ * File is always named SKILL.md inside the name directory
1508
+ */
1509
+ getSkillFilePath(name) {
1510
+ return path.join(this.getSkillDirectoryPath(name), "SKILL.md");
1511
+ }
1512
+ /**
1513
+ * Read skill from file
1514
+ * Uses name as the directory name and reads SKILL.md from it
1515
+ */
1516
+ async readSkillFile(name) {
1517
+ await this.ensureDirectoryExists();
1518
+ const filePath = this.getSkillFilePath(name);
1519
+ try {
1520
+ const content = await fs.readFile(filePath, "utf-8");
1521
+ const { frontmatter, body } = parseFrontmatter(content);
1522
+ if (!frontmatter.name || !frontmatter.description) {
1523
+ console.warn(
1524
+ `Skill file ${name} parsed frontmatter:`,
1525
+ JSON.stringify(frontmatter, null, 2)
1526
+ );
1527
+ console.warn(`Raw frontmatter text (first 200 chars):`, content.substring(0, 200));
1528
+ }
1529
+ const stats = await fs.stat(filePath);
1530
+ if (!frontmatter.name || !frontmatter.description) {
1531
+ throw new Error(
1532
+ `Invalid skill file ${name}: missing required fields (name or description). Frontmatter: ${JSON.stringify(frontmatter)}`
1533
+ );
1534
+ }
1535
+ if (frontmatter.name !== name) {
1536
+ throw new Error(
1537
+ `Skill name mismatch: directory name is "${name}" but frontmatter name is "${frontmatter.name}"`
1538
+ );
1539
+ }
1540
+ return {
1541
+ id: name,
1542
+ // id equals name (name is used for path addressing)
1543
+ name: frontmatter.name,
1544
+ description: frontmatter.description,
1545
+ license: frontmatter.license,
1546
+ compatibility: frontmatter.compatibility,
1547
+ metadata: frontmatter.metadata || {},
1548
+ content: body.trim() || void 0,
1549
+ subSkills: Array.isArray(frontmatter.subSkills) ? frontmatter.subSkills : void 0,
1550
+ createdAt: stats.birthtime,
1551
+ updatedAt: stats.mtime
1552
+ };
1553
+ } catch (error) {
1554
+ if (error.code === "ENOENT") {
1555
+ console.warn(`Skill file not found: ${filePath}`);
1556
+ return null;
1557
+ }
1558
+ const errorMessage = error instanceof Error ? error.message : String(error);
1559
+ throw new Error(`Failed to read skill file ${filePath}: ${errorMessage}`);
1560
+ }
1561
+ }
1562
+ /**
1563
+ * Write skill to file
1564
+ * Creates directory with name and writes SKILL.md inside it
1565
+ */
1566
+ async writeSkillFile(skill) {
1567
+ await this.ensureDirectoryExists();
1568
+ const skillName = skill.name;
1569
+ const skillDir = this.getSkillDirectoryPath(skillName);
1570
+ const filePath = this.getSkillFilePath(skillName);
1571
+ try {
1572
+ await fs.mkdir(skillDir, { recursive: true });
1573
+ } catch (error) {
1574
+ }
1575
+ const frontmatter = generateFrontmatter({
1576
+ name: skillName,
1577
+ description: skill.description,
1578
+ license: skill.license,
1579
+ compatibility: skill.compatibility,
1580
+ metadata: skill.metadata,
1581
+ subSkills: skill.subSkills
1582
+ });
1583
+ const body = skill.content || "";
1584
+ const content = body ? `${frontmatter}
1585
+ ${body}` : `${frontmatter}
1586
+ `;
1587
+ await fs.writeFile(filePath, content, "utf-8");
1588
+ }
1589
+ /**
1590
+ * Get all skills
1591
+ */
1592
+ async getAllSkills() {
1593
+ await this.ensureDirectoryExists();
1594
+ try {
1595
+ const entries = await fs.readdir(this.rootDir, { withFileTypes: true });
1596
+ const skills = [];
1597
+ for (const entry of entries) {
1598
+ if (entry.isDirectory()) {
1599
+ const skillName = entry.name;
1600
+ try {
1601
+ const skill = await this.readSkillFile(skillName);
1602
+ if (skill) {
1603
+ skills.push(skill);
1604
+ } else {
1605
+ console.warn(
1606
+ `Failed to load skill "${skillName}": readSkillFile returned null`
1607
+ );
1608
+ }
1609
+ } catch (error) {
1610
+ console.error(
1611
+ `Error loading skill "${skillName}" from ${this.getSkillFilePath(skillName)}:`,
1612
+ error instanceof Error ? error.message : String(error)
1613
+ );
1614
+ }
1615
+ }
1616
+ }
1617
+ return skills.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
1618
+ } catch (error) {
1619
+ if (error.code === "ENOENT") {
1620
+ console.warn(
1621
+ `Skills directory not found: ${this.rootDir}`
1622
+ );
1623
+ return [];
1624
+ }
1625
+ throw error;
1626
+ }
1627
+ }
1628
+ /**
1629
+ * Get skill by ID
1630
+ * ID should equal name (name is used for path addressing)
1631
+ */
1632
+ async getSkillById(id) {
1633
+ return this.readSkillFile(id);
1634
+ }
1635
+ /**
1636
+ * Create a new skill
1637
+ * id should equal name (name is used for path addressing)
1638
+ */
1639
+ async createSkill(id, data) {
1640
+ await this.ensureDirectoryExists();
1641
+ validateSkillName(data.name);
1642
+ if (id !== data.name) {
1643
+ throw new Error(
1644
+ `Skill id "${id}" must equal name "${data.name}" (name is used for path addressing)`
1645
+ );
1646
+ }
1647
+ const existing = await this.getSkillById(id);
1648
+ if (existing) {
1649
+ return this.updateSkill(id, data);
1650
+ }
1651
+ const now = /* @__PURE__ */ new Date();
1652
+ const skill = {
1653
+ id: data.name,
1654
+ // id equals name
1655
+ name: data.name,
1656
+ description: data.description,
1657
+ license: data.license,
1658
+ compatibility: data.compatibility,
1659
+ metadata: data.metadata || {},
1660
+ content: data.content,
1661
+ subSkills: data.subSkills,
1662
+ createdAt: now,
1663
+ updatedAt: now
1664
+ };
1665
+ await this.writeSkillFile(skill);
1666
+ return skill;
1667
+ }
1668
+ /**
1669
+ * Update an existing skill
1670
+ */
1671
+ async updateSkill(id, updates) {
1672
+ const skill = await this.readSkillFile(id);
1673
+ if (!skill) {
1674
+ return null;
1675
+ }
1676
+ if (updates.name !== void 0) {
1677
+ validateSkillName(updates.name);
1678
+ if (updates.name !== skill.name) {
1679
+ const oldDir = this.getSkillDirectoryPath(skill.name);
1680
+ const newDir = this.getSkillDirectoryPath(updates.name);
1681
+ try {
1682
+ await fs.rename(oldDir, newDir);
1683
+ } catch (error) {
1684
+ throw new Error(
1685
+ `Failed to rename skill directory from "${skill.name}" to "${updates.name}": ${error instanceof Error ? error.message : String(error)}`
1686
+ );
1687
+ }
1688
+ }
1689
+ }
1690
+ const updatedSkill = {
1691
+ ...skill,
1692
+ name: updates.name ?? skill.name,
1693
+ id: updates.name ?? skill.id,
1694
+ // id equals name
1695
+ description: updates.description ?? skill.description,
1696
+ license: updates.license ?? skill.license,
1697
+ compatibility: updates.compatibility ?? skill.compatibility,
1698
+ metadata: updates.metadata ?? skill.metadata,
1699
+ content: updates.content !== void 0 ? updates.content : skill.content,
1700
+ subSkills: updates.subSkills !== void 0 ? updates.subSkills : skill.subSkills,
1701
+ updatedAt: /* @__PURE__ */ new Date()
1702
+ };
1703
+ await this.writeSkillFile(updatedSkill);
1704
+ return updatedSkill;
1705
+ }
1706
+ /**
1707
+ * Delete a skill by ID
1708
+ * Deletes the entire directory (name is the directory name)
1709
+ */
1710
+ async deleteSkill(id) {
1711
+ await this.ensureDirectoryExists();
1712
+ const skillDir = this.getSkillDirectoryPath(id);
1713
+ try {
1714
+ await fs.rm(skillDir, { recursive: true, force: true });
1715
+ return true;
1716
+ } catch (error) {
1717
+ if (error.code === "ENOENT") {
1718
+ return false;
1719
+ }
1720
+ throw error;
1721
+ }
1722
+ }
1723
+ /**
1724
+ * Check if skill exists
1725
+ */
1726
+ async hasSkill(id) {
1727
+ const skill = await this.getSkillById(id);
1728
+ return skill !== null;
1729
+ }
1730
+ /**
1731
+ * Search skills by metadata
1732
+ */
1733
+ async searchByMetadata(metadataKey, metadataValue) {
1734
+ const allSkills = await this.getAllSkills();
1735
+ return allSkills.filter((skill) => {
1736
+ return skill.metadata && skill.metadata[metadataKey] === metadataValue;
1737
+ });
1738
+ }
1739
+ /**
1740
+ * Filter skills by compatibility
1741
+ */
1742
+ async filterByCompatibility(compatibility) {
1743
+ const allSkills = await this.getAllSkills();
1744
+ return allSkills.filter((skill) => {
1745
+ return skill.compatibility === compatibility;
1746
+ });
1747
+ }
1748
+ /**
1749
+ * Filter skills by license
1750
+ */
1751
+ async filterByLicense(license) {
1752
+ const allSkills = await this.getAllSkills();
1753
+ return allSkills.filter((skill) => {
1754
+ return skill.license === license;
1755
+ });
1756
+ }
1757
+ /**
1758
+ * Get sub-skills of a parent skill
1759
+ */
1760
+ async getSubSkills(parentSkillName) {
1761
+ const parentSkill = await this.getSkillById(parentSkillName);
1762
+ if (!parentSkill || !parentSkill.subSkills || parentSkill.subSkills.length === 0) {
1763
+ return [];
1764
+ }
1765
+ const subSkills = [];
1766
+ for (const subSkillName of parentSkill.subSkills) {
1767
+ const subSkill = await this.getSkillById(subSkillName);
1768
+ if (subSkill) {
1769
+ subSkills.push(subSkill);
1770
+ }
1771
+ }
1772
+ return subSkills;
1773
+ }
1774
+ };
1775
+
1776
+ // src/store_lattice/StoreLatticeManager.ts
1777
+ var StoreLatticeManager = class _StoreLatticeManager extends BaseLatticeManager {
1778
+ /**
1779
+ * Get StoreLatticeManager singleton instance
1780
+ */
1781
+ static getInstance() {
1782
+ if (!_StoreLatticeManager._instance) {
1783
+ _StoreLatticeManager._instance = new _StoreLatticeManager();
1784
+ }
1785
+ return _StoreLatticeManager._instance;
1786
+ }
1787
+ /**
1788
+ * Get Lattice type prefix
1789
+ */
1790
+ getLatticeType() {
1791
+ return "stores";
1792
+ }
1793
+ /**
1794
+ * Generate composite key from key and type
1795
+ * @param key Lattice key name
1796
+ * @param type Store type
1797
+ * @returns Composite key string
1798
+ */
1799
+ getCompositeKey(key, type) {
1800
+ return `${key}:${type}`;
1801
+ }
1802
+ /**
1803
+ * Register store Lattice with type safety
1804
+ * Uses composite key (key + type) as unique identifier
1805
+ * @param key Lattice key name
1806
+ * @param type Store type (e.g., "thread")
1807
+ * @param store Store implementation instance matching the type
1808
+ */
1809
+ registerLattice(key, type, store) {
1810
+ const storeLattice = {
1811
+ key,
1812
+ type,
1813
+ store
1814
+ };
1815
+ const compositeKey = this.getCompositeKey(key, type);
1816
+ this.register(compositeKey, storeLattice);
1817
+ }
1818
+ /**
1819
+ * Get StoreLattice with type safety
1820
+ * Uses composite key (key + type) to retrieve the store
1821
+ * @param key Lattice key name
1822
+ * @param type Expected store type for type checking
1823
+ * @returns StoreLattice with typed store
1824
+ */
1825
+ getStoreLattice(key, type) {
1826
+ const compositeKey = this.getCompositeKey(key, type);
1827
+ const storeLattice = this.get(compositeKey);
1828
+ if (!storeLattice) {
1829
+ throw new Error(`StoreLattice ${key}:${type} not found`);
1830
+ }
1831
+ if (storeLattice.type !== type) {
1832
+ throw new Error(
1833
+ `StoreLattice ${key}:${type} has type "${storeLattice.type}", expected "${type}"`
1834
+ );
1835
+ }
1836
+ return storeLattice;
1837
+ }
1838
+ /**
1839
+ * Get StoreLattice without type checking (for backward compatibility)
1840
+ * @param key Lattice key name
1841
+ * @param type Store type
1842
+ * @returns StoreLattice (type may be unknown)
1843
+ */
1844
+ getStoreLatticeUnsafe(key, type) {
1845
+ const compositeKey = this.getCompositeKey(key, type);
1846
+ const storeLattice = this.get(compositeKey);
1847
+ if (!storeLattice) {
1848
+ throw new Error(`StoreLattice ${key}:${type} not found`);
1849
+ }
1850
+ return storeLattice;
1851
+ }
1852
+ /**
1853
+ * Get all Lattices
1854
+ */
1855
+ getAllLattices() {
1856
+ return this.getAll();
1857
+ }
1858
+ /**
1859
+ * Check if Lattice exists
1860
+ * Uses composite key (key + type) to check existence
1861
+ * @param key Lattice key name
1862
+ * @param type Store type
1863
+ */
1864
+ hasLattice(key, type) {
1865
+ const compositeKey = this.getCompositeKey(key, type);
1866
+ return this.has(compositeKey);
1867
+ }
1868
+ /**
1869
+ * Remove Lattice
1870
+ * Uses composite key (key + type) to remove the store
1871
+ * @param key Lattice key name
1872
+ * @param type Store type
1873
+ */
1874
+ removeLattice(key, type) {
1875
+ const compositeKey = this.getCompositeKey(key, type);
1876
+ return this.remove(compositeKey);
1877
+ }
1878
+ /**
1879
+ * Clear all Lattices
1880
+ */
1881
+ clearLattices() {
1882
+ this.clear();
1883
+ }
1884
+ /**
1885
+ * Get Lattice count
1886
+ */
1887
+ getLatticeCount() {
1888
+ return this.count();
1889
+ }
1890
+ /**
1891
+ * Get Lattice key list
1892
+ */
1893
+ getLatticeKeys() {
1894
+ return this.keys();
1895
+ }
1896
+ };
1897
+ var storeLatticeManager = StoreLatticeManager.getInstance();
1898
+ var registerStoreLattice = (key, type, store) => storeLatticeManager.registerLattice(key, type, store);
1899
+ var getStoreLattice = (key, type) => storeLatticeManager.getStoreLattice(key, type);
1900
+ var defaultThreadStore = new InMemoryThreadStore();
1901
+ var defaultAssistantStore = new InMemoryAssistantStore();
1902
+ var defaultSkillStore = new FileSystemSkillStore();
1903
+ storeLatticeManager.registerLattice("default", "thread", defaultThreadStore);
1904
+ storeLatticeManager.registerLattice(
1905
+ "default",
1906
+ "assistant",
1907
+ defaultAssistantStore
1908
+ );
1909
+ storeLatticeManager.registerLattice("default", "skill", defaultSkillStore);
1910
+
1911
+ // src/tool_lattice/load_skills/index.ts
1912
+ var LOAD_SKILLS_DESCRIPTION = `Load all available skills and return their metadata (name, description, license, compatibility, metadata, and subSkills) without the content. This tool returns skill information including hierarchical relationships (subSkills). Use this to discover what skills are available and their structure. Skills can have sub-skills, creating a tree structure for organizing capabilities.`;
1913
+ registerToolLattice(
1914
+ "load_skills",
1915
+ {
1916
+ name: "load_skills",
1917
+ description: LOAD_SKILLS_DESCRIPTION,
1918
+ needUserApprove: false,
1919
+ schema: z7.object({})
1920
+ },
1921
+ async () => {
1922
+ try {
1923
+ const storeLattice = getStoreLattice("default", "skill");
1924
+ const skillStore = storeLattice.store;
1925
+ const skills = await skillStore.getAllSkills();
1926
+ const skillsMeta = skills.map((skill) => ({
1927
+ name: skill.name,
1928
+ description: skill.description,
1929
+ license: skill.license,
1930
+ compatibility: skill.compatibility,
1931
+ metadata: skill.metadata,
1932
+ subSkills: skill.subSkills
1933
+ }));
1934
+ return JSON.stringify(skillsMeta, null, 2);
1935
+ } catch (error) {
1936
+ return `Error loading skills: ${error instanceof Error ? error.message : String(error)}`;
1937
+ }
1938
+ }
1939
+ );
1940
+
1941
+ // src/tool_lattice/load_skill_content/index.ts
1942
+ import z8 from "zod";
1943
+ var LOAD_SKILL_CONTENT_DESCRIPTION = `Load a specific skill's content by name and return its full content including markdown body. This tool returns the complete skill content including frontmatter and markdown body. If the skill has sub-skills defined, they will be listed in the frontmatter. Use this tool to get the complete skill content for a skill that you want to use.`;
1944
+ registerToolLattice(
1945
+ "load_skill_content",
1946
+ {
1947
+ name: "load_skill_content",
1948
+ description: LOAD_SKILL_CONTENT_DESCRIPTION,
1949
+ needUserApprove: false,
1950
+ schema: z8.object({
1951
+ skill_name: z8.string().describe("The name of the skill to load")
1952
+ })
1953
+ },
1954
+ async (input) => {
1955
+ try {
1956
+ const storeLattice = getStoreLattice("default", "skill");
1957
+ const skillStore = storeLattice.store;
1958
+ const skill = await skillStore.getSkillById(input.skill_name);
1959
+ if (!skill) {
1960
+ const allSkills = await skillStore.getAllSkills();
1961
+ const availableSkills = allSkills.map((s) => s.name).join(", ");
1962
+ return `Skill "${input.skill_name}" not found. Available skills: ${availableSkills}`;
1963
+ }
1964
+ const frontmatter = ["---"];
1965
+ frontmatter.push(`name: ${skill.name}`);
1966
+ frontmatter.push(`description: ${skill.description}`);
1967
+ if (skill.license) {
1968
+ frontmatter.push(`license: ${skill.license}`);
1969
+ }
1970
+ if (skill.compatibility) {
1971
+ frontmatter.push(`compatibility: ${skill.compatibility}`);
1972
+ }
1973
+ if (skill.metadata && Object.keys(skill.metadata).length > 0) {
1974
+ frontmatter.push("metadata:");
1975
+ for (const [key, value] of Object.entries(skill.metadata)) {
1976
+ frontmatter.push(` ${key}: ${value}`);
1977
+ }
1978
+ }
1979
+ if (skill.subSkills && skill.subSkills.length > 0) {
1980
+ frontmatter.push("subSkills:");
1981
+ for (const subSkill of skill.subSkills) {
1982
+ frontmatter.push(` - ${subSkill}`);
1983
+ }
1984
+ }
1985
+ frontmatter.push("---");
1986
+ const content = skill.content || "";
1987
+ return `${frontmatter.join("\n")}
1988
+ ${content}`;
1989
+ } catch (error) {
1990
+ return `Error loading skill content: ${error instanceof Error ? error.message : String(error)}`;
1991
+ }
1992
+ }
1993
+ );
1994
+
1123
1995
  // src/agent_lattice/types.ts
1124
1996
  import {
1125
1997
  AgentType,
1126
1998
  AgentConfig,
1127
1999
  ReactAgentConfig,
1128
2000
  DeepAgentConfig,
1129
- PlanExecuteAgentConfig,
1130
- SequentialAgentConfig,
1131
2001
  AgentConfigWithTools,
1132
2002
  GraphBuildOptions,
1133
2003
  hasTools,
@@ -1365,8 +2235,8 @@ function performStringReplacement(content, oldString, newString, replaceAll) {
1365
2235
  const newContent = content.split(oldString).join(newString);
1366
2236
  return [newContent, occurrences];
1367
2237
  }
1368
- function validatePath(path) {
1369
- const pathStr = path || "/";
2238
+ function validatePath(path2) {
2239
+ const pathStr = path2 || "/";
1370
2240
  if (!pathStr || pathStr.trim() === "") {
1371
2241
  throw new Error("Path cannot be empty");
1372
2242
  }
@@ -1376,10 +2246,10 @@ function validatePath(path) {
1376
2246
  }
1377
2247
  return normalized;
1378
2248
  }
1379
- function globSearchFiles(files, pattern, path = "/") {
2249
+ function globSearchFiles(files, pattern, path2 = "/") {
1380
2250
  let normalizedPath;
1381
2251
  try {
1382
- normalizedPath = validatePath(path);
2252
+ normalizedPath = validatePath(path2);
1383
2253
  } catch {
1384
2254
  return "No files found";
1385
2255
  }
@@ -1410,7 +2280,7 @@ function globSearchFiles(files, pattern, path = "/") {
1410
2280
  }
1411
2281
  return matches.map(([fp]) => fp).join("\n");
1412
2282
  }
1413
- function grepMatchesFromFiles(files, pattern, path = null, glob = null) {
2283
+ function grepMatchesFromFiles(files, pattern, path2 = null, glob = null) {
1414
2284
  let regex;
1415
2285
  try {
1416
2286
  regex = new RegExp(pattern);
@@ -1419,7 +2289,7 @@ function grepMatchesFromFiles(files, pattern, path = null, glob = null) {
1419
2289
  }
1420
2290
  let normalizedPath;
1421
2291
  try {
1422
- normalizedPath = validatePath(path);
2292
+ normalizedPath = validatePath(path2);
1423
2293
  } catch {
1424
2294
  return [];
1425
2295
  }
@@ -1464,11 +2334,11 @@ var StateBackend = class {
1464
2334
  * @returns List of FileInfo objects for files and directories directly in the directory.
1465
2335
  * Directories have a trailing / in their path and is_dir=true.
1466
2336
  */
1467
- lsInfo(path) {
2337
+ lsInfo(path2) {
1468
2338
  const files = this.getFiles();
1469
2339
  const infos = [];
1470
2340
  const subdirs = /* @__PURE__ */ new Set();
1471
- const normalizedPath = path.endsWith("/") ? path : path + "/";
2341
+ const normalizedPath = path2.endsWith("/") ? path2 : path2 + "/";
1472
2342
  for (const [k, fd] of Object.entries(files)) {
1473
2343
  if (!k.startsWith(normalizedPath)) {
1474
2344
  continue;
@@ -1574,16 +2444,16 @@ var StateBackend = class {
1574
2444
  /**
1575
2445
  * Structured search results or error string for invalid input.
1576
2446
  */
1577
- grepRaw(pattern, path = "/", glob = null) {
2447
+ grepRaw(pattern, path2 = "/", glob = null) {
1578
2448
  const files = this.getFiles();
1579
- return grepMatchesFromFiles(files, pattern, path, glob);
2449
+ return grepMatchesFromFiles(files, pattern, path2, glob);
1580
2450
  }
1581
2451
  /**
1582
2452
  * Structured glob matching returning FileInfo objects.
1583
2453
  */
1584
- globInfo(pattern, path = "/") {
2454
+ globInfo(pattern, path2 = "/") {
1585
2455
  const files = this.getFiles();
1586
- const result = globSearchFiles(files, pattern, path);
2456
+ const result = globSearchFiles(files, pattern, path2);
1587
2457
  if (result === "No files found") {
1588
2458
  return [];
1589
2459
  }
@@ -1669,10 +2539,10 @@ function createLsTool(backend, options) {
1669
2539
  store: config.store
1670
2540
  };
1671
2541
  const resolvedBackend = getBackend(backend, stateAndStore);
1672
- const path = input.path || "/";
1673
- const infos = await resolvedBackend.lsInfo(path);
2542
+ const path2 = input.path || "/";
2543
+ const infos = await resolvedBackend.lsInfo(path2);
1674
2544
  if (infos.length === 0) {
1675
- return `No files found in ${path}`;
2545
+ return `No files found in ${path2}`;
1676
2546
  }
1677
2547
  const lines = [];
1678
2548
  for (const info of infos) {
@@ -1807,8 +2677,8 @@ function createGlobTool(backend, options) {
1807
2677
  store: config.store
1808
2678
  };
1809
2679
  const resolvedBackend = getBackend(backend, stateAndStore);
1810
- const { pattern, path = "/" } = input;
1811
- const infos = await resolvedBackend.globInfo(pattern, path);
2680
+ const { pattern, path: path2 = "/" } = input;
2681
+ const infos = await resolvedBackend.globInfo(pattern, path2);
1812
2682
  if (infos.length === 0) {
1813
2683
  return `No files found matching pattern '${pattern}'`;
1814
2684
  }
@@ -1833,8 +2703,8 @@ function createGrepTool(backend, options) {
1833
2703
  store: config.store
1834
2704
  };
1835
2705
  const resolvedBackend = getBackend(backend, stateAndStore);
1836
- const { pattern, path = "/", glob = null } = input;
1837
- const result = await resolvedBackend.grepRaw(pattern, path, glob);
2706
+ const { pattern, path: path2 = "/", glob = null } = input;
2707
+ const result = await resolvedBackend.grepRaw(pattern, path2, glob);
1838
2708
  if (typeof result === "string") {
1839
2709
  return result;
1840
2710
  }
@@ -1987,7 +2857,7 @@ ${systemPrompt}` : systemPrompt;
1987
2857
  }
1988
2858
 
1989
2859
  // src/deep_agent_new/middleware/subagents.ts
1990
- import { z as z7 } from "zod/v3";
2860
+ import { z as z9 } from "zod/v3";
1991
2861
  import {
1992
2862
  createMiddleware as createMiddleware2,
1993
2863
  createAgent as createAgent2,
@@ -2262,12 +3132,12 @@ var AgentManager = class _AgentManager {
2262
3132
  return _AgentManager.instance;
2263
3133
  }
2264
3134
  callAgentInQueue(queue, return_agent_state) {
2265
- return new Promise((resolve, reject) => {
3135
+ return new Promise((resolve2, reject) => {
2266
3136
  const callback_event = `${queue.assistant_id}::${queue.thread_id}`;
2267
3137
  if (return_agent_state) {
2268
3138
  event_bus_default.subscribeOnce(callback_event, (data) => {
2269
3139
  if (data.success) {
2270
- resolve(data.state);
3140
+ resolve2(data.state);
2271
3141
  } else {
2272
3142
  reject(data.error);
2273
3143
  }
@@ -2282,7 +3152,7 @@ var AgentManager = class _AgentManager {
2282
3152
  },
2283
3153
  true
2284
3154
  );
2285
- !return_agent_state && resolve({ callback_event_id: callback_event, success: true });
3155
+ !return_agent_state && resolve2({ callback_event_id: callback_event, success: true });
2286
3156
  } catch (error) {
2287
3157
  !return_agent_state && reject({
2288
3158
  callback_event_id: callback_event,
@@ -2664,9 +3534,9 @@ function createTaskTool(options) {
2664
3534
  {
2665
3535
  name: "task",
2666
3536
  description: finalTaskDescription,
2667
- schema: z7.object({
2668
- description: z7.string().describe("The task to execute with the selected agent"),
2669
- subagent_type: z7.string().describe(
3537
+ schema: z9.object({
3538
+ description: z9.string().describe("The task to execute with the selected agent"),
3539
+ subagent_type: z9.string().describe(
2670
3540
  `Name of the agent to use. Available: ${Object.keys(
2671
3541
  subagentGraphs
2672
3542
  ).join(", ")}`
@@ -2770,7 +3640,7 @@ var SUPPORTS_NOFOLLOW = fsSync.constants.O_NOFOLLOW !== void 0;
2770
3640
 
2771
3641
  // src/deep_agent_new/middleware/todos.ts
2772
3642
  import { Command as Command3 } from "@langchain/langgraph";
2773
- import { z as z8 } from "zod";
3643
+ import { z as z10 } from "zod";
2774
3644
  import { createMiddleware as createMiddleware4, tool as tool4, ToolMessage as ToolMessage4 } from "langchain";
2775
3645
  var WRITE_TODOS_DESCRIPTION = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
2776
3646
  It also helps the user understand the progress of the task and overall progress of their requests.
@@ -2998,12 +3868,12 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
2998
3868
  ## Important To-Do List Usage Notes to Remember
2999
3869
  - The \`write_todos\` tool should never be called multiple times in parallel.
3000
3870
  - Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.`;
3001
- var TodoStatus = z8.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
3002
- var TodoSchema = z8.object({
3003
- content: z8.string().describe("Content of the todo item"),
3871
+ var TodoStatus = z10.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
3872
+ var TodoSchema = z10.object({
3873
+ content: z10.string().describe("Content of the todo item"),
3004
3874
  status: TodoStatus
3005
3875
  });
3006
- var stateSchema = z8.object({ todos: z8.array(TodoSchema).default([]) });
3876
+ var stateSchema = z10.object({ todos: z10.array(TodoSchema).default([]) });
3007
3877
  function todoListMiddleware(options) {
3008
3878
  const writeTodos = tool4(
3009
3879
  ({ todos }, config) => {
@@ -3022,8 +3892,8 @@ function todoListMiddleware(options) {
3022
3892
  {
3023
3893
  name: "write_todos",
3024
3894
  description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
3025
- schema: z8.object({
3026
- todos: z8.array(TodoSchema).describe("List of todo items to update")
3895
+ schema: z10.object({
3896
+ todos: z10.array(TodoSchema).describe("List of todo items to update")
3027
3897
  })
3028
3898
  }
3029
3899
  );
@@ -3040,6 +3910,56 @@ function todoListMiddleware(options) {
3040
3910
  });
3041
3911
  }
3042
3912
 
3913
+ // src/middlewares/skillMiddleware.ts
3914
+ import { createMiddleware as createMiddleware5 } from "langchain";
3915
+ var DEFAULT_HEADING = "## Available Skills";
3916
+ var DEFAULT_EXTRA_NOTE = "Use the load_skill tool when you need detailed information about handling a specific type of request.";
3917
+ function createSkillMiddleware(params = {}) {
3918
+ const {
3919
+ skillCategories,
3920
+ loadSkillTool = getToolClient("load_skill_content"),
3921
+ heading = DEFAULT_HEADING,
3922
+ extraNote = DEFAULT_EXTRA_NOTE
3923
+ } = params;
3924
+ let latestSkills = [];
3925
+ return createMiddleware5({
3926
+ name: "skillMiddleware",
3927
+ tools: [loadSkillTool],
3928
+ // Fetch the latest skills from the Skill Lattice before the agent runs
3929
+ beforeAgent: async () => {
3930
+ try {
3931
+ if (skillCategories && skillCategories.length > 0) {
3932
+ const storeLattice = getStoreLattice("default", "skill");
3933
+ const skillStore = storeLattice?.store;
3934
+ const skillLatticePromises = skillCategories.map(
3935
+ (category) => skillStore.searchByMetadata("category", category)
3936
+ );
3937
+ const skillLatticesArrays = await Promise.all(skillLatticePromises);
3938
+ latestSkills = skillLatticesArrays.flat().filter((skill) => skill !== void 0);
3939
+ }
3940
+ } catch (error) {
3941
+ console.error("Error fetching skills:", error);
3942
+ }
3943
+ },
3944
+ wrapModelCall: (request, handler) => {
3945
+ const skillsPrompt = latestSkills.map((skill) => `- **${skill.name}**: ${skill.description}`).join("\n");
3946
+ const skillsAddendum = `
3947
+
3948
+ ${heading}
3949
+
3950
+ ${skillsPrompt}
3951
+
3952
+ ${extraNote}`;
3953
+ const existingSystemPrompt = request.systemPrompt ?? "";
3954
+ const newSystemPrompt = existingSystemPrompt.length > 0 ? `${existingSystemPrompt}${skillsAddendum}` : skillsAddendum.trimStart();
3955
+ return handler({
3956
+ ...request,
3957
+ systemPrompt: newSystemPrompt
3958
+ });
3959
+ }
3960
+ });
3961
+ }
3962
+
3043
3963
  // src/deep_agent_new/agent.ts
3044
3964
  var BASE_PROMPT = `In order to complete the objective that the user asks of you, you have access to a number of standard tools.`;
3045
3965
  function createDeepAgent(params = {}) {
@@ -3055,7 +3975,8 @@ function createDeepAgent(params = {}) {
3055
3975
  store,
3056
3976
  backend,
3057
3977
  interruptOn,
3058
- name
3978
+ name,
3979
+ skillCategories
3059
3980
  } = params;
3060
3981
  const finalSystemPrompt = systemPrompt ? `${systemPrompt}
3061
3982
 
@@ -3105,7 +4026,8 @@ ${BASE_PROMPT}` : BASE_PROMPT;
3105
4026
  unsupportedModelBehavior: "ignore"
3106
4027
  }),
3107
4028
  // Patches tool calls to ensure compatibility across different model providers
3108
- createPatchToolCallsMiddleware()
4029
+ createPatchToolCallsMiddleware(),
4030
+ createSkillMiddleware({ skillCategories })
3109
4031
  ];
3110
4032
  if (interruptOn) {
3111
4033
  middleware.push(humanInTheLoopMiddleware2({ interruptOn }));
@@ -3162,7 +4084,8 @@ var DeepAgentGraphBuilder = class {
3162
4084
  contextSchema: params.stateSchema,
3163
4085
  systemPrompt: params.prompt,
3164
4086
  subagents,
3165
- checkpointer: getCheckpointSaver("default")
4087
+ checkpointer: getCheckpointSaver("default"),
4088
+ skillCategories: params.skillCategories
3166
4089
  });
3167
4090
  return deepAgent;
3168
4091
  }
@@ -3237,6 +4160,7 @@ var AgentParamsBuilder = class {
3237
4160
  * @returns Agent build parameters
3238
4161
  */
3239
4162
  buildParams(agentLattice, options) {
4163
+ const skillCategories = isDeepAgentConfig2(agentLattice.config) ? agentLattice.config.skillCategories : void 0;
3240
4164
  const toolKeys = options?.overrideTools || getToolsFromConfig2(agentLattice.config);
3241
4165
  const tools = toolKeys.map((toolKey) => {
3242
4166
  const toolLattice = toolLatticeManager.getToolLattice(toolKey);
@@ -3278,7 +4202,8 @@ var AgentParamsBuilder = class {
3278
4202
  model,
3279
4203
  subAgents: [...subAgents, ...internalSubAgents],
3280
4204
  prompt: agentLattice.config.prompt,
3281
- stateSchema: agentLattice.config.schema
4205
+ stateSchema: agentLattice.config.schema,
4206
+ skillCategories
3282
4207
  };
3283
4208
  }
3284
4209
  };
@@ -3633,9 +4558,9 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
3633
4558
  next: (chunk) => {
3634
4559
  queue.push(chunk);
3635
4560
  if (resolveNext) {
3636
- const resolve = resolveNext;
4561
+ const resolve2 = resolveNext;
3637
4562
  resolveNext = null;
3638
- resolve();
4563
+ resolve2();
3639
4564
  }
3640
4565
  },
3641
4566
  error: (err) => {
@@ -3645,17 +4570,17 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
3645
4570
  errorNext = null;
3646
4571
  reject(err);
3647
4572
  } else if (resolveNext) {
3648
- const resolve = resolveNext;
4573
+ const resolve2 = resolveNext;
3649
4574
  resolveNext = null;
3650
- resolve();
4575
+ resolve2();
3651
4576
  }
3652
4577
  },
3653
4578
  complete: () => {
3654
4579
  isCompleted = true;
3655
4580
  if (resolveNext) {
3656
- const resolve = resolveNext;
4581
+ const resolve2 = resolveNext;
3657
4582
  resolveNext = null;
3658
- resolve();
4583
+ resolve2();
3659
4584
  }
3660
4585
  }
3661
4586
  });
@@ -3667,8 +4592,8 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
3667
4592
  }
3668
4593
  if (queue.length === 0) {
3669
4594
  if (isCompleted) break;
3670
- await new Promise((resolve, reject) => {
3671
- resolveNext = resolve;
4595
+ await new Promise((resolve2, reject) => {
4596
+ resolveNext = resolve2;
3672
4597
  errorNext = reject;
3673
4598
  });
3674
4599
  }
@@ -4700,7 +5625,90 @@ var ScheduleLatticeManager = class _ScheduleLatticeManager extends BaseLatticeMa
4700
5625
  if (!scheduleLattice) {
4701
5626
  throw new Error(`ScheduleLattice ${key} not found`);
4702
5627
  }
4703
- return scheduleLattice;
5628
+ return scheduleLattice;
5629
+ }
5630
+ /**
5631
+ * Get all Lattices
5632
+ */
5633
+ getAllLattices() {
5634
+ return this.getAll();
5635
+ }
5636
+ /**
5637
+ * Check if Lattice exists
5638
+ * @param key Lattice key name
5639
+ */
5640
+ hasLattice(key) {
5641
+ return this.has(key);
5642
+ }
5643
+ /**
5644
+ * Remove Lattice
5645
+ * @param key Lattice key name
5646
+ */
5647
+ removeLattice(key) {
5648
+ return this.remove(key);
5649
+ }
5650
+ /**
5651
+ * Clear all Lattices
5652
+ */
5653
+ clearLattices() {
5654
+ this.clear();
5655
+ }
5656
+ /**
5657
+ * Get Lattice count
5658
+ */
5659
+ getLatticeCount() {
5660
+ return this.count();
5661
+ }
5662
+ /**
5663
+ * Get Lattice key list
5664
+ */
5665
+ getLatticeKeys() {
5666
+ return this.keys();
5667
+ }
5668
+ };
5669
+ var scheduleLatticeManager = ScheduleLatticeManager.getInstance();
5670
+ var registerScheduleLattice = (key, config, client) => scheduleLatticeManager.registerLattice(key, config, client);
5671
+ var getScheduleLattice = (key) => scheduleLatticeManager.getScheduleLattice(key);
5672
+
5673
+ // src/embeddings_lattice/EmbeddingsLatticeManager.ts
5674
+ var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatticeManager {
5675
+ /**
5676
+ * Get EmbeddingsLatticeManager singleton instance
5677
+ */
5678
+ static getInstance() {
5679
+ if (!_EmbeddingsLatticeManager._instance) {
5680
+ _EmbeddingsLatticeManager._instance = new _EmbeddingsLatticeManager();
5681
+ }
5682
+ return _EmbeddingsLatticeManager._instance;
5683
+ }
5684
+ /**
5685
+ * Get Lattice type prefix
5686
+ */
5687
+ getLatticeType() {
5688
+ return "embeddings";
5689
+ }
5690
+ /**
5691
+ * Register embeddings Lattice
5692
+ * @param key Lattice key name
5693
+ * @param embeddings Embeddings instance
5694
+ */
5695
+ registerLattice(key, embeddings) {
5696
+ const embeddingsLattice = {
5697
+ key,
5698
+ client: embeddings
5699
+ };
5700
+ this.register(key, embeddingsLattice);
5701
+ }
5702
+ /**
5703
+ * Get EmbeddingsLattice
5704
+ * @param key Lattice key name
5705
+ */
5706
+ getEmbeddingsLattice(key) {
5707
+ const embeddingsLattice = this.get(key);
5708
+ if (!embeddingsLattice) {
5709
+ throw new Error(`EmbeddingsLattice ${key} not found`);
5710
+ }
5711
+ return embeddingsLattice;
4704
5712
  }
4705
5713
  /**
4706
5714
  * Get all Lattices
@@ -4740,261 +5748,385 @@ var ScheduleLatticeManager = class _ScheduleLatticeManager extends BaseLatticeMa
4740
5748
  getLatticeKeys() {
4741
5749
  return this.keys();
4742
5750
  }
4743
- };
4744
- var scheduleLatticeManager = ScheduleLatticeManager.getInstance();
4745
- var registerScheduleLattice = (key, config, client) => scheduleLatticeManager.registerLattice(key, config, client);
4746
- var getScheduleLattice = (key) => scheduleLatticeManager.getScheduleLattice(key);
4747
-
4748
- // src/store_lattice/InMemoryThreadStore.ts
4749
- var InMemoryThreadStore = class {
4750
- constructor() {
4751
- // Map<assistantId, Map<threadId, Thread>>
4752
- this.threads = /* @__PURE__ */ new Map();
4753
- }
4754
5751
  /**
4755
- * Get all threads for a specific assistant
5752
+ * Get embeddings client
5753
+ * @param key Lattice key name
4756
5754
  */
4757
- async getThreadsByAssistantId(assistantId) {
4758
- const assistantThreads = this.threads.get(assistantId);
4759
- if (!assistantThreads) {
4760
- return [];
4761
- }
4762
- return Array.from(assistantThreads.values());
5755
+ getEmbeddingsClient(key) {
5756
+ const embeddingsLattice = this.getEmbeddingsLattice(key);
5757
+ return embeddingsLattice.client;
4763
5758
  }
5759
+ };
5760
+ var embeddingsLatticeManager = EmbeddingsLatticeManager.getInstance();
5761
+ var registerEmbeddingsLattice = (key, embeddings) => embeddingsLatticeManager.registerLattice(key, embeddings);
5762
+ var getEmbeddingsLattice = (key) => embeddingsLatticeManager.getEmbeddingsLattice(key);
5763
+ var getEmbeddingsClient = (key) => embeddingsLatticeManager.getEmbeddingsClient(key);
5764
+
5765
+ // src/vectorstore_lattice/VectorStoreLatticeManager.ts
5766
+ var VectorStoreLatticeManager = class _VectorStoreLatticeManager extends BaseLatticeManager {
4764
5767
  /**
4765
- * Get a thread by ID for a specific assistant
5768
+ * Get VectorStoreLatticeManager singleton instance
4766
5769
  */
4767
- async getThreadById(assistantId, threadId) {
4768
- const assistantThreads = this.threads.get(assistantId);
4769
- if (!assistantThreads) {
4770
- return void 0;
5770
+ static getInstance() {
5771
+ if (!_VectorStoreLatticeManager._instance) {
5772
+ _VectorStoreLatticeManager._instance = new _VectorStoreLatticeManager();
4771
5773
  }
4772
- return assistantThreads.get(threadId);
5774
+ return _VectorStoreLatticeManager._instance;
4773
5775
  }
4774
5776
  /**
4775
- * Create a new thread for an assistant
5777
+ * Get Lattice type prefix
4776
5778
  */
4777
- async createThread(assistantId, threadId, data) {
4778
- const now = /* @__PURE__ */ new Date();
4779
- const thread = {
4780
- id: threadId,
4781
- assistantId,
4782
- metadata: data.metadata || {},
4783
- createdAt: now,
4784
- updatedAt: now
4785
- };
4786
- if (!this.threads.has(assistantId)) {
4787
- this.threads.set(assistantId, /* @__PURE__ */ new Map());
4788
- }
4789
- const assistantThreads = this.threads.get(assistantId);
4790
- assistantThreads.set(threadId, thread);
4791
- return thread;
5779
+ getLatticeType() {
5780
+ return "vectorstores";
4792
5781
  }
4793
5782
  /**
4794
- * Update an existing thread
5783
+ * Register vector store Lattice
5784
+ * @param key Lattice key name
5785
+ * @param vectorStore VectorStore instance
4795
5786
  */
4796
- async updateThread(assistantId, threadId, updates) {
4797
- const assistantThreads = this.threads.get(assistantId);
4798
- if (!assistantThreads) {
4799
- return null;
4800
- }
4801
- const existing = assistantThreads.get(threadId);
4802
- if (!existing) {
4803
- return null;
4804
- }
4805
- const updated = {
4806
- ...existing,
4807
- metadata: {
4808
- ...existing.metadata,
4809
- ...updates.metadata || {}
4810
- },
4811
- updatedAt: /* @__PURE__ */ new Date()
5787
+ registerLattice(key, vectorStore) {
5788
+ const vectorStoreLattice = {
5789
+ key,
5790
+ client: vectorStore
4812
5791
  };
4813
- assistantThreads.set(threadId, updated);
4814
- return updated;
5792
+ this.register(key, vectorStoreLattice);
4815
5793
  }
4816
5794
  /**
4817
- * Delete a thread by ID
5795
+ * Get VectorStoreLattice
5796
+ * @param key Lattice key name
4818
5797
  */
4819
- async deleteThread(assistantId, threadId) {
4820
- const assistantThreads = this.threads.get(assistantId);
4821
- if (!assistantThreads) {
4822
- return false;
5798
+ getVectorStoreLattice(key) {
5799
+ const vectorStoreLattice = this.get(key);
5800
+ if (!vectorStoreLattice) {
5801
+ throw new Error(`VectorStoreLattice ${key} not found`);
4823
5802
  }
4824
- return assistantThreads.delete(threadId);
5803
+ return vectorStoreLattice;
4825
5804
  }
4826
5805
  /**
4827
- * Check if thread exists
5806
+ * Get all Lattices
4828
5807
  */
4829
- async hasThread(assistantId, threadId) {
4830
- const assistantThreads = this.threads.get(assistantId);
4831
- if (!assistantThreads) {
4832
- return false;
4833
- }
4834
- return assistantThreads.has(threadId);
5808
+ getAllLattices() {
5809
+ return this.getAll();
4835
5810
  }
4836
5811
  /**
4837
- * Clear all threads (useful for testing)
5812
+ * Check if Lattice exists
5813
+ * @param key Lattice key name
4838
5814
  */
4839
- clear() {
4840
- this.threads.clear();
5815
+ hasLattice(key) {
5816
+ return this.has(key);
4841
5817
  }
4842
5818
  /**
4843
- * Get all threads for all assistants (useful for debugging)
5819
+ * Remove Lattice
5820
+ * @param key Lattice key name
4844
5821
  */
4845
- getAllThreads() {
4846
- const allThreads = [];
4847
- for (const assistantThreads of this.threads.values()) {
4848
- allThreads.push(...Array.from(assistantThreads.values()));
4849
- }
4850
- return allThreads;
4851
- }
4852
- };
4853
-
4854
- // src/store_lattice/InMemoryAssistantStore.ts
4855
- var InMemoryAssistantStore = class {
4856
- constructor() {
4857
- this.assistants = /* @__PURE__ */ new Map();
5822
+ removeLattice(key) {
5823
+ return this.remove(key);
4858
5824
  }
4859
5825
  /**
4860
- * Get all assistants
5826
+ * Clear all Lattices
4861
5827
  */
4862
- async getAllAssistants() {
4863
- return Array.from(this.assistants.values());
5828
+ clearLattices() {
5829
+ this.clear();
4864
5830
  }
4865
5831
  /**
4866
- * Get assistant by ID
5832
+ * Get Lattice count
4867
5833
  */
4868
- async getAssistantById(id) {
4869
- return this.assistants.get(id) || null;
5834
+ getLatticeCount() {
5835
+ return this.count();
4870
5836
  }
4871
5837
  /**
4872
- * Create a new assistant
5838
+ * Get Lattice key list
4873
5839
  */
4874
- async createAssistant(id, data) {
4875
- const now = /* @__PURE__ */ new Date();
4876
- const assistant = {
4877
- id,
4878
- name: data.name,
4879
- description: data.description,
4880
- graphDefinition: data.graphDefinition,
4881
- createdAt: now,
4882
- updatedAt: now
4883
- };
4884
- this.assistants.set(id, assistant);
4885
- return assistant;
5840
+ getLatticeKeys() {
5841
+ return this.keys();
4886
5842
  }
4887
5843
  /**
4888
- * Update an existing assistant
5844
+ * Get vector store client
5845
+ * @param key Lattice key name
4889
5846
  */
4890
- async updateAssistant(id, updates) {
4891
- const existing = this.assistants.get(id);
4892
- if (!existing) {
4893
- return null;
4894
- }
4895
- const updated = {
4896
- ...existing,
4897
- ...updates,
4898
- updatedAt: /* @__PURE__ */ new Date()
5847
+ getVectorStoreClient(key) {
5848
+ const vectorStoreLattice = this.getVectorStoreLattice(key);
5849
+ return vectorStoreLattice.client;
5850
+ }
5851
+ };
5852
+ var vectorStoreLatticeManager = VectorStoreLatticeManager.getInstance();
5853
+ var registerVectorStoreLattice = (key, vectorStore) => vectorStoreLatticeManager.registerLattice(key, vectorStore);
5854
+ var getVectorStoreLattice = (key) => vectorStoreLatticeManager.getVectorStoreLattice(key);
5855
+ var getVectorStoreClient = (key) => vectorStoreLatticeManager.getVectorStoreClient(key);
5856
+
5857
+ // src/logger_lattice/LoggerLatticeManager.ts
5858
+ import {
5859
+ LoggerType
5860
+ } from "@axiom-lattice/protocols";
5861
+
5862
+ // src/logger_lattice/PinoLoggerClient.ts
5863
+ import pino from "pino";
5864
+ import "pino-pretty";
5865
+ import "pino-roll";
5866
+ var PinoLoggerClient = class _PinoLoggerClient {
5867
+ constructor(config) {
5868
+ this.config = config;
5869
+ this.context = config.context || {};
5870
+ const loggerConfig = {
5871
+ // Custom timestamp format
5872
+ timestamp: () => `,"@timestamp":"${(/* @__PURE__ */ new Date()).toISOString()}"`,
5873
+ // Base metadata
5874
+ base: {
5875
+ "@version": "1",
5876
+ app_name: "lattice",
5877
+ service_name: config.serviceName || "lattice-service",
5878
+ thread_name: "main",
5879
+ logger_name: config.loggerName || config.name || "lattice-logger"
5880
+ },
5881
+ formatters: {
5882
+ level: (label, number) => {
5883
+ return {
5884
+ level: label.toUpperCase(),
5885
+ level_value: number * 1e3
5886
+ };
5887
+ }
5888
+ }
4899
5889
  };
4900
- this.assistants.set(id, updated);
4901
- return updated;
5890
+ const useFileLogging = this.shouldUseFileLogging(config);
5891
+ const fileOptions = this.getFileOptions(config);
5892
+ if (useFileLogging && fileOptions) {
5893
+ try {
5894
+ this.pinoLogger = pino(
5895
+ loggerConfig,
5896
+ pino.transport({
5897
+ target: "pino-roll",
5898
+ options: {
5899
+ file: fileOptions.file || "./logs/app",
5900
+ frequency: fileOptions.frequency || "daily",
5901
+ mkdir: fileOptions.mkdir !== false,
5902
+ // Default to true
5903
+ size: fileOptions.size,
5904
+ maxFiles: fileOptions.maxFiles
5905
+ }
5906
+ })
5907
+ );
5908
+ } catch (error) {
5909
+ console.error(
5910
+ "Failed to initialize pino-roll logger, falling back to console",
5911
+ error
5912
+ );
5913
+ this.pinoLogger = pino({
5914
+ ...loggerConfig,
5915
+ transport: {
5916
+ target: "pino-pretty",
5917
+ options: {
5918
+ colorize: true
5919
+ }
5920
+ }
5921
+ });
5922
+ }
5923
+ } else {
5924
+ this.pinoLogger = pino({
5925
+ ...loggerConfig,
5926
+ transport: {
5927
+ target: "pino-pretty",
5928
+ options: {
5929
+ colorize: true
5930
+ }
5931
+ }
5932
+ });
5933
+ }
4902
5934
  }
4903
5935
  /**
4904
- * Delete an assistant by ID
5936
+ * Determine if file logging should be used
4905
5937
  */
4906
- async deleteAssistant(id) {
4907
- return this.assistants.delete(id);
5938
+ shouldUseFileLogging(config) {
5939
+ const hasFileConfig = config.file !== void 0;
5940
+ const isProduction = process.env.NODE_ENV === "production";
5941
+ return hasFileConfig || isProduction;
4908
5942
  }
4909
5943
  /**
4910
- * Check if assistant exists
5944
+ * Get file options from config
4911
5945
  */
4912
- async hasAssistant(id) {
4913
- return this.assistants.has(id);
5946
+ getFileOptions(config) {
5947
+ if (!config.file) {
5948
+ if (process.env.NODE_ENV === "production") {
5949
+ return {
5950
+ file: "./logs/app",
5951
+ frequency: "daily",
5952
+ mkdir: true
5953
+ };
5954
+ }
5955
+ return null;
5956
+ }
5957
+ if (typeof config.file === "string") {
5958
+ return {
5959
+ file: config.file,
5960
+ frequency: "daily",
5961
+ mkdir: true
5962
+ };
5963
+ }
5964
+ return config.file;
4914
5965
  }
4915
5966
  /**
4916
- * Clear all assistants (useful for testing)
5967
+ * Get contextual logger with merged context
4917
5968
  */
4918
- clear() {
4919
- this.assistants.clear();
5969
+ getContextualLogger(additionalContext) {
5970
+ const contextObj = {
5971
+ "x-user-id": this.context["x-user-id"] || "",
5972
+ "x-tenant-id": this.context["x-tenant-id"] || "",
5973
+ "x-request-id": this.context["x-request-id"] || "",
5974
+ "x-thread-id": this.context["x-thread-id"] || "",
5975
+ service_name: this.config.serviceName || "lattice-service",
5976
+ logger_name: this.config.loggerName || this.config.name || "lattice-logger",
5977
+ ...additionalContext
5978
+ };
5979
+ return this.pinoLogger.child(contextObj);
5980
+ }
5981
+ info(msg, obj) {
5982
+ this.getContextualLogger(obj).info(msg);
5983
+ }
5984
+ error(msg, obj) {
5985
+ this.getContextualLogger(obj).error(msg);
5986
+ }
5987
+ warn(msg, obj) {
5988
+ this.getContextualLogger(obj).warn(msg);
5989
+ }
5990
+ debug(msg, obj) {
5991
+ this.getContextualLogger(obj).debug(msg);
5992
+ }
5993
+ updateContext(context) {
5994
+ this.context = {
5995
+ ...this.context,
5996
+ ...context
5997
+ };
5998
+ }
5999
+ child(options) {
6000
+ return new _PinoLoggerClient({
6001
+ ...this.config,
6002
+ ...options,
6003
+ context: {
6004
+ ...this.context,
6005
+ ...options.context
6006
+ }
6007
+ });
6008
+ }
6009
+ };
6010
+
6011
+ // src/logger_lattice/ConsoleLoggerClient.ts
6012
+ var ConsoleLoggerClient = class _ConsoleLoggerClient {
6013
+ constructor(config) {
6014
+ this.config = config;
6015
+ this.context = config.context || {};
6016
+ }
6017
+ formatMessage(level, msg, obj) {
6018
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
6019
+ const contextStr = Object.keys(this.context).length > 0 ? ` [${JSON.stringify(this.context)}]` : "";
6020
+ const objStr = obj ? ` ${JSON.stringify(obj)}` : "";
6021
+ return `[${timestamp}] [${level}]${contextStr} ${msg}${objStr}`;
6022
+ }
6023
+ info(msg, obj) {
6024
+ console.log(this.formatMessage("INFO", msg, obj));
6025
+ }
6026
+ error(msg, obj) {
6027
+ console.error(this.formatMessage("ERROR", msg, obj));
6028
+ }
6029
+ warn(msg, obj) {
6030
+ console.warn(this.formatMessage("WARN", msg, obj));
6031
+ }
6032
+ debug(msg, obj) {
6033
+ console.debug(this.formatMessage("DEBUG", msg, obj));
6034
+ }
6035
+ updateContext(context) {
6036
+ this.context = {
6037
+ ...this.context,
6038
+ ...context
6039
+ };
6040
+ }
6041
+ child(options) {
6042
+ const childClient = new _ConsoleLoggerClient({
6043
+ ...this.config,
6044
+ ...options,
6045
+ context: {
6046
+ ...this.context,
6047
+ ...options.context
6048
+ }
6049
+ });
6050
+ return childClient;
4920
6051
  }
4921
6052
  };
4922
6053
 
4923
- // src/store_lattice/StoreLatticeManager.ts
4924
- var StoreLatticeManager = class _StoreLatticeManager extends BaseLatticeManager {
6054
+ // src/logger_lattice/LoggerLatticeManager.ts
6055
+ var LoggerLatticeManager = class _LoggerLatticeManager extends BaseLatticeManager {
4925
6056
  /**
4926
- * Get StoreLatticeManager singleton instance
6057
+ * Get LoggerLatticeManager singleton instance
4927
6058
  */
4928
6059
  static getInstance() {
4929
- if (!_StoreLatticeManager._instance) {
4930
- _StoreLatticeManager._instance = new _StoreLatticeManager();
6060
+ if (!_LoggerLatticeManager._instance) {
6061
+ _LoggerLatticeManager._instance = new _LoggerLatticeManager();
4931
6062
  }
4932
- return _StoreLatticeManager._instance;
6063
+ return _LoggerLatticeManager._instance;
4933
6064
  }
4934
6065
  /**
4935
6066
  * Get Lattice type prefix
4936
6067
  */
4937
6068
  getLatticeType() {
4938
- return "stores";
4939
- }
4940
- /**
4941
- * Generate composite key from key and type
4942
- * @param key Lattice key name
4943
- * @param type Store type
4944
- * @returns Composite key string
4945
- */
4946
- getCompositeKey(key, type) {
4947
- return `${key}:${type}`;
6069
+ return "loggers";
4948
6070
  }
4949
6071
  /**
4950
- * Register store Lattice with type safety
4951
- * Uses composite key (key + type) as unique identifier
6072
+ * Register logger Lattice
4952
6073
  * @param key Lattice key name
4953
- * @param type Store type (e.g., "thread")
4954
- * @param store Store implementation instance matching the type
6074
+ * @param config Logger configuration
6075
+ * @param client Optional logger client. If not provided, will create based on config type.
4955
6076
  */
4956
- registerLattice(key, type, store) {
4957
- const storeLattice = {
6077
+ registerLattice(key, config, client) {
6078
+ let loggerClient;
6079
+ if (client) {
6080
+ loggerClient = client;
6081
+ } else {
6082
+ if (config.type === LoggerType.PINO) {
6083
+ loggerClient = new PinoLoggerClient(config);
6084
+ } else if (config.type === LoggerType.CONSOLE) {
6085
+ loggerClient = new ConsoleLoggerClient(config);
6086
+ } else if (config.type === LoggerType.CUSTOM) {
6087
+ throw new Error(
6088
+ `Custom logger client must be provided. Please pass the client to registerLattice.`
6089
+ );
6090
+ } else {
6091
+ loggerClient = new PinoLoggerClient(config);
6092
+ }
6093
+ }
6094
+ const loggerLattice = {
4958
6095
  key,
4959
- type,
4960
- store
6096
+ config,
6097
+ client: loggerClient,
6098
+ // Logger operations
6099
+ info: (msg, obj) => {
6100
+ loggerClient.info(msg, obj);
6101
+ },
6102
+ error: (msg, obj) => {
6103
+ loggerClient.error(msg, obj);
6104
+ },
6105
+ warn: (msg, obj) => {
6106
+ loggerClient.warn(msg, obj);
6107
+ },
6108
+ debug: (msg, obj) => {
6109
+ loggerClient.debug(msg, obj);
6110
+ },
6111
+ updateContext: loggerClient.updateContext ? (context) => {
6112
+ loggerClient.updateContext(context);
6113
+ } : void 0,
6114
+ child: loggerClient.child ? (options) => {
6115
+ return loggerClient.child(options);
6116
+ } : void 0
4961
6117
  };
4962
- const compositeKey = this.getCompositeKey(key, type);
4963
- this.register(compositeKey, storeLattice);
4964
- }
4965
- /**
4966
- * Get StoreLattice with type safety
4967
- * Uses composite key (key + type) to retrieve the store
4968
- * @param key Lattice key name
4969
- * @param type Expected store type for type checking
4970
- * @returns StoreLattice with typed store
4971
- */
4972
- getStoreLattice(key, type) {
4973
- const compositeKey = this.getCompositeKey(key, type);
4974
- const storeLattice = this.get(compositeKey);
4975
- if (!storeLattice) {
4976
- throw new Error(`StoreLattice ${key}:${type} not found`);
4977
- }
4978
- if (storeLattice.type !== type) {
4979
- throw new Error(
4980
- `StoreLattice ${key}:${type} has type "${storeLattice.type}", expected "${type}"`
4981
- );
4982
- }
4983
- return storeLattice;
6118
+ this.register(key, loggerLattice);
4984
6119
  }
4985
6120
  /**
4986
- * Get StoreLattice without type checking (for backward compatibility)
6121
+ * Get LoggerLattice
4987
6122
  * @param key Lattice key name
4988
- * @param type Store type
4989
- * @returns StoreLattice (type may be unknown)
4990
6123
  */
4991
- getStoreLatticeUnsafe(key, type) {
4992
- const compositeKey = this.getCompositeKey(key, type);
4993
- const storeLattice = this.get(compositeKey);
4994
- if (!storeLattice) {
4995
- throw new Error(`StoreLattice ${key}:${type} not found`);
6124
+ getLoggerLattice(key) {
6125
+ const loggerLattice = this.get(key);
6126
+ if (!loggerLattice) {
6127
+ throw new Error(`LoggerLattice ${key} not found`);
4996
6128
  }
4997
- return storeLattice;
6129
+ return loggerLattice;
4998
6130
  }
4999
6131
  /**
5000
6132
  * Get all Lattices
@@ -5004,23 +6136,17 @@ var StoreLatticeManager = class _StoreLatticeManager extends BaseLatticeManager
5004
6136
  }
5005
6137
  /**
5006
6138
  * Check if Lattice exists
5007
- * Uses composite key (key + type) to check existence
5008
6139
  * @param key Lattice key name
5009
- * @param type Store type
5010
6140
  */
5011
- hasLattice(key, type) {
5012
- const compositeKey = this.getCompositeKey(key, type);
5013
- return this.has(compositeKey);
6141
+ hasLattice(key) {
6142
+ return this.has(key);
5014
6143
  }
5015
6144
  /**
5016
6145
  * Remove Lattice
5017
- * Uses composite key (key + type) to remove the store
5018
6146
  * @param key Lattice key name
5019
- * @param type Store type
5020
6147
  */
5021
- removeLattice(key, type) {
5022
- const compositeKey = this.getCompositeKey(key, type);
5023
- return this.remove(compositeKey);
6148
+ removeLattice(key) {
6149
+ return this.remove(key);
5024
6150
  }
5025
6151
  /**
5026
6152
  * Clear all Lattices
@@ -5041,63 +6167,151 @@ var StoreLatticeManager = class _StoreLatticeManager extends BaseLatticeManager
5041
6167
  return this.keys();
5042
6168
  }
5043
6169
  };
5044
- var storeLatticeManager = StoreLatticeManager.getInstance();
5045
- var registerStoreLattice = (key, type, store) => storeLatticeManager.registerLattice(key, type, store);
5046
- var getStoreLattice = (key, type) => storeLatticeManager.getStoreLattice(key, type);
5047
- var defaultThreadStore = new InMemoryThreadStore();
5048
- var defaultAssistantStore = new InMemoryAssistantStore();
5049
- storeLatticeManager.registerLattice("default", "thread", defaultThreadStore);
5050
- storeLatticeManager.registerLattice(
5051
- "default",
5052
- "assistant",
5053
- defaultAssistantStore
5054
- );
6170
+ var loggerLatticeManager = LoggerLatticeManager.getInstance();
6171
+ var registerLoggerLattice = (key, config, client) => loggerLatticeManager.registerLattice(key, config, client);
6172
+ var getLoggerLattice = (key) => loggerLatticeManager.getLoggerLattice(key);
5055
6173
 
5056
- // src/embeddings_lattice/EmbeddingsLatticeManager.ts
5057
- var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatticeManager {
6174
+ // src/skill_lattice/SkillLatticeManager.ts
6175
+ var SkillLatticeManager = class _SkillLatticeManager extends BaseLatticeManager {
5058
6176
  /**
5059
- * Get EmbeddingsLatticeManager singleton instance
6177
+ * Get SkillLatticeManager singleton instance
5060
6178
  */
5061
6179
  static getInstance() {
5062
- if (!_EmbeddingsLatticeManager._instance) {
5063
- _EmbeddingsLatticeManager._instance = new _EmbeddingsLatticeManager();
6180
+ if (!_SkillLatticeManager._instance) {
6181
+ _SkillLatticeManager._instance = new _SkillLatticeManager();
5064
6182
  }
5065
- return _EmbeddingsLatticeManager._instance;
6183
+ return _SkillLatticeManager._instance;
5066
6184
  }
5067
6185
  /**
5068
6186
  * Get Lattice type prefix
5069
6187
  */
5070
6188
  getLatticeType() {
5071
- return "embeddings";
6189
+ return "skills";
5072
6190
  }
5073
6191
  /**
5074
- * Register embeddings Lattice
6192
+ * Configure store for persistence
6193
+ * @param storeKey Store key name registered in StoreLatticeManager
6194
+ */
6195
+ configureStore(storeKey) {
6196
+ this.storeKey = storeKey;
6197
+ }
6198
+ /**
6199
+ * Get configured store
6200
+ * @returns SkillStore instance if configured, null otherwise
6201
+ */
6202
+ getStore() {
6203
+ if (!this.storeKey) {
6204
+ return null;
6205
+ }
6206
+ try {
6207
+ const storeLattice = storeLatticeManager.getStoreLattice(
6208
+ this.storeKey,
6209
+ "skill"
6210
+ );
6211
+ return storeLattice.store;
6212
+ } catch {
6213
+ return null;
6214
+ }
6215
+ }
6216
+ /**
6217
+ * Inject store into client if client supports it
6218
+ * @param client Skill client instance
6219
+ * @param store Store instance to inject
6220
+ */
6221
+ injectStoreIntoClient(client, store) {
6222
+ if (!client || typeof client !== "object") {
6223
+ return;
6224
+ }
6225
+ if (typeof client.setStore === "function") {
6226
+ client.setStore(store);
6227
+ }
6228
+ client.store = store;
6229
+ }
6230
+ /**
6231
+ * Register a skill Lattice
5075
6232
  * @param key Lattice key name
5076
- * @param embeddings Embeddings instance
6233
+ * @param config Skill configuration
6234
+ * @param client Optional skill client implementation
5077
6235
  */
5078
- registerLattice(key, embeddings) {
5079
- const embeddingsLattice = {
6236
+ async registerLattice(key, config, client) {
6237
+ if (!config.name) {
6238
+ throw new Error("Skill name is required");
6239
+ }
6240
+ if (!config.description) {
6241
+ throw new Error("Skill description is required");
6242
+ }
6243
+ validateSkillName(config.name);
6244
+ if (key !== config.name) {
6245
+ throw new Error(
6246
+ `Skill key "${key}" must equal name "${config.name}" (name is used for path addressing)`
6247
+ );
6248
+ }
6249
+ const store = this.getStore();
6250
+ if (client && store) {
6251
+ this.injectStoreIntoClient(client, store);
6252
+ }
6253
+ const skillLattice = {
5080
6254
  key,
5081
- client: embeddings
6255
+ config,
6256
+ client: client ?? null
5082
6257
  };
5083
- this.register(key, embeddingsLattice);
6258
+ this.register(key, skillLattice);
6259
+ if (store) {
6260
+ try {
6261
+ await store.createSkill(key, {
6262
+ name: config.name,
6263
+ description: config.description,
6264
+ license: config.license,
6265
+ compatibility: config.compatibility,
6266
+ metadata: config.metadata,
6267
+ content: config.content,
6268
+ subSkills: config.subSkills
6269
+ });
6270
+ } catch (error) {
6271
+ console.warn(
6272
+ `Failed to persist skill ${key} to store:`,
6273
+ error instanceof Error ? error.message : String(error)
6274
+ );
6275
+ }
6276
+ }
5084
6277
  }
5085
6278
  /**
5086
- * Get EmbeddingsLattice
6279
+ * Get skill Lattice by key
5087
6280
  * @param key Lattice key name
5088
6281
  */
5089
- getEmbeddingsLattice(key) {
5090
- const embeddingsLattice = this.get(key);
5091
- if (!embeddingsLattice) {
5092
- throw new Error(`EmbeddingsLattice ${key} not found`);
5093
- }
5094
- return embeddingsLattice;
6282
+ getSkillLattice(key) {
6283
+ return this.get(key);
5095
6284
  }
5096
6285
  /**
5097
- * Get all Lattices
6286
+ * Get all skill Lattices from store
6287
+ * Always reads from the configured store and merges with in-memory clients
5098
6288
  */
5099
- getAllLattices() {
5100
- return this.getAll();
6289
+ async getAllLattices() {
6290
+ const store = this.getStore();
6291
+ if (!store) {
6292
+ return this.getAll();
6293
+ }
6294
+ const skills = await store.getAllSkills();
6295
+ return skills.map((skill) => {
6296
+ const memoryLattice = this.get(skill.id);
6297
+ const client = memoryLattice?.client || null;
6298
+ if (client && store) {
6299
+ this.injectStoreIntoClient(client, store);
6300
+ }
6301
+ return {
6302
+ key: skill.id,
6303
+ config: {
6304
+ name: skill.name,
6305
+ description: skill.description,
6306
+ license: skill.license,
6307
+ compatibility: skill.compatibility,
6308
+ metadata: skill.metadata,
6309
+ content: skill.content,
6310
+ subSkills: skill.subSkills
6311
+ },
6312
+ client
6313
+ };
6314
+ });
5101
6315
  }
5102
6316
  /**
5103
6317
  * Check if Lattice exists
@@ -5110,8 +6324,22 @@ var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatti
5110
6324
  * Remove Lattice
5111
6325
  * @param key Lattice key name
5112
6326
  */
5113
- removeLattice(key) {
5114
- return this.remove(key);
6327
+ async removeLattice(key) {
6328
+ const removed = this.remove(key);
6329
+ if (removed) {
6330
+ const store = this.getStore();
6331
+ if (store) {
6332
+ try {
6333
+ await store.deleteSkill(key);
6334
+ } catch (error) {
6335
+ console.warn(
6336
+ `Failed to remove skill ${key} from store:`,
6337
+ error instanceof Error ? error.message : String(error)
6338
+ );
6339
+ }
6340
+ }
6341
+ }
6342
+ return removed;
5115
6343
  }
5116
6344
  /**
5117
6345
  * Clear all Lattices
@@ -5126,116 +6354,139 @@ var EmbeddingsLatticeManager = class _EmbeddingsLatticeManager extends BaseLatti
5126
6354
  return this.count();
5127
6355
  }
5128
6356
  /**
5129
- * Get Lattice key list
6357
+ * Get Lattice key name list
5130
6358
  */
5131
6359
  getLatticeKeys() {
5132
6360
  return this.keys();
5133
6361
  }
5134
6362
  /**
5135
- * Get embeddings client
6363
+ * Get skill configuration
5136
6364
  * @param key Lattice key name
5137
6365
  */
5138
- getEmbeddingsClient(key) {
5139
- const embeddingsLattice = this.getEmbeddingsLattice(key);
5140
- return embeddingsLattice.client;
5141
- }
5142
- };
5143
- var embeddingsLatticeManager = EmbeddingsLatticeManager.getInstance();
5144
- var registerEmbeddingsLattice = (key, embeddings) => embeddingsLatticeManager.registerLattice(key, embeddings);
5145
- var getEmbeddingsLattice = (key) => embeddingsLatticeManager.getEmbeddingsLattice(key);
5146
- var getEmbeddingsClient = (key) => embeddingsLatticeManager.getEmbeddingsClient(key);
5147
-
5148
- // src/vectorstore_lattice/VectorStoreLatticeManager.ts
5149
- var VectorStoreLatticeManager = class _VectorStoreLatticeManager extends BaseLatticeManager {
5150
- /**
5151
- * Get VectorStoreLatticeManager singleton instance
5152
- */
5153
- static getInstance() {
5154
- if (!_VectorStoreLatticeManager._instance) {
5155
- _VectorStoreLatticeManager._instance = new _VectorStoreLatticeManager();
6366
+ getSkillConfig(key) {
6367
+ const skillLattice = this.getSkillLattice(key);
6368
+ if (!skillLattice) {
6369
+ throw new Error(`SkillLattice ${key} not found`);
5156
6370
  }
5157
- return _VectorStoreLatticeManager._instance;
5158
- }
5159
- /**
5160
- * Get Lattice type prefix
5161
- */
5162
- getLatticeType() {
5163
- return "vectorstores";
6371
+ return skillLattice.config;
5164
6372
  }
5165
6373
  /**
5166
- * Register vector store Lattice
5167
- * @param key Lattice key name
5168
- * @param vectorStore VectorStore instance
5169
- */
5170
- registerLattice(key, vectorStore) {
5171
- const vectorStoreLattice = {
5172
- key,
5173
- client: vectorStore
5174
- };
5175
- this.register(key, vectorStoreLattice);
5176
- }
5177
- /**
5178
- * Get VectorStoreLattice
6374
+ * Get skill client
6375
+ * Ensures client has store access if store is configured
5179
6376
  * @param key Lattice key name
5180
6377
  */
5181
- getVectorStoreLattice(key) {
5182
- const vectorStoreLattice = this.get(key);
5183
- if (!vectorStoreLattice) {
5184
- throw new Error(`VectorStoreLattice ${key} not found`);
6378
+ getSkillClient(key) {
6379
+ const skillLattice = this.getSkillLattice(key);
6380
+ if (!skillLattice) {
6381
+ throw new Error(`SkillLattice ${key} not found`);
5185
6382
  }
5186
- return vectorStoreLattice;
5187
- }
5188
- /**
5189
- * Get all Lattices
5190
- */
5191
- getAllLattices() {
5192
- return this.getAll();
6383
+ const client = skillLattice.client;
6384
+ if (!client) {
6385
+ return null;
6386
+ }
6387
+ const store = this.getStore();
6388
+ if (store && client) {
6389
+ this.injectStoreIntoClient(client, store);
6390
+ }
6391
+ return client;
5193
6392
  }
5194
6393
  /**
5195
- * Check if Lattice exists
5196
- * @param key Lattice key name
6394
+ * Get all skill configurations from store
6395
+ * Always reads from the configured store, not from memory
5197
6396
  */
5198
- hasLattice(key) {
5199
- return this.has(key);
6397
+ async getAllSkillConfigs() {
6398
+ const lattices = await this.getAllLattices();
6399
+ return lattices.map((lattice) => lattice.config);
5200
6400
  }
5201
6401
  /**
5202
- * Remove Lattice
5203
- * @param key Lattice key name
6402
+ * Search skills by metadata
6403
+ * @param metadataKey Metadata key to search for
6404
+ * @param metadataValue Metadata value to match
5204
6405
  */
5205
- removeLattice(key) {
5206
- return this.remove(key);
6406
+ async searchByMetadata(metadataKey, metadataValue) {
6407
+ const lattices = await this.getAllLattices();
6408
+ return lattices.filter((lattice) => {
6409
+ return lattice.config.metadata && lattice.config.metadata[metadataKey] === metadataValue;
6410
+ });
5207
6411
  }
5208
6412
  /**
5209
- * Clear all Lattices
6413
+ * Filter skills by compatibility
6414
+ * @param compatibility Compatibility string to filter by
5210
6415
  */
5211
- clearLattices() {
5212
- this.clear();
6416
+ async filterByCompatibility(compatibility) {
6417
+ const lattices = await this.getAllLattices();
6418
+ return lattices.filter((lattice) => {
6419
+ return lattice.config.compatibility === compatibility;
6420
+ });
5213
6421
  }
5214
6422
  /**
5215
- * Get Lattice count
6423
+ * Filter skills by license
6424
+ * @param license License string to filter by
5216
6425
  */
5217
- getLatticeCount() {
5218
- return this.count();
6426
+ async filterByLicense(license) {
6427
+ const lattices = await this.getAllLattices();
6428
+ return lattices.filter((lattice) => {
6429
+ return lattice.config.license === license;
6430
+ });
5219
6431
  }
5220
6432
  /**
5221
- * Get Lattice key list
5222
- */
5223
- getLatticeKeys() {
5224
- return this.keys();
6433
+ * Load skills from configured store
6434
+ * This method loads all skills from the store and registers them in memory
6435
+ */
6436
+ async loadFromStore() {
6437
+ const store = this.getStore();
6438
+ if (!store) {
6439
+ throw new Error("No store configured. Call configureStore() first.");
6440
+ }
6441
+ const skills = await store.getAllSkills();
6442
+ for (const skill of skills) {
6443
+ const skillLattice = {
6444
+ key: skill.id,
6445
+ config: {
6446
+ name: skill.name,
6447
+ description: skill.description,
6448
+ license: skill.license,
6449
+ compatibility: skill.compatibility,
6450
+ metadata: skill.metadata,
6451
+ content: skill.content,
6452
+ subSkills: skill.subSkills
6453
+ },
6454
+ client: null
6455
+ };
6456
+ this.register(skill.id, skillLattice);
6457
+ }
5225
6458
  }
5226
6459
  /**
5227
- * Get vector store client
5228
- * @param key Lattice key name
6460
+ * Update skill in store
6461
+ * @param key Skill key
6462
+ * @param updates Partial skill data to update
5229
6463
  */
5230
- getVectorStoreClient(key) {
5231
- const vectorStoreLattice = this.getVectorStoreLattice(key);
5232
- return vectorStoreLattice.client;
6464
+ async updateSkillInStore(key, updates) {
6465
+ const store = this.getStore();
6466
+ if (!store) {
6467
+ throw new Error("No store configured. Call configureStore() first.");
6468
+ }
6469
+ const skillLattice = this.getSkillLattice(key);
6470
+ if (!skillLattice) {
6471
+ throw new Error(`SkillLattice ${key} not found`);
6472
+ }
6473
+ const updatedConfig = {
6474
+ ...skillLattice.config,
6475
+ ...updates
6476
+ };
6477
+ skillLattice.config = updatedConfig;
6478
+ await store.updateSkill(key, {
6479
+ name: updatedConfig.name,
6480
+ description: updatedConfig.description,
6481
+ license: updatedConfig.license,
6482
+ compatibility: updatedConfig.compatibility,
6483
+ metadata: updatedConfig.metadata,
6484
+ content: updatedConfig.content,
6485
+ subSkills: updatedConfig.subSkills
6486
+ });
5233
6487
  }
5234
6488
  };
5235
- var vectorStoreLatticeManager = VectorStoreLatticeManager.getInstance();
5236
- var registerVectorStoreLattice = (key, vectorStore) => vectorStoreLatticeManager.registerLattice(key, vectorStore);
5237
- var getVectorStoreLattice = (key) => vectorStoreLatticeManager.getVectorStoreLattice(key);
5238
- var getVectorStoreClient = (key) => vectorStoreLatticeManager.getVectorStoreClient(key);
6489
+ var skillLatticeManager = SkillLatticeManager.getInstance();
5239
6490
 
5240
6491
  // src/index.ts
5241
6492
  import * as Protocols from "@axiom-lattice/protocols";
@@ -5247,21 +6498,26 @@ export {
5247
6498
  AgentType,
5248
6499
  ChunkBuffer,
5249
6500
  ChunkBufferLatticeManager,
6501
+ ConsoleLoggerClient,
5250
6502
  DefaultScheduleClient,
5251
6503
  EmbeddingsLatticeManager,
6504
+ FileSystemSkillStore,
5252
6505
  GraphBuildOptions,
5253
6506
  InMemoryAssistantStore,
5254
6507
  InMemoryChunkBuffer,
5255
6508
  InMemoryThreadStore,
6509
+ LoggerLatticeManager,
5256
6510
  MemoryLatticeManager,
5257
6511
  MemoryQueueClient,
5258
6512
  MemoryScheduleStorage,
5259
6513
  MemoryType,
5260
6514
  ModelLatticeManager,
6515
+ PinoLoggerClient,
5261
6516
  PostgresDatabase,
5262
6517
  Protocols,
5263
6518
  QueueLatticeManager,
5264
6519
  ScheduleLatticeManager,
6520
+ SkillLatticeManager,
5265
6521
  SqlDatabaseManager,
5266
6522
  StoreLatticeManager,
5267
6523
  ThreadStatus,
@@ -5281,6 +6537,7 @@ export {
5281
6537
  getChunkBuffer,
5282
6538
  getEmbeddingsClient,
5283
6539
  getEmbeddingsLattice,
6540
+ getLoggerLattice,
5284
6541
  getModelLattice,
5285
6542
  getNextCronTime,
5286
6543
  getQueueLattice,
@@ -5293,6 +6550,8 @@ export {
5293
6550
  getVectorStoreLattice,
5294
6551
  hasChunkBuffer,
5295
6552
  isValidCronExpression,
6553
+ isValidSkillName,
6554
+ loggerLatticeManager,
5296
6555
  modelLatticeManager,
5297
6556
  parseCronExpression,
5298
6557
  queueLatticeManager,
@@ -5301,6 +6560,7 @@ export {
5301
6560
  registerCheckpointSaver,
5302
6561
  registerChunkBuffer,
5303
6562
  registerEmbeddingsLattice,
6563
+ registerLoggerLattice,
5304
6564
  registerModelLattice,
5305
6565
  registerQueueLattice,
5306
6566
  registerScheduleLattice,
@@ -5308,10 +6568,12 @@ export {
5308
6568
  registerToolLattice,
5309
6569
  registerVectorStoreLattice,
5310
6570
  scheduleLatticeManager,
6571
+ skillLatticeManager,
5311
6572
  sqlDatabaseManager,
5312
6573
  storeLatticeManager,
5313
6574
  toolLatticeManager,
5314
6575
  validateAgentInput,
6576
+ validateSkillName,
5315
6577
  validateToolInput,
5316
6578
  vectorStoreLatticeManager
5317
6579
  };