@inkeep/agents-manage-api 0.3.0 → 0.5.0

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
@@ -9,10 +9,8 @@ var cors = require('hono/cors');
9
9
  var httpException = require('hono/http-exception');
10
10
  var requestId = require('hono/request-id');
11
11
  var honoPino = require('hono-pino');
12
- var async_hooks = require('async_hooks');
13
- var pino = require('pino');
14
- var zod = require('zod');
15
12
  var factory = require('hono/factory');
13
+ var zod = require('zod');
16
14
  var swaggerUi = require('@hono/swagger-ui');
17
15
  var nanoid = require('nanoid');
18
16
 
@@ -46,39 +44,8 @@ ${error.message}`
46
44
  };
47
45
  var env = parseEnv();
48
46
 
49
- // src/logger.ts
50
- var isDevelopment = env.ENVIRONMENT === "development";
51
- var loggerConfig = {
52
- level: env.LOG_LEVEL,
53
- serializers: {
54
- obj: (value) => ({ ...value })
55
- },
56
- redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
57
- // Only use pino-pretty in development
58
- ...isDevelopment && {
59
- transport: {
60
- target: "pino-pretty",
61
- options: {
62
- sync: true,
63
- destination: 1,
64
- // stdout
65
- colorize: true,
66
- translateTime: "SYS:standard"
67
- }
68
- }
69
- }
70
- };
71
- var logger = pino.pino(loggerConfig);
72
- var asyncLocalStorage = new async_hooks.AsyncLocalStorage();
73
- function getLogger(name) {
74
- const store = asyncLocalStorage.getStore();
75
- const reqId = store?.get("requestId") || void 0;
76
- if (!reqId) {
77
- return logger.child({ name });
78
- }
79
- return logger.child({ reqId, name });
80
- }
81
- var logger2 = agentsCore.getLogger("env-key-auth");
47
+ // src/middleware/auth.ts
48
+ var logger = agentsCore.getLogger("env-key-auth");
82
49
  var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
83
50
  if (env.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET) {
84
51
  const authHeader = c.req.header("Authorization");
@@ -89,7 +56,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
89
56
  }
90
57
  const apiKey = authHeader.substring(7);
91
58
  if (apiKey === env.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET) {
92
- logger2.info({}, "Bypass secret authenticated successfully");
59
+ logger.info({}, "Bypass secret authenticated successfully");
93
60
  await next();
94
61
  return;
95
62
  } else {
@@ -3058,7 +3025,7 @@ app12.openapi(
3058
3025
  }
3059
3026
  );
3060
3027
  var externalAgents_default = app12;
3061
- var logger3 = getLogger("graphFull");
3028
+ var logger2 = agentsCore.getLogger("graphFull");
3062
3029
  var app13 = new zodOpenapi.OpenAPIHono();
3063
3030
  var GraphIdParamsSchema = zod.z.object({
3064
3031
  tenantId: zod.z.string().openapi({
@@ -3116,7 +3083,7 @@ app13.openapi(
3116
3083
  const { tenantId, projectId } = c.req.valid("param");
3117
3084
  const graphData = c.req.valid("json");
3118
3085
  const validatedGraphData = agentsCore.FullGraphDefinitionSchema.parse(graphData);
3119
- const createdGraph = await agentsCore.createFullGraphServerSide(dbClient_default, logger3)(
3086
+ const createdGraph = await agentsCore.createFullGraphServerSide(dbClient_default, logger2)(
3120
3087
  { tenantId, projectId },
3121
3088
  validatedGraphData
3122
3089
  );
@@ -3151,7 +3118,7 @@ app13.openapi(
3151
3118
  try {
3152
3119
  const graph = await agentsCore.getFullGraph(
3153
3120
  dbClient_default,
3154
- logger3
3121
+ logger2
3155
3122
  )({
3156
3123
  scopes: { tenantId, projectId, graphId }
3157
3124
  });
@@ -3227,15 +3194,15 @@ app13.openapi(
3227
3194
  }
3228
3195
  const existingGraph = await agentsCore.getFullGraph(
3229
3196
  dbClient_default,
3230
- logger3
3197
+ logger2
3231
3198
  )({
3232
3199
  scopes: { tenantId, projectId, graphId }
3233
3200
  });
3234
3201
  const isCreate = !existingGraph;
3235
- const updatedGraph = isCreate ? await agentsCore.createFullGraphServerSide(dbClient_default, logger3)(
3202
+ const updatedGraph = isCreate ? await agentsCore.createFullGraphServerSide(dbClient_default, logger2)(
3236
3203
  { tenantId, projectId },
3237
3204
  validatedGraphData
3238
- ) : await agentsCore.updateFullGraphServerSide(dbClient_default, logger3)(
3205
+ ) : await agentsCore.updateFullGraphServerSide(dbClient_default, logger2)(
3239
3206
  { tenantId, projectId },
3240
3207
  validatedGraphData
3241
3208
  );
@@ -3283,7 +3250,7 @@ app13.openapi(
3283
3250
  try {
3284
3251
  const deleted = await agentsCore.deleteFullGraph(
3285
3252
  dbClient_default,
3286
- logger3
3253
+ logger2
3287
3254
  )({
3288
3255
  scopes: { tenantId, projectId, graphId }
3289
3256
  });
@@ -3550,7 +3517,7 @@ function extractInputSchema(toolDef) {
3550
3517
  }
3551
3518
  return {};
3552
3519
  }
3553
- var logger4 = getLogger("tools");
3520
+ var logger3 = agentsCore.getLogger("tools");
3554
3521
  var convertToMCPToolConfig = (tool) => {
3555
3522
  return {
3556
3523
  id: tool.id,
@@ -3659,7 +3626,7 @@ var checkToolHealth = async (tool, credentialStoreRegistry) => {
3659
3626
  }
3660
3627
  };
3661
3628
  } catch (error) {
3662
- logger4.error({ toolId: tool.id, error }, "Tool health check failed");
3629
+ logger3.error({ toolId: tool.id, error }, "Tool health check failed");
3663
3630
  if (error instanceof Error && await agentsCore.detectAuthenticationRequired(tool, error)) {
3664
3631
  return {
3665
3632
  status: "needs_auth",
@@ -3740,7 +3707,7 @@ var discoverToolsFromServer = async (tool, credentialStoreRegistry) => {
3740
3707
  );
3741
3708
  return toolDefinitions;
3742
3709
  } catch (error) {
3743
- logger4.error({ toolId: tool.id, error }, "Tool discovery failed");
3710
+ logger3.error({ toolId: tool.id, error }, "Tool discovery failed");
3744
3711
  throw error;
3745
3712
  }
3746
3713
  };
@@ -3804,7 +3771,7 @@ var checkAllToolsHealth = async (tenantId, projectId, credentialStoreRegistry) =
3804
3771
  };
3805
3772
 
3806
3773
  // src/utils/auth-detection.ts
3807
- var logger5 = getLogger("auth-detection");
3774
+ var logger4 = agentsCore.getLogger("auth-detection");
3808
3775
  var getWellKnownUrls = (baseUrl) => [
3809
3776
  `${baseUrl}/.well-known/oauth-authorization-server`,
3810
3777
  `${baseUrl}/.well-known/openid-configuration`
@@ -3826,12 +3793,12 @@ var tryWellKnownEndpoints = async (baseUrl) => {
3826
3793
  if (response.ok) {
3827
3794
  const metadata = await response.json();
3828
3795
  if (validateOAuthMetadata(metadata)) {
3829
- logger5.debug({ baseUrl, wellKnownUrl }, "OAuth 2.1/PKCE support detected");
3796
+ logger4.debug({ baseUrl, wellKnownUrl }, "OAuth 2.1/PKCE support detected");
3830
3797
  return buildOAuthConfig(metadata);
3831
3798
  }
3832
3799
  }
3833
3800
  } catch (error) {
3834
- logger5.debug({ wellKnownUrl, error }, "OAuth endpoint check failed");
3801
+ logger4.debug({ wellKnownUrl, error }, "OAuth endpoint check failed");
3835
3802
  }
3836
3803
  }
3837
3804
  return null;
@@ -3866,7 +3833,7 @@ var discoverOAuthEndpoints = async (serverUrl) => {
3866
3833
  };
3867
3834
 
3868
3835
  // src/utils/oauth-service.ts
3869
- var logger6 = getLogger("oauth-service");
3836
+ var logger5 = agentsCore.getLogger("oauth-service");
3870
3837
  var pkceStore = /* @__PURE__ */ new Map();
3871
3838
  function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId) {
3872
3839
  pkceStore.set(state, { codeVerifier, toolId, tenantId, projectId, clientId });
@@ -3924,7 +3891,7 @@ var OAuthService = class {
3924
3891
  resource: tool.config.mcp.server.url
3925
3892
  });
3926
3893
  storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId);
3927
- logger6.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
3894
+ logger5.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
3928
3895
  return {
3929
3896
  redirectUrl: authUrl,
3930
3897
  state
@@ -3949,9 +3916,9 @@ var OAuthService = class {
3949
3916
  codeVerifier,
3950
3917
  redirectUri
3951
3918
  });
3952
- logger6.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
3919
+ logger5.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
3953
3920
  } catch (error) {
3954
- logger6.warn(
3921
+ logger5.warn(
3955
3922
  { error: error instanceof Error ? error.message : error },
3956
3923
  "openid-client failed, falling back to manual token exchange"
3957
3924
  );
@@ -3962,7 +3929,7 @@ var OAuthService = class {
3962
3929
  codeVerifier,
3963
3930
  redirectUri
3964
3931
  });
3965
- logger6.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
3932
+ logger5.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
3966
3933
  }
3967
3934
  return { tokens, oAuthConfig };
3968
3935
  }
@@ -3970,7 +3937,7 @@ var OAuthService = class {
3970
3937
  * Perform dynamic client registration
3971
3938
  */
3972
3939
  async performDynamicClientRegistration(registrationUrl, redirectUri) {
3973
- logger6.info({ registrationUrl }, "Attempting dynamic client registration");
3940
+ logger5.info({ registrationUrl }, "Attempting dynamic client registration");
3974
3941
  try {
3975
3942
  const registrationResponse = await fetch(registrationUrl, {
3976
3943
  method: "POST",
@@ -3993,11 +3960,11 @@ var OAuthService = class {
3993
3960
  });
3994
3961
  if (registrationResponse.ok) {
3995
3962
  const registration = await registrationResponse.json();
3996
- logger6.info({ clientId: registration.client_id }, "Dynamic client registration successful");
3963
+ logger5.info({ clientId: registration.client_id }, "Dynamic client registration successful");
3997
3964
  return registration.client_id;
3998
3965
  } else {
3999
3966
  const errorText = await registrationResponse.text();
4000
- logger6.warn(
3967
+ logger5.warn(
4001
3968
  {
4002
3969
  status: registrationResponse.status,
4003
3970
  errorText
@@ -4006,7 +3973,7 @@ var OAuthService = class {
4006
3973
  );
4007
3974
  }
4008
3975
  } catch (regError) {
4009
- logger6.warn(
3976
+ logger5.warn(
4010
3977
  { error: regError },
4011
3978
  "Dynamic client registration error, using default client_id"
4012
3979
  );
@@ -4036,7 +4003,7 @@ var OAuthService = class {
4036
4003
  const oauth = await import('openid-client');
4037
4004
  const tokenUrl = new URL(oAuthConfig.tokenUrl);
4038
4005
  const oauthServerUrl = `${tokenUrl.protocol}//${tokenUrl.host}`;
