@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,18 @@
|
|
|
1
|
+
//#region src/tools/sandbox-utils.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared utilities for sandbox executors
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create an execution wrapper that handles input/output for function tools
|
|
7
|
+
* This is used by both Native and Vercel sandbox executors
|
|
8
|
+
*/
|
|
9
|
+
declare function createExecutionWrapper(executeCode: string, args: Record<string, unknown>): string;
|
|
10
|
+
/**
|
|
11
|
+
* Parse execution result from stdout
|
|
12
|
+
* Returns the parsed result or the raw stdout if parsing fails
|
|
13
|
+
*/
|
|
14
|
+
declare function parseExecutionResult(stdout: string, functionId: string, logger?: {
|
|
15
|
+
warn: (obj: unknown, msg: string) => void;
|
|
16
|
+
}): unknown;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createExecutionWrapper, parseExecutionResult };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/tools/sandbox-utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared utilities for sandbox executors
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create an execution wrapper that handles input/output for function tools
|
|
7
|
+
* This is used by both Native and Vercel sandbox executors
|
|
8
|
+
*/
|
|
9
|
+
function createExecutionWrapper(executeCode, args) {
|
|
10
|
+
return `
|
|
11
|
+
// Function tool execution wrapper
|
|
12
|
+
const args = ${JSON.stringify(args, null, 2)};
|
|
13
|
+
|
|
14
|
+
// User's function code
|
|
15
|
+
const execute = ${executeCode}
|
|
16
|
+
|
|
17
|
+
// Execute the function and output the result
|
|
18
|
+
(async () => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await execute(args);
|
|
21
|
+
// Output result as JSON on the last line
|
|
22
|
+
console.log(JSON.stringify({ success: true, result }));
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error(JSON.stringify({
|
|
25
|
+
success: false,
|
|
26
|
+
error: error instanceof Error ? error.message : String(error)
|
|
27
|
+
}));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse execution result from stdout
|
|
35
|
+
* Returns the parsed result or the raw stdout if parsing fails
|
|
36
|
+
*/
|
|
37
|
+
function parseExecutionResult(stdout, functionId, logger) {
|
|
38
|
+
try {
|
|
39
|
+
const outputLines = stdout.split("\n").filter((line) => line.trim());
|
|
40
|
+
const resultLine = outputLines[outputLines.length - 1];
|
|
41
|
+
return JSON.parse(resultLine);
|
|
42
|
+
} catch (parseError) {
|
|
43
|
+
if (logger) logger.warn({
|
|
44
|
+
functionId,
|
|
45
|
+
stdout,
|
|
46
|
+
parseError
|
|
47
|
+
}, "Failed to parse execution result");
|
|
48
|
+
return stdout;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { createExecutionWrapper, parseExecutionResult };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/types/chat.d.ts
|
|
2
|
+
type ContentItem = {
|
|
3
|
+
type: string;
|
|
4
|
+
text?: string;
|
|
5
|
+
};
|
|
6
|
+
type Message = {
|
|
7
|
+
role: 'system' | 'user' | 'assistant' | 'function' | 'tool';
|
|
8
|
+
content: string | ContentItem[];
|
|
9
|
+
name?: string;
|
|
10
|
+
};
|
|
11
|
+
type ChatCompletionRequest = {
|
|
12
|
+
model: string;
|
|
13
|
+
messages: Message[];
|
|
14
|
+
temperature?: number;
|
|
15
|
+
top_p?: number;
|
|
16
|
+
n?: number;
|
|
17
|
+
stream?: boolean;
|
|
18
|
+
max_tokens?: number;
|
|
19
|
+
presence_penalty?: number;
|
|
20
|
+
frequency_penalty?: number;
|
|
21
|
+
logit_bias?: Record<string, number>;
|
|
22
|
+
user?: string;
|
|
23
|
+
tools?: Record<string, unknown>;
|
|
24
|
+
runConfig?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ChatCompletionRequest, ContentItem, Message };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ExecutionContext } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/types/execution-context.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Extract userId from execution context metadata (when available)
|
|
7
|
+
* Only available when request originates from an authenticated user session (e.g., playground)
|
|
8
|
+
*/
|
|
9
|
+
declare function getUserIdFromContext(ctx: ExecutionContext): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Create execution context from middleware values
|
|
12
|
+
*/
|
|
13
|
+
declare function createExecutionContext(params: {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
tenantId: string;
|
|
16
|
+
projectId: string;
|
|
17
|
+
agentId: string;
|
|
18
|
+
apiKeyId: string;
|
|
19
|
+
subAgentId?: string;
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
metadata?: {
|
|
22
|
+
teamDelegation?: boolean;
|
|
23
|
+
originAgentId?: string;
|
|
24
|
+
initiatedBy?: {
|
|
25
|
+
type: 'user' | 'api_key';
|
|
26
|
+
id: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}): ExecutionContext;
|
|
30
|
+
interface CommonSandboxConfig {
|
|
31
|
+
runtime: 'node22' | 'typescript';
|
|
32
|
+
timeout?: number;
|
|
33
|
+
vcpus?: number;
|
|
34
|
+
}
|
|
35
|
+
interface NativeSandboxConfig extends CommonSandboxConfig {
|
|
36
|
+
provider: 'native';
|
|
37
|
+
}
|
|
38
|
+
interface VercelSandboxConfig extends CommonSandboxConfig {
|
|
39
|
+
provider: 'vercel';
|
|
40
|
+
teamId: string;
|
|
41
|
+
projectId: string;
|
|
42
|
+
token: string;
|
|
43
|
+
}
|
|
44
|
+
type SandboxConfig = NativeSandboxConfig | VercelSandboxConfig;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { NativeSandboxConfig, SandboxConfig, VercelSandboxConfig, createExecutionContext, getUserIdFromContext };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/types/execution-context.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extract userId from execution context metadata (when available)
|
|
4
|
+
* Only available when request originates from an authenticated user session (e.g., playground)
|
|
5
|
+
*/
|
|
6
|
+
function getUserIdFromContext(ctx) {
|
|
7
|
+
const metadata = ctx.metadata;
|
|
8
|
+
return metadata?.initiatedBy?.type === "user" ? metadata.initiatedBy.id : void 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create execution context from middleware values
|
|
12
|
+
*/
|
|
13
|
+
function createExecutionContext(params) {
|
|
14
|
+
return {
|
|
15
|
+
apiKey: params.apiKey,
|
|
16
|
+
tenantId: params.tenantId,
|
|
17
|
+
projectId: params.projectId,
|
|
18
|
+
agentId: params.agentId,
|
|
19
|
+
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
20
|
+
apiKeyId: params.apiKeyId,
|
|
21
|
+
subAgentId: params.subAgentId,
|
|
22
|
+
metadata: params.metadata || {}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createExecutionContext, getUserIdFromContext };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/utils/SchemaProcessor.d.ts
|
|
2
|
+
interface SchemaValidationResult {
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
errors: string[];
|
|
5
|
+
transformedSchema?: any;
|
|
6
|
+
}
|
|
7
|
+
interface JMESPathValidationResult {
|
|
8
|
+
isLiteral: boolean;
|
|
9
|
+
isValidSelector: boolean;
|
|
10
|
+
suggestions?: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Centralized schema processing and validation utilities
|
|
14
|
+
*/
|
|
15
|
+
declare class SchemaProcessor {
|
|
16
|
+
private static logger;
|
|
17
|
+
/**
|
|
18
|
+
* Transform complex schema types to strings for JMESPath compatibility
|
|
19
|
+
*/
|
|
20
|
+
static transformSchemaForJMESPath(schema: any): any;
|
|
21
|
+
/**
|
|
22
|
+
* Validate if a selector looks like a valid JMESPath expression
|
|
23
|
+
*/
|
|
24
|
+
static validateJMESPathSelector(selector: string): JMESPathValidationResult;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a selector looks like a JMESPath expression
|
|
27
|
+
*/
|
|
28
|
+
private static looksLikeJMESPath;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a selector appears to be a literal value rather than a JMESPath expression
|
|
31
|
+
*/
|
|
32
|
+
private static isLiteralValue;
|
|
33
|
+
/**
|
|
34
|
+
* Safely extract data using JMESPath with validation
|
|
35
|
+
*/
|
|
36
|
+
static safeJMESPathSearch(data: any, selector: string, fallback?: any): any;
|
|
37
|
+
/**
|
|
38
|
+
* Validate schema structure for artifact components
|
|
39
|
+
*/
|
|
40
|
+
static validateArtifactSchema(schema: any): SchemaValidationResult;
|
|
41
|
+
/**
|
|
42
|
+
* Extract property value with proper type conversion and validation
|
|
43
|
+
*/
|
|
44
|
+
static extractPropertyValue(data: any, _propName: string, selector: string, expectedType?: string): any;
|
|
45
|
+
/**
|
|
46
|
+
* Enhance schema with JMESPath guidance for artifact component schemas
|
|
47
|
+
* Transforms all schema types to string selectors with helpful descriptions
|
|
48
|
+
*/
|
|
49
|
+
static enhanceSchemaWithJMESPathGuidance(schema: Record<string, unknown> | null | undefined): Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { JMESPathValidationResult, SchemaProcessor, SchemaValidationResult };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import jmespath from "jmespath";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/SchemaProcessor.ts
|
|
5
|
+
/**
|
|
6
|
+
* Centralized schema processing and validation utilities
|
|
7
|
+
*/
|
|
8
|
+
var SchemaProcessor = class SchemaProcessor {
|
|
9
|
+
static logger = getLogger("SchemaProcessor");
|
|
10
|
+
/**
|
|
11
|
+
* Transform complex schema types to strings for JMESPath compatibility
|
|
12
|
+
*/
|
|
13
|
+
static transformSchemaForJMESPath(schema) {
|
|
14
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
15
|
+
const transform = (obj) => {
|
|
16
|
+
if (Array.isArray(obj)) return obj.map(transform);
|
|
17
|
+
if (obj && typeof obj === "object") {
|
|
18
|
+
const result = {};
|
|
19
|
+
for (const [key, value] of Object.entries(obj)) if (key === "type" && typeof value === "string") result[key] = value === "string" ? "string" : "string";
|
|
20
|
+
else result[key] = transform(value);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
};
|
|
25
|
+
return transform(schema);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validate if a selector looks like a valid JMESPath expression
|
|
29
|
+
*/
|
|
30
|
+
static validateJMESPathSelector(selector) {
|
|
31
|
+
if (SchemaProcessor.isLiteralValue(selector)) return {
|
|
32
|
+
isLiteral: true,
|
|
33
|
+
isValidSelector: false
|
|
34
|
+
};
|
|
35
|
+
if (SchemaProcessor.looksLikeJMESPath(selector)) return {
|
|
36
|
+
isLiteral: false,
|
|
37
|
+
isValidSelector: true
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
isLiteral: false,
|
|
41
|
+
isValidSelector: false
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a selector looks like a JMESPath expression
|
|
46
|
+
*/
|
|
47
|
+
static looksLikeJMESPath(selector) {
|
|
48
|
+
if (/^[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*$/.test(selector)) return true;
|
|
49
|
+
if (/^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*)+$/.test(selector)) return true;
|
|
50
|
+
if (/\[\d+\]/.test(selector) || /\[\*\]/.test(selector)) return true;
|
|
51
|
+
if (/\[.*?\]/.test(selector) && /[=<>!]/.test(selector)) return true;
|
|
52
|
+
if (selector.includes("|")) return true;
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a selector appears to be a literal value rather than a JMESPath expression
|
|
57
|
+
*/
|
|
58
|
+
static isLiteralValue(selector) {
|
|
59
|
+
if (SchemaProcessor.looksLikeJMESPath(selector)) return false;
|
|
60
|
+
if (/^https?:\/\//.test(selector)) return true;
|
|
61
|
+
if (/^[0-9]+$/.test(selector)) return true;
|
|
62
|
+
if (selector.includes(" ") && !selector.includes("[")) return true;
|
|
63
|
+
if (/^[a-zA-Z0-9\s\-_,;:!?.'"+()]+$/.test(selector) && selector.length > 20) return true;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Safely extract data using JMESPath with validation
|
|
68
|
+
*/
|
|
69
|
+
static safeJMESPathSearch(data, selector, fallback = null) {
|
|
70
|
+
try {
|
|
71
|
+
const validation = SchemaProcessor.validateJMESPathSelector(selector);
|
|
72
|
+
if (validation.isLiteral) {
|
|
73
|
+
SchemaProcessor.logger.debug({ selector }, "Selector appears to be literal value, returning as-is");
|
|
74
|
+
return selector;
|
|
75
|
+
}
|
|
76
|
+
if (!validation.isValidSelector) {
|
|
77
|
+
SchemaProcessor.logger.warn({ selector }, "Selector does not appear to be valid JMESPath");
|
|
78
|
+
return fallback;
|
|
79
|
+
}
|
|
80
|
+
return jmespath.search(data, selector) || fallback;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
SchemaProcessor.logger.warn({
|
|
83
|
+
selector,
|
|
84
|
+
error: error instanceof Error ? error.message : String(error)
|
|
85
|
+
}, "JMESPath search failed");
|
|
86
|
+
return fallback;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Validate schema structure for artifact components
|
|
91
|
+
*/
|
|
92
|
+
static validateArtifactSchema(schema) {
|
|
93
|
+
const errors = [];
|
|
94
|
+
if (!schema || typeof schema !== "object") {
|
|
95
|
+
errors.push("Schema must be an object");
|
|
96
|
+
return {
|
|
97
|
+
isValid: false,
|
|
98
|
+
errors
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (!schema.type || schema.type !== "object") errors.push("Schema must have type \"object\"");
|
|
102
|
+
if (!schema.properties || typeof schema.properties !== "object") errors.push("Schema must have properties object");
|
|
103
|
+
const transformedSchema = SchemaProcessor.transformSchemaForJMESPath(schema);
|
|
104
|
+
return {
|
|
105
|
+
isValid: errors.length === 0,
|
|
106
|
+
errors,
|
|
107
|
+
transformedSchema
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Extract property value with proper type conversion and validation
|
|
112
|
+
*/
|
|
113
|
+
static extractPropertyValue(data, _propName, selector, expectedType) {
|
|
114
|
+
const value = SchemaProcessor.safeJMESPathSearch(data, selector);
|
|
115
|
+
if (value === null || value === void 0) return null;
|
|
116
|
+
if (expectedType) switch (expectedType) {
|
|
117
|
+
case "string": return String(value);
|
|
118
|
+
case "number": {
|
|
119
|
+
const num = Number(value);
|
|
120
|
+
return Number.isNaN(num) ? null : num;
|
|
121
|
+
}
|
|
122
|
+
case "boolean": return Boolean(value);
|
|
123
|
+
case "array": return Array.isArray(value) ? value : [value];
|
|
124
|
+
default: return value;
|
|
125
|
+
}
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Enhance schema with JMESPath guidance for artifact component schemas
|
|
130
|
+
* Transforms all schema types to string selectors with helpful descriptions
|
|
131
|
+
*/
|
|
132
|
+
static enhanceSchemaWithJMESPathGuidance(schema) {
|
|
133
|
+
if (!schema || typeof schema !== "object") return schema || {};
|
|
134
|
+
const transformToSelectorSchema = (obj, path = "") => {
|
|
135
|
+
if (!obj || typeof obj !== "object") return obj;
|
|
136
|
+
if (obj.type === "array") {
|
|
137
|
+
obj.items?.description;
|
|
138
|
+
const arrayDescription = obj.description || "array data";
|
|
139
|
+
path.includes("content");
|
|
140
|
+
return {
|
|
141
|
+
type: "string",
|
|
142
|
+
description: `🎯 ARRAY SELECTOR: Provide JMESPath selector for ${arrayDescription}. RELATIVE to base selector - this will be applied to the item selected by base_selector. Example: "content.blocks" or "items" (NOT absolute paths like "result.content.blocks")`
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (obj.type === "object" && !obj.properties) return {
|
|
146
|
+
type: "string",
|
|
147
|
+
description: `🎯 OBJECT SELECTOR: Provide JMESPath selector for ${obj.description || "object data"}. RELATIVE to base selector - this will be applied to the item selected by base_selector. Example: "metadata" or "spec.details" (NOT absolute paths)`
|
|
148
|
+
};
|
|
149
|
+
if (obj.type === "object" && obj.properties) {
|
|
150
|
+
const transformedProperties = {};
|
|
151
|
+
Object.entries(obj.properties).forEach(([propertyName, property]) => {
|
|
152
|
+
transformedProperties[propertyName] = transformToSelectorSchema(property, path ? `${path}.${propertyName}` : propertyName);
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
type: "object",
|
|
156
|
+
properties: transformedProperties,
|
|
157
|
+
required: obj.required || [],
|
|
158
|
+
description: `${obj.description || "Object containing JMESPath selectors"} - Each property should be a selector RELATIVE to the base_selector`
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if ([
|
|
162
|
+
"string",
|
|
163
|
+
"number",
|
|
164
|
+
"boolean"
|
|
165
|
+
].includes(obj.type)) {
|
|
166
|
+
const originalDescription = obj.description || `${obj.type} value`;
|
|
167
|
+
return {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: `🎯 FIELD SELECTOR: Provide JMESPath selector for ${originalDescription}. RELATIVE to base selector (e.g., "title", "metadata.category", "properties.value"). For nested data: use field paths like "content.details", "attributes.data", "specifications.info". NOT absolute paths and NOT literal values like "${originalDescription}". The base_selector finds the item, this selector extracts the field FROM that item.`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
type: "string",
|
|
174
|
+
description: `🎯 SELECTOR: Provide JMESPath selector RELATIVE to base selector. Example: "fieldName" or "nested.path" (NOT absolute paths)`
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
return transformToSelectorSchema(schema);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
export { SchemaProcessor };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DataOperationEvent } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/agent-operations.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Agent initialization operation event
|
|
7
|
+
*/
|
|
8
|
+
interface AgentInitializingEvent {
|
|
9
|
+
type: 'agent_initializing';
|
|
10
|
+
details: {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
agentId: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Completion operation event
|
|
17
|
+
*/
|
|
18
|
+
interface CompletionEvent {
|
|
19
|
+
type: 'completion';
|
|
20
|
+
details: {
|
|
21
|
+
agent: string;
|
|
22
|
+
iteration: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Unified error event structure
|
|
27
|
+
* Can be used for both operational errors (with agent context) and general stream errors
|
|
28
|
+
*/
|
|
29
|
+
interface ErrorEvent {
|
|
30
|
+
type: 'error';
|
|
31
|
+
message: string;
|
|
32
|
+
agent?: string;
|
|
33
|
+
severity?: 'error' | 'warning' | 'info';
|
|
34
|
+
code?: string;
|
|
35
|
+
timestamp?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Discriminated union of all operation events
|
|
39
|
+
*/
|
|
40
|
+
type OperationEvent = AgentInitializingEvent | CompletionEvent | ErrorEvent | DataOperationEvent;
|
|
41
|
+
/**
|
|
42
|
+
* Creates an agent initializing operation
|
|
43
|
+
*/
|
|
44
|
+
declare function agentInitializingOp(sessionId: string, agentId: string): AgentInitializingEvent;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a completion operation
|
|
47
|
+
*/
|
|
48
|
+
declare function completionOp(subAgentId: string, iterations: number): CompletionEvent;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a unified error event
|
|
51
|
+
* @param message - Error message
|
|
52
|
+
* @param subAgentId - Optional agent ID for context
|
|
53
|
+
* @param severity - Error severity level
|
|
54
|
+
* @param code - Optional error code
|
|
55
|
+
*/
|
|
56
|
+
declare function errorOp(message: string, subAgentId?: string, severity?: 'error' | 'warning' | 'info', code?: string): ErrorEvent;
|
|
57
|
+
/**
|
|
58
|
+
* Generate a unique tool execution ID for lifecycle tracking
|
|
59
|
+
*/
|
|
60
|
+
declare function generateToolId(): string;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { AgentInitializingEvent, CompletionEvent, ErrorEvent, OperationEvent, agentInitializingOp, completionOp, errorOp, generateToolId };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { generateId } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/agent-operations.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates an agent initializing operation
|
|
6
|
+
*/
|
|
7
|
+
function agentInitializingOp(sessionId, agentId) {
|
|
8
|
+
return {
|
|
9
|
+
type: "agent_initializing",
|
|
10
|
+
details: {
|
|
11
|
+
sessionId,
|
|
12
|
+
agentId
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a completion operation
|
|
18
|
+
*/
|
|
19
|
+
function completionOp(subAgentId, iterations) {
|
|
20
|
+
return {
|
|
21
|
+
type: "completion",
|
|
22
|
+
details: {
|
|
23
|
+
agent: subAgentId,
|
|
24
|
+
iteration: iterations
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a unified error event
|
|
30
|
+
* @param message - Error message
|
|
31
|
+
* @param subAgentId - Optional agent ID for context
|
|
32
|
+
* @param severity - Error severity level
|
|
33
|
+
* @param code - Optional error code
|
|
34
|
+
*/
|
|
35
|
+
function errorOp(message, subAgentId, severity = "error", code) {
|
|
36
|
+
return {
|
|
37
|
+
type: "error",
|
|
38
|
+
message,
|
|
39
|
+
agent: subAgentId,
|
|
40
|
+
severity,
|
|
41
|
+
code,
|
|
42
|
+
timestamp: Date.now()
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate a unique tool execution ID for lifecycle tracking
|
|
47
|
+
*/
|
|
48
|
+
function generateToolId() {
|
|
49
|
+
return `tool_${generateId(8)}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { agentInitializingOp, completionOp, errorOp, generateToolId };
|
|
@@ -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 };
|