@inkeep/agents-manage-api 0.36.1 → 0.37.1

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.
@@ -1,5 +1,5 @@
1
1
  import { F, u, R, x, T, h, U, L, or, C, Vr, ce, ur, P } from './chunk-SBJLXGYG.js';
2
- import { loadEnvironmentFiles, getLogger, createDatabaseClient, commonGetErrorResponses, AgentListResponse, PaginationQueryParamsSchema, TenantProjectParamsSchema, listAgents, AgentResponse, TenantProjectIdParamsSchema, getAgentById, createApiError, RelatedAgentInfoListResponse, TenantProjectAgentSubAgentParamsSchema, getAgentSubAgentInfos, AgentWithinContextOfProjectResponse, TenantProjectAgentParamsSchema, getFullAgentDefinition, AgentApiInsertSchema, createAgent, generateId, AgentApiUpdateSchema, updateAgent, ErrorResponseSchema, deleteAgent, AgentWithinContextOfProjectSchema, createFullAgentServerSide, getFullAgent, updateFullAgentServerSide, deleteFullAgent, ApiKeyListResponse, listApiKeysPaginated, ApiKeyResponse, getApiKeyById, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, generateApiKey, createApiKey, ApiKeyApiUpdateSchema, updateApiKey, deleteApiKey, ArtifactComponentListResponse, listArtifactComponentsPaginated, ArtifactComponentResponse, getArtifactComponentById, ArtifactComponentApiInsertSchema, validatePropsAsJsonSchema, createArtifactComponent, ArtifactComponentApiUpdateSchema, updateArtifactComponent, deleteArtifactComponent, ContextConfigListResponse, listContextConfigsPaginated, ContextConfigResponse, TenantProjectAgentIdParamsSchema, getContextConfigById, ContextConfigApiInsertSchema, createContextConfig, commonUpdateErrorResponses, ContextConfigApiUpdateSchema, updateContextConfig, commonDeleteErrorResponses, deleteContextConfig, CredentialStoreListResponseSchema, CreateCredentialInStoreResponseSchema, CreateCredentialInStoreRequestSchema, CredentialReferenceListResponse, listCredentialReferencesPaginated, ListResponseSchema, CredentialReferenceApiSelectSchema, CredentialReferenceResponse, getCredentialReferenceWithResources, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialReferenceById, getCredentialStoreLookupKeyFromRetrievalParams, deleteCredentialReference, DataComponentListResponse, listDataComponentsPaginated, DataComponentResponse, getDataComponent, DataComponentApiInsertSchema, createDataComponent, DataComponentApiUpdateSchema, updateDataComponent, deleteDataComponent, ExternalAgentListResponse, listExternalAgentsPaginated, ExternalAgentResponse, getExternalAgent, ExternalAgentApiInsertSchema, createExternalAgent, ExternalAgentApiUpdateSchema, updateExternalAgent, deleteExternalAgent, FunctionListResponse, listFunctions, FunctionResponse, getFunction, FunctionApiInsertSchema, upsertFunction, FunctionApiUpdateSchema, deleteFunction, FunctionToolListResponse, listFunctionTools, FunctionToolResponse, getFunctionToolById, FunctionToolApiInsertSchema, createFunctionTool, FunctionToolApiUpdateSchema, updateFunctionTool, deleteFunctionTool, MCPCatalogListResponse, fetchComposioServers, MCPTransportType, ProjectListResponse, TenantParamsSchema, listProjectsPaginated, ProjectResponse, TenantIdParamsSchema, getProject, ProjectApiInsertSchema, createProject, ProjectApiUpdateSchema, updateProject, deleteProject, ArtifactComponentArrayResponse, getArtifactComponentsForAgent, ComponentAssociationListResponse, getAgentsUsingArtifactComponent, SubAgentArtifactComponentResponse, SubAgentArtifactComponentApiInsertSchema, getSubAgentById, isArtifactComponentAssociatedWithAgent, associateArtifactComponentWithAgent, RemovedResponseSchema, removeArtifactComponentFromAgent, ExistsResponseSchema, DataComponentArrayResponse, getDataComponentsForAgent, getAgentsUsingDataComponent, SubAgentDataComponentResponse, SubAgentDataComponentApiInsertSchema, isDataComponentAssociatedWithAgent, associateDataComponentWithAgent, removeDataComponentFromAgent, SubAgentExternalAgentRelationListResponse, listSubAgentExternalAgentRelations, SubAgentExternalAgentRelationResponse, TenantProjectAgentSubAgentIdParamsSchema, getSubAgentExternalAgentRelationById, SubAgentExternalAgentRelationApiInsertSchema, createSubAgentExternalAgentRelation, SubAgentExternalAgentRelationApiUpdateSchema, updateSubAgentExternalAgentRelation, deleteSubAgentExternalAgentRelation, SubAgentRelationListResponse, SubAgentRelationQuerySchema, getAgentRelationsBySource, getSubAgentRelationsByTarget, listAgentRelations, SubAgentRelationResponse, getAgentRelationById, SubAgentRelationApiInsertSchema, validateSubAgent, createSubAgentRelation, SubAgentRelationApiUpdateSchema, updateAgentRelation, deleteSubAgentRelation, SubAgentListResponse, listSubAgentsPaginated, SubAgentResponse, SubAgentApiInsertSchema, createSubAgent, SubAgentApiUpdateSchema, updateSubAgent, deleteSubAgent, SubAgentTeamAgentRelationListResponse, listSubAgentTeamAgentRelations, SubAgentTeamAgentRelationResponse, getSubAgentTeamAgentRelationById, SubAgentTeamAgentRelationApiInsertSchema, createSubAgentTeamAgentRelation, SubAgentTeamAgentRelationApiUpdateSchema, updateSubAgentTeamAgentRelation, deleteSubAgentTeamAgentRelation, SubAgentToolRelationListResponse, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, SubAgentToolRelationResponse, getAgentToolRelationById, getAgentsForTool, SubAgentToolRelationApiInsertSchema, createAgentToolRelation, SubAgentToolRelationApiUpdateSchema, updateAgentToolRelation, deleteAgentToolRelation, ThirdPartyMCPServerResponse, fetchSingleComposioServer, McpToolListResponse, ToolStatusSchema, listTools, dbResultToMcpTool, McpToolResponse, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, getPendingInvitationsByEmail, OAuthLoginQuerySchema, OAuthCallbackQuerySchema, CredentialStoreType, FullProjectDefinitionResponse, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, getUserOrganizations, addUserToOrganization, initiateMcpOAuthFlow, exchangeMcpAuthorizationCode, handleApiError, organization, getUserByEmail, member, createDefaultCredentialStores, CredentialStoreRegistry } from '@inkeep/agents-core';
2
+ import { loadEnvironmentFiles, getLogger, createDatabaseClient, commonGetErrorResponses, AgentListResponse, PaginationQueryParamsSchema, TenantProjectParamsSchema, listAgents, AgentResponse, TenantProjectIdParamsSchema, getAgentById, createApiError, RelatedAgentInfoListResponse, TenantProjectAgentSubAgentParamsSchema, getAgentSubAgentInfos, AgentWithinContextOfProjectResponse, TenantProjectAgentParamsSchema, getFullAgentDefinition, AgentApiInsertSchema, createAgent, generateId, AgentApiUpdateSchema, updateAgent, ErrorResponseSchema, deleteAgent, AgentWithinContextOfProjectSchema, createFullAgentServerSide, getFullAgent, updateFullAgentServerSide, deleteFullAgent, ApiKeyListResponse, listApiKeysPaginated, ApiKeyResponse, getApiKeyById, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, generateApiKey, createApiKey, ApiKeyApiUpdateSchema, updateApiKey, deleteApiKey, ArtifactComponentListResponse, listArtifactComponentsPaginated, ArtifactComponentResponse, getArtifactComponentById, ArtifactComponentApiInsertSchema, validatePropsAsJsonSchema, createArtifactComponent, ArtifactComponentApiUpdateSchema, updateArtifactComponent, deleteArtifactComponent, ContextConfigListResponse, listContextConfigsPaginated, ContextConfigResponse, TenantProjectAgentIdParamsSchema, getContextConfigById, ContextConfigApiInsertSchema, createContextConfig, commonUpdateErrorResponses, ContextConfigApiUpdateSchema, updateContextConfig, commonDeleteErrorResponses, deleteContextConfig, getConversationHistory, formatMessagesForLLMContext, CredentialStoreListResponseSchema, CreateCredentialInStoreResponseSchema, CreateCredentialInStoreRequestSchema, CredentialReferenceListResponse, listCredentialReferencesPaginated, ListResponseSchema, CredentialReferenceApiSelectSchema, CredentialReferenceResponse, getCredentialReferenceWithResources, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialReferenceById, getCredentialStoreLookupKeyFromRetrievalParams, deleteCredentialReference, DataComponentListResponse, listDataComponentsPaginated, DataComponentResponse, getDataComponent, DataComponentApiInsertSchema, createDataComponent, DataComponentApiUpdateSchema, updateDataComponent, deleteDataComponent, ExternalAgentListResponse, listExternalAgentsPaginated, ExternalAgentResponse, getExternalAgent, ExternalAgentApiInsertSchema, createExternalAgent, ExternalAgentApiUpdateSchema, updateExternalAgent, deleteExternalAgent, FunctionListResponse, listFunctions, FunctionResponse, getFunction, FunctionApiInsertSchema, upsertFunction, FunctionApiUpdateSchema, deleteFunction, FunctionToolListResponse, listFunctionTools, FunctionToolResponse, getFunctionToolById, FunctionToolApiInsertSchema, createFunctionTool, FunctionToolApiUpdateSchema, updateFunctionTool, deleteFunctionTool, MCPCatalogListResponse, fetchComposioServers, MCPTransportType, ProjectListResponse, TenantParamsSchema, listProjectsPaginated, ProjectResponse, TenantIdParamsSchema, getProject, ProjectApiInsertSchema, createProject, ProjectApiUpdateSchema, updateProject, deleteProject, ArtifactComponentArrayResponse, getArtifactComponentsForAgent, ComponentAssociationListResponse, getAgentsUsingArtifactComponent, SubAgentArtifactComponentResponse, SubAgentArtifactComponentApiInsertSchema, getSubAgentById, isArtifactComponentAssociatedWithAgent, associateArtifactComponentWithAgent, RemovedResponseSchema, removeArtifactComponentFromAgent, ExistsResponseSchema, DataComponentArrayResponse, getDataComponentsForAgent, getAgentsUsingDataComponent, SubAgentDataComponentResponse, SubAgentDataComponentApiInsertSchema, isDataComponentAssociatedWithAgent, associateDataComponentWithAgent, removeDataComponentFromAgent, SubAgentExternalAgentRelationListResponse, listSubAgentExternalAgentRelations, SubAgentExternalAgentRelationResponse, TenantProjectAgentSubAgentIdParamsSchema, getSubAgentExternalAgentRelationById, SubAgentExternalAgentRelationApiInsertSchema, createSubAgentExternalAgentRelation, SubAgentExternalAgentRelationApiUpdateSchema, updateSubAgentExternalAgentRelation, deleteSubAgentExternalAgentRelation, SubAgentRelationListResponse, SubAgentRelationQuerySchema, getAgentRelationsBySource, getSubAgentRelationsByTarget, listAgentRelations, SubAgentRelationResponse, getAgentRelationById, SubAgentRelationApiInsertSchema, validateSubAgent, createSubAgentRelation, SubAgentRelationApiUpdateSchema, updateAgentRelation, deleteSubAgentRelation, SubAgentListResponse, listSubAgentsPaginated, SubAgentResponse, SubAgentApiInsertSchema, createSubAgent, SubAgentApiUpdateSchema, updateSubAgent, deleteSubAgent, SubAgentIsDefaultError, SubAgentTeamAgentRelationListResponse, listSubAgentTeamAgentRelations, SubAgentTeamAgentRelationResponse, getSubAgentTeamAgentRelationById, SubAgentTeamAgentRelationApiInsertSchema, createSubAgentTeamAgentRelation, SubAgentTeamAgentRelationApiUpdateSchema, updateSubAgentTeamAgentRelation, deleteSubAgentTeamAgentRelation, SubAgentToolRelationListResponse, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, SubAgentToolRelationResponse, getAgentToolRelationById, getAgentsForTool, SubAgentToolRelationApiInsertSchema, createAgentToolRelation, SubAgentToolRelationApiUpdateSchema, updateAgentToolRelation, deleteAgentToolRelation, ThirdPartyMCPServerResponse, fetchSingleComposioServer, McpToolListResponse, ToolStatusSchema, listTools, dbResultToMcpTool, McpToolResponse, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, getPendingInvitationsByEmail, OAuthLoginQuerySchema, OAuthCallbackQuerySchema, CredentialStoreType, projectExists, signTempToken, FullProjectDefinitionResponse, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, getUserOrganizations, addUserToOrganization, initiateMcpOAuthFlow, exchangeMcpAuthorizationCode, handleApiError, organization, getUserByEmail, member, createDefaultCredentialStores, CredentialStoreRegistry } from '@inkeep/agents-core';
3
3
  import { createAuth } from '@inkeep/agents-core/auth';
