@inkeep/agents-core 0.0.0-dev-20251009005405 → 0.0.0-dev-20251009020740
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/{chunk-MLKHAZVU.js → chunk-L53XWAYG.js} +1 -1
- package/dist/{chunk-HZZTBK7Y.js → chunk-TO2HNKGP.js} +4 -4
- package/dist/{chunk-TN5JDW2L.js → chunk-VPJ6Z5QZ.js} +1 -2
- package/dist/client-exports.cjs +4 -5
- package/dist/client-exports.d.cts +2 -2
- package/dist/client-exports.d.ts +2 -2
- package/dist/client-exports.js +2 -2
- package/dist/db/schema.cjs +1 -2
- package/dist/db/schema.d.cts +2 -2
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.js +1 -1
- package/dist/index.cjs +113 -148
- package/dist/index.d.cts +39 -67
- package/dist/index.d.ts +39 -67
- package/dist/index.js +114 -146
- package/dist/{schema-DfH0zjbm.d.ts → schema-BQk_FMBV.d.ts} +3 -41
- package/dist/{schema-DKTW_XSC.d.cts → schema-Ct2NlO81.d.cts} +3 -41
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/{utility-BHDxGp6I.d.cts → utility-s9c5CVOe.d.cts} +16 -34
- package/dist/{utility-BHDxGp6I.d.ts → utility-s9c5CVOe.d.ts} +16 -34
- package/dist/validation/index.cjs +4 -5
- package/dist/validation/index.d.cts +2 -2
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +2 -2
- package/drizzle/0003_soft_forgotten_one.sql +39 -0
- package/drizzle/0004_melted_omega_flight.sql +3 -0
- package/drizzle/meta/0000_snapshot.json +2425 -0
- package/drizzle/meta/0001_snapshot.json +2435 -0
- package/drizzle/meta/0003_snapshot.json +2 -2
- package/drizzle/meta/0004_snapshot.json +2547 -0
- package/drizzle/meta/_journal.json +11 -4
- package/package.json +1 -1
- package/drizzle/0002_brown_marvel_apes.sql +0 -16
- package/drizzle/0003_gifted_doctor_spectrum.sql +0 -343
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
|
+
var nanoid = require('nanoid');
|
|
4
5
|
var pino = require('pino');
|
|
5
6
|
var pinoPretty = require('pino-pretty');
|
|
6
7
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
@@ -10,7 +11,6 @@ var sqliteCore = require('drizzle-orm/sqlite-core');
|
|
|
10
11
|
var jmespath = require('jmespath');
|
|
11
12
|
var client = require('@libsql/client');
|
|
12
13
|
var libsql = require('drizzle-orm/libsql');
|
|
13
|
-
var nanoid = require('nanoid');
|
|
14
14
|
var crypto = require('crypto');
|
|
15
15
|
var util = require('util');
|
|
16
16
|
var httpException = require('hono/http-exception');
|
|
@@ -54,16 +54,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
54
54
|
|
|
55
55
|
// src/api-client/base-client.ts
|
|
56
56
|
async function apiFetch(url, options = {}) {
|
|
57
|
-
const
|
|
57
|
+
const headers2 = {
|
|
58
58
|
"Content-Type": "application/json",
|
|
59
59
|
Accept: "application/json",
|
|
60
60
|
...options.headers || {}
|
|
61
61
|
};
|
|
62
62
|
return fetch(url, {
|
|
63
63
|
...options,
|
|
64
|
-
headers
|
|
64
|
+
headers: headers2
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
var generateId = nanoid.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 21);
|
|
68
|
+
function getConversationId() {
|
|
69
|
+
return generateId();
|
|
70
|
+
}
|
|
67
71
|
var PinoLogger = class {
|
|
68
72
|
constructor(name, config = {}) {
|
|
69
73
|
this.name = name;
|
|
@@ -397,9 +401,8 @@ var contextConfigs = sqliteCore.sqliteTable(
|
|
|
397
401
|
"context_configs",
|
|
398
402
|
{
|
|
399
403
|
...graphScoped,
|
|
400
|
-
...uiProperties,
|
|
401
404
|
// Developer-defined Zod schema for validating incoming request context
|
|
402
|
-
|
|
405
|
+
headersSchema: sqliteCore.blob("headers_schema", { mode: "json" }).$type(),
|
|
403
406
|
// Stores serialized Zod schema
|
|
404
407
|
// Object mapping template keys to fetch definitions that use request context data
|
|
405
408
|
contextVariables: sqliteCore.blob("context_variables", { mode: "json" }).$type(),
|
|
@@ -1615,11 +1618,11 @@ var FetchDefinitionSchema = zodOpenapi.z.object({
|
|
|
1615
1618
|
credential: CredentialReferenceApiInsertSchema.optional()
|
|
1616
1619
|
});
|
|
1617
1620
|
var ContextConfigSelectSchema = drizzleZod.createSelectSchema(contextConfigs).extend({
|
|
1618
|
-
|
|
1621
|
+
headersSchema: zodOpenapi.z.unknown().optional()
|
|
1619
1622
|
});
|
|
1620
1623
|
var ContextConfigInsertSchema = drizzleZod.createInsertSchema(contextConfigs).extend({
|
|
1621
|
-
id: resourceIdSchema,
|
|
1622
|
-
|
|
1624
|
+
id: resourceIdSchema.optional(),
|
|
1625
|
+
headersSchema: zodOpenapi.z.unknown().optional()
|
|
1623
1626
|
}).omit({
|
|
1624
1627
|
createdAt: true,
|
|
1625
1628
|
updatedAt: true
|
|
@@ -1854,14 +1857,14 @@ var PaginationQueryParamsSchema = zodOpenapi.z.object({
|
|
|
1854
1857
|
|
|
1855
1858
|
// src/context/ContextConfig.ts
|
|
1856
1859
|
var logger2 = getLogger("context-config");
|
|
1857
|
-
var
|
|
1860
|
+
var HeadersSchemaBuilder = class {
|
|
1858
1861
|
constructor(options) {
|
|
1859
1862
|
__publicField(this, "schema");
|
|
1860
1863
|
this.schema = options.schema;
|
|
1861
1864
|
}
|
|
1862
|
-
/** Template function for
|
|
1865
|
+
/** Template function for headers paths with type-safe autocomplete */
|
|
1863
1866
|
toTemplate(path2) {
|
|
1864
|
-
return `{{
|
|
1867
|
+
return `{{headers.${path2}}}`;
|
|
1865
1868
|
}
|
|
1866
1869
|
getSchema() {
|
|
1867
1870
|
return this.schema;
|
|
@@ -1881,16 +1884,16 @@ var ContextConfigBuilder = class {
|
|
|
1881
1884
|
this.projectId = options.projectId || "default";
|
|
1882
1885
|
this.graphId = options.graphId || "default";
|
|
1883
1886
|
this.baseURL = process.env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002";
|
|
1884
|
-
let
|
|
1885
|
-
if (options.
|
|
1886
|
-
const actualSchema = options.
|
|
1887
|
+
let headers2;
|
|
1888
|
+
if (options.headers) {
|
|
1889
|
+
const actualSchema = options.headers instanceof HeadersSchemaBuilder ? options.headers.getSchema() : options.headers;
|
|
1887
1890
|
logger2.info(
|
|
1888
1891
|
{
|
|
1889
|
-
|
|
1892
|
+
headers: options.headers
|
|
1890
1893
|
},
|
|
1891
|
-
"Converting
|
|
1894
|
+
"Converting headers schema to JSON Schema for database storage"
|
|
1892
1895
|
);
|
|
1893
|
-
|
|
1896
|
+
headers2 = convertZodToJsonSchema(actualSchema);
|
|
1894
1897
|
}
|
|
1895
1898
|
const processedContextVariables = {};
|
|
1896
1899
|
if (options.contextVariables) {
|
|
@@ -1913,12 +1916,10 @@ var ContextConfigBuilder = class {
|
|
|
1913
1916
|
}
|
|
1914
1917
|
}
|
|
1915
1918
|
this.config = {
|
|
1916
|
-
id: options.id,
|
|
1919
|
+
id: options.id || generateId(),
|
|
1917
1920
|
tenantId: this.tenantId,
|
|
1918
1921
|
projectId: this.projectId,
|
|
1919
|
-
|
|
1920
|
-
description: options.description || "",
|
|
1921
|
-
requestContextSchema: requestContextSchema2,
|
|
1922
|
+
headersSchema: headers2,
|
|
1922
1923
|
contextVariables: processedContextVariables
|
|
1923
1924
|
};
|
|
1924
1925
|
logger2.info(
|
|
@@ -1960,9 +1961,7 @@ var ContextConfigBuilder = class {
|
|
|
1960
1961
|
tenantId: this.tenantId,
|
|
1961
1962
|
projectId: this.projectId,
|
|
1962
1963
|
graphId: this.graphId,
|
|
1963
|
-
|
|
1964
|
-
description: this.getDescription(),
|
|
1965
|
-
requestContextSchema: this.getRequestContextSchema(),
|
|
1964
|
+
headersSchema: this.getHeadersSchema(),
|
|
1966
1965
|
contextVariables: this.getContextVariables(),
|
|
1967
1966
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1968
1967
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -1975,24 +1974,15 @@ var ContextConfigBuilder = class {
|
|
|
1975
1974
|
}
|
|
1976
1975
|
return this.config.id;
|
|
1977
1976
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
throw new Error("Context config name is not set");
|
|
1981
|
-
}
|
|
1982
|
-
return this.config.name;
|
|
1983
|
-
}
|
|
1984
|
-
getDescription() {
|
|
1985
|
-
return this.config.description || "";
|
|
1986
|
-
}
|
|
1987
|
-
getRequestContextSchema() {
|
|
1988
|
-
return this.config.requestContextSchema || null;
|
|
1977
|
+
getHeadersSchema() {
|
|
1978
|
+
return this.config.headersSchema || null;
|
|
1989
1979
|
}
|
|
1990
1980
|
getContextVariables() {
|
|
1991
1981
|
return this.config.contextVariables || {};
|
|
1992
1982
|
}
|
|
1993
1983
|
// Builder methods for fluent API
|
|
1994
|
-
|
|
1995
|
-
this.config.
|
|
1984
|
+
withHeadersSchema(schema) {
|
|
1985
|
+
this.config.headersSchema = schema;
|
|
1996
1986
|
return this;
|
|
1997
1987
|
}
|
|
1998
1988
|
/** 4) The function you ship: path autocomplete + validation, returns {{path}} */
|
|
@@ -2003,19 +1993,17 @@ var ContextConfigBuilder = class {
|
|
|
2003
1993
|
validate() {
|
|
2004
1994
|
try {
|
|
2005
1995
|
const contextVariables = this.config.contextVariables || {};
|
|
2006
|
-
if ("
|
|
1996
|
+
if ("headers" in contextVariables) {
|
|
2007
1997
|
return {
|
|
2008
1998
|
valid: false,
|
|
2009
1999
|
errors: [
|
|
2010
|
-
"The key '
|
|
2000
|
+
"The key 'headers' is reserved for the headers context and cannot be used in contextVariables"
|
|
2011
2001
|
]
|
|
2012
2002
|
};
|
|
2013
2003
|
}
|
|
2014
2004
|
ContextConfigApiUpdateSchema.parse({
|
|
2015
2005
|
id: this.config.id,
|
|
2016
|
-
|
|
2017
|
-
description: this.config.description,
|
|
2018
|
-
requestContextSchema: this.config.requestContextSchema,
|
|
2006
|
+
headersSchema: this.config.headersSchema,
|
|
2019
2007
|
contextVariables: this.config.contextVariables
|
|
2020
2008
|
});
|
|
2021
2009
|
return { valid: true, errors: [] };
|
|
@@ -2058,9 +2046,7 @@ var ContextConfigBuilder = class {
|
|
|
2058
2046
|
async upsertContextConfig() {
|
|
2059
2047
|
const configData = {
|
|
2060
2048
|
id: this.getId(),
|
|
2061
|
-
|
|
2062
|
-
description: this.getDescription(),
|
|
2063
|
-
requestContextSchema: this.getRequestContextSchema(),
|
|
2049
|
+
headersSchema: this.getHeadersSchema(),
|
|
2064
2050
|
contextVariables: this.getContextVariables()
|
|
2065
2051
|
};
|
|
2066
2052
|
try {
|
|
@@ -2142,8 +2128,8 @@ var ContextConfigBuilder = class {
|
|
|
2142
2128
|
function contextConfig(options) {
|
|
2143
2129
|
return new ContextConfigBuilder(options);
|
|
2144
2130
|
}
|
|
2145
|
-
function
|
|
2146
|
-
return new
|
|
2131
|
+
function headers(options) {
|
|
2132
|
+
return new HeadersSchemaBuilder(options);
|
|
2147
2133
|
}
|
|
2148
2134
|
function fetchDefinition(options) {
|
|
2149
2135
|
const fetchConfig = options.fetchConfig;
|
|
@@ -2208,15 +2194,15 @@ var _TemplateEngine = class _TemplateEngine {
|
|
|
2208
2194
|
if (options.preserveUnresolved) {
|
|
2209
2195
|
return match2;
|
|
2210
2196
|
}
|
|
2211
|
-
if (trimmedPath.startsWith("
|
|
2197
|
+
if (trimmedPath.startsWith("headers.")) {
|
|
2212
2198
|
logger3.warn(
|
|
2213
2199
|
{
|
|
2214
2200
|
variable: trimmedPath,
|
|
2215
2201
|
availableKeys: Object.keys(context),
|
|
2216
2202
|
contextStructure: JSON.stringify(context, null, 2),
|
|
2217
|
-
|
|
2203
|
+
headersContent: context.headers ? JSON.stringify(context.headers, null, 2) : "undefined"
|
|
2218
2204
|
},
|
|
2219
|
-
"
|
|
2205
|
+
"Headers template variable debugging"
|
|
2220
2206
|
);
|
|
2221
2207
|
} else {
|
|
2222
2208
|
logger3.warn(
|
|
@@ -2432,12 +2418,12 @@ var CredentialStuffer = class {
|
|
|
2432
2418
|
metadata: nangoCredentialData.metadata
|
|
2433
2419
|
};
|
|
2434
2420
|
}
|
|
2435
|
-
const
|
|
2421
|
+
const headers2 = {};
|
|
2436
2422
|
if (nangoCredentialData.token) {
|
|
2437
|
-
|
|
2423
|
+
headers2.Authorization = `Bearer ${nangoCredentialData.token}`;
|
|
2438
2424
|
}
|
|
2439
2425
|
return {
|
|
2440
|
-
headers,
|
|
2426
|
+
headers: headers2,
|
|
2441
2427
|
metadata: nangoCredentialData.metadata
|
|
2442
2428
|
};
|
|
2443
2429
|
} catch (parseError) {
|
|
@@ -2482,23 +2468,23 @@ var CredentialStuffer = class {
|
|
|
2482
2468
|
}) || context.tenantId;
|
|
2483
2469
|
}
|
|
2484
2470
|
/**
|
|
2485
|
-
* Get credentials from
|
|
2471
|
+
* Get credentials from headers context
|
|
2486
2472
|
*/
|
|
2487
|
-
async
|
|
2473
|
+
async getCredentialsFromHeaders(credentialContext, headers2) {
|
|
2488
2474
|
const contextConfigId = credentialContext.contextConfigId;
|
|
2489
2475
|
const conversationId = credentialContext.conversationId;
|
|
2490
2476
|
if (!contextConfigId || !conversationId || !this.contextResolver) {
|
|
2491
2477
|
return null;
|
|
2492
2478
|
}
|
|
2493
|
-
const
|
|
2479
|
+
const context = await this.contextResolver.resolveHeaders(
|
|
2494
2480
|
conversationId,
|
|
2495
2481
|
contextConfigId
|
|
2496
2482
|
);
|
|
2497
2483
|
const resolvedHeaders = {};
|
|
2498
|
-
for (const [key, value] of Object.entries(
|
|
2484
|
+
for (const [key, value] of Object.entries(headers2)) {
|
|
2499
2485
|
resolvedHeaders[key] = TemplateEngine.render(
|
|
2500
2486
|
value,
|
|
2501
|
-
|
|
2487
|
+
context,
|
|
2502
2488
|
{ strict: true }
|
|
2503
2489
|
);
|
|
2504
2490
|
}
|
|
@@ -2514,23 +2500,23 @@ var CredentialStuffer = class {
|
|
|
2514
2500
|
context,
|
|
2515
2501
|
mcpType,
|
|
2516
2502
|
storeReference,
|
|
2517
|
-
headers
|
|
2503
|
+
headers: headers2
|
|
2518
2504
|
}) {
|
|
2519
|
-
let
|
|
2520
|
-
if (context.contextConfigId && context.conversationId &&
|
|
2521
|
-
|
|
2505
|
+
let credentialsFromHeaders = null;
|
|
2506
|
+
if (context.contextConfigId && context.conversationId && headers2) {
|
|
2507
|
+
credentialsFromHeaders = await this.getCredentialsFromHeaders(context, headers2);
|
|
2522
2508
|
}
|
|
2523
2509
|
let credentialStoreHeaders = null;
|
|
2524
2510
|
if (storeReference) {
|
|
2525
2511
|
credentialStoreHeaders = await this.getCredentials(context, storeReference, mcpType);
|
|
2526
2512
|
}
|
|
2527
2513
|
if (!credentialStoreHeaders) {
|
|
2528
|
-
return
|
|
2514
|
+
return credentialsFromHeaders ? credentialsFromHeaders.headers : {};
|
|
2529
2515
|
}
|
|
2530
2516
|
const combinedHeaders = {
|
|
2531
2517
|
...credentialStoreHeaders.headers,
|
|
2532
2518
|
...credentialStoreHeaders.metadata,
|
|
2533
|
-
...
|
|
2519
|
+
...credentialsFromHeaders?.headers
|
|
2534
2520
|
};
|
|
2535
2521
|
return combinedHeaders;
|
|
2536
2522
|
}
|
|
@@ -3295,9 +3281,7 @@ var createContextConfig = (db) => async (params) => {
|
|
|
3295
3281
|
tenantId: params.tenantId,
|
|
3296
3282
|
projectId: params.projectId,
|
|
3297
3283
|
graphId: params.graphId,
|
|
3298
|
-
|
|
3299
|
-
description: params.description,
|
|
3300
|
-
requestContextSchema: params.requestContextSchema ?? null,
|
|
3284
|
+
headersSchema: params.headersSchema ?? null,
|
|
3301
3285
|
contextVariables: contextVariables ?? null,
|
|
3302
3286
|
createdAt: now,
|
|
3303
3287
|
updatedAt: now
|
|
@@ -3312,8 +3296,8 @@ var updateContextConfig = (db) => async (params) => {
|
|
|
3312
3296
|
processedData.contextVariables = null;
|
|
3313
3297
|
}
|
|
3314
3298
|
}
|
|
3315
|
-
if ("
|
|
3316
|
-
processedData.
|
|
3299
|
+
if ("headersSchema" in params.data && params.data.headersSchema === null) {
|
|
3300
|
+
processedData.headersSchema = null;
|
|
3317
3301
|
}
|
|
3318
3302
|
const updated = await db.update(contextConfigs).set({
|
|
3319
3303
|
...processedData,
|
|
@@ -3359,17 +3343,6 @@ var countContextConfigs = (db) => async (params) => {
|
|
|
3359
3343
|
const total = result[0]?.count || 0;
|
|
3360
3344
|
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
3361
3345
|
};
|
|
3362
|
-
var getContextConfigsByName = (db) => async (params) => {
|
|
3363
|
-
return await db.query.contextConfigs.findMany({
|
|
3364
|
-
where: drizzleOrm.and(
|
|
3365
|
-
drizzleOrm.eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
3366
|
-
drizzleOrm.eq(contextConfigs.projectId, params.scopes.projectId),
|
|
3367
|
-
drizzleOrm.eq(contextConfigs.graphId, params.scopes.graphId),
|
|
3368
|
-
drizzleOrm.eq(contextConfigs.name, params.name)
|
|
3369
|
-
),
|
|
3370
|
-
orderBy: [drizzleOrm.desc(contextConfigs.createdAt)]
|
|
3371
|
-
});
|
|
3372
|
-
};
|
|
3373
3346
|
var upsertContextConfig = (db) => async (params) => {
|
|
3374
3347
|
const scopes = {
|
|
3375
3348
|
tenantId: params.data.tenantId,
|
|
@@ -3386,9 +3359,7 @@ var upsertContextConfig = (db) => async (params) => {
|
|
|
3386
3359
|
scopes,
|
|
3387
3360
|
id: params.data.id,
|
|
3388
3361
|
data: {
|
|
3389
|
-
|
|
3390
|
-
description: params.data.description,
|
|
3391
|
-
requestContextSchema: params.data.requestContextSchema,
|
|
3362
|
+
headersSchema: params.data.headersSchema,
|
|
3392
3363
|
contextVariables: params.data.contextVariables
|
|
3393
3364
|
}
|
|
3394
3365
|
});
|
|
@@ -3808,10 +3779,6 @@ var detectAuthenticationRequired = async ({
|
|
|
3808
3779
|
);
|
|
3809
3780
|
return false;
|
|
3810
3781
|
};
|
|
3811
|
-
var generateId = nanoid.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 21);
|
|
3812
|
-
function getConversationId() {
|
|
3813
|
-
return generateId();
|
|
3814
|
-
}
|
|
3815
3782
|
var ErrorCode = zodOpenapi.z.enum([
|
|
3816
3783
|
"bad_request",
|
|
3817
3784
|
"unauthorized",
|
|
@@ -4571,7 +4538,7 @@ var discoverToolsFromServer = async (tool2, dbClient, credentialStoreRegistry) =
|
|
|
4571
4538
|
}
|
|
4572
4539
|
};
|
|
4573
4540
|
var dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry) => {
|
|
4574
|
-
const { headers, capabilities, credentialReferenceId, imageUrl, createdAt, ...rest } = dbResult;
|
|
4541
|
+
const { headers: headers2, capabilities, credentialReferenceId, imageUrl, createdAt, ...rest } = dbResult;
|
|
4575
4542
|
if (dbResult.config.type !== "mcp") {
|
|
4576
4543
|
return {
|
|
4577
4544
|
...rest,
|
|
@@ -4584,7 +4551,7 @@ var dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry) => {
|
|
|
4584
4551
|
createdAt: new Date(createdAt),
|
|
4585
4552
|
updatedAt: new Date(dbResult.updatedAt),
|
|
4586
4553
|
lastError: null,
|
|
4587
|
-
headers:
|
|
4554
|
+
headers: headers2 || void 0,
|
|
4588
4555
|
imageUrl: imageUrl || void 0
|
|
4589
4556
|
};
|
|
4590
4557
|
}
|
|
@@ -4625,7 +4592,7 @@ var dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry) => {
|
|
|
4625
4592
|
createdAt: new Date(createdAt),
|
|
4626
4593
|
updatedAt: new Date(now),
|
|
4627
4594
|
lastError: lastErrorComputed,
|
|
4628
|
-
headers:
|
|
4595
|
+
headers: headers2 || void 0,
|
|
4629
4596
|
imageUrl: imageUrl || void 0
|
|
4630
4597
|
};
|
|
4631
4598
|
};
|
|
@@ -5141,9 +5108,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
5141
5108
|
if (contextConfig2) {
|
|
5142
5109
|
result.contextConfig = {
|
|
5143
5110
|
id: contextConfig2.id,
|
|
5144
|
-
|
|
5145
|
-
description: contextConfig2.description,
|
|
5146
|
-
requestContextSchema: contextConfig2.requestContextSchema,
|
|
5111
|
+
headersSchema: contextConfig2.headersSchema,
|
|
5147
5112
|
contextVariables: contextConfig2.contextVariables
|
|
5148
5113
|
};
|
|
5149
5114
|
}
|
|
@@ -5860,14 +5825,14 @@ var cleanupTenantCache = (db) => async (params) => {
|
|
|
5860
5825
|
);
|
|
5861
5826
|
return result.rowsAffected || 0;
|
|
5862
5827
|
};
|
|
5863
|
-
var
|
|
5828
|
+
var invalidateHeadersCache = (db) => async (params) => {
|
|
5864
5829
|
const result = await db.delete(contextCache).where(
|
|
5865
5830
|
drizzleOrm.and(
|
|
5866
5831
|
drizzleOrm.eq(contextCache.tenantId, params.scopes.tenantId),
|
|
5867
5832
|
drizzleOrm.eq(contextCache.projectId, params.scopes.projectId),
|
|
5868
5833
|
drizzleOrm.eq(contextCache.conversationId, params.conversationId),
|
|
5869
5834
|
drizzleOrm.eq(contextCache.contextConfigId, params.contextConfigId),
|
|
5870
|
-
drizzleOrm.eq(contextCache.contextVariableKey, "
|
|
5835
|
+
drizzleOrm.eq(contextCache.contextVariableKey, "headers")
|
|
5871
5836
|
)
|
|
5872
5837
|
);
|
|
5873
5838
|
return result.rowsAffected || 0;
|
|
@@ -6706,14 +6671,14 @@ var createFullGraphServerSide = (db, logger13 = defaultLogger) => async (scopes,
|
|
|
6706
6671
|
agentToolPromises.push(
|
|
6707
6672
|
(async () => {
|
|
6708
6673
|
try {
|
|
6709
|
-
const { toolId, toolSelection, headers, agentToolRelationId } = canUseItem;
|
|
6674
|
+
const { toolId, toolSelection, headers: headers2, agentToolRelationId } = canUseItem;
|
|
6710
6675
|
logger13.info({ agentId, toolId }, "Processing agent-tool relation");
|
|
6711
6676
|
await upsertAgentToolRelation(db)({
|
|
6712
6677
|
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
6713
6678
|
agentId,
|
|
6714
6679
|
toolId,
|
|
6715
6680
|
selectedTools: toolSelection || void 0,
|
|
6716
|
-
headers:
|
|
6681
|
+
headers: headers2 || void 0,
|
|
6717
6682
|
relationId: agentToolRelationId
|
|
6718
6683
|
});
|
|
6719
6684
|
logger13.info({ agentId, toolId }, "Agent-tool relation processed successfully");
|
|
@@ -7224,14 +7189,14 @@ var updateFullGraphServerSide = (db, logger13 = defaultLogger) => async (scopes,
|
|
|
7224
7189
|
agentToolPromises.push(
|
|
7225
7190
|
(async () => {
|
|
7226
7191
|
try {
|
|
7227
|
-
const { toolId, toolSelection, headers, agentToolRelationId } = canUseItem;
|
|
7192
|
+
const { toolId, toolSelection, headers: headers2, agentToolRelationId } = canUseItem;
|
|
7228
7193
|
logger13.info({ agentId, toolId }, "Processing agent-tool relation");
|
|
7229
7194
|
await upsertAgentToolRelation(db)({
|
|
7230
7195
|
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
7231
7196
|
agentId,
|
|
7232
7197
|
toolId,
|
|
7233
7198
|
selectedTools: toolSelection || void 0,
|
|
7234
|
-
headers:
|
|
7199
|
+
headers: headers2 || void 0,
|
|
7235
7200
|
relationId: agentToolRelationId
|
|
7236
7201
|
});
|
|
7237
7202
|
logger13.info(
|
|
@@ -9216,8 +9181,8 @@ var ContextCache = class {
|
|
|
9216
9181
|
invocationDefinitionIds: definitionIds
|
|
9217
9182
|
});
|
|
9218
9183
|
}
|
|
9219
|
-
async
|
|
9220
|
-
await
|
|
9184
|
+
async invalidateHeaders(tenantId, projectId, conversationId, contextConfigId) {
|
|
9185
|
+
await invalidateHeadersCache(this.dbClient)({
|
|
9221
9186
|
scopes: { tenantId, projectId },
|
|
9222
9187
|
conversationId,
|
|
9223
9188
|
contextConfigId
|
|
@@ -9270,21 +9235,21 @@ var ContextResolver = class {
|
|
|
9270
9235
|
try {
|
|
9271
9236
|
const result = {
|
|
9272
9237
|
resolvedContext: {},
|
|
9273
|
-
|
|
9238
|
+
headers: options.headers || {},
|
|
9274
9239
|
fetchedDefinitions: [],
|
|
9275
9240
|
cacheHits: [],
|
|
9276
9241
|
cacheMisses: [],
|
|
9277
9242
|
errors: [],
|
|
9278
9243
|
totalDurationMs: 0
|
|
9279
9244
|
};
|
|
9280
|
-
result.resolvedContext.
|
|
9281
|
-
const
|
|
9245
|
+
result.resolvedContext.headers = result.headers;
|
|
9246
|
+
const currentHeaders = await this.cache.get({
|
|
9282
9247
|
conversationId: options.conversationId,
|
|
9283
9248
|
contextConfigId: contextConfig2.id,
|
|
9284
|
-
contextVariableKey: "
|
|
9249
|
+
contextVariableKey: "headers"
|
|
9285
9250
|
});
|
|
9286
|
-
if (options.
|
|
9287
|
-
await this.cache.
|
|
9251
|
+
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
9252
|
+
await this.cache.invalidateHeaders(
|
|
9288
9253
|
this.tenantId,
|
|
9289
9254
|
this.projectId,
|
|
9290
9255
|
options.conversationId,
|
|
@@ -9295,13 +9260,13 @@ var ContextResolver = class {
|
|
|
9295
9260
|
conversationId: options.conversationId,
|
|
9296
9261
|
contextConfigId: contextConfig2.id
|
|
9297
9262
|
},
|
|
9298
|
-
"Invalidated
|
|
9263
|
+
"Invalidated headers in cache"
|
|
9299
9264
|
);
|
|
9300
9265
|
await this.cache.set({
|
|
9301
9266
|
contextConfigId: contextConfig2.id,
|
|
9302
|
-
contextVariableKey: "
|
|
9267
|
+
contextVariableKey: "headers",
|
|
9303
9268
|
conversationId: options.conversationId,
|
|
9304
|
-
value: options.
|
|
9269
|
+
value: options.headers,
|
|
9305
9270
|
tenantId: this.tenantId
|
|
9306
9271
|
});
|
|
9307
9272
|
logger8.info(
|
|
@@ -9309,14 +9274,14 @@ var ContextResolver = class {
|
|
|
9309
9274
|
conversationId: options.conversationId,
|
|
9310
9275
|
contextConfigId: contextConfig2.id
|
|
9311
9276
|
},
|
|
9312
|
-
"
|
|
9277
|
+
"Headers set in cache"
|
|
9313
9278
|
);
|
|
9314
|
-
} else if (
|
|
9315
|
-
result.
|
|
9279
|
+
} else if (currentHeaders) {
|
|
9280
|
+
result.headers = currentHeaders.value;
|
|
9316
9281
|
} else {
|
|
9317
|
-
result.
|
|
9282
|
+
result.headers = {};
|
|
9318
9283
|
}
|
|
9319
|
-
result.resolvedContext.
|
|
9284
|
+
result.resolvedContext.headers = result.headers;
|
|
9320
9285
|
const contextVariables = contextConfig2.contextVariables || {};
|
|
9321
9286
|
const contextVariableEntries = Object.entries(contextVariables);
|
|
9322
9287
|
if (contextVariableEntries.length === 0) {
|
|
@@ -9345,7 +9310,7 @@ var ContextResolver = class {
|
|
|
9345
9310
|
invocationDefs.map(([, def]) => def.id)
|
|
9346
9311
|
);
|
|
9347
9312
|
}
|
|
9348
|
-
const requestHash = this.createRequestHash(result.
|
|
9313
|
+
const requestHash = this.createRequestHash(result.headers);
|
|
9349
9314
|
const fetchPromises = contextVariableEntries.map(
|
|
9350
9315
|
([templateKey, definition]) => this.resolveSingleFetchDefinition(
|
|
9351
9316
|
contextConfig2,
|
|
@@ -9518,13 +9483,13 @@ var ContextResolver = class {
|
|
|
9518
9483
|
);
|
|
9519
9484
|
}
|
|
9520
9485
|
/**
|
|
9521
|
-
* Resolve the
|
|
9486
|
+
* Resolve the headers for a given conversation
|
|
9522
9487
|
*/
|
|
9523
|
-
async
|
|
9488
|
+
async resolveHeaders(conversationId, contextConfigId) {
|
|
9524
9489
|
const cachedEntry = await this.cache.get({
|
|
9525
9490
|
conversationId,
|
|
9526
9491
|
contextConfigId,
|
|
9527
|
-
contextVariableKey: "
|
|
9492
|
+
contextVariableKey: "headers"
|
|
9528
9493
|
});
|
|
9529
9494
|
if (cachedEntry) {
|
|
9530
9495
|
return cachedEntry.value;
|
|
@@ -9532,10 +9497,10 @@ var ContextResolver = class {
|
|
|
9532
9497
|
return {};
|
|
9533
9498
|
}
|
|
9534
9499
|
/**
|
|
9535
|
-
* Create a hash of the
|
|
9500
|
+
* Create a hash of the headers for cache invalidation
|
|
9536
9501
|
*/
|
|
9537
|
-
createRequestHash(
|
|
9538
|
-
const contextString = JSON.stringify(
|
|
9502
|
+
createRequestHash(headers2) {
|
|
9503
|
+
const contextString = JSON.stringify(headers2, Object.keys(headers2).sort());
|
|
9539
9504
|
return crypto__default.default.createHash("sha256").update(contextString).digest("hex").substring(0, 16);
|
|
9540
9505
|
}
|
|
9541
9506
|
/**
|
|
@@ -9721,7 +9686,7 @@ async function validateHttpRequestHeaders(headersSchema, httpRequest) {
|
|
|
9721
9686
|
};
|
|
9722
9687
|
}
|
|
9723
9688
|
}
|
|
9724
|
-
async function
|
|
9689
|
+
async function fetchExistingHeaders({
|
|
9725
9690
|
tenantId,
|
|
9726
9691
|
projectId,
|
|
9727
9692
|
contextConfig: contextConfig2,
|
|
@@ -9730,22 +9695,22 @@ async function fetchExistingRequestContext({
|
|
|
9730
9695
|
credentialStores
|
|
9731
9696
|
}) {
|
|
9732
9697
|
const contextResolver = new ContextResolver(tenantId, projectId, dbClient, credentialStores);
|
|
9733
|
-
const
|
|
9698
|
+
const headers2 = await contextResolver.resolveHeaders(
|
|
9734
9699
|
conversationId,
|
|
9735
9700
|
contextConfig2.id
|
|
9736
9701
|
);
|
|
9737
|
-
if (Object.keys(
|
|
9702
|
+
if (Object.keys(headers2).length > 0) {
|
|
9738
9703
|
return {
|
|
9739
9704
|
valid: true,
|
|
9740
9705
|
errors: [],
|
|
9741
|
-
validatedContext:
|
|
9706
|
+
validatedContext: headers2
|
|
9742
9707
|
};
|
|
9743
9708
|
}
|
|
9744
9709
|
throw new Error(
|
|
9745
|
-
"No
|
|
9710
|
+
"No headers found in cache. Please provide headers in request."
|
|
9746
9711
|
);
|
|
9747
9712
|
}
|
|
9748
|
-
async function
|
|
9713
|
+
async function validateHeaders({
|
|
9749
9714
|
tenantId,
|
|
9750
9715
|
projectId,
|
|
9751
9716
|
graphId,
|
|
@@ -9782,10 +9747,10 @@ async function validateRequestContext({
|
|
|
9782
9747
|
]
|
|
9783
9748
|
};
|
|
9784
9749
|
}
|
|
9785
|
-
if (!contextConfig2.
|
|
9750
|
+
if (!contextConfig2.headersSchema) {
|
|
9786
9751
|
logger9.debug(
|
|
9787
9752
|
{ contextConfigId: contextConfig2.id },
|
|
9788
|
-
"No
|
|
9753
|
+
"No headers schema defined, accepting any context"
|
|
9789
9754
|
);
|
|
9790
9755
|
return {
|
|
9791
9756
|
valid: true,
|
|
@@ -9794,7 +9759,7 @@ async function validateRequestContext({
|
|
|
9794
9759
|
};
|
|
9795
9760
|
}
|
|
9796
9761
|
try {
|
|
9797
|
-
const schema = contextConfig2.
|
|
9762
|
+
const schema = contextConfig2.headersSchema;
|
|
9798
9763
|
logger9.debug({ contextConfigId: contextConfig2.id }, "Using headers schema validation");
|
|
9799
9764
|
const httpRequest = parsedRequest;
|
|
9800
9765
|
const validationResult = await validateHttpRequestHeaders(schema, httpRequest);
|
|
@@ -9802,7 +9767,7 @@ async function validateRequestContext({
|
|
|
9802
9767
|
return validationResult;
|
|
9803
9768
|
}
|
|
9804
9769
|
try {
|
|
9805
|
-
return await
|
|
9770
|
+
return await fetchExistingHeaders({
|
|
9806
9771
|
tenantId,
|
|
9807
9772
|
projectId,
|
|
9808
9773
|
contextConfig: contextConfig2,
|
|
@@ -9812,8 +9777,8 @@ async function validateRequestContext({
|
|
|
9812
9777
|
});
|
|
9813
9778
|
} catch (_error) {
|
|
9814
9779
|
validationResult.errors.push({
|
|
9815
|
-
field: "
|
|
9816
|
-
message: "Failed to fetch
|
|
9780
|
+
field: "headers",
|
|
9781
|
+
message: "Failed to fetch headers from cache"
|
|
9817
9782
|
});
|
|
9818
9783
|
return validationResult;
|
|
9819
9784
|
}
|
|
@@ -9842,7 +9807,7 @@ async function validateRequestContext({
|
|
|
9842
9807
|
graphId,
|
|
9843
9808
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
9844
9809
|
},
|
|
9845
|
-
"Failed to validate
|
|
9810
|
+
"Failed to validate headers"
|
|
9846
9811
|
);
|
|
9847
9812
|
return {
|
|
9848
9813
|
valid: false,
|
|
@@ -9870,15 +9835,15 @@ function contextValidationMiddleware(dbClient) {
|
|
|
9870
9835
|
}
|
|
9871
9836
|
const body = c.get("requestBody") || {};
|
|
9872
9837
|
const conversationId = body.conversationId || "";
|
|
9873
|
-
const
|
|
9838
|
+
const headers2 = {};
|
|
9874
9839
|
c.req.raw.headers.forEach((value, key) => {
|
|
9875
|
-
|
|
9840
|
+
headers2[key.toLowerCase()] = value;
|
|
9876
9841
|
});
|
|
9877
9842
|
const credentialStores = c.get("credentialStores");
|
|
9878
9843
|
const parsedRequest = {
|
|
9879
|
-
headers
|
|
9844
|
+
headers: headers2
|
|
9880
9845
|
};
|
|
9881
|
-
const validationResult = await
|
|
9846
|
+
const validationResult = await validateHeaders({
|
|
9882
9847
|
tenantId,
|
|
9883
9848
|
projectId,
|
|
9884
9849
|
graphId,
|
|
@@ -9894,9 +9859,9 @@ function contextValidationMiddleware(dbClient) {
|
|
|
9894
9859
|
graphId,
|
|
9895
9860
|
errors: validationResult.errors
|
|
9896
9861
|
},
|
|
9897
|
-
"
|
|
9862
|
+
"Headers validation failed"
|
|
9898
9863
|
);
|
|
9899
|
-
const errorMessage = `Invalid
|
|
9864
|
+
const errorMessage = `Invalid headers: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`;
|
|
9900
9865
|
throw createApiError({
|
|
9901
9866
|
code: "bad_request",
|
|
9902
9867
|
message: errorMessage
|
|
@@ -10303,7 +10268,7 @@ async function handleContextResolution({
|
|
|
10303
10268
|
projectId,
|
|
10304
10269
|
graphId,
|
|
10305
10270
|
conversationId,
|
|
10306
|
-
|
|
10271
|
+
headers: headers2,
|
|
10307
10272
|
dbClient,
|
|
10308
10273
|
credentialStores
|
|
10309
10274
|
}) {
|
|
@@ -10311,7 +10276,7 @@ async function handleContextResolution({
|
|
|
10311
10276
|
"context.handle_context_resolution",
|
|
10312
10277
|
{
|
|
10313
10278
|
attributes: {
|
|
10314
|
-
"context.
|
|
10279
|
+
"context.headers_keys": Object.keys(headers2)
|
|
10315
10280
|
}
|
|
10316
10281
|
},
|
|
10317
10282
|
async (parentSpan) => {
|
|
@@ -10359,7 +10324,7 @@ async function handleContextResolution({
|
|
|
10359
10324
|
const contextResult = await contextResolver.resolve(contextConfig2, {
|
|
10360
10325
|
triggerEvent: trigger,
|
|
10361
10326
|
conversationId,
|
|
10362
|
-
|
|
10327
|
+
headers: headers2,
|
|
10363
10328
|
tenantId
|
|
10364
10329
|
});
|
|
10365
10330
|
const resolvedContext = {
|
|
@@ -11578,6 +11543,7 @@ exports.functions = functions;
|
|
|
11578
11543
|
exports.functionsRelations = functionsRelations;
|
|
11579
11544
|
exports.generateAndCreateApiKey = generateAndCreateApiKey;
|
|
11580
11545
|
exports.generateApiKey = generateApiKey;
|
|
11546
|
+
exports.generateId = generateId;
|
|
11581
11547
|
exports.generateIdFromName = generateIdFromName;
|
|
11582
11548
|
exports.getActiveAgentForConversation = getActiveAgentForConversation;
|
|
11583
11549
|
exports.getAgentById = getAgentById;
|
|
@@ -11604,7 +11570,6 @@ exports.getCacheEntry = getCacheEntry;
|
|
|
11604
11570
|
exports.getCachedValidator = getCachedValidator;
|
|
11605
11571
|
exports.getContextConfigById = getContextConfigById;
|
|
11606
11572
|
exports.getContextConfigCacheEntries = getContextConfigCacheEntries;
|
|
11607
|
-
exports.getContextConfigsByName = getContextConfigsByName;
|
|
11608
11573
|
exports.getConversation = getConversation;
|
|
11609
11574
|
exports.getConversationCacheEntries = getConversationCacheEntries;
|
|
11610
11575
|
exports.getConversationHistory = getConversationHistory;
|
|
@@ -11646,8 +11611,9 @@ exports.hasApiKey = hasApiKey;
|
|
|
11646
11611
|
exports.hasContextConfig = hasContextConfig;
|
|
11647
11612
|
exports.hasCredentialReference = hasCredentialReference;
|
|
11648
11613
|
exports.hashApiKey = hashApiKey;
|
|
11614
|
+
exports.headers = headers;
|
|
11615
|
+
exports.invalidateHeadersCache = invalidateHeadersCache;
|
|
11649
11616
|
exports.invalidateInvocationDefinitionsCache = invalidateInvocationDefinitionsCache;
|
|
11650
|
-
exports.invalidateRequestContextCache = invalidateRequestContextCache;
|
|
11651
11617
|
exports.isApiKeyExpired = isApiKeyExpired;
|
|
11652
11618
|
exports.isArtifactComponentAssociatedWithAgent = isArtifactComponentAssociatedWithAgent;
|
|
11653
11619
|
exports.isDataComponentAssociatedWithAgent = isDataComponentAssociatedWithAgent;
|
|
@@ -11698,7 +11664,6 @@ exports.projectsRelations = projectsRelations;
|
|
|
11698
11664
|
exports.removeArtifactComponentFromAgent = removeArtifactComponentFromAgent;
|
|
11699
11665
|
exports.removeDataComponentFromAgent = removeDataComponentFromAgent;
|
|
11700
11666
|
exports.removeToolFromAgent = removeToolFromAgent;
|
|
11701
|
-
exports.requestContextSchema = requestContextSchema;
|
|
11702
11667
|
exports.resourceIdSchema = resourceIdSchema;
|
|
11703
11668
|
exports.setActiveAgentForConversation = setActiveAgentForConversation;
|
|
11704
11669
|
exports.setActiveAgentForThread = setActiveAgentForThread;
|
|
@@ -11752,11 +11717,11 @@ exports.validateArtifactComponentReferences = validateArtifactComponentReference
|
|
|
11752
11717
|
exports.validateDataComponentReferences = validateDataComponentReferences;
|
|
11753
11718
|
exports.validateExternalAgent = validateExternalAgent;
|
|
11754
11719
|
exports.validateGraphStructure = validateGraphStructure;
|
|
11720
|
+
exports.validateHeaders = validateHeaders;
|
|
11755
11721
|
exports.validateHttpRequestHeaders = validateHttpRequestHeaders;
|
|
11756
11722
|
exports.validateInternalAgent = validateInternalAgent;
|
|
11757
11723
|
exports.validateProjectExists = validateProjectExists;
|
|
11758
11724
|
exports.validatePropsAsJsonSchema = validatePropsAsJsonSchema;
|
|
11759
|
-
exports.validateRequestContext = validateRequestContext;
|
|
11760
11725
|
exports.validateToolReferences = validateToolReferences;
|
|
11761
11726
|
exports.validationHelper = validationHelper;
|
|
11762
11727
|
exports.withProjectValidation = withProjectValidation;
|