@inkeep/agents-manage-api 0.1.2 → 0.1.6
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/LICENSE.md +7 -0
- package/README.md +1 -1
- package/SUPPLEMENTAL_TERMS.md +40 -0
- package/dist/index.cjs +5083 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +13 -18
- package/dist/index.js +5052 -26
- package/package.json +10 -10
- package/dist/ManagementServer.d.ts +0 -28
- package/dist/ManagementServer.d.ts.map +0 -1
- package/dist/ManagementServer.js +0 -41
- package/dist/__tests__/setup.d.ts +0 -2
- package/dist/__tests__/setup.d.ts.map +0 -1
- package/dist/__tests__/setup.js +0 -26
- package/dist/__tests__/utils/testProject.d.ts +0 -18
- package/dist/__tests__/utils/testProject.d.ts.map +0 -1
- package/dist/__tests__/utils/testProject.js +0 -26
- package/dist/__tests__/utils/testRequest.d.ts +0 -2
- package/dist/__tests__/utils/testRequest.d.ts.map +0 -1
- package/dist/__tests__/utils/testRequest.js +0 -11
- package/dist/__tests__/utils/testTenant.d.ts +0 -64
- package/dist/__tests__/utils/testTenant.d.ts.map +0 -1
- package/dist/__tests__/utils/testTenant.js +0 -71
- package/dist/app.d.ts +0 -11
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -148
- package/dist/data/conversations.d.ts +0 -59
- package/dist/data/conversations.d.ts.map +0 -1
- package/dist/data/conversations.js +0 -216
- package/dist/data/db/clean.d.ts +0 -6
- package/dist/data/db/clean.d.ts.map +0 -1
- package/dist/data/db/clean.js +0 -77
- package/dist/data/db/dbClient.d.ts +0 -3
- package/dist/data/db/dbClient.d.ts.map +0 -1
- package/dist/data/db/dbClient.js +0 -13
- package/dist/data/graphFull.d.ts +0 -11
- package/dist/data/graphFull.d.ts.map +0 -1
- package/dist/data/graphFull.js +0 -90
- package/dist/data/graphFullClient.d.ts +0 -22
- package/dist/data/graphFullClient.d.ts.map +0 -1
- package/dist/data/graphFullClient.js +0 -189
- package/dist/data/tools.d.ts +0 -82
- package/dist/data/tools.d.ts.map +0 -1
- package/dist/data/tools.js +0 -271
- package/dist/env.d.ts +0 -41
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -59
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -32
- package/dist/middleware/auth.d.ts +0 -12
- package/dist/middleware/auth.d.ts.map +0 -1
- package/dist/middleware/auth.js +0 -36
- package/dist/openapi.d.ts +0 -2
- package/dist/openapi.d.ts.map +0 -1
- package/dist/openapi.js +0 -38
- package/dist/routes/agentArtifactComponents.d.ts +0 -4
- package/dist/routes/agentArtifactComponents.d.ts.map +0 -1
- package/dist/routes/agentArtifactComponents.js +0 -230
- package/dist/routes/agentDataComponents.d.ts +0 -4
- package/dist/routes/agentDataComponents.d.ts.map +0 -1
- package/dist/routes/agentDataComponents.js +0 -225
- package/dist/routes/agentGraph.d.ts +0 -4
- package/dist/routes/agentGraph.d.ts.map +0 -1
- package/dist/routes/agentGraph.js +0 -289
- package/dist/routes/agentRelations.d.ts +0 -4
- package/dist/routes/agentRelations.d.ts.map +0 -1
- package/dist/routes/agentRelations.js +0 -290
- package/dist/routes/agentToolRelations.d.ts +0 -4
- package/dist/routes/agentToolRelations.d.ts.map +0 -1
- package/dist/routes/agentToolRelations.js +0 -342
- package/dist/routes/agents.d.ts +0 -4
- package/dist/routes/agents.d.ts.map +0 -1
- package/dist/routes/agents.js +0 -213
- package/dist/routes/apiKeys.d.ts +0 -4
- package/dist/routes/apiKeys.d.ts.map +0 -1
- package/dist/routes/apiKeys.js +0 -236
- package/dist/routes/artifactComponents.d.ts +0 -4
- package/dist/routes/artifactComponents.d.ts.map +0 -1
- package/dist/routes/artifactComponents.js +0 -202
- package/dist/routes/contextConfigs.d.ts +0 -4
- package/dist/routes/contextConfigs.d.ts.map +0 -1
- package/dist/routes/contextConfigs.js +0 -181
- package/dist/routes/credentials.d.ts +0 -10
- package/dist/routes/credentials.d.ts.map +0 -1
- package/dist/routes/credentials.js +0 -219
- package/dist/routes/dataComponents.d.ts +0 -4
- package/dist/routes/dataComponents.d.ts.map +0 -1
- package/dist/routes/dataComponents.js +0 -188
- package/dist/routes/externalAgents.d.ts +0 -4
- package/dist/routes/externalAgents.d.ts.map +0 -1
- package/dist/routes/externalAgents.js +0 -216
- package/dist/routes/graphFull.d.ts +0 -4
- package/dist/routes/graphFull.d.ts.map +0 -1
- package/dist/routes/graphFull.js +0 -248
- package/dist/routes/index.d.ts +0 -4
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/index.js +0 -37
- package/dist/routes/oauth.d.ts +0 -21
- package/dist/routes/oauth.d.ts.map +0 -1
- package/dist/routes/oauth.js +0 -191
- package/dist/routes/projects.d.ts +0 -4
- package/dist/routes/projects.d.ts.map +0 -1
- package/dist/routes/projects.js +0 -221
- package/dist/routes/tools.d.ts +0 -11
- package/dist/routes/tools.d.ts.map +0 -1
- package/dist/routes/tools.js +0 -555
- package/dist/utils/auth-detection.d.ts +0 -22
- package/dist/utils/auth-detection.d.ts.map +0 -1
- package/dist/utils/auth-detection.js +0 -149
- package/dist/utils/oauth-service.d.ts +0 -88
- package/dist/utils/oauth-service.d.ts.map +0 -1
- package/dist/utils/oauth-service.js +0 -240
package/dist/routes/graphFull.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
|
|
4
|
-
import { createFullGraphServerSide, deleteFullGraph, getFullGraph, updateFullGraphServerSide, ErrorResponseSchema, FullGraphDefinitionSchema, SingleResponseSchema, TenantProjectParamsSchema, } from '@inkeep/agents-core';
|
|
5
|
-
import dbClient from '../data/db/dbClient.js';
|
|
6
|
-
import { getLogger } from '../logger.js';
|
|
7
|
-
const logger = getLogger('graphFull');
|
|
8
|
-
const app = new OpenAPIHono();
|
|
9
|
-
// Schema for path parameters with graphId
|
|
10
|
-
const GraphIdParamsSchema = z
|
|
11
|
-
.object({
|
|
12
|
-
tenantId: z.string().openapi({
|
|
13
|
-
description: 'Tenant identifier',
|
|
14
|
-
example: 'tenant_123',
|
|
15
|
-
}),
|
|
16
|
-
projectId: z.string().openapi({
|
|
17
|
-
description: 'Project identifier',
|
|
18
|
-
example: 'project_456',
|
|
19
|
-
}),
|
|
20
|
-
graphId: z.string().openapi({
|
|
21
|
-
description: 'Graph identifier',
|
|
22
|
-
example: 'graph_789',
|
|
23
|
-
}),
|
|
24
|
-
})
|
|
25
|
-
.openapi('GraphIdParams');
|
|
26
|
-
// Create full graph from JSON
|
|
27
|
-
app.openapi(createRoute({
|
|
28
|
-
method: 'post',
|
|
29
|
-
path: '/',
|
|
30
|
-
summary: 'Create Full Graph',
|
|
31
|
-
operationId: 'create-full-graph',
|
|
32
|
-
tags: ['CRUD Full Graph'],
|
|
33
|
-
description: 'Create a complete agent graph with all agents, tools, and relationships from JSON definition',
|
|
34
|
-
request: {
|
|
35
|
-
params: TenantProjectParamsSchema,
|
|
36
|
-
body: {
|
|
37
|
-
content: {
|
|
38
|
-
'application/json': {
|
|
39
|
-
schema: FullGraphDefinitionSchema,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
responses: {
|
|
45
|
-
201: {
|
|
46
|
-
description: 'Full graph created successfully',
|
|
47
|
-
content: {
|
|
48
|
-
'application/json': {
|
|
49
|
-
schema: SingleResponseSchema(FullGraphDefinitionSchema),
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
409: {
|
|
54
|
-
description: 'Graph already exists',
|
|
55
|
-
content: {
|
|
56
|
-
'application/json': {
|
|
57
|
-
schema: ErrorResponseSchema,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
...commonGetErrorResponses,
|
|
62
|
-
},
|
|
63
|
-
}), async (c) => {
|
|
64
|
-
const { tenantId, projectId } = c.req.valid('param');
|
|
65
|
-
const graphData = c.req.valid('json');
|
|
66
|
-
// Validate the graph data
|
|
67
|
-
const validatedGraphData = FullGraphDefinitionSchema.parse(graphData);
|
|
68
|
-
// Create the full graph using the server-side data layer operations
|
|
69
|
-
const createdGraph = await createFullGraphServerSide(dbClient, logger)({ tenantId, projectId }, validatedGraphData);
|
|
70
|
-
return c.json({ data: createdGraph }, 201);
|
|
71
|
-
});
|
|
72
|
-
// Get full graph by ID
|
|
73
|
-
app.openapi(createRoute({
|
|
74
|
-
method: 'get',
|
|
75
|
-
path: '/{graphId}',
|
|
76
|
-
summary: 'Get Full Graph',
|
|
77
|
-
operationId: 'get-full-graph',
|
|
78
|
-
tags: ['CRUD Full Graph'],
|
|
79
|
-
description: 'Retrieve a complete agent graph definition with all agents, tools, and relationships',
|
|
80
|
-
request: {
|
|
81
|
-
params: GraphIdParamsSchema,
|
|
82
|
-
},
|
|
83
|
-
responses: {
|
|
84
|
-
200: {
|
|
85
|
-
description: 'Full graph found',
|
|
86
|
-
content: {
|
|
87
|
-
'application/json': {
|
|
88
|
-
schema: SingleResponseSchema(FullGraphDefinitionSchema),
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
...commonGetErrorResponses,
|
|
93
|
-
},
|
|
94
|
-
}), async (c) => {
|
|
95
|
-
const { tenantId, projectId, graphId } = c.req.valid('param');
|
|
96
|
-
try {
|
|
97
|
-
const graph = await getFullGraph(dbClient, logger)({
|
|
98
|
-
scopes: { tenantId, projectId },
|
|
99
|
-
graphId,
|
|
100
|
-
});
|
|
101
|
-
if (!graph) {
|
|
102
|
-
throw createApiError({
|
|
103
|
-
code: 'not_found',
|
|
104
|
-
message: 'Graph not found',
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return c.json({ data: graph });
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
if (error instanceof Error && error.message.includes('not found')) {
|
|
111
|
-
throw createApiError({
|
|
112
|
-
code: 'not_found',
|
|
113
|
-
message: 'Graph not found',
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
throw createApiError({
|
|
117
|
-
code: 'internal_server_error',
|
|
118
|
-
message: error instanceof Error ? error.message : 'Failed to retrieve graph',
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
// Update/upsert full graph
|
|
123
|
-
app.openapi(createRoute({
|
|
124
|
-
method: 'put',
|
|
125
|
-
path: '/{graphId}',
|
|
126
|
-
summary: 'Update Full Graph',
|
|
127
|
-
operationId: 'update-full-graph',
|
|
128
|
-
tags: ['CRUD Full Graph'],
|
|
129
|
-
description: 'Update or create a complete agent graph with all agents, tools, and relationships from JSON definition',
|
|
130
|
-
request: {
|
|
131
|
-
params: GraphIdParamsSchema,
|
|
132
|
-
body: {
|
|
133
|
-
content: {
|
|
134
|
-
'application/json': {
|
|
135
|
-
schema: FullGraphDefinitionSchema,
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
responses: {
|
|
141
|
-
200: {
|
|
142
|
-
description: 'Full graph updated successfully',
|
|
143
|
-
content: {
|
|
144
|
-
'application/json': {
|
|
145
|
-
schema: SingleResponseSchema(FullGraphDefinitionSchema),
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
201: {
|
|
150
|
-
description: 'Full graph created successfully',
|
|
151
|
-
content: {
|
|
152
|
-
'application/json': {
|
|
153
|
-
schema: SingleResponseSchema(FullGraphDefinitionSchema),
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
...commonGetErrorResponses,
|
|
158
|
-
},
|
|
159
|
-
}), async (c) => {
|
|
160
|
-
const { tenantId, projectId, graphId } = c.req.valid('param');
|
|
161
|
-
const graphData = c.req.valid('json');
|
|
162
|
-
try {
|
|
163
|
-
// Validate the graph data
|
|
164
|
-
const validatedGraphData = FullGraphDefinitionSchema.parse(graphData);
|
|
165
|
-
// Validate that the URL graphId matches the data.id
|
|
166
|
-
if (graphId !== validatedGraphData.id) {
|
|
167
|
-
throw createApiError({
|
|
168
|
-
code: 'bad_request',
|
|
169
|
-
message: `Graph ID mismatch: expected ${graphId}, got ${validatedGraphData.id}`,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
// Check if the graph exists first to determine status code
|
|
173
|
-
const existingGraph = await getFullGraph(dbClient, logger)({
|
|
174
|
-
scopes: { tenantId, projectId },
|
|
175
|
-
graphId,
|
|
176
|
-
});
|
|
177
|
-
const isCreate = !existingGraph;
|
|
178
|
-
// Update/create the full graph using server-side data layer operations
|
|
179
|
-
const updatedGraph = isCreate
|
|
180
|
-
? await createFullGraphServerSide(dbClient, logger)({ tenantId, projectId }, validatedGraphData)
|
|
181
|
-
: await updateFullGraphServerSide(dbClient, logger)({ tenantId, projectId }, validatedGraphData);
|
|
182
|
-
return c.json({ data: updatedGraph }, isCreate ? 201 : 200);
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
if (error instanceof z.ZodError) {
|
|
186
|
-
throw createApiError({
|
|
187
|
-
code: 'bad_request',
|
|
188
|
-
message: 'Invalid graph definition',
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
if (error instanceof Error && error.message.includes('ID mismatch')) {
|
|
192
|
-
throw createApiError({
|
|
193
|
-
code: 'bad_request',
|
|
194
|
-
message: error.message,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
throw createApiError({
|
|
198
|
-
code: 'internal_server_error',
|
|
199
|
-
message: error instanceof Error ? error.message : 'Failed to update graph',
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
// Delete full graph
|
|
204
|
-
app.openapi(createRoute({
|
|
205
|
-
method: 'delete',
|
|
206
|
-
path: '/{graphId}',
|
|
207
|
-
summary: 'Delete Full Graph',
|
|
208
|
-
operationId: 'delete-full-graph',
|
|
209
|
-
tags: ['CRUD Full Graph'],
|
|
210
|
-
description: 'Delete a complete agent graph and cascade to all related entities (relationships, not agents/tools)',
|
|
211
|
-
request: {
|
|
212
|
-
params: GraphIdParamsSchema,
|
|
213
|
-
},
|
|
214
|
-
responses: {
|
|
215
|
-
204: {
|
|
216
|
-
description: 'Graph deleted successfully',
|
|
217
|
-
},
|
|
218
|
-
...commonGetErrorResponses,
|
|
219
|
-
},
|
|
220
|
-
}), async (c) => {
|
|
221
|
-
const { tenantId, projectId, graphId } = c.req.valid('param');
|
|
222
|
-
try {
|
|
223
|
-
const deleted = await deleteFullGraph(dbClient, logger)({
|
|
224
|
-
scopes: { tenantId, projectId },
|
|
225
|
-
graphId,
|
|
226
|
-
});
|
|
227
|
-
if (!deleted) {
|
|
228
|
-
throw createApiError({
|
|
229
|
-
code: 'not_found',
|
|
230
|
-
message: 'Graph not found',
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
return c.body(null, 204);
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
if (error instanceof Error && error.message.includes('not found')) {
|
|
237
|
-
throw createApiError({
|
|
238
|
-
code: 'not_found',
|
|
239
|
-
message: 'Graph not found',
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
throw createApiError({
|
|
243
|
-
code: 'internal_server_error',
|
|
244
|
-
message: error instanceof Error ? error.message : 'Failed to delete graph',
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
export default app;
|
package/dist/routes/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBhD,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAuB9B,eAAe,GAAG,CAAC"}
|
package/dist/routes/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
-
import agentArtifactComponentsRoutes from './agentArtifactComponents.js';
|
|
3
|
-
import agentDataComponentsRoutes from './agentDataComponents.js';
|
|
4
|
-
import agentGraphRoutes from './agentGraph.js';
|
|
5
|
-
import agentRelationsRoutes from './agentRelations.js';
|
|
6
|
-
// Import existing CRUD route modules (others can be added as they're created)
|
|
7
|
-
import agentsRoutes from './agents.js';
|
|
8
|
-
import agentToolRelationsRoutes from './agentToolRelations.js';
|
|
9
|
-
import apiKeysRoutes from './apiKeys.js';
|
|
10
|
-
import artifactComponentsRoutes from './artifactComponents.js';
|
|
11
|
-
import contextConfigsRoutes from './contextConfigs.js';
|
|
12
|
-
import credentialsRoutes from './credentials.js';
|
|
13
|
-
import dataComponentsRoutes from './dataComponents.js';
|
|
14
|
-
import externalAgentsRoutes from './externalAgents.js';
|
|
15
|
-
import graphFullRoutes from './graphFull.js';
|
|
16
|
-
import projectsRoutes from './projects.js';
|
|
17
|
-
import toolsRoutes from './tools.js';
|
|
18
|
-
const app = new OpenAPIHono();
|
|
19
|
-
// Mount projects route first (no projectId in path)
|
|
20
|
-
app.route('/projects', projectsRoutes);
|
|
21
|
-
// Mount existing CRUD routes under project scope
|
|
22
|
-
app.route('/projects/:projectId/agents', agentsRoutes);
|
|
23
|
-
app.route('/projects/:projectId/agent-relations', agentRelationsRoutes);
|
|
24
|
-
app.route('/projects/:projectId/agent-graphs', agentGraphRoutes);
|
|
25
|
-
app.route('/projects/:projectId/agent-tool-relations', agentToolRelationsRoutes);
|
|
26
|
-
app.route('/projects/:projectId/agent-artifact-components', agentArtifactComponentsRoutes);
|
|
27
|
-
app.route('/projects/:projectId/agent-data-components', agentDataComponentsRoutes);
|
|
28
|
-
app.route('/projects/:projectId/artifact-components', artifactComponentsRoutes);
|
|
29
|
-
app.route('/projects/:projectId/context-configs', contextConfigsRoutes);
|
|
30
|
-
app.route('/projects/:projectId/credentials', credentialsRoutes);
|
|
31
|
-
app.route('/projects/:projectId/data-components', dataComponentsRoutes);
|
|
32
|
-
app.route('/projects/:projectId/external-agents', externalAgentsRoutes);
|
|
33
|
-
app.route('/projects/:projectId/tools', toolsRoutes);
|
|
34
|
-
app.route('/projects/:projectId/api-keys', apiKeysRoutes);
|
|
35
|
-
// Mount new full graph CRUD routes
|
|
36
|
-
app.route('/projects/:projectId/graph', graphFullRoutes);
|
|
37
|
-
export default app;
|
package/dist/routes/oauth.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth Callback Handler
|
|
3
|
-
*
|
|
4
|
-
* Handles OAuth 2.1 authorization code flows for MCP tools:
|
|
5
|
-
* - Processes authorization codes from OAuth providers
|
|
6
|
-
* - Exchanges codes for access tokens using PKCE
|
|
7
|
-
* - Stores credentials in Keychain
|
|
8
|
-
* - Updates MCP tool status
|
|
9
|
-
* - Redirects users back to frontend
|
|
10
|
-
*/
|
|
11
|
-
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
12
|
-
import { type CredentialStoreRegistry, type ServerConfig } from '@inkeep/agents-core';
|
|
13
|
-
type AppVariables = {
|
|
14
|
-
serverConfig: ServerConfig;
|
|
15
|
-
credentialStores: CredentialStoreRegistry;
|
|
16
|
-
};
|
|
17
|
-
declare const app: OpenAPIHono<{
|
|
18
|
-
Variables: AppVariables;
|
|
19
|
-
}, {}, "/">;
|
|
20
|
-
export default app;
|
|
21
|
-
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/routes/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAe,WAAW,EAAK,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAOL,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAK7B,KAAK,YAAY,GAAG;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,uBAAuB,CAAC;CAC3C,CAAC;AAEF,QAAA,MAAM,GAAG;eAAgC,YAAY;WAAK,CAAC;AA8M3D,eAAe,GAAG,CAAC"}
|
package/dist/routes/oauth.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth Callback Handler
|
|
3
|
-
*
|
|
4
|
-
* Handles OAuth 2.1 authorization code flows for MCP tools:
|
|
5
|
-
* - Processes authorization codes from OAuth providers
|
|
6
|
-
* - Exchanges codes for access tokens using PKCE
|
|
7
|
-
* - Stores credentials in Keychain
|
|
8
|
-
* - Updates MCP tool status
|
|
9
|
-
* - Redirects users back to frontend
|
|
10
|
-
*/
|
|
11
|
-
import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi';
|
|
12
|
-
import { dbResultToMcpTool, getToolById, updateTool, createCredentialReference, getCredentialReference, updateCredentialReference, } from '@inkeep/agents-core';
|
|
13
|
-
import { getLogger } from '../logger.js';
|
|
14
|
-
import { oauthService, retrievePKCEVerifier } from '../utils/oauth-service.js';
|
|
15
|
-
import dbClient from '../data/db/dbClient.js';
|
|
16
|
-
const app = new OpenAPIHono();
|
|
17
|
-
const logger = getLogger('oauth-callback');
|
|
18
|
-
// OAuth callback endpoint schema
|
|
19
|
-
const OAuthCallbackQuerySchema = z.object({
|
|
20
|
-
code: z.string().min(1, 'Authorization code is required'),
|
|
21
|
-
state: z.string().min(1, 'State parameter is required'),
|
|
22
|
-
error: z.string().optional(),
|
|
23
|
-
error_description: z.string().optional(),
|
|
24
|
-
});
|
|
25
|
-
// OAuth callback endpoint
|
|
26
|
-
app.openapi(createRoute({
|
|
27
|
-
method: 'get',
|
|
28
|
-
path: '/callback',
|
|
29
|
-
summary: 'OAuth authorization callback',
|
|
30
|
-
description: 'Handles OAuth authorization codes and completes the authentication flow',
|
|
31
|
-
operationId: 'oauth-callback',
|
|
32
|
-
tags: ['OAuth'],
|
|
33
|
-
request: {
|
|
34
|
-
query: OAuthCallbackQuerySchema,
|
|
35
|
-
},
|
|
36
|
-
responses: {
|
|
37
|
-
302: {
|
|
38
|
-
description: 'Redirect to frontend after successful OAuth',
|
|
39
|
-
},
|
|
40
|
-
400: {
|
|
41
|
-
description: 'OAuth error or invalid request',
|
|
42
|
-
content: {
|
|
43
|
-
'text/html': {
|
|
44
|
-
schema: z.string(),
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
500: {
|
|
49
|
-
description: 'Internal server error',
|
|
50
|
-
content: {
|
|
51
|
-
'text/html': {
|
|
52
|
-
schema: z.string(),
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
}), async (c) => {
|
|
58
|
-
try {
|
|
59
|
-
const { code, state, error, error_description } = c.req.valid('query');
|
|
60
|
-
logger.info({ state, hasCode: !!code }, 'OAuth callback received');
|
|
61
|
-
// Check for OAuth errors
|
|
62
|
-
if (error) {
|
|
63
|
-
logger.error({ error, error_description }, 'OAuth authorization failed');
|
|
64
|
-
const errorMessage = 'OAuth Authorization Failed. Please try again.';
|
|
65
|
-
return c.text(errorMessage, 400);
|
|
66
|
-
}
|
|
67
|
-
// Retrieve PKCE verifier and tool info
|
|
68
|
-
const pkceData = retrievePKCEVerifier(state);
|
|
69
|
-
if (!pkceData) {
|
|
70
|
-
logger.error({ state }, 'Invalid or expired OAuth state');
|
|
71
|
-
return c.text('OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.', 400);
|
|
72
|
-
}
|
|
73
|
-
const { codeVerifier, toolId, tenantId, projectId, clientId } = pkceData;
|
|
74
|
-
// Get the MCP tool
|
|
75
|
-
const tool = await getToolById(dbClient)({
|
|
76
|
-
scopes: { tenantId, projectId },
|
|
77
|
-
toolId,
|
|
78
|
-
});
|
|
79
|
-
if (!tool) {
|
|
80
|
-
throw new Error(`Tool ${toolId} not found`);
|
|
81
|
-
}
|
|
82
|
-
logger.info({ toolId, tenantId, projectId }, 'Processing OAuth callback');
|
|
83
|
-
// Exchange authorization code for access token using OAuth service
|
|
84
|
-
logger.info('Exchanging authorization code for access token');
|
|
85
|
-
// Convert database result to McpTool (using helper function)
|
|
86
|
-
const mcpTool = dbResultToMcpTool(tool);
|
|
87
|
-
const { tokens } = await oauthService.exchangeCodeForTokens({
|
|
88
|
-
code,
|
|
89
|
-
codeVerifier,
|
|
90
|
-
clientId,
|
|
91
|
-
tool: mcpTool,
|
|
92
|
-
});
|
|
93
|
-
logger.info({ toolId, tokenType: tokens.token_type, hasRefresh: !!tokens.refresh_token }, 'Token exchange successful');
|
|
94
|
-
// Store access token in keychain
|
|
95
|
-
const credentialStores = c.get('credentialStores');
|
|
96
|
-
const keychainStore = credentialStores.get('keychain-default');
|
|
97
|
-
const keychainKey = `oauth_token_${toolId}`;
|
|
98
|
-
await keychainStore?.set(keychainKey, JSON.stringify(tokens));
|
|
99
|
-
const credentialId = tool.name;
|
|
100
|
-
const existingCredential = await getCredentialReference(dbClient)({
|
|
101
|
-
scopes: { tenantId, projectId },
|
|
102
|
-
id: credentialId,
|
|
103
|
-
});
|
|
104
|
-
const credentialData = {
|
|
105
|
-
type: 'keychain',
|
|
106
|
-
credentialStoreId: 'keychain-default',
|
|
107
|
-
retrievalParams: {
|
|
108
|
-
key: keychainKey,
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
let credential;
|
|
112
|
-
if (existingCredential) {
|
|
113
|
-
// Update existing credential
|
|
114
|
-
logger.info({ credentialId: existingCredential.id }, 'Updating existing credential');
|
|
115
|
-
credential = await updateCredentialReference(dbClient)({
|
|
116
|
-
scopes: { tenantId, projectId },
|
|
117
|
-
id: existingCredential.id,
|
|
118
|
-
data: credentialData,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
// Create new credential
|
|
123
|
-
logger.info('Creating new credential');
|
|
124
|
-
credential = await createCredentialReference(dbClient)({
|
|
125
|
-
tenantId,
|
|
126
|
-
projectId,
|
|
127
|
-
id: credentialId,
|
|
128
|
-
...credentialData,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
if (!credential) {
|
|
132
|
-
throw new Error('Failed to create or update credential');
|
|
133
|
-
}
|
|
134
|
-
// Update MCP tool to link the credential
|
|
135
|
-
await updateTool(dbClient)({
|
|
136
|
-
scopes: { tenantId, projectId },
|
|
137
|
-
toolId,
|
|
138
|
-
data: {
|
|
139
|
-
credentialReferenceId: credential.id,
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
logger.info({ toolId, credentialId: credential.id }, 'OAuth flow completed successfully');
|
|
143
|
-
// Show simple success page that auto-closes the tab
|
|
144
|
-
const successPage = `
|
|
145
|
-
<!DOCTYPE html>
|
|
146
|
-
<html>
|
|
147
|
-
<head>
|
|
148
|
-
<title>Authentication Complete</title>
|
|
149
|
-
<meta charset="utf-8">
|
|
150
|
-
</head>
|
|
151
|
-
<body>
|
|
152
|
-
<p>Authentication successful. Closing in <span id="countdown">3</span> seconds...</p>
|
|
153
|
-
<script>
|
|
154
|
-
let countdown = 3;
|
|
155
|
-
const countdownEl = document.getElementById('countdown');
|
|
156
|
-
|
|
157
|
-
// Notify parent window of successful authentication
|
|
158
|
-
if (window.opener) {
|
|
159
|
-
window.opener.postMessage({
|
|
160
|
-
type: 'oauth-success',
|
|
161
|
-
toolId: '${toolId}'
|
|
162
|
-
}, '*');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const timer = setInterval(() => {
|
|
166
|
-
countdown--;
|
|
167
|
-
countdownEl.textContent = countdown;
|
|
168
|
-
|
|
169
|
-
if (countdown <= 0) {
|
|
170
|
-
clearInterval(timer);
|
|
171
|
-
window.close();
|
|
172
|
-
}
|
|
173
|
-
}, 1000);
|
|
174
|
-
|
|
175
|
-
// Also try to close immediately for some browsers
|
|
176
|
-
setTimeout(() => {
|
|
177
|
-
window.close();
|
|
178
|
-
}, 3000);
|
|
179
|
-
</script>
|
|
180
|
-
</body>
|
|
181
|
-
</html>
|
|
182
|
-
`;
|
|
183
|
-
return c.html(successPage);
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
logger.error({ error }, 'OAuth callback processing failed');
|
|
187
|
-
const errorMessage = 'OAuth Processing Failed. Please try again.';
|
|
188
|
-
return c.text(errorMessage, 500);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
export default app;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/routes/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAqB7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAwP9B,eAAe,GAAG,CAAC"}
|