@inkeep/agents-run-api 0.0.0-dev-20260113172432 → 0.0.0-dev-20260115183047
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/README.md +2 -1
- package/dist/a2a/client.d.ts +3 -1
- package/dist/a2a/client.js +23 -9
- package/dist/a2a/handlers.js +11 -5
- package/dist/a2a/transfer.d.ts +6 -1
- package/dist/a2a/transfer.js +10 -6
- package/dist/agents/Agent.d.ts +8 -4
- package/dist/agents/Agent.js +226 -92
- package/dist/agents/ToolSessionManager.js +2 -2
- package/dist/agents/generateTaskHandler.d.ts +4 -9
- package/dist/agents/generateTaskHandler.js +107 -246
- package/dist/agents/relationTools.d.ts +19 -8
- package/dist/agents/relationTools.js +105 -14
- package/dist/agents/types.d.ts +4 -2
- package/dist/agents/versions/v1/Phase1Config.d.ts +4 -3
- package/dist/agents/versions/v1/Phase1Config.js +33 -20
- package/dist/constants/execution-limits/index.js +1 -1
- package/dist/context/ContextFetcher.d.ts +68 -0
- package/dist/context/ContextFetcher.js +276 -0
- package/dist/context/ContextResolver.d.ts +56 -0
- package/dist/context/ContextResolver.js +273 -0
- package/dist/context/context.d.ts +19 -0
- package/dist/context/context.js +108 -0
- package/dist/context/contextCache.d.ts +56 -0
- package/dist/context/contextCache.js +175 -0
- package/dist/context/index.d.ts +6 -0
- package/dist/context/index.js +7 -0
- package/dist/context/validation.d.ts +39 -0
- package/dist/context/validation.js +255 -0
- package/dist/create-app.d.ts +2 -2
- package/dist/create-app.js +7 -2
- package/dist/data/agent.d.ts +2 -2
- package/dist/data/agent.js +17 -22
- package/dist/data/agents.d.ts +2 -2
- package/dist/data/agents.js +34 -42
- package/dist/data/conversations.d.ts +2 -1
- package/dist/data/conversations.js +7 -8
- package/dist/data/db/dbClient.d.ts +2 -2
- package/dist/data/db/dbClient.js +2 -10
- package/dist/env.d.ts +6 -2
- package/dist/env.js +3 -1
- package/dist/handlers/executionHandler.d.ts +3 -2
- package/dist/handlers/executionHandler.js +46 -22
- package/dist/index.d.ts +3 -3
- package/dist/middleware/api-key-auth.d.ts +4 -10
- package/dist/middleware/api-key-auth.js +164 -163
- package/dist/middleware/index.d.ts +3 -2
- package/dist/middleware/index.js +3 -2
- package/dist/middleware/projectConfig.d.ts +19 -0
- package/dist/middleware/projectConfig.js +80 -0
- package/dist/routes/agents.d.ts +2 -1
- package/dist/routes/agents.js +7 -13
- package/dist/routes/chat.d.ts +2 -1
- package/dist/routes/chat.js +29 -52
- package/dist/routes/chatDataStream.d.ts +2 -1
- package/dist/routes/chatDataStream.js +28 -30
- package/dist/routes/mcp.d.ts +2 -1
- package/dist/routes/mcp.js +25 -37
- package/dist/services/AgentSession.d.ts +5 -7
- package/dist/services/AgentSession.js +25 -34
- package/dist/services/ArtifactParser.d.ts +2 -2
- package/dist/services/ArtifactParser.js +2 -2
- package/dist/services/ArtifactService.d.ts +2 -3
- package/dist/services/ArtifactService.js +23 -20
- package/dist/services/BaseCompressor.js +2 -2
- package/dist/services/IncrementalStreamParser.d.ts +2 -2
- package/dist/services/IncrementalStreamParser.js +2 -2
- package/dist/services/ResponseFormatter.d.ts +2 -2
- package/dist/services/ResponseFormatter.js +2 -2
- package/dist/services/evaluationHttpClient.d.ts +21 -0
- package/dist/services/evaluationHttpClient.js +48 -0
- package/dist/services/evaluationRunConfigMatcher.d.ts +6 -0
- package/dist/services/evaluationRunConfigMatcher.js +7 -0
- package/dist/tools/NativeSandboxExecutor.js +1 -1
- package/dist/tools/distill-conversation-history-tool.js +2 -2
- package/dist/tools/distill-conversation-tool.js +2 -2
- package/dist/types/execution-context.d.ts +8 -14
- package/dist/types/execution-context.js +3 -2
- package/dist/utils/model-resolver.d.ts +2 -2
- package/dist/utils/model-resolver.js +3 -13
- package/dist/utils/project.d.ts +207 -0
- package/dist/utils/project.js +315 -0
- package/dist/utils/token-estimator.d.ts +6 -52
- package/dist/utils/token-estimator.js +2 -38
- package/package.json +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContextCache } from "./contextCache.js";
|
|
2
|
+
import { ContextResolver } from "./ContextResolver.js";
|
|
3
|
+
import { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper } from "./validation.js";
|
|
4
|
+
import { ContextFetcher, MissingRequiredVariableError } from "./ContextFetcher.js";
|
|
5
|
+
import { determineContextTrigger, handleContextConfigChange, handleContextResolution } from "./context.js";
|
|
6
|
+
|
|
7
|
+
export { ContextCache, ContextFetcher, ContextResolver, HTTP_REQUEST_PARTS, MissingRequiredVariableError, contextValidationMiddleware, determineContextTrigger, getCachedValidator, handleContextConfigChange, handleContextResolution, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CredentialStoreRegistry, FullExecutionContext } from "@inkeep/agents-core";
|
|
2
|
+
import { Context, Next } from "hono";
|
|
3
|
+
import { ValidateFunction } from "ajv";
|
|
4
|
+
|
|
5
|
+
//#region src/context/validation.d.ts
|
|
6
|
+
declare const HTTP_REQUEST_PARTS: readonly ["headers"];
|
|
7
|
+
type HttpRequestPart = (typeof HTTP_REQUEST_PARTS)[number];
|
|
8
|
+
interface ContextValidationError {
|
|
9
|
+
field: string;
|
|
10
|
+
message: string;
|
|
11
|
+
value?: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface ContextValidationResult {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
errors: ContextValidationError[];
|
|
16
|
+
validatedContext?: Record<string, unknown> | ParsedHttpRequest;
|
|
17
|
+
}
|
|
18
|
+
interface ParsedHttpRequest {
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
declare function isValidHttpRequest(obj: any): obj is ParsedHttpRequest;
|
|
22
|
+
declare function getCachedValidator(schema: Record<string, unknown>): ValidateFunction;
|
|
23
|
+
declare function validationHelper(jsonSchema: Record<string, unknown>): ValidateFunction<unknown>;
|
|
24
|
+
declare function validateAgainstJsonSchema(jsonSchema: Record<string, unknown>, context: unknown): boolean;
|
|
25
|
+
declare function validateHttpRequestHeaders(headersSchema: any, httpRequest: ParsedHttpRequest): Promise<ContextValidationResult>;
|
|
26
|
+
declare function validateHeaders({
|
|
27
|
+
executionContext,
|
|
28
|
+
conversationId,
|
|
29
|
+
parsedRequest,
|
|
30
|
+
credentialStores
|
|
31
|
+
}: {
|
|
32
|
+
executionContext: FullExecutionContext;
|
|
33
|
+
conversationId: string;
|
|
34
|
+
parsedRequest: ParsedHttpRequest;
|
|
35
|
+
credentialStores?: CredentialStoreRegistry;
|
|
36
|
+
}): Promise<ContextValidationResult>;
|
|
37
|
+
declare function contextValidationMiddleware(c: Context, next: Next): Promise<void>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ContextValidationError, ContextValidationResult, HTTP_REQUEST_PARTS, HttpRequestPart, ParsedHttpRequest, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { ContextResolver } from "./ContextResolver.js";
|
|
2
|
+
import { createApiError, getLogger } from "@inkeep/agents-core";
|
|
3
|
+
import Ajv from "ajv";
|
|
4
|
+
|
|
5
|
+
//#region src/context/validation.ts
|
|
6
|
+
const logger = getLogger("context-validation");
|
|
7
|
+
const ajv = new Ajv({
|
|
8
|
+
allErrors: true,
|
|
9
|
+
strict: false
|
|
10
|
+
});
|
|
11
|
+
const HTTP_REQUEST_PARTS = ["headers"];
|
|
12
|
+
const MAX_SCHEMA_CACHE_SIZE = 1e3;
|
|
13
|
+
const schemaCache = /* @__PURE__ */ new Map();
|
|
14
|
+
function isValidHttpRequest(obj) {
|
|
15
|
+
return obj != null && typeof obj === "object" && !Array.isArray(obj) && "headers" in obj;
|
|
16
|
+
}
|
|
17
|
+
function getCachedValidator(schema) {
|
|
18
|
+
const key = JSON.stringify(schema);
|
|
19
|
+
if (schemaCache.has(key)) {
|
|
20
|
+
const validator$1 = schemaCache.get(key);
|
|
21
|
+
if (!validator$1) throw new Error("Unexpected: validator not found in cache after has() check");
|
|
22
|
+
schemaCache.delete(key);
|
|
23
|
+
schemaCache.set(key, validator$1);
|
|
24
|
+
return validator$1;
|
|
25
|
+
}
|
|
26
|
+
if (schemaCache.size >= MAX_SCHEMA_CACHE_SIZE) {
|
|
27
|
+
const firstKey = schemaCache.keys().next().value;
|
|
28
|
+
if (firstKey) schemaCache.delete(firstKey);
|
|
29
|
+
}
|
|
30
|
+
const permissiveSchema = makeSchemaPermissive(schema);
|
|
31
|
+
const validator = ajv.compile(permissiveSchema);
|
|
32
|
+
schemaCache.set(key, validator);
|
|
33
|
+
return validator;
|
|
34
|
+
}
|
|
35
|
+
function makeSchemaPermissive(schema) {
|
|
36
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
37
|
+
const permissiveSchema = { ...schema };
|
|
38
|
+
if (permissiveSchema.type === "object") {
|
|
39
|
+
permissiveSchema.additionalProperties = true;
|
|
40
|
+
if (permissiveSchema.properties && typeof permissiveSchema.properties === "object") {
|
|
41
|
+
const newProperties = {};
|
|
42
|
+
for (const [key, value] of Object.entries(permissiveSchema.properties)) newProperties[key] = makeSchemaPermissive(value);
|
|
43
|
+
permissiveSchema.properties = newProperties;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (permissiveSchema.type === "array" && permissiveSchema.items) permissiveSchema.items = makeSchemaPermissive(permissiveSchema.items);
|
|
47
|
+
if (permissiveSchema.oneOf) permissiveSchema.oneOf = permissiveSchema.oneOf.map(makeSchemaPermissive);
|
|
48
|
+
if (permissiveSchema.anyOf) permissiveSchema.anyOf = permissiveSchema.anyOf.map(makeSchemaPermissive);
|
|
49
|
+
if (permissiveSchema.allOf) permissiveSchema.allOf = permissiveSchema.allOf.map(makeSchemaPermissive);
|
|
50
|
+
return permissiveSchema;
|
|
51
|
+
}
|
|
52
|
+
function validationHelper(jsonSchema) {
|
|
53
|
+
return getCachedValidator(jsonSchema);
|
|
54
|
+
}
|
|
55
|
+
function validateAgainstJsonSchema(jsonSchema, context) {
|
|
56
|
+
return validationHelper(jsonSchema)(context);
|
|
57
|
+
}
|
|
58
|
+
function filterByJsonSchema(data, schema) {
|
|
59
|
+
if (!schema || data === null || data === void 0) return data;
|
|
60
|
+
if (schema.type === "object" && schema.properties && typeof data === "object" && !Array.isArray(data)) {
|
|
61
|
+
const filtered = {};
|
|
62
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) if (key in data) filtered[key] = filterByJsonSchema(data[key], propSchema);
|
|
63
|
+
return filtered;
|
|
64
|
+
}
|
|
65
|
+
if (schema.type === "array" && schema.items && Array.isArray(data)) return data.map((item) => filterByJsonSchema(item, schema.items));
|
|
66
|
+
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
67
|
+
for (const subSchema of schema.anyOf) if (subSchema.type && typeof data === subSchema.type) return filterByJsonSchema(data, subSchema);
|
|
68
|
+
return filterByJsonSchema(data, schema.anyOf[0]);
|
|
69
|
+
}
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
function filterContextToSchemaKeys(validatedContext, headersSchema) {
|
|
73
|
+
if (!headersSchema || !validatedContext) return validatedContext;
|
|
74
|
+
const filteredHeaders = filterByJsonSchema(validatedContext, headersSchema);
|
|
75
|
+
if (filteredHeaders !== null && filteredHeaders !== void 0) {
|
|
76
|
+
if (typeof filteredHeaders === "object" && Object.keys(filteredHeaders).length > 0) return filteredHeaders;
|
|
77
|
+
if (typeof filteredHeaders !== "object") return filteredHeaders;
|
|
78
|
+
}
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
async function validateHttpRequestHeaders(headersSchema, httpRequest) {
|
|
82
|
+
const errors = [];
|
|
83
|
+
let validatedContext = {};
|
|
84
|
+
if (!isValidHttpRequest(httpRequest)) return {
|
|
85
|
+
valid: false,
|
|
86
|
+
errors: [{
|
|
87
|
+
field: "httpRequest",
|
|
88
|
+
message: "Invalid HTTP request format - must contain headers"
|
|
89
|
+
}]
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
if (headersSchema && httpRequest.headers !== void 0) try {
|
|
93
|
+
const validate = validationHelper(headersSchema);
|
|
94
|
+
if (validate(httpRequest.headers)) validatedContext = httpRequest.headers;
|
|
95
|
+
else if (validate.errors) for (const error of validate.errors) errors.push({
|
|
96
|
+
field: `headers.${error.instancePath || "root"}`,
|
|
97
|
+
message: `headers ${error.message}`,
|
|
98
|
+
value: error.data
|
|
99
|
+
});
|
|
100
|
+
} catch (validationError) {
|
|
101
|
+
errors.push({
|
|
102
|
+
field: "headers",
|
|
103
|
+
message: `Failed to validate headers: ${validationError instanceof Error ? validationError.message : "Unknown error"}`
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const filteredContext = errors.length === 0 ? filterContextToSchemaKeys(validatedContext, headersSchema) : void 0;
|
|
107
|
+
return {
|
|
108
|
+
valid: errors.length === 0,
|
|
109
|
+
errors,
|
|
110
|
+
validatedContext: filteredContext
|
|
111
|
+
};
|
|
112
|
+
} catch (error) {
|
|
113
|
+
logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Failed to validate headers schema");
|
|
114
|
+
return {
|
|
115
|
+
valid: false,
|
|
116
|
+
errors: [{
|
|
117
|
+
field: "schema",
|
|
118
|
+
message: "Failed to validate headers schema"
|
|
119
|
+
}]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function fetchExistingHeaders({ executionContext, contextConfig, conversationId, credentialStores }) {
|
|
124
|
+
const headers$1 = await new ContextResolver(executionContext, credentialStores).resolveHeaders(conversationId, contextConfig.id);
|
|
125
|
+
if (Object.keys(headers$1).length > 0) return {
|
|
126
|
+
valid: true,
|
|
127
|
+
errors: [],
|
|
128
|
+
validatedContext: headers$1
|
|
129
|
+
};
|
|
130
|
+
throw new Error("No headers found in cache. Please provide headers in request.");
|
|
131
|
+
}
|
|
132
|
+
async function validateHeaders({ executionContext, conversationId, parsedRequest, credentialStores }) {
|
|
133
|
+
try {
|
|
134
|
+
const { tenantId, projectId, agentId, project } = executionContext;
|
|
135
|
+
logger.info({
|
|
136
|
+
tenantId,
|
|
137
|
+
projectId,
|
|
138
|
+
agentId
|
|
139
|
+
}, "Validating headers");
|
|
140
|
+
const contextConfig = project.agents[agentId].contextConfig;
|
|
141
|
+
logger.info({ contextConfig }, "Context config found");
|
|
142
|
+
if (!contextConfig) {
|
|
143
|
+
logger.info({ agentId }, "No context config found for agent, skipping validation");
|
|
144
|
+
return {
|
|
145
|
+
valid: true,
|
|
146
|
+
errors: [],
|
|
147
|
+
validatedContext: parsedRequest
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (!contextConfig.headersSchema) {
|
|
151
|
+
logger.debug({ contextConfigId: contextConfig.id }, "No headers schema defined, accepting any context");
|
|
152
|
+
return {
|
|
153
|
+
valid: true,
|
|
154
|
+
errors: [],
|
|
155
|
+
validatedContext: parsedRequest
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const schema = contextConfig.headersSchema;
|
|
160
|
+
logger.debug({ contextConfigId: contextConfig.id }, "Using headers schema validation");
|
|
161
|
+
const validationResult = await validateHttpRequestHeaders(schema, parsedRequest);
|
|
162
|
+
if (validationResult.valid) return validationResult;
|
|
163
|
+
try {
|
|
164
|
+
return await fetchExistingHeaders({
|
|
165
|
+
executionContext,
|
|
166
|
+
contextConfig,
|
|
167
|
+
conversationId,
|
|
168
|
+
credentialStores
|
|
169
|
+
});
|
|
170
|
+
} catch (_error) {
|
|
171
|
+
validationResult.errors.push({
|
|
172
|
+
field: "headers",
|
|
173
|
+
message: "Failed to fetch headers from cache"
|
|
174
|
+
});
|
|
175
|
+
return validationResult;
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
logger.error({
|
|
179
|
+
contextConfigId: contextConfig.id,
|
|
180
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
181
|
+
}, "Failed to compile or validate schema");
|
|
182
|
+
return {
|
|
183
|
+
valid: false,
|
|
184
|
+
errors: [{
|
|
185
|
+
field: "schema",
|
|
186
|
+
message: "Invalid schema definition or validation error"
|
|
187
|
+
}]
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
logger.error({
|
|
192
|
+
tenantId: executionContext.tenantId,
|
|
193
|
+
agentId: executionContext.agentId,
|
|
194
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
195
|
+
}, "Failed to validate headers");
|
|
196
|
+
return {
|
|
197
|
+
valid: false,
|
|
198
|
+
errors: [{
|
|
199
|
+
field: "validation",
|
|
200
|
+
message: "Context validation failed due to internal error"
|
|
201
|
+
}]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async function contextValidationMiddleware(c, next) {
|
|
206
|
+
try {
|
|
207
|
+
const executionContext = c.get("executionContext");
|
|
208
|
+
let { tenantId, projectId, agentId, ref } = executionContext;
|
|
209
|
+
if (!tenantId || !projectId || !agentId) {
|
|
210
|
+
tenantId = c.req.param("tenantId");
|
|
211
|
+
projectId = c.req.param("projectId");
|
|
212
|
+
agentId = c.req.param("agentId");
|
|
213
|
+
}
|
|
214
|
+
if (!tenantId || !projectId || !agentId) return next();
|
|
215
|
+
const conversationId = (c.get("requestBody") || {}).conversationId || "";
|
|
216
|
+
const headers$1 = {};
|
|
217
|
+
c.req.raw.headers.forEach((value, key) => {
|
|
218
|
+
headers$1[key.toLowerCase()] = value;
|
|
219
|
+
});
|
|
220
|
+
const credentialStores = c.get("credentialStores");
|
|
221
|
+
const validationResult = await validateHeaders({
|
|
222
|
+
executionContext,
|
|
223
|
+
conversationId,
|
|
224
|
+
parsedRequest: { headers: headers$1 },
|
|
225
|
+
credentialStores
|
|
226
|
+
});
|
|
227
|
+
if (!validationResult.valid) {
|
|
228
|
+
logger.warn({
|
|
229
|
+
tenantId,
|
|
230
|
+
agentId,
|
|
231
|
+
errors: validationResult.errors
|
|
232
|
+
}, "Headers validation failed");
|
|
233
|
+
throw createApiError({
|
|
234
|
+
code: "bad_request",
|
|
235
|
+
message: `Invalid headers: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
c.set("validatedContext", validationResult.validatedContext);
|
|
239
|
+
logger.debug({
|
|
240
|
+
tenantId,
|
|
241
|
+
agentId,
|
|
242
|
+
contextKeys: Object.keys(validationResult.validatedContext || {})
|
|
243
|
+
}, "Request context validation successful");
|
|
244
|
+
return next();
|
|
245
|
+
} catch (error) {
|
|
246
|
+
logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Context validation middleware error");
|
|
247
|
+
throw createApiError({
|
|
248
|
+
code: "internal_server_error",
|
|
249
|
+
message: "Context validation failed"
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//#endregion
|
|
255
|
+
export { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
|
package/dist/create-app.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SandboxConfig } from "./types/execution-context.js";
|
|
2
2
|
import { CredentialStoreRegistry, ServerConfig } from "@inkeep/agents-core";
|
|
3
3
|
import { Hono } from "hono";
|
|
4
|
-
import * as
|
|
4
|
+
import * as hono_types0 from "hono/types";
|
|
5
5
|
|
|
6
6
|
//#region src/create-app.d.ts
|
|
7
|
-
declare function createExecutionHono(serverConfig: ServerConfig, credentialStores: CredentialStoreRegistry, sandboxConfig?: SandboxConfig): Hono<
|
|
7
|
+
declare function createExecutionHono(serverConfig: ServerConfig, credentialStores: CredentialStoreRegistry, sandboxConfig?: SandboxConfig): Hono<hono_types0.BlankEnv, hono_types0.BlankSchema, "/">;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { createExecutionHono };
|
package/dist/create-app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getLogger } from "./logger.js";
|
|
1
|
+
import { getLogger as getLogger$1 } from "./logger.js";
|
|
2
2
|
import { flushBatchProcessor } from "./instrumentation.js";
|
|
3
3
|
import { apiKeyAuth } from "./middleware/api-key-auth.js";
|
|
4
|
+
import { projectConfigMiddleware } from "./middleware/projectConfig.js";
|
|
4
5
|
import { setupOpenAPIRoutes } from "./openapi.js";
|
|
5
6
|
import agents_default from "./routes/agents.js";
|
|
6
7
|
import chat_default from "./routes/chat.js";
|
|
@@ -16,7 +17,7 @@ import { HTTPException } from "hono/http-exception";
|
|
|
16
17
|
import { requestId } from "hono/request-id";
|
|
17
18
|
|
|
18
19
|
//#region src/create-app.ts
|
|
19
|
-
const logger = getLogger("agents-run-api");
|
|
20
|
+
const logger = getLogger$1("agents-run-api");
|
|
20
21
|
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
21
22
|
const app = new OpenAPIHono();
|
|
22
23
|
app.use("*", otel());
|
|
@@ -125,6 +126,10 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
125
126
|
app.use("/agents/*", apiKeyAuth());
|
|
126
127
|
app.use("/v1/*", apiKeyAuth());
|
|
127
128
|
app.use("/api/*", apiKeyAuth());
|
|
129
|
+
app.use("/tenants/*", projectConfigMiddleware);
|
|
130
|
+
app.use("/agents/*", projectConfigMiddleware);
|
|
131
|
+
app.use("/v1/*", projectConfigMiddleware);
|
|
132
|
+
app.use("/api/*", projectConfigMiddleware);
|
|
128
133
|
app.use("*", async (c, next) => {
|
|
129
134
|
const executionContext = c.get("executionContext");
|
|
130
135
|
if (!executionContext) {
|
package/dist/data/agent.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RegisteredAgent } from "../a2a/types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FullExecutionContext } from "@inkeep/agents-core";
|
|
3
3
|
|
|
4
4
|
//#region src/data/agent.d.ts
|
|
5
|
-
declare function getRegisteredAgent(executionContext:
|
|
5
|
+
declare function getRegisteredAgent(executionContext: FullExecutionContext): Promise<RegisteredAgent | null>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { getRegisteredAgent };
|
package/dist/data/agent.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getAgentFromProject, getSubAgentFromProject } from "../utils/project.js";
|
|
2
2
|
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
3
|
-
import { getAgentById, getSubAgentById } from "@inkeep/agents-core";
|
|
4
3
|
|
|
5
4
|
//#region src/data/agent.ts
|
|
6
|
-
async function hydrateAgent({ dbAgent,
|
|
5
|
+
async function hydrateAgent({ dbAgent, executionContext, baseUrl }) {
|
|
6
|
+
const { tenantId, projectId, agentId, project, resolvedRef, apiKey } = executionContext;
|
|
7
7
|
try {
|
|
8
8
|
if (!dbAgent.defaultSubAgentId) throw new Error(`Agent ${dbAgent.id} does not have a default agent configured`);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
subAgentId: dbAgent.defaultSubAgentId
|
|
9
|
+
const subAgentId = dbAgent.defaultSubAgentId;
|
|
10
|
+
if (!getSubAgentFromProject({
|
|
11
|
+
project,
|
|
12
|
+
agentId,
|
|
13
|
+
subAgentId
|
|
16
14
|
})) throw new Error(`Default agent ${dbAgent.defaultSubAgentId} not found for agent ${dbAgent.id}`);
|
|
17
15
|
const taskHandler = createTaskHandler(await createTaskHandlerConfig({
|
|
18
|
-
|
|
19
|
-
projectId: dbAgent.projectId,
|
|
20
|
-
agentId: dbAgent.id,
|
|
16
|
+
executionContext,
|
|
21
17
|
subAgentId: dbAgent.defaultSubAgentId,
|
|
22
18
|
baseUrl,
|
|
23
19
|
apiKey
|
|
@@ -42,8 +38,8 @@ async function hydrateAgent({ dbAgent, baseUrl, apiKey }) {
|
|
|
42
38
|
};
|
|
43
39
|
return {
|
|
44
40
|
subAgentId: dbAgent.id,
|
|
45
|
-
tenantId
|
|
46
|
-
projectId
|
|
41
|
+
tenantId,
|
|
42
|
+
projectId,
|
|
47
43
|
agentId: dbAgent.id,
|
|
48
44
|
agentCard,
|
|
49
45
|
taskHandler
|
|
@@ -54,17 +50,16 @@ async function hydrateAgent({ dbAgent, baseUrl, apiKey }) {
|
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
52
|
async function getRegisteredAgent(executionContext) {
|
|
57
|
-
const {
|
|
58
|
-
const dbAgent =
|
|
59
|
-
|
|
60
|
-
projectId,
|
|
53
|
+
const { project, agentId, baseUrl } = executionContext;
|
|
54
|
+
const dbAgent = getAgentFromProject({
|
|
55
|
+
project,
|
|
61
56
|
agentId
|
|
62
|
-
}
|
|
57
|
+
});
|
|
63
58
|
if (!dbAgent) return null;
|
|
64
59
|
return hydrateAgent({
|
|
65
60
|
dbAgent,
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
executionContext,
|
|
62
|
+
baseUrl: `${baseUrl}/agents`
|
|
68
63
|
});
|
|
69
64
|
}
|
|
70
65
|
|
package/dist/data/agents.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentCard as AgentCard$1, RegisteredAgent } from "../a2a/types.js";
|
|
2
2
|
import { SandboxConfig } from "../types/execution-context.js";
|
|
3
|
-
import { CredentialStoreRegistry,
|
|
3
|
+
import { CredentialStoreRegistry, FullExecutionContext, SubAgentSelect } from "@inkeep/agents-core";
|
|
4
4
|
|
|
5
5
|
//#region src/data/agents.d.ts
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ declare function createAgentCard({
|
|
|
26
26
|
*/
|
|
27
27
|
declare function generateDescriptionWithRelationData(baseDescription: string, internalRelations: any[], externalRelations: any[], teamRelations: any[]): string;
|
|
28
28
|
declare function getRegisteredAgent(params: {
|
|
29
|
-
executionContext:
|
|
29
|
+
executionContext: FullExecutionContext;
|
|
30
30
|
credentialStoreRegistry?: CredentialStoreRegistry;
|
|
31
31
|
sandboxConfig?: SandboxConfig;
|
|
32
32
|
}): Promise<RegisteredAgent | null>;
|
package/dist/data/agents.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { getLogger } from "../logger.js";
|
|
2
|
-
import
|
|
3
|
-
import { getUserIdFromContext } from "../types/execution-context.js";
|
|
2
|
+
import { getSubAgentFromProject } from "../utils/project.js";
|
|
4
3
|
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
5
|
-
import { getAgentWithDefaultSubAgent, getSubAgentById } from "@inkeep/agents-core";
|
|
6
4
|
|
|
7
5
|
//#region src/data/agents.ts
|
|
8
6
|
const logger = getLogger("agents");
|
|
@@ -67,26 +65,30 @@ function generateDescriptionWithRelationData(baseDescription, internalRelations,
|
|
|
67
65
|
* Create a RegisteredAgent from database agent data
|
|
68
66
|
* Hydrates agent directly from database schema using types from schema.ts
|
|
69
67
|
*/
|
|
70
|
-
async function hydrateAgent({ dbAgent,
|
|
68
|
+
async function hydrateAgent({ dbAgent, executionContext, baseUrl, apiKey, credentialStoreRegistry, sandboxConfig }) {
|
|
71
69
|
try {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
projectId: dbAgent.projectId,
|
|
75
|
-
agentId,
|
|
70
|
+
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
71
|
+
executionContext,
|
|
76
72
|
subAgentId: dbAgent.id,
|
|
77
73
|
baseUrl,
|
|
78
74
|
apiKey,
|
|
79
|
-
sandboxConfig
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
sandboxConfig
|
|
76
|
+
});
|
|
77
|
+
const { tenantId, projectId, agentId } = executionContext;
|
|
78
|
+
const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
|
|
82
79
|
const agentCard = createAgentCard({
|
|
83
|
-
dbAgent
|
|
80
|
+
dbAgent: {
|
|
81
|
+
...dbAgent,
|
|
82
|
+
tenantId,
|
|
83
|
+
projectId,
|
|
84
|
+
agentId
|
|
85
|
+
},
|
|
84
86
|
baseUrl
|
|
85
87
|
});
|
|
86
88
|
return {
|
|
87
89
|
subAgentId: dbAgent.id,
|
|
88
|
-
tenantId
|
|
89
|
-
projectId
|
|
90
|
+
tenantId,
|
|
91
|
+
projectId,
|
|
90
92
|
agentId,
|
|
91
93
|
agentCard,
|
|
92
94
|
taskHandler
|
|
@@ -98,40 +100,30 @@ async function hydrateAgent({ dbAgent, agentId, baseUrl, apiKey, credentialStore
|
|
|
98
100
|
}
|
|
99
101
|
async function getRegisteredAgent(params) {
|
|
100
102
|
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
101
|
-
const {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
},
|
|
103
|
+
const { agentId, subAgentId, baseUrl, apiKey, project } = executionContext;
|
|
104
|
+
const dbAgent = getSubAgentFromProject({
|
|
105
|
+
project,
|
|
106
|
+
agentId,
|
|
107
|
+
subAgentId
|
|
108
|
+
});
|
|
109
|
+
if (!dbAgent) {
|
|
110
|
+
logger.warn({
|
|
111
|
+
agentId,
|
|
120
112
|
subAgentId
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
dbAgent = response;
|
|
113
|
+
}, "Could not find sub-agent in project");
|
|
114
|
+
return null;
|
|
124
115
|
}
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
logger.info({
|
|
117
|
+
agentId,
|
|
118
|
+
subAgentId: dbAgent.id
|
|
119
|
+
}, "Found sub-agent from project definition");
|
|
127
120
|
return hydrateAgent({
|
|
128
121
|
dbAgent,
|
|
129
|
-
|
|
130
|
-
baseUrl:
|
|
122
|
+
executionContext,
|
|
123
|
+
baseUrl: `${baseUrl}/agents`,
|
|
131
124
|
credentialStoreRegistry,
|
|
132
125
|
apiKey,
|
|
133
|
-
sandboxConfig
|
|
134
|
-
userId
|
|
126
|
+
sandboxConfig
|
|
135
127
|
});
|
|
136
128
|
}
|
|
137
129
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentConversationHistoryConfig, Artifact, ConversationHistoryConfig, ConversationScopeOptions } from "@inkeep/agents-core";
|
|
1
|
+
import { AgentConversationHistoryConfig, Artifact, ConversationHistoryConfig, ConversationScopeOptions, ResolvedRef } from "@inkeep/agents-core";
|
|
2
2
|
|
|
3
3
|
//#region src/data/conversations.d.ts
|
|
4
4
|
declare const compressionLocks: Map<string, Promise<any>>;
|
|
@@ -123,6 +123,7 @@ declare function getConversationScopedArtifacts(params: {
|
|
|
123
123
|
projectId: string;
|
|
124
124
|
conversationId: string;
|
|
125
125
|
historyConfig: AgentConversationHistoryConfig;
|
|
126
|
+
ref: ResolvedRef;
|
|
126
127
|
}): Promise<Artifact[]>;
|
|
127
128
|
//#endregion
|
|
128
129
|
export { compressConversationIfNeeded, compressionLocks, createDefaultConversationHistoryConfig, getConversationHistoryWithCompression, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { getLogger } from "../logger.js";
|
|
1
|
+
import { getLogger as getLogger$1 } from "../logger.js";
|
|
2
2
|
import dbClient_default from "./db/dbClient.js";
|
|
3
3
|
import { CONVERSATION_ARTIFACTS_LIMIT, CONVERSATION_HISTORY_DEFAULT_LIMIT as CONVERSATION_HISTORY_DEFAULT_LIMIT$1 } from "../constants/execution-limits/index.js";
|
|
4
4
|
import { getCompressionConfigForModel } from "../utils/model-context-utils.js";
|
|
5
5
|
import { ConversationCompressor } from "../services/ConversationCompressor.js";
|
|
6
|
-
import { CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, createMessage, generateId, getConversationHistory } from "@inkeep/agents-core";
|
|
6
|
+
import { CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, createMessage, generateId, getConversationHistory, getLedgerArtifacts } from "@inkeep/agents-core";
|
|
7
7
|
|
|
8
8
|
//#region src/data/conversations.ts
|
|
9
|
-
const logger = getLogger("conversations");
|
|
9
|
+
const logger = getLogger$1("conversations");
|
|
10
10
|
const compressionLocks = /* @__PURE__ */ new Map();
|
|
11
11
|
/**
|
|
12
12
|
* Creates default conversation history configuration
|
|
@@ -24,9 +24,10 @@ function createDefaultConversationHistoryConfig(mode = "full") {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Extracts text content from A2A Message parts array
|
|
27
|
+
* Escapes control characters to ensure proper JSON serialization for Dolt
|
|
27
28
|
*/
|
|
28
29
|
function extractA2AMessageText(parts) {
|
|
29
|
-
return parts.filter((part) => part.kind === "text" && part.text).map((part) => part.text).join("");
|
|
30
|
+
return parts.filter((part) => part.kind === "text" && part.text).map((part) => part.text).join("").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\f/g, "\\f").replace(/\b/g, "\\b");
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Saves the result of an A2A client sendMessage call as a conversation message
|
|
@@ -470,7 +471,7 @@ function formatMessagesAsConversationHistory(messages) {
|
|
|
470
471
|
* Uses the same scoping logic as getFormattedConversationHistory
|
|
471
472
|
*/
|
|
472
473
|
async function getConversationScopedArtifacts(params) {
|
|
473
|
-
const { tenantId, projectId, conversationId, historyConfig } = params;
|
|
474
|
+
const { tenantId, projectId, conversationId, historyConfig, ref } = params;
|
|
474
475
|
if (!conversationId) return [];
|
|
475
476
|
try {
|
|
476
477
|
if (historyConfig.mode === "none") return [];
|
|
@@ -482,12 +483,10 @@ async function getConversationScopedArtifacts(params) {
|
|
|
482
483
|
});
|
|
483
484
|
if (visibleMessages.length === 0) return [];
|
|
484
485
|
if (visibleMessages.filter((msg) => !(msg.messageType === "system" && msg.content?.text?.includes("Previous conversation history truncated"))).map((msg) => msg.id).length === 0) return [];
|
|
485
|
-
const { getLedgerArtifacts: getLedgerArtifacts$1 } = await import("@inkeep/agents-core");
|
|
486
|
-
const dbClient = (await import("./db/dbClient.js")).default;
|
|
487
486
|
const visibleTaskIds = visibleMessages.map((msg) => msg.taskId).filter((taskId) => Boolean(taskId));
|
|
488
487
|
const referenceArtifacts = [];
|
|
489
488
|
for (const taskId of visibleTaskIds) {
|
|
490
|
-
const artifacts = await getLedgerArtifacts
|
|
489
|
+
const artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
491
490
|
scopes: {
|
|
492
491
|
tenantId,
|
|
493
492
|
projectId
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _inkeep_agents_core2 from "@inkeep/agents-core";
|
|
2
2
|
|
|
3
3
|
//#region src/data/db/dbClient.d.ts
|
|
4
|
-
declare
|
|
4
|
+
declare const dbClient: _inkeep_agents_core2.AgentsRunDatabaseClient;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { dbClient as default };
|
package/dist/data/db/dbClient.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { env } from "../../env.js";
|
|
2
|
-
import {
|
|
3
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
4
|
-
import * as schema from "@inkeep/agents-core/db/schema";
|
|
5
|
-
import { drizzle } from "drizzle-orm/pglite";
|
|
2
|
+
import { createAgentsRunDatabaseClient } from "@inkeep/agents-core";
|
|
6
3
|
|
|
7
4
|
//#region src/data/db/dbClient.ts
|
|
8
|
-
|
|
9
|
-
if (env.ENVIRONMENT === "test") dbClient = drizzle({
|
|
10
|
-
client: new PGlite(),
|
|
11
|
-
schema
|
|
12
|
-
});
|
|
13
|
-
else dbClient = createDatabaseClient({ connectionString: env.DATABASE_URL });
|
|
5
|
+
const dbClient = createAgentsRunDatabaseClient({ connectionString: env.INKEEP_AGENTS_RUN_DATABASE_URL });
|
|
14
6
|
var dbClient_default = dbClient;
|
|
15
7
|
|
|
16
8
|
//#endregion
|