4039
- logger6.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
4006
+ logger5.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
4040
4007
  const config = await oauth.discovery(
4041
4008
  new URL(oauthServerUrl),
4042
4009
  clientId,
@@ -4068,7 +4035,7 @@ var OAuthService = class {
4068
4035
  */
4069
4036
  async exchangeManually(params) {
4070
4037
  const { oAuthConfig, clientId, code, codeVerifier, redirectUri } = params;
4071
- logger6.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
4038
+ logger5.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
4072
4039
  const tokenResponse = await fetch(oAuthConfig.tokenUrl, {
4073
4040
  method: "POST",
4074
4041
  headers: {
@@ -4086,7 +4053,7 @@ var OAuthService = class {
4086
4053
  });
4087
4054
  if (!tokenResponse.ok) {
4088
4055
  const errorText = await tokenResponse.text();
4089
- logger6.error(
4056
+ logger5.error(
4090
4057
  {
4091
4058
  status: tokenResponse.status,
4092
4059
  statusText: tokenResponse.statusText,
@@ -4104,6 +4071,7 @@ var OAuthService = class {
4104
4071
  var oauthService = new OAuthService();
4105
4072
 
4106
4073
  // src/routes/tools.ts
4074
+ var logger6 = agentsCore.getLogger("tools");
4107
4075
  var app15 = new zodOpenapi.OpenAPIHono();
4108
4076
  app15.openapi(
4109
4077
  zodOpenapi.createRoute({
@@ -4226,7 +4194,7 @@ app15.openapi(
4226
4194
  async (c) => {
4227
4195
  const { tenantId, projectId } = c.req.valid("param");
4228
4196
  const body = c.req.valid("json");
4229
- getLogger().info({ body }, "body");
4197
+ logger6.info({ body }, "body");
4230
4198
  const id = body.id || nanoid.nanoid();
4231
4199
  const tool = await agentsCore.createTool(dbClient_default)({
4232
4200
  tenantId,
@@ -4647,7 +4615,6 @@ app15.openapi(
4647
4615
  }),
4648
4616
  async (c) => {
4649
4617
  const { tenantId, projectId, id } = c.req.valid("param");
4650
- const logger9 = getLogger("oauth-login");
4651
4618
  try {
4652
4619
  const tool = await agentsCore.getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
4653
4620
  if (!tool) {
@@ -4665,7 +4632,7 @@ app15.openapi(
4665
4632
  });
4666
4633
  return c.redirect(redirectUrl, 302);
4667
4634
  } catch (error) {
4668
- logger9.error({ toolId: id, error }, "OAuth login failed");
4635
+ logger6.error({ toolId: id, error }, "OAuth login failed");
4669
4636
  if (error && typeof error === "object" && "code" in error) {
4670
4637
  const apiError = error;
4671
4638
  return c.json({ error: apiError.message }, apiError.code === "not_found" ? 404 : 400);
@@ -4700,7 +4667,7 @@ app16.route("/projects/:projectId/api-keys", apiKeys_default);
4700
4667
  app16.route("/projects/:projectId/graph", graphFull_default);
4701
4668
  var routes_default = app16;
4702
4669
  var app17 = new zodOpenapi.OpenAPIHono();
4703
- var logger7 = getLogger("oauth-callback");
4670
+ var logger7 = agentsCore.getLogger("oauth-callback");
4704
4671
  var OAuthCallbackQuerySchema = zodOpenapi.z.object({
4705
4672
  code: zodOpenapi.z.string().min(1, "Authorization code is required"),
4706
4673
  state: zodOpenapi.z.string().min(1, "State parameter is required"),
@@ -4766,7 +4733,7 @@ app17.openapi(
4766
4733
  throw new Error(`Tool ${toolId} not found`);
4767
4734
  }
4768
4735
  logger7.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
4769
- logger7.info("Exchanging authorization code for access token");
4736
+ logger7.info({ toolId }, "Exchanging authorization code for access token");
4770
4737
  const mcpTool = agentsCore.dbResultToMcpTool(tool);
4771
4738
  const { tokens } = await oauthService.exchangeCodeForTokens({
4772
4739
  code,
@@ -4803,7 +4770,7 @@ app17.openapi(
4803
4770
  data: credentialData
4804
4771
  });
4805
4772
  } else {
4806
- logger7.info("Creating new credential");
4773
+ logger7.info({ credentialId }, "Creating new credential");
4807
4774
  credential = await agentsCore.createCredentialReference(dbClient_default)({
4808
4775
  tenantId,
4809
4776
  projectId,
@@ -4870,7 +4837,7 @@ app17.openapi(
4870
4837
  }
4871
4838
  );
4872
4839
  var oauth_default = app17;
4873
- var logger8 = getLogger("projectFull");
4840
+ var logger8 = agentsCore.getLogger("projectFull");
4874
4841
  var app18 = new zodOpenapi.OpenAPIHono();
4875
4842
  var ProjectIdParamsSchema = zod.z.object({
4876
4843
  tenantId: zod.z.string().openapi({
@@ -5135,6 +5102,8 @@ app18.openapi(
5135
5102
  var projectFull_default = app18;
5136
5103
 
5137
5104
  // src/app.ts
5105
+ var logger9 = agentsCore.getLogger("agents-manage-api");
5106
+ logger9.info({ logger: logger9.getTransports() }, "Logger initialized");
5138
5107
  function createManagementHono(serverConfig, credentialStores) {
5139
5108
  const app20 = new zodOpenapi.OpenAPIHono();
5140
5109
  app20.use("*", requestId.requestId());
@@ -5145,7 +5114,7 @@ function createManagementHono(serverConfig, credentialStores) {
5145
5114
  });
5146
5115
  app20.use(
5147
5116
  honoPino.pinoLogger({
5148
- pino: getLogger(),
5117
+ pino: agentsCore.getLogger("agents-manage-api").getPinoInstance(),
5149
5118
  http: {
5150
5119
  onResLevel(c) {
5151
5120
  if (c.res.status >= 500) {
@@ -5189,7 +5158,7 @@ function createManagementHono(serverConfig, credentialStores) {
5189
5158
  if (!isExpectedError) {
5190
5159
  const errorMessage = err instanceof Error ? err.message : String(err);
5191
5160
  const errorStack = err instanceof Error ? err.stack : void 0;
5192
- getLogger().error(
5161
+ logger9.error(
5193
5162
  {
5194
5163
  error: err,
5195
5164
  message: errorMessage,
@@ -5200,7 +5169,7 @@ function createManagementHono(serverConfig, credentialStores) {
5200
5169
  "Unexpected server error occurred"
5201
5170
  );
5202
5171
  } else {
5203
- getLogger().error(
5172
+ logger9.error(
5204
5173
  {
5205
5174
  error: err,
5206
5175
  path: c.req.path,
@@ -5216,7 +5185,7 @@ function createManagementHono(serverConfig, credentialStores) {
5216
5185
  const response = err.getResponse();
5217
5186
  return response;
5218
5187
  } catch (responseError) {
5219
- getLogger().error({ error: responseError }, "Error while handling HTTPException response");
5188
+ logger9.error({ error: responseError }, "Error while handling HTTPException response");
5220
5189
  }
5221
5190
  }
5222
5191
  const { status: respStatus, title, detail, instance } = await agentsCore.handleApiError(err, requestId2);
package/dist/index.js CHANGED
@@ -1,14 +1,12 @@
1
- import { loadEnvironmentFiles, getLogger as getLogger$1, createDatabaseClient, commonGetErrorResponses, TenantProjectGraphParamsSchema, ArtifactComponentApiSelectSchema, getArtifactComponentsForAgent, getAgentsUsingArtifactComponent, ErrorResponseSchema, SingleResponseSchema, AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, getAgentById, getArtifactComponentById, createApiError, isArtifactComponentAssociatedWithAgent, associateArtifactComponentWithAgent, RemovedResponseSchema, removeArtifactComponentFromAgent, ExistsResponseSchema, DataComponentApiSelectSchema, getDataComponentsForAgent, getAgentsUsingDataComponent, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, getDataComponent, isDataComponentAssociatedWithAgent, associateDataComponentWithAgent, removeDataComponentFromAgent, ListResponseSchema, PaginationQueryParamsSchema, TenantProjectParamsSchema, AgentGraphApiSelectSchema, listAgentGraphs, IdParamsSchema, getAgentGraphById, getGraphAgentInfos, FullGraphDefinitionSchema, getFullGraphDefinition, AgentGraphApiInsertSchema, createAgentGraph, AgentGraphApiUpdateSchema, updateAgentGraph, deleteAgentGraph, AgentRelationApiSelectSchema, AgentRelationQuerySchema, getAgentRelationsBySource, getAgentRelationsByTarget, getExternalAgentRelations, listAgentRelations, TenantProjectGraphIdParamsSchema, getAgentRelationById, AgentRelationApiInsertSchema, validateExternalAgent, validateInternalAgent, createAgentRelation, AgentRelationApiUpdateSchema, updateAgentRelation, deleteAgentRelation, AgentApiSelectSchema, listAgentsPaginated, AgentApiInsertSchema, createAgent, AgentApiUpdateSchema, updateAgent, deleteAgent, AgentToolRelationApiSelectSchema, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, getAgentToolRelationById, getToolsForAgent, getAgentsForTool, AgentToolRelationApiInsertSchema, createAgentToolRelation, AgentToolRelationApiUpdateSchema, updateAgentToolRelation, deleteAgentToolRelation, ApiKeyApiSelectSchema, listApiKeysPaginated, getApiKeyById, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, generateApiKey, createApiKey, ApiKeyApiUpdateSchema, updateApiKey, deleteApiKey, listArtifactComponentsPaginated, ArtifactComponentApiInsertSchema, createArtifactComponent, ArtifactComponentApiUpdateSchema, updateArtifactComponent, deleteArtifactComponent, ContextConfigApiSelectSchema, listContextConfigsPaginated, getContextConfigById, ContextConfigApiInsertSchema, createContextConfig, commonUpdateErrorResponses, ContextConfigApiUpdateSchema, updateContextConfig, commonDeleteErrorResponses, deleteContextConfig, CredentialReferenceApiSelectSchema, listCredentialReferencesPaginated, getCredentialReferenceById, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialStoreLookupKeyFromRetrievalParams, deleteCredentialReference, listDataComponentsPaginated, DataComponentApiInsertSchema, createDataComponent, DataComponentApiUpdateSchema, updateDataComponent, deleteDataComponent, ExternalAgentApiSelectSchema, listExternalAgentsPaginated, getExternalAgent, ExternalAgentApiInsertSchema, createExternalAgent, ExternalAgentApiUpdateSchema, updateExternalAgent, deleteExternalAgent, createFullGraphServerSide, getFullGraph, updateFullGraphServerSide, deleteFullGraph, TenantParamsSchema, ProjectApiSelectSchema, listProjectsPaginated, TenantIdParamsSchema, getProject, ProjectApiInsertSchema, createProject, ProjectApiUpdateSchema, updateProject, deleteProject, McpToolSchema, ToolStatusSchema, listToolsByStatus, dbResultToMcpTool, listTools, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, getCredentialReference, CredentialStoreType, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, createDefaultCredentialStores, CredentialStoreRegistry, ContextResolver, CredentialStuffer, McpClient, detectAuthenticationRequired, handleApiError, MCPServerType, MCPTransportType } from '@inkeep/agents-core';
1
+ import { loadEnvironmentFiles, getLogger, createDatabaseClient, commonGetErrorResponses, TenantProjectGraphParamsSchema, ArtifactComponentApiSelectSchema, getArtifactComponentsForAgent, getAgentsUsingArtifactComponent, ErrorResponseSchema, SingleResponseSchema, AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, getAgentById, getArtifactComponentById, createApiError, isArtifactComponentAssociatedWithAgent, associateArtifactComponentWithAgent, RemovedResponseSchema, removeArtifactComponentFromAgent, ExistsResponseSchema, DataComponentApiSelectSchema, getDataComponentsForAgent, getAgentsUsingDataComponent, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, getDataComponent, isDataComponentAssociatedWithAgent, associateDataComponentWithAgent, removeDataComponentFromAgent, ListResponseSchema, PaginationQueryParamsSchema, TenantProjectParamsSchema, AgentGraphApiSelectSchema, listAgentGraphs, IdParamsSchema, getAgentGraphById, getGraphAgentInfos, FullGraphDefinitionSchema, getFullGraphDefinition, AgentGraphApiInsertSchema, createAgentGraph, AgentGraphApiUpdateSchema, updateAgentGraph, deleteAgentGraph, AgentRelationApiSelectSchema, AgentRelationQuerySchema, getAgentRelationsBySource, getAgentRelationsByTarget, getExternalAgentRelations, listAgentRelations, TenantProjectGraphIdParamsSchema, getAgentRelationById, AgentRelationApiInsertSchema, validateExternalAgent, validateInternalAgent, createAgentRelation, AgentRelationApiUpdateSchema, updateAgentRelation, deleteAgentRelation, AgentApiSelectSchema, listAgentsPaginated, AgentApiInsertSchema, createAgent, AgentApiUpdateSchema, updateAgent, deleteAgent, AgentToolRelationApiSelectSchema, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, getAgentToolRelationById, getToolsForAgent, getAgentsForTool, AgentToolRelationApiInsertSchema, createAgentToolRelation, AgentToolRelationApiUpdateSchema, updateAgentToolRelation, deleteAgentToolRelation, ApiKeyApiSelectSchema, listApiKeysPaginated, getApiKeyById, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, generateApiKey, createApiKey, ApiKeyApiUpdateSchema, updateApiKey, deleteApiKey, listArtifactComponentsPaginated, ArtifactComponentApiInsertSchema, createArtifactComponent, ArtifactComponentApiUpdateSchema, updateArtifactComponent, deleteArtifactComponent, ContextConfigApiSelectSchema, listContextConfigsPaginated, getContextConfigById, ContextConfigApiInsertSchema, createContextConfig, commonUpdateErrorResponses, ContextConfigApiUpdateSchema, updateContextConfig, commonDeleteErrorResponses, deleteContextConfig, CredentialReferenceApiSelectSchema, listCredentialReferencesPaginated, getCredentialReferenceById, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialStoreLookupKeyFromRetrievalParams, deleteCredentialReference, listDataComponentsPaginated, DataComponentApiInsertSchema, createDataComponent, DataComponentApiUpdateSchema, updateDataComponent, deleteDataComponent, ExternalAgentApiSelectSchema, listExternalAgentsPaginated, getExternalAgent, ExternalAgentApiInsertSchema, createExternalAgent, ExternalAgentApiUpdateSchema, updateExternalAgent, deleteExternalAgent, createFullGraphServerSide, getFullGraph, updateFullGraphServerSide, deleteFullGraph, TenantParamsSchema, ProjectApiSelectSchema, listProjectsPaginated, TenantIdParamsSchema, getProject, ProjectApiInsertSchema, createProject, ProjectApiUpdateSchema, updateProject, deleteProject, McpToolSchema, ToolStatusSchema, listToolsByStatus, dbResultToMcpTool, listTools, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, getCredentialReference, CredentialStoreType, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, createDefaultCredentialStores, CredentialStoreRegistry, ContextResolver, CredentialStuffer, McpClient, detectAuthenticationRequired, handleApiError, MCPServerType, MCPTransportType } from '@inkeep/agents-core';
2
2
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
3
3
  import { Hono } from 'hono';
4
4
  import { cors } from 'hono/cors';
5
5
  import { HTTPException } from 'hono/http-exception';
6
6
  import { requestId } from 'hono/request-id';
7
7
  import { pinoLogger } from 'hono-pino';
8
- import { AsyncLocalStorage } from 'async_hooks';
9
- import { pino } from 'pino';
10
- import { z } from 'zod';
11
8
  import { createMiddleware } from 'hono/factory';
9
+ import { z } from 'zod';
12
10
  import { swaggerUI } from '@hono/swagger-ui';
13
11
  import { nanoid } from 'nanoid';
14
12
 
@@ -42,39 +40,8 @@ ${error.message}`
42
40
  };
43
41
  var env = parseEnv();
44
42
 
45
- // src/logger.ts
46
- var isDevelopment = env.ENVIRONMENT === "development";
47
- var loggerConfig = {
48
- level: env.LOG_LEVEL,
49
- serializers: {
50
- obj: (value) => ({ ...value })
51
- },
52
- redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
53
- // Only use pino-pretty in development
54
- ...isDevelopment && {
55
- transport: {
56
- target: "pino-pretty",
57
- options: {
58
- sync: true,
59
- destination: 1,
60
- // stdout
61
- colorize: true,
62
- translateTime: "SYS:standard"
63
- }
64
- }
65
- }
66
- };
67
- var logger = pino(loggerConfig);
68
- var asyncLocalStorage = new AsyncLocalStorage();
69
- function getLogger(name) {
70
- const store = asyncLocalStorage.getStore();
71
- const reqId = store?.get("requestId") || void 0;
72
- if (!reqId) {
73
- return logger.child({ name });
74
- }
75
- return logger.child({ reqId, name });
76
- }
77
- var logger2 = getLogger$1("env-key-auth");
43
+ // src/middleware/auth.ts
44
+ var logger = getLogger("env-key-auth");
78
45
  var apiKeyAuth = () => createMiddleware(async (c, next) => {
79
46
  if (env.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET) {
80
47
  const authHeader = c.req.header("Authorization");
@@ -85,7 +52,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
85
52
  }
86
53
  const apiKey = authHeader.substring(7);
87
54
  if (apiKey === env.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET) {
88
- logger2.info({}, "Bypass secret authenticated successfully");
55
+ logger.info({}, "Bypass secret authenticated successfully");
89
56
  await next();
90
57
  return;
91
58
  } else {
@@ -3054,7 +3021,7 @@ app12.openapi(
3054
3021
  }
3055
3022
  );
3056
3023
  var externalAgents_default = app12;
3057
- var logger3 = getLogger("graphFull");
3024
+ var logger2 = getLogger("graphFull");
3058
3025
  var app13 = new OpenAPIHono();
3059
3026
  var GraphIdParamsSchema = z.object({
3060
3027
  tenantId: z.string().openapi({
@@ -3112,7 +3079,7 @@ app13.openapi(
3112
3079
  const { tenantId, projectId } = c.req.valid("param");
3113
3080
  const graphData = c.req.valid("json");
3114
3081
  const validatedGraphData = FullGraphDefinitionSchema.parse(graphData);
3115
- const createdGraph = await createFullGraphServerSide(dbClient_default, logger3)(
3082
+ const createdGraph = await createFullGraphServerSide(dbClient_default, logger2)(
3116
3083
  { tenantId, projectId },
3117
3084
  validatedGraphData
3118
3085
  );
@@ -3147,7 +3114,7 @@ app13.openapi(
3147
3114
  try {
3148
3115
  const graph = await getFullGraph(
3149
3116
  dbClient_default,
3150
- logger3
3117
+ logger2
3151
3118
  )({
3152
3119
  scopes: { tenantId, projectId, graphId }
3153
3120
  });
@@ -3223,15 +3190,15 @@ app13.openapi(
3223
3190
  }
3224
3191
  const existingGraph = await getFullGraph(
3225
3192
  dbClient_default,
3226
- logger3
3193
+ logger2
3227
3194
  )({
3228
3195
  scopes: { tenantId, projectId, graphId }
3229
3196
  });
3230
3197
  const isCreate = !existingGraph;
3231
- const updatedGraph = isCreate ? await createFullGraphServerSide(dbClient_default, logger3)(
3198
+ const updatedGraph = isCreate ? await createFullGraphServerSide(dbClient_default, logger2)(
3232
3199
  { tenantId, projectId },
3233
3200
  validatedGraphData
3234
- ) : await updateFullGraphServerSide(dbClient_default, logger3)(
3201
+ ) : await updateFullGraphServerSide(dbClient_default, logger2)(
3235
3202
  { tenantId, projectId },
3236
3203
  validatedGraphData
3237
3204
  );
@@ -3279,7 +3246,7 @@ app13.openapi(
3279
3246
  try {
3280
3247
  const deleted = await deleteFullGraph(
3281
3248
  dbClient_default,
3282
- logger3
3249
+ logger2
3283
3250
  )({
3284
3251
  scopes: { tenantId, projectId, graphId }
3285
3252
  });
@@ -3546,7 +3513,7 @@ function extractInputSchema(toolDef) {
3546
3513
  }
3547
3514
  return {};
3548
3515
  }
3549
- var logger4 = getLogger("tools");
3516
+ var logger3 = getLogger("tools");
3550
3517
  var convertToMCPToolConfig = (tool) => {
3551
3518
  return {
3552
3519
  id: tool.id,
@@ -3655,7 +3622,7 @@ var checkToolHealth = async (tool, credentialStoreRegistry) => {
3655
3622
  }
3656
3623
  };
3657
3624
  } catch (error) {
3658
- logger4.error({ toolId: tool.id, error }, "Tool health check failed");
3625
+ logger3.error({ toolId: tool.id, error }, "Tool health check failed");
3659
3626
  if (error instanceof Error && await detectAuthenticationRequired(tool, error)) {
3660
3627
  return {
3661
3628
  status: "needs_auth",
@@ -3736,7 +3703,7 @@ var discoverToolsFromServer = async (tool, credentialStoreRegistry) => {
3736
3703
  );
3737
3704
  return toolDefinitions;
3738
3705
  } catch (error) {
3739
- logger4.error({ toolId: tool.id, error }, "Tool discovery failed");
3706
+ logger3.error({ toolId: tool.id, error }, "Tool discovery failed");
3740
3707
  throw error;
3741
3708
  }
3742
3709
  };
@@ -3800,7 +3767,7 @@ var checkAllToolsHealth = async (tenantId, projectId, credentialStoreRegistry) =
3800
3767
  };
3801
3768
 
3802
3769
  // src/utils/auth-detection.ts
3803
- var logger5 = getLogger("auth-detection");
3770
+ var logger4 = getLogger("auth-detection");
3804
3771
  var getWellKnownUrls = (baseUrl) => [
3805
3772
  `${baseUrl}/.well-known/oauth-authorization-server`,
3806
3773
  `${baseUrl}/.well-known/openid-configuration`
@@ -3822,12 +3789,12 @@ var tryWellKnownEndpoints = async (baseUrl) => {
3822
3789
  if (response.ok) {
3823
3790
  const metadata = await response.json();
3824
3791
  if (validateOAuthMetadata(metadata)) {
3825
- logger5.debug({ baseUrl, wellKnownUrl }, "OAuth 2.1/PKCE support detected");
3792
+ logger4.debug({ baseUrl, wellKnownUrl }, "OAuth 2.1/PKCE support detected");
3826
3793
  return buildOAuthConfig(metadata);
3827
3794
  }
3828
3795
  }
3829
3796
  } catch (error) {
3830
- logger5.debug({ wellKnownUrl, error }, "OAuth endpoint check failed");
3797
+ logger4.debug({ wellKnownUrl, error }, "OAuth endpoint check failed");
3831
3798
  }
3832
3799
  }
3833
3800
  return null;
@@ -3862,7 +3829,7 @@ var discoverOAuthEndpoints = async (serverUrl) => {
3862
3829
  };
3863
3830
 
3864
3831
  // src/utils/oauth-service.ts
3865
- var logger6 = getLogger("oauth-service");
3832
+ var logger5 = getLogger("oauth-service");
3866
3833
  var pkceStore = /* @__PURE__ */ new Map();
3867
3834
  function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId) {
3868
3835
  pkceStore.set(state, { codeVerifier, toolId, tenantId, projectId, clientId });
@@ -3920,7 +3887,7 @@ var OAuthService = class {
3920
3887
  resource: tool.config.mcp.server.url
3921
3888
  });
3922
3889
  storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId);
3923
- logger6.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
3890
+ logger5.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
3924
3891
  return {
3925
3892
  redirectUrl: authUrl,
3926
3893
  state
@@ -3945,9 +3912,9 @@ var OAuthService = class {
3945
3912
  codeVerifier,
3946
3913
  redirectUri
3947
3914
  });
3948
- logger6.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
3915
+ logger5.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
3949
3916
  } catch (error) {
3950
- logger6.warn(
3917
+ logger5.warn(
3951
3918
  { error: error instanceof Error ? error.message : error },
3952
3919
  "openid-client failed, falling back to manual token exchange"
3953
3920
  );
@@ -3958,7 +3925,7 @@ var OAuthService = class {
3958
3925
  codeVerifier,
3959
3926
  redirectUri
3960
3927
  });
3961
- logger6.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
3928
+ logger5.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
3962
3929
  }
3963
3930
  return { tokens, oAuthConfig };
3964
3931
  }
@@ -3966,7 +3933,7 @@ var OAuthService = class {
3966
3933
  * Perform dynamic client registration
3967
3934
  */
3968
3935
  async performDynamicClientRegistration(registrationUrl, redirectUri) {
3969
- logger6.info({ registrationUrl }, "Attempting dynamic client registration");
3936
+ logger5.info({ registrationUrl }, "Attempting dynamic client registration");
3970
3937
  try {
3971
3938
  const registrationResponse = await fetch(registrationUrl, {
3972
3939
  method: "POST",
@@ -3989,11 +3956,11 @@ var OAuthService = class {
3989
3956
  });
3990
3957
  if (registrationResponse.ok) {
3991
3958
  const registration = await registrationResponse.json();
3992
- logger6.info({ clientId: registration.client_id }, "Dynamic client registration successful");
3959
+ logger5.info({ clientId: registration.client_id }, "Dynamic client registration successful");
3993
3960
  return registration.client_id;
3994
3961
  } else {
3995
3962
  const errorText = await registrationResponse.text();
3996
- logger6.warn(
3963
+ logger5.warn(
3997
3964
  {
3998
3965
  status: registrationResponse.status,
3999
3966
  errorText
@@ -4002,7 +3969,7 @@ var OAuthService = class {
4002
3969
  );
4003
3970
  }
4004
3971
  } catch (regError) {
4005
- logger6.warn(
3972
+ logger5.warn(
4006
3973
  { error: regError },
4007
3974
  "Dynamic client registration error, using default client_id"
4008
3975
  );
@@ -4032,7 +3999,7 @@ var OAuthService = class {
4032
3999
  const oauth = await import('openid-client');
4033
4000
  const tokenUrl = new URL(oAuthConfig.tokenUrl);
4034
4001
  const oauthServerUrl = `${tokenUrl.protocol}//${tokenUrl.host}`;
4035
- logger6.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
4002
+ logger5.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
4036
4003
  const config = await oauth.discovery(
4037
4004
  new URL(oauthServerUrl),
4038
4005
  clientId,
@@ -4064,7 +4031,7 @@ var OAuthService = class {
4064
4031
  */
4065
4032
  async exchangeManually(params) {
4066
4033
  const { oAuthConfig, clientId, code, codeVerifier, redirectUri } = params;
4067
- logger6.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
4034
+ logger5.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
4068
4035
  const tokenResponse = await fetch(oAuthConfig.tokenUrl, {
4069
4036
  method: "POST",
4070
4037
  headers: {
@@ -4082,7 +4049,7 @@ var OAuthService = class {
4082
4049
  });
4083
4050
  if (!tokenResponse.ok) {
4084
4051
  const errorText = await tokenResponse.text();
4085
- logger6.error(
4052
+ logger5.error(
4086
4053
  {
4087
4054
  status: tokenResponse.status,
4088
4055
  statusText: tokenResponse.statusText,
@@ -4100,6 +4067,7 @@ var OAuthService = class {
4100
4067
  var oauthService = new OAuthService();
4101
4068
 
4102
4069
  // src/routes/tools.ts
4070
+ var logger6 = getLogger("tools");
4103
4071
  var app15 = new OpenAPIHono();
4104
4072
  app15.openapi(
4105
4073
  createRoute({
@@ -4222,7 +4190,7 @@ app15.openapi(
4222
4190
  async (c) => {
4223
4191
  const { tenantId, projectId } = c.req.valid("param");
4224
4192
  const body = c.req.valid("json");
4225
- getLogger().info({ body }, "body");
4193
+ logger6.info({ body }, "body");
4226
4194
  const id = body.id || nanoid();
4227
4195
  const tool = await createTool(dbClient_default)({
4228
4196
  tenantId,
@@ -4643,7 +4611,6 @@ app15.openapi(
4643
4611
  }),
4644
4612
  async (c) => {
4645
4613
  const { tenantId, projectId, id } = c.req.valid("param");
4646
- const logger9 = getLogger("oauth-login");
4647
4614
  try {
4648
4615
  const tool = await getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId: id });
4649
4616
  if (!tool) {
@@ -4661,7 +4628,7 @@ app15.openapi(
4661
4628
  });
4662
4629
  return c.redirect(redirectUrl, 302);
4663
4630
  } catch (error) {
4664
- logger9.error({ toolId: id, error }, "OAuth login failed");
4631
+ logger6.error({ toolId: id, error }, "OAuth login failed");
4665
4632
  if (error && typeof error === "object" && "code" in error) {
4666
4633
  const apiError = error;
4667
4634
  return c.json({ error: apiError.message }, apiError.code === "not_found" ? 404 : 400);
@@ -4762,7 +4729,7 @@ app17.openapi(
4762
4729
  throw new Error(`Tool ${toolId} not found`);
4763
4730
  }
4764
4731
  logger7.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
4765
- logger7.info("Exchanging authorization code for access token");
4732
+ logger7.info({ toolId }, "Exchanging authorization code for access token");
4766
4733
  const mcpTool = dbResultToMcpTool(tool);
4767
4734
  const { tokens } = await oauthService.exchangeCodeForTokens({
4768
4735
  code,
@@ -4799,7 +4766,7 @@ app17.openapi(
4799
4766
  data: credentialData
4800
4767
  });
4801
4768
  } else {
4802
- logger7.info("Creating new credential");
4769
+ logger7.info({ credentialId }, "Creating new credential");
4803
4770
  credential = await createCredentialReference(dbClient_default)({
4804
4771
  tenantId,
4805
4772
  projectId,
@@ -5131,6 +5098,8 @@ app18.openapi(
5131
5098
  var projectFull_default = app18;
5132
5099
 
5133
5100
  // src/app.ts
5101
+ var logger9 = getLogger("agents-manage-api");
5102
+ logger9.info({ logger: logger9.getTransports() }, "Logger initialized");
5134
5103
  function createManagementHono(serverConfig, credentialStores) {
5135
5104
  const app20 = new OpenAPIHono();
5136
5105
  app20.use("*", requestId());
@@ -5141,7 +5110,7 @@ function createManagementHono(serverConfig, credentialStores) {
5141
5110
  });
5142
5111
  app20.use(
5143
5112
  pinoLogger({
5144
- pino: getLogger(),
5113
+ pino: getLogger("agents-manage-api").getPinoInstance(),
5145
5114
  http: {
5146
5115
  onResLevel(c) {
5147
5116
  if (c.res.status >= 500) {
@@ -5185,7 +5154,7 @@ function createManagementHono(serverConfig, credentialStores) {
5185
5154
  if (!isExpectedError) {
5186
5155
  const errorMessage = err instanceof Error ? err.message : String(err);
5187
5156
  const errorStack = err instanceof Error ? err.stack : void 0;
5188
- getLogger().error(
5157
+ logger9.error(
5189
5158
  {
5190
5159
  error: err,
5191
5160
  message: errorMessage,
@@ -5196,7 +5165,7 @@ function createManagementHono(serverConfig, credentialStores) {
5196
5165
  "Unexpected server error occurred"
5197
5166
  );
5198
5167
  } else {
5199
- getLogger().error(
5168
+ logger9.error(
5200
5169
  {
5201
5170
  error: err,
5202
5171
  path: c.req.path,
@@ -5212,7 +5181,7 @@ function createManagementHono(serverConfig, credentialStores) {
5212
5181
  const response = err.getResponse();
5213
5182
  return response;
5214
5183
  } catch (responseError) {
5215
- getLogger().error({ error: responseError }, "Error while handling HTTPException response");
5184
+ logger9.error({ error: responseError }, "Error while handling HTTPException response");
5216
5185
  }
5217
5186
  }
5218
5187
  const { status: respStatus, title, detail, instance } = await handleApiError(err, requestId2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-manage-api",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Agents Manage API for Inkeep Agent Framework - handles CRUD operations and OAuth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "openid-client": "^6.6.4",
25
25
  "pino": "^9.7.0",
26
26
  "zod": "^4.1.5",
27
- "@inkeep/agents-core": "^0.3.0"
27
+ "@inkeep/agents-core": "^0.5.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@hono/vite-dev-server": "^0.20.1",