@inkeep/agents-core 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.js CHANGED
@@ -197,6 +197,22 @@ function getLogger(name) {
197
197
 
198
198
  // src/context/ContextConfig.ts
199
199
  var logger = getLogger("context-config");
200
+ var RequestContextSchemaBuilder = class {
201
+ constructor(options) {
202
+ __publicField(this, "schema");
203
+ this.schema = options.schema;
204
+ }
205
+ /** Template function for request context paths with type-safe autocomplete */
206
+ toTemplate(path2) {
207
+ return `{{requestContext.${path2}}}`;
208
+ }
209
+ getSchema() {
210
+ return this.schema;
211
+ }
212
+ getJsonSchema() {
213
+ return convertZodToJsonSchema(this.schema);
214
+ }
215
+ };
200
216
  function convertZodToJsonSchema(zodSchema) {
201
217
  try {
202
218
  return z$1.toJSONSchema(zodSchema, { target: "draft-7" });
@@ -219,23 +235,34 @@ var ContextConfigBuilder = class {
219
235
  this.tenantId = options.tenantId || "default";
220
236
  this.projectId = options.projectId || "default";
221
237
  this.baseURL = process.env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002";
222
- let requestContextSchema;
238
+ let requestContextSchema2;
223
239
  if (options.requestContextSchema) {
240
+ const actualSchema = options.requestContextSchema instanceof RequestContextSchemaBuilder ? options.requestContextSchema.getSchema() : options.requestContextSchema;
224
241
  logger.info(
225
242
  {
226
243
  requestContextSchema: options.requestContextSchema
227
244
  },
228
245
  "Converting request headers schema to JSON Schema for database storage"
229
246
  );
230
- let schema = options.requestContextSchema;
231
- if (schema instanceof z$1.ZodObject) {
232
- schema = schema.loose();
247
+ requestContextSchema2 = convertZodToJsonSchema(actualSchema);
248
+ }
249
+ const processedContextVariables = {};
250
+ if (options.contextVariables) {
251
+ for (const [key, definition] of Object.entries(options.contextVariables)) {
252
+ const { credentialReference, ...rest } = definition;
253
+ processedContextVariables[key] = {
254
+ ...rest,
255
+ responseSchema: convertZodToJsonSchema(definition.responseSchema),
256
+ credentialReferenceId: credentialReference?.id
257
+ };
233
258
  logger.debug(
234
- { schemaType: "ZodObject" },
235
- "Applied .loose() to ZodObject requestContextSchema for more permissive validation"
259
+ {
260
+ contextVariableKey: key,
261
+ originalSchema: definition.responseSchema
262
+ },
263
+ "Converting contextVariable responseSchema to JSON Schema for database storage"
236
264
  );
237
265
  }
238
- requestContextSchema = convertZodToJsonSchema(schema);
239
266
  }
240
267
  this.config = {
241
268
  id: options.id,
@@ -243,8 +270,8 @@ var ContextConfigBuilder = class {
243
270
  projectId: this.projectId,
244
271
  name: options.name,
245
272
  description: options.description || "",
246
- requestContextSchema,
247
- contextVariables: options.contextVariables || {}
273
+ requestContextSchema: requestContextSchema2,
274
+ contextVariables: processedContextVariables
248
275
  };
249
276
  logger.info(
250
277
  {
@@ -254,6 +281,22 @@ var ContextConfigBuilder = class {
254
281
  "ContextConfig builder initialized"
255
282
  );
256
283
  }
284
+ /**
285
+ * Convert the builder to a plain object for database operations
286
+ */
287
+ toObject() {
288
+ return {
289
+ id: this.getId(),
290
+ tenantId: this.tenantId,
291
+ projectId: this.projectId,
292
+ name: this.getName(),
293
+ description: this.getDescription(),
294
+ requestContextSchema: this.getRequestContextSchema(),
295
+ contextVariables: this.getContextVariables(),
296
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
297
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
298
+ };
299
+ }
257
300
  // Getter methods
258
301
  getId() {
259
302
  if (!this.config.id) {
@@ -276,35 +319,14 @@ var ContextConfigBuilder = class {
276
319
  getContextVariables() {
277
320
  return this.config.contextVariables || {};
278
321
  }
279
- /**
280
- * Convert the builder to a plain object for database operations
281
- */
282
- toObject() {
283
- return {
284
- id: this.getId(),
285
- tenantId: this.tenantId,
286
- projectId: this.projectId,
287
- name: this.getName(),
288
- description: this.getDescription(),
289
- requestContextSchema: this.getRequestContextSchema(),
290
- contextVariables: this.getContextVariables(),
291
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
292
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
293
- };
294
- }
295
322
  // Builder methods for fluent API
296
323
  withRequestContextSchema(schema) {
297
324
  this.config.requestContextSchema = schema;
298
325
  return this;
299
326
  }
300
- withContextVariable(key, definition) {
301
- this.config.contextVariables = this.config.contextVariables || {};
302
- this.config.contextVariables[key] = definition;
303
- return this;
304
- }
305
- withContextVariables(variables) {
306
- this.config.contextVariables = variables;
307
- return this;
327
+ /** 4) The function you ship: path autocomplete + validation, returns {{path}} */
328
+ toTemplate(path2) {
329
+ return `{{${path2}}}`;
308
330
  }
309
331
  // Validation method
310
332
  validate() {
@@ -449,15 +471,11 @@ var ContextConfigBuilder = class {
449
471
  function contextConfig(options) {
450
472
  return new ContextConfigBuilder(options);
451
473
  }
474
+ function requestContextSchema(options) {
475
+ return new RequestContextSchemaBuilder(options);
476
+ }
452
477
  function fetchDefinition(options) {
453
- const fetchConfig = options.fetchConfig || {
454
- url: options.url,
455
- method: options.method,
456
- headers: options.headers,
457
- body: options.body,
458
- transform: options.transform,
459
- timeout: options.timeout
460
- };
478
+ const fetchConfig = options.fetchConfig;
461
479
  return {
462
480
  id: options.id,
463
481
  name: options.name,
@@ -470,9 +488,9 @@ function fetchDefinition(options) {
470
488
  transform: fetchConfig.transform,
471
489
  timeout: fetchConfig.timeout
472
490
  },
473
- responseSchema: options.responseSchema ? convertZodToJsonSchema(options.responseSchema) : void 0,
491
+ responseSchema: options.responseSchema,
474
492
  defaultValue: options.defaultValue,
475
- credentialReferenceId: options.credential?.id
493
+ credentialReferenceId: options.credentialReference?.id
476
494
  };
477
495
  }
478
496
  var logger2 = getLogger("template-engine");
@@ -6378,7 +6396,7 @@ var McpClient = class {
6378
6396
  if (!activeTools) return;
6379
6397
  for (const item of activeTools) {
6380
6398
  if (tools2.includes(item)) continue;
6381
- throw new Error(`[Tools] Tool ${item} not found in tools`);
6399
+ console.warn(`[Tools] Tool ${item} not found in tools`);
6382
6400
  }
6383
6401
  }
6384
6402
  async selectTools() {
@@ -7043,21 +7061,62 @@ var ContextResolver = class {
7043
7061
  var logger7 = getLogger("context-validation");
7044
7062
  var ajv = new Ajv({ allErrors: true, strict: false });
7045
7063
  var HTTP_REQUEST_PARTS = ["headers"];
7064
+ var MAX_SCHEMA_CACHE_SIZE = 1e3;
7046
7065
  var schemaCache = /* @__PURE__ */ new Map();
7047
7066
  function isValidHttpRequest(obj) {
7048
7067
  return obj != null && typeof obj === "object" && !Array.isArray(obj) && "headers" in obj;
7049
7068
  }
7050
7069
  function getCachedValidator(schema) {
7051
7070
  const key = JSON.stringify(schema);
7052
- if (!schemaCache.has(key)) {
7053
- schemaCache.set(key, ajv.compile(schema));
7071
+ if (schemaCache.has(key)) {
7072
+ const validator2 = schemaCache.get(key);
7073
+ if (!validator2) {
7074
+ throw new Error("Unexpected: validator not found in cache after has() check");
7075
+ }
7076
+ schemaCache.delete(key);
7077
+ schemaCache.set(key, validator2);
7078
+ return validator2;
7054
7079
  }
7055
- const validator = schemaCache.get(key);
7056
- if (!validator) {
7057
- throw new Error("Failed to compile JSON schema");
7080
+ if (schemaCache.size >= MAX_SCHEMA_CACHE_SIZE) {
7081
+ const firstKey = schemaCache.keys().next().value;
7082
+ if (firstKey) {
7083
+ schemaCache.delete(firstKey);
7084
+ }
7058
7085
  }
7086
+ const permissiveSchema = makeSchemaPermissive(schema);
7087
+ const validator = ajv.compile(permissiveSchema);
7088
+ schemaCache.set(key, validator);
7059
7089
  return validator;
7060
7090
  }
7091
+ function makeSchemaPermissive(schema) {
7092
+ if (!schema || typeof schema !== "object") {
7093
+ return schema;
7094
+ }
7095
+ const permissiveSchema = { ...schema };
7096
+ if (permissiveSchema.type === "object") {
7097
+ permissiveSchema.additionalProperties = true;
7098
+ if (permissiveSchema.properties && typeof permissiveSchema.properties === "object") {
7099
+ const newProperties = {};
7100
+ for (const [key, value] of Object.entries(permissiveSchema.properties)) {
7101
+ newProperties[key] = makeSchemaPermissive(value);
7102
+ }
7103
+ permissiveSchema.properties = newProperties;
7104
+ }
7105
+ }
7106
+ if (permissiveSchema.type === "array" && permissiveSchema.items) {
7107
+ permissiveSchema.items = makeSchemaPermissive(permissiveSchema.items);
7108
+ }
7109
+ if (permissiveSchema.oneOf) {
7110
+ permissiveSchema.oneOf = permissiveSchema.oneOf.map(makeSchemaPermissive);
7111
+ }
7112
+ if (permissiveSchema.anyOf) {
7113
+ permissiveSchema.anyOf = permissiveSchema.anyOf.map(makeSchemaPermissive);
7114
+ }
7115
+ if (permissiveSchema.allOf) {
7116
+ permissiveSchema.allOf = permissiveSchema.allOf.map(makeSchemaPermissive);
7117
+ }
7118
+ return permissiveSchema;
7119
+ }
7061
7120
  function validationHelper(jsonSchema) {
7062
7121
  return getCachedValidator(jsonSchema);
7063
7122
  }
@@ -8522,4 +8581,4 @@ ${error.message}`
8522
8581
  };
8523
8582
  parseEnv();
8524
8583
 
8525
- export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, PinoLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getHealthyToolsForAgent, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsByStatus, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, listToolsByStatus, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, updateToolStatus, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
8584
+ export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, PinoLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getHealthyToolsForAgent, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsByStatus, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, listToolsByStatus, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, updateToolStatus, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };