@inkeep/agents-run-api 0.0.0-dev-20251222193909 → 0.0.0-dev-20251222215156
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/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-component.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-components.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js +5 -0
- package/dist/a2a/client.d.ts +184 -0
- package/dist/a2a/client.js +510 -0
- package/dist/a2a/handlers.d.ts +7 -0
- package/dist/a2a/handlers.js +559 -0
- package/dist/a2a/transfer.d.ts +22 -0
- package/dist/a2a/transfer.js +46 -0
- package/dist/a2a/types.d.ts +79 -0
- package/dist/a2a/types.js +22 -0
- package/dist/agents/Agent.d.ts +220 -0
- package/dist/agents/Agent.js +1938 -0
- package/dist/agents/ModelFactory.d.ts +63 -0
- package/dist/agents/ModelFactory.js +194 -0
- package/dist/agents/SystemPromptBuilder.d.ts +21 -0
- package/dist/agents/SystemPromptBuilder.js +48 -0
- package/dist/agents/ToolSessionManager.d.ts +63 -0
- package/dist/agents/ToolSessionManager.js +146 -0
- package/dist/agents/generateTaskHandler.d.ts +49 -0
- package/dist/agents/generateTaskHandler.js +512 -0
- package/dist/agents/relationTools.d.ts +57 -0
- package/dist/agents/relationTools.js +262 -0
- package/dist/agents/types.d.ts +28 -0
- package/dist/agents/types.js +1 -0
- package/dist/agents/versions/v1/Phase1Config.d.ts +26 -0
- package/dist/agents/versions/v1/Phase1Config.js +413 -0
- package/dist/agents/versions/v1/Phase2Config.d.ts +31 -0
- package/dist/agents/versions/v1/Phase2Config.js +330 -0
- package/dist/constants/execution-limits/defaults.d.ts +47 -0
- package/dist/constants/execution-limits/defaults.js +48 -0
- package/dist/constants/execution-limits/index.d.ts +6 -0
- package/dist/constants/execution-limits/index.js +16 -0
- package/dist/create-app.d.ts +9 -0
- package/dist/create-app.js +195 -0
- package/dist/data/agent.d.ts +7 -0
- package/dist/data/agent.js +72 -0
- package/dist/data/agents.d.ts +34 -0
- package/dist/data/agents.js +139 -0
- package/dist/data/conversations.d.ts +88 -0
- package/dist/{conversations2.js → data/conversations.js} +42 -7
- package/dist/data/db/dbClient.d.ts +6 -0
- package/dist/data/db/dbClient.js +17 -0
- package/dist/env.d.ts +57 -0
- package/dist/env.js +1 -2
- package/dist/handlers/executionHandler.d.ts +39 -0
- package/dist/handlers/executionHandler.js +456 -0
- package/dist/index.d.ts +8 -29
- package/dist/index.js +5 -11487
- package/dist/instrumentation.d.ts +1 -2
- package/dist/instrumentation.js +66 -3
- package/dist/{logger2.js → logger.d.ts} +1 -2
- package/dist/logger.js +1 -1
- package/dist/middleware/api-key-auth.d.ts +26 -0
- package/dist/middleware/api-key-auth.js +240 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +3 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.js +54 -0
- package/dist/routes/agents.d.ts +12 -0
- package/dist/routes/agents.js +147 -0
- package/dist/routes/chat.d.ts +13 -0
- package/dist/routes/chat.js +293 -0
- package/dist/routes/chatDataStream.d.ts +13 -0
- package/dist/routes/chatDataStream.js +352 -0
- package/dist/routes/mcp.d.ts +13 -0
- package/dist/routes/mcp.js +495 -0
- package/dist/services/AgentSession.d.ts +356 -0
- package/dist/services/AgentSession.js +1208 -0
- package/dist/services/ArtifactParser.d.ts +105 -0
- package/dist/services/ArtifactParser.js +338 -0
- package/dist/services/ArtifactService.d.ts +123 -0
- package/dist/services/ArtifactService.js +611 -0
- package/dist/services/IncrementalStreamParser.d.ts +98 -0
- package/dist/services/IncrementalStreamParser.js +327 -0
- package/dist/services/MidGenerationCompressor.d.ts +91 -0
- package/dist/services/MidGenerationCompressor.js +375 -0
- package/dist/services/PendingToolApprovalManager.d.ts +62 -0
- package/dist/services/PendingToolApprovalManager.js +133 -0
- package/dist/services/ResponseFormatter.d.ts +39 -0
- package/dist/services/ResponseFormatter.js +152 -0
- package/dist/tools/NativeSandboxExecutor.d.ts +38 -0
- package/dist/tools/NativeSandboxExecutor.js +432 -0
- package/dist/tools/SandboxExecutorFactory.d.ts +36 -0
- package/dist/tools/SandboxExecutorFactory.js +80 -0
- package/dist/tools/VercelSandboxExecutor.d.ts +71 -0
- package/dist/tools/VercelSandboxExecutor.js +340 -0
- package/dist/tools/distill-conversation-tool.d.ts +41 -0
- package/dist/tools/distill-conversation-tool.js +156 -0
- package/dist/tools/sandbox-utils.d.ts +18 -0
- package/dist/tools/sandbox-utils.js +53 -0
- package/dist/types/chat.d.ts +27 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/execution-context.d.ts +46 -0
- package/dist/types/execution-context.js +27 -0
- package/dist/types/xml.d.ts +5 -0
- package/dist/utils/SchemaProcessor.d.ts +52 -0
- package/dist/utils/SchemaProcessor.js +182 -0
- package/dist/utils/agent-operations.d.ts +62 -0
- package/dist/utils/agent-operations.js +53 -0
- package/dist/utils/artifact-component-schema.d.ts +42 -0
- package/dist/utils/artifact-component-schema.js +186 -0
- package/dist/utils/cleanup.d.ts +21 -0
- package/dist/utils/cleanup.js +59 -0
- package/dist/utils/data-component-schema.d.ts +2 -0
- package/dist/utils/data-component-schema.js +3 -0
- package/dist/utils/default-status-schemas.d.ts +20 -0
- package/dist/utils/default-status-schemas.js +24 -0
- package/dist/utils/json-postprocessor.d.ts +13 -0
- package/dist/{json-postprocessor.cjs → utils/json-postprocessor.js} +1 -2
- package/dist/utils/model-context-utils.d.ts +31 -0
- package/dist/utils/model-context-utils.js +149 -0
- package/dist/utils/model-resolver.d.ts +6 -0
- package/dist/utils/model-resolver.js +34 -0
- package/dist/utils/schema-validation.d.ts +44 -0
- package/dist/utils/schema-validation.js +97 -0
- package/dist/utils/stream-helpers.d.ts +197 -0
- package/dist/utils/stream-helpers.js +518 -0
- package/dist/utils/stream-registry.d.ts +22 -0
- package/dist/utils/stream-registry.js +34 -0
- package/dist/utils/token-estimator.d.ts +69 -0
- package/dist/utils/token-estimator.js +53 -0
- package/dist/utils/tracer.d.ts +7 -0
- package/dist/utils/tracer.js +7 -0
- package/package.json +4 -20
- package/dist/SandboxExecutorFactory.cjs +0 -895
- package/dist/SandboxExecutorFactory.js +0 -893
- package/dist/SandboxExecutorFactory.js.map +0 -1
- package/dist/chunk-VBDAOXYI.cjs +0 -927
- package/dist/chunk-VBDAOXYI.js +0 -832
- package/dist/chunk-VBDAOXYI.js.map +0 -1
- package/dist/chunk.cjs +0 -34
- package/dist/conversations.cjs +0 -7
- package/dist/conversations.js +0 -7
- package/dist/conversations2.cjs +0 -209
- package/dist/conversations2.js.map +0 -1
- package/dist/dbClient.cjs +0 -9676
- package/dist/dbClient.js +0 -9670
- package/dist/dbClient.js.map +0 -1
- package/dist/dbClient2.cjs +0 -5
- package/dist/dbClient2.js +0 -5
- package/dist/env.cjs +0 -59
- package/dist/env.js.map +0 -1
- package/dist/execution-limits.cjs +0 -260
- package/dist/execution-limits.js +0 -63
- package/dist/execution-limits.js.map +0 -1
- package/dist/index.cjs +0 -11512
- package/dist/index.d.cts +0 -36
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation.cjs +0 -12
- package/dist/instrumentation.d.cts +0 -18
- package/dist/instrumentation.d.cts.map +0 -1
- package/dist/instrumentation.d.ts.map +0 -1
- package/dist/instrumentation2.cjs +0 -116
- package/dist/instrumentation2.js +0 -69
- package/dist/instrumentation2.js.map +0 -1
- package/dist/json-postprocessor.js +0 -20
- package/dist/json-postprocessor.js.map +0 -1
- package/dist/logger.cjs +0 -5
- package/dist/logger2.cjs +0 -1
- package/dist/nodefs.cjs +0 -29
- package/dist/nodefs.js +0 -27
- package/dist/nodefs.js.map +0 -1
- package/dist/opfs-ahp.cjs +0 -367
- package/dist/opfs-ahp.js +0 -368
- package/dist/opfs-ahp.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RegisteredAgent } from "../a2a/types.js";
|
|
2
|
+
import { ExecutionContext } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/data/agent.d.ts
|
|
5
|
+
declare function getRegisteredAgent(executionContext: ExecutionContext): Promise<RegisteredAgent | null>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { getRegisteredAgent };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import dbClient_default from "./db/dbClient.js";
|
|
2
|
+
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
3
|
+
import { getAgentById, getSubAgentById } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/data/agent.ts
|
|
6
|
+
async function hydrateAgent({ dbAgent, baseUrl, apiKey }) {
|
|
7
|
+
try {
|
|
8
|
+
if (!dbAgent.defaultSubAgentId) throw new Error(`Agent ${dbAgent.id} does not have a default agent configured`);
|
|
9
|
+
if (!await getSubAgentById(dbClient_default)({
|
|
10
|
+
scopes: {
|
|
11
|
+
tenantId: dbAgent.tenantId,
|
|
12
|
+
projectId: dbAgent.projectId,
|
|
13
|
+
agentId: dbAgent.id
|
|
14
|
+
},
|
|
15
|
+
subAgentId: dbAgent.defaultSubAgentId
|
|
16
|
+
})) throw new Error(`Default agent ${dbAgent.defaultSubAgentId} not found for agent ${dbAgent.id}`);
|
|
17
|
+
const taskHandler = createTaskHandler(await createTaskHandlerConfig({
|
|
18
|
+
tenantId: dbAgent.tenantId,
|
|
19
|
+
projectId: dbAgent.projectId,
|
|
20
|
+
agentId: dbAgent.id,
|
|
21
|
+
subAgentId: dbAgent.defaultSubAgentId,
|
|
22
|
+
baseUrl,
|
|
23
|
+
apiKey
|
|
24
|
+
}));
|
|
25
|
+
const agentCard = {
|
|
26
|
+
name: dbAgent.name,
|
|
27
|
+
description: dbAgent.description || `Agent: ${dbAgent.name}`,
|
|
28
|
+
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
29
|
+
version: "1.0.0",
|
|
30
|
+
capabilities: {
|
|
31
|
+
streaming: true,
|
|
32
|
+
pushNotifications: false,
|
|
33
|
+
stateTransitionHistory: false
|
|
34
|
+
},
|
|
35
|
+
defaultInputModes: ["text", "text/plain"],
|
|
36
|
+
defaultOutputModes: ["text", "text/plain"],
|
|
37
|
+
skills: [],
|
|
38
|
+
...baseUrl && { provider: {
|
|
39
|
+
organization: "Inkeep",
|
|
40
|
+
url: baseUrl
|
|
41
|
+
} }
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
subAgentId: dbAgent.id,
|
|
45
|
+
tenantId: dbAgent.tenantId,
|
|
46
|
+
projectId: dbAgent.projectId,
|
|
47
|
+
agentId: dbAgent.id,
|
|
48
|
+
agentCard,
|
|
49
|
+
taskHandler
|
|
50
|
+
};
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`❌ Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function getRegisteredAgent(executionContext) {
|
|
57
|
+
const { tenantId, projectId, agentId, baseUrl, apiKey } = executionContext;
|
|
58
|
+
const dbAgent = await getAgentById(dbClient_default)({ scopes: {
|
|
59
|
+
tenantId,
|
|
60
|
+
projectId,
|
|
61
|
+
agentId
|
|
62
|
+
} });
|
|
63
|
+
if (!dbAgent) return null;
|
|
64
|
+
return hydrateAgent({
|
|
65
|
+
dbAgent,
|
|
66
|
+
baseUrl: `${baseUrl}/agents`,
|
|
67
|
+
apiKey
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { getRegisteredAgent };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AgentCard as AgentCard$1, RegisteredAgent } from "../a2a/types.js";
|
|
2
|
+
import { SandboxConfig } from "../types/execution-context.js";
|
|
3
|
+
import { CredentialStoreRegistry, ExecutionContext, SubAgentSelect } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/data/agents.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create an AgentCard from database agent data
|
|
9
|
+
* Reusable function that standardizes agent card creation across the codebase
|
|
10
|
+
* Used for external discovery via /.well-known/agent.json endpoint
|
|
11
|
+
*/
|
|
12
|
+
declare function createAgentCard({
|
|
13
|
+
dbAgent,
|
|
14
|
+
baseUrl
|
|
15
|
+
}: {
|
|
16
|
+
dbAgent: SubAgentSelect;
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
}): AgentCard$1;
|
|
19
|
+
/**
|
|
20
|
+
* Generate an enhanced description that includes transfer and delegation information
|
|
21
|
+
* Used in generateTaskHandler to help agents understand what other agents can do
|
|
22
|
+
*
|
|
23
|
+
* @param baseDescription - The base description of the agent
|
|
24
|
+
* @param internalRelations - Pre-computed internal relations
|
|
25
|
+
* @param externalRelations - Pre-computed external relations
|
|
26
|
+
*/
|
|
27
|
+
declare function generateDescriptionWithRelationData(baseDescription: string, internalRelations: any[], externalRelations: any[], teamRelations: any[]): string;
|
|
28
|
+
declare function getRegisteredAgent(params: {
|
|
29
|
+
executionContext: ExecutionContext;
|
|
30
|
+
credentialStoreRegistry?: CredentialStoreRegistry;
|
|
31
|
+
sandboxConfig?: SandboxConfig;
|
|
32
|
+
}): Promise<RegisteredAgent | null>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { createAgentCard, generateDescriptionWithRelationData, getRegisteredAgent };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import dbClient_default from "./db/dbClient.js";
|
|
3
|
+
import { getUserIdFromContext } from "../types/execution-context.js";
|
|
4
|
+
import { createTaskHandler, createTaskHandlerConfig } from "../agents/generateTaskHandler.js";
|
|
5
|
+
import { getAgentWithDefaultSubAgent, getSubAgentById } from "@inkeep/agents-core";
|
|
6
|
+
|
|
7
|
+
//#region src/data/agents.ts
|
|
8
|
+
const logger = getLogger("agents");
|
|
9
|
+
/**
|
|
10
|
+
* Create an AgentCard from database agent data
|
|
11
|
+
* Reusable function that standardizes agent card creation across the codebase
|
|
12
|
+
* Used for external discovery via /.well-known/agent.json endpoint
|
|
13
|
+
*/
|
|
14
|
+
function createAgentCard({ dbAgent, baseUrl }) {
|
|
15
|
+
const description = dbAgent.description || "AI Agent";
|
|
16
|
+
return {
|
|
17
|
+
name: dbAgent.name,
|
|
18
|
+
description,
|
|
19
|
+
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
20
|
+
version: "1.0.0",
|
|
21
|
+
capabilities: {
|
|
22
|
+
streaming: true,
|
|
23
|
+
pushNotifications: false,
|
|
24
|
+
stateTransitionHistory: false
|
|
25
|
+
},
|
|
26
|
+
defaultInputModes: ["text", "text/plain"],
|
|
27
|
+
defaultOutputModes: ["text", "text/plain"],
|
|
28
|
+
skills: [],
|
|
29
|
+
...baseUrl && { provider: {
|
|
30
|
+
organization: "Inkeep",
|
|
31
|
+
url: baseUrl
|
|
32
|
+
} }
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generate an enhanced description that includes transfer and delegation information
|
|
37
|
+
* Used in generateTaskHandler to help agents understand what other agents can do
|
|
38
|
+
*
|
|
39
|
+
* @param baseDescription - The base description of the agent
|
|
40
|
+
* @param internalRelations - Pre-computed internal relations
|
|
41
|
+
* @param externalRelations - Pre-computed external relations
|
|
42
|
+
*/
|
|
43
|
+
function generateDescriptionWithRelationData(baseDescription, internalRelations, externalRelations, teamRelations) {
|
|
44
|
+
const transfers = [...internalRelations.filter((rel) => rel.relationType === "transfer")];
|
|
45
|
+
const delegates = [
|
|
46
|
+
...internalRelations.filter((rel) => rel.relationType === "delegate"),
|
|
47
|
+
...externalRelations.map((data) => data.externalAgent),
|
|
48
|
+
...teamRelations.map((data) => data.targetAgent)
|
|
49
|
+
];
|
|
50
|
+
if (transfers.length === 0 && delegates.length === 0) return baseDescription;
|
|
51
|
+
let enhancedDescription = baseDescription;
|
|
52
|
+
if (transfers.length > 0) {
|
|
53
|
+
const transferList = transfers.map((rel) => {
|
|
54
|
+
return `- ${rel.externalAgent?.name || rel.name}: ${rel.externalAgent?.description || rel.description || ""}`;
|
|
55
|
+
}).join("\n");
|
|
56
|
+
enhancedDescription += `\n\nCan transfer to:\n${transferList}`;
|
|
57
|
+
}
|
|
58
|
+
if (delegates.length > 0) {
|
|
59
|
+
const delegateList = delegates.map((rel) => {
|
|
60
|
+
return `- ${rel.name}: ${rel.description || ""}`;
|
|
61
|
+
}).join("\n");
|
|
62
|
+
enhancedDescription += `\n\nCan delegate to:\n${delegateList}`;
|
|
63
|
+
}
|
|
64
|
+
return enhancedDescription;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a RegisteredAgent from database agent data
|
|
68
|
+
* Hydrates agent directly from database schema using types from schema.ts
|
|
69
|
+
*/
|
|
70
|
+
async function hydrateAgent({ dbAgent, agentId, baseUrl, apiKey, credentialStoreRegistry, sandboxConfig, userId }) {
|
|
71
|
+
try {
|
|
72
|
+
const taskHandler = createTaskHandler(await createTaskHandlerConfig({
|
|
73
|
+
tenantId: dbAgent.tenantId,
|
|
74
|
+
projectId: dbAgent.projectId,
|
|
75
|
+
agentId,
|
|
76
|
+
subAgentId: dbAgent.id,
|
|
77
|
+
baseUrl,
|
|
78
|
+
apiKey,
|
|
79
|
+
sandboxConfig,
|
|
80
|
+
userId
|
|
81
|
+
}), credentialStoreRegistry);
|
|
82
|
+
const agentCard = createAgentCard({
|
|
83
|
+
dbAgent,
|
|
84
|
+
baseUrl
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
subAgentId: dbAgent.id,
|
|
88
|
+
tenantId: dbAgent.tenantId,
|
|
89
|
+
projectId: dbAgent.projectId,
|
|
90
|
+
agentId,
|
|
91
|
+
agentCard,
|
|
92
|
+
taskHandler
|
|
93
|
+
};
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error(`❌ Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function getRegisteredAgent(params) {
|
|
100
|
+
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
101
|
+
const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
102
|
+
const userId = getUserIdFromContext(executionContext);
|
|
103
|
+
let dbAgent;
|
|
104
|
+
if (!subAgentId) {
|
|
105
|
+
const agent = await getAgentWithDefaultSubAgent(dbClient_default)({ scopes: {
|
|
106
|
+
tenantId,
|
|
107
|
+
projectId,
|
|
108
|
+
agentId
|
|
109
|
+
} });
|
|
110
|
+
logger.info({ agent }, "agent with default sub agent");
|
|
111
|
+
if (!agent || !agent.defaultSubAgent) return null;
|
|
112
|
+
dbAgent = agent.defaultSubAgent;
|
|
113
|
+
} else {
|
|
114
|
+
const response = await getSubAgentById(dbClient_default)({
|
|
115
|
+
scopes: {
|
|
116
|
+
tenantId,
|
|
117
|
+
projectId,
|
|
118
|
+
agentId
|
|
119
|
+
},
|
|
120
|
+
subAgentId
|
|
121
|
+
});
|
|
122
|
+
if (!response) return null;
|
|
123
|
+
dbAgent = response;
|
|
124
|
+
}
|
|
125
|
+
if (!dbAgent) return null;
|
|
126
|
+
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
127
|
+
return hydrateAgent({
|
|
128
|
+
dbAgent,
|
|
129
|
+
agentId,
|
|
130
|
+
baseUrl: agentFrameworkBaseUrl,
|
|
131
|
+
credentialStoreRegistry,
|
|
132
|
+
apiKey,
|
|
133
|
+
sandboxConfig,
|
|
134
|
+
userId
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
export { createAgentCard, generateDescriptionWithRelationData, getRegisteredAgent };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AgentConversationHistoryConfig, Artifact, ConversationHistoryConfig, ConversationScopeOptions } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/data/conversations.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates default conversation history configuration
|
|
7
|
+
* @param mode - The conversation history mode ('full' | 'scoped' | 'none')
|
|
8
|
+
* @returns Default AgentConversationHistoryConfig
|
|
9
|
+
*/
|
|
10
|
+
declare function createDefaultConversationHistoryConfig(mode?: 'full' | 'scoped' | 'none'): AgentConversationHistoryConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Saves the result of an A2A client sendMessage call as a conversation message
|
|
13
|
+
* @param response - The response from a2aClient.sendMessage()
|
|
14
|
+
* @param params - Parameters for saving the message
|
|
15
|
+
* @returns The saved message or null if no text content was found
|
|
16
|
+
*/
|
|
17
|
+
declare function saveA2AMessageResponse(response: any,
|
|
18
|
+
// SendMessageResponse type
|
|
19
|
+
params: {
|
|
20
|
+
tenantId: string;
|
|
21
|
+
projectId: string;
|
|
22
|
+
conversationId: string;
|
|
23
|
+
messageType: 'a2a-response' | 'a2a-request';
|
|
24
|
+
visibility: 'internal' | 'external' | 'user-facing';
|
|
25
|
+
fromSubAgentId?: string;
|
|
26
|
+
toSubAgentId?: string;
|
|
27
|
+
fromExternalAgentId?: string;
|
|
28
|
+
toExternalAgentId?: string;
|
|
29
|
+
a2aTaskId?: string;
|
|
30
|
+
a2aSessionId?: string;
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}): Promise<any | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Applies filtering based on agent, task, or both criteria
|
|
35
|
+
* Returns the filtered messages array
|
|
36
|
+
*/
|
|
37
|
+
declare function getScopedHistory({
|
|
38
|
+
tenantId,
|
|
39
|
+
projectId,
|
|
40
|
+
conversationId,
|
|
41
|
+
filters,
|
|
42
|
+
options
|
|
43
|
+
}: {
|
|
44
|
+
tenantId: string;
|
|
45
|
+
projectId: string;
|
|
46
|
+
conversationId: string;
|
|
47
|
+
filters?: ConversationScopeOptions;
|
|
48
|
+
options?: ConversationHistoryConfig;
|
|
49
|
+
}): Promise<any[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Get user-facing conversation history (for client display)
|
|
52
|
+
*/
|
|
53
|
+
declare function getUserFacingHistory(tenantId: string, projectId: string, conversationId: string, limit?: 50): Promise<any[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Get full conversation context (for agent processing)
|
|
56
|
+
*/
|
|
57
|
+
declare function getFullConversationContext(tenantId: string, projectId: string, conversationId: string, maxTokens?: number): Promise<any[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Get formatted conversation history for a2a
|
|
60
|
+
*/
|
|
61
|
+
declare function getFormattedConversationHistory({
|
|
62
|
+
tenantId,
|
|
63
|
+
projectId,
|
|
64
|
+
conversationId,
|
|
65
|
+
currentMessage,
|
|
66
|
+
options,
|
|
67
|
+
filters
|
|
68
|
+
}: {
|
|
69
|
+
tenantId: string;
|
|
70
|
+
projectId: string;
|
|
71
|
+
conversationId: string;
|
|
72
|
+
currentMessage?: string;
|
|
73
|
+
options?: ConversationHistoryConfig;
|
|
74
|
+
filters?: ConversationScopeOptions;
|
|
75
|
+
}): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Get artifacts that are within the scope of the conversation history
|
|
78
|
+
* Only returns artifacts from messages that are actually visible to the LLM
|
|
79
|
+
* Uses the same scoping logic as getFormattedConversationHistory
|
|
80
|
+
*/
|
|
81
|
+
declare function getConversationScopedArtifacts(params: {
|
|
82
|
+
tenantId: string;
|
|
83
|
+
projectId: string;
|
|
84
|
+
conversationId: string;
|
|
85
|
+
historyConfig: AgentConversationHistoryConfig;
|
|
86
|
+
}): Promise<Artifact[]>;
|
|
87
|
+
//#endregion
|
|
88
|
+
export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import dbClient_default from "./db/dbClient.js";
|
|
2
|
+
import { CONVERSATION_HISTORY_DEFAULT_LIMIT as CONVERSATION_HISTORY_DEFAULT_LIMIT$1 } from "../constants/execution-limits/index.js";
|
|
3
3
|
import { CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, createMessage, generateId, getConversationHistory } from "@inkeep/agents-core";
|
|
4
4
|
|
|
5
5
|
//#region src/data/conversations.ts
|
|
@@ -101,6 +101,42 @@ async function getScopedHistory({ tenantId, projectId, conversationId, filters,
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
|
+
* Get user-facing conversation history (for client display)
|
|
105
|
+
*/
|
|
106
|
+
async function getUserFacingHistory(tenantId, projectId, conversationId, limit = CONVERSATION_HISTORY_DEFAULT_LIMIT$1) {
|
|
107
|
+
return await getConversationHistory(dbClient_default)({
|
|
108
|
+
scopes: {
|
|
109
|
+
tenantId,
|
|
110
|
+
projectId
|
|
111
|
+
},
|
|
112
|
+
conversationId,
|
|
113
|
+
options: {
|
|
114
|
+
limit,
|
|
115
|
+
includeInternal: false,
|
|
116
|
+
messageTypes: ["chat"]
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get full conversation context (for agent processing)
|
|
122
|
+
*/
|
|
123
|
+
async function getFullConversationContext(tenantId, projectId, conversationId, maxTokens) {
|
|
124
|
+
const defaultConfig = createDefaultConversationHistoryConfig();
|
|
125
|
+
return await getConversationHistory(dbClient_default)({
|
|
126
|
+
scopes: {
|
|
127
|
+
tenantId,
|
|
128
|
+
projectId
|
|
129
|
+
},
|
|
130
|
+
conversationId,
|
|
131
|
+
options: {
|
|
132
|
+
...defaultConfig,
|
|
133
|
+
limit: 100,
|
|
134
|
+
includeInternal: true,
|
|
135
|
+
maxOutputTokens: maxTokens
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
104
140
|
* Get formatted conversation history for a2a
|
|
105
141
|
*/
|
|
106
142
|
async function getFormattedConversationHistory({ tenantId, projectId, conversationId, currentMessage, options, filters }) {
|
|
@@ -145,7 +181,7 @@ async function getConversationScopedArtifacts(params) {
|
|
|
145
181
|
if (visibleMessages.length === 0) return [];
|
|
146
182
|
if (visibleMessages.filter((msg) => !(msg.messageType === "system" && msg.content?.text?.includes("Previous conversation history truncated"))).map((msg) => msg.id).length === 0) return [];
|
|
147
183
|
const { getLedgerArtifacts: getLedgerArtifacts$1 } = await import("@inkeep/agents-core");
|
|
148
|
-
const dbClient = (await import("./
|
|
184
|
+
const dbClient = (await import("./db/dbClient.js")).default;
|
|
149
185
|
const visibleTaskIds = visibleMessages.map((msg) => msg.taskId).filter((taskId) => Boolean(taskId));
|
|
150
186
|
const referenceArtifacts = [];
|
|
151
187
|
for (const taskId of visibleTaskIds) {
|
|
@@ -158,7 +194,7 @@ async function getConversationScopedArtifacts(params) {
|
|
|
158
194
|
});
|
|
159
195
|
referenceArtifacts.push(...artifacts);
|
|
160
196
|
}
|
|
161
|
-
(await import("
|
|
197
|
+
(await import("../logger.js")).getLogger("conversations").debug({
|
|
162
198
|
conversationId,
|
|
163
199
|
visibleMessages: visibleMessages.length,
|
|
164
200
|
visibleTasks: visibleTaskIds.length,
|
|
@@ -167,7 +203,7 @@ async function getConversationScopedArtifacts(params) {
|
|
|
167
203
|
}, "Loaded conversation-scoped artifacts");
|
|
168
204
|
return referenceArtifacts;
|
|
169
205
|
} catch (error) {
|
|
170
|
-
(await import("
|
|
206
|
+
(await import("../logger.js")).getLogger("conversations").error({
|
|
171
207
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
172
208
|
conversationId
|
|
173
209
|
}, "Failed to get conversation-scoped artifacts");
|
|
@@ -176,5 +212,4 @@ async function getConversationScopedArtifacts(params) {
|
|
|
176
212
|
}
|
|
177
213
|
|
|
178
214
|
//#endregion
|
|
179
|
-
export {
|
|
180
|
-
//# sourceMappingURL=conversations2.js.map
|
|
215
|
+
export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { env } from "../../env.js";
|
|
2
|
+
import { createDatabaseClient } from "@inkeep/agents-core";
|
|
3
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
4
|
+
import * as schema from "@inkeep/agents-core/db/schema";
|
|
5
|
+
import { drizzle } from "drizzle-orm/pglite";
|
|
6
|
+
|
|
7
|
+
//#region src/data/db/dbClient.ts
|
|
8
|
+
let dbClient;
|
|
9
|
+
if (env.ENVIRONMENT === "test") dbClient = drizzle({
|
|
10
|
+
client: new PGlite(),
|
|
11
|
+
schema
|
|
12
|
+
});
|
|
13
|
+
else dbClient = createDatabaseClient({ connectionString: env.DATABASE_URL });
|
|
14
|
+
var dbClient_default = dbClient;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { dbClient_default as default };
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
|
|
3
|
+
//#region src/env.d.ts
|
|
4
|
+
declare const envSchema: z.ZodObject<{
|
|
5
|
+
NODE_ENV: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
development: "development";
|
|
7
|
+
production: "production";
|
|
8
|
+
test: "test";
|
|
9
|
+
}>>;
|
|
10
|
+
ENVIRONMENT: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
development: "development";
|
|
12
|
+
production: "production";
|
|
13
|
+
test: "test";
|
|
14
|
+
pentest: "pentest";
|
|
15
|
+
}>>>;
|
|
16
|
+
DATABASE_URL: z.ZodOptional<z.ZodString>;
|
|
17
|
+
INKEEP_AGENTS_RUN_API_URL: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
|
+
AGENTS_MANAGE_UI_URL: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
19
|
+
LOG_LEVEL: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
error: "error";
|
|
21
|
+
trace: "trace";
|
|
22
|
+
debug: "debug";
|
|
23
|
+
info: "info";
|
|
24
|
+
warn: "warn";
|
|
25
|
+
}>>>;
|
|
26
|
+
NANGO_SERVER_URL: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
27
|
+
NANGO_SECRET_KEY: z.ZodOptional<z.ZodString>;
|
|
28
|
+
ANTHROPIC_API_KEY: z.ZodString;
|
|
29
|
+
OPENAI_API_KEY: z.ZodOptional<z.ZodString>;
|
|
30
|
+
GOOGLE_GENERATIVE_AI_API_KEY: z.ZodOptional<z.ZodString>;
|
|
31
|
+
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z.ZodOptional<z.ZodString>;
|
|
32
|
+
INKEEP_AGENTS_JWT_SIGNING_SECRET: z.ZodOptional<z.ZodString>;
|
|
33
|
+
INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
34
|
+
OTEL_BSP_SCHEDULE_DELAY: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
|
|
35
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
declare const env: {
|
|
38
|
+
ENVIRONMENT: "development" | "production" | "test" | "pentest";
|
|
39
|
+
INKEEP_AGENTS_RUN_API_URL: string;
|
|
40
|
+
AGENTS_MANAGE_UI_URL: string;
|
|
41
|
+
LOG_LEVEL: "error" | "trace" | "debug" | "info" | "warn";
|
|
42
|
+
NANGO_SERVER_URL: string;
|
|
43
|
+
ANTHROPIC_API_KEY: string;
|
|
44
|
+
OTEL_BSP_SCHEDULE_DELAY: number;
|
|
45
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: number;
|
|
46
|
+
NODE_ENV?: "development" | "production" | "test" | undefined;
|
|
47
|
+
DATABASE_URL?: string | undefined;
|
|
48
|
+
NANGO_SECRET_KEY?: string | undefined;
|
|
49
|
+
OPENAI_API_KEY?: string | undefined;
|
|
50
|
+
GOOGLE_GENERATIVE_AI_API_KEY?: string | undefined;
|
|
51
|
+
INKEEP_AGENTS_RUN_API_BYPASS_SECRET?: string | undefined;
|
|
52
|
+
INKEEP_AGENTS_JWT_SIGNING_SECRET?: string | undefined;
|
|
53
|
+
INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY?: string | undefined;
|
|
54
|
+
};
|
|
55
|
+
type Env = z.infer<typeof envSchema>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Env, env };
|
package/dist/env.js
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { StreamHelper } from "../utils/stream-helpers.js";
|
|
2
|
+
import { ExecutionContext } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/handlers/executionHandler.d.ts
|
|
5
|
+
interface ExecutionHandlerParams {
|
|
6
|
+
executionContext: ExecutionContext;
|
|
7
|
+
conversationId: string;
|
|
8
|
+
userMessage: string;
|
|
9
|
+
initialAgentId: string;
|
|
10
|
+
requestId: string;
|
|
11
|
+
sseHelper: StreamHelper;
|
|
12
|
+
emitOperations?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface ExecutionResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
iterations: number;
|
|
18
|
+
response?: string;
|
|
19
|
+
}
|
|
20
|
+
declare class ExecutionHandler {
|
|
21
|
+
private readonly MAX_ERRORS;
|
|
22
|
+
/**
|
|
23
|
+
* performs exeuction loop
|
|
24
|
+
*
|
|
25
|
+
* Do up to limit of MAX_ITERATIONS
|
|
26
|
+
*
|
|
27
|
+
* 1. lookup active agent for thread
|
|
28
|
+
* 2. Send A2A message to selected agent
|
|
29
|
+
* 3. Parse A2A message response
|
|
30
|
+
* 4. Handle transfer messages (if any)
|
|
31
|
+
* 5. Handle completion messages (if any)
|
|
32
|
+
* 6. If no valid response or transfer, return error
|
|
33
|
+
* @param params
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
execute(params: ExecutionHandlerParams): Promise<ExecutionResult>;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ExecutionHandler };
|