4
4
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
5
5
  import { Hono } from 'hono';
@@ -13,6 +13,8 @@ import * as schema from '@inkeep/agents-core/db/schema';
13
13
  import { drizzle } from 'drizzle-orm/pglite';
14
14
  import { swaggerUI } from '@hono/swagger-ui';
15
15
  import { nanoid } from 'nanoid';
16
+ import { StreamableHTTPTransport } from '@hono/mcp';
17
+ import { createConsoleLogger, createMCPServer } from '@inkeep/agents-manage-mcp';
16
18
  import { UserOrganizationsResponseSchema, AddUserToOrganizationResponseSchema, AddUserToOrganizationRequestSchema } from '@inkeep/agents-core/auth/validation';
17
19
  import { eq, and } from 'drizzle-orm';
18
20
  import * as client from 'openid-client';
@@ -36,7 +38,8 @@ var envSchema = z.object({
36
38
  INKEEP_AGENTS_MANAGE_UI_PASSWORD: z.string().optional().refine((val) => !val || val.length >= 8, {
37
39
  message: "Password must be at least 8 characters"
38
40
  }),
39
- DISABLE_AUTH: z.string().optional().default("false").transform((val) => val === "true")
41
+ DISABLE_AUTH: z.string().optional().default("false").transform((val) => val === "true"),
42
+ INKEEP_AGENTS_TEMP_JWT_PRIVATE_KEY: z.string().optional()
40
43
  });
41
44
  var parseEnv = () => {
42
45
  try {
@@ -67,11 +70,10 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
67
70
  logger.info({}, "Bypass secret authenticated successfully");
68
71
  await next();
69
72
  return;
70
- } else {
71
- throw new HTTPException(401, {
72
- message: "Invalid Token"
73
- });
74
73
  }
74
+ throw new HTTPException(401, {
75
+ message: "Invalid Token"
76
+ });
75
77
  }
76
78
  await next();
77
79
  return;
