@inkeep/agents-run-api 0.6.0 → 0.6.5

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 CHANGED
@@ -283,6 +283,9 @@ var init_conversations = __esm({
283
283
  init_dbClient();
284
284
  }
285
285
  });
286
+
287
+ // src/index.ts
288
+ init_env();
286
289
  var otlpExporter = new exporterTraceOtlpHttp.OTLPTraceExporter();
287
290
  var defaultBatchProcessor = new sdkTraceBase.BatchSpanProcessor(otlpExporter);
288
291
  var defaultResource = resources.resourceFromAttributes({
@@ -325,6 +328,8 @@ new sdkNode.NodeSDK({
325
328
  spanProcessors: defaultSpanProcessors,
326
329
  instrumentations: defaultInstrumentations
327
330
  });
331
+
332
+ // src/middleware/api-key-auth.ts
328
333
  init_dbClient();
329
334
  init_env();
330
335
 
@@ -359,6 +364,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
359
364
  if (authHeader?.startsWith("Bearer ")) {
360
365
  try {
361
366
  executionContext = await extractContextFromApiKey(authHeader.substring(7));
367
+ executionContext.agentId = agentId;
362
368
  logger.info({}, "Development/test environment - API key authenticated successfully");
363
369
  } catch {
364
370
  executionContext = createExecutionContext({
@@ -5269,6 +5275,37 @@ var Agent = class {
5269
5275
  getMaxGenerationSteps() {
5270
5276
  return this.config.stopWhen?.stepCountIs ?? CONSTANTS.MAX_GENERATION_STEPS;
5271
5277
  }
5278
+ /**
5279
+ * Sanitizes tool names at runtime for AI SDK compatibility.
5280
+ * The AI SDK requires tool names to match pattern ^[a-zA-Z0-9_-]{1,128}$
5281
+ */
5282
+ sanitizeToolsForAISDK(tools) {
5283
+ const sanitizedTools = {};
5284
+ for (const [originalKey, toolDef] of Object.entries(tools)) {
5285
+ let sanitizedKey = originalKey.replace(/[^a-zA-Z0-9_-]/g, "_");
5286
+ sanitizedKey = sanitizedKey.replace(/_+/g, "_");
5287
+ sanitizedKey = sanitizedKey.replace(/^_+|_+$/g, "");
5288
+ if (!sanitizedKey || sanitizedKey.length === 0) {
5289
+ sanitizedKey = "unnamed_tool";
5290
+ }
5291
+ if (sanitizedKey.length > 100) {
5292
+ sanitizedKey = sanitizedKey.substring(0, 100);
5293
+ }
5294
+ const originalId = toolDef.id || originalKey;
5295
+ let sanitizedId = originalId.replace(/[^a-zA-Z0-9_.-]/g, "_");
5296
+ sanitizedId = sanitizedId.replace(/_+/g, "_");
5297
+ sanitizedId = sanitizedId.replace(/^_+|_+$/g, "");
5298
+ if (sanitizedId.length > 128) {
5299
+ sanitizedId = sanitizedId.substring(0, 128);
5300
+ }
5301
+ const sanitizedTool = {
5302
+ ...toolDef,
5303
+ id: sanitizedId
5304
+ };
5305
+ sanitizedTools[sanitizedKey] = sanitizedTool;
5306
+ }
5307
+ return sanitizedTools;
5308
+ }
5272
5309
  /**
5273
5310
  * Get the primary model settings for text generation and thinking
5274
5311
  * Requires model to be configured at project level
@@ -5965,6 +6002,7 @@ Key requirements:
5965
6002
  ...relationTools,
5966
6003
  ...defaultTools
5967
6004
  };
6005
+ const sanitizedTools = this.sanitizeToolsForAISDK(allTools);
5968
6006
  let conversationHistory = "";
5969
6007
  const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
5970
6008
  if (historyConfig && historyConfig.mode !== "none") {
@@ -6029,7 +6067,7 @@ Key requirements:
6029
6067
  const streamResult = ai.streamText({
6030
6068
  ...streamConfig,
6031
6069
  messages,
6032
- tools: allTools,
6070
+ tools: sanitizedTools,
6033
6071
  stopWhen: async ({ steps }) => {
6034
6072
  const last = steps.at(-1);
6035
6073
  if (last && "text" in last && last.text) {
@@ -6112,7 +6150,7 @@ Key requirements:
6112
6150
  response = await ai.generateText({
6113
6151
  ...genConfig,
6114
6152
  messages,
6115
- tools: allTools,
6153
+ tools: sanitizedTools,
6116
6154
  stopWhen: async ({ steps }) => {
6117
6155
  const last = steps.at(-1);
6118
6156
  if (last && "text" in last && last.text) {
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
59
59
  if (authHeader?.startsWith("Bearer ")) {
60
60
  try {
61
61
  executionContext = await extractContextFromApiKey(authHeader.substring(7));
62
+ executionContext.agentId = agentId;
62
63
  logger.info({}, "Development/test environment - API key authenticated successfully");
63
64
  } catch {
64
65
  executionContext = createExecutionContext({
@@ -4943,6 +4944,37 @@ var Agent = class {
4943
4944
  getMaxGenerationSteps() {
4944
4945
  return this.config.stopWhen?.stepCountIs ?? CONSTANTS.MAX_GENERATION_STEPS;
4945
4946
  }
4947
+ /**
4948
+ * Sanitizes tool names at runtime for AI SDK compatibility.
4949
+ * The AI SDK requires tool names to match pattern ^[a-zA-Z0-9_-]{1,128}$
4950
+ */
4951
+ sanitizeToolsForAISDK(tools) {
4952
+ const sanitizedTools = {};
4953
+ for (const [originalKey, toolDef] of Object.entries(tools)) {
4954
+ let sanitizedKey = originalKey.replace(/[^a-zA-Z0-9_-]/g, "_");
4955
+ sanitizedKey = sanitizedKey.replace(/_+/g, "_");
4956
+ sanitizedKey = sanitizedKey.replace(/^_+|_+$/g, "");
4957
+ if (!sanitizedKey || sanitizedKey.length === 0) {
4958
+ sanitizedKey = "unnamed_tool";
4959
+ }
4960
+ if (sanitizedKey.length > 100) {
4961
+ sanitizedKey = sanitizedKey.substring(0, 100);
4962
+ }
4963
+ const originalId = toolDef.id || originalKey;
4964
+ let sanitizedId = originalId.replace(/[^a-zA-Z0-9_.-]/g, "_");
4965
+ sanitizedId = sanitizedId.replace(/_+/g, "_");
4966
+ sanitizedId = sanitizedId.replace(/^_+|_+$/g, "");
4967
+ if (sanitizedId.length > 128) {
4968
+ sanitizedId = sanitizedId.substring(0, 128);
4969
+ }
4970
+ const sanitizedTool = {
4971
+ ...toolDef,
4972
+ id: sanitizedId
4973
+ };
4974
+ sanitizedTools[sanitizedKey] = sanitizedTool;
4975
+ }
4976
+ return sanitizedTools;
4977
+ }
4946
4978
  /**
4947
4979
  * Get the primary model settings for text generation and thinking
4948
4980
  * Requires model to be configured at project level
@@ -5639,6 +5671,7 @@ Key requirements:
5639
5671
  ...relationTools,
5640
5672
  ...defaultTools
5641
5673
  };
5674
+ const sanitizedTools = this.sanitizeToolsForAISDK(allTools);
5642
5675
  let conversationHistory = "";
5643
5676
  const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
5644
5677
  if (historyConfig && historyConfig.mode !== "none") {
@@ -5703,7 +5736,7 @@ Key requirements:
5703
5736
  const streamResult = streamText({
5704
5737
  ...streamConfig,
5705
5738
  messages,
5706
- tools: allTools,
5739
+ tools: sanitizedTools,
5707
5740
  stopWhen: async ({ steps }) => {
5708
5741
  const last = steps.at(-1);
5709
5742
  if (last && "text" in last && last.text) {
@@ -5786,7 +5819,7 @@ Key requirements:
5786
5819
  response = await generateText({
5787
5820
  ...genConfig,
5788
5821
  messages,
5789
- tools: allTools,
5822
+ tools: sanitizedTools,
5790
5823
  stopWhen: async ({ steps }) => {
5791
5824
  const last = steps.at(-1);
5792
5825
  if (last && "text" in last && last.text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.6.0",
3
+ "version": "0.6.5",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "traverse": "^0.6.11",
53
53
  "ts-pattern": "^5.7.1",
54
54
  "zod": "^4.1.5",
55
- "@inkeep/agents-core": "^0.6.0"
55
+ "@inkeep/agents-core": "^0.6.5"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@hono/vite-dev-server": "^0.20.1",