@jaypie/fabric 0.1.1 → 0.1.3
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/cjs/ServiceSuite.d.ts +58 -0
- package/dist/cjs/commander/index.cjs +7 -7
- package/dist/cjs/commander/index.cjs.map +1 -1
- package/dist/cjs/data/index.cjs.map +1 -1
- package/dist/cjs/http/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +159 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/lambda/index.cjs +7 -7
- package/dist/cjs/lambda/index.cjs.map +1 -1
- package/dist/cjs/llm/index.cjs +7 -7
- package/dist/cjs/llm/index.cjs.map +1 -1
- package/dist/cjs/mcp/FabricMcpServer.d.ts +44 -0
- package/dist/cjs/mcp/index.cjs +156 -7
- package/dist/cjs/mcp/index.cjs.map +1 -1
- package/dist/cjs/mcp/index.d.ts +2 -1
- package/dist/cjs/mcp/types.d.ts +66 -0
- package/dist/cjs/service.d.ts +5 -0
- package/dist/esm/ServiceSuite.d.ts +58 -0
- package/dist/esm/commander/index.js +7 -7
- package/dist/esm/commander/index.js.map +1 -1
- package/dist/esm/data/index.js.map +1 -1
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +158 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lambda/index.js +7 -7
- package/dist/esm/lambda/index.js.map +1 -1
- package/dist/esm/llm/index.js +7 -7
- package/dist/esm/llm/index.js.map +1 -1
- package/dist/esm/mcp/FabricMcpServer.d.ts +44 -0
- package/dist/esm/mcp/index.d.ts +2 -1
- package/dist/esm/mcp/index.js +155 -8
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/mcp/types.d.ts +66 -0
- package/package.json +1 -1
- package/dist/cjs/commander/registerServiceCommand.d.ts +0 -43
- package/dist/cjs/convert-date.d.ts +0 -47
- package/dist/cjs/convert.d.ts +0 -69
- package/dist/cjs/lambda/createLambdaService.d.ts +0 -33
- package/dist/cjs/llm/createLlmTool.d.ts +0 -40
- package/dist/cjs/mcp/registerMcpTool.d.ts +0 -38
- package/dist/cjs/types/fieldCategory.d.ts +0 -20
- package/dist/esm/commander/registerServiceCommand.d.ts +0 -43
- package/dist/esm/convert-date.d.ts +0 -47
- package/dist/esm/convert.d.ts +0 -69
- package/dist/esm/lambda/createLambdaService.d.ts +0 -33
- package/dist/esm/llm/createLlmTool.d.ts +0 -40
- package/dist/esm/mcp/registerMcpTool.d.ts +0 -38
- package/dist/esm/types/fieldCategory.d.ts +0 -20
package/dist/cjs/index.cjs
CHANGED
|
@@ -1452,6 +1452,13 @@ async function processField(fieldName, value, definition) {
|
|
|
1452
1452
|
}
|
|
1453
1453
|
return convertedValue;
|
|
1454
1454
|
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Type guard to check if a value is a pre-instantiated Service
|
|
1457
|
+
* A Service is a function with the `$fabric` property set by fabricService
|
|
1458
|
+
*/
|
|
1459
|
+
function isService(value) {
|
|
1460
|
+
return typeof value === "function" && "$fabric" in value;
|
|
1461
|
+
}
|
|
1455
1462
|
/**
|
|
1456
1463
|
* Fabric a service function
|
|
1457
1464
|
*
|
|
@@ -1504,13 +1511,6 @@ function fabricService(config) {
|
|
|
1504
1511
|
}
|
|
1505
1512
|
|
|
1506
1513
|
// Resolve inline service definitions to full Service objects
|
|
1507
|
-
/**
|
|
1508
|
-
* Type guard to check if a value is a pre-instantiated Service
|
|
1509
|
-
* A Service is a function with the `$fabric` property set by fabricService
|
|
1510
|
-
*/
|
|
1511
|
-
function isService(value) {
|
|
1512
|
-
return typeof value === "function" && "$fabric" in value;
|
|
1513
|
-
}
|
|
1514
1514
|
/**
|
|
1515
1515
|
* Resolve a service configuration to a full Service object
|
|
1516
1516
|
*
|
|
@@ -1566,6 +1566,156 @@ function resolveService(config) {
|
|
|
1566
1566
|
});
|
|
1567
1567
|
}
|
|
1568
1568
|
|
|
1569
|
+
// ServiceSuite for @jaypie/fabric
|
|
1570
|
+
// Groups fabricService instances for discovery, metadata export, and direct execution
|
|
1571
|
+
/**
|
|
1572
|
+
* Derive type string from InputFieldDefinition.type
|
|
1573
|
+
*/
|
|
1574
|
+
function deriveTypeString(type) {
|
|
1575
|
+
// Handle constructors
|
|
1576
|
+
if (type === String || type === "string")
|
|
1577
|
+
return "string";
|
|
1578
|
+
if (type === Number || type === "number")
|
|
1579
|
+
return "number";
|
|
1580
|
+
if (type === Boolean || type === "boolean")
|
|
1581
|
+
return "boolean";
|
|
1582
|
+
if (type === Object || type === "object")
|
|
1583
|
+
return "object";
|
|
1584
|
+
if (type === Array || type === "array")
|
|
1585
|
+
return "array";
|
|
1586
|
+
if (type === Date)
|
|
1587
|
+
return "string"; // Dates are passed as strings
|
|
1588
|
+
// Handle typed arrays: [String], [Number], etc.
|
|
1589
|
+
if (Array.isArray(type)) {
|
|
1590
|
+
if (type.length === 0)
|
|
1591
|
+
return "array";
|
|
1592
|
+
const first = type[0];
|
|
1593
|
+
// If it's a type constructor, it's a typed array
|
|
1594
|
+
if (first === String ||
|
|
1595
|
+
first === Number ||
|
|
1596
|
+
first === Boolean ||
|
|
1597
|
+
first === Object ||
|
|
1598
|
+
first === "string" ||
|
|
1599
|
+
first === "number" ||
|
|
1600
|
+
first === "boolean" ||
|
|
1601
|
+
first === "object" ||
|
|
1602
|
+
first === "") {
|
|
1603
|
+
return "array";
|
|
1604
|
+
}
|
|
1605
|
+
// If all elements are strings (or RegExp), it's a validated string enum
|
|
1606
|
+
if (type.every((item) => typeof item === "string" || item instanceof RegExp)) {
|
|
1607
|
+
return "string";
|
|
1608
|
+
}
|
|
1609
|
+
// If all elements are numbers, it's a validated number enum
|
|
1610
|
+
if (type.every((item) => typeof item === "number")) {
|
|
1611
|
+
return "number";
|
|
1612
|
+
}
|
|
1613
|
+
return "array";
|
|
1614
|
+
}
|
|
1615
|
+
// Handle RegExp (validated string)
|
|
1616
|
+
if (type instanceof RegExp) {
|
|
1617
|
+
return "string";
|
|
1618
|
+
}
|
|
1619
|
+
return "string"; // Default fallback
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Extract enum values if the type is a validated string/number array
|
|
1623
|
+
*/
|
|
1624
|
+
function extractEnumValues(type) {
|
|
1625
|
+
if (!Array.isArray(type))
|
|
1626
|
+
return undefined;
|
|
1627
|
+
if (type.length === 0)
|
|
1628
|
+
return undefined;
|
|
1629
|
+
// Check if it's a validated string enum (array of strings, possibly with RegExp)
|
|
1630
|
+
const stringValues = type.filter((item) => typeof item === "string");
|
|
1631
|
+
if (stringValues.length > 0 && stringValues.length === type.filter((item) => typeof item === "string").length) {
|
|
1632
|
+
// All non-RegExp items are strings
|
|
1633
|
+
return stringValues;
|
|
1634
|
+
}
|
|
1635
|
+
// Check if it's a validated number enum
|
|
1636
|
+
if (type.every((item) => typeof item === "number")) {
|
|
1637
|
+
return type.map((n) => String(n));
|
|
1638
|
+
}
|
|
1639
|
+
return undefined;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Convert fabricService input definitions to ServiceInput array
|
|
1643
|
+
*/
|
|
1644
|
+
function extractInputs(inputDefinitions) {
|
|
1645
|
+
if (!inputDefinitions)
|
|
1646
|
+
return [];
|
|
1647
|
+
return Object.entries(inputDefinitions).map(([name, def]) => {
|
|
1648
|
+
const required = def.required !== false && def.default === undefined;
|
|
1649
|
+
const enumValues = extractEnumValues(def.type);
|
|
1650
|
+
return {
|
|
1651
|
+
name,
|
|
1652
|
+
type: deriveTypeString(def.type),
|
|
1653
|
+
required,
|
|
1654
|
+
description: def.description || "",
|
|
1655
|
+
...(enumValues && { enum: enumValues }),
|
|
1656
|
+
};
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Check if a service has any required inputs
|
|
1661
|
+
*/
|
|
1662
|
+
function hasRequiredInputs(inputs) {
|
|
1663
|
+
return inputs.some((input) => input.required);
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Create a ServiceSuite instance
|
|
1667
|
+
*/
|
|
1668
|
+
function createServiceSuite(config) {
|
|
1669
|
+
const { name, version } = config;
|
|
1670
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1671
|
+
const serviceRegistry = new Map();
|
|
1672
|
+
const categorySet = new Set();
|
|
1673
|
+
const suite = {
|
|
1674
|
+
name,
|
|
1675
|
+
version,
|
|
1676
|
+
get categories() {
|
|
1677
|
+
return Array.from(categorySet).sort();
|
|
1678
|
+
},
|
|
1679
|
+
get services() {
|
|
1680
|
+
return Array.from(serviceRegistry.values()).map((entry) => entry.meta);
|
|
1681
|
+
},
|
|
1682
|
+
getService(serviceName) {
|
|
1683
|
+
return serviceRegistry.get(serviceName)?.meta;
|
|
1684
|
+
},
|
|
1685
|
+
getServicesByCategory(category) {
|
|
1686
|
+
return Array.from(serviceRegistry.values())
|
|
1687
|
+
.filter((entry) => entry.meta.category === category)
|
|
1688
|
+
.map((entry) => entry.meta);
|
|
1689
|
+
},
|
|
1690
|
+
async execute(serviceName, inputs) {
|
|
1691
|
+
const entry = serviceRegistry.get(serviceName);
|
|
1692
|
+
if (!entry) {
|
|
1693
|
+
throw new Error(`Service "${serviceName}" not found in suite "${name}"`);
|
|
1694
|
+
}
|
|
1695
|
+
return entry.service(inputs);
|
|
1696
|
+
},
|
|
1697
|
+
register(
|
|
1698
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1699
|
+
service, category) {
|
|
1700
|
+
const serviceName = service.alias;
|
|
1701
|
+
if (!serviceName) {
|
|
1702
|
+
throw new Error("Service must have an alias to be registered");
|
|
1703
|
+
}
|
|
1704
|
+
const inputs = extractInputs(service.input);
|
|
1705
|
+
const meta = {
|
|
1706
|
+
name: serviceName,
|
|
1707
|
+
description: service.description || "",
|
|
1708
|
+
category,
|
|
1709
|
+
inputs,
|
|
1710
|
+
executable: !hasRequiredInputs(inputs),
|
|
1711
|
+
};
|
|
1712
|
+
serviceRegistry.set(serviceName, { service, meta });
|
|
1713
|
+
categorySet.add(category);
|
|
1714
|
+
},
|
|
1715
|
+
};
|
|
1716
|
+
return suite;
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1569
1719
|
/**
|
|
1570
1720
|
* Status Type for @jaypie/fabric
|
|
1571
1721
|
*
|
|
@@ -1637,6 +1787,7 @@ exports.calculateScope = calculateScope;
|
|
|
1637
1787
|
exports.clearRegistry = clearRegistry;
|
|
1638
1788
|
exports.computeResolvedName = computeResolvedName;
|
|
1639
1789
|
exports.createFabricModelInput = createFabricModelInput;
|
|
1790
|
+
exports.createServiceSuite = createServiceSuite;
|
|
1640
1791
|
exports.fabric = fabric;
|
|
1641
1792
|
exports.fabricArray = fabricArray;
|
|
1642
1793
|
exports.fabricBoolean = fabricBoolean;
|
|
@@ -1659,6 +1810,7 @@ exports.isElementaryType = isElementaryType;
|
|
|
1659
1810
|
exports.isFabricModel = isFabricModel;
|
|
1660
1811
|
exports.isFieldDefinition = isFieldDefinition;
|
|
1661
1812
|
exports.isModelRegistered = isModelRegistered;
|
|
1813
|
+
exports.isService = isService;
|
|
1662
1814
|
exports.isStatus = isStatus;
|
|
1663
1815
|
exports.isTimestampField = isTimestampField;
|
|
1664
1816
|
exports.isValidDate = isValidDate;
|