@flutchai/flutch-sdk 0.2.11 → 0.2.15

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.d.cts CHANGED
@@ -1015,6 +1015,7 @@ interface ModelByIdConfig {
1015
1015
  modelId: string;
1016
1016
  temperature?: number;
1017
1017
  maxTokens?: number;
1018
+ baseURL?: string;
1018
1019
  toolsConfig?: IAgentToolConfig[];
1019
1020
  customTools?: DynamicStructuredTool[];
1020
1021
  }
@@ -1029,6 +1030,7 @@ interface ModelConfigWithToken {
1029
1030
  requiresApiKey: boolean;
1030
1031
  useBedrock?: boolean;
1031
1032
  bedrockModelId?: string;
1033
+ baseURL?: string;
1032
1034
  }
1033
1035
  type ApiKeyResolver = (provider: ModelProvider) => string | undefined;
1034
1036
  type LLModel = BaseChatModel;
@@ -1278,6 +1280,10 @@ interface ExecuteToolWithAttachmentsParams {
1278
1280
  injectIntoArg?: string;
1279
1281
  sourceAttachmentId?: string;
1280
1282
  threadId?: string;
1283
+ toolSchema?: {
1284
+ properties?: Record<string, any>;
1285
+ required?: string[];
1286
+ };
1281
1287
  }
1282
1288
  interface ExecuteToolWithAttachmentsResult {
1283
1289
  toolMessage: ToolMessage;
@@ -1287,7 +1293,10 @@ interface ExecuteToolWithAttachmentsResult {
1287
1293
  };
1288
1294
  }
1289
1295
  declare function executeToolWithAttachments(params: ExecuteToolWithAttachmentsParams): Promise<ExecuteToolWithAttachmentsResult>;
1290
- declare function shouldInjectData(args: Record<string, any>, attachments: Record<string, IGraphAttachment>, dataArgName: string): boolean;
1296
+ declare function shouldInjectData(args: Record<string, any>, attachments: Record<string, IGraphAttachment>, dataArgName: string, toolSchema?: {
1297
+ properties?: Record<string, any>;
1298
+ required?: string[];
1299
+ }): boolean;
1291
1300
  declare const _internals: {
1292
1301
  shouldInjectData: typeof shouldInjectData;
1293
1302
  getLatestAttachment: typeof getLatestAttachment;
package/dist/index.d.ts CHANGED
@@ -1015,6 +1015,7 @@ interface ModelByIdConfig {
1015
1015
  modelId: string;
1016
1016
  temperature?: number;
1017
1017
  maxTokens?: number;
1018
+ baseURL?: string;
1018
1019
  toolsConfig?: IAgentToolConfig[];
1019
1020
  customTools?: DynamicStructuredTool[];
1020
1021
  }
@@ -1029,6 +1030,7 @@ interface ModelConfigWithToken {
1029
1030
  requiresApiKey: boolean;
1030
1031
  useBedrock?: boolean;
1031
1032
  bedrockModelId?: string;
1033
+ baseURL?: string;
1032
1034
  }
1033
1035
  type ApiKeyResolver = (provider: ModelProvider) => string | undefined;
1034
1036
  type LLModel = BaseChatModel;
@@ -1278,6 +1280,10 @@ interface ExecuteToolWithAttachmentsParams {
1278
1280
  injectIntoArg?: string;
1279
1281
  sourceAttachmentId?: string;
1280
1282
  threadId?: string;
1283
+ toolSchema?: {
1284
+ properties?: Record<string, any>;
1285
+ required?: string[];
1286
+ };
1281
1287
  }
1282
1288
  interface ExecuteToolWithAttachmentsResult {
1283
1289
  toolMessage: ToolMessage;
@@ -1287,7 +1293,10 @@ interface ExecuteToolWithAttachmentsResult {
1287
1293
  };
1288
1294
  }
1289
1295
  declare function executeToolWithAttachments(params: ExecuteToolWithAttachmentsParams): Promise<ExecuteToolWithAttachmentsResult>;
1290
- declare function shouldInjectData(args: Record<string, any>, attachments: Record<string, IGraphAttachment>, dataArgName: string): boolean;
1296
+ declare function shouldInjectData(args: Record<string, any>, attachments: Record<string, IGraphAttachment>, dataArgName: string, toolSchema?: {
1297
+ properties?: Record<string, any>;
1298
+ required?: string[];
1299
+ }): boolean;
1291
1300
  declare const _internals: {
1292
1301
  shouldInjectData: typeof shouldInjectData;
1293
1302
  getLatestAttachment: typeof getLatestAttachment;
package/dist/index.js CHANGED
@@ -4447,11 +4447,17 @@ async function executeToolWithAttachments(params) {
4447
4447
  threshold = DEFAULT_ATTACHMENT_THRESHOLD,
4448
4448
  injectIntoArg = "data",
4449
4449
  sourceAttachmentId,
4450
- threadId
4450
+ threadId,
4451
+ toolSchema
4451
4452
  } = params;
4452
4453
  const argsWithInjection = { ...enrichedArgs };
4453
4454
  try {
4454
- if (shouldInjectData(argsWithInjection, attachments, injectIntoArg)) {
4455
+ if (shouldInjectData(
4456
+ argsWithInjection,
4457
+ attachments,
4458
+ injectIntoArg,
4459
+ toolSchema
4460
+ )) {
4455
4461
  const attachment = sourceAttachmentId ? attachments[sourceAttachmentId] : getLatestAttachment(attachments);
4456
4462
  if (attachment) {
4457
4463
  const attachmentKey = sourceAttachmentId || attachment.toolCallId;
@@ -4513,9 +4519,17 @@ async function executeToolWithAttachments(params) {
4513
4519
  });
4514
4520
  return { toolMessage };
4515
4521
  }
4516
- function shouldInjectData(args, attachments, dataArgName) {
4522
+ function shouldInjectData(args, attachments, dataArgName, toolSchema) {
4517
4523
  if (Object.keys(attachments).length === 0) return false;
4518
- return args[dataArgName] === void 0;
4524
+ if (args[dataArgName] !== void 0) return false;
4525
+ if (toolSchema) {
4526
+ const hasProperty = toolSchema.properties && dataArgName in toolSchema.properties;
4527
+ const isRequired = toolSchema.required?.includes(dataArgName);
4528
+ if (!hasProperty && !isRequired) {
4529
+ return false;
4530
+ }
4531
+ }
4532
+ return true;
4519
4533
  }
4520
4534
  var _internals = {
4521
4535
  shouldInjectData,
@@ -6422,12 +6436,19 @@ function hashToolsConfig(toolsConfig) {
6422
6436
  const sorted = toolsConfig.map((t) => `${t.toolName}:${t.enabled}:${JSON.stringify(t.config || {})}`).sort().join("|");
6423
6437
  return createHash("md5").update(sorted).digest("hex").slice(0, 16);
6424
6438
  }
6425
- function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig) {
6439
+ var DEFAULT_ROUTER_URL = "https://router.flutch.ai";
6440
+ function resolveRouterURL(baseURL) {
6441
+ return baseURL ?? process.env.FLUTCH_ROUTER_URL ?? DEFAULT_ROUTER_URL;
6442
+ }
6443
+ function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig, baseURL) {
6426
6444
  const parts = [
6427
6445
  modelId,
6428
6446
  temperature ?? "default",
6429
6447
  maxTokens ?? "default"
6430
6448
  ];
6449
+ if (baseURL) {
6450
+ parts.push(baseURL);
6451
+ }
6431
6452
  if (toolsConfig && toolsConfig.length > 0) {
6432
6453
  parts.push(hashToolsConfig(toolsConfig));
6433
6454
  }
@@ -6555,7 +6576,8 @@ var ModelInitializer = class _ModelInitializer {
6555
6576
  config.modelId,
6556
6577
  config.temperature,
6557
6578
  config.maxTokens,
6558
- config.toolsConfig
6579
+ config.toolsConfig,
6580
+ config.baseURL
6559
6581
  );
6560
6582
  }
6561
6583
  // Chat model creators
@@ -6564,7 +6586,8 @@ var ModelInitializer = class _ModelInitializer {
6564
6586
  modelName,
6565
6587
  defaultTemperature,
6566
6588
  defaultMaxTokens,
6567
- apiToken
6589
+ apiToken,
6590
+ baseURL
6568
6591
  }) => {
6569
6592
  const config = buildOpenAIModelConfig(
6570
6593
  modelName,
@@ -6572,18 +6595,21 @@ var ModelInitializer = class _ModelInitializer {
6572
6595
  defaultMaxTokens,
6573
6596
  apiToken || this.resolveApiKey("openai" /* OPENAI */) || ""
6574
6597
  );
6598
+ config.configuration = { baseURL: `${resolveRouterURL(baseURL)}/v1` };
6575
6599
  return new ChatOpenAI(config);
6576
6600
  },
6577
6601
  ["anthropic" /* ANTHROPIC */]: ({
6578
6602
  modelName,
6579
6603
  defaultTemperature,
6580
6604
  defaultMaxTokens,
6581
- apiToken
6605
+ apiToken,
6606
+ baseURL
6582
6607
  }) => new ChatAnthropic({
6583
6608
  modelName,
6584
6609
  temperature: defaultTemperature,
6585
6610
  maxTokens: defaultMaxTokens,
6586
- anthropicApiKey: apiToken || this.resolveApiKey("anthropic" /* ANTHROPIC */)
6611
+ anthropicApiKey: apiToken || this.resolveApiKey("anthropic" /* ANTHROPIC */),
6612
+ anthropicApiUrl: resolveRouterURL(baseURL)
6587
6613
  }),
6588
6614
  ["cohere" /* COHERE */]: ({
6589
6615
  modelName,
@@ -6599,12 +6625,17 @@ var ModelInitializer = class _ModelInitializer {
6599
6625
  modelName,
6600
6626
  defaultTemperature,
6601
6627
  defaultMaxTokens,
6602
- apiToken
6628
+ apiToken,
6629
+ baseURL
6603
6630
  }) => new ChatMistralAI({
6604
6631
  model: modelName,
6605
6632
  temperature: defaultTemperature,
6606
6633
  maxTokens: defaultMaxTokens,
6607
- apiKey: apiToken || this.resolveApiKey("mistral" /* MISTRAL */)
6634
+ apiKey: apiToken || this.resolveApiKey("mistral" /* MISTRAL */),
6635
+ // Route through the same gateway as OpenAI/Anthropic.
6636
+ // Without serverURL, ChatMistralAI ignores FLUTCH_ROUTER_URL and calls
6637
+ // api.mistral.ai directly — inconsistent with other providers.
6638
+ serverURL: `${resolveRouterURL(baseURL)}/v1`
6608
6639
  }),
6609
6640
  ["voyageai" /* VOYAGEAI */]: () => {
6610
6641
  throw new Error("VoyageAI chat models not implemented");
@@ -6665,7 +6696,8 @@ var ModelInitializer = class _ModelInitializer {
6665
6696
  ),
6666
6697
  defaultMaxTokens: Number(
6667
6698
  config.maxTokens ?? modelConfig.defaultMaxTokens
6668
- )
6699
+ ),
6700
+ baseURL: config.baseURL ?? modelConfig.baseURL
6669
6701
  };
6670
6702
  this.logger.debug(`Creating new chat model instance: ${cacheKey}`);
6671
6703
  let model;