@inkeep/agents-api 0.0.0-dev-20260202060901 → 0.0.0-dev-20260203023016

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 (57) hide show
  1. package/dist/.well-known/workflow/v1/manifest.debug.json +16 -16
  2. package/dist/.well-known/workflow/v1/step.cjs +57211 -56922
  3. package/dist/createApp.d.ts +2 -2
  4. package/dist/createApp.js +3 -3
  5. package/dist/domains/evals/routes/datasetTriggers.d.ts +2 -2
  6. package/dist/domains/evals/routes/index.d.ts +2 -2
  7. package/dist/domains/evals/workflow/routes.d.ts +2 -2
  8. package/dist/domains/manage/index.js +6 -0
  9. package/dist/domains/manage/routes/conversations.d.ts +2 -2
  10. package/dist/domains/manage/routes/evals/evaluationResults.d.ts +2 -2
  11. package/dist/domains/manage/routes/github.d.ts +16 -0
  12. package/dist/domains/manage/routes/github.js +511 -0
  13. package/dist/domains/manage/routes/index.d.ts +2 -2
  14. package/dist/domains/manage/routes/mcp.d.ts +2 -2
  15. package/dist/domains/manage/routes/mcpToolGithubAccess.d.ts +9 -0
  16. package/dist/domains/manage/routes/mcpToolGithubAccess.js +205 -0
  17. package/dist/domains/manage/routes/projectGithubAccess.d.ts +9 -0
  18. package/dist/domains/manage/routes/projectGithubAccess.js +167 -0
  19. package/dist/domains/manage/routes/tools.js +4 -2
  20. package/dist/domains/mcp/routes/mcp.d.ts +2 -2
  21. package/dist/domains/run/agents/Agent.js +7 -1
  22. package/dist/domains/run/constants/execution-limits/defaults.d.ts +1 -1
  23. package/dist/domains/run/constants/execution-limits/defaults.js +1 -1
  24. package/dist/domains/run/constants/execution-limits/index.d.ts +1 -1
  25. package/dist/domains/run/context/ContextResolver.js +1 -1
  26. package/dist/domains/run/services/AgentSession.js +5 -1
  27. package/dist/domains/run/services/BaseCompressor.js +1 -1
  28. package/dist/domains/run/types/executionContext.js +3 -1
  29. package/dist/env.d.ts +12 -0
  30. package/dist/env.js +7 -1
  31. package/dist/factory.d.ts +261 -261
  32. package/dist/index.d.ts +261 -261
  33. package/dist/middleware/evalsAuth.d.ts +2 -2
  34. package/dist/middleware/manageAuth.d.ts +2 -2
  35. package/dist/middleware/projectAccess.d.ts +2 -2
  36. package/dist/middleware/projectConfig.d.ts +3 -3
  37. package/dist/middleware/requirePermission.d.ts +2 -2
  38. package/dist/middleware/runAuth.d.ts +4 -4
  39. package/dist/middleware/sessionAuth.d.ts +3 -3
  40. package/dist/middleware/tenantAccess.d.ts +2 -2
  41. package/dist/middleware/tracing.d.ts +3 -3
  42. package/dist/openapi.d.ts +1 -0
  43. package/dist/openapi.js +1 -0
  44. package/dist/types/runExecutionContext.js +3 -1
  45. package/package.json +5 -4
  46. package/dist/domains/github/config.d.ts +0 -14
  47. package/dist/domains/github/config.js +0 -47
  48. package/dist/domains/github/index.d.ts +0 -12
  49. package/dist/domains/github/index.js +0 -18
  50. package/dist/domains/github/installation.d.ts +0 -34
  51. package/dist/domains/github/installation.js +0 -172
  52. package/dist/domains/github/jwks.d.ts +0 -20
  53. package/dist/domains/github/jwks.js +0 -85
  54. package/dist/domains/github/oidcToken.d.ts +0 -22
  55. package/dist/domains/github/oidcToken.js +0 -140
  56. package/dist/domains/github/routes/tokenExchange.d.ts +0 -7
  57. package/dist/domains/github/routes/tokenExchange.js +0 -130
