@inkeep/agents-manage-api 0.14.16 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +448 -133
- package/dist/index.js +449 -134
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -70,10 +70,10 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
70
70
|
await next();
|
|
71
71
|
return;
|
|
72
72
|
});
|
|
73
|
-
function setupOpenAPIRoutes(
|
|
74
|
-
|
|
73
|
+
function setupOpenAPIRoutes(app21) {
|
|
74
|
+
app21.get("/openapi.json", (c) => {
|
|
75
75
|
try {
|
|
76
|
-
const document =
|
|
76
|
+
const document = app21.getOpenAPIDocument({
|
|
77
77
|
openapi: "3.0.0",
|
|
78
78
|
info: {
|
|
79
79
|
title: "Inkeep Agents Manage API",
|
|
@@ -94,7 +94,7 @@ function setupOpenAPIRoutes(app20) {
|
|
|
94
94
|
return c.json({ error: "Failed to generate OpenAPI document", details: errorDetails }, 500);
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
|
-
|
|
97
|
+
app21.get(
|
|
98
98
|
"/docs",
|
|
99
99
|
swaggerUi.swaggerUI({
|
|
100
100
|
url: "/openapi.json",
|
|
@@ -2037,6 +2037,16 @@ app8.openapi(
|
|
|
2037
2037
|
async (c) => {
|
|
2038
2038
|
const { tenantId, projectId } = c.req.valid("param");
|
|
2039
2039
|
const body = c.req.valid("json");
|
|
2040
|
+
if (body.props !== null && body.props !== void 0) {
|
|
2041
|
+
const propsValidation = agentsCore.validatePropsAsJsonSchema(body.props);
|
|
2042
|
+
if (!propsValidation.isValid) {
|
|
2043
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2044
|
+
throw agentsCore.createApiError({
|
|
2045
|
+
code: "bad_request",
|
|
2046
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2040
2050
|
const finalId = body.id ? String(body.id) : nanoid.nanoid();
|
|
2041
2051
|
const componentData = {
|
|
2042
2052
|
tenantId,
|
|
@@ -2044,8 +2054,7 @@ app8.openapi(
|
|
|
2044
2054
|
id: finalId,
|
|
2045
2055
|
name: String(body.name),
|
|
2046
2056
|
description: String(body.description),
|
|
2047
|
-
|
|
2048
|
-
fullProps: body.fullProps || void 0
|
|
2057
|
+
props: body.props ?? null
|
|
2049
2058
|
};
|
|
2050
2059
|
try {
|
|
2051
2060
|
const artifactComponent = await agentsCore.createArtifactComponent(dbClient_default)({
|
|
@@ -2095,15 +2104,30 @@ app8.openapi(
|
|
|
2095
2104
|
async (c) => {
|
|
2096
2105
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2097
2106
|
const body = c.req.valid("json");
|
|
2107
|
+
if (body.props !== void 0 && body.props !== null) {
|
|
2108
|
+
const propsValidation = agentsCore.validatePropsAsJsonSchema(body.props);
|
|
2109
|
+
if (!propsValidation.isValid) {
|
|
2110
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2111
|
+
throw agentsCore.createApiError({
|
|
2112
|
+
code: "bad_request",
|
|
2113
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
const updateData = {};
|
|
2118
|
+
if (body.name !== void 0) {
|
|
2119
|
+
updateData.name = String(body.name);
|
|
2120
|
+
}
|
|
2121
|
+
if (body.description !== void 0) {
|
|
2122
|
+
updateData.description = String(body.description);
|
|
2123
|
+
}
|
|
2124
|
+
if (body.props !== void 0) {
|
|
2125
|
+
updateData.props = body.props ?? null;
|
|
2126
|
+
}
|
|
2098
2127
|
const updatedArtifactComponent = await agentsCore.updateArtifactComponent(dbClient_default)({
|
|
2099
2128
|
scopes: { tenantId, projectId },
|
|
2100
2129
|
id,
|
|
2101
|
-
data:
|
|
2102
|
-
name: body.name ? String(body.name) : void 0,
|
|
2103
|
-
description: body.description ? String(body.description) : void 0,
|
|
2104
|
-
summaryProps: body.summaryProps || void 0,
|
|
2105
|
-
fullProps: body.fullProps || void 0
|
|
2106
|
-
}
|
|
2130
|
+
data: updateData
|
|
2107
2131
|
});
|
|
2108
2132
|
if (!updatedArtifactComponent) {
|
|
2109
2133
|
throw agentsCore.createApiError({
|
|
@@ -2163,7 +2187,7 @@ app9.openapi(
|
|
|
2163
2187
|
operationId: "list-context-configs",
|
|
2164
2188
|
tags: ["Context Config"],
|
|
2165
2189
|
request: {
|
|
2166
|
-
params: agentsCore.
|
|
2190
|
+
params: agentsCore.TenantProjectGraphParamsSchema,
|
|
2167
2191
|
query: agentsCore.PaginationQueryParamsSchema
|
|
2168
2192
|
},
|
|
2169
2193
|
responses: {
|
|
@@ -2179,11 +2203,11 @@ app9.openapi(
|
|
|
2179
2203
|
}
|
|
2180
2204
|
}),
|
|
2181
2205
|
async (c) => {
|
|
2182
|
-
const { tenantId, projectId } = c.req.valid("param");
|
|
2206
|
+
const { tenantId, projectId, graphId } = c.req.valid("param");
|
|
2183
2207
|
const page = Number(c.req.query("page")) || 1;
|
|
2184
2208
|
const limit = Math.min(Number(c.req.query("limit")) || 10, 100);
|
|
2185
2209
|
const result = await agentsCore.listContextConfigsPaginated(dbClient_default)({
|
|
2186
|
-
scopes: { tenantId, projectId },
|
|
2210
|
+
scopes: { tenantId, projectId, graphId },
|
|
2187
2211
|
pagination: { page, limit }
|
|
2188
2212
|
});
|
|
2189
2213
|
return c.json(result);
|
|
@@ -2197,7 +2221,7 @@ app9.openapi(
|
|
|
2197
2221
|
operationId: "get-context-config-by-id",
|
|
2198
2222
|
tags: ["Context Config"],
|
|
2199
2223
|
request: {
|
|
2200
|
-
params: agentsCore.
|
|
2224
|
+
params: agentsCore.TenantProjectGraphParamsSchema.merge(agentsCore.IdParamsSchema)
|
|
2201
2225
|
},
|
|
2202
2226
|
responses: {
|
|
2203
2227
|
200: {
|
|
@@ -2212,9 +2236,9 @@ app9.openapi(
|
|
|
2212
2236
|
}
|
|
2213
2237
|
}),
|
|
2214
2238
|
async (c) => {
|
|
2215
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2239
|
+
const { tenantId, projectId, graphId, id } = c.req.valid("param");
|
|
2216
2240
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
2217
|
-
scopes: { tenantId, projectId },
|
|
2241
|
+
scopes: { tenantId, projectId, graphId },
|
|
2218
2242
|
id
|
|
2219
2243
|
});
|
|
2220
2244
|
if (!contextConfig) {
|
|
@@ -2234,7 +2258,7 @@ app9.openapi(
|
|
|
2234
2258
|
operationId: "create-context-config",
|
|
2235
2259
|
tags: ["Context Config"],
|
|
2236
2260
|
request: {
|
|
2237
|
-
params: agentsCore.
|
|
2261
|
+
params: agentsCore.TenantProjectGraphParamsSchema,
|
|
2238
2262
|
body: {
|
|
2239
2263
|
content: {
|
|
2240
2264
|
"application/json": {
|
|
@@ -2256,11 +2280,12 @@ app9.openapi(
|
|
|
2256
2280
|
}
|
|
2257
2281
|
}),
|
|
2258
2282
|
async (c) => {
|
|
2259
|
-
const { tenantId, projectId } = c.req.valid("param");
|
|
2283
|
+
const { tenantId, projectId, graphId } = c.req.valid("param");
|
|
2260
2284
|
const body = c.req.valid("json");
|
|
2261
2285
|
const configData = {
|
|
2262
2286
|
tenantId,
|
|
2263
2287
|
projectId,
|
|
2288
|
+
graphId,
|
|
2264
2289
|
...body
|
|
2265
2290
|
};
|
|
2266
2291
|
const contextConfig = await agentsCore.createContextConfig(dbClient_default)(configData);
|
|
@@ -2275,7 +2300,7 @@ app9.openapi(
|
|
|
2275
2300
|
operationId: "update-context-config",
|
|
2276
2301
|
tags: ["Context Config"],
|
|
2277
2302
|
request: {
|
|
2278
|
-
params: agentsCore.
|
|
2303
|
+
params: agentsCore.TenantProjectGraphParamsSchema.merge(agentsCore.IdParamsSchema),
|
|
2279
2304
|
body: {
|
|
2280
2305
|
content: {
|
|
2281
2306
|
"application/json": {
|
|
@@ -2297,10 +2322,10 @@ app9.openapi(
|
|
|
2297
2322
|
}
|
|
2298
2323
|
}),
|
|
2299
2324
|
async (c) => {
|
|
2300
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2325
|
+
const { tenantId, projectId, graphId, id } = c.req.valid("param");
|
|
2301
2326
|
const body = c.req.valid("json");
|
|
2302
2327
|
const updatedContextConfig = await agentsCore.updateContextConfig(dbClient_default)({
|
|
2303
|
-
scopes: { tenantId, projectId },
|
|
2328
|
+
scopes: { tenantId, projectId, graphId },
|
|
2304
2329
|
id,
|
|
2305
2330
|
data: body
|
|
2306
2331
|
});
|
|
@@ -2321,7 +2346,7 @@ app9.openapi(
|
|
|
2321
2346
|
operationId: "delete-context-config",
|
|
2322
2347
|
tags: ["Context Config"],
|
|
2323
2348
|
request: {
|
|
2324
|
-
params: agentsCore.
|
|
2349
|
+
params: agentsCore.TenantProjectGraphParamsSchema.merge(agentsCore.IdParamsSchema)
|
|
2325
2350
|
},
|
|
2326
2351
|
responses: {
|
|
2327
2352
|
204: {
|
|
@@ -2331,9 +2356,9 @@ app9.openapi(
|
|
|
2331
2356
|
}
|
|
2332
2357
|
}),
|
|
2333
2358
|
async (c) => {
|
|
2334
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2359
|
+
const { tenantId, projectId, graphId, id } = c.req.valid("param");
|
|
2335
2360
|
const deleted = await agentsCore.deleteContextConfig(dbClient_default)({
|
|
2336
|
-
scopes: { tenantId, projectId },
|
|
2361
|
+
scopes: { tenantId, projectId, graphId },
|
|
2337
2362
|
id
|
|
2338
2363
|
});
|
|
2339
2364
|
if (!deleted) {
|
|
@@ -2685,6 +2710,16 @@ app11.openapi(
|
|
|
2685
2710
|
async (c) => {
|
|
2686
2711
|
const { tenantId, projectId } = c.req.valid("param");
|
|
2687
2712
|
const body = c.req.valid("json");
|
|
2713
|
+
if (body.props) {
|
|
2714
|
+
const propsValidation = agentsCore.validatePropsAsJsonSchema(body.props);
|
|
2715
|
+
if (!propsValidation.isValid) {
|
|
2716
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2717
|
+
throw agentsCore.createApiError({
|
|
2718
|
+
code: "bad_request",
|
|
2719
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2688
2723
|
const dataComponentData = {
|
|
2689
2724
|
...body,
|
|
2690
2725
|
tenantId,
|
|
@@ -2726,6 +2761,16 @@ app11.openapi(
|
|
|
2726
2761
|
async (c) => {
|
|
2727
2762
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
2728
2763
|
const body = c.req.valid("json");
|
|
2764
|
+
if (body.props !== void 0 && body.props !== null) {
|
|
2765
|
+
const propsValidation = agentsCore.validatePropsAsJsonSchema(body.props);
|
|
2766
|
+
if (!propsValidation.isValid) {
|
|
2767
|
+
const errorMessages = propsValidation.errors.map((e) => `${e.field}: ${e.message}`).join(", ");
|
|
2768
|
+
throw agentsCore.createApiError({
|
|
2769
|
+
code: "bad_request",
|
|
2770
|
+
message: `Invalid props schema: ${errorMessages}`
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2729
2774
|
const updatedDataComponent = await agentsCore.updateDataComponent(dbClient_default)({
|
|
2730
2775
|
scopes: { tenantId, projectId },
|
|
2731
2776
|
dataComponentId: id,
|
|
@@ -3003,8 +3048,268 @@ app12.openapi(
|
|
|
3003
3048
|
}
|
|
3004
3049
|
);
|
|
3005
3050
|
var externalAgents_default = app12;
|
|
3006
|
-
var logger2 = agentsCore.getLogger("
|
|
3051
|
+
var logger2 = agentsCore.getLogger("functions");
|
|
3007
3052
|
var app13 = new zodOpenapi.OpenAPIHono();
|
|
3053
|
+
app13.openapi(
|
|
3054
|
+
zodOpenapi.createRoute({
|
|
3055
|
+
method: "get",
|
|
3056
|
+
path: "/",
|
|
3057
|
+
summary: "List Functions",
|
|
3058
|
+
operationId: "list-functions",
|
|
3059
|
+
tags: ["Functions"],
|
|
3060
|
+
request: {
|
|
3061
|
+
params: agentsCore.TenantProjectParamsSchema,
|
|
3062
|
+
query: agentsCore.PaginationQueryParamsSchema
|
|
3063
|
+
},
|
|
3064
|
+
responses: {
|
|
3065
|
+
200: {
|
|
3066
|
+
description: "List of functions",
|
|
3067
|
+
content: {
|
|
3068
|
+
"application/json": {
|
|
3069
|
+
schema: agentsCore.ListResponseSchema(agentsCore.FunctionApiSelectSchema)
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
},
|
|
3073
|
+
...agentsCore.commonGetErrorResponses
|
|
3074
|
+
}
|
|
3075
|
+
}),
|
|
3076
|
+
async (c) => {
|
|
3077
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
3078
|
+
try {
|
|
3079
|
+
const functions = await agentsCore.listFunctions(dbClient_default)({ scopes: { tenantId, projectId } });
|
|
3080
|
+
return c.json({
|
|
3081
|
+
data: functions,
|
|
3082
|
+
pagination: {
|
|
3083
|
+
page: 1,
|
|
3084
|
+
limit: functions.length,
|
|
3085
|
+
total: functions.length,
|
|
3086
|
+
pages: 1
|
|
3087
|
+
}
|
|
3088
|
+
});
|
|
3089
|
+
} catch (error) {
|
|
3090
|
+
logger2.error({ error, tenantId }, "Failed to list functions");
|
|
3091
|
+
return c.json(
|
|
3092
|
+
agentsCore.createApiError({ code: "internal_server_error", message: "Failed to list functions" }),
|
|
3093
|
+
500
|
|
3094
|
+
);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
);
|
|
3098
|
+
app13.openapi(
|
|
3099
|
+
zodOpenapi.createRoute({
|
|
3100
|
+
method: "get",
|
|
3101
|
+
path: "/{id}",
|
|
3102
|
+
summary: "Get Function by ID",
|
|
3103
|
+
operationId: "get-function",
|
|
3104
|
+
tags: ["Functions"],
|
|
3105
|
+
request: {
|
|
3106
|
+
params: agentsCore.TenantProjectParamsSchema.merge(agentsCore.IdParamsSchema)
|
|
3107
|
+
},
|
|
3108
|
+
responses: {
|
|
3109
|
+
200: {
|
|
3110
|
+
description: "Function details",
|
|
3111
|
+
content: {
|
|
3112
|
+
"application/json": {
|
|
3113
|
+
schema: agentsCore.SingleResponseSchema(agentsCore.FunctionApiSelectSchema)
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
},
|
|
3117
|
+
...agentsCore.commonGetErrorResponses
|
|
3118
|
+
}
|
|
3119
|
+
}),
|
|
3120
|
+
async (c) => {
|
|
3121
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
3122
|
+
try {
|
|
3123
|
+
const functionData = await agentsCore.getFunction(dbClient_default)({
|
|
3124
|
+
functionId: id,
|
|
3125
|
+
scopes: { tenantId, projectId }
|
|
3126
|
+
});
|
|
3127
|
+
if (!functionData) {
|
|
3128
|
+
return c.json(
|
|
3129
|
+
agentsCore.createApiError({ code: "not_found", message: "Function not found" }),
|
|
3130
|
+
404
|
|
3131
|
+
);
|
|
3132
|
+
}
|
|
3133
|
+
return c.json({ data: functionData });
|
|
3134
|
+
} catch (error) {
|
|
3135
|
+
logger2.error({ error, tenantId, id }, "Failed to get function");
|
|
3136
|
+
return c.json(
|
|
3137
|
+
agentsCore.createApiError({ code: "internal_server_error", message: "Failed to get function" }),
|
|
3138
|
+
500
|
|
3139
|
+
);
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
);
|
|
3143
|
+
app13.openapi(
|
|
3144
|
+
zodOpenapi.createRoute({
|
|
3145
|
+
method: "post",
|
|
3146
|
+
path: "/",
|
|
3147
|
+
summary: "Create Function",
|
|
3148
|
+
operationId: "create-function",
|
|
3149
|
+
tags: ["Functions"],
|
|
3150
|
+
request: {
|
|
3151
|
+
params: agentsCore.TenantProjectParamsSchema,
|
|
3152
|
+
body: {
|
|
3153
|
+
content: {
|
|
3154
|
+
"application/json": {
|
|
3155
|
+
schema: agentsCore.FunctionApiInsertSchema
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
},
|
|
3160
|
+
responses: {
|
|
3161
|
+
201: {
|
|
3162
|
+
description: "Function created",
|
|
3163
|
+
content: {
|
|
3164
|
+
"application/json": {
|
|
3165
|
+
schema: agentsCore.SingleResponseSchema(agentsCore.FunctionApiSelectSchema)
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
},
|
|
3169
|
+
...agentsCore.commonGetErrorResponses
|
|
3170
|
+
}
|
|
3171
|
+
}),
|
|
3172
|
+
async (c) => {
|
|
3173
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
3174
|
+
const functionData = c.req.valid("json");
|
|
3175
|
+
try {
|
|
3176
|
+
const id = functionData.id || nanoid.nanoid();
|
|
3177
|
+
await agentsCore.upsertFunction(dbClient_default)({
|
|
3178
|
+
data: {
|
|
3179
|
+
...functionData,
|
|
3180
|
+
id
|
|
3181
|
+
},
|
|
3182
|
+
scopes: { tenantId, projectId }
|
|
3183
|
+
});
|
|
3184
|
+
const created = await agentsCore.getFunction(dbClient_default)({
|
|
3185
|
+
functionId: id,
|
|
3186
|
+
scopes: { tenantId, projectId }
|
|
3187
|
+
});
|
|
3188
|
+
logger2.info({ tenantId, functionId: id }, "Function created");
|
|
3189
|
+
return c.json({ data: created }, 201);
|
|
3190
|
+
} catch (error) {
|
|
3191
|
+
logger2.error({ error, tenantId, functionData }, "Failed to create function");
|
|
3192
|
+
return c.json(
|
|
3193
|
+
agentsCore.createApiError({ code: "internal_server_error", message: "Failed to create function" }),
|
|
3194
|
+
500
|
|
3195
|
+
);
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
);
|
|
3199
|
+
app13.openapi(
|
|
3200
|
+
zodOpenapi.createRoute({
|
|
3201
|
+
method: "put",
|
|
3202
|
+
path: "/{id}",
|
|
3203
|
+
summary: "Update Function",
|
|
3204
|
+
operationId: "update-function",
|
|
3205
|
+
tags: ["Functions"],
|
|
3206
|
+
request: {
|
|
3207
|
+
params: agentsCore.TenantProjectParamsSchema.merge(agentsCore.IdParamsSchema),
|
|
3208
|
+
body: {
|
|
3209
|
+
content: {
|
|
3210
|
+
"application/json": {
|
|
3211
|
+
schema: agentsCore.FunctionApiUpdateSchema
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
},
|
|
3216
|
+
responses: {
|
|
3217
|
+
200: {
|
|
3218
|
+
description: "Function updated",
|
|
3219
|
+
content: {
|
|
3220
|
+
"application/json": {
|
|
3221
|
+
schema: agentsCore.SingleResponseSchema(agentsCore.FunctionApiSelectSchema)
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
},
|
|
3225
|
+
...agentsCore.commonGetErrorResponses
|
|
3226
|
+
}
|
|
3227
|
+
}),
|
|
3228
|
+
async (c) => {
|
|
3229
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
3230
|
+
const updateData = c.req.valid("json");
|
|
3231
|
+
try {
|
|
3232
|
+
const existing = await agentsCore.getFunction(dbClient_default)({
|
|
3233
|
+
functionId: id,
|
|
3234
|
+
scopes: { tenantId, projectId }
|
|
3235
|
+
});
|
|
3236
|
+
if (!existing) {
|
|
3237
|
+
return c.json(
|
|
3238
|
+
agentsCore.createApiError({ code: "not_found", message: "Function not found" }),
|
|
3239
|
+
404
|
|
3240
|
+
);
|
|
3241
|
+
}
|
|
3242
|
+
await agentsCore.upsertFunction(dbClient_default)({
|
|
3243
|
+
data: {
|
|
3244
|
+
...existing,
|
|
3245
|
+
...updateData,
|
|
3246
|
+
id
|
|
3247
|
+
},
|
|
3248
|
+
scopes: { tenantId, projectId }
|
|
3249
|
+
});
|
|
3250
|
+
const updated = await agentsCore.getFunction(dbClient_default)({
|
|
3251
|
+
functionId: id,
|
|
3252
|
+
scopes: { tenantId, projectId }
|
|
3253
|
+
});
|
|
3254
|
+
logger2.info({ tenantId, functionId: id }, "Function updated");
|
|
3255
|
+
return c.json({ data: updated });
|
|
3256
|
+
} catch (error) {
|
|
3257
|
+
logger2.error({ error, tenantId, id, updateData }, "Failed to update function");
|
|
3258
|
+
return c.json(
|
|
3259
|
+
agentsCore.createApiError({ code: "internal_server_error", message: "Failed to update function" }),
|
|
3260
|
+
500
|
|
3261
|
+
);
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
);
|
|
3265
|
+
app13.openapi(
|
|
3266
|
+
zodOpenapi.createRoute({
|
|
3267
|
+
method: "delete",
|
|
3268
|
+
path: "/{id}",
|
|
3269
|
+
summary: "Delete Function",
|
|
3270
|
+
operationId: "delete-function",
|
|
3271
|
+
tags: ["Functions"],
|
|
3272
|
+
request: {
|
|
3273
|
+
params: agentsCore.TenantProjectParamsSchema.merge(agentsCore.IdParamsSchema)
|
|
3274
|
+
},
|
|
3275
|
+
responses: {
|
|
3276
|
+
204: {
|
|
3277
|
+
description: "Function deleted"
|
|
3278
|
+
},
|
|
3279
|
+
...agentsCore.commonGetErrorResponses
|
|
3280
|
+
}
|
|
3281
|
+
}),
|
|
3282
|
+
async (c) => {
|
|
3283
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
3284
|
+
try {
|
|
3285
|
+
const existing = await agentsCore.getFunction(dbClient_default)({
|
|
3286
|
+
functionId: id,
|
|
3287
|
+
scopes: { tenantId, projectId }
|
|
3288
|
+
});
|
|
3289
|
+
if (!existing) {
|
|
3290
|
+
return c.json(
|
|
3291
|
+
agentsCore.createApiError({ code: "not_found", message: "Function not found" }),
|
|
3292
|
+
404
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
await agentsCore.deleteFunction(dbClient_default)({
|
|
3296
|
+
functionId: id,
|
|
3297
|
+
scopes: { tenantId, projectId }
|
|
3298
|
+
});
|
|
3299
|
+
logger2.info({ tenantId, functionId: id }, "Function deleted");
|
|
3300
|
+
return c.body(null, 204);
|
|
3301
|
+
} catch (error) {
|
|
3302
|
+
logger2.error({ error, tenantId, id }, "Failed to delete function");
|
|
3303
|
+
return c.json(
|
|
3304
|
+
agentsCore.createApiError({ code: "internal_server_error", message: "Failed to delete function" }),
|
|
3305
|
+
500
|
|
3306
|
+
);
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
);
|
|
3310
|
+
var functions_default = app13;
|
|
3311
|
+
var logger3 = agentsCore.getLogger("graphFull");
|
|
3312
|
+
var app14 = new zodOpenapi.OpenAPIHono();
|
|
3008
3313
|
var GraphIdParamsSchema = zod.z.object({
|
|
3009
3314
|
tenantId: zod.z.string().openapi({
|
|
3010
3315
|
description: "Tenant identifier",
|
|
@@ -3019,7 +3324,7 @@ var GraphIdParamsSchema = zod.z.object({
|
|
|
3019
3324
|
example: "graph_789"
|
|
3020
3325
|
})
|
|
3021
3326
|
}).openapi("GraphIdParams");
|
|
3022
|
-
|
|
3327
|
+
app14.openapi(
|
|
3023
3328
|
zodOpenapi.createRoute({
|
|
3024
3329
|
method: "post",
|
|
3025
3330
|
path: "/",
|
|
@@ -3061,14 +3366,14 @@ app13.openapi(
|
|
|
3061
3366
|
const { tenantId, projectId } = c.req.valid("param");
|
|
3062
3367
|
const graphData = c.req.valid("json");
|
|
3063
3368
|
const validatedGraphData = agentsCore.FullGraphDefinitionSchema.parse(graphData);
|
|
3064
|
-
const createdGraph = await agentsCore.createFullGraphServerSide(dbClient_default,
|
|
3369
|
+
const createdGraph = await agentsCore.createFullGraphServerSide(dbClient_default, logger3)(
|
|
3065
3370
|
{ tenantId, projectId },
|
|
3066
3371
|
validatedGraphData
|
|
3067
3372
|
);
|
|
3068
3373
|
return c.json({ data: createdGraph }, 201);
|
|
3069
3374
|
}
|
|
3070
3375
|
);
|
|
3071
|
-
|
|
3376
|
+
app14.openapi(
|
|
3072
3377
|
zodOpenapi.createRoute({
|
|
3073
3378
|
method: "get",
|
|
3074
3379
|
path: "/{graphId}",
|
|
@@ -3096,7 +3401,7 @@ app13.openapi(
|
|
|
3096
3401
|
try {
|
|
3097
3402
|
const graph = await agentsCore.getFullGraph(
|
|
3098
3403
|
dbClient_default,
|
|
3099
|
-
|
|
3404
|
+
logger3
|
|
3100
3405
|
)({
|
|
3101
3406
|
scopes: { tenantId, projectId, graphId }
|
|
3102
3407
|
});
|
|
@@ -3121,7 +3426,7 @@ app13.openapi(
|
|
|
3121
3426
|
}
|
|
3122
3427
|
}
|
|
3123
3428
|
);
|
|
3124
|
-
|
|
3429
|
+
app14.openapi(
|
|
3125
3430
|
zodOpenapi.createRoute({
|
|
3126
3431
|
method: "put",
|
|
3127
3432
|
path: "/{graphId}",
|
|
@@ -3172,15 +3477,15 @@ app13.openapi(
|
|
|
3172
3477
|
}
|
|
3173
3478
|
const existingGraph = await agentsCore.getFullGraph(
|
|
3174
3479
|
dbClient_default,
|
|
3175
|
-
|
|
3480
|
+
logger3
|
|
3176
3481
|
)({
|
|
3177
3482
|
scopes: { tenantId, projectId, graphId }
|
|
3178
3483
|
});
|
|
3179
3484
|
const isCreate = !existingGraph;
|
|
3180
|
-
const updatedGraph = isCreate ? await agentsCore.createFullGraphServerSide(dbClient_default,
|
|
3485
|
+
const updatedGraph = isCreate ? await agentsCore.createFullGraphServerSide(dbClient_default, logger3)(
|
|
3181
3486
|
{ tenantId, projectId },
|
|
3182
3487
|
validatedGraphData
|
|
3183
|
-
) : await agentsCore.updateFullGraphServerSide(dbClient_default,
|
|
3488
|
+
) : await agentsCore.updateFullGraphServerSide(dbClient_default, logger3)(
|
|
3184
3489
|
{ tenantId, projectId },
|
|
3185
3490
|
validatedGraphData
|
|
3186
3491
|
);
|
|
@@ -3205,7 +3510,7 @@ app13.openapi(
|
|
|
3205
3510
|
}
|
|
3206
3511
|
}
|
|
3207
3512
|
);
|
|
3208
|
-
|
|
3513
|
+
app14.openapi(
|
|
3209
3514
|
zodOpenapi.createRoute({
|
|
3210
3515
|
method: "delete",
|
|
3211
3516
|
path: "/{graphId}",
|
|
@@ -3228,7 +3533,7 @@ app13.openapi(
|
|
|
3228
3533
|
try {
|
|
3229
3534
|
const deleted = await agentsCore.deleteFullGraph(
|
|
3230
3535
|
dbClient_default,
|
|
3231
|
-
|
|
3536
|
+
logger3
|
|
3232
3537
|
)({
|
|
3233
3538
|
scopes: { tenantId, projectId, graphId }
|
|
3234
3539
|
});
|
|
@@ -3253,9 +3558,9 @@ app13.openapi(
|
|
|
3253
3558
|
}
|
|
3254
3559
|
}
|
|
3255
3560
|
);
|
|
3256
|
-
var graphFull_default =
|
|
3257
|
-
var
|
|
3258
|
-
|
|
3561
|
+
var graphFull_default = app14;
|
|
3562
|
+
var app15 = new zodOpenapi.OpenAPIHono();
|
|
3563
|
+
app15.openapi(
|
|
3259
3564
|
zodOpenapi.createRoute({
|
|
3260
3565
|
method: "get",
|
|
3261
3566
|
path: "/",
|
|
@@ -3290,7 +3595,7 @@ app14.openapi(
|
|
|
3290
3595
|
return c.json(result);
|
|
3291
3596
|
}
|
|
3292
3597
|
);
|
|
3293
|
-
|
|
3598
|
+
app15.openapi(
|
|
3294
3599
|
zodOpenapi.createRoute({
|
|
3295
3600
|
method: "get",
|
|
3296
3601
|
path: "/{id}",
|
|
@@ -3325,7 +3630,7 @@ app14.openapi(
|
|
|
3325
3630
|
return c.json({ data: project });
|
|
3326
3631
|
}
|
|
3327
3632
|
);
|
|
3328
|
-
|
|
3633
|
+
app15.openapi(
|
|
3329
3634
|
zodOpenapi.createRoute({
|
|
3330
3635
|
method: "post",
|
|
3331
3636
|
path: "/",
|
|
@@ -3383,7 +3688,7 @@ app14.openapi(
|
|
|
3383
3688
|
}
|
|
3384
3689
|
}
|
|
3385
3690
|
);
|
|
3386
|
-
|
|
3691
|
+
app15.openapi(
|
|
3387
3692
|
zodOpenapi.createRoute({
|
|
3388
3693
|
method: "patch",
|
|
3389
3694
|
path: "/{id}",
|
|
@@ -3429,7 +3734,7 @@ app14.openapi(
|
|
|
3429
3734
|
return c.json({ data: project });
|
|
3430
3735
|
}
|
|
3431
3736
|
);
|
|
3432
|
-
|
|
3737
|
+
app15.openapi(
|
|
3433
3738
|
zodOpenapi.createRoute({
|
|
3434
3739
|
method: "delete",
|
|
3435
3740
|
path: "/{id}",
|
|
@@ -3479,10 +3784,10 @@ app14.openapi(
|
|
|
3479
3784
|
}
|
|
3480
3785
|
}
|
|
3481
3786
|
);
|
|
3482
|
-
var projects_default =
|
|
3483
|
-
var
|
|
3484
|
-
var
|
|
3485
|
-
|
|
3787
|
+
var projects_default = app15;
|
|
3788
|
+
var logger4 = agentsCore.getLogger("tools");
|
|
3789
|
+
var app16 = new zodOpenapi.OpenAPIHono();
|
|
3790
|
+
app16.openapi(
|
|
3486
3791
|
zodOpenapi.createRoute({
|
|
3487
3792
|
method: "get",
|
|
3488
3793
|
path: "/",
|
|
@@ -3542,7 +3847,7 @@ app15.openapi(
|
|
|
3542
3847
|
return c.json(result);
|
|
3543
3848
|
}
|
|
3544
3849
|
);
|
|
3545
|
-
|
|
3850
|
+
app16.openapi(
|
|
3546
3851
|
zodOpenapi.createRoute({
|
|
3547
3852
|
method: "get",
|
|
3548
3853
|
path: "/{id}",
|
|
@@ -3579,7 +3884,7 @@ app15.openapi(
|
|
|
3579
3884
|
});
|
|
3580
3885
|
}
|
|
3581
3886
|
);
|
|
3582
|
-
|
|
3887
|
+
app16.openapi(
|
|
3583
3888
|
zodOpenapi.createRoute({
|
|
3584
3889
|
method: "post",
|
|
3585
3890
|
path: "/",
|
|
@@ -3612,7 +3917,7 @@ app15.openapi(
|
|
|
3612
3917
|
const { tenantId, projectId } = c.req.valid("param");
|
|
3613
3918
|
const body = c.req.valid("json");
|
|
3614
3919
|
const credentialStores = c.get("credentialStores");
|
|
3615
|
-
|
|
3920
|
+
logger4.info({ body }, "body");
|
|
3616
3921
|
const id = body.id || nanoid.nanoid();
|
|
3617
3922
|
const tool = await agentsCore.createTool(dbClient_default)({
|
|
3618
3923
|
tenantId,
|
|
@@ -3632,7 +3937,7 @@ app15.openapi(
|
|
|
3632
3937
|
);
|
|
3633
3938
|
}
|
|
3634
3939
|
);
|
|
3635
|
-
|
|
3940
|
+
app16.openapi(
|
|
3636
3941
|
zodOpenapi.createRoute({
|
|
3637
3942
|
method: "put",
|
|
3638
3943
|
path: "/{id}",
|
|
@@ -3693,7 +3998,7 @@ app15.openapi(
|
|
|
3693
3998
|
});
|
|
3694
3999
|
}
|
|
3695
4000
|
);
|
|
3696
|
-
|
|
4001
|
+
app16.openapi(
|
|
3697
4002
|
zodOpenapi.createRoute({
|
|
3698
4003
|
method: "delete",
|
|
3699
4004
|
path: "/{id}",
|
|
@@ -3729,27 +4034,31 @@ app15.openapi(
|
|
|
3729
4034
|
return c.body(null, 204);
|
|
3730
4035
|
}
|
|
3731
4036
|
);
|
|
3732
|
-
var tools_default =
|
|
4037
|
+
var tools_default = app16;
|
|
3733
4038
|
|
|
3734
4039
|
// src/routes/index.ts
|
|
3735
|
-
var
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
4040
|
+
var app17 = new zodOpenapi.OpenAPIHono();
|
|
4041
|
+
app17.route("/projects", projects_default);
|
|
4042
|
+
app17.route("/projects/:projectId/graphs/:graphId/agents", agents_default);
|
|
4043
|
+
app17.route("/projects/:projectId/graphs/:graphId/agent-relations", agentRelations_default);
|
|
4044
|
+
app17.route("/projects/:projectId/agent-graphs", agentGraph_default);
|
|
4045
|
+
app17.route("/projects/:projectId/graphs/:graphId/agent-tool-relations", agentToolRelations_default);
|
|
4046
|
+
app17.route(
|
|
4047
|
+
"/projects/:projectId/graphs/:graphId/agent-artifact-components",
|
|
4048
|
+
agentArtifactComponents_default
|
|
4049
|
+
);
|
|
4050
|
+
app17.route("/projects/:projectId/graphs/:graphId/agent-data-components", agentDataComponents_default);
|
|
4051
|
+
app17.route("/projects/:projectId/artifact-components", artifactComponents_default);
|
|
4052
|
+
app17.route("/projects/:projectId/graphs/:graphId/context-configs", contextConfigs_default);
|
|
4053
|
+
app17.route("/projects/:projectId/credentials", credentials_default);
|
|
4054
|
+
app17.route("/projects/:projectId/data-components", dataComponents_default);
|
|
4055
|
+
app17.route("/projects/:projectId/graphs/:graphId/external-agents", externalAgents_default);
|
|
4056
|
+
app17.route("/projects/:projectId/functions", functions_default);
|
|
4057
|
+
app17.route("/projects/:projectId/tools", tools_default);
|
|
4058
|
+
app17.route("/projects/:projectId/api-keys", apiKeys_default);
|
|
4059
|
+
app17.route("/projects/:projectId/graph", graphFull_default);
|
|
4060
|
+
var routes_default = app17;
|
|
4061
|
+
var logger5 = agentsCore.getLogger("oauth-service");
|
|
3753
4062
|
var pkceStore = /* @__PURE__ */ new Map();
|
|
3754
4063
|
function storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId) {
|
|
3755
4064
|
pkceStore.set(state, { codeVerifier, toolId, tenantId, projectId, clientId });
|
|
@@ -3784,7 +4093,10 @@ var OAuthService = class {
|
|
|
3784
4093
|
*/
|
|
3785
4094
|
async initiateOAuthFlow(params) {
|
|
3786
4095
|
const { tool, tenantId, projectId, toolId, baseUrl } = params;
|
|
3787
|
-
|
|
4096
|
+
if (tool.config.type !== "mcp") {
|
|
4097
|
+
throw new Error("OAuth is only supported for MCP tools");
|
|
4098
|
+
}
|
|
4099
|
+
const oAuthConfig = await agentsCore.discoverOAuthEndpoints(tool.config.mcp.server.url, logger5);
|
|
3788
4100
|
if (!oAuthConfig) {
|
|
3789
4101
|
throw new Error("OAuth not supported by this server");
|
|
3790
4102
|
}
|
|
@@ -3808,7 +4120,7 @@ var OAuthService = class {
|
|
|
3808
4120
|
resource: tool.config.mcp.server.url
|
|
3809
4121
|
});
|
|
3810
4122
|
storePKCEVerifier(state, codeVerifier, toolId, tenantId, projectId, clientId);
|
|
3811
|
-
|
|
4123
|
+
logger5.info({ toolId, oAuthConfig, tenantId, projectId }, "OAuth flow initiated successfully");
|
|
3812
4124
|
return {
|
|
3813
4125
|
redirectUrl: authUrl,
|
|
3814
4126
|
state
|
|
@@ -3819,7 +4131,10 @@ var OAuthService = class {
|
|
|
3819
4131
|
*/
|
|
3820
4132
|
async exchangeCodeForTokens(params) {
|
|
3821
4133
|
const { code, codeVerifier, clientId, tool, baseUrl } = params;
|
|
3822
|
-
|
|
4134
|
+
if (tool.config.type !== "mcp") {
|
|
4135
|
+
throw new Error("OAuth is only supported for MCP tools");
|
|
4136
|
+
}
|
|
4137
|
+
const oAuthConfig = await agentsCore.discoverOAuthEndpoints(tool.config.mcp.server.url, logger5);
|
|
3823
4138
|
if (!oAuthConfig?.tokenUrl) {
|
|
3824
4139
|
throw new Error("Could not discover OAuth token endpoint");
|
|
3825
4140
|
}
|
|
@@ -3834,9 +4149,9 @@ var OAuthService = class {
|
|
|
3834
4149
|
codeVerifier,
|
|
3835
4150
|
redirectUri
|
|
3836
4151
|
});
|
|
3837
|
-
|
|
4152
|
+
logger5.info({ tokenType: tokens.token_type }, "Token exchange successful with openid-client");
|
|
3838
4153
|
} catch (error) {
|
|
3839
|
-
|
|
4154
|
+
logger5.warn(
|
|
3840
4155
|
{ error: error instanceof Error ? error.message : error },
|
|
3841
4156
|
"openid-client failed, falling back to manual token exchange"
|
|
3842
4157
|
);
|
|
@@ -3847,7 +4162,7 @@ var OAuthService = class {
|
|
|
3847
4162
|
codeVerifier,
|
|
3848
4163
|
redirectUri
|
|
3849
4164
|
});
|
|
3850
|
-
|
|
4165
|
+
logger5.info({ tokenType: tokens.token_type }, "Manual token exchange successful");
|
|
3851
4166
|
}
|
|
3852
4167
|
return { tokens, oAuthConfig };
|
|
3853
4168
|
}
|
|
@@ -3855,7 +4170,7 @@ var OAuthService = class {
|
|
|
3855
4170
|
* Perform dynamic client registration
|
|
3856
4171
|
*/
|
|
3857
4172
|
async performDynamicClientRegistration(registrationUrl, redirectUri) {
|
|
3858
|
-
|
|
4173
|
+
logger5.info({ registrationUrl }, "Attempting dynamic client registration");
|
|
3859
4174
|
try {
|
|
3860
4175
|
const registrationResponse = await fetch(registrationUrl, {
|
|
3861
4176
|
method: "POST",
|
|
@@ -3878,11 +4193,11 @@ var OAuthService = class {
|
|
|
3878
4193
|
});
|
|
3879
4194
|
if (registrationResponse.ok) {
|
|
3880
4195
|
const registration = await registrationResponse.json();
|
|
3881
|
-
|
|
4196
|
+
logger5.info({ clientId: registration.client_id }, "Dynamic client registration successful");
|
|
3882
4197
|
return registration.client_id;
|
|
3883
4198
|
} else {
|
|
3884
4199
|
const errorText = await registrationResponse.text();
|
|
3885
|
-
|
|
4200
|
+
logger5.warn(
|
|
3886
4201
|
{
|
|
3887
4202
|
status: registrationResponse.status,
|
|
3888
4203
|
errorText
|
|
@@ -3891,7 +4206,7 @@ var OAuthService = class {
|
|
|
3891
4206
|
);
|
|
3892
4207
|
}
|
|
3893
4208
|
} catch (regError) {
|
|
3894
|
-
|
|
4209
|
+
logger5.warn(
|
|
3895
4210
|
{ error: regError },
|
|
3896
4211
|
"Dynamic client registration error, using default client_id"
|
|
3897
4212
|
);
|
|
@@ -3921,7 +4236,7 @@ var OAuthService = class {
|
|
|
3921
4236
|
const oauth = await import('openid-client');
|
|
3922
4237
|
const tokenUrl = new URL(oAuthConfig.tokenUrl);
|
|
3923
4238
|
const oauthServerUrl = `${tokenUrl.protocol}//${tokenUrl.host}`;
|
|
3924
|
-
|
|
4239
|
+
logger5.info({ oauthServerUrl, clientId }, "Attempting openid-client discovery");
|
|
3925
4240
|
const config = await oauth.discovery(
|
|
3926
4241
|
new URL(oauthServerUrl),
|
|
3927
4242
|
clientId,
|
|
@@ -3953,7 +4268,7 @@ var OAuthService = class {
|
|
|
3953
4268
|
*/
|
|
3954
4269
|
async exchangeManually(params) {
|
|
3955
4270
|
const { oAuthConfig, clientId, code, codeVerifier, redirectUri } = params;
|
|
3956
|
-
|
|
4271
|
+
logger5.info({ tokenUrl: oAuthConfig.tokenUrl }, "Attempting manual token exchange");
|
|
3957
4272
|
const tokenResponse = await fetch(oAuthConfig.tokenUrl, {
|
|
3958
4273
|
method: "POST",
|
|
3959
4274
|
headers: {
|
|
@@ -3971,7 +4286,7 @@ var OAuthService = class {
|
|
|
3971
4286
|
});
|
|
3972
4287
|
if (!tokenResponse.ok) {
|
|
3973
4288
|
const errorText = await tokenResponse.text();
|
|
3974
|
-
|
|
4289
|
+
logger5.error(
|
|
3975
4290
|
{
|
|
3976
4291
|
status: tokenResponse.status,
|
|
3977
4292
|
statusText: tokenResponse.statusText,
|
|
@@ -4014,8 +4329,8 @@ async function findOrCreateCredential(tenantId, projectId, credentialData) {
|
|
|
4014
4329
|
throw new Error(`Failed to save credential '${credentialData.id}' to database`);
|
|
4015
4330
|
}
|
|
4016
4331
|
}
|
|
4017
|
-
var
|
|
4018
|
-
var
|
|
4332
|
+
var app18 = new zodOpenapi.OpenAPIHono();
|
|
4333
|
+
var logger6 = agentsCore.getLogger("oauth-callback");
|
|
4019
4334
|
function getBaseUrlFromRequest(c) {
|
|
4020
4335
|
const url = new URL(c.req.url);
|
|
4021
4336
|
return `${url.protocol}//${url.host}`;
|
|
@@ -4101,7 +4416,7 @@ var OAuthCallbackQuerySchema = zodOpenapi.z.object({
|
|
|
4101
4416
|
error: zodOpenapi.z.string().optional(),
|
|
4102
4417
|
error_description: zodOpenapi.z.string().optional()
|
|
4103
4418
|
});
|
|
4104
|
-
|
|
4419
|
+
app18.openapi(
|
|
4105
4420
|
zodOpenapi.createRoute({
|
|
4106
4421
|
method: "get",
|
|
4107
4422
|
path: "/login",
|
|
@@ -4147,7 +4462,7 @@ app17.openapi(
|
|
|
4147
4462
|
try {
|
|
4148
4463
|
const tool = await agentsCore.getToolById(dbClient_default)({ scopes: { tenantId, projectId }, toolId });
|
|
4149
4464
|
if (!tool) {
|
|
4150
|
-
|
|
4465
|
+
logger6.error({ toolId, tenantId, projectId }, "Tool not found for OAuth login");
|
|
4151
4466
|
return c.text("Tool not found", 404);
|
|
4152
4467
|
}
|
|
4153
4468
|
const credentialStores = c.get("credentialStores");
|
|
@@ -4162,13 +4477,13 @@ app17.openapi(
|
|
|
4162
4477
|
});
|
|
4163
4478
|
return c.redirect(redirectUrl, 302);
|
|
4164
4479
|
} catch (error) {
|
|
4165
|
-
|
|
4480
|
+
logger6.error({ toolId, tenantId, projectId, error }, "OAuth login failed");
|
|
4166
4481
|
const errorMessage = error instanceof Error ? error.message : "Failed to initiate OAuth login";
|
|
4167
4482
|
return c.text(`OAuth Error: ${errorMessage}`, 500);
|
|
4168
4483
|
}
|
|
4169
4484
|
}
|
|
4170
4485
|
);
|
|
4171
|
-
|
|
4486
|
+
app18.openapi(
|
|
4172
4487
|
zodOpenapi.createRoute({
|
|
4173
4488
|
method: "get",
|
|
4174
4489
|
path: "/callback",
|
|
@@ -4204,9 +4519,9 @@ app17.openapi(
|
|
|
4204
4519
|
async (c) => {
|
|
4205
4520
|
try {
|
|
4206
4521
|
const { code, state, error, error_description } = c.req.valid("query");
|
|
4207
|
-
|
|
4522
|
+
logger6.info({ state, hasCode: !!code }, "OAuth callback received");
|
|
4208
4523
|
if (error) {
|
|
4209
|
-
|
|
4524
|
+
logger6.error({ error, error_description }, "OAuth authorization failed");
|
|
4210
4525
|
const errorMessage = error_description || error || "OAuth Authorization Failed. Please try again.";
|
|
4211
4526
|
const errorPage = generateOAuthCallbackPage({
|
|
4212
4527
|
title: "Authentication Failed",
|
|
@@ -4217,7 +4532,7 @@ app17.openapi(
|
|
|
4217
4532
|
}
|
|
4218
4533
|
const pkceData = retrievePKCEVerifier(state);
|
|
4219
4534
|
if (!pkceData) {
|
|
4220
|
-
|
|
4535
|
+
logger6.error({ state }, "Invalid or expired OAuth state");
|
|
4221
4536
|
const errorMessage = "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.";
|
|
4222
4537
|
const expiredPage = generateOAuthCallbackPage({
|
|
4223
4538
|
title: "Session Expired",
|
|
@@ -4234,8 +4549,8 @@ app17.openapi(
|
|
|
4234
4549
|
if (!tool) {
|
|
4235
4550
|
throw new Error(`Tool ${toolId} not found`);
|
|
4236
4551
|
}
|
|
4237
|
-
|
|
4238
|
-
|
|
4552
|
+
logger6.info({ toolId, tenantId, projectId }, "Processing OAuth callback");
|
|
4553
|
+
logger6.info({ toolId }, "Exchanging authorization code for access token");
|
|
4239
4554
|
const credentialStores = c.get("credentialStores");
|
|
4240
4555
|
const mcpTool = await agentsCore.dbResultToMcpTool(tool, dbClient_default, credentialStores);
|
|
4241
4556
|
const baseUrl = getBaseUrlFromRequest(c);
|
|
@@ -4246,7 +4561,7 @@ app17.openapi(
|
|
|
4246
4561
|
tool: mcpTool,
|
|
4247
4562
|
baseUrl
|
|
4248
4563
|
});
|
|
4249
|
-
|
|
4564
|
+
logger6.info(
|
|
4250
4565
|
{ toolId, tokenType: tokens.token_type, hasRefresh: !!tokens.refresh_token },
|
|
4251
4566
|
"Token exchange successful"
|
|
4252
4567
|
);
|
|
@@ -4293,7 +4608,7 @@ app17.openapi(
|
|
|
4293
4608
|
credentialReferenceId: newCredential.id
|
|
4294
4609
|
}
|
|
4295
4610
|
});
|
|
4296
|
-
|
|
4611
|
+
logger6.info({ toolId, credentialId: newCredential.id }, "OAuth flow completed successfully");
|
|
4297
4612
|
const successPage = generateOAuthCallbackPage({
|
|
4298
4613
|
title: "Authentication Complete",
|
|
4299
4614
|
message: "You have been successfully authenticated.",
|
|
@@ -4301,7 +4616,7 @@ app17.openapi(
|
|
|
4301
4616
|
});
|
|
4302
4617
|
return c.html(successPage);
|
|
4303
4618
|
} catch (error) {
|
|
4304
|
-
|
|
4619
|
+
logger6.error({ error }, "OAuth callback processing failed");
|
|
4305
4620
|
const errorMessage = "OAuth Processing Failed. Please try again.";
|
|
4306
4621
|
const errorPage = generateOAuthCallbackPage({
|
|
4307
4622
|
title: "Processing Failed",
|
|
@@ -4312,9 +4627,9 @@ app17.openapi(
|
|
|
4312
4627
|
}
|
|
4313
4628
|
}
|
|
4314
4629
|
);
|
|
4315
|
-
var oauth_default =
|
|
4316
|
-
var
|
|
4317
|
-
var
|
|
4630
|
+
var oauth_default = app18;
|
|
4631
|
+
var logger7 = agentsCore.getLogger("projectFull");
|
|
4632
|
+
var app19 = new zodOpenapi.OpenAPIHono();
|
|
4318
4633
|
var ProjectIdParamsSchema = zod.z.object({
|
|
4319
4634
|
tenantId: zod.z.string().openapi({
|
|
4320
4635
|
description: "Tenant identifier",
|
|
@@ -4331,7 +4646,7 @@ var TenantParamsSchema2 = zod.z.object({
|
|
|
4331
4646
|
example: "tenant_123"
|
|
4332
4647
|
})
|
|
4333
4648
|
}).openapi("TenantParams");
|
|
4334
|
-
|
|
4649
|
+
app19.openapi(
|
|
4335
4650
|
zodOpenapi.createRoute({
|
|
4336
4651
|
method: "post",
|
|
4337
4652
|
path: "/project-full",
|
|
@@ -4374,7 +4689,7 @@ app18.openapi(
|
|
|
4374
4689
|
const projectData = c.req.valid("json");
|
|
4375
4690
|
const validatedProjectData = agentsCore.FullProjectDefinitionSchema.parse(projectData);
|
|
4376
4691
|
try {
|
|
4377
|
-
const createdProject = await agentsCore.createFullProjectServerSide(dbClient_default,
|
|
4692
|
+
const createdProject = await agentsCore.createFullProjectServerSide(dbClient_default, logger7)(
|
|
4378
4693
|
{ tenantId, projectId: validatedProjectData.id },
|
|
4379
4694
|
validatedProjectData
|
|
4380
4695
|
);
|
|
@@ -4390,7 +4705,7 @@ app18.openapi(
|
|
|
4390
4705
|
}
|
|
4391
4706
|
}
|
|
4392
4707
|
);
|
|
4393
|
-
|
|
4708
|
+
app19.openapi(
|
|
4394
4709
|
zodOpenapi.createRoute({
|
|
4395
4710
|
method: "get",
|
|
4396
4711
|
path: "/project-full/{projectId}",
|
|
@@ -4418,7 +4733,7 @@ app18.openapi(
|
|
|
4418
4733
|
try {
|
|
4419
4734
|
const project = await agentsCore.getFullProject(
|
|
4420
4735
|
dbClient_default,
|
|
4421
|
-
|
|
4736
|
+
logger7
|
|
4422
4737
|
)({
|
|
4423
4738
|
scopes: { tenantId, projectId }
|
|
4424
4739
|
});
|
|
@@ -4443,7 +4758,7 @@ app18.openapi(
|
|
|
4443
4758
|
}
|
|
4444
4759
|
}
|
|
4445
4760
|
);
|
|
4446
|
-
|
|
4761
|
+
app19.openapi(
|
|
4447
4762
|
zodOpenapi.createRoute({
|
|
4448
4763
|
method: "put",
|
|
4449
4764
|
path: "/project-full/{projectId}",
|
|
@@ -4494,15 +4809,15 @@ app18.openapi(
|
|
|
4494
4809
|
}
|
|
4495
4810
|
const existingProject = await agentsCore.getFullProject(
|
|
4496
4811
|
dbClient_default,
|
|
4497
|
-
|
|
4812
|
+
logger7
|
|
4498
4813
|
)({
|
|
4499
4814
|
scopes: { tenantId, projectId }
|
|
4500
4815
|
});
|
|
4501
4816
|
const isCreate = !existingProject;
|
|
4502
|
-
const updatedProject = isCreate ? await agentsCore.createFullProjectServerSide(dbClient_default,
|
|
4817
|
+
const updatedProject = isCreate ? await agentsCore.createFullProjectServerSide(dbClient_default, logger7)(
|
|
4503
4818
|
{ tenantId, projectId },
|
|
4504
4819
|
validatedProjectData
|
|
4505
|
-
) : await agentsCore.updateFullProjectServerSide(dbClient_default,
|
|
4820
|
+
) : await agentsCore.updateFullProjectServerSide(dbClient_default, logger7)(
|
|
4506
4821
|
{ tenantId, projectId },
|
|
4507
4822
|
validatedProjectData
|
|
4508
4823
|
);
|
|
@@ -4527,7 +4842,7 @@ app18.openapi(
|
|
|
4527
4842
|
}
|
|
4528
4843
|
}
|
|
4529
4844
|
);
|
|
4530
|
-
|
|
4845
|
+
app19.openapi(
|
|
4531
4846
|
zodOpenapi.createRoute({
|
|
4532
4847
|
method: "delete",
|
|
4533
4848
|
path: "/project-full/{projectId}",
|
|
@@ -4550,7 +4865,7 @@ app18.openapi(
|
|
|
4550
4865
|
try {
|
|
4551
4866
|
const deleted = await agentsCore.deleteFullProject(
|
|
4552
4867
|
dbClient_default,
|
|
4553
|
-
|
|
4868
|
+
logger7
|
|
4554
4869
|
)({
|
|
4555
4870
|
scopes: { tenantId, projectId }
|
|
4556
4871
|
});
|
|
@@ -4575,20 +4890,20 @@ app18.openapi(
|
|
|
4575
4890
|
}
|
|
4576
4891
|
}
|
|
4577
4892
|
);
|
|
4578
|
-
var projectFull_default =
|
|
4893
|
+
var projectFull_default = app19;
|
|
4579
4894
|
|
|
4580
4895
|
// src/app.ts
|
|
4581
|
-
var
|
|
4582
|
-
|
|
4896
|
+
var logger8 = agentsCore.getLogger("agents-manage-api");
|
|
4897
|
+
logger8.info({ logger: logger8.getTransports() }, "Logger initialized");
|
|
4583
4898
|
function createManagementHono(serverConfig, credentialStores) {
|
|
4584
|
-
const
|
|
4585
|
-
|
|
4586
|
-
|
|
4899
|
+
const app21 = new zodOpenapi.OpenAPIHono();
|
|
4900
|
+
app21.use("*", requestId.requestId());
|
|
4901
|
+
app21.use("*", async (c, next) => {
|
|
4587
4902
|
c.set("serverConfig", serverConfig);
|
|
4588
4903
|
c.set("credentialStores", credentialStores);
|
|
4589
4904
|
return next();
|
|
4590
4905
|
});
|
|
4591
|
-
|
|
4906
|
+
app21.use(
|
|
4592
4907
|
honoPino.pinoLogger({
|
|
4593
4908
|
pino: agentsCore.getLogger("agents-manage-api").getPinoInstance(),
|
|
4594
4909
|
http: {
|
|
@@ -4601,7 +4916,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4601
4916
|
}
|
|
4602
4917
|
})
|
|
4603
4918
|
);
|
|
4604
|
-
|
|
4919
|
+
app21.onError(async (err, c) => {
|
|
4605
4920
|
const isExpectedError = err instanceof httpException.HTTPException;
|
|
4606
4921
|
const status = isExpectedError ? err.status : 500;
|
|
4607
4922
|
const requestId2 = c.get("requestId") || "unknown";
|
|
@@ -4634,7 +4949,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4634
4949
|
if (!isExpectedError) {
|
|
4635
4950
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
4636
4951
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
4637
|
-
|
|
4952
|
+
logger8.error(
|
|
4638
4953
|
{
|
|
4639
4954
|
error: err,
|
|
4640
4955
|
message: errorMessage,
|
|
@@ -4645,7 +4960,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4645
4960
|
"Unexpected server error occurred"
|
|
4646
4961
|
);
|
|
4647
4962
|
} else {
|
|
4648
|
-
|
|
4963
|
+
logger8.error(
|
|
4649
4964
|
{
|
|
4650
4965
|
error: err,
|
|
4651
4966
|
path: c.req.path,
|
|
@@ -4661,7 +4976,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4661
4976
|
const response = err.getResponse();
|
|
4662
4977
|
return response;
|
|
4663
4978
|
} catch (responseError) {
|
|
4664
|
-
|
|
4979
|
+
logger8.error({ error: responseError }, "Error while handling HTTPException response");
|
|
4665
4980
|
}
|
|
4666
4981
|
}
|
|
4667
4982
|
const { status: respStatus, title, detail, instance } = await agentsCore.handleApiError(err, requestId2);
|
|
@@ -4676,7 +4991,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4676
4991
|
...instance && { instance }
|
|
4677
4992
|
});
|
|
4678
4993
|
});
|
|
4679
|
-
|
|
4994
|
+
app21.use(
|
|
4680
4995
|
"*",
|
|
4681
4996
|
cors.cors({
|
|
4682
4997
|
origin: (origin) => {
|
|
@@ -4690,7 +5005,7 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4690
5005
|
credentials: true
|
|
4691
5006
|
})
|
|
4692
5007
|
);
|
|
4693
|
-
|
|
5008
|
+
app21.openapi(
|
|
4694
5009
|
zodOpenapi.createRoute({
|
|
4695
5010
|
method: "get",
|
|
4696
5011
|
path: "/health",
|
|
@@ -4707,13 +5022,13 @@ function createManagementHono(serverConfig, credentialStores) {
|
|
|
4707
5022
|
return c.body(null, 204);
|
|
4708
5023
|
}
|
|
4709
5024
|
);
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
setupOpenAPIRoutes(
|
|
5025
|
+
app21.use("/tenants/*", apiKeyAuth());
|
|
5026
|
+
app21.route("/tenants/:tenantId", routes_default);
|
|
5027
|
+
app21.route("/tenants/:tenantId", projectFull_default);
|
|
5028
|
+
app21.route("/oauth", oauth_default);
|
|
5029
|
+
setupOpenAPIRoutes(app21);
|
|
4715
5030
|
const baseApp = new hono.Hono();
|
|
4716
|
-
baseApp.route("/",
|
|
5031
|
+
baseApp.route("/", app21);
|
|
4717
5032
|
return baseApp;
|
|
4718
5033
|
}
|
|
4719
5034
|
|
|
@@ -4729,8 +5044,8 @@ var defaultConfig = {
|
|
|
4729
5044
|
};
|
|
4730
5045
|
var defaultStores = agentsCore.createDefaultCredentialStores();
|
|
4731
5046
|
var defaultRegistry = new agentsCore.CredentialStoreRegistry(defaultStores);
|
|
4732
|
-
var
|
|
4733
|
-
var index_default =
|
|
5047
|
+
var app20 = createManagementHono(defaultConfig, defaultRegistry);
|
|
5048
|
+
var index_default = app20;
|
|
4734
5049
|
function createManagementApp(config) {
|
|
4735
5050
|
const serverConfig = config?.serverConfig ?? defaultConfig;
|
|
4736
5051
|
const stores = config?.credentialStores ?? defaultStores;
|