@inkeep/agents-run-api 0.1.3 → 0.1.6

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.
Files changed (157) hide show
  1. package/LICENSE.md +7 -0
  2. package/SUPPLEMENTAL_TERMS.md +40 -0
  3. package/dist/chunk-P6IQZWFC.js +239 -0
  4. package/dist/conversations-EUPRCMQZ.js +1 -0
  5. package/dist/index.cjs +8992 -0
  6. package/dist/index.d.cts +15 -0
  7. package/dist/index.d.ts +13 -21
  8. package/dist/index.js +8644 -27
  9. package/package.json +8 -7
  10. package/dist/AgentExecutionServer.d.ts +0 -28
  11. package/dist/AgentExecutionServer.d.ts.map +0 -1
  12. package/dist/AgentExecutionServer.js +0 -41
  13. package/dist/__tests__/setup.d.ts +0 -4
  14. package/dist/__tests__/setup.d.ts.map +0 -1
  15. package/dist/__tests__/setup.js +0 -80
  16. package/dist/__tests__/utils/testProject.d.ts +0 -18
  17. package/dist/__tests__/utils/testProject.d.ts.map +0 -1
  18. package/dist/__tests__/utils/testProject.js +0 -26
  19. package/dist/__tests__/utils/testRequest.d.ts +0 -8
  20. package/dist/__tests__/utils/testRequest.d.ts.map +0 -1
  21. package/dist/__tests__/utils/testRequest.js +0 -32
  22. package/dist/__tests__/utils/testTenant.d.ts +0 -64
  23. package/dist/__tests__/utils/testTenant.d.ts.map +0 -1
  24. package/dist/__tests__/utils/testTenant.js +0 -71
  25. package/dist/a2a/client.d.ts +0 -182
  26. package/dist/a2a/client.d.ts.map +0 -1
  27. package/dist/a2a/client.js +0 -645
  28. package/dist/a2a/handlers.d.ts +0 -4
  29. package/dist/a2a/handlers.d.ts.map +0 -1
  30. package/dist/a2a/handlers.js +0 -656
  31. package/dist/a2a/transfer.d.ts +0 -18
  32. package/dist/a2a/transfer.d.ts.map +0 -1
  33. package/dist/a2a/transfer.js +0 -22
  34. package/dist/a2a/types.d.ts +0 -63
  35. package/dist/a2a/types.d.ts.map +0 -1
  36. package/dist/a2a/types.js +0 -1
  37. package/dist/agents/Agent.d.ts +0 -154
  38. package/dist/agents/Agent.d.ts.map +0 -1
  39. package/dist/agents/Agent.js +0 -1110
  40. package/dist/agents/ModelFactory.d.ts +0 -62
  41. package/dist/agents/ModelFactory.d.ts.map +0 -1
  42. package/dist/agents/ModelFactory.js +0 -208
  43. package/dist/agents/SystemPromptBuilder.d.ts +0 -14
  44. package/dist/agents/SystemPromptBuilder.d.ts.map +0 -1
  45. package/dist/agents/SystemPromptBuilder.js +0 -62
  46. package/dist/agents/ToolSessionManager.d.ts +0 -61
  47. package/dist/agents/ToolSessionManager.d.ts.map +0 -1
  48. package/dist/agents/ToolSessionManager.js +0 -143
  49. package/dist/agents/artifactTools.d.ts +0 -30
  50. package/dist/agents/artifactTools.d.ts.map +0 -1
  51. package/dist/agents/artifactTools.js +0 -463
  52. package/dist/agents/generateTaskHandler.d.ts +0 -41
  53. package/dist/agents/generateTaskHandler.d.ts.map +0 -1
  54. package/dist/agents/generateTaskHandler.js +0 -350
  55. package/dist/agents/relationTools.d.ts +0 -35
  56. package/dist/agents/relationTools.d.ts.map +0 -1
  57. package/dist/agents/relationTools.js +0 -246
  58. package/dist/agents/types.d.ts +0 -23
  59. package/dist/agents/types.d.ts.map +0 -1
  60. package/dist/agents/types.js +0 -1
  61. package/dist/agents/versions/V1Config.d.ts +0 -21
  62. package/dist/agents/versions/V1Config.d.ts.map +0 -1
  63. package/dist/agents/versions/V1Config.js +0 -285
  64. package/dist/app.d.ts +0 -12
  65. package/dist/app.d.ts.map +0 -1
  66. package/dist/app.js +0 -216
  67. package/dist/data/agentGraph.d.ts +0 -4
  68. package/dist/data/agentGraph.d.ts.map +0 -1
  69. package/dist/data/agentGraph.js +0 -73
  70. package/dist/data/agents.d.ts +0 -4
  71. package/dist/data/agents.d.ts.map +0 -1
  72. package/dist/data/agents.js +0 -78
  73. package/dist/data/conversations.d.ts +0 -59
  74. package/dist/data/conversations.d.ts.map +0 -1
  75. package/dist/data/conversations.js +0 -216
  76. package/dist/data/db/clean.d.ts +0 -6
  77. package/dist/data/db/clean.d.ts.map +0 -1
  78. package/dist/data/db/clean.js +0 -77
  79. package/dist/data/db/dbClient.d.ts +0 -3
  80. package/dist/data/db/dbClient.d.ts.map +0 -1
  81. package/dist/data/db/dbClient.js +0 -13
  82. package/dist/env.d.ts +0 -45
  83. package/dist/env.d.ts.map +0 -1
  84. package/dist/env.js +0 -64
  85. package/dist/handlers/executionHandler.d.ts +0 -36
  86. package/dist/handlers/executionHandler.d.ts.map +0 -1
  87. package/dist/handlers/executionHandler.js +0 -399
  88. package/dist/index.d.ts.map +0 -1
  89. package/dist/instrumentation.d.ts +0 -13
  90. package/dist/instrumentation.d.ts.map +0 -1
  91. package/dist/instrumentation.js +0 -66
  92. package/dist/logger.d.ts +0 -4
  93. package/dist/logger.d.ts.map +0 -1
  94. package/dist/logger.js +0 -32
  95. package/dist/middleware/api-key-auth.d.ts +0 -22
  96. package/dist/middleware/api-key-auth.d.ts.map +0 -1
  97. package/dist/middleware/api-key-auth.js +0 -139
  98. package/dist/middleware/index.d.ts +0 -2
  99. package/dist/middleware/index.d.ts.map +0 -1
  100. package/dist/middleware/index.js +0 -1
  101. package/dist/openapi.d.ts +0 -2
  102. package/dist/openapi.d.ts.map +0 -1
  103. package/dist/openapi.js +0 -36
  104. package/dist/routes/agents.d.ts +0 -10
  105. package/dist/routes/agents.d.ts.map +0 -1
  106. package/dist/routes/agents.js +0 -158
  107. package/dist/routes/chat.d.ts +0 -10
  108. package/dist/routes/chat.d.ts.map +0 -1
  109. package/dist/routes/chat.js +0 -307
  110. package/dist/routes/chatDataStream.d.ts +0 -10
  111. package/dist/routes/chatDataStream.d.ts.map +0 -1
  112. package/dist/routes/chatDataStream.js +0 -179
  113. package/dist/routes/mcp.d.ts +0 -10
  114. package/dist/routes/mcp.d.ts.map +0 -1
  115. package/dist/routes/mcp.js +0 -500
  116. package/dist/server.d.ts +0 -5
  117. package/dist/server.d.ts.map +0 -1
  118. package/dist/server.js +0 -61
  119. package/dist/tracer.d.ts +0 -24
  120. package/dist/tracer.d.ts.map +0 -1
  121. package/dist/tracer.js +0 -107
  122. package/dist/types/chat.d.ts +0 -25
  123. package/dist/types/chat.d.ts.map +0 -1
  124. package/dist/types/chat.js +0 -1
  125. package/dist/types/execution-context.d.ts +0 -14
  126. package/dist/types/execution-context.d.ts.map +0 -1
  127. package/dist/types/execution-context.js +0 -14
  128. package/dist/utils/agent-operations.d.ts +0 -92
  129. package/dist/utils/agent-operations.d.ts.map +0 -1
  130. package/dist/utils/agent-operations.js +0 -78
  131. package/dist/utils/artifact-component-schema.d.ts +0 -29
  132. package/dist/utils/artifact-component-schema.d.ts.map +0 -1
  133. package/dist/utils/artifact-component-schema.js +0 -119
  134. package/dist/utils/artifact-parser.d.ts +0 -71
  135. package/dist/utils/artifact-parser.d.ts.map +0 -1
  136. package/dist/utils/artifact-parser.js +0 -251
  137. package/dist/utils/cleanup.d.ts +0 -19
  138. package/dist/utils/cleanup.d.ts.map +0 -1
  139. package/dist/utils/cleanup.js +0 -66
  140. package/dist/utils/data-component-schema.d.ts +0 -6
  141. package/dist/utils/data-component-schema.d.ts.map +0 -1
  142. package/dist/utils/data-component-schema.js +0 -43
  143. package/dist/utils/graph-session.d.ts +0 -200
  144. package/dist/utils/graph-session.d.ts.map +0 -1
  145. package/dist/utils/graph-session.js +0 -1016
  146. package/dist/utils/incremental-stream-parser.d.ts +0 -57
  147. package/dist/utils/incremental-stream-parser.d.ts.map +0 -1
  148. package/dist/utils/incremental-stream-parser.js +0 -289
  149. package/dist/utils/response-formatter.d.ts +0 -27
  150. package/dist/utils/response-formatter.d.ts.map +0 -1
  151. package/dist/utils/response-formatter.js +0 -160
  152. package/dist/utils/stream-helpers.d.ts +0 -174
  153. package/dist/utils/stream-helpers.d.ts.map +0 -1
  154. package/dist/utils/stream-helpers.js +0 -466
  155. package/dist/utils/stream-registry.d.ts +0 -18
  156. package/dist/utils/stream-registry.d.ts.map +0 -1
  157. package/dist/utils/stream-registry.js +0 -33
