@inkeep/agents-api 0.0.0-dev-20260127203411 → 0.0.0-dev-20260127205750
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.well-known/workflow/v1/manifest.debug.json +14 -14
- package/dist/createApp.d.ts +2 -2
- package/dist/data/db/manageDbClient.d.ts +2 -2
- package/dist/data/db/runDbClient.d.ts +2 -2
- package/dist/domains/evals/routes/datasetTriggers.d.ts +2 -2
- package/dist/domains/evals/routes/index.d.ts +2 -2
- package/dist/domains/evals/workflow/routes.d.ts +2 -2
- package/dist/domains/github/index.d.ts +3 -3
- package/dist/domains/github/routes/tokenExchange.d.ts +2 -2
- package/dist/domains/manage/routes/conversations.d.ts +2 -2
- package/dist/domains/manage/routes/evals/evaluationResults.d.ts +2 -2
- package/dist/domains/manage/routes/index.d.ts +2 -2
- package/dist/domains/manage/routes/mcp.d.ts +2 -2
- package/dist/domains/mcp/routes/mcp.d.ts +2 -2
- package/dist/domains/run/agents/relationTools.d.ts +2 -2
- package/dist/domains/run/utils/token-estimator.d.ts +2 -2
- package/dist/factory.d.ts +262 -262
- package/dist/index.d.ts +259 -259
- package/dist/middleware/evalsAuth.d.ts +2 -2
- package/dist/middleware/manageAuth.d.ts +2 -2
- package/dist/middleware/projectAccess.d.ts +2 -2
- package/dist/middleware/requirePermission.d.ts +2 -2
- package/dist/middleware/runAuth.d.ts +4 -4
- package/dist/middleware/sessionAuth.d.ts +3 -3
- package/dist/middleware/tenantAccess.d.ts +2 -2
- package/dist/middleware/tracing.d.ts +3 -3
- package/package.json +5 -10
- package/dist/domains/evals/services/startEvaluation.d.ts +0 -19
- package/dist/domains/evals/services/startEvaluation.js +0 -18
- package/dist/domains/index.d.ts +0 -5
- package/dist/domains/index.js +0 -6
- package/dist/domains/run/agents/ModelFactory.d.ts +0 -63
- package/dist/domains/run/agents/ModelFactory.js +0 -194
- package/dist/domains/run/data/agent.d.ts +0 -7
- package/dist/domains/run/data/agent.js +0 -67
- package/dist/domains/run/services/evaluationRunConfigMatcher.d.ts +0 -4
- package/dist/domains/run/services/evaluationRunConfigMatcher.js +0 -7
- package/dist/domains/run/utils/cleanup.d.ts +0 -21
- package/dist/domains/run/utils/cleanup.js +0 -59
- package/dist/utils/tempApiKeys.d.ts +0 -17
- package/dist/utils/tempApiKeys.js +0 -26
- package/dist/utils/workflowApiHelpers.d.ts +0 -1
- package/dist/utils/workflowApiHelpers.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as hono1 from "hono";
|
|
2
2
|
import { BaseExecutionContext } from "@inkeep/agents-core";
|
|
3
3
|
|
|
4
4
|
//#region src/middleware/evalsAuth.d.ts
|
|
@@ -7,7 +7,7 @@ import { BaseExecutionContext } from "@inkeep/agents-core";
|
|
|
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: () =>
|
|
10
|
+
declare const evalApiKeyAuth: () => hono1.MiddlewareHandler<{
|
|
11
11
|
Variables: {
|
|
12
12
|
executionContext: BaseExecutionContext;
|
|
13
13
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as hono17 from "hono";
|
|
2
2
|
import { BaseExecutionContext } from "@inkeep/agents-core";
|
|
3
3
|
import { createAuth } from "@inkeep/agents-core/auth";
|
|
4
4
|
|
|
@@ -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: () =>
|
|
15
|
+
declare const manageApiKeyAuth: () => hono17.MiddlewareHandler<{
|
|
16
16
|
Variables: {
|
|
17
17
|
executionContext: BaseExecutionContext;
|
|
18
18
|
userId?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ManageAppVariables } from "../types/app.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as hono2 from "hono";
|
|
3
3
|
import { ProjectPermissionLevel } from "@inkeep/agents-core";
|
|
4
4
|
|
|
5
5
|
//#region src/middleware/projectAccess.d.ts
|
|
@@ -19,6 +19,6 @@ declare const requireProjectPermission: <Env$1 extends {
|
|
|
19
19
|
Variables: ManageAppVariables;
|
|
20
20
|
} = {
|
|
21
21
|
Variables: ManageAppVariables;
|
|
22
|
-
}>(permission?: ProjectPermissionLevel) =>
|
|
22
|
+
}>(permission?: ProjectPermissionLevel) => hono2.MiddlewareHandler<Env$1, string, {}, Response>;
|
|
23
23
|
//#endregion
|
|
24
24
|
export { requireProjectPermission };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ManageAppVariables } from "../types/app.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as hono0 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) =>
|
|
12
|
+
}>(permissions: Permission) => hono0.MiddlewareHandler<Env$1, string, {}, Response>;
|
|
13
13
|
//#endregion
|
|
14
14
|
export { requirePermission };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as hono5 from "hono";
|
|
2
2
|
import { BaseExecutionContext } from "@inkeep/agents-core";
|
|
3
3
|
|
|
4
4
|
//#region src/middleware/runAuth.d.ts
|
|
5
|
-
declare const runApiKeyAuth: () =>
|
|
5
|
+
declare const runApiKeyAuth: () => hono5.MiddlewareHandler<{
|
|
6
6
|
Variables: {
|
|
7
7
|
executionContext: BaseExecutionContext;
|
|
8
8
|
};
|
|
@@ -11,7 +11,7 @@ declare const runApiKeyAuth: () => hono9.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) =>
|
|
14
|
+
declare const runApiKeyAuthExcept: (skipRouteCheck: (path: string) => boolean) => hono5.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: () =>
|
|
23
|
+
declare const runOptionalAuth: () => hono5.MiddlewareHandler<{
|
|
24
24
|
Variables: {
|
|
25
25
|
executionContext?: BaseExecutionContext;
|
|
26
26
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as hono8 from "hono";
|
|
2
2
|
|
|
3
3
|
//#region src/middleware/sessionAuth.d.ts
|
|
4
4
|
|
|
@@ -7,11 +7,11 @@ import * as hono13 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: () =>
|
|
10
|
+
declare const sessionAuth: () => hono8.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: () =>
|
|
15
|
+
declare const sessionContext: () => hono8.MiddlewareHandler<any, string, {}, Response>;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { sessionAuth, sessionContext };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as hono10 from "hono";
|
|
2
2
|
|
|
3
3
|
//#region src/middleware/tenantAccess.d.ts
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ import * as hono0 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: () =>
|
|
14
|
+
declare const requireTenantAccess: () => hono10.MiddlewareHandler<{
|
|
15
15
|
Variables: {
|
|
16
16
|
userId: string;
|
|
17
17
|
tenantId: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as hono11 from "hono";
|
|
2
2
|
|
|
3
3
|
//#region src/middleware/tracing.d.ts
|
|
4
|
-
declare const otelBaggageMiddleware: () =>
|
|
5
|
-
declare const executionBaggageMiddleware: () =>
|
|
4
|
+
declare const otelBaggageMiddleware: () => hono11.MiddlewareHandler<any, string, {}, Response>;
|
|
5
|
+
declare const executionBaggageMiddleware: () => hono11.MiddlewareHandler<any, string, {}, Response>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { executionBaggageMiddleware, otelBaggageMiddleware };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-api",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260127205750",
|
|
4
4
|
"description": "Unified Inkeep Agents API - combines management, runtime, and evaluation capabilities",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -32,17 +32,11 @@
|
|
|
32
32
|
"type": "module",
|
|
33
33
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@ai-sdk/anthropic": "3.0.7",
|
|
36
|
-
"@ai-sdk/gateway": "3.0.9",
|
|
37
35
|
"@ai-sdk/google": "3.0.4",
|
|
38
|
-
"@ai-sdk/openai": "3.0.7",
|
|
39
|
-
"@ai-sdk/openai-compatible": "2.0.4",
|
|
40
36
|
"@hono/mcp": "^0.1.5",
|
|
41
|
-
"@hono/otel": "^0.4.0",
|
|
42
37
|
"@hono/swagger-ui": "^0.5.1",
|
|
43
38
|
"@hono/zod-openapi": "^1.1.5",
|
|
44
39
|
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
45
|
-
"@openrouter/ai-sdk-provider": "^1.2.0",
|
|
46
40
|
"@opentelemetry/api": "^1.9.0",
|
|
47
41
|
"@opentelemetry/auto-instrumentations-node": "^0.64.1",
|
|
48
42
|
"@opentelemetry/baggage-span-processor": "^0.4.0",
|
|
@@ -72,9 +66,9 @@
|
|
|
72
66
|
"openid-client": "^6.8.1",
|
|
73
67
|
"pg": "^8.16.3",
|
|
74
68
|
"workflow": "4.0.1-beta.33",
|
|
75
|
-
"@inkeep/agents-core": "^0.0.0-dev-
|
|
76
|
-
"@inkeep/agents-manage-mcp": "^0.0.0-dev-
|
|
77
|
-
"@inkeep/agents-mcp": "^0.0.0-dev-
|
|
69
|
+
"@inkeep/agents-core": "^0.0.0-dev-20260127205750",
|
|
70
|
+
"@inkeep/agents-manage-mcp": "^0.0.0-dev-20260127205750",
|
|
71
|
+
"@inkeep/agents-mcp": "^0.0.0-dev-20260127205750"
|
|
78
72
|
},
|
|
79
73
|
"peerDependencies": {
|
|
80
74
|
"@hono/zod-openapi": "^1.1.5",
|
|
@@ -110,6 +104,7 @@
|
|
|
110
104
|
"directory": "agents-api"
|
|
111
105
|
},
|
|
112
106
|
"scripts": {
|
|
107
|
+
"knip": "knip --directory .. --workspace agents-api --config agents-api/knip.config.ts --dependencies --files",
|
|
113
108
|
"workflow:build": "tsx src/domains/evals/scripts/build-workflow.ts",
|
|
114
109
|
"well-known:copy": "tsx scripts/copy-well-known.ts",
|
|
115
110
|
"dev": "pnpm workflow:build && vite",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#region src/domains/evals/services/startEvaluation.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Service to start evaluation workflows.
|
|
4
|
-
* This encapsulates the workflow logic so consumers don't need to import workflow packages.
|
|
5
|
-
*/
|
|
6
|
-
interface StartEvaluationParams {
|
|
7
|
-
tenantId: string;
|
|
8
|
-
projectId: string;
|
|
9
|
-
conversationId: string;
|
|
10
|
-
evaluatorIds: string[];
|
|
11
|
-
evaluationRunId: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Start an evaluation workflow for a conversation.
|
|
15
|
-
* This is a convenience wrapper that handles workflow initialization internally.
|
|
16
|
-
*/
|
|
17
|
-
declare function startConversationEvaluation(params: StartEvaluationParams): Promise<void>;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { StartEvaluationParams, startConversationEvaluation };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { evaluateConversationWorkflow } from "../workflow/functions/evaluateConversation.js";
|
|
2
|
-
import { start } from "workflow/api";
|
|
3
|
-
|
|
4
|
-
//#region src/domains/evals/services/startEvaluation.ts
|
|
5
|
-
/**
|
|
6
|
-
* Service to start evaluation workflows.
|
|
7
|
-
* This encapsulates the workflow logic so consumers don't need to import workflow packages.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Start an evaluation workflow for a conversation.
|
|
11
|
-
* This is a convenience wrapper that handles workflow initialization internally.
|
|
12
|
-
*/
|
|
13
|
-
async function startConversationEvaluation(params) {
|
|
14
|
-
await start(evaluateConversationWorkflow, [params]);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { startConversationEvaluation };
|
package/dist/domains/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { createEvalRoutes, evalRoutes } from "./evals/index.js";
|
|
2
|
-
import { createGithubRoutes, githubRoutes } from "./github/index.js";
|
|
3
|
-
import { createManageRoutes, manageRoutes } from "./manage/index.js";
|
|
4
|
-
import { createRunRoutes, runRoutes } from "./run/index.js";
|
|
5
|
-
export { createEvalRoutes, createGithubRoutes, createManageRoutes, createRunRoutes, evalRoutes, githubRoutes, manageRoutes, runRoutes };
|
package/dist/domains/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createEvalRoutes, evalRoutes } from "./evals/index.js";
|
|
2
|
-
import { createGithubRoutes, githubRoutes } from "./github/index.js";
|
|
3
|
-
import { createManageRoutes, manageRoutes } from "./manage/index.js";
|
|
4
|
-
import { createRunRoutes, runRoutes } from "./run/index.js";
|
|
5
|
-
|
|
6
|
-
export { createEvalRoutes, createGithubRoutes, createManageRoutes, createRunRoutes, evalRoutes, githubRoutes, manageRoutes, runRoutes };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { LanguageModel } from "ai";
|
|
2
|
-
|
|
3
|
-
//#region src/domains/run/agents/ModelFactory.d.ts
|
|
4
|
-
interface ModelSettings {
|
|
5
|
-
model?: string;
|
|
6
|
-
providerOptions?: Record<string, unknown>;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Factory for creating AI SDK language models from configuration
|
|
10
|
-
* Supports multiple providers and AI Gateway integration
|
|
11
|
-
*/
|
|
12
|
-
declare class ModelFactory {
|
|
13
|
-
/**
|
|
14
|
-
* Create a provider instance with custom configuration
|
|
15
|
-
* Returns a provider with at least languageModel method
|
|
16
|
-
*/
|
|
17
|
-
private static createProvider;
|
|
18
|
-
/**
|
|
19
|
-
* Extract provider configuration from providerOptions
|
|
20
|
-
* Only includes settings that go to the provider constructor (baseURL, apiKey, etc.)
|
|
21
|
-
*/
|
|
22
|
-
private static extractProviderConfig;
|
|
23
|
-
/**
|
|
24
|
-
* Create a language model instance from configuration
|
|
25
|
-
* Throws error if no config provided - models must be configured at project level
|
|
26
|
-
*/
|
|
27
|
-
static createModel(config: ModelSettings): LanguageModel;
|
|
28
|
-
/**
|
|
29
|
-
* Built-in providers that have special handling
|
|
30
|
-
*/
|
|
31
|
-
private static readonly BUILT_IN_PROVIDERS;
|
|
32
|
-
/**
|
|
33
|
-
* Parse model string to extract provider and model name
|
|
34
|
-
* Examples: "anthropic/claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" }
|
|
35
|
-
* "openrouter/anthropic/claude-sonnet-4" -> { provider: "openrouter", modelName: "anthropic/claude-sonnet-4" }
|
|
36
|
-
* "claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" } (default to anthropic)
|
|
37
|
-
*/
|
|
38
|
-
static parseModelString(modelString: string): {
|
|
39
|
-
provider: string;
|
|
40
|
-
modelName: string;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Get generation parameters from provider options
|
|
44
|
-
* These are parameters that get passed to generateText/streamText calls
|
|
45
|
-
*/
|
|
46
|
-
static getGenerationParams(providerOptions?: Record<string, unknown>): Record<string, unknown>;
|
|
47
|
-
/**
|
|
48
|
-
* Prepare complete generation configuration from model settings
|
|
49
|
-
* Returns model instance and generation parameters ready to spread into generateText/streamText
|
|
50
|
-
* Includes maxDuration if specified in provider options (in seconds, following Vercel standard)
|
|
51
|
-
*/
|
|
52
|
-
static prepareGenerationConfig(modelSettings?: ModelSettings): {
|
|
53
|
-
model: LanguageModel;
|
|
54
|
-
maxDuration?: number;
|
|
55
|
-
} & Record<string, unknown>;
|
|
56
|
-
/**
|
|
57
|
-
* Validate model settingsuration
|
|
58
|
-
* Basic validation only - let AI SDK handle parameter-specific validation
|
|
59
|
-
*/
|
|
60
|
-
static validateConfig(config: ModelSettings): string[];
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { ModelFactory, ModelSettings };
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../../../logger.js";
|
|
2
|
-
import { anthropic, createAnthropic } from "@ai-sdk/anthropic";
|
|
3
|
-
import { createGateway, gateway } from "@ai-sdk/gateway";
|
|
4
|
-
import { createGoogleGenerativeAI, google } from "@ai-sdk/google";
|
|
5
|
-
import { createOpenAI, openai } from "@ai-sdk/openai";
|
|
6
|
-
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
7
|
-
import { createOpenRouter, openrouter } from "@openrouter/ai-sdk-provider";
|
|
8
|
-
|
|
9
|
-
//#region src/domains/run/agents/ModelFactory.ts
|
|
10
|
-
const logger = getLogger("ModelFactory");
|
|
11
|
-
const nimDefault = createOpenAICompatible({
|
|
12
|
-
name: "nim",
|
|
13
|
-
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
14
|
-
headers: { Authorization: `Bearer ${process.env.NIM_API_KEY}` }
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* Factory for creating AI SDK language models from configuration
|
|
18
|
-
* Supports multiple providers and AI Gateway integration
|
|
19
|
-
*/
|
|
20
|
-
var ModelFactory = class ModelFactory {
|
|
21
|
-
/**
|
|
22
|
-
* Create a provider instance with custom configuration
|
|
23
|
-
* Returns a provider with at least languageModel method
|
|
24
|
-
*/
|
|
25
|
-
static createProvider(provider, config) {
|
|
26
|
-
switch (provider) {
|
|
27
|
-
case "anthropic": return createAnthropic(config);
|
|
28
|
-
case "openai": return createOpenAI(config);
|
|
29
|
-
case "google": return createGoogleGenerativeAI(config);
|
|
30
|
-
case "openrouter": return createOpenRouter(config);
|
|
31
|
-
case "gateway": return createGateway(config);
|
|
32
|
-
case "nim": return createOpenAICompatible({
|
|
33
|
-
name: "nim",
|
|
34
|
-
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
35
|
-
headers: { Authorization: `Bearer ${process.env.NIM_API_KEY}` },
|
|
36
|
-
...config
|
|
37
|
-
});
|
|
38
|
-
case "custom": {
|
|
39
|
-
if (!config.baseURL && !config.baseUrl) throw new Error("Custom provider requires baseURL. Please provide it in providerOptions.baseURL or providerOptions.baseUrl");
|
|
40
|
-
const customConfig = {
|
|
41
|
-
name: "custom",
|
|
42
|
-
baseURL: config.baseURL || config.baseUrl,
|
|
43
|
-
headers: {
|
|
44
|
-
...process.env.CUSTOM_LLM_API_KEY && { Authorization: `Bearer ${process.env.CUSTOM_LLM_API_KEY}` },
|
|
45
|
-
...config.headers || {}
|
|
46
|
-
},
|
|
47
|
-
...config
|
|
48
|
-
};
|
|
49
|
-
logger.info({ config: {
|
|
50
|
-
baseURL: customConfig.baseURL,
|
|
51
|
-
hasApiKey: !!process.env.CUSTOM_LLM_API_KEY,
|
|
52
|
-
apiKeyPrefix: `${process.env.CUSTOM_LLM_API_KEY?.substring(0, 10) || ""}...`,
|
|
53
|
-
headers: Object.keys(customConfig.headers || {})
|
|
54
|
-
} }, "Creating custom OpenAI-compatible provider");
|
|
55
|
-
return createOpenAICompatible(customConfig);
|
|
56
|
-
}
|
|
57
|
-
default: throw new Error(`Unsupported provider: ${provider}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Extract provider configuration from providerOptions
|
|
62
|
-
* Only includes settings that go to the provider constructor (baseURL, apiKey, etc.)
|
|
63
|
-
*/
|
|
64
|
-
static extractProviderConfig(providerOptions) {
|
|
65
|
-
if (!providerOptions) return {};
|
|
66
|
-
const providerConfig = {};
|
|
67
|
-
if (providerOptions.baseUrl || providerOptions.baseURL) providerConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
68
|
-
if (providerOptions.headers) providerConfig.headers = providerOptions.headers;
|
|
69
|
-
if (providerOptions.gateway) Object.assign(providerConfig, providerOptions.gateway);
|
|
70
|
-
if (providerOptions.nim) Object.assign(providerConfig, providerOptions.nim);
|
|
71
|
-
if (providerOptions.custom) Object.assign(providerConfig, providerOptions.custom);
|
|
72
|
-
return providerConfig;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create a language model instance from configuration
|
|
76
|
-
* Throws error if no config provided - models must be configured at project level
|
|
77
|
-
*/
|
|
78
|
-
static createModel(config) {
|
|
79
|
-
if (!config?.model?.trim()) throw new Error("Model configuration is required. Please configure models at the project level.");
|
|
80
|
-
const modelSettings = config;
|
|
81
|
-
if (!modelSettings.model) throw new Error("Model configuration is required");
|
|
82
|
-
const modelString = modelSettings.model.trim();
|
|
83
|
-
const { provider, modelName } = ModelFactory.parseModelString(modelString);
|
|
84
|
-
logger.debug({
|
|
85
|
-
provider,
|
|
86
|
-
model: modelName,
|
|
87
|
-
fullModelString: modelSettings.model,
|
|
88
|
-
hasProviderOptions: !!modelSettings.providerOptions
|
|
89
|
-
}, "Creating language model from config");
|
|
90
|
-
const providerConfig = ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
91
|
-
if (Object.keys(providerConfig).length > 0) {
|
|
92
|
-
logger.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
93
|
-
return ModelFactory.createProvider(provider, providerConfig).languageModel(modelName);
|
|
94
|
-
}
|
|
95
|
-
switch (provider) {
|
|
96
|
-
case "anthropic": return anthropic(modelName);
|
|
97
|
-
case "openai": return openai(modelName);
|
|
98
|
-
case "google": return google(modelName);
|
|
99
|
-
case "openrouter": return openrouter(modelName);
|
|
100
|
-
case "gateway": return gateway(modelName);
|
|
101
|
-
case "nim": return nimDefault(modelName);
|
|
102
|
-
case "custom": throw new Error("Custom provider requires configuration. Please provide baseURL in providerOptions.custom.baseURL or providerOptions.baseURL");
|
|
103
|
-
default: throw new Error(`Unsupported provider: ${provider}. Supported providers are: ${ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Built-in providers that have special handling
|
|
108
|
-
*/
|
|
109
|
-
static BUILT_IN_PROVIDERS = [
|
|
110
|
-
"anthropic",
|
|
111
|
-
"openai",
|
|
112
|
-
"google",
|
|
113
|
-
"openrouter",
|
|
114
|
-
"gateway",
|
|
115
|
-
"nim",
|
|
116
|
-
"custom"
|
|
117
|
-
];
|
|
118
|
-
/**
|
|
119
|
-
* Parse model string to extract provider and model name
|
|
120
|
-
* Examples: "anthropic/claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" }
|
|
121
|
-
* "openrouter/anthropic/claude-sonnet-4" -> { provider: "openrouter", modelName: "anthropic/claude-sonnet-4" }
|
|
122
|
-
* "claude-sonnet-4" -> { provider: "anthropic", modelName: "claude-sonnet-4" } (default to anthropic)
|
|
123
|
-
*/
|
|
124
|
-
static parseModelString(modelString) {
|
|
125
|
-
if (modelString.includes("/")) {
|
|
126
|
-
const [provider, ...modelParts] = modelString.split("/");
|
|
127
|
-
const normalizedProvider = provider.toLowerCase();
|
|
128
|
-
if (!ModelFactory.BUILT_IN_PROVIDERS.includes(normalizedProvider)) throw new Error(`Unsupported provider: ${normalizedProvider}. Supported providers are: ${ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`);
|
|
129
|
-
return {
|
|
130
|
-
provider: normalizedProvider,
|
|
131
|
-
modelName: modelParts.join("/")
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
throw new Error(`No provider specified in model string: ${modelString}`);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get generation parameters from provider options
|
|
138
|
-
* These are parameters that get passed to generateText/streamText calls
|
|
139
|
-
*/
|
|
140
|
-
static getGenerationParams(providerOptions) {
|
|
141
|
-
if (!providerOptions) return {};
|
|
142
|
-
const excludedKeys = [
|
|
143
|
-
"apiKey",
|
|
144
|
-
"baseURL",
|
|
145
|
-
"baseUrl",
|
|
146
|
-
"maxDuration",
|
|
147
|
-
"headers",
|
|
148
|
-
"gateway",
|
|
149
|
-
"nim",
|
|
150
|
-
"custom"
|
|
151
|
-
];
|
|
152
|
-
const params = {};
|
|
153
|
-
for (const [key, value] of Object.entries(providerOptions)) if (!excludedKeys.includes(key) && value !== void 0) params[key] = value;
|
|
154
|
-
return params;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Prepare complete generation configuration from model settings
|
|
158
|
-
* Returns model instance and generation parameters ready to spread into generateText/streamText
|
|
159
|
-
* Includes maxDuration if specified in provider options (in seconds, following Vercel standard)
|
|
160
|
-
*/
|
|
161
|
-
static prepareGenerationConfig(modelSettings) {
|
|
162
|
-
const modelString = modelSettings?.model?.trim();
|
|
163
|
-
const model = ModelFactory.createModel({
|
|
164
|
-
model: modelString,
|
|
165
|
-
providerOptions: modelSettings?.providerOptions
|
|
166
|
-
});
|
|
167
|
-
const generationParams = ModelFactory.getGenerationParams(modelSettings?.providerOptions);
|
|
168
|
-
const maxDuration = modelSettings?.providerOptions?.maxDuration;
|
|
169
|
-
return {
|
|
170
|
-
model,
|
|
171
|
-
...generationParams,
|
|
172
|
-
...maxDuration !== void 0 && { maxDuration }
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Validate model settingsuration
|
|
177
|
-
* Basic validation only - let AI SDK handle parameter-specific validation
|
|
178
|
-
*/
|
|
179
|
-
static validateConfig(config) {
|
|
180
|
-
const errors = [];
|
|
181
|
-
if (!config.model) errors.push("Model name is required");
|
|
182
|
-
if (config.providerOptions) {
|
|
183
|
-
if (config.providerOptions.apiKey) errors.push("API keys should not be stored in provider options. Use environment variables (ANTHROPIC_API_KEY, OPENAI_API_KEY) or credential store instead.");
|
|
184
|
-
if (config.providerOptions.maxDuration !== void 0) {
|
|
185
|
-
const maxDuration = config.providerOptions.maxDuration;
|
|
186
|
-
if (typeof maxDuration !== "number" || maxDuration <= 0) errors.push("maxDuration must be a positive number (in seconds)");
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return errors;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
//#endregion
|
|
194
|
-
export { ModelFactory };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RegisteredAgent } from "../a2a/types.js";
|
|
2
|
-
import { FullExecutionContext } from "@inkeep/agents-core";
|
|
3
|
-
|
|
4
|
-
//#region src/domains/run/data/agent.d.ts
|
|
5
|
-
declare function getRegisteredAgent(executionContext: FullExecutionContext): Promise<RegisteredAgent | null>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { getRegisteredAgent };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { getAgentFromProject, getSubAgentFromProject } from "../utils/project.js";
|
|
2
|
-
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
3
|
-
|
|
4
|
-
//#region src/domains/run/data/agent.ts
|
|
5
|
-
async function hydrateAgent({ dbAgent, executionContext, baseUrl }) {
|
|
6
|
-
const { tenantId, projectId, agentId, project, apiKey } = executionContext;
|
|
7
|
-
try {
|
|
8
|
-
if (!dbAgent.defaultSubAgentId) throw new Error(`Agent ${dbAgent.id} does not have a default agent configured`);
|
|
9
|
-
const subAgentId = dbAgent.defaultSubAgentId;
|
|
10
|
-
if (!getSubAgentFromProject({
|
|
11
|
-
project,
|
|
12
|
-
agentId,
|
|
13
|
-
subAgentId
|
|
14
|
-
})) throw new Error(`Default agent ${dbAgent.defaultSubAgentId} not found for agent ${dbAgent.id}`);
|
|
15
|
-
const taskHandler = createTaskHandler(await createTaskHandlerConfig({
|
|
16
|
-
executionContext,
|
|
17
|
-
subAgentId: dbAgent.defaultSubAgentId,
|
|
18
|
-
baseUrl,
|
|
19
|
-
apiKey
|
|
20
|
-
}));
|
|
21
|
-
const agentCard = {
|
|
22
|
-
name: dbAgent.name,
|
|
23
|
-
description: dbAgent.description || `Agent: ${dbAgent.name}`,
|
|
24
|
-
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
25
|
-
version: "1.0.0",
|
|
26
|
-
capabilities: {
|
|
27
|
-
streaming: true,
|
|
28
|
-
pushNotifications: false,
|
|
29
|
-
stateTransitionHistory: false
|
|
30
|
-
},
|
|
31
|
-
defaultInputModes: ["text", "text/plain"],
|
|
32
|
-
defaultOutputModes: ["text", "text/plain"],
|
|
33
|
-
skills: [],
|
|
34
|
-
...baseUrl && { provider: {
|
|
35
|
-
organization: "Inkeep",
|
|
36
|
-
url: baseUrl
|
|
37
|
-
} }
|
|
38
|
-
};
|
|
39
|
-
return {
|
|
40
|
-
subAgentId: dbAgent.id,
|
|
41
|
-
tenantId,
|
|
42
|
-
projectId,
|
|
43
|
-
agentId: dbAgent.id,
|
|
44
|
-
agentCard,
|
|
45
|
-
taskHandler
|
|
46
|
-
};
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error(`❌ Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async function getRegisteredAgent(executionContext) {
|
|
53
|
-
const { project, agentId, baseUrl } = executionContext;
|
|
54
|
-
const dbAgent = getAgentFromProject({
|
|
55
|
-
project,
|
|
56
|
-
agentId
|
|
57
|
-
});
|
|
58
|
-
if (!dbAgent) return null;
|
|
59
|
-
return hydrateAgent({
|
|
60
|
-
dbAgent,
|
|
61
|
-
executionContext,
|
|
62
|
-
baseUrl: `${baseUrl}/run/agents`
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { getRegisteredAgent };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region src/domains/run/utils/cleanup.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Cleanup utilities for gracefully shutting down resources
|
|
4
|
-
* Helps prevent Node.js processes from hanging
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Gracefully exit the process after cleaning up resources
|
|
8
|
-
*/
|
|
9
|
-
declare function gracefulExit(code?: number, delayMs?: number, message?: string): void;
|
|
10
|
-
/**
|
|
11
|
-
* Setup signal handlers for graceful shutdown
|
|
12
|
-
*/
|
|
13
|
-
declare function setupGracefulShutdown(cleanupFn?: () => Promise<void> | void, exitDelayMs?: number): void;
|
|
14
|
-
/**
|
|
15
|
-
* Stop all tools associated with agents
|
|
16
|
-
*/
|
|
17
|
-
declare function stopAllAgentTools(agents: Array<{
|
|
18
|
-
getTools: () => Record<string, any>;
|
|
19
|
-
}>): Promise<void>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { gracefulExit, setupGracefulShutdown, stopAllAgentTools };
|