@@ -1,5 +1,5 @@
1
1
  import { BaseExecutionContext } from "@inkeep/agents-core";
2
- import * as hono0 from "hono";
2
+ import * as hono4 from "hono";
3
3
 
4
4
  //#region src/middleware/evalsAuth.d.ts
5
5
 
@@ -7,7 +7,7 @@ import * as hono0 from "hono";
7
7
  * Middleware to authenticate API requests using Bearer token authentication
8
8
  * First checks if token matches INKEEP_AGENTS_EVAL_API_BYPASS_SECRET,
9
9
  */
10
- declare const evalApiKeyAuth: () => hono0.MiddlewareHandler<{
10
+ declare const evalApiKeyAuth: () => hono4.MiddlewareHandler<{
11
11
  Variables: {
12
12
  executionContext: BaseExecutionContext;
13
13
  };
@@ -1,5 +1,5 @@
1
1
  import { BaseExecutionContext } from "@inkeep/agents-core";
2
- import * as hono1 from "hono";
2
+ import * as hono16 from "hono";
3
3
  import { createAuth } from "@inkeep/agents-core/auth";
4
4
 
5
5
  //#region src/middleware/manageAuth.d.ts
@@ -12,7 +12,7 @@ import { createAuth } from "@inkeep/agents-core/auth";
12
12
  * 3. Database API key
13
13
  * 4. Internal service token
14
14
  */
15
- declare const manageApiKeyAuth: () => hono1.MiddlewareHandler<{
15
+ declare const manageApiKeyAuth: () => hono16.MiddlewareHandler<{
16
16
  Variables: {
17
17
  executionContext: BaseExecutionContext;
18
18
  userId?: string;
@@ -1,6 +1,6 @@
1
1
  import { ManageAppVariables } from "../types/app.js";
2
2
  import { ProjectPermissionLevel } from "@inkeep/agents-core";
3
- import * as hono2 from "hono";
3
+ import * as hono17 from "hono";
4
4
 
5
5
  //#region src/middleware/projectAccess.d.ts
6
6
  /**
@@ -10,6 +10,6 @@ declare const requireProjectPermission: <Env$1 extends {
10
10
  Variables: ManageAppVariables;
11
11
  } = {
12
12
  Variables: ManageAppVariables;
13
- }>(permission?: ProjectPermissionLevel) => hono2.MiddlewareHandler<Env$1, string, {}, Response>;
13
+ }>(permission?: ProjectPermissionLevel) => hono17.MiddlewareHandler<Env$1, string, {}, Response>;
14
14
  //#endregion
15
15
  export { requireProjectPermission };
@@ -1,11 +1,11 @@
1
1
  import { BaseExecutionContext, ResolvedRef } from "@inkeep/agents-core";
2
- import * as hono3 from "hono";
2
+ import * as hono9 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: hono3.MiddlewareHandler<{
8
+ declare const projectConfigMiddleware: hono9.MiddlewareHandler<{
9
9
  Variables: {
10
10
  executionContext: BaseExecutionContext;
11
11
  resolvedRef: ResolvedRef;
@@ -15,7 +15,7 @@ declare const projectConfigMiddleware: hono3.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) => hono3.MiddlewareHandler<{
18
+ declare const projectConfigMiddlewareExcept: (skipRouteCheck: (path: string) => boolean) => hono9.MiddlewareHandler<{
19
19
  Variables: {
20
20
  executionContext: BaseExecutionContext;
21
21
  resolvedRef: ResolvedRef;
@@ -1,5 +1,5 @@
1
1
  import { ManageAppVariables } from "../types/app.js";
2
- import * as hono5 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) => hono5.MiddlewareHandler<Env$1, string, {}, Response>;
12
+ }>(permissions: Permission) => hono8.MiddlewareHandler<Env$1, string, {}, Response>;
13
13
  //#endregion
14
14
  export { requirePermission };
@@ -1,8 +1,8 @@
1
1
  import { BaseExecutionContext } from "@inkeep/agents-core";
2
- import * as hono6 from "hono";
2
+ import * as hono11 from "hono";
3
3
 
4
4
  //#region src/middleware/runAuth.d.ts
5
- declare const runApiKeyAuth: () => hono6.MiddlewareHandler<{
5
+ declare const runApiKeyAuth: () => hono11.MiddlewareHandler<{
6
6
  Variables: {
7
7
  executionContext: BaseExecutionContext;
8
8
  };
@@ -11,7 +11,7 @@ declare const runApiKeyAuth: () => hono6.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) => hono6.MiddlewareHandler<{
14
+ declare const runApiKeyAuthExcept: (skipRouteCheck: (path: string) => boolean) => hono11.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: () => hono6.MiddlewareHandler<{
23
+ declare const runOptionalAuth: () => hono11.MiddlewareHandler<{
24
24
  Variables: {
25
25
  executionContext?: BaseExecutionContext;
26
26
  };
@@ -1,4 +1,4 @@
1
- import * as hono9 from "hono";
1
+ import * as hono5 from "hono";
2
2
 
3
3
  //#region src/middleware/sessionAuth.d.ts
4
4
 
@@ -7,11 +7,11 @@ import * as hono9 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: () => hono9.MiddlewareHandler<any, string, {}, Response>;
10
+ declare const sessionAuth: () => hono5.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: () => hono9.MiddlewareHandler<any, string, {}, Response>;
15
+ declare const sessionContext: () => hono5.MiddlewareHandler<any, string, {}, Response>;
16
16
  //#endregion
17
17
  export { sessionAuth, sessionContext };
@@ -1,4 +1,4 @@
1
- import * as hono11 from "hono";
1
+ import * as hono2 from "hono";
2
2
 
3
3
  //#region src/middleware/tenantAccess.d.ts
4
4
 
@@ -11,7 +11,7 @@ import * as hono11 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: () => hono11.MiddlewareHandler<{
14
+ declare const requireTenantAccess: () => hono2.MiddlewareHandler<{
15
15
  Variables: {
16
16
  userId: string;
17
17
  tenantId: string;
@@ -1,7 +1,7 @@
1
- import * as hono12 from "hono";
1
+ import * as hono14 from "hono";
2
2
 
3
3
  //#region src/middleware/tracing.d.ts
4
- declare const otelBaggageMiddleware: () => hono12.MiddlewareHandler<any, string, {}, Response>;
5
- declare const executionBaggageMiddleware: () => hono12.MiddlewareHandler<any, string, {}, Response>;
4
+ declare const otelBaggageMiddleware: () => hono14.MiddlewareHandler<any, string, {}, Response>;
5
+ declare const executionBaggageMiddleware: () => hono14.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.0.0-dev-20260202060901",
3
+ "version": "0.0.0-dev-20260203023016",
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.0.0-dev-20260202060901",
70
- "@inkeep/agents-manage-mcp": "^0.0.0-dev-20260202060901",
71
- "@inkeep/agents-mcp": "^0.0.0-dev-20260202060901"
69
+ "@inkeep/agents-core": "^0.0.0-dev-20260203023016",
70
+ "@inkeep/agents-manage-mcp": "^0.0.0-dev-20260203023016",
71
+ "@inkeep/agents-mcp": "^0.0.0-dev-20260203023016",
72
+ "@inkeep/agents-work-apps": "^0.0.0-dev-20260203023016"
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 };
@@ -1,85 +0,0 @@
1
- import { getLogger } from "../../logger.js";
2
- import { createRemoteJWKSet } from "jose";
3
-
4
- //#region src/domains/github/jwks.ts
5
- const logger = getLogger("github-jwks");
6
- const GITHUB_OIDC_JWKS_URL = "https://token.actions.githubusercontent.com/.well-known/jwks";
7
- const CACHE_TTL_MS = 3600 * 1e3;
8
- let jwksCache = null;
9
- function createJwksWithLogging() {
10
- logger.info({}, "Creating new JWKS fetch function for GitHub OIDC");
11
- return createRemoteJWKSet(new URL(GITHUB_OIDC_JWKS_URL), { cacheMaxAge: CACHE_TTL_MS });
12
- }
13
- function isCacheExpired() {
14
- if (!jwksCache) return true;
15
- return Date.now() - jwksCache.fetchedAt > CACHE_TTL_MS;
16
- }
17
- function getOrCreateJwksFunction() {
18
- if (!jwksCache || isCacheExpired()) jwksCache = {
19
- jwks: createJwksWithLogging(),
20
- fetchedAt: Date.now()
21
- };
22
- return jwksCache.jwks;
23
- }
24
- async function getJwkForToken(header) {
25
- const kid = header.kid;
26
- if (!kid) return {
27
- success: false,
28
- error: "Token is missing key ID (kid) in header"
29
- };
30
- try {
31
- const key = await getOrCreateJwksFunction()(header);
32
- logger.debug({ kid }, "Successfully retrieved JWK for token");
33
- return {
34
- success: true,
35
- key
36
- };
37
- } catch (error) {
38
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
39
- if (errorMessage.includes("no applicable key found")) {
40
- logger.warn({ kid }, "Key ID not found in JWKS, refreshing cache");
41
- jwksCache = null;
42
- try {
43
- const key = await getOrCreateJwksFunction()(header);
44
- logger.info({ kid }, "Successfully retrieved JWK after cache refresh");
45
- return {
46
- success: true,
47
- key
48
- };
49
- } catch (retryError) {
50
- const retryErrorMessage = retryError instanceof Error ? retryError.message : "Unknown error";
51
- logger.error({
52
- kid,
53
- error: retryErrorMessage
54
- }, "Failed to retrieve JWK after cache refresh");
55
- return {
56
- success: false,
57
- error: `Key ID '${kid}' not found in GitHub OIDC JWKS`
58
- };
59
- }
60
- }
61
- logger.error({
62
- kid,
63
- error: errorMessage
64
- }, "Failed to fetch JWKS from GitHub");
65
- return {
66
- success: false,
67
- error: `Failed to fetch GitHub OIDC JWKS: ${errorMessage}`
68
- };
69
- }
70
- }
71
- function clearJwksCache() {
72
- jwksCache = null;
73
- logger.debug({}, "JWKS cache cleared");
74
- }
75
- function getJwksCacheStatus() {
76
- if (!jwksCache) return { cached: false };
77
- const expiresIn = CACHE_TTL_MS - (Date.now() - jwksCache.fetchedAt);
78
- return {
79
- cached: true,
80
- expiresIn: Math.max(0, expiresIn)
81
- };
82
- }
83
-
84
- //#endregion
85
- export { clearJwksCache, getJwkForToken, getJwksCacheStatus };
@@ -1,22 +0,0 @@
1
- //#region src/domains/github/oidcToken.d.ts
2
- interface GitHubOidcClaims {
3
- repository: string;
4
- repository_owner: string;
5
- repository_id: string;
6
- workflow: string;
7
- actor: string;
8
- ref: string;
9
- }
10
- interface ValidateTokenResult {
11
- success: true;
12
- claims: GitHubOidcClaims;
13
- }
14
- interface ValidateTokenError {
15
- success: false;
16
- errorType: 'invalid_signature' | 'expired' | 'wrong_issuer' | 'wrong_audience' | 'malformed' | 'jwks_error';
17
- message: string;
18
- }
19
- type ValidateOidcTokenResult = ValidateTokenResult | ValidateTokenError;
20
- declare function validateOidcToken(token: string): Promise<ValidateOidcTokenResult>;
21
- //#endregion
22
- export { GitHubOidcClaims, ValidateOidcTokenResult, ValidateTokenError, ValidateTokenResult, validateOidcToken };