@inkeep/agents-cli 0.58.10 → 0.58.12
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/agents-cli/package.js +3 -2
- package/dist/agents-cli/package.js.map +1 -0
- package/dist/api.js +7 -11
- package/dist/api.js.map +1 -0
- package/dist/commands/add-ui.js +2 -1
- package/dist/commands/add-ui.js.map +1 -0
- package/dist/commands/add.js +2 -1
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/config.js +2 -1
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/dev.js +2 -1
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/init.js +2 -1
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/list-agents.js +2 -1
- package/dist/commands/list-agents.js.map +1 -0
- package/dist/commands/login.js +2 -1
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.js +2 -1
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/profile.js +2 -1
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/pull-v4/component-parser.js +2 -1
- package/dist/commands/pull-v4/component-parser.js.map +1 -0
- package/dist/commands/pull-v4/component-registry.js +2 -1
- package/dist/commands/pull-v4/component-registry.js.map +1 -0
- package/dist/commands/pull-v4/generators/agent-generator.helpers.js +186 -0
- package/dist/commands/pull-v4/generators/agent-generator.helpers.js.map +1 -0
- package/dist/commands/pull-v4/generators/agent-generator.js +70 -209
- package/dist/commands/pull-v4/generators/agent-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/artifact-component-generator.js +13 -16
- package/dist/commands/pull-v4/generators/artifact-component-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/context-config-generator.js +38 -24
- package/dist/commands/pull-v4/generators/context-config-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/credential-generator.js +14 -10
- package/dist/commands/pull-v4/generators/credential-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/data-component-generator.js +10 -12
- package/dist/commands/pull-v4/generators/data-component-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/environment-generator.js +11 -91
- package/dist/commands/pull-v4/generators/environment-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/external-agent-generator.js +22 -39
- package/dist/commands/pull-v4/generators/external-agent-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/function-tool-generator.js +19 -31
- package/dist/commands/pull-v4/generators/function-tool-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js +30 -71
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/project-generator.js +64 -31
- package/dist/commands/pull-v4/generators/project-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/skill-generator.js +4 -1
- package/dist/commands/pull-v4/generators/skill-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/status-component-generator.js +19 -19
- package/dist/commands/pull-v4/generators/status-component-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/sub-agent-generator.helpers.js +84 -0
- package/dist/commands/pull-v4/generators/sub-agent-generator.helpers.js.map +1 -0
- package/dist/commands/pull-v4/generators/sub-agent-generator.js +82 -113
- package/dist/commands/pull-v4/generators/sub-agent-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/trigger-generator.js +21 -30
- package/dist/commands/pull-v4/generators/trigger-generator.js.map +1 -0
- package/dist/commands/pull-v4/introspect/demo-project.js +1616 -0
- package/dist/commands/pull-v4/introspect/demo-project.js.map +1 -0
- package/dist/commands/pull-v4/introspect/index.js +17 -16
- package/dist/commands/pull-v4/introspect/index.js.map +1 -0
- package/dist/commands/pull-v4/introspect/test-helpers.js +5 -3
- package/dist/commands/pull-v4/introspect/test-helpers.js.map +1 -0
- package/dist/commands/pull-v4/introspect-generator.js +606 -93
- package/dist/commands/pull-v4/introspect-generator.js.map +1 -0
- package/dist/commands/pull-v4/module-merge.js +2 -1
- package/dist/commands/pull-v4/module-merge.js.map +1 -0
- package/dist/commands/pull-v4/scheduled-trigger-generator.js +16 -17
- package/dist/commands/pull-v4/scheduled-trigger-generator.js.map +1 -0
- package/dist/commands/pull-v4/utils.js +90 -28
- package/dist/commands/pull-v4/utils.js.map +1 -0
- package/dist/commands/push.js +2 -1
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/status.js +2 -1
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/update.js +2 -1
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/whoami.js +2 -1
- package/dist/commands/whoami.js.map +1 -0
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -0
- package/dist/env.js +2 -1
- package/dist/env.js.map +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.js +2 -1
- package/dist/instrumentation.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/array.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/array.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/base.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/character.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/character.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/css.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/css.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/json.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/json.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/line.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/line.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/word.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/diff/word.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/patch/create.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/patch/create.js.map +1 -0
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/util/string.js +2 -1
- package/dist/node_modules/.pnpm/diff@8.0.3/node_modules/diff/libesm/util/string.js.map +1 -0
- package/dist/utils/background-version-check.js +2 -1
- package/dist/utils/background-version-check.js.map +1 -0
- package/dist/utils/ci-environment.js +2 -1
- package/dist/utils/ci-environment.js.map +1 -0
- package/dist/utils/cli-pipeline.js +2 -1
- package/dist/utils/cli-pipeline.js.map +1 -0
- package/dist/utils/config.js +2 -1
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/credentials.js +2 -1
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/environment-loader.js +2 -1
- package/dist/utils/environment-loader.js.map +1 -0
- package/dist/utils/file-finder.js +2 -1
- package/dist/utils/file-finder.js.map +1 -0
- package/dist/utils/json-comparator.js +2 -1
- package/dist/utils/json-comparator.js.map +1 -0
- package/dist/utils/json-comparison.js +2 -1
- package/dist/utils/json-comparison.js.map +1 -0
- package/dist/utils/mcp-runner.js +2 -1
- package/dist/utils/mcp-runner.js.map +1 -0
- package/dist/utils/model-config.js +2 -1
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/package-manager.js +2 -1
- package/dist/utils/package-manager.js.map +1 -0
- package/dist/utils/profile-config.js +2 -1
- package/dist/utils/profile-config.js.map +1 -0
- package/dist/utils/profiles/profile-manager.js +2 -1
- package/dist/utils/profiles/profile-manager.js.map +1 -0
- package/dist/utils/profiles/types.js +2 -1
- package/dist/utils/profiles/types.js.map +1 -0
- package/dist/utils/project-directory.js +2 -1
- package/dist/utils/project-directory.js.map +1 -0
- package/dist/utils/project-loader.js +2 -1
- package/dist/utils/project-loader.js.map +1 -0
- package/dist/utils/schema-introspection.js +2 -1
- package/dist/utils/schema-introspection.js.map +1 -0
- package/dist/utils/templates.js +2 -1
- package/dist/utils/templates.js.map +1 -0
- package/dist/utils/tsx-loader.js +2 -1
- package/dist/utils/tsx-loader.js.map +1 -0
- package/dist/utils/version-check.js +2 -1
- package/dist/utils/version-check.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import { buildComponentFileName, collectTemplateVariableNames, createInMemoryProject, isPlainObject, toCamelCase } from "./utils.js";
|
|
1
|
+
import { buildComponentFileName, collectTemplateVariableNames, createInMemoryProject, isHumanReadableId, isPlainObject, toCamelCase, toCredentialReferenceName, toKebabCase, toToolReferenceName } from "./utils.js";
|
|
2
2
|
import { buildComponentRegistryFromParsing } from "./component-parser.js";
|
|
3
3
|
import { generateAgentDefinition } from "./generators/agent-generator.js";
|
|
4
4
|
import { generateArtifactComponentDefinition } from "./generators/artifact-component-generator.js";
|
|
5
5
|
import { generateContextConfigDefinition } from "./generators/context-config-generator.js";
|
|
6
6
|
import { generateCredentialDefinition } from "./generators/credential-generator.js";
|
|
7
7
|
import { generateDataComponentDefinition } from "./generators/data-component-generator.js";
|
|
8
|
+
import { generateEnvironmentIndexDefinition, generateEnvironmentSettingsDefinition } from "./generators/environment-generator.js";
|
|
9
|
+
import { generateExternalAgentDefinition } from "./generators/external-agent-generator.js";
|
|
10
|
+
import { generateFunctionToolDefinition } from "./generators/function-tool-generator.js";
|
|
8
11
|
import { generateMcpToolDefinition } from "./generators/mcp-tool-generator.js";
|
|
9
12
|
import { generateProjectDefinition } from "./generators/project-generator.js";
|
|
10
13
|
import { generateStatusComponentDefinition } from "./generators/status-component-generator.js";
|
|
14
|
+
import { resolveSubAgentVariableName } from "./generators/sub-agent-generator.helpers.js";
|
|
11
15
|
import { generateSubAgentDefinition } from "./generators/sub-agent-generator.js";
|
|
12
16
|
import { generateTriggerDefinition } from "./generators/trigger-generator.js";
|
|
13
17
|
import { mergeGeneratedModule } from "./module-merge.js";
|
|
14
18
|
import { generateScheduledTriggerDefinition } from "./scheduled-trigger-generator.js";
|
|
15
|
-
import { dirname, join } from "node:path";
|
|
19
|
+
import { basename, dirname, join } from "node:path";
|
|
16
20
|
import { Node, SyntaxKind } from "ts-morph";
|
|
17
21
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
22
|
|
|
19
23
|
//#region src/commands/pull-v4/introspect-generator.ts
|
|
20
|
-
async function introspectGenerate({ project, paths, writeMode = "merge",
|
|
24
|
+
async function introspectGenerate({ project, paths, writeMode = "merge", debug = false }) {
|
|
21
25
|
validateProject(project);
|
|
22
26
|
const skippedAgents = [];
|
|
23
27
|
const context = {
|
|
@@ -27,7 +31,6 @@ async function introspectGenerate({ project, paths, writeMode = "merge", failOnU
|
|
|
27
31
|
existingComponentRegistry: writeMode === "merge" ? buildComponentRegistryFromParsing(paths.projectRoot, debug) : void 0
|
|
28
32
|
};
|
|
29
33
|
const tasks = createGenerationTasks();
|
|
30
|
-
const failures = [];
|
|
31
34
|
const generatedFiles = [];
|
|
32
35
|
for (const task of tasks) {
|
|
33
36
|
const records = task.collect(context);
|
|
@@ -37,13 +40,9 @@ async function introspectGenerate({ project, paths, writeMode = "merge", failOnU
|
|
|
37
40
|
generatedFiles.push(record.filePath);
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
const unsupportedCounts = collectUnsupportedComponentCounts(project);
|
|
41
|
-
if (failOnUnsupportedComponents && hasUnsupportedComponents(unsupportedCounts)) failures.push(formatUnsupportedComponentsError(unsupportedCounts));
|
|
42
|
-
if (failures.length > 0) throw new Error(`Inkeep Pull failed:\n${failures.join("\n")}`);
|
|
43
43
|
if (debug) {
|
|
44
44
|
console.log(`Generated ${generatedFiles.length} files`);
|
|
45
|
-
if (skippedAgents.length
|
|
46
|
-
if (hasUnsupportedComponents(unsupportedCounts)) console.log(formatUnsupportedComponentsWarning(unsupportedCounts));
|
|
45
|
+
if (skippedAgents.length) console.log(`Skipped ${skippedAgents.length} agent(s): ${skippedAgents.map((agent) => `${agent.id} (${agent.reason})`).join(", ")}`);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
function createGenerationTasks() {
|
|
@@ -53,6 +52,16 @@ function createGenerationTasks() {
|
|
|
53
52
|
collect: collectCredentialRecords,
|
|
54
53
|
generate: generateCredentialDefinition
|
|
55
54
|
},
|
|
55
|
+
{
|
|
56
|
+
type: "environment-settings",
|
|
57
|
+
collect: collectEnvironmentSettingsRecords,
|
|
58
|
+
generate: generateEnvironmentSettingsRecord
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "environment-index",
|
|
62
|
+
collect: collectEnvironmentIndexRecords,
|
|
63
|
+
generate: generateEnvironmentIndexDefinition
|
|
64
|
+
},
|
|
56
65
|
{
|
|
57
66
|
type: "artifact-component",
|
|
58
67
|
collect: collectArtifactComponentRecords,
|
|
@@ -63,11 +72,21 @@ function createGenerationTasks() {
|
|
|
63
72
|
collect: collectDataComponentRecords,
|
|
64
73
|
generate: generateDataComponentDefinition
|
|
65
74
|
},
|
|
75
|
+
{
|
|
76
|
+
type: "function-tool",
|
|
77
|
+
collect: collectFunctionToolRecords,
|
|
78
|
+
generate: generateFunctionToolDefinition
|
|
79
|
+
},
|
|
66
80
|
{
|
|
67
81
|
type: "tool",
|
|
68
82
|
collect: collectToolRecords,
|
|
69
83
|
generate: generateMcpToolDefinition
|
|
70
84
|
},
|
|
85
|
+
{
|
|
86
|
+
type: "external-agent",
|
|
87
|
+
collect: collectExternalAgentRecords,
|
|
88
|
+
generate: generateExternalAgentDefinition
|
|
89
|
+
},
|
|
71
90
|
{
|
|
72
91
|
type: "context-config",
|
|
73
92
|
collect: collectContextConfigRecords,
|
|
@@ -107,15 +126,49 @@ function createGenerationTasks() {
|
|
|
107
126
|
}
|
|
108
127
|
function collectCredentialRecords(context) {
|
|
109
128
|
if (!context.project.credentialReferences) return [];
|
|
110
|
-
|
|
129
|
+
const credentialEntries = Object.entries(context.project.credentialReferences);
|
|
130
|
+
const fileNamesByCredentialId = buildSequentialNameFileNames(credentialEntries);
|
|
131
|
+
return credentialEntries.map(([credentialId, credentialData]) => ({
|
|
111
132
|
id: credentialId,
|
|
112
|
-
filePath: resolveRecordFilePath(context, "credentials", credentialId, join(context.paths.credentialsDir,
|
|
133
|
+
filePath: resolveRecordFilePath(context, "credentials", credentialId, join(context.paths.credentialsDir, fileNamesByCredentialId[credentialId])),
|
|
113
134
|
payload: {
|
|
114
135
|
credentialId,
|
|
115
136
|
...credentialData
|
|
116
137
|
}
|
|
117
138
|
}));
|
|
118
139
|
}
|
|
140
|
+
function collectEnvironmentSettingsRecords(context) {
|
|
141
|
+
const credentialReferenceIds = collectEnvironmentCredentialReferenceIds(context.project);
|
|
142
|
+
if (credentialReferenceIds.length === 0) return [];
|
|
143
|
+
const credentialsById = {};
|
|
144
|
+
for (const credentialReferenceId of credentialReferenceIds) {
|
|
145
|
+
const credentialData = context.project.credentialReferences?.[credentialReferenceId];
|
|
146
|
+
if (isPlainObject(credentialData)) {
|
|
147
|
+
credentialsById[credentialReferenceId] = {
|
|
148
|
+
...credentialData,
|
|
149
|
+
id: credentialReferenceId
|
|
150
|
+
};
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
credentialsById[credentialReferenceId] = { id: credentialReferenceId };
|
|
154
|
+
}
|
|
155
|
+
return [{
|
|
156
|
+
id: "development",
|
|
157
|
+
filePath: resolveRecordFilePath(context, "environments", "development", join(context.paths.environmentsDir, "development.env.ts")),
|
|
158
|
+
payload: { credentials: credentialsById }
|
|
159
|
+
}];
|
|
160
|
+
}
|
|
161
|
+
function collectEnvironmentIndexRecords(context) {
|
|
162
|
+
if (collectEnvironmentCredentialReferenceIds(context.project).length === 0) return [];
|
|
163
|
+
return [{
|
|
164
|
+
id: "index",
|
|
165
|
+
filePath: resolveRecordFilePath(context, "environments", "index", join(context.paths.environmentsDir, "index.ts")),
|
|
166
|
+
payload: ["development"]
|
|
167
|
+
}];
|
|
168
|
+
}
|
|
169
|
+
function generateEnvironmentSettingsRecord(payload) {
|
|
170
|
+
return generateEnvironmentSettingsDefinition("development", payload);
|
|
171
|
+
}
|
|
119
172
|
function collectArtifactComponentRecords(context) {
|
|
120
173
|
if (!context.project.artifactComponents) return [];
|
|
121
174
|
return Object.entries(context.project.artifactComponents).map(([artifactComponentId, artifactComponentData]) => ({
|
|
@@ -128,15 +181,45 @@ function collectArtifactComponentRecords(context) {
|
|
|
128
181
|
}));
|
|
129
182
|
}
|
|
130
183
|
function collectDataComponentRecords(context) {
|
|
131
|
-
|
|
132
|
-
|
|
184
|
+
const recordsByDataComponentId = /* @__PURE__ */ new Map();
|
|
185
|
+
for (const [dataComponentId, dataComponent] of Object.entries(context.project.dataComponents ?? {})) recordsByDataComponentId.set(dataComponentId, {
|
|
133
186
|
id: dataComponentId,
|
|
134
187
|
filePath: resolveRecordFilePath(context, "dataComponents", dataComponentId, join(context.paths.dataComponentsDir, buildComponentFileName(dataComponentId, dataComponent.name ?? void 0))),
|
|
135
188
|
payload: {
|
|
136
189
|
dataComponentId,
|
|
137
190
|
...dataComponent
|
|
138
191
|
}
|
|
139
|
-
})
|
|
192
|
+
});
|
|
193
|
+
for (const dataComponentId of collectReferencedSubAgentComponentIds(context, "dataComponents")) {
|
|
194
|
+
if (recordsByDataComponentId.has(dataComponentId)) continue;
|
|
195
|
+
recordsByDataComponentId.set(dataComponentId, {
|
|
196
|
+
id: dataComponentId,
|
|
197
|
+
filePath: resolveRecordFilePath(context, "dataComponents", dataComponentId, join(context.paths.dataComponentsDir, `${dataComponentId}.ts`)),
|
|
198
|
+
payload: {
|
|
199
|
+
dataComponentId,
|
|
200
|
+
name: dataComponentId,
|
|
201
|
+
props: {
|
|
202
|
+
type: "object",
|
|
203
|
+
properties: {}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return [...recordsByDataComponentId.values()];
|
|
209
|
+
}
|
|
210
|
+
function collectReferencedSubAgentComponentIds(context, componentProperty) {
|
|
211
|
+
const componentIds = /* @__PURE__ */ new Set();
|
|
212
|
+
for (const agentId of context.completeAgentIds) {
|
|
213
|
+
const agentData = context.project.agents?.[agentId];
|
|
214
|
+
const subAgents = asRecord(agentData?.subAgents);
|
|
215
|
+
if (!subAgents) continue;
|
|
216
|
+
for (const subAgentData of Object.values(subAgents)) {
|
|
217
|
+
const subAgentRecord = asRecord(subAgentData);
|
|
218
|
+
if (!subAgentRecord) continue;
|
|
219
|
+
for (const componentId of extractReferenceIds(subAgentRecord[componentProperty])) componentIds.add(componentId);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return [...componentIds];
|
|
140
223
|
}
|
|
141
224
|
function collectContextConfigRecords(context) {
|
|
142
225
|
if (!context.project.agents) return [];
|
|
@@ -151,6 +234,7 @@ function collectContextConfigRecords(context) {
|
|
|
151
234
|
if (!contextConfigRecordsById.has(contextConfigId)) {
|
|
152
235
|
const contextConfigFilePath = resolveRecordFilePath(context, "contextConfigs", contextConfigId, join(context.paths.contextConfigsDir, `${contextConfigId}.ts`));
|
|
153
236
|
const credentialReferenceOverrides = collectContextConfigCredentialReferenceOverrides(context, normalizedContextConfig);
|
|
237
|
+
const credentialReferencePathOverrides = collectContextConfigCredentialReferencePathOverrides(context, normalizedContextConfig);
|
|
154
238
|
const headersReferenceOverride = collectContextConfigHeadersReferenceOverride(context, contextConfigId, contextConfigFilePath);
|
|
155
239
|
contextConfigRecordsById.set(contextConfigId, {
|
|
156
240
|
id: contextConfigId,
|
|
@@ -158,39 +242,166 @@ function collectContextConfigRecords(context) {
|
|
|
158
242
|
payload: {
|
|
159
243
|
contextConfigId,
|
|
160
244
|
...normalizedContextConfig,
|
|
161
|
-
...headersReferenceOverride && {
|
|
162
|
-
...credentialReferenceOverrides && { referenceOverrides: { credentialReferences: credentialReferenceOverrides } }
|
|
245
|
+
...headersReferenceOverride && { headersReference: headersReferenceOverride },
|
|
246
|
+
...credentialReferenceOverrides && { referenceOverrides: { credentialReferences: credentialReferenceOverrides } },
|
|
247
|
+
...credentialReferencePathOverrides && { referencePathOverrides: { credentialReferences: credentialReferencePathOverrides } }
|
|
163
248
|
}
|
|
164
249
|
});
|
|
165
250
|
}
|
|
166
251
|
}
|
|
167
252
|
return [...contextConfigRecordsById.values()];
|
|
168
253
|
}
|
|
254
|
+
function collectFunctionToolRecords(context) {
|
|
255
|
+
const functionToolEntries = collectFunctionToolEntries(context.project);
|
|
256
|
+
if (!functionToolEntries.length) return [];
|
|
257
|
+
const fileNamesByFunctionToolId = buildSequentialNameFileNames(functionToolEntries.map(({ functionToolId, fileName }) => [functionToolId, { name: fileName }]));
|
|
258
|
+
return functionToolEntries.map(({ functionToolId, functionToolData, functionData }) => {
|
|
259
|
+
const modulePath = stripExtension(fileNamesByFunctionToolId[functionToolId]);
|
|
260
|
+
const functionToolName = typeof functionToolData.name === "string" && functionToolData.name.length > 0 ? functionToolData.name : typeof functionData.name === "string" && functionData.name.length > 0 ? functionData.name : void 0;
|
|
261
|
+
const functionToolDescription = typeof functionToolData.description === "string" ? functionToolData.description : typeof functionData.description === "string" ? functionData.description : void 0;
|
|
262
|
+
return {
|
|
263
|
+
id: functionToolId,
|
|
264
|
+
filePath: resolveRecordFilePath(context, "functionTools", functionToolId, join(context.paths.toolsDir, `${modulePath}.ts`)),
|
|
265
|
+
payload: {
|
|
266
|
+
functionToolId,
|
|
267
|
+
...functionToolName && { name: functionToolName },
|
|
268
|
+
...functionToolDescription !== void 0 && { description: functionToolDescription },
|
|
269
|
+
...functionData.inputSchema !== void 0 && { inputSchema: functionData.inputSchema },
|
|
270
|
+
...functionData.schema !== void 0 && { schema: functionData.schema },
|
|
271
|
+
...functionData.executeCode !== void 0 && { executeCode: functionData.executeCode },
|
|
272
|
+
...functionData.dependencies !== void 0 && { dependencies: functionData.dependencies }
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function collectFunctionToolEntries(project) {
|
|
278
|
+
const functionToolsById = collectFunctionToolsById(project);
|
|
279
|
+
const functionsById = collectFunctionsById(project);
|
|
280
|
+
const entries = [];
|
|
281
|
+
for (const [functionToolId, functionToolData] of Object.entries(functionToolsById)) {
|
|
282
|
+
const functionId = typeof functionToolData.functionId === "string" && functionToolData.functionId.length > 0 ? functionToolData.functionId : functionToolId;
|
|
283
|
+
const functionData = functionsById[functionId] ?? {};
|
|
284
|
+
const functionToolName = typeof functionToolData.name === "string" && functionToolData.name.length > 0 ? functionToolData.name : void 0;
|
|
285
|
+
const functionName = typeof functionData.name === "string" && functionData.name.length > 0 ? functionData.name : void 0;
|
|
286
|
+
const fallbackName = functionToolName ?? functionName ?? functionToolId;
|
|
287
|
+
entries.push({
|
|
288
|
+
functionToolId,
|
|
289
|
+
functionId,
|
|
290
|
+
functionToolData,
|
|
291
|
+
functionData,
|
|
292
|
+
exportName: fallbackName,
|
|
293
|
+
fileName: fallbackName
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return entries;
|
|
297
|
+
}
|
|
298
|
+
function collectFunctionToolsById(project) {
|
|
299
|
+
const functionToolsById = {};
|
|
300
|
+
for (const [functionToolId, functionToolData] of Object.entries(project.functionTools ?? {})) {
|
|
301
|
+
const functionToolRecord = asRecord(functionToolData);
|
|
302
|
+
if (!functionToolRecord) continue;
|
|
303
|
+
functionToolsById[functionToolId] = { ...functionToolRecord };
|
|
304
|
+
}
|
|
305
|
+
for (const agentData of Object.values(project.agents ?? {})) {
|
|
306
|
+
const agentFunctionTools = asRecord(asRecord(agentData)?.functionTools);
|
|
307
|
+
if (!agentFunctionTools) continue;
|
|
308
|
+
for (const [functionToolId, functionToolData] of Object.entries(agentFunctionTools)) {
|
|
309
|
+
const functionToolRecord = asRecord(functionToolData);
|
|
310
|
+
if (!functionToolRecord) continue;
|
|
311
|
+
const existingFunctionTool = functionToolsById[functionToolId] ?? {};
|
|
312
|
+
functionToolsById[functionToolId] = {
|
|
313
|
+
...functionToolRecord,
|
|
314
|
+
...existingFunctionTool
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return functionToolsById;
|
|
319
|
+
}
|
|
320
|
+
function collectFunctionsById(project) {
|
|
321
|
+
const functionsById = {};
|
|
322
|
+
for (const [functionId, functionData] of Object.entries(project.functions ?? {})) {
|
|
323
|
+
const functionRecord = asRecord(functionData);
|
|
324
|
+
if (!functionRecord) continue;
|
|
325
|
+
functionsById[functionId] = { ...functionRecord };
|
|
326
|
+
}
|
|
327
|
+
for (const agentData of Object.values(project.agents ?? {})) {
|
|
328
|
+
const agentFunctions = asRecord(asRecord(agentData)?.functions);
|
|
329
|
+
if (!agentFunctions) continue;
|
|
330
|
+
for (const [functionId, functionData] of Object.entries(agentFunctions)) {
|
|
331
|
+
const functionRecord = asRecord(functionData);
|
|
332
|
+
if (!functionRecord) continue;
|
|
333
|
+
const existingFunction = functionsById[functionId] ?? {};
|
|
334
|
+
functionsById[functionId] = {
|
|
335
|
+
...functionRecord,
|
|
336
|
+
...existingFunction
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return functionsById;
|
|
341
|
+
}
|
|
169
342
|
function collectToolRecords(context) {
|
|
170
|
-
|
|
343
|
+
const toolEntries = Object.entries(context.project.tools ?? {});
|
|
344
|
+
const fileNamesByToolId = buildSequentialNameFileNames(toolEntries);
|
|
345
|
+
return toolEntries.map(([toolId, toolData]) => ({
|
|
171
346
|
id: toolId,
|
|
172
|
-
filePath: resolveRecordFilePath(context, "tools", toolId, join(context.paths.toolsDir,
|
|
347
|
+
filePath: resolveRecordFilePath(context, "tools", toolId, join(context.paths.toolsDir, fileNamesByToolId[toolId])),
|
|
173
348
|
payload: {
|
|
174
349
|
mcpToolId: toolId,
|
|
175
350
|
...toolData
|
|
176
351
|
}
|
|
177
352
|
}));
|
|
178
353
|
}
|
|
354
|
+
function collectExternalAgentRecords(context) {
|
|
355
|
+
const externalAgentEntries = Object.entries(context.project.externalAgents ?? {});
|
|
356
|
+
const fileNamesByExternalAgentId = buildSequentialNameFileNames(externalAgentEntries.map(([externalAgentId, externalAgentData]) => [externalAgentId, { name: resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) }]));
|
|
357
|
+
const referenceNamesByExternalAgentId = buildExternalAgentReferenceNamesById(context.project);
|
|
358
|
+
return externalAgentEntries.map(([externalAgentId, externalAgentData]) => {
|
|
359
|
+
const externalAgentRecord = asRecord(externalAgentData) ?? {};
|
|
360
|
+
return {
|
|
361
|
+
id: externalAgentId,
|
|
362
|
+
filePath: resolveRecordFilePath(context, "externalAgents", externalAgentId, join(context.paths.externalAgentsDir, fileNamesByExternalAgentId[externalAgentId])),
|
|
363
|
+
payload: {
|
|
364
|
+
externalAgentId,
|
|
365
|
+
externalAgentReferenceName: referenceNamesByExternalAgentId[externalAgentId],
|
|
366
|
+
...externalAgentRecord
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
}
|
|
179
371
|
function collectContextConfigCredentialReferenceOverrides(context, contextConfigData) {
|
|
180
|
-
const registry = context.existingComponentRegistry;
|
|
181
|
-
if (!registry) return;
|
|
182
372
|
const contextVariables = asRecord(contextConfigData.contextVariables);
|
|
183
373
|
if (!contextVariables) return;
|
|
374
|
+
const credentialReferenceNamesById = buildCredentialReferenceNamesById(context.project);
|
|
375
|
+
const registry = context.existingComponentRegistry;
|
|
184
376
|
const overrides = {};
|
|
185
377
|
for (const contextVariable of Object.values(contextVariables)) {
|
|
186
378
|
const contextVariableRecord = asRecord(contextVariable);
|
|
187
379
|
const credentialReferenceId = contextVariableRecord && typeof contextVariableRecord.credentialReferenceId === "string" ? contextVariableRecord.credentialReferenceId : void 0;
|
|
188
380
|
if (!credentialReferenceId) continue;
|
|
189
|
-
const
|
|
381
|
+
const credentialReferenceName = credentialReferenceNamesById[credentialReferenceId];
|
|
382
|
+
if (credentialReferenceName) overrides[credentialReferenceId] = credentialReferenceName;
|
|
383
|
+
const existingCredential = registry?.get(credentialReferenceId, "credentials");
|
|
190
384
|
if (existingCredential?.name) overrides[credentialReferenceId] = existingCredential.name;
|
|
191
385
|
}
|
|
192
386
|
return Object.keys(overrides).length ? overrides : void 0;
|
|
193
387
|
}
|
|
388
|
+
function collectContextConfigCredentialReferencePathOverrides(context, contextConfigData) {
|
|
389
|
+
const contextVariables = asRecord(contextConfigData.contextVariables);
|
|
390
|
+
if (!contextVariables) return;
|
|
391
|
+
const credentialReferencePathById = buildCredentialReferencePathById(context.project);
|
|
392
|
+
const registry = context.existingComponentRegistry;
|
|
393
|
+
const overrides = {};
|
|
394
|
+
for (const contextVariable of Object.values(contextVariables)) {
|
|
395
|
+
const contextVariableRecord = asRecord(contextVariable);
|
|
396
|
+
const credentialReferenceId = contextVariableRecord && typeof contextVariableRecord.credentialReferenceId === "string" ? contextVariableRecord.credentialReferenceId : void 0;
|
|
397
|
+
if (!credentialReferenceId) continue;
|
|
398
|
+
const credentialReferencePath = credentialReferencePathById[credentialReferenceId];
|
|
399
|
+
if (credentialReferencePath) overrides[credentialReferenceId] = credentialReferencePath;
|
|
400
|
+
const existingCredential = registry?.get(credentialReferenceId, "credentials");
|
|
401
|
+
if (existingCredential?.filePath) overrides[credentialReferenceId] = stripExtension(basename(existingCredential.filePath));
|
|
402
|
+
}
|
|
403
|
+
return Object.keys(overrides).length ? overrides : void 0;
|
|
404
|
+
}
|
|
194
405
|
function collectContextConfigHeadersReferenceOverride(context, contextConfigId, filePath) {
|
|
195
406
|
if (!context.existingComponentRegistry || !existsSync(filePath)) return;
|
|
196
407
|
const sourceFile = createInMemoryProject().createSourceFile("existing-context-config.ts", readFileSync(filePath, "utf8"), { overwrite: true });
|
|
@@ -222,18 +433,35 @@ function collectContextConfigHeadersReferenceOverride(context, contextConfigId,
|
|
|
222
433
|
}
|
|
223
434
|
function collectTriggerRecords(context) {
|
|
224
435
|
if (!context.project.agents) return [];
|
|
436
|
+
const credentialReferenceNamesById = buildCredentialReferenceNamesById(context.project);
|
|
437
|
+
const credentialReferencePathsById = buildCredentialReferencePathById(context.project);
|
|
225
438
|
const records = [];
|
|
226
439
|
for (const agentId of context.completeAgentIds) {
|
|
227
440
|
const agentData = context.project.agents[agentId];
|
|
228
441
|
if (!agentData?.triggers) continue;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
442
|
+
const triggerEntries = Object.entries(agentData.triggers);
|
|
443
|
+
const fileNamesByTriggerId = buildSequentialNameFileNames(triggerEntries);
|
|
444
|
+
for (const [triggerId, triggerData] of triggerEntries) {
|
|
445
|
+
const triggerRecord = asRecord(triggerData);
|
|
446
|
+
const signingSecretCredentialReferenceId = typeof triggerRecord?.signingSecretCredentialReferenceId === "string" ? triggerRecord.signingSecretCredentialReferenceId : void 0;
|
|
447
|
+
let signingSecretCredentialReferenceName = signingSecretCredentialReferenceId ? credentialReferenceNamesById[signingSecretCredentialReferenceId] : void 0;
|
|
448
|
+
let signingSecretCredentialReferencePath = signingSecretCredentialReferenceId ? credentialReferencePathsById[signingSecretCredentialReferenceId] : void 0;
|
|
449
|
+
if (signingSecretCredentialReferenceId && context.existingComponentRegistry) {
|
|
450
|
+
const existingCredential = context.existingComponentRegistry.get(signingSecretCredentialReferenceId, "credentials");
|
|
451
|
+
if (existingCredential?.name) signingSecretCredentialReferenceName = existingCredential.name;
|
|
452
|
+
if (existingCredential?.filePath) signingSecretCredentialReferencePath = stripExtension(basename(existingCredential.filePath));
|
|
235
453
|
}
|
|
236
|
-
|
|
454
|
+
records.push({
|
|
455
|
+
id: triggerId,
|
|
456
|
+
filePath: resolveRecordFilePath(context, "triggers", triggerId, join(context.paths.agentsDir, "triggers", fileNamesByTriggerId[triggerId])),
|
|
457
|
+
payload: {
|
|
458
|
+
triggerId,
|
|
459
|
+
...triggerData,
|
|
460
|
+
...signingSecretCredentialReferenceName && { signingSecretCredentialReferenceName },
|
|
461
|
+
...signingSecretCredentialReferencePath && { signingSecretCredentialReferencePath }
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
237
465
|
}
|
|
238
466
|
return records;
|
|
239
467
|
}
|
|
@@ -243,9 +471,10 @@ function collectScheduledTriggerRecords(context) {
|
|
|
243
471
|
for (const agentId of context.completeAgentIds) {
|
|
244
472
|
const agentData = context.project.agents[agentId];
|
|
245
473
|
if (!agentData?.scheduledTriggers) continue;
|
|
474
|
+
const fileNamesByScheduledTriggerId = buildSequentialNameFileNames(Object.entries(agentData.scheduledTriggers));
|
|
246
475
|
for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(agentData.scheduledTriggers)) records.push({
|
|
247
476
|
id: scheduledTriggerId,
|
|
248
|
-
filePath: resolveRecordFilePath(context, "scheduledTriggers", scheduledTriggerId, join(context.paths.agentsDir, "scheduled-triggers",
|
|
477
|
+
filePath: resolveRecordFilePath(context, "scheduledTriggers", scheduledTriggerId, join(context.paths.agentsDir, "scheduled-triggers", fileNamesByScheduledTriggerId[scheduledTriggerId])),
|
|
249
478
|
payload: {
|
|
250
479
|
scheduledTriggerId,
|
|
251
480
|
...scheduledTriggerData
|
|
@@ -264,6 +493,7 @@ function collectAgentRecords(context) {
|
|
|
264
493
|
const agentFilePath = resolveRecordFilePath(context, "agents", agentId, join(context.paths.agentsDir, buildComponentFileName(agentId, agentName)));
|
|
265
494
|
const existingAgent = context.existingComponentRegistry?.get(agentId, "agents");
|
|
266
495
|
const subAgentReferences = collectSubAgentReferenceOverrides(context, agentData, agentFilePath);
|
|
496
|
+
const subAgentReferencePathOverrides = collectSubAgentReferencePathOverrides(context, agentData);
|
|
267
497
|
const statusUpdates = asRecord(agentData.statusUpdates);
|
|
268
498
|
const contextTemplateReferences = collectContextTemplateReferences(context, agentData, agentFilePath, [typeof agentData.prompt === "string" ? agentData.prompt : void 0, typeof statusUpdates?.prompt === "string" ? statusUpdates.prompt : void 0]);
|
|
269
499
|
records.push({
|
|
@@ -273,7 +503,8 @@ function collectAgentRecords(context) {
|
|
|
273
503
|
agentId,
|
|
274
504
|
...agentData,
|
|
275
505
|
...existingAgent?.name?.length && { agentVariableName: existingAgent.name },
|
|
276
|
-
...Object.keys(subAgentReferences).length
|
|
506
|
+
...Object.keys(subAgentReferences).length && { subAgentReferences },
|
|
507
|
+
...Object.keys(subAgentReferencePathOverrides).length && { subAgentReferencePathOverrides },
|
|
277
508
|
...contextTemplateReferences && { contextConfigReference: contextTemplateReferences.contextConfigReference },
|
|
278
509
|
...contextTemplateReferences?.contextConfigHeadersReference && { contextConfigHeadersReference: contextTemplateReferences.contextConfigHeadersReference }
|
|
279
510
|
}
|
|
@@ -281,9 +512,24 @@ function collectAgentRecords(context) {
|
|
|
281
512
|
}
|
|
282
513
|
return records;
|
|
283
514
|
}
|
|
515
|
+
function collectSubAgentReferencePathOverrides(context, agentData) {
|
|
516
|
+
const generatedSubAgentReferencePathById = buildSubAgentReferencePathById(context.project, context.completeAgentIds);
|
|
517
|
+
const subAgentIds = new Set(extractReferenceIds(agentData.subAgents));
|
|
518
|
+
if (typeof agentData.defaultSubAgentId === "string" && agentData.defaultSubAgentId.length > 0) subAgentIds.add(agentData.defaultSubAgentId);
|
|
519
|
+
if (!subAgentIds.size) return {};
|
|
520
|
+
const subAgents = asRecord(agentData.subAgents);
|
|
521
|
+
const overrides = {};
|
|
522
|
+
for (const subAgentId of subAgentIds) {
|
|
523
|
+
const fallbackReferencePath = generatedSubAgentReferencePathById[subAgentId];
|
|
524
|
+
const subAgentData = asRecord(subAgents?.[subAgentId]);
|
|
525
|
+
const subAgentName = typeof subAgentData?.name === "string" ? subAgentData.name : void 0;
|
|
526
|
+
overrides[subAgentId] = stripExtension(basename(resolveRecordFilePath(context, "subAgents", subAgentId, join(context.paths.agentsDir, "sub-agents", fallbackReferencePath ? `${fallbackReferencePath}.ts` : buildComponentFileName(subAgentId, subAgentName)))));
|
|
527
|
+
}
|
|
528
|
+
return overrides;
|
|
529
|
+
}
|
|
284
530
|
function collectSubAgentRecords(context) {
|
|
285
531
|
if (!context.project.agents) return [];
|
|
286
|
-
const
|
|
532
|
+
const recordsBySubAgentId = /* @__PURE__ */ new Map();
|
|
287
533
|
for (const agentId of context.completeAgentIds) {
|
|
288
534
|
const agentData = context.project.agents[agentId];
|
|
289
535
|
const subAgents = asRecord(agentData?.subAgents);
|
|
@@ -291,17 +537,18 @@ function collectSubAgentRecords(context) {
|
|
|
291
537
|
for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {
|
|
292
538
|
const payload = asRecord(subAgentData);
|
|
293
539
|
if (!payload) continue;
|
|
294
|
-
const
|
|
540
|
+
const dependencyReferences = collectSubAgentDependencyReferenceOverrides(context, payload);
|
|
295
541
|
const subAgentName = typeof payload.name === "string" ? payload.name : void 0;
|
|
296
542
|
const subAgentFilePath = resolveRecordFilePath(context, "subAgents", subAgentId, join(context.paths.agentsDir, "sub-agents", buildComponentFileName(subAgentId, subAgentName)));
|
|
297
543
|
const contextTemplateReferences = collectContextTemplateReferences(context, agentData, subAgentFilePath, [typeof payload.prompt === "string" ? payload.prompt : void 0]);
|
|
298
|
-
|
|
544
|
+
recordsBySubAgentId.set(subAgentId, {
|
|
299
545
|
id: subAgentId,
|
|
300
546
|
filePath: subAgentFilePath,
|
|
301
547
|
payload: {
|
|
302
548
|
subAgentId,
|
|
303
549
|
...payload,
|
|
304
|
-
...referenceOverrides && { referenceOverrides },
|
|
550
|
+
...dependencyReferences?.referenceOverrides && { referenceOverrides: dependencyReferences.referenceOverrides },
|
|
551
|
+
...dependencyReferences?.referencePathOverrides && { referencePathOverrides: dependencyReferences.referencePathOverrides },
|
|
305
552
|
...contextTemplateReferences && {
|
|
306
553
|
contextConfigId: contextTemplateReferences.contextConfigId,
|
|
307
554
|
contextConfigReference: contextTemplateReferences.contextConfigReference
|
|
@@ -311,7 +558,7 @@ function collectSubAgentRecords(context) {
|
|
|
311
558
|
});
|
|
312
559
|
}
|
|
313
560
|
}
|
|
314
|
-
return
|
|
561
|
+
return [...recordsBySubAgentId.values()];
|
|
315
562
|
}
|
|
316
563
|
function collectStatusComponentRecords(context) {
|
|
317
564
|
if (!context.project.agents) return [];
|
|
@@ -340,6 +587,7 @@ function collectStatusComponentRecords(context) {
|
|
|
340
587
|
}
|
|
341
588
|
function collectProjectRecord(context) {
|
|
342
589
|
const referenceOverrides = collectProjectReferenceOverrides(context);
|
|
590
|
+
const referencePathOverrides = collectProjectReferencePathOverrides(context);
|
|
343
591
|
return [{
|
|
344
592
|
id: context.project.id,
|
|
345
593
|
filePath: resolveRecordFilePath(context, "project", context.project.id, join(context.paths.projectRoot, "index.ts")),
|
|
@@ -356,7 +604,8 @@ function collectProjectRecord(context) {
|
|
|
356
604
|
dataComponents: getObjectKeys(context.project.dataComponents),
|
|
357
605
|
artifactComponents: getObjectKeys(context.project.artifactComponents),
|
|
358
606
|
credentialReferences: getObjectKeys(context.project.credentialReferences),
|
|
359
|
-
...referenceOverrides && { referenceOverrides }
|
|
607
|
+
...referenceOverrides && { referenceOverrides },
|
|
608
|
+
...referencePathOverrides && { referencePathOverrides }
|
|
360
609
|
}
|
|
361
610
|
}];
|
|
362
611
|
}
|
|
@@ -400,24 +649,15 @@ function isAgentComplete(agentData) {
|
|
|
400
649
|
};
|
|
401
650
|
return { complete: true };
|
|
402
651
|
}
|
|
403
|
-
function
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
function formatUnsupportedComponentsError(counts) {
|
|
414
|
-
return `Unsupported components for v4 introspect: ${formatUnsupportedCounts(counts)}`;
|
|
415
|
-
}
|
|
416
|
-
function formatUnsupportedComponentsWarning(counts) {
|
|
417
|
-
return `Skipped unsupported components for v4 introspect: ${formatUnsupportedCounts(counts)}`;
|
|
418
|
-
}
|
|
419
|
-
function formatUnsupportedCounts(counts) {
|
|
420
|
-
return Object.entries(counts).filter(([, value]) => value > 0).map(([name, value]) => `${name}=${value}`).join(", ");
|
|
652
|
+
function collectEnvironmentCredentialReferenceIds(project) {
|
|
653
|
+
const credentialReferenceIds = /* @__PURE__ */ new Set();
|
|
654
|
+
for (const toolData of Object.values(project.tools ?? {})) {
|
|
655
|
+
const toolRecord = asRecord(toolData);
|
|
656
|
+
const credentialReferenceId = toolRecord && typeof toolRecord.credentialReferenceId === "string" ? toolRecord.credentialReferenceId : void 0;
|
|
657
|
+
const hasInlineCredential = toolRecord?.credential !== void 0 && toolRecord?.credential !== null;
|
|
658
|
+
if (credentialReferenceId && !hasInlineCredential) credentialReferenceIds.add(credentialReferenceId);
|
|
659
|
+
}
|
|
660
|
+
return [...credentialReferenceIds];
|
|
421
661
|
}
|
|
422
662
|
function getObjectKeys(value) {
|
|
423
663
|
const record = asRecord(value);
|
|
@@ -434,11 +674,16 @@ function asRecord(value) {
|
|
|
434
674
|
return value;
|
|
435
675
|
}
|
|
436
676
|
function collectSubAgentReferenceOverrides(context, agentData, agentFilePath) {
|
|
677
|
+
const generatedSubAgentReferenceNamesById = buildSubAgentReferenceNamesById(context.project, context.completeAgentIds);
|
|
437
678
|
const subAgentIds = new Set(extractReferenceIds(agentData.subAgents));
|
|
438
679
|
if (typeof agentData.defaultSubAgentId === "string" && agentData.defaultSubAgentId.length > 0) subAgentIds.add(agentData.defaultSubAgentId);
|
|
439
680
|
if (!subAgentIds.size) return {};
|
|
681
|
+
const subAgents = asRecord(agentData.subAgents);
|
|
440
682
|
const overrides = {};
|
|
441
683
|
for (const subAgentId of subAgentIds) {
|
|
684
|
+
const subAgentData = asRecord(subAgents?.[subAgentId]);
|
|
685
|
+
const subAgentName = typeof subAgentData?.name === "string" ? subAgentData.name : void 0;
|
|
686
|
+
overrides[subAgentId] = { name: generatedSubAgentReferenceNamesById[subAgentId] ?? resolveSubAgentVariableName(subAgentId, subAgentName) };
|
|
442
687
|
const existingSubAgent = context.existingComponentRegistry?.get(subAgentId, "subAgents");
|
|
443
688
|
if (!existingSubAgent?.name) continue;
|
|
444
689
|
overrides[subAgentId] = normalizeFilePath(resolveProjectFilePath(context.paths.projectRoot, existingSubAgent.filePath)) === normalizeFilePath(agentFilePath) ? {
|
|
@@ -494,8 +739,8 @@ function inferHeadersReferenceFromContextConfig(contextConfig, contextConfigId)
|
|
|
494
739
|
if (typeof headers === "string" && headers.length > 0) return toCamelCase(headers);
|
|
495
740
|
const headersRecord = asRecord(headers);
|
|
496
741
|
if (headersRecord) {
|
|
497
|
-
if (typeof headersRecord.id === "string" && headersRecord.id
|
|
498
|
-
if (typeof headersRecord.name === "string" && headersRecord.name
|
|
742
|
+
if (typeof headersRecord.id === "string" && headersRecord.id) return toCamelCase(headersRecord.id);
|
|
743
|
+
if (typeof headersRecord.name === "string" && headersRecord.name) return toCamelCase(headersRecord.name);
|
|
499
744
|
}
|
|
500
745
|
if (isPlainObject(contextConfig.value.headersSchema)) return `${toCamelCase(contextConfigId)}Headers`;
|
|
501
746
|
}
|
|
@@ -545,53 +790,116 @@ function applyPromptHeaderTemplateSchema(contextConfig, headerTemplateVariables)
|
|
|
545
790
|
}
|
|
546
791
|
function collectSubAgentDependencyReferenceOverrides(context, subAgentData) {
|
|
547
792
|
const registry = context.existingComponentRegistry;
|
|
548
|
-
|
|
549
|
-
const
|
|
793
|
+
const referenceOverrides = {};
|
|
794
|
+
const referencePathOverrides = {};
|
|
795
|
+
const toolReferenceNamesById = buildToolReferenceNamesById(context.project);
|
|
796
|
+
const toolReferencePathsById = buildToolReferencePathById(context.project);
|
|
797
|
+
const subAgentReferenceNamesById = buildSubAgentReferenceNamesById(context.project, context.completeAgentIds);
|
|
798
|
+
const subAgentReferencePathsById = buildSubAgentReferencePathById(context.project, context.completeAgentIds);
|
|
799
|
+
const agentReferenceNamesById = buildAgentReferenceNamesById(context.project);
|
|
800
|
+
const agentReferencePathsById = buildAgentReferencePathById(context.project);
|
|
801
|
+
const externalAgentReferenceNamesById = buildExternalAgentReferenceNamesById(context.project);
|
|
802
|
+
const externalAgentReferencePathsById = buildExternalAgentReferencePathById(context.project);
|
|
803
|
+
const assignSubAgentReferenceOverrides = (subAgentId) => {
|
|
804
|
+
const subAgentReferenceName = subAgentReferenceNamesById[subAgentId];
|
|
805
|
+
if (subAgentReferenceName) assignReferenceOverride(referenceOverrides, "subAgents", subAgentId, subAgentReferenceName);
|
|
806
|
+
const subAgentReferencePath = subAgentReferencePathsById[subAgentId];
|
|
807
|
+
if (subAgentReferencePath) assignReferencePathOverride(referencePathOverrides, "subAgents", subAgentId, subAgentReferencePath);
|
|
808
|
+
};
|
|
809
|
+
const assignAgentReferenceOverrides = (agentId) => {
|
|
810
|
+
const agentReferenceName = agentReferenceNamesById[agentId];
|
|
811
|
+
if (agentReferenceName) assignReferenceOverride(referenceOverrides, "agents", agentId, agentReferenceName);
|
|
812
|
+
const agentReferencePath = agentReferencePathsById[agentId];
|
|
813
|
+
if (agentReferencePath) assignReferencePathOverride(referencePathOverrides, "agents", agentId, agentReferencePath);
|
|
814
|
+
};
|
|
815
|
+
const assignExternalAgentReferenceOverrides = (externalAgentId) => {
|
|
816
|
+
const externalAgentReferenceName = externalAgentReferenceNamesById[externalAgentId];
|
|
817
|
+
if (externalAgentReferenceName) assignReferenceOverride(referenceOverrides, "externalAgents", externalAgentId, externalAgentReferenceName);
|
|
818
|
+
const externalAgentReferencePath = externalAgentReferencePathsById[externalAgentId];
|
|
819
|
+
if (externalAgentReferencePath) assignReferencePathOverride(referencePathOverrides, "externalAgents", externalAgentId, externalAgentReferencePath);
|
|
820
|
+
};
|
|
550
821
|
const canUse = Array.isArray(subAgentData.canUse) ? subAgentData.canUse : [];
|
|
551
822
|
for (const item of canUse) {
|
|
552
|
-
if (typeof item === "string") {
|
|
553
|
-
assignComponentReferenceOverride(registry, overrides, "tools", item, "tools");
|
|
554
|
-
assignComponentReferenceOverride(registry, overrides, "tools", item, "functionTools");
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
823
|
const canUseRecord = asRecord(item);
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
824
|
+
const toolId = typeof item === "string" ? item : canUseRecord && typeof canUseRecord.toolId === "string" ? canUseRecord.toolId : void 0;
|
|
825
|
+
if (!toolId) continue;
|
|
826
|
+
assignReferenceOverride(referenceOverrides, "tools", toolId, toolReferenceNamesById[toolId] ?? toToolReferenceName(toolId));
|
|
827
|
+
assignReferencePathOverride(referencePathOverrides, "tools", toolId, toolReferencePathsById[toolId] ?? toKebabCase(toolId));
|
|
828
|
+
if (registry) {
|
|
829
|
+
assignComponentReferenceOverride(registry, referenceOverrides, "tools", toolId, "tools");
|
|
830
|
+
assignComponentReferenceOverride(registry, referenceOverrides, "tools", toolId, "functionTools");
|
|
831
|
+
const toolComponent = registry.get(toolId, "functionTools") ?? registry.get(toolId, "tools");
|
|
832
|
+
if (toolComponent?.filePath) assignReferencePathOverride(referencePathOverrides, "tools", toolId, resolveToolModulePath(toolComponent.filePath));
|
|
833
|
+
}
|
|
561
834
|
}
|
|
562
835
|
const canDelegateTo = Array.isArray(subAgentData.canDelegateTo) ? subAgentData.canDelegateTo : [];
|
|
563
836
|
for (const item of canDelegateTo) {
|
|
564
837
|
if (typeof item === "string") {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
["externalAgents", "externalAgents"]
|
|
569
|
-
]);
|
|
838
|
+
assignSubAgentReferenceOverrides(item);
|
|
839
|
+
assignAgentReferenceOverrides(item);
|
|
840
|
+
assignExternalAgentReferenceOverrides(item);
|
|
570
841
|
continue;
|
|
571
842
|
}
|
|
572
843
|
const canDelegateRecord = asRecord(item);
|
|
573
|
-
if (
|
|
574
|
-
if (typeof canDelegateRecord
|
|
575
|
-
|
|
576
|
-
|
|
844
|
+
if (typeof canDelegateRecord?.subAgentId === "string") assignSubAgentReferenceOverrides(canDelegateRecord.subAgentId);
|
|
845
|
+
if (typeof canDelegateRecord?.agentId === "string") assignAgentReferenceOverrides(canDelegateRecord.agentId);
|
|
846
|
+
if (typeof canDelegateRecord?.externalAgentId === "string") assignExternalAgentReferenceOverrides(canDelegateRecord.externalAgentId);
|
|
847
|
+
}
|
|
848
|
+
const canTransferTo = extractReferenceIds(subAgentData.canTransferTo);
|
|
849
|
+
for (const transferTargetId of canTransferTo) {
|
|
850
|
+
assignSubAgentReferenceOverrides(transferTargetId);
|
|
851
|
+
assignAgentReferenceOverrides(transferTargetId);
|
|
852
|
+
assignExternalAgentReferenceOverrides(transferTargetId);
|
|
853
|
+
}
|
|
854
|
+
if (registry) {
|
|
855
|
+
for (const item of canDelegateTo) {
|
|
856
|
+
if (typeof item === "string") {
|
|
857
|
+
assignFirstMatchingComponentReferenceOverride(registry, referenceOverrides, item, [
|
|
858
|
+
["subAgents", "subAgents"],
|
|
859
|
+
["agents", "agents"],
|
|
860
|
+
["externalAgents", "externalAgents"]
|
|
861
|
+
]);
|
|
862
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "subAgents", item, "subAgents");
|
|
863
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "agents", item, "agents");
|
|
864
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "externalAgents", item, "externalAgents");
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const canDelegateRecord = asRecord(item);
|
|
868
|
+
if (!canDelegateRecord) continue;
|
|
869
|
+
if (typeof canDelegateRecord.subAgentId === "string") {
|
|
870
|
+
assignComponentReferenceOverride(registry, referenceOverrides, "subAgents", canDelegateRecord.subAgentId, "subAgents");
|
|
871
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "subAgents", canDelegateRecord.subAgentId, "subAgents");
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
if (typeof canDelegateRecord.agentId === "string") {
|
|
875
|
+
assignComponentReferenceOverride(registry, referenceOverrides, "agents", canDelegateRecord.agentId, "agents");
|
|
876
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "agents", canDelegateRecord.agentId, "agents");
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
if (typeof canDelegateRecord.externalAgentId === "string") {
|
|
880
|
+
assignComponentReferenceOverride(registry, referenceOverrides, "externalAgents", canDelegateRecord.externalAgentId, "externalAgents");
|
|
881
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "externalAgents", canDelegateRecord.externalAgentId, "externalAgents");
|
|
882
|
+
}
|
|
577
883
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
884
|
+
for (const transferTargetId of canTransferTo) {
|
|
885
|
+
assignFirstMatchingComponentReferenceOverride(registry, referenceOverrides, transferTargetId, [
|
|
886
|
+
["subAgents", "subAgents"],
|
|
887
|
+
["agents", "agents"],
|
|
888
|
+
["externalAgents", "externalAgents"]
|
|
889
|
+
]);
|
|
890
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "subAgents", transferTargetId, "subAgents");
|
|
891
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "agents", transferTargetId, "agents");
|
|
892
|
+
assignComponentReferencePathOverride(registry, referencePathOverrides, "externalAgents", transferTargetId, "externalAgents");
|
|
581
893
|
}
|
|
582
|
-
|
|
894
|
+
const dataComponentIds = extractReferenceIds(subAgentData.dataComponents);
|
|
895
|
+
for (const dataComponentId of dataComponentIds) assignComponentReferenceOverride(registry, referenceOverrides, "dataComponents", dataComponentId, "dataComponents");
|
|
896
|
+
const artifactComponentIds = extractReferenceIds(subAgentData.artifactComponents);
|
|
897
|
+
for (const artifactComponentId of artifactComponentIds) assignComponentReferenceOverride(registry, referenceOverrides, "artifactComponents", artifactComponentId, "artifactComponents");
|
|
583
898
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
["externalAgents", "externalAgents"]
|
|
589
|
-
]);
|
|
590
|
-
const dataComponentIds = extractReferenceIds(subAgentData.dataComponents);
|
|
591
|
-
for (const dataComponentId of dataComponentIds) assignComponentReferenceOverride(registry, overrides, "dataComponents", dataComponentId, "dataComponents");
|
|
592
|
-
const artifactComponentIds = extractReferenceIds(subAgentData.artifactComponents);
|
|
593
|
-
for (const artifactComponentId of artifactComponentIds) assignComponentReferenceOverride(registry, overrides, "artifactComponents", artifactComponentId, "artifactComponents");
|
|
594
|
-
return Object.keys(overrides).length > 0 ? overrides : void 0;
|
|
899
|
+
return Object.keys(referenceOverrides).length > 0 || Object.keys(referencePathOverrides).length > 0 ? {
|
|
900
|
+
...Object.keys(referenceOverrides).length > 0 && { referenceOverrides },
|
|
901
|
+
...Object.keys(referencePathOverrides).length > 0 && { referencePathOverrides }
|
|
902
|
+
} : void 0;
|
|
595
903
|
}
|
|
596
904
|
function assignFirstMatchingComponentReferenceOverride(registry, overrides, componentId, candidates) {
|
|
597
905
|
for (const [overrideType, componentType] of candidates) {
|
|
@@ -606,15 +914,123 @@ function assignComponentReferenceOverride(registry, overrides, overrideType, com
|
|
|
606
914
|
if (!component?.name) return;
|
|
607
915
|
assignReferenceOverride(overrides, overrideType, componentId, component.name);
|
|
608
916
|
}
|
|
917
|
+
function assignComponentReferencePathOverride(registry, overrides, overrideType, componentId, componentType) {
|
|
918
|
+
const component = registry.get(componentId, componentType);
|
|
919
|
+
if (!component?.filePath) return;
|
|
920
|
+
assignReferencePathOverride(overrides, overrideType, componentId, componentType === "tools" || componentType === "functionTools" ? resolveToolModulePath(component.filePath) : stripExtension(basename(component.filePath)));
|
|
921
|
+
}
|
|
609
922
|
function assignReferenceOverride(overrides, overrideType, componentId, referenceName) {
|
|
610
923
|
const overrideMap = overrides[overrideType] ?? {};
|
|
611
924
|
overrideMap[componentId] = referenceName;
|
|
612
925
|
overrides[overrideType] = overrideMap;
|
|
613
926
|
}
|
|
927
|
+
function assignReferencePathOverride(overrides, overrideType, componentId, referencePath) {
|
|
928
|
+
const overrideMap = overrides[overrideType] ?? {};
|
|
929
|
+
overrideMap[componentId] = referencePath;
|
|
930
|
+
overrides[overrideType] = overrideMap;
|
|
931
|
+
}
|
|
932
|
+
function buildToolReferenceNamesById(project) {
|
|
933
|
+
const toolReferenceNamesById = {};
|
|
934
|
+
for (const [toolId, toolData] of Object.entries(project.tools ?? {})) {
|
|
935
|
+
const toolName = asRecord(toolData)?.name;
|
|
936
|
+
toolReferenceNamesById[toolId] = typeof toolName === "string" && toolName.length > 0 ? toToolReferenceName(toolName) : toToolReferenceName(toolId);
|
|
937
|
+
}
|
|
938
|
+
for (const functionToolEntry of collectFunctionToolEntries(project)) toolReferenceNamesById[functionToolEntry.functionToolId] = toToolReferenceName(functionToolEntry.exportName);
|
|
939
|
+
return toolReferenceNamesById;
|
|
940
|
+
}
|
|
941
|
+
function buildToolReferencePathById(project) {
|
|
942
|
+
const toolEntries = Object.entries(project.tools ?? {});
|
|
943
|
+
const toolFileNamesById = buildSequentialNameFileNames(toolEntries);
|
|
944
|
+
const toolReferencePathById = {};
|
|
945
|
+
for (const [toolId] of toolEntries) toolReferencePathById[toolId] = stripExtension(toolFileNamesById[toolId]);
|
|
946
|
+
const functionToolEntries = collectFunctionToolEntries(project);
|
|
947
|
+
const functionToolFileNamesById = buildSequentialNameFileNames(functionToolEntries.map(({ functionToolId, fileName }) => [functionToolId, { name: fileName }]));
|
|
948
|
+
for (const { functionToolId } of functionToolEntries) toolReferencePathById[functionToolId] = stripExtension(functionToolFileNamesById[functionToolId]);
|
|
949
|
+
return toolReferencePathById;
|
|
950
|
+
}
|
|
951
|
+
function buildCredentialReferenceNamesById(project) {
|
|
952
|
+
const credentialReferenceNamesById = {};
|
|
953
|
+
const countsByReferenceName = /* @__PURE__ */ new Map();
|
|
954
|
+
for (const [credentialId, credentialData] of Object.entries(project.credentialReferences ?? {})) {
|
|
955
|
+
const credentialName = asRecord(credentialData)?.name;
|
|
956
|
+
const baseReferenceName = typeof credentialName === "string" && credentialName.length > 0 ? toCredentialReferenceName(credentialName) : toCredentialReferenceName(credentialId);
|
|
957
|
+
const occurrence = countsByReferenceName.get(baseReferenceName) ?? 0;
|
|
958
|
+
countsByReferenceName.set(baseReferenceName, occurrence + 1);
|
|
959
|
+
credentialReferenceNamesById[credentialId] = occurrence === 0 ? baseReferenceName : `${baseReferenceName}${occurrence}`;
|
|
960
|
+
}
|
|
961
|
+
return credentialReferenceNamesById;
|
|
962
|
+
}
|
|
963
|
+
function buildCredentialReferencePathById(project) {
|
|
964
|
+
const credentialEntries = Object.entries(project.credentialReferences ?? {});
|
|
965
|
+
const credentialFileNamesById = buildSequentialNameFileNames(credentialEntries);
|
|
966
|
+
const credentialReferencePathById = {};
|
|
967
|
+
for (const [credentialId] of credentialEntries) credentialReferencePathById[credentialId] = stripExtension(credentialFileNamesById[credentialId]);
|
|
968
|
+
return credentialReferencePathById;
|
|
969
|
+
}
|
|
970
|
+
function buildExternalAgentReferenceNamesById(project) {
|
|
971
|
+
const externalAgentReferenceNamesById = {};
|
|
972
|
+
const countsByReferenceName = /* @__PURE__ */ new Map();
|
|
973
|
+
for (const [externalAgentId, externalAgentData] of Object.entries(project.externalAgents ?? {})) {
|
|
974
|
+
const baseReferenceName = toExternalAgentReferenceName(resolveExternalAgentNamingSeed(externalAgentId, externalAgentData));
|
|
975
|
+
const occurrence = countsByReferenceName.get(baseReferenceName) ?? 0;
|
|
976
|
+
countsByReferenceName.set(baseReferenceName, occurrence + 1);
|
|
977
|
+
externalAgentReferenceNamesById[externalAgentId] = occurrence === 0 ? baseReferenceName : `${baseReferenceName}${occurrence}`;
|
|
978
|
+
}
|
|
979
|
+
return externalAgentReferenceNamesById;
|
|
980
|
+
}
|
|
981
|
+
function buildExternalAgentReferencePathById(project) {
|
|
982
|
+
const externalAgentEntries = Object.entries(project.externalAgents ?? {}).map(([externalAgentId, externalAgentData]) => [externalAgentId, { name: resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) }]);
|
|
983
|
+
const externalAgentFileNamesById = buildSequentialNameFileNames(externalAgentEntries);
|
|
984
|
+
const externalAgentReferencePathById = {};
|
|
985
|
+
for (const [externalAgentId] of externalAgentEntries) externalAgentReferencePathById[externalAgentId] = stripExtension(externalAgentFileNamesById[externalAgentId]);
|
|
986
|
+
return externalAgentReferencePathById;
|
|
987
|
+
}
|
|
988
|
+
function buildSubAgentReferenceNamesById(project, agentIds) {
|
|
989
|
+
const subAgentReferenceNamesById = {};
|
|
990
|
+
const candidateAgentIds = agentIds !== void 0 ? [...agentIds] : Object.keys(project.agents ?? {});
|
|
991
|
+
for (const agentId of candidateAgentIds) {
|
|
992
|
+
const agentData = project.agents?.[agentId];
|
|
993
|
+
const subAgents = asRecord(agentData?.subAgents);
|
|
994
|
+
if (!subAgents) continue;
|
|
995
|
+
for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {
|
|
996
|
+
const subAgentName = asRecord(subAgentData)?.name;
|
|
997
|
+
subAgentReferenceNamesById[subAgentId] = resolveSubAgentVariableName(subAgentId, typeof subAgentName === "string" ? subAgentName : void 0);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return subAgentReferenceNamesById;
|
|
1001
|
+
}
|
|
1002
|
+
function buildSubAgentReferencePathById(project, agentIds) {
|
|
1003
|
+
const subAgentReferencePathById = {};
|
|
1004
|
+
const candidateAgentIds = agentIds !== void 0 ? [...agentIds] : Object.keys(project.agents ?? {});
|
|
1005
|
+
for (const agentId of candidateAgentIds) {
|
|
1006
|
+
const agentData = project.agents?.[agentId];
|
|
1007
|
+
const subAgents = asRecord(agentData?.subAgents);
|
|
1008
|
+
if (!subAgents) continue;
|
|
1009
|
+
for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {
|
|
1010
|
+
const subAgentName = asRecord(subAgentData)?.name;
|
|
1011
|
+
subAgentReferencePathById[subAgentId] = stripExtension(buildComponentFileName(subAgentId, typeof subAgentName === "string" ? subAgentName : void 0));
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
return subAgentReferencePathById;
|
|
1015
|
+
}
|
|
1016
|
+
function buildAgentReferenceNamesById(project) {
|
|
1017
|
+
const agentReferenceNamesById = {};
|
|
1018
|
+
for (const agentId of Object.keys(project.agents ?? {})) agentReferenceNamesById[agentId] = toCamelCase(agentId);
|
|
1019
|
+
return agentReferenceNamesById;
|
|
1020
|
+
}
|
|
1021
|
+
function buildAgentReferencePathById(project) {
|
|
1022
|
+
const agentReferencePathById = {};
|
|
1023
|
+
for (const [agentId, agentData] of Object.entries(project.agents ?? {})) {
|
|
1024
|
+
const agentName = asRecord(agentData)?.name;
|
|
1025
|
+
agentReferencePathById[agentId] = stripExtension(buildComponentFileName(agentId, typeof agentName === "string" ? agentName : void 0));
|
|
1026
|
+
}
|
|
1027
|
+
return agentReferencePathById;
|
|
1028
|
+
}
|
|
614
1029
|
function collectProjectReferenceOverrides(context) {
|
|
615
|
-
const registry = context.existingComponentRegistry;
|
|
616
|
-
if (!registry) return;
|
|
617
1030
|
const overrides = {};
|
|
1031
|
+
addProjectNameBasedReferenceOverrides(context.project, overrides);
|
|
1032
|
+
const registry = context.existingComponentRegistry;
|
|
1033
|
+
if (!registry) return Object.keys(overrides).length > 0 ? overrides : void 0;
|
|
618
1034
|
for (const agentId of context.completeAgentIds) assignComponentReferenceOverrideForProject(registry, overrides, "agents", agentId, "agents");
|
|
619
1035
|
const toolIds = getObjectKeys(context.project.tools);
|
|
620
1036
|
for (const toolId of toolIds) {
|
|
@@ -631,6 +1047,102 @@ function collectProjectReferenceOverrides(context) {
|
|
|
631
1047
|
for (const credentialId of credentialIds) assignComponentReferenceOverrideForProject(registry, overrides, "credentialReferences", credentialId, "credentials");
|
|
632
1048
|
return Object.keys(overrides).length > 0 ? overrides : void 0;
|
|
633
1049
|
}
|
|
1050
|
+
function addProjectNameBasedReferenceOverrides(project, overrides) {
|
|
1051
|
+
for (const [toolId, toolData] of Object.entries(project.tools ?? {})) {
|
|
1052
|
+
const toolName = asRecord(toolData)?.name;
|
|
1053
|
+
assignProjectReferenceOverride(overrides, "tools", toolId, typeof toolName === "string" && toolName.length > 0 ? toToolReferenceName(toolName) : toToolReferenceName(toolId));
|
|
1054
|
+
}
|
|
1055
|
+
for (const [credentialId, credentialData] of Object.entries(project.credentialReferences ?? {})) {
|
|
1056
|
+
const credentialName = asRecord(credentialData)?.name;
|
|
1057
|
+
assignProjectReferenceOverride(overrides, "credentialReferences", credentialId, typeof credentialName === "string" && credentialName.length > 0 ? toCredentialReferenceName(credentialName) : toCredentialReferenceName(credentialId));
|
|
1058
|
+
}
|
|
1059
|
+
const externalAgentReferenceNamesById = buildExternalAgentReferenceNamesById(project);
|
|
1060
|
+
for (const [externalAgentId, referenceName] of Object.entries(externalAgentReferenceNamesById)) assignProjectReferenceOverride(overrides, "externalAgents", externalAgentId, referenceName);
|
|
1061
|
+
}
|
|
1062
|
+
function collectProjectReferencePathOverrides(context) {
|
|
1063
|
+
const overrides = {};
|
|
1064
|
+
if (context.project.agents) for (const agentId of context.completeAgentIds) {
|
|
1065
|
+
const agentData = asRecord(context.project.agents[agentId]);
|
|
1066
|
+
assignProjectReferenceOverride(overrides, "agents", agentId, stripExtension(buildComponentFileName(agentId, typeof agentData?.name === "string" ? agentData.name : void 0)));
|
|
1067
|
+
}
|
|
1068
|
+
const toolEntries = Object.entries(context.project.tools ?? {});
|
|
1069
|
+
const toolFileNamesById = buildSequentialNameFileNames(toolEntries);
|
|
1070
|
+
for (const [toolId] of toolEntries) assignProjectReferenceOverride(overrides, "tools", toolId, stripExtension(toolFileNamesById[toolId]));
|
|
1071
|
+
const credentialEntries = Object.entries(context.project.credentialReferences ?? {});
|
|
1072
|
+
const credentialFileNamesById = buildSequentialNameFileNames(credentialEntries);
|
|
1073
|
+
for (const [credentialId] of credentialEntries) assignProjectReferenceOverride(overrides, "credentialReferences", credentialId, stripExtension(credentialFileNamesById[credentialId]));
|
|
1074
|
+
const externalAgentReferencePathsById = buildExternalAgentReferencePathById(context.project);
|
|
1075
|
+
for (const [externalAgentId, referencePath] of Object.entries(externalAgentReferencePathsById)) assignProjectReferenceOverride(overrides, "externalAgents", externalAgentId, referencePath);
|
|
1076
|
+
const registry = context.existingComponentRegistry;
|
|
1077
|
+
if (registry) {
|
|
1078
|
+
for (const agentId of context.completeAgentIds) {
|
|
1079
|
+
const agentComponent = registry.get(agentId, "agents");
|
|
1080
|
+
if (agentComponent?.filePath) assignProjectReferenceOverride(overrides, "agents", agentId, stripExtension(basename(agentComponent.filePath)));
|
|
1081
|
+
}
|
|
1082
|
+
for (const toolId of getObjectKeys(context.project.tools)) {
|
|
1083
|
+
const toolComponent = registry.get(toolId, "functionTools") ?? registry.get(toolId, "tools");
|
|
1084
|
+
if (toolComponent?.filePath) assignProjectReferenceOverride(overrides, "tools", toolId, resolveToolModulePath(toolComponent.filePath));
|
|
1085
|
+
}
|
|
1086
|
+
for (const credentialId of getObjectKeys(context.project.credentialReferences)) {
|
|
1087
|
+
const credentialComponent = registry.get(credentialId, "credentials");
|
|
1088
|
+
if (credentialComponent?.filePath) assignProjectReferenceOverride(overrides, "credentialReferences", credentialId, stripExtension(basename(credentialComponent.filePath)));
|
|
1089
|
+
}
|
|
1090
|
+
for (const externalAgentId of getObjectKeys(context.project.externalAgents)) {
|
|
1091
|
+
const externalAgentComponent = registry.get(externalAgentId, "externalAgents");
|
|
1092
|
+
if (externalAgentComponent?.filePath) assignProjectReferenceOverride(overrides, "externalAgents", externalAgentId, stripExtension(basename(externalAgentComponent.filePath)));
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return Object.keys(overrides).length > 0 ? overrides : void 0;
|
|
1096
|
+
}
|
|
1097
|
+
function assignProjectReferenceOverride(overrides, overrideType, componentId, referenceName) {
|
|
1098
|
+
const overrideMap = overrides[overrideType] ?? {};
|
|
1099
|
+
overrideMap[componentId] = referenceName;
|
|
1100
|
+
overrides[overrideType] = overrideMap;
|
|
1101
|
+
}
|
|
1102
|
+
function stripExtension(fileName) {
|
|
1103
|
+
return fileName.replace(/\.[^.]+$/, "");
|
|
1104
|
+
}
|
|
1105
|
+
function resolveToolModulePath(filePath) {
|
|
1106
|
+
const normalizedFilePath = normalizeFilePath(filePath);
|
|
1107
|
+
const toolsIndex = normalizedFilePath.lastIndexOf("/tools/");
|
|
1108
|
+
if (toolsIndex >= 0) {
|
|
1109
|
+
let modulePath = stripExtension(normalizedFilePath.slice(toolsIndex + 7));
|
|
1110
|
+
if (modulePath.endsWith("/index")) modulePath = modulePath.slice(0, -6);
|
|
1111
|
+
if (modulePath.length > 0) return modulePath;
|
|
1112
|
+
}
|
|
1113
|
+
const baseModulePath = stripExtension(basename(normalizedFilePath));
|
|
1114
|
+
if (baseModulePath === "index") return stripExtension(basename(dirname(normalizedFilePath)));
|
|
1115
|
+
return baseModulePath;
|
|
1116
|
+
}
|
|
1117
|
+
function resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) {
|
|
1118
|
+
if (isHumanReadableId(externalAgentId)) return externalAgentId;
|
|
1119
|
+
const externalAgentName = asRecord(externalAgentData)?.name;
|
|
1120
|
+
if (typeof externalAgentName === "string" && externalAgentName.length > 0) return externalAgentName;
|
|
1121
|
+
return externalAgentId;
|
|
1122
|
+
}
|
|
1123
|
+
function toExternalAgentReferenceName(input) {
|
|
1124
|
+
const base = toCamelCase(input);
|
|
1125
|
+
return base.endsWith("Agent") ? base : `${base}Agent`;
|
|
1126
|
+
}
|
|
1127
|
+
function buildSequentialNameFileNames(entries) {
|
|
1128
|
+
const countsByStem = /* @__PURE__ */ new Map();
|
|
1129
|
+
const fileNamesById = {};
|
|
1130
|
+
for (const [componentId, componentData] of entries) {
|
|
1131
|
+
const name = asRecord(componentData)?.name;
|
|
1132
|
+
const baseStem = resolveNameFileStem(componentId, typeof name === "string" ? name : void 0);
|
|
1133
|
+
const occurrence = countsByStem.get(baseStem) ?? 0;
|
|
1134
|
+
countsByStem.set(baseStem, occurrence + 1);
|
|
1135
|
+
fileNamesById[componentId] = `${occurrence === 0 ? baseStem : `${baseStem}-${occurrence}`}.ts`;
|
|
1136
|
+
}
|
|
1137
|
+
return fileNamesById;
|
|
1138
|
+
}
|
|
1139
|
+
function resolveNameFileStem(componentId, name) {
|
|
1140
|
+
const nameStem = name ? toKebabCase(name) : "";
|
|
1141
|
+
if (nameStem.length > 0) return nameStem;
|
|
1142
|
+
const idStem = toKebabCase(componentId);
|
|
1143
|
+
if (idStem.length > 0) return idStem;
|
|
1144
|
+
return componentId;
|
|
1145
|
+
}
|
|
634
1146
|
function assignComponentReferenceOverrideForProject(registry, overrides, overrideType, componentId, componentType) {
|
|
635
1147
|
const component = registry.get(componentId, componentType);
|
|
636
1148
|
if (!component?.name) return false;
|
|
@@ -729,4 +1241,5 @@ function isReferenceInsideFunctionLike(referenceNode) {
|
|
|
729
1241
|
}
|
|
730
1242
|
|
|
731
1243
|
//#endregion
|
|
732
|
-
export { introspectGenerate };
|
|
1244
|
+
export { introspectGenerate };
|
|
1245
|
+
//# sourceMappingURL=introspect-generator.js.map
|