@inkeep/agents-api 0.43.0 → 0.44.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.
Files changed (74) hide show
  1. package/dist/.well-known/workflow/v1/manifest.debug.json +20 -20
  2. package/dist/.well-known/workflow/v1/step.cjs +211763 -195914
  3. package/dist/createApp.js +11 -9
  4. package/dist/domains/evals/routes/datasetTriggers.d.ts +2 -2
  5. package/dist/domains/evals/routes/index.d.ts +2 -2
  6. package/dist/domains/evals/workflow/routes.d.ts +2 -2
  7. package/dist/domains/manage/index.js +6 -0
  8. package/dist/domains/manage/routes/conversations.d.ts +2 -2
  9. package/dist/domains/manage/routes/github.d.ts +16 -0
  10. package/dist/domains/manage/routes/github.js +511 -0
  11. package/dist/domains/manage/routes/index.d.ts +2 -2
  12. package/dist/domains/manage/routes/mcp.d.ts +2 -2
  13. package/dist/domains/manage/routes/mcpToolGithubAccess.d.ts +9 -0
  14. package/dist/domains/manage/routes/mcpToolGithubAccess.js +205 -0
  15. package/dist/domains/manage/routes/projectGithubAccess.d.ts +9 -0
  16. package/dist/domains/manage/routes/projectGithubAccess.js +167 -0
  17. package/dist/domains/manage/routes/projectMembers.js +1 -14
  18. package/dist/domains/manage/routes/projectPermissions.js +2 -9
  19. package/dist/domains/manage/routes/projects.js +14 -16
  20. package/dist/domains/manage/routes/signoz.d.ts +2 -2
  21. package/dist/domains/manage/routes/signoz.js +1 -1
  22. package/dist/domains/manage/routes/tools.js +4 -2
  23. package/dist/domains/manage/routes/userProjectMemberships.js +1 -2
  24. package/dist/domains/mcp/routes/mcp.d.ts +2 -2
  25. package/dist/domains/run/agents/Agent.js +29 -2
  26. package/dist/domains/run/constants/execution-limits/defaults.d.ts +1 -1
  27. package/dist/domains/run/constants/execution-limits/defaults.js +1 -1
  28. package/dist/domains/run/constants/execution-limits/index.d.ts +1 -1
  29. package/dist/domains/run/context/ContextResolver.js +1 -1
  30. package/dist/domains/run/context/validation.d.ts +1 -1
  31. package/dist/domains/run/services/AgentSession.js +5 -1
  32. package/dist/domains/run/services/BaseCompressor.js +1 -1
  33. package/dist/domains/run/services/TriggerService.d.ts +1 -1
  34. package/dist/domains/run/services/TriggerService.js +15 -13
  35. package/dist/domains/run/tools/sandbox-utils.js +1 -1
  36. package/dist/domains/run/types/executionContext.js +3 -1
  37. package/dist/env.d.ts +12 -2
  38. package/dist/env.js +37 -32
  39. package/dist/factory.d.ts +7 -7
  40. package/dist/factory.js +4 -10
  41. package/dist/index.d.ts +6 -5
  42. package/dist/index.js +3 -5
  43. package/dist/middleware/branchScopedDb.d.ts +1 -1
  44. package/dist/middleware/evalsAuth.d.ts +2 -2
  45. package/dist/middleware/manageAuth.d.ts +2 -2
  46. package/dist/middleware/projectAccess.d.ts +2 -11
  47. package/dist/middleware/projectAccess.js +7 -33
  48. package/dist/middleware/projectConfig.d.ts +3 -3
  49. package/dist/middleware/ref.d.ts +1 -1
  50. package/dist/middleware/requirePermission.d.ts +2 -2
  51. package/dist/middleware/requirePermission.js +1 -2
  52. package/dist/middleware/runAuth.d.ts +4 -4
  53. package/dist/middleware/sessionAuth.d.ts +3 -3
  54. package/dist/middleware/sessionAuth.js +1 -2
  55. package/dist/middleware/tenantAccess.d.ts +2 -2
  56. package/dist/middleware/tracing.d.ts +3 -3
  57. package/dist/openapi.d.ts +1 -0
  58. package/dist/openapi.js +1 -0
  59. package/dist/types/runExecutionContext.js +3 -1
  60. package/package.json +5 -4
  61. package/dist/domains/github/config.d.ts +0 -14
  62. package/dist/domains/github/config.js +0 -47
  63. package/dist/domains/github/index.d.ts +0 -12
  64. package/dist/domains/github/index.js +0 -18
  65. package/dist/domains/github/installation.d.ts +0 -34
  66. package/dist/domains/github/installation.js +0 -172
  67. package/dist/domains/github/jwks.d.ts +0 -20
  68. package/dist/domains/github/jwks.js +0 -85
  69. package/dist/domains/github/oidcToken.d.ts +0 -22
  70. package/dist/domains/github/oidcToken.js +0 -140
  71. package/dist/domains/github/routes/tokenExchange.d.ts +0 -7
  72. package/dist/domains/github/routes/tokenExchange.js +0 -130
  73. package/dist/initialization.d.ts +0 -6
  74. package/dist/initialization.js +0 -72
