@inkeep/agents-run-api 0.39.4 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js +5 -0
  2. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js +5 -0
  3. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js +5 -0
  4. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-component.js +5 -0
  5. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-components.js +5 -0
  6. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/system-prompt.js +5 -0
  7. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
  8. package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js +5 -0
  9. package/dist/a2a/client.d.ts +184 -0
  10. package/dist/a2a/client.js +510 -0
  11. package/dist/a2a/handlers.d.ts +7 -0
  12. package/dist/a2a/handlers.js +560 -0
  13. package/dist/a2a/transfer.d.ts +22 -0
  14. package/dist/a2a/transfer.js +46 -0
  15. package/dist/a2a/types.d.ts +79 -0
  16. package/dist/a2a/types.js +22 -0
  17. package/dist/agents/Agent.d.ts +266 -0
  18. package/dist/agents/Agent.js +1927 -0
  19. package/dist/agents/ModelFactory.d.ts +63 -0
  20. package/dist/agents/ModelFactory.js +194 -0
  21. package/dist/agents/SystemPromptBuilder.d.ts +21 -0
  22. package/dist/agents/SystemPromptBuilder.js +48 -0
  23. package/dist/agents/ToolSessionManager.d.ts +63 -0
  24. package/dist/agents/ToolSessionManager.js +146 -0
  25. package/dist/agents/generateTaskHandler.d.ts +49 -0
  26. package/dist/agents/generateTaskHandler.js +521 -0
  27. package/dist/agents/relationTools.d.ts +57 -0
  28. package/dist/agents/relationTools.js +262 -0
  29. package/dist/agents/types.d.ts +28 -0
  30. package/dist/agents/types.js +1 -0
  31. package/dist/agents/versions/v1/Phase1Config.d.ts +27 -0
  32. package/dist/agents/versions/v1/Phase1Config.js +424 -0
  33. package/dist/agents/versions/v1/Phase2Config.d.ts +31 -0
  34. package/dist/agents/versions/v1/Phase2Config.js +330 -0
  35. package/dist/constants/execution-limits/defaults.d.ts +51 -0
  36. package/dist/constants/execution-limits/defaults.js +52 -0
  37. package/dist/constants/execution-limits/index.d.ts +6 -0
  38. package/dist/constants/execution-limits/index.js +21 -0
  39. package/dist/create-app.d.ts +9 -0
  40. package/dist/create-app.js +195 -0
  41. package/dist/data/agent.d.ts +7 -0
  42. package/dist/data/agent.js +72 -0
  43. package/dist/data/agents.d.ts +34 -0
  44. package/dist/data/agents.js +139 -0
  45. package/dist/data/conversations.d.ts +128 -0
  46. package/dist/data/conversations.js +522 -0
  47. package/dist/data/db/dbClient.d.ts +6 -0
  48. package/dist/data/db/dbClient.js +17 -0
  49. package/dist/env.d.ts +57 -0
  50. package/dist/env.js +1 -2
  51. package/dist/handlers/executionHandler.d.ts +39 -0
  52. package/dist/handlers/executionHandler.js +456 -0
  53. package/dist/index.d.ts +8 -29
  54. package/dist/index.js +5 -11235
  55. package/dist/instrumentation.d.ts +1 -2
  56. package/dist/instrumentation.js +66 -3
  57. package/dist/{logger2.js → logger.d.ts} +1 -2
  58. package/dist/logger.js +1 -1
  59. package/dist/middleware/api-key-auth.d.ts +26 -0
  60. package/dist/middleware/api-key-auth.js +240 -0
  61. package/dist/middleware/index.d.ts +2 -0
  62. package/dist/middleware/index.js +3 -0
  63. package/dist/openapi.d.ts +4 -0
  64. package/dist/openapi.js +54 -0
  65. package/dist/routes/agents.d.ts +12 -0
  66. package/dist/routes/agents.js +147 -0
  67. package/dist/routes/chat.d.ts +13 -0
  68. package/dist/routes/chat.js +293 -0
  69. package/dist/routes/chatDataStream.d.ts +13 -0
  70. package/dist/routes/chatDataStream.js +352 -0
  71. package/dist/routes/mcp.d.ts +13 -0
  72. package/dist/routes/mcp.js +495 -0
  73. package/dist/services/AgentSession.d.ts +356 -0
  74. package/dist/services/AgentSession.js +1208 -0
  75. package/dist/services/ArtifactParser.d.ts +105 -0
  76. package/dist/services/ArtifactParser.js +338 -0
  77. package/dist/services/ArtifactService.d.ts +123 -0
  78. package/dist/services/ArtifactService.js +612 -0
  79. package/dist/services/BaseCompressor.d.ts +183 -0
  80. package/dist/services/BaseCompressor.js +504 -0
  81. package/dist/services/ConversationCompressor.d.ts +32 -0
  82. package/dist/services/ConversationCompressor.js +91 -0
  83. package/dist/services/IncrementalStreamParser.d.ts +98 -0
  84. package/dist/services/IncrementalStreamParser.js +327 -0
  85. package/dist/services/MidGenerationCompressor.d.ts +63 -0
  86. package/dist/services/MidGenerationCompressor.js +104 -0
  87. package/dist/services/PendingToolApprovalManager.d.ts +62 -0
  88. package/dist/services/PendingToolApprovalManager.js +133 -0
  89. package/dist/services/ResponseFormatter.d.ts +39 -0
  90. package/dist/services/ResponseFormatter.js +152 -0
  91. package/dist/tools/NativeSandboxExecutor.d.ts +38 -0
  92. package/dist/tools/NativeSandboxExecutor.js +432 -0
  93. package/dist/tools/SandboxExecutorFactory.d.ts +36 -0
  94. package/dist/tools/SandboxExecutorFactory.js +80 -0
  95. package/dist/tools/VercelSandboxExecutor.d.ts +71 -0
  96. package/dist/tools/VercelSandboxExecutor.js +340 -0
  97. package/dist/tools/distill-conversation-history-tool.d.ts +62 -0
  98. package/dist/tools/distill-conversation-history-tool.js +206 -0
  99. package/dist/tools/distill-conversation-tool.d.ts +41 -0
  100. package/dist/tools/distill-conversation-tool.js +141 -0
  101. package/dist/tools/sandbox-utils.d.ts +18 -0
  102. package/dist/tools/sandbox-utils.js +53 -0
  103. package/dist/types/chat.d.ts +27 -0
  104. package/dist/types/chat.js +1 -0
  105. package/dist/types/execution-context.d.ts +46 -0
  106. package/dist/types/execution-context.js +27 -0
  107. package/dist/types/xml.d.ts +5 -0
  108. package/dist/utils/SchemaProcessor.d.ts +52 -0
  109. package/dist/utils/SchemaProcessor.js +182 -0
  110. package/dist/utils/agent-operations.d.ts +62 -0
  111. package/dist/utils/agent-operations.js +53 -0
  112. package/dist/utils/artifact-component-schema.d.ts +42 -0
  113. package/dist/utils/artifact-component-schema.js +186 -0
  114. package/dist/utils/cleanup.d.ts +21 -0
  115. package/dist/utils/cleanup.js +59 -0
  116. package/dist/utils/data-component-schema.d.ts +2 -0
  117. package/dist/utils/data-component-schema.js +3 -0
  118. package/dist/utils/default-status-schemas.d.ts +20 -0
  119. package/dist/utils/default-status-schemas.js +24 -0
  120. package/dist/utils/json-postprocessor.d.ts +13 -0
  121. package/dist/{json-postprocessor.cjs → utils/json-postprocessor.js} +1 -2
  122. package/dist/utils/model-context-utils.d.ts +39 -0
  123. package/dist/utils/model-context-utils.js +181 -0
  124. package/dist/utils/model-resolver.d.ts +6 -0
  125. package/dist/utils/model-resolver.js +34 -0
  126. package/dist/utils/schema-validation.d.ts +44 -0
  127. package/dist/utils/schema-validation.js +97 -0
  128. package/dist/utils/stream-helpers.d.ts +197 -0
  129. package/dist/utils/stream-helpers.js +518 -0
  130. package/dist/utils/stream-registry.d.ts +22 -0
  131. package/dist/utils/stream-registry.js +34 -0
  132. package/dist/utils/token-estimator.d.ts +69 -0
  133. package/dist/utils/token-estimator.js +53 -0
  134. package/dist/utils/tracer.d.ts +7 -0
  135. package/dist/utils/tracer.js +7 -0
  136. package/package.json +5 -20
  137. package/dist/SandboxExecutorFactory.cjs +0 -895
  138. package/dist/SandboxExecutorFactory.js +0 -893
  139. package/dist/SandboxExecutorFactory.js.map +0 -1
  140. package/dist/chunk-VBDAOXYI.cjs +0 -927
  141. package/dist/chunk-VBDAOXYI.js +0 -832
  142. package/dist/chunk-VBDAOXYI.js.map +0 -1
  143. package/dist/chunk.cjs +0 -34
  144. package/dist/conversations.cjs +0 -7
  145. package/dist/conversations.js +0 -7
  146. package/dist/conversations2.cjs +0 -209
  147. package/dist/conversations2.js +0 -180
  148. package/dist/conversations2.js.map +0 -1
  149. package/dist/dbClient.cjs +0 -9676
  150. package/dist/dbClient.js +0 -9670
  151. package/dist/dbClient.js.map +0 -1
  152. package/dist/dbClient2.cjs +0 -5
  153. package/dist/dbClient2.js +0 -5
  154. package/dist/env.cjs +0 -59
  155. package/dist/env.js.map +0 -1
  156. package/dist/execution-limits.cjs +0 -260
  157. package/dist/execution-limits.js +0 -63
  158. package/dist/execution-limits.js.map +0 -1
  159. package/dist/index.cjs +0 -11260
  160. package/dist/index.d.cts +0 -36
  161. package/dist/index.d.cts.map +0 -1
  162. package/dist/index.d.ts.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/instrumentation.cjs +0 -12
  165. package/dist/instrumentation.d.cts +0 -18
  166. package/dist/instrumentation.d.cts.map +0 -1
  167. package/dist/instrumentation.d.ts.map +0 -1
  168. package/dist/instrumentation2.cjs +0 -116
  169. package/dist/instrumentation2.js +0 -69
  170. package/dist/instrumentation2.js.map +0 -1
  171. package/dist/json-postprocessor.js +0 -20
  172. package/dist/json-postprocessor.js.map +0 -1
  173. package/dist/logger.cjs +0 -5
  174. package/dist/logger2.cjs +0 -1
  175. package/dist/nodefs.cjs +0 -29
  176. package/dist/nodefs.js +0 -27
  177. package/dist/nodefs.js.map +0 -1
  178. package/dist/opfs-ahp.cjs +0 -367
  179. package/dist/opfs-ahp.js +0 -368
  180. package/dist/opfs-ahp.js.map +0 -1