@@ -80,8 +82,9 @@ var sessionAuth = () => createMiddleware(async (c, next) => {
80
82
  try {
81
83
  const user = c.get("user");
82
84
  if (!user) {
83
- throw new HTTPException(401, {
84
- message: "Unauthorized - Please log in"
85
+ throw createApiError({
86
+ code: "unauthorized",
87
+ message: "Please log in to access this resource"
85
88
  });
86
89
  }
87
90
  c.set("userId", user.id);
@@ -91,7 +94,8 @@ var sessionAuth = () => createMiddleware(async (c, next) => {
91
94
  if (error instanceof HTTPException) {
92
95
  throw error;
93
96
  }
94
- throw new HTTPException(401, {
97
+ throw createApiError({
98
+ code: "unauthorized",
95
99
  message: "Authentication failed"
96
100
  });
97
101
  }
@@ -5165,22 +5169,23 @@ var requireTenantAccess = () => createMiddleware(async (c, next) => {
5165
5169
  const userId = c.get("userId");
5166
5170
  const tenantId = c.req.param("tenantId");
5167
5171
  if (!userId) {
5168
- throw new HTTPException(401, {
5169
- message: "Unauthorized - User ID not found"
5172
+ throw createApiError({
5173
+ code: "unauthorized",
5174
+ message: "User ID not found"
5170
5175
  });
5171
5176
  }
5172
5177
  if (!tenantId) {
5173
- throw new HTTPException(400, {
5174
- message: "Bad Request - Organization ID is required"
5178
+ throw createApiError({
5179
+ code: "bad_request",
5180
+ message: "Organization ID is required"
5175
5181
  });
5176
5182
  }
5177
5183
  try {
5178
5184
  const userOrganizations = await getUserOrganizations(dbClient_default)(userId);
5179
- const organizationAccess = userOrganizations.find(
5180
- (org) => org.organizationId === tenantId
5181
- );
5185
+ const organizationAccess = userOrganizations.find((org) => org.organizationId === tenantId);
5182
5186
  if (!organizationAccess) {
5183
- throw new HTTPException(403, {
5187
+ throw createApiError({
5188
+ code: "forbidden",
5184
5189
  message: "Access denied to this organization"
5185
5190
  });
5186
5191
  }
@@ -5191,16 +5196,17 @@ var requireTenantAccess = () => createMiddleware(async (c, next) => {
5191
5196
  if (error instanceof HTTPException) {
5192
5197
  throw error;
5193
5198
  }
5194
- throw new HTTPException(500, {
5199
+ throw createApiError({
5200
+ code: "internal_server_error",
5195
5201
  message: "Failed to verify organization access"
5196
5202
  });
5197
5203
  }
5198
5204
  });
5199
- function setupOpenAPIRoutes(app26) {
5200
- app26.get("/openapi.json", (c) => {
5205
+ function setupOpenAPIRoutes(app29) {
5206
+ app29.get("/openapi.json", (c) => {
5201
5207
  try {
5202
5208
  const serverUrl = process.env.VERCEL_ENV === "production" && process.env.VERCEL_PROJECT_PRODUCTION_URL ? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}` : process.env.VERCEL_ENV === "preview" && process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : env.INKEEP_AGENTS_MANAGE_API_URL;
5203
- const document2 = app26.getOpenAPIDocument({
5209
+ const document2 = app29.getOpenAPIDocument({
5204
5210
  openapi: "3.0.0",
5205
5211
  info: {
5206
5212
  title: "Inkeep Agents Manage API",
@@ -5308,6 +5314,30 @@ function setupOpenAPIRoutes(app26) {
5308
5314
  }
5309
5315
  ]
5310
5316
  });
5317
+ document2.components = {
5318
+ ...document2.components,
5319
+ securitySchemes: {
5320
+ ...document2.components?.securitySchemes || {},
5321
+ cookieAuth: {
5322
+ type: "apiKey",
5323
+ in: "cookie",
5324
+ name: "better-auth.session_token",
5325
+ description: 'Session-based authentication using HTTP-only cookies. Cookies are automatically sent by browsers. For server-side requests, include cookies with names starting with "better-auth." in the Cookie header.'
5326
+ },
5327
+ bearerAuth: {
5328
+ type: "http",
5329
+ scheme: "bearer",
5330
+ bearerFormat: "Token",
5331
+ description: 'Bearer token authentication. Use this for API clients and service-to-service communication. Set the Authorization header to "Bearer <token>".'
5332
+ }
5333
+ }
5334
+ };
5335
+ document2.security = [
5336
+ {
5337
+ cookieAuth: [],
5338
+ bearerAuth: []
5339
+ }
5340
+ ];
5311
5341
  return c.json(document2);
5312
5342
  } catch (error) {
5313
5343
  console.error("OpenAPI document generation failed:", error);
@@ -5315,7 +5345,7 @@ function setupOpenAPIRoutes(app26) {
5315
5345
  return c.json({ error: "Failed to generate OpenAPI document", details: errorDetails }, 500);
5316
5346
  }
5317
5347
  });
5318
- app26.get(
5348
+ app29.get(
5319
5349
  "/docs",
5320
5350
  swaggerUI({
5321
5351
  url: "/openapi.json",
@@ -5564,15 +5594,26 @@ app.openapi(
5564
5594
  async (c) => {
5565
5595
  const { tenantId, projectId } = c.req.valid("param");
5566
5596
  const validatedBody = c.req.valid("json");
5567
- const agent = await createAgent(dbClient_default)({
5568
- tenantId,
5569
- projectId,
5570
- id: validatedBody.id || generateId(),
5571
- name: validatedBody.name,
5572
- defaultSubAgentId: validatedBody.defaultSubAgentId,
5573
- contextConfigId: validatedBody.contextConfigId ?? void 0
5574
- });
5575
- return c.json({ data: agent }, 201);
5597
+ try {
5598
+ const agent = await createAgent(dbClient_default)({
5599
+ tenantId,
5600
+ projectId,
5601
+ id: validatedBody.id || generateId(),
5602
+ name: validatedBody.name,
5603
+ defaultSubAgentId: validatedBody.defaultSubAgentId,
5604
+ contextConfigId: validatedBody.contextConfigId ?? void 0
5605
+ });
5606
+ return c.json({ data: agent }, 201);
5607
+ } catch (error) {
5608
+ if (error?.cause?.code === "23505") {
5609
+ const agentId = validatedBody.id || "unknown";
5610
+ throw createApiError({
5611
+ code: "conflict",
5612
+ message: `An agent with ID '${agentId}' already exists`
5613
+ });
5614
+ }
5615
+ throw error;
5616
+ }
5576
5617
  }
5577
5618
  );
5578
5619
  app.openapi(
@@ -6656,7 +6697,72 @@ app5.openapi(
6656
6697
  );
6657
6698
  var contextConfigs_default = app5;
6658
6699
  var app6 = new OpenAPIHono();
6700
+ var ConversationQueryParamsSchema = z.object({
6701
+ limit: z.coerce.number().min(1).max(200).default(20).optional(),
6702
+ includeInternal: z.coerce.boolean().default(false).optional()
6703
+ });
6704
+ var ConversationWithFormattedMessagesResponse = z.object({
6705
+ data: z.object({
6706
+ messages: z.array(z.any()),
6707
+ formatted: z.object({
6708
+ llmContext: z.string()
6709
+ })
6710
+ })
6711
+ }).openapi("ConversationWithFormattedMessagesResponse");
6659
6712
  app6.openapi(
6713
+ createRoute({
6714
+ method: "get",
6715
+ path: "/{id}",
6716
+ summary: "Get Conversation",
6717
+ operationId: "get-conversation",
6718
+ tags: ["Conversations"],
6719
+ request: {
6720
+ params: TenantProjectIdParamsSchema,
6721
+ query: ConversationQueryParamsSchema
6722
+ },
6723
+ responses: {
6724
+ 200: {
6725
+ description: "Conversation found with formatted messages for LLM use",
6726
+ content: {
6727
+ "application/json": {
6728
+ schema: ConversationWithFormattedMessagesResponse
6729
+ }
6730
+ }
6731
+ },
6732
+ ...commonGetErrorResponses
6733
+ }
6734
+ }),
6735
+ async (c) => {
6736
+ const { tenantId, projectId, id } = c.req.valid("param");
6737
+ const { limit = 20, includeInternal = true } = c.req.valid("query");
6738
+ const messages = await getConversationHistory(dbClient_default)({
6739
+ scopes: { tenantId, projectId },
6740
+ conversationId: id,
6741
+ options: {
6742
+ limit,
6743
+ includeInternal
6744
+ }
6745
+ });
6746
+ if (!messages || messages.length === 0) {
6747
+ throw createApiError({
6748
+ code: "not_found",
6749
+ message: "Conversation not found"
6750
+ });
6751
+ }
6752
+ const llmContext = formatMessagesForLLMContext(messages);
6753
+ return c.json({
6754
+ data: {
6755
+ messages,
6756
+ formatted: {
6757
+ llmContext
6758
+ }
6759
+ }
6760
+ });
6761
+ }
6762
+ );
6763
+ var conversations_default = app6;
6764
+ var app7 = new OpenAPIHono();
6765
+ app7.openapi(
6660
6766
  createRoute({
6661
6767
  method: "get",
6662
6768
  path: "/",
@@ -6697,7 +6803,7 @@ app6.openapi(
6697
6803
  });
6698
6804
  }
6699
6805
  );
6700
- app6.openapi(
6806
+ app7.openapi(
6701
6807
  createRoute({
6702
6808
  method: "post",
6703
6809
  path: "/{id}/credentials",
@@ -6765,33 +6871,30 @@ app6.openapi(
6765
6871
  }
6766
6872
  }
6767
6873
  );
6768
- var credentialStores_default = app6;
6769
- var app7 = new OpenAPIHono();
6770
- app7.use("/", async (c, next) => {
6874
+ var credentialStores_default = app7;
6875
+ var app8 = new OpenAPIHono();
6876
+ app8.use("/", async (c, next) => {
6771
6877
  if (c.req.method === "POST") {
6772
- return requirePermission({ credential: ["create"] })(
6773
- c,
6774
- next
6775
- );
6878
+ return requirePermission({
6879
+ credential: ["create"]
6880
+ })(c, next);
6776
6881
  }
6777
6882
  return next();
6778
6883
  });
6779
- app7.use("/:id", async (c, next) => {
6884
+ app8.use("/:id", async (c, next) => {
6780
6885
  if (c.req.method === "PATCH") {
6781
- return requirePermission({ credential: ["update"] })(
6782
- c,
6783
- next
6784
- );
6886
+ return requirePermission({
6887
+ credential: ["update"]
6888
+ })(c, next);
6785
6889
  }
6786
6890
  if (c.req.method === "DELETE") {
6787
- return requirePermission({ credential: ["delete"] })(
6788
- c,
6789
- next
6790
- );
6891
+ return requirePermission({
6892
+ credential: ["delete"]
6893
+ })(c, next);
6791
6894
  }
6792
6895
  return next();
6793
6896
  });
6794
- app7.openapi(
6897
+ app8.openapi(
6795
6898
  createRoute({
6796
6899
  method: "get",
6797
6900
  path: "/",
@@ -6826,7 +6929,7 @@ app7.openapi(
6826
6929
  return c.json(validatedResult);
6827
6930
  }
6828
6931
  );
6829
- app7.openapi(
6932
+ app8.openapi(
6830
6933
  createRoute({
6831
6934
  method: "get",
6832
6935
  path: "/{id}",
@@ -6864,7 +6967,7 @@ app7.openapi(
6864
6967
  return c.json({ data: validatedCredential });
6865
6968
  }
6866
6969
  );
6867
- app7.openapi(
6970
+ app8.openapi(
6868
6971
  createRoute({
6869
6972
  method: "post",
6870
6973
  path: "/",
@@ -6906,7 +7009,7 @@ app7.openapi(
6906
7009
  return c.json({ data: validatedCredential }, 201);
6907
7010
  }
6908
7011
  );
6909
- app7.openapi(
7012
+ app8.openapi(
6910
7013
  createRoute({
6911
7014
  method: "put",
6912
7015
  path: "/{id}",
@@ -6953,7 +7056,7 @@ app7.openapi(
6953
7056
  return c.json({ data: validatedCredential });
6954
7057
  }
6955
7058
  );
6956
- app7.openapi(
7059
+ app8.openapi(
6957
7060
  createRoute({
6958
7061
  method: "delete",
6959
7062
  path: "/{id}",
@@ -7024,15 +7127,15 @@ app7.openapi(
7024
7127
  return c.body(null, 204);
7025
7128
  }
7026
7129
  );
7027
- var credentials_default = app7;
7028
- var app8 = new OpenAPIHono();
7029
- app8.use("/", async (c, next) => {
7130
+ var credentials_default = app8;
7131
+ var app9 = new OpenAPIHono();
7132
+ app9.use("/", async (c, next) => {
7030
7133
  if (c.req.method === "POST") {
7031
7134
  return requirePermission({ data_component: ["create"] })(c, next);
7032
7135
  }
7033
7136
  return next();
7034
7137
  });
7035
- app8.use("/:id", async (c, next) => {
7138
+ app9.use("/:id", async (c, next) => {
7036
7139
  if (c.req.method === "PATCH") {
7037
7140
  return requirePermission({ data_component: ["update"] })(c, next);
7038
7141
  }
@@ -7041,7 +7144,7 @@ app8.use("/:id", async (c, next) => {
7041
7144
  }
7042
7145
  return next();
7043
7146
  });
7044
- app8.openapi(
7147
+ app9.openapi(
7045
7148
  createRoute({
7046
7149
  method: "get",
7047
7150
  path: "/",
@@ -7075,7 +7178,7 @@ app8.openapi(
7075
7178
  return c.json(result);
7076
7179
  }
7077
7180
  );
7078
- app8.openapi(
7181
+ app9.openapi(
7079
7182
  createRoute({
7080
7183
  method: "get",
7081
7184
  path: "/{id}",
@@ -7112,7 +7215,7 @@ app8.openapi(
7112
7215
  return c.json({ data: dataComponent });
7113
7216
  }
7114
7217
  );
7115
- app8.openapi(
7218
+ app9.openapi(
7116
7219
  createRoute({
7117
7220
  method: "post",
7118
7221
  path: "/",
@@ -7163,7 +7266,7 @@ app8.openapi(
7163
7266
  return c.json({ data: dataComponent }, 201);
7164
7267
  }
7165
7268
  );
7166
- app8.openapi(
7269
+ app9.openapi(
7167
7270
  createRoute({
7168
7271
  method: "put",
7169
7272
  path: "/{id}",
@@ -7219,7 +7322,7 @@ app8.openapi(
7219
7322
  return c.json({ data: updatedDataComponent });
7220
7323
  }
7221
7324
  );
7222
- app8.openapi(
7325
+ app9.openapi(
7223
7326
  createRoute({
7224
7327
  method: "delete",
7225
7328
  path: "/{id}",
@@ -7258,15 +7361,15 @@ app8.openapi(
7258
7361
  return c.body(null, 204);
7259
7362
  }
7260
7363
  );
7261
- var dataComponents_default = app8;
7262
- var app9 = new OpenAPIHono();
7263
- app9.use("/", async (c, next) => {
7364
+ var dataComponents_default = app9;
7365
+ var app10 = new OpenAPIHono();
7366
+ app10.use("/", async (c, next) => {
7264
7367
  if (c.req.method === "POST") {
7265
7368
  return requirePermission({ external_agent: ["create"] })(c, next);
7266
7369
  }
7267
7370
  return next();
7268
7371
  });
7269
- app9.use("/:id", async (c, next) => {
7372
+ app10.use("/:id", async (c, next) => {
7270
7373
  if (c.req.method === "PATCH") {
7271
7374
  return requirePermission({ external_agent: ["update"] })(c, next);
7272
7375
  }
@@ -7275,7 +7378,7 @@ app9.use("/:id", async (c, next) => {
7275
7378
  }
7276
7379
  return next();
7277
7380
  });
7278
- app9.openapi(
7381
+ app10.openapi(
7279
7382
  createRoute({
7280
7383
  method: "get",
7281
7384
  path: "/",
@@ -7315,7 +7418,7 @@ app9.openapi(
7315
7418
  return c.json(dataWithType);
7316
7419
  }
7317
7420
  );
7318
- app9.openapi(
7421
+ app10.openapi(
7319
7422
  createRoute({
7320
7423
  method: "get",
7321
7424
  path: "/{id}",
@@ -7356,7 +7459,7 @@ app9.openapi(
7356
7459
  return c.json({ data: agentWithType });
7357
7460
  }
7358
7461
  );
7359
- app9.openapi(
7462
+ app10.openapi(
7360
7463
  createRoute({
7361
7464
  method: "post",
7362
7465
  path: "/",
@@ -7405,7 +7508,7 @@ app9.openapi(
7405
7508
  return c.json({ data: agentWithType }, 201);
7406
7509
  }
7407
7510
  );
7408
- app9.openapi(
7511
+ app10.openapi(
7409
7512
  createRoute({
7410
7513
  method: "put",
7411
7514
  path: "/{id}",
@@ -7455,7 +7558,7 @@ app9.openapi(
7455
7558
  return c.json({ data: agentWithType });
7456
7559
  }
7457
7560
  );
7458
- app9.openapi(
7561
+ app10.openapi(
7459
7562
  createRoute({
7460
7563
  method: "delete",
7461
7564
  path: "/{id}",
@@ -7494,16 +7597,16 @@ app9.openapi(
7494
7597
  return c.body(null, 204);
7495
7598
  }
7496
7599
  );
7497
- var externalAgents_default = app9;
7600
+ var externalAgents_default = app10;
7498
7601
  var logger3 = getLogger("functions");
7499
- var app10 = new OpenAPIHono();
7500
- app10.use("/", async (c, next) => {
7602
+ var app11 = new OpenAPIHono();
7603
+ app11.use("/", async (c, next) => {
7501
7604
  if (c.req.method === "POST") {
7502
7605
  return requirePermission({ function: ["create"] })(c, next);
7503
7606
  }
7504
7607
  return next();
7505
7608
  });
7506
- app10.use("/:id", async (c, next) => {
7609
+ app11.use("/:id", async (c, next) => {
7507
7610
  if (c.req.method === "PUT") {
7508
7611
  return requirePermission({ function: ["update"] })(c, next);
7509
7612
  }
@@ -7512,7 +7615,7 @@ app10.use("/:id", async (c, next) => {
7512
7615
  }
7513
7616
  return next();
7514
7617
  });
7515
- app10.openapi(
7618
+ app11.openapi(
7516
7619
  createRoute({
7517
7620
  method: "get",
7518
7621
  path: "/",
@@ -7557,7 +7660,7 @@ app10.openapi(
7557
7660
  }
7558
7661
  }
7559
7662
  );
7560
- app10.openapi(
7663
+ app11.openapi(
7561
7664
  createRoute({
7562
7665
  method: "get",
7563
7666
  path: "/{id}",
@@ -7602,7 +7705,7 @@ app10.openapi(
7602
7705
  }
7603
7706
  }
7604
7707
  );
7605
- app10.openapi(
7708
+ app11.openapi(
7606
7709
  createRoute({
7607
7710
  method: "post",
7608
7711
  path: "/",
@@ -7658,7 +7761,7 @@ app10.openapi(
7658
7761
  }
7659
7762
  }
7660
7763
  );
7661
- app10.openapi(
7764
+ app11.openapi(
7662
7765
  createRoute({
7663
7766
  method: "put",
7664
7767
  path: "/{id}",
@@ -7724,7 +7827,7 @@ app10.openapi(
7724
7827
  }
7725
7828
  }
7726
7829
  );
7727
- app10.openapi(
7830
+ app11.openapi(
7728
7831
  createRoute({
7729
7832
  method: "delete",
7730
7833
  path: "/{id}",
@@ -7769,16 +7872,16 @@ app10.openapi(
7769
7872
  }
7770
7873
  }
7771
7874
  );
7772
- var functions_default = app10;
7875
+ var functions_default = app11;
7773
7876
  var logger4 = getLogger("functionTools");
7774
- var app11 = new OpenAPIHono();
7775
- app11.use("/", async (c, next) => {
7877
+ var app12 = new OpenAPIHono();
7878
+ app12.use("/", async (c, next) => {
7776
7879
  if (c.req.method === "POST") {
7777
7880
  return requirePermission({ function: ["create"] })(c, next);
7778
7881
  }
7779
7882
  return next();
7780
7883
  });
7781
- app11.use("/:id", async (c, next) => {
7884
+ app12.use("/:id", async (c, next) => {
7782
7885
  if (c.req.method === "PUT") {
7783
7886
  return requirePermission({ function: ["update"] })(c, next);
7784
7887
  }
@@ -7787,7 +7890,7 @@ app11.use("/:id", async (c, next) => {
7787
7890
  }
7788
7891
  return next();
7789
7892
  });
7790
- app11.openapi(
7893
+ app12.openapi(
7791
7894
  createRoute({
7792
7895
  method: "get",
7793
7896
  path: "/",
@@ -7828,7 +7931,7 @@ app11.openapi(
7828
7931
  }
7829
7932
  }
7830
7933
  );
7831
- app11.openapi(
7934
+ app12.openapi(
7832
7935
  createRoute({
7833
7936
  method: "get",
7834
7937
  path: "/{id}",
@@ -7873,7 +7976,7 @@ app11.openapi(
7873
7976
  }
7874
7977
  }
7875
7978
  );
7876
- app11.openapi(
7979
+ app12.openapi(
7877
7980
  createRoute({
7878
7981
  method: "post",
7879
7982
  path: "/",
@@ -7927,7 +8030,7 @@ app11.openapi(
7927
8030
  }
7928
8031
  }
7929
8032
  );
7930
- app11.openapi(
8033
+ app12.openapi(
7931
8034
  createRoute({
7932
8035
  method: "put",
7933
8036
  path: "/{id}",
@@ -7987,7 +8090,7 @@ app11.openapi(
7987
8090
  }
7988
8091
  }
7989
8092
  );
7990
- app11.openapi(
8093
+ app12.openapi(
7991
8094
  createRoute({
7992
8095
  method: "delete",
7993
8096
  path: "/{id}",
@@ -8030,8 +8133,8 @@ app11.openapi(
8030
8133
  }
8031
8134
  }
8032
8135
  );
8033
- var functionTools_default = app11;
8034
- var app12 = new OpenAPIHono();
8136
+ var functionTools_default = app12;
8137
+ var app13 = new OpenAPIHono();
8035
8138
  var PREBUILT_MCP_SERVERS = [
8036
8139
  {
8037
8140
  id: "apify",
@@ -8453,7 +8556,7 @@ var PREBUILT_MCP_SERVERS = [
8453
8556
  description: "AI-powered content creation"
8454
8557
  }
8455
8558
  ];
8456
- app12.openapi(
8559
+ app13.openapi(
8457
8560
  createRoute({
8458
8561
  method: "get",
8459
8562
  path: "/",
@@ -8488,15 +8591,15 @@ app12.openapi(
8488
8591
  });
8489
8592
  }
8490
8593
  );
8491
- var mcpCatalog_default = app12;
8492
- var app13 = new OpenAPIHono();
8493
- app13.use("/", async (c, next) => {
8594
+ var mcpCatalog_default = app13;
8595
+ var app14 = new OpenAPIHono();
8596
+ app14.use("/", async (c, next) => {
8494
8597
  if (c.req.method === "POST") {
8495
8598
  return requirePermission({ project: ["create"] })(c, next);
8496
8599
  }
8497
8600
  return next();
8498
8601
  });
8499
- app13.use("/:id", async (c, next) => {
8602
+ app14.use("/:id", async (c, next) => {
8500
8603
  if (c.req.method === "PATCH") {
8501
8604
  return requirePermission({ project: ["update"] })(c, next);
8502
8605
  }
@@ -8505,7 +8608,7 @@ app13.use("/:id", async (c, next) => {
8505
8608
  }
8506
8609
  return next();
8507
8610
  });
8508
- app13.openapi(
8611
+ app14.openapi(
8509
8612
  createRoute({
8510
8613
  method: "get",
8511
8614
  path: "/",
@@ -8540,7 +8643,7 @@ app13.openapi(
8540
8643
  return c.json(result);
8541
8644
  }
8542
8645
  );
8543
- app13.openapi(
8646
+ app14.openapi(
8544
8647
  createRoute({
8545
8648
  method: "get",
8546
8649
  path: "/{id}",
@@ -8575,7 +8678,7 @@ app13.openapi(
8575
8678
  return c.json({ data: project });
8576
8679
  }
8577
8680
  );
8578
- app13.openapi(
8681
+ app14.openapi(
8579
8682
  createRoute({
8580
8683
  method: "post",
8581
8684
  path: "/",
@@ -8633,7 +8736,7 @@ app13.openapi(
8633
8736
  }
8634
8737
  }
8635
8738
  );
8636
- app13.openapi(
8739
+ app14.openapi(
8637
8740
  createRoute({
8638
8741
  method: "patch",
8639
8742
  path: "/{id}",
@@ -8679,7 +8782,7 @@ app13.openapi(
8679
8782
  return c.json({ data: project });
8680
8783
  }
8681
8784
  );
8682
- app13.openapi(
8785
+ app14.openapi(
8683
8786
  createRoute({
8684
8787
  method: "delete",
8685
8788
  path: "/{id}",
@@ -8729,21 +8832,21 @@ app13.openapi(
8729
8832
  }
8730
8833
  }
8731
8834
  );
8732
- var projects_default = app13;
8733
- var app14 = new OpenAPIHono();
8734
- app14.use("/", async (c, next) => {
8835
+ var projects_default = app14;
8836
+ var app15 = new OpenAPIHono();
8837
+ app15.use("/", async (c, next) => {
8735
8838
  if (c.req.method === "POST") {
8736
8839
  return requirePermission({ sub_agent: ["create"] })(c, next);
8737
8840
  }
8738
8841
  return next();
8739
8842
  });
8740
- app14.use("/agent/:subAgentId/component/:artifactComponentId", async (c, next) => {
8843
+ app15.use("/agent/:subAgentId/component/:artifactComponentId", async (c, next) => {
8741
8844
  if (c.req.method === "DELETE") {
8742
8845
  return requirePermission({ sub_agent: ["delete"] })(c, next);
8743
8846
  }
8744
8847
  return next();
8745
8848
  });
8746
- app14.openapi(
8849
+ app15.openapi(
8747
8850
  createRoute({
8748
8851
  method: "get",
8749
8852
  path: "/agent/{subAgentId}",
@@ -8775,7 +8878,7 @@ app14.openapi(
8775
8878
  });
8776
8879
  }
8777
8880
  );
8778
- app14.openapi(
8881
+ app15.openapi(
8779
8882
  createRoute({
8780
8883
  method: "get",
8781
8884
  path: "/component/{artifactComponentId}/agents",
@@ -8808,7 +8911,7 @@ app14.openapi(
8808
8911
  return c.json({ data: agents });
8809
8912
  }
8810
8913
  );
8811
- app14.openapi(
8914
+ app15.openapi(
8812
8915
  createRoute({
8813
8916
  method: "post",
8814
8917
  path: "/",
@@ -8885,7 +8988,7 @@ app14.openapi(
8885
8988
  return c.json({ data: association }, 201);
8886
8989
  }
8887
8990
  );
8888
- app14.openapi(
8991
+ app15.openapi(
8889
8992
  createRoute({
8890
8993
  method: "delete",
8891
8994
  path: "/agent/{subAgentId}/component/{artifactComponentId}",
@@ -8927,7 +9030,7 @@ app14.openapi(
8927
9030
  });
8928
9031
  }
8929
9032
  );
8930
- app14.openapi(
9033
+ app15.openapi(
8931
9034
  createRoute({
8932
9035
  method: "get",
8933
9036
  path: "/agent/{subAgentId}/component/{artifactComponentId}/exists",
@@ -8960,21 +9063,21 @@ app14.openapi(
8960
9063
  return c.json({ exists });
8961
9064
  }
8962
9065
  );
8963
- var subAgentArtifactComponents_default = app14;
8964
- var app15 = new OpenAPIHono();
8965
- app15.use("/", async (c, next) => {
9066
+ var subAgentArtifactComponents_default = app15;
9067
+ var app16 = new OpenAPIHono();
9068
+ app16.use("/", async (c, next) => {
8966
9069
  if (c.req.method === "POST") {
8967
9070
  return requirePermission({ sub_agent: ["create"] })(c, next);
8968
9071
  }
8969
9072
  return next();
8970
9073
  });
8971
- app15.use("/agent/:subAgentId/component/:dataComponentId", async (c, next) => {
9074
+ app16.use("/agent/:subAgentId/component/:dataComponentId", async (c, next) => {
8972
9075
  if (c.req.method === "DELETE") {
8973
9076
  return requirePermission({ sub_agent: ["delete"] })(c, next);
8974
9077
  }
8975
9078
  return next();
8976
9079
  });
8977
- app15.openapi(
9080
+ app16.openapi(
8978
9081
  createRoute({
8979
9082
  method: "get",
8980
9083
  path: "/agent/{subAgentId}",
@@ -9004,7 +9107,7 @@ app15.openapi(
9004
9107
  return c.json({ data: dataComponents });
9005
9108
  }
9006
9109
  );
9007
- app15.openapi(
9110
+ app16.openapi(
9008
9111
  createRoute({
9009
9112
  method: "get",
9010
9113
  path: "/component/{dataComponentId}/agents",
@@ -9037,7 +9140,7 @@ app15.openapi(
9037
9140
  return c.json({ data: agents });
9038
9141
  }
9039
9142
  );
9040
- app15.openapi(
9143
+ app16.openapi(
9041
9144
  createRoute({
9042
9145
  method: "post",
9043
9146
  path: "/",
@@ -9110,7 +9213,7 @@ app15.openapi(
9110
9213
  return c.json({ data: association }, 201);
9111
9214
  }
9112
9215
  );
9113
- app15.openapi(
9216
+ app16.openapi(
9114
9217
  createRoute({
9115
9218
  method: "delete",
9116
9219
  path: "/agent/{subAgentId}/component/{dataComponentId}",
@@ -9152,7 +9255,7 @@ app15.openapi(
9152
9255
  });
9153
9256
  }
9154
9257
  );
9155
- app15.openapi(
9258
+ app16.openapi(
9156
9259
  createRoute({
9157
9260
  method: "get",
9158
9261
  path: "/agent/{subAgentId}/component/{dataComponentId}/exists",
@@ -9185,15 +9288,15 @@ app15.openapi(
9185
9288
  return c.json({ exists });
9186
9289
  }
9187
9290
  );
9188
- var subAgentDataComponents_default = app15;
9189
- var app16 = new OpenAPIHono();
9190
- app16.use("/", async (c, next) => {
9291
+ var subAgentDataComponents_default = app16;
9292
+ var app17 = new OpenAPIHono();
9293
+ app17.use("/", async (c, next) => {
9191
9294
  if (c.req.method === "POST") {
9192
9295
  return requirePermission({ sub_agent: ["create"] })(c, next);
9193
9296
  }
9194
9297
  return next();
9195
9298
  });
9196
- app16.use("/:id", async (c, next) => {
9299
+ app17.use("/:id", async (c, next) => {
9197
9300
  if (c.req.method === "PUT") {
9198
9301
  return requirePermission({ sub_agent: ["update"] })(c, next);
9199
9302
  }
@@ -9202,7 +9305,7 @@ app16.use("/:id", async (c, next) => {
9202
9305
  }
9203
9306
  return next();
9204
9307
  });
9205
- app16.openapi(
9308
+ app17.openapi(
9206
9309
  createRoute({
9207
9310
  method: "get",
9208
9311
  path: "/",
@@ -9244,7 +9347,7 @@ app16.openapi(
9244
9347
  }
9245
9348
  }
9246
9349
  );
9247
- app16.openapi(
9350
+ app17.openapi(
9248
9351
  createRoute({
9249
9352
  method: "get",
9250
9353
  path: "/{id}",
@@ -9281,7 +9384,7 @@ app16.openapi(
9281
9384
  return c.json({ data: relation });
9282
9385
  }
9283
9386
  );
9284
- app16.openapi(
9387
+ app17.openapi(
9285
9388
  createRoute({
9286
9389
  method: "post",
9287
9390
  path: "/",
@@ -9337,7 +9440,7 @@ app16.openapi(
9337
9440
  return c.json({ data: relation }, 201);
9338
9441
  }
9339
9442
  );
9340
- app16.openapi(
9443
+ app17.openapi(
9341
9444
  createRoute({
9342
9445
  method: "put",
9343
9446
  path: "/{id}",
@@ -9383,7 +9486,7 @@ app16.openapi(
9383
9486
  return c.json({ data: updatedRelation });
9384
9487
  }
9385
9488
  );
9386
- app16.openapi(
9489
+ app17.openapi(
9387
9490
  createRoute({
9388
9491
  method: "delete",
9389
9492
  path: "/{id}",
@@ -9422,15 +9525,15 @@ app16.openapi(
9422
9525
  return c.body(null, 204);
9423
9526
  }
9424
9527
  );
9425
- var subAgentExternalAgentRelations_default = app16;
9426
- var app17 = new OpenAPIHono();
9427
- app17.use("/", async (c, next) => {
9528
+ var subAgentExternalAgentRelations_default = app17;
9529
+ var app18 = new OpenAPIHono();
9530
+ app18.use("/", async (c, next) => {
9428
9531
  if (c.req.method === "POST") {
9429
9532
  return requirePermission({ sub_agent: ["create"] })(c, next);
9430
9533
  }
9431
9534
  return next();
9432
9535
  });
9433
- app17.use("/:id", async (c, next) => {
9536
+ app18.use("/:id", async (c, next) => {
9434
9537
  if (c.req.method === "PUT") {
9435
9538
  return requirePermission({ sub_agent: ["update"] })(c, next);
9436
9539
  }
@@ -9439,7 +9542,7 @@ app17.use("/:id", async (c, next) => {
9439
9542
  }
9440
9543
  return next();
9441
9544
  });
9442
- app17.openapi(
9545
+ app18.openapi(
9443
9546
  createRoute({
9444
9547
  method: "get",
9445
9548
  path: "/",
@@ -9499,7 +9602,7 @@ app17.openapi(
9499
9602
  }
9500
9603
  }
9501
9604
  );
9502
- app17.openapi(
9605
+ app18.openapi(
9503
9606
  createRoute({
9504
9607
  method: "get",
9505
9608
  path: "/{id}",
@@ -9536,7 +9639,7 @@ app17.openapi(
9536
9639
  return c.json({ data: agentRelation });
9537
9640
  }
9538
9641
  );
9539
- app17.openapi(
9642
+ app18.openapi(
9540
9643
  createRoute({
9541
9644
  method: "post",
9542
9645
  path: "/",
@@ -9610,7 +9713,7 @@ app17.openapi(
9610
9713
  return c.json({ data: agentRelation }, 201);
9611
9714
  }
9612
9715
  );
9613
- app17.openapi(
9716
+ app18.openapi(
9614
9717
  createRoute({
9615
9718
  method: "put",
9616
9719
  path: "/{id}",
@@ -9656,7 +9759,7 @@ app17.openapi(
9656
9759
  return c.json({ data: updatedAgentRelation });
9657
9760
  }
9658
9761
  );
9659
- app17.openapi(
9762
+ app18.openapi(
9660
9763
  createRoute({
9661
9764
  method: "delete",
9662
9765
  path: "/{id}",
@@ -9695,15 +9798,15 @@ app17.openapi(
9695
9798
  return c.body(null, 204);
9696
9799
  }
9697
9800
  );
9698
- var subAgentRelations_default = app17;
9699
- var app18 = new OpenAPIHono();
9700
- app18.use("/", async (c, next) => {
9801
+ var subAgentRelations_default = app18;
9802
+ var app19 = new OpenAPIHono();
9803
+ app19.use("/", async (c, next) => {
9701
9804
  if (c.req.method === "POST") {
9702
9805
  return requirePermission({ sub_agent: ["create"] })(c, next);
9703
9806
  }
9704
9807
  return next();
9705
9808
  });
9706
- app18.use("/:id", async (c, next) => {
9809
+ app19.use("/:id", async (c, next) => {
9707
9810
  if (c.req.method === "PUT") {
9708
9811
  return requirePermission({ sub_agent: ["update"] })(c, next);
9709
9812
  }
@@ -9712,7 +9815,7 @@ app18.use("/:id", async (c, next) => {
9712
9815
  }
9713
9816
  return next();
9714
9817
  });
9715
- app18.openapi(
9818
+ app19.openapi(
9716
9819
  createRoute({
9717
9820
  method: "get",
9718
9821
  path: "/",
@@ -9753,7 +9856,7 @@ app18.openapi(
9753
9856
  return c.json(dataWithType);
9754
9857
  }
9755
9858
  );
9756
- app18.openapi(
9859
+ app19.openapi(
9757
9860
  createRoute({
9758
9861
  method: "get",
9759
9862
  path: "/{id}",
@@ -9794,7 +9897,7 @@ app18.openapi(
9794
9897
  return c.json({ data: subAgentWithType });
9795
9898
  }
9796
9899
  );
9797
- app18.openapi(
9900
+ app19.openapi(
9798
9901
  createRoute({
9799
9902
  method: "post",
9800
9903
  path: "/",
@@ -9841,7 +9944,7 @@ app18.openapi(
9841
9944
  return c.json({ data: subAgentWithType }, 201);
9842
9945
  }
9843
9946
  );
9844
- app18.openapi(
9947
+ app19.openapi(
9845
9948
  createRoute({
9846
9949
  method: "put",
9847
9950
  path: "/{id}",
@@ -9891,7 +9994,7 @@ app18.openapi(
9891
9994
  return c.json({ data: subAgentWithType });
9892
9995
  }
9893
9996
  );
9894
- app18.openapi(
9997
+ app19.openapi(
9895
9998
  createRoute({
9896
9999
  method: "delete",
9897
10000
  path: "/{id}",
@@ -9912,33 +10015,51 @@ app18.openapi(
9912
10015
  schema: ErrorResponseSchema
9913
10016
  }
9914
10017
  }
10018
+ },
10019
+ 409: {
10020
+ description: "SubAgent is set as default and cannot be deleted",
10021
+ content: {
10022
+ "application/json": {
10023
+ schema: ErrorResponseSchema
10024
+ }
10025
+ }
9915
10026
  }
9916
10027
  }
9917
10028
  }),
9918
10029
  async (c) => {
9919
10030
  const { tenantId, projectId, agentId, id } = c.req.valid("param");
9920
- const deleted = await deleteSubAgent(dbClient_default)({
9921
- scopes: { tenantId, projectId, agentId },
9922
- subAgentId: id
9923
- });
9924
- if (!deleted) {
9925
- throw createApiError({
9926
- code: "not_found",
9927
- message: "SubAgent not found"
10031
+ try {
10032
+ const deleted = await deleteSubAgent(dbClient_default)({
10033
+ scopes: { tenantId, projectId, agentId },
10034
+ subAgentId: id
9928
10035
  });
10036
+ if (!deleted) {
10037
+ throw createApiError({
10038
+ code: "not_found",
10039
+ message: "SubAgent not found"
10040
+ });
10041
+ }
10042
+ return c.body(null, 204);
10043
+ } catch (error) {
10044
+ if (error instanceof SubAgentIsDefaultError) {
10045
+ throw createApiError({
10046
+ code: "conflict",
10047
+ message: error.message
10048
+ });
10049
+ }
10050
+ throw error;
9929
10051
  }
9930
- return c.body(null, 204);
9931
10052
  }
9932
10053
  );
9933
- var subAgents_default = app18;
9934
- var app19 = new OpenAPIHono();
9935
- app19.use("/", async (c, next) => {
10054
+ var subAgents_default = app19;
10055
+ var app20 = new OpenAPIHono();
10056
+ app20.use("/", async (c, next) => {
9936
10057
  if (c.req.method === "POST") {
9937
10058
  return requirePermission({ sub_agent: ["create"] })(c, next);
9938
10059
  }
9939
10060
  return next();
9940
10061
  });
9941
- app19.use("/:id", async (c, next) => {
10062
+ app20.use("/:id", async (c, next) => {
9942
10063
  if (c.req.method === "PUT") {
9943
10064
  return requirePermission({ sub_agent: ["update"] })(c, next);
9944
10065
  }
@@ -9947,7 +10068,7 @@ app19.use("/:id", async (c, next) => {
9947
10068
  }
9948
10069
  return next();
9949
10070
  });
9950
- app19.openapi(
10071
+ app20.openapi(
9951
10072
  createRoute({
9952
10073
  method: "get",
9953
10074
  path: "/",
@@ -9989,7 +10110,7 @@ app19.openapi(
9989
10110
  }
9990
10111
  }
9991
10112
  );
9992
- app19.openapi(
10113
+ app20.openapi(
9993
10114
  createRoute({
9994
10115
  method: "get",
9995
10116
  path: "/{id}",
@@ -10026,7 +10147,7 @@ app19.openapi(
10026
10147
  return c.json({ data: relation });
10027
10148
  }
10028
10149
  );
10029
- app19.openapi(
10150
+ app20.openapi(
10030
10151
  createRoute({
10031
10152
  method: "post",
10032
10153
  path: "/",
@@ -10082,7 +10203,7 @@ app19.openapi(
10082
10203
  return c.json({ data: relation }, 201);
10083
10204
  }
10084
10205
  );
10085
- app19.openapi(
10206
+ app20.openapi(
10086
10207
  createRoute({
10087
10208
  method: "put",
10088
10209
  path: "/{id}",
@@ -10128,7 +10249,7 @@ app19.openapi(
10128
10249
  return c.json({ data: updatedRelation });
10129
10250
  }
10130
10251
  );
10131
- app19.openapi(
10252
+ app20.openapi(
10132
10253
  createRoute({
10133
10254
  method: "delete",
10134
10255
  path: "/{id}",
@@ -10167,15 +10288,15 @@ app19.openapi(
10167
10288
  return c.body(null, 204);
10168
10289
  }
10169
10290
  );
10170
- var subAgentTeamAgentRelations_default = app19;
10171
- var app20 = new OpenAPIHono();
10172
- app20.use("/", async (c, next) => {
10291
+ var subAgentTeamAgentRelations_default = app20;
10292
+ var app21 = new OpenAPIHono();
10293
+ app21.use("/", async (c, next) => {
10173
10294
  if (c.req.method === "POST") {
10174
10295
  return requirePermission({ sub_agent: ["create"] })(c, next);
10175
10296
  }
10176
10297
  return next();
10177
10298
  });
10178
- app20.use("/:id", async (c, next) => {
10299
+ app21.use("/:id", async (c, next) => {
10179
10300
  if (c.req.method === "PUT") {
10180
10301
  return requirePermission({ sub_agent: ["update"] })(c, next);
10181
10302
  }
@@ -10184,7 +10305,7 @@ app20.use("/:id", async (c, next) => {
10184
10305
  }
10185
10306
  return next();
10186
10307
  });
10187
- app20.openapi(
10308
+ app21.openapi(
10188
10309
  createRoute({
10189
10310
  method: "get",
10190
10311
  path: "/",
@@ -10246,7 +10367,7 @@ app20.openapi(
10246
10367
  return c.json(result);
10247
10368
  }
10248
10369
  );
10249
- app20.openapi(
10370
+ app21.openapi(
10250
10371
  createRoute({
10251
10372
  method: "get",
10252
10373
  path: "/{id}",
@@ -10283,7 +10404,7 @@ app20.openapi(
10283
10404
  return c.json({ data: agentToolRelation });
10284
10405
  }
10285
10406
  );
10286
- app20.openapi(
10407
+ app21.openapi(
10287
10408
  createRoute({
10288
10409
  method: "get",
10289
10410
  path: "/tool/{toolId}/sub-agents",
@@ -10319,7 +10440,7 @@ app20.openapi(
10319
10440
  return c.json(dbResult);
10320
10441
  }
10321
10442
  );
10322
- app20.openapi(
10443
+ app21.openapi(
10323
10444
  createRoute({
10324
10445
  method: "post",
10325
10446
  path: "/",
@@ -10382,7 +10503,7 @@ app20.openapi(
10382
10503
  }
10383
10504
  }
10384
10505
  );
10385
- app20.openapi(
10506
+ app21.openapi(
10386
10507
  createRoute({
10387
10508
  method: "put",
10388
10509
  path: "/{id}",
@@ -10434,7 +10555,7 @@ app20.openapi(
10434
10555
  return c.json({ data: updatedAgentToolRelation });
10435
10556
  }
10436
10557
  );
10437
- app20.openapi(
10558
+ app21.openapi(
10438
10559
  createRoute({
10439
10560
  method: "delete",
10440
10561
  path: "/{id}",
@@ -10473,12 +10594,12 @@ app20.openapi(
10473
10594
  return c.body(null, 204);
10474
10595
  }
10475
10596
  );
10476
- var subAgentToolRelations_default = app20;
10477
- var app21 = new OpenAPIHono();
10597
+ var subAgentToolRelations_default = app21;
10598
+ var app22 = new OpenAPIHono();
10478
10599
  var ThirdPartyMCPServerBodySchema = z.object({
10479
10600
  url: z.url().describe("The MCP server URL to fetch details for")
10480
10601
  });
10481
- app21.openapi(
10602
+ app22.openapi(
10482
10603
  createRoute({
10483
10604
  method: "post",
10484
10605
  path: "/",
@@ -10517,10 +10638,10 @@ app21.openapi(
10517
10638
  });
10518
10639
  }
10519
10640
  );
10520
- var thirdPartyMCPServers_default = app21;
10641
+ var thirdPartyMCPServers_default = app22;
10521
10642
  var logger5 = getLogger("tools");
10522
- var app22 = new OpenAPIHono();
10523
- app22.use("/", async (c, next) => {
10643
+ var app23 = new OpenAPIHono();
10644
+ app23.use("/", async (c, next) => {
10524
10645
  if (c.req.method === "POST") {
10525
10646
  return requirePermission({ tool: ["create"] })(
10526
10647
  c,
@@ -10529,7 +10650,7 @@ app22.use("/", async (c, next) => {
10529
10650
  }
10530
10651
  return next();
10531
10652
  });
10532
- app22.use("/:id", async (c, next) => {
10653
+ app23.use("/:id", async (c, next) => {
10533
10654
  if (c.req.method === "PUT") {
10534
10655
  return requirePermission({ tool: ["update"] })(
10535
10656
  c,
@@ -10544,7 +10665,7 @@ app22.use("/:id", async (c, next) => {
10544
10665
  }
10545
10666
  return next();
10546
10667
  });
10547
- app22.openapi(
10668
+ app23.openapi(
10548
10669
  createRoute({
10549
10670
  method: "get",
10550
10671
  path: "/",
@@ -10604,7 +10725,7 @@ app22.openapi(
10604
10725
  return c.json(result);
10605
10726
  }
10606
10727
  );
10607
- app22.openapi(
10728
+ app23.openapi(
10608
10729
  createRoute({
10609
10730
  method: "get",
10610
10731
  path: "/{id}",
@@ -10641,7 +10762,7 @@ app22.openapi(
10641
10762
  });
10642
10763
  }
10643
10764
  );
10644
- app22.openapi(
10765
+ app23.openapi(
10645
10766
  createRoute({
10646
10767
  method: "post",
10647
10768
  path: "/",
@@ -10694,7 +10815,7 @@ app22.openapi(
10694
10815
  );
10695
10816
  }
10696
10817
  );
10697
- app22.openapi(
10818
+ app23.openapi(
10698
10819
  createRoute({
10699
10820
  method: "put",
10700
10821
  path: "/{id}",
@@ -10755,7 +10876,7 @@ app22.openapi(
10755
10876
  });
10756
10877
  }
10757
10878
  );
10758
- app22.openapi(
10879
+ app23.openapi(
10759
10880
  createRoute({
10760
10881
  method: "delete",
10761
10882
  path: "/{id}",
@@ -10784,48 +10905,49 @@ app22.openapi(
10784
10905
  return c.body(null, 204);
10785
10906
  }
10786
10907
  );
10787
- var tools_default = app22;
10908
+ var tools_default = app23;
10788
10909
 
10789
10910
  // src/routes/index.ts
10790
- var app23 = new OpenAPIHono();
10791
- app23.route("/projects", projects_default);
10792
- app23.route("/projects/:projectId/agents/:agentId/sub-agents", subAgents_default);
10793
- app23.route("/projects/:projectId/agents/:agentId/sub-agent-relations", subAgentRelations_default);
10794
- app23.route(
10911
+ var app24 = new OpenAPIHono();
10912
+ app24.route("/projects", projects_default);
10913
+ app24.route("/projects/:projectId/agents/:agentId/sub-agents", subAgents_default);
10914
+ app24.route("/projects/:projectId/agents/:agentId/sub-agent-relations", subAgentRelations_default);
10915
+ app24.route(
10795
10916
  "/projects/:projectId/agents/:agentId/sub-agents/:subAgentId/external-agent-relations",
10796
10917
  subAgentExternalAgentRelations_default
10797
10918
  );
10798
- app23.route(
10919
+ app24.route(
10799
10920
  "/projects/:projectId/agents/:agentId/sub-agents/:subAgentId/team-agent-relations",
10800
10921
  subAgentTeamAgentRelations_default
10801
10922
  );
10802
- app23.route("/projects/:projectId/agents", agent_default);
10803
- app23.route(
10923
+ app24.route("/projects/:projectId/agents", agent_default);
10924
+ app24.route(
10804
10925
  "/projects/:projectId/agents/:agentId/sub-agent-tool-relations",
10805
10926
  subAgentToolRelations_default
10806
10927
  );
10807
- app23.route(
10928
+ app24.route(
10808
10929
  "/projects/:projectId/agents/:agentId/sub-agent-artifact-components",
10809
10930
  subAgentArtifactComponents_default
10810
10931
  );
10811
- app23.route(
10932
+ app24.route(
10812
10933
  "/projects/:projectId/agents/:agentId/sub-agent-data-components",
10813
10934
  subAgentDataComponents_default
10814
10935
  );
10815
- app23.route("/projects/:projectId/artifact-components", artifactComponents_default);
10816
- app23.route("/projects/:projectId/agents/:agentId/context-configs", contextConfigs_default);
10817
- app23.route("/projects/:projectId/credentials", credentials_default);
10818
- app23.route("/projects/:projectId/credential-stores", credentialStores_default);
10819
- app23.route("/projects/:projectId/data-components", dataComponents_default);
10820
- app23.route("/projects/:projectId/external-agents", externalAgents_default);
10821
- app23.route("/projects/:projectId/agents/:agentId/function-tools", functionTools_default);
10822
- app23.route("/projects/:projectId/functions", functions_default);
10823
- app23.route("/projects/:projectId/tools", tools_default);
10824
- app23.route("/projects/:projectId/api-keys", apiKeys_default);
10825
- app23.route("/projects/:projectId/agent", agentFull_default);
10826
- app23.route("/projects/:projectId/mcp-catalog", mcpCatalog_default);
10827
- app23.route("/projects/:projectId/third-party-mcp-servers", thirdPartyMCPServers_default);
10828
- var routes_default = app23;
10936
+ app24.route("/projects/:projectId/artifact-components", artifactComponents_default);
10937
+ app24.route("/projects/:projectId/agents/:agentId/context-configs", contextConfigs_default);
10938
+ app24.route("/projects/:projectId/conversations", conversations_default);
10939
+ app24.route("/projects/:projectId/credentials", credentials_default);
10940
+ app24.route("/projects/:projectId/credential-stores", credentialStores_default);
10941
+ app24.route("/projects/:projectId/data-components", dataComponents_default);
10942
+ app24.route("/projects/:projectId/external-agents", externalAgents_default);
10943
+ app24.route("/projects/:projectId/agents/:agentId/function-tools", functionTools_default);
10944
+ app24.route("/projects/:projectId/functions", functions_default);
10945
+ app24.route("/projects/:projectId/tools", tools_default);
10946
+ app24.route("/projects/:projectId/api-keys", apiKeys_default);
10947
+ app24.route("/projects/:projectId/agent", agentFull_default);
10948
+ app24.route("/projects/:projectId/mcp-catalog", mcpCatalog_default);
10949
+ app24.route("/projects/:projectId/third-party-mcp-servers", thirdPartyMCPServers_default);
10950
+ var routes_default = app24;
10829
10951
  var invitationsRoutes = new OpenAPIHono();
10830
10952
  var PendingInvitationSchema = z$1.object({
10831
10953
  id: z$1.string(),
@@ -10873,6 +10995,17 @@ invitationsRoutes.openapi(
10873
10995
  }
10874
10996
  );
10875
10997
  var invitations_default = invitationsRoutes;
10998
+ var app25 = new Hono();
10999
+ app25.all("/", async (c) => {
11000
+ const transport = new StreamableHTTPTransport();
11001
+ const noOpLogger = createConsoleLogger("error");
11002
+ const mcpServer = createMCPServer({
11003
+ logger: noOpLogger
11004
+ });
11005
+ await mcpServer.connect(transport);
11006
+ return transport.handleRequest(c);
11007
+ });
11008
+ var mcp_default = app25;
10876
11009
  var logger6 = getLogger("oauth-service");
10877
11010
  var pkceStore = /* @__PURE__ */ new Map();
10878
11011
  function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientInformation, metadata2, resourceUrl) {
@@ -11010,7 +11143,7 @@ async function findOrCreateCredential(tenantId, projectId, credentialData) {
11010
11143
  throw new Error(`Failed to save credential '${credentialData.id}' to database`);
11011
11144
  }
11012
11145
  }
11013
- var app24 = new OpenAPIHono();
11146
+ var app26 = new OpenAPIHono();
11014
11147
  var logger7 = getLogger("oauth-callback");
11015
11148
  function getBaseUrlFromRequest(c) {
11016
11149
  const url = new URL(c.req.url);
@@ -11086,7 +11219,7 @@ function generateOAuthCallbackPage(params) {
11086
11219
  </html>
11087
11220
  `;
11088
11221
  }
11089
- app24.openapi(
11222
+ app26.openapi(
11090
11223
  createRoute({
11091
11224
  method: "get",
11092
11225
  path: "/login",
@@ -11151,7 +11284,7 @@ app24.openapi(
11151
11284
  }
11152
11285
  }
11153
11286
  );
11154
- app24.openapi(
11287
+ app26.openapi(
11155
11288
  createRoute({
11156
11289
  method: "get",
11157
11290
  path: "/callback",
@@ -11294,16 +11427,119 @@ app24.openapi(
11294
11427
  }
11295
11428
  }
11296
11429
  );
11297
- var oauth_default = app24;
11298
- var logger8 = getLogger("projectFull");
11299
- var app25 = new OpenAPIHono();
11300
- app25.use("/project-full", async (c, next) => {
11430
+ var oauth_default = app26;
11431
+ var logger8 = getLogger("playgroundToken");
11432
+ var app27 = new OpenAPIHono();
11433
+ app27.use("/", requirePermission({ agent: ["create"] }));
11434
+ var PlaygroundTokenRequestSchema = z$1.object({
11435
+ projectId: z$1.string(),
11436
+ agentId: z$1.string()
11437
+ });
11438
+ var PlaygroundTokenResponseSchema = z$1.object({
11439
+ apiKey: z$1.string().describe("Temporary API key for playground use"),
11440
+ expiresAt: z$1.string().describe("ISO 8601 timestamp when the key expires")
11441
+ });
11442
+ app27.openapi(
11443
+ createRoute({
11444
+ method: "post",
11445
+ path: "/",
11446
+ summary: "Generate temporary API key for playground",
11447
+ operationId: "create-playground-token",
11448
+ tags: ["Playground"],
11449
+ description: "Generates a short-lived API key (1 hour expiry) for authenticated users to access the run-api from the playground",
11450
+ security: [{ cookieAuth: [] }],
11451
+ request: {
11452
+ body: {
11453
+ content: {
11454
+ "application/json": {
11455
+ schema: PlaygroundTokenRequestSchema
11456
+ }
11457
+ }
11458
+ }
11459
+ },
11460
+ responses: {
11461
+ 200: {
11462
+ description: "Temporary API key generated successfully",
11463
+ content: {
11464
+ "application/json": {
11465
+ schema: PlaygroundTokenResponseSchema
11466
+ }
11467
+ }
11468
+ },
11469
+ 401: {
11470
+ description: "Unauthorized - session required",
11471
+ content: {
11472
+ "application/json": {
11473
+ schema: ErrorResponseSchema
11474
+ }
11475
+ }
11476
+ }
11477
+ }
11478
+ }),
11479
+ async (c) => {
11480
+ const userId = c.get("userId");
11481
+ const tenantId = c.get("tenantId");
11482
+ const { projectId, agentId } = c.req.valid("json");
11483
+ logger8.info(
11484
+ { userId, tenantId, projectId, agentId },
11485
+ "Generating temporary JWT token for playground"
11486
+ );
11487
+ const projectExistsCheck = await projectExists(dbClient_default)({ tenantId, projectId });
11488
+ if (!projectExistsCheck) {
11489
+ logger8.warn({ userId, tenantId, projectId }, "Project not found or access denied");
11490
+ throw createApiError({
11491
+ code: "not_found",
11492
+ message: "Project not found"
11493
+ });
11494
+ }
11495
+ const agent = await getAgentById(dbClient_default)({ scopes: { tenantId, projectId, agentId } });
11496
+ if (!agent) {
11497
+ logger8.warn({ userId, tenantId, projectId, agentId }, "Agent not found or access denied");
11498
+ throw createApiError({
11499
+ code: "not_found",
11500
+ message: "Agent not found"
11501
+ });
11502
+ }
11503
+ if (!env.INKEEP_AGENTS_TEMP_JWT_PRIVATE_KEY) {
11504
+ throw createApiError({
11505
+ code: "internal_server_error",
11506
+ message: "Temporary token signing not configured"
11507
+ });
11508
+ }
11509
+ const privateKeyPem = Buffer.from(env.INKEEP_AGENTS_TEMP_JWT_PRIVATE_KEY, "base64").toString(
11510
+ "utf-8"
11511
+ );
11512
+ const result = await signTempToken(
11513
+ privateKeyPem,
11514
+ {
11515
+ tenantId,
11516
+ projectId,
11517
+ agentId,
11518
+ type: "temporary",
11519
+ initiatedBy: { type: "user", id: userId }
11520
+ },
11521
+ userId
11522
+ );
11523
+ logger8.info({ userId, expiresAt: result.expiresAt }, "Temporary JWT token generated");
11524
+ return c.json(
11525
+ {
11526
+ apiKey: result.token,
11527
+ expiresAt: result.expiresAt
11528
+ },
11529
+ 200
11530
+ );
11531
+ }
11532
+ );
11533
+ var playgroundToken_default = app27;
11534
+ var logger9 = getLogger("projectFull");
11535
+ var app28 = new OpenAPIHono();
11536
+ app28.use("/project-full", async (c, next) => {
11301
11537
  if (c.req.method === "POST") {
11302
11538
  return requirePermission({ project: ["create"] })(c, next);
11303
11539
  }
11304
11540
  return next();
11305
11541
  });
11306
- app25.use("/project-full/:projectId", async (c, next) => {
11542
+ app28.use("/project-full/:projectId", async (c, next) => {
11307
11543
  if (c.req.method === "PUT") {
11308
11544
  return requirePermission({ project: ["update"] })(c, next);
11309
11545
  }
@@ -11312,7 +11548,7 @@ app25.use("/project-full/:projectId", async (c, next) => {
11312
11548
  }
11313
11549
  return next();
11314
11550
  });
11315
- app25.openapi(
11551
+ app28.openapi(
11316
11552
  createRoute({
11317
11553
  method: "post",
11318
11554
  path: "/project-full",
@@ -11355,13 +11591,13 @@ app25.openapi(
11355
11591
  const projectData = c.req.valid("json");
11356
11592
  const validatedProjectData = FullProjectDefinitionSchema.parse(projectData);
11357
11593
  try {
11358
- const createdProject = await createFullProjectServerSide(dbClient_default, logger8)(
11594
+ const createdProject = await createFullProjectServerSide(dbClient_default, logger9)(
11359
11595
  { tenantId, projectId: validatedProjectData.id },
11360
11596
  validatedProjectData
11361
11597
  );
11362
11598
  return c.json({ data: createdProject }, 201);
11363
11599
  } catch (error) {
11364
- logger8.error({ error }, "Error creating project");
11600
+ logger9.error({ error }, "Error creating project");
11365
11601
  if (error?.cause?.code === "23505") {
11366
11602
  throw createApiError({
11367
11603
  code: "conflict",
@@ -11372,7 +11608,7 @@ app25.openapi(
11372
11608
  }
11373
11609
  }
11374
11610
  );
11375
- app25.openapi(
11611
+ app28.openapi(
11376
11612
  createRoute({
11377
11613
  method: "get",
11378
11614
  path: "/project-full/{projectId}",
@@ -11400,7 +11636,7 @@ app25.openapi(
11400
11636
  try {
11401
11637
  const project = await getFullProject(
11402
11638
  dbClient_default,
11403
- logger8
11639
+ logger9
11404
11640
  )({
11405
11641
  scopes: { tenantId, projectId }
11406
11642
  });
@@ -11425,7 +11661,7 @@ app25.openapi(
11425
11661
  }
11426
11662
  }
11427
11663
  );
11428
- app25.openapi(
11664
+ app28.openapi(
11429
11665
  createRoute({
11430
11666
  method: "put",
11431
11667
  path: "/project-full/{projectId}",
@@ -11476,15 +11712,15 @@ app25.openapi(
11476
11712
  }
11477
11713
  const existingProject = await getFullProject(
11478
11714
  dbClient_default,
11479
- logger8
11715
+ logger9
11480
11716
  )({
11481
11717
  scopes: { tenantId, projectId }
11482
11718
  });
11483
11719
  const isCreate = !existingProject;
11484
- const updatedProject = isCreate ? await createFullProjectServerSide(dbClient_default, logger8)(
11720
+ const updatedProject = isCreate ? await createFullProjectServerSide(dbClient_default, logger9)(
11485
11721
  { tenantId, projectId },
11486
11722
  validatedProjectData
11487
- ) : await updateFullProjectServerSide(dbClient_default, logger8)(
11723
+ ) : await updateFullProjectServerSide(dbClient_default, logger9)(
11488
11724
  { tenantId, projectId },
11489
11725
  validatedProjectData
11490
11726
  );
@@ -11509,7 +11745,7 @@ app25.openapi(
11509
11745
  }
11510
11746
  }
11511
11747
  );
11512
- app25.openapi(
11748
+ app28.openapi(
11513
11749
  createRoute({
11514
11750
  method: "delete",
11515
11751
  path: "/project-full/{projectId}",
@@ -11532,7 +11768,7 @@ app25.openapi(
11532
11768
  try {
11533
11769
  const deleted = await deleteFullProject(
11534
11770
  dbClient_default,
11535
- logger8
11771
+ logger9
11536
11772
  )({
11537
11773
  scopes: { tenantId, projectId }
11538
11774
  });
@@ -11557,7 +11793,7 @@ app25.openapi(
11557
11793
  }
11558
11794
  }
11559
11795
  );
11560
- var projectFull_default = app25;
11796
+ var projectFull_default = app28;
11561
11797
  var userOrganizationsRoutes = new OpenAPIHono();
11562
11798
  userOrganizationsRoutes.openapi(
11563
11799
  createRoute({
@@ -11632,8 +11868,8 @@ userOrganizationsRoutes.openapi(
11632
11868
  var userOrganizations_default = userOrganizationsRoutes;
11633
11869
 
11634
11870
  // src/app.ts
11635
- var logger9 = getLogger("agents-manage-api");
11636
- logger9.info({ logger: logger9.getTransports() }, "Logger initialized");
11871
+ var logger10 = getLogger("agents-manage-api");
11872
+ logger10.info({ logger: logger10.getTransports() }, "Logger initialized");
11637
11873
  function isOriginAllowed(origin) {
11638
11874
  if (!origin) return false;
11639
11875
  try {
@@ -11652,15 +11888,15 @@ function isOriginAllowed(origin) {
11652
11888
  }
11653
11889
  }
11654
11890
  function createManagementHono(serverConfig, credentialStores, auth) {
11655
- const app26 = new OpenAPIHono();
11656
- app26.use("*", requestId());
11657
- app26.use("*", async (c, next) => {
11891
+ const app29 = new OpenAPIHono();
11892
+ app29.use("*", requestId());
11893
+ app29.use("*", async (c, next) => {
11658
11894
  c.set("serverConfig", serverConfig);
11659
11895
  c.set("credentialStores", credentialStores);
11660
11896
  c.set("auth", auth);
11661
11897
  return next();
11662
11898
  });
11663
- app26.use(
11899
+ app29.use(
11664
11900
  pinoLogger({
11665
11901
  pino: getLogger("agents-manage-api").getPinoInstance(),
11666
11902
  http: {
@@ -11673,7 +11909,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11673
11909
  }
11674
11910
  })
11675
11911
  );
11676
- app26.onError(async (err2, c) => {
11912
+ app29.onError(async (err2, c) => {
11677
11913
  const isExpectedError = err2 instanceof HTTPException;
11678
11914
  const status = isExpectedError ? err2.status : 500;
11679
11915
  const requestId2 = c.get("requestId") || "unknown";
@@ -11706,7 +11942,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11706
11942
  if (!isExpectedError) {
11707
11943
  const errorMessage = err2 instanceof Error ? err2.message : String(err2);
11708
11944
  const errorStack = err2 instanceof Error ? err2.stack : void 0;
11709
- logger9.error(
11945
+ logger10.error(
11710
11946
  {
11711
11947
  error: err2,
11712
11948
  message: errorMessage,
@@ -11717,7 +11953,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11717
11953
  "Unexpected server error occurred"
11718
11954
  );
11719
11955
  } else {
11720
- logger9.error(
11956
+ logger10.error(
11721
11957
  {
11722
11958
  error: err2,
11723
11959
  path: c.req.path,
@@ -11743,7 +11979,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11743
11979
  return c.body(JSON.stringify(responseBody));
11744
11980
  });
11745
11981
  if (auth) {
11746
- app26.use(
11982
+ app29.use(
11747
11983
  "/api/auth/*",
11748
11984
  cors({
11749
11985
  origin: (origin) => {
@@ -11756,14 +11992,30 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11756
11992
  credentials: true
11757
11993
  })
11758
11994
  );
11759
- app26.on(["POST", "GET"], "/api/auth/*", (c) => {
11995
+ app29.on(["POST", "GET", "OPTIONS"], "/api/auth/*", (c) => {
11760
11996
  return auth.handler(c.req.raw);
11761
11997
  });
11762
11998
  }
11763
- app26.use("*", async (c, next) => {
11999
+ app29.use(
12000
+ "/tenants/*/playground/token",
12001
+ cors({
12002
+ origin: (origin) => {
12003
+ return isOriginAllowed(origin) ? origin : null;
12004
+ },
12005
+ allowHeaders: ["content-type", "Content-Type", "authorization", "Authorization"],
12006
+ allowMethods: ["POST", "OPTIONS"],
12007
+ exposeHeaders: ["Content-Length"],
12008
+ maxAge: 600,
12009
+ credentials: true
12010
+ })
12011
+ );
12012
+ app29.use("*", async (c, next) => {
11764
12013
  if (auth && c.req.path.startsWith("/api/auth/")) {
11765
12014
  return next();
11766
12015
  }
12016
+ if (c.req.path.includes("/playground/token")) {
12017
+ return next();
12018
+ }
11767
12019
  return cors({
11768
12020
  origin: (origin) => {
11769
12021
  return isOriginAllowed(origin) ? origin : null;
@@ -11775,7 +12027,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11775
12027
  credentials: true
11776
12028
  })(c, next);
11777
12029
  });
11778
- app26.use("*", async (c, next) => {
12030
+ app29.use("*", async (c, next) => {
11779
12031
  if (env.DISABLE_AUTH || !auth) {
11780
12032
  c.set("user", null);
11781
12033
  c.set("session", null);
@@ -11793,7 +12045,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11793
12045
  c.set("session", session.session);
11794
12046
  await next();
11795
12047
  });
11796
- app26.openapi(
12048
+ app29.openapi(
11797
12049
  createRoute({
11798
12050
  method: "get",
11799
12051
  path: "/health",
@@ -11810,7 +12062,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11810
12062
  return c.body(null, 204);
11811
12063
  }
11812
12064
  );
11813
- app26.use("/tenants/*", async (c, next) => {
12065
+ app29.use("/tenants/*", async (c, next) => {
11814
12066
  const isTestEnvironment = process.env.ENVIRONMENT === "test";
11815
12067
  if (env.DISABLE_AUTH || isTestEnvironment) {
11816
12068
  await next();
@@ -11824,19 +12076,21 @@ function createManagementHono(serverConfig, credentialStores, auth) {
11824
12076
  });
11825
12077
  const isTestEnv = process.env.ENVIRONMENT === "test";
11826
12078
  if (!env.DISABLE_AUTH && !isTestEnv) {
11827
- app26.use("/tenants/:tenantId/*", requireTenantAccess());
11828
- }
11829
- app26.route("/api/users/:userId/organizations", userOrganizations_default);
11830
- app26.route("/api/invitations", invitations_default);
11831
- app26.route("/tenants/:tenantId", routes_default);
11832
- app26.route("/tenants/:tenantId", projectFull_default);
11833
- app26.route("/oauth", oauth_default);
11834
- setupOpenAPIRoutes(app26);
12079
+ app29.use("/tenants/:tenantId/*", requireTenantAccess());
12080
+ }
12081
+ app29.route("/api/users/:userId/organizations", userOrganizations_default);
12082
+ app29.route("/api/invitations", invitations_default);
12083
+ app29.route("/tenants/:tenantId", routes_default);
12084
+ app29.route("/tenants/:tenantId/playground/token", playgroundToken_default);
12085
+ app29.route("/tenants/:tenantId", projectFull_default);
12086
+ app29.route("/oauth", oauth_default);
12087
+ app29.route("/mcp", mcp_default);
12088
+ setupOpenAPIRoutes(app29);
11835
12089
  const baseApp = new Hono();
11836
- baseApp.route("/", app26);
12090
+ baseApp.route("/", app29);
11837
12091
  return baseApp;
11838
12092
  }
11839
- var logger10 = getLogger("initialization");
12093
+ var logger11 = getLogger("initialization");
11840
12094
  async function initializeDefaultUser(authInstance) {
11841
12095
  const { INKEEP_AGENTS_MANAGE_UI_USERNAME, INKEEP_AGENTS_MANAGE_UI_PASSWORD, DISABLE_AUTH } = env;
11842
12096
  const hasCredentials = INKEEP_AGENTS_MANAGE_UI_USERNAME && INKEEP_AGENTS_MANAGE_UI_PASSWORD;
@@ -11851,23 +12105,23 @@ async function initializeDefaultUser(authInstance) {
11851
12105
  logo: null,
11852
12106
  metadata: null
11853
12107
  });
11854
- logger10.info({ organizationId: orgId }, "Created default organization");
12108
+ logger11.info({ organizationId: orgId }, "Created default organization");
11855
12109
  } else {
11856
- logger10.info({ organizationId: orgId }, "Organization already exists");
12110
+ logger11.info({ organizationId: orgId }, "Organization already exists");
11857
12111
  }
11858
12112
  if (!hasCredentials || DISABLE_AUTH || !authInstance) {
11859
- logger10.info({ hasCredentials: false }, "Skipping default user creation");
12113
+ logger11.info({ hasCredentials: false }, "Skipping default user creation");
11860
12114
  return;
11861
12115
  }
11862
12116
  try {
11863
12117
  let user = await getUserByEmail(dbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
11864
12118
  if (user) {
11865
- logger10.info(
12119
+ logger11.info(
11866
12120
  { email: INKEEP_AGENTS_MANAGE_UI_USERNAME, userId: user.id },
11867
12121
  "Default user already exists"
11868
12122
  );
11869
12123
  } else {
11870
- logger10.info(
12124
+ logger11.info(
11871
12125
  { email: INKEEP_AGENTS_MANAGE_UI_USERNAME },
11872
12126
  "Creating default user with Better Auth..."
11873
12127
  );
@@ -11886,7 +12140,7 @@ async function initializeDefaultUser(authInstance) {
11886
12140
  if (!user) {
11887
12141
  throw new Error("User was created but could not be retrieved from database");
11888
12142
  }
11889
- logger10.info(
12143
+ logger11.info(
11890
12144
  {
11891
12145
  email: user.email,
11892
12146
  id: user.id
@@ -11903,14 +12157,14 @@ async function initializeDefaultUser(authInstance) {
11903
12157
  role: "owner",
11904
12158
  createdAt: /* @__PURE__ */ new Date()
11905
12159
  });
11906
- logger10.info({ userId: user.id, organizationId: orgId }, "Added user as organization owner");
12160
+ logger11.info({ userId: user.id, organizationId: orgId }, "Added user as organization owner");
11907
12161
  } else {
11908
- logger10.info(
12162
+ logger11.info(
11909
12163
  { userId: user.id, organizationId: orgId },
11910
12164
  "User already a member of organization"
11911
12165
  );
11912
12166
  }
11913
- logger10.info(
12167
+ logger11.info(
11914
12168
  {
11915
12169
  organizationId: orgId,
11916
12170
  organizationSlug: env.TENANT_ID,
@@ -11920,7 +12174,7 @@ async function initializeDefaultUser(authInstance) {
11920
12174
  "\u2705 Initialization complete - login with these credentials"
11921
12175
  );
11922
12176
  } catch (error) {
11923
- logger10.error(
12177
+ logger11.error(
11924
12178
  { error, email: INKEEP_AGENTS_MANAGE_UI_USERNAME },
11925
12179
  "\u274C Failed to create default user"
11926
12180
  );
@@ -11932,7 +12186,9 @@ async function createOIDCProvider(options) {
11932
12186
  const config = await client.discovery(issuerUrl, client.randomPKCECodeVerifier());
11933
12187
  const metadata2 = config.serverMetadata();
11934
12188
  if (!metadata2.issuer || !metadata2.authorization_endpoint || !metadata2.token_endpoint || !metadata2.userinfo_endpoint || !metadata2.jwks_uri) {
11935
- console.log("Some OIDC configuration endpoints are missing, which might cause issues with SSO");
12189
+ console.log(
12190
+ "Some OIDC configuration endpoints are missing, which might cause issues with SSO"
12191
+ );
11936
12192
  }
11937
12193
  const oidcConfig = {
11938
12194
  clientId: options.clientId,