@inkeep/agents-core 0.41.2 → 0.43.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/api-client/base-client.d.ts +87 -8
- package/dist/api-client/base-client.js +174 -1
- package/dist/api-client/eval-api-client.d.ts +47 -0
- package/dist/api-client/eval-api-client.js +65 -0
- package/dist/api-client/index.d.ts +4 -0
- package/dist/api-client/index.js +5 -0
- package/dist/api-client/manage-api-client.d.ts +34 -0
- package/dist/api-client/manage-api-client.js +104 -0
- package/dist/auth/auth.d.ts +86 -20
- package/dist/auth/auth.js +60 -2
- package/dist/auth/authz/client.d.ts +87 -0
- package/dist/auth/authz/client.js +196 -0
- package/dist/auth/authz/config.d.ts +103 -0
- package/dist/auth/authz/config.js +93 -0
- package/dist/auth/authz/index.d.ts +5 -0
- package/dist/auth/authz/index.js +6 -0
- package/dist/auth/authz/permissions.d.ts +53 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +106 -0
- package/dist/auth/authz/sync.js +321 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +9 -3
- package/dist/client-exports.js +4 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/execution-limits-shared/defaults.d.ts +1 -1
- package/dist/constants/execution-limits-shared/defaults.js +1 -1
- package/dist/constants/execution-limits-shared/index.d.ts +1 -1
- package/dist/constants/otel-attributes.d.ts +4 -0
- package/dist/constants/otel-attributes.js +4 -0
- package/dist/context/ContextConfig.d.ts +2 -2
- package/dist/context/ContextConfig.js +3 -3
- package/dist/context/TemplateEngine.d.ts +0 -6
- package/dist/context/TemplateEngine.js +4 -19
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stores/keychain-store.d.ts +20 -8
- package/dist/credential-stores/keychain-store.js +107 -43
- package/dist/credential-stuffer/CredentialStuffer.d.ts +1 -1
- package/dist/data-access/index.d.ts +34 -26
- package/dist/data-access/index.js +34 -26
- package/dist/data-access/manage/agentFull.d.ts +36 -0
- package/dist/data-access/{agentFull.js → manage/agentFull.js} +209 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +64 -63
- package/dist/data-access/{agents.js → manage/agents.js} +80 -27
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +33 -33
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +26 -26
- package/dist/data-access/{contextConfigs.js → manage/contextConfigs.js} +3 -3
- package/dist/data-access/{credentialReferences.d.ts → manage/credentialReferences.d.ts} +17 -17
- package/dist/data-access/{credentialReferences.js → manage/credentialReferences.js} +2 -2
- package/dist/data-access/{dataComponents.d.ts → manage/dataComponents.d.ts} +26 -26
- package/dist/data-access/{dataComponents.js → manage/dataComponents.js} +7 -7
- package/dist/data-access/manage/evalConfig.d.ts +221 -0
- package/dist/data-access/manage/evalConfig.js +275 -0
- package/dist/data-access/{externalAgents.d.ts → manage/externalAgents.d.ts} +16 -16
- package/dist/data-access/{externalAgents.js → manage/externalAgents.js} +2 -2
- package/dist/data-access/manage/functionTools.d.ts +242 -0
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +124 -30
- package/dist/data-access/{functions.d.ts → manage/functions.d.ts} +9 -9
- package/dist/data-access/{functions.js → manage/functions.js} +3 -3
- package/dist/data-access/manage/projectFull.d.ts +38 -0
- package/dist/data-access/{projectFull.js → manage/projectFull.js} +64 -65
- package/dist/data-access/manage/projectLifecycle.d.ts +119 -0
- package/dist/data-access/manage/projectLifecycle.js +234 -0
- package/dist/data-access/manage/projects.d.ts +75 -0
- package/dist/data-access/{projects.js → manage/projects.js} +15 -16
- package/dist/data-access/{subAgentExternalAgentRelations.d.ts → manage/subAgentExternalAgentRelations.d.ts} +43 -43
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +65 -65
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +43 -43
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +28 -28
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +65 -52
- package/dist/data-access/{tools.js → manage/tools.js} +109 -64
- package/dist/data-access/manage/triggers.d.ts +106 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +37 -37
- package/dist/data-access/{apiKeys.js → runtime/apiKeys.js} +3 -3
- package/dist/data-access/runtime/cascade-delete.d.ts +77 -0
- package/dist/data-access/runtime/cascade-delete.js +111 -0
- package/dist/data-access/{contextCache.d.ts → runtime/contextCache.d.ts} +13 -13
- package/dist/data-access/{contextCache.js → runtime/contextCache.js} +5 -5
- package/dist/data-access/{conversations.d.ts → runtime/conversations.d.ts} +80 -31
- package/dist/data-access/{conversations.js → runtime/conversations.js} +13 -7
- package/dist/data-access/runtime/evalRuns.d.ts +120 -0
- package/dist/data-access/runtime/evalRuns.js +168 -0
- package/dist/data-access/{ledgerArtifacts.d.ts → runtime/ledgerArtifacts.d.ts} +13 -13
- package/dist/data-access/{ledgerArtifacts.js → runtime/ledgerArtifacts.js} +3 -3
- package/dist/data-access/{messages.d.ts → runtime/messages.d.ts} +24 -24
- package/dist/data-access/{messages.js → runtime/messages.js} +2 -2
- package/dist/data-access/{organizations.d.ts → runtime/organizations.d.ts} +16 -7
- package/dist/data-access/{organizations.js → runtime/organizations.js} +16 -4
- package/dist/data-access/runtime/projects.d.ts +62 -0
- package/dist/data-access/runtime/projects.js +90 -0
- package/dist/data-access/runtime/tasks.d.ts +55 -0
- package/dist/data-access/{tasks.js → runtime/tasks.js} +2 -2
- package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
- package/dist/data-access/runtime/triggerInvocations.js +54 -0
- package/dist/data-access/runtime/users.d.ts +19 -0
- package/dist/data-access/{users.js → runtime/users.js} +2 -2
- package/dist/data-access/validation.d.ts +4 -4
- package/dist/data-access/validation.js +1 -1
- package/dist/db/clean.d.ts +8 -4
- package/dist/db/clean.js +14 -105
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +7 -10
- package/dist/db/manage/dolt-cleanup.d.ts +51 -0
- package/dist/db/manage/dolt-cleanup.js +132 -0
- package/dist/db/manage/manage-client.d.ts +26 -0
- package/dist/db/manage/manage-client.js +68 -0
- package/dist/db/{schema.d.ts → manage/manage-schema.d.ts} +1257 -969
- package/dist/db/{schema.js → manage/manage-schema.js} +436 -334
- package/dist/db/manage/test-manage-client.d.ts +27 -0
- package/dist/db/manage/test-manage-client.js +68 -0
- package/dist/db/runtime/runtime-client.d.ts +20 -0
- package/dist/db/runtime/runtime-client.js +30 -0
- package/dist/db/runtime/runtime-schema.d.ts +2834 -0
- package/dist/db/runtime/runtime-schema.js +483 -0
- package/dist/db/runtime/test-runtime-client.d.ts +27 -0
- package/dist/db/{test-client.js → runtime/test-runtime-client.js} +11 -25
- package/dist/db/utils.d.ts +6 -0
- package/dist/db/utils.js +42 -0
- package/dist/dolt/branch.d.ts +62 -0
- package/dist/dolt/branch.js +82 -0
- package/dist/dolt/branches-api.d.ts +108 -0
- package/dist/dolt/branches-api.js +162 -0
- package/dist/dolt/commit.d.ts +94 -0
- package/dist/dolt/commit.js +103 -0
- package/dist/dolt/diff.d.ts +27 -0
- package/dist/dolt/diff.js +21 -0
- package/dist/dolt/index.d.ts +10 -0
- package/dist/dolt/index.js +11 -0
- package/dist/dolt/merge.d.ts +63 -0
- package/dist/dolt/merge.js +81 -0
- package/dist/dolt/migrate-all-branches.d.ts +4 -0
- package/dist/dolt/migrate-all-branches.js +83 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +25 -0
- package/dist/dolt/ref-helpers.d.ts +19 -0
- package/dist/dolt/ref-helpers.js +65 -0
- package/dist/dolt/ref-middleware.d.ts +82 -0
- package/dist/dolt/ref-middleware.js +217 -0
- package/dist/dolt/ref-scope.d.ts +101 -0
- package/dist/dolt/ref-scope.js +231 -0
- package/dist/dolt/schema-sync.d.ts +135 -0
- package/dist/dolt/schema-sync.js +255 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +73 -46
- package/dist/index.js +76 -49
- package/dist/types/@napi-rs__keyring/index.d.ts +14 -0
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +46 -5
- package/dist/types/utility.js +2 -1
- package/dist/utils/JsonTransformer.d.ts +42 -0
- package/dist/utils/JsonTransformer.js +103 -0
- package/dist/utils/apiKeys.d.ts +5 -1
- package/dist/utils/apiKeys.js +11 -1
- package/dist/utils/colors.d.ts +34 -0
- package/dist/utils/colors.js +49 -0
- package/dist/utils/credential-store-utils.d.ts +1 -1
- package/dist/utils/format-messages.d.ts +1 -1
- package/dist/utils/index.d.ts +8 -4
- package/dist/utils/index.js +8 -4
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jmespath-utils.d.ts +152 -0
- package/dist/utils/jmespath-utils.js +213 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/mcp-client.d.ts +1 -1
- package/dist/utils/mcp-client.js +1 -1
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/signature-validation.d.ts +2 -0
- package/dist/utils/signature-validation.js +3 -0
- package/dist/utils/template-interpolation.d.ts +22 -0
- package/dist/utils/template-interpolation.js +62 -0
- package/dist/utils/third-party-mcp-servers/composio-client.d.ts +13 -1
- package/dist/utils/third-party-mcp-servers/composio-client.js +47 -29
- package/dist/utils/third-party-mcp-servers/index.d.ts +2 -2
- package/dist/utils/third-party-mcp-servers/index.js +2 -2
- package/dist/utils/trigger-auth.d.ts +85 -0
- package/dist/utils/trigger-auth.js +233 -0
- package/dist/validation/agentFull.js +2 -4
- package/dist/validation/dolt-schemas.d.ts +49 -0
- package/dist/validation/dolt-schemas.js +44 -0
- package/dist/validation/drizzle-schema-helpers.d.ts +4 -26
- package/dist/validation/drizzle-schema-helpers.js +5 -151
- package/dist/validation/index.d.ts +5 -4
- package/dist/validation/index.js +4 -3
- package/dist/validation/render-validation.js +19 -0
- package/dist/validation/schemas.d.ts +18223 -5148
- package/dist/validation/schemas.js +559 -12
- package/dist/validation/stream-event-schemas.d.ts +96 -1
- package/dist/validation/stream-event-schemas.js +67 -2
- package/drizzle/manage/0000_tearful_rhodey.sql +414 -0
- package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
- package/drizzle/manage/0002_bent_sunfire.sql +1 -0
- package/drizzle/manage/0003_tiny_captain_universe.sql +8 -0
- package/drizzle/manage/0004_curious_phil_sheldon.sql +2 -0
- package/drizzle/manage/0005_silent_shatterstar.sql +53 -0
- package/drizzle/manage/meta/0000_snapshot.json +2987 -0
- package/drizzle/manage/meta/0001_snapshot.json +3115 -0
- package/drizzle/manage/meta/0002_snapshot.json +3115 -0
- package/drizzle/manage/meta/0003_snapshot.json +3134 -0
- package/drizzle/manage/meta/0004_snapshot.json +3141 -0
- package/drizzle/manage/meta/0005_snapshot.json +3141 -0
- package/drizzle/manage/meta/_journal.json +48 -0
- package/drizzle/runtime/0008_silly_preak.sql +127 -0
- package/drizzle/runtime/0009_freezing_leo.sql +17 -0
- package/drizzle/runtime/meta/0008_snapshot.json +2263 -0
- package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
- package/drizzle/{meta → runtime/meta}/_journal.json +14 -0
- package/package.json +56 -18
- package/spicedb/schema.zed +114 -0
- package/dist/context/ContextFetcher.d.ts +0 -73
- package/dist/context/ContextFetcher.js +0 -291
- package/dist/context/ContextResolver.d.ts +0 -60
- package/dist/context/ContextResolver.js +0 -278
- package/dist/context/context.d.ts +0 -27
- package/dist/context/context.js +0 -128
- package/dist/context/contextCache.d.ts +0 -58
- package/dist/context/contextCache.js +0 -177
- package/dist/data-access/agentFull.d.ts +0 -33
- package/dist/data-access/functionTools.d.ts +0 -169
- package/dist/data-access/projectFull.d.ts +0 -32
- package/dist/data-access/projects.d.ts +0 -71
- package/dist/data-access/tasks.d.ts +0 -45
- package/dist/data-access/users.d.ts +0 -19
- package/dist/db/client.d.ts +0 -20
- package/dist/db/client.js +0 -28
- package/dist/db/test-client.d.ts +0 -31
- package/dist/middleware/contextValidation.d.ts +0 -46
- package/dist/middleware/contextValidation.js +0 -280
- package/dist/middleware/index.d.ts +0 -2
- package/dist/middleware/index.js +0 -3
- package/dist/utils/execution.d.ts +0 -22
- package/dist/utils/execution.js +0 -25
- /package/drizzle/{0000_exotic_mysterio.sql → runtime/0000_exotic_mysterio.sql} +0 -0
- /package/drizzle/{0001_calm_sheva_callister.sql → runtime/0001_calm_sheva_callister.sql} +0 -0
- /package/drizzle/{0002_puzzling_goblin_queen.sql → runtime/0002_puzzling_goblin_queen.sql} +0 -0
- /package/drizzle/{0003_sweet_human_robot.sql → runtime/0003_sweet_human_robot.sql} +0 -0
- /package/drizzle/{0004_cuddly_shooting_star.sql → runtime/0004_cuddly_shooting_star.sql} +0 -0
- /package/drizzle/{0005_reflective_starfox.sql → runtime/0005_reflective_starfox.sql} +0 -0
- /package/drizzle/{0006_stale_thaddeus_ross.sql → runtime/0006_stale_thaddeus_ross.sql} +0 -0
- /package/drizzle/{0007_slim_karma.sql → runtime/0007_slim_karma.sql} +0 -0
- /package/drizzle/{meta → runtime/meta}/0000_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0001_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0003_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0005_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0006_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0007_snapshot.json +0 -0
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../utils/logger.js";
|
|
2
|
-
import { getContextConfigById } from "../data-access/contextConfigs.js";
|
|
3
|
-
import { createApiError } from "../utils/error.js";
|
|
4
|
-
import { getRequestExecutionContext } from "../utils/execution.js";
|
|
5
|
-
import { getAgentWithDefaultSubAgent } from "../data-access/agents.js";
|
|
6
|
-
import { ContextResolver } from "../context/ContextResolver.js";
|
|
7
|
-
import Ajv from "ajv";
|
|
8
|
-
|
|
9
|
-
//#region src/middleware/contextValidation.ts
|
|
10
|
-
const logger = getLogger("context-validation");
|
|
11
|
-
const ajv = new Ajv({
|
|
12
|
-
allErrors: true,
|
|
13
|
-
strict: false
|
|
14
|
-
});
|
|
15
|
-
const HTTP_REQUEST_PARTS = ["headers"];
|
|
16
|
-
const MAX_SCHEMA_CACHE_SIZE = 1e3;
|
|
17
|
-
const schemaCache = /* @__PURE__ */ new Map();
|
|
18
|
-
function isValidHttpRequest(obj) {
|
|
19
|
-
return obj != null && typeof obj === "object" && !Array.isArray(obj) && "headers" in obj;
|
|
20
|
-
}
|
|
21
|
-
function getCachedValidator(schema) {
|
|
22
|
-
const key = JSON.stringify(schema);
|
|
23
|
-
if (schemaCache.has(key)) {
|
|
24
|
-
const validator$1 = schemaCache.get(key);
|
|
25
|
-
if (!validator$1) throw new Error("Unexpected: validator not found in cache after has() check");
|
|
26
|
-
schemaCache.delete(key);
|
|
27
|
-
schemaCache.set(key, validator$1);
|
|
28
|
-
return validator$1;
|
|
29
|
-
}
|
|
30
|
-
if (schemaCache.size >= MAX_SCHEMA_CACHE_SIZE) {
|
|
31
|
-
const firstKey = schemaCache.keys().next().value;
|
|
32
|
-
if (firstKey) schemaCache.delete(firstKey);
|
|
33
|
-
}
|
|
34
|
-
const permissiveSchema = makeSchemaPermissive(schema);
|
|
35
|
-
const validator = ajv.compile(permissiveSchema);
|
|
36
|
-
schemaCache.set(key, validator);
|
|
37
|
-
return validator;
|
|
38
|
-
}
|
|
39
|
-
function makeSchemaPermissive(schema) {
|
|
40
|
-
if (!schema || typeof schema !== "object") return schema;
|
|
41
|
-
const permissiveSchema = { ...schema };
|
|
42
|
-
if (permissiveSchema.type === "object") {
|
|
43
|
-
permissiveSchema.additionalProperties = true;
|
|
44
|
-
if (permissiveSchema.properties && typeof permissiveSchema.properties === "object") {
|
|
45
|
-
const newProperties = {};
|
|
46
|
-
for (const [key, value] of Object.entries(permissiveSchema.properties)) newProperties[key] = makeSchemaPermissive(value);
|
|
47
|
-
permissiveSchema.properties = newProperties;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (permissiveSchema.type === "array" && permissiveSchema.items) permissiveSchema.items = makeSchemaPermissive(permissiveSchema.items);
|
|
51
|
-
if (permissiveSchema.oneOf) permissiveSchema.oneOf = permissiveSchema.oneOf.map(makeSchemaPermissive);
|
|
52
|
-
if (permissiveSchema.anyOf) permissiveSchema.anyOf = permissiveSchema.anyOf.map(makeSchemaPermissive);
|
|
53
|
-
if (permissiveSchema.allOf) permissiveSchema.allOf = permissiveSchema.allOf.map(makeSchemaPermissive);
|
|
54
|
-
return permissiveSchema;
|
|
55
|
-
}
|
|
56
|
-
function validationHelper(jsonSchema) {
|
|
57
|
-
return getCachedValidator(jsonSchema);
|
|
58
|
-
}
|
|
59
|
-
function validateAgainstJsonSchema(jsonSchema, context) {
|
|
60
|
-
return validationHelper(jsonSchema)(context);
|
|
61
|
-
}
|
|
62
|
-
function filterByJsonSchema(data, schema) {
|
|
63
|
-
if (!schema || data === null || data === void 0) return data;
|
|
64
|
-
if (schema.type === "object" && schema.properties && typeof data === "object" && !Array.isArray(data)) {
|
|
65
|
-
const filtered = {};
|
|
66
|
-
for (const [key, propSchema] of Object.entries(schema.properties)) if (key in data) filtered[key] = filterByJsonSchema(data[key], propSchema);
|
|
67
|
-
return filtered;
|
|
68
|
-
}
|
|
69
|
-
if (schema.type === "array" && schema.items && Array.isArray(data)) return data.map((item) => filterByJsonSchema(item, schema.items));
|
|
70
|
-
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
71
|
-
for (const subSchema of schema.anyOf) if (subSchema.type && typeof data === subSchema.type) return filterByJsonSchema(data, subSchema);
|
|
72
|
-
return filterByJsonSchema(data, schema.anyOf[0]);
|
|
73
|
-
}
|
|
74
|
-
return data;
|
|
75
|
-
}
|
|
76
|
-
function filterContextToSchemaKeys(validatedContext, headersSchema) {
|
|
77
|
-
if (!headersSchema || !validatedContext) return validatedContext;
|
|
78
|
-
const filteredHeaders = filterByJsonSchema(validatedContext, headersSchema);
|
|
79
|
-
if (filteredHeaders !== null && filteredHeaders !== void 0) {
|
|
80
|
-
if (typeof filteredHeaders === "object" && Object.keys(filteredHeaders).length > 0) return filteredHeaders;
|
|
81
|
-
if (typeof filteredHeaders !== "object") return filteredHeaders;
|
|
82
|
-
}
|
|
83
|
-
return {};
|
|
84
|
-
}
|
|
85
|
-
async function validateHttpRequestHeaders(headersSchema, httpRequest) {
|
|
86
|
-
const errors = [];
|
|
87
|
-
let validatedContext = {};
|
|
88
|
-
if (!isValidHttpRequest(httpRequest)) return {
|
|
89
|
-
valid: false,
|
|
90
|
-
errors: [{
|
|
91
|
-
field: "httpRequest",
|
|
92
|
-
message: "Invalid HTTP request format - must contain headers"
|
|
93
|
-
}]
|
|
94
|
-
};
|
|
95
|
-
try {
|
|
96
|
-
if (headersSchema && httpRequest.headers !== void 0) try {
|
|
97
|
-
const validate = validationHelper(headersSchema);
|
|
98
|
-
if (validate(httpRequest.headers)) validatedContext = httpRequest.headers;
|
|
99
|
-
else if (validate.errors) for (const error of validate.errors) errors.push({
|
|
100
|
-
field: `headers.${error.instancePath || "root"}`,
|
|
101
|
-
message: `headers ${error.message}`,
|
|
102
|
-
value: error.data
|
|
103
|
-
});
|
|
104
|
-
} catch (validationError) {
|
|
105
|
-
errors.push({
|
|
106
|
-
field: "headers",
|
|
107
|
-
message: `Failed to validate headers: ${validationError instanceof Error ? validationError.message : "Unknown error"}`
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
const filteredContext = errors.length === 0 ? filterContextToSchemaKeys(validatedContext, headersSchema) : void 0;
|
|
111
|
-
return {
|
|
112
|
-
valid: errors.length === 0,
|
|
113
|
-
errors,
|
|
114
|
-
validatedContext: filteredContext
|
|
115
|
-
};
|
|
116
|
-
} catch (error) {
|
|
117
|
-
logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Failed to validate headers schema");
|
|
118
|
-
return {
|
|
119
|
-
valid: false,
|
|
120
|
-
errors: [{
|
|
121
|
-
field: "schema",
|
|
122
|
-
message: "Failed to validate headers schema"
|
|
123
|
-
}]
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async function fetchExistingHeaders({ tenantId, projectId, contextConfig, conversationId, dbClient, credentialStores }) {
|
|
128
|
-
const headers = await new ContextResolver(tenantId, projectId, dbClient, credentialStores).resolveHeaders(conversationId, contextConfig.id);
|
|
129
|
-
if (Object.keys(headers).length > 0) return {
|
|
130
|
-
valid: true,
|
|
131
|
-
errors: [],
|
|
132
|
-
validatedContext: headers
|
|
133
|
-
};
|
|
134
|
-
throw new Error("No headers found in cache. Please provide headers in request.");
|
|
135
|
-
}
|
|
136
|
-
async function validateHeaders({ tenantId, projectId, agentId, conversationId, parsedRequest, dbClient, credentialStores }) {
|
|
137
|
-
try {
|
|
138
|
-
const agent = await getAgentWithDefaultSubAgent(dbClient)({ scopes: {
|
|
139
|
-
tenantId,
|
|
140
|
-
projectId,
|
|
141
|
-
agentId
|
|
142
|
-
} });
|
|
143
|
-
if (!agent?.contextConfigId) {
|
|
144
|
-
logger.debug({ agentId }, "No context config found for agent, skipping validation");
|
|
145
|
-
return {
|
|
146
|
-
valid: true,
|
|
147
|
-
errors: [],
|
|
148
|
-
validatedContext: parsedRequest
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
const contextConfig = await getContextConfigById(dbClient)({
|
|
152
|
-
scopes: {
|
|
153
|
-
tenantId,
|
|
154
|
-
projectId,
|
|
155
|
-
agentId
|
|
156
|
-
},
|
|
157
|
-
id: agent.contextConfigId
|
|
158
|
-
});
|
|
159
|
-
if (!contextConfig) {
|
|
160
|
-
logger.warn({ contextConfigId: agent.contextConfigId }, "Context config not found");
|
|
161
|
-
return {
|
|
162
|
-
valid: false,
|
|
163
|
-
errors: [{
|
|
164
|
-
field: "contextConfig",
|
|
165
|
-
message: "Context configuration not found"
|
|
166
|
-
}]
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
if (!contextConfig.headersSchema) {
|
|
170
|
-
logger.debug({ contextConfigId: contextConfig.id }, "No headers schema defined, accepting any context");
|
|
171
|
-
return {
|
|
172
|
-
valid: true,
|
|
173
|
-
errors: [],
|
|
174
|
-
validatedContext: parsedRequest
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
const schema = contextConfig.headersSchema;
|
|
179
|
-
logger.debug({ contextConfigId: contextConfig.id }, "Using headers schema validation");
|
|
180
|
-
const validationResult = await validateHttpRequestHeaders(schema, parsedRequest);
|
|
181
|
-
if (validationResult.valid) return validationResult;
|
|
182
|
-
try {
|
|
183
|
-
return await fetchExistingHeaders({
|
|
184
|
-
tenantId,
|
|
185
|
-
projectId,
|
|
186
|
-
contextConfig,
|
|
187
|
-
conversationId,
|
|
188
|
-
dbClient,
|
|
189
|
-
credentialStores
|
|
190
|
-
});
|
|
191
|
-
} catch (_error) {
|
|
192
|
-
validationResult.errors.push({
|
|
193
|
-
field: "headers",
|
|
194
|
-
message: "Failed to fetch headers from cache"
|
|
195
|
-
});
|
|
196
|
-
return validationResult;
|
|
197
|
-
}
|
|
198
|
-
} catch (error) {
|
|
199
|
-
logger.error({
|
|
200
|
-
contextConfigId: contextConfig.id,
|
|
201
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
202
|
-
}, "Failed to compile or validate schema");
|
|
203
|
-
return {
|
|
204
|
-
valid: false,
|
|
205
|
-
errors: [{
|
|
206
|
-
field: "schema",
|
|
207
|
-
message: "Invalid schema definition or validation error"
|
|
208
|
-
}]
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
logger.error({
|
|
213
|
-
tenantId,
|
|
214
|
-
agentId,
|
|
215
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
216
|
-
}, "Failed to validate headers");
|
|
217
|
-
return {
|
|
218
|
-
valid: false,
|
|
219
|
-
errors: [{
|
|
220
|
-
field: "validation",
|
|
221
|
-
message: "Context validation failed due to internal error"
|
|
222
|
-
}]
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function contextValidationMiddleware(dbClient) {
|
|
227
|
-
return async (c, next) => {
|
|
228
|
-
try {
|
|
229
|
-
let { tenantId, projectId, agentId } = getRequestExecutionContext(c);
|
|
230
|
-
if (!tenantId || !projectId || !agentId) {
|
|
231
|
-
tenantId = c.req.param("tenantId");
|
|
232
|
-
projectId = c.req.param("projectId");
|
|
233
|
-
agentId = c.req.param("agentId");
|
|
234
|
-
}
|
|
235
|
-
if (!tenantId || !projectId || !agentId) return next();
|
|
236
|
-
const conversationId = (c.get("requestBody") || {}).conversationId || "";
|
|
237
|
-
const headers = {};
|
|
238
|
-
c.req.raw.headers.forEach((value, key) => {
|
|
239
|
-
headers[key.toLowerCase()] = value;
|
|
240
|
-
});
|
|
241
|
-
const credentialStores = c.get("credentialStores");
|
|
242
|
-
const validationResult = await validateHeaders({
|
|
243
|
-
tenantId,
|
|
244
|
-
projectId,
|
|
245
|
-
agentId,
|
|
246
|
-
conversationId,
|
|
247
|
-
parsedRequest: { headers },
|
|
248
|
-
dbClient,
|
|
249
|
-
credentialStores
|
|
250
|
-
});
|
|
251
|
-
if (!validationResult.valid) {
|
|
252
|
-
logger.warn({
|
|
253
|
-
tenantId,
|
|
254
|
-
agentId,
|
|
255
|
-
errors: validationResult.errors
|
|
256
|
-
}, "Headers validation failed");
|
|
257
|
-
throw createApiError({
|
|
258
|
-
code: "bad_request",
|
|
259
|
-
message: `Invalid headers: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
c.set("validatedContext", validationResult.validatedContext);
|
|
263
|
-
logger.debug({
|
|
264
|
-
tenantId,
|
|
265
|
-
agentId,
|
|
266
|
-
contextKeys: Object.keys(validationResult.validatedContext || {})
|
|
267
|
-
}, "Request context validation successful");
|
|
268
|
-
return next();
|
|
269
|
-
} catch (error) {
|
|
270
|
-
logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Context validation middleware error");
|
|
271
|
-
throw createApiError({
|
|
272
|
-
code: "internal_server_error",
|
|
273
|
-
message: "Context validation failed"
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
//#endregion
|
|
280
|
-
export { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { ContextValidationError, ContextValidationResult, HTTP_REQUEST_PARTS, HttpRequestPart, ParsedHttpRequest, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper } from "./contextValidation.js";
|
|
2
|
-
export { ContextValidationError, ContextValidationResult, HTTP_REQUEST_PARTS, HttpRequestPart, ParsedHttpRequest, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
|
package/dist/middleware/index.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper } from "./contextValidation.js";
|
|
2
|
-
|
|
3
|
-
export { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ExecutionContext } from "../types/utility.js";
|
|
2
|
-
import { Context } from "hono";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/execution.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create execution context from middleware values
|
|
8
|
-
*/
|
|
9
|
-
declare function createExecutionContext(params: {
|
|
10
|
-
apiKey: string;
|
|
11
|
-
tenantId: string;
|
|
12
|
-
projectId: string;
|
|
13
|
-
agentId: string;
|
|
14
|
-
apiKeyId: string;
|
|
15
|
-
baseUrl?: string;
|
|
16
|
-
}): ExecutionContext;
|
|
17
|
-
/**
|
|
18
|
-
* Get execution context from API key authentication
|
|
19
|
-
*/
|
|
20
|
-
declare function getRequestExecutionContext(c: Context): ExecutionContext;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { createExecutionContext, getRequestExecutionContext };
|
package/dist/utils/execution.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
//#region src/utils/execution.ts
|
|
2
|
-
/**
|
|
3
|
-
* Create execution context from middleware values
|
|
4
|
-
*/
|
|
5
|
-
function createExecutionContext(params) {
|
|
6
|
-
return {
|
|
7
|
-
apiKey: params.apiKey,
|
|
8
|
-
tenantId: params.tenantId,
|
|
9
|
-
projectId: params.projectId,
|
|
10
|
-
agentId: params.agentId,
|
|
11
|
-
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
12
|
-
apiKeyId: params.apiKeyId
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Get execution context from API key authentication
|
|
17
|
-
*/
|
|
18
|
-
function getRequestExecutionContext(c) {
|
|
19
|
-
const executionContext = c.get("executionContext");
|
|
20
|
-
if (!executionContext) throw new Error("No execution context available. API key authentication is required.");
|
|
21
|
-
return executionContext;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { createExecutionContext, getRequestExecutionContext };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|