@inkeep/agents-run-api 0.39.5 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-component.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-components.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js +5 -0
- package/dist/a2a/client.d.ts +184 -0
- package/dist/a2a/client.js +510 -0
- package/dist/a2a/handlers.d.ts +7 -0
- package/dist/a2a/handlers.js +576 -0
- package/dist/a2a/transfer.d.ts +22 -0
- package/dist/a2a/transfer.js +46 -0
- package/dist/a2a/types.d.ts +79 -0
- package/dist/a2a/types.js +22 -0
- package/dist/agents/Agent.d.ts +268 -0
- package/dist/agents/Agent.js +1932 -0
- package/dist/agents/ModelFactory.d.ts +63 -0
- package/dist/agents/ModelFactory.js +194 -0
- package/dist/agents/SystemPromptBuilder.d.ts +21 -0
- package/dist/agents/SystemPromptBuilder.js +48 -0
- package/dist/agents/ToolSessionManager.d.ts +63 -0
- package/dist/agents/ToolSessionManager.js +146 -0
- package/dist/agents/generateTaskHandler.d.ts +49 -0
- package/dist/agents/generateTaskHandler.js +523 -0
- package/dist/agents/relationTools.d.ts +57 -0
- package/dist/agents/relationTools.js +262 -0
- package/dist/agents/types.d.ts +28 -0
- package/dist/agents/types.js +1 -0
- package/dist/agents/versions/v1/Phase1Config.d.ts +27 -0
- package/dist/agents/versions/v1/Phase1Config.js +424 -0
- package/dist/agents/versions/v1/Phase2Config.d.ts +31 -0
- package/dist/agents/versions/v1/Phase2Config.js +330 -0
- package/dist/constants/execution-limits/defaults.d.ts +51 -0
- package/dist/constants/execution-limits/defaults.js +52 -0
- package/dist/constants/execution-limits/index.d.ts +6 -0
- package/dist/constants/execution-limits/index.js +21 -0
- package/dist/create-app.d.ts +9 -0
- package/dist/create-app.js +195 -0
- package/dist/data/agent.d.ts +7 -0
- package/dist/data/agent.js +72 -0
- package/dist/data/agents.d.ts +34 -0
- package/dist/data/agents.js +139 -0
- package/dist/data/conversations.d.ts +128 -0
- package/dist/data/conversations.js +522 -0
- package/dist/data/db/dbClient.d.ts +6 -0
- package/dist/data/db/dbClient.js +17 -0
- package/dist/env.d.ts +57 -0
- package/dist/env.js +1 -2
- package/dist/handlers/executionHandler.d.ts +41 -0
- package/dist/handlers/executionHandler.js +457 -0
- package/dist/index.d.ts +8 -29
- package/dist/index.js +5 -11386
- package/dist/instrumentation.d.ts +1 -2
- package/dist/instrumentation.js +66 -3
- package/dist/{logger2.js → logger.d.ts} +1 -2
- package/dist/logger.js +1 -1
- package/dist/middleware/api-key-auth.d.ts +26 -0
- package/dist/middleware/api-key-auth.js +240 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +3 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.js +54 -0
- package/dist/routes/agents.d.ts +12 -0
- package/dist/routes/agents.js +147 -0
- package/dist/routes/chat.d.ts +13 -0
- package/dist/routes/chat.js +305 -0
- package/dist/routes/chatDataStream.d.ts +13 -0
- package/dist/routes/chatDataStream.js +365 -0
- package/dist/routes/mcp.d.ts +13 -0
- package/dist/routes/mcp.js +495 -0
- package/dist/services/AgentSession.d.ts +356 -0
- package/dist/services/AgentSession.js +1208 -0
- package/dist/services/ArtifactParser.d.ts +105 -0
- package/dist/services/ArtifactParser.js +338 -0
- package/dist/services/ArtifactService.d.ts +123 -0
- package/dist/services/ArtifactService.js +612 -0
- package/dist/services/BaseCompressor.d.ts +183 -0
- package/dist/services/BaseCompressor.js +500 -0
- package/dist/services/ConversationCompressor.d.ts +32 -0
- package/dist/services/ConversationCompressor.js +91 -0
- package/dist/services/IncrementalStreamParser.d.ts +98 -0
- package/dist/services/IncrementalStreamParser.js +327 -0
- package/dist/services/MidGenerationCompressor.d.ts +63 -0
- package/dist/services/MidGenerationCompressor.js +104 -0
- package/dist/services/PendingToolApprovalManager.d.ts +62 -0
- package/dist/services/PendingToolApprovalManager.js +133 -0
- package/dist/services/ResponseFormatter.d.ts +39 -0
- package/dist/services/ResponseFormatter.js +152 -0
- package/dist/tools/NativeSandboxExecutor.d.ts +38 -0
- package/dist/tools/NativeSandboxExecutor.js +432 -0
- package/dist/tools/SandboxExecutorFactory.d.ts +36 -0
- package/dist/tools/SandboxExecutorFactory.js +80 -0
- package/dist/tools/VercelSandboxExecutor.d.ts +71 -0
- package/dist/tools/VercelSandboxExecutor.js +340 -0
- package/dist/tools/distill-conversation-history-tool.d.ts +62 -0
- package/dist/tools/distill-conversation-history-tool.js +206 -0
- package/dist/tools/distill-conversation-tool.d.ts +41 -0
- package/dist/tools/distill-conversation-tool.js +141 -0
- package/dist/tools/sandbox-utils.d.ts +18 -0
- package/dist/tools/sandbox-utils.js +53 -0
- package/dist/types/chat.d.ts +27 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/execution-context.d.ts +46 -0
- package/dist/types/execution-context.js +27 -0
- package/dist/types/xml.d.ts +5 -0
- package/dist/utils/SchemaProcessor.d.ts +52 -0
- package/dist/utils/SchemaProcessor.js +182 -0
- package/dist/utils/agent-operations.d.ts +62 -0
- package/dist/utils/agent-operations.js +53 -0
- package/dist/utils/artifact-component-schema.d.ts +42 -0
- package/dist/utils/artifact-component-schema.js +186 -0
- package/dist/utils/cleanup.d.ts +21 -0
- package/dist/utils/cleanup.js +59 -0
- package/dist/utils/data-component-schema.d.ts +2 -0
- package/dist/utils/data-component-schema.js +3 -0
- package/dist/utils/default-status-schemas.d.ts +20 -0
- package/dist/utils/default-status-schemas.js +24 -0
- package/dist/utils/json-postprocessor.d.ts +13 -0
- package/dist/{json-postprocessor.cjs → utils/json-postprocessor.js} +2 -3
- package/dist/utils/model-context-utils.d.ts +39 -0
- package/dist/utils/model-context-utils.js +181 -0
- package/dist/utils/model-resolver.d.ts +6 -0
- package/dist/utils/model-resolver.js +34 -0
- package/dist/utils/schema-validation.d.ts +44 -0
- package/dist/utils/schema-validation.js +97 -0
- package/dist/utils/stream-helpers.d.ts +197 -0
- package/dist/utils/stream-helpers.js +518 -0
- package/dist/utils/stream-registry.d.ts +22 -0
- package/dist/utils/stream-registry.js +34 -0
- package/dist/utils/token-estimator.d.ts +69 -0
- package/dist/utils/token-estimator.js +53 -0
- package/dist/utils/tracer.d.ts +7 -0
- package/dist/utils/tracer.js +7 -0
- package/package.json +10 -26
- package/dist/SandboxExecutorFactory.cjs +0 -895
- package/dist/SandboxExecutorFactory.js +0 -893
- package/dist/SandboxExecutorFactory.js.map +0 -1
- package/dist/chunk-VBDAOXYI.cjs +0 -927
- package/dist/chunk-VBDAOXYI.js +0 -832
- package/dist/chunk-VBDAOXYI.js.map +0 -1
- package/dist/chunk.cjs +0 -34
- package/dist/conversations.cjs +0 -7
- package/dist/conversations.js +0 -7
- package/dist/conversations2.cjs +0 -209
- package/dist/conversations2.js +0 -180
- package/dist/conversations2.js.map +0 -1
- package/dist/dbClient.cjs +0 -9676
- package/dist/dbClient.js +0 -9670
- package/dist/dbClient.js.map +0 -1
- package/dist/dbClient2.cjs +0 -5
- package/dist/dbClient2.js +0 -5
- package/dist/env.cjs +0 -59
- package/dist/env.js.map +0 -1
- package/dist/execution-limits.cjs +0 -260
- package/dist/execution-limits.js +0 -63
- package/dist/execution-limits.js.map +0 -1
- package/dist/index.cjs +0 -11411
- package/dist/index.d.cts +0 -36
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation.cjs +0 -12
- package/dist/instrumentation.d.cts +0 -18
- package/dist/instrumentation.d.cts.map +0 -1
- package/dist/instrumentation.d.ts.map +0 -1
- package/dist/instrumentation2.cjs +0 -116
- package/dist/instrumentation2.js +0 -69
- package/dist/instrumentation2.js.map +0 -1
- package/dist/json-postprocessor.js +0 -20
- package/dist/json-postprocessor.js.map +0 -1
- package/dist/logger.cjs +0 -5
- package/dist/logger2.cjs +0 -1
- package/dist/nodefs.cjs +0 -29
- package/dist/nodefs.js +0 -27
- package/dist/nodefs.js.map +0 -1
- package/dist/opfs-ahp.cjs +0 -367
- package/dist/opfs-ahp.js +0 -368
- package/dist/opfs-ahp.js.map +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { getLogger } from "./logger.js";
|
|
2
|
+
import { flushBatchProcessor } from "./instrumentation.js";
|
|
3
|
+
import { apiKeyAuth } from "./middleware/api-key-auth.js";
|
|
4
|
+
import { setupOpenAPIRoutes } from "./openapi.js";
|
|
5
|
+
import agents_default from "./routes/agents.js";
|
|
6
|
+
import chat_default from "./routes/chat.js";
|
|
7
|
+
import chatDataStream_default from "./routes/chatDataStream.js";
|
|
8
|
+
import mcp_default from "./routes/mcp.js";
|
|
9
|
+
import { otel } from "@hono/otel";
|
|
10
|
+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
|
|
11
|
+
import { handleApiError } from "@inkeep/agents-core";
|
|
12
|
+
import { context, propagation } from "@opentelemetry/api";
|
|
13
|
+
import { Hono } from "hono";
|
|
14
|
+
import { cors } from "hono/cors";
|
|
15
|
+
import { HTTPException } from "hono/http-exception";
|
|
16
|
+
import { requestId } from "hono/request-id";
|
|
17
|
+
|
|
18
|
+
//#region src/create-app.ts
|
|
19
|
+
const logger = getLogger("agents-run-api");
|
|
20
|
+
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
21
|
+
const app = new OpenAPIHono();
|
|
22
|
+
app.use("*", otel());
|
|
23
|
+
app.use("*", requestId());
|
|
24
|
+
app.use("*", async (c, next) => {
|
|
25
|
+
c.set("serverConfig", serverConfig);
|
|
26
|
+
c.set("credentialStores", credentialStores);
|
|
27
|
+
if (sandboxConfig) c.set("sandboxConfig", sandboxConfig);
|
|
28
|
+
return next();
|
|
29
|
+
});
|
|
30
|
+
app.use("*", async (c, next) => {
|
|
31
|
+
if (c.req.header("content-type")?.includes("application/json")) try {
|
|
32
|
+
const body = await c.req.json();
|
|
33
|
+
c.set("requestBody", body);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
logger.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
36
|
+
}
|
|
37
|
+
return next();
|
|
38
|
+
});
|
|
39
|
+
app.use("*", async (c, next) => {
|
|
40
|
+
const reqId = c.get("requestId");
|
|
41
|
+
let bag = propagation.getBaggage(context.active());
|
|
42
|
+
if (!bag) bag = propagation.createBaggage();
|
|
43
|
+
if (bag && typeof bag.setEntry === "function") {
|
|
44
|
+
bag = bag.setEntry("request.id", { value: String(reqId ?? "unknown") });
|
|
45
|
+
const ctxWithBag = propagation.setBaggage(context.active(), bag);
|
|
46
|
+
return await context.with(ctxWithBag, async () => await next());
|
|
47
|
+
}
|
|
48
|
+
return next();
|
|
49
|
+
});
|
|
50
|
+
app.onError(async (err, c) => {
|
|
51
|
+
const isExpectedError = err instanceof HTTPException;
|
|
52
|
+
const status = isExpectedError ? err.status : 500;
|
|
53
|
+
const requestId$1 = c.get("requestId") || "unknown";
|
|
54
|
+
let zodIssues;
|
|
55
|
+
if (err && typeof err === "object") {
|
|
56
|
+
if (err.cause && Array.isArray(err.cause.issues)) zodIssues = err.cause.issues;
|
|
57
|
+
else if (Array.isArray(err.issues)) zodIssues = err.issues;
|
|
58
|
+
}
|
|
59
|
+
if (status === 400 && Array.isArray(zodIssues)) {
|
|
60
|
+
c.status(400);
|
|
61
|
+
c.header("Content-Type", "application/problem+json");
|
|
62
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
63
|
+
return c.json({
|
|
64
|
+
type: "https://docs.inkeep.com/agents-api/errors#bad_request",
|
|
65
|
+
title: "Validation Failed",
|
|
66
|
+
status: 400,
|
|
67
|
+
detail: "Request validation failed",
|
|
68
|
+
errors: zodIssues.map((issue) => ({
|
|
69
|
+
detail: issue.message,
|
|
70
|
+
pointer: issue.path ? `/${issue.path.join("/")}` : void 0,
|
|
71
|
+
name: issue.path ? issue.path.join(".") : void 0,
|
|
72
|
+
reason: issue.message
|
|
73
|
+
}))
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (status >= 500) {
|
|
77
|
+
if (!isExpectedError) {
|
|
78
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
79
|
+
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
80
|
+
if (logger) logger.error({
|
|
81
|
+
error: err,
|
|
82
|
+
message: errorMessage,
|
|
83
|
+
stack: errorStack,
|
|
84
|
+
path: c.req.path,
|
|
85
|
+
requestId: requestId$1
|
|
86
|
+
}, "Unexpected server error occurred");
|
|
87
|
+
} else if (logger) logger.error({
|
|
88
|
+
error: err,
|
|
89
|
+
path: c.req.path,
|
|
90
|
+
requestId: requestId$1,
|
|
91
|
+
status
|
|
92
|
+
}, "Server error occurred");
|
|
93
|
+
}
|
|
94
|
+
if (isExpectedError) try {
|
|
95
|
+
return err.getResponse();
|
|
96
|
+
} catch (responseError) {
|
|
97
|
+
if (logger) logger.error({ error: responseError }, "Error while handling HTTPException response");
|
|
98
|
+
}
|
|
99
|
+
const { status: respStatus, title, detail, instance } = await handleApiError(err, requestId$1);
|
|
100
|
+
c.status(respStatus);
|
|
101
|
+
c.header("Content-Type", "application/problem+json");
|
|
102
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
103
|
+
return c.json({
|
|
104
|
+
type: "https://docs.inkeep.com/agents-api/errors#internal_server_error",
|
|
105
|
+
title,
|
|
106
|
+
status: respStatus,
|
|
107
|
+
detail,
|
|
108
|
+
...instance && { instance }
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
app.use("*", cors({
|
|
112
|
+
origin: "*",
|
|
113
|
+
allowMethods: [
|
|
114
|
+
"GET",
|
|
115
|
+
"POST",
|
|
116
|
+
"PUT",
|
|
117
|
+
"DELETE",
|
|
118
|
+
"OPTIONS"
|
|
119
|
+
],
|
|
120
|
+
allowHeaders: ["*"],
|
|
121
|
+
exposeHeaders: ["Content-Length"],
|
|
122
|
+
maxAge: 86400
|
|
123
|
+
}));
|
|
124
|
+
app.use("/tenants/*", apiKeyAuth());
|
|
125
|
+
app.use("/agents/*", apiKeyAuth());
|
|
126
|
+
app.use("/v1/*", apiKeyAuth());
|
|
127
|
+
app.use("/api/*", apiKeyAuth());
|
|
128
|
+
app.use("*", async (c, next) => {
|
|
129
|
+
const executionContext = c.get("executionContext");
|
|
130
|
+
if (!executionContext) {
|
|
131
|
+
logger.debug({}, "Empty execution context");
|
|
132
|
+
return next();
|
|
133
|
+
}
|
|
134
|
+
const { tenantId, projectId, agentId } = executionContext;
|
|
135
|
+
let conversationId;
|
|
136
|
+
const requestBody = c.get("requestBody") || {};
|
|
137
|
+
if (requestBody) {
|
|
138
|
+
conversationId = requestBody.conversationId;
|
|
139
|
+
if (!conversationId) logger.debug({ requestBody }, "No conversation ID found in request body");
|
|
140
|
+
}
|
|
141
|
+
const entries = Object.fromEntries(Object.entries({
|
|
142
|
+
"agent.id": agentId,
|
|
143
|
+
"tenant.id": tenantId,
|
|
144
|
+
"project.id": projectId,
|
|
145
|
+
"conversation.id": conversationId
|
|
146
|
+
}).filter((entry) => {
|
|
147
|
+
const [, v] = entry;
|
|
148
|
+
return typeof v === "string" && v.length > 0;
|
|
149
|
+
}));
|
|
150
|
+
if (!Object.keys(entries).length) {
|
|
151
|
+
logger.debug({}, "Empty entries for baggage");
|
|
152
|
+
return next();
|
|
153
|
+
}
|
|
154
|
+
const bag = Object.entries(entries).reduce((b, [key, value]) => b.setEntry(key, { value: value || "" }), propagation.getBaggage(context.active()) ?? propagation.createBaggage());
|
|
155
|
+
const ctxWithBag = propagation.setBaggage(context.active(), bag);
|
|
156
|
+
return await context.with(ctxWithBag, async () => await next());
|
|
157
|
+
});
|
|
158
|
+
app.openapi(createRoute({
|
|
159
|
+
method: "get",
|
|
160
|
+
path: "/health",
|
|
161
|
+
tags: ["health"],
|
|
162
|
+
summary: "Health check",
|
|
163
|
+
description: "Check if the execution service is healthy",
|
|
164
|
+
responses: { 204: { description: "Service is healthy" } }
|
|
165
|
+
}), (c) => {
|
|
166
|
+
return c.body(null, 204);
|
|
167
|
+
});
|
|
168
|
+
app.route("/v1/chat", chat_default);
|
|
169
|
+
app.route("/api", chatDataStream_default);
|
|
170
|
+
app.route("/v1/mcp", mcp_default);
|
|
171
|
+
app.route("/agents", agents_default);
|
|
172
|
+
setupOpenAPIRoutes(app);
|
|
173
|
+
app.use("/tenants/*", async (_c, next) => {
|
|
174
|
+
await next();
|
|
175
|
+
await flushBatchProcessor();
|
|
176
|
+
});
|
|
177
|
+
app.use("/agents/*", async (_c, next) => {
|
|
178
|
+
await next();
|
|
179
|
+
await flushBatchProcessor();
|
|
180
|
+
});
|
|
181
|
+
app.use("/v1/*", async (_c, next) => {
|
|
182
|
+
await next();
|
|
183
|
+
await flushBatchProcessor();
|
|
184
|
+
});
|
|
185
|
+
app.use("/api/*", async (_c, next) => {
|
|
186
|
+
await next();
|
|
187
|
+
await flushBatchProcessor();
|
|
188
|
+
});
|
|
189
|
+
const baseApp = new Hono();
|
|
190
|
+
baseApp.route("/", app);
|
|
191
|
+
return baseApp;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
//#endregion
|
|
195
|
+
export { createExecutionHono };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RegisteredAgent } from "../a2a/types.js";
|
|
2
|
+
import { ExecutionContext } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/data/agent.d.ts
|
|
5
|
+
declare function getRegisteredAgent(executionContext: ExecutionContext): Promise<RegisteredAgent | null>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { getRegisteredAgent };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import dbClient_default from "./db/dbClient.js";
|
|
2
|
+
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
3
|
+
import { getAgentById, getSubAgentById } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/data/agent.ts
|
|
6
|
+
async function hydrateAgent({ dbAgent, baseUrl, apiKey }) {
|
|
7
|
+
try {
|
|
8
|
+
if (!dbAgent.defaultSubAgentId) throw new Error(`Agent ${dbAgent.id} does not have a default agent configured`);
|
|
9
|
+
if (!await getSubAgentById(dbClient_default)({
|
|
10
|
+
scopes: {
|
|
11
|
+
tenantId: dbAgent.tenantId,
|
|
12
|
+
projectId: dbAgent.projectId,
|
|
13
|
+
agentId: dbAgent.id
|
|
14
|
+
},
|
|
15
|
+
subAgentId: dbAgent.defaultSubAgentId
|
|
16
|
+
})) throw new Error(`Default agent ${dbAgent.defaultSubAgentId} not found for agent ${dbAgent.id}`);
|
|
17
|
+
const taskHandler = createTaskHandler(await createTaskHandlerConfig({
|
|
18
|
+
tenantId: dbAgent.tenantId,
|
|
19
|
+
projectId: dbAgent.projectId,
|
|
20
|
+
agentId: dbAgent.id,
|
|
21
|
+
subAgentId: dbAgent.defaultSubAgentId,
|
|
22
|
+
baseUrl,
|
|
23
|
+
apiKey
|
|
24
|
+
}));
|
|
25
|
+
const agentCard = {
|
|
26
|
+
name: dbAgent.name,
|
|
27
|
+
description: dbAgent.description || `Agent: ${dbAgent.name}`,
|
|
28
|
+
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
29
|
+
version: "1.0.0",
|
|
30
|
+
capabilities: {
|
|
31
|
+
streaming: true,
|
|
32
|
+
pushNotifications: false,
|
|
33
|
+
stateTransitionHistory: false
|
|
34
|
+
},
|
|
35
|
+
defaultInputModes: ["text", "text/plain"],
|
|
36
|
+
defaultOutputModes: ["text", "text/plain"],
|
|
37
|
+
skills: [],
|
|
38
|
+
...baseUrl && { provider: {
|
|
39
|
+
organization: "Inkeep",
|
|
40
|
+
url: baseUrl
|
|
41
|
+
} }
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
subAgentId: dbAgent.id,
|
|
45
|
+
tenantId: dbAgent.tenantId,
|
|
46
|
+
projectId: dbAgent.projectId,
|
|
47
|
+
agentId: dbAgent.id,
|
|
48
|
+
agentCard,
|
|
49
|
+
taskHandler
|
|
50
|
+
};
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`❌ Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function getRegisteredAgent(executionContext) {
|
|
57
|
+
const { tenantId, projectId, agentId, baseUrl, apiKey } = executionContext;
|
|
58
|
+
const dbAgent = await getAgentById(dbClient_default)({ scopes: {
|
|
59
|
+
tenantId,
|
|
60
|
+
projectId,
|
|
61
|
+
agentId
|
|
62
|
+
} });
|
|
63
|
+
if (!dbAgent) return null;
|
|
64
|
+
return hydrateAgent({
|
|
65
|
+
dbAgent,
|
|
66
|
+
baseUrl: `${baseUrl}/agents`,
|
|
67
|
+
apiKey
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { getRegisteredAgent };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AgentCard as AgentCard$1, RegisteredAgent } from "../a2a/types.js";
|
|
2
|
+
import { SandboxConfig } from "../types/execution-context.js";
|
|
3
|
+
import { CredentialStoreRegistry, ExecutionContext, SubAgentSelect } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/data/agents.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create an AgentCard from database agent data
|
|
9
|
+
* Reusable function that standardizes agent card creation across the codebase
|
|
10
|
+
* Used for external discovery via /.well-known/agent.json endpoint
|
|
11
|
+
*/
|
|
12
|
+
declare function createAgentCard({
|
|
13
|
+
dbAgent,
|
|
14
|
+
baseUrl
|
|
15
|
+
}: {
|
|
16
|
+
dbAgent: SubAgentSelect;
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
}): AgentCard$1;
|
|
19
|
+
/**
|
|
20
|
+
* Generate an enhanced description that includes transfer and delegation information
|
|
21
|
+
* Used in generateTaskHandler to help agents understand what other agents can do
|
|
22
|
+
*
|
|
23
|
+
* @param baseDescription - The base description of the agent
|
|
24
|
+
* @param internalRelations - Pre-computed internal relations
|
|
25
|
+
* @param externalRelations - Pre-computed external relations
|
|
26
|
+
*/
|
|
27
|
+
declare function generateDescriptionWithRelationData(baseDescription: string, internalRelations: any[], externalRelations: any[], teamRelations: any[]): string;
|
|
28
|
+
declare function getRegisteredAgent(params: {
|
|
29
|
+
executionContext: ExecutionContext;
|
|
30
|
+
credentialStoreRegistry?: CredentialStoreRegistry;
|
|
31
|
+
sandboxConfig?: SandboxConfig;
|
|
32
|
+
}): Promise<RegisteredAgent | null>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { createAgentCard, generateDescriptionWithRelationData, getRegisteredAgent };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import dbClient_default from "./db/dbClient.js";
|
|
3
|
+
import { getUserIdFromContext } from "../types/execution-context.js";
|
|
4
|
+
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
5
|
+
import { getAgentWithDefaultSubAgent, getSubAgentById } from "@inkeep/agents-core";
|
|
6
|
+
|
|
7
|
+
//#region src/data/agents.ts
|
|
8
|
+
const logger = getLogger("agents");
|
|
9
|
+
/**
|
|
10
|
+
* Create an AgentCard from database agent data
|
|
11
|
+
* Reusable function that standardizes agent card creation across the codebase
|
|
12
|
+
* Used for external discovery via /.well-known/agent.json endpoint
|
|
13
|
+
*/
|
|
14
|
+
function createAgentCard({ dbAgent, baseUrl }) {
|
|
15
|
+
const description = dbAgent.description || "AI Agent";
|
|
16
|
+
return {
|
|
17
|
+
name: dbAgent.name,
|
|
18
|
+
description,
|
|
19
|
+
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
20
|
+
version: "1.0.0",
|
|
21
|
+
capabilities: {
|
|
22
|
+
streaming: true,
|
|
23
|
+
pushNotifications: false,
|
|
24
|
+
stateTransitionHistory: false
|
|
25
|
+
},
|
|
26
|
+
defaultInputModes: ["text", "text/plain"],
|
|
27
|
+
defaultOutputModes: ["text", "text/plain"],
|
|
28
|
+
skills: [],
|
|
29
|
+
...baseUrl && { provider: {
|
|
30
|
+
organization: "Inkeep",
|
|
31
|
+
url: baseUrl
|
|
32
|
+
} }
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generate an enhanced description that includes transfer and delegation information
|
|
37
|
+
* Used in generateTaskHandler to help agents understand what other agents can do
|
|
38
|
+
*
|
|
39
|
+
* @param baseDescription - The base description of the agent
|
|
40
|
+
* @param internalRelations - Pre-computed internal relations
|
|
41
|
+
* @param externalRelations - Pre-computed external relations
|
|
42
|
+
*/
|
|
43
|
+
function generateDescriptionWithRelationData(baseDescription, internalRelations, externalRelations, teamRelations) {
|
|
44
|
+
const transfers = [...internalRelations.filter((rel) => rel.relationType === "transfer")];
|
|
45
|
+
const delegates = [
|
|
46
|
+
...internalRelations.filter((rel) => rel.relationType === "delegate"),
|
|
47
|
+
...externalRelations.map((data) => data.externalAgent),
|
|
48
|
+
...teamRelations.map((data) => data.targetAgent)
|
|
49
|
+
];
|
|
50
|
+
if (transfers.length === 0 && delegates.length === 0) return baseDescription;
|
|
51
|
+
let enhancedDescription = baseDescription;
|
|
52
|
+
if (transfers.length > 0) {
|
|
53
|
+
const transferList = transfers.map((rel) => {
|
|
54
|
+
return `- ${rel.externalAgent?.name || rel.name}: ${rel.externalAgent?.description || rel.description || ""}`;
|
|
55
|
+
}).join("\n");
|
|
56
|
+
enhancedDescription += `\n\nCan transfer to:\n${transferList}`;
|
|
57
|
+
}
|
|
58
|
+
if (delegates.length > 0) {
|
|
59
|
+
const delegateList = delegates.map((rel) => {
|
|
60
|
+
return `- ${rel.name}: ${rel.description || ""}`;
|
|
61
|
+
}).join("\n");
|
|
62
|
+
enhancedDescription += `\n\nCan delegate to:\n${delegateList}`;
|
|
63
|
+
}
|
|
64
|
+
return enhancedDescription;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a RegisteredAgent from database agent data
|
|
68
|
+
* Hydrates agent directly from database schema using types from schema.ts
|
|
69
|
+
*/
|
|
70
|
+
async function hydrateAgent({ dbAgent, agentId, baseUrl, apiKey, credentialStoreRegistry, sandboxConfig, userId }) {
|
|
71
|
+
try {
|
|
72
|
+
const taskHandler = createTaskHandler(await createTaskHandlerConfig({
|
|
73
|
+
tenantId: dbAgent.tenantId,
|
|
74
|
+
projectId: dbAgent.projectId,
|
|
75
|
+
agentId,
|
|
76
|
+
subAgentId: dbAgent.id,
|
|
77
|
+
baseUrl,
|
|
78
|
+
apiKey,
|
|
79
|
+
sandboxConfig,
|
|
80
|
+
userId
|
|
81
|
+
}), credentialStoreRegistry);
|
|
82
|
+
const agentCard = createAgentCard({
|
|
83
|
+
dbAgent,
|
|
84
|
+
baseUrl
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
subAgentId: dbAgent.id,
|
|
88
|
+
tenantId: dbAgent.tenantId,
|
|
89
|
+
projectId: dbAgent.projectId,
|
|
90
|
+
agentId,
|
|
91
|
+
agentCard,
|
|
92
|
+
taskHandler
|
|
93
|
+
};
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error(`❌ Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function getRegisteredAgent(params) {
|
|
100
|
+
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
101
|
+
const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
102
|
+
const userId = getUserIdFromContext(executionContext);
|
|
103
|
+
let dbAgent;
|
|
104
|
+
if (!subAgentId) {
|
|
105
|
+
const agent = await getAgentWithDefaultSubAgent(dbClient_default)({ scopes: {
|
|
106
|
+
tenantId,
|
|
107
|
+
projectId,
|
|
108
|
+
agentId
|
|
109
|
+
} });
|
|
110
|
+
logger.info({ agent }, "agent with default sub agent");
|
|
111
|
+
if (!agent || !agent.defaultSubAgent) return null;
|
|
112
|
+
dbAgent = agent.defaultSubAgent;
|
|
113
|
+
} else {
|
|
114
|
+
const response = await getSubAgentById(dbClient_default)({
|
|
115
|
+
scopes: {
|
|
116
|
+
tenantId,
|
|
117
|
+
projectId,
|
|
118
|
+
agentId
|
|
119
|
+
},
|
|
120
|
+
subAgentId
|
|
121
|
+
});
|
|
122
|
+
if (!response) return null;
|
|
123
|
+
dbAgent = response;
|
|
124
|
+
}
|
|
125
|
+
if (!dbAgent) return null;
|
|
126
|
+
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
127
|
+
return hydrateAgent({
|
|
128
|
+
dbAgent,
|
|
129
|
+
agentId,
|
|
130
|
+
baseUrl: agentFrameworkBaseUrl,
|
|
131
|
+
credentialStoreRegistry,
|
|
132
|
+
apiKey,
|
|
133
|
+
sandboxConfig,
|
|
134
|
+
userId
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
export { createAgentCard, generateDescriptionWithRelationData, getRegisteredAgent };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { AgentConversationHistoryConfig, Artifact, ConversationHistoryConfig, ConversationScopeOptions } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/data/conversations.d.ts
|
|
4
|
+
declare const compressionLocks: Map<string, Promise<any>>;
|
|
5
|
+
/**
|
|
6
|
+
* Creates default conversation history configuration
|
|
7
|
+
* @param mode - The conversation history mode ('full' | 'scoped' | 'none')
|
|
8
|
+
* @returns Default AgentConversationHistoryConfig
|
|
9
|
+
*/
|
|
10
|
+
declare function createDefaultConversationHistoryConfig(mode?: 'full' | 'scoped' | 'none'): AgentConversationHistoryConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Saves the result of an A2A client sendMessage call as a conversation message
|
|
13
|
+
* @param response - The response from a2aClient.sendMessage()
|
|
14
|
+
* @param params - Parameters for saving the message
|
|
15
|
+
* @returns The saved message or null if no text content was found
|
|
16
|
+
*/
|
|
17
|
+
declare function saveA2AMessageResponse(response: any,
|
|
18
|
+
// SendMessageResponse type
|
|
19
|
+
params: {
|
|
20
|
+
tenantId: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
conversationId: string;
|
|
23
|
+
messageType: 'a2a-response' | 'a2a-request';
|
|
24
|
+
visibility: 'internal' | 'external' | 'user-facing';
|
|
25
|
+
fromSubAgentId?: string;
|
|
26
|
+
toSubAgentId?: string;
|
|
27
|
+
fromExternalAgentId?: string;
|
|
28
|
+
toExternalAgentId?: string;
|
|
29
|
+
a2aTaskId?: string;
|
|
30
|
+
a2aSessionId?: string;
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}): Promise<any | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Applies filtering based on agent, task, or both criteria
|
|
35
|
+
* Returns the filtered messages array
|
|
36
|
+
*/
|
|
37
|
+
declare function getScopedHistory({
|
|
38
|
+
tenantId,
|
|
39
|
+
projectId,
|
|
40
|
+
conversationId,
|
|
41
|
+
filters,
|
|
42
|
+
options
|
|
43
|
+
}: {
|
|
44
|
+
tenantId: string;
|
|
45
|
+
projectId: string;
|
|
46
|
+
conversationId: string;
|
|
47
|
+
filters?: ConversationScopeOptions;
|
|
48
|
+
options?: ConversationHistoryConfig;
|
|
49
|
+
}): Promise<any[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Get user-facing conversation history (for client display)
|
|
52
|
+
*/
|
|
53
|
+
declare function getUserFacingHistory(tenantId: string, projectId: string, conversationId: string, limit?: 50): Promise<any[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Get full conversation context (for agent processing)
|
|
56
|
+
*/
|
|
57
|
+
declare function getFullConversationContext(tenantId: string, projectId: string, conversationId: string, maxTokens?: number): Promise<any[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Get formatted conversation history for a2a
|
|
60
|
+
*/
|
|
61
|
+
declare function getFormattedConversationHistory({
|
|
62
|
+
tenantId,
|
|
63
|
+
projectId,
|
|
64
|
+
conversationId,
|
|
65
|
+
currentMessage,
|
|
66
|
+
options,
|
|
67
|
+
filters,
|
|
68
|
+
sessionId,
|
|
69
|
+
summarizerModel
|
|
70
|
+
}: {
|
|
71
|
+
tenantId: string;
|
|
72
|
+
projectId: string;
|
|
73
|
+
conversationId: string;
|
|
74
|
+
currentMessage?: string;
|
|
75
|
+
options?: ConversationHistoryConfig;
|
|
76
|
+
filters?: ConversationScopeOptions;
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
summarizerModel?: any;
|
|
79
|
+
}): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Modern conversation history retrieval with compression support
|
|
82
|
+
* Replaces getFormattedConversationHistory with built-in compression when needed
|
|
83
|
+
*/
|
|
84
|
+
declare function getConversationHistoryWithCompression({
|
|
85
|
+
tenantId,
|
|
86
|
+
projectId,
|
|
87
|
+
conversationId,
|
|
88
|
+
currentMessage,
|
|
89
|
+
options,
|
|
90
|
+
filters,
|
|
91
|
+
summarizerModel,
|
|
92
|
+
streamRequestId,
|
|
93
|
+
fullContextSize
|
|
94
|
+
}: {
|
|
95
|
+
tenantId: string;
|
|
96
|
+
projectId: string;
|
|
97
|
+
conversationId: string;
|
|
98
|
+
currentMessage?: string;
|
|
99
|
+
options?: ConversationHistoryConfig;
|
|
100
|
+
filters?: ConversationScopeOptions;
|
|
101
|
+
summarizerModel?: any;
|
|
102
|
+
streamRequestId?: string;
|
|
103
|
+
fullContextSize?: number;
|
|
104
|
+
}): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Apply conversation compression using the BaseCompressor infrastructure
|
|
107
|
+
*/
|
|
108
|
+
declare function compressConversationIfNeeded(messages: any[], params: {
|
|
109
|
+
conversationId: string;
|
|
110
|
+
tenantId: string;
|
|
111
|
+
projectId: string;
|
|
112
|
+
summarizerModel: any;
|
|
113
|
+
streamRequestId?: string;
|
|
114
|
+
fullContextSize?: number;
|
|
115
|
+
}): Promise<any[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Get artifacts that are within the scope of the conversation history
|
|
118
|
+
* Only returns artifacts from messages that are actually visible to the LLM
|
|
119
|
+
* Uses the same scoping logic as getFormattedConversationHistory
|
|
120
|
+
*/
|
|
121
|
+
declare function getConversationScopedArtifacts(params: {
|
|
122
|
+
tenantId: string;
|
|
123
|
+
projectId: string;
|
|
124
|
+
conversationId: string;
|
|
125
|
+
historyConfig: AgentConversationHistoryConfig;
|
|
126
|
+
}): Promise<Artifact[]>;
|
|
127
|
+
//#endregion
|
|
128
|
+
export { compressConversationIfNeeded, compressionLocks, createDefaultConversationHistoryConfig, getConversationHistoryWithCompression, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse };
|