@@ -1,23 +1,13 @@
1
- import { env } from "../env.js";
2
- import { canEditProject, canUseProject, canViewProject, createApiError, isAuthzEnabled } from "@inkeep/agents-core";
1
+ import { canEditProject, canUseProject, canViewProject, createApiError } from "@inkeep/agents-core";
3
2
  import { createMiddleware } from "hono/factory";
4
3
  import { HTTPException } from "hono/http-exception";
5
4
 
6
5
  //#region src/middleware/projectAccess.ts
7
6
  /**
8
7
  * Middleware to check project-level access.
9
- *
10
- * When ENABLE_AUTHZ is false:
11
- * - 'view' permission: all org members can view
12
- * - 'edit': only org owner/admin
13
- *
14
- * When ENABLE_AUTHZ is true:
15
- * - Uses SpiceDB to check permissions
16
- * - Org owner/admin bypass (handled in canViewProject etc.)
17
8
  */
18
9
  const requireProjectPermission = (permission = "view") => createMiddleware(async (c, next) => {
19
- const isTestEnvironment = process.env.ENVIRONMENT === "test";
20
- if (env.DISABLE_AUTH || isTestEnvironment) {
10
+ if (process.env.ENVIRONMENT === "test") {
21
11
  await next();
22
12
  return;
23
13
  }
@@ -64,27 +54,11 @@ const requireProjectPermission = (permission = "view") => createMiddleware(async
64
54
  });
65
55
  break;
66
56
  }
67
- if (!hasAccess) {
68
- if (isAuthzEnabled()) throw createApiError({
69
- code: "not_found",
70
- message: "Project not found",
71
- instance: c.req.path
72
- });
73
- throw createApiError({
74
- code: "forbidden",
75
- message: `Permission denied. Required: project:${permission}`,
76
- instance: c.req.path,
77
- extensions: {
78
- requiredPermissions: [`project:${permission}`],
79
- context: {
80
- userId,
81
- organizationId: tenantId,
82
- projectId,
83
- currentRole: tenantRole
84
- }
85
- }
86
- });
87
- }
57
+ if (!hasAccess) throw createApiError({
58
+ code: "not_found",
59
+ message: "Project not found",
60
+ instance: c.req.path
61
+ });
88
62
  await next();
89
63
  } catch (error) {
90
64
  if (error instanceof HTTPException) throw error;
@@ -1,11 +1,11 @@
1
- import * as hono1 from "hono";
2
1
  import { BaseExecutionContext, ResolvedRef } from "@inkeep/agents-core";
2
+ import * as hono5 from "hono";
3
3
 
4
4
  //#region src/middleware/projectConfig.d.ts
5
5
  /**
6
6
  * Middleware that fetches the full project definition from the Management API
7
7
  */
8
- declare const projectConfigMiddleware: hono1.MiddlewareHandler<{
8
+ declare const projectConfigMiddleware: hono5.MiddlewareHandler<{
9
9
  Variables: {
10
10
  executionContext: BaseExecutionContext;
11
11
  resolvedRef: ResolvedRef;
@@ -15,7 +15,7 @@ declare const projectConfigMiddleware: hono1.MiddlewareHandler<{
15
15
  * Creates a middleware that applies project config fetching except for specified route patterns
16
16
  * @param skipRouteCheck - Function that returns true if the route should skip the middleware
17
17
  */
18
- declare const projectConfigMiddlewareExcept: (skipRouteCheck: (path: string) => boolean) => hono1.MiddlewareHandler<{
18
+ declare const projectConfigMiddlewareExcept: (skipRouteCheck: (path: string) => boolean) => hono5.MiddlewareHandler<{
19
19
  Variables: {
20
20
  executionContext: BaseExecutionContext;
21
21
  resolvedRef: ResolvedRef;
@@ -1,5 +1,5 @@
1
- import { Context, Next } from "hono";
2
1
  import { AgentsManageDatabaseClient, ResolvedRef } from "@inkeep/agents-core";
2
+ import { Context, Next } from "hono";
3
3
 
4
4
  //#region src/middleware/ref.d.ts
5
5
  type RefContext = {
@@ -1,5 +1,5 @@
1
1
  import { ManageAppVariables } from "../types/app.js";
2
- import * as hono14 from "hono";
2
+ import * as hono8 from "hono";
3
3
 
4
4
  //#region src/middleware/requirePermission.d.ts
5
5
  type Permission = {
@@ -9,6 +9,6 @@ declare const requirePermission: <Env$1 extends {
9
9
  Variables: ManageAppVariables;
10
10
  } = {
11
11
  Variables: ManageAppVariables;
12
- }>(permissions: Permission) => hono14.MiddlewareHandler<Env$1, string, {}, Response>;
12
+ }>(permissions: Permission) => hono8.MiddlewareHandler<Env$1, string, {}, Response>;
13
13
  //#endregion
14
14
  export { requirePermission };
@@ -1,4 +1,3 @@
1
- import { env } from "../env.js";
2
1
  import { createApiError } from "@inkeep/agents-core";
3
2
  import { createMiddleware } from "hono/factory";
4
3
  import { HTTPException } from "hono/http-exception";
@@ -15,7 +14,7 @@ function formatPermissionsForDisplay(permissions) {
15
14
  const requirePermission = (permissions) => createMiddleware(async (c, next) => {
16
15
  const isTestEnvironment = process.env.ENVIRONMENT === "test";
17
16
  const auth = c.get("auth");
18
- if (env.DISABLE_AUTH || isTestEnvironment || !auth) {
17
+ if (isTestEnvironment || !auth) {
19
18
  await next();
20
19
  return;
21
20
  }
@@ -1,8 +1,8 @@
1
- import * as hono5 from "hono";
2
1
  import { BaseExecutionContext } from "@inkeep/agents-core";
2
+ import * as hono9 from "hono";
3
3
 
4
4
  //#region src/middleware/runAuth.d.ts
5
- declare const runApiKeyAuth: () => hono5.MiddlewareHandler<{
5
+ declare const runApiKeyAuth: () => hono9.MiddlewareHandler<{
6
6
  Variables: {
7
7
  executionContext: BaseExecutionContext;
8
8
  };
@@ -11,7 +11,7 @@ declare const runApiKeyAuth: () => hono5.MiddlewareHandler<{
11
11
  * Creates a middleware that applies API key authentication except for specified route patterns
12
12
  * @param skipRouteCheck - Function that returns true if the route should skip authentication
13
13
  */
14
- declare const runApiKeyAuthExcept: (skipRouteCheck: (path: string) => boolean) => hono5.MiddlewareHandler<{
14
+ declare const runApiKeyAuthExcept: (skipRouteCheck: (path: string) => boolean) => hono9.MiddlewareHandler<{
15
15
  Variables: {
16
16
  executionContext: BaseExecutionContext;
17
17
  };
@@ -20,7 +20,7 @@ declare const runApiKeyAuthExcept: (skipRouteCheck: (path: string) => boolean) =
20
20
  * Helper middleware for endpoints that optionally support API key authentication
21
21
  * If no auth header is present, it continues without setting the executionContext
22
22
  */
23
- declare const runOptionalAuth: () => hono5.MiddlewareHandler<{
23
+ declare const runOptionalAuth: () => hono9.MiddlewareHandler<{
24
24
  Variables: {
25
25
  executionContext?: BaseExecutionContext;
26
26
  };
@@ -1,4 +1,4 @@
1
- import * as hono8 from "hono";
1
+ import * as hono12 from "hono";
2
2
 
3
3
  //#region src/middleware/sessionAuth.d.ts
4
4
 
@@ -7,11 +7,11 @@ import * as hono8 from "hono";
7
7
  * Requires that a user has already been authenticated via Better Auth session.
8
8
  * Used primarily for manage routes that require an active user session.
9
9
  */
10
- declare const sessionAuth: () => hono8.MiddlewareHandler<any, string, {}, Response>;
10
+ declare const sessionAuth: () => hono12.MiddlewareHandler<any, string, {}, Response>;
11
11
  /**
12
12
  * Global session middleware - sets user and session in context for all routes
13
13
  * Used for all routes that require an active user session.
14
14
  */
15
- declare const sessionContext: () => hono8.MiddlewareHandler<any, string, {}, Response>;
15
+ declare const sessionContext: () => hono12.MiddlewareHandler<any, string, {}, Response>;
16
16
  //#endregion
17
17
  export { sessionAuth, sessionContext };
@@ -1,4 +1,3 @@
1
- import { env } from "../env.js";
2
1
  import { createApiError } from "@inkeep/agents-core";
3
2
  import { createMiddleware } from "hono/factory";
4
3
  import { HTTPException } from "hono/http-exception";
@@ -33,7 +32,7 @@ const sessionAuth = () => createMiddleware(async (c, next) => {
33
32
  */
34
33
  const sessionContext = () => createMiddleware(async (c, next) => {
35
34
  const auth = c.get("auth");
36
- if (env.DISABLE_AUTH || !auth) {
35
+ if (!auth) {
37
36
  c.set("user", null);
38
37
  c.set("session", null);
39
38
  await next();
@@ -1,4 +1,4 @@
1
- import * as hono15 from "hono";
1
+ import * as hono14 from "hono";
2
2
 
3
3
  //#region src/middleware/tenantAccess.d.ts
4
4
 
@@ -11,7 +11,7 @@ import * as hono15 from "hono";
11
11
  * - API key user: Access only to the tenant associated with the API key
12
12
  * - Session user: Access based on organization membership
13
13
  */
14
- declare const requireTenantAccess: () => hono15.MiddlewareHandler<{
14
+ declare const requireTenantAccess: () => hono14.MiddlewareHandler<{
15
15
  Variables: {
16
16
  userId: string;
17
17
  tenantId: string;
@@ -1,7 +1,7 @@
1
- import * as hono10 from "hono";
1
+ import * as hono15 from "hono";
2
2
 
3
3
  //#region src/middleware/tracing.d.ts
4
- declare const otelBaggageMiddleware: () => hono10.MiddlewareHandler<any, string, {}, Response>;
5
- declare const executionBaggageMiddleware: () => hono10.MiddlewareHandler<any, string, {}, Response>;
4
+ declare const otelBaggageMiddleware: () => hono15.MiddlewareHandler<any, string, {}, Response>;
5
+ declare const executionBaggageMiddleware: () => hono15.MiddlewareHandler<any, string, {}, Response>;
6
6
  //#endregion
7
7
  export { executionBaggageMiddleware, otelBaggageMiddleware };
package/dist/openapi.d.ts CHANGED
@@ -19,6 +19,7 @@ declare const TagToDescription: {
19
19
  'External Agents': string;
20
20
  'Function Tools': string;
21
21
  Functions: string;
22
+ GitHub: string;
22
23
  Invitations: string;
23
24
  MCP: string;
24
25
  'MCP Catalog': string;
package/dist/openapi.js CHANGED
@@ -18,6 +18,7 @@ const TagToDescription = {
18
18
  "External Agents": "Operations for managing external agents",
19
19
  "Function Tools": "Operations for managing function tools",
20
20
  Functions: "Operations for managing functions",
21
+ GitHub: "GitHub App integration endpoints",
21
22
  Invitations: "Operations for managing invitations",
22
23
  MCP: "MCP (Model Context Protocol) endpoints",
23
24
  "MCP Catalog": "Operations for MCP catalog",
@@ -1,3 +1,5 @@
1
+ import { env } from "../env.js";
2
+
1
3
  //#region src/types/runExecutionContext.ts
2
4
  /**
3
5
  * Extract userId from execution context metadata (when available)
@@ -16,7 +18,7 @@ function createBaseExecutionContext(params) {
16
18
  tenantId: params.tenantId,
17
19
  projectId: params.projectId,
18
20
  agentId: params.agentId,
19
- baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
21
+ baseUrl: params.baseUrl || env.INKEEP_AGENTS_API_URL,
20
22
  apiKeyId: params.apiKeyId,
21
23
  subAgentId: params.subAgentId,
22
24
  ref: params.ref,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-api",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "Unified Inkeep Agents API - combines management, runtime, and evaluation capabilities",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -66,9 +66,10 @@
66
66
  "openid-client": "^6.8.1",
67
67
  "pg": "^8.16.3",
68
68
  "workflow": "4.0.1-beta.33",
69
- "@inkeep/agents-core": "^0.43.0",
70
- "@inkeep/agents-mcp": "^0.43.0",
71
- "@inkeep/agents-manage-mcp": "^0.43.0"
69
+ "@inkeep/agents-core": "^0.44.0",
70
+ "@inkeep/agents-manage-mcp": "^0.44.0",
71
+ "@inkeep/agents-mcp": "^0.44.0",
72
+ "@inkeep/agents-work-apps": "^0.44.0"
72
73
  },
73
74
  "peerDependencies": {
74
75
  "@hono/zod-openapi": "^1.1.5",
@@ -1,14 +0,0 @@
1
- import { z } from "@hono/zod-openapi";
2
-
3
- //#region src/domains/github/config.d.ts
4
- declare const GitHubAppConfigSchema: z.ZodObject<{
5
- appId: z.ZodString;
6
- privateKey: z.ZodString;
7
- }, z.core.$strip>;
8
- type GitHubAppConfig = z.infer<typeof GitHubAppConfigSchema>;
9
- declare function getGitHubAppConfig(): GitHubAppConfig;
10
- declare function isGitHubAppConfigured(): boolean;
11
- declare function validateGitHubAppConfigOnStartup(): void;
12
- declare function clearConfigCache(): void;
13
- //#endregion
14
- export { GitHubAppConfig, clearConfigCache, getGitHubAppConfig, isGitHubAppConfigured, validateGitHubAppConfigOnStartup };
@@ -1,47 +0,0 @@
1
- import { getLogger } from "../../logger.js";
2
- import { z } from "@hono/zod-openapi";
3
-
4
- //#region src/domains/github/config.ts
5
- const logger = getLogger("github-config");
6
- const GitHubAppConfigSchema = z.object({
7
- appId: z.string().min(1, "GITHUB_APP_ID is required"),
8
- privateKey: z.string().min(1, "GITHUB_APP_PRIVATE_KEY is required")
9
- });
10
- let cachedConfig = null;
11
- function getGitHubAppConfig() {
12
- if (cachedConfig) return cachedConfig;
13
- const appId = process.env.GITHUB_APP_ID;
14
- const privateKey = process.env.GITHUB_APP_PRIVATE_KEY?.replace(/\\n/g, "\n");
15
- const result = GitHubAppConfigSchema.safeParse({
16
- appId,
17
- privateKey
18
- });
19
- if (!result.success) {
20
- const errorMessage = `GitHub App credentials are not configured. ${result.error.issues.map((issue) => issue.message).join(". ")}. Please set GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY environment variables.`;
21
- logger.error({}, errorMessage);
22
- throw new Error(errorMessage);
23
- }
24
- cachedConfig = result.data;
25
- logger.info({}, "GitHub App credentials loaded successfully");
26
- return cachedConfig;
27
- }
28
- function isGitHubAppConfigured() {
29
- return Boolean(process.env.GITHUB_APP_ID && process.env.GITHUB_APP_PRIVATE_KEY);
30
- }
31
- function validateGitHubAppConfigOnStartup() {
32
- if (!isGitHubAppConfigured()) {
33
- logger.warn({}, "GitHub App credentials not configured. Token exchange endpoint will return 500 errors. Set GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY to enable the feature.");
34
- return;
35
- }
36
- try {
37
- getGitHubAppConfig();
38
- } catch (error) {
39
- logger.error({ error }, "GitHub App credentials are invalid. Token exchange endpoint will return 500 errors.");
40
- }
41
- }
42
- function clearConfigCache() {
43
- cachedConfig = null;
44
- }
45
-
46
- //#endregion
47
- export { clearConfigCache, getGitHubAppConfig, isGitHubAppConfigured, validateGitHubAppConfigOnStartup };
@@ -1,12 +0,0 @@
1
- import { GitHubAppConfig, getGitHubAppConfig, isGitHubAppConfigured } from "./config.js";
2
- import { GenerateInstallationAccessTokenResult, GenerateTokenError, GenerateTokenResult, InstallationAccessToken, InstallationInfo, LookupInstallationError, LookupInstallationForRepoResult, LookupInstallationResult, generateInstallationAccessToken, lookupInstallationForRepo } from "./installation.js";
3
- import { GetJwkResult, JwksError, JwksResult, clearJwksCache, getJwkForToken, getJwksCacheStatus } from "./jwks.js";
4
- import { GitHubOidcClaims, ValidateOidcTokenResult, ValidateTokenError, ValidateTokenResult, validateOidcToken } from "./oidcToken.js";
5
- import { Hono } from "hono";
6
- import * as hono_types5 from "hono/types";
7
-
8
- //#region src/domains/github/index.d.ts
9
- declare function createGithubRoutes(): Hono<hono_types5.BlankEnv, hono_types5.BlankSchema, "/">;
10
- declare const githubRoutes: Hono<hono_types5.BlankEnv, hono_types5.BlankSchema, "/">;
11
- //#endregion
12
- export { type GenerateInstallationAccessTokenResult, type GenerateTokenError, type GenerateTokenResult, type GetJwkResult, type GitHubAppConfig, type GitHubOidcClaims, type InstallationAccessToken, type InstallationInfo, type JwksError, type JwksResult, type LookupInstallationError, type LookupInstallationForRepoResult, type LookupInstallationResult, type ValidateOidcTokenResult, type ValidateTokenError, type ValidateTokenResult, clearJwksCache, createGithubRoutes, generateInstallationAccessToken, getGitHubAppConfig, getJwkForToken, getJwksCacheStatus, githubRoutes, isGitHubAppConfigured, lookupInstallationForRepo, validateOidcToken };
@@ -1,18 +0,0 @@
1
- import { getGitHubAppConfig, isGitHubAppConfigured, validateGitHubAppConfigOnStartup } from "./config.js";
2
- import { generateInstallationAccessToken, lookupInstallationForRepo } from "./installation.js";
3
- import { clearJwksCache, getJwkForToken, getJwksCacheStatus } from "./jwks.js";
4
- import { validateOidcToken } from "./oidcToken.js";
5
- import tokenExchange_default from "./routes/tokenExchange.js";
6
- import { Hono } from "hono";
7
-
8
- //#region src/domains/github/index.ts
9
- function createGithubRoutes() {
10
- validateGitHubAppConfigOnStartup();
11
- const app = new Hono();
12
- app.route("/token-exchange", tokenExchange_default);
13
- return app;
14
- }
15
- const githubRoutes = createGithubRoutes();
16
-
17
- //#endregion
18
- export { clearJwksCache, createGithubRoutes, generateInstallationAccessToken, getGitHubAppConfig, getJwkForToken, getJwksCacheStatus, githubRoutes, isGitHubAppConfigured, lookupInstallationForRepo, validateOidcToken };
@@ -1,34 +0,0 @@
1
- //#region src/domains/github/installation.d.ts
2
- interface InstallationInfo {
3
- installationId: number;
4
- accountLogin: string;
5
- accountType: 'User' | 'Organization';
6
- }
7
- interface LookupInstallationResult {
8
- success: true;
9
- installation: InstallationInfo;
10
- }
11
- interface LookupInstallationError {
12
- success: false;
13
- errorType: 'not_installed' | 'api_error' | 'jwt_error';
14
- message: string;
15
- }
16
- type LookupInstallationForRepoResult = LookupInstallationResult | LookupInstallationError;
17
- interface InstallationAccessToken {
18
- token: string;
19
- expiresAt: string;
20
- }
21
- interface GenerateTokenResult {
22
- success: true;
23
- accessToken: InstallationAccessToken;
24
- }
25
- interface GenerateTokenError {
26
- success: false;
27
- errorType: 'api_error' | 'jwt_error';
28
- message: string;
29
- }
30
- type GenerateInstallationAccessTokenResult = GenerateTokenResult | GenerateTokenError;
31
- declare function lookupInstallationForRepo(repositoryOwner: string, repositoryName: string): Promise<LookupInstallationForRepoResult>;
32
- declare function generateInstallationAccessToken(installationId: number): Promise<GenerateInstallationAccessTokenResult>;
33
- //#endregion
34
- export { GenerateInstallationAccessTokenResult, GenerateTokenError, GenerateTokenResult, InstallationAccessToken, InstallationInfo, LookupInstallationError, LookupInstallationForRepoResult, LookupInstallationResult, generateInstallationAccessToken, lookupInstallationForRepo };
@@ -1,172 +0,0 @@
1
- import { getLogger } from "../../logger.js";
2
- import { getGitHubAppConfig } from "./config.js";
3
- import { createPrivateKey } from "node:crypto";
4
- import { SignJWT } from "jose";
5
-
6
- //#region src/domains/github/installation.ts
7
- const logger = getLogger("github-installation");
8
- const GITHUB_API_BASE = "https://api.github.com";
9
- async function createAppJwt() {
10
- const config = getGitHubAppConfig();
11
- const privateKey = createPrivateKey({
12
- key: config.privateKey,
13
- format: "pem"
14
- });
15
- const now = Math.floor(Date.now() / 1e3);
16
- return await new SignJWT({}).setProtectedHeader({ alg: "RS256" }).setIssuedAt(now - 60).setExpirationTime(now + 600).setIssuer(config.appId).sign(privateKey);
17
- }
18
- async function lookupInstallationForRepo(repositoryOwner, repositoryName) {
19
- let appJwt;
20
- try {
21
- appJwt = await createAppJwt();
22
- } catch (error) {
23
- const message = error instanceof Error ? error.message : "Unknown error";
24
- logger.error({ error: message }, "Failed to create GitHub App JWT");
25
- return {
26
- success: false,
27
- errorType: "jwt_error",
28
- message: `Failed to create GitHub App authentication: ${message}`
29
- };
30
- }
31
- const url = `${GITHUB_API_BASE}/repos/${repositoryOwner}/${repositoryName}/installation`;
32
- try {
33
- const response = await fetch(url, {
34
- method: "GET",
35
- headers: {
36
- Authorization: `Bearer ${appJwt}`,
37
- Accept: "application/vnd.github+json",
38
- "X-GitHub-Api-Version": "2022-11-28",
39
- "User-Agent": "inkeep-agents-api"
40
- }
41
- });
42
- if (response.status === 404) return {
43
- success: false,
44
- errorType: "not_installed",
45
- message: `GitHub App is not installed on repository ${repositoryOwner}/${repositoryName}. Please install the Inkeep Agents GitHub App on the repository to enable token exchange.`
46
- };
47
- if (!response.ok) {
48
- const errorText = await response.text();
49
- logger.error({
50
- status: response.status,
51
- error: errorText,
52
- repositoryOwner,
53
- repositoryName
54
- }, "GitHub API error looking up installation");
55
- return {
56
- success: false,
57
- errorType: "api_error",
58
- message: `GitHub API error (${response.status}): Failed to look up installation for repository`
59
- };
60
- }
61
- const data = await response.json();
62
- const installationId = data.id;
63
- const accountLogin = data.account?.login;
64
- const accountType = data.account?.type;
65
- if (typeof installationId !== "number" || typeof accountLogin !== "string") {
66
- logger.error({ data }, "Unexpected response format from GitHub API");
67
- return {
68
- success: false,
69
- errorType: "api_error",
70
- message: "Unexpected response format from GitHub API"
71
- };
72
- }
73
- logger.info({
74
- installationId,
75
- accountLogin,
76
- accountType,
77
- repositoryOwner,
78
- repositoryName
79
- }, "Found GitHub App installation for repository");
80
- return {
81
- success: true,
82
- installation: {
83
- installationId,
84
- accountLogin,
85
- accountType: accountType === "Organization" ? "Organization" : "User"
86
- }
87
- };
88
- } catch (error) {
89
- const message = error instanceof Error ? error.message : "Unknown error";
90
- logger.error({
91
- error: message,
92
- repositoryOwner,
93
- repositoryName
94
- }, "Error calling GitHub API to look up installation");
95
- return {
96
- success: false,
97
- errorType: "api_error",
98
- message: `Failed to connect to GitHub API: ${message}`
99
- };
100
- }
101
- }
102
- async function generateInstallationAccessToken(installationId) {
103
- let appJwt;
104
- try {
105
- appJwt = await createAppJwt();
106
- } catch (error) {
107
- const message = error instanceof Error ? error.message : "Unknown error";
108
- logger.error({ error: message }, "Failed to create GitHub App JWT for token generation");
109
- return {
110
- success: false,
111
- errorType: "jwt_error",
112
- message: `Failed to create GitHub App authentication: ${message}`
113
- };
114
- }
115
- const url = `${GITHUB_API_BASE}/app/installations/${installationId}/access_tokens`;
116
- try {
117
- const response = await fetch(url, {
118
- method: "POST",
119
- headers: {
120
- Authorization: `Bearer ${appJwt}`,
121
- Accept: "application/vnd.github+json",
122
- "X-GitHub-Api-Version": "2022-11-28",
123
- "User-Agent": "inkeep-agents-api"
124
- }
125
- });
126
- if (!response.ok) {
127
- const errorText = await response.text();
128
- logger.error({
129
- status: response.status,
130
- error: errorText,
131
- installationId
132
- }, "GitHub API error generating installation access token");
133
- return {
134
- success: false,
135
- errorType: "api_error",
136
- message: `GitHub API error (${response.status}): Failed to generate installation access token`
137
- };
138
- }
139
- const data = await response.json();
140
- const token = data.token;
141
- const expiresAt = data.expires_at;
142
- if (typeof token !== "string" || typeof expiresAt !== "string") {
143
- logger.error({ data }, "Unexpected response format from GitHub API for token generation");
144
- return {
145
- success: false,
146
- errorType: "api_error",
147
- message: "Unexpected response format from GitHub API"
148
- };
149
- }
150
- return {
151
- success: true,
152
- accessToken: {
153
- token,
154
- expiresAt
155
- }
156
- };
157
- } catch (error) {
158
- const message = error instanceof Error ? error.message : "Unknown error";
159
- logger.error({
160
- error: message,
161
- installationId
162
- }, "Error calling GitHub API to generate installation access token");
163
- return {
164
- success: false,
165
- errorType: "api_error",
166
- message: `Failed to connect to GitHub API: ${message}`
167
- };
168
- }
169
- }
170
-
171
- //#endregion
172
- export { generateInstallationAccessToken, lookupInstallationForRepo };
@@ -1,20 +0,0 @@
1
- import { CryptoKey, JWSHeaderParameters } from "jose";
2
-
3
- //#region src/domains/github/jwks.d.ts
4
- interface JwksResult {
5
- success: true;
6
- key: CryptoKey;
7
- }
8
- interface JwksError {
9
- success: false;
10
- error: string;
11
- }
12
- type GetJwkResult = JwksResult | JwksError;
13
- declare function getJwkForToken(header: JWSHeaderParameters): Promise<GetJwkResult>;
14
- declare function clearJwksCache(): void;
15
- declare function getJwksCacheStatus(): {
16
- cached: boolean;
17
- expiresIn?: number;
18
- };
19
- //#endregion
20
- export { GetJwkResult, JwksError, JwksResult, clearJwksCache, getJwkForToken, getJwksCacheStatus };