@inkeep/agents-core 0.41.2 → 0.42.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 +55 -1
- package/dist/auth/authz/client.d.ts +81 -0
- package/dist/auth/authz/client.js +189 -0
- package/dist/auth/authz/config.d.ts +76 -0
- package/dist/auth/authz/config.js +76 -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 +57 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +85 -0
- package/dist/auth/authz/sync.js +237 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +8 -3
- package/dist/client-exports.js +3 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- 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.js +0 -1
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- 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} +205 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +23 -22
- package/dist/data-access/{agents.js → manage/agents.js} +52 -7
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +21 -21
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +14 -14
- 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} +20 -20
- 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/{functionTools.d.ts → manage/functionTools.d.ts} +65 -15
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +90 -8
- 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} +19 -19
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +29 -29
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +13 -13
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +26 -19
- package/dist/data-access/{tools.js → manage/tools.js} +57 -35
- package/dist/data-access/manage/triggers.d.ts +80 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +17 -17
- 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} +68 -19
- 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} +15 -15
- 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} +15 -3
- 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} +1459 -1285
- package/dist/db/{schema.js → manage/manage-schema.js} +433 -341
- 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/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 +78 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +22 -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 +134 -0
- package/dist/dolt/schema-sync.js +246 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +71 -44
- package/dist/index.js +74 -47
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +45 -4
- package/dist/utils/JsonTransformer.d.ts +44 -0
- package/dist/utils/JsonTransformer.js +112 -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 +7 -3
- package/dist/utils/index.js +7 -3
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- 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.js +23 -23
- package/dist/utils/trigger-auth.d.ts +62 -0
- package/dist/utils/trigger-auth.js +125 -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 +4 -3
- package/dist/validation/index.js +3 -2
- package/dist/validation/schemas.d.ts +17647 -4789
- package/dist/validation/schemas.js +328 -11
- 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/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/_journal.json +27 -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 +48 -15
- 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/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,278 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../utils/logger.js";
|
|
2
|
-
import { setSpanWithError } from "../utils/tracer-factory.js";
|
|
3
|
-
import "../utils/index.js";
|
|
4
|
-
import { tracer } from "../utils/tracer.js";
|
|
5
|
-
import { ContextCache } from "./contextCache.js";
|
|
6
|
-
import { ContextFetcher, MissingRequiredVariableError } from "./ContextFetcher.js";
|
|
7
|
-
import crypto from "node:crypto";
|
|
8
|
-
import { SpanStatusCode } from "@opentelemetry/api";
|
|
9
|
-
|
|
10
|
-
//#region src/context/ContextResolver.ts
|
|
11
|
-
const logger = getLogger("context-resolver");
|
|
12
|
-
var ContextResolver = class {
|
|
13
|
-
fetcher;
|
|
14
|
-
cache;
|
|
15
|
-
tenantId;
|
|
16
|
-
projectId;
|
|
17
|
-
constructor(tenantId, projectId, dbClient, credentialStoreRegistry) {
|
|
18
|
-
this.tenantId = tenantId;
|
|
19
|
-
this.projectId = projectId;
|
|
20
|
-
this.fetcher = new ContextFetcher(tenantId, projectId, dbClient, credentialStoreRegistry);
|
|
21
|
-
this.cache = new ContextCache(tenantId, projectId, dbClient);
|
|
22
|
-
logger.info({
|
|
23
|
-
tenantId: this.tenantId,
|
|
24
|
-
hasCredentialSupport: !!credentialStoreRegistry
|
|
25
|
-
}, "ContextResolver initialized");
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Resolve all contexts for a given configuration and trigger event
|
|
29
|
-
*/
|
|
30
|
-
async resolve(contextConfig, options) {
|
|
31
|
-
const startTime = Date.now();
|
|
32
|
-
logger.info({
|
|
33
|
-
contextConfigId: contextConfig.id,
|
|
34
|
-
triggerEvent: options.triggerEvent,
|
|
35
|
-
conversationId: options.conversationId
|
|
36
|
-
}, "Starting context resolution");
|
|
37
|
-
return tracer.startActiveSpan("context.resolve", { attributes: {
|
|
38
|
-
"context.config_id": contextConfig.id,
|
|
39
|
-
"context.trigger_event": options.triggerEvent
|
|
40
|
-
} }, async (parentSpan) => {
|
|
41
|
-
try {
|
|
42
|
-
const result = {
|
|
43
|
-
resolvedContext: {},
|
|
44
|
-
headers: options.headers || {},
|
|
45
|
-
fetchedDefinitions: [],
|
|
46
|
-
cacheHits: [],
|
|
47
|
-
cacheMisses: [],
|
|
48
|
-
errors: [],
|
|
49
|
-
skipped: [],
|
|
50
|
-
totalDurationMs: 0
|
|
51
|
-
};
|
|
52
|
-
result.resolvedContext.headers = result.headers;
|
|
53
|
-
const currentHeaders = await this.cache.get({
|
|
54
|
-
conversationId: options.conversationId,
|
|
55
|
-
contextConfigId: contextConfig.id,
|
|
56
|
-
contextVariableKey: "headers"
|
|
57
|
-
});
|
|
58
|
-
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
59
|
-
await this.cache.invalidateHeaders(this.tenantId, this.projectId, options.conversationId, contextConfig.id);
|
|
60
|
-
logger.info({
|
|
61
|
-
conversationId: options.conversationId,
|
|
62
|
-
contextConfigId: contextConfig.id
|
|
63
|
-
}, "Invalidated headers in cache");
|
|
64
|
-
await this.cache.set({
|
|
65
|
-
contextConfigId: contextConfig.id,
|
|
66
|
-
contextVariableKey: "headers",
|
|
67
|
-
conversationId: options.conversationId,
|
|
68
|
-
value: options.headers,
|
|
69
|
-
tenantId: this.tenantId
|
|
70
|
-
});
|
|
71
|
-
logger.info({
|
|
72
|
-
conversationId: options.conversationId,
|
|
73
|
-
contextConfigId: contextConfig.id
|
|
74
|
-
}, "Headers set in cache");
|
|
75
|
-
} else if (currentHeaders) result.headers = currentHeaders.value;
|
|
76
|
-
else result.headers = {};
|
|
77
|
-
result.resolvedContext.headers = result.headers;
|
|
78
|
-
const contextVariables = contextConfig.contextVariables || {};
|
|
79
|
-
const contextVariableEntries = Object.entries(contextVariables);
|
|
80
|
-
if (contextVariableEntries.length === 0) {
|
|
81
|
-
logger.info({ contextConfigId: contextConfig.id }, "No context variables in context config");
|
|
82
|
-
result.totalDurationMs = Date.now() - startTime;
|
|
83
|
-
parentSpan.setStatus({ code: SpanStatusCode.OK });
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
contextVariableEntries.filter(([, def]) => def.trigger === "initialization");
|
|
87
|
-
const invocationDefs = contextVariableEntries.filter(([, def]) => def.trigger === "invocation");
|
|
88
|
-
if (options.triggerEvent === "invocation" && invocationDefs.length > 0) await this.cache.invalidateInvocationDefinitions(this.tenantId, this.projectId, options.conversationId, contextConfig.id, invocationDefs.map(([, def]) => def.id));
|
|
89
|
-
const requestHash = this.createRequestHash(result.headers);
|
|
90
|
-
const fetchPromises = contextVariableEntries.map(([templateKey, definition]) => this.resolveSingleFetchDefinition(contextConfig, definition, templateKey, options, requestHash, result).catch((error) => {
|
|
91
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
92
|
-
if (error instanceof MissingRequiredVariableError) {
|
|
93
|
-
logger.info({
|
|
94
|
-
contextConfigId: contextConfig.id,
|
|
95
|
-
definitionId: definition.id,
|
|
96
|
-
templateKey,
|
|
97
|
-
reason: errorMessage
|
|
98
|
-
}, "Context fetch skipped due to missing required variable");
|
|
99
|
-
result.skipped.push({
|
|
100
|
-
definitionId: definition.id,
|
|
101
|
-
reason: errorMessage
|
|
102
|
-
});
|
|
103
|
-
if (definition.defaultValue !== void 0) {
|
|
104
|
-
result.resolvedContext[templateKey] = definition.defaultValue;
|
|
105
|
-
logger.info({
|
|
106
|
-
contextConfigId: contextConfig.id,
|
|
107
|
-
definitionId: definition.id,
|
|
108
|
-
templateKey
|
|
109
|
-
}, "Using default value for skipped context variable");
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
logger.error({
|
|
114
|
-
contextConfigId: contextConfig.id,
|
|
115
|
-
definitionId: definition.id,
|
|
116
|
-
templateKey,
|
|
117
|
-
error: errorMessage
|
|
118
|
-
}, "Failed to resolve context variable");
|
|
119
|
-
result.errors.push({
|
|
120
|
-
definitionId: definition.id,
|
|
121
|
-
error: errorMessage
|
|
122
|
-
});
|
|
123
|
-
if (definition.defaultValue !== void 0) {
|
|
124
|
-
result.resolvedContext[templateKey] = definition.defaultValue;
|
|
125
|
-
logger.info({
|
|
126
|
-
contextConfigId: contextConfig.id,
|
|
127
|
-
definitionId: definition.id,
|
|
128
|
-
templateKey
|
|
129
|
-
}, "Using default value for failed context variable");
|
|
130
|
-
}
|
|
131
|
-
}));
|
|
132
|
-
await Promise.all(fetchPromises);
|
|
133
|
-
result.totalDurationMs = Date.now() - startTime;
|
|
134
|
-
parentSpan.addEvent("context.resolution.completed", {
|
|
135
|
-
resolved_keys: Object.keys(result.resolvedContext),
|
|
136
|
-
fetched_definitions: result.fetchedDefinitions,
|
|
137
|
-
skipped_definitions: result.skipped.map((s) => s.definitionId)
|
|
138
|
-
});
|
|
139
|
-
if (result.errors.length > 0) parentSpan.setStatus({
|
|
140
|
-
code: SpanStatusCode.ERROR,
|
|
141
|
-
message: `Context resolution completed with errors`
|
|
142
|
-
});
|
|
143
|
-
else parentSpan.setStatus({ code: SpanStatusCode.OK });
|
|
144
|
-
logger.info({
|
|
145
|
-
contextConfigId: contextConfig.id,
|
|
146
|
-
resolvedKeys: Object.keys(result.resolvedContext),
|
|
147
|
-
fetchedDefinitions: result.fetchedDefinitions.length,
|
|
148
|
-
cacheHits: result.cacheHits.length,
|
|
149
|
-
cacheMisses: result.cacheMisses.length,
|
|
150
|
-
errors: result.errors.length,
|
|
151
|
-
skipped: result.skipped.length,
|
|
152
|
-
totalDurationMs: result.totalDurationMs
|
|
153
|
-
}, "Context resolution completed");
|
|
154
|
-
return result;
|
|
155
|
-
} catch (error) {
|
|
156
|
-
const durationMs = Date.now() - startTime;
|
|
157
|
-
setSpanWithError(parentSpan, error instanceof Error ? error : new Error(String(error)));
|
|
158
|
-
logger.error({
|
|
159
|
-
contextConfigId: contextConfig.id,
|
|
160
|
-
error: error instanceof Error ? error.message : String(error),
|
|
161
|
-
durationMs
|
|
162
|
-
}, "Context resolution failed");
|
|
163
|
-
throw error;
|
|
164
|
-
} finally {
|
|
165
|
-
parentSpan.end();
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Resolve a single context variable
|
|
171
|
-
*/
|
|
172
|
-
async resolveSingleFetchDefinition(contextConfig, definition, templateKey, options, requestHash, result) {
|
|
173
|
-
const cachedEntry = await this.cache.get({
|
|
174
|
-
conversationId: options.conversationId,
|
|
175
|
-
contextConfigId: contextConfig.id,
|
|
176
|
-
contextVariableKey: templateKey,
|
|
177
|
-
requestHash
|
|
178
|
-
});
|
|
179
|
-
if (cachedEntry) {
|
|
180
|
-
result.resolvedContext[templateKey] = cachedEntry.value;
|
|
181
|
-
result.cacheHits.push(definition.id);
|
|
182
|
-
logger.debug({
|
|
183
|
-
definitionId: definition.id,
|
|
184
|
-
templateKey,
|
|
185
|
-
conversationId: options.conversationId
|
|
186
|
-
}, "Cache hit for context variable");
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
result.cacheMisses.push(definition.id);
|
|
190
|
-
logger.debug({
|
|
191
|
-
definitionId: definition.id,
|
|
192
|
-
templateKey,
|
|
193
|
-
conversationId: options.conversationId
|
|
194
|
-
}, "Cache miss for context variable, fetching data");
|
|
195
|
-
const definitionWithConversationId = {
|
|
196
|
-
...definition,
|
|
197
|
-
fetchConfig: {
|
|
198
|
-
...definition.fetchConfig,
|
|
199
|
-
conversationId: options.conversationId
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
const fetchedData = await tracer.startActiveSpan("context-resolver.resolve_single_fetch_definition", { attributes: {
|
|
203
|
-
"context.definition_id": definition.id,
|
|
204
|
-
"context.template_key": templateKey,
|
|
205
|
-
"context.url_template": definition.fetchConfig.url,
|
|
206
|
-
"context.method": definition.fetchConfig.method,
|
|
207
|
-
"context.trigger": definition.trigger
|
|
208
|
-
} }, async (parentSpan) => {
|
|
209
|
-
try {
|
|
210
|
-
const { data, resolvedUrl } = await this.fetcher.fetch(definitionWithConversationId, result.resolvedContext);
|
|
211
|
-
parentSpan.setAttribute("context.url", resolvedUrl);
|
|
212
|
-
parentSpan.setStatus({ code: SpanStatusCode.OK });
|
|
213
|
-
parentSpan.addEvent("context.fetch_success", {
|
|
214
|
-
definition_id: definition.id,
|
|
215
|
-
template_key: templateKey,
|
|
216
|
-
source: resolvedUrl
|
|
217
|
-
});
|
|
218
|
-
return data;
|
|
219
|
-
} catch (error) {
|
|
220
|
-
if (error instanceof MissingRequiredVariableError) {
|
|
221
|
-
parentSpan.setStatus({ code: SpanStatusCode.OK });
|
|
222
|
-
parentSpan.addEvent("context.fetch_skipped", {
|
|
223
|
-
definition_id: definition.id,
|
|
224
|
-
template_key: templateKey,
|
|
225
|
-
reason: error.message
|
|
226
|
-
});
|
|
227
|
-
} else setSpanWithError(parentSpan, error instanceof Error ? error : new Error(String(error)));
|
|
228
|
-
throw error;
|
|
229
|
-
} finally {
|
|
230
|
-
parentSpan.end();
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
result.resolvedContext[templateKey] = fetchedData;
|
|
234
|
-
result.fetchedDefinitions.push(definition.id);
|
|
235
|
-
await this.cache.set({
|
|
236
|
-
contextConfigId: contextConfig.id,
|
|
237
|
-
contextVariableKey: templateKey,
|
|
238
|
-
conversationId: options.conversationId,
|
|
239
|
-
value: fetchedData,
|
|
240
|
-
requestHash,
|
|
241
|
-
tenantId: this.tenantId
|
|
242
|
-
});
|
|
243
|
-
logger.debug({
|
|
244
|
-
definitionId: definition.id,
|
|
245
|
-
templateKey,
|
|
246
|
-
conversationId: options.conversationId
|
|
247
|
-
}, "Context variable resolved and cached");
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Resolve the headers for a given conversation
|
|
251
|
-
*/
|
|
252
|
-
async resolveHeaders(conversationId, contextConfigId) {
|
|
253
|
-
const cachedEntry = await this.cache.get({
|
|
254
|
-
conversationId,
|
|
255
|
-
contextConfigId,
|
|
256
|
-
contextVariableKey: "headers"
|
|
257
|
-
});
|
|
258
|
-
if (cachedEntry) return cachedEntry.value;
|
|
259
|
-
return {};
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Create a hash of the headers for cache invalidation
|
|
263
|
-
*/
|
|
264
|
-
createRequestHash(headers) {
|
|
265
|
-
const contextString = JSON.stringify(headers, Object.keys(headers).sort());
|
|
266
|
-
return crypto.createHash("sha256").update(contextString).digest("hex").substring(0, 16);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Clear cache
|
|
270
|
-
*/
|
|
271
|
-
async clearCache(tenantId, projectId, conversationId) {
|
|
272
|
-
await this.cache.clearConversation(tenantId, projectId, conversationId);
|
|
273
|
-
logger.info({ conversationId }, "Context cache cleared for conversation");
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
//#endregion
|
|
278
|
-
export { ContextResolver };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { CredentialStoreRegistry } from "../credential-stores/CredentialStoreRegistry.js";
|
|
2
|
-
import { ResolvedContext } from "./ContextResolver.js";
|
|
3
|
-
import "../index.js";
|
|
4
|
-
import { DatabaseClient } from "../db/client.js";
|
|
5
|
-
|
|
6
|
-
//#region src/context/context.d.ts
|
|
7
|
-
declare function determineContextTrigger(tenantId: string, projectId: string, conversationId: string, dbClient: DatabaseClient): Promise<'initialization' | 'invocation'>;
|
|
8
|
-
declare function handleContextConfigChange(tenantId: string, projectId: string, conversationId: string, agentId: string, newContextConfigId: string, dbClient: DatabaseClient, credentialStores?: CredentialStoreRegistry): Promise<void>;
|
|
9
|
-
declare function handleContextResolution({
|
|
10
|
-
tenantId,
|
|
11
|
-
projectId,
|
|
12
|
-
agentId,
|
|
13
|
-
conversationId,
|
|
14
|
-
headers,
|
|
15
|
-
dbClient,
|
|
16
|
-
credentialStores
|
|
17
|
-
}: {
|
|
18
|
-
tenantId: string;
|
|
19
|
-
projectId: string;
|
|
20
|
-
agentId: string;
|
|
21
|
-
conversationId: string;
|
|
22
|
-
headers: Record<string, unknown>;
|
|
23
|
-
dbClient: DatabaseClient;
|
|
24
|
-
credentialStores?: CredentialStoreRegistry;
|
|
25
|
-
}): Promise<ResolvedContext | null>;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { determineContextTrigger, handleContextConfigChange, handleContextResolution };
|
package/dist/context/context.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../utils/logger.js";
|
|
2
|
-
import { getContextConfigById } from "../data-access/contextConfigs.js";
|
|
3
|
-
import { setSpanWithError } from "../utils/tracer-factory.js";
|
|
4
|
-
import "../utils/index.js";
|
|
5
|
-
import { getAgentWithDefaultSubAgent } from "../data-access/agents.js";
|
|
6
|
-
import { getConversation, updateConversation } from "../data-access/conversations.js";
|
|
7
|
-
import { tracer } from "../utils/tracer.js";
|
|
8
|
-
import { ContextResolver } from "./ContextResolver.js";
|
|
9
|
-
import "../index.js";
|
|
10
|
-
import { SpanStatusCode } from "@opentelemetry/api";
|
|
11
|
-
|
|
12
|
-
//#region src/context/context.ts
|
|
13
|
-
const logger = getLogger("context");
|
|
14
|
-
async function determineContextTrigger(tenantId, projectId, conversationId, dbClient) {
|
|
15
|
-
const conversation = await getConversation(dbClient)({
|
|
16
|
-
scopes: {
|
|
17
|
-
tenantId,
|
|
18
|
-
projectId
|
|
19
|
-
},
|
|
20
|
-
conversationId
|
|
21
|
-
});
|
|
22
|
-
if (!conversation || !conversation.lastContextResolution) return "initialization";
|
|
23
|
-
return "invocation";
|
|
24
|
-
}
|
|
25
|
-
async function handleContextConfigChange(tenantId, projectId, conversationId, agentId, newContextConfigId, dbClient, credentialStores) {
|
|
26
|
-
const conversation = await getConversation(dbClient)({
|
|
27
|
-
scopes: {
|
|
28
|
-
tenantId,
|
|
29
|
-
projectId
|
|
30
|
-
},
|
|
31
|
-
conversationId
|
|
32
|
-
});
|
|
33
|
-
if (!conversation) return;
|
|
34
|
-
if (conversation.lastContextResolution) {
|
|
35
|
-
await new ContextResolver(tenantId, projectId, dbClient, credentialStores).clearCache(tenantId, projectId, conversationId);
|
|
36
|
-
logger.info({
|
|
37
|
-
conversationId,
|
|
38
|
-
agentId,
|
|
39
|
-
contextConfigId: newContextConfigId
|
|
40
|
-
}, "Potential context config change for existing conversation, cache cleared");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async function handleContextResolution({ tenantId, projectId, agentId, conversationId, headers, dbClient, credentialStores }) {
|
|
44
|
-
return tracer.startActiveSpan("context.handle_context_resolution", { attributes: { "context.headers_keys": Object.keys(headers) } }, async (parentSpan) => {
|
|
45
|
-
let agent;
|
|
46
|
-
let trigger;
|
|
47
|
-
try {
|
|
48
|
-
agent = await getAgentWithDefaultSubAgent(dbClient)({ scopes: {
|
|
49
|
-
tenantId,
|
|
50
|
-
projectId,
|
|
51
|
-
agentId
|
|
52
|
-
} });
|
|
53
|
-
if (!agent?.contextConfigId) {
|
|
54
|
-
logger.debug({ agentId }, "No context config found for agent");
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
await handleContextConfigChange(tenantId, projectId, conversationId, agentId, agent.contextConfigId, dbClient, credentialStores);
|
|
58
|
-
trigger = await determineContextTrigger(tenantId, projectId, conversationId, dbClient);
|
|
59
|
-
const contextConfig = await getContextConfigById(dbClient)({
|
|
60
|
-
scopes: {
|
|
61
|
-
tenantId,
|
|
62
|
-
projectId,
|
|
63
|
-
agentId
|
|
64
|
-
},
|
|
65
|
-
id: agent.contextConfigId
|
|
66
|
-
});
|
|
67
|
-
if (!contextConfig) {
|
|
68
|
-
logger.warn({ contextConfigId: agent.contextConfigId }, "Context config not found, proceeding without context resolution");
|
|
69
|
-
parentSpan.setStatus({ code: SpanStatusCode.ERROR });
|
|
70
|
-
parentSpan.addEvent("context.config_not_found", { contextConfigId: agent.contextConfigId });
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
const contextResult = await new ContextResolver(tenantId, projectId, dbClient, credentialStores).resolve(contextConfig, {
|
|
74
|
-
triggerEvent: trigger,
|
|
75
|
-
conversationId,
|
|
76
|
-
headers,
|
|
77
|
-
tenantId
|
|
78
|
-
});
|
|
79
|
-
const resolvedContext = {
|
|
80
|
-
...contextResult.resolvedContext,
|
|
81
|
-
$env: process.env
|
|
82
|
-
};
|
|
83
|
-
await updateConversation(dbClient)({
|
|
84
|
-
scopes: {
|
|
85
|
-
tenantId,
|
|
86
|
-
projectId
|
|
87
|
-
},
|
|
88
|
-
conversationId,
|
|
89
|
-
data: { lastContextResolution: (/* @__PURE__ */ new Date()).toISOString() }
|
|
90
|
-
});
|
|
91
|
-
if (contextResult.errors.length > 0) parentSpan.setStatus({
|
|
92
|
-
code: SpanStatusCode.ERROR,
|
|
93
|
-
message: `Context resolution completed with errors`
|
|
94
|
-
});
|
|
95
|
-
else parentSpan.setStatus({ code: SpanStatusCode.OK });
|
|
96
|
-
logger.info({
|
|
97
|
-
conversationId,
|
|
98
|
-
agentId,
|
|
99
|
-
contextConfigId: contextConfig.id,
|
|
100
|
-
trigger,
|
|
101
|
-
resolvedKeys: Object.keys(resolvedContext),
|
|
102
|
-
cacheHits: contextResult.cacheHits.length,
|
|
103
|
-
cacheMisses: contextResult.cacheMisses.length,
|
|
104
|
-
fetchedDefinitions: contextResult.fetchedDefinitions.length,
|
|
105
|
-
errors: contextResult.errors.length
|
|
106
|
-
}, "Context resolution completed (contextConfigId derived from agent)");
|
|
107
|
-
return resolvedContext;
|
|
108
|
-
} catch (error) {
|
|
109
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
110
|
-
parentSpan.setAttributes({
|
|
111
|
-
"context.final_status": "failed",
|
|
112
|
-
"context.error_message": errorMessage
|
|
113
|
-
});
|
|
114
|
-
setSpanWithError(parentSpan, error instanceof Error ? error : new Error(String(error)));
|
|
115
|
-
logger.error({
|
|
116
|
-
error: errorMessage,
|
|
117
|
-
contextConfigId: agent?.contextConfigId,
|
|
118
|
-
trigger: await determineContextTrigger(tenantId, projectId, conversationId, dbClient).catch(() => "unknown")
|
|
119
|
-
}, "Failed to resolve context, proceeding without context resolution");
|
|
120
|
-
return null;
|
|
121
|
-
} finally {
|
|
122
|
-
parentSpan.end();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
export { determineContextTrigger, handleContextConfigChange, handleContextResolution };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { DatabaseClient } from "../db/client.js";
|
|
2
|
-
|
|
3
|
-
//#region src/context/contextCache.d.ts
|
|
4
|
-
interface CacheEntry {
|
|
5
|
-
contextConfigId: string;
|
|
6
|
-
contextVariableKey: string;
|
|
7
|
-
conversationId: string;
|
|
8
|
-
value: unknown;
|
|
9
|
-
requestHash?: string;
|
|
10
|
-
tenantId: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Context cache with request hash-based invalidation and graceful error handling.
|
|
14
|
-
*
|
|
15
|
-
* Implements conversation-scoped caching with smart cache invalidation based on
|
|
16
|
-
* request hash changes. All cache errors are treated as cache misses to ensure
|
|
17
|
-
* system reliability.
|
|
18
|
-
*/
|
|
19
|
-
declare class ContextCache {
|
|
20
|
-
private tenantId;
|
|
21
|
-
private projectId;
|
|
22
|
-
private dbClient;
|
|
23
|
-
constructor(tenantId: string, projectId: string, dbClient: DatabaseClient);
|
|
24
|
-
/**
|
|
25
|
-
* Get cached context data for a conversation
|
|
26
|
-
*/
|
|
27
|
-
get({
|
|
28
|
-
conversationId,
|
|
29
|
-
contextConfigId,
|
|
30
|
-
contextVariableKey,
|
|
31
|
-
requestHash
|
|
32
|
-
}: {
|
|
33
|
-
conversationId: string;
|
|
34
|
-
contextConfigId: string;
|
|
35
|
-
contextVariableKey: string;
|
|
36
|
-
requestHash?: string;
|
|
37
|
-
}): Promise<CacheEntry | null>;
|
|
38
|
-
/**
|
|
39
|
-
* Set cached context data for a conversation
|
|
40
|
-
*/
|
|
41
|
-
set(entry: CacheEntry): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Clear cache entries for a specific conversation
|
|
44
|
-
*/
|
|
45
|
-
clearConversation(tenantId: string, projectId: string, conversationId: string): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Clear all cache entries for a specific context configuration
|
|
48
|
-
*/
|
|
49
|
-
clearContextConfig(tenantId: string, projectId: string, contextConfigId: string): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Clean up expired or orphaned cache entries
|
|
52
|
-
*/
|
|
53
|
-
cleanup(): Promise<void>;
|
|
54
|
-
invalidateInvocationDefinitions(tenantId: string, projectId: string, conversationId: string, contextConfigId: string, definitionIds: string[]): Promise<void>;
|
|
55
|
-
invalidateHeaders(tenantId: string, projectId: string, conversationId: string, contextConfigId: string): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
export { CacheEntry, ContextCache };
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../utils/logger.js";
|
|
2
|
-
import { generateId } from "../utils/conversations.js";
|
|
3
|
-
import { cleanupTenantCache, clearContextConfigCache, clearConversationCache, getCacheEntry, invalidateHeadersCache, invalidateInvocationDefinitionsCache, setCacheEntry } from "../data-access/contextCache.js";
|
|
4
|
-
import "../data-access/index.js";
|
|
5
|
-
|
|
6
|
-
//#region src/context/contextCache.ts
|
|
7
|
-
const logger = getLogger("context-cache");
|
|
8
|
-
/**
|
|
9
|
-
* Context cache with request hash-based invalidation and graceful error handling.
|
|
10
|
-
*
|
|
11
|
-
* Implements conversation-scoped caching with smart cache invalidation based on
|
|
12
|
-
* request hash changes. All cache errors are treated as cache misses to ensure
|
|
13
|
-
* system reliability.
|
|
14
|
-
*/
|
|
15
|
-
var ContextCache = class {
|
|
16
|
-
tenantId;
|
|
17
|
-
projectId;
|
|
18
|
-
dbClient;
|
|
19
|
-
constructor(tenantId, projectId, dbClient) {
|
|
20
|
-
this.tenantId = tenantId;
|
|
21
|
-
this.projectId = projectId;
|
|
22
|
-
this.dbClient = dbClient;
|
|
23
|
-
logger.info({ tenantId: this.tenantId }, "ContextCache initialized");
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get cached context data for a conversation
|
|
27
|
-
*/
|
|
28
|
-
async get({ conversationId, contextConfigId, contextVariableKey, requestHash }) {
|
|
29
|
-
try {
|
|
30
|
-
const cacheEntry = await getCacheEntry(this.dbClient)({
|
|
31
|
-
conversationId,
|
|
32
|
-
contextConfigId,
|
|
33
|
-
contextVariableKey,
|
|
34
|
-
requestHash
|
|
35
|
-
});
|
|
36
|
-
if (!cacheEntry) return null;
|
|
37
|
-
return {
|
|
38
|
-
contextConfigId: cacheEntry.contextConfigId,
|
|
39
|
-
contextVariableKey: cacheEntry.contextVariableKey,
|
|
40
|
-
conversationId: cacheEntry.conversationId,
|
|
41
|
-
value: cacheEntry.value,
|
|
42
|
-
requestHash: cacheEntry.requestHash || void 0,
|
|
43
|
-
tenantId: this.tenantId
|
|
44
|
-
};
|
|
45
|
-
} catch (error) {
|
|
46
|
-
logger.error({
|
|
47
|
-
conversationId,
|
|
48
|
-
contextConfigId,
|
|
49
|
-
contextVariableKey,
|
|
50
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
51
|
-
}, "Failed to get cache entry");
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Set cached context data for a conversation
|
|
57
|
-
*/
|
|
58
|
-
async set(entry) {
|
|
59
|
-
try {
|
|
60
|
-
const cacheData = {
|
|
61
|
-
id: generateId(),
|
|
62
|
-
tenantId: this.tenantId,
|
|
63
|
-
projectId: this.projectId,
|
|
64
|
-
conversationId: entry.conversationId,
|
|
65
|
-
contextConfigId: entry.contextConfigId,
|
|
66
|
-
contextVariableKey: entry.contextVariableKey,
|
|
67
|
-
value: entry.value,
|
|
68
|
-
requestHash: entry.requestHash,
|
|
69
|
-
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
70
|
-
fetchSource: `${entry.contextConfigId}:${entry.contextVariableKey}`,
|
|
71
|
-
fetchDurationMs: 0,
|
|
72
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
73
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
74
|
-
};
|
|
75
|
-
await setCacheEntry(this.dbClient)(cacheData);
|
|
76
|
-
logger.debug({
|
|
77
|
-
conversationId: entry.conversationId,
|
|
78
|
-
contextConfigId: entry.contextConfigId,
|
|
79
|
-
contextVariableKey: entry.contextVariableKey
|
|
80
|
-
}, "Cache entry set successfully");
|
|
81
|
-
} catch (error) {
|
|
82
|
-
logger.error({
|
|
83
|
-
conversationId: entry.conversationId,
|
|
84
|
-
contextConfigId: entry.contextConfigId,
|
|
85
|
-
contextVariableKey: entry.contextVariableKey,
|
|
86
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
87
|
-
}, "Failed to set cache entry");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Clear cache entries for a specific conversation
|
|
92
|
-
*/
|
|
93
|
-
async clearConversation(tenantId, projectId, conversationId) {
|
|
94
|
-
try {
|
|
95
|
-
const result = await clearConversationCache(this.dbClient)({
|
|
96
|
-
scopes: {
|
|
97
|
-
tenantId,
|
|
98
|
-
projectId
|
|
99
|
-
},
|
|
100
|
-
conversationId
|
|
101
|
-
});
|
|
102
|
-
logger.info({
|
|
103
|
-
conversationId,
|
|
104
|
-
rowsCleared: result
|
|
105
|
-
}, "Conversation cache cleared successfully");
|
|
106
|
-
} catch (error) {
|
|
107
|
-
logger.error({
|
|
108
|
-
conversationId,
|
|
109
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
110
|
-
}, "Failed to clear conversation cache");
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Clear all cache entries for a specific context configuration
|
|
116
|
-
*/
|
|
117
|
-
async clearContextConfig(tenantId, projectId, contextConfigId) {
|
|
118
|
-
try {
|
|
119
|
-
const result = await clearContextConfigCache(this.dbClient)({
|
|
120
|
-
scopes: {
|
|
121
|
-
tenantId,
|
|
122
|
-
projectId
|
|
123
|
-
},
|
|
124
|
-
contextConfigId
|
|
125
|
-
});
|
|
126
|
-
logger.info({
|
|
127
|
-
contextConfigId,
|
|
128
|
-
rowsCleared: result
|
|
129
|
-
}, "Context config cache cleared successfully");
|
|
130
|
-
} catch (error) {
|
|
131
|
-
logger.error({
|
|
132
|
-
contextConfigId,
|
|
133
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
134
|
-
}, "Failed to clear context config cache");
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Clean up expired or orphaned cache entries
|
|
140
|
-
*/
|
|
141
|
-
async cleanup() {
|
|
142
|
-
try {
|
|
143
|
-
const result = await cleanupTenantCache(this.dbClient)({ scopes: {
|
|
144
|
-
tenantId: this.tenantId,
|
|
145
|
-
projectId: this.projectId
|
|
146
|
-
} });
|
|
147
|
-
logger.info({ rowsCleared: result }, "Cache cleanup completed");
|
|
148
|
-
} catch (error) {
|
|
149
|
-
logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Failed to cleanup cache");
|
|
150
|
-
throw error;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async invalidateInvocationDefinitions(tenantId, projectId, conversationId, contextConfigId, definitionIds) {
|
|
154
|
-
await invalidateInvocationDefinitionsCache(this.dbClient)({
|
|
155
|
-
scopes: {
|
|
156
|
-
tenantId,
|
|
157
|
-
projectId
|
|
158
|
-
},
|
|
159
|
-
conversationId,
|
|
160
|
-
contextConfigId,
|
|
161
|
-
invocationDefinitionIds: definitionIds
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
async invalidateHeaders(tenantId, projectId, conversationId, contextConfigId) {
|
|
165
|
-
await invalidateHeadersCache(this.dbClient)({
|
|
166
|
-
scopes: {
|
|
167
|
-
tenantId,
|
|
168
|
-
projectId
|
|
169
|
-
},
|
|
170
|
-
conversationId,
|
|
171
|
-
contextConfigId
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
//#endregion
|
|
177
|
-
export { ContextCache };
|