@@ -0,0 +1,42 @@
1
+ import { z } from "@hono/zod-openapi";
2
+ import { ArtifactComponentApiInsert, ArtifactComponentApiSelect, DataComponentInsert } from "@inkeep/agents-core";
3
+
4
+ //#region src/utils/artifact-component-schema.d.ts
5
+
6
+ /**
7
+ * Converts artifact component configurations to Zod schema for structured generation
8
+ */
9
+ declare function createArtifactComponentsSchema(artifactComponents?: ArtifactComponentApiSelect[]): z.ZodObject<{}, z.core.$strip> | z.ZodUnion<any>;
10
+ /**
11
+ * Standard artifact reference component schema for tool responses
12
+ */
13
+ declare class ArtifactReferenceSchema {
14
+ private static readonly ARTIFACT_PROPS_SCHEMA;
15
+ /**
16
+ * Get the standard Zod schema for artifact reference components
17
+ */
18
+ static getSchema(): z.ZodType<any>;
19
+ /**
20
+ * Get complete DataComponent by adding missing fields to base definition
21
+ */
22
+ static getDataComponent(tenantId: string, projectId?: string): DataComponentInsert;
23
+ }
24
+ /**
25
+ * Standard artifact creation component schema for data components
26
+ */
27
+ declare class ArtifactCreateSchema {
28
+ /**
29
+ * Generate artifact create schemas - one for each artifact component type
30
+ * @param artifactComponents - The available artifact components to generate schemas for
31
+ * @returns Array of Zod schemas, one for each artifact component
32
+ */
33
+ static getSchemas(artifactComponents: Array<ArtifactComponentApiInsert | ArtifactComponentApiSelect>): z.ZodType<any>[];
34
+ /**
35
+ * Get DataComponents for artifact creation - one for each artifact component type
36
+ * @param artifactComponents - The available artifact components to generate schemas for
37
+ * @returns Array of DataComponent definitions, one for each artifact component
38
+ */
39
+ static getDataComponents(tenantId: string, projectId: string | undefined, artifactComponents: Array<ArtifactComponentApiInsert | ArtifactComponentApiSelect>): DataComponentInsert[];
40
+ }
41
+ //#endregion
42
+ export { ArtifactCreateSchema, ArtifactReferenceSchema, createArtifactComponentsSchema };
@@ -0,0 +1,186 @@
1
+ import { getLogger } from "../logger.js";
2
+ import { jsonSchemaToZod } from "./data-component-schema.js";
3
+ import { SchemaProcessor } from "./SchemaProcessor.js";
4
+ import { z } from "@hono/zod-openapi";
5
+
6
+ //#region src/utils/artifact-component-schema.ts
7
+ getLogger("ArtifactComponentSchema");
8
+ /**
9
+ * Converts artifact component configurations to Zod schema for structured generation
10
+ */
11
+ function createArtifactComponentsSchema(artifactComponents) {
12
+ const componentSchemas = artifactComponents?.map((component) => {
13
+ const propsSchema = jsonSchemaToZod(component.props ? removePreviewFlags(component.props) : {});
14
+ return z.object({
15
+ id: z.string().describe(component.id),
16
+ name: z.literal(component.name).describe(component.name),
17
+ props: propsSchema
18
+ }).describe(`${component.name}: ${component.description}`);
19
+ }) || [];
20
+ if (componentSchemas.length === 0) return z.object({});
21
+ if (componentSchemas.length === 1) return componentSchemas[0];
22
+ return z.union(componentSchemas);
23
+ }
24
+ /**
25
+ * Remove inPreview flags from schema properties (for LLM consumption)
26
+ */
27
+ function removePreviewFlags(schema) {
28
+ const cleanSchema = { ...schema };
29
+ if (cleanSchema.properties) {
30
+ const cleanProperties = {};
31
+ for (const [key, prop] of Object.entries(cleanSchema.properties)) {
32
+ const cleanProp = { ...prop };
33
+ delete cleanProp.inPreview;
34
+ cleanProperties[key] = cleanProp;
35
+ }
36
+ cleanSchema.properties = cleanProperties;
37
+ }
38
+ return cleanSchema;
39
+ }
40
+ /**
41
+ * Standard artifact reference component schema for tool responses
42
+ */
43
+ var ArtifactReferenceSchema = class ArtifactReferenceSchema {
44
+ static ARTIFACT_PROPS_SCHEMA = {
45
+ type: "object",
46
+ properties: {
47
+ artifact_id: {
48
+ type: "string",
49
+ description: "The artifact_id from your artifact:create tag. Must match exactly."
50
+ },
51
+ tool_call_id: {
52
+ type: "string",
53
+ description: "The EXACT tool_call_id from tool execution (call_xyz789 or toolu_abc123). NEVER invent or make up IDs."
54
+ }
55
+ },
56
+ required: ["artifact_id", "tool_call_id"]
57
+ };
58
+ /**
59
+ * Get the standard Zod schema for artifact reference components
60
+ */
61
+ static getSchema() {
62
+ return z.object({
63
+ id: z.string(),
64
+ name: z.literal("Artifact"),
65
+ props: jsonSchemaToZod(ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
66
+ });
67
+ }
68
+ /**
69
+ * Get complete DataComponent by adding missing fields to base definition
70
+ */
71
+ static getDataComponent(tenantId, projectId = "") {
72
+ return {
73
+ id: "The artifact_id from your artifact:create tag. Must match exactly.",
74
+ tenantId,
75
+ projectId,
76
+ name: "Artifact",
77
+ description: "Reference to artifacts created from tool results that grounds information in verifiable sources.",
78
+ props: ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA
79
+ };
80
+ }
81
+ };
82
+ /**
83
+ * Standard artifact creation component schema for data components
84
+ */
85
+ var ArtifactCreateSchema = class {
86
+ /**
87
+ * Generate artifact create schemas - one for each artifact component type
88
+ * @param artifactComponents - The available artifact components to generate schemas for
89
+ * @returns Array of Zod schemas, one for each artifact component
90
+ */
91
+ static getSchemas(artifactComponents) {
92
+ return artifactComponents.map((component) => {
93
+ const enhancedSchema = component.props ? SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.props) : {
94
+ type: "object",
95
+ properties: {}
96
+ };
97
+ const propsSchema = {
98
+ type: "object",
99
+ properties: {
100
+ id: {
101
+ type: "string",
102
+ description: `Unique artifact identifier for ${component.name} (e.g., "${component.name.toLowerCase()}-1")`
103
+ },
104
+ tool_call_id: {
105
+ type: "string",
106
+ description: "The EXACT tool_call_id from tool execution (call_xyz789 or toolu_abc123). NEVER invent or make up IDs."
107
+ },
108
+ type: {
109
+ type: "string",
110
+ enum: [component.name],
111
+ description: `Artifact type - must be "${component.name}"`
112
+ },
113
+ base_selector: {
114
+ type: "string",
115
+ description: "JMESPath selector starting with \"result.\" to navigate to ONE specific item. Details selector will be relative to this selection. Use filtering to avoid arrays (e.g., \"result.items[?type=='guide']\")."
116
+ },
117
+ details_selector: enhancedSchema
118
+ },
119
+ required: [
120
+ "id",
121
+ "tool_call_id",
122
+ "type",
123
+ "base_selector"
124
+ ]
125
+ };
126
+ return z.object({
127
+ id: z.string(),
128
+ name: z.literal(`ArtifactCreate_${component.name}`),
129
+ props: jsonSchemaToZod(propsSchema)
130
+ });
131
+ });
132
+ }
133
+ /**
134
+ * Get DataComponents for artifact creation - one for each artifact component type
135
+ * @param artifactComponents - The available artifact components to generate schemas for
136
+ * @returns Array of DataComponent definitions, one for each artifact component
137
+ */
138
+ static getDataComponents(tenantId, projectId = "", artifactComponents) {
139
+ return artifactComponents.map((component) => {
140
+ const enhancedSchema = component.props ? SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.props) : {
141
+ type: "object",
142
+ properties: {}
143
+ };
144
+ const propsSchema = {
145
+ type: "object",
146
+ properties: {
147
+ id: {
148
+ type: "string",
149
+ description: `Unique artifact identifier for ${component.name} (e.g., "${component.name.toLowerCase()}-1")`
150
+ },
151
+ tool_call_id: {
152
+ type: "string",
153
+ description: "The EXACT tool_call_id from tool execution (call_xyz789 or toolu_abc123). NEVER invent or make up IDs."
154
+ },
155
+ type: {
156
+ type: "string",
157
+ enum: [component.name],
158
+ description: `Artifact type - must be "${component.name}"`
159
+ },
160
+ base_selector: {
161
+ type: "string",
162
+ description: "JMESPath selector starting with \"result.\" to navigate to ONE specific item. Details selector will be relative to this selection. Use filtering to avoid arrays (e.g., \"result.items[?type=='guide']\")."
163
+ },
164
+ details_selector: enhancedSchema
165
+ },
166
+ required: [
167
+ "id",
168
+ "tool_call_id",
169
+ "type",
170
+ "base_selector"
171
+ ]
172
+ };
173
+ return {
174
+ id: `artifact-create-${component.name.toLowerCase().replace(/\s+/g, "-")}`,
175
+ tenantId,
176
+ projectId,
177
+ name: `ArtifactCreate_${component.name}`,
178
+ description: `Create ${component.name} artifacts from tool results by extracting structured data using selectors.`,
179
+ props: propsSchema
180
+ };
181
+ });
182
+ }
183
+ };
184
+
185
+ //#endregion
186
+ export { ArtifactCreateSchema, ArtifactReferenceSchema, createArtifactComponentsSchema };
@@ -0,0 +1,21 @@
1
+ //#region src/utils/cleanup.d.ts
2
+ /**
3
+ * Cleanup utilities for gracefully shutting down resources
4
+ * Helps prevent Node.js processes from hanging
5
+ */
6
+ /**
7
+ * Gracefully exit the process after cleaning up resources
8
+ */
9
+ declare function gracefulExit(code?: number, delayMs?: number, message?: string): void;
10
+ /**
11
+ * Setup signal handlers for graceful shutdown
12
+ */
13
+ declare function setupGracefulShutdown(cleanupFn?: () => Promise<void> | void, exitDelayMs?: number): void;
14
+ /**
15
+ * Stop all tools associated with agents
16
+ */
17
+ declare function stopAllAgentTools(agents: Array<{
18
+ getTools: () => Record<string, any>;
19
+ }>): Promise<void>;
20
+ //#endregion
21
+ export { gracefulExit, setupGracefulShutdown, stopAllAgentTools };
@@ -0,0 +1,59 @@
1
+ import { getLogger } from "../logger.js";
2
+
3
+ //#region src/utils/cleanup.ts
4
+ /**
5
+ * Cleanup utilities for gracefully shutting down resources
6
+ * Helps prevent Node.js processes from hanging
7
+ */
8
+ const logger = getLogger("cleanup");
9
+ /**
10
+ * Gracefully exit the process after cleaning up resources
11
+ */
12
+ function gracefulExit(code = 0, delayMs = 1e3, message) {
13
+ if (message) logger.info({}, message);
14
+ setTimeout(() => {
15
+ logger.debug({}, "Forcing process exit after cleanup delay");
16
+ process.exit(code);
17
+ }, delayMs);
18
+ }
19
+ /**
20
+ * Setup signal handlers for graceful shutdown
21
+ */
22
+ function setupGracefulShutdown(cleanupFn, exitDelayMs = 2e3) {
23
+ const signals = ["SIGTERM", "SIGINT"];
24
+ let isShuttingDown = false;
25
+ for (const signal of signals) process.on(signal, async () => {
26
+ if (isShuttingDown) {
27
+ logger.warn({}, `Received ${signal} during shutdown, forcing exit`);
28
+ process.exit(1);
29
+ }
30
+ logger.info({}, `Received ${signal}, starting graceful shutdown`);
31
+ isShuttingDown = true;
32
+ try {
33
+ if (cleanupFn) await cleanupFn();
34
+ } catch (error) {
35
+ logger.error({ error }, "Error during cleanup");
36
+ }
37
+ gracefulExit(0, exitDelayMs, "🚪 Graceful shutdown complete");
38
+ });
39
+ }
40
+ /**
41
+ * Stop all tools associated with agents
42
+ */
43
+ async function stopAllAgentTools(agents) {
44
+ logger.info({}, "Stopping all agent tools...");
45
+ for (const agent of agents) {
46
+ const tools = agent.getTools();
47
+ for (const toolInstance of Object.values(tools)) if (toolInstance && typeof toolInstance.stop === "function") try {
48
+ await toolInstance.stop();
49
+ const toolName = toolInstance.config?.name || "unknown";
50
+ logger.debug({}, `Stopped tool: ${toolName}`);
51
+ } catch (error) {
52
+ logger.warn({}, `Failed to stop tool: ${error instanceof Error ? error.message : "Unknown error"}`);
53
+ }
54
+ }
55
+ logger.info({}, "All agent tools stopped");
56
+ }
57
+
58
+ //#endregion
59
+ export { gracefulExit, setupGracefulShutdown, stopAllAgentTools };
@@ -0,0 +1,2 @@
1
+ import { jsonSchemaToZod } from "@inkeep/agents-core";
2
+ export { jsonSchemaToZod };
@@ -0,0 +1,3 @@
1
+ import { jsonSchemaToZod } from "@inkeep/agents-core";
2
+
3
+ export { jsonSchemaToZod };
@@ -0,0 +1,20 @@
1
+ import { StatusComponent } from "@inkeep/agents-core";
2
+
3
+ //#region src/utils/default-status-schemas.d.ts
4
+
5
+ /**
6
+ * Schema for retrieve operations - when agents are looking up, searching,
7
+ * or researching information in web or downstream services
8
+ */
9
+ declare const retrieveStatusSchema: StatusComponent;
10
+ /**
11
+ * Schema for action operations - when agents are using tools or delegating
12
+ * tasks with side-effects to update, create, or modify downstream services
13
+ */
14
+ declare const actionStatusSchema: StatusComponent;
15
+ /**
16
+ * Default status component schemas collection
17
+ */
18
+ declare const defaultStatusSchemas: StatusComponent[];
19
+ //#endregion
20
+ export { actionStatusSchema, defaultStatusSchemas, retrieveStatusSchema };
@@ -0,0 +1,24 @@
1
+ //#region src/utils/default-status-schemas.ts
2
+ /**
3
+ * Schema for retrieve operations - when agents are looking up, searching,
4
+ * or researching information in web or downstream services
5
+ */
6
+ const retrieveStatusSchema = {
7
+ type: "retrieve",
8
+ description: "Use this when the system found or retrieved specific information from searches, queries, or lookups. ONLY report ACTUAL findings that appear explicitly in the tool results - never make up data, names, numbers, or details. The label must state the SPECIFIC discovery (e.g., \"Found 3 authentication methods\", \"Database contains 500 records\", \"API supports JSON format\") not the act of searching. Every detail must be traceable to actual tool output. NEVER invent placeholder names, fictional data, or information not present in the activities."
9
+ };
10
+ /**
11
+ * Schema for action operations - when agents are using tools or delegating
12
+ * tasks with side-effects to update, create, or modify downstream services
13
+ */
14
+ const actionStatusSchema = {
15
+ type: "action",
16
+ description: "Use this when the system executed a tool or performed an operation that modified state or had side effects. ONLY report ACTUAL tool executions and their results as they appear in the tool outputs - never make up tool names, parameters, or outcomes. The label must describe what specific action was performed and its concrete result based on actual tool execution data. DO NOT make up examples like \"Ran test suite with X passes\" unless a test suite was ACTUALLY run and reported X passes. DO NOT say \"Executed database query\" unless a database query was ACTUALLY executed. Only report what literally happened. NEVER invent tool names, execution results, or details not explicitly present in the tool execution activities. If a tool failed, report the actual failure, not imagined success."
17
+ };
18
+ /**
19
+ * Default status component schemas collection
20
+ */
21
+ const defaultStatusSchemas = [retrieveStatusSchema, actionStatusSchema];
22
+
23
+ //#endregion
24
+ export { actionStatusSchema, defaultStatusSchemas, retrieveStatusSchema };
@@ -0,0 +1,13 @@
1
+ //#region src/utils/json-postprocessor.d.ts
2
+ /**
3
+ * Simple post-processor to clean up common LLM JSON formatting issues
4
+ */
5
+ declare function stripJsonCodeBlocks(text: string): string;
6
+ /**
7
+ * Configuration helper to add JSON post-processing to generateObject calls
8
+ */
9
+ declare function withJsonPostProcessing<T extends Record<string, any>>(config: T): T & {
10
+ experimental_transform?: (text: string) => string;
11
+ };
12
+ //#endregion
13
+ export { stripJsonCodeBlocks, withJsonPostProcessing };
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/utils/json-postprocessor.ts
3
2
  /**
4
3
  * Simple post-processor to clean up common LLM JSON formatting issues
@@ -17,4 +16,4 @@ function withJsonPostProcessing(config) {
17
16
  }
18
17
 
19
18
  //#endregion
20
- exports.withJsonPostProcessing = withJsonPostProcessing;
19
+ export { stripJsonCodeBlocks, withJsonPostProcessing };
@@ -0,0 +1,39 @@
1
+ import { ModelSettings } from "@inkeep/agents-core";
2
+
3
+ //#region src/utils/model-context-utils.d.ts
4
+
5
+ /**
6
+ * Get context window information for a model
7
+ */
8
+ interface ModelContextInfo {
9
+ contextWindow: number | null;
10
+ hasValidContextWindow: boolean;
11
+ modelId: string;
12
+ source: 'llm-info' | 'fallback';
13
+ }
14
+ /**
15
+ * Extract model ID from model string for llm-info lookup
16
+ * Includes smart mapping to find dated versions for models that don't have exact matches
17
+ */
18
+ declare function extractModelIdForLlmInfo(modelInput: string): string;
19
+ declare function extractModelIdForLlmInfo(modelSettings?: ModelSettings): string | null;
20
+ /**
21
+ * Get context window size for a model using llm-info
22
+ * Falls back to default values if model not found
23
+ */
24
+ declare function getModelContextWindow(modelSettings?: ModelSettings): ModelContextInfo;
25
+ /**
26
+ * Get compression configuration based on model context window
27
+ * Uses actual model context window when available, otherwise falls back to environment variables
28
+ * @param modelSettings - Model settings to get context window for
29
+ * @param targetPercentage - Target percentage of context window to use (e.g., 0.5 for conversation, undefined for model-aware defaults)
30
+ */
31
+ declare function getCompressionConfigForModel(modelSettings?: ModelSettings, targetPercentage?: number): {
32
+ hardLimit: number;
33
+ safetyBuffer: number;
34
+ enabled: boolean;
35
+ source: string;
36
+ modelContextInfo: ModelContextInfo;
37
+ };
38
+ //#endregion
39
+ export { ModelContextInfo, extractModelIdForLlmInfo, getCompressionConfigForModel, getModelContextWindow };
@@ -0,0 +1,181 @@
1
+ import { getLogger } from "../logger.js";
2
+ import { COMPRESSION_ENABLED, COMPRESSION_HARD_LIMIT, COMPRESSION_SAFETY_BUFFER } from "../constants/execution-limits/index.js";
3
+ import { ModelInfoMap } from "llm-info";
4
+
5
+ //#region src/utils/model-context-utils.ts
6
+ const logger = getLogger("ModelContextUtils");
7
+ function extractModelIdForLlmInfo(modelInput) {
8
+ let modelString;
9
+ if (typeof modelInput === "string") {
10
+ modelString = modelInput.trim();
11
+ if (!modelString) return null;
12
+ } else if (modelInput?.model) {
13
+ modelString = modelInput.model.trim();
14
+ if (!modelString) return null;
15
+ } else return null;
16
+ let modelId;
17
+ if (modelString.includes("/")) {
18
+ const parts = modelString.split("/");
19
+ modelId = parts[parts.length - 1];
20
+ } else modelId = modelString;
21
+ if (modelId in ModelInfoMap) return modelId;
22
+ const matchingModels = Object.keys(ModelInfoMap).filter((key) => key.startsWith(modelId));
23
+ if (matchingModels.length > 0) return matchingModels.sort().reverse()[0];
24
+ return modelId;
25
+ }
26
+ /**
27
+ * Get context window size for a model using llm-info
28
+ * Falls back to default values if model not found
29
+ */
30
+ function getModelContextWindow(modelSettings) {
31
+ const defaultContextWindow = 12e4;
32
+ if (!modelSettings?.model) {
33
+ logger.debug({}, "No model settings provided, using fallback");
34
+ return {
35
+ contextWindow: defaultContextWindow,
36
+ hasValidContextWindow: false,
37
+ modelId: "unknown",
38
+ source: "fallback"
39
+ };
40
+ }
41
+ const modelId = extractModelIdForLlmInfo(modelSettings);
42
+ if (!modelId) {
43
+ logger.debug({ modelString: modelSettings.model }, "Could not extract model ID for llm-info lookup");
44
+ return {
45
+ contextWindow: defaultContextWindow,
46
+ hasValidContextWindow: false,
47
+ modelId: modelSettings.model,
48
+ source: "fallback"
49
+ };
50
+ }
51
+ try {
52
+ const modelDetails = ModelInfoMap[modelId];
53
+ if (modelDetails && modelDetails.contextWindowTokenLimit && modelDetails.contextWindowTokenLimit > 0) {
54
+ logger.debug({
55
+ modelId,
56
+ contextWindow: modelDetails.contextWindowTokenLimit,
57
+ originalModel: modelSettings.model
58
+ }, "Found context window from llm-info");
59
+ return {
60
+ contextWindow: modelDetails.contextWindowTokenLimit,
61
+ hasValidContextWindow: true,
62
+ modelId,
63
+ source: "llm-info"
64
+ };
65
+ }
66
+ logger.debug({
67
+ modelId,
68
+ modelDetails,
69
+ originalModel: modelSettings.model
70
+ }, "No valid context window found in llm-info");
71
+ } catch (error) {
72
+ logger.debug({
73
+ modelId,
74
+ error: error instanceof Error ? error.message : String(error),
75
+ originalModel: modelSettings.model
76
+ }, "Error getting model details from llm-info");
77
+ }
78
+ logger.debug({
79
+ modelId,
80
+ defaultContextWindow
81
+ }, "Using fallback context window");
82
+ return {
83
+ contextWindow: defaultContextWindow,
84
+ hasValidContextWindow: false,
85
+ modelId,
86
+ source: "fallback"
87
+ };
88
+ }
89
+ /**
90
+ * Get model-size aware compression parameters
91
+ * Uses aggressive thresholds for better utilization, especially on large models
92
+ */
93
+ function getCompressionParams(contextWindow) {
94
+ if (contextWindow < 1e5) return {
95
+ threshold: .85,
96
+ bufferPct: .1
97
+ };
98
+ if (contextWindow < 5e5) return {
99
+ threshold: .9,
100
+ bufferPct: .07
101
+ };
102
+ return {
103
+ threshold: .95,
104
+ bufferPct: .04
105
+ };
106
+ }
107
+ /**
108
+ * Get compression configuration based on model context window
109
+ * Uses actual model context window when available, otherwise falls back to environment variables
110
+ * @param modelSettings - Model settings to get context window for
111
+ * @param targetPercentage - Target percentage of context window to use (e.g., 0.5 for conversation, undefined for model-aware defaults)
112
+ */
113
+ function getCompressionConfigForModel(modelSettings, targetPercentage) {
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());
117
+ const enabled = process.env.AGENTS_COMPRESSION_ENABLED !== "false" && COMPRESSION_ENABLED;
118
+ if (modelContextInfo.hasValidContextWindow && modelContextInfo.contextWindow) {
119
+ let hardLimit;
120
+ let safetyBuffer;
121
+ let logContext;
122
+ if (targetPercentage !== void 0) {
123
+ hardLimit = Math.floor(modelContextInfo.contextWindow * targetPercentage);
124
+ safetyBuffer = Math.floor(modelContextInfo.contextWindow * .05);
125
+ const triggerPoint = hardLimit - safetyBuffer;
126
+ const triggerPercentage = (triggerPoint / modelContextInfo.contextWindow * 100).toFixed(1);
127
+ logContext = {
128
+ modelId: modelContextInfo.modelId,
129
+ contextWindow: modelContextInfo.contextWindow,
130
+ hardLimit,
131
+ safetyBuffer,
132
+ triggerPoint,
133
+ triggerPercentage: `${triggerPercentage}%`,
134
+ targetPercentage: `${(targetPercentage * 100).toFixed(1)}%`,
135
+ compressionType: targetPercentage <= .6 ? "conversation" : "mid-generation"
136
+ };
137
+ logger.info(logContext, "Using percentage-based compression configuration");
138
+ } else {
139
+ const params = getCompressionParams(modelContextInfo.contextWindow);
140
+ hardLimit = Math.floor(modelContextInfo.contextWindow * params.threshold);
141
+ safetyBuffer = Math.floor(modelContextInfo.contextWindow * params.bufferPct);
142
+ const triggerPoint = hardLimit - safetyBuffer;
143
+ const triggerPercentage = (triggerPoint / modelContextInfo.contextWindow * 100).toFixed(1);
144
+ logContext = {
145
+ modelId: modelContextInfo.modelId,
146
+ contextWindow: modelContextInfo.contextWindow,
147
+ hardLimit,
148
+ safetyBuffer,
149
+ triggerPoint,
150
+ triggerPercentage: `${triggerPercentage}%`,
151
+ threshold: params.threshold,
152
+ bufferPct: params.bufferPct
153
+ };
154
+ logger.info(logContext, "Using model-size aware compression configuration");
155
+ }
156
+ return {
157
+ hardLimit,
158
+ safetyBuffer,
159
+ enabled,
160
+ source: "model-specific",
161
+ modelContextInfo
162
+ };
163
+ }
164
+ const source = process.env.AGENTS_COMPRESSION_HARD_LIMIT ? "environment" : "default";
165
+ logger.debug({
166
+ modelId: modelContextInfo.modelId,
167
+ hardLimit: envHardLimit,
168
+ safetyBuffer: envSafetyBuffer,
169
+ source
170
+ }, "Using fallback compression configuration");
171
+ return {
172
+ hardLimit: envHardLimit,
173
+ safetyBuffer: envSafetyBuffer,
174
+ enabled,
175
+ source,
176
+ modelContextInfo
177
+ };
178
+ }
179
+
180
+ //#endregion
181
+ export { extractModelIdForLlmInfo, getCompressionConfigForModel, getModelContextWindow };
@@ -0,0 +1,6 @@
1
+ import { Models, SubAgentSelect } from "@inkeep/agents-core";
2
+
3
+ //#region src/utils/model-resolver.d.ts
4
+ declare function resolveModelConfig(agentId: string, subAgent: SubAgentSelect): Promise<Models>;
5
+ //#endregion
6
+ export { resolveModelConfig };
@@ -0,0 +1,34 @@
1
+ import dbClient_default from "../data/db/dbClient.js";
2
+ import { getAgentById, getProject } from "@inkeep/agents-core";
3
+
4
+ //#region src/utils/model-resolver.ts
5
+ async function resolveModelConfig(agentId, subAgent) {
6
+ if (subAgent.models?.base?.model) return {
7
+ base: subAgent.models.base,
8
+ structuredOutput: subAgent.models.structuredOutput || subAgent.models.base,
9
+ summarizer: subAgent.models.summarizer || subAgent.models.base
10
+ };
11
+ const agent = await getAgentById(dbClient_default)({ scopes: {
12
+ tenantId: subAgent.tenantId,
13
+ projectId: subAgent.projectId,
14
+ agentId
15
+ } });
16
+ if (agent?.models?.base?.model) return {
17
+ base: agent.models.base,
18
+ structuredOutput: subAgent.models?.structuredOutput || agent.models.structuredOutput || agent.models.base,
19
+ summarizer: subAgent.models?.summarizer || agent.models.summarizer || agent.models.base
20
+ };
21
+ const project = await getProject(dbClient_default)({ scopes: {
22
+ tenantId: subAgent.tenantId,
23
+ projectId: subAgent.projectId
24
+ } });
25
+ if (project?.models?.base?.model) return {
26
+ base: project.models.base,
27
+ structuredOutput: subAgent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
28
+ summarizer: subAgent.models?.summarizer || project.models.summarizer || project.models.base
29
+ };
30
+ throw new Error("Base model configuration is required. Please configure models at the project level.");
31
+ }
32
+
33
+ //#endregion
34
+ export { resolveModelConfig };