@inkeep/agents-run-api 0.0.0-dev-20251222193909 → 0.0.0-dev-20251222214618
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,80 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import { NativeSandboxExecutor } from "./NativeSandboxExecutor.js";
|
|
3
|
+
import { VercelSandboxExecutor } from "./VercelSandboxExecutor.js";
|
|
4
|
+
|
|
5
|
+
//#region src/tools/SandboxExecutorFactory.ts
|
|
6
|
+
const logger = getLogger("SandboxExecutorFactory");
|
|
7
|
+
/**
|
|
8
|
+
* Factory for creating and managing sandbox executors
|
|
9
|
+
* Routes execution to the appropriate sandbox provider (native or Vercel)
|
|
10
|
+
*/
|
|
11
|
+
var SandboxExecutorFactory = class SandboxExecutorFactory {
|
|
12
|
+
static instance;
|
|
13
|
+
nativeExecutor = null;
|
|
14
|
+
vercelExecutors = /* @__PURE__ */ new Map();
|
|
15
|
+
constructor() {
|
|
16
|
+
logger.info({}, "SandboxExecutorFactory initialized");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get singleton instance of SandboxExecutorFactory
|
|
20
|
+
*/
|
|
21
|
+
static getInstance() {
|
|
22
|
+
if (!SandboxExecutorFactory.instance) SandboxExecutorFactory.instance = new SandboxExecutorFactory();
|
|
23
|
+
return SandboxExecutorFactory.instance;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Execute a function tool using the appropriate sandbox provider
|
|
27
|
+
*/
|
|
28
|
+
async executeFunctionTool(functionId, args, config) {
|
|
29
|
+
const sandboxConfig = config.sandboxConfig;
|
|
30
|
+
if (!sandboxConfig) throw new Error("Sandbox configuration is required for function tool execution");
|
|
31
|
+
if (sandboxConfig.provider === "native") return this.executeInNativeSandbox(functionId, args, config);
|
|
32
|
+
if (sandboxConfig.provider === "vercel") return this.executeInVercelSandbox(functionId, args, config);
|
|
33
|
+
throw new Error(`Unknown sandbox provider: ${sandboxConfig.provider}`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Execute in native sandbox
|
|
37
|
+
*/
|
|
38
|
+
async executeInNativeSandbox(functionId, args, config) {
|
|
39
|
+
if (!this.nativeExecutor) {
|
|
40
|
+
this.nativeExecutor = NativeSandboxExecutor.getInstance();
|
|
41
|
+
logger.info({}, "Native sandbox executor created");
|
|
42
|
+
}
|
|
43
|
+
return this.nativeExecutor.executeFunctionTool(functionId, args, config);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute in Vercel sandbox
|
|
47
|
+
*/
|
|
48
|
+
async executeInVercelSandbox(functionId, args, config) {
|
|
49
|
+
const vercelConfig = config.sandboxConfig;
|
|
50
|
+
const configKey = `${vercelConfig.teamId}:${vercelConfig.projectId}`;
|
|
51
|
+
if (!this.vercelExecutors.has(configKey)) {
|
|
52
|
+
const executor$1 = VercelSandboxExecutor.getInstance(vercelConfig);
|
|
53
|
+
this.vercelExecutors.set(configKey, executor$1);
|
|
54
|
+
logger.info({
|
|
55
|
+
teamId: vercelConfig.teamId,
|
|
56
|
+
projectId: vercelConfig.projectId
|
|
57
|
+
}, "Vercel sandbox executor created");
|
|
58
|
+
}
|
|
59
|
+
const executor = this.vercelExecutors.get(configKey);
|
|
60
|
+
if (!executor) throw new Error(`Failed to get Vercel executor for config: ${configKey}`);
|
|
61
|
+
const result = await executor.executeFunctionTool(functionId, args, config);
|
|
62
|
+
if (!result.success) throw new Error(result.error || "Vercel sandbox execution failed");
|
|
63
|
+
return result.result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Clean up all sandbox executors
|
|
67
|
+
*/
|
|
68
|
+
async cleanup() {
|
|
69
|
+
logger.info({}, "Cleaning up sandbox executors");
|
|
70
|
+
this.nativeExecutor = null;
|
|
71
|
+
for (const [key, executor] of this.vercelExecutors.entries()) {
|
|
72
|
+
await executor.cleanup();
|
|
73
|
+
this.vercelExecutors.delete(key);
|
|
74
|
+
}
|
|
75
|
+
logger.info({}, "Sandbox executor cleanup completed");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { SandboxExecutorFactory };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { VercelSandboxConfig } from "../types/execution-context.js";
|
|
2
|
+
import { FunctionToolConfig } from "./NativeSandboxExecutor.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/VercelSandboxExecutor.d.ts
|
|
5
|
+
interface ExecutionResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
result?: unknown;
|
|
8
|
+
error?: string;
|
|
9
|
+
logs?: string[];
|
|
10
|
+
executionTime?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Vercel Sandbox Executor with pooling/reuse
|
|
14
|
+
* Executes function tools in isolated Vercel Sandbox MicroVMs
|
|
15
|
+
* Caches and reuses sandboxes based on dependencies to improve performance
|
|
16
|
+
*/
|
|
17
|
+
declare class VercelSandboxExecutor {
|
|
18
|
+
private static instance;
|
|
19
|
+
private config;
|
|
20
|
+
private sandboxPool;
|
|
21
|
+
private cleanupInterval;
|
|
22
|
+
private constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Get singleton instance of VercelSandboxExecutor
|
|
25
|
+
*/
|
|
26
|
+
static getInstance(config: VercelSandboxConfig): VercelSandboxExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* Generate a hash for dependencies to use as cache key
|
|
29
|
+
*/
|
|
30
|
+
private generateDependencyHash;
|
|
31
|
+
/**
|
|
32
|
+
* Get a cached sandbox if available and still valid
|
|
33
|
+
*/
|
|
34
|
+
private getCachedSandbox;
|
|
35
|
+
/**
|
|
36
|
+
* Add sandbox to pool
|
|
37
|
+
*/
|
|
38
|
+
private addToPool;
|
|
39
|
+
/**
|
|
40
|
+
* Increment use count for a sandbox
|
|
41
|
+
*/
|
|
42
|
+
private incrementUseCount;
|
|
43
|
+
/**
|
|
44
|
+
* Remove and clean up a sandbox
|
|
45
|
+
*/
|
|
46
|
+
private removeSandbox;
|
|
47
|
+
/**
|
|
48
|
+
* Start periodic cleanup of expired sandboxes
|
|
49
|
+
*/
|
|
50
|
+
private startPoolCleanup;
|
|
51
|
+
/**
|
|
52
|
+
* Cleanup all sandboxes and stop cleanup interval
|
|
53
|
+
*/
|
|
54
|
+
cleanup(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Extract environment variable names from code
|
|
57
|
+
* Matches patterns like process.env.VAR_NAME or process.env['VAR_NAME']
|
|
58
|
+
*/
|
|
59
|
+
private extractEnvVars;
|
|
60
|
+
/**
|
|
61
|
+
* Create .env file content from environment variables
|
|
62
|
+
* Note: Currently creates empty placeholders. Values will be populated in the future.
|
|
63
|
+
*/
|
|
64
|
+
private createEnvFileContent;
|
|
65
|
+
/**
|
|
66
|
+
* Execute a function tool in Vercel Sandbox with pooling
|
|
67
|
+
*/
|
|
68
|
+
executeFunctionTool(functionId: string, args: Record<string, unknown>, toolConfig: FunctionToolConfig): Promise<ExecutionResult>;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { ExecutionResult, VercelSandboxExecutor };
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import { FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_POOL_TTL_MS } from "../constants/execution-limits/index.js";
|
|
3
|
+
import { createExecutionWrapper, parseExecutionResult } from "./sandbox-utils.js";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
import { Sandbox } from "@vercel/sandbox";
|
|
6
|
+
|
|
7
|
+
//#region src/tools/VercelSandboxExecutor.ts
|
|
8
|
+
const logger = getLogger("VercelSandboxExecutor");
|
|
9
|
+
/**
|
|
10
|
+
* Vercel Sandbox Executor with pooling/reuse
|
|
11
|
+
* Executes function tools in isolated Vercel Sandbox MicroVMs
|
|
12
|
+
* Caches and reuses sandboxes based on dependencies to improve performance
|
|
13
|
+
*/
|
|
14
|
+
var VercelSandboxExecutor = class VercelSandboxExecutor {
|
|
15
|
+
static instance;
|
|
16
|
+
config;
|
|
17
|
+
sandboxPool = /* @__PURE__ */ new Map();
|
|
18
|
+
cleanupInterval = null;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
logger.info({
|
|
22
|
+
teamId: config.teamId,
|
|
23
|
+
projectId: config.projectId,
|
|
24
|
+
runtime: config.runtime,
|
|
25
|
+
timeout: config.timeout,
|
|
26
|
+
vcpus: config.vcpus
|
|
27
|
+
}, "VercelSandboxExecutor initialized with pooling");
|
|
28
|
+
this.startPoolCleanup();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get singleton instance of VercelSandboxExecutor
|
|
32
|
+
*/
|
|
33
|
+
static getInstance(config) {
|
|
34
|
+
if (!VercelSandboxExecutor.instance) VercelSandboxExecutor.instance = new VercelSandboxExecutor(config);
|
|
35
|
+
return VercelSandboxExecutor.instance;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generate a hash for dependencies to use as cache key
|
|
39
|
+
*/
|
|
40
|
+
generateDependencyHash(dependencies) {
|
|
41
|
+
const sorted = Object.keys(dependencies).sort().map((key) => `${key}@${dependencies[key]}`).join(",");
|
|
42
|
+
return crypto.createHash("md5").update(sorted).digest("hex").substring(0, 8);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get a cached sandbox if available and still valid
|
|
46
|
+
*/
|
|
47
|
+
getCachedSandbox(dependencyHash) {
|
|
48
|
+
const cached = this.sandboxPool.get(dependencyHash);
|
|
49
|
+
if (!cached) return null;
|
|
50
|
+
const age = Date.now() - cached.createdAt;
|
|
51
|
+
if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
52
|
+
logger.debug({
|
|
53
|
+
dependencyHash,
|
|
54
|
+
age,
|
|
55
|
+
useCount: cached.useCount,
|
|
56
|
+
ttl: FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
|
|
57
|
+
maxUseCount: FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT
|
|
58
|
+
}, "Sandbox expired, will create new one");
|
|
59
|
+
this.removeSandbox(dependencyHash);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
logger.debug({
|
|
63
|
+
dependencyHash,
|
|
64
|
+
useCount: cached.useCount,
|
|
65
|
+
age
|
|
66
|
+
}, "Reusing cached sandbox");
|
|
67
|
+
return cached.sandbox;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Add sandbox to pool
|
|
71
|
+
*/
|
|
72
|
+
addToPool(dependencyHash, sandbox, dependencies) {
|
|
73
|
+
this.sandboxPool.set(dependencyHash, {
|
|
74
|
+
sandbox,
|
|
75
|
+
createdAt: Date.now(),
|
|
76
|
+
useCount: 0,
|
|
77
|
+
dependencies
|
|
78
|
+
});
|
|
79
|
+
logger.debug({
|
|
80
|
+
dependencyHash,
|
|
81
|
+
poolSize: this.sandboxPool.size
|
|
82
|
+
}, "Sandbox added to pool");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Increment use count for a sandbox
|
|
86
|
+
*/
|
|
87
|
+
incrementUseCount(dependencyHash) {
|
|
88
|
+
const cached = this.sandboxPool.get(dependencyHash);
|
|
89
|
+
if (cached) cached.useCount++;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Remove and clean up a sandbox
|
|
93
|
+
*/
|
|
94
|
+
async removeSandbox(dependencyHash) {
|
|
95
|
+
const cached = this.sandboxPool.get(dependencyHash);
|
|
96
|
+
if (cached) {
|
|
97
|
+
try {
|
|
98
|
+
await cached.sandbox.stop();
|
|
99
|
+
logger.debug({ dependencyHash }, "Sandbox stopped");
|
|
100
|
+
} catch (error) {
|
|
101
|
+
logger.warn({
|
|
102
|
+
error,
|
|
103
|
+
dependencyHash
|
|
104
|
+
}, "Error stopping sandbox");
|
|
105
|
+
}
|
|
106
|
+
this.sandboxPool.delete(dependencyHash);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Start periodic cleanup of expired sandboxes
|
|
111
|
+
*/
|
|
112
|
+
startPoolCleanup() {
|
|
113
|
+
this.cleanupInterval = setInterval(() => {
|
|
114
|
+
const now = Date.now();
|
|
115
|
+
const toRemove = [];
|
|
116
|
+
for (const [hash, cached] of this.sandboxPool.entries()) if (now - cached.createdAt > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) toRemove.push(hash);
|
|
117
|
+
if (toRemove.length > 0) {
|
|
118
|
+
logger.info({
|
|
119
|
+
count: toRemove.length,
|
|
120
|
+
poolSize: this.sandboxPool.size
|
|
121
|
+
}, "Cleaning up expired sandboxes");
|
|
122
|
+
for (const hash of toRemove) this.removeSandbox(hash);
|
|
123
|
+
}
|
|
124
|
+
}, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Cleanup all sandboxes and stop cleanup interval
|
|
128
|
+
*/
|
|
129
|
+
async cleanup() {
|
|
130
|
+
if (this.cleanupInterval) {
|
|
131
|
+
clearInterval(this.cleanupInterval);
|
|
132
|
+
this.cleanupInterval = null;
|
|
133
|
+
}
|
|
134
|
+
logger.info({ poolSize: this.sandboxPool.size }, "Cleaning up all sandboxes");
|
|
135
|
+
const promises = Array.from(this.sandboxPool.keys()).map((hash) => this.removeSandbox(hash));
|
|
136
|
+
await Promise.all(promises);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Extract environment variable names from code
|
|
140
|
+
* Matches patterns like process.env.VAR_NAME or process.env['VAR_NAME']
|
|
141
|
+
*/
|
|
142
|
+
extractEnvVars(code) {
|
|
143
|
+
const envVars = /* @__PURE__ */ new Set();
|
|
144
|
+
const dotNotationRegex = /process\.env\.([A-Z_][A-Z0-9_]*)/g;
|
|
145
|
+
let match = dotNotationRegex.exec(code);
|
|
146
|
+
while (match !== null) {
|
|
147
|
+
envVars.add(match[1]);
|
|
148
|
+
match = dotNotationRegex.exec(code);
|
|
149
|
+
}
|
|
150
|
+
const bracketNotationRegex = /process\.env\[['"]([A-Z_][A-Z0-9_]*)['"]\]/g;
|
|
151
|
+
match = bracketNotationRegex.exec(code);
|
|
152
|
+
while (match !== null) {
|
|
153
|
+
envVars.add(match[1]);
|
|
154
|
+
match = bracketNotationRegex.exec(code);
|
|
155
|
+
}
|
|
156
|
+
return envVars;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Create .env file content from environment variables
|
|
160
|
+
* Note: Currently creates empty placeholders. Values will be populated in the future.
|
|
161
|
+
*/
|
|
162
|
+
createEnvFileContent(envVarNames) {
|
|
163
|
+
const envLines = [];
|
|
164
|
+
for (const varName of envVarNames) {
|
|
165
|
+
envLines.push(`${varName}=""`);
|
|
166
|
+
logger.debug({ varName }, "Adding environment variable placeholder to sandbox");
|
|
167
|
+
}
|
|
168
|
+
return envLines.join("\n");
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Execute a function tool in Vercel Sandbox with pooling
|
|
172
|
+
*/
|
|
173
|
+
async executeFunctionTool(functionId, args, toolConfig) {
|
|
174
|
+
const startTime = Date.now();
|
|
175
|
+
const logs = [];
|
|
176
|
+
const dependencies = toolConfig.dependencies || {};
|
|
177
|
+
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
178
|
+
try {
|
|
179
|
+
logger.info({
|
|
180
|
+
functionId,
|
|
181
|
+
functionName: toolConfig.name,
|
|
182
|
+
dependencyHash,
|
|
183
|
+
poolSize: this.sandboxPool.size
|
|
184
|
+
}, "Executing function in Vercel Sandbox");
|
|
185
|
+
let sandbox = this.getCachedSandbox(dependencyHash);
|
|
186
|
+
let isNewSandbox = false;
|
|
187
|
+
if (!sandbox) {
|
|
188
|
+
isNewSandbox = true;
|
|
189
|
+
sandbox = await Sandbox.create({
|
|
190
|
+
token: this.config.token,
|
|
191
|
+
teamId: this.config.teamId,
|
|
192
|
+
projectId: this.config.projectId,
|
|
193
|
+
timeout: this.config.timeout,
|
|
194
|
+
resources: { vcpus: this.config.vcpus || 1 },
|
|
195
|
+
runtime: this.config.runtime
|
|
196
|
+
});
|
|
197
|
+
logger.info({
|
|
198
|
+
functionId,
|
|
199
|
+
sandboxId: sandbox.sandboxId,
|
|
200
|
+
dependencyHash
|
|
201
|
+
}, `New sandbox created for function ${functionId}`);
|
|
202
|
+
this.addToPool(dependencyHash, sandbox, dependencies);
|
|
203
|
+
} else logger.info({
|
|
204
|
+
functionId,
|
|
205
|
+
sandboxId: sandbox.sandboxId,
|
|
206
|
+
dependencyHash
|
|
207
|
+
}, `Reusing cached sandbox for function ${functionId}`);
|
|
208
|
+
this.incrementUseCount(dependencyHash);
|
|
209
|
+
try {
|
|
210
|
+
if (isNewSandbox && toolConfig.dependencies && Object.keys(toolConfig.dependencies).length > 0) {
|
|
211
|
+
logger.debug({
|
|
212
|
+
functionId,
|
|
213
|
+
functionName: toolConfig.name,
|
|
214
|
+
dependencies: toolConfig.dependencies
|
|
215
|
+
}, "Installing dependencies in new sandbox");
|
|
216
|
+
const packageJson = { dependencies: toolConfig.dependencies };
|
|
217
|
+
const packageJsonContent = JSON.stringify(packageJson, null, 2);
|
|
218
|
+
await sandbox.writeFiles([{
|
|
219
|
+
path: "package.json",
|
|
220
|
+
content: Buffer.from(packageJsonContent, "utf-8")
|
|
221
|
+
}]);
|
|
222
|
+
const installCmd = await sandbox.runCommand({
|
|
223
|
+
cmd: "npm",
|
|
224
|
+
args: ["install", "--omit=dev"]
|
|
225
|
+
});
|
|
226
|
+
const installStdout = await installCmd.stdout();
|
|
227
|
+
const installStderr = await installCmd.stderr();
|
|
228
|
+
if (installStdout) logs.push(installStdout);
|
|
229
|
+
if (installStderr) logs.push(installStderr);
|
|
230
|
+
if (installCmd.exitCode !== 0) throw new Error(`Failed to install dependencies: ${installStderr}`);
|
|
231
|
+
logger.info({
|
|
232
|
+
functionId,
|
|
233
|
+
dependencyHash
|
|
234
|
+
}, "Dependencies installed successfully");
|
|
235
|
+
}
|
|
236
|
+
const executionCode = createExecutionWrapper(toolConfig.executeCode, args);
|
|
237
|
+
const envVars = this.extractEnvVars(toolConfig.executeCode);
|
|
238
|
+
const filesToWrite = [];
|
|
239
|
+
const filename = this.config.runtime === "typescript" ? "execute.ts" : "execute.js";
|
|
240
|
+
filesToWrite.push({
|
|
241
|
+
path: filename,
|
|
242
|
+
content: Buffer.from(executionCode, "utf-8")
|
|
243
|
+
});
|
|
244
|
+
if (envVars.size > 0) {
|
|
245
|
+
const envFileContent = this.createEnvFileContent(envVars);
|
|
246
|
+
if (envFileContent) {
|
|
247
|
+
filesToWrite.push({
|
|
248
|
+
path: ".env",
|
|
249
|
+
content: Buffer.from(envFileContent, "utf-8")
|
|
250
|
+
});
|
|
251
|
+
logger.info({
|
|
252
|
+
functionId,
|
|
253
|
+
envVarCount: envVars.size,
|
|
254
|
+
envVars: Array.from(envVars)
|
|
255
|
+
}, "Creating environment variable placeholders in sandbox");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
await sandbox.writeFiles(filesToWrite);
|
|
259
|
+
logger.info({
|
|
260
|
+
functionId,
|
|
261
|
+
runtime: this.config.runtime === "typescript" ? "tsx" : "node",
|
|
262
|
+
hasEnvVars: envVars.size > 0
|
|
263
|
+
}, `Execution code written to file for runtime ${this.config.runtime}`);
|
|
264
|
+
const executeCmd = await (async () => {
|
|
265
|
+
if (envVars.size > 0) return sandbox.runCommand({
|
|
266
|
+
cmd: "npx",
|
|
267
|
+
args: this.config.runtime === "typescript" ? [
|
|
268
|
+
"--yes",
|
|
269
|
+
"dotenv-cli",
|
|
270
|
+
"--",
|
|
271
|
+
"npx",
|
|
272
|
+
"tsx",
|
|
273
|
+
filename
|
|
274
|
+
] : [
|
|
275
|
+
"--yes",
|
|
276
|
+
"dotenv-cli",
|
|
277
|
+
"--",
|
|
278
|
+
"node",
|
|
279
|
+
filename
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
const runtime = this.config.runtime === "typescript" ? "tsx" : "node";
|
|
283
|
+
return sandbox.runCommand({
|
|
284
|
+
cmd: runtime,
|
|
285
|
+
args: [filename]
|
|
286
|
+
});
|
|
287
|
+
})();
|
|
288
|
+
const executeStdout = await executeCmd.stdout();
|
|
289
|
+
const executeStderr = await executeCmd.stderr();
|
|
290
|
+
if (executeStdout) logs.push(executeStdout);
|
|
291
|
+
if (executeStderr) logs.push(executeStderr);
|
|
292
|
+
const executionTime = Date.now() - startTime;
|
|
293
|
+
if (executeCmd.exitCode !== 0) {
|
|
294
|
+
logger.error({
|
|
295
|
+
functionId,
|
|
296
|
+
exitCode: executeCmd.exitCode,
|
|
297
|
+
stderr: executeStderr
|
|
298
|
+
}, "Function execution failed");
|
|
299
|
+
return {
|
|
300
|
+
success: false,
|
|
301
|
+
error: executeStderr || "Function execution failed with non-zero exit code",
|
|
302
|
+
logs,
|
|
303
|
+
executionTime
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
const result = parseExecutionResult(executeStdout, functionId, logger);
|
|
307
|
+
logger.info({
|
|
308
|
+
functionId,
|
|
309
|
+
executionTime
|
|
310
|
+
}, "Function executed successfully in Vercel Sandbox");
|
|
311
|
+
return {
|
|
312
|
+
success: true,
|
|
313
|
+
result,
|
|
314
|
+
logs,
|
|
315
|
+
executionTime
|
|
316
|
+
};
|
|
317
|
+
} catch (innerError) {
|
|
318
|
+
await this.removeSandbox(dependencyHash);
|
|
319
|
+
throw innerError;
|
|
320
|
+
}
|
|
321
|
+
} catch (error) {
|
|
322
|
+
const executionTime = Date.now() - startTime;
|
|
323
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
324
|
+
logger.error({
|
|
325
|
+
functionId,
|
|
326
|
+
error: errorMessage,
|
|
327
|
+
executionTime
|
|
328
|
+
}, "Vercel Sandbox execution error");
|
|
329
|
+
return {
|
|
330
|
+
success: false,
|
|
331
|
+
error: errorMessage,
|
|
332
|
+
logs,
|
|
333
|
+
executionTime
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
//#endregion
|
|
340
|
+
export { VercelSandboxExecutor };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ModelSettings } from "@inkeep/agents-core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/distill-conversation-tool.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Conversation Summary Schema - structured object for maintaining conversation context
|
|
8
|
+
*/
|
|
9
|
+
declare const ConversationSummarySchema: z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"conversation_summary_v1">;
|
|
11
|
+
session_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
high_level: z.ZodString;
|
|
13
|
+
user_intent: z.ZodString;
|
|
14
|
+
decisions: z.ZodArray<z.ZodString>;
|
|
15
|
+
open_questions: z.ZodArray<z.ZodString>;
|
|
16
|
+
next_steps: z.ZodObject<{
|
|
17
|
+
for_agent: z.ZodArray<z.ZodString>;
|
|
18
|
+
for_user: z.ZodArray<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
related_artifacts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
tool_name: z.ZodString;
|
|
24
|
+
tool_call_id: z.ZodString;
|
|
25
|
+
content_type: z.ZodString;
|
|
26
|
+
key_findings: z.ZodArray<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
type ConversationSummary = z.infer<typeof ConversationSummarySchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Core conversation distillation - takes messages and creates structured summary
|
|
32
|
+
*/
|
|
33
|
+
declare function distillConversation(params: {
|
|
34
|
+
messages: any[];
|
|
35
|
+
conversationId: string;
|
|
36
|
+
currentSummary?: ConversationSummary | null;
|
|
37
|
+
summarizerModel?: ModelSettings;
|
|
38
|
+
toolCallToArtifactMap?: Record<string, string>;
|
|
39
|
+
}): Promise<ConversationSummary>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { ConversationSummary, ConversationSummarySchema, distillConversation };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import { ModelFactory } from "@inkeep/agents-core";
|
|
3
|
+
import { generateObject } from "ai";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/tools/distill-conversation-tool.ts
|
|
7
|
+
const logger = getLogger("distill-conversation-tool");
|
|
8
|
+
/**
|
|
9
|
+
* Conversation Summary Schema - structured object for maintaining conversation context
|
|
10
|
+
*/
|
|
11
|
+
const ConversationSummarySchema = z.object({
|
|
12
|
+
type: z.literal("conversation_summary_v1"),
|
|
13
|
+
session_id: z.string().nullable().optional(),
|
|
14
|
+
high_level: z.string().describe("1-3 sentences capturing what was discovered and learned"),
|
|
15
|
+
user_intent: z.string().describe("Current main goal or what the user wants to accomplish"),
|
|
16
|
+
decisions: z.array(z.string()).describe("Concrete decisions made about approach or implementation (≤5 items)"),
|
|
17
|
+
open_questions: z.array(z.string()).describe("Unresolved questions about the subject matter (≤5 items)"),
|
|
18
|
+
next_steps: z.object({
|
|
19
|
+
for_agent: z.array(z.string()).describe("Content-focused actions: what to discover, analyze, or present. Don't get trapped in an infinite loop of tool calls. You have already done a lot of work that is why you are being compressed. Don't encourage too much more work."),
|
|
20
|
+
for_user: z.array(z.string()).describe("Actions for user based on discovered content")
|
|
21
|
+
}),
|
|
22
|
+
related_artifacts: z.array(z.object({
|
|
23
|
+
id: z.string().describe("Artifact ID"),
|
|
24
|
+
name: z.string().describe("Human-readable name describing the content"),
|
|
25
|
+
tool_name: z.string().describe("Tool that generated this artifact (e.g. search-inkeep-docs)"),
|
|
26
|
+
tool_call_id: z.string().describe("Specific tool call ID for precise referencing"),
|
|
27
|
+
content_type: z.string().describe("Type of content (e.g. search_results, api_response, documentation)"),
|
|
28
|
+
key_findings: z.array(z.string()).describe("2-3 most important findings from this specific artifact")
|
|
29
|
+
})).optional().describe("Artifacts containing detailed findings with citation info")
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Core conversation distillation - takes messages and creates structured summary
|
|
33
|
+
*/
|
|
34
|
+
async function distillConversation(params) {
|
|
35
|
+
const { messages, conversationId, currentSummary, summarizerModel, toolCallToArtifactMap } = params;
|
|
36
|
+
try {
|
|
37
|
+
const modelToUse = summarizerModel;
|
|
38
|
+
if (!modelToUse?.model?.trim()) throw new Error("Summarizer model is required");
|
|
39
|
+
const model = ModelFactory.createModel(modelToUse);
|
|
40
|
+
const existingSummaryContext = currentSummary ? `**Current summary:**\n\n\`\`\`json\n${JSON.stringify(currentSummary, null, 2)}\n\`\`\`` : "**Current summary:** None (first distillation)";
|
|
41
|
+
const formattedMessages = messages.map((msg) => {
|
|
42
|
+
const parts = [];
|
|
43
|
+
if (typeof msg.content === "string") parts.push(msg.content);
|
|
44
|
+
else if (Array.isArray(msg.content)) {
|
|
45
|
+
for (const block of msg.content) if (block.type === "text") parts.push(block.text);
|
|
46
|
+
else if (block.type === "tool-call") parts.push(`[TOOL CALL] ${block.toolName}(${JSON.stringify(block.input)}) [ID: ${block.toolCallId}]`);
|
|
47
|
+
else if (block.type === "tool-result") {
|
|
48
|
+
const artifactId = toolCallToArtifactMap?.[block.toolCallId];
|
|
49
|
+
const artifactInfo = artifactId ? `\n[ARTIFACT CREATED: ${artifactId}]` : "";
|
|
50
|
+
parts.push(`[TOOL RESULT] ${block.toolName} [ID: ${block.toolCallId}]${artifactInfo}\nResult: ${JSON.stringify(block.result)}`);
|
|
51
|
+
}
|
|
52
|
+
} else if (msg.content?.text) parts.push(msg.content.text);
|
|
53
|
+
return parts.length > 0 ? `${msg.role || "system"}: ${parts.join("\n")}` : "";
|
|
54
|
+
}).filter((line) => line.trim().length > 0).join("\n\n");
|
|
55
|
+
logger.debug({
|
|
56
|
+
conversationId,
|
|
57
|
+
messageCount: messages.length,
|
|
58
|
+
formattedLength: formattedMessages.length,
|
|
59
|
+
sampleMessages: messages.slice(0, 2).map((m) => ({
|
|
60
|
+
role: m.role,
|
|
61
|
+
contentType: typeof m.content,
|
|
62
|
+
hasContent: !!m.content
|
|
63
|
+
}))
|
|
64
|
+
}, "Formatting messages for distillation");
|
|
65
|
+
const { object: summary } = await generateObject({
|
|
66
|
+
model,
|
|
67
|
+
prompt: `You are a conversation summarization assistant. Your job is to create or update a compact, structured summary that captures VALUABLE CONTENT and FINDINGS, not just operational details.
|
|
68
|
+
|
|
69
|
+
${existingSummaryContext}
|
|
70
|
+
|
|
71
|
+
**Messages to summarize:**
|
|
72
|
+
|
|
73
|
+
\`\`\`text
|
|
74
|
+
${formattedMessages}
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
Create/update a summary using this exact JSON schema:
|
|
78
|
+
|
|
79
|
+
\`\`\`json
|
|
80
|
+
{
|
|
81
|
+
"type": "conversation_summary_v1",
|
|
82
|
+
"session_id": "<conversationId>",
|
|
83
|
+
"high_level": "<1–3 sentences capturing what was discovered and learned>",
|
|
84
|
+
"user_intent": "<current main goal>",
|
|
85
|
+
"decisions": ["<concrete decisions made>"],
|
|
86
|
+
"open_questions": ["<unresolved issues>"],
|
|
87
|
+
"next_steps": {
|
|
88
|
+
"for_agent": ["<what agent should do>"],
|
|
89
|
+
"for_user": ["<what user should do>"]
|
|
90
|
+
},
|
|
91
|
+
"related_artifacts": [
|
|
92
|
+
{
|
|
93
|
+
"id": "<artifact_id>",
|
|
94
|
+
"name": "<descriptive name>",
|
|
95
|
+
"tool_name": "<tool_name>",
|
|
96
|
+
"tool_call_id": "<tool_call_id>",
|
|
97
|
+
"content_type": "<search_results|api_response|documentation>",
|
|
98
|
+
"key_findings": ["<important finding 1>", "<important finding 2>"]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
\`\`\`
|
|
103
|
+
|
|
104
|
+
**CRITICAL RULES - FOCUS ON CONTENT NOT OPERATIONS:**
|
|
105
|
+
🎯 **EXTRACT VALUABLE FINDINGS**: Capture the actual information discovered, data retrieved, insights gained
|
|
106
|
+
🎯 **IGNORE OPERATIONAL DETAILS**: Don't mention "tool was used", "artifact was created", "messages were compressed"
|
|
107
|
+
🎯 **PRESERVE SUBSTANCE**: Include specific facts, features, capabilities, configurations, results found
|
|
108
|
+
🎯 **BUILD KNOWLEDGE**: When updating existing summary, ADD new discoveries to existing knowledge
|
|
109
|
+
🎯 **BE CONCRETE**: Use specific details from tool results, not generic descriptions
|
|
110
|
+
🎯 **BE CONCISE**: Keep ALL fields brief - you are compressing to save context, not writing a report
|
|
111
|
+
🎯 **LIMIT NEXT STEPS**: Agent has already done substantial work - suggest minimal follow-up actions only
|
|
112
|
+
|
|
113
|
+
**Examples:**
|
|
114
|
+
❌ BAD: "Assistant used search tool and created artifacts"
|
|
115
|
+
✅ GOOD: "Inkeep supports streaming structured objects, OpenAI-compatible APIs, analytics logging, and Zendesk integration"
|
|
116
|
+
|
|
117
|
+
❌ BAD: "Tool calls were made to gather information"
|
|
118
|
+
✅ GOOD: "Platform includes 10 feature categories: chat widgets, knowledge base, analytics, integrations, theming options"
|
|
119
|
+
|
|
120
|
+
**Focus on WHAT WAS LEARNED, not HOW IT WAS LEARNED**
|
|
121
|
+
|
|
122
|
+
Return **only** valid JSON.`,
|
|
123
|
+
schema: ConversationSummarySchema
|
|
124
|
+
});
|
|
125
|
+
summary.session_id = conversationId;
|
|
126
|
+
logger.info({
|
|
127
|
+
conversationId,
|
|
128
|
+
messageCount: messages.length,
|
|
129
|
+
artifactsCount: summary.related_artifacts?.length || 0,
|
|
130
|
+
decisionsCount: summary.decisions.length
|
|
131
|
+
}, "Successfully distilled conversation");
|
|
132
|
+
return summary;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
logger.error({
|
|
135
|
+
conversationId,
|
|
136
|
+
messageCount: messages.length,
|
|
137
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
138
|
+
}, "Failed to distill conversation");
|
|
139
|
+
return {
|
|
140
|
+
type: "conversation_summary_v1",
|
|
141
|
+
session_id: conversationId,
|
|
142
|
+
high_level: "Ongoing conversation session",
|
|
143
|
+
user_intent: "Continue working on current task",
|
|
144
|
+
related_artifacts: [],
|
|
145
|
+
decisions: [],
|
|
146
|
+
open_questions: ["Review recent work and determine next steps"],
|
|
147
|
+
next_steps: {
|
|
148
|
+
for_agent: ["Continue with current task"],
|
|
149
|
+
for_user: ["Provide additional guidance if needed"]
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
export { ConversationSummarySchema, distillConversation };
|