@inkeep/agents-manage-api 0.15.0 → 0.16.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.
- package/dist/index.cjs +430 -119
- package/dist/index.js +431 -120
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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, 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, getCredentialReferenceWithTools, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialReferenceById, 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, listTools, dbResultToMcpTool, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, CredentialStoreType, generateIdFromName, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, createDefaultCredentialStores, CredentialStoreRegistry, discoverOAuthEndpoints, handleApiError } 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, getAgentsForTool, AgentToolRelationApiInsertSchema, createAgentToolRelation, AgentToolRelationApiUpdateSchema, updateAgentToolRelation, deleteAgentToolRelation, ApiKeyApiSelectSchema, listApiKeysPaginated, getApiKeyById, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, generateApiKey, createApiKey, ApiKeyApiUpdateSchema, updateApiKey, deleteApiKey, listArtifactComponentsPaginated, ArtifactComponentApiInsertSchema, validatePropsAsJsonSchema, createArtifactComponent, ArtifactComponentApiUpdateSchema, updateArtifactComponent, deleteArtifactComponent, ContextConfigApiSelectSchema, listContextConfigsPaginated, getContextConfigById, ContextConfigApiInsertSchema, createContextConfig, commonUpdateErrorResponses, ContextConfigApiUpdateSchema, updateContextConfig, commonDeleteErrorResponses, deleteContextConfig, CredentialReferenceApiSelectSchema, listCredentialReferencesPaginated, getCredentialReferenceWithTools, CredentialReferenceApiInsertSchema, createCredentialReference, CredentialReferenceApiUpdateSchema, updateCredentialReference, getCredentialReferenceById, getCredentialStoreLookupKeyFromRetrievalParams, deleteCredentialReference, listDataComponentsPaginated, DataComponentApiInsertSchema, createDataComponent, DataComponentApiUpdateSchema, updateDataComponent, deleteDataComponent, ExternalAgentApiSelectSchema, listExternalAgentsPaginated, getExternalAgent, ExternalAgentApiInsertSchema, createExternalAgent, ExternalAgentApiUpdateSchema, updateExternalAgent, deleteExternalAgent, FunctionApiSelectSchema, listFunctions, getFunction, FunctionApiInsertSchema, upsertFunction, FunctionApiUpdateSchema, deleteFunction, createFullGraphServerSide, getFullGraph, updateFullGraphServerSide, deleteFullGraph, TenantParamsSchema, ProjectApiSelectSchema, listProjectsPaginated, TenantIdParamsSchema, getProject, ProjectApiInsertSchema, createProject, ProjectApiUpdateSchema, updateProject, deleteProject, McpToolSchema, ToolStatusSchema, listTools, dbResultToMcpTool, getToolById, ToolApiInsertSchema, createTool, ToolApiUpdateSchema, updateTool, deleteTool, CredentialStoreType, generateIdFromName, FullProjectDefinitionSchema, createFullProjectServerSide, getFullProject, updateFullProjectServerSide, deleteFullProject, createDefaultCredentialStores, CredentialStoreRegistry, discoverOAuthEndpoints, handleApiError } 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';
|
|
@@ -66,10 +66,10 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
66
66
|
await next();
|
|
67
67
|
return;
|
|
68
68
|
});
|
|
69
|
-
function setupOpenAPIRoutes(
|
|
70
|
-
|
|
69
|
+
function setupOpenAPIRoutes(app21) {
|
|
70
|
+
app21.get("/openapi.json", (c) => {
|
|
71
71
|
try {
|
|
72
|
-
const document =
|
|
72
|
+
const document = app21.getOpenAPIDocument({
|
|
73
73
|
openapi: "3.0.0",
|
|
74
74
|
info: {
|
|
75
75
|
title: "Inkeep Agents Manage API",
|
|
@@ -90,7 +90,7 @@ function setupOpenAPIRoutes(app20) {
|
|
|
90
90
|
return c.json({ error: "Failed to generate OpenAPI document", details: errorDetails }, 500);
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
|
|
93
|
+
app21.get(
|
|
94
94
|
"/docs",
|
|
95
95
|
swaggerUI({
|
|
96
96
|
url: "/openapi.json",
|
|
@@ -2033,6 +2033,16 @@ app8.openapi(
|
|
|
2033
2033
|
async (c) => {
|
|
2034
2034
|
const { tenantId, projectId } = c.req.valid("param");
|
|
2035
2035
|
const body = c.req.valid("json");
|
|
2036
|
+
if (body.props !== null && body.props !== void 0) {
|
|
2037
|
+
const propsValidation = validatePropsAsJsonSchema(body.props);
|
|
2038
|
+
if (!propsValidation.isValid) {
|
|
2039
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2040
|
+
throw createApiError({
|
|
2041
|
+
code: "bad_request",
|
|
2042
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2036
2046
|
const finalId = body.id ? String(body.id) : nanoid();
|
|
2037
2047
|
const componentData = {
|
|
2038
2048
|
tenantId,
|
|
@@ -2040,8 +2050,7 @@ app8.openapi(
|
|
|
2040
2050
|
id: finalId,
|
|
2041
2051
|
name: String(body.name),
|
|
2042
2052
|
description: String(body.description),
|
|
2043
|
-
|
|
2044
|
-
fullProps: body.fullProps || void 0
|
|
2053
|
+
props: body.props ?? null
|
|
2045
2054
|
};
|
|
2046
2055
|
try {
|
|
2047
2056
|
const artifactComponent = await createArtifactComponent(dbClient_default)({
|
|
@@ -2091,15 +2100,30 @@ app8.openapi(
|
|
|
2091
2100
|
async (c) => {
|
|
2092
2101
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2093
2102
|
const body = c.req.valid("json");
|
|
2103
|
+
if (body.props !== void 0 && body.props !== null) {
|
|
2104
|
+
const propsValidation = validatePropsAsJsonSchema(body.props);
|
|
2105
|
+
if (!propsValidation.isValid) {
|
|
2106
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2107
|
+
throw createApiError({
|
|
2108
|
+
code: "bad_request",
|
|
2109
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
const updateData = {};
|
|
2114
|
+
if (body.name !== void 0) {
|
|
2115
|
+
updateData.name = String(body.name);
|
|
2116
|
+
}
|
|
2117
|
+
if (body.description !== void 0) {
|
|
2118
|
+
updateData.description = String(body.description);
|
|
2119
|
+
}
|
|
2120
|
+
if (body.props !== void 0) {
|
|
2121
|
+
updateData.props = body.props ?? null;
|
|
2122
|
+
}
|
|
2094
2123
|
const updatedArtifactComponent = await updateArtifactComponent(dbClient_default)({
|
|
2095
2124
|
scopes: { tenantId, projectId },
|
|
2096
2125
|
id,
|
|
2097
|
-
data:
|
|
2098
|
-
name: body.name ? String(body.name) : void 0,
|
|
2099
|
-
description: body.description ? String(body.description) : void 0,
|
|
2100
|
-
summaryProps: body.summaryProps || void 0,
|
|
2101
|
-
fullProps: body.fullProps || void 0
|
|
2102
|
-
}
|
|
2126
|
+
data: updateData
|
|
2103
2127
|
});
|
|
2104
2128
|
if (!updatedArtifactComponent) {
|
|
2105
2129
|
throw createApiError({
|
|
@@ -2682,6 +2706,16 @@ app11.openapi(
|
|
|
2682
2706
|
async (c) => {
|
|
2683
2707
|
const { tenantId, projectId } = c.req.valid("param");
|
|
2684
2708
|
const body = c.req.valid("json");
|
|
2709
|
+
if (body.props) {
|
|
2710
|
+
const propsValidation = validatePropsAsJsonSchema(body.props);
|
|
2711
|
+
if (!propsValidation.isValid) {
|
|
2712
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2713
|
+
throw createApiError({
|
|
2714
|
+
code: "bad_request",
|
|
2715
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2716
|
+
});
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2685
2719
|
const dataComponentData = {
|
|
2686
2720
|
...body,
|
|
2687
2721
|
tenantId,
|
|
@@ -2723,6 +2757,16 @@ app11.openapi(
|
|
|
2723
2757
|
async (c) => {
|
|
2724
2758
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2725
2759
|
const body = c.req.valid("json");
|
|
2760
|
+
if (body.props !== void 0 && body.props !== null) {
|
|
2761
|
+
const propsValidation = validatePropsAsJsonSchema(body.props);
|
|
2762
|
+
if (!propsValidation.isValid) {
|
|
2763
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2764
|
+
throw createApiError({
|
|
2765
|
+
code: "bad_request",
|
|
2766
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2726
2770
|
const updatedDataComponent = await updateDataComponent(dbClient_default)({
|
|
2727
2771
|
scopes: { tenantId, projectId },
|
|
2728
2772
|
dataComponentId: id,
|
|
@@ -3000,8 +3044,268 @@ app12.openapi(
|
|
|
3000
3044
|
}
|
|
3001
3045
|
);
|
|
3002
3046
|
var externalAgents_default = app12;
|
|
3003
|
-
var logger2 = getLogger("
|
|
3047
|
+
var logger2 = getLogger("functions");
|
|
3004
3048
|
var app13 = new OpenAPIHono();
|
|
3049
|
+
app13.openapi(
|
|
3050
|
+
createRoute({
|
|
3051
|
+
method: "get",
|
|
3052
|
+
path: "/",
|
|
3053
|
+
summary: "List Functions",
|
|
3054
|
+
operationId: "list-functions",
|
|
3055
|
+
tags: ["Functions"],
|
|
3056
|
+
request: {
|
|
3057
|
+
params: TenantProjectParamsSchema,
|
|
3058
|
+
query: PaginationQueryParamsSchema
|
|
3059
|
+
},
|
|
3060
|
+
responses: {
|
|
3061
|
+
200: {
|
|
3062
|
+
description: "List of functions",
|
|
3063
|
+
content: {
|
|
3064
|
+
"application/json": {
|
|
3065
|
+
schema: ListResponseSchema(FunctionApiSelectSchema)
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
},
|
|
3069
|
+
...commonGetErrorResponses
|
|
3070
|
+
}
|
|
3071
|
+
}),
|
|
3072
|
+
async (c) => {
|
|
3073
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
3074
|
+
try {
|
|
3075
|
+
const functions = await listFunctions(dbClient_default)({ scopes: { tenantId, projectId } });
|
|
3076
|
+
return c.json({
|
|
3077
|
+
data: functions,
|
|
3078
|
+
pagination: {
|
|
3079
|
+
page: 1,
|
|
3080
|
+
limit: functions.length,
|
|
3081
|
+
total: functions.length,
|
|
3082
|
+
pages: 1
|
|
3083
|
+
}
|
|
3084
|
+
});
|
|
3085
|
+
} catch (error) {
|
|
3086
|
+
logger2.error({ error, tenantId }, "Failed to list functions");
|
|
3087
|
+
return c.json(
|
|
3088
|
+
createApiError({ code: "internal_server_error", message: "Failed to list functions" }),
|
|
3089
|
+
500
|
|
3090
|
+
);
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
);
|
|
3094
|
+
app13.openapi(
|
|
3095
|
+
createRoute({
|
|
3096
|
+
method: "get",
|
|
3097
|
+
path: "/{id}",
|
|
3098
|
+
summary: "Get Function by ID",
|
|
3099
|
+
operationId: "get-function",
|
|
3100
|
+
tags: ["Functions"],
|
|
3101
|
+
request: {
|
|
3102
|
+
params: TenantProjectParamsSchema.merge(IdParamsSchema)
|
|
3103
|
+
},
|
|
3104
|
+
responses: {
|
|
3105
|
+
200: {
|
|
3106
|
+
description: "Function details",
|
|
3107
|
+
content: {
|
|
3108
|
+
"application/json": {
|
|
3109
|
+
schema: SingleResponseSchema(FunctionApiSelectSchema)
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
},
|
|
3113
|
+
...commonGetErrorResponses
|
|
3114
|
+
}
|
|
3115
|
+
}),
|
|
3116
|
+
async (c) => {
|
|
3117
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
3118
|
+
try {
|
|
3119
|
+
const functionData = await getFunction(dbClient_default)({
|
|
3120
|
+
functionId: id,
|
|
3121
|
+
scopes: { tenantId, projectId }
|
|
3122
|
+
});
|
|
3123
|
+
if (!functionData) {
|
|
3124
|
+
return c.json(
|
|
3125
|
+
createApiError({ code: "not_found", message: "Function not found" }),
|
|
3126
|
+
404
|
|
3127
|
+
);
|
|
3128
|
+
}
|
|
3129
|
+
return c.json({ data: functionData });
|
|
3130
|
+
} catch (error) {
|
|
3131
|
+
logger2.error({ error, tenantId, id }, "Failed to get function");
|
|
3132
|
+
return c.json(
|
|
3133
|
+
createApiError({ code: "internal_server_error", message: "Failed to get function" }),
|
|
3134
|
+
500
|
|
3135
|
+
);
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
);
|
|
3139
|
+
app13.openapi(
|
|
3140
|
+
createRoute({
|
|
3141
|
+
method: "post",
|
|
3142
|
+
path: "/",
|
|
3143
|
+
summary: "Create Function",
|
|
3144
|
+
operationId: "create-function",
|
|
3145
|
+
tags: ["Functions"],
|
|
3146
|
+
request: {
|
|
3147
|
+
params: TenantProjectParamsSchema,
|
|
3148
|
+
body: {
|
|
3149
|
+
content: {
|
|
3150
|
+
"application/json": {
|
|
3151
|
+
schema: FunctionApiInsertSchema
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
},
|
|
3156
|
+
responses: {
|
|
3157
|
+
201: {
|
|
3158
|
+
description: "Function created",
|
|
3159
|
+
content: {
|
|
3160
|
+
"application/json": {
|
|
3161
|
+
schema: SingleResponseSchema(FunctionApiSelectSchema)
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
},
|
|
3165
|
+
...commonGetErrorResponses
|
|
3166
|
+
}
|
|
3167
|
+
}),
|
|
3168
|
+
async (c) => {
|
|
3169
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
3170
|
+
const functionData = c.req.valid("json");
|
|
3171
|
+
try {
|
|
3172
|
+
const id = functionData.id || nanoid();
|
|
3173
|
+
await upsertFunction(dbClient_default)({
|
|
3174
|
+
data: {
|
|
3175
|
+
...functionData,
|
|
3176
|
+
id
|
|
3177
|
+
},
|
|
3178
|
+
scopes: { tenantId, projectId }
|
|
3179
|
+
});
|
|
3180
|
+
const created = await getFunction(dbClient_default)({
|
|
3181
|
+
functionId: id,
|
|
3182
|
+
scopes: { tenantId, projectId }
|
|
3183
|
+
});
|
|
3184
|
+
logger2.info({ tenantId, functionId: id }, "Function created");
|
|
3185
|
+
return c.json({ data: created }, 201);
|
|
3186
|
+
} catch (error) {
|
|
3187
|
+
logger2.error({ error, tenantId, functionData }, "Failed to create function");
|
|
3188
|
+
return c.json(
|
|
3189
|
+
createApiError({ code: "internal_server_error", message: "Failed to create function" }),
|
|
3190
|
+
500
|
|
3191
|
+
);
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
);
|
|
3195
|
+
app13.openapi(
|
|
3196
|
+
createRoute({
|
|
3197
|
+
method: "put",
|
|
3198
|
+
path: "/{id}",
|
|
3199
|
+
summary: "Update Function",
|
|
3200
|
+
operationId: "update-function",
|
|
3201
|
+
tags: ["Functions"],
|
|
3202
|
+
request: {
|
|
3203
|
+
params: TenantProjectParamsSchema.merge(IdParamsSchema),
|
|
3204
|
+
body: {
|
|
3205
|
+
content: {
|
|
3206
|
+
"application/json": {
|
|
3207
|
+
schema: FunctionApiUpdateSchema
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
},
|
|
3212
|
+
responses: {
|
|
3213
|
+
200: {
|
|
3214
|
+
description: "Function updated",
|
|
3215
|
+
content: {
|
|
3216
|
+
"application/json": {
|
|
3217
|
+
schema: SingleResponseSchema(FunctionApiSelectSchema)
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
},
|
|
3221
|
+
...commonGetErrorResponses
|
|
3222
|
+
}
|
|
3223
|
+
}),
|
|
3224
|
+
async (c) => {
|
|
3225
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
3226
|
+
const updateData = c.req.valid("json");
|
|
3227
|
+
try {
|
|
3228
|
+
const existing = await getFunction(dbClient_default)({
|
|
3229
|
+
functionId: id,
|
|
3230
|
+
scopes: { tenantId, projectId }
|
|
3231
|
+
});
|
|
3232
|
+
if (!existing) {
|
|
3233
|
+
return c.json(
|
|
3234
|
+
createApiError({ code: "not_found", message: "Function not found" }),
|
|
3235
|
+
404
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3238
|
+
await upsertFunction(dbClient_default)({
|
|
3239
|
+
data: {
|
|
3240
|
+
...existing,
|
|
3241
|
+
...updateData,
|
|
3242
|
+
id
|
|
3243
|
+
},
|
|
3244
|
+
scopes: { tenantId, projectId }
|
|
3245
|
+
});
|
|
3246
|
+
const updated = await getFunction(dbClient_default)({
|
|
3247
|
+
functionId: id,
|
|
3248
|
+
scopes: { tenantId, projectId }
|
|
3249
|
+
});
|
|
3250
|
+
logger2.info({ tenantId, functionId: id }, "Function updated");
|
|
3251
|
+
return c.json({ data: updated });
|
|
3252
|
+
} catch (error) {
|
|
3253
|
+
logger2.error({ error, tenantId, id, updateData }, "Failed to update function");
|
|
3254
|
+
return c.json(
|
|
3255
|
+
createApiError({ code: "internal_server_error", message: "Failed to update function" }),
|
|
3256
|
+
500
|
|
3257
|
+
);
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
);
|
|
3261
|
+
app13.openapi(
|
|
3262
|
+
createRoute({
|
|
3263
|
+
method: "delete",
|
|
3264
|
+
path: "/{id}",
|
|
3265
|
+
summary: "Delete Function",
|
|
3266
|
+
operationId: "delete-function",
|
|
3267
|
+
tags: ["Functions"],
|
|
3268
|
+
request: {
|
|
3269
|
+
params: TenantProjectParamsSchema.merge(IdParamsSchema)
|
|
3270
|
+
},
|
|
3271
|
+
responses: {
|
|
3272
|
+
204: {
|
|
3273
|
+
description: "Function deleted"
|
|
3274
|
+
},
|
|
3275
|
+
...commonGetErrorResponses
|
|
3276
|
+
}
|
|
3277
|
+
}),
|
|
3278
|
+
async (c) => {
|
|
3279
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
3280
|
+
try {
|
|
3281
|
+
const existing = await getFunction(dbClient_default)({
|
|
3282
|
+
functionId: id,
|
|
3283
|
+
scopes: { tenantId, projectId }
|
|
3284
|
+
});
|
|
3285
|
+
if (!existing) {
|
|
3286
|
+
return c.json(
|
|
3287
|
+
createApiError({ code: "not_found", message: "Function not found" }),
|
|
3288
|
+
404
|
|
3289
|
+
);
|
|
3290
|
+
}
|
|
3291
|
+
await deleteFunction(dbClient_default)({
|
|
3292
|
+
functionId: id,
|
|
3293
|
+
scopes: { tenantId, projectId }
|
|
3294
|
+
});
|
|
3295
|
+
logger2.info({ tenantId, functionId: id }, "Function deleted");
|
|
3296
|
+
return c.body(null, 204);
|
|
3297
|
+
} catch (error) {
|
|
3298
|
+
logger2.error({ error, tenantId, id }, "Failed to delete function");
|
|
3299
|
+
return c.json(
|
|
3300
|
+
createApiError({ code: "internal_server_error", message: "Failed to delete function" }),
|
|
3301
|
+
500
|
|
3302
|
+
);
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
);
|
|
3306
|
+
var functions_default = app13;
|
|
3307
|
+
var logger3 = getLogger("graphFull");
|
|
3308
|
+
var app14 = new OpenAPIHono();
|
|
3005
3309
|
var GraphIdParamsSchema = z.object({
|
|
3006
3310
|
tenantId: z.string().openapi({
|
|
3007
3311
|
description: "Tenant identifier",
|
|
@@ -3016,7 +3320,7 @@ var GraphIdParamsSchema = z.object({
|
|
|
3016
3320
|
example: "graph_789"
|
|
3017
3321
|
})
|
|
3018
3322
|
}).openapi("GraphIdParams");
|
|
3019
|
-
|
|
3323
|
+
app14.openapi(
|
|
3020
3324
|
createRoute({
|
|
3021
3325
|
method: "post",
|
|
3022
3326
|
path: "/",
|
|
@@ -3058,14 +3362,14 @@ app13.openapi(
|
|
|
3058
3362
|
const { tenantId, projectId } = c.req.valid("param");
|
|
3059
3363
|
const graphData = c.req.valid("json");
|
|
3060
3364
|
const validatedGraphData = FullGraphDefinitionSchema.parse(graphData);
|
|
3061
|
-
const createdGraph = await createFullGraphServerSide(dbClient_default,
|
|
3365
|
+
const createdGraph = await createFullGraphServerSide(dbClient_default, logger3)(
|
|
3062
3366
|
{ tenantId, projectId },
|
|
3063
3367
|
validatedGraphData
|
|
3064
3368
|
);
|
|
3065
3369
|
return c.json({ data: createdGraph }, 201);
|
|
3066
3370
|
}
|
|
3067
3371
|
);
|
|
3068
|
-
|
|
3372
|
+
app14.openapi(
|
|
3069
3373
|
createRoute({
|
|
3070
3374
|
method: "get",
|
|
3071
3375
|
path: "/{graphId}",
|
|
@@ -3093,7 +3397,7 @@ app13.openapi(
|
|
|
3093
3397
|
try {
|
|
3094
3398
|
const graph = await getFullGraph(
|
|
3095
3399
|
dbClient_default,
|
|
3096
|
-
|
|
3400
|
+
logger3
|
|
3097
3401
|
)({
|
|
3098
3402
|
scopes: { tenantId, projectId, graphId }
|
|
3099
3403
|
});
|
|
@@ -3118,7 +3422,7 @@ app13.openapi(
|
|
|
3118
3422
|
}
|
|
3119
3423
|
}
|
|
3120
3424
|
);
|
|
3121
|
-
|
|
3425
|
+
app14.openapi(
|
|
3122
3426
|
createRoute({
|
|
3123
3427
|
method: "put",
|
|
3124
3428
|
path: "/{graphId}",
|
|
@@ -3169,15 +3473,15 @@ app13.openapi(
|
|
|
3169
3473
|
}
|
|
3170
3474
|
const existingGraph = await getFullGraph(
|
|
3171
3475
|
dbClient_default,
|
|
3172
|
-
|
|
3476
|
+
logger3
|
|
3173
3477
|
)({
|
|
3174
3478
|
scopes: { tenantId, projectId, graphId }
|
|
3175
3479
|
});
|
|
3176
3480
|
const isCreate = !existingGraph;
|
|
3177
|
-
const updatedGraph = isCreate ? await createFullGraphServerSide(dbClient_default,
|
|
3481
|
+
const updatedGraph = isCreate ? await createFullGraphServerSide(dbClient_default, logger3)(
|
|
3178
3482
|
{ tenantId, projectId },
|
|
3179
3483
|
validatedGraphData
|
|
3180
|
-
) : await updateFullGraphServerSide(dbClient_default,
|
|
3484
|
+
) : await updateFullGraphServerSide(dbClient_default, logger3)(
|
|
3181
3485
|
{ tenantId, projectId },
|
|
3182
3486
|
validatedGraphData
|
|
3183
3487
|
);
|
|
@@ -3202,7 +3506,7 @@ app13.openapi(
|
|
|
3202
3506
|
}
|
|
3203
3507
|
}
|
|
3204
3508
|
);
|
|
3205
|
-
|
|
3509
|
+
app14.openapi(
|
|
3206
3510
|
createRoute({
|
|
3207
3511
|
method: "delete",
|
|
3208
3512
|
path: "/{graphId}",
|
|
@@ -3225,7 +3529,7 @@ app13.openapi(
|
|
|
3225
3529
|
try {
|
|
3226
3530
|
const deleted = await deleteFullGraph(
|
|
3227
3531
|
dbClient_default,
|
|
3228
|
-
|
|
3532
|
+
logger3
|
|
3229
3533
|
)({
|
|
3230
3534
|
scopes: { tenantId, projectId, graphId }
|
|
3231
3535
|
});
|
|
@@ -3250,9 +3554,9 @@ app13.openapi(
|
|
|
3250
3554
|
}
|
|
3251
3555
|
}
|
|
3252
3556
|
);
|
|
3253
|
-
var graphFull_default =
|
|
3254
|
-
var
|
|
3255
|
-
|
|
3557
|
+
var graphFull_default = app14;
|
|
3558
|
+
var app15 = new OpenAPIHono();
|
|
3559
|
+
app15.openapi(
|
|
3256
3560
|
createRoute({
|
|
3257
3561
|
method: "get",
|
|
3258
3562
|
path: "/",
|
|
@@ -3287,7 +3591,7 @@ app14.openapi(
|
|
|
3287
3591
|
return c.json(result);
|
|
3288
3592
|
}
|
|
3289
3593
|
);
|
|
3290
|
-
|
|
3594
|
+
app15.openapi(
|
|
3291
3595
|
createRoute({
|
|
3292
3596
|
method: "get",
|
|
3293
3597
|
path: "/{id}",
|
|
@@ -3322,7 +3626,7 @@ app14.openapi(
|
|
|
3322
3626
|
return c.json({ data: project });
|
|
3323
3627
|
}
|
|
3324
3628
|
);
|
|
3325
|
-
|
|
3629
|
+
app15.openapi(
|
|
3326
3630
|
createRoute({
|
|
3327
3631
|
method: "post",
|
|
3328
3632
|
path: "/",
|
|
@@ -3380,7 +3684,7 @@ app14.openapi(
|
|
|
3380
3684
|
}
|
|
3381
3685
|
}
|
|
3382
3686
|
);
|
|
3383
|
-
|
|
3687
|
+
app15.openapi(
|
|
3384
3688
|
createRoute({
|
|
3385
3689
|
method: "patch",
|
|
3386
3690
|
path: "/{id}",
|
|
@@ -3426,7 +3730,7 @@ app14.openapi(
|
|
|
3426
3730
|
return c.json({ data: project });
|
|
3427
3731
|
}
|
|
3428
3732
|
);
|
|
3429
|
-
|
|
3733
|
+
app15.openapi(
|
|
3430
3734
|
createRoute({
|
|
3431
3735
|
method: "delete",
|
|
3432
3736
|
path: "/{id}",
|
|
@@ -3476,10 +3780,10 @@ app14.openapi(
|
|
|
3476
3780
|
}
|
|
3477
3781
|
}
|
|
3478
3782
|
);
|
|
3479
|
-
var projects_default =
|
|
3480
|
-
var
|
|
3481
|
-
var
|
|
3482
|
-
|
|
3783
|
+
var projects_default = app15;
|
|
3784
|
+
var logger4 = getLogger("tools");
|
|
3785
|
+
var app16 = new OpenAPIHono();
|
|
3786
|
+
app16.openapi(
|
|
3483
3787
|
createRoute({
|
|
3484
3788
|
method: "get",
|
|
3485
3789
|
path: "/",
|
|
@@ -3539,7 +3843,7 @@ app15.openapi(
|
|
|
3539
3843
|
return c.json(result);
|
|
3540
3844
|
}
|
|
3541
3845
|
);
|
|
3542
|
-
|
|
3846
|
+
app16.openapi(
|
|
3543
3847
|
createRoute({
|
|
3544
3848
|
method: "get",
|
|
3545
3849
|
path: "/{id}",
|
|
@@ -3576,7 +3880,7 @@ app15.openapi(
|
|
|
3576
3880
|
});
|
|
3577
3881
|
}
|
|
3578
3882
|
);
|
|
3579
|
-
|
|
3883
|
+
app16.openapi(
|
|
3580
3884
|
createRoute({
|
|
3581
3885
|
method: "post",
|
|
3582
3886
|
path: "/",
|
|
@@ -3609,7 +3913,7 @@ app15.openapi(
|
|
|
3609
3913
|
const { tenantId, projectId } = c.req.valid("param");
|
|
3610
3914
|
const body = c.req.valid("json");
|
|
3611
3915
|
const credentialStores = c.get("credentialStores");
|
|
3612
|
-
|
|
3916
|
+
logger4.info({ body }, "body");
|
|
3613
3917
|
const id = body.id || nanoid();
|
|
3614
3918
|
const tool = await createTool(dbClient_default)({
|
|
3615
3919
|
tenantId,
|
|
@@ -3629,7 +3933,7 @@ app15.openapi(
|
|
|
3629
3933
|
);
|
|
3630
3934
|
}
|
|
3631
3935
|
);
|
|
3632
|
-
|
|
3936
|
+
app16.openapi(
|
|
3633
3937
|
createRoute({
|
|
3634
3938
|
method: "put",
|
|
3635
3939
|
path: "/{id}",
|
|
@@ -3690,7 +3994,7 @@ app15.openapi(
|
|
|
3690
3994
|
});
|
|
3691
3995
|
}
|
|
3692
3996
|
);
|
|
3693
|
-
|
|
3997
|
+
app16.openapi(
|
|
3694
3998
|
createRoute({
|
|
3695
3999
|
method: "delete",
|
|
3696
4000
|
path: "/{id}",
|
|
@@ -3726,30 +4030,31 @@ app15.openapi(
|
|
|
3726
4030
|
return c.body(null, 204);
|
|
3727
4031
|
}
|
|
3728
4032
|
);
|
|
3729
|
-
var tools_default =
|
|
4033
|
+
var tools_default = app16;
|
|
3730
4034
|
|
|
3731
4035
|
// src/routes/index.ts
|
|
3732
|
-
var
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
4036
|
+
var app17 = new OpenAPIHono();
|
|
4037
|
+
app17.route("/projects", projects_default);
|
|
4038
|
+
app17.route("/projects/:projectId/graphs/:graphId/agents", agents_default);
|
|
4039
|
+
app17.route("/projects/:projectId/graphs/:graphId/agent-relations", agentRelations_default);
|
|
4040
|
+
app17.route("/projects/:projectId/agent-graphs", agentGraph_default);
|
|
4041
|
+
app17.route("/projects/:projectId/graphs/:graphId/agent-tool-relations", agentToolRelations_default);
|
|
4042
|
+
app17.route(
|
|
3739
4043
|
"/projects/:projectId/graphs/:graphId/agent-artifact-components",
|
|
3740
4044
|
agentArtifactComponents_default
|
|
3741
4045
|
);
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
var
|
|
4046
|
+
app17.route("/projects/:projectId/graphs/:graphId/agent-data-components", agentDataComponents_default);
|
|
4047
|
+
app17.route("/projects/:projectId/artifact-components", artifactComponents_default);
|
|
4048
|
+
app17.route("/projects/:projectId/graphs/:graphId/context-configs", contextConfigs_default);
|
|
4049
|
+
app17.route("/projects/:projectId/credentials", credentials_default);
|
|
4050
|
+
app17.route("/projects/:projectId/data-components", dataComponents_default);
|
|
4051
|
+
app17.route("/projects/:projectId/graphs/:graphId/external-agents", externalAgents_default);
|
|
4052
|
+
app17.route("/projects/:projectId/functions", functions_default);
|
|
4053
|
+
app17.route("/projects/:projectId/tools", tools_default);
|
|
4054
|
+
app17.route("/projects/:projectId/api-keys", apiKeys_default);
|
|
4055
|
+
app17.route("/projects/:projectId/graph", graphFull_default);
|
|
4056
|
+
var routes_default = app17;
|
|
4057
|
+
var logger5 = getLogger("oauth-service");
|
|
3753
4058
|
var pkceStore = /* @__PURE__ */ new Map();
|
|
3754
4059
|
function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId) {
|
|
3755
4060
|
pkceStore.set(state, { codeVerifier, toolId, tenantId, projectId, clientId });
|
|
@@ -3784,7 +4089,10 @@ var OAuthService = class {
|
|
|
3784
4089
|
*/
|
|
3785
4090
|
async initiateOAuthFlow(params) {
|
|
3786
4091
|
const { tool, tenantId, projectId, toolId, baseUrl } = params;
|
|
3787
|
-
|
|
4092
|
+
if (tool.config.type !== "mcp") {
|
|
4093
|
+
throw new Error("OAuth is only supported for MCP tools");
|
|
4094
|
+
}
|
|
4095
|
+
const oAuthConfig = await discoverOAuthEndpoints(tool.config.mcp.server.url, logger5);
|
|
3788
4096
|
if (!oAuthConfig) {
|
|
3789
4097
|
throw new Error("OAuth not supported by this server");
|
|
3790
4098
|
}
|
|
@@ -3808,7 +4116,7 @@ var OAuthService = class {
|
|
|
3808
4116
|
resource: tool.config.mcp.server.url
|
|
3809
4117
|
});
|
|
3810
4118
|
storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId);
|
|
3811
|
-
|
|
4119
|
+
logger5.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
|
|
3812
4120
|
return {
|
|
3813
4121
|
redirectUrl: authUrl,
|
|
3814
4122
|
state
|
|
@@ -3819,7 +4127,10 @@ var OAuthService = class {
|
|
|
3819
4127
|
*/
|
|
3820
4128
|
async exchangeCodeForTokens(params) {
|
|
3821
4129
|
const { code, codeVerifier, clientId, tool, baseUrl } = params;
|
|
3822
|
-
|
|
4130
|
+
if (tool.config.type !== "mcp") {
|
|
4131
|
+
throw new Error("OAuth is only supported for MCP tools");
|
|
4132
|
+
}
|
|
4133
|
+
const oAuthConfig = await discoverOAuthEndpoints(tool.config.mcp.server.url, logger5);
|
|
3823
4134
|
if (!oAuthConfig?.tokenUrl) {
|
|
3824
4135
|
throw new Error("Could not discover OAuth token endpoint");
|
|
3825
4136
|
}
|
|
@@ -3834,9 +4145,9 @@ var OAuthService = class {
|
|
|
3834
4145
|
codeVerifier,
|
|
3835
4146
|
redirectUri
|
|
3836
4147
|
});
|
|
3837
|
-
|
|
4148
|
+
logger5.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
|
|
3838
4149
|
} catch (error) {
|
|
3839
|
-
|
|
4150
|
+
logger5.warn(
|
|
3840
4151
|
{ error: error instanceof Error ? error.message : error },
|
|
3841
4152
|
"openid-client failed, falling back to manual token exchange"
|
|
3842
4153
|
);
|
|
@@ -3847,7 +4158,7 @@ var OAuthService = class {
|
|
|
3847
4158
|
codeVerifier,
|
|
3848
4159
|
redirectUri
|
|
3849
4160
|
});
|
|
3850
|
-
|
|
4161
|
+
logger5.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
|
|
3851
4162
|
}
|
|
3852
4163
|
return { tokens, oAuthConfig };
|
|
3853
4164
|
}
|
|
@@ -3855,7 +4166,7 @@ var OAuthService = class {
|
|
|
3855
4166
|
* Perform dynamic client registration
|
|
3856
4167
|
*/
|
|
3857
4168
|
async performDynamicClientRegistration(registrationUrl, redirectUri) {
|
|
3858
|
-
|
|
4169
|
+
logger5.info({ registrationUrl }, "Attempting dynamic client registration");
|
|
3859
4170
|
try {
|
|
3860
4171
|
const registrationResponse = await fetch(registrationUrl, {
|
|
3861
4172
|
method: "POST",
|
|
@@ -3878,11 +4189,11 @@ var OAuthService = class {
|
|
|
3878
4189
|
});
|
|
3879
4190
|
if (registrationResponse.ok) {
|
|
3880
4191
|
const registration = await registrationResponse.json();
|
|
3881
|
-
|
|
4192
|
+
logger5.info({ clientId: registration.client_id }, "Dynamic client registration successful");
|
|
3882
4193
|
return registration.client_id;
|
|
3883
4194
|
} else {
|
|
3884
4195
|
const errorText = await registrationResponse.text();
|
|
3885
|
-
|
|
4196
|
+
logger5.warn(
|
|
3886
4197
|
{
|
|
3887
4198
|
status: registrationResponse.status,
|
|
3888
4199
|
errorText
|
|
@@ -3891,7 +4202,7 @@ var OAuthService = class {
|
|
|
3891
4202
|
);
|
|
3892
4203
|
}
|
|
3893
4204
|
} catch (regError) {
|
|
3894
|
-
|
|
4205
|
+
logger5.warn(
|
|
3895
4206
|
{ error: regError },
|
|
3896
4207
|
"Dynamic client registration error, using default client_id"
|
|
3897
4208
|
);
|
|
@@ -3921,7 +4232,7 @@ var OAuthService = class {
|
|
|
3921
4232
|
const oauth = await import('openid-client');
|
|
3922
4233
|
const tokenUrl = new URL(oAuthConfig.tokenUrl);
|
|
3923
4234
|
const oauthServerUrl = `${tokenUrl.protocol}//${tokenUrl.host}`;
|
|
3924
|
-
|
|
4235
|
+
logger5.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
|
|
3925
4236
|
const config = await oauth.discovery(
|
|
3926
4237
|
new URL(oauthServerUrl),
|
|
3927
4238
|
clientId,
|
|
@@ -3953,7 +4264,7 @@ var OAuthService = class {
|
|
|
3953
4264
|
*/
|
|
3954
4265
|
async exchangeManually(params) {
|
|
3955
4266
|
const { oAuthConfig, clientId, code, codeVerifier, redirectUri } = params;
|
|
3956
|
-
|
|
4267
|
+
logger5.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
|
|
3957
4268
|
const tokenResponse = await fetch(oAuthConfig.tokenUrl, {
|
|
3958
4269
|
method: "POST",
|
|
3959
4270
|
headers: {
|
|
@@ -3971,7 +4282,7 @@ var OAuthService = class {
|
|
|
3971
4282
|
});
|
|
3972
4283
|
if (!tokenResponse.ok) {
|
|
3973
4284
|
const errorText = await tokenResponse.text();
|
|
3974
|
-
|
|
4285
|
+
logger5.error(
|
|
3975
4286
|
{
|
|
3976
4287
|
status: tokenResponse.status,
|
|
3977
4288
|
statusText: tokenResponse.statusText,
|
|
@@ -4014,8 +4325,8 @@ async function findOrCreateCredential(tenantId, projectId, credentialData) {
|
|
|
4014
4325
|
throw new Error(`Failed to save credential '${credentialData.id}' to database`);
|
|
4015
4326
|
}
|
|
4016
4327
|
}
|
|
4017
|
-
var
|
|
4018
|
-
var
|
|
4328
|
+
var app18 = new OpenAPIHono();
|
|
4329
|
+
var logger6 = getLogger("oauth-callback");
|
|
4019
4330
|
function getBaseUrlFromRequest(c) {
|
|
4020
4331
|
const url = new URL(c.req.url);
|
|
4021
4332
|
return `${url.protocol}//${url.host}`;
|
|
@@ -4101,7 +4412,7 @@ var OAuthCallbackQuerySchema = z$1.object({
|
|
|
4101
4412
|
error: z$1.string().optional(),
|
|
4102
4413
|
error_description: z$1.string().optional()
|
|
4103
4414
|
});
|
|
4104
|
-
|
|
4415
|
+
app18.openapi(
|
|
4105
4416
|
createRoute({
|
|
4106
4417
|
method: "get",
|
|
4107
4418
|
path: "/login",
|
|
@@ -4147,7 +4458,7 @@ app17.openapi(
|
|
|
4147
4458
|
try {
|
|
4148
4459
|
const tool = await getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId });
|
|
4149
4460
|
if (!tool) {
|
|
4150
|
-
|
|
4461
|
+
logger6.error({ toolId, tenantId, projectId }, "Tool not found for OAuth login");
|
|
4151
4462
|
return c.text("Tool not found", 404);
|
|
4152
4463
|
}
|
|
4153
4464
|
const credentialStores = c.get("credentialStores");
|
|
@@ -4162,13 +4473,13 @@ app17.openapi(
|
|
|
4162
4473
|
});
|
|
4163
4474
|
return c.redirect(redirectUrl, 302);
|
|
4164
4475
|
} catch (error) {
|
|
4165
|
-
|
|
4476
|
+
logger6.error({ toolId, tenantId, projectId, error }, "OAuth login failed");
|
|
4166
4477
|
const errorMessage = error instanceof Error ? error.message : "Failed to initiate OAuth login";
|
|
4167
4478
|
return c.text(`OAuth Error: ${errorMessage}`, 500);
|
|
4168
4479
|
}
|
|
4169
4480
|
}
|
|
4170
4481
|
);
|
|
4171
|
-
|
|
4482
|
+
app18.openapi(
|
|
4172
4483
|
createRoute({
|
|
4173
4484
|
method: "get",
|
|
4174
4485
|
path: "/callback",
|
|
@@ -4204,9 +4515,9 @@ app17.openapi(
|
|
|
4204
4515
|
async (c) => {
|
|
4205
4516
|
try {
|
|
4206
4517
|
const { code, state, error, error_description } = c.req.valid("query");
|
|
4207
|
-
|
|
4518
|
+
logger6.info({ state, hasCode: !!code }, "OAuth callback received");
|
|
4208
4519
|
if (error) {
|
|
4209
|
-
|
|
4520
|
+
logger6.error({ error, error_description }, "OAuth authorization failed");
|
|
4210
4521
|
const errorMessage = error_description || error || "OAuth Authorization Failed. Please try again.";
|
|
4211
4522
|
const errorPage = generateOAuthCallbackPage({
|
|
4212
4523
|
title: "Authentication Failed",
|
|
@@ -4217,7 +4528,7 @@ app17.openapi(
|
|
|
4217
4528
|
}
|
|
4218
4529
|
const pkceData = retrievePKCEVerifier(state);
|
|
4219
4530
|
if (!pkceData) {
|
|
4220
|
-
|
|
4531
|
+
logger6.error({ state }, "Invalid or expired OAuth state");
|
|
4221
4532
|
const errorMessage = "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.";
|
|
4222
4533
|
const expiredPage = generateOAuthCallbackPage({
|
|
4223
4534
|
title: "Session Expired",
|
|
@@ -4234,8 +4545,8 @@ app17.openapi(
|
|
|
4234
4545
|
if (!tool) {
|
|
4235
4546
|
throw new Error(`Tool ${toolId} not found`);
|
|
4236
4547
|
}
|
|
4237
|
-
|
|
4238
|
-
|
|
4548
|
+
logger6.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
|
|
4549
|
+
logger6.info({ toolId }, "Exchanging authorization code for access token");
|
|
4239
4550
|
const credentialStores = c.get("credentialStores");
|
|
4240
4551
|
const mcpTool = await dbResultToMcpTool(tool, dbClient_default, credentialStores);
|
|
4241
4552
|
const baseUrl = getBaseUrlFromRequest(c);
|
|
@@ -4246,7 +4557,7 @@ app17.openapi(
|
|
|
4246
4557
|
tool: mcpTool,
|
|
4247
4558
|
baseUrl
|
|
4248
4559
|
});
|
|
4249
|
-
|
|
4560
|
+
logger6.info(
|
|
4250
4561
|
{ toolId, tokenType: tokens.token_type, hasRefresh: !!tokens.refresh_token },
|
|
4251
4562
|
"Token exchange successful"
|
|
4252
4563
|
);
|
|
@@ -4293,7 +4604,7 @@ app17.openapi(
|
|
|
4293
4604
|
credentialReferenceId: newCredential.id
|
|
4294
4605
|
}
|
|
4295
4606
|
});
|
|
4296
|
-
|
|
4607
|
+
logger6.info({ toolId, credentialId: newCredential.id }, "OAuth flow completed successfully");
|
|
4297
4608
|
const successPage = generateOAuthCallbackPage({
|
|
4298
4609
|
title: "Authentication Complete",
|
|
4299
4610
|
message: "You have been successfully authenticated.",
|
|
@@ -4301,7 +4612,7 @@ app17.openapi(
|
|
|
4301
4612
|
});
|
|
4302
4613
|
return c.html(successPage);
|
|
4303
4614
|
} catch (error) {
|
|
4304
|
-
|
|
4615
|
+
logger6.error({ error }, "OAuth callback processing failed");
|
|
4305
4616
|
const errorMessage = "OAuth Processing Failed. Please try again.";
|
|
4306
4617
|
const errorPage = generateOAuthCallbackPage({
|
|
4307
4618
|
title: "Processing Failed",
|
|
@@ -4312,9 +4623,9 @@ app17.openapi(
|
|
|
4312
4623
|
}
|
|
4313
4624
|
}
|
|
4314
4625
|
);
|
|
4315
|
-
var oauth_default =
|
|
4316
|
-
var
|
|
4317
|
-
var
|
|
4626
|
+
var oauth_default = app18;
|
|
4627
|
+
var logger7 = getLogger("projectFull");
|
|
4628
|
+
var app19 = new OpenAPIHono();
|
|
4318
4629
|
var ProjectIdParamsSchema = z.object({
|
|
4319
4630
|
tenantId: z.string().openapi({
|
|
4320
4631
|
description: "Tenant identifier",
|
|
@@ -4331,7 +4642,7 @@ var TenantParamsSchema2 = z.object({
|
|
|
4331
4642
|
example: "tenant_123"
|
|
4332
4643
|
})
|
|
4333
4644
|
}).openapi("TenantParams");
|
|
4334
|
-
|
|
4645
|
+
app19.openapi(
|
|
4335
4646
|
createRoute({
|
|
4336
4647
|
method: "post",
|
|
4337
4648
|
path: "/project-full",
|
|
@@ -4374,7 +4685,7 @@ app18.openapi(
|
|
|
4374
4685
|
const projectData = c.req.valid("json");
|
|
4375
4686
|
const validatedProjectData = FullProjectDefinitionSchema.parse(projectData);
|
|
4376
4687
|
try {
|
|
4377
|
-
const createdProject = await createFullProjectServerSide(dbClient_default,
|
|
4688
|
+
const createdProject = await createFullProjectServerSide(dbClient_default, logger7)(
|
|
4378
4689
|
{ tenantId, projectId: validatedProjectData.id },
|
|
4379
4690
|
validatedProjectData
|
|
4380
4691
|
);
|
|
@@ -4390,7 +4701,7 @@ app18.openapi(
|
|
|
4390
4701
|
}
|
|
4391
4702
|
}
|
|
4392
4703
|
);
|
|
4393
|
-
|
|
4704
|
+
app19.openapi(
|
|
4394
4705
|
createRoute({
|
|
4395
4706
|
method: "get",
|
|
4396
4707
|
path: "/project-full/{projectId}",
|
|
@@ -4418,7 +4729,7 @@ app18.openapi(
|
|
|
4418
4729
|
try {
|
|
4419
4730
|
const project = await getFullProject(
|
|
4420
4731
|
dbClient_default,
|
|
4421
|
-
|
|
4732
|
+
logger7
|
|
4422
4733
|
)({
|
|
4423
4734
|
scopes: { tenantId, projectId }
|
|
4424
4735
|
});
|
|
@@ -4443,7 +4754,7 @@ app18.openapi(
|
|
|
4443
4754
|
}
|
|
4444
4755
|
}
|
|
4445
4756
|
);
|
|
4446
|
-
|
|
4757
|
+
app19.openapi(
|
|
4447
4758
|
createRoute({
|
|
4448
4759
|
method: "put",
|
|
4449
4760
|
path: "/project-full/{projectId}",
|
|
@@ -4494,15 +4805,15 @@ app18.openapi(
|
|
|
4494
4805
|
}
|
|
4495
4806
|
const existingProject = await getFullProject(
|
|
4496
4807
|
dbClient_default,
|
|
4497
|
-
|
|
4808
|
+
logger7
|
|
4498
4809
|
)({
|
|
4499
4810
|
scopes: { tenantId, projectId }
|
|
4500
4811
|
});
|
|
4501
4812
|
const isCreate = !existingProject;
|
|
4502
|
-
const updatedProject = isCreate ? await createFullProjectServerSide(dbClient_default,
|
|
4813
|
+
const updatedProject = isCreate ? await createFullProjectServerSide(dbClient_default, logger7)(
|
|
4503
4814
|
{ tenantId, projectId },
|
|
4504
4815
|
validatedProjectData
|
|
4505
|
-
) : await updateFullProjectServerSide(dbClient_default,
|
|
4816
|
+
) : await updateFullProjectServerSide(dbClient_default, logger7)(
|
|
4506
4817
|
{ tenantId, projectId },
|
|
4507
4818
|
validatedProjectData
|
|
4508
4819
|
);
|
|
@@ -4527,7 +4838,7 @@ app18.openapi(
|
|
|
4527
4838
|
}
|
|
4528
4839
|
}
|
|
4529
4840
|
);
|
|
4530
|
-
|
|
4841
|
+
app19.openapi(
|
|
4531
4842
|
createRoute({
|
|
4532
4843
|
method: "delete",
|
|
4533
4844
|
path: "/project-full/{projectId}",
|
|
@@ -4550,7 +4861,7 @@ app18.openapi(
|
|
|
4550
4861
|
try {
|
|
4551
4862
|
const deleted = await deleteFullProject(
|
|
4552
4863
|
dbClient_default,
|
|
4553
|
-
|
|
4864
|
+
logger7
|
|
4554
4865
|
)({
|
|
4555
4866
|
scopes: { tenantId, projectId }
|
|
4556
4867
|
});
|
|
@@ -4575,20 +4886,20 @@ app18.openapi(
|
|
|
4575
4886
|
}
|
|
4576
4887
|
}
|
|
4577
4888
|
);
|
|
4578
|
-
var projectFull_default =
|
|
4889
|
+
var projectFull_default = app19;
|
|
4579
4890
|
|
|
4580
4891
|
// src/app.ts
|
|
4581
|
-
var
|
|
4582
|
-
|
|
4892
|
+
var logger8 = getLogger("agents-manage-api");
|
|
4893
|
+
logger8.info({ logger: logger8.getTransports() }, "Logger initialized");
|
|
4583
4894
|
function createManagementHono(serverConfig, credentialStores) {
|
|
4584
|
-
const
|
|
4585
|
-
|
|
4586
|
-
|
|
4895
|
+
const app21 = new OpenAPIHono();
|
|
4896
|
+
app21.use("*", requestId());
|
|
4897
|
+
app21.use("*", async (c, next) => {
|
|
4587
4898
|
c.set("serverConfig", serverConfig);
|
|
4588
4899
|
c.set("credentialStores", credentialStores);
|
|
4589
4900
|
return next();
|
|
4590
4901
|
});
|
|
4591
|
-
|
|
4902
|
+
app21.use(
|
|
4592
4903
|
pinoLogger({
|
|
4593
4904
|
pino: getLogger("agents-manage-api").getPinoInstance(),
|
|
4594
4905
|
http: {
|
|
@@ -4601,7 +4912,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4601
4912
|
}
|
|
4602
4913
|
})
|
|
4603
4914
|
);
|
|
4604
|
-
|
|
4915
|
+
app21.onError(async (err, c) => {
|
|
4605
4916
|
const isExpectedError = err instanceof HTTPException;
|
|
4606
4917
|
const status = isExpectedError ? err.status : 500;
|
|
4607
4918
|
const requestId2 = c.get("requestId") || "unknown";
|
|
@@ -4634,7 +4945,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4634
4945
|
if (!isExpectedError) {
|
|
4635
4946
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
4636
4947
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
4637
|
-
|
|
4948
|
+
logger8.error(
|
|
4638
4949
|
{
|
|
4639
4950
|
error: err,
|
|
4640
4951
|
message: errorMessage,
|
|
@@ -4645,7 +4956,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4645
4956
|
"Unexpected server error occurred"
|
|
4646
4957
|
);
|
|
4647
4958
|
} else {
|
|
4648
|
-
|
|
4959
|
+
logger8.error(
|
|
4649
4960
|
{
|
|
4650
4961
|
error: err,
|
|
4651
4962
|
path: c.req.path,
|
|
@@ -4661,7 +4972,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4661
4972
|
const response = err.getResponse();
|
|
4662
4973
|
return response;
|
|
4663
4974
|
} catch (responseError) {
|
|
4664
|
-
|
|
4975
|
+
logger8.error({ error: responseError }, "Error while handling HTTPException response");
|
|
4665
4976
|
}
|
|
4666
4977
|
}
|
|
4667
4978
|
const { status: respStatus, title, detail, instance } = await handleApiError(err, requestId2);
|
|
@@ -4676,7 +4987,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4676
4987
|
...instance && { instance }
|
|
4677
4988
|
});
|
|
4678
4989
|
});
|
|
4679
|
-
|
|
4990
|
+
app21.use(
|
|
4680
4991
|
"*",
|
|
4681
4992
|
cors({
|
|
4682
4993
|
origin: (origin) => {
|
|
@@ -4690,7 +5001,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4690
5001
|
credentials: true
|
|
4691
5002
|
})
|
|
4692
5003
|
);
|
|
4693
|
-
|
|
5004
|
+
app21.openapi(
|
|
4694
5005
|
createRoute({
|
|
4695
5006
|
method: "get",
|
|
4696
5007
|
path: "/health",
|
|
@@ -4707,13 +5018,13 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4707
5018
|
return c.body(null, 204);
|
|
4708
5019
|
}
|
|
4709
5020
|
);
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
setupOpenAPIRoutes(
|
|
5021
|
+
app21.use("/tenants/*", apiKeyAuth());
|
|
5022
|
+
app21.route("/tenants/:tenantId", routes_default);
|
|
5023
|
+
app21.route("/tenants/:tenantId", projectFull_default);
|
|
5024
|
+
app21.route("/oauth", oauth_default);
|
|
5025
|
+
setupOpenAPIRoutes(app21);
|
|
4715
5026
|
const baseApp = new Hono();
|
|
4716
|
-
baseApp.route("/",
|
|
5027
|
+
baseApp.route("/", app21);
|
|
4717
5028
|
return baseApp;
|
|
4718
5029
|
}
|
|
4719
5030
|
|
|
@@ -4729,8 +5040,8 @@ var defaultConfig = {
|
|
|
4729
5040
|
};
|
|
4730
5041
|
var defaultStores = createDefaultCredentialStores();
|
|
4731
5042
|
var defaultRegistry = new CredentialStoreRegistry(defaultStores);
|
|
4732
|
-
var
|
|
4733
|
-
var index_default =
|
|
5043
|
+
var app20 = createManagementHono(defaultConfig, defaultRegistry);
|
|
5044
|
+
var index_default = app20;
|
|
4734
5045
|
function createManagementApp(config) {
|
|
4735
5046
|
const serverConfig = config?.serverConfig ?? defaultConfig;
|
|
4736
5047
|
const stores = config?.credentialStores ?? defaultStores;
|