@inkeep/agents-manage-api 0.1.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/README.md +176 -0
- package/dist/ManagementServer.d.ts +28 -0
- package/dist/ManagementServer.d.ts.map +1 -0
- package/dist/ManagementServer.js +41 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +26 -0
- package/dist/__tests__/utils/testProject.d.ts +18 -0
- package/dist/__tests__/utils/testProject.d.ts.map +1 -0
- package/dist/__tests__/utils/testProject.js +26 -0
- package/dist/__tests__/utils/testRequest.d.ts +2 -0
- package/dist/__tests__/utils/testRequest.d.ts.map +1 -0
- package/dist/__tests__/utils/testRequest.js +11 -0
- package/dist/__tests__/utils/testTenant.d.ts +64 -0
- package/dist/__tests__/utils/testTenant.d.ts.map +1 -0
- package/dist/__tests__/utils/testTenant.js +71 -0
- package/dist/app.d.ts +4 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +140 -0
- package/dist/data/conversations.d.ts +59 -0
- package/dist/data/conversations.d.ts.map +1 -0
- package/dist/data/conversations.js +216 -0
- package/dist/data/db/clean.d.ts +6 -0
- package/dist/data/db/clean.d.ts.map +1 -0
- package/dist/data/db/clean.js +77 -0
- package/dist/data/db/dbClient.d.ts +3 -0
- package/dist/data/db/dbClient.d.ts.map +1 -0
- package/dist/data/db/dbClient.js +13 -0
- package/dist/data/graphFull.d.ts +11 -0
- package/dist/data/graphFull.d.ts.map +1 -0
- package/dist/data/graphFull.js +90 -0
- package/dist/data/graphFullClient.d.ts +22 -0
- package/dist/data/graphFullClient.d.ts.map +1 -0
- package/dist/data/graphFullClient.js +189 -0
- package/dist/data/tools.d.ts +81 -0
- package/dist/data/tools.d.ts.map +1 -0
- package/dist/data/tools.js +266 -0
- package/dist/env.d.ts +41 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +59 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +32 -0
- package/dist/middleware/auth.d.ts +12 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +36 -0
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +38 -0
- package/dist/routes/agentArtifactComponents.d.ts +4 -0
- package/dist/routes/agentArtifactComponents.d.ts.map +1 -0
- package/dist/routes/agentArtifactComponents.js +230 -0
- package/dist/routes/agentDataComponents.d.ts +4 -0
- package/dist/routes/agentDataComponents.d.ts.map +1 -0
- package/dist/routes/agentDataComponents.js +225 -0
- package/dist/routes/agentGraph.d.ts +4 -0
- package/dist/routes/agentGraph.d.ts.map +1 -0
- package/dist/routes/agentGraph.js +289 -0
- package/dist/routes/agentRelations.d.ts +4 -0
- package/dist/routes/agentRelations.d.ts.map +1 -0
- package/dist/routes/agentRelations.js +290 -0
- package/dist/routes/agentToolRelations.d.ts +4 -0
- package/dist/routes/agentToolRelations.d.ts.map +1 -0
- package/dist/routes/agentToolRelations.js +342 -0
- package/dist/routes/agents.d.ts +4 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/agents.js +213 -0
- package/dist/routes/apiKeys.d.ts +4 -0
- package/dist/routes/apiKeys.d.ts.map +1 -0
- package/dist/routes/apiKeys.js +236 -0
- package/dist/routes/artifactComponents.d.ts +4 -0
- package/dist/routes/artifactComponents.d.ts.map +1 -0
- package/dist/routes/artifactComponents.js +202 -0
- package/dist/routes/contextConfigs.d.ts +4 -0
- package/dist/routes/contextConfigs.d.ts.map +1 -0
- package/dist/routes/contextConfigs.js +181 -0
- package/dist/routes/credentials.d.ts +4 -0
- package/dist/routes/credentials.d.ts.map +1 -0
- package/dist/routes/credentials.js +219 -0
- package/dist/routes/dataComponents.d.ts +4 -0
- package/dist/routes/dataComponents.d.ts.map +1 -0
- package/dist/routes/dataComponents.js +188 -0
- package/dist/routes/externalAgents.d.ts +4 -0
- package/dist/routes/externalAgents.d.ts.map +1 -0
- package/dist/routes/externalAgents.js +216 -0
- package/dist/routes/graphFull.d.ts +4 -0
- package/dist/routes/graphFull.d.ts.map +1 -0
- package/dist/routes/graphFull.js +248 -0
- package/dist/routes/index.d.ts +4 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +37 -0
- package/dist/routes/oauth.d.ts +14 -0
- package/dist/routes/oauth.d.ts.map +1 -0
- package/dist/routes/oauth.js +191 -0
- package/dist/routes/projects.d.ts +4 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/projects.js +221 -0
- package/dist/routes/tools.d.ts +4 -0
- package/dist/routes/tools.d.ts.map +1 -0
- package/dist/routes/tools.js +547 -0
- package/dist/utils/auth-detection.d.ts +22 -0
- package/dist/utils/auth-detection.d.ts.map +1 -0
- package/dist/utils/auth-detection.js +149 -0
- package/dist/utils/oauth-service.d.ts +88 -0
- package/dist/utils/oauth-service.d.ts.map +1 -0
- package/dist/utils/oauth-service.js +240 -0
- package/package.json +68 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ManagementServer } from './ManagementServer.js';
|
|
2
|
+
import { InMemoryCredentialStore, createNangoCredentialStore, createKeyChainStore, } from '@inkeep/agents-core';
|
|
3
|
+
import { env } from './env.js';
|
|
4
|
+
import { getLogger } from './logger.js';
|
|
5
|
+
const logger = getLogger('management-api');
|
|
6
|
+
export const MANAGEMENT_API_PORT = 3002;
|
|
7
|
+
// Create credential stores
|
|
8
|
+
const credentialStores = [
|
|
9
|
+
new InMemoryCredentialStore('memory-default'), // In-memory store + env vars
|
|
10
|
+
// Nango store (only loads if NANGO_SECRET_KEY is set)
|
|
11
|
+
...(process.env.NANGO_SECRET_KEY
|
|
12
|
+
? [
|
|
13
|
+
createNangoCredentialStore('nango-default', {
|
|
14
|
+
apiUrl: process.env.NANGO_HOST || 'https://api.nango.dev',
|
|
15
|
+
secretKey: process.env.NANGO_SECRET_KEY,
|
|
16
|
+
}),
|
|
17
|
+
]
|
|
18
|
+
: []),
|
|
19
|
+
createKeyChainStore('keychain-default'),
|
|
20
|
+
];
|
|
21
|
+
// Initialize Management Server
|
|
22
|
+
export const managementServer = new ManagementServer({
|
|
23
|
+
port: MANAGEMENT_API_PORT,
|
|
24
|
+
credentialStores,
|
|
25
|
+
serverOptions: {
|
|
26
|
+
requestTimeout: 60000, // 60 seconds
|
|
27
|
+
keepAliveTimeout: 60000,
|
|
28
|
+
keepAlive: true,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
// Start the server only if not in test environment
|
|
32
|
+
if (env.ENVIRONMENT !== 'test') {
|
|
33
|
+
managementServer
|
|
34
|
+
.serve()
|
|
35
|
+
.then(() => {
|
|
36
|
+
logger.info(`📝 OpenAPI documentation available at http://localhost:${MANAGEMENT_API_PORT}/openapi.json`);
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
logger.error('Failed to start Management API server:', error);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
42
|
+
}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAwBjC,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,yCAOtC;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,iBAEzD"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { pino } from 'pino';
|
|
3
|
+
// import { createGcpLoggingPinoConfig } from '@google-cloud/pino-logging-gcp-config';
|
|
4
|
+
import { env } from './env.js';
|
|
5
|
+
const logger = pino({
|
|
6
|
+
level: env.LOG_LEVEL,
|
|
7
|
+
serializers: {
|
|
8
|
+
obj: (value) => ({ ...value }),
|
|
9
|
+
},
|
|
10
|
+
redact: ['req.headers.authorization', 'req.headers["x-inkeep-admin-authentication"]'],
|
|
11
|
+
transport: {
|
|
12
|
+
target: 'pino-pretty',
|
|
13
|
+
options: {
|
|
14
|
+
sync: true,
|
|
15
|
+
destination: 1, // stdout
|
|
16
|
+
colorize: true,
|
|
17
|
+
translateTime: 'SYS:standard',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const asyncLocalStorage = new AsyncLocalStorage();
|
|
22
|
+
export function getLogger(name) {
|
|
23
|
+
const store = asyncLocalStorage.getStore();
|
|
24
|
+
const reqId = store?.get('requestId') || undefined;
|
|
25
|
+
if (!reqId) {
|
|
26
|
+
return logger.child({ name });
|
|
27
|
+
}
|
|
28
|
+
return logger.child({ reqId, name });
|
|
29
|
+
}
|
|
30
|
+
export function withRequestContext(reqId, fn) {
|
|
31
|
+
return asyncLocalStorage.run(new Map([['requestId', reqId]]), fn);
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ExecutionContext } from '@inkeep/agents-core';
|
|
2
|
+
/**
|
|
3
|
+
* Middleware to authenticate API requests using Bearer token authentication
|
|
4
|
+
* First checks if token matches INKEEP_AGENTS_RUN_BYPASS_SECRET, then falls back to API key validation
|
|
5
|
+
* Extracts and validates API keys, then adds execution context to the request
|
|
6
|
+
*/
|
|
7
|
+
export declare const apiKeyAuth: () => import("hono").MiddlewareHandler<{
|
|
8
|
+
Variables: {
|
|
9
|
+
executionContext: ExecutionContext;
|
|
10
|
+
};
|
|
11
|
+
}, string, {}>;
|
|
12
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,qBAAqB,CAAC;AAIvE;;;;GAIG;AACH,eAAO,MAAM,UAAU;eAER;QACT,gBAAgB,EAAE,gBAAgB,CAAC;KACpC;cA6BD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createMiddleware } from 'hono/factory';
|
|
2
|
+
import { HTTPException } from 'hono/http-exception';
|
|
3
|
+
import { getLogger } from '@inkeep/agents-core';
|
|
4
|
+
import { env } from '../env.js';
|
|
5
|
+
const logger = getLogger('env-key-auth');
|
|
6
|
+
/**
|
|
7
|
+
* Middleware to authenticate API requests using Bearer token authentication
|
|
8
|
+
* First checks if token matches INKEEP_AGENTS_RUN_BYPASS_SECRET, then falls back to API key validation
|
|
9
|
+
* Extracts and validates API keys, then adds execution context to the request
|
|
10
|
+
*/
|
|
11
|
+
export const apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
12
|
+
// If bypass secret is configured, only allow bypass authentication
|
|
13
|
+
if (env.INKEEP_AGENTS_MANAGE_API_SECRET) {
|
|
14
|
+
const authHeader = c.req.header('Authorization');
|
|
15
|
+
// Check for Bearer token
|
|
16
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
17
|
+
throw new HTTPException(401, {
|
|
18
|
+
message: 'Missing or invalid authorization header. Expected: Bearer <api_key>',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const apiKey = authHeader.substring(7); // Remove 'Bearer ' prefix
|
|
22
|
+
if (apiKey === env.INKEEP_AGENTS_MANAGE_API_SECRET) {
|
|
23
|
+
logger.info({}, 'Bypass secret authenticated successfully');
|
|
24
|
+
await next();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Bypass secret is set but token doesn't match - reject
|
|
29
|
+
throw new HTTPException(401, {
|
|
30
|
+
message: 'Invalid Token',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
await next();
|
|
35
|
+
return;
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAIA,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,QAwC1C"}
|
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { swaggerUI } from '@hono/swagger-ui';
|
|
2
|
+
import { env } from './env.js';
|
|
3
|
+
export function setupOpenAPIRoutes(app) {
|
|
4
|
+
// OpenAPI specification endpoint - serves the complete API spec
|
|
5
|
+
app.get('/openapi.json', (c) => {
|
|
6
|
+
try {
|
|
7
|
+
const document = app.getOpenAPIDocument({
|
|
8
|
+
openapi: '3.0.0',
|
|
9
|
+
info: {
|
|
10
|
+
title: 'Inkeep Agent Framework Management API',
|
|
11
|
+
version: '1.0.0',
|
|
12
|
+
description: 'Complete REST API for Inkeep Agent Framework Management application including chat completions, A2A agent communication, and comprehensive CRUD operations for all entities',
|
|
13
|
+
},
|
|
14
|
+
servers: [
|
|
15
|
+
{
|
|
16
|
+
url: env.MANAGEMENT_PORT
|
|
17
|
+
? `http://localhost:${env.MANAGEMENT_PORT}`
|
|
18
|
+
: `http://localhost:3002`,
|
|
19
|
+
description: 'Development server',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
return c.json(document);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('OpenAPI document generation failed:', error);
|
|
27
|
+
const errorDetails = error instanceof Error
|
|
28
|
+
? { message: error.message, stack: error.stack }
|
|
29
|
+
: JSON.stringify(error, null, 2);
|
|
30
|
+
return c.json({ error: 'Failed to generate OpenAPI document', details: errorDetails }, 500);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Swagger UI endpoint for interactive documentation
|
|
34
|
+
app.get('/docs', swaggerUI({
|
|
35
|
+
url: '/openapi.json',
|
|
36
|
+
title: 'InkeepAgent Framework Management API Documentation',
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentArtifactComponents.d.ts","sourceRoot":"","sources":["../../src/routes/agentArtifactComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAuB7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAsQ9B,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getAgentById } from '@inkeep/agents-core';
|
|
4
|
+
import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
|
|
5
|
+
import { AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, ErrorResponseSchema, SingleResponseSchema, TenantProjectParamsSchema, ArtifactComponentApiSelectSchema, associateArtifactComponentWithAgent, getAgentsUsingArtifactComponent, getArtifactComponentById, getArtifactComponentsForAgent, isArtifactComponentAssociatedWithAgent, removeArtifactComponentFromAgent, RemovedResponseSchema, ExistsResponseSchema, } from '@inkeep/agents-core';
|
|
6
|
+
import dbClient from '../data/db/dbClient.js';
|
|
7
|
+
const app = new OpenAPIHono();
|
|
8
|
+
// List artifact components for a specific agent in a graph
|
|
9
|
+
app.openapi(createRoute({
|
|
10
|
+
method: 'get',
|
|
11
|
+
path: '/agent/:agentId',
|
|
12
|
+
summary: 'Get Artifact Components for Agent',
|
|
13
|
+
operationId: 'get-artifact-components-for-agent',
|
|
14
|
+
tags: ['CRUD Agent Artifact Component Relations'],
|
|
15
|
+
request: {
|
|
16
|
+
params: TenantProjectParamsSchema.extend({
|
|
17
|
+
agentId: z.string(),
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
responses: {
|
|
21
|
+
200: {
|
|
22
|
+
description: 'Artifact components retrieved successfully',
|
|
23
|
+
content: {
|
|
24
|
+
'application/json': {
|
|
25
|
+
schema: z.object({
|
|
26
|
+
data: z.array(ArtifactComponentApiSelectSchema),
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
...commonGetErrorResponses,
|
|
32
|
+
},
|
|
33
|
+
}), async (c) => {
|
|
34
|
+
const { tenantId, projectId, agentId } = c.req.valid('param');
|
|
35
|
+
const artifactComponents = await getArtifactComponentsForAgent(dbClient)({
|
|
36
|
+
scopes: { tenantId, projectId },
|
|
37
|
+
agentId,
|
|
38
|
+
});
|
|
39
|
+
return c.json({
|
|
40
|
+
data: artifactComponents,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
// List agents using a specific artifact component
|
|
44
|
+
app.openapi(createRoute({
|
|
45
|
+
method: 'get',
|
|
46
|
+
path: '/component/:artifactComponentId/agents',
|
|
47
|
+
summary: 'Get Agents Using Artifact Component',
|
|
48
|
+
operationId: 'get-agents-using-artifact-component',
|
|
49
|
+
tags: ['CRUD Agent Artifact Component Relations'],
|
|
50
|
+
request: {
|
|
51
|
+
params: TenantProjectParamsSchema.extend({
|
|
52
|
+
artifactComponentId: z.string(),
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
responses: {
|
|
56
|
+
200: {
|
|
57
|
+
description: 'Agents retrieved successfully',
|
|
58
|
+
content: {
|
|
59
|
+
'application/json': {
|
|
60
|
+
schema: z.object({
|
|
61
|
+
data: z.array(z.object({
|
|
62
|
+
agentId: z.string(),
|
|
63
|
+
createdAt: z.string(),
|
|
64
|
+
})),
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
...commonGetErrorResponses,
|
|
70
|
+
},
|
|
71
|
+
}), async (c) => {
|
|
72
|
+
const { tenantId, projectId, artifactComponentId } = c.req.valid('param');
|
|
73
|
+
const agents = await getAgentsUsingArtifactComponent(dbClient)({
|
|
74
|
+
scopes: { tenantId, projectId },
|
|
75
|
+
artifactComponentId,
|
|
76
|
+
});
|
|
77
|
+
return c.json({ data: agents });
|
|
78
|
+
});
|
|
79
|
+
// Create agent artifact component association
|
|
80
|
+
app.openapi(createRoute({
|
|
81
|
+
method: 'post',
|
|
82
|
+
path: '/',
|
|
83
|
+
summary: 'Associate Artifact Component with Agent',
|
|
84
|
+
operationId: 'associate-artifact-component-with-agent',
|
|
85
|
+
tags: ['CRUD Agent Artifact Component Relations'],
|
|
86
|
+
request: {
|
|
87
|
+
params: TenantProjectParamsSchema,
|
|
88
|
+
body: {
|
|
89
|
+
content: {
|
|
90
|
+
'application/json': {
|
|
91
|
+
schema: AgentArtifactComponentApiInsertSchema,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
responses: {
|
|
97
|
+
201: {
|
|
98
|
+
description: 'Agent artifact component association created successfully',
|
|
99
|
+
content: {
|
|
100
|
+
'application/json': {
|
|
101
|
+
schema: SingleResponseSchema(AgentArtifactComponentApiSelectSchema),
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
409: {
|
|
106
|
+
description: 'Association already exists',
|
|
107
|
+
content: {
|
|
108
|
+
'application/json': {
|
|
109
|
+
schema: ErrorResponseSchema,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
...commonGetErrorResponses,
|
|
114
|
+
},
|
|
115
|
+
}), async (c) => {
|
|
116
|
+
const { tenantId, projectId } = c.req.valid('param');
|
|
117
|
+
const { agentId, artifactComponentId } = c.req.valid('json');
|
|
118
|
+
// Validate that both agent and artifact component exist before creating association
|
|
119
|
+
const agent = await getAgentById(dbClient)({ scopes: { tenantId, projectId }, agentId });
|
|
120
|
+
const artifactComponent = await getArtifactComponentById(dbClient)({
|
|
121
|
+
scopes: { tenantId, projectId },
|
|
122
|
+
id: artifactComponentId,
|
|
123
|
+
});
|
|
124
|
+
if (!agent) {
|
|
125
|
+
throw createApiError({
|
|
126
|
+
code: 'not_found',
|
|
127
|
+
message: `Agent with id '${agentId}' not found`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (!artifactComponent) {
|
|
131
|
+
throw createApiError({
|
|
132
|
+
code: 'not_found',
|
|
133
|
+
message: `Artifact component with id '${artifactComponentId}' not found`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
// Check if association already exists
|
|
137
|
+
const exists = await isArtifactComponentAssociatedWithAgent(dbClient)({
|
|
138
|
+
scopes: { tenantId, projectId },
|
|
139
|
+
agentId,
|
|
140
|
+
artifactComponentId,
|
|
141
|
+
});
|
|
142
|
+
if (exists) {
|
|
143
|
+
throw createApiError({
|
|
144
|
+
code: 'conflict',
|
|
145
|
+
message: 'Agent artifact component association already exists',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const association = await associateArtifactComponentWithAgent(dbClient)({
|
|
149
|
+
scopes: { tenantId, projectId },
|
|
150
|
+
agentId,
|
|
151
|
+
artifactComponentId,
|
|
152
|
+
});
|
|
153
|
+
return c.json({ data: association }, 201);
|
|
154
|
+
});
|
|
155
|
+
// Remove agent artifact component association
|
|
156
|
+
app.openapi(createRoute({
|
|
157
|
+
method: 'delete',
|
|
158
|
+
path: '/agent/:agentId/component/:artifactComponentId',
|
|
159
|
+
summary: 'Remove Artifact Component from Agent',
|
|
160
|
+
operationId: 'remove-artifact-component-from-agent',
|
|
161
|
+
tags: ['CRUD Agent Artifact Component Relations'],
|
|
162
|
+
request: {
|
|
163
|
+
params: TenantProjectParamsSchema.extend({
|
|
164
|
+
agentId: z.string(),
|
|
165
|
+
artifactComponentId: z.string(),
|
|
166
|
+
}),
|
|
167
|
+
},
|
|
168
|
+
responses: {
|
|
169
|
+
200: {
|
|
170
|
+
description: 'Association removed successfully',
|
|
171
|
+
content: {
|
|
172
|
+
'application/json': {
|
|
173
|
+
schema: RemovedResponseSchema,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
...commonGetErrorResponses,
|
|
178
|
+
},
|
|
179
|
+
}), async (c) => {
|
|
180
|
+
const { tenantId, projectId, agentId, artifactComponentId } = c.req.valid('param');
|
|
181
|
+
const removed = await removeArtifactComponentFromAgent(dbClient)({
|
|
182
|
+
scopes: { tenantId, projectId },
|
|
183
|
+
agentId,
|
|
184
|
+
artifactComponentId,
|
|
185
|
+
});
|
|
186
|
+
if (!removed) {
|
|
187
|
+
throw createApiError({
|
|
188
|
+
code: 'not_found',
|
|
189
|
+
message: 'Agent artifact component association not found',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return c.json({
|
|
193
|
+
message: 'Association removed successfully',
|
|
194
|
+
removed: true,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
// Check if artifact component is associated with agent
|
|
198
|
+
app.openapi(createRoute({
|
|
199
|
+
method: 'get',
|
|
200
|
+
path: '/agent/:agentId/component/:artifactComponentId/exists',
|
|
201
|
+
summary: 'Check if Artifact Component is Associated with Agent',
|
|
202
|
+
operationId: 'check-artifact-component-agent-association',
|
|
203
|
+
tags: ['CRUD Agent Artifact Component Relations'],
|
|
204
|
+
request: {
|
|
205
|
+
params: TenantProjectParamsSchema.extend({
|
|
206
|
+
agentId: z.string(),
|
|
207
|
+
artifactComponentId: z.string(),
|
|
208
|
+
}),
|
|
209
|
+
},
|
|
210
|
+
responses: {
|
|
211
|
+
200: {
|
|
212
|
+
description: 'Association status retrieved successfully',
|
|
213
|
+
content: {
|
|
214
|
+
'application/json': {
|
|
215
|
+
schema: ExistsResponseSchema,
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
...commonGetErrorResponses,
|
|
220
|
+
},
|
|
221
|
+
}), async (c) => {
|
|
222
|
+
const { tenantId, projectId, agentId, artifactComponentId } = c.req.valid('param');
|
|
223
|
+
const exists = await isArtifactComponentAssociatedWithAgent(dbClient)({
|
|
224
|
+
scopes: { tenantId, projectId },
|
|
225
|
+
agentId,
|
|
226
|
+
artifactComponentId,
|
|
227
|
+
});
|
|
228
|
+
return c.json({ exists });
|
|
229
|
+
});
|
|
230
|
+
export default app;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentDataComponents.d.ts","sourceRoot":"","sources":["../../src/routes/agentDataComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsB7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAkQ9B,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { associateDataComponentWithAgent, getAgentsUsingDataComponent, getDataComponentsForAgent, getDataComponent, getAgentById, isDataComponentAssociatedWithAgent, removeDataComponentFromAgent, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, DataComponentApiSelectSchema, ErrorResponseSchema, SingleResponseSchema, TenantProjectParamsSchema, RemovedResponseSchema, ExistsResponseSchema, } from '@inkeep/agents-core';
|
|
4
|
+
import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
|
|
5
|
+
import dbClient from '../data/db/dbClient.js';
|
|
6
|
+
const app = new OpenAPIHono();
|
|
7
|
+
// List data components for a specific agent in a graph
|
|
8
|
+
app.openapi(createRoute({
|
|
9
|
+
method: 'get',
|
|
10
|
+
path: '/agent/:agentId',
|
|
11
|
+
summary: 'Get Data Components for Agent',
|
|
12
|
+
operationId: 'get-data-components-for-agent',
|
|
13
|
+
tags: ['CRUD Agent Data Component Relations'],
|
|
14
|
+
request: {
|
|
15
|
+
params: TenantProjectParamsSchema.extend({
|
|
16
|
+
agentId: z.string(),
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
responses: {
|
|
20
|
+
200: {
|
|
21
|
+
description: 'Data components retrieved successfully',
|
|
22
|
+
content: {
|
|
23
|
+
'application/json': {
|
|
24
|
+
schema: z.object({
|
|
25
|
+
data: z.array(DataComponentApiSelectSchema),
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
...commonGetErrorResponses,
|
|
31
|
+
},
|
|
32
|
+
}), async (c) => {
|
|
33
|
+
const { tenantId, projectId, agentId } = c.req.valid('param');
|
|
34
|
+
const dataComponents = await getDataComponentsForAgent(dbClient)({
|
|
35
|
+
scopes: { tenantId, projectId },
|
|
36
|
+
agentId,
|
|
37
|
+
});
|
|
38
|
+
return c.json({ data: dataComponents });
|
|
39
|
+
});
|
|
40
|
+
// List agent ids using a specific data component
|
|
41
|
+
app.openapi(createRoute({
|
|
42
|
+
method: 'get',
|
|
43
|
+
path: '/component/:dataComponentId/agents',
|
|
44
|
+
summary: 'Get Agents Using Data Component',
|
|
45
|
+
operationId: 'get-agents-using-data-component',
|
|
46
|
+
tags: ['CRUD Agent Data Component Relations'],
|
|
47
|
+
request: {
|
|
48
|
+
params: TenantProjectParamsSchema.extend({
|
|
49
|
+
dataComponentId: z.string(),
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
responses: {
|
|
53
|
+
200: {
|
|
54
|
+
description: 'Agents retrieved successfully',
|
|
55
|
+
content: {
|
|
56
|
+
'application/json': {
|
|
57
|
+
schema: z.object({
|
|
58
|
+
data: z.array(z.object({
|
|
59
|
+
agentId: z.string(),
|
|
60
|
+
createdAt: z.string(),
|
|
61
|
+
})),
|
|
62
|
+
}),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
...commonGetErrorResponses,
|
|
67
|
+
},
|
|
68
|
+
}), async (c) => {
|
|
69
|
+
const { tenantId, projectId, dataComponentId } = c.req.valid('param');
|
|
70
|
+
const agents = await getAgentsUsingDataComponent(dbClient)({
|
|
71
|
+
scopes: { tenantId, projectId },
|
|
72
|
+
dataComponentId,
|
|
73
|
+
});
|
|
74
|
+
return c.json({ data: agents });
|
|
75
|
+
});
|
|
76
|
+
// Create agent data component association
|
|
77
|
+
app.openapi(createRoute({
|
|
78
|
+
method: 'post',
|
|
79
|
+
path: '/',
|
|
80
|
+
summary: 'Associate Data Component with Agent',
|
|
81
|
+
operationId: 'associate-data-component-with-agent',
|
|
82
|
+
tags: ['CRUD Agent Data Component Relations'],
|
|
83
|
+
request: {
|
|
84
|
+
params: TenantProjectParamsSchema,
|
|
85
|
+
body: {
|
|
86
|
+
content: {
|
|
87
|
+
'application/json': {
|
|
88
|
+
schema: AgentDataComponentApiInsertSchema,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
responses: {
|
|
94
|
+
201: {
|
|
95
|
+
description: 'Agent data component association created successfully',
|
|
96
|
+
content: {
|
|
97
|
+
'application/json': {
|
|
98
|
+
schema: SingleResponseSchema(AgentDataComponentApiSelectSchema),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
409: {
|
|
103
|
+
description: 'Association already exists',
|
|
104
|
+
content: {
|
|
105
|
+
'application/json': {
|
|
106
|
+
schema: ErrorResponseSchema,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
...commonGetErrorResponses,
|
|
111
|
+
},
|
|
112
|
+
}), async (c) => {
|
|
113
|
+
const { tenantId, projectId } = c.req.valid('param');
|
|
114
|
+
const { agentId, dataComponentId } = c.req.valid('json');
|
|
115
|
+
const [agent, dataComponent] = await Promise.all([
|
|
116
|
+
getAgentById(dbClient)({ scopes: { tenantId, projectId }, agentId }),
|
|
117
|
+
getDataComponent(dbClient)({ scopes: { tenantId, projectId }, dataComponentId }),
|
|
118
|
+
]);
|
|
119
|
+
if (!agent) {
|
|
120
|
+
throw createApiError({
|
|
121
|
+
code: 'not_found',
|
|
122
|
+
message: `Agent with id '${agentId}' not found`,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (!dataComponent) {
|
|
126
|
+
throw createApiError({
|
|
127
|
+
code: 'not_found',
|
|
128
|
+
message: `Data component with id '${dataComponentId}' not found`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Check if association already exists
|
|
132
|
+
const exists = await isDataComponentAssociatedWithAgent(dbClient)({
|
|
133
|
+
scopes: { tenantId, projectId },
|
|
134
|
+
agentId,
|
|
135
|
+
dataComponentId,
|
|
136
|
+
});
|
|
137
|
+
if (exists) {
|
|
138
|
+
throw createApiError({
|
|
139
|
+
code: 'conflict',
|
|
140
|
+
message: 'Agent data component association already exists',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const association = await associateDataComponentWithAgent(dbClient)({
|
|
144
|
+
scopes: { tenantId, projectId },
|
|
145
|
+
agentId,
|
|
146
|
+
dataComponentId,
|
|
147
|
+
});
|
|
148
|
+
return c.json({ data: association }, 201);
|
|
149
|
+
});
|
|
150
|
+
// Remove agent data component association
|
|
151
|
+
app.openapi(createRoute({
|
|
152
|
+
method: 'delete',
|
|
153
|
+
path: '/agent/:agentId/component/:dataComponentId',
|
|
154
|
+
summary: 'Remove Data Component from Agent',
|
|
155
|
+
operationId: 'remove-data-component-from-agent',
|
|
156
|
+
tags: ['CRUD Agent Data Component Relations'],
|
|
157
|
+
request: {
|
|
158
|
+
params: TenantProjectParamsSchema.extend({
|
|
159
|
+
agentId: z.string(),
|
|
160
|
+
dataComponentId: z.string(),
|
|
161
|
+
}),
|
|
162
|
+
},
|
|
163
|
+
responses: {
|
|
164
|
+
200: {
|
|
165
|
+
description: 'Association removed successfully',
|
|
166
|
+
content: {
|
|
167
|
+
'application/json': {
|
|
168
|
+
schema: RemovedResponseSchema,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
...commonGetErrorResponses,
|
|
173
|
+
},
|
|
174
|
+
}), async (c) => {
|
|
175
|
+
const { tenantId, projectId, agentId, dataComponentId } = c.req.valid('param');
|
|
176
|
+
const removed = await removeDataComponentFromAgent(dbClient)({
|
|
177
|
+
scopes: { tenantId, projectId },
|
|
178
|
+
agentId,
|
|
179
|
+
dataComponentId,
|
|
180
|
+
});
|
|
181
|
+
if (!removed) {
|
|
182
|
+
throw createApiError({
|
|
183
|
+
code: 'not_found',
|
|
184
|
+
message: 'Agent data component association not found',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return c.json({
|
|
188
|
+
message: 'Association removed successfully',
|
|
189
|
+
removed: true,
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
// Check if data component is associated with agent
|
|
193
|
+
app.openapi(createRoute({
|
|
194
|
+
method: 'get',
|
|
195
|
+
path: '/agent/:agentId/component/:dataComponentId/exists',
|
|
196
|
+
summary: 'Check if Data Component is Associated with Agent',
|
|
197
|
+
operationId: 'check-data-component-agent-association',
|
|
198
|
+
tags: ['CRUD Agent Data Component Relations'],
|
|
199
|
+
request: {
|
|
200
|
+
params: TenantProjectParamsSchema.extend({
|
|
201
|
+
agentId: z.string(),
|
|
202
|
+
dataComponentId: z.string(),
|
|
203
|
+
}),
|
|
204
|
+
},
|
|
205
|
+
responses: {
|
|
206
|
+
200: {
|
|
207
|
+
description: 'Association status retrieved successfully',
|
|
208
|
+
content: {
|
|
209
|
+
'application/json': {
|
|
210
|
+
schema: ExistsResponseSchema,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
...commonGetErrorResponses,
|
|
215
|
+
},
|
|
216
|
+
}), async (c) => {
|
|
217
|
+
const { tenantId, projectId, agentId, dataComponentId } = c.req.valid('param');
|
|
218
|
+
const exists = await isDataComponentAssociatedWithAgent(dbClient)({
|
|
219
|
+
scopes: { tenantId, projectId },
|
|
220
|
+
agentId,
|
|
221
|
+
dataComponentId,
|
|
222
|
+
});
|
|
223
|
+
return c.json({ exists });
|
|
224
|
+
});
|
|
225
|
+
export default app;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentGraph.d.ts","sourceRoot":"","sources":["../../src/routes/agentGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA8B7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAsU9B,eAAe,GAAG,CAAC"}
|