@flutchai/flutch-sdk 0.2.16 → 0.2.18
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 +195 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -6
- package/dist/index.d.ts +14 -6
- package/dist/index.js +196 -146
- 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,
|
|
@@ -6475,7 +6517,10 @@ function normalizeToolConfigs(tools) {
|
|
|
6475
6517
|
}
|
|
6476
6518
|
var DEFAULT_ROUTER_URL = "https://router.flutch.ai";
|
|
6477
6519
|
function resolveRouterURL(baseURL) {
|
|
6478
|
-
|
|
6520
|
+
if (baseURL) return baseURL;
|
|
6521
|
+
if (process.env.FLUTCH_ROUTER_URL) return process.env.FLUTCH_ROUTER_URL;
|
|
6522
|
+
if (process.env.FLUTCH_API_TOKEN) return DEFAULT_ROUTER_URL;
|
|
6523
|
+
return void 0;
|
|
6479
6524
|
}
|
|
6480
6525
|
function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig, baseURL) {
|
|
6481
6526
|
const parts = [
|
|
@@ -6582,12 +6627,15 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6582
6627
|
};
|
|
6583
6628
|
/**
|
|
6584
6629
|
* Resolve API key for a provider.
|
|
6585
|
-
*
|
|
6630
|
+
* Priority: custom resolver > FLUTCH_API_TOKEN > provider-specific env var.
|
|
6586
6631
|
*/
|
|
6587
6632
|
resolveApiKey(provider) {
|
|
6588
6633
|
if (this.apiKeyResolver) {
|
|
6589
6634
|
return this.apiKeyResolver(provider);
|
|
6590
6635
|
}
|
|
6636
|
+
if (process.env.FLUTCH_API_TOKEN) {
|
|
6637
|
+
return process.env.FLUTCH_API_TOKEN;
|
|
6638
|
+
}
|
|
6591
6639
|
const envVar = _ModelInitializer.DEFAULT_ENV_MAP[provider];
|
|
6592
6640
|
return envVar ? process.env[envVar] : void 0;
|
|
6593
6641
|
}
|
|
@@ -6633,7 +6681,10 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6633
6681
|
defaultMaxTokens,
|
|
6634
6682
|
apiToken || this.resolveApiKey("openai" /* OPENAI */) || ""
|
|
6635
6683
|
);
|
|
6636
|
-
|
|
6684
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6685
|
+
if (routerURL) {
|
|
6686
|
+
config.configuration = { baseURL: `${routerURL}/v1` };
|
|
6687
|
+
}
|
|
6637
6688
|
return new openai.ChatOpenAI(config);
|
|
6638
6689
|
},
|
|
6639
6690
|
["anthropic" /* ANTHROPIC */]: ({
|
|
@@ -6647,7 +6698,9 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6647
6698
|
temperature: defaultTemperature,
|
|
6648
6699
|
maxTokens: defaultMaxTokens,
|
|
6649
6700
|
anthropicApiKey: apiToken || this.resolveApiKey("anthropic" /* ANTHROPIC */),
|
|
6650
|
-
|
|
6701
|
+
...resolveRouterURL(baseURL) && {
|
|
6702
|
+
anthropicApiUrl: resolveRouterURL(baseURL)
|
|
6703
|
+
}
|
|
6651
6704
|
}),
|
|
6652
6705
|
["cohere" /* COHERE */]: ({
|
|
6653
6706
|
modelName,
|
|
@@ -6655,30 +6708,35 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6655
6708
|
defaultMaxTokens,
|
|
6656
6709
|
apiToken,
|
|
6657
6710
|
baseURL
|
|
6658
|
-
}) =>
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6711
|
+
}) => {
|
|
6712
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6713
|
+
const token = apiToken || this.resolveApiKey("cohere" /* COHERE */);
|
|
6714
|
+
return routerURL ? new cohere.ChatCohere({
|
|
6715
|
+
model: modelName,
|
|
6716
|
+
temperature: defaultTemperature,
|
|
6717
|
+
client: new cohereAi.CohereClient({ token, baseUrl: routerURL })
|
|
6718
|
+
}) : new cohere.ChatCohere({
|
|
6719
|
+
model: modelName,
|
|
6720
|
+
temperature: defaultTemperature,
|
|
6721
|
+
apiKey: token
|
|
6722
|
+
});
|
|
6723
|
+
},
|
|
6666
6724
|
["mistral" /* MISTRAL */]: ({
|
|
6667
6725
|
modelName,
|
|
6668
6726
|
defaultTemperature,
|
|
6669
6727
|
defaultMaxTokens,
|
|
6670
6728
|
apiToken,
|
|
6671
6729
|
baseURL
|
|
6672
|
-
}) =>
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
}
|
|
6730
|
+
}) => {
|
|
6731
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6732
|
+
return new mistralai.ChatMistralAI({
|
|
6733
|
+
model: modelName,
|
|
6734
|
+
temperature: defaultTemperature,
|
|
6735
|
+
maxTokens: defaultMaxTokens,
|
|
6736
|
+
apiKey: apiToken || this.resolveApiKey("mistral" /* MISTRAL */),
|
|
6737
|
+
...routerURL && { serverURL: `${routerURL}/v1` }
|
|
6738
|
+
});
|
|
6739
|
+
},
|
|
6682
6740
|
["voyageai" /* VOYAGEAI */]: () => {
|
|
6683
6741
|
throw new Error("VoyageAI chat models not implemented");
|
|
6684
6742
|
}
|
|
@@ -6691,13 +6749,16 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6691
6749
|
maxDocuments,
|
|
6692
6750
|
baseURL
|
|
6693
6751
|
}) => {
|
|
6694
|
-
|
|
6752
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6753
|
+
const token = apiToken || this.resolveApiKey("cohere" /* COHERE */);
|
|
6754
|
+
return routerURL ? new cohere.CohereRerank({
|
|
6695
6755
|
model: modelName,
|
|
6696
6756
|
topN: maxDocuments || 20,
|
|
6697
|
-
client: new cohereAi.CohereClient({
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6757
|
+
client: new cohereAi.CohereClient({ token, baseUrl: routerURL })
|
|
6758
|
+
}) : new cohere.CohereRerank({
|
|
6759
|
+
model: modelName,
|
|
6760
|
+
topN: maxDocuments || 20,
|
|
6761
|
+
apiKey: token
|
|
6701
6762
|
});
|
|
6702
6763
|
},
|
|
6703
6764
|
["voyageai" /* VOYAGEAI */]: ({
|
|
@@ -6706,11 +6767,12 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6706
6767
|
maxDocuments,
|
|
6707
6768
|
baseURL
|
|
6708
6769
|
}) => {
|
|
6770
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6709
6771
|
return new VoyageAIRerank({
|
|
6710
6772
|
apiKey: apiToken || this.resolveApiKey("voyageai" /* VOYAGEAI */),
|
|
6711
6773
|
model: modelName,
|
|
6712
6774
|
topN: maxDocuments || 20,
|
|
6713
|
-
baseUrl:
|
|
6775
|
+
...routerURL && { baseUrl: routerURL }
|
|
6714
6776
|
});
|
|
6715
6777
|
},
|
|
6716
6778
|
// Other providers don't support rerank yet
|
|
@@ -6721,11 +6783,16 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6721
6783
|
};
|
|
6722
6784
|
// Embedding model creators
|
|
6723
6785
|
embeddingModelCreators = {
|
|
6724
|
-
["openai" /* OPENAI */]: ({ modelName, apiToken, baseURL }) =>
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6786
|
+
["openai" /* OPENAI */]: ({ modelName, apiToken, baseURL }) => {
|
|
6787
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6788
|
+
return new openai.OpenAIEmbeddings({
|
|
6789
|
+
model: modelName,
|
|
6790
|
+
apiKey: apiToken || this.resolveApiKey("openai" /* OPENAI */),
|
|
6791
|
+
...routerURL && {
|
|
6792
|
+
configuration: { baseURL: `${routerURL}/v1` }
|
|
6793
|
+
}
|
|
6794
|
+
});
|
|
6795
|
+
},
|
|
6729
6796
|
// Other providers not yet implemented for embeddings
|
|
6730
6797
|
["anthropic" /* ANTHROPIC */]: void 0,
|
|
6731
6798
|
["cohere" /* COHERE */]: void 0,
|
|
@@ -7106,28 +7173,11 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7106
7173
|
);
|
|
7107
7174
|
}
|
|
7108
7175
|
const config = await response.json();
|
|
7109
|
-
console.debug(
|
|
7110
|
-
`ModelInitializer.fetchFromApi - API response for ${modelId}:`,
|
|
7111
|
-
{
|
|
7112
|
-
url,
|
|
7113
|
-
statusCode: response.status,
|
|
7114
|
-
configKeys: Object.keys(config),
|
|
7115
|
-
modelType: config.modelType,
|
|
7116
|
-
hasModelType: !!config.modelType,
|
|
7117
|
-
fullConfig: config
|
|
7118
|
-
}
|
|
7119
|
-
);
|
|
7120
7176
|
const result = {
|
|
7121
7177
|
...config,
|
|
7122
7178
|
modelType: config.modelType || "chat" /* CHAT */
|
|
7123
7179
|
// Fallback for compatibility
|
|
7124
7180
|
};
|
|
7125
|
-
console.debug(`ModelInitializer.fetchFromApi - final result:`, {
|
|
7126
|
-
modelId,
|
|
7127
|
-
resultModelType: result.modelType,
|
|
7128
|
-
usedFallback: !config.modelType,
|
|
7129
|
-
resultKeys: Object.keys(result)
|
|
7130
|
-
});
|
|
7131
7181
|
return result;
|
|
7132
7182
|
}
|
|
7133
7183
|
};
|