package/LICENSE.md CHANGED
@@ -1,3 +1,10 @@
1
+ <!--
2
+ AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
3
+ Source: ./LICENSE.md
4
+ This file is automatically copied from the root LICENSE.md during build.
5
+ Any changes should be made to the root LICENSE.md file.
6
+ -->
7
+
1
8
  # Inkeep SDK – Elastic License 2.0 with Supplemental Terms
2
9
 
3
10
  NOTE: The Inkeep SDK is licensed under the Elastic License 2.0 (ELv2), subject to Supplemental Terms included in [SUPPLEMENTAL_TERMS.md](SUPPLEMENTAL_TERMS.md). In the event of conflict, the Supplemental Terms control.
@@ -0,0 +1,40 @@
1
+ <!--
2
+ AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
3
+ Source: ./SUPPLEMENTAL_TERMS.md
4
+ This file is automatically copied from the root SUPPLEMENTAL_TERMS.md during build.
5
+ Any changes should be made to the root SUPPLEMENTAL_TERMS.md file.
6
+ -->
7
+
8
+ # Inkeep SDK – Elastic License 2.0 with Supplemental Terms
9
+
10
+ The Inkeep [SDK] (the "Software") is licensed under the Elastic License 2.0 ("ELv2"), available at [https://www.elastic.co/licensing/elastic-license](https://www.elastic.co/licensing/elastic-license), subject to the supplemental terms below. By using the Software, you, your company, and your licensees agree to both ELv2 and these Supplemental Terms – for purposes of these Supplemental Terms, references to "you" have the same meaning as in ELv2 and include your company and contractors acting on your behalf. In the event of conflict, these Supplemental Terms control.
11
+
12
+ Any copy or redistribution of the Software must include both the ELv2 license reference and these Supplemental Terms.
13
+
14
+ ## 1. Restrictions
15
+
16
+ ### 1.1
17
+ You may not use the Software, directly or indirectly, to offer, enable, operate, or provide any Agent Builder.
18
+
19
+ ### 1.2
20
+ You may not repackage, rebrand, or otherwise expose the Software's agent-creation or orchestration functionality for third-party use, including in specialized or verticalized offerings that present substantially similar functionality to the Software.
21
+
22
+ ### 1.3
23
+ For clarity, the foregoing restrictions do not prohibit your use of the Software as Embedded Assistants or Professional Services, provided neither allow third parties to create, configure, train, orchestrate, deploy, or manage their own agents or agent workflows.
24
+
25
+ ## 2. Definitions
26
+
27
+ ### 2.1 Inkeep
28
+ **"Inkeep"** means Inkeep, Inc., a Delaware corporation with principal offices at 169 Madison Ave, Ste 2544, New York, NY, 10016, the licensor (as defined in ELv2) of the Software.
29
+
30
+ ### 2.2 Agent Builder
31
+ **"Agent Builder"** means any hosted or on-premise product, platform, UI or API that allows third parties (e.g., customers, developers, or community users other than your personnel) to create, configure, compose, train, orchestrate, deploy, or manage their own Agents using the Software, or that otherwise exposes a substantial set of the Agent-creation and orchestration functionality of the Software.
32
+
33
+ ### 2.3 Agents
34
+ **"Agents"** means autonomous, semi-autonomous, or automated systems — including assistants, copilots, workflows, orchestrations, or other systems powered by or incorporating artificial intelligence, machine learning, large language models, or related technologies.
35
+
36
+ ### 2.4 Embedded Assistant
37
+ **"Embedded Assistant"** means embedding the Software in your own products or services to power a specific assistant/copilot/agent experience for you or your end users (e.g., a support bot in your app or an internal helpdesk agent), where end users do not receive access to any substantial set of the Software's agent-creation or orchestration features.
38
+
39
+ ### 2.5 Professional Services
40
+ **"Professional Services"** means using the Software to deliver a bespoke solution to a single client where only your personnel operate the Software, the client receives access solely to the resulting assistant within the client's environment and not to the agent-creation/orchestration features of the Software, and no multi-tenant or self-service builder is provided.
@@ -0,0 +1,239 @@
1
+ import { createDatabaseClient, createMessage, getConversationHistory } from '@inkeep/agents-core';
2
+ import { nanoid } from 'nanoid';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import * as dotenv from 'dotenv';
6
+ import { z } from 'zod';
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ dotenv.config({ quiet: true });
12
+ z.enum(["development", "production"]).default("development");
13
+ var environmentSchema = z.enum(["development", "pentest", "production", "test"]);
14
+ var criticalEnv = z.object({
15
+ ENVIRONMENT: environmentSchema
16
+ }).parse(process.env);
17
+ var loadEnvFile = () => {
18
+ const envPath = path.resolve(process.cwd(), `.env.${criticalEnv.ENVIRONMENT}.nonsecret`);
19
+ if (fs.existsSync(envPath)) {
20
+ const envConfig = dotenv.parse(fs.readFileSync(envPath));
21
+ for (const k in envConfig) {
22
+ if (!(k in process.env)) {
23
+ process.env[k] = envConfig[k];
24
+ }
25
+ }
26
+ }
27
+ };
28
+ loadEnvFile();
29
+ var envSchema = z.object({
30
+ NODE_ENV: z.enum(["development", "production", "test"]).optional(),
31
+ ENVIRONMENT: z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
32
+ DB_FILE_NAME: z.string().default("file:../local.db"),
33
+ PORT: z.coerce.number().optional().default(3003),
34
+ AGENT_BASE_URL: z.string().optional(),
35
+ LOG_LEVEL: z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
36
+ NANGO_SECRET_KEY: z.string().optional(),
37
+ OPENAI_API_KEY: z.string().optional(),
38
+ ANTHROPIC_API_KEY: z.string(),
39
+ INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z.string().optional(),
40
+ OTEL_MAX_EXPORT_BATCH_SIZE: z.coerce.number().optional(),
41
+ OTEL_EXPORTER_OTLP_ENDPOINT: z.string().optional().default("http://localhost:14318/v1/traces")
42
+ });
43
+ var parseEnv = () => {
44
+ try {
45
+ const parsedEnv = envSchema.parse(process.env);
46
+ if (!parsedEnv.AGENT_BASE_URL) {
47
+ parsedEnv.AGENT_BASE_URL = `http://localhost:${parsedEnv.PORT}`;
48
+ }
49
+ return parsedEnv;
50
+ } catch (error) {
51
+ if (error instanceof z.ZodError) {
52
+ const missingVars = error.issues.map((issue) => issue.path.join("."));
53
+ throw new Error(
54
+ `\u274C Invalid environment variables: ${missingVars.join(", ")}
55
+ ${error.message}`
56
+ );
57
+ }
58
+ throw error;
59
+ }
60
+ };
61
+ var env = parseEnv();
62
+
63
+ // src/data/db/dbClient.ts
64
+ var getDbUrl = () => {
65
+ if (env.ENVIRONMENT === "test") {
66
+ return ":memory:";
67
+ }
68
+ return env.DB_FILE_NAME;
69
+ };
70
+ var dbClient = createDatabaseClient({ url: getDbUrl() });
71
+ var dbClient_default = dbClient;
72
+
73
+ // src/data/conversations.ts
74
+ function createDefaultConversationHistoryConfig(mode = "full") {
75
+ return {
76
+ mode,
77
+ limit: 50,
78
+ includeInternal: true,
79
+ messageTypes: ["chat"],
80
+ maxOutputTokens: 4e3
81
+ };
82
+ }
83
+ function extractA2AMessageText(parts) {
84
+ return parts.filter((part) => part.kind === "text" && part.text).map((part) => part.text).join("");
85
+ }
86
+ async function saveA2AMessageResponse(response, params) {
87
+ if (response.error) {
88
+ throw new Error(response.error.message);
89
+ }
90
+ let messageText = "";
91
+ if (response.result.kind === "message") {
92
+ messageText = extractA2AMessageText(response.result.parts);
93
+ } else if (response.result.kind === "task") {
94
+ if (response.result.artifacts && response.result.artifacts.length > 0) {
95
+ const firstArtifact = response.result.artifacts[0];
96
+ if (firstArtifact.parts) {
97
+ messageText = extractA2AMessageText(firstArtifact.parts);
98
+ }
99
+ }
100
+ } else if (typeof response.result === "string") {
101
+ messageText = response.result;
102
+ }
103
+ if (!messageText || messageText.trim() === "") {
104
+ return null;
105
+ }
106
+ return await createMessage(dbClient_default)({
107
+ id: nanoid(),
108
+ tenantId: params.tenantId,
109
+ projectId: params.projectId,
110
+ conversationId: params.conversationId,
111
+ role: "agent",
112
+ content: {
113
+ text: messageText
114
+ },
115
+ visibility: params.visibility,
116
+ messageType: params.messageType,
117
+ fromAgentId: params.fromAgentId,
118
+ toAgentId: params.toAgentId,
119
+ fromExternalAgentId: params.fromExternalAgentId,
120
+ toExternalAgentId: params.toExternalAgentId,
121
+ a2aTaskId: params.a2aTaskId,
122
+ a2aSessionId: params.a2aSessionId,
123
+ metadata: params.metadata
124
+ });
125
+ }
126
+ async function getScopedHistory({
127
+ tenantId,
128
+ projectId,
129
+ conversationId,
130
+ filters,
131
+ options
132
+ }) {
133
+ try {
134
+ const messages = await getConversationHistory(dbClient_default)({
135
+ scopes: { tenantId, projectId },
136
+ conversationId,
137
+ options
138
+ });
139
+ if (!filters || !filters.agentId && !filters.taskId) {
140
+ return messages;
141
+ }
142
+ const relevantMessages = messages.filter((msg) => {
143
+ if (msg.role === "user") return true;
144
+ let matchesAgent = true;
145
+ let matchesTask = true;
146
+ if (filters.agentId) {
147
+ matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.agentId || msg.fromAgentId === filters.agentId;
148
+ }
149
+ if (filters.taskId) {
150
+ matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
151
+ }
152
+ if (filters.agentId && filters.taskId) {
153
+ return matchesAgent && matchesTask;
154
+ }
155
+ if (filters.agentId) {
156
+ return matchesAgent;
157
+ }
158
+ if (filters.taskId) {
159
+ return matchesTask;
160
+ }
161
+ return false;
162
+ });
163
+ return relevantMessages;
164
+ } catch (error) {
165
+ console.error("Failed to fetch scoped messages:", error);
166
+ return [];
167
+ }
168
+ }
169
+ async function getUserFacingHistory(tenantId, projectId, conversationId, limit = 50) {
170
+ return await getConversationHistory(dbClient_default)({
171
+ scopes: { tenantId, projectId },
172
+ conversationId,
173
+ options: {
174
+ limit,
175
+ includeInternal: false,
176
+ messageTypes: ["chat"]
177
+ }
178
+ });
179
+ }
180
+ async function getFullConversationContext(tenantId, projectId, conversationId, maxTokens) {
181
+ return await getConversationHistory(dbClient_default)({
182
+ scopes: { tenantId, projectId },
183
+ conversationId,
184
+ options: {
185
+ limit: 100,
186
+ includeInternal: true,
187
+ maxOutputTokens: maxTokens
188
+ }
189
+ });
190
+ }
191
+ async function getFormattedConversationHistory({
192
+ tenantId,
193
+ projectId,
194
+ conversationId,
195
+ currentMessage,
196
+ options,
197
+ filters
198
+ }) {
199
+ const historyOptions = options ?? { includeInternal: true };
200
+ const conversationHistory = await getScopedHistory({
201
+ tenantId,
202
+ projectId,
203
+ conversationId,
204
+ filters,
205
+ options: historyOptions
206
+ });
207
+ let messagesToFormat = conversationHistory;
208
+ if (currentMessage && conversationHistory.length > 0) {
209
+ const lastMessage = conversationHistory[conversationHistory.length - 1];
210
+ if (lastMessage.content.text === currentMessage) {
211
+ messagesToFormat = conversationHistory.slice(0, -1);
212
+ }
213
+ }
214
+ if (!messagesToFormat.length) {
215
+ return "";
216
+ }
217
+ const formattedHistory = messagesToFormat.map((msg) => {
218
+ let roleLabel;
219
+ if (msg.role === "user") {
220
+ roleLabel = "user";
221
+ } else if (msg.role === "agent" && (msg.messageType === "a2a-request" || msg.messageType === "a2a-response")) {
222
+ const fromAgent = msg.fromAgentId || msg.fromExternalAgentId || "unknown";
223
+ const toAgent = msg.toAgentId || msg.toExternalAgentId || "unknown";
224
+ roleLabel = `${fromAgent} to ${toAgent}`;
225
+ } else if (msg.role === "agent" && msg.messageType === "chat") {
226
+ const fromAgent = msg.fromAgentId || "unknown";
227
+ roleLabel = `${fromAgent} to User`;
228
+ } else {
229
+ roleLabel = msg.role || "system";
230
+ }
231
+ return `${roleLabel}: """${msg.content.text}"""`;
232
+ }).join("\n");
233
+ return `<conversation_history>
234
+ ${formattedHistory}
235
+ </conversation_history>
236
+ `;
237
+ }
238
+
239
+ export { __publicField, createDefaultConversationHistoryConfig, dbClient_default, env, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse };
@@ -0,0 +1 @@
1
+ export { createDefaultConversationHistoryConfig, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-P6IQZWFC.js';