@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.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as path2 from 'path';
|
|
|
6
6
|
import * as os from 'os';
|
|
7
7
|
import { NestFactory, MetadataScanner, ModuleRef, DiscoveryModule } from '@nestjs/core';
|
|
8
8
|
import * as net from 'net';
|
|
9
|
-
import {
|
|
9
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
10
10
|
import mongoose from 'mongoose';
|
|
11
11
|
import { MongoDBSaver } from '@langchain/langgraph-checkpoint-mongodb';
|
|
12
12
|
import * as crypto from 'crypto';
|
|
@@ -307,11 +307,6 @@ function registerUIEndpointsFromClass(endpointRegistry, EndpointClass, instance)
|
|
|
307
307
|
if (methodsMetadata.length === 0) {
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
|
-
console.log("DEBUG: registerUIEndpointsFromClass", {
|
|
311
|
-
hasInstance: !!instance,
|
|
312
|
-
willCreateNew: !instance,
|
|
313
|
-
className: EndpointClass.name
|
|
314
|
-
});
|
|
315
310
|
const endpointInstance = instance || new EndpointClass();
|
|
316
311
|
const descriptors = methodsMetadata.map((meta) => ({
|
|
317
312
|
name: meta.endpointName,
|
|
@@ -373,11 +368,6 @@ var init_ui_endpoints_discovery = __esm({
|
|
|
373
368
|
}
|
|
374
369
|
if (hasUIEndpoints(metatype)) {
|
|
375
370
|
this.logger.debug(`Found UI endpoints class: ${metatype.name}`);
|
|
376
|
-
console.log("DEBUG: Discovery found instance", {
|
|
377
|
-
className: metatype.name,
|
|
378
|
-
hasInstance: !!instance,
|
|
379
|
-
instanceType: typeof instance
|
|
380
|
-
});
|
|
381
371
|
registerUIEndpointsFromClass(
|
|
382
372
|
this.endpointRegistry,
|
|
383
373
|
metatype,
|
|
@@ -1296,10 +1286,37 @@ var AbstractGraphBuilder = class {
|
|
|
1296
1286
|
}
|
|
1297
1287
|
/**
|
|
1298
1288
|
* Prepare config for graph execution
|
|
1299
|
-
*
|
|
1289
|
+
* Automatically sets checkpoint_ns and checkpoint_id if not present
|
|
1300
1290
|
*/
|
|
1301
1291
|
async preparePayload(payload) {
|
|
1302
|
-
const
|
|
1292
|
+
const checkpoint_ns = payload.config.configurable.checkpoint_ns || this.graphType;
|
|
1293
|
+
const checkpoint_id = payload.config.configurable.checkpoint_id || payload.config.configurable.thread_id;
|
|
1294
|
+
this.logger.debug({
|
|
1295
|
+
message: "[SDK] preparePayload - setting checkpoint config",
|
|
1296
|
+
checkpoint_ns,
|
|
1297
|
+
checkpoint_id,
|
|
1298
|
+
thread_id: payload.config.configurable.thread_id,
|
|
1299
|
+
graphType: this.graphType
|
|
1300
|
+
});
|
|
1301
|
+
const payloadWithCheckpoint = {
|
|
1302
|
+
...payload,
|
|
1303
|
+
config: {
|
|
1304
|
+
...payload.config,
|
|
1305
|
+
configurable: {
|
|
1306
|
+
...payload.config.configurable,
|
|
1307
|
+
checkpoint_ns,
|
|
1308
|
+
checkpoint_id
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
const finalPayload = await this.customizeConfig(payloadWithCheckpoint);
|
|
1313
|
+
this.logger.debug({
|
|
1314
|
+
message: "[SDK] preparePayload - final config",
|
|
1315
|
+
has_checkpoint_ns: !!finalPayload.config.configurable.checkpoint_ns,
|
|
1316
|
+
has_checkpoint_id: !!finalPayload.config.configurable.checkpoint_id,
|
|
1317
|
+
checkpoint_ns: finalPayload.config.configurable.checkpoint_ns,
|
|
1318
|
+
checkpoint_id: finalPayload.config.configurable.checkpoint_id
|
|
1319
|
+
});
|
|
1303
1320
|
return finalPayload;
|
|
1304
1321
|
}
|
|
1305
1322
|
/**
|
|
@@ -1373,11 +1390,6 @@ var AbstractGraphBuilder = class {
|
|
|
1373
1390
|
return null;
|
|
1374
1391
|
}
|
|
1375
1392
|
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Validate graph manifest
|
|
1378
|
-
*/
|
|
1379
|
-
validateManifest(manifest) {
|
|
1380
|
-
}
|
|
1381
1393
|
/**
|
|
1382
1394
|
* Get graph metadata (from manifest or decorator)
|
|
1383
1395
|
*/
|
|
@@ -1475,9 +1487,7 @@ var UniversalGraphService = class {
|
|
|
1475
1487
|
* Returns graph types supported by the service
|
|
1476
1488
|
*/
|
|
1477
1489
|
async getSupportedGraphTypes() {
|
|
1478
|
-
return this.builders.map((builder) =>
|
|
1479
|
-
return builder.graphType;
|
|
1480
|
-
});
|
|
1490
|
+
return this.builders.map((builder) => builder.graphType);
|
|
1481
1491
|
}
|
|
1482
1492
|
/**
|
|
1483
1493
|
* Generate answer without streaming
|
|
@@ -1754,12 +1764,10 @@ UniversalGraphService = __decorateClass([
|
|
|
1754
1764
|
], UniversalGraphService);
|
|
1755
1765
|
function setupRedisMock() {
|
|
1756
1766
|
if (process.env.NODE_ENV === "development" && !process.env.KUBERNETES_SERVICE_HOST) {
|
|
1757
|
-
console.log("[REDIS_MOCK] Intercepting ioredis requires for development");
|
|
1758
1767
|
const Module2 = __require("module");
|
|
1759
1768
|
const originalRequire = Module2.prototype.require;
|
|
1760
1769
|
Module2.prototype.require = function(...args) {
|
|
1761
1770
|
if (args[0] === "ioredis") {
|
|
1762
|
-
console.log("[REDIS_MOCK] Redirecting ioredis to ioredis-mock");
|
|
1763
1771
|
return originalRequire.apply(this, ["ioredis-mock"]);
|
|
1764
1772
|
}
|
|
1765
1773
|
return originalRequire.apply(this, args);
|
|
@@ -5541,17 +5549,16 @@ function createMetaBuilder(config, versionedGraphService, moduleRef) {
|
|
|
5541
5549
|
const resolution = await versionedGraphService.resolveVersion(graphType, {
|
|
5542
5550
|
strict: false
|
|
5543
5551
|
});
|
|
5552
|
+
let versionedBuilder;
|
|
5544
5553
|
try {
|
|
5545
|
-
|
|
5554
|
+
versionedBuilder = moduleRef.get(resolution.builderClass, {
|
|
5546
5555
|
strict: false
|
|
5547
5556
|
});
|
|
5548
|
-
return versionedBuilder.buildGraph(payload);
|
|
5549
5557
|
} catch (error) {
|
|
5550
|
-
|
|
5551
|
-
resolution.builderClass
|
|
5552
|
-
);
|
|
5553
|
-
return versionedBuilder.buildGraph(payload);
|
|
5558
|
+
versionedBuilder = await moduleRef.create(resolution.builderClass);
|
|
5554
5559
|
}
|
|
5560
|
+
const preparedPayload = await versionedBuilder.preparePayload(payload);
|
|
5561
|
+
return versionedBuilder.buildGraph(preparedPayload);
|
|
5555
5562
|
}
|
|
5556
5563
|
async preparePayload(payload) {
|
|
5557
5564
|
const graphType = payload.config?.configurable?.graphSettings?.graphType;
|
|
@@ -5590,6 +5597,82 @@ function createMetaBuilder(config, versionedGraphService, moduleRef) {
|
|
|
5590
5597
|
Object.defineProperty(VersionRouter, "name", { value: className });
|
|
5591
5598
|
return VersionRouter;
|
|
5592
5599
|
}
|
|
5600
|
+
function buildCheckpointerProviders(options) {
|
|
5601
|
+
const logger2 = new Logger("UniversalGraphModule");
|
|
5602
|
+
if (options.postgres !== void 0) {
|
|
5603
|
+
return [
|
|
5604
|
+
{
|
|
5605
|
+
provide: "CHECKPOINTER",
|
|
5606
|
+
useFactory: async () => {
|
|
5607
|
+
const { PostgresSaver } = await import(
|
|
5608
|
+
// Dynamic import keeps the package optional at build time
|
|
5609
|
+
'@langchain/langgraph-checkpoint-postgres'
|
|
5610
|
+
);
|
|
5611
|
+
const connString = options.postgres.connectionString ?? process.env.DATABASE_URL;
|
|
5612
|
+
if (!connString) {
|
|
5613
|
+
throw new Error(
|
|
5614
|
+
"[UniversalGraphModule] Postgres checkpointer: provide postgres.connectionString or set the DATABASE_URL environment variable."
|
|
5615
|
+
);
|
|
5616
|
+
}
|
|
5617
|
+
logger2.log(
|
|
5618
|
+
`Checkpointer: PostgreSQL (${connString.replace(/:[^:@]+@/, ":***@")})`
|
|
5619
|
+
);
|
|
5620
|
+
const saver = PostgresSaver.fromConnString(connString, {
|
|
5621
|
+
...options.postgres.schema ? { schema: options.postgres.schema } : {}
|
|
5622
|
+
});
|
|
5623
|
+
await saver.setup();
|
|
5624
|
+
return saver;
|
|
5625
|
+
}
|
|
5626
|
+
}
|
|
5627
|
+
];
|
|
5628
|
+
}
|
|
5629
|
+
if (options.mongodb !== void 0) {
|
|
5630
|
+
return [
|
|
5631
|
+
{
|
|
5632
|
+
provide: "MONGO_CONNECTION",
|
|
5633
|
+
useFactory: async (configService) => {
|
|
5634
|
+
const mongoUri = options.mongodb?.uri || configService.get("MONGODB_URI") || process.env.MONGODB_URI;
|
|
5635
|
+
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5636
|
+
if (!mongoUri) {
|
|
5637
|
+
throw new Error(
|
|
5638
|
+
"[UniversalGraphModule] MongoDB checkpointer: provide mongodb.uri or set the MONGODB_URI environment variable."
|
|
5639
|
+
);
|
|
5640
|
+
}
|
|
5641
|
+
logger2.log(`Checkpointer: MongoDB (${mongoUri.substring(0, 50)}...)`);
|
|
5642
|
+
await mongoose.connect(mongoUri, { dbName });
|
|
5643
|
+
return mongoose.connection;
|
|
5644
|
+
},
|
|
5645
|
+
inject: [ConfigService]
|
|
5646
|
+
},
|
|
5647
|
+
{
|
|
5648
|
+
provide: "CHECKPOINTER",
|
|
5649
|
+
useFactory: async (connection, configService) => {
|
|
5650
|
+
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5651
|
+
const mongoClient = createMongoClientAdapter(connection.getClient());
|
|
5652
|
+
return new MongoDBSaver({
|
|
5653
|
+
client: mongoClient,
|
|
5654
|
+
dbName,
|
|
5655
|
+
checkpointCollectionName: options.mongodb?.checkpointCollectionName ?? "checkpoints",
|
|
5656
|
+
checkpointWritesCollectionName: options.mongodb?.checkpointWritesCollectionName ?? "checkpoint_writes"
|
|
5657
|
+
});
|
|
5658
|
+
},
|
|
5659
|
+
inject: ["MONGO_CONNECTION", ConfigService]
|
|
5660
|
+
}
|
|
5661
|
+
];
|
|
5662
|
+
}
|
|
5663
|
+
return [
|
|
5664
|
+
{
|
|
5665
|
+
provide: "CHECKPOINTER",
|
|
5666
|
+
useFactory: async () => {
|
|
5667
|
+
const { MemorySaver } = await import('@langchain/langgraph');
|
|
5668
|
+
logger2.warn(
|
|
5669
|
+
"Checkpointer: MemorySaver (in-process, no persistence). Configure postgres or mongodb in UniversalGraphModule.forRoot() for production."
|
|
5670
|
+
);
|
|
5671
|
+
return new MemorySaver();
|
|
5672
|
+
}
|
|
5673
|
+
}
|
|
5674
|
+
];
|
|
5675
|
+
}
|
|
5593
5676
|
var UniversalGraphModule = class {
|
|
5594
5677
|
static forRoot(options) {
|
|
5595
5678
|
const providers = [
|
|
@@ -5610,12 +5693,24 @@ var UniversalGraphModule = class {
|
|
|
5610
5693
|
GraphEngineFactory,
|
|
5611
5694
|
VersionedGraphService,
|
|
5612
5695
|
UniversalGraphService,
|
|
5613
|
-
// Callback infrastructure
|
|
5696
|
+
// Callback infrastructure — Redis or in-memory fallback
|
|
5614
5697
|
{
|
|
5615
5698
|
provide: "REDIS_CLIENT",
|
|
5616
5699
|
useFactory: () => {
|
|
5617
|
-
const
|
|
5618
|
-
|
|
5700
|
+
const redisUrl = options.redis?.url ?? process.env.REDIS_URL;
|
|
5701
|
+
if (redisUrl) {
|
|
5702
|
+
const Redis = __require("ioredis");
|
|
5703
|
+
const logger2 = new Logger("UniversalGraphModule");
|
|
5704
|
+
logger2.log(
|
|
5705
|
+
`Callbacks: Redis (${redisUrl.replace(/:[^:@]+@/, ":***@")})`
|
|
5706
|
+
);
|
|
5707
|
+
return new Redis(redisUrl);
|
|
5708
|
+
}
|
|
5709
|
+
const IORedisMock = __require("ioredis-mock");
|
|
5710
|
+
new Logger("UniversalGraphModule").warn(
|
|
5711
|
+
"Callbacks: in-memory store (single-instance only). Set redis.url or REDIS_URL for production."
|
|
5712
|
+
);
|
|
5713
|
+
return new IORedisMock();
|
|
5619
5714
|
}
|
|
5620
5715
|
},
|
|
5621
5716
|
{
|
|
@@ -5709,58 +5804,9 @@ var UniversalGraphModule = class {
|
|
|
5709
5804
|
},
|
|
5710
5805
|
inject: [CallbackRegistry]
|
|
5711
5806
|
},
|
|
5712
|
-
//
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
provide: "MONGO_CONNECTION",
|
|
5716
|
-
useFactory: async (configService) => {
|
|
5717
|
-
const logger2 = new Logger("UniversalGraphModule");
|
|
5718
|
-
const mongoUri = options.mongodb?.uri || configService.get("MONGODB_URI") || process.env.MONGODB_URI;
|
|
5719
|
-
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5720
|
-
if (!mongoUri) {
|
|
5721
|
-
throw new Error(
|
|
5722
|
-
"MONGODB_URI is not defined in options, config, or environment"
|
|
5723
|
-
);
|
|
5724
|
-
}
|
|
5725
|
-
logger2.log(
|
|
5726
|
-
`Connecting to MongoDB: ${mongoUri?.substring(0, 50) + "..."}`
|
|
5727
|
-
);
|
|
5728
|
-
try {
|
|
5729
|
-
await mongoose.connect(mongoUri, { dbName });
|
|
5730
|
-
logger2.log(
|
|
5731
|
-
`Successfully connected to MongoDB (db: ${dbName})`
|
|
5732
|
-
);
|
|
5733
|
-
return mongoose.connection;
|
|
5734
|
-
} catch (error) {
|
|
5735
|
-
logger2.error("Failed to connect to MongoDB", error);
|
|
5736
|
-
throw error;
|
|
5737
|
-
}
|
|
5738
|
-
},
|
|
5739
|
-
inject: [ConfigService]
|
|
5740
|
-
},
|
|
5741
|
-
// MongoDB checkpointer
|
|
5742
|
-
{
|
|
5743
|
-
provide: "CHECKPOINTER",
|
|
5744
|
-
useFactory: async (connection, configService) => {
|
|
5745
|
-
const logger2 = new Logger("UniversalGraphModule");
|
|
5746
|
-
const dbName = options.mongodb?.dbName || configService.get("MONGO_DB_NAME") || process.env.MONGO_DB_NAME;
|
|
5747
|
-
const checkpointCollectionName = options.mongodb?.checkpointCollectionName || "checkpoints";
|
|
5748
|
-
const checkpointWritesCollectionName = options.mongodb?.checkpointWritesCollectionName || "checkpoint_writes";
|
|
5749
|
-
logger2.log(
|
|
5750
|
-
`Creating CHECKPOINTER with collections: ${checkpointCollectionName}, ${checkpointWritesCollectionName}`
|
|
5751
|
-
);
|
|
5752
|
-
const mongooseClient = connection.getClient();
|
|
5753
|
-
const mongoClient = createMongoClientAdapter(mongooseClient);
|
|
5754
|
-
return new MongoDBSaver({
|
|
5755
|
-
client: mongoClient,
|
|
5756
|
-
dbName,
|
|
5757
|
-
checkpointCollectionName,
|
|
5758
|
-
checkpointWritesCollectionName
|
|
5759
|
-
});
|
|
5760
|
-
},
|
|
5761
|
-
inject: ["MONGO_CONNECTION", ConfigService]
|
|
5762
|
-
}
|
|
5763
|
-
] : [],
|
|
5807
|
+
// ── Checkpointer ────────────────────────────────────────────────────
|
|
5808
|
+
// Priority: postgres > mongodb > memory (in-process, no persistence)
|
|
5809
|
+
...buildCheckpointerProviders(options),
|
|
5764
5810
|
{
|
|
5765
5811
|
provide: "GRAPH_ENGINE",
|
|
5766
5812
|
useFactory: (langGraphEngine) => langGraphEngine,
|
|
@@ -5785,12 +5831,10 @@ var UniversalGraphModule = class {
|
|
|
5785
5831
|
{
|
|
5786
5832
|
provide: "VERSIONING_INITIALIZER",
|
|
5787
5833
|
useFactory: (builderRegistry, versionedGraphService, configs, moduleRef) => {
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
configs?.length || 0
|
|
5834
|
+
const initLogger = new Logger("UniversalGraphModule");
|
|
5835
|
+
initLogger.debug(
|
|
5836
|
+
`Initializing versioning for ${configs?.length || 0} graph type(s)`
|
|
5791
5837
|
);
|
|
5792
|
-
console.log("\u{1F527} ModuleRef available:", !!moduleRef);
|
|
5793
|
-
console.log("\u{1F527} BuilderRegistry available:", !!builderRegistry);
|
|
5794
5838
|
configs.forEach(
|
|
5795
5839
|
(config) => versionedGraphService.registerVersioning(config)
|
|
5796
5840
|
);
|
|
@@ -5802,9 +5846,8 @@ var UniversalGraphModule = class {
|
|
|
5802
5846
|
moduleRef
|
|
5803
5847
|
);
|
|
5804
5848
|
const versionRouter = new VersionRouterClass();
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
config.baseGraphType
|
|
5849
|
+
initLogger.debug(
|
|
5850
|
+
`Registered VersionRouter for ${config.baseGraphType}`
|
|
5808
5851
|
);
|
|
5809
5852
|
builderRegistry.registerBuilder(versionRouter);
|
|
5810
5853
|
} else {
|
|
@@ -5825,10 +5868,8 @@ var UniversalGraphModule = class {
|
|
|
5825
5868
|
}
|
|
5826
5869
|
}
|
|
5827
5870
|
const simpleRouter = new SimpleVersionRouter();
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
config.baseGraphType,
|
|
5831
|
-
"(no ModuleRef)"
|
|
5871
|
+
initLogger.warn(
|
|
5872
|
+
`Registered SimpleRouter for ${config.baseGraphType} (no ModuleRef)`
|
|
5832
5873
|
);
|
|
5833
5874
|
builderRegistry.registerBuilder(simpleRouter);
|
|
5834
5875
|
}
|
|
@@ -5852,6 +5893,7 @@ var UniversalGraphModule = class {
|
|
|
5852
5893
|
exports: [
|
|
5853
5894
|
"GRAPH_SERVICE",
|
|
5854
5895
|
"GRAPH_ENGINE",
|
|
5896
|
+
"CHECKPOINTER",
|
|
5855
5897
|
UniversalGraphService,
|
|
5856
5898
|
BuilderRegistryService,
|
|
5857
5899
|
VersionedGraphService,
|
|
@@ -6445,7 +6487,10 @@ function normalizeToolConfigs(tools) {
|
|
|
6445
6487
|
}
|
|
6446
6488
|
var DEFAULT_ROUTER_URL = "https://router.flutch.ai";
|
|
6447
6489
|
function resolveRouterURL(baseURL) {
|
|
6448
|
-
|
|
6490
|
+
if (baseURL) return baseURL;
|
|
6491
|
+
if (process.env.FLUTCH_ROUTER_URL) return process.env.FLUTCH_ROUTER_URL;
|
|
6492
|
+
if (process.env.FLUTCH_API_TOKEN) return DEFAULT_ROUTER_URL;
|
|
6493
|
+
return void 0;
|
|
6449
6494
|
}
|
|
6450
6495
|
function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig, baseURL) {
|
|
6451
6496
|
const parts = [
|
|
@@ -6552,12 +6597,15 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6552
6597
|
};
|
|
6553
6598
|
/**
|
|
6554
6599
|
* Resolve API key for a provider.
|
|
6555
|
-
*
|
|
6600
|
+
* Priority: custom resolver > FLUTCH_API_TOKEN > provider-specific env var.
|
|
6556
6601
|
*/
|
|
6557
6602
|
resolveApiKey(provider) {
|
|
6558
6603
|
if (this.apiKeyResolver) {
|
|
6559
6604
|
return this.apiKeyResolver(provider);
|
|
6560
6605
|
}
|
|
6606
|
+
if (process.env.FLUTCH_API_TOKEN) {
|
|
6607
|
+
return process.env.FLUTCH_API_TOKEN;
|
|
6608
|
+
}
|
|
6561
6609
|
const envVar = _ModelInitializer.DEFAULT_ENV_MAP[provider];
|
|
6562
6610
|
return envVar ? process.env[envVar] : void 0;
|
|
6563
6611
|
}
|
|
@@ -6603,7 +6651,10 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6603
6651
|
defaultMaxTokens,
|
|
6604
6652
|
apiToken || this.resolveApiKey("openai" /* OPENAI */) || ""
|
|
6605
6653
|
);
|
|
6606
|
-
|
|
6654
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6655
|
+
if (routerURL) {
|
|
6656
|
+
config.configuration = { baseURL: `${routerURL}/v1` };
|
|
6657
|
+
}
|
|
6607
6658
|
return new ChatOpenAI(config);
|
|
6608
6659
|
},
|
|
6609
6660
|
["anthropic" /* ANTHROPIC */]: ({
|
|
@@ -6617,7 +6668,9 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6617
6668
|
temperature: defaultTemperature,
|
|
6618
6669
|
maxTokens: defaultMaxTokens,
|
|
6619
6670
|
anthropicApiKey: apiToken || this.resolveApiKey("anthropic" /* ANTHROPIC */),
|
|
6620
|
-
|
|
6671
|
+
...resolveRouterURL(baseURL) && {
|
|
6672
|
+
anthropicApiUrl: resolveRouterURL(baseURL)
|
|
6673
|
+
}
|
|
6621
6674
|
}),
|
|
6622
6675
|
["cohere" /* COHERE */]: ({
|
|
6623
6676
|
modelName,
|
|
@@ -6625,30 +6678,35 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6625
6678
|
defaultMaxTokens,
|
|
6626
6679
|
apiToken,
|
|
6627
6680
|
baseURL
|
|
6628
|
-
}) =>
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6681
|
+
}) => {
|
|
6682
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6683
|
+
const token = apiToken || this.resolveApiKey("cohere" /* COHERE */);
|
|
6684
|
+
return routerURL ? new ChatCohere({
|
|
6685
|
+
model: modelName,
|
|
6686
|
+
temperature: defaultTemperature,
|
|
6687
|
+
client: new CohereClient({ token, baseUrl: routerURL })
|
|
6688
|
+
}) : new ChatCohere({
|
|
6689
|
+
model: modelName,
|
|
6690
|
+
temperature: defaultTemperature,
|
|
6691
|
+
apiKey: token
|
|
6692
|
+
});
|
|
6693
|
+
},
|
|
6636
6694
|
["mistral" /* MISTRAL */]: ({
|
|
6637
6695
|
modelName,
|
|
6638
6696
|
defaultTemperature,
|
|
6639
6697
|
defaultMaxTokens,
|
|
6640
6698
|
apiToken,
|
|
6641
6699
|
baseURL
|
|
6642
|
-
}) =>
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
}
|
|
6700
|
+
}) => {
|
|
6701
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6702
|
+
return new ChatMistralAI({
|
|
6703
|
+
model: modelName,
|
|
6704
|
+
temperature: defaultTemperature,
|
|
6705
|
+
maxTokens: defaultMaxTokens,
|
|
6706
|
+
apiKey: apiToken || this.resolveApiKey("mistral" /* MISTRAL */),
|
|
6707
|
+
...routerURL && { serverURL: `${routerURL}/v1` }
|
|
6708
|
+
});
|
|
6709
|
+
},
|
|
6652
6710
|
["voyageai" /* VOYAGEAI */]: () => {
|
|
6653
6711
|
throw new Error("VoyageAI chat models not implemented");
|
|
6654
6712
|
}
|
|
@@ -6661,13 +6719,16 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6661
6719
|
maxDocuments,
|
|
6662
6720
|
baseURL
|
|
6663
6721
|
}) => {
|
|
6664
|
-
|
|
6722
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6723
|
+
const token = apiToken || this.resolveApiKey("cohere" /* COHERE */);
|
|
6724
|
+
return routerURL ? new CohereRerank({
|
|
6665
6725
|
model: modelName,
|
|
6666
6726
|
topN: maxDocuments || 20,
|
|
6667
|
-
client: new CohereClient({
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6727
|
+
client: new CohereClient({ token, baseUrl: routerURL })
|
|
6728
|
+
}) : new CohereRerank({
|
|
6729
|
+
model: modelName,
|
|
6730
|
+
topN: maxDocuments || 20,
|
|
6731
|
+
apiKey: token
|
|
6671
6732
|
});
|
|
6672
6733
|
},
|
|
6673
6734
|
["voyageai" /* VOYAGEAI */]: ({
|
|
@@ -6676,11 +6737,12 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6676
6737
|
maxDocuments,
|
|
6677
6738
|
baseURL
|
|
6678
6739
|
}) => {
|
|
6740
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6679
6741
|
return new VoyageAIRerank({
|
|
6680
6742
|
apiKey: apiToken || this.resolveApiKey("voyageai" /* VOYAGEAI */),
|
|
6681
6743
|
model: modelName,
|
|
6682
6744
|
topN: maxDocuments || 20,
|
|
6683
|
-
baseUrl:
|
|
6745
|
+
...routerURL && { baseUrl: routerURL }
|
|
6684
6746
|
});
|
|
6685
6747
|
},
|
|
6686
6748
|
// Other providers don't support rerank yet
|
|
@@ -6691,11 +6753,16 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6691
6753
|
};
|
|
6692
6754
|
// Embedding model creators
|
|
6693
6755
|
embeddingModelCreators = {
|
|
6694
|
-
["openai" /* OPENAI */]: ({ modelName, apiToken, baseURL }) =>
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6756
|
+
["openai" /* OPENAI */]: ({ modelName, apiToken, baseURL }) => {
|
|
6757
|
+
const routerURL = resolveRouterURL(baseURL);
|
|
6758
|
+
return new OpenAIEmbeddings({
|
|
6759
|
+
model: modelName,
|
|
6760
|
+
apiKey: apiToken || this.resolveApiKey("openai" /* OPENAI */),
|
|
6761
|
+
...routerURL && {
|
|
6762
|
+
configuration: { baseURL: `${routerURL}/v1` }
|
|
6763
|
+
}
|
|
6764
|
+
});
|
|
6765
|
+
},
|
|
6699
6766
|
// Other providers not yet implemented for embeddings
|
|
6700
6767
|
["anthropic" /* ANTHROPIC */]: void 0,
|
|
6701
6768
|
["cohere" /* COHERE */]: void 0,
|
|
@@ -7076,28 +7143,11 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
7076
7143
|
);
|
|
7077
7144
|
}
|
|
7078
7145
|
const config = await response.json();
|
|
7079
|
-
console.debug(
|
|
7080
|
-
`ModelInitializer.fetchFromApi - API response for ${modelId}:`,
|
|
7081
|
-
{
|
|
7082
|
-
url,
|
|
7083
|
-
statusCode: response.status,
|
|
7084
|
-
configKeys: Object.keys(config),
|
|
7085
|
-
modelType: config.modelType,
|
|
7086
|
-
hasModelType: !!config.modelType,
|
|
7087
|
-
fullConfig: config
|
|
7088
|
-
}
|
|
7089
|
-
);
|
|
7090
7146
|
const result = {
|
|
7091
7147
|
...config,
|
|
7092
7148
|
modelType: config.modelType || "chat" /* CHAT */
|
|
7093
7149
|
// Fallback for compatibility
|
|
7094
7150
|
};
|
|
7095
|
-
console.debug(`ModelInitializer.fetchFromApi - final result:`, {
|
|
7096
|
-
modelId,
|
|
7097
|
-
resultModelType: result.modelType,
|
|
7098
|
-
usedFallback: !config.modelType,
|
|
7099
|
-
resultKeys: Object.keys(result)
|
|
7100
|
-
});
|
|
7101
7151
|
return result;
|
|
7102
7152
|
}
|
|
7103
7153
|
};
|