@inkeep/agents-cli 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.
- package/dist/_virtual/rolldown_runtime.js +7 -0
- package/dist/api.js +185 -0
- package/dist/commands/add.js +139 -0
- package/dist/commands/config.js +86 -0
- package/dist/commands/dev.js +259 -0
- package/dist/commands/init.js +360 -0
- package/dist/commands/list-agents.js +56 -0
- package/dist/commands/login.js +179 -0
- package/dist/commands/logout.js +56 -0
- package/dist/commands/profile.js +276 -0
- package/dist/{component-parser2.js → commands/pull-v3/component-parser.js} +16 -3
- package/dist/commands/pull-v3/component-updater.js +710 -0
- package/dist/commands/pull-v3/components/agent-generator.js +241 -0
- package/dist/commands/pull-v3/components/artifact-component-generator.js +127 -0
- package/dist/commands/pull-v3/components/context-config-generator.js +190 -0
- package/dist/commands/pull-v3/components/credential-generator.js +89 -0
- package/dist/commands/pull-v3/components/data-component-generator.js +102 -0
- package/dist/commands/pull-v3/components/environment-generator.js +170 -0
- package/dist/commands/pull-v3/components/external-agent-generator.js +75 -0
- package/dist/commands/pull-v3/components/function-tool-generator.js +94 -0
- package/dist/commands/pull-v3/components/mcp-tool-generator.js +86 -0
- package/dist/commands/pull-v3/components/project-generator.js +145 -0
- package/dist/commands/pull-v3/components/status-component-generator.js +92 -0
- package/dist/commands/pull-v3/components/sub-agent-generator.js +285 -0
- package/dist/commands/pull-v3/index.js +510 -0
- package/dist/commands/pull-v3/introspect-generator.js +278 -0
- package/dist/commands/pull-v3/llm-content-merger.js +192 -0
- package/dist/{new-component-generator.js → commands/pull-v3/new-component-generator.js} +14 -3
- package/dist/commands/pull-v3/project-comparator.js +914 -0
- package/dist/{project-index-generator.js → commands/pull-v3/project-index-generator.js} +1 -2
- package/dist/{project-validator.js → commands/pull-v3/project-validator.js} +4 -4
- package/dist/commands/pull-v3/targeted-typescript-placeholders.js +173 -0
- package/dist/commands/pull-v3/utils/component-registry.js +369 -0
- package/dist/commands/pull-v3/utils/component-tracker.js +165 -0
- package/dist/commands/pull-v3/utils/generator-utils.js +146 -0
- package/dist/commands/pull-v3/utils/model-provider-detector.js +44 -0
- package/dist/commands/push.js +326 -0
- package/dist/commands/status.js +89 -0
- package/dist/commands/update.js +97 -0
- package/dist/commands/whoami.js +38 -0
- package/dist/config.js +0 -1
- package/dist/env.js +30 -0
- package/dist/exports.js +3 -0
- package/dist/index.js +28 -196514
- package/dist/instrumentation.js +47 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/tsx.d.d.ts +1 -0
- package/dist/utils/background-version-check.js +19 -0
- package/dist/utils/ci-environment.js +87 -0
- package/dist/utils/cli-pipeline.js +158 -0
- package/dist/utils/config.js +290 -0
- package/dist/utils/credentials.js +132 -0
- package/dist/utils/environment-loader.js +28 -0
- package/dist/utils/file-finder.js +62 -0
- package/dist/utils/json-comparator.js +185 -0
- package/dist/utils/json-comparison.js +232 -0
- package/dist/utils/mcp-runner.js +120 -0
- package/dist/utils/model-config.js +182 -0
- package/dist/utils/package-manager.js +58 -0
- package/dist/utils/profile-config.js +85 -0
- package/dist/utils/profiles/index.js +4 -0
- package/dist/utils/profiles/profile-manager.js +219 -0
- package/dist/utils/profiles/types.js +62 -0
- package/dist/utils/project-directory.js +33 -0
- package/dist/utils/project-loader.js +29 -0
- package/dist/utils/schema-introspection.js +44 -0
- package/dist/utils/templates.js +198 -0
- package/dist/utils/tsx-loader.js +27 -0
- package/dist/utils/url.js +26 -0
- package/dist/utils/version-check.js +79 -0
- package/package.json +4 -19
- package/dist/component-parser.js +0 -4
- package/dist/component-updater.js +0 -4
- package/dist/config2.js +0 -4
- package/dist/credential-stores.js +0 -4
- package/dist/environment-generator.js +0 -4
- package/dist/nodefs.js +0 -27
- package/dist/opfs-ahp.js +0 -368
- package/dist/project-loader.js +0 -4
- package/dist/tsx-loader.js +0 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { DEFAULT_STYLE, formatObject, formatString, generateFileContent, generateImport, removeTrailingComma, shouldInclude, toCamelCase } from "../utils/generator-utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/pull-v3/components/project-generator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate Project Definition using project() builder function
|
|
6
|
+
*/
|
|
7
|
+
function generateProjectDefinition(projectId, projectData, style = DEFAULT_STYLE, registry) {
|
|
8
|
+
if (!projectId || typeof projectId !== "string") throw new Error("projectId is required and must be a string");
|
|
9
|
+
if (!projectData || typeof projectData !== "object") throw new Error(`projectData is required for project '${projectId}'`);
|
|
10
|
+
const missingFields = ["name", "models"].filter((field) => !projectData[field] || projectData[field] === null || projectData[field] === void 0);
|
|
11
|
+
if (!projectData.models?.base) missingFields.push("models.base");
|
|
12
|
+
if (missingFields.length > 0) throw new Error(`Missing required fields for project '${projectId}': ${missingFields.join(", ")}`);
|
|
13
|
+
const { quotes, semicolons, indentation } = style;
|
|
14
|
+
const q = quotes === "single" ? "'" : "\"";
|
|
15
|
+
const semi = semicolons ? ";" : "";
|
|
16
|
+
const projectVarName = toCamelCase(projectId);
|
|
17
|
+
const lines = [];
|
|
18
|
+
lines.push(`export const ${projectVarName} = project({`);
|
|
19
|
+
lines.push(`${indentation}id: ${formatString(projectId, q)},`);
|
|
20
|
+
lines.push(`${indentation}name: ${formatString(projectData.name, q)},`);
|
|
21
|
+
if (shouldInclude(projectData.description)) lines.push(`${indentation}description: ${formatString(projectData.description, q, true)},`);
|
|
22
|
+
if (shouldInclude(projectData.models)) lines.push(`${indentation}models: ${formatObject(projectData.models, style, 2)},`);
|
|
23
|
+
if (shouldInclude(projectData.stopWhen)) {
|
|
24
|
+
lines.push(`${indentation}stopWhen: {`);
|
|
25
|
+
if (projectData.stopWhen.transferCountIs !== void 0) lines.push(`${indentation}${indentation}transferCountIs: ${projectData.stopWhen.transferCountIs}, // Max transfers for agents`);
|
|
26
|
+
if (projectData.stopWhen.stepCountIs !== void 0) lines.push(`${indentation}${indentation}stepCountIs: ${projectData.stopWhen.stepCountIs} // Max steps for sub-agents`);
|
|
27
|
+
if (lines.length > 1) {
|
|
28
|
+
const lastLine = lines[lines.length - 1];
|
|
29
|
+
if (lastLine.includes(",") && (lastLine.includes("//") || lastLine.endsWith(","))) if (lastLine.includes("//")) lines[lines.length - 1] = lastLine.replace(", //", " //");
|
|
30
|
+
else lines[lines.length - 1] = lastLine.slice(0, -1);
|
|
31
|
+
}
|
|
32
|
+
lines.push(`${indentation}},`);
|
|
33
|
+
}
|
|
34
|
+
if (shouldInclude(projectData.agents)) {
|
|
35
|
+
const agentsArray = registry ? registry.formatReferencesForCode(projectData.agents, "agents", style, 2) : "[]";
|
|
36
|
+
lines.push(`${indentation}agents: () => ${agentsArray},`);
|
|
37
|
+
}
|
|
38
|
+
if (shouldInclude(projectData.tools)) {
|
|
39
|
+
const toolsArray = registry ? registry.formatReferencesForCode(projectData.tools, "tools", style, 2) : "[]";
|
|
40
|
+
lines.push(`${indentation}tools: () => ${toolsArray},`);
|
|
41
|
+
}
|
|
42
|
+
if (shouldInclude(projectData.externalAgents)) {
|
|
43
|
+
const externalAgentsArray = registry ? registry.formatReferencesForCode(projectData.externalAgents, "externalAgents", style, 2) : "[]";
|
|
44
|
+
lines.push(`${indentation}externalAgents: () => ${externalAgentsArray},`);
|
|
45
|
+
}
|
|
46
|
+
if (shouldInclude(projectData.dataComponents)) {
|
|
47
|
+
const dataComponentsArray = registry ? registry.formatReferencesForCode(projectData.dataComponents, "dataComponents", style, 2) : "[]";
|
|
48
|
+
lines.push(`${indentation}dataComponents: () => ${dataComponentsArray},`);
|
|
49
|
+
}
|
|
50
|
+
if (shouldInclude(projectData.artifactComponents)) {
|
|
51
|
+
const artifactComponentsArray = registry ? registry.formatReferencesForCode(projectData.artifactComponents, "artifactComponents", style, 2) : "[]";
|
|
52
|
+
lines.push(`${indentation}artifactComponents: () => ${artifactComponentsArray},`);
|
|
53
|
+
}
|
|
54
|
+
if (shouldInclude(projectData.credentialReferences)) {
|
|
55
|
+
const credentialReferencesArray = registry ? registry.formatReferencesForCode(projectData.credentialReferences, "credentials", style, 2) : "[]";
|
|
56
|
+
lines.push(`${indentation}credentialReferences: () => ${credentialReferencesArray},`);
|
|
57
|
+
}
|
|
58
|
+
removeTrailingComma(lines);
|
|
59
|
+
lines.push(`})${semi}`);
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generate imports needed for a project file
|
|
64
|
+
*/
|
|
65
|
+
function generateProjectImports(projectId, projectData, style = DEFAULT_STYLE, registry) {
|
|
66
|
+
const imports = [];
|
|
67
|
+
imports.push(generateImport(["project"], "@inkeep/agents-sdk", style));
|
|
68
|
+
if (registry) {
|
|
69
|
+
const currentFilePath = "index.ts";
|
|
70
|
+
const referencedComponents = [];
|
|
71
|
+
if (projectData.agents) {
|
|
72
|
+
let agentIds = [];
|
|
73
|
+
if (Array.isArray(projectData.agents)) agentIds = projectData.agents;
|
|
74
|
+
else if (typeof projectData.agents === "object") agentIds = Object.keys(projectData.agents);
|
|
75
|
+
for (const agentId of agentIds) referencedComponents.push({
|
|
76
|
+
id: agentId,
|
|
77
|
+
type: "agents"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (projectData.tools) {
|
|
81
|
+
let toolIds = [];
|
|
82
|
+
if (Array.isArray(projectData.tools)) toolIds = projectData.tools;
|
|
83
|
+
else if (typeof projectData.tools === "object") toolIds = Object.keys(projectData.tools);
|
|
84
|
+
for (const toolId of toolIds) {
|
|
85
|
+
let componentType = "tools";
|
|
86
|
+
if (registry && registry.get(toolId, "functionTools")) componentType = "functionTools";
|
|
87
|
+
else if (registry && registry.get(toolId, "tools")) componentType = "tools";
|
|
88
|
+
referencedComponents.push({
|
|
89
|
+
id: toolId,
|
|
90
|
+
type: componentType
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (projectData.externalAgents) {
|
|
95
|
+
let extAgentIds = [];
|
|
96
|
+
if (Array.isArray(projectData.externalAgents)) extAgentIds = projectData.externalAgents;
|
|
97
|
+
else if (typeof projectData.externalAgents === "object") extAgentIds = Object.keys(projectData.externalAgents);
|
|
98
|
+
for (const extAgentId of extAgentIds) referencedComponents.push({
|
|
99
|
+
id: extAgentId,
|
|
100
|
+
type: "externalAgents"
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (projectData.dataComponents) {
|
|
104
|
+
let dataCompIds = [];
|
|
105
|
+
if (Array.isArray(projectData.dataComponents)) dataCompIds = projectData.dataComponents;
|
|
106
|
+
else if (typeof projectData.dataComponents === "object") dataCompIds = Object.keys(projectData.dataComponents);
|
|
107
|
+
for (const dataCompId of dataCompIds) referencedComponents.push({
|
|
108
|
+
id: dataCompId,
|
|
109
|
+
type: "dataComponents"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (projectData.artifactComponents) {
|
|
113
|
+
let artifactCompIds = [];
|
|
114
|
+
if (Array.isArray(projectData.artifactComponents)) artifactCompIds = projectData.artifactComponents;
|
|
115
|
+
else if (typeof projectData.artifactComponents === "object") artifactCompIds = Object.keys(projectData.artifactComponents);
|
|
116
|
+
for (const artifactCompId of artifactCompIds) referencedComponents.push({
|
|
117
|
+
id: artifactCompId,
|
|
118
|
+
type: "artifactComponents"
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (projectData.credentialReferences) {
|
|
122
|
+
let credIds = [];
|
|
123
|
+
if (Array.isArray(projectData.credentialReferences)) credIds = projectData.credentialReferences;
|
|
124
|
+
else if (typeof projectData.credentialReferences === "object") credIds = Object.keys(projectData.credentialReferences);
|
|
125
|
+
for (const credId of credIds) referencedComponents.push({
|
|
126
|
+
id: credId,
|
|
127
|
+
type: "credentials"
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (referencedComponents.length > 0) {
|
|
131
|
+
const componentImports = registry.getImportsForFile(currentFilePath, referencedComponents);
|
|
132
|
+
imports.push(...componentImports);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return imports;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Generate complete project file (imports + definition)
|
|
139
|
+
*/
|
|
140
|
+
function generateProjectFile(projectId, projectData, style = DEFAULT_STYLE, registry) {
|
|
141
|
+
return generateFileContent(generateProjectImports(projectId, projectData, style, registry), [generateProjectDefinition(projectId, projectData, style, registry)]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
export { generateProjectDefinition, generateProjectFile, generateProjectImports };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsonSchemaToZod } from "json-schema-to-zod";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/pull-v3/components/status-component-generator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Status Component Generator - Generate status component definitions
|
|
6
|
+
*
|
|
7
|
+
* Generates status components using the statusComponent() builder function from @inkeep/agents-sdk
|
|
8
|
+
* Status components are used for progress updates and event notifications in agents
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_STYLE = {
|
|
11
|
+
quotes: "single",
|
|
12
|
+
semicolons: true,
|
|
13
|
+
indentation: " "
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Utility functions
|
|
17
|
+
*/
|
|
18
|
+
function toCamelCase(str) {
|
|
19
|
+
return str.toLowerCase().replace(/[-_](.)/g, (_, char) => char.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "").replace(/^[0-9]/, "_$&");
|
|
20
|
+
}
|
|
21
|
+
function formatString(str, quote = "'", multiline = false) {
|
|
22
|
+
if (!str) return `${quote}${quote}`;
|
|
23
|
+
if (multiline && (str.includes("\n") || str.length > 80)) return `\`${str.replace(/`/g, "\\`")}\``;
|
|
24
|
+
return `${quote}${str.replace(new RegExp(quote, "g"), "\\" + quote)}${quote}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convert JSON Schema to Zod schema using existing utility
|
|
28
|
+
*/
|
|
29
|
+
function convertJsonSchemaToZod(schema) {
|
|
30
|
+
if (!schema || typeof schema !== "object") return "z.any()";
|
|
31
|
+
try {
|
|
32
|
+
return jsonSchemaToZod(schema);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.warn("Failed to convert JSON schema to Zod:", error);
|
|
35
|
+
return "z.any()";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate Status Component Definition using statusComponent() builder function
|
|
40
|
+
*/
|
|
41
|
+
function generateStatusComponentDefinition(componentId, componentData, style = DEFAULT_STYLE) {
|
|
42
|
+
if (!componentId || typeof componentId !== "string") throw new Error("componentId is required and must be a string");
|
|
43
|
+
if (!componentData || typeof componentData !== "object") throw new Error(`componentData is required for status component '${componentId}'`);
|
|
44
|
+
const missingFields = ["type"].filter((field) => !componentData[field] || componentData[field] === null || componentData[field] === void 0);
|
|
45
|
+
if (missingFields.length > 0) throw new Error(`Missing required fields for status component '${componentId}': ${missingFields.join(", ")}`);
|
|
46
|
+
const { quotes, semicolons, indentation } = style;
|
|
47
|
+
const q = quotes === "single" ? "'" : "\"";
|
|
48
|
+
const semi = semicolons ? ";" : "";
|
|
49
|
+
const componentVarName = toCamelCase(componentId);
|
|
50
|
+
const lines = [];
|
|
51
|
+
lines.push(`export const ${componentVarName} = statusComponent({`);
|
|
52
|
+
lines.push(`${indentation}type: ${formatString(componentData.type, q)},`);
|
|
53
|
+
if (componentData.description) lines.push(`${indentation}description: ${formatString(componentData.description, q, true)},`);
|
|
54
|
+
const schema = componentData.detailsSchema || componentData.schema;
|
|
55
|
+
if (schema) {
|
|
56
|
+
const zodSchema = convertJsonSchemaToZod(schema);
|
|
57
|
+
if (zodSchema.includes("\n")) {
|
|
58
|
+
const schemaLines = zodSchema.split("\n");
|
|
59
|
+
lines.push(`${indentation}detailsSchema: ${schemaLines[0]}`);
|
|
60
|
+
schemaLines.slice(1, -1).forEach((line) => {
|
|
61
|
+
lines[lines.length - 1] += "\n" + indentation + line;
|
|
62
|
+
});
|
|
63
|
+
lines[lines.length - 1] += "\n" + indentation + schemaLines[schemaLines.length - 1] + ",";
|
|
64
|
+
} else lines.push(`${indentation}detailsSchema: ${zodSchema},`);
|
|
65
|
+
}
|
|
66
|
+
if (lines.length > 0 && lines[lines.length - 1].endsWith(",")) lines[lines.length - 1] = lines[lines.length - 1].slice(0, -1);
|
|
67
|
+
lines.push(`})${semi}`);
|
|
68
|
+
return lines.join("\n");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate imports needed for a status component file
|
|
72
|
+
*/
|
|
73
|
+
function generateStatusComponentImports(componentId, componentData, style = DEFAULT_STYLE) {
|
|
74
|
+
const { quotes, semicolons } = style;
|
|
75
|
+
const q = quotes === "single" ? "'" : "\"";
|
|
76
|
+
const semi = semicolons ? ";" : "";
|
|
77
|
+
const imports = [];
|
|
78
|
+
imports.push(`import { statusComponent } from ${q}@inkeep/agents-sdk${q}${semi}`);
|
|
79
|
+
if (componentData.detailsSchema || componentData.schema) imports.push(`import { z } from ${q}zod${q}${semi}`);
|
|
80
|
+
return imports;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Generate complete status component file (imports + definition)
|
|
84
|
+
*/
|
|
85
|
+
function generateStatusComponentFile(componentId, componentData, style = DEFAULT_STYLE) {
|
|
86
|
+
const imports = generateStatusComponentImports(componentId, componentData, style);
|
|
87
|
+
const definition = generateStatusComponentDefinition(componentId, componentData, style);
|
|
88
|
+
return imports.join("\n") + "\n\n" + definition + "\n";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { generateStatusComponentDefinition, generateStatusComponentFile, generateStatusComponentImports };
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { compareJsonObjects } from "../../../utils/json-comparator.js";
|
|
2
|
+
import { DEFAULT_STYLE, formatPromptWithContext, formatString, generateFileContent, generateImport, hasTemplateVariables, removeTrailingComma, toCamelCase } from "../utils/generator-utils.js";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/pull-v3/components/sub-agent-generator.ts
|
|
5
|
+
/**
|
|
6
|
+
* Sub Agent Generator - Generate sub-agent definitions
|
|
7
|
+
*
|
|
8
|
+
* Generates sub-agents using the subAgent() builder function from @inkeep/agents-sdk
|
|
9
|
+
* Sub-agents are the individual agents within an agent graph that handle specific tasks
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Check if subAgent models are different from parent agent models (or project models)
|
|
13
|
+
*/
|
|
14
|
+
function hasDistinctModels(subAgentModels, parentModels) {
|
|
15
|
+
if (!subAgentModels) return false;
|
|
16
|
+
if (!parentModels) return !!subAgentModels;
|
|
17
|
+
for (const type of [
|
|
18
|
+
"base",
|
|
19
|
+
"structuredOutput",
|
|
20
|
+
"summarizer"
|
|
21
|
+
]) {
|
|
22
|
+
const subAgentModel = subAgentModels[type]?.model;
|
|
23
|
+
const parentModel = parentModels[type]?.model;
|
|
24
|
+
if (subAgentModel !== parentModel) return true;
|
|
25
|
+
if (subAgentModel && parentModel) {
|
|
26
|
+
const subAgentOptions = subAgentModels[type]?.providerOptions;
|
|
27
|
+
const parentOptions = parentModels[type]?.providerOptions;
|
|
28
|
+
if (subAgentOptions !== parentOptions) {
|
|
29
|
+
if (!subAgentOptions && !parentOptions) continue;
|
|
30
|
+
if (!subAgentOptions || !parentOptions) return true;
|
|
31
|
+
if (!compareJsonObjects(subAgentOptions, parentOptions, {
|
|
32
|
+
ignoreArrayOrder: true,
|
|
33
|
+
showDetails: false
|
|
34
|
+
}).isEqual) return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generate Sub Agent Definition using subAgent() builder function
|
|
42
|
+
*/
|
|
43
|
+
function generateSubAgentDefinition(agentId, agentData, style = DEFAULT_STYLE, registry, parentAgentId, contextConfigData, parentModels) {
|
|
44
|
+
if (!agentId || typeof agentId !== "string") throw new Error("agentId is required and must be a string");
|
|
45
|
+
if (!agentData || typeof agentData !== "object") throw new Error(`agentData is required for sub-agent '${agentId}'`);
|
|
46
|
+
const { quotes, semicolons, indentation } = style;
|
|
47
|
+
const q = quotes === "single" ? "'" : "\"";
|
|
48
|
+
const semi = semicolons ? ";" : "";
|
|
49
|
+
let agentVarName = toCamelCase(agentId);
|
|
50
|
+
if (registry) {
|
|
51
|
+
const registryVarName = registry.getVariableName(agentId, "subAgents");
|
|
52
|
+
if (registryVarName) agentVarName = registryVarName;
|
|
53
|
+
}
|
|
54
|
+
const agentName = agentData.name !== void 0 && agentData.name !== null ? agentData.name : agentId.replace(/[-_]/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
55
|
+
const lines = [];
|
|
56
|
+
lines.push(`export const ${agentVarName} = subAgent({`);
|
|
57
|
+
lines.push(`${indentation}id: ${formatString(agentId, q)},`);
|
|
58
|
+
lines.push(`${indentation}name: ${formatString(agentName, q)},`);
|
|
59
|
+
lines.push(`${indentation}description: ${formatString(agentData.description, q, true)},`);
|
|
60
|
+
if (agentData.prompt !== void 0 && agentData.prompt !== null) if (hasTemplateVariables(agentData.prompt) && parentAgentId && registry && contextConfigData) {
|
|
61
|
+
const contextVarName = registry.getVariableName(contextConfigData.id, "contextConfigs");
|
|
62
|
+
if (!contextVarName) throw new Error(`Failed to resolve context config variable name for: ${contextConfigData.id}`);
|
|
63
|
+
lines.push(`${indentation}prompt: ${formatPromptWithContext(agentData.prompt, contextVarName, "headersSchema", contextConfigData, q, true)},`);
|
|
64
|
+
} else lines.push(`${indentation}prompt: ${formatString(agentData.prompt, q, true)},`);
|
|
65
|
+
if (agentData.models && hasDistinctModels(agentData.models, parentModels)) {
|
|
66
|
+
lines.push(`${indentation}models: {`);
|
|
67
|
+
if (agentData.models.base?.model) {
|
|
68
|
+
lines.push(`${indentation}${indentation}base: {`);
|
|
69
|
+
lines.push(`${indentation}${indentation}${indentation}model: ${formatString(agentData.models.base.model, q)}`);
|
|
70
|
+
if (agentData.models.base.providerOptions) {
|
|
71
|
+
lines.push(`${indentation}${indentation}${indentation},`);
|
|
72
|
+
lines.push(`${indentation}${indentation}${indentation}providerOptions: ${JSON.stringify(agentData.models.base.providerOptions)}`);
|
|
73
|
+
}
|
|
74
|
+
lines.push(`${indentation}${indentation}},`);
|
|
75
|
+
}
|
|
76
|
+
if (agentData.models.structuredOutput?.model) {
|
|
77
|
+
lines.push(`${indentation}${indentation}structuredOutput: {`);
|
|
78
|
+
lines.push(`${indentation}${indentation}${indentation}model: ${formatString(agentData.models.structuredOutput.model, q)}`);
|
|
79
|
+
if (agentData.models.structuredOutput.providerOptions) {
|
|
80
|
+
lines.push(`${indentation}${indentation}${indentation},`);
|
|
81
|
+
lines.push(`${indentation}${indentation}${indentation}providerOptions: ${JSON.stringify(agentData.models.structuredOutput.providerOptions)}`);
|
|
82
|
+
}
|
|
83
|
+
lines.push(`${indentation}${indentation}},`);
|
|
84
|
+
}
|
|
85
|
+
if (agentData.models.summarizer?.model) {
|
|
86
|
+
lines.push(`${indentation}${indentation}summarizer: {`);
|
|
87
|
+
lines.push(`${indentation}${indentation}${indentation}model: ${formatString(agentData.models.summarizer.model, q)}`);
|
|
88
|
+
if (agentData.models.summarizer.providerOptions) {
|
|
89
|
+
lines.push(`${indentation}${indentation}${indentation},`);
|
|
90
|
+
lines.push(`${indentation}${indentation}${indentation}providerOptions: ${JSON.stringify(agentData.models.summarizer.providerOptions)}`);
|
|
91
|
+
}
|
|
92
|
+
lines.push(`${indentation}${indentation}},`);
|
|
93
|
+
}
|
|
94
|
+
removeTrailingComma(lines);
|
|
95
|
+
lines.push(`${indentation}},`);
|
|
96
|
+
}
|
|
97
|
+
if (agentData.canUse && Array.isArray(agentData.canUse) && agentData.canUse.length > 0) {
|
|
98
|
+
const toolReferences = [];
|
|
99
|
+
if (!registry) throw new Error("Registry is required for canUse generation");
|
|
100
|
+
for (const toolRelation of agentData.canUse) {
|
|
101
|
+
const toolId = toolRelation.toolId;
|
|
102
|
+
let toolVarName = registry.getVariableName(toolId, "tools");
|
|
103
|
+
if (!toolVarName) toolVarName = registry.getVariableName(toolId, "functionTools");
|
|
104
|
+
if (!toolVarName) throw new Error(`Failed to resolve variable name for tool: ${toolId} (tried both 'tools' and 'functionTools' types)`);
|
|
105
|
+
const hasToolSelection = toolRelation.toolSelection && toolRelation.toolSelection.length > 0;
|
|
106
|
+
const hasHeaders = toolRelation.headers && Object.keys(toolRelation.headers).length > 0;
|
|
107
|
+
if (hasToolSelection || hasHeaders) {
|
|
108
|
+
const configLines = [];
|
|
109
|
+
if (hasToolSelection) {
|
|
110
|
+
const selectedToolsStr = JSON.stringify(toolRelation.toolSelection);
|
|
111
|
+
configLines.push(`selectedTools: ${selectedToolsStr}`);
|
|
112
|
+
}
|
|
113
|
+
if (hasHeaders) {
|
|
114
|
+
const headersStr = JSON.stringify(toolRelation.headers);
|
|
115
|
+
configLines.push(`headers: ${headersStr}`);
|
|
116
|
+
}
|
|
117
|
+
const configStr = configLines.join(", ");
|
|
118
|
+
const finalRef = `${toolVarName}.with({ ${configStr} })`;
|
|
119
|
+
toolReferences.push(finalRef);
|
|
120
|
+
} else toolReferences.push(toolVarName);
|
|
121
|
+
}
|
|
122
|
+
const { indentation: indent } = style;
|
|
123
|
+
const nestedIndent = indent.repeat(2);
|
|
124
|
+
if (toolReferences.length === 1) lines.push(`${indentation}canUse: () => [${toolReferences[0]}],`);
|
|
125
|
+
else {
|
|
126
|
+
lines.push(`${indentation}canUse: () => [`);
|
|
127
|
+
toolReferences.forEach((ref, index) => {
|
|
128
|
+
const isLast = index === toolReferences.length - 1;
|
|
129
|
+
lines.push(`${indentation}${nestedIndent}${ref}${isLast ? "" : ","}`);
|
|
130
|
+
});
|
|
131
|
+
lines.push(`${indentation}],`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (agentData.canDelegateTo && Array.isArray(agentData.canDelegateTo) && agentData.canDelegateTo.length > 0) {
|
|
135
|
+
if (!registry) throw new Error("Registry is required for canDelegateTo generation");
|
|
136
|
+
const delegateReferences = [];
|
|
137
|
+
for (const delegateRelation of agentData.canDelegateTo) {
|
|
138
|
+
let targetAgentId;
|
|
139
|
+
let targetType;
|
|
140
|
+
let hasHeaders = false;
|
|
141
|
+
if (typeof delegateRelation === "string") {
|
|
142
|
+
targetAgentId = delegateRelation;
|
|
143
|
+
targetType = "subAgents";
|
|
144
|
+
hasHeaders = false;
|
|
145
|
+
} else if (delegateRelation && typeof delegateRelation === "object") {
|
|
146
|
+
hasHeaders = delegateRelation.headers && Object.keys(delegateRelation.headers).length > 0;
|
|
147
|
+
if (delegateRelation.externalAgentId) {
|
|
148
|
+
targetAgentId = delegateRelation.externalAgentId;
|
|
149
|
+
targetType = "externalAgents";
|
|
150
|
+
} else if (delegateRelation.agentId) {
|
|
151
|
+
targetAgentId = delegateRelation.agentId;
|
|
152
|
+
targetType = "agents";
|
|
153
|
+
} else if (delegateRelation.subAgentId) {
|
|
154
|
+
targetAgentId = delegateRelation.subAgentId;
|
|
155
|
+
targetType = "subAgents";
|
|
156
|
+
} else throw new Error(`Delegate relation missing agentId, subAgentId, or externalAgentId: ${JSON.stringify(delegateRelation)}`);
|
|
157
|
+
} else throw new Error(`Invalid delegate relation format: ${JSON.stringify(delegateRelation)}`);
|
|
158
|
+
if (!targetAgentId) throw new Error(`Failed to extract target agent ID from delegate relation: ${JSON.stringify(delegateRelation)}`);
|
|
159
|
+
const agentVarName$1 = registry.getVariableName(targetAgentId, targetType);
|
|
160
|
+
if (!agentVarName$1) throw new Error(`Failed to resolve variable name for delegate ${targetType}: ${targetAgentId}`);
|
|
161
|
+
if (hasHeaders) {
|
|
162
|
+
const finalRef = `${agentVarName$1}.with({ headers: ${JSON.stringify(delegateRelation.headers)} })`;
|
|
163
|
+
delegateReferences.push(finalRef);
|
|
164
|
+
} else delegateReferences.push(agentVarName$1);
|
|
165
|
+
}
|
|
166
|
+
const { indentation: indent } = style;
|
|
167
|
+
const nestedIndent = indent.repeat(2);
|
|
168
|
+
if (delegateReferences.length === 1) lines.push(`${indentation}canDelegateTo: () => [${delegateReferences[0]}],`);
|
|
169
|
+
else {
|
|
170
|
+
lines.push(`${indentation}canDelegateTo: () => [`);
|
|
171
|
+
delegateReferences.forEach((ref, index) => {
|
|
172
|
+
const isLast = index === delegateReferences.length - 1;
|
|
173
|
+
lines.push(`${indentation}${nestedIndent}${ref}${isLast ? "" : ","}`);
|
|
174
|
+
});
|
|
175
|
+
lines.push(`${indentation}],`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (agentData.canTransferTo && Array.isArray(agentData.canTransferTo) && agentData.canTransferTo.length > 0) {
|
|
179
|
+
if (!registry) throw new Error("Registry is required for canTransferTo generation");
|
|
180
|
+
const transferArray = registry.formatReferencesForCode(agentData.canTransferTo, "subAgents", style, 2);
|
|
181
|
+
if (!transferArray) throw new Error(`Failed to resolve variable names for canTransferTo agents: ${agentData.canTransferTo.join(", ")}`);
|
|
182
|
+
lines.push(`${indentation}canTransferTo: () => ${transferArray},`);
|
|
183
|
+
}
|
|
184
|
+
if (agentData.dataComponents && Array.isArray(agentData.dataComponents) && agentData.dataComponents.length > 0) {
|
|
185
|
+
if (!registry) throw new Error("Registry is required for dataComponents generation");
|
|
186
|
+
const dataComponentsArray = registry.formatReferencesForCode(agentData.dataComponents, "dataComponents", style, 2);
|
|
187
|
+
if (!dataComponentsArray) throw new Error(`Failed to resolve variable names for data components: ${agentData.dataComponents.join(", ")}`);
|
|
188
|
+
lines.push(`${indentation}dataComponents: () => ${dataComponentsArray},`);
|
|
189
|
+
}
|
|
190
|
+
if (agentData.artifactComponents && Array.isArray(agentData.artifactComponents) && agentData.artifactComponents.length > 0) {
|
|
191
|
+
if (!registry) throw new Error("Registry is required for artifactComponents generation");
|
|
192
|
+
const artifactComponentsArray = registry.formatReferencesForCode(agentData.artifactComponents, "artifactComponents", style, 2);
|
|
193
|
+
if (!artifactComponentsArray) throw new Error(`Failed to resolve variable names for artifact components: ${agentData.artifactComponents.join(", ")}`);
|
|
194
|
+
lines.push(`${indentation}artifactComponents: () => ${artifactComponentsArray},`);
|
|
195
|
+
}
|
|
196
|
+
if (agentData.stopWhen && agentData.stopWhen.stepCountIs !== void 0) {
|
|
197
|
+
lines.push(`${indentation}stopWhen: {`);
|
|
198
|
+
lines.push(`${indentation}${indentation}stepCountIs: ${agentData.stopWhen.stepCountIs} // Max tool calls + LLM responses`);
|
|
199
|
+
lines.push(`${indentation}},`);
|
|
200
|
+
}
|
|
201
|
+
removeTrailingComma(lines);
|
|
202
|
+
lines.push(`})${semi}`);
|
|
203
|
+
return lines.join("\n");
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Generate imports needed for a sub-agent file
|
|
207
|
+
*/
|
|
208
|
+
function generateSubAgentImports(agentId, agentData, style = DEFAULT_STYLE, registry, parentAgentId, contextConfigData, actualFilePath) {
|
|
209
|
+
const imports = [];
|
|
210
|
+
imports.push(generateImport(["subAgent"], "@inkeep/agents-sdk", style));
|
|
211
|
+
if (hasTemplateVariables(agentData.prompt) && parentAgentId && registry && contextConfigData) {
|
|
212
|
+
const contextConfigId = contextConfigData.id;
|
|
213
|
+
const currentFilePath = actualFilePath || `agents/sub-agents/${agentId}.ts`;
|
|
214
|
+
const importStatement = registry.getImportStatement(currentFilePath, contextConfigId, "contextConfigs");
|
|
215
|
+
if (importStatement) imports.push(importStatement);
|
|
216
|
+
}
|
|
217
|
+
if (registry) {
|
|
218
|
+
const currentFilePath = actualFilePath || `agents/sub-agents/${agentId}.ts`;
|
|
219
|
+
const referencedComponents = [];
|
|
220
|
+
if (Array.isArray(agentData.canUse)) for (const toolRelation of agentData.canUse) {
|
|
221
|
+
const toolId = toolRelation.toolId;
|
|
222
|
+
if (toolId) {
|
|
223
|
+
let componentType = "tools";
|
|
224
|
+
if (registry.get(toolId, "functionTools")) componentType = "functionTools";
|
|
225
|
+
else if (registry.get(toolId, "tools")) componentType = "tools";
|
|
226
|
+
referencedComponents.push({
|
|
227
|
+
id: toolId,
|
|
228
|
+
type: componentType
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (Array.isArray(agentData.canDelegateTo)) for (const delegateRelation of agentData.canDelegateTo) {
|
|
233
|
+
let targetId;
|
|
234
|
+
let targetType = "agents";
|
|
235
|
+
if (delegateRelation && typeof delegateRelation === "object") {
|
|
236
|
+
if (delegateRelation.externalAgentId) {
|
|
237
|
+
targetId = delegateRelation.externalAgentId;
|
|
238
|
+
targetType = "externalAgents";
|
|
239
|
+
} else if (delegateRelation.agentId) {
|
|
240
|
+
targetId = delegateRelation.agentId;
|
|
241
|
+
targetType = "agents";
|
|
242
|
+
} else if (delegateRelation.subAgentId) {
|
|
243
|
+
targetId = delegateRelation.subAgentId;
|
|
244
|
+
targetType = "subAgents";
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (targetId) referencedComponents.push({
|
|
248
|
+
id: targetId,
|
|
249
|
+
type: targetType
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (Array.isArray(agentData.canTransferTo)) {
|
|
253
|
+
for (const transferId of agentData.canTransferTo) if (typeof transferId === "string") referencedComponents.push({
|
|
254
|
+
id: transferId,
|
|
255
|
+
type: "subAgents"
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (Array.isArray(agentData.dataComponents)) {
|
|
259
|
+
for (const dataCompId of agentData.dataComponents) if (typeof dataCompId === "string") referencedComponents.push({
|
|
260
|
+
id: dataCompId,
|
|
261
|
+
type: "dataComponents"
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(agentData.artifactComponents)) {
|
|
265
|
+
for (const artifactCompId of agentData.artifactComponents) if (typeof artifactCompId === "string") referencedComponents.push({
|
|
266
|
+
id: artifactCompId,
|
|
267
|
+
type: "artifactComponents"
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (referencedComponents.length > 0) {
|
|
271
|
+
const componentImports = registry.getImportsForFile(currentFilePath, referencedComponents);
|
|
272
|
+
imports.push(...componentImports);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return imports;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Generate complete sub-agent file (imports + definition)
|
|
279
|
+
*/
|
|
280
|
+
function generateSubAgentFile(agentId, agentData, style = DEFAULT_STYLE, registry, parentAgentId, contextConfigData, parentModels, actualFilePath) {
|
|
281
|
+
return generateFileContent(generateSubAgentImports(agentId, agentData, style, registry, parentAgentId, contextConfigData, actualFilePath), [generateSubAgentDefinition(agentId, agentData, style, registry, parentAgentId, contextConfigData, parentModels)]);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
//#endregion
|
|
285
|
+
export { generateSubAgentDefinition, generateSubAgentFile, generateSubAgentImports };
|