@flutchai/flutch-sdk 0.2.17 → 0.2.19
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.cjs +137 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +138 -113
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -337,11 +337,6 @@ function registerUIEndpointsFromClass(endpointRegistry, EndpointClass, instance)
|
|
|
337
337
|
if (methodsMetadata.length === 0) {
|
|
338
338
|
return;
|
|
339
339
|
}
|
|
340
|
-
console.log("DEBUG: registerUIEndpointsFromClass", {
|
|
341
|
-
hasInstance: !!instance,
|
|
342
|
-
willCreateNew: !instance,
|
|
343
|
-
className: EndpointClass.name
|
|
344
|
-
});
|
|
345
340
|
const endpointInstance = instance || new EndpointClass();
|
|
346
341
|
const descriptors = methodsMetadata.map((meta) => ({
|
|
347
342
|
name: meta.endpointName,
|
|
@@ -403,11 +398,6 @@ var init_ui_endpoints_discovery = __esm({
|
|
|
403
398
|
}
|
|
404
399
|
if (hasUIEndpoints(metatype)) {
|
|
405
400
|
this.logger.debug(`Found UI endpoints class: ${metatype.name}`);
|
|
406
|
-
console.log("DEBUG: Discovery found instance", {
|
|
407
|
-
className: metatype.name,
|
|
408
|
-
hasInstance: !!instance,
|
|
409
|
-
instanceType: typeof instance
|
|
410
|
-
});
|
|
411
401
|
registerUIEndpointsFromClass(
|
|
412
402
|
this.endpointRegistry,
|
|
413
403
|
metatype,
|
|
@@ -1326,10 +1316,37 @@ exports.AbstractGraphBuilder = class AbstractGraphBuilder {
|
|
|
1326
1316
|
}
|
|
1327
1317
|
/**
|
|
1328
1318
|
* Prepare config for graph execution
|
|
1329
|
-
*
|
|
1319
|
+
* Automatically sets checkpoint_ns and checkpoint_id if not present
|
|
1330
1320
|
*/
|
|
1331
1321
|
async preparePayload(payload) {
|
|
1332
|
-
const
|
|
1322
|
+
const checkpoint_ns = payload.config.configurable.checkpoint_ns || this.graphType;
|
|
1323
|
+
const checkpoint_id = payload.config.configurable.checkpoint_id || payload.config.configurable.thread_id;
|
|
1324
|
+
this.logger.debug({
|
|
1325
|
+
message: "[SDK] preparePayload - setting checkpoint config",
|
|
1326
|
+
checkpoint_ns,
|
|
1327
|
+
checkpoint_id,
|
|
1328
|
+
thread_id: payload.config.configurable.thread_id,
|
|
1329
|
+
graphType: this.graphType
|
|
1330
|
+
});
|
|
1331
|
+
const payloadWithCheckpoint = {
|
|
1332
|
+
...payload,
|
|
1333
|
+
config: {
|
|
1334
|
+
...payload.config,
|
|
1335
|
+
configurable: {
|
|
1336
|
+
...payload.config.configurable,
|
|
1337
|
+
checkpoint_ns,
|
|
1338
|
+
checkpoint_id
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
const finalPayload = await this.customizeConfig(payloadWithCheckpoint);
|
|
1343
|
+
this.logger.debug({
|
|
1344
|
+
message: "[SDK] preparePayload - final config",
|
|
1345
|
+
has_checkpoint_ns: !!finalPayload.config.configurable.checkpoint_ns,
|
|
1346
|
+
has_checkpoint_id: !!finalPayload.config.configurable.checkpoint_id,
|
|
1347
|
+
checkpoint_ns: finalPayload.config.configurable.checkpoint_ns,
|
|
1348
|
+
checkpoint_id: finalPayload.config.configurable.checkpoint_id
|
|
1349
|
+
});
|
|
1333
1350
|
return finalPayload;
|
|
1334
1351
|
}
|
|
1335
1352
|
/**
|
|
@@ -1403,11 +1420,6 @@ exports.AbstractGraphBuilder = class AbstractGraphBuilder {
|
|
|
1403
1420
|
return null;
|
|
1404
1421
|
}
|
|
1405
1422
|
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Validate graph manifest
|
|
1408
|
-
*/
|
|
1409
|
-
validateManifest(manifest) {
|
|
1410
|
-
}
|
|
1411
1423
|
/**
|
|
1412
1424
|
* Get graph metadata (from manifest or decorator)
|
|
1413
1425
|
*/
|
|
@@ -1505,9 +1517,7 @@ exports.UniversalGraphService = class UniversalGraphService {
|
|
|
1505
1517
|
* Returns graph types supported by the service
|
|
1506
1518
|
*/
|
|
1507
1519
|
async getSupportedGraphTypes() {
|
|
1508
|
-
return this.builders.map((builder) =>
|
|
1509
|
-
return builder.graphType;
|
|
1510
|
-
});
|
|
1520
|
+
return this.builders.map((builder) => builder.graphType);
|
|
1511
1521
|
}
|
|
1512
1522
|
/**
|
|
1513
1523
|
* Generate answer without streaming
|
|
@@ -1784,12 +1794,10 @@ exports.UniversalGraphService = __decorateClass([
|
|
|
1784
1794
|
], exports.UniversalGraphService);
|
|
1785
1795
|
function setupRedisMock() {
|
|
1786
1796
|
if (process.env.NODE_ENV === "development" && !process.env.KUBERNETES_SERVICE_HOST) {
|
|
1787
|
-
console.log("[REDIS_MOCK] Intercepting ioredis requires for development");
|
|
1788
1797
|
const Module2 = __require("module");
|
|
1789
1798
|
const originalRequire = Module2.prototype.require;
|
|
1790
1799
|
Module2.prototype.require = function(...args) {
|
|
1791
1800
|
if (args[0] === "ioredis") {
|
|
1792
|
-
console.log("[REDIS_MOCK] Redirecting ioredis to ioredis-mock");
|
|
1793
1801
|
return originalRequire.apply(this, ["ioredis-mock"]);
|
|
1794
1802
|
}
|
|
1795
1803
|
return originalRequire.apply(this, args);
|
|
@@ -5571,17 +5579,16 @@ function createMetaBuilder(config, versionedGraphService, moduleRef) {
|
|
|
5571
5579
|
const resolution = await versionedGraphService.resolveVersion(graphType, {
|
|
5572
5580
|
strict: false
|
|
5573
5581
|
});
|
|
5582
|
+
let versionedBuilder;
|
|
5574
5583
|
try {
|
|
5575
|
-
|
|
5584
|
+
versionedBuilder = moduleRef.get(resolution.builderClass, {
|
|
5576
5585
|
strict: false
|
|
5577
5586
|
});
|
|
5578
|
-
return versionedBuilder.buildGraph(payload);
|
|
5579
5587
|
} catch (error) {
|
|
5580
|
-
|
|
5581
|
-
resolution.builderClass
|
|
5582
|
-
);
|
|
5583
|
-
return versionedBuilder.buildGraph(payload);
|
|
5588
|
+
versionedBuilder = await moduleRef.create(resolution.builderClass);
|
|
5584
5589
|
}
|
|
5590
|
+
const preparedPayload = await versionedBuilder.preparePayload(payload);
|
|
5591
|
+
return versionedBuilder.buildGraph(preparedPayload);
|
|
5585
5592
|
}
|
|
5586
5593
|
async preparePayload(payload) {
|
|
5587
5594
|
const graphType = payload.config?.configurable?.graphSettings?.graphType;
|
|
@@ -5620,6 +5627,82 @@ function createMetaBuilder(config, versionedGraphService, moduleRef) {
|
|
|
5620
5627
|
Object.defineProperty(VersionRouter, "name", { value: className });
|
|
5621
5628
|
return VersionRouter;
|
|
5622
5629
|
}
|
|
5630
|
+
function buildCheckpointerProviders(options) {
|
|
5631
|
+
const logger2 = new common.Logger("UniversalGraphModule");
|
|
5632
|
+
if (options.postgres !== void 0) {
|
|
5633
|
+
return [
|
|
5634
|
+
{
|
|
5635
|
+
provide: "CHECKPOINTER",
|
|
5636
|
+
useFactory: async () => {
|
|
5637
|
+
const { PostgresSaver } = await import(
|
|
5638
|
+
// Dynamic import keeps the package optional at build time
|
|
5639
|
+
'@langchain/langgraph-checkpoint-postgres'
|
|
5640
|
+
);
|
|
5641
|
+
const connString = options.postgres.connectionString ?? process.env.DATABASE_URL;
|
|
5642
|
+
if (!connString) {
|
|
5643
|
+
throw new Error(
|
|
5644
|
+
"[UniversalGraphModule] Postgres checkpointer: provide postgres.connectionString or set the DATABASE_URL environment variable."
|
|
5645
|
+
);
|
|
5646
|
+
}
|
|
5647
|
+
logger2.log(
|
|
5648
|
+
`Checkpointer: PostgreSQL (${connString.replace(/:[^:@]+@/, ":***@")})`
|
|
5649
|
+
);
|
|
5650
|
+
const saver = PostgresSaver.fromConnString(connString, {
|
|
5651
|
+
...options.postgres.schema ? { schema: options.postgres.schema } : {}
|
|
5652
|
+
});
|
|
5653
|
+
await saver.setup();
|
|
5654
|
+
return saver;
|
|
5655
|
+
}
|
|
5656
|
+
}
|
|
5657
|
+
];
|
|
5658
|
+
}
|
|
5659
|
+
if (options.mongodb !== void 0) {
|
|
5660
|
+
return [
|
|
5661
|
+
{
|
|
5662
|
+
provide: "MONGO_CONNECTION",
|
|
5663
|
+
useFactory: async (configService) => {
|
|
5664
|
+
const mongoUri = options.mongodb?.uri || configService.get("MONGODB_URI") || process.env.MONGODB_URI;
|
|
5665
|
+
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5666
|
+
if (!mongoUri) {
|
|
5667
|
+
throw new Error(
|
|
5668
|
+
"[UniversalGraphModule] MongoDB checkpointer: provide mongodb.uri or set the MONGODB_URI environment variable."
|
|
5669
|
+
);
|
|
5670
|
+
}
|
|
5671
|
+
logger2.log(`Checkpointer: MongoDB (${mongoUri.substring(0, 50)}...)`);
|
|
5672
|
+
await mongoose__default.default.connect(mongoUri, { dbName });
|
|
5673
|
+
return mongoose__default.default.connection;
|
|
5674
|
+
},
|
|
5675
|
+
inject: [config.ConfigService]
|
|
5676
|
+
},
|
|
5677
|
+
{
|
|
5678
|
+
provide: "CHECKPOINTER",
|
|
5679
|
+
useFactory: async (connection, configService) => {
|
|
5680
|
+
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5681
|
+
const mongoClient = createMongoClientAdapter(connection.getClient());
|
|
5682
|
+
return new langgraphCheckpointMongodb.MongoDBSaver({
|
|
5683
|
+
client: mongoClient,
|
|
5684
|
+
dbName,
|
|
5685
|
+
checkpointCollectionName: options.mongodb?.checkpointCollectionName ?? "checkpoints",
|
|
5686
|
+
checkpointWritesCollectionName: options.mongodb?.checkpointWritesCollectionName ?? "checkpoint_writes"
|
|
5687
|
+
});
|
|
5688
|
+
},
|
|
5689
|
+
inject: ["MONGO_CONNECTION", config.ConfigService]
|
|
5690
|
+
}
|
|
5691
|
+
];
|
|
5692
|
+
}
|
|
5693
|
+
return [
|
|
5694
|
+
{
|
|
5695
|
+
provide: "CHECKPOINTER",
|
|
5696
|
+
useFactory: async () => {
|
|
5697
|
+
const { MemorySaver } = await import('@langchain/langgraph');
|
|
5698
|
+
logger2.warn(
|
|
5699
|
+
"Checkpointer: MemorySaver (in-process, no persistence). Configure postgres or mongodb in UniversalGraphModule.forRoot() for production."
|
|
5700
|
+
);
|
|
5701
|
+
return new MemorySaver();
|
|
5702
|
+
}
|
|
5703
|
+
}
|
|
5704
|
+
];
|
|
5705
|
+
}
|
|
5623
5706
|
exports.UniversalGraphModule = class UniversalGraphModule {
|
|
5624
5707
|
static forRoot(options) {
|
|
5625
5708
|
const providers = [
|
|
@@ -5640,12 +5723,24 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5640
5723
|
exports.GraphEngineFactory,
|
|
5641
5724
|
exports.VersionedGraphService,
|
|
5642
5725
|
exports.UniversalGraphService,
|
|
5643
|
-
// Callback infrastructure
|
|
5726
|
+
// Callback infrastructure — Redis or in-memory fallback
|
|
5644
5727
|
{
|
|
5645
5728
|
provide: "REDIS_CLIENT",
|
|
5646
5729
|
useFactory: () => {
|
|
5647
|
-
const
|
|
5648
|
-
|
|
5730
|
+
const redisUrl = options.redis?.url ?? process.env.REDIS_URL;
|
|
5731
|
+
if (redisUrl) {
|
|
5732
|
+
const Redis = __require("ioredis");
|
|
5733
|
+
const logger2 = new common.Logger("UniversalGraphModule");
|
|
5734
|
+
logger2.log(
|
|
5735
|
+
`Callbacks: Redis (${redisUrl.replace(/:[^:@]+@/, ":***@")})`
|
|
5736
|
+
);
|
|
5737
|
+
return new Redis(redisUrl);
|
|
5738
|
+
}
|
|
5739
|
+
const IORedisMock = __require("ioredis-mock");
|
|
5740
|
+
new common.Logger("UniversalGraphModule").warn(
|
|
5741
|
+
"Callbacks: in-memory store (single-instance only). Set redis.url or REDIS_URL for production."
|
|
5742
|
+
);
|
|
5743
|
+
return new IORedisMock();
|
|
5649
5744
|
}
|
|
5650
5745
|
},
|
|
5651
5746
|
{
|
|
@@ -5739,58 +5834,9 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5739
5834
|
},
|
|
5740
5835
|
inject: [CallbackRegistry]
|
|
5741
5836
|
},
|
|
5742
|
-
//
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
provide: "MONGO_CONNECTION",
|
|
5746
|
-
useFactory: async (configService) => {
|
|
5747
|
-
const logger2 = new common.Logger("UniversalGraphModule");
|
|
5748
|
-
const mongoUri = options.mongodb?.uri || configService.get("MONGODB_URI") || process.env.MONGODB_URI;
|
|
5749
|
-
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5750
|
-
if (!mongoUri) {
|
|
5751
|
-
throw new Error(
|
|
5752
|
-
"MONGODB_URI is not defined in options, config, or environment"
|
|
5753
|
-
);
|
|
5754
|
-
}
|
|
5755
|
-
logger2.log(
|
|
5756
|
-
`Connecting to MongoDB: ${mongoUri?.substring(0, 50) + "..."}`
|
|
5757
|
-
);
|
|
5758
|
-
try {
|
|
5759
|
-
await mongoose__default.default.connect(mongoUri, { dbName });
|
|
5760
|
-
logger2.log(
|
|
5761
|
-
`Successfully connected to MongoDB (db: ${dbName})`
|
|
5762
|
-
);
|
|
5763
|
-
return mongoose__default.default.connection;
|
|
5764
|
-
} catch (error) {
|
|
5765
|
-
logger2.error("Failed to connect to MongoDB", error);
|
|
5766
|
-
throw error;
|
|
5767
|
-
}
|
|
5768
|
-
},
|
|
5769
|
-
inject: [config.ConfigService]
|
|
5770
|
-
},
|
|
5771
|
-
// MongoDB checkpointer
|
|
5772
|
-
{
|
|
5773
|
-
provide: "CHECKPOINTER",
|
|
5774
|
-
useFactory: async (connection, configService) => {
|
|
5775
|
-
const logger2 = new common.Logger("UniversalGraphModule");
|
|
5776
|
-
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5777
|
-
const checkpointCollectionName = options.mongodb?.checkpointCollectionName || "checkpoints";
|
|
5778
|
-
const checkpointWritesCollectionName = options.mongodb?.checkpointWritesCollectionName || "checkpoint_writes";
|
|
5779
|
-
logger2.log(
|
|
5780
|
-
`Creating CHECKPOINTER with collections: ${checkpointCollectionName}, ${checkpointWritesCollectionName}`
|
|
5781
|
-
);
|
|
5782
|
-
const mongooseClient = connection.getClient();
|
|
5783
|
-
const mongoClient = createMongoClientAdapter(mongooseClient);
|
|
5784
|
-
return new langgraphCheckpointMongodb.MongoDBSaver({
|
|
5785
|
-
client: mongoClient,
|
|
5786
|
-
dbName,
|
|
5787
|
-
checkpointCollectionName,
|
|
5788
|
-
checkpointWritesCollectionName
|
|
5789
|
-
});
|
|
5790
|
-
},
|
|
5791
|
-
inject: ["MONGO_CONNECTION", config.ConfigService]
|
|
5792
|
-
}
|
|
5793
|
-
] : [],
|
|
5837
|
+
// ── Checkpointer ────────────────────────────────────────────────────
|
|
5838
|
+
// Priority: postgres > mongodb > memory (in-process, no persistence)
|
|
5839
|
+
...buildCheckpointerProviders(options),
|
|
5794
5840
|
{
|
|
5795
5841
|
provide: "GRAPH_ENGINE",
|
|
5796
5842
|
useFactory: (langGraphEngine) => langGraphEngine,
|
|
@@ -5815,12 +5861,10 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5815
5861
|
{
|
|
5816
5862
|
provide: "VERSIONING_INITIALIZER",
|
|
5817
5863
|
useFactory: (builderRegistry, versionedGraphService, configs, moduleRef) => {
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
configs?.length || 0
|
|
5864
|
+
const initLogger = new common.Logger("UniversalGraphModule");
|
|
5865
|
+
initLogger.debug(
|
|
5866
|
+
`Initializing versioning for ${configs?.length || 0} graph type(s)`
|
|
5821
5867
|
);
|
|
5822
|
-
console.log("\u{1F527} ModuleRef available:", !!moduleRef);
|
|
5823
|
-
console.log("\u{1F527} BuilderRegistry available:", !!builderRegistry);
|
|
5824
5868
|
configs.forEach(
|
|
5825
5869
|
(config) => versionedGraphService.registerVersioning(config)
|
|
5826
5870
|
);
|
|
@@ -5832,9 +5876,8 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5832
5876
|
moduleRef
|
|
5833
5877
|
);
|
|
5834
5878
|
const versionRouter = new VersionRouterClass();
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
config.baseGraphType
|
|
5879
|
+
initLogger.debug(
|
|
5880
|
+
`Registered VersionRouter for ${config.baseGraphType}`
|
|
5838
5881
|
);
|
|
5839
5882
|
builderRegistry.registerBuilder(versionRouter);
|
|
5840
5883
|
} else {
|
|
@@ -5855,10 +5898,8 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5855
5898
|
}
|
|
5856
5899
|
}
|
|
5857
5900
|
const simpleRouter = new SimpleVersionRouter();
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
config.baseGraphType,
|
|
5861
|
-
"(no ModuleRef)"
|
|
5901
|
+
initLogger.warn(
|
|
5902
|
+
`Registered SimpleRouter for ${config.baseGraphType} (no ModuleRef)`
|
|
5862
5903
|
);
|
|
5863
5904
|
builderRegistry.registerBuilder(simpleRouter);
|
|
5864
5905
|
}
|
|
@@ -5882,6 +5923,7 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5882
5923
|
exports: [
|
|
5883
5924
|
"GRAPH_SERVICE",
|
|
5884
5925
|
"GRAPH_ENGINE",
|
|
5926
|
+
"CHECKPOINTER",
|
|
5885
5927
|
exports.UniversalGraphService,
|
|
5886
5928
|
exports.BuilderRegistryService,
|
|
5887
5929
|
exports.VersionedGraphService,
|
|
@@ -7131,28 +7173,11 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7131
7173
|
);
|
|
7132
7174
|
}
|
|
7133
7175
|
const config = await response.json();
|
|
7134
|
-
console.debug(
|
|
7135
|
-
`ModelInitializer.fetchFromApi - API response for ${modelId}:`,
|
|
7136
|
-
{
|
|
7137
|
-
url,
|
|
7138
|
-
statusCode: response.status,
|
|
7139
|
-
configKeys: Object.keys(config),
|
|
7140
|
-
modelType: config.modelType,
|
|
7141
|
-
hasModelType: !!config.modelType,
|
|
7142
|
-
fullConfig: config
|
|
7143
|
-
}
|
|
7144
|
-
);
|
|
7145
7176
|
const result = {
|
|
7146
7177
|
...config,
|
|
7147
7178
|
modelType: config.modelType || "chat" /* CHAT */
|
|
7148
7179
|
// Fallback for compatibility
|
|
7149
7180
|
};
|
|
7150
|
-
console.debug(`ModelInitializer.fetchFromApi - final result:`, {
|
|
7151
|
-
modelId,
|
|
7152
|
-
resultModelType: result.modelType,
|
|
7153
|
-
usedFallback: !config.modelType,
|
|
7154
|
-
resultKeys: Object.keys(result)
|
|
7155
|
-
});
|
|
7156
7181
|
return result;
|
|
7157
7182
|
}
|
|
7158
7183
|
};
|