@inkeep/agents-run-api 0.0.0-dev-20260117013710 → 0.0.0-dev-20260117173149
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/agents/Agent.js +7 -9
- package/dist/agents/ModelFactory.js +1 -1
- package/dist/agents/relationTools.d.ts +0 -4
- package/dist/agents/relationTools.js +2 -2
- package/dist/agents/versions/v1/Phase1Config.js +15 -17
- package/dist/agents/versions/v1/Phase2Config.js +1 -1
- package/dist/context/contextCache.js +2 -4
- package/dist/context/validation.js +1 -1
- package/dist/data/agent.js +1 -1
- package/dist/data/conversations.js +43 -24
- package/dist/data/db/dbClient.d.ts +2 -2
- package/dist/routes/chat.js +2 -2
- package/dist/routes/chatDataStream.js +2 -2
- package/dist/routes/mcp.js +6 -6
- package/dist/services/ArtifactService.js +0 -1
- package/dist/services/BaseCompressor.js +3 -3
- package/dist/services/evaluationRunConfigMatcher.d.ts +1 -1
- package/dist/services/evaluationRunConfigMatcher.js +1 -1
- package/dist/utils/model-context-utils.js +3 -3
- package/dist/utils/stream-helpers.d.ts +0 -4
- package/dist/utils/stream-helpers.js +0 -8
- package/dist/utils/token-estimator.d.ts +2 -2
- package/package.json +4 -2
package/dist/agents/Agent.js
CHANGED
|
@@ -315,7 +315,6 @@ var Agent = class {
|
|
|
315
315
|
return [toolName, this.wrapToolWithStreaming(toolName, createTransferToAgentTool({
|
|
316
316
|
transferConfig: agentConfig,
|
|
317
317
|
callingAgentId: this.config.id,
|
|
318
|
-
subAgent: this,
|
|
319
318
|
streamRequestId: runtimeContext?.metadata?.streamRequestId
|
|
320
319
|
}), runtimeContext?.metadata?.streamRequestId, "transfer")];
|
|
321
320
|
}), ...delegateRelations.map((relation) => {
|
|
@@ -332,7 +331,6 @@ var Agent = class {
|
|
|
332
331
|
apiKey: runtimeContext?.metadata?.apiKey
|
|
333
332
|
},
|
|
334
333
|
sessionId,
|
|
335
|
-
subAgent: this,
|
|
336
334
|
credentialStoreRegistry: this.credentialStoreRegistry
|
|
337
335
|
}), runtimeContext?.metadata?.streamRequestId, "delegation")];
|
|
338
336
|
})]);
|
|
@@ -1217,7 +1215,7 @@ var Agent = class {
|
|
|
1217
1215
|
transformationDuration: duration,
|
|
1218
1216
|
hasSimpleArgs: !!simpleArgs,
|
|
1219
1217
|
hasComplexArgs: !!complexArgs,
|
|
1220
|
-
transformation: typeof override.transformation === "string" ? override.transformation.substring(0, 100)
|
|
1218
|
+
transformation: typeof override.transformation === "string" ? `${override.transformation.substring(0, 100)}...` : "object-transformation"
|
|
1221
1219
|
}, "Successfully transformed tool arguments");
|
|
1222
1220
|
} catch (transformError) {
|
|
1223
1221
|
const errorMessage = transformError instanceof Error ? transformError.message : String(transformError);
|
|
@@ -1296,7 +1294,7 @@ var Agent = class {
|
|
|
1296
1294
|
let parsedResult = result;
|
|
1297
1295
|
if (typeof result === "string") try {
|
|
1298
1296
|
parsedResult = JSON.parse(result);
|
|
1299
|
-
} catch
|
|
1297
|
+
} catch {}
|
|
1300
1298
|
const cleanResult = parsedResult && typeof parsedResult === "object" && !Array.isArray(parsedResult) ? {
|
|
1301
1299
|
...parsedResult,
|
|
1302
1300
|
result: parsedResult.result && typeof parsedResult.result === "object" && !Array.isArray(parsedResult.result) ? Object.fromEntries(Object.entries(parsedResult.result).filter(([key]) => key !== "_structureHints")) : parsedResult.result
|
|
@@ -1464,7 +1462,7 @@ ${typeof cleanResult === "string" ? cleanResult : JSON.stringify(cleanResult, nu
|
|
|
1464
1462
|
try {
|
|
1465
1463
|
const subAgents = this.executionContext.project.agents[this.config.agentId]?.subAgents;
|
|
1466
1464
|
if (!subAgents) return false;
|
|
1467
|
-
return Object.values(subAgents).some((subAgent) => subAgent.artifactComponents?.length
|
|
1465
|
+
return Object.values(subAgents).some((subAgent) => subAgent.artifactComponents?.length);
|
|
1468
1466
|
} catch (error) {
|
|
1469
1467
|
logger.error({
|
|
1470
1468
|
error,
|
|
@@ -1798,10 +1796,10 @@ ${typeof cleanResult === "string" ? cleanResult : JSON.stringify(cleanResult, nu
|
|
|
1798
1796
|
} catch (error) {
|
|
1799
1797
|
logger.debug({ error }, "Failed to track agent reasoning");
|
|
1800
1798
|
}
|
|
1801
|
-
if (!includeThinkingComplete && last && last
|
|
1802
|
-
const lastContent = last
|
|
1803
|
-
if (lastContent
|
|
1804
|
-
const error = lastContent
|
|
1799
|
+
if (!includeThinkingComplete && last && last.content && last.content.length > 0) {
|
|
1800
|
+
const lastContent = last.content[last.content.length - 1];
|
|
1801
|
+
if (lastContent.type === "tool-error") {
|
|
1802
|
+
const error = lastContent.error;
|
|
1805
1803
|
if (error && typeof error === "object" && "name" in error && error.name === "connection_refused") return true;
|
|
1806
1804
|
}
|
|
1807
1805
|
}
|
|
@@ -49,7 +49,7 @@ var ModelFactory = class ModelFactory {
|
|
|
49
49
|
logger.info({ config: {
|
|
50
50
|
baseURL: customConfig.baseURL,
|
|
51
51
|
hasApiKey: !!process.env.CUSTOM_LLM_API_KEY,
|
|
52
|
-
apiKeyPrefix: process.env.CUSTOM_LLM_API_KEY?.substring(0, 10)
|
|
52
|
+
apiKeyPrefix: `${process.env.CUSTOM_LLM_API_KEY?.substring(0, 10)}...`,
|
|
53
53
|
headers: Object.keys(customConfig.headers || {})
|
|
54
54
|
} }, "Creating custom OpenAI-compatible provider");
|
|
55
55
|
return createOpenAICompatible(customConfig);
|
|
@@ -8,12 +8,10 @@ import * as ai0 from "ai";
|
|
|
8
8
|
declare const createTransferToAgentTool: ({
|
|
9
9
|
transferConfig,
|
|
10
10
|
callingAgentId,
|
|
11
|
-
subAgent,
|
|
12
11
|
streamRequestId
|
|
13
12
|
}: {
|
|
14
13
|
transferConfig: AgentConfig;
|
|
15
14
|
callingAgentId: string;
|
|
16
|
-
subAgent: any;
|
|
17
15
|
streamRequestId?: string;
|
|
18
16
|
}) => ai0.Tool<Record<string, never>, {
|
|
19
17
|
type: string;
|
|
@@ -27,7 +25,6 @@ declare function createDelegateToAgentTool({
|
|
|
27
25
|
contextId,
|
|
28
26
|
metadata,
|
|
29
27
|
sessionId,
|
|
30
|
-
subAgent,
|
|
31
28
|
credentialStoreRegistry
|
|
32
29
|
}: {
|
|
33
30
|
delegateConfig: DelegateRelation;
|
|
@@ -42,7 +39,6 @@ declare function createDelegateToAgentTool({
|
|
|
42
39
|
apiKey?: string;
|
|
43
40
|
};
|
|
44
41
|
sessionId?: string;
|
|
45
|
-
subAgent: any;
|
|
46
42
|
credentialStoreRegistry?: CredentialStoreRegistry;
|
|
47
43
|
}): ai0.Tool<{
|
|
48
44
|
message: string;
|
|
@@ -97,7 +97,7 @@ Delegate a specific task to agent ${config.id} when it can do relevant work. The
|
|
|
97
97
|
|
|
98
98
|
NOTE: Unlike transfers, delegation returns control back to you with the delegated agent's results.`;
|
|
99
99
|
};
|
|
100
|
-
const createTransferToAgentTool = ({ transferConfig, callingAgentId,
|
|
100
|
+
const createTransferToAgentTool = ({ transferConfig, callingAgentId, streamRequestId }) => {
|
|
101
101
|
return tool({
|
|
102
102
|
description: generateTransferToolDescription(transferConfig),
|
|
103
103
|
inputSchema: z.object({}),
|
|
@@ -129,7 +129,7 @@ const createTransferToAgentTool = ({ transferConfig, callingAgentId, subAgent, s
|
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
};
|
|
132
|
-
function createDelegateToAgentTool({ delegateConfig, callingAgentId, executionContext, contextId, metadata, sessionId,
|
|
132
|
+
function createDelegateToAgentTool({ delegateConfig, callingAgentId, executionContext, contextId, metadata, sessionId, credentialStoreRegistry }) {
|
|
133
133
|
const { tenantId, projectId, agentId, project } = executionContext;
|
|
134
134
|
return tool({
|
|
135
135
|
description: generateDelegateToolDescription(delegateConfig),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getLogger as getLogger$1 } from "../../../logger.js";
|
|
2
1
|
import { calculateBreakdownTotal, createEmptyBreakdown, estimateTokens } from "../../../utils/token-estimator.js";
|
|
3
2
|
import system_prompt_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js";
|
|
4
3
|
import thinking_preparation_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js";
|
|
@@ -9,7 +8,6 @@ import { V1_BREAKDOWN_SCHEMA } from "@inkeep/agents-core";
|
|
|
9
8
|
import { convertZodToJsonSchema, isZodSchema } from "@inkeep/agents-core/utils/schema-conversion";
|
|
10
9
|
|
|
11
10
|
//#region src/agents/versions/v1/Phase1Config.ts
|
|
12
|
-
getLogger$1("Phase1Config");
|
|
13
11
|
var Phase1Config = class Phase1Config {
|
|
14
12
|
loadTemplates() {
|
|
15
13
|
const templates = /* @__PURE__ */ new Map();
|
|
@@ -48,7 +46,7 @@ var Phase1Config = class Phase1Config {
|
|
|
48
46
|
if (!inputSchema || typeof inputSchema !== "object") return inputSchema || {};
|
|
49
47
|
if (isZodSchema(inputSchema)) try {
|
|
50
48
|
return convertZodToJsonSchema(inputSchema);
|
|
51
|
-
} catch
|
|
49
|
+
} catch {
|
|
52
50
|
return {};
|
|
53
51
|
}
|
|
54
52
|
return inputSchema;
|
|
@@ -57,17 +55,17 @@ var Phase1Config = class Phase1Config {
|
|
|
57
55
|
const breakdown = createEmptyBreakdown(this.getBreakdownSchema());
|
|
58
56
|
const systemPromptTemplateContent = templates.get("system-prompt");
|
|
59
57
|
if (!systemPromptTemplateContent) throw new Error("System prompt template not loaded");
|
|
60
|
-
breakdown.components
|
|
58
|
+
breakdown.components.systemPromptTemplate = estimateTokens(systemPromptTemplateContent.replace("{{CORE_INSTRUCTIONS}}", "").replace("{{CURRENT_TIME_SECTION}}", "").replace("{{AGENT_CONTEXT_SECTION}}", "").replace("{{ARTIFACTS_SECTION}}", "").replace("{{TOOLS_SECTION}}", "").replace("{{THINKING_PREPARATION_INSTRUCTIONS}}", "").replace("{{TRANSFER_INSTRUCTIONS}}", "").replace("{{DELEGATION_INSTRUCTIONS}}", ""));
|
|
61
59
|
let systemPrompt = systemPromptTemplateContent;
|
|
62
|
-
if (config.corePrompt
|
|
63
|
-
breakdown.components
|
|
60
|
+
if (config.corePrompt?.trim()) {
|
|
61
|
+
breakdown.components.coreInstructions = estimateTokens(config.corePrompt);
|
|
64
62
|
systemPrompt = systemPrompt.replace("{{CORE_INSTRUCTIONS}}", config.corePrompt);
|
|
65
63
|
} else systemPrompt = systemPrompt.replace(/<core_instructions>\s*\{\{CORE_INSTRUCTIONS\}\}\s*<\/core_instructions>/g, "");
|
|
66
64
|
const currentTimeSection = this.generateCurrentTimeSection(config.clientCurrentTime);
|
|
67
|
-
breakdown.components
|
|
65
|
+
breakdown.components.currentTime = estimateTokens(currentTimeSection);
|
|
68
66
|
systemPrompt = systemPrompt.replace("{{CURRENT_TIME_SECTION}}", currentTimeSection);
|
|
69
67
|
const agentContextSection = this.generateAgentContextSection(config.prompt);
|
|
70
|
-
breakdown.components
|
|
68
|
+
breakdown.components.agentPrompt = estimateTokens(agentContextSection);
|
|
71
69
|
systemPrompt = systemPrompt.replace("{{AGENT_CONTEXT_SECTION}}", agentContextSection);
|
|
72
70
|
const toolData = (this.isToolDataArray(config.tools) ? config.tools : Phase1Config.convertMcpToolsToToolData(config.tools)).map((tool) => ({
|
|
73
71
|
...tool,
|
|
@@ -75,26 +73,26 @@ var Phase1Config = class Phase1Config {
|
|
|
75
73
|
}));
|
|
76
74
|
const hasArtifactComponents = Boolean(config.artifactComponents && config.artifactComponents.length > 0);
|
|
77
75
|
const artifactsSection = this.generateArtifactsSection(templates, config.artifacts, hasArtifactComponents, config.artifactComponents, config.hasAgentArtifactComponents);
|
|
78
|
-
const artifactInstructionsTokens = this.getArtifactInstructionsTokens(templates, hasArtifactComponents, config.
|
|
79
|
-
breakdown.components
|
|
76
|
+
const artifactInstructionsTokens = this.getArtifactInstructionsTokens(templates, hasArtifactComponents, config.hasAgentArtifactComponents, (config.artifacts?.length ?? 0) > 0);
|
|
77
|
+
breakdown.components.systemPromptTemplate += artifactInstructionsTokens;
|
|
80
78
|
const actualArtifactsXml = config.artifacts?.length > 0 ? config.artifacts.map((artifact) => this.generateArtifactXml(templates, artifact)).join("\n ") : "";
|
|
81
|
-
breakdown.components
|
|
79
|
+
breakdown.components.artifactsSection = estimateTokens(actualArtifactsXml);
|
|
82
80
|
if (hasArtifactComponents) {
|
|
83
81
|
const creationInstructions = this.getArtifactCreationInstructions(hasArtifactComponents, config.artifactComponents);
|
|
84
|
-
breakdown.components
|
|
82
|
+
breakdown.components.artifactComponents = estimateTokens(creationInstructions);
|
|
85
83
|
}
|
|
86
84
|
systemPrompt = systemPrompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
|
|
87
85
|
const toolsSection = this.generateToolsSection(templates, toolData);
|
|
88
|
-
breakdown.components
|
|
86
|
+
breakdown.components.toolsSection = estimateTokens(toolsSection);
|
|
89
87
|
systemPrompt = systemPrompt.replace("{{TOOLS_SECTION}}", toolsSection);
|
|
90
88
|
const thinkingPreparationSection = this.generateThinkingPreparationSection(templates, config.isThinkingPreparation);
|
|
91
|
-
breakdown.components
|
|
89
|
+
breakdown.components.thinkingPreparation = estimateTokens(thinkingPreparationSection);
|
|
92
90
|
systemPrompt = systemPrompt.replace("{{THINKING_PREPARATION_INSTRUCTIONS}}", thinkingPreparationSection);
|
|
93
91
|
const transferSection = this.generateTransferInstructions(config.hasTransferRelations);
|
|
94
|
-
breakdown.components
|
|
92
|
+
breakdown.components.transferInstructions = estimateTokens(transferSection);
|
|
95
93
|
systemPrompt = systemPrompt.replace("{{TRANSFER_INSTRUCTIONS}}", transferSection);
|
|
96
94
|
const delegationSection = this.generateDelegationInstructions(config.hasDelegateRelations);
|
|
97
|
-
breakdown.components
|
|
95
|
+
breakdown.components.delegationInstructions = estimateTokens(delegationSection);
|
|
98
96
|
systemPrompt = systemPrompt.replace("{{DELEGATION_INSTRUCTIONS}}", delegationSection);
|
|
99
97
|
calculateBreakdownTotal(breakdown);
|
|
100
98
|
return {
|
|
@@ -163,7 +161,7 @@ Your goal: preserve the illusion of a single, seamless, intelligent assistant. A
|
|
|
163
161
|
- Present results as YOUR work: "I found", "I've analyzed"
|
|
164
162
|
- NEVER say you're delegating or that another agent helped`;
|
|
165
163
|
}
|
|
166
|
-
getArtifactInstructionsTokens(templates, hasArtifactComponents,
|
|
164
|
+
getArtifactInstructionsTokens(templates, hasArtifactComponents, hasAgentArtifactComponents, hasArtifacts) {
|
|
167
165
|
const shouldShowReferencingRules = hasAgentArtifactComponents || hasArtifacts;
|
|
168
166
|
const rules = this.getArtifactReferencingRules(hasArtifactComponents, templates, shouldShowReferencingRules);
|
|
169
167
|
return estimateTokens(`<available_artifacts description="${hasArtifacts ? "These are the artifacts available for you to use in generating responses." : "No artifacts are currently available, but you may create them during execution."}
|
|
@@ -325,7 +325,7 @@ ${artifact_retrieval_guidance_default}
|
|
|
325
325
|
const artifactGuidance = this.getStructuredArtifactGuidance(hasArtifactComponents, artifactComponents, shouldShowReferencingRules);
|
|
326
326
|
const artifactTypes = this.getArtifactCreationInstructions(hasArtifactComponents, artifactComponents);
|
|
327
327
|
let phase2Prompt = system_prompt_default;
|
|
328
|
-
if (corePrompt
|
|
328
|
+
if (corePrompt?.trim()) phase2Prompt = phase2Prompt.replace("{{CORE_INSTRUCTIONS}}", corePrompt);
|
|
329
329
|
else phase2Prompt = phase2Prompt.replace(/<core_instructions>\s*\{\{CORE_INSTRUCTIONS\}\}\s*<\/core_instructions>/g, "");
|
|
330
330
|
const currentTimeSection = this.generateCurrentTimeSection(clientCurrentTime);
|
|
331
331
|
phase2Prompt = phase2Prompt.replace("{{CURRENT_TIME_SECTION}}", currentTimeSection);
|
|
@@ -21,8 +21,7 @@ var ContextCache = class {
|
|
|
21
21
|
*/
|
|
22
22
|
async get({ conversationId, contextConfigId, contextVariableKey, requestHash }) {
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
cacheEntry = await getCacheEntry(dbClient_default)({
|
|
24
|
+
const cacheEntry = await getCacheEntry(dbClient_default)({
|
|
26
25
|
conversationId,
|
|
27
26
|
contextConfigId,
|
|
28
27
|
contextVariableKey,
|
|
@@ -88,8 +87,7 @@ var ContextCache = class {
|
|
|
88
87
|
*/
|
|
89
88
|
async clearConversation(tenantId, projectId, conversationId) {
|
|
90
89
|
try {
|
|
91
|
-
|
|
92
|
-
result = await clearConversationCache(dbClient_default)({
|
|
90
|
+
const result = await clearConversationCache(dbClient_default)({
|
|
93
91
|
scopes: {
|
|
94
92
|
tenantId,
|
|
95
93
|
projectId
|
|
@@ -205,7 +205,7 @@ async function validateHeaders({ executionContext, conversationId, parsedRequest
|
|
|
205
205
|
async function contextValidationMiddleware(c, next) {
|
|
206
206
|
try {
|
|
207
207
|
const executionContext = c.get("executionContext");
|
|
208
|
-
let { tenantId, projectId, agentId
|
|
208
|
+
let { tenantId, projectId, agentId } = executionContext;
|
|
209
209
|
if (!tenantId || !projectId || !agentId) {
|
|
210
210
|
tenantId = c.req.param("tenantId");
|
|
211
211
|
projectId = c.req.param("projectId");
|
package/dist/data/agent.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTa
|
|
|
3
3
|
|
|
4
4
|
//#region src/data/agent.ts
|
|
5
5
|
async function hydrateAgent({ dbAgent, executionContext, baseUrl }) {
|
|
6
|
-
const { tenantId, projectId, agentId, project,
|
|
6
|
+
const { tenantId, projectId, agentId, project, apiKey } = executionContext;
|
|
7
7
|
try {
|
|
8
8
|
if (!dbAgent.defaultSubAgentId) throw new Error(`Agent ${dbAgent.id} does not have a default agent configured`);
|
|
9
9
|
const subAgentId = dbAgent.defaultSubAgentId;
|
|
@@ -269,17 +269,14 @@ async function getConversationHistoryWithCompression({ tenantId, projectId, conv
|
|
|
269
269
|
}, "Re-compression completed - combined with existing summary");
|
|
270
270
|
} else messagesToFormat = [compressionSummary, ...messagesAfterCompression];
|
|
271
271
|
}
|
|
272
|
-
} else {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
fullContextSize
|
|
281
|
-
});
|
|
282
|
-
}
|
|
272
|
+
} else messagesToFormat = await compressConversationIfNeeded(messagesToFormat, {
|
|
273
|
+
conversationId,
|
|
274
|
+
tenantId,
|
|
275
|
+
projectId,
|
|
276
|
+
summarizerModel,
|
|
277
|
+
streamRequestId,
|
|
278
|
+
fullContextSize
|
|
279
|
+
});
|
|
283
280
|
const compressedTokens = messagesToFormat.reduce((total, msg) => {
|
|
284
281
|
const text = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
285
282
|
return total + Math.ceil(text.length / 4);
|
|
@@ -299,7 +296,7 @@ async function getConversationHistoryWithCompression({ tenantId, projectId, conv
|
|
|
299
296
|
* Apply conversation compression using the BaseCompressor infrastructure
|
|
300
297
|
*/
|
|
301
298
|
async function compressConversationIfNeeded(messages, params) {
|
|
302
|
-
const { conversationId, tenantId, projectId
|
|
299
|
+
const { conversationId, tenantId, projectId } = params;
|
|
303
300
|
const lockKey = `${conversationId}_${tenantId}_${projectId}`;
|
|
304
301
|
if (compressionLocks.has(lockKey)) {
|
|
305
302
|
logger.debug({ conversationId }, "Waiting for existing compression to complete");
|
|
@@ -375,58 +372,80 @@ function buildCompressionSummaryMessage(summary, artifactIds) {
|
|
|
375
372
|
parts.push(`🎯 Primary Goal: ${summary.user_goals.primary}`);
|
|
376
373
|
if (summary.user_goals.secondary && summary.user_goals.secondary.length > 0) {
|
|
377
374
|
parts.push(`🎯 Secondary Goals:`);
|
|
378
|
-
summary.user_goals.secondary.forEach((goal) =>
|
|
375
|
+
summary.user_goals.secondary.forEach((goal) => {
|
|
376
|
+
parts.push(` • ${goal}`);
|
|
377
|
+
});
|
|
379
378
|
}
|
|
380
379
|
}
|
|
381
380
|
if (summary.key_outcomes) {
|
|
382
381
|
if (summary.key_outcomes.completed && summary.key_outcomes.completed.length > 0) {
|
|
383
382
|
parts.push(`✅ Completed:`);
|
|
384
|
-
summary.key_outcomes.completed.forEach((item) =>
|
|
383
|
+
summary.key_outcomes.completed.forEach((item) => {
|
|
384
|
+
parts.push(` • ${item}`);
|
|
385
|
+
});
|
|
385
386
|
}
|
|
386
387
|
if (summary.key_outcomes.discoveries && summary.key_outcomes.discoveries.length > 0) {
|
|
387
388
|
parts.push(`💡 Key Discoveries:`);
|
|
388
|
-
summary.key_outcomes.discoveries.forEach((discovery) =>
|
|
389
|
+
summary.key_outcomes.discoveries.forEach((discovery) => {
|
|
390
|
+
parts.push(` • ${discovery}`);
|
|
391
|
+
});
|
|
389
392
|
}
|
|
390
393
|
if (summary.key_outcomes.partial && summary.key_outcomes.partial.length > 0) {
|
|
391
394
|
parts.push(`⏳ In Progress:`);
|
|
392
|
-
summary.key_outcomes.partial.forEach((item) =>
|
|
395
|
+
summary.key_outcomes.partial.forEach((item) => {
|
|
396
|
+
parts.push(` • ${item}`);
|
|
397
|
+
});
|
|
393
398
|
}
|
|
394
399
|
}
|
|
395
400
|
if (summary.context_for_continuation) {
|
|
396
401
|
if (summary.context_for_continuation.current_state) parts.push(`📍 Current State: ${summary.context_for_continuation.current_state}`);
|
|
397
402
|
if (summary.context_for_continuation.next_logical_steps && summary.context_for_continuation.next_logical_steps.length > 0) {
|
|
398
403
|
parts.push(`📝 Next Steps:`);
|
|
399
|
-
summary.context_for_continuation.next_logical_steps.forEach((step) =>
|
|
404
|
+
summary.context_for_continuation.next_logical_steps.forEach((step) => {
|
|
405
|
+
parts.push(` • ${step}`);
|
|
406
|
+
});
|
|
400
407
|
}
|
|
401
408
|
if (summary.context_for_continuation.important_context && summary.context_for_continuation.important_context.length > 0) {
|
|
402
409
|
parts.push(`🔑 Key Context:`);
|
|
403
|
-
summary.context_for_continuation.important_context.forEach((context) =>
|
|
410
|
+
summary.context_for_continuation.important_context.forEach((context) => {
|
|
411
|
+
parts.push(` • ${context}`);
|
|
412
|
+
});
|
|
404
413
|
}
|
|
405
414
|
}
|
|
406
415
|
if (summary.technical_context) {
|
|
407
416
|
if (summary.technical_context.technologies && summary.technical_context.technologies.length > 0) parts.push(`🔧 Technologies: ${summary.technical_context.technologies.join(", ")}`);
|
|
408
417
|
if (summary.technical_context.issues_encountered && summary.technical_context.issues_encountered.length > 0) {
|
|
409
418
|
parts.push(`⚠️ Issues Encountered:`);
|
|
410
|
-
summary.technical_context.issues_encountered.forEach((issue) =>
|
|
419
|
+
summary.technical_context.issues_encountered.forEach((issue) => {
|
|
420
|
+
parts.push(` • ${issue}`);
|
|
421
|
+
});
|
|
411
422
|
}
|
|
412
423
|
if (summary.technical_context.solutions_applied && summary.technical_context.solutions_applied.length > 0) {
|
|
413
424
|
parts.push(`✨ Solutions Applied:`);
|
|
414
|
-
summary.technical_context.solutions_applied.forEach((solution) =>
|
|
425
|
+
summary.technical_context.solutions_applied.forEach((solution) => {
|
|
426
|
+
parts.push(` • ${solution}`);
|
|
427
|
+
});
|
|
415
428
|
}
|
|
416
429
|
}
|
|
417
430
|
if (summary.high_level) parts.push(`📋 Overview: ${summary.high_level}`);
|
|
418
431
|
if (summary.user_intent) parts.push(`🎯 User Goal: ${summary.user_intent}`);
|
|
419
432
|
if (summary.decisions && summary.decisions.length > 0) {
|
|
420
433
|
parts.push(`✅ Key Decisions Made:`);
|
|
421
|
-
summary.decisions.forEach((decision) =>
|
|
434
|
+
summary.decisions.forEach((decision) => {
|
|
435
|
+
parts.push(` • ${decision}`);
|
|
436
|
+
});
|
|
422
437
|
}
|
|
423
438
|
if (summary.next_steps && summary.next_steps.length > 0) {
|
|
424
439
|
parts.push(`📝 Planned Next Steps:`);
|
|
425
|
-
summary.next_steps.forEach((step) =>
|
|
440
|
+
summary.next_steps.forEach((step) => {
|
|
441
|
+
parts.push(` • ${step}`);
|
|
442
|
+
});
|
|
426
443
|
}
|
|
427
444
|
if (summary.open_questions && summary.open_questions.length > 0) {
|
|
428
445
|
parts.push(`❓ Outstanding Questions:`);
|
|
429
|
-
summary.open_questions.forEach((question) =>
|
|
446
|
+
summary.open_questions.forEach((question) => {
|
|
447
|
+
parts.push(` • ${question}`);
|
|
448
|
+
});
|
|
430
449
|
}
|
|
431
450
|
if (summary.conversation_artifacts && summary.conversation_artifacts.length > 0) {
|
|
432
451
|
parts.push(`💾 Research Artifacts: ${summary.conversation_artifacts.length} created from previous work`);
|
|
@@ -471,7 +490,7 @@ function formatMessagesAsConversationHistory(messages) {
|
|
|
471
490
|
* Uses the same scoping logic as getFormattedConversationHistory
|
|
472
491
|
*/
|
|
473
492
|
async function getConversationScopedArtifacts(params) {
|
|
474
|
-
const { tenantId, projectId, conversationId, historyConfig
|
|
493
|
+
const { tenantId, projectId, conversationId, historyConfig } = params;
|
|
475
494
|
if (!conversationId) return [];
|
|
476
495
|
try {
|
|
477
496
|
if (historyConfig.mode === "none") return [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _inkeep_agents_core2 from "@inkeep/agents-core";
|
|
2
2
|
|
|
3
3
|
//#region src/data/db/dbClient.d.ts
|
|
4
|
-
declare const dbClient:
|
|
4
|
+
declare const dbClient: _inkeep_agents_core2.AgentsRunDatabaseClient;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { dbClient as default };
|
package/dist/routes/chat.js
CHANGED
|
@@ -104,7 +104,7 @@ app.openapi(chatCompletionsRoute, async (c) => {
|
|
|
104
104
|
}, "OpenTelemetry headers: chat");
|
|
105
105
|
try {
|
|
106
106
|
const executionContext = c.get("executionContext");
|
|
107
|
-
const { tenantId, projectId, agentId
|
|
107
|
+
const { tenantId, projectId, agentId } = executionContext;
|
|
108
108
|
getLogger$1("chat").debug({
|
|
109
109
|
tenantId,
|
|
110
110
|
agentId
|
|
@@ -235,7 +235,7 @@ app.openapi(chatCompletionsRoute, async (c) => {
|
|
|
235
235
|
if (xForwardedCookie) forwardedHeaders["x-forwarded-cookie"] = xForwardedCookie;
|
|
236
236
|
else if (cookie) forwardedHeaders["x-forwarded-cookie"] = cookie;
|
|
237
237
|
if (clientTimezone && clientTimestamp) {
|
|
238
|
-
const isValidTimezone = clientTimezone.length < 100 && /^[A-Za-z0-9_
|
|
238
|
+
const isValidTimezone = clientTimezone.length < 100 && /^[A-Za-z0-9_/\-+]+$/.test(clientTimezone);
|
|
239
239
|
const isValidTimestamp = clientTimestamp.length < 50 && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/.test(clientTimestamp);
|
|
240
240
|
if (isValidTimezone && isValidTimestamp) {
|
|
241
241
|
forwardedHeaders["x-inkeep-client-timezone"] = clientTimezone;
|
|
@@ -67,7 +67,7 @@ app.use("/chat", contextValidationMiddleware);
|
|
|
67
67
|
app.openapi(chatDataStreamRoute, async (c) => {
|
|
68
68
|
try {
|
|
69
69
|
const executionContext = c.get("executionContext");
|
|
70
|
-
const { tenantId, projectId, agentId
|
|
70
|
+
const { tenantId, projectId, agentId } = executionContext;
|
|
71
71
|
loggerFactory.getLogger("chatDataStream").debug({
|
|
72
72
|
tenantId,
|
|
73
73
|
projectId,
|
|
@@ -86,7 +86,7 @@ app.openapi(chatDataStreamRoute, async (c) => {
|
|
|
86
86
|
if (xForwardedCookie) forwardedHeaders["x-forwarded-cookie"] = xForwardedCookie;
|
|
87
87
|
else if (cookie) forwardedHeaders["x-forwarded-cookie"] = cookie;
|
|
88
88
|
if (clientTimezone && clientTimestamp) {
|
|
89
|
-
const isValidTimezone = clientTimezone.length < 100 && /^[A-Za-z0-9_
|
|
89
|
+
const isValidTimezone = clientTimezone.length < 100 && /^[A-Za-z0-9_/\-+]+$/.test(clientTimezone);
|
|
90
90
|
const isValidTimestamp = clientTimestamp.length < 50 && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/.test(clientTimestamp);
|
|
91
91
|
if (isValidTimezone && isValidTimestamp) {
|
|
92
92
|
forwardedHeaders["x-inkeep-client-timezone"] = clientTimezone;
|
package/dist/routes/mcp.js
CHANGED
|
@@ -86,7 +86,7 @@ const spoofTransportInitialization = async (transport, req, sessionId, mcpProtoc
|
|
|
86
86
|
}, "Spoof initialization failed, continuing anyway");
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
|
-
const validateSession = async (req, res, body, tenantId, projectId, agentId
|
|
89
|
+
const validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
90
90
|
const sessionId = req.headers["mcp-session-id"];
|
|
91
91
|
logger.info({ sessionId }, "Received MCP session ID");
|
|
92
92
|
if (!sessionId) {
|
|
@@ -157,7 +157,7 @@ const setupTracing = (conversationId, tenantId, agentId) => {
|
|
|
157
157
|
/**
|
|
158
158
|
* Processes and stores the user message
|
|
159
159
|
*/
|
|
160
|
-
const processUserMessage = async (tenantId, projectId, conversationId, query
|
|
160
|
+
const processUserMessage = async (tenantId, projectId, conversationId, query) => {
|
|
161
161
|
const messageSpan = trace.getActiveSpan();
|
|
162
162
|
if (messageSpan) messageSpan.setAttributes({
|
|
163
163
|
"message.content": query,
|
|
@@ -205,7 +205,7 @@ const executeAgentQuery = async (executionContext, conversationId, query, defaul
|
|
|
205
205
|
* Creates and configures an MCP server for the given context
|
|
206
206
|
*/
|
|
207
207
|
const getServer = async (headers$1, executionContext, conversationId, credentialStores) => {
|
|
208
|
-
const { tenantId, projectId, agentId
|
|
208
|
+
const { tenantId, projectId, agentId } = executionContext;
|
|
209
209
|
setupTracing(conversationId, tenantId, agentId);
|
|
210
210
|
const agent = executionContext.project.agents[agentId];
|
|
211
211
|
if (!agent) throw new Error("Agent not found");
|
|
@@ -245,7 +245,7 @@ const getServer = async (headers$1, executionContext, conversationId, credential
|
|
|
245
245
|
hasHeaders: !!headers$1,
|
|
246
246
|
hasValidatedContext: !!resolvedContext
|
|
247
247
|
}, "parameters");
|
|
248
|
-
await processUserMessage(tenantId, projectId, conversationId, query
|
|
248
|
+
await processUserMessage(tenantId, projectId, conversationId, query);
|
|
249
249
|
return executeAgentQuery(executionContext, conversationId, query, defaultSubAgentId);
|
|
250
250
|
} catch (error) {
|
|
251
251
|
return {
|
|
@@ -368,8 +368,8 @@ const handleInitializationRequest = async (body, executionContext, validatedCont
|
|
|
368
368
|
* Handles requests for existing MCP sessions
|
|
369
369
|
*/
|
|
370
370
|
const handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
371
|
-
const { tenantId, projectId, agentId
|
|
372
|
-
const conversation = await validateSession(req, res, body, tenantId, projectId, agentId
|
|
371
|
+
const { tenantId, projectId, agentId } = executionContext;
|
|
372
|
+
const conversation = await validateSession(req, res, body, tenantId, projectId, agentId);
|
|
373
373
|
if (!conversation) return toFetchResponse(res);
|
|
374
374
|
const sessionId = conversation.id;
|
|
375
375
|
await updateConversation(dbClient_default)({
|
|
@@ -370,7 +370,6 @@ var ArtifactService = class ArtifactService {
|
|
|
370
370
|
const summaryValidation = validateAgainstSchema(summaryData, previewSchema);
|
|
371
371
|
const fullValidation = validateAgainstSchema(fullData, fullSchema);
|
|
372
372
|
if (!summaryValidation.hasRequiredFields) {
|
|
373
|
-
`${summaryValidation.missingRequired.join(", ")}${artifactType}${summaryValidation.missingRequired.join(", ")}${summaryValidation.actualFields.join(", ")}`;
|
|
374
373
|
logger.error({
|
|
375
374
|
artifactId,
|
|
376
375
|
artifactType,
|
|
@@ -4,9 +4,9 @@ import { distillConversation } from "../tools/distill-conversation-tool.js";
|
|
|
4
4
|
import { getCompressionConfigForModel } from "../utils/model-context-utils.js";
|
|
5
5
|
import { tracer } from "../utils/tracer.js";
|
|
6
6
|
import { agentSessionManager } from "./AgentSession.js";
|
|
7
|
-
import { getLedgerArtifacts
|
|
7
|
+
import { getLedgerArtifacts } from "@inkeep/agents-core";
|
|
8
8
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
9
|
-
import { randomUUID } from "crypto";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
10
|
|
|
11
11
|
//#region src/services/BaseCompressor.ts
|
|
12
12
|
const logger = getLogger$1("BaseCompressor");
|
|
@@ -313,7 +313,7 @@ var BaseCompressor = class {
|
|
|
313
313
|
else if (typeof toolResult === "object") preview = JSON.stringify(toolResult);
|
|
314
314
|
else preview = String(toolResult);
|
|
315
315
|
return preview.slice(0, 150).replace(/\s+/g, " ").trim() + (preview.length > 150 ? "..." : "");
|
|
316
|
-
} catch
|
|
316
|
+
} catch {
|
|
317
317
|
return "Preview unavailable";
|
|
318
318
|
}
|
|
319
319
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { conversations } from "@inkeep/agents-core";
|
|
2
2
|
|
|
3
3
|
//#region src/services/evaluationRunConfigMatcher.d.ts
|
|
4
|
-
declare function evaluationRunConfigMatchesConversation(
|
|
4
|
+
declare function evaluationRunConfigMatchesConversation(_runConfig: any, _conversation: typeof conversations.$inferSelect): Promise<boolean>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { evaluationRunConfigMatchesConversation };
|
|
@@ -50,7 +50,7 @@ function getModelContextWindow(modelSettings) {
|
|
|
50
50
|
}
|
|
51
51
|
try {
|
|
52
52
|
const modelDetails = ModelInfoMap[modelId];
|
|
53
|
-
if (modelDetails
|
|
53
|
+
if (modelDetails?.contextWindowTokenLimit && modelDetails.contextWindowTokenLimit > 0) {
|
|
54
54
|
logger.debug({
|
|
55
55
|
modelId,
|
|
56
56
|
contextWindow: modelDetails.contextWindowTokenLimit,
|
|
@@ -112,8 +112,8 @@ function getCompressionParams(contextWindow) {
|
|
|
112
112
|
*/
|
|
113
113
|
function getCompressionConfigForModel(modelSettings, targetPercentage) {
|
|
114
114
|
const modelContextInfo = getModelContextWindow(modelSettings);
|
|
115
|
-
const envHardLimit = parseInt(process.env.AGENTS_COMPRESSION_HARD_LIMIT || COMPRESSION_HARD_LIMIT.toString());
|
|
116
|
-
const envSafetyBuffer = parseInt(process.env.AGENTS_COMPRESSION_SAFETY_BUFFER || COMPRESSION_SAFETY_BUFFER.toString());
|
|
115
|
+
const envHardLimit = parseInt(process.env.AGENTS_COMPRESSION_HARD_LIMIT || COMPRESSION_HARD_LIMIT.toString(), 10);
|
|
116
|
+
const envSafetyBuffer = parseInt(process.env.AGENTS_COMPRESSION_SAFETY_BUFFER || COMPRESSION_SAFETY_BUFFER.toString(), 10);
|
|
117
117
|
const enabled = process.env.AGENTS_COMPRESSION_ENABLED !== "false" && COMPRESSION_ENABLED;
|
|
118
118
|
if (modelContextInfo.hasValidContextWindow && modelContextInfo.contextWindow) {
|
|
119
119
|
let hardLimit;
|
|
@@ -94,7 +94,6 @@ declare class VercelDataStreamHelper implements StreamHelper {
|
|
|
94
94
|
private jsonBuffer;
|
|
95
95
|
private sentItems;
|
|
96
96
|
private completedItems;
|
|
97
|
-
private sessionId?;
|
|
98
97
|
private static readonly MAX_BUFFER_SIZE;
|
|
99
98
|
private isCompleted;
|
|
100
99
|
private isTextStreaming;
|
|
@@ -102,7 +101,6 @@ declare class VercelDataStreamHelper implements StreamHelper {
|
|
|
102
101
|
private lastTextEndTimestamp;
|
|
103
102
|
private connectionDropTimer?;
|
|
104
103
|
constructor(writer: VercelUIWriter);
|
|
105
|
-
setSessionId(sessionId: string): void;
|
|
106
104
|
writeRole(_?: string): Promise<void>;
|
|
107
105
|
writeContent(content: string): Promise<void>;
|
|
108
106
|
streamText(text: string, delayMs?: number): Promise<void>;
|
|
@@ -166,8 +164,6 @@ declare class BufferingStreamHelper implements StreamHelper {
|
|
|
166
164
|
private capturedSummaries;
|
|
167
165
|
private hasError;
|
|
168
166
|
private errorMessage;
|
|
169
|
-
private sessionId?;
|
|
170
|
-
setSessionId(sessionId: string): void;
|
|
171
167
|
writeRole(_role?: string): Promise<void>;
|
|
172
168
|
writeContent(content: string): Promise<void>;
|
|
173
169
|
streamText(text: string, _delayMs?: number): Promise<void>;
|
|
@@ -154,7 +154,6 @@ var VercelDataStreamHelper = class VercelDataStreamHelper {
|
|
|
154
154
|
jsonBuffer = "";
|
|
155
155
|
sentItems = /* @__PURE__ */ new Map();
|
|
156
156
|
completedItems = /* @__PURE__ */ new Set();
|
|
157
|
-
sessionId;
|
|
158
157
|
static MAX_BUFFER_SIZE = STREAM_BUFFER_MAX_SIZE_BYTES;
|
|
159
158
|
isCompleted = false;
|
|
160
159
|
isTextStreaming = false;
|
|
@@ -167,9 +166,6 @@ var VercelDataStreamHelper = class VercelDataStreamHelper {
|
|
|
167
166
|
this.forceCleanup("Connection lifetime exceeded");
|
|
168
167
|
}, STREAM_MAX_LIFETIME_MS);
|
|
169
168
|
}
|
|
170
|
-
setSessionId(sessionId) {
|
|
171
|
-
this.sessionId = sessionId;
|
|
172
|
-
}
|
|
173
169
|
async writeRole(_ = "assistant") {}
|
|
174
170
|
async writeContent(content) {
|
|
175
171
|
if (this.isCompleted) {
|
|
@@ -462,10 +458,6 @@ var BufferingStreamHelper = class {
|
|
|
462
458
|
capturedSummaries = [];
|
|
463
459
|
hasError = false;
|
|
464
460
|
errorMessage = "";
|
|
465
|
-
sessionId;
|
|
466
|
-
setSessionId(sessionId) {
|
|
467
|
-
this.sessionId = sessionId;
|
|
468
|
-
}
|
|
469
461
|
async writeRole(_role) {}
|
|
470
462
|
async writeContent(content) {
|
|
471
463
|
this.capturedText += content;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _inkeep_agents_core1 from "@inkeep/agents-core";
|
|
2
2
|
import { BreakdownComponentDef, ContextBreakdown, calculateBreakdownTotal, createEmptyBreakdown } from "@inkeep/agents-core";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/token-estimator.d.ts
|
|
@@ -17,7 +17,7 @@ interface AssembleResult {
|
|
|
17
17
|
/** The assembled prompt string */
|
|
18
18
|
prompt: string;
|
|
19
19
|
/** Token breakdown for each component */
|
|
20
|
-
breakdown:
|
|
20
|
+
breakdown: _inkeep_agents_core1.ContextBreakdown;
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
23
|
export { AssembleResult, type BreakdownComponentDef, type ContextBreakdown, calculateBreakdownTotal, createEmptyBreakdown, estimateTokens };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-run-api",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260117173149",
|
|
4
4
|
"description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"hono": "^4.10.4",
|
|
42
42
|
"jmespath": "^0.16.0",
|
|
43
43
|
"llm-info": "^1.0.69",
|
|
44
|
-
"@inkeep/agents-core": "^0.0.0-dev-
|
|
44
|
+
"@inkeep/agents-core": "^0.0.0-dev-20260117173149"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@hono/zod-openapi": "^1.1.5",
|
|
@@ -85,6 +85,8 @@
|
|
|
85
85
|
"dev:with-bypass": "PORT=3003 vite",
|
|
86
86
|
"dev:without-bypass": "PORT=3004 INKEEP_AGENTS_RUN_API_BYPASS_SECRET= vite",
|
|
87
87
|
"build": "tsdown",
|
|
88
|
+
"lint": "biome lint --error-on-warnings",
|
|
89
|
+
"lint:fix": "biome check --write",
|
|
88
90
|
"start": "node dist/index.js",
|
|
89
91
|
"test": "./run-tests.sh",
|
|
90
92
|
"test:ci": "vitest --run --config vitest.config.ci